예제 #1
0
        public void OrderMustBeValidBeforeItCanBeSent_with_mock_example()
        {
            var repository   = Substitute.For <IOrderRepository>();
            var exampleOrder = new Order();
            var fakeOrderId  = new OrderId();

            repository.Add(Arg.Any <Order>()).Returns(fakeOrderId);
            repository.Get(fakeOrderId).Returns(exampleOrder);

            var client = new PizzaClient(new TestFactory(), repository);

            var menu = client.GetMenu();

            var orderId = client.StartOrder();

            client.AddToOrder("Arek", orderId, new ClientOrderPosition(menu.Position(1), 2));
            client.AddToOrder("Marek", orderId, new ClientOrderPosition(menu.Position(2), 4));

            Assert.False(client.Validate(orderId));
            client.AddToOrder("Jarek", orderId, new ClientOrderPosition(menu.Position(1), 2));
            Assert.True(client.Validate(orderId));
            client.Send(orderId);

            // gdzie dotarło zamówienie?
            // czy się zapisało?

            repository.Received(1).Add(Arg.Is <Order>(x => x.Positions.Count() == 0));
        }
예제 #2
0
        public void OrderMustBeValidBeforeItCanBeSent_with_in_memmory_example()
        {
            var exampleMenu = new TestFactory();
            var repository  = new InMemmoryOrderRepository();

            var client = new PizzaClient(exampleMenu, repository);

            var menu = client.GetMenu();

            var orderId = client.StartOrder();

            client.AddToOrder("Arek", orderId, new ClientOrderPosition(menu.Position(1), 2));
            client.AddToOrder("Marek", orderId, new ClientOrderPosition(menu.Position(2), 4));

            Assert.False(client.Validate(orderId));
            client.AddToOrder("Jarek", orderId, new ClientOrderPosition(menu.Position(1), 2));
            Assert.True(client.Validate(orderId));
            client.Send(orderId);

            // gdzie dotarło zamówienie?
            // czy się zapisało?
        }