Skip to content

Commit

Permalink
NUnit 4.*.
Browse files Browse the repository at this point in the history
  • Loading branch information
Corniel committed Apr 19, 2024
1 parent 6fb78c5 commit d5a9577
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 58 deletions.
15 changes: 5 additions & 10 deletions test/Qowaiv.Json.UnitTests/BsonConverterRegisterTest.cs
@@ -1,5 +1,4 @@
using NUnit.Framework;
using Qowaiv.Bson.MongoDB;
using Qowaiv.Bson.MongoDB;
using Qowaiv.Json.UnitTests.TestTools;

namespace Qowaiv.Json.UnitTests;
Expand All @@ -10,18 +9,14 @@ public class BsonConverterRegisterTest
public void RegisterAssembly_Qowaiv_SerializesSvoFromAssembly()
{
QowaivBsonConverter.RegisterAssembly(typeof(Date).Assembly);
Assert.AreEqual(@"""2017-06-11""", TestSerializer.BsonSerialize(new Date(2017, 06, 11)));
TestSerializer.BsonSerialize(new Date(2017, 06, 11)).Should().Be(@"""2017-06-11""");
}

[Test]
public void RegisterTypeGeneric_Int_Throws()
{
Assert.Throws<NotSupportedException>(() => QowaivBsonConverter.RegisterType<int>());
}

=> 42.Invoking(_ => QowaivBsonConverter.RegisterType<int>()).Should().Throw<NotSupportedException>();

[Test]
public void RegisterType_Int_Throws()
{
Assert.Throws<NotSupportedException>(() => QowaivBsonConverter.RegisterType(typeof(int)));
}
=> 42.Invoking(_ => QowaivBsonConverter.RegisterType(typeof(int))).Should().Throw<NotSupportedException>();
}
48 changes: 11 additions & 37 deletions test/Qowaiv.Json.UnitTests/JsonCanConvertTestBase.cs
@@ -1,6 +1,4 @@
using NUnit.Framework;
using Qowaiv.Json.UnitTests.Models;
using System;
using Qowaiv.Json.UnitTests.Models;

namespace Qowaiv.Json.UnitTests;

Expand All @@ -11,52 +9,28 @@ namespace Qowaiv.Json.UnitTests;
public abstract class JsonCanConvertTestBase
{
[Test]
public void CanConvert_Null_False()
{
Assert.IsFalse(CanConvert(null));
}
public void CanConvert_Null_False() => CanConvert(null).Should().BeFalse();

[Test]
public void CanConvert_Object_False()
{
Assert.IsFalse(CanConvert(typeof(object)));
}
public void CanConvert_Object_False() => CanConvert(typeof(object)).Should().BeFalse();

[Test]
public void CanConvert_Int32_False()
{
Assert.IsFalse(CanConvert(typeof(int)));
}
public void CanConvert_Int32_False() => CanConvert(typeof(int)).Should().BeFalse();

[Test]
public void CanConvert_SvoWithFromJsonBoolOnly_False()
{
Assert.IsFalse(CanConvert(typeof(SvoWithFromJsonBoolOnly)));
}

public void CanConvert_SvoWithFromJsonBoolOnly_False() => CanConvert(typeof(SvoWithFromJsonBoolOnly)).Should().BeFalse();

[Test]
public void CanConvert_SvoWithFromJsonStringOnly_True()
{
Assert.IsTrue(CanConvert(typeof(SvoWithFromJsonStringOnly)));
}
public void CanConvert_SvoWithFromJsonStringOnly_True() => CanConvert(typeof(SvoWithFromJsonStringOnly)).Should().BeTrue();

[Test]
public void CanConvert_SvoWithFromJson_True()
{
Assert.IsTrue(CanConvert(typeof(SvoWithFromJson)));
}
public void CanConvert_SvoWithFromJson_True() => CanConvert(typeof(SvoWithFromJson)).Should().BeTrue();

[Test]
public void CanConvert_NullableSvoWithFromJson_True()
{
Assert.IsTrue(CanConvert(typeof(SvoWithFromJson?)));
}
public void CanConvert_NullableSvoWithFromJson_True() => CanConvert(typeof(SvoWithFromJson?)).Should().BeTrue();

[Test]
public void CanConvert_SvoWithFromJsonClass_True()
{
Assert.IsTrue(CanConvert(typeof(SvoWithFromJsonClass)));
}
public void CanConvert_SvoWithFromJsonClass_True() => CanConvert(typeof(SvoWithFromJsonClass)).Should().BeTrue();

protected abstract bool CanConvert(Type type);
protected abstract bool CanConvert(Type? type);
}
15 changes: 5 additions & 10 deletions test/Qowaiv.Json.UnitTests/NewtonsoftSerializeTest.cs
Expand Up @@ -7,27 +7,22 @@ public class NewtonsoftSerializeTest : JsonSerializeTestBase<JsonSerializationEx
{
public NewtonsoftSerializeTest()
{
if (JsonConvert.DefaultSettings == null)
{
JsonConvert.DefaultSettings = () => new JsonSerializerSettings { Converters = { new QowaivJsonConverter() } };
}
JsonConvert.DefaultSettings ??= () => new JsonSerializerSettings { Converters = { new QowaivJsonConverter() } };
QowaivJsonConverter.Register();
}

[Test]
public void Register_ClearAll_Successful()
{
var settings = JsonConvert.DefaultSettings.Invoke();
settings.Converters.Clear();
var settings = JsonConvert.DefaultSettings!.Invoke();

Assert.AreEqual(0, settings.Converters.Count, "Default converters should be empty.");
settings.Converters.Clear();
settings.Converters.Should().BeEmpty();

QowaivJsonConverter.Register();

settings = JsonConvert.DefaultSettings.Invoke();

Assert.AreEqual(1, settings.Converters.Count, "Default converters should contain one converter.");
Assert.AreEqual(typeof(QowaivJsonConverter), settings.Converters[0].GetType(), "Default converters should contain a QowaivJsonConverter.");
settings.Converters.Single().Should().BeOfType<QowaivJsonConverter>();
}

protected override T Deserialize<T>(string? jsonString)
Expand Down
2 changes: 1 addition & 1 deletion test/Qowaiv.Json.UnitTests/Qowaiv.Json.UnitTests.csproj
Expand Up @@ -22,7 +22,7 @@
<PackageReference Include="coverlet.msbuild" Version="*" PrivateAssets="all" />
<PackageReference Include="FluentAssertions" Version="6.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.*" />
<PackageReference Include="NUnit" Version="3.*" />
<PackageReference Include="NUnit" Version="4.*" />
<PackageReference Include="NUnit3TestAdapter" Version="*" PrivateAssets="all" />
</ItemGroup>

Expand Down

0 comments on commit d5a9577

Please sign in to comment.