public void Behaviour_should_also_work_with_method_calls() { var SUT = new YakShayBus(); SUT.RegisterType<SomeTestClass>(); var resultingMessages = new List<Message>(); var msg = new { SomePartOfTheUID = "A", AnotherPartOfTheUID = "B", SomeFlag = true, SomeString = "ABC" }; SUT.Handle( Message.FromAction(x => x.MethodToInvoke(SomePartOfTheUID: "A", AnotherPartOfTheUID: "B", SomeFlag: true, SomeString: "ABC")) , x => resultingMessages.Add(x)); resultingMessages.Count.ShouldBe(1); resultingMessages.First().ToFriendlyString().ShouldBe(new Message("OnMethodWasInvoked", new { SomePartOfTheUID = "A", AnotherPartOfTheUID = "B", SomeString = "ABC", AnotherInt = 123 }).ToFriendlyString()); }
public void Deposits_and_withdraws_should_not_interfere_with_each_other() { var SUT = new YakShayBus(); // register all types under test SUT.RegisterType<Account>(); SUT.RegisterType<AccountTransferSaga>(); SUT.RegisterType<AccountBalances>(); var ms = new MessageStore(); SUT.HandleUntilAllConsumed(Message.FromAction(x => x.RegisterAccount(AccountId: "account/1", OwnerName: "Tom")), ms.Add, ms.Filter); SUT.HandleUntilAllConsumed(Message.FromAction(x => x.RegisterAccount(AccountId: "account/2", OwnerName: "Ben")), ms.Add, ms.Filter); SUT.HandleUntilAllConsumed(Message.FromAction(x => x.DepositAmount(AccountId: "account/1", Amount: 126m)), ms.Add, ms.Filter); SUT.HandleUntilAllConsumed(Message.FromAction(x => x.DepositAmount(AccountId: "account/2", Amount: 10m)), ms.Add, ms.Filter); SUT.HandleUntilAllConsumed(Message.FromAction(x => x.Transfer(AccountId: "account/1", TargetAccountId: "account/2", Amount: 26m)), ms.Add, ms.Filter); SUT.HandleUntilAllConsumed(Message.FromAction(x => x.WithdrawAmount(AccountId: "account/2", Amount: 10m)), ms.Add, ms.Filter); var bal = new AccountBalances(); SUT.ApplyHistory(bal, ms.Filter); bal.Balances.Count.ShouldBe(2); bal.Balances["account/1"].ShouldBe(100m); bal.Balances["account/2"].ShouldBe(26m); }
public void Invoking_a_message_that_does_not_have_the_unique_ids_should_not_generate_events() { var SUT = new YakShayBus(); SUT.RegisterType<SomeTestClass>(); var resultingMessages = new List<Message>(); var msg = new Message("MethodToInvoke", new { NotPartOfTheKey = "A", AnotherPartOfTheUID = "B", SomeFlag = true, SomeString = "ABC" }); SUT.Handle(msg, x => resultingMessages.Add(x)); resultingMessages.ShouldBeEmpty(); }
public void Message_should_get_processed_and_generate_a_single_InterceptThis_message_with_the_correct_parameters() { var SUT = new YakShayBus(); SUT.RegisterType<SomeTestClass>(); var ms = new MessageStore(); var msg = new Message("MethodToInvoke", new { SomePartOfTheUID = "A", AnotherPartOfTheUID = "B", SomeFlag = true, SomeString = "ABC" }); SUT.Handle(msg, ms.Add); ms.msgs.Count.ShouldBe(1); ms.msgs.First().ToFriendlyString().ShouldBe(new Message("OnMethodWasInvoked", new { SomePartOfTheUID = "A", AnotherPartOfTheUID = "B", SomeString = "ABC", AnotherInt = 123 }).ToFriendlyString()); var ArInstance = new SomeTestClass { SomePartOfTheUID = "A", AnotherPartOfTheUID = "B" }; var AnotherArInstance = new SomeTestClass { SomePartOfTheUID = "X", AnotherPartOfTheUID = "Y" }; SUT.ApplyHistory(ArInstance, ms.Filter); SUT.ApplyHistory(AnotherArInstance, ms.Filter); ArInstance.HasMethodBeenCalled.ShouldBe(true); AnotherArInstance.HasMethodBeenCalled.ShouldBe(false); }