Ejemplo n.º 1
0
        public void ShouldBeAbleToStoreMultipleConflictsAndRetrieveUsingGetAll()
        {
            var sut = CreateSut();

            var bookOrderLineConflict1 = BookOrderLineQuantityConflict.CreateExisting(Guid.NewGuid(),
                                                                                      Guid.NewGuid(), Guid.NewGuid(), 1, true, DateTime.UtcNow);
            var bookOrderLineConflict2 = BookOrderLinePriceConflict.CreateExisting(Guid.NewGuid(),
                                                                                   Guid.NewGuid(), Guid.NewGuid(), 30.25M, false, DateTime.UtcNow);

            sut.Store(new BookOrderLineConflict[] { bookOrderLineConflict1, bookOrderLineConflict2 });

            var result = sut.Get();

            var storedConflict1 = result.Single(x => x.Id == bookOrderLineConflict1.Id);

            storedConflict1.BookOrderId.Should().Be(bookOrderLineConflict1.BookOrderId);
            storedConflict1.ConflictType.Should().Be(bookOrderLineConflict1.ConflictType);
            storedConflict1.BookOrderLineId.Should().Be(bookOrderLineConflict1.BookOrderLineId);
            storedConflict1.ConflictValue.Should().Be(bookOrderLineConflict1.ConflictValue);
            storedConflict1.Accepted.Should().Be(bookOrderLineConflict1.Accepted);

            var storedConflict2 = result.Single(x => x.Id == bookOrderLineConflict2.Id);

            storedConflict2.BookOrderId.Should().Be(bookOrderLineConflict2.BookOrderId);
            storedConflict2.ConflictType.Should().Be(bookOrderLineConflict2.ConflictType);
            storedConflict2.BookOrderLineId.Should().Be(bookOrderLineConflict2.BookOrderLineId);
            storedConflict2.ConflictValue.Should().Be(bookOrderLineConflict2.ConflictValue);
            storedConflict2.Accepted.Should().Be(bookOrderLineConflict2.Accepted);
        }
        internal static BookOrderLineConflict ToEntity(this BookOrderLineConflictDto dto)
        {
            if (dto.conflict_type.Equals("Quantity"))
            {
                int quantity = Convert.ToInt32(dto.Conflict_Value);
                return(BookOrderLineQuantityConflict.CreateExisting(dto.Id,
                                                                    dto.Order_Id,
                                                                    dto.Order_Line_Id, quantity, dto.Accepted,
                                                                    dto.Created_DateTime));
            }
            else if (dto.conflict_type.Equals("Price"))
            {
                decimal price = Convert.ToDecimal(dto.Conflict_Value);
                return(BookOrderLinePriceConflict.CreateExisting(
                           dto.Id, dto.Order_Id, dto.Order_Line_Id, price, dto.Accepted,
                           dto.Created_DateTime));
            }

            throw new ArgumentOutOfRangeException();
        }