Пример #1
0
        private Basket InitialiseBasket()
        {
            var mockDiscountValidator = new Mock <IValidateAppliedDiscounts>();

            mockDiscountValidator
            .Setup(x => x.CanApplyDiscount(It.IsAny <IEnumerable <IMayApplyDiscount> >(), It.IsAny <IMayApplyDiscount>()))
            .Returns(DiscountApplicationResult.CreateSuccess());

            return(new Basket(mockDiscountValidator.Object));
        }
Пример #2
0
        public void AddVoucher_DelegatesToValidator()
        {
            var discountToAddMock        = new Mock <IMayApplyDiscount>();
            var expectedValidationResult = DiscountApplicationResult.CreateSuccess();

            _discountValidatorMock
            .Setup(x => x.CanApplyDiscount(It.IsAny <IEnumerable <IMayApplyDiscount> >(), discountToAddMock.Object))
            .Returns(expectedValidationResult)
            .Verifiable();

            var basket = new Basket(_discountValidatorMock.Object);

            var applicationResult = basket.AddVoucher(discountToAddMock.Object);

            Assert.Equal(expectedValidationResult, applicationResult);
            _discountValidatorMock.Verify(x => x.CanApplyDiscount(It.IsAny <IEnumerable <IMayApplyDiscount> >(), discountToAddMock.Object), Times.Once);
        }