示例#1
0
        public bool UpdateProperties(string name,
                                     string description,
                                     decimal price,
                                     Dimensions dimensions,
                                     DateTime updateDispatchedFromOrigin)
        {
            //if last update is fresher than intended change queued,
            //then such action may invalid newest state
            if ((LastUpdatedAt ?? DateTime.MinValue) >= updateDispatchedFromOrigin)
            {
                return(false);
            }

            var isAllEqual = AllEqual(name, description, price, dimensions);

            if (isAllEqual)
            {
                return(false);
            }

            UpdateBasicProperties(name, description, price, dimensions);

            var @event = new ProductPropertiesChangedDomainEvent(Id, ManufacturerId, name, price, description, dimensions);

            AddDomainEvent(@event);
            return(true);
        }
示例#2
0
        public void Should_Initialize_Correctly()
        {
            //arrange
            Guid       productId      = Guid.NewGuid();
            string     name           = "eventName";
            string     description    = "description";
            decimal    price          = 999;
            Guid       manufacturerId = Guid.NewGuid();
            Dimensions dimensions     = new Dimensions(2, 4, 1, 3);

            //act
            var @event = new ProductPropertiesChangedDomainEvent(productId, manufacturerId, name, price, description, dimensions);

            //assert
            @event.ProductId.Should().Be(productId);
            @event.Name.Should().Be(name);
            @event.Price.Should().Be(price);
            @event.Manufacturer.Should().Be(manufacturerId);
            @event.Dimensions.Should().Be(dimensions);
        }
示例#3
0
        public void Should_UpdateProperties_UpdatedPropertiesAndRaisedProductPropertiesChangedDomainEvent()
        {
            //arrange
            var product       = GetProduct();
            var lastUpdatedAt = product.LastUpdatedAt;
            var lastUpdatedBy = product.LastUpdatedBy;
            var createdAt     = product.CreatedAt;
            var createdBy     = product.CreatedBy;

            string     newName        = "newName";
            string     newDescription = "newDescription";
            decimal    newPrice       = _price + 100;
            Dimensions newDimensions  = _dimensions;

            newDimensions.Height = _dimensions.Height + 5;
            newDimensions.Weight = _dimensions.Weight + 5;
            newDimensions.Length = _dimensions.Length + 5;
            newDimensions.Width  = _dimensions.Width + 5;
            DateTime dateTimeSent = DateTime.UtcNow;

            //act
            var isUpdated = product.UpdateProperties(newName,
                                                     newDescription,
                                                     newPrice,
                                                     newDimensions,
                                                     dateTimeSent);

            var productAddedDomainEvent = new ProductPropertiesChangedDomainEvent(
                product.Id,
                product.ManufacturerId,
                product.Name,
                product.Price,
                product.Description,
                product.Dimensions);

            var domainEvent         = JsonConvert.SerializeObject(product.DomainEvents.ElementAt(1));
            var expectedDomainEvent = JsonConvert.SerializeObject(productAddedDomainEvent);

            //assert
            isUpdated.Should().BeTrue();
            product.AggregateId.Should().Be(productAddedDomainEvent.ProductId);
            product.Id.Should().Be(productAddedDomainEvent.ProductId);
            product.Name.Should().Be(newName);
            product.Description.Should().Be(newDescription);
            product.BarCode.Should().Be(_barCode);
            product.Price.Should().Be(newPrice);
            product.Dimensions.Should().Be(newDimensions);
            product.ManufacturerId.Should().Be(_manufacturerId);
            product.CategoryId.Should().Be(_categoryId);
            product.Category.Should().BeNull();
            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));
        }