public void Publish() { if (IsPublished) { return; } IsPublished = true; var @event = new ProductPublishedDomainEvent(Id, Name, Price, ManufacturerId); AddDomainEvent(@event); }
public void Should_Initialize_Correctly() { //arrange Guid id = Guid.NewGuid(); string name = "eventName"; decimal price = 999; Guid manufacturerId = Guid.NewGuid(); //act var @event = new ProductPublishedDomainEvent(id, name, price, manufacturerId); //assert @event.ProductId.Should().Be(id); @event.Name.Should().Be(name); @event.Price.Should().Be(price); @event.Manufacturer.Should().Be(manufacturerId); }
public void Should_Publish_PublishedAndRaisedProductPublishedDomainEvent() { //arrange var product = GetProduct(); var lastUpdatedAt = product.LastUpdatedAt; var lastUpdatedBy = product.LastUpdatedBy; var createdAt = product.CreatedAt; var createdBy = product.CreatedBy; //act product.Publish(); var productAddedDomainEvent = new ProductPublishedDomainEvent(product.Id, product.Name, product.Price, product.ManufacturerId); var domainEvent = JsonConvert.SerializeObject(product.DomainEvents.ElementAt(1)); var expectedDomainEvent = JsonConvert.SerializeObject(productAddedDomainEvent); //assert product.AggregateId.Should().Be(productAddedDomainEvent.ProductId); product.Id.Should().Be(productAddedDomainEvent.ProductId); product.Name.Should().Be(_name); product.Description.Should().Be(_description); product.BarCode.Should().Be(_barCode); product.Price.Should().Be(_price); product.Dimensions.Should().Be(_dimensions); product.ManufacturerId.Should().Be(_manufacturerId); product.CategoryId.Should().Be(_categoryId); product.ExternalSourceName.Should().Be(_externalSourceName); product.ExternalId.Should().Be(_externalId); product.IsPublished.Should().BeTrue(); product.ProductType.Should().BeNull(); product.ProductTypeId.Should().Be(ProductType.SimpleProduct.Id); product.LastUpdatedAt.Should().NotBe(lastUpdatedAt ?? DateTime.UtcNow); expectedDomainEvent.Should().Be(domainEvent); product.LastUpdatedBy.Should().Be(lastUpdatedBy); product.CreatedAt.Should().Be(createdAt); product.CreatedBy.Should().Be(createdBy); product.AggregateTypeName.Should().Be(nameof(Domain.Entities.Product.Product)); }