Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ltrzesniewski committed Aug 19, 2019
1 parent 0b0b645 commit d94bd82
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 33 deletions.
31 changes: 12 additions & 19 deletions src/Abc.Zebus.MessageDsl.Tests/MessageDsl/CSharpGeneratorTests.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<T>");
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<T>");
}

protected override string GenerateRaw(ParsedContracts contracts) => CSharpGenerator.Generate(contracts);
Expand Down
16 changes: 4 additions & 12 deletions src/Abc.Zebus.MessageDsl.Tests/MessageDsl/ParsedContractsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>();");

// 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)
Expand Down
3 changes: 1 addition & 2 deletions src/Abc.Zebus.MessageDsl/Analysis/AstValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit d94bd82

Please sign in to comment.