示例#1
0
        public static BookOrder Execute(IDbConnection connection, Guid id)
        {
            var bookOrderDto = connection.QueryFirstOrDefault <BookOrderDto>(
                "SELECT supplier, order_id, state FROM book_orders WHERE order_id = ?orderId",
                new { orderId = id });

            if (bookOrderDto == null)
            {
                return(null);
            }

            var orderLineDtos = connection.Query <OrderLineDto>(
                "SELECT order_line_id, " +
                "order_id," +
                "price, quantity, title FROM book_order_lines WHERE order_id = ?orderId",
                new { orderId = id });

            List <OrderLine> orderLines = new List <OrderLine>();

            foreach (var orderLineDto in orderLineDtos)
            {
                orderLines.Add(new OrderLine(
                                   orderLineDto.Title,
                                   orderLineDto.Price,
                                   orderLineDto.Quantity,
                                   orderLineDto.Order_Line_Id));
            }

            return(BookOrder.CreateExisting(bookOrderDto.Supplier,
                                            bookOrderDto.Order_Id,
                                            bookOrderDto.State,
                                            orderLines));
        }
示例#2
0
        public void Delete_ShouldRemoveAllBookOrders()
        {
            var sut = CreateSut();

            var bookOrder1 = BookOrder.CreateExisting("Foo", Guid.NewGuid(), BookOrderState.Sent,
                                                      new List <OrderLine>()
            {
                new OrderLine("Line1Book", 100M, 2, Guid.NewGuid())
            });
            var bookOrder2 = BookOrder.CreateExisting("Foo", Guid.NewGuid(), BookOrderState.New,
                                                      new List <OrderLine>()
            {
                new OrderLine("Line1Book", 200M, 3, Guid.NewGuid())
            });
            var bookOrder3 = BookOrder.CreateExisting("Baz", Guid.NewGuid(), BookOrderState.New,
                                                      new List <OrderLine>()
            {
                new OrderLine("Line1Book", 200M, 3, Guid.NewGuid())
            });

            sut.Store(bookOrder1);
            sut.Store(bookOrder2);
            sut.Store(bookOrder3);

            // act
            sut.Delete();

            // assert
            var bookOrders = sut.Get();

            bookOrders.Should().BeEmpty();
        }
示例#3
0
        public void GetBySupplierAndState_ShouldOnlyReturnExactMatches()
        {
            var sut = CreateSut();

            var bookOrder1 = BookOrder.CreateExisting("Foo", Guid.NewGuid(), BookOrderState.Sent,
                                                      new List <OrderLine>()
            {
                new OrderLine("Line1Book", 100M, 2, Guid.NewGuid())
            });
            var bookOrder2 = BookOrder.CreateExisting("Foo", Guid.NewGuid(), BookOrderState.New,
                                                      new List <OrderLine>()
            {
                new OrderLine("Line1Book", 200M, 3, Guid.NewGuid())
            });
            var bookOrder3 = BookOrder.CreateExisting("Baz", Guid.NewGuid(), BookOrderState.New,
                                                      new List <OrderLine>()
            {
                new OrderLine("Line1Book", 200M, 3, Guid.NewGuid())
            });

            sut.Store(bookOrder1);
            sut.Store(bookOrder2);
            sut.Store(bookOrder3);

            var results = sut.GetBySupplier("Foo", BookOrderState.New).ToList();

            results.Should().NotBeNull();
            results.Select(x => x.State).Should().OnlyContain(orderstate => orderstate == BookOrderState.New);
            results.Select(x => x.Supplier).Should().OnlyContain(supplier => supplier == "Foo");
        }
示例#4
0
        public void Get_ShouldReturnAllBookOrders()
        {
            var sut = CreateSut();

            var bookOrder1 = BookOrder.CreateExisting("Foo", Guid.NewGuid(), BookOrderState.Sent,
                                                      new List <OrderLine>()
            {
                new OrderLine("Line1Book", 100M, 2, Guid.NewGuid())
            });
            var bookOrder2 = BookOrder.CreateExisting("Foo", Guid.NewGuid(), BookOrderState.New,
                                                      new List <OrderLine>()
            {
                new OrderLine("Line1Book", 200M, 3, Guid.NewGuid())
            });
            var bookOrder3 = BookOrder.CreateExisting("Baz", Guid.NewGuid(), BookOrderState.New,
                                                      new List <OrderLine>()
            {
                new OrderLine("Line1Book", 200M, 3, Guid.NewGuid())
            });

            sut.Store(bookOrder1);
            sut.Store(bookOrder2);
            sut.Store(bookOrder3);

            var results = sut.Get().ToList();

            results.Should().NotBeNull();
            results.Count.Should().Be(3);
            results.ShouldBeEquivalentTo(
                new [] { bookOrder1, bookOrder2, bookOrder3 });
        }
示例#5
0
        public void Store_WhenBookOrderExists_ShouldUpdateBookOrder()
        {
            Guid bookOrderId = Guid.NewGuid();
            IEnumerable <OrderLine> orderLines = new List <OrderLine>()
            {
                new OrderLine("Line1Book", 100M, 2, Guid.NewGuid())
            };

            var bookOrder = BookOrder.CreateExisting("AcmeBooks", bookOrderId, BookOrderState.New,
                                                     orderLines);

            var sut = CreateSut();

            sut.Store(bookOrder);

            bookOrder.Approve();
            sut.Store(bookOrder);

            // assert
            var storedBookOrder = sut.Get(bookOrderId);

            storedBookOrder.Should().NotBeNull();
            storedBookOrder.Id.Should().Be(bookOrderId);
            storedBookOrder.OrderLines.ShouldBeEquivalentTo(bookOrder.OrderLines);
            storedBookOrder.State.Should().Be(BookOrderState.Approved);
            storedBookOrder.Supplier.Should().Be(bookOrder.Supplier);
        }
        public static IEnumerable <BookOrder> Execute(IDbConnection connection, string supplier = null,
                                                      BookOrderState?state = null)
        {
            DynamicParameters parameters = new DynamicParameters();
            var sqlStatement             =
                "SELECT supplier, order_id, state FROM book_orders ";

            var sqlConditional = "";

            if (supplier != null)
            {
                sqlConditional  = EvaluateSqlConditional(sqlConditional);
                sqlConditional += " supplier = ?supplier";
                parameters.Add("supplier", supplier);
            }

            if (state.HasValue)
            {
                sqlConditional  = EvaluateSqlConditional(sqlConditional);
                sqlConditional += " state = ?state";
                parameters.Add("state", state);
            }

            sqlStatement = sqlStatement + sqlConditional;

            var bookOrderDtos = connection.Query <BookOrderDto>(sqlStatement, parameters);

            List <BookOrder> bookOrders = new List <BookOrder>();

            foreach (var bookOrderDto in bookOrderDtos)
            {
                List <OrderLine> orderLines = new List <OrderLine>();
                var orderLineDtos           = connection.Query <OrderLineDto>(
                    "SELECT order_line_id, " +
                    "order_id," +
                    "price, quantity, title FROM book_order_lines WHERE order_id = ?orderId",
                    new { orderId = bookOrderDto.Order_Id });
                foreach (var orderLineDto in orderLineDtos)
                {
                    orderLines.Add(new OrderLine(
                                       orderLineDto.Title,
                                       orderLineDto.Price,
                                       orderLineDto.Quantity,
                                       orderLineDto.Order_Line_Id));
                }

                bookOrders.Add(BookOrder.CreateExisting(
                                   bookOrderDto.Supplier,
                                   bookOrderDto.Order_Id,
                                   bookOrderDto.State,
                                   orderLines));
            }

            return(bookOrders);
        }
        public static BookOrder ToDomain(this BookOrderDto dto)
        {
            BookOrderState   state      = dto.State.ToDomain();
            List <OrderLine> orderLines = new List <OrderLine>();

            foreach (var dtoOrderLine in dto.OrderLines)
            {
                orderLines.Add(new OrderLine(dtoOrderLine.Title, dtoOrderLine.Price, dtoOrderLine.Quantity, dtoOrderLine.Id));
            }
            return(BookOrder.CreateExisting(dto.Supplier, dto.Id, state, orderLines));
        }
示例#8
0
        public BookOrder Get(Guid orderId)
        {
            using (var connection = CreateConnection())
            {
                var bookOrderDto      = new GetBookOrderAction(connection).Execute(orderId);
                var bookOrderLineDtos = new GetBookOrderLinesAction(connection).Execute(bookOrderDto.Order_Id);

                List <OrderLine> lines = OrderLineFactory.CreateFrom(bookOrderLineDtos);

                var bookOrder = BookOrder.CreateExisting(
                    bookOrderDto.Supplier, bookOrderDto.State, bookOrderDto.Order_Id, lines);

                return(bookOrder);
            }
        }
示例#9
0
        public void GetBySupplierAndState_WhenNoMatchesForState_ShouldReturnEmptyList()
        {
            var sut        = CreateSut();
            var bookOrder1 = BookOrder.CreateExisting("Foo", Guid.NewGuid(), BookOrderState.Sent,
                                                      new List <OrderLine>()
            {
                new OrderLine("Line1Book", 100M, 2, Guid.NewGuid())
            });

            sut.Store(bookOrder1);

            var results = sut.GetBySupplier("Foo", BookOrderState.New).ToList();

            results.Should().BeEmpty();
        }
示例#10
0
        internal static BookOrder MapFrom(BookOrderDto retrieved)
        {
            List <OrderLine> orderLines = new List <OrderLine>();

            foreach (var orderLineDto in retrieved.OrderLines)
            {
                orderLines.Add(new OrderLine(
                                   orderLineDto.Title, orderLineDto.Price, orderLineDto.Quantity,
                                   orderLineDto.Id));
            }

            BookOrder bookOrder = BookOrder.CreateExisting(retrieved.Supplier, Guid.Parse(retrieved._id),
                                                           retrieved.State, orderLines);

            return(bookOrder);
        }
        public static IEnumerable <BookOrder> ToDomain(this IEnumerable <BookOrderDto> dtos)
        {
            List <BookOrder> bookOrders = new List <BookOrder>();

            foreach (var dto in dtos)
            {
                BookOrderState   state      = dto.State.ToDomain();
                List <OrderLine> orderLines = new List <OrderLine>();
                foreach (var dtoOrderLine in dto.OrderLines)
                {
                    orderLines.Add(new OrderLine(dtoOrderLine.Title, dtoOrderLine.Price, dtoOrderLine.Quantity, dtoOrderLine.Id));
                }

                bookOrders.Add(
                    BookOrder.CreateExisting(dto.Supplier, dto.Id, state, orderLines));
            }

            return(bookOrders);
        }
示例#12
0
        public void GetBySupplier_WhenBookOrdersForAllSuppliersExist_ShouldOnlyReturnBookOrdersForSupplier(string supplierToFilterBy)
        {
            var sut = CreateSut();

            Guid bookOrderId = Guid.NewGuid();
            IEnumerable <OrderLine> orderLines = new List <OrderLine>()
            {
                new OrderLine("Line1Book", 100M, 2, Guid.NewGuid())
            };

            var bookOrder = BookOrder.CreateExisting(supplierToFilterBy, bookOrderId, BookOrderState.New,
                                                     orderLines);

            sut.Store(bookOrder);

            var results = sut.GetBySupplier(supplierToFilterBy).ToList();

            results.Should().NotBeNull();
            results.Select(x => x.Supplier).Should().OnlyContain(y => y == supplierToFilterBy);
        }
示例#13
0
        public void GetBySupplier_ShouldIgnorePartialMatches()
        {
            var sut = CreateSut();

            var bookOrder1 = BookOrder.CreateExisting("Foo1", Guid.NewGuid(), BookOrderState.New,
                                                      new List <OrderLine>()
            {
                new OrderLine("Line1Book", 100M, 2, Guid.NewGuid())
            });
            var bookOrder2 = BookOrder.CreateExisting("Foo", Guid.NewGuid(), BookOrderState.New,
                                                      new List <OrderLine>()
            {
                new OrderLine("Line1Book", 200M, 3, Guid.NewGuid())
            });

            sut.Store(bookOrder1);
            sut.Store(bookOrder2);

            var results = sut.GetBySupplier("Foo").ToList();

            results.Select(x => x.Supplier).Should().OnlyContain(y => y == "Foo");
        }
示例#14
0
        public void GetByState_ShouldOnlyReturnMatchesForState()
        {
            var sut = CreateSut();

            var bookOrder1 = BookOrder.CreateExisting("Foo", Guid.NewGuid(), BookOrderState.Sent,
                                                      new List <OrderLine>()
            {
                new OrderLine("Line1Book", 100M, 2, Guid.NewGuid())
            });
            var bookOrder2 = BookOrder.CreateExisting("Foo", Guid.NewGuid(), BookOrderState.New,
                                                      new List <OrderLine>()
            {
                new OrderLine("Line1Book", 200M, 3, Guid.NewGuid())
            });

            sut.Store(bookOrder1);
            sut.Store(bookOrder2);

            var results = sut.GetByState(BookOrderState.Sent).ToList();

            results.Should().NotBeNull();
            results.Select(x => x.State).Should().OnlyContain(orderstate => orderstate == BookOrderState.Sent);
        }
 protected override void DoHandle(BookOrderCreatedEvent ev, BookOrderResult result)
 {
     result.BookOrder = BookOrder.CreateExisting(ev.Supplier, BookOrderState.New, ev.Id,
                                                 new List <OrderLine>());
 }