Exemple #1
0
        public Product(string name,
                       decimal price,
                       string barCode,
                       string description,
                       Dimensions dimensions,
                       Guid manufacturerId,
                       Guid categoryId,
                       int productTypeId,
                       string externalSourceName,
                       string externalId) : this()
        {
            Name               = name;
            Price              = price;
            BarCode            = barCode;
            Description        = description;
            Dimensions         = dimensions;
            ManufacturerId     = manufacturerId;
            CategoryId         = categoryId;
            ProductTypeId      = productTypeId;
            ExternalSourceName = externalSourceName;
            ExternalId         = externalId;

            var @event = new ProductAddedDomainEvent(
                Id,
                Name,
                Price,
                ManufacturerId,
                categoryId,
                externalSourceName,
                externalId);

            AddDomainEvent(@event);
        }
Exemple #2
0
        public void Should_OnCreation_CorrectlyAssignArgumentsAndRaiseProductAddedDomainEvent()
        {
            //arrange
            //act
            var product       = GetProduct();
            var lastUpdatedAt = product.LastUpdatedAt;
            var lastUpdatedBy = product.LastUpdatedBy;
            var createdAt     = product.CreatedAt;
            var createdBy     = product.CreatedBy;

            var productAddedDomainEvent = new ProductAddedDomainEvent(
                product.Id,
                _name,
                _price,
                _manufacturerId,
                _categoryId,
                _externalSourceName,
                _externalId);

            var domainEvent         = JsonConvert.SerializeObject(product.DomainEvents.First());
            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);
            product.LastUpdatedBy.Should().Be(lastUpdatedBy);
            product.CreatedAt.Should().Be(createdAt);
            product.CreatedBy.Should().Be(createdBy);
            product.AggregateTypeName.Should().Be(nameof(Domain.Entities.Product.Product));
            expectedDomainEvent.Should().Be(domainEvent);
        }
Exemple #3
0
        public void Should_Initialize_Correctly()
        {
            //arrange
            Guid    id                 = Guid.NewGuid();
            string  name               = "eventName";
            decimal price              = 999;
            Guid    manufacturerId     = Guid.NewGuid();
            Guid    categoryId         = Guid.NewGuid();
            string  externalSourceName = "externalSourceName";
            string  externalId         = Guid.NewGuid().ToString();

            //act
            var @event = new ProductAddedDomainEvent(id, name, price, manufacturerId, categoryId, externalSourceName, externalId);

            //assert
            @event.ProductId.Should().Be(id);
            @event.Name.Should().Be(name);
            @event.Price.Should().Be(price);
            @event.Manufacturer.Should().Be(manufacturerId);
            @event.CategoryId.Should().Be(categoryId);
            @event.ExternalSourceName.Should().Be(externalSourceName);
            @event.ExternalId.Should().Be(externalId);
        }