Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only try to inverse translate if the dictionary is set up #24

Merged
merged 2 commits into from
Oct 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/RdbmsEventStore.Tests/RdbmsEventStore.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="Moq" Version="4.7.137" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
</ItemGroup>
Expand Down
82 changes: 82 additions & 0 deletions src/RdbmsEventStore.Tests/TranslatingEventRegistryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System.Collections.Generic;
using Moq;
using RdbmsEventStore.EventRegistry;
using Xunit;

namespace RdbmsEventStore.Tests
{
public class TranslatingEventRegistryTests
{
private class Foo { }

public class UnidirectionalTranslations
{
private readonly TranslatingEventRegistry _registry;

public UnidirectionalTranslations()
{
var innerRegistry = new Mock<IComposableEventRegistry>(MockBehavior.Strict);
innerRegistry.Setup(r => r.NameFor(typeof(Foo))).Returns(nameof(Foo));
innerRegistry.Setup(r => r.TypeFor(nameof(Foo))).Returns(typeof(Foo));

_registry = new TranslatingEventRegistry(new Dictionary<string, string>
{
{"Bar", "Foo"}
}, innerRegistry.Object);
}

[Fact]
public void CanReturnTypesNotRegisteredInTranslations()
{
Assert.Equal(typeof(Foo), _registry.TypeFor(nameof(Foo)));
}

[Fact]
public void CanReturnTypesRegisteredInTranslations()
{
Assert.Equal(typeof(Foo), _registry.TypeFor("Bar"));
}

[Fact]
public void ReturnsNewName()
{
Assert.Equal(nameof(Foo), _registry.NameFor(typeof(Foo)));
}
}

public class BidirectionalTranslations
{
private readonly TranslatingEventRegistry _registry;

public BidirectionalTranslations()
{
var innerRegistry = new Mock<IComposableEventRegistry>(MockBehavior.Strict);
innerRegistry.Setup(r => r.NameFor(typeof(Foo))).Returns(nameof(Foo));
innerRegistry.Setup(r => r.TypeFor(nameof(Foo))).Returns(typeof(Foo));

_registry = new TranslatingEventRegistry(new Dictionary<string, string>
{
{"Bar", "Foo"}
}, innerRegistry.Object, translateNewEvents: true);
}

[Fact]
public void CanReturnTypesNotRegisteredInTranslations()
{
Assert.Equal(typeof(Foo), _registry.TypeFor(nameof(Foo)));
}

[Fact]
public void CanReturnTypesRegisteredInTranslations()
{
Assert.Equal(typeof(Foo), _registry.TypeFor("Bar"));
}

[Fact]
public void ReturnsOldName()
{
Assert.Equal("Bar", _registry.NameFor(typeof(Foo)));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private string TranslationFor(string eventType)
: eventType;

private string InverseTranslationFor(string eventType)
=> _inverseTranslations.TryGetValue(eventType, out var translated)
=> _translateNewEvents && _inverseTranslations.TryGetValue(eventType, out var translated)
? InverseTranslationFor(translated)
: eventType;

Expand Down