Ejemplo n.º 1
0
        public void ShouldNotPlaceOrderIfFailsToRemove()
        {
            // Arrange
            var catalog   = new Mock <ICatalogService>();
            var view      = new Mock <IProductsView>();
            var presenter = new ProductsPresenter(catalog.Object, view.Object);
            var order     = new Order
            {
                Product = new Product {
                    Id = 1
                },
                Quantity = 5
            };

            catalog
            .Setup(c => c.HasInventory(1, 5))
            .Returns(true);
            catalog
            .Setup(c => c.Remove(1, 5))
            .Throws <InvalidOperationException>();

            // Act
            presenter.PlaceOrder(order);

            // Assert
            Assert.IsFalse(order.Filled);
            catalog.Verify(c => c.HasInventory(1, 5));
            catalog.Verify(c => c.Remove(1, 5));
        }
Ejemplo n.º 2
0
        public void ShouldNotPlaceOrderIfNotEnoughInventory()
        {
            // Arrange
            var catalog   = new Mock <ICatalogService>();
            var view      = new Mock <IProductsView>();
            var presenter = new ProductsPresenter(catalog.Object, view.Object);
            var order     = new Order
            {
                Product = new Product {
                    Id = 1
                },
                Quantity = 5
            };

            catalog
            .Setup(c => c.HasInventory(1, 5))
            .Returns(false);

            // Act
            presenter.PlaceOrder(order);

            // Assert
            Assert.IsFalse(order.Filled);
            catalog.Verify(c => c.HasInventory(1, 5));
        }
Ejemplo n.º 3
0
        public void ShouldNotPlaceOrderIfFailsToRemove()
        {
            // Arrange
            var catalog = new Mock<ICatalogService>();
            var view = new Mock<IProductsView>();
            var presenter = new ProductsPresenter(catalog.Object, view.Object);
            var order = new Order
            {
                Product = new Product { Id = 1 },
                Quantity = 5
            };

            catalog
                .Setup(c => c.HasInventory(1, 5))
                .Returns(true);
            catalog
                .Setup(c => c.Remove(1, 5))
                .Throws<InvalidOperationException>();

            // Act
            presenter.PlaceOrder(order);

            // Assert
            Assert.IsFalse(order.Filled);
            catalog.Verify(c => c.HasInventory(1, 5));
            catalog.Verify(c => c.Remove(1, 5));
        }
Ejemplo n.º 4
0
		public void ShouldNotPlaceOrderIfNotEnoughInventory()
		{
			// Arrange
			var catalog = new Mock<ICatalogService>();
			var view = new Mock<IProductsView>();
			var presenter = new ProductsPresenter(catalog.Object, view.Object);
			var order = new Order
			{
				Product = new Product { Id = 1 },
				Quantity = 5
			};

			catalog
				.Setup(c => c.HasInventory(1, 5))
				.Returns(false);

			// Act
			presenter.PlaceOrder(order);

			// Assert
			Assert.IsFalse(order.Filled);
			catalog.Verify(c => c.HasInventory(1, 5));
		}