public void BeInitialized_GivenValidConstructor()
        {
            var basketAggregate = new BasketAggregate(AggregateId);

            basketAggregate.Id.Should().Be(AggregateId);
            basketAggregate.Items.Should().BeEmpty();
        }
Beispiel #2
0
 public static BasketResponse MapToDto(this BasketAggregate aggregate)
 {
     return(new BasketResponse()
     {
         Id = aggregate.Id,
         Items = aggregate.Items.Select(MapToDto).ToArray()
     });
 }
Beispiel #3
0
 public static BasketModel FromAggregate(BasketAggregate basket)
 {
     return(new BasketModel
     {
         Id = basket.AggregateId,
         OrderLines = basket.OrderLines.ToList(),
         State = basket.State
     });
 }
        public BasketControllerShould()
        {
            _repositoryMock  = new Mock <IBasketRepository>();
            _basketAggregate = new BasketAggregate(Id);
            _repositoryMock.Setup(r => r.Load(It.Is <string>(x => x == Id), It.IsAny <CancellationToken>()))
            .ReturnsAsync(_basketAggregate);

            _controller = new BasketControllerV1(_repositoryMock.Object);
        }
Beispiel #5
0
        public async Task Save(BasketAggregate basketAggregate, CancellationToken cancellationToken)
        {
            if (basketAggregate.HasBeenUpdated)
            {
                Cache.Set(basketAggregate.Id, basketAggregate);
            }

            await Task.CompletedTask;
        }
        public void BeIdempotent_WhenClearingEmptyBasket()
        {
            var basketAggregate = new BasketAggregate(AggregateId);

            basketAggregate.Apply(new ClearItemsCommand());

            basketAggregate.HasBeenUpdated.Should().BeFalse();
            basketAggregate.Items.Should().BeEmpty();
        }
        public void BeUpdated_WhenAddingNewItem()
        {
            var basketAggregate = new BasketAggregate(AggregateId);

            basketAggregate.Apply(_addItemCommand);

            basketAggregate.HasBeenUpdated.Should().BeTrue();
            basketAggregate.Items.Should()
            .ContainSingle(item => item.Quantity == 1)
            .And.AllBeEquivalentTo(_addItemCommand);
        }
        public void BeUpdated_WhenClearingBasketWithItems()
        {
            var basketAggregate = new BasketAggregate(AggregateId);

            basketAggregate.Apply(_addItemCommand);
            basketAggregate.HasBeenUpdated = false;

            basketAggregate.Apply(new ClearItemsCommand());

            basketAggregate.HasBeenUpdated.Should().BeTrue();
            basketAggregate.Items.Should().BeEmpty();
        }
        public void BeIdempotent_WhenRemovingNonExistingProduct()
        {
            var basketAggregate = new BasketAggregate(AggregateId);

            basketAggregate.Apply(new RemoveItemCommand
            {
                Sku = _addItemCommand.Sku
            });

            basketAggregate.HasBeenUpdated.Should().BeFalse();
            basketAggregate.Items.Should().NotContain(item => item.Sku == _addItemCommand.Sku);
        }
        public void BeUpdated_WhenUpdatingExistingItem()
        {
            var basketAggregate = new BasketAggregate(AggregateId);

            basketAggregate.Apply(_addItemCommand);
            basketAggregate.HasBeenUpdated = false;

            basketAggregate.Apply(_updateItemCommand);

            basketAggregate.HasBeenUpdated.Should().BeTrue();
            basketAggregate.Items.Should().ContainSingle(
                item => item.Sku == _addItemCommand.Sku && item.Quantity == _updateItemCommand.Quantity);
        }
        public void BeIdempotent_WhenAddingExistingItem()
        {
            var basketAggregate = new BasketAggregate(AggregateId);

            basketAggregate.Apply(_addItemCommand);
            basketAggregate.HasBeenUpdated = false;

            basketAggregate.Apply(_addItemCommand);

            basketAggregate.Items.Should()
            .ContainSingle(item => item.Quantity == 1);
            basketAggregate.HasBeenUpdated.Should().BeFalse();
        }
        public void BeIdempotent_WhenUpdatingToTheSameQuantity()
        {
            var basketAggregate = new BasketAggregate(AggregateId);

            basketAggregate.Apply(_addItemCommand);
            basketAggregate.Apply(_updateItemCommand);
            basketAggregate.HasBeenUpdated = false;

            basketAggregate.Apply(_updateItemCommand);

            basketAggregate.HasBeenUpdated.Should().BeFalse();
            basketAggregate.Items.Should().ContainSingle(
                item => item.Sku == _addItemCommand.Sku && item.Quantity == _updateItemCommand.Quantity);
        }
        public void ThrowException_WhenUpdatingNonExistingItem()
        {
            var basketAggregate = new BasketAggregate(AggregateId);

            basketAggregate.Apply(_addItemCommand);
            basketAggregate.HasBeenUpdated = false;

            Action action = () => basketAggregate.Apply(new UpdateItemCommand
            {
                Sku      = "54321",
                Quantity = 2
            });

            action.Should().Throw <BasketDoesNotContainProductException>();
        }
        public void BeUpdated_WhenRemovingAnExistingItem()
        {
            var basketAggregate = new BasketAggregate(AggregateId);

            basketAggregate.Apply(_addItemCommand);
            basketAggregate.HasBeenUpdated = false;

            basketAggregate.Apply(new RemoveItemCommand
            {
                Sku = _addItemCommand.Sku
            });

            basketAggregate.HasBeenUpdated.Should().BeTrue();
            basketAggregate.Items.Should().NotContain(item => item.Sku == _addItemCommand.Sku);
        }
Beispiel #15
0
        public static void Main(string[] args)
        {
            var basket          = new BasketAggregate(new Guid(), 3);
            var basketRepo      = basket.CreateRepository();
            var basketFromCache = basketRepo.Set(basket);

            Console.WriteLine(basketFromCache.Count);

            var product       = new ProductAggregate(new Guid(), "Sample");
            var productRepo   = product.CreateRepository();
            var productFromDb = productRepo.Set(product);

            Console.WriteLine(productFromDb.ProductName);

            Console.ReadKey();
        }