示例#1
0
        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 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);
        }
示例#3
0
        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 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 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 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);
        }
示例#8
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 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);
        }