/// <summary>
        /// Adds the transaction fee.
        /// </summary>
        /// <param name="product">The product.</param>
        /// <param name="transactionFeeId">The transaction fee 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>
        /// <exception cref="InvalidOperationException">Product Id {product.ProductId} is not a valid product on this contract</exception>
        /// <exception cref="System.InvalidOperationException">Product Id {productId} is not a valid product on this contract</exception>
        public void AddTransactionFee(Product product,
                                      Guid transactionFeeId,
                                      String description,
                                      CalculationType calculationType,
                                      FeeType feeType,
                                      Decimal value)
        {
            Guard.ThrowIfInvalidGuid(transactionFeeId, typeof(ArgumentNullException), "Transaction Fee Id cannot be an empty Guid");
            Guard.ThrowIfNull(product, typeof(ArgumentNullException), "Product to add fee for cannot be null");
            Guard.ThrowIfNullOrEmpty(description, typeof(ArgumentNullException), "Transaction Fee description must not be null or empty");
            Guard.ThrowIfZero(value, typeof(ArgumentOutOfRangeException), "Transaction Fee value cannot be zero");
            Guard.ThrowIfNegative(value, typeof(ArgumentOutOfRangeException), "Transaction Fee value cannot be negative");

            if (this.Products.Any(p => p.ProductId == product.ProductId) == false)
            {
                throw new InvalidOperationException($"Product Id {product.ProductId} is not a valid product on this contract");
            }

            Guard.ThrowIfInvalidEnum(typeof(CalculationType), calculationType, nameof(calculationType));
            Guard.ThrowIfInvalidEnum(typeof(FeeType), feeType, nameof(feeType));

            TransactionFeeForProductAddedToContractEvent transactionFeeForProductAddedToContractEvent =
                new TransactionFeeForProductAddedToContractEvent(this.AggregateId, this.EstateId, product.ProductId, transactionFeeId, description, (Int32)calculationType, (Int32)feeType, value);

            this.ApplyAndAppend(transactionFeeForProductAddedToContractEvent);
        }
        public void ContractDomainEventHandler_TransactionFeeForProductAddedToContractEvent_EventIsHandled()
        {
            TransactionFeeForProductAddedToContractEvent transactionFeeForProductAddedToContractEvent = TestData.TransactionFeeForProductAddedToContractEvent;

            Mock <IEstateReportingRepository> estateReportingRepository = new Mock <IEstateReportingRepository>();

            ContractDomainEventHandler eventHandler = new ContractDomainEventHandler(estateReportingRepository.Object);

            Logger.Initialise(NullLogger.Instance);

            Should.NotThrow(async() => { await eventHandler.Handle(transactionFeeForProductAddedToContractEvent, CancellationToken.None); });
        }
        /// <summary>
        /// Plays the event.
        /// </summary>
        /// <param name="domainEvent">The domain event.</param>
        private void PlayEvent(TransactionFeeForProductAddedToContractEvent domainEvent)
        {
            // Find the product
            Product product = this.Products.Single(p => p.ProductId == domainEvent.ProductId);

            product.TransactionFees.Add(new TransactionFee
            {
                Description      = domainEvent.Description,
                CalculationType  = (Models.Contract.CalculationType)domainEvent.CalculationType,
                TransactionFeeId = domainEvent.TransactionFeeId,
                Value            = domainEvent.Value,
                IsEnabled        = true,
                FeeType          = (Models.Contract.FeeType)domainEvent.FeeType
            });
        }
        public void TransactionFeeForProductAddedToContractEvent_CanBeCreated_IsCreated(CalculationType calculationType, FeeType feeType)
        {
            TransactionFeeForProductAddedToContractEvent transactionFeeForProductAddedToContractEvent = new TransactionFeeForProductAddedToContractEvent(TestData.ContractId,
                                                                                                                                                         TestData.EstateId,
                                                                                                                                                         TestData.ProductId,
                                                                                                                                                         TestData.TransactionFeeId,
                                                                                                                                                         TestData.TransactionFeeDescription,
                                                                                                                                                         (Int32)calculationType,
                                                                                                                                                         (Int32)feeType,
                                                                                                                                                         TestData.TransactionFeeValue);

            transactionFeeForProductAddedToContractEvent.ShouldNotBeNull();
            transactionFeeForProductAddedToContractEvent.AggregateId.ShouldBe(TestData.ContractId);
            transactionFeeForProductAddedToContractEvent.EventId.ShouldNotBe(Guid.Empty);
            transactionFeeForProductAddedToContractEvent.ContractId.ShouldBe(TestData.ContractId);
            transactionFeeForProductAddedToContractEvent.EstateId.ShouldBe(TestData.EstateId);
            transactionFeeForProductAddedToContractEvent.ProductId.ShouldBe(TestData.ProductId);
            transactionFeeForProductAddedToContractEvent.TransactionFeeId.ShouldBe(TestData.TransactionFeeId);
            transactionFeeForProductAddedToContractEvent.Description.ShouldBe(TestData.TransactionFeeDescription);
            transactionFeeForProductAddedToContractEvent.CalculationType.ShouldBe((Int32)calculationType);
            transactionFeeForProductAddedToContractEvent.FeeType.ShouldBe((Int32)feeType);
            transactionFeeForProductAddedToContractEvent.Value.ShouldBe(TestData.TransactionFeeValue);
        }
Beispiel #5
0
 /// <summary>
 /// Handles the specific domain event.
 /// </summary>
 /// <param name="domainEvent">The domain event.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 private async Task HandleSpecificDomainEvent(TransactionFeeForProductAddedToContractEvent domainEvent,
                                              CancellationToken cancellationToken)
 {
     await this.EstateReportingRepository.AddContractProductTransactionFee(domainEvent, cancellationToken);
 }