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(); }
/// <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); }
public void ContractAggregate_Create_InvalidDescription_ErrorThrown(String description) { ContractAggregate aggregate = ContractAggregate.Create(TestData.ContractId); Should.Throw <ArgumentNullException>(() => { aggregate.Create(TestData.EstateId, TestData.OperatorId, description); }); }
public void ContractAggregate_Create_InvalidOperatorId_ErrorThrown() { ContractAggregate aggregate = ContractAggregate.Create(TestData.ContractId); Should.Throw <ArgumentNullException>(() => { aggregate.Create(TestData.EstateId, Guid.Empty, TestData.ContractDescription); }); }
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); }); }
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); }); }
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); }); }
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); }); }
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(); }
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); }); }
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); }); }
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); }
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); }); }
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); }); }
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); }
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); }
public void ContractAggregate_CanBeCreated_IsCreated() { ContractAggregate aggregate = ContractAggregate.Create(TestData.ContractId); aggregate.AggregateId.ShouldBe(TestData.ContractId); }