Ejemplo n.º 1
0
        public Contracts.Order CreateOrder(Contracts.Order order)
        {
            var mappedDTOOrder = Mapper.Map <DTOs.Order>(order);
            var orderAdded     = InventoryAccessor.CreateOrder(mappedDTOOrder);

            return(Mapper.Map <Contracts.Order>(orderAdded));
        }
        public void InventoryAccessor_CreateOrder_ShouldSucceed()
        {
            // Arrange
            using var inventoryDbContext = InventoryDbContext;

            try
            {
                // Insert seed data into the database using one instance of the context
                AddCustomers(inventoryDbContext);

                var order = new DTOs.Order
                {
                    Name             = "French fries",
                    DateCreated      = DateTime.Now,
                    DateLastModified = DateTime.Now,
                    CustomerId       = 1
                };

                var inventoryAccessor = new InventoryAccessor(inventoryDbContext, Mapper);

                // Act
                var orderCreated = inventoryAccessor.CreateOrder(order);

                // Assert
                Assert.NotNull(orderCreated);
                Assert.Equal(order.Name, orderCreated.Name);
            }
            finally
            {
                inventoryDbContext.ChangeTracker
                .Entries()
                .ToList()
                .ForEach(e => e.State = EntityState.Detached);
                inventoryDbContext.Database.EnsureDeleted();
            }
        }