Skip to content

Commit

Permalink
fix: missing unit test file
Browse files Browse the repository at this point in the history
  • Loading branch information
jose-sousa-8 committed Sep 20, 2023
1 parent ce7b5d7 commit 4053927
Showing 1 changed file with 48 additions and 0 deletions.
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; }
}
}
}

0 comments on commit 4053927

Please sign in to comment.