Esempio n. 1
0
        public void Should_Throw_ArgumentNullException_When_Adding_Null_DiscountCode()
        {
            var sut = new OrderViewModel(
                Substitute.For <IDiscountCalculator <OrderViewModel> >(),
                Substitute.For <IDiscountCalculator <LineViewModel> >(),
                new Order(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <decimal>()));

            Assert.Throws <ArgumentNullException>(() => sut.AddDiscountCode(null));
            Assert.Throws <ArgumentNullException>(() => sut.AddDiscountCode(string.Empty));
        }
Esempio n. 2
0
        public void Should_Update_Prices_When_Adding_DiscountCode()
        {
            var orderDiscount = Substitute.For <IDiscountCalculator <OrderViewModel> >();

            orderDiscount.GetDiscount(Arg.Any <OrderViewModel>()).Returns(info =>
            {
                var orderVm = info.ArgAt <OrderViewModel>(0);
                if (orderVm.DiscountCodes != null && orderVm.DiscountCodes.Contains("test"))
                {
                    return(orderVm.SubTotal * 0.1m);
                }
                return(0);
            });

            var sut = new OrderViewModel(orderDiscount, Substitute.For <IDiscountCalculator <LineViewModel> >(),
                                         new Order(Arg.Any <string>(), Arg.Any <string>(), 0.0725m));

            sut.AddLine(new Line(new Bike("brand", "model", 1000m), 1));

            Assert.That(sut.Lines.Count, Is.EqualTo(1));
            Assert.That(sut.SubTotal, Is.EqualTo(1000m));
            Assert.That(sut.Tax, Is.EqualTo(1000m * 0.0725m));
            Assert.That(sut.Total, Is.EqualTo(1000m * 0.0725m + 1000m));

            sut.AddDiscountCode("test");

            Assert.That(sut.SubTotal, Is.EqualTo(1000m));
            Assert.That(sut.Tax, Is.EqualTo(1000m * 0.0725m));
            Assert.That(sut.Total, Is.EqualTo(1000m * 0.0725m + 900m));
        }