コード例 #1
0
        public void Add_Product_Should_Add_Correctly()
        {
            // Act
            this.productStock.Add(firstProduct);
            var result = productStock.FindByLabel(PRODUCT_LABEL);

            // Assert
            Assert.That(this.productStock.Count, Is.Not.Null);
            Assert.That(result.Label, Is.EqualTo(this.firstProduct.Label));
            Assert.That(result.Price, Is.EqualTo(this.firstProduct.Price));
            Assert.That(result.Quantity, Is.EqualTo(this.firstProduct.Quantity));
        }
コード例 #2
0
        public void AddProductShouldAddTheProduct()
        {
            //Arrange
            //Act
            this.productStock.Add(this.product);
            //Assert
            IProduct actualProduct = productStock.FindByLabel(ProductLabel);

            Assert.That(productStock, Is.Not.Null);
            Assert.AreEqual(product.Label, actualProduct.Label);
            Assert.AreEqual(product.Price, actualProduct.Price);
            Assert.AreEqual(product.Quantity, actualProduct.Quantity);
        }
コード例 #3
0
        public void FindByLabel_ThrowsException_ProductIfProductNotExist(string label)
        {
            productStock.Add(new Product("1", 1, 1));
            productStock.Add(new Product("2", 2, 1));

            Assert.Throws <NullReferenceException>(() => productStock.FindByLabel(label));
        }
コード例 #4
0
        public void ProductStock_RandomTest()
        {
            var stock = new ProductStock();

            stock.Add(new Product("SSD", 12.4m, 3));
            stock.Add(new Product("CPU", 16.5m, 3));
            stock.Add(new Product("HDD", 20.7m, 3));
            stock.Add(new Product("RAM", 14.9m, 3));

            stock.FindByLabel("SSD").Price = 100;
        }
コード例 #5
0
        public void ProductStock_FindByLabelThrowsExceptionWhenProductCannotBeFound()
        {
            var stock = new ProductStock();

            stock.Add(new Product("SSD", 12.4m, 3));
            stock.Add(new Product("CPU", 16.5m, 3));
            stock.Add(new Product("HDD", 20.7m, 3));
            stock.Add(new Product("RAM", 14.9m, 3));

            Assert.Throws <ArgumentException>(() => stock.FindByLabel("GPU"));
        }
コード例 #6
0
        public void ProductStock_FindByLabelReturnsTheCorrectProduct()
        {
            var stock = new ProductStock();

            stock.Add(new Product("SSD", 12.4m, 3));
            stock.Add(new Product("CPU", 16.5m, 3));
            stock.Add(new Product("HDD", 20.7m, 3));
            stock.Add(new Product("RAM", 14.9m, 3));

            Assert.AreEqual(stock.FindByLabel("SSD").CompareTo(new Product("SSD", 12.4m, 3)), 0);
        }
コード例 #7
0
 public void FindByLabel_WithNonExistingLabelShouldThrowInvalidOperationException()
 {
     Assert.Throws <InvalidOperationException>(() => productStock.FindByLabel("SSD"));
 }