Exemplo n.º 1
0
        public void Unpublish()
        {
            if (IsPublished == false)
            {
                return;
            }

            IsPublished = false;

            var @event = new ProductUnpublishedDomainEvent(Id, Name, Price, ManufacturerId);

            AddDomainEvent(@event);
        }
Exemplo n.º 2
0
        public void Should_Initialize_Correctly()
        {
            //arrange
            Guid    id             = Guid.NewGuid();
            string  name           = "eventName";
            decimal price          = 999;
            Guid    manufacturerId = Guid.NewGuid();

            //act
            var @event = new ProductUnpublishedDomainEvent(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);
        }
Exemplo n.º 3
0
        public void Should_UnPublish_UnpublishedAndRaisedProductPublishedDomainEvent()
        {
            //arrange
            var product       = GetProduct();
            var lastUpdatedAt = product.LastUpdatedAt;
            var lastUpdatedBy = product.LastUpdatedBy;
            var createdAt     = product.CreatedAt;
            var createdBy     = product.CreatedBy;

            //act
            product.Publish();
            product.Unpublish();

            var productAddedDomainEvent = new ProductUnpublishedDomainEvent(
                product.Id,
                product.Name,
                product.Price,
                product.ManufacturerId);

            var domainEvent         = JsonConvert.SerializeObject(product.DomainEvents.ElementAt(2));
            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().BeFalse();
            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));
        }