PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/Framework/src/Ncqrs.Tests/Eventing/Storage/AttributeEventTypeResolverTests.cs

http://github.com/ncqrs/ncqrs
C# | 126 lines | 100 code | 26 blank | 0 comment | 0 complexity | d3f5ad7f537ccf93495e01e44df4f613 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, Apache-2.0
  1. using System;
  2. using FluentAssertions;
  3. using Ncqrs.Eventing;
  4. using Ncqrs.Eventing.Storage;
  5. using Xunit;
  6. namespace Ncqrs.Tests.Eventing.Storage
  7. {
  8. public class AttributeEventTypeResolverTests
  9. {
  10. private AttributeEventTypeResolver resolver;
  11. public AttributeEventTypeResolverTests()
  12. {
  13. resolver = new AttributeEventTypeResolver();
  14. }
  15. [Fact]
  16. public void Resolves_types_to_event_names()
  17. {
  18. var type = typeof(FooEvent);
  19. resolver.AddEvent(type);
  20. var result = resolver.EventNameFor(type);
  21. result.Should().Be("foo");
  22. }
  23. [Fact]
  24. public void Does_not_use_alias_when_resolving_event_name()
  25. {
  26. var type = typeof(AliasedFooEvent);
  27. resolver.AddEvent(type);
  28. var result = resolver.EventNameFor(type);
  29. result.Should().Be("foo");
  30. }
  31. [Fact]
  32. public void Resolves_event_names_to_types()
  33. {
  34. var type = typeof(FooEvent);
  35. resolver.AddEvent(type);
  36. var result = resolver.ResolveType("foo");
  37. result.Should().Be(type);
  38. }
  39. [Fact]
  40. public void Resolves_alias_to_type()
  41. {
  42. var type = typeof(AliasedFooEvent);
  43. resolver.AddEvent(type);
  44. var result = resolver.ResolveType("bar");
  45. result.Should().Be(type);
  46. }
  47. [Fact]
  48. public void Does_not_error_when_adding_event_twice()
  49. {
  50. var type = typeof(FooEvent);
  51. resolver.AddEvent(type);
  52. resolver.AddEvent(type);
  53. }
  54. [Fact]
  55. public void Throws_if_adding_events_with_same_name()
  56. {
  57. resolver.AddEvent(typeof(FooEvent));
  58. var ex = Assert.Throws<ArgumentException>(() => resolver.AddEvent(typeof(AliasedFooEvent)));
  59. ex.Should();
  60. }
  61. [Fact]
  62. public void Throws_if_adding_aliases_that_exists()
  63. {
  64. resolver.AddEvent(typeof(BarEvent));
  65. var ex = Assert.Throws<ArgumentException>(() => resolver.AddEvent(typeof(AliasedFooEvent)));
  66. ex.Should();
  67. }
  68. [Fact]
  69. public void Throws_if_event_does_not_have_a_name()
  70. {
  71. var ex = Assert.Throws<ArgumentException>(() => resolver.AddEvent(typeof(UnnamedEvent1)));
  72. ex.Message.Should().Be("No name found for event Ncqrs.Tests.Eventing.Storage.AttributeEventTypeResolverTests+UnnamedEvent1, specify an EventNameAttribute.");
  73. }
  74. [Fact]
  75. public void Throws_if_event_name_is_empty()
  76. {
  77. var ex = Assert.Throws<ArgumentException>(() => resolver.AddEvent(typeof(UnnamedEvent2)));
  78. ex.Message.Should().Be("Type Ncqrs.Tests.Eventing.Storage.AttributeEventTypeResolverTests+UnnamedEvent2 does not have a name");
  79. }
  80. [Fact]
  81. public void Aliases_do_not_count_as_a_name()
  82. {
  83. var ex = Assert.Throws<ArgumentException>(() => resolver.AddEvent(typeof(UnnamedEvent3)));
  84. ex.Message.Should().Be("No name found for event Ncqrs.Tests.Eventing.Storage.AttributeEventTypeResolverTests+UnnamedEvent3, specify an EventNameAttribute.");
  85. }
  86. private class NotAnEvent {}
  87. private class UnnamedEvent1 : Event {}
  88. [EventName(" ")]
  89. private class UnnamedEvent2 : Event {}
  90. [EventNameAlias("bar")]
  91. private class UnnamedEvent3 : Event {}
  92. [EventName("foo")]
  93. private class FooEvent : Event {}
  94. [EventName("foo")]
  95. [EventNameAlias("bar")]
  96. private class AliasedFooEvent : Event {}
  97. [EventName("bar")]
  98. private class BarEvent : Event {}
  99. }
  100. }