public void Handle_NonExistentMerchant_ThrowsException() { //arrange var calculateFeeHandler = new Mock <ICommandHandler <CalculateFee, Fee> >(); var merchantRepository = new Mock <IMerchantRepository>(); merchantRepository.Setup(x => x.Get(It.IsAny <Name>())).Returns((Merchant)null); var calculateFeeWithDiscountHandler = new CalculateFeeWithDiscountHandler(calculateFeeHandler.Object, merchantRepository.Object); var transaction = new Transaction(new Date(DateTime.Now), new Name("STEAM"), new Amount(100)); //act && assert Assert.Throws <DomainObjectNotFoundException>( () => calculateFeeWithDiscountHandler.Handle(new CalculateFee(Guid.NewGuid(), transaction))); }
public void Handle_AppliesMerchantDiscount(double originalFee, double merchantDiscount, double expectedFee) { //arrange var calculateFeeHandler = new Mock <ICommandHandler <CalculateFee, Fee> >(); calculateFeeHandler.Setup(x => x.Handle(It.IsAny <CalculateFee>())).Returns(new Fee(originalFee)); var merchantRepository = new Mock <IMerchantRepository>(); merchantRepository.Setup(x => x.Get(It.IsAny <Name>())). Returns(new Merchant(new Name("STEAM"), new Percentage(merchantDiscount))); var calculateFeeWithDiscountHandler = new CalculateFeeWithDiscountHandler(calculateFeeHandler.Object, merchantRepository.Object); var transaction = new Transaction(new Date(DateTime.Now), new Name("STEAM"), new Amount(100)); //act var feeWithDiscount = calculateFeeWithDiscountHandler.Handle(new CalculateFee(Guid.NewGuid(), transaction)); //assert calculateFeeHandler.Verify(x => x.Handle(It.IsAny <CalculateFee>()), Times.Once); Assert.Equal(expectedFee, feeWithDiscount.Value); }