PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/Extensions/src/Ncqrs.NServiceBus.Tests/NsbCommandServiceTests.cs

http://github.com/ncqrs/ncqrs
C# | 67 lines | 58 code | 9 blank | 0 comment | 0 complexity | 95405ce0c42987a4bd2f130f9e128b1c MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, Apache-2.0
  1. using System;
  2. using FluentAssertions;
  3. using Ncqrs.Commanding;
  4. using Ncqrs.Commanding.CommandExecution;
  5. using Ncqrs.Commanding.CommandExecution.Mapping.Attributes;
  6. using Ncqrs.Domain;
  7. using NUnit.Framework;
  8. using Rhino.Mocks;
  9. namespace Ncqrs.NServiceBus.Tests
  10. {
  11. [TestFixture]
  12. public class NsbCommandServiceTests
  13. {
  14. [Test]
  15. public void Executing_not_mapped_command_with_no_registered_executors_should_cause_exception()
  16. {
  17. var sut = new NsbCommandService();
  18. Action act = () => sut.Execute(new NotMappedCommand());
  19. act.ShouldThrow<ExecutorForCommandNotFoundException>();
  20. }
  21. [Test]
  22. public void Mapped_command_with_no_registered_executors_should_be_executed_using_mapped_executor()
  23. {
  24. var sut = new NsbCommandService();
  25. sut.Execute(new MappedCommand());
  26. }
  27. [Test]
  28. public void Mapped_command_with_registered_executors_should_be_executed_using_registered_executor()
  29. {
  30. var executor = MockRepository.GenerateMock<ICommandExecutor<MappedCommand>>();
  31. var sut = new NsbCommandService();
  32. sut.RegisterExecutor(executor);
  33. var command = new MappedCommand();
  34. sut.Execute(command);
  35. executor.AssertWasCalled(x => x.Execute(command));
  36. }
  37. [Test]
  38. public void Not_mapped_command_with_registered_executors_should_be_executed_using_registered_executor()
  39. {
  40. var executor = MockRepository.GenerateMock<ICommandExecutor<NotMappedCommand>>();
  41. var sut = new NsbCommandService();
  42. sut.RegisterExecutor(executor);
  43. var command = new NotMappedCommand();
  44. sut.Execute(command);
  45. executor.AssertWasCalled(x => x.Execute(command));
  46. }
  47. public class NotMappedCommand : CommandBase
  48. {
  49. }
  50. [MapsToAggregateRootConstructor("Ncqrs.NServiceBus.Tests.NsbCommandServiceTests+TestAgggregateRoot, Ncqrs.NServiceBus.Tests")]
  51. public class MappedCommand : CommandBase
  52. {
  53. }
  54. public class TestAgggregateRoot : AggregateRoot
  55. {
  56. }
  57. }
  58. }