示例#1
0
        public void Should_Initialize_Correctly()
        {
            //arrange
            Guid    id            = Guid.NewGuid();
            decimal previousPrice = 999;
            decimal currentPrice  = 999;

            //act
            var @event = new ProductPriceChangedDomainEvent(id, previousPrice, currentPrice);

            //assert
            @event.ProductId.Should().Be(id);
            @event.PreviousPrice.Should().Be(previousPrice);
            @event.CurrentPrice.Should().Be(currentPrice);
        }
示例#2
0
        public void Should_ChangePrice_PriceChangedAndRaisedProductPriceChanged()
        {
            //arrange
            var     product       = GetProduct();
            decimal oldPrice      = _price;
            decimal newPrice      = _price + 100;
            var     lastUpdatedAt = product.LastUpdatedAt;
            var     lastUpdatedBy = product.LastUpdatedBy;
            var     createdAt     = product.CreatedAt;
            var     createdBy     = product.CreatedBy;

            //act
            product.ChangePrice(newPrice);

            var productAddedDomainEvent = new ProductPriceChangedDomainEvent(product.Id,
                                                                             oldPrice,
                                                                             newPrice);
            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(newPrice);
            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);
        }
示例#3
0
        public void ChangePrice(decimal price)
        {
            if (price < 0)
            {
                throw new DomainException("Price must not be below 0!");
            }

            if (price == Price)
            {
                return;
            }

            var previousPrice = Price;

            Price = price;

            var @event = new ProductPriceChangedDomainEvent(Id, previousPrice, Price);

            AddDomainEvent(@event);
        }