protected override void Given() { _hotelService = new HotelService(ObjectContextFake, RepositoryFake, null); A.CallTo(() => RepositoryFake.Get(null)).WithAnyArguments().Returns( new Hotel() { Id = 42, Name = "Test Beach Resort", Description = "Nice hotel on the beach", Image = "http://test.com/test.jpg", Facts = new Collection <Fact>() }); }
protected override void Given() { _hotelService = new HotelService(ObjectContextFake, RepositoryFake, null); _hotel = new Hotel() { Id = HotelId, Name = null, Description = null, Facts = new Collection <Fact>() }; A.CallTo(() => RepositoryFake.Get(null)).WithAnyArguments().Returns(_hotel); }
protected override void Given() { _hotelService = new HotelService(ObjectContextFake, RepositoryFake, null); _hotel = new Hotel() { Id = HotelId, Name = "Test Beach Hotel", Description = "A nice hotel situated right at Test Beach", Image = "http://test.com/test.jpg" }; A.CallTo(() => RepositoryFake.Get(null)).WithAnyArguments().Returns(_hotel); }
internal void Receive( AggregateCommandHandler <Customer> handler, RepositoryFake <Customer> repo, IContext context, Customer customer, ID customerID ) { GIVEN["a handler instance and a service provider"] = () => { handler = new AggregateCommandHandler <Customer>(); IServiceProvider sp = new ServiceProviderFake().Register <IRepository <Customer> >( repo = Substitute.ForPartsOf <RepositoryFake <Customer> >()); context = new GenericContext(); context.Set(sp, false); }; When["sending a create message to the aggregate"] = () => Send(customerID = ID.NewID(), new Customer.Create()); Then["the aggregate gets created"] = async() => customer = await repo.Get(customerID); AND["it receives the command"] = () => customer.Commands.Should().BeEmpty(); When["sending a non-create message to the aggregate"] = () => { repo.ClearReceivedCalls(); customer.Commands.Clear(); return(Send(customerID, new Customer.Promote())); }; Then["the aggregate is loaded and saved"] = async() => { await repo.Received().Get(customerID); await repo.Received().Save(customer); }; AND["it receives the command"] = () => customer.Commands.Should().ContainSingle(m => m is Customer.Promote); When["sending a message that does not belong to the aggregate"] = () => { repo.ClearReceivedCalls(); return(Send(customerID, new Order.Ship())); }; THEN["no action is performed"] = () => repo.ReceivedCalls().Should().BeEmpty(); Task Send(ID target, ICommandMessage message) { Maybe <Task> result = handler.Receive(new HandleCommand( new Command(message, target), context)); return(result is Some <Task> t ? (Task)t : Task.CompletedTask); } }
protected override void Given() { _hotelService = new HotelService(ObjectContextFake, RepositoryFake, null); A.CallTo(() => RepositoryFake.Get(null)).WithAnyArguments().Returns(null); }