/// <summary> /// Plays the event. /// </summary> /// <param name="domainEvent">The domain event.</param> private void PlayEvent(FixedValueProductAddedToContractEvent domainEvent) { this.Products.Add(new Product { ProductId = domainEvent.ProductId, Name = domainEvent.ProductName, DisplayText = domainEvent.DisplayText, Value = domainEvent.Value }); }
public void ContractDomainEventHandler_FixedValueProductAddedToContractEvent_EventIsHandled() { FixedValueProductAddedToContractEvent fixedValueProductAddedToContractEvent = TestData.FixedValueProductAddedToContractEvent; Mock <IEstateReportingRepository> estateReportingRepository = new Mock <IEstateReportingRepository>(); ContractDomainEventHandler eventHandler = new ContractDomainEventHandler(estateReportingRepository.Object); Logger.Initialise(NullLogger.Instance); Should.NotThrow(async() => { await eventHandler.Handle(fixedValueProductAddedToContractEvent, CancellationToken.None); }); }
public void ProductAddedToContractEvent_CanBeCreated_IsCreated() { FixedValueProductAddedToContractEvent fixedValueProductAddedToContractEvent = new FixedValueProductAddedToContractEvent(TestData.ContractId, TestData.EstateId, TestData.ProductId, TestData.ProductName, TestData.ProductDisplayText, TestData.ProductFixedValue); fixedValueProductAddedToContractEvent.ShouldNotBeNull(); fixedValueProductAddedToContractEvent.AggregateId.ShouldBe(TestData.ContractId); fixedValueProductAddedToContractEvent.EventId.ShouldNotBe(Guid.Empty); fixedValueProductAddedToContractEvent.ContractId.ShouldBe(TestData.ContractId); fixedValueProductAddedToContractEvent.EstateId.ShouldBe(TestData.EstateId); fixedValueProductAddedToContractEvent.ProductId.ShouldBe(TestData.ProductId); fixedValueProductAddedToContractEvent.ProductName.ShouldBe(TestData.ProductName); fixedValueProductAddedToContractEvent.DisplayText.ShouldBe(TestData.ProductDisplayText); fixedValueProductAddedToContractEvent.Value.ShouldBe(TestData.ProductFixedValue); }
/// <summary> /// Adds the product. /// </summary> /// <param name="productId">The product identifier.</param> /// <param name="productName">Name of the product.</param> /// <param name="displayText">The display text.</param> /// <param name="value">The value.</param> /// <exception cref="System.InvalidOperationException">Product Name {productName} has already been added to the contract</exception> public void AddFixedValueProduct(Guid productId, String productName, String displayText, Decimal value) { Guard.ThrowIfInvalidGuid(productId, typeof(ArgumentNullException), "Product Id cannot be an empty Guid"); Guard.ThrowIfNullOrEmpty(productName, typeof(ArgumentNullException), "Product Name must not be null or empty"); Guard.ThrowIfNullOrEmpty(displayText, typeof(ArgumentNullException), "Product Display Text must not be null or empty"); Guard.ThrowIfZero(value, typeof(ArgumentOutOfRangeException), "Product value must not be zero"); Guard.ThrowIfNegative(value, typeof(ArgumentOutOfRangeException), "Product value must not be negative"); // Check product not already added if (this.Products.Any(p => p.Name == productName)) { throw new InvalidOperationException($"Product Name {productName} has already been added to the contract"); } FixedValueProductAddedToContractEvent fixedValueProductAddedToContractEvent = new FixedValueProductAddedToContractEvent(this.AggregateId, this.EstateId, productId, productName, displayText, value); this.ApplyAndAppend(fixedValueProductAddedToContractEvent); }
/// <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(FixedValueProductAddedToContractEvent domainEvent, CancellationToken cancellationToken) { await this.EstateReportingRepository.AddContractProduct(domainEvent, cancellationToken); }