示例#1
0
        public async void Should_CalculateAndComparePurchaseData_With_PreCalculatedPurchaseData(PurchaseData purchaseData)
        {
            // Arrange
            var pcmd = new CalculatePurchaseCommand.Handler(new PurchaseService());

            // Act
            var resultGrossAmount = await pcmd.Handle(new CalculatePurchaseCommand { VATRate = purchaseData.VATRate, GrossAmount = purchaseData.GrossAmount }, CancellationToken.None);

            var resultVATAmount = await pcmd.Handle(new CalculatePurchaseCommand { VATRate = purchaseData.VATRate, VATAmount = purchaseData.VATAmount }, CancellationToken.None);

            var resultNetAmount = await pcmd.Handle(new CalculatePurchaseCommand { VATRate = purchaseData.VATRate, NetAmount = purchaseData.NetAmount }, CancellationToken.None);

            // Assert
            Assert.Equal(purchaseData.VATRate, resultGrossAmount.VATRate);
            Assert.Equal(purchaseData.GrossAmount, resultGrossAmount.GrossAmount);
            Assert.Equal(purchaseData.VATAmount, resultGrossAmount.VATAmount);
            Assert.Equal(purchaseData.NetAmount, resultGrossAmount.NetAmount);

            Assert.Equal(purchaseData.VATRate, resultVATAmount.VATRate);
            Assert.Equal(purchaseData.GrossAmount, resultVATAmount.GrossAmount);
            Assert.Equal(purchaseData.VATAmount, resultVATAmount.VATAmount);
            Assert.Equal(purchaseData.NetAmount, resultVATAmount.NetAmount);

            Assert.Equal(purchaseData.VATRate, resultNetAmount.VATRate);
            Assert.Equal(purchaseData.GrossAmount, resultNetAmount.GrossAmount);
            Assert.Equal(purchaseData.VATAmount, resultNetAmount.VATAmount);
            Assert.Equal(purchaseData.NetAmount, resultNetAmount.NetAmount);
        }
示例#2
0
        public async void Should_ValidateInputPurchaseDataModel_With_ExpectedResult(PurchaseData purchaseData, bool expectedResult)
        {
            //Arrange
            var pcmd = new CalculatePurchaseCommand.Handler(new PurchaseService());

            //Act & Assert
            if (expectedResult == false)
            {
                await Assert.ThrowsAsync <ValidationException>(async() => await pcmd.Handle(new CalculatePurchaseCommand {
                    VATRate = purchaseData.VATRate, GrossAmount = purchaseData.GrossAmount, NetAmount = purchaseData.NetAmount, VATAmount = purchaseData.VATAmount
                }, CancellationToken.None));
            }
            else
            {
                var result = await pcmd.Handle(new CalculatePurchaseCommand { VATRate = purchaseData.VATRate, GrossAmount = purchaseData.GrossAmount, NetAmount = purchaseData.NetAmount, VATAmount = purchaseData.VATAmount }, CancellationToken.None);

                Assert.IsType <PurchaseData>(result);
                Assert.Equal(purchaseData.VATRate, result.VATRate);
            }
        }
示例#3
0
        public async void Should_ValidateInputVatRate_With_ExpectedResult(decimal vatRate, bool expectedResult)
        {
            // Arrange
            var pcmd = new CalculatePurchaseCommand.Handler(new PurchaseService());

            //Act - assert
            if (expectedResult == false)
            {
                await Assert.ThrowsAsync <ValidationException>(async() => await pcmd.Handle(new CalculatePurchaseCommand {
                    VATRate = vatRate, GrossAmount = 100
                }, CancellationToken.None));
            }
            else
            {
                var result = await pcmd.Handle(new CalculatePurchaseCommand { VATRate = vatRate, GrossAmount = 100 }, CancellationToken.None);

                Assert.IsType <PurchaseData>(result);
                Assert.Equal(vatRate, result.VATRate);
            }
        }