public async Task CannotUnblockAccountAfterDepositCheque()
        {
            var accCreatedEv = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId,
                Name      = "Jake Sanders"
            };

            var accBlockedEv = new AccountBlocked(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId
            };

            var cmd = new DepositCheque()
            {
                AccountId = _accountId,
                Amount    = 1000
            };

            var amountSetEv = new ChequeDeposited(CorrelatedMessage.NewRoot())
            {
                AccountId = cmd.AccountId,
                Amount    = cmd.Amount
            };

            await _runner.Run(
                def => def
                .Given(accCreatedEv, accBlockedEv)
                .When(cmd)
                .Then(amountSetEv));
        }
        public async Task CanDepositCash()
        {
            Clock.SetCurrent(new LocalDateTime(2018, 1, 1, 9, 0));

            var created = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId         = AccountId,
                AccountHolderName = "NNN"
            };

            var cmd = new DepositCash
            {
                AccountId = AccountId,
                Amount    = 350
            };

            var ev = new CashDeposited(cmd)
            {
                AccountId   = AccountId,
                Amount      = cmd.Amount,
                DepositedAt = Clock.Current
            };

            await Runner.Run(
                def => def.Given(created).When(cmd).Then(ev)
                );
        }
        public when_using_listener_start_with_custom_stream_synched(StreamStoreConnectionFixture fixture)
        {
            var conn = fixture.Connection;

            conn.Connect();

            // Build an origin stream from strings to which the the events are appended
            var originStreamName = $"testStream-{Guid.NewGuid():N}";


            var result = fixture.Connection.AppendToStream(
                originStreamName,
                ExpectedVersion.NoStream,
                null,
                _eventSerializer.Serialize(new TestEvent(CorrelatedMessage.NewRoot())));

            Assert.True(result.NextExpectedVersion == 0);

            // Wait for the stream to be written
            CommonHelpers.WaitForStream(conn, originStreamName);

            StreamListener listener = new SynchronizableStreamListener(
                originStreamName,
                fixture.Connection,
                new PrefixedCamelCaseStreamNameBuilder(),
                _eventSerializer,
                true);

            listener.EventStream.Subscribe(new AdHocHandler <Event>(Handle));
            listener.Start(originStreamName);
        }
Exemple #4
0
        public void can_serialize_json_success_commandresponse()
        {
            var cmd      = new TestCommands.TypedResponse(false, CorrelatedMessage.NewRoot());
            var nearSide = cmd.Succeed(15);

            TestCommands.TestResponse farSide;


            StringBuilder sb = new StringBuilder();
            StringWriter  sw = new StringWriter(sb);

            using (var writer = new JsonTextWriter(sw))
            {
                var serializer = JsonSerializer.Create(Json.JsonSettings);
                serializer.Serialize(writer, nearSide);
            }

            using (var reader = new JsonTextReader(new StringReader(sb.ToString())))
            {
                var serializer = JsonSerializer.Create(Json.JsonSettings);
                serializer.SerializationBinder = new TestDeserializer();
                serializer.ContractResolver    = new TestContractResolver();
                farSide = serializer.Deserialize <TestCommands.TestResponse>(reader);
            }

            Assert.Equal(nearSide.MsgId, farSide.MsgId);
            Assert.Equal(nearSide.GetType(), farSide.GetType());
            Assert.Equal(nearSide.CorrelationId, farSide.CorrelationId);
            Assert.Equal(nearSide.CommandType, farSide.CommandType);
            Assert.Equal(nearSide.CommandId, farSide.CommandId);
            Assert.Equal(nearSide.SourceId, farSide.SourceId);

            Assert.Equal(nearSide.Data, farSide.Data);
        }
Exemple #5
0
        public async Task CanWithdrawCash(decimal deposit, decimal withdraw)
        {
            var accCreatedEv = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId,
                Name      = "Jake Sanders"
            };

            var depositedEv = new CashDeposited(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId,
                Amount    = deposit
            };

            var cmd = new WithdrawCash()
            {
                AccountId = _accountId,
                Amount    = withdraw
            };

            var withdrawnEv = new CashWithdrawn(cmd)
            {
                AccountId = _accountId,
                Amount    = cmd.Amount
            };

            await _runner.Run(
                def => def
                .Given(accCreatedEv, depositedEv)
                .When(cmd)
                .Then(withdrawnEv));
        }
Exemple #6
0
        public async Task CannotWithdrawCashIfNotEnoughFunds()
        {
            var deposit  = 500m;
            var withdraw = 1000m;

            var accCreatedEv = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId,
                Name      = "Jake Sanders"
            };

            var depositSetEv = new CashDeposited(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId,
                Amount    = deposit
            };

            var cmd = new WithdrawCash()
            {
                AccountId = _accountId,
                Amount    = withdraw
            };

            await _runner.Run(
                def => def
                .Given(accCreatedEv, depositSetEv)
                .When(cmd)
                .Throws(new SystemException("The account does not have enough funds for requested wire transfer.")));
        }
        public when_using_listener_start_with_category_aggregate(StreamStoreConnectionFixture fixture)
        {
            var streamNameBuilder = new PrefixedCamelCaseStreamNameBuilder();
            var conn = fixture.Connection;

            conn.Connect();

            var aggStream      = streamNameBuilder.GenerateForAggregate(typeof(AggregateCategoryTestAggregate), Guid.NewGuid());
            var categoryStream = streamNameBuilder.GenerateForCategory(typeof(AggregateCategoryTestAggregate));

            // Drop an event into the stream testAggregate-guid
            var result = conn.AppendToStream(
                aggStream,
                ExpectedVersion.NoStream,
                null,
                _eventSerializer.Serialize(new TestEvent(CorrelatedMessage.NewRoot())));

            Assert.True(result.NextExpectedVersion == 0);

            //wait for the projection to be written.
            CommonHelpers.WaitForStream(conn, categoryStream);

            // Now set up the projection listener, and start it.
            var listener = new SynchronizableStreamListener(
                "category listener",
                conn,
                streamNameBuilder,
                new JsonMessageSerializer());

            listener.EventStream.Subscribe <TestEvent>(new AdHocHandler <TestEvent>(Handle));
            listener.Start <AggregateCategoryTestAggregate>();
        }
        public when_logging_disabled_and_commands_are_fired(StreamStoreConnectionFixture fixture) : base(fixture.Connection)
        {
            // command must have a commandHandler
            _cmdHandler = new TestCommandSubscriber(Bus);

            _multiFireCount   = 0;
            _testCommandCount = 0;

            _listener = new SynchronizableStreamListener(
                Logging.FullStreamName,
                Connection,
                StreamNameBuilder,
                EventSerializer);
            _listener.EventStream.Subscribe <Message>(this);

            _listener.Start(Logging.FullStreamName);
            CorrelatedMessage source = CorrelatedMessage.NewRoot();

            // create and fire a set of commands
            for (int i = 0; i < _maxCountedCommands; i++)
            {
                // this is just an example command - choice to fire this one was random
                var cmd = new TestCommands.Command2(source);
                Bus.Send(cmd,
                         $"exception message{i}",
                         TimeSpan.FromSeconds(2));
                source = cmd;
            }
            var tstCmd = new TestCommands.Command3(source);

            Bus.Send(tstCmd,
                     "Test Command exception message",
                     TimeSpan.FromSeconds(1));
        }
        public async Task CanUnblockAccountOnNextBusinessDay()
        {
            var accCreatedEv = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId,
                Name      = "Jake Sanders"
            };

            var accBlockedEv = new AccountBlocked(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId
            };

            var depositedEv = new ChequeDeposited(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId,
                Amount    = 1000m
            };

            var cmd = new StartNewBusinessDay()
            {
                AccountId = _accountId
            };

            var accUnblockedEv = new AccountUnblocked(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId
            };

            await _runner.Run(
                def => def
                .Given(accCreatedEv, accBlockedEv, depositedEv)
                .When(cmd)
                .Then(accUnblockedEv));
        }
Exemple #10
0
        public when_commands_are_fired(StreamStoreConnectionFixture fixture) : base(fixture.Connection)
        {
            Bus.Subscribe(new AdHocCommandHandler <TestCommands.Command2>(_ => true));
            Bus.Subscribe(new AdHocCommandHandler <TestCommands.Command3>(_ => true));
            Bus.Subscribe <Message>(this);

            _multiFireCount   = 0;
            _testCommandCount = 0;


            CorrelatedMessage source = CorrelatedMessage.NewRoot();

            // create and fire a set of commands
            for (int i = 0; i < MaxCountedCommands; i++)
            {
                // this is just an example command - choice to fire this one was random
                var cmd = new TestCommands.Command2(source);
                Bus.Send(cmd,
                         $"exception message{i}",
                         TimeSpan.FromSeconds(2));
                source = cmd;
            }


            Bus.Send(new TestCommands.Command3(source),
                     "Test Command exception message",
                     TimeSpan.FromSeconds(1));

            Assert.IsOrBecomesTrue(() => _testCommandCount == 1, 1000, "Set Setup failed: Timed out waiting for last cmd");
            Assert.IsOrBecomesTrue(() => _multiFireCount == MaxCountedCommands, 9000, "Didn't get all commands");
        }
Exemple #11
0
        public async Task CannotWireTransferIfNotEnoughFunds(
            decimal deposit, decimal transfer)
        {
            var accCreatedEv = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId,
                Name      = "Jake Sanders"
            };

            var cashDepositedEv = new CashDeposited(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId,
                Amount    = deposit
            };

            var cmd = new TryWireTransfer()
            {
                AccountId = _accountId,
                Amount    = transfer
            };

            await _runner.Run(
                def => def
                .Given(accCreatedEv, cashDepositedEv)
                .When(cmd)
                .Throws(new SystemException("The account does not have enough funds for requested wire transfer.")));
        }
        public async Task CanLimitOverdraft()
        {
            var created = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId         = AccountId,
                AccountHolderName = "Miled",
                OverdraftLimit    = 0
            };

            var cmd = new LimitOverdraft
            {
                AccountId = AccountId,
                Limit     = 350
            };

            var ev = new OverdraftLimited(cmd)
            {
                AccountId = AccountId,
                Limit     = 350
            };

            await Runner.Run(
                def => def.Given(created).When(cmd).Then(ev)
                );
        }
Exemple #13
0
 public void can_resubscribe_handler()
 {
     lock (_fixture) {
         AssertEx.IsOrBecomesTrue(() => _fixture.Bus.Idle);
         _fixture.ClearCounters();
         //no subscription
         Assert.False(_fixture.Bus.HasSubscriberFor <TestCommands.Command3>());
         //Add subscription
         var subscription = _fixture.Bus.Subscribe <TestCommands.Command3>(_fixture);
         Assert.True(_fixture.Bus.HasSubscriberFor <TestCommands.Command3>());
         _fixture.Bus.Send(new TestCommands.Command3(CorrelatedMessage.NewRoot()));
         AssertEx.IsOrBecomesTrue(
             () => Interlocked.Read(ref _fixture.GotTestCommand3) == 1,
             msg: "Expected command handled once, got" + Interlocked.Read(ref _fixture.GotTestCommand3));
         //dispose subscription to unsubscribe
         subscription.Dispose();
         Assert.False(_fixture.Bus.HasSubscriberFor <TestCommands.Command3>());
         Assert.Throws <CommandNotHandledException>(() =>
                                                    _fixture.Bus.Send(new TestCommands.Command3(CorrelatedMessage.NewRoot())));
         //resubscribe
         subscription = _fixture.Bus.Subscribe <TestCommands.Command3>(_fixture);
         Assert.True(_fixture.Bus.HasSubscriberFor <TestCommands.Command3>());
         _fixture.Bus.Send(new TestCommands.Command3(CorrelatedMessage.NewRoot()));
         AssertEx.IsOrBecomesTrue(
             () => Interlocked.Read(ref _fixture.GotTestCommand3) == 2,
             msg: "Expected command handled twice, got" + Interlocked.Read(ref _fixture.GotTestCommand3));
         //cleanup
         subscription.Dispose();
     }
 }
Exemple #14
0
        public async Task CanSetDailyTransfertLimit()
        {
            var created = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId         = AccountId,
                AccountHolderName = "Miled",
                OverdraftLimit    = 0
            };

            var cmd = new SetDailyWireTransfertLimit
            {
                AccountId = AccountId,
                Limit     = 350
            };

            var ev = new DailyWireTransfertLimitSet(cmd)
            {
                AccountId = AccountId,
                Limit     = 350
            };

            await Runner.Run(
                def => def.Given(created).When(cmd).Then(ev)
                );
        }
Exemple #15
0
        public void can_retrieve_correlated_aggregate()
        {
            var command1 = CorrelatedMessage.NewRoot();
            var id       = Guid.NewGuid();
            var agg      = new CorrelatedAggregate(id, command1);

            agg.RaiseCorrelatedEvent();
            agg.RaiseCorrelatedEvent();
            _repo.Save(agg);

            var command2  = CorrelatedMessage.NewRoot();
            var recovered = _repo.GetById <CorrelatedAggregate>(id, command2);

            Assert.NotNull(recovered);
            Assert.Equal(2, recovered.Version);//zero based, includes created

            recovered.RaiseCorrelatedEvent();
            recovered.RaiseCorrelatedEvent();

            _repo.Save(recovered);
            var command3   = CorrelatedMessage.NewRoot();
            var recovered2 = _repo.GetById <CorrelatedAggregate>(id, command3);

            Assert.NotNull(recovered2);
            Assert.Equal(4, recovered2.Version);
        }
Exemple #16
0
        public when_events_are_published(StreamStoreConnectionFixture fixture) : base(fixture.Connection)
        {
            _listener = new SynchronizableStreamListener(
                Logging.FullStreamName,
                Connection,
                StreamNameBuilder,
                EventSerializer);
            _listener.EventStream.Subscribe <Event>(this);

            _listener.Start(Logging.FullStreamName);

            _countedEventCount    = 0;
            _testDomainEventCount = 0;
            CorrelatedMessage source = CorrelatedMessage.NewRoot();

            // create and publish a set of events
            for (int i = 0; i < _maxCountedEvents; i++)
            {
                var evt = new CountedEvent(i, source);
                Bus.Publish(evt);
                source = evt;
            }

            Bus.Subscribe(new AdHocHandler <TestEvent>(_ => Interlocked.Increment(ref _gotEvt)));
            Bus.Publish(new TestEvent(source));
        }
        public void TestNoSubscriber()
        {
            var testEvent = new TestEvent(CorrelatedMessage.NewRoot());

            _bus.Publish(testEvent);
            AssertEx.IsOrBecomesTrue(() => _testEventCount == 0, msg: $"Expected 0 got {_testEventCount}");
        }
        public void TestParentTestMessage()
        {
            // When subscribing to ParentTest Event the appropriate handler will be invoked when
            //  child (descendant) message types are published.
            _bus.Subscribe <ParentTestEvent>(this);
            var parentTestEvent = new ParentTestEvent(CorrelatedMessage.NewRoot());

            _bus.Publish(parentTestEvent);
            AssertEx.IsOrBecomesTrue(() => _testEventCount == 0, msg: $"Expected 0 got {_testEventCount}");
            AssertEx.IsOrBecomesTrue(() => _parentTestEventCount == 1, msg: $"Expected 1 got {_parentTestEventCount}");
            AssertEx.IsOrBecomesTrue(() => _childTestEventCount == 0, msg: $"Expected 0 got {_childTestEventCount}");
            AssertEx.IsOrBecomesTrue(() => _grandChildTestEventCount == 0, msg: $"Expected 0 got {_grandChildTestEventCount}");

            _bus.Subscribe <ChildTestEvent>(this);
            var childTestEvent = new ChildTestEvent(parentTestEvent);

            _bus.Publish(childTestEvent);
            AssertEx.IsOrBecomesTrue(() => _testEventCount == 0, msg: $"Expected 0 got {_testEventCount}");
            AssertEx.IsOrBecomesTrue(() => _parentTestEventCount == 2, msg: $"Expected 2 got {_parentTestEventCount}");
            AssertEx.IsOrBecomesTrue(() => _childTestEventCount == 1, msg: $"Expected 1 got {_childTestEventCount}");
            AssertEx.IsOrBecomesTrue(() => _grandChildTestEventCount == 0, msg: $"Expected 0 got {_grandChildTestEventCount}");

            _bus.Subscribe <GrandChildTestEvent>(this);
            var grandChildTestEvent = new GrandChildTestEvent(childTestEvent);

            _bus.Publish(grandChildTestEvent);
            AssertEx.IsOrBecomesTrue(() => _testEventCount == 0, msg: $"Expected 0 got {_testEventCount}");
            AssertEx.IsOrBecomesTrue(() => _parentTestEventCount == 3, msg: $"Expected 3 got {_parentTestEventCount}");
            AssertEx.IsOrBecomesTrue(() => _childTestEventCount == 2, msg: $"Expected 2 got {_childTestEventCount}");
            AssertEx.IsOrBecomesTrue(() => _grandChildTestEventCount == 1, msg: $"Expected 1 got {_grandChildTestEventCount}");
        }
Exemple #19
0
        public when_using_listener_start_with_aggregate_and_guid(StreamStoreConnectionFixture fixture)
        {
            var conn = fixture.Connection;

            conn.Connect();

            // Build an origin stream to which the the events are appended. We are testing this stream directly
            var originalStreamGuid = Guid.NewGuid();
            var originStreamName   = _streamNameBuilder.GenerateForAggregate(typeof(AggregateIdTestAggregate), originalStreamGuid);


            // Drop an event into the stream testAggregate-guid
            var result = conn.AppendToStream(
                originStreamName,
                ExpectedVersion.NoStream,
                null,
                _eventSerializer.Serialize(new TestEvent(CorrelatedMessage.NewRoot())));

            Assert.True(result.NextExpectedVersion == 0);

            // Wait for the stream to be written
            CommonHelpers.WaitForStream(conn, originStreamName);

            StreamListener listener = new SynchronizableStreamListener(
                "guidStream",
                conn,
                _streamNameBuilder,
                _eventSerializer);

            listener.EventStream.Subscribe(new AdHocHandler <Event>(Handle));

            // This will start listening on the TestAggregate-guid stream.
            listener.Start <AggregateIdTestAggregate>(originalStreamGuid);
        }
Exemple #20
0
        public async Task CanDepositCashInToValidAccount()
        {
            decimal  depositeAmount = 5000;
            DateTime depositeDate   = System.DateTime.Now;
            var      accountCreated = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId         = _accountId,
                AccountHolderName = "Tushar"
            };
            var cmd = new DepositCash
            {
                AccountId     = _accountId,
                DepositAmount = depositeAmount
            };

            var ev = new CashDeposited(cmd)
            {
                AccountId     = _accountId,
                DepositAmount = depositeAmount
            };

            await _runner.Run(
                def => def.Given(accountCreated).When(cmd).Then(ev)
                );
        }
Exemple #21
0
        public async Task CashWithdrawalGreaterThanAllowedLimit()
        {
            decimal withdrawAmount = 10000;
            decimal depositeAmount = 5000;

            var accountCreated = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId         = _accountId,
                AccountHolderName = "Tushar"
            };

            var evtCashDeposited = new CashDeposited(CorrelatedMessage.NewRoot())
            {
                AccountId     = _accountId,
                DepositAmount = depositeAmount
            };

            var cmdWithdrawCash = new WithdrawCash()
            {
                AccountId      = _accountId,
                WithdrawAmount = withdrawAmount
            };

            var evAccountBlocked = new AccountBlocked(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId,
                Amount    = withdrawAmount
            };

            await _runner.Run(
                def => def.Given(accountCreated, evtCashDeposited).When(cmdWithdrawCash).Then(evAccountBlocked)
                );
        }
Exemple #22
0
        public async Task CannotWithdrawFundsIfTransferIsNotPositive(decimal transfer)
        {
            var deposit = 5000m;
            var limit   = 5000m;

            var accCreatedEv = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId,
                Name      = "Jake Sanders"
            };

            var cashDepositedEv = new CashDeposited(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId,
                Amount    = deposit
            };

            var limitSetEv = new DailyWireTransferLimitSet(CorrelatedMessage.NewRoot())
            {
                AccountId  = _accountId,
                DailyLimit = limit
            };

            var cmd = new TryWireTransfer()
            {
                AccountId = _accountId,
                Amount    = transfer
            };

            await _runner.Run(
                def => def
                .Given(accCreatedEv, cashDepositedEv, limitSetEv)
                .When(cmd)
                .Throws(new SystemException("Wire Transfer amount should be greater than 0.")));
        }
Exemple #23
0
        public void unsubscribe_should_not_remove_other_handlers()
        {
            lock (_fixture) {
                AssertEx.IsOrBecomesTrue(() => _fixture.Bus.Idle);
                _fixture.ClearCounters();

                Interlocked.Exchange(ref _fixture.GotTestCommand3, 0);
                //no subscription
                Assert.False(_fixture.Bus.HasSubscriberFor <TestCommands.Command3>());
                //Add subscription
                var subscription = _fixture.Bus.Subscribe <TestCommands.Command3>(_fixture);
                Assert.True(_fixture.Bus.HasSubscriberFor <TestCommands.Command3>());
                _fixture.Bus.Send(new TestCommands.Command3(CorrelatedMessage.NewRoot()));
                AssertEx.IsOrBecomesTrue(
                    () => Interlocked.Read(ref _fixture.GotTestCommand3) == 1,
                    msg: "Expected command handled once, got" + Interlocked.Read(ref _fixture.GotTestCommand3));
                //dispose subscription to unsubscribe
                subscription.Dispose();
                Assert.False(_fixture.Bus.HasSubscriberFor <TestCommands.Command3>());
                Assert.Throws <CommandNotHandledException>(() =>
                                                           _fixture.Bus.Send(new TestCommands.Command3(CorrelatedMessage.NewRoot())));

                Assert.True(_fixture.Bus.HasSubscriberFor <TestCommands.Command1>());
                Assert.True(_fixture.Bus.HasSubscriberFor <TestCommands.Command2>());
                Assert.True(_fixture.Bus.HasSubscriberFor <TestCommands.Fail>());
                Assert.True(_fixture.Bus.HasSubscriberFor <TestCommands.Throw>());
                Assert.True(_fixture.Bus.HasSubscriberFor <TestCommands.WrapException>());
                Assert.True(_fixture.Bus.HasSubscriberFor <TestCommands.TypedResponse>());
                Assert.True(_fixture.Bus.HasSubscriberFor <TestCommands.ChainedCaller>());
                Assert.True(_fixture.Bus.HasSubscriberFor <TestCommands.LongRunning>());
            }
        }
Exemple #24
0
        private void CreateAccount(Guid id)
        {
            var cmd = new DomainMsg.CreateAccount(id, CorrelatedMessage.NewRoot());

            _fixture.MainBus.Send(cmd, "Failed to create a new Account");

            log.Trace($"Account {id} created");
        }
Exemple #25
0
        public void commands_logged_only_while_logging_is_enabled()
        {
            Assert.False(Logging.Enabled);

            _multiFireCount = 0;
            CorrelatedMessage source = CorrelatedMessage.NewRoot();

            for (int i = 0; i < _maxCountedMessages; i++)
            {
                var cmd = new TestCommands.Command2(source);
                Bus.Send(cmd,
                         $"exception message{i}",
                         TimeSpan.FromSeconds(2));
                source = cmd;
            }

            Assert.Throws <TrueException>(() => Assert.IsOrBecomesTrue(
                                              () => _multiFireCount > 0,
                                              1000,
                                              $"Found {_multiFireCount} of first set of commands on disabled log. Should be 0"));


            _multiFireCount = 0;
            Logging.Enabled = true;

            // create and fire a mixed set of commands and events
            for (int i = 0; i < _maxCountedMessages; i++)
            {
                var cmd = new TestCommands.Command2(source);
                Bus.Send(cmd,
                         $"exception message{i}",
                         TimeSpan.FromSeconds(2));
                source = cmd;
            }

            Assert.IsOrBecomesTrue(
                () => _multiFireCount == _maxCountedMessages,
                1000,
                $"Second set of Commands count {_multiFireCount} not properly logged. Expected {_maxCountedMessages}");


            Logging.Enabled = false;
            _multiFireCount = 0;

            for (int i = 0; i < _maxCountedMessages; i++)
            {
                var cmd = new TestCommands.Command2(source);
                Bus.Send(cmd,
                         $"exception message{i}",
                         TimeSpan.FromSeconds(2));
                source = cmd;
            }

            Assert.Throws <TrueException>(() => Assert.IsOrBecomesTrue(
                                              () => _multiFireCount > 0,
                                              1000,
                                              $"Found {_multiFireCount} of third set of commands on disabled log. Should be 0"));
        }
 public void TestPublishSimpleMessage()
 {
     _bus.Subscribe <TestEvent>(this);
     _bus.Publish(new TestEvent(CorrelatedMessage.NewRoot()));
     AssertEx.IsOrBecomesTrue(() => _testEventCount == 1, msg: $"Expected 1 got {_testEventCount}");
     AssertEx.IsOrBecomesTrue(() => _parentTestEventCount == 0, msg: $"Expected 0 got {_parentTestEventCount}");
     AssertEx.IsOrBecomesTrue(() => _childTestEventCount == 0, msg: $"Expected 0 got {_childTestEventCount}");
     AssertEx.IsOrBecomesTrue(() => _grandChildTestEventCount == 0, msg: $"Expected 0 got {_grandChildTestEventCount}");
 }
Exemple #27
0
 public void fire_publishes_command_as_message()
 {
     lock (_fixture) {
         AssertEx.IsOrBecomesTrue(() => _fixture.Bus.Idle);
         _fixture.ClearCounters();
         _fixture.Bus.Send(new TestCommands.Command1(CorrelatedMessage.NewRoot()));
         SpinWait.SpinUntil(() => Interlocked.Read(ref _fixture.GotTestCommand1) == 1, 250);
     }
 }
 public void cancel_will_cancel_nested_commands()
 {
     TokenSource = new CancellationTokenSource();
     AssertEx.CommandThrows <CommandCanceledException>(() => {
         _bus.Send(
             new TestTokenCancellableCmd(false, CorrelatedMessage.NewRoot(), TokenSource.Token));
     });
     Assert.True(Interlocked.Read(ref _gotCmd) == 1, "Failed to receive first cmd");
     Assert.True(Interlocked.Read(ref _gotNestedCmd) == 1, "Nested Command received");
 }
Exemple #29
0
 public void command_handler_acks_command_message()
 {
     lock (_fixture) {
         AssertEx.IsOrBecomesTrue(() => _fixture.Bus.Idle);
         _fixture.ClearCounters();
         _fixture.Bus.Send(new TestCommands.AckedCommand(CorrelatedMessage.NewRoot()));
         AssertEx.IsOrBecomesTrue(() => Interlocked.Read(ref _fixture.GotAckedCommand) == 1);
         AssertEx.IsOrBecomesTrue(() => Interlocked.Read(ref _fixture.GotAck) == 1);
     }
 }
        public void can_cancel_while_processing()
        {
            _bus.Subscribe <TestTokenCancellableLongRunningCmd>(this);
            _tokenSource = new CancellationTokenSource();
            var cmd = new TestTokenCancellableLongRunningCmd(false, CorrelatedMessage.NewRoot(), _tokenSource.Token);

            _bus.TrySendAsync(cmd);
            AssertEx.IsOrBecomesTrue(() => Interlocked.Read(ref _gotCmd) == 1, msg: "Command not handled");
            AssertEx.IsOrBecomesTrue(() => Interlocked.Read(ref _canceled) == 1, msg: "Command not canceled");
        }