public void PassThroughVariableDiscount()
        {
            // Arrange
            Mock<IDiscountHelper> mock = new Mock<IDiscountHelper>();

            mock.Setup(x => x.ApplyDiscount(It.IsAny<decimal>())).Returns<decimal>(x => x);
            mock.Setup(x => x.ApplyDiscount(It.Is<decimal>(y => y == 0))).Throws<ArgumentOutOfRangeException>();
            mock.Setup(x => x.ApplyDiscount(It.Is<decimal>(y => y > 100))).Returns<decimal>(x => x * 0.9M);
            mock.Setup(x => x.ApplyDiscount(It.IsInRange<decimal>(10, 100, Range.Inclusive))).Returns<decimal>(x => x - 5);

            IValueCalculator target = new LinqValueCalculator(mock.Object);

            // Act
            decimal fiveDollarDiscount = target.ValueProducts(CreateProduct(5));
            decimal tenDollarDiscount = target.ValueProducts(CreateProduct(10));
            decimal fiftyDollarDiscount = target.ValueProducts(CreateProduct(50));
            decimal hundredDollarDiscount = target.ValueProducts(CreateProduct(100));
            decimal fiveHundredDollarDiscount = target.ValueProducts(CreateProduct(500));

            // Assert
            Assert.AreEqual(5, fiveDollarDiscount, "$5 Fail");
            Assert.AreEqual(5, tenDollarDiscount, "$10 Fail");
            Assert.AreEqual(45, fiftyDollarDiscount, "$50 Fail");
            Assert.AreEqual(95, hundredDollarDiscount, "$100 Fail");
            Assert.AreEqual(450, fiveHundredDollarDiscount, "$500 Fail");

            target.ValueProducts(CreateProduct(0));
        }
        public void Pass_Through_Variable_Discounts() {
            //arrange
            Mock<IDiscountHelper> mock = new Mock<IDiscountHelper>();
            mock.Setup(m => m.ApplyDiscount(It.IsAny<decimal>()))
                .Returns<decimal>(total => total);
            mock.Setup(m => m.ApplyDiscount(It.Is<decimal>(v => v == 0)))
                .Throws<System.ArgumentOutOfRangeException>();
            mock.Setup(m => m.ApplyDiscount(It.Is<decimal>(v => v > 100)))
                .Throws<System.ArgumentOutOfRangeException>();
            mock.Setup(m => m.ApplyDiscount(It.IsInRange<decimal>(10, 100,
                Range.Inclusive))).Returns<decimal>(total => total - 5);
            var target = new LinqValueCalculator(mock.Object);
            //act
            decimal FiveDollarDiscount = target.ValueProducts(createProduct(5));
            decimal TenDollarDiscount = target.ValueProducts(createProduct(10));
            decimal FiftyDollarDiscount = target.ValueProducts(createProduct(50));
            decimal HundredDollarDiscount = target.ValueProducts(createProduct(100));
            decimal FiveHundredDollarDiscount = target.ValueProducts(createProduct(500));

            //assert
            Assert.AreEqual(5, FiveDollarDiscount, "$5 Fail");
            Assert.AreEqual(5, TenDollarDiscount, "$10 Fail");
            Assert.AreEqual(45, FiftyDollarDiscount, "$50 Fail");
            Assert.AreEqual(95, HundredDollarDiscount, "$100 Fail");
            Assert.AreEqual(450, FiveHundredDollarDiscount, "$500 Fail");
            target.ValueProducts(createProduct(0));
        }
 // GET: Home
 public ActionResult Index()
 {
     LinqValueCalculator calc = new LinqValueCalculator();
     ShoppingCart cart = new ShoppingCart(calc) {Products = _products};
     decimal totalValue = cart.CalculateProductTotal();
     return View(totalValue);
 }
Ejemplo n.º 4
0
        public void PassThroughVariableDiscounts()
        {
            //            var discounter = new MinimumDiscountHelper();
            //            var target = new LinqValueCalculator(discounter);
            //            var goalToal = products.Sum(prod => prod.Price);

            Mock<IDiscountHelper> mock = new Mock<IDiscountHelper>();
            mock.Setup(moq => moq.ApplyDiscount(It.IsAny<decimal>())).Returns<decimal>(total => total);
            mock.Setup(moq => moq.ApplyDiscount(It.Is<decimal>(v=>v==0))).Throws<ArgumentOutOfRangeException>();
            mock.Setup(moq => moq.ApplyDiscount(It.Is<decimal>(v=>v>100))).Returns<decimal>(total => total*0.9M);
            mock.Setup(moq => moq.ApplyDiscount(It.IsInRange<decimal>(10,100,Range.Inclusive))).Returns<decimal>(total => total-5);
            var target = new LinqValueCalculator(mock.Object);

            var FiveDollarDiscount = target.ValueProducts(createProduct(5));
            var TenDollarDiscount = target.ValueProducts(createProduct(10));
            var FiftyDollarDiscount = target.ValueProducts(createProduct(50));
            var HundredDollarDiscount = target.ValueProducts(createProduct(100));
            var FiveHundredDollarDiscount = target.ValueProducts(createProduct(500));

            Assert.AreEqual(5, FiveDollarDiscount, "Niepowodzenie 5 zł ");
            Assert.AreEqual(5, TenDollarDiscount, "Niepowodzenie 10 zł ");
            Assert.AreEqual(45, FiftyDollarDiscount, "Niepowodzenie 50 zł ");
            Assert.AreEqual(95, HundredDollarDiscount, "Niepowodzenie 100 zł ");
            Assert.AreEqual(450, FiveHundredDollarDiscount, "Niepowodzenie 500 zł ");
            target.ValueProducts(createProduct(0));
        }
        public void ValueProducts_ReplicateMinimumDiscountFunctionality()
        {
            var mock = new Mock<IDiscountHelper>();

            mock.Setup(m => m.ApplyDiscount(It.IsAny<decimal>()))
                .Returns<decimal>(total => total);
            mock.Setup(m => m.ApplyDiscount(It.Is<decimal>(v => v == 0)))
                .Throws<System.ArgumentOutOfRangeException>();
            mock.Setup(m => m.ApplyDiscount(It.Is<decimal>(v => v > 100)))
                .Returns<decimal>(total => (total * 0.9m));
            mock.Setup(m => m.ApplyDiscount(It.IsInRange<decimal>(10, 100, Range.Inclusive)))
                .Returns<decimal>(total => total - 5);

            var target = new LinqValueCalculator(mock.Object);

            decimal FiveDollarDiscount = target.ValueProducts(createProduct(5));
            decimal TenDollarDiscount = target.ValueProducts(createProduct(10));
            decimal FiftyDollarDiscount = target.ValueProducts(createProduct(50));
            decimal HundredDollarDiscount = target.ValueProducts(createProduct(100));
            decimal FiveHundredDollarDiscount = target.ValueProducts(createProduct(500));

            Assert.AreEqual(5, FiveDollarDiscount, "$5 Fail");
            Assert.AreEqual(5, TenDollarDiscount, "$10 Fail");
            Assert.AreEqual(45, FiftyDollarDiscount, "$50 Fail");
            Assert.AreEqual(95, HundredDollarDiscount, "$100 Fail");
            Assert.AreEqual(450, FiveHundredDollarDiscount, "$500 Fail");
            target.ValueProducts(createProduct(0));
        }
Ejemplo n.º 6
0
        public void Sum_Products_Correctly() {
            Mock<IDiscountHelper> mockDiscounter = new Mock<IDiscountHelper>();
            mockDiscounter.Setup(m => m.ApplyDiscount(It.IsAny<decimal>())).Returns<decimal>(total => total);
            var target = new LinqValueCalculator(mockDiscounter.Object);
            var goalTotal = products.Sum(e => e.Price);

            var result = target.ValueProducts(products);

            Assert.AreEqual(goalTotal, result);
        }
Ejemplo n.º 7
0
 public void Sum_Products_Correctly()
 {
     // arrange
     Mock<IDiscountHelper> mock = new Mock<IDiscountHelper>();
     mock.Setup(m => m.ApplyDiscount(It.IsAny<decimal>())).Returns<decimal>(total => total);
     var target = new LinqValueCalculator(mock.Object);
     // act
     var result = target.ValueProducts(products);
     // assert
     Assert.AreEqual(products.Sum(e=> e.Price), result);
 }
Ejemplo n.º 8
0
 public void Sum_Products_Correctly()
 {
     // arrange
     var discounter = new MinimumDiscountHelper();
     var target = new LinqValueCalculator(discounter);
     var goalTotal = products.Sum(e => e.Price);
     // act
     var result = target.ValueProducts(products);
     // assert
     Assert.Equal(goalTotal, result);
 }
Ejemplo n.º 9
0
        public void Sum_Products_Correctly()
        {
            //            var discounter = new MinimumDiscountHelper();
            //            var target = new LinqValueCalculator(discounter);
            //            var goalToal = products.Sum(prod => prod.Price);

            Mock<IDiscountHelper> mock = new Mock<IDiscountHelper>();
            mock.Setup(moq => moq.ApplyDiscount(It.IsAny<decimal>())).Returns<decimal>(total => total);
            var target = new LinqValueCalculator(mock.Object);

            var result = target.ValueProducts(products);

            Assert.AreEqual(products.Sum(prod=>prod.Price), result);
        }
        public void SumProductsCorrectly()
        {
            // Arrange
            Mock<IDiscountHelper> mock = new Mock<IDiscountHelper>();
            mock.Setup(x => x.ApplyDiscount(It.IsAny<decimal>())).Returns<decimal>(x => x);

            IValueCalculator target = new LinqValueCalculator(mock.Object);
            decimal goalTotal = products.Sum(x => x.Price);

            // Act
            decimal result = target.ValueProducts(products);

            // Assert
            Assert.AreEqual(goalTotal, result);
        }
        public void Pass_Through_Variable_Discounts()
        {
            // arrange
            // mock-up the entire logic in the implementation?

            Mock<IDiscountHelper> mock = new Mock<IDiscountHelper>();
            // TODO: remember that .Setup() runs in reverse order than the coded order! :/

            // "no discount is applied on totals lt $10" (this is the 'else')
            mock.Setup(m => m.ApplyDiscount(It.IsAny<decimal>())).Returns<decimal>(total => total);

            // "ArgumentoutOfRangeException will be thrown on negatives"
            mock.Setup(m => m.ApplyDiscount(It.Is<decimal>(v => v == 0))).Throws<ArgumentOutOfRangeException>();

            // "if the total gt $100, discount will be 10%"
            mock.Setup(m => m.ApplyDiscount(It.Is<decimal>(v => v > 100))).Returns<decimal>(total => (total * 0.9M));

            // "if total gt $10 && lt $100 inclusive, discount will be $5"
            mock.Setup(m => m.ApplyDiscount(It.IsInRange<decimal>(10, 100, Range.Inclusive))).Returns<decimal>(total => total - 5);

            var target = new LinqValueCalculator(mock.Object);

            // act
            decimal fiveDollarAmount = target.ValueProducts(createProduct(5));
            decimal tenDollarAmount = target.ValueProducts(createProduct(10));
            decimal fiftyDollarAmount = target.ValueProducts(createProduct(50));
            decimal oneHunderedDollarAmount = target.ValueProducts(createProduct(100));
            decimal fiveHundredDollarAmount = target.ValueProducts(createProduct(500));

            decimal negativeDollarAmount = target.ValueProducts(createProduct(-1));

            // assert
            Assert.AreEqual(5, fiveDollarAmount, "$5 Fail");
            Assert.AreEqual(5, tenDollarAmount, "$10 Fail");
            Assert.AreEqual(45, fiftyDollarAmount, "$50 Fail");
            Assert.AreEqual(95, oneHunderedDollarAmount, "$100 Fail");
            Assert.AreEqual(450, fiveHundredDollarAmount, "$500 Fail");

            target.ValueProducts(createProduct(0));
        }
Ejemplo n.º 12
0
 public ShoppingCart(LinqValueCalculator calcParam)
 {
     calc = calcParam;
 }
Ejemplo n.º 13
0
 public ShoppingCart(LinqValueCalculator calcParam)
 {
     calc = calcParam;
 }
        public void Sum_Products_Correctly()
        {
            // arrange

            // the reason we'd use MOQ's here is because our LinkValueCalculator has a dependency
            // on the IDiscountHelper implementation. so if we have a test fail,
            // we don't know if it's the Implimentation of the discounter or if
            // it's the linqvaluecalculator

            // IDiscountHelper discounter = new MinimumDiscountHelper();
            Mock<IDiscountHelper> mock = new Mock<IDiscountHelper>();
            // we inform the mock that i will be passing in a decimal and getting back a decimal
            mock.Setup(m =>
                m.ApplyDiscount(It.IsAny<decimal>()))
                .Returns<decimal>(total => total);
            // this doesn't implement the mocked classes internal logic however.

            LinqValueCalculator target = new LinqValueCalculator(mock.Object);

            // act
            // this returns _discounter.ApplyDiscount(products.Sum(p => p.Price));
            var result = target.ValueProducts(_products);

            // assert
            Assert.AreEqual(_products.Sum(e => e.Price), result);
        }