From d94bd82290ad39d355da9503e27b068e2af0ecca Mon Sep 17 00:00:00 2001 From: Lucas Trzesniewski Date: Mon, 19 Aug 2019 14:35:59 +0200 Subject: [PATCH] Cleanup --- .../MessageDsl/CSharpGeneratorTests.cs | 31 +++++++------------ .../MessageDsl/ParsedContractsTests.cs | 16 +++------- .../Analysis/AstValidator.cs | 3 +- 3 files changed, 17 insertions(+), 33 deletions(-) diff --git a/src/Abc.Zebus.MessageDsl.Tests/MessageDsl/CSharpGeneratorTests.cs b/src/Abc.Zebus.MessageDsl.Tests/MessageDsl/CSharpGeneratorTests.cs index 6306d05..a762e98 100644 --- a/src/Abc.Zebus.MessageDsl.Tests/MessageDsl/CSharpGeneratorTests.cs +++ b/src/Abc.Zebus.MessageDsl.Tests/MessageDsl/CSharpGeneratorTests.cs @@ -1,5 +1,4 @@ -using System; -using Abc.Zebus.MessageDsl.Ast; +using Abc.Zebus.MessageDsl.Ast; using Abc.Zebus.MessageDsl.Generator; using Abc.Zebus.MessageDsl.Tests.TestTools; using NUnit.Framework; @@ -455,23 +454,17 @@ public void should_leave_supplied_protomap() [Test] public void should_generate_two_classes_with_same_name_and_different_arity() { - // Arrange - var msg1 = new MessageDefinition(); - msg1.Name = "GenericCommand"; - var msg2 = new MessageDefinition(); - msg2.Name = msg1.Name; - msg2.GenericParameters.Add("T"); - var contracts = new ParsedContracts(); - contracts.Messages.Add(msg1); - contracts.Messages.Add(msg2); - - // Act - var result = GenerateRaw(contracts); - - // Assert - contracts.Errors.ShouldBeEmpty(); - result.ShouldContain("public sealed partial class GenericCommand"); - result.ShouldContain("public sealed partial class GenericCommand"); + var code = GenerateRaw(new ParsedContracts + { + Messages = + { + new MessageDefinition { Name = "GenericCommand" }, + new MessageDefinition { Name = "GenericCommand", GenericParameters = { "T" } } + } + }); + + code.ShouldContain("public sealed partial class GenericCommand"); + code.ShouldContain("public sealed partial class GenericCommand"); } protected override string GenerateRaw(ParsedContracts contracts) => CSharpGenerator.Generate(contracts); diff --git a/src/Abc.Zebus.MessageDsl.Tests/MessageDsl/ParsedContractsTests.cs b/src/Abc.Zebus.MessageDsl.Tests/MessageDsl/ParsedContractsTests.cs index a0b786f..9485617 100644 --- a/src/Abc.Zebus.MessageDsl.Tests/MessageDsl/ParsedContractsTests.cs +++ b/src/Abc.Zebus.MessageDsl.Tests/MessageDsl/ParsedContractsTests.cs @@ -501,20 +501,12 @@ public void should_return_source_text() [Test] public void should_return_two_messages_with_same_name_but_different_arity() { - // Arrange - var name = "Foo"; - var genericParam = "T"; - var definitionText = $"{name}()" + Environment.NewLine + - $"{name}<{genericParam}>()"; + var contracts = ParseValid("Foo(); Foo();"); - // Act - var contracts = ParseValid(definitionText); - - // Assert contracts.Messages.Count.ShouldEqual(2); - contracts.Messages[0].Name.ShouldEqual(name); - contracts.Messages[1].Name.ShouldEqual(name); - contracts.Messages[1].GenericParameters.ExpectedSingle().ShouldEqual(genericParam); + contracts.Messages[0].Name.ShouldEqual("Foo"); + contracts.Messages[1].Name.ShouldEqual("Foo"); + contracts.Messages[1].GenericParameters.ExpectedSingle().ShouldEqual("T"); } private static ParsedContracts ParseValid(string definitionText) diff --git a/src/Abc.Zebus.MessageDsl/Analysis/AstValidator.cs b/src/Abc.Zebus.MessageDsl/Analysis/AstValidator.cs index b1a9089..cb1e794 100644 --- a/src/Abc.Zebus.MessageDsl/Analysis/AstValidator.cs +++ b/src/Abc.Zebus.MessageDsl/Analysis/AstValidator.cs @@ -117,9 +117,8 @@ string GetNameWithGenericArity(AstNode node) { var name = ((INamedNode)node).Name; if (node is MessageDefinition messageDef && messageDef.GenericParameters.Count > 0) - { name = $"{name}`{messageDef.GenericParameters.Count}"; - } + return name; } }