コード例 #1
0
        public void Should_Create_Instance_Of_Order_With_Delivery()
        {
            // Arrange
            _mockEventPublisher.Setup(x => x.Publish(It.IsAny <IDomainEvent>())).Callback(() =>
            {
                new OrderNeedsDelivery(It.IsAny <Order>());
            });

            // Act
            var pizza  = new Pizza(PizzaMocks.ToppingMocks().ToList(), PizzaMocks.SizeMocks().First(), PizzaMocks.BreadMocks().ElementAt(1), PizzaMocks.GetSauces().ElementAt(1), PizzaMocks.GetCheese().ElementAt(2));
            var pizzas = new List <Pizza>()
            {
                pizza
            };
            var sut = new Order(ServiceType.Delivery, pizzas, "Jose");

            sut.ProcessOrder(sut, _mockEventPublisher.Object);

            // Assert
            _mockEventPublisher.VerifyAll();
            _mockEventPublisher.Verify(x => x.Publish(It.IsAny <IDomainEvent>()), Times.Once);
            Assert.IsInstanceOf <Order>(sut);
            Assert.Greater(sut.ServiceCharge, 0);
            Assert.Greater(sut.SubTotal, 0);
            Assert.AreEqual(sut.ServiceCharge + sut.SubTotal, sut.TotalAmount);
        }
コード例 #2
0
ファイル: PizzaUnitTests.cs プロジェクト: llenroc/DDDPizza
        public void Should_Create_Instance_Of_Pizza_Calculate_Total()
        {
            var sut = new Pizza(PizzaMocks.ToppingMocks().ToList(), PizzaMocks.SizeMocks().First(), PizzaMocks.BreadMocks().ElementAt(1), PizzaMocks.GetSauces().ElementAt(1), PizzaMocks.GetCheese().ElementAt(2));

            Assert.IsInstanceOf <Pizza>(sut);
            Assert.Greater(sut.Total, 0);
        }
コード例 #3
0
ファイル: PizzaUnitTests.cs プロジェクト: llenroc/DDDPizza
        public void Should_Create_Instance_Of_Order_With_TakeOut()
        {
            var pizza  = new Pizza(PizzaMocks.ToppingMocks().ToList(), PizzaMocks.SizeMocks().First(), PizzaMocks.BreadMocks().ElementAt(1), PizzaMocks.GetSauces().ElementAt(1), PizzaMocks.GetCheese().ElementAt(2));
            var pizzas = new List <Pizza>()
            {
                pizza
            };
            var sut = new Order(ServiceType.TakeOut, pizzas, "Jose");

            sut.ProcessOrder(sut, _mockEventPublisher.Object);

            _mockEventPublisher.VerifyAll();
            _mockEventPublisher.Verify(x => x.Publish(It.IsAny <IDomainEvent>()), Times.Never);
            Assert.IsInstanceOf <Order>(sut);
            Assert.AreEqual(sut.ServiceCharge, 0);
            Assert.Greater(sut.SubTotal, 0);
            Assert.AreEqual(sut.ServiceCharge + sut.SubTotal, sut.TotalAmount);
        }
コード例 #4
0
ファイル: PizzaUnitTests.cs プロジェクト: llenroc/DDDPizza
        public void Should_Create_Instance_Of_NotifyOrderNeedsDelivery()
        {
            //Arrange
            _mockMessageService.Setup(x => x.NotifyDelivery(It.IsAny <Order>())).Verifiable();
            var pizza  = new Pizza(PizzaMocks.ToppingMocks().ToList(), PizzaMocks.SizeMocks().First(), PizzaMocks.BreadMocks().ElementAt(1), PizzaMocks.GetSauces().ElementAt(1), PizzaMocks.GetCheese().ElementAt(2));
            var pizzas = new List <Pizza>()
            {
                pizza
            };
            var order = new Order(ServiceType.TakeOut, pizzas, "Jose");

            //Act
            var sut = new NotifyOrderNeedsDelivery(_mockMessageService.Object);

            sut.Handle(new OrderNeedsDelivery(order));

            //Assert
            _mockMessageService.VerifyAll();
            _mockMessageService.Verify(x => x.NotifyDelivery(It.IsAny <Order>()), Times.Once);
            Assert.Pass();
        }
コード例 #5
0
        public void Should_Create_Instance_Of_Pizza_Calculate_Total()
        {
            // Arrange

            var toppingsCost = PizzaMocks.ToppingMocks().Sum(x => x.Price);
            var sizeCost     = PizzaMocks.SizeMocks().First().Price;
            var expectedCost = toppingsCost + sizeCost;

            // Act
            var sut = new Pizza(
                PizzaMocks.ToppingMocks().ToList(),
                PizzaMocks.SizeMocks().First(),
                PizzaMocks.BreadMocks().ElementAt(1),
                PizzaMocks.GetSauces().ElementAt(1),
                PizzaMocks.GetCheese().ElementAt(2));

            // Assert
            Assert.IsInstanceOf <Pizza>(sut);
            Assert.Less(0, sut.Total);
            Assert.AreEqual(expectedCost, sut.Total);
        }