-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
209 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
publisher/test/LeanPipe.TestClient.Tests/LeanPipe.TestClient.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" /> | ||
|
||
<PackageReference Include="xunit" /> | ||
<PackageReference Include="xunit.analyzers" /> | ||
<PackageReference Include="xunit.runner.visualstudio"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="FluentAssertions" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="../../src/LeanPipe.TestClient/LeanPipe.TestClient.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
48 changes: 48 additions & 0 deletions
48
publisher/test/LeanPipe.TestClient.Tests/NotificationEnvelopeDeserializerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Text.Json; | ||
using FluentAssertions; | ||
using LeanCode.Contracts; | ||
using Xunit; | ||
|
||
namespace LeanPipe.TestClient.Tests; | ||
|
||
public class NotificationEnvelopeDeserializerTests | ||
{ | ||
private static readonly NotificationEnvelopeDeserializer Deserializer = | ||
new(new(typeof(Topic)), null); | ||
|
||
[Fact] | ||
public void NotificationEnvelopeDeserializer_deserializes_topic_and_notification() | ||
{ | ||
var topic = new Topic | ||
{ | ||
EntityIds = new() { "Entity1", "Entity2" }, | ||
}; | ||
|
||
var notification = new Notification { EntityId = "Entity1" }; | ||
|
||
var notificationEnvelope = NotificationEnvelope.Create(topic, notification); | ||
|
||
var serializedEnvelope = JsonSerializer.Serialize(notificationEnvelope); | ||
|
||
var deserializedEnvelope = JsonSerializer.Deserialize<NotificationEnvelope>( | ||
serializedEnvelope | ||
); | ||
|
||
Deserializer | ||
.Deserialize(deserializedEnvelope!) | ||
.Should() | ||
.BeEquivalentTo( | ||
new NotificationEnvelopeDeserializer.TopicsNotification(topic, notification) | ||
); | ||
} | ||
|
||
public class Topic : ITopic, IProduceNotification<Notification> | ||
{ | ||
public List<string> EntityIds { get; set; } = default!; | ||
} | ||
|
||
public class Notification | ||
{ | ||
public string EntityId { get; set; } = default!; | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
publisher/test/LeanPipe.TestClient.Tests/TopicDeepEqualityComparerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using FluentAssertions; | ||
using LeanCode.Contracts; | ||
using Xunit; | ||
|
||
namespace LeanPipe.TestClient.Tests; | ||
|
||
public class TopicDeepEqualityComparerTests | ||
{ | ||
private static readonly TopicDeepEqualityComparer ComparerInstance = | ||
TopicDeepEqualityComparer.Instance; | ||
|
||
private static ComplexTopic GetComplexTopic => | ||
new() | ||
{ | ||
PrimitiveGuid = Guid.Parse("c00d2320-3ff8-4fcb-854f-8c53d8d2637f"), | ||
ListOfPrimitives = new() { 1, 2 }, | ||
Complex = new() { PrimitiveString = "String1", }, | ||
}; | ||
|
||
[Fact] | ||
public void Topics_are_correctly_compared_when_they_are_the_same() | ||
{ | ||
var topic1 = GetComplexTopic; | ||
var topic2 = GetComplexTopic; | ||
|
||
ComparerInstance.Equals(topic1, topic2).Should().BeTrue(); | ||
|
||
ComparerInstance.GetHashCode(topic1).Should().Be(ComparerInstance.GetHashCode(topic2)); | ||
} | ||
|
||
[Fact] | ||
public void Topics_are_correctly_compared_when_some_primitives_differ() | ||
{ | ||
var topic1 = GetComplexTopic; | ||
var topic2 = GetComplexTopic; | ||
topic2.PrimitiveGuid = Guid.NewGuid(); | ||
|
||
ComparerInstance.Equals(topic1, topic2).Should().BeFalse(); | ||
|
||
ComparerInstance.GetHashCode(topic1).Should().NotBe(ComparerInstance.GetHashCode(topic2)); | ||
} | ||
|
||
[Fact] | ||
public void Topics_are_correctly_compared_when_some_lists_differ() | ||
{ | ||
var topic1 = GetComplexTopic; | ||
var topic2 = GetComplexTopic; | ||
topic2.ListOfPrimitives[^1] = 3; | ||
|
||
ComparerInstance.Equals(topic1, topic2).Should().BeFalse(); | ||
|
||
ComparerInstance.GetHashCode(topic1).Should().NotBe(ComparerInstance.GetHashCode(topic2)); | ||
|
||
var topic3 = GetComplexTopic; | ||
topic3.ListOfPrimitives.Add(3); | ||
|
||
ComparerInstance.Equals(topic1, topic3).Should().BeFalse(); | ||
|
||
ComparerInstance.GetHashCode(topic1).Should().NotBe(ComparerInstance.GetHashCode(topic3)); | ||
} | ||
|
||
[Fact] | ||
public void Topics_are_correctly_compared_when_some_complex_objects_differ() | ||
{ | ||
var topic1 = GetComplexTopic; | ||
var topic2 = GetComplexTopic; | ||
topic2.Complex.PrimitiveString = "String2"; | ||
|
||
ComparerInstance.Equals(topic1, topic2).Should().BeFalse(); | ||
|
||
ComparerInstance.GetHashCode(topic1).Should().NotBe(ComparerInstance.GetHashCode(topic2)); | ||
} | ||
|
||
private class ComplexTopic : ITopic | ||
{ | ||
public Guid PrimitiveGuid { get; set; } | ||
public List<int> ListOfPrimitives { get; set; } = default!; | ||
public ComplexDTO Complex { get; set; } = default!; | ||
} | ||
|
||
private class ComplexDTO | ||
{ | ||
public string PrimitiveString { get; set; } = default!; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters