From c073c904bd5c4dfac7c57f3a18392010b5764401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Fija=C5=82kowski?= Date: Fri, 11 Aug 2023 16:14:16 +0200 Subject: [PATCH] Simplify tag generation tests --- .../NotificationTagGenerators.cs | 59 ++++++------------- 1 file changed, 19 insertions(+), 40 deletions(-) diff --git a/src/LeanCode.ContractsGenerator.Tests/Notifications/NotificationTagGenerators.cs b/src/LeanCode.ContractsGenerator.Tests/Notifications/NotificationTagGenerators.cs index c84fa47..3a6c588 100644 --- a/src/LeanCode.ContractsGenerator.Tests/Notifications/NotificationTagGenerators.cs +++ b/src/LeanCode.ContractsGenerator.Tests/Notifications/NotificationTagGenerators.cs @@ -1,4 +1,5 @@ using Xunit; +using static LeanCode.ContractsGenerator.Tests.TypeRefExtensions; using CompilationTagGenerator = LeanCode.ContractsGenerator.Generation.NotificationTagGenerator; using ContractsTagGenerator = LeanCode.Contracts.NotificationTagGenerator; using OtherNamespaceDTO1 = Notifications.Internal.DTO1; @@ -16,7 +17,7 @@ public class NotificationTagGenerators private readonly string otherNamespaceDto1Name = $"{typeof(OtherNamespaceDTO1).FullName}"; [Fact] - public void Simple_class() + public void Simple_class_tag_is_generated_correctly() { var type = typeof(Class1); var typeRef = TypeRefExtensions.Internal(class1Name); @@ -26,47 +27,36 @@ public void Simple_class() } [Fact] - public void Single_generic_argument() + public void Generic_arguments_are_described_correctly() { var type = typeof(Class2); - var typeRef = TypeRefExtensions - .Internal(class2Name) - .WithArguments(TypeRefExtensions.Known(KnownType.Int32)); + var typeRef = TypeRefExtensions.Internal(class2Name).WithArguments(Known(KnownType.Int32)); var expectedTag = $"{class2Name}[!Int32]"; CheckGeneratedTags(type, typeRef, expectedTag); } [Fact] - public void Multiple_generic_arguments() + public void Multiple_generic_arguments_are_described_correctly() { var type = typeof(Class3); var typeRef = TypeRefExtensions .Internal(class3Name) - .WithArguments( - TypeRefExtensions.Known(KnownType.Int32), - TypeRefExtensions.Known(KnownType.DateTimeOffset) - ); + .WithArguments(Known(KnownType.Int32), Known(KnownType.DateTimeOffset)); var expectedTag = $"{class3Name}[!Int32,!DateTimeOffset]"; CheckGeneratedTags(type, typeRef, expectedTag); } [Fact] - public void Nested_generic_arguments() + public void Nested_generic_arguments_are_described_correctly() { var type = typeof(Class3, Class2>); var typeRef = TypeRefExtensions .Internal(class3Name) .WithArguments( - TypeRefExtensions - .Internal(class2Name) - .WithArguments(TypeRefExtensions.Known(KnownType.Object)), - TypeRefExtensions - .Internal(class2Name) - .WithArguments( - TypeRefExtensions.Array(TypeRefExtensions.Known(KnownType.Int32)) - ) + TypeRefExtensions.Internal(class2Name).WithArguments(Known(KnownType.Object)), + TypeRefExtensions.Internal(class2Name).WithArguments(Array(Known(KnownType.Int32))) ); var expectedTag = $"{class3Name}[{class2Name}[!Object],{class2Name}[!Array[!Int32]]]"; @@ -74,14 +64,12 @@ public void Nested_generic_arguments() } [Fact] - public void Map() + public void Maps_are_described_correctly() { var type = typeof(Dictionary>); - var typeRef = TypeRefExtensions.Map( - TypeRefExtensions.Array(TypeRefExtensions.Known(KnownType.Guid)), - TypeRefExtensions - .Internal(class2Name) - .WithArguments(TypeRefExtensions.Known(KnownType.TimeSpan)) + var typeRef = Map( + Array(Known(KnownType.Guid)), + TypeRefExtensions.Internal(class2Name).WithArguments(Known(KnownType.TimeSpan)) ); var expectedTag = $"!Map[!Array[!Guid],{class2Name}[!TimeSpan]]"; @@ -95,17 +83,10 @@ public void Map() } [Fact] - public void Array() + public void Arrays_are_described_correctly() { var type = typeof(Dictionary[][]); - var typeRef = TypeRefExtensions.Array( - TypeRefExtensions.Array( - TypeRefExtensions.Map( - TypeRefExtensions.Known(KnownType.Int32), - TypeRefExtensions.Known(KnownType.String) - ) - ) - ); + var typeRef = Array(Array(Map(Known(KnownType.Int32), Known(KnownType.String)))); var expectedTag = "!Array[!Array[!Map[!Int32,!String]]]"; CheckGeneratedTags(type, typeRef, expectedTag); @@ -120,17 +101,15 @@ public void Array() } [Fact] - public void Known_type_name_clashes() + public void If_a_known_type_clashes_name_with_internal_type_The_clash_is_resolved_correctly() { var type1 = typeof(List); var type2 = typeof(System.Collections.Generic.List); CheckIfTagsAreDifferent(type1, type2); - var typeRef1 = TypeRefExtensions - .Internal(listName) - .WithArguments(TypeRefExtensions.Known(KnownType.Int32)); - var typeRef2 = TypeRefExtensions.Array(TypeRefExtensions.Known(KnownType.Int32)); + var typeRef1 = TypeRefExtensions.Internal(listName).WithArguments(Known(KnownType.Int32)); + var typeRef2 = Array(Known(KnownType.Int32)); CheckIfTagsAreDifferent(typeRef1, typeRef2); @@ -139,7 +118,7 @@ public void Known_type_name_clashes() } [Fact] - public void Class_name_clashes() + public void Namespaces_are_preserved_and_contribute_to_the_tag() { var type1 = typeof(DTO1); var type2 = typeof(OtherNamespaceDTO1);