Line data Source code
1 : using System;
2 : using Cqrs.Bus;
3 : using Cqrs.Authentication;
4 : using cdmdotnet.Logging;
5 : using cdmdotnet.Logging.Configuration;
6 : using cdmdotnet.StateManagement.Threaded;
7 : using Cqrs.Commands;
8 : using Cqrs.Configuration;
9 : using Cqrs.Tests.Substitutes;
10 : using NUnit.Framework;
11 :
12 : namespace Cqrs.Tests.Bus
13 : {
14 : [TestFixture]
15 : public class When_sending_command
16 0 : {
17 : private InProcessBus<ISingleSignOnToken> _bus;
18 :
19 : [SetUp]
20 0 : public void Setup()
21 : {
22 : _bus = new InProcessBus<ISingleSignOnToken>(new AuthenticationTokenHelper(new ThreadedContextItemCollectionFactory()), new NullCorrelationIdHelper(), new TestDependencyResolver(null), new ConsoleLogger(new LoggerSettingsConfigurationSection(), new NullCorrelationIdHelper()), new ConfigurationManager(), new BusHelper(new ConfigurationManager()));
23 : }
24 :
25 : [Test]
26 0 : public void Should_run_handler()
27 : {
28 : var handler = new TestAggregateDoSomethingHandler();
29 : _bus.RegisterHandler<TestAggregateDoSomething>(handler.Handle, handler.GetType());
30 : _bus.Send(new TestAggregateDoSomething());
31 :
32 : Assert.AreEqual(1,handler.TimesRun);
33 : }
34 :
35 : [Test]
36 0 : public void Should_throw_if_more_handlers()
37 : {
38 : var x = new TestAggregateDoSomethingHandler();
39 : _bus.RegisterHandler<TestAggregateDoSomething>(x.Handle, x.GetType());
40 : _bus.RegisterHandler<TestAggregateDoSomething>(x.Handle, x.GetType());
41 :
42 : Assert.Throws<MultipleCommandHandlersRegisteredException>(() => _bus.Send(new TestAggregateDoSomething()));
43 : }
44 :
45 : [Test]
46 0 : public void Should_throw_if_no_handlers()
47 : {
48 : Assert.Throws<NoCommandHandlerRegisteredException>(() => _bus.Send(new TestAggregateDoSomething2()));
49 : }
50 :
51 : [Test]
52 0 : public void Has_no_handles_should_not_throw_due_to_settings()
53 : {
54 : _bus.Send(new TestAggregateDoSomething3());
55 : }
56 : }
57 : }
|