public async Task GetAllOrdersAsyncTest() { var options = new DbContextOptionsBuilder <OrdersDbContext>() .UseInMemoryDatabase(nameof(GetAllOrdersAsyncTest)) .Options; var dbContext = new OrdersDbContext(options); CreateOrders(dbContext); var orderProfile = new OrderProfile(); var configuration = new MapperConfiguration(config => config.AddProfile(orderProfile)); var mapper = new Mapper(configuration); var ordersProvider = new OrdersProvider(dbContext, null, mapper); var orders = await ordersProvider.GetOrdersAsync(1); Assert.IsNotNull(orders.Orders); Assert.IsTrue(orders.IsSuccess); Assert.IsNull(orders.ErrorMessage); }
public async Task GetOrdersReturnsAllOrdersByCustomerId() { var options = new DbContextOptionsBuilder <OrderDbContext>() .UseInMemoryDatabase(nameof(GetOrdersReturnsAllOrdersByCustomerId)) .Options; var dbContext = new OrderDbContext(options); //Mock Object for the mapper var orderProfile = new OrderProfile(); var configuration = new MapperConfiguration(cfg => cfg.AddProfile(orderProfile)); var mapper = new Mapper(configuration); var ordersProvider = new OrdersProvider(dbContext, null, mapper); var order = await ordersProvider.GetOrdersAsync(1); Assert.True(order.IsSuccess); Assert.True(order.Orders.Any()); Assert.Null(order.ErrorMessage); }
public async Task GetAllOrdersWdInvalidId() { var options = new DbContextOptionsBuilder <OrdersDbContext>() .UseInMemoryDatabase(nameof(GetAllOrdersWdValidId)) .Options; var dbContext = new OrdersDbContext(options); SeedData(dbContext); var ordersProfile = new OrderProfile(); var configuration = new MapperConfiguration(cfg => cfg.AddProfile(ordersProfile)); var mapper = new Mapper(configuration); var ordersProvider = new OrdersProvider(dbContext, null, mapper); var results = await ordersProvider.GetOrdersAsync(-1); Assert.False(results.IsSuccess); Assert.Null(results.Orders); Assert.NotNull(results.ErrorMessage); }