コード例 #1
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();
        }
コード例 #2
0
        /// <summary>
        /// Adds the product to contract.
        /// </summary>
        /// <param name="productId">The product identifier.</param>
        /// <param name="contractId">The contract identifier.</param>
        /// <param name="productName">Name of the product.</param>
        /// <param name="displayText">The display text.</param>
        /// <param name="value">The value.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <exception cref="System.InvalidOperationException">Contract Id [{contractId}] must be created to add products</exception>
        public async Task AddProductToContract(Guid productId,
                                               Guid contractId,
                                               String productName,
                                               String displayText,
                                               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");
            }

            if (value.HasValue)
            {
                contractAggregate.AddFixedValueProduct(productId, productName, displayText, value.Value);
            }
            else
            {
                contractAggregate.AddVariableValueProduct(productId, productName, displayText);
            }

            await this.ContractAggregateRepository.SaveChanges(contractAggregate, cancellationToken);
        }
コード例 #3
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);
        }
コード例 #4
0
        /// <summary>
        /// Creates the contract.
        /// </summary>
        /// <param name="contractId">The contract identifier.</param>
        /// <param name="estateId">The estate identifier.</param>
        /// <param name="operatorId">The operator identifier.</param>
        /// <param name="description">The description.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <exception cref="System.InvalidOperationException">
        /// Unable to create a contract for an estate that is not created
        /// or
        /// Unable to create a contract for an operator that is not setup on estate [{estate.Name}]
        /// or
        /// Contract Id [{contractId}] already created for estate [{estate.Name}]
        /// </exception>
        public async Task CreateContract(Guid contractId,
                                         Guid estateId,
                                         Guid operatorId,
                                         String description,
                                         CancellationToken cancellationToken)
        {
            // Validate the estate
            EstateAggregate estateAggregate = await this.EstateAggregateRepository.GetLatestVersion(estateId, cancellationToken);

            if (estateAggregate.IsCreated == false)
            {
                throw new InvalidOperationException("Unable to create a contract for an estate that is not created");
            }

            // Validate the operator
            Estate estate = estateAggregate.GetEstate();

            if (estate.Operators == null || estate.Operators.Any(o => o.OperatorId == operatorId) == false)
            {
                throw new InvalidOperationException($"Unable to create a contract for an operator that is not setup on estate [{estate.Name}]");
            }

            // Get the contract aggregate
            ContractAggregate contractAggregate = await this.ContractAggregateRepository.GetLatestVersion(contractId, cancellationToken);

            // Check for a duplicate
            if (contractAggregate.IsCreated)
            {
                throw new InvalidOperationException($"Contract Id [{contractId}] already created for estate [{estate.Name}]");
            }

            contractAggregate.Create(estateId, operatorId, description);

            await this.ContractAggregateRepository.SaveChanges(contractAggregate, cancellationToken);
        }
コード例 #5
0
        public async Task <Guid> Create(ContractCreateRequest request)
        {
            var contract = ContractAggregate.CreateFromRequest(request);

            await _repo.Add(contract);

            return(contract.Id);
        }
コード例 #6
0
        public void ContractAggregate_Create_InvalidOperatorId_ErrorThrown()
        {
            ContractAggregate aggregate = ContractAggregate.Create(TestData.ContractId);

            Should.Throw <ArgumentNullException>(() =>
            {
                aggregate.Create(TestData.EstateId, Guid.Empty, TestData.ContractDescription);
            });
        }
コード例 #7
0
        public void ContractAggregate_Create_InvalidDescription_ErrorThrown(String description)
        {
            ContractAggregate aggregate = ContractAggregate.Create(TestData.ContractId);

            Should.Throw <ArgumentNullException>(() =>
            {
                aggregate.Create(TestData.EstateId, TestData.OperatorId, description);
            });
        }
コード例 #8
0
        public void ContractAggregate_AddVariableValueProduct_InvalidProductDisplayText_ErrorThrown(String displayText)
        {
            ContractAggregate aggregate = ContractAggregate.Create(TestData.ContractId);

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

            Should.Throw <ArgumentNullException>(() =>
            {
                aggregate.AddVariableValueProduct(TestData.ProductId, TestData.ProductName, displayText);
            });
        }
コード例 #9
0
        public void ContractAggregate_AddFixedValueProduct_InvalidProductValue_ErrorThrown(Decimal value)
        {
            ContractAggregate aggregate = ContractAggregate.Create(TestData.ContractId);

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

            Should.Throw <ArgumentOutOfRangeException>(() =>
            {
                aggregate.AddFixedValueProduct(TestData.ProductId, TestData.ProductName, TestData.ProductDisplayText, value);
            });
        }
コード例 #10
0
        public void ContractAggregate_DisableTransactionFee_ProductNotFound_ErrorThrown()
        {
            ContractAggregate aggregate = ContractAggregate.Create(TestData.ContractId);

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

            Should.Throw <InvalidOperationException>(() =>
            {
                aggregate.DisableTransactionFee(TestData.ProductId, TestData.TransactionFeeId);
            });
        }
コード例 #11
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);
            });
        }
コード例 #12
0
        /// <summary>
        /// Disables the transaction fee for product.
        /// </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="cancellationToken">The cancellation token.</param>
        public async Task DisableTransactionFeeForProduct(Guid transactionFeeId,
                                                          Guid contractId,
                                                          Guid productId,
                                                          CancellationToken cancellationToken)
        {
            // Get the contract aggregate
            ContractAggregate contractAggregate = await this.ContractAggregateRepository.GetLatestVersion(contractId, cancellationToken);

            contractAggregate.DisableTransactionFee(productId, transactionFeeId);

            await this.ContractAggregateRepository.SaveChanges(contractAggregate, cancellationToken);
        }
コード例 #13
0
        public void ContractAggregate_ShouldBeDeleted()
        {
            //Arrange
            var request  = AggregatesRequestBuilder.CreateRandomContractCreateRequest();
            var contract = ContractAggregate.CreateFromRequest(request);

            //Act
            contract.MarkAsDeleted();

            //Assert
            contract.IsDeleted.Should().BeTrue();
        }
コード例 #14
0
        public void ContractAggregate_Create_IsCreated()
        {
            ContractAggregate aggregate = ContractAggregate.Create(TestData.ContractId);

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

            aggregate.AggregateId.ShouldBe(TestData.ContractId);
            aggregate.EstateId.ShouldBe(TestData.EstateId);
            aggregate.OperatorId.ShouldBe(TestData.OperatorId);
            aggregate.Description.ShouldBe(TestData.ContractDescription);
            aggregate.IsCreated.ShouldBeTrue();
        }
コード例 #15
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);
            });
        }
コード例 #16
0
        public void ContractAggregate_AddFixedValueProduct_DuplicateProduct_ErrorThrown()
        {
            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.AddFixedValueProduct(TestData.ProductId, TestData.ProductName, TestData.ProductDisplayText, TestData.ProductFixedValue);
            });
        }
コード例 #17
0
        public void ContractAggregate_UpdateRandomFromRequest()
        {
            //Arrange
            var createRequest = AggregatesRequestBuilder.CreateRandomContractCreateRequest();
            var contract      = ContractAggregate.CreateFromRequest(createRequest);
            var updateRequest = AggregatesRequestBuilder.CreateRandomContractUpdateRequest();

            //Act
            contract.UpdateFromRequest(updateRequest);

            // Assert
            contract.Title.Should().Be(updateRequest.Title);
            contract.Description.Should().Be(updateRequest.Description);
        }
コード例 #18
0
        public void ContractAggregate_GetContract_ContractReturned()
        {
            ContractAggregate aggregate = ContractAggregate.Create(TestData.ContractId);

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

            Contract contract = aggregate.GetContract();

            contract.EstateId.ShouldBe(TestData.EstateId);
            contract.ContractId.ShouldBe(TestData.ContractId);
            contract.Description.ShouldBe(TestData.ContractDescription);
            contract.IsCreated.ShouldBeTrue();
            contract.OperatorId.ShouldBe(TestData.OperatorId);
        }
コード例 #19
0
        public void ContractAggregate_CreateRandomFromRequest()
        {
            //Arrange
            var request = AggregatesRequestBuilder.CreateRandomContractCreateRequest();

            //Act
            var contract = ContractAggregate.CreateFromRequest(request);

            // Assert
            contract.Title.Should().Be(request.Title);
            contract.DateStart.Should().Be(request.DateStart);
            contract.DateEnd.Should().Be(request.DateEnd);
            contract.Description.Should().Be(request.Description);
            contract.IsDeleted.Should().BeFalse();
        }
コード例 #20
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);
            });
        }
コード例 #21
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);
            });
        }
コード例 #22
0
        public void ContractAggregate_AddFixedValueProduct_ProductAdded()
        {
            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();

            products.Count.ShouldBe(1);
            products.First().ProductId.ShouldNotBe(Guid.Empty);
            products.First().Name.ShouldBe(TestData.ProductName);
            products.First().DisplayText.ShouldBe(TestData.ProductDisplayText);
            products.First().Value.ShouldBe(TestData.ProductFixedValue);
        }
コード例 #23
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);
        }
コード例 #24
0
        public async Task Add(ContractAggregate item)
        {
            await _context.Contracts.AddAsync(item);

            await _context.SaveChangesAsync();
        }
コード例 #25
0
 public async Task Update(ContractAggregate item)
 {
     _context.Contracts.Update(item);
     await _context.SaveChangesAsync();
 }
コード例 #26
0
        public void ContractAggregate_CanBeCreated_IsCreated()
        {
            ContractAggregate aggregate = ContractAggregate.Create(TestData.ContractId);

            aggregate.AggregateId.ShouldBe(TestData.ContractId);
        }