-
Notifications
You must be signed in to change notification settings - Fork 119
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
1 parent
ce7b5d7
commit 4053927
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/KafkaFlow.UnitTests/Serializers/NewtonsoftJsonDeserializerTests.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 @@ | ||
namespace KafkaFlow.UnitTests.Serializers | ||
{ | ||
using System; | ||
using System.IO; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using AutoFixture; | ||
using FluentAssertions; | ||
using KafkaFlow.Serializer; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; | ||
using Newtonsoft.Json; | ||
|
||
[TestClass] | ||
public class NewtonsoftJsonDeserializerTests | ||
{ | ||
private readonly Mock<ISerializerContext> contextMock = new (); | ||
private readonly NewtonsoftJsonDeserializer deserializer = new (); | ||
|
||
private readonly Fixture fixture = new(); | ||
|
||
[TestMethod] | ||
public async Task DeserializeAsync_ValidPayload_ObjectGenerated() | ||
{ | ||
// Arrange | ||
var message = this.fixture.Create<TestMessage>(); | ||
using var input = new MemoryStream(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message))); | ||
|
||
// Act | ||
var result = await this.deserializer.DeserializeAsync(input, typeof(TestMessage), this.contextMock.Object); | ||
|
||
// Assert | ||
result.Should().NotBeNull(); | ||
result.Should().BeOfType<TestMessage>(); | ||
} | ||
|
||
private class TestMessage | ||
{ | ||
public int IntegerField { get; set; } | ||
|
||
public string StringField { get; set; } | ||
|
||
public double DoubleField { get; set; } | ||
|
||
public DateTime DateTimeField { get; set; } | ||
} | ||
} | ||
} |