コード例 #1
0
        /// <summary>
        /// Adds the transaction fee for product to contract.
        /// </summary>
        /// <param name="transactionFeeId">The transaction fee identifier.</param>
        /// <param name="contractId">The contract identifier.</param>
        /// <param name="productId">The product identifier.</param>
        /// <param name="description">The description.</param>
        /// <param name="calculationType">Type of the calculation.</param>
        /// <param name="feeType">Type of the fee.</param>
        /// <param name="value">The value.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <exception cref="InvalidOperationException">
        /// Contract Id [{contractId}] must be created to add products
        /// or
        /// Product Id [{productId}] not added to contract [{contractAggregate.Description}]
        /// </exception>
        /// <exception cref="System.InvalidOperationException">Contract Id [{contractId}] must be created to add products
        /// or
        /// Product Id [{productId}] not added to contract [{contractAggregate.Description}]</exception>
        public async Task AddTransactionFeeForProductToContract(Guid transactionFeeId,
                                                                Guid contractId,
                                                                Guid productId,
                                                                String description,
                                                                CalculationType calculationType,
                                                                FeeType feeType,
                                                                Decimal value,
                                                                CancellationToken cancellationToken)
        {
            // Get the contract aggregate
            ContractAggregate contractAggregate = await this.ContractAggregateRepository.GetLatestVersion(contractId, cancellationToken);

            // Check for a duplicate
            if (contractAggregate.IsCreated == false)
            {
                throw new InvalidOperationException($"Contract Id [{contractId}] must be created to add products");
            }

            List <Product> products = contractAggregate.GetProducts();
            Product        product  = products.SingleOrDefault(p => p.ProductId == productId);

            if (product == null)
            {
                throw new InvalidOperationException($"Product Id [{productId}] not added to contract [{contractAggregate.Description}]");
            }

            contractAggregate.AddTransactionFee(product, transactionFeeId, description, calculationType, feeType, value);

            await this.ContractAggregateRepository.SaveChanges(contractAggregate, cancellationToken);
        }
コード例 #2
0
        public void ContractAggregate_DisableTransactionFee_TransactionFeeIsDisabled(CalculationType calculationType, FeeType feeType)
        {
            ContractAggregate aggregate = ContractAggregate.Create(TestData.ContractId);

            aggregate.Create(TestData.EstateId, TestData.OperatorId, TestData.ContractDescription);
            aggregate.AddVariableValueProduct(TestData.ProductId, TestData.ProductName, TestData.ProductDisplayText);

            List <Product> products = aggregate.GetProducts();
            Product        product  = products.Single();

            aggregate.AddTransactionFee(product, TestData.TransactionFeeId, TestData.TransactionFeeDescription, calculationType, feeType, TestData.TransactionFeeValue);

            List <Product> productsAfterFeeAdded = aggregate.GetProducts();
            Product        productWithFees       = productsAfterFeeAdded.Single();

            productWithFees.TransactionFees.ShouldHaveSingleItem();
            TransactionFee fee = productWithFees.TransactionFees.Single();

            fee.IsEnabled.ShouldBeTrue();

            aggregate.DisableTransactionFee(TestData.ProductId, TestData.TransactionFeeId);

            productsAfterFeeAdded = aggregate.GetProducts();
            productWithFees       = productsAfterFeeAdded.Single();
            productWithFees.TransactionFees.ShouldHaveSingleItem();
            fee = productWithFees.TransactionFees.Single();
            fee.IsEnabled.ShouldBeFalse();
        }
コード例 #3
0
        public void ContractAggregate_AddTransactionFee_NullProduct_ErrorThrown(CalculationType calculationType, FeeType feeType)
        {
            ContractAggregate aggregate = ContractAggregate.Create(TestData.ContractId);

            aggregate.Create(TestData.EstateId, TestData.OperatorId, TestData.ContractDescription);

            Should.Throw <ArgumentNullException>(() =>
            {
                aggregate.AddTransactionFee(null, TestData.TransactionFeeId, TestData.TransactionFeeDescription, calculationType, feeType, TestData.TransactionFeeValue);
            });
        }
コード例 #4
0
        public void ContractAggregate_AddTransactionFee_ProductNotFound_ErrorThrown(CalculationType calculationType, FeeType feeType)
        {
            ContractAggregate aggregate = ContractAggregate.Create(TestData.ContractId);

            aggregate.Create(TestData.EstateId, TestData.OperatorId, TestData.ContractDescription);
            aggregate.AddFixedValueProduct(TestData.ProductId, TestData.ProductName, TestData.ProductDisplayText, TestData.ProductFixedValue);

            Should.Throw <InvalidOperationException>(() =>
            {
                aggregate.AddTransactionFee(new Product(), TestData.TransactionFeeId, TestData.TransactionFeeDescription, calculationType, feeType, TestData.TransactionFeeValue);
            });
        }
コード例 #5
0
        public void ContractAggregate_AddTransactionFee_VariableValueProduct_InvalidFeeType_ErrorThrown(CalculationType calculationType)
        {
            ContractAggregate aggregate = ContractAggregate.Create(TestData.ContractId);

            aggregate.Create(TestData.EstateId, TestData.OperatorId, TestData.ContractDescription);
            aggregate.AddVariableValueProduct(TestData.ProductId, TestData.ProductName, TestData.ProductDisplayText);

            List <Product> products = aggregate.GetProducts();
            Product        product  = products.Single();

            Should.Throw <ArgumentOutOfRangeException>(() =>
            {
                aggregate.AddTransactionFee(product, TestData.TransactionFeeId, TestData.TransactionFeeDescription, calculationType, (FeeType)99, TestData.TransactionFeeValue);
            });
        }
コード例 #6
0
        public void ContractAggregate_AddTransactionFee_FixedValueProduct_InvalidFeeDescription_ErrorThrown(CalculationType calculationType, FeeType feeType, String feeDescription)
        {
            ContractAggregate aggregate = ContractAggregate.Create(TestData.ContractId);

            aggregate.Create(TestData.EstateId, TestData.OperatorId, TestData.ContractDescription);
            aggregate.AddFixedValueProduct(TestData.ProductId, TestData.ProductName, TestData.ProductDisplayText, TestData.ProductFixedValue);

            List <Product> products = aggregate.GetProducts();
            Product        product  = products.Single();

            Should.Throw <ArgumentNullException>(() =>
            {
                aggregate.AddTransactionFee(product, TestData.TransactionFeeId, feeDescription, calculationType, feeType, TestData.TransactionFeeValue);
            });
        }
コード例 #7
0
        public void ContractAggregate_AddTransactionFee_FixedValueProduct_TransactionFeeAdded(CalculationType calculationType, FeeType feeType)
        {
            ContractAggregate aggregate = ContractAggregate.Create(TestData.ContractId);

            aggregate.Create(TestData.EstateId, TestData.OperatorId, TestData.ContractDescription);
            aggregate.AddFixedValueProduct(TestData.ProductId, TestData.ProductName, TestData.ProductDisplayText, TestData.ProductFixedValue);

            List <Product> products = aggregate.GetProducts();
            Product        product  = products.Single();

            aggregate.AddTransactionFee(product, TestData.TransactionFeeId, TestData.TransactionFeeDescription, calculationType, feeType, TestData.TransactionFeeValue);

            List <Product> productsAfterFeeAdded = aggregate.GetProducts();
            Product        productWithFees       = productsAfterFeeAdded.Single();

            productWithFees.TransactionFees.ShouldHaveSingleItem();
            TransactionFee fee = productWithFees.TransactionFees.Single();

            fee.Description.ShouldBe(TestData.TransactionFeeDescription);
            fee.TransactionFeeId.ShouldBe(TestData.TransactionFeeId);
            fee.CalculationType.ShouldBe(calculationType);
            fee.FeeType.ShouldBe(feeType);
            fee.Value.ShouldBe(TestData.TransactionFeeValue);
        }