public async Task TestCreateOrderAsync() { // Arrange var logger = LoggingHelper.GetLogger <SalesController>(); var service = ServiceMocker.GetSalesService(nameof(TestCreateOrderAsync)); var controller = new SalesController(logger, service); var model = new OrderHeaderRequest { CustomerID = 1, PaymentMethodID = new Guid("7671A4F7-A735-4CB7-AAB4-CF47AE20171D"), Comments = "Order from unit tests", CreationUser = "******", CreationDateTime = DateTime.Now, Details = new List <OrderDetailRequest> { new OrderDetailRequest { ProductID = 1, ProductName = "The King of Fighters XIV", Quantity = 1, } } }; // Act var response = await controller.CreateOrderAsync(model) as ObjectResult; var value = response.Value as ISingleResponse <OrderHeader>; service.Dispose(); // Assert Assert.False(value.DidError); Assert.True(value.Model.OrderHeaderID.HasValue); }
public async Task TestPostOrderAsync() { // Arrange var dbContext = DbContextMocker.GetStoreDbContext(nameof(TestPostOrderAsync)); var service = ServiceMocker.GetSalesService(dbContext); var controller = new SalesController(service, null); var request = new PlaceOrderRequest { Details = new List <PlaceOrderDetailRequest> { new PlaceOrderDetailRequest { ProductID = 1000, Quantity = 1 } } }; controller.MockControllerContext(); // Act var response = await controller.PostOrderAsync(request) as ObjectResult; var value = response.Value as IResponse; service.Dispose(); // Assert Assert.False(value?.DidError); }
public async Task TestAddProductAsync() { // Arrange var dbContext = DbContextMocker.GetStoreDbContext(nameof(TestAddProductAsync)); var service = ServiceMocker.GetWarehouseService(dbContext); var controller = new WarehouseController(service, null); var request = new AddProductRequest { ProductID = 100, ProductName = "Coca Cola Zero 24 fl Oz Bottle Special Edition", ProductDescription = "Enjoy Coca-Cola’s crisp.", Price = 2.15m }; controller.MockControllerContext(); // Act var response = await controller.AddProductAsync(request) as ObjectResult; var value = response.Value as ISingleResponse <AddProductRequest>; service.Dispose(); // Assert Assert.False(value?.DidError); }
public async Task TestPostOrderAsync() { // Arrange var userInfo = IdentityMocker.GetCustomerIdentity().GetUserInfo(); var service = ServiceMocker.GetSalesService(userInfo, nameof(TestPostOrderAsync), true); var identityClient = new MockedRothschildHouseIdentityClient(); var paymentClient = new MockedRothschildHousePaymentClient(); var controller = new SalesController(null, identityClient, paymentClient, service); var request = new PostOrderRequest { ID = 2, CustomerID = 1, PaymentMethodID = new Guid("7671A4F7-A735-4CB7-AAB4-CF47AE20171D"), CurrencyID = "USD", Comments = "Order from unit tests", Details = new List <OrderDetailRequest> { new OrderDetailRequest { ID = 2, ProductID = 1, Quantity = 1 } } }; // Act var response = await controller.PostOrderAsync(request) as ObjectResult; var value = response.Value as ISingleResponse <OrderHeader>; // Assert Assert.False(value.DidError); Assert.True(value.Model.ID.HasValue); }
public async Task TestCreateOrderAsync() { // Arrange var userInfo = IdentityMocker.GetCustomerIdentity().GetUserInfo(); var service = ServiceMocker.GetSalesService(userInfo, nameof(TestCreateOrderAsync)); var controller = new SalesController(LoggingHelper.GetLogger <SalesController>(), service); var request = new Requests.CreateOrderRequest { CustomerID = 1, PaymentMethodID = new Guid("7671A4F7-A735-4CB7-AAB4-CF47AE20171D"), CurrencyID = "USD", Comments = "Order from unit tests", Details = new List <OrderDetailRequest> { new OrderDetailRequest { ProductID = 1, Quantity = 1 } } }; // Act var response = await controller.CreateOrderAsync(request) as ObjectResult; var value = response.Value as ISingleResponse <OrderHeader>; service.Dispose(); // Assert Assert.False(value.DidError); Assert.True(value.Model.OrderHeaderID.HasValue); }
public async Task AddPlayerShouldCreateEntity() { var service = ServiceMocker.MockPlayerService(ServiceMocker.MockDbContext()); var players = await service.GetAllPlayersAsync(); Assert.NotEmpty(players); Assert.Equal("Javi", players.First().Name); }
public async Task AddPlayerShouldAddNewPlayer() { var service = ServiceMocker.MockGameService(ServiceMocker.MockDbContext()); var gameId = await service.CreateGameAsync(new Game()); await service.AddPlayerAsync(gameId, new Player { Name = "test" }); var game = await service.GetGameAsync(gameId); Assert.NotEmpty(game.Players); Assert.Equal("test", game.Players.First().Name); }
public async Task TestGetCreateOrderRequestAsync() { // Arrange var userInfo = IdentityMocker.GetCustomerIdentity().GetUserInfo(); var service = ServiceMocker.GetSalesService(userInfo, nameof(TestGetCreateOrderRequestAsync), true); var controller = new SalesController(null, null, null, service); // Act var response = await controller.GetPostOrderModelAsync() as ObjectResult; var value = response.Value as ISingleResponse <CreateOrderRequest>; // Assert Assert.False(value.DidError); }
public async Task CreateGameShouldAddNewGameToDb() { var service = ServiceMocker.MockGameService(ServiceMocker.MockDbContext()); var games = await service.GetAllGamesAsync(); Assert.Empty(games); await service.CreateGameAsync(new Game { Name = "test" }); games = await service.GetAllGamesAsync(); Assert.NotEmpty(games); Assert.Equal("test", games.First().Name); }
public async Task TestCloneOrderAsync() { // Arrange var userInfo = IdentityMocker.GetCustomerIdentity().GetUserInfo(); var service = ServiceMocker.GetSalesService(userInfo, nameof(TestCloneOrderAsync), true); var controller = new SalesController(null, null, null, service); var id = 1; // Act var response = await controller.CloneOrderAsync(id) as ObjectResult; var value = response.Value as ISingleResponse <OrderHeader>; // Assert Assert.False(value.DidError); }
public async Task TestSearchOrdersAsync() { // Arrange var userInfo = IdentityMocker.GetCustomerIdentity().GetUserInfo(); var service = ServiceMocker.GetSalesService(userInfo, nameof(TestSearchOrdersAsync), true); var controller = new SalesController(null, null, null, service); var request = new GetOrdersRequest(); // Act var response = await controller.GetOrdersAsync(request) as ObjectResult; var value = response.Value as IPagedResponse <OrderInfo>; // Assert Assert.False(value.DidError); }
public async Task TestGetOrdersAsync() { // Arrange var logger = LoggingHelper.GetLogger <SalesController>(); var service = ServiceMocker.GetSalesService(nameof(TestGetOrdersAsync)); var controller = new SalesController(logger, service); // Act var response = await controller.GetOrdersAsync() as ObjectResult; var value = response.Value as IPagedResponse <OrderInfo>; service.Dispose(); // Assert Assert.False(value.DidError); }
public async Task TestGetProductsAsync() { // Arrange var dbContext = DbContextMocker.GetStoreDbContext(nameof(TestGetProductsAsync)); var service = ServiceMocker.GetWarehouseService(dbContext); var controller = new WarehouseController(service, null); // Act var response = await controller.GetProductsAsync() as ObjectResult; var value = response.Value as IPagedResponse <Product>; service.Dispose(); // Assert Assert.False(value.DidError); Assert.True(value.Model.Count() > 0); }
public async Task TestGetNonExistingOrderAsync() { // Arrange var userInfo = IdentityMocker.GetCustomerIdentity().GetUserInfo(); var service = ServiceMocker.GetSalesService(userInfo, nameof(TestGetNonExistingOrderAsync)); var controller = new SalesController(LoggingHelper.GetLogger <SalesController>(), service); var id = 0; // Act var response = await controller.GetOrderAsync(id) as ObjectResult; var value = response.Value as ISingleResponse <OrderHeader>; service.Dispose(); // Assert Assert.False(value.DidError); }
public async Task TestGetProductsTestAsync() { // Arrange var logger = LoggingHelper.GetLogger <WarehouseController>(); var service = ServiceMocker.GetWarehouseService(nameof(TestGetProductsTestAsync)); var controller = new WarehouseController(logger, service); // Act var response = await controller.GetProductsAsync() as ObjectResult; var value = response.Value as IPagedResponse <Product>; service.Dispose(); // Assert Assert.False(value.DidError); Assert.True(value.Model.Count() > 0); }
public async Task GetProductsAsync() { // Arrange var userInfo = IdentityMocker.GetWarehouseOperatorIdentity().GetUserInfo(); var service = ServiceMocker.GetWarehouseService(userInfo, nameof(GetProductsAsync), true); var controller = new WarehouseController(null, service); var request = new GetProductsRequest(); // Act var response = await controller.GetProductsAsync(request) as ObjectResult; var value = response.Value as IPagedResponse <Product>; service.Dispose(); // Assert Assert.False(value.DidError); Assert.True(value.Model.Count() > 0); }
public async Task TestGetOrdersByEmployeeAsync() { // Arrange var logger = LoggingHelper.GetLogger <SalesController>(); var service = ServiceMocker.GetSalesService(nameof(TestGetOrdersByEmployeeAsync)); var controller = new SalesController(logger, service); var employeeID = 1; // Act var response = await controller.GetOrdersAsync(employeeID : employeeID) as ObjectResult; var value = response.Value as IPagedResponse <OrderInfo>; service.Dispose(); // Assert Assert.False(value.DidError); Assert.True(value.Model.Count(item => item.EmployeeID == employeeID) == value.Model.Count()); }
public async Task TestGetCreateOrderRequestAsync() { // Arrange var logger = LoggingHelper.GetLogger <SalesController>(); var service = ServiceMocker.GetSalesService(nameof(TestGetCreateOrderRequestAsync)); var controller = new SalesController(logger, service); // Act var response = await controller.GetCreateOrderRequestAsync() as ObjectResult; var value = response.Value as ISingleResponse <CreateOrderRequest>; service.Dispose(); // Assert Assert.False(value.DidError); Assert.True(value.Model.Products.Count() > 0); Assert.True(value.Model.Customers.Count() > 0); }
public async Task TestGetOrdersByCustomerAsync() { // Arrange var userInfo = IdentityMocker.GetCustomerIdentity().GetUserInfo(); var service = ServiceMocker.GetSalesService(userInfo, nameof(TestGetOrdersByCustomerAsync)); var controller = new SalesController(LoggingHelper.GetLogger <SalesController>(), service); var customerID = 1; // Act var response = await controller.GetOrdersAsync(customerID : customerID) as ObjectResult; var value = response.Value as IPagedResponse <OrderInfo>; service.Dispose(); // Assert Assert.False(value.DidError); Assert.True(value.Model.Count(item => item.CustomerID == customerID) == value.Model.Count()); }
public async Task TestGetCreateOrderRequestAsync() { // Arrange var userInfo = IdentityMocker.GetCustomerIdentity().GetUserInfo(); var service = ServiceMocker.GetSalesService(userInfo, nameof(TestGetCreateOrderRequestAsync)); var controller = new SalesController(LoggingHelper.GetLogger <SalesController>(), service); // Act var response = await controller.GetCreateOrderRequestAsync() as ObjectResult; var value = response.Value as ISingleResponse <Core.BusinessLayer.Requests.CreateOrderRequest>; service.Dispose(); // Assert Assert.False(value.DidError); Assert.True(value.Model.Products.Count() > 0); Assert.True(value.Model.Customers.Count() > 0); }
public async Task TestLikeProductAsync() { // Arrange var dbContext = DbContextMocker.GetStoreDbContext(nameof(TestLikeProductAsync)); var service = ServiceMocker.GetWarehouseService(dbContext); var controller = new WarehouseController(service, null); var id = 1000; controller.MockControllerContext(); // Act var response = await controller.LikeProductAsync(id) as ObjectResult; var value = response.Value as IResponse; service.Dispose(); // Assert Assert.False(value?.DidError); }
public async Task TestGetInventoryByProductTestAsync() { // Arrange var userInfo = IdentityMocker.GetWarehouseOperatorIdentity().GetUserInfo(); var service = ServiceMocker.GetWarehouseService(userInfo, nameof(TestGetInventoryByProductTestAsync), true); var controller = new WarehouseController(LoggingHelper.GetLogger <WarehouseController>(), service); var productID = 1; var locationID = "W01"; // Act var response = await controller.GetProductInventoryAsync(productID, locationID) as ObjectResult; var value = response.Value as IListResponse <ProductInventory>; service.Dispose(); // Assert Assert.False(value.DidError); Assert.True(value.Model.Count() > 0); }
public async Task TestGetInventoryByProductTestAsync() { // Arrange var logger = LoggingHelper.GetLogger <WarehouseController>(); var service = ServiceMocker.GetWarehouseService(nameof(TestGetInventoryByProductTestAsync)); var controller = new WarehouseController(logger, service); var productID = 1; var warehouseID = "W0001"; // Act var response = await controller.GetProductInventoryAsync(productID, warehouseID) as ObjectResult; var value = response.Value as IListResponse <ProductInventory>; service.Dispose(); // Assert Assert.False(value.DidError); Assert.True(value.Model.Count() > 0); }
public async Task PutProductUnitPriceAsync() { // Arrange var userInfo = IdentityMocker.GetWarehouseOperatorIdentity().GetUserInfo(); var service = ServiceMocker.GetWarehouseService(userInfo, nameof(PutProductUnitPriceAsync)); var controller = new WarehouseController(null, service); var id = 1; var request = new PutProductUnitPriceRequest { UnitPrice = 14.99m }; // Act var response = await controller.PutProductUnitPriceAsync(id, request) as ObjectResult; var value = response.Value as ISingleResponse <Product>; // Assert Assert.False(value.DidError); }
public async Task GetOrdersByEmployeeAsync() { // Arrange var userInfo = IdentityMocker.GetCustomerIdentity().GetUserInfo(); var service = ServiceMocker.GetSalesService(userInfo, nameof(GetOrdersByEmployeeAsync), true); var controller = new SalesController(null, null, null, service); var request = new GetOrdersRequest { EmployeeID = 1 }; // Act var response = await controller.GetOrdersAsync(request) as ObjectResult; var value = response.Value as IPagedResponse <OrderInfo>; // Assert Assert.False(value.DidError); Assert.True(value.Model.Count(item => item.EmployeeID == request.EmployeeID) == value.Model.Count()); }
public async Task PostProductAsync() { // Arrange var userInfo = IdentityMocker.GetWarehouseOperatorIdentity().GetUserInfo(); var service = ServiceMocker.GetWarehouseService(userInfo, nameof(PostProductAsync)); var controller = new WarehouseController(null, service); var request = new PostProductRequest { ProductName = "Test product", ProductCategoryID = 100, UnitPrice = 9.99m, Description = "unit tests" }; // Act var response = await controller.PostProductAsync(request) as ObjectResult; var value = response.Value as ISingleResponse <Product>; service.Dispose(); // Assert Assert.False(value.DidError); }