Example #1
0
        public void WhenSupplierRequestsDifferentQuantity_ShouldCreateBookOrderLineConflict()
        {
            var sut = CreateSut();

            BookOrder bookOrder = BookOrder.CreateNew(
                "SupplierBar",
                Guid.NewGuid());

            bookOrder.AddBookRequest(
                a.BookTitleOrder
                .ForSupplier("SupplierBar")
                .ForTitle("The Hobbit")
                .WithPrice(20)
                .WithQuantity(10)
                );

            _bookOrderRepository.Store(bookOrder);

            var supplierBookOrderUpdateRequest = new SupplierBookOrderUpdateRequest(
                bookOrder.Id,
                new List <SupplierBookOrderLineUpdateRequest>()
            {
                new SupplierBookOrderLineUpdateRequest(
                    bookOrder.OrderLines[0].Id,
                    price: 20, quantity: 9)
            });

            sut.Execute(supplierBookOrderUpdateRequest);

            List <BookOrderLineConflict> conflicts =
                _bookOrderLineConflictRepository.GetForBookOrder(bookOrder.Id).ToList();

            conflicts.Count().Should().Be(1);
            conflicts[0].ConflictType.Should().Be(ConflictType.Quantity);
        }
        public void WhenLineIsModified_ShouldStoreChanges()
        {
            var sut     = CreateSut();
            var orderId = Guid.NewGuid();
            var order   = BookOrder.CreateNew("SomeSupplier", orderId);

            order.AddBookRequest(new BookTitleOrder("Title1", "SomeSupplier", 10.5M, 5));
            order.AddBookRequest(new BookTitleOrder("Title2", "SomeSupplier", 20.5M, 7));

            sut.Store(order);

            var orderLineToUpdate = order.OrderLines[0];

            order.UpdateOrderLinePrice(orderLineToUpdate.Id, 99M);
            sut.Store(order);

            var bookOrder = sut.Get(orderId);

            bookOrder.Supplier.Should().Be("SomeSupplier");
            bookOrder.Id.Should().Be(orderId);
            bookOrder.State.Should().Be(BookOrderState.New);
            bookOrder.OrderLines.Count.Should().Be(2);
            bookOrder.OrderLines.Should().ContainSingle(
                x => x.Title.Equals("Title1") && x.Price == 99M && x.Quantity == 5);
            bookOrder.OrderLines.Should().ContainSingle(
                x => x.Title.Equals("Title2") && x.Price == 20.5M && x.Quantity == 7);
        }
        public Guid Execute(BookTitleRequest bookTitleRequest)
        {
            Logger.Information($"Execute {nameof(AddBookTitleRequestUseCase)} for Title: {{Title}}", bookTitleRequest.Title);

            IEnumerable <BookOrder> bookOrders = _bookOrderRepository.GetBySupplier(
                bookTitleRequest.Supplier, BookOrderState.New);
            var bookOrder = bookOrders.FirstOrDefault();

            if (bookOrder == null)
            {
                bookOrder = BookOrder.CreateNew(
                    bookTitleRequest.Supplier, Guid.NewGuid());
            }

            bookOrder.AddBookRequest(bookTitleRequest);

            _bookOrderRepository.Store(bookOrder);

            return(bookOrder.Id);
        }
        public void WhenLineIsRemoved_ShouldStoreChanges()
        {
            var sut     = CreateSut();
            var orderId = Guid.NewGuid();
            var order   = BookOrder.CreateNew("SomeSupplier", orderId);

            order.AddBookRequest(new BookTitleOrder("Title1", "SomeSupplier", 10.5M, 5));
            order.AddBookRequest(new BookTitleOrder("Title2", "SomeSupplier", 20.5M, 7));

            sut.Store(order);

            Guid orderLineId = order.OrderLines.Single(x => x.Title.Equals("Title1")).Id;

            order.RemoveOrderLine(orderLineId);

            sut.Store(order);

            var bookOrder = sut.Get(orderId);

            bookOrder.OrderLines.Count.Should().Be(1);
            bookOrder.OrderLines.Should().NotContain(x => x.Title.Equals("Title1"));
        }