Exemple #1
0
        public async Task Create_Success()
        {
            var serviceProvider = GetServiceProvider();

            var stockServiceMock = new Mock <IGarmentLeftoverWarehouseStockService>();

            stockServiceMock.Setup(s => s.StockIn(It.IsAny <GarmentLeftoverWarehouseStock>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>()))
            .ReturnsAsync(1);

            serviceProvider
            .Setup(x => x.GetService(typeof(IGarmentLeftoverWarehouseStockService)))
            .Returns(stockServiceMock.Object);

            serviceProvider
            .Setup(x => x.GetService(typeof(IHttpService)))
            .Returns(new HttpTestService());

            GarmentLeftoverWarehouseReceiptFabricService service = new GarmentLeftoverWarehouseReceiptFabricService(_dbContext(GetCurrentMethod()), serviceProvider.Object);

            var data = _dataUtil(service).GetNewData();

            var result = await service.CreateAsync(data);

            Assert.NotEqual(0, result);
        }
        public async Task <GarmentLeftoverWarehouseReceiptFabric> GetTestData()
        {
            GarmentLeftoverWarehouseReceiptFabric data = GetNewData();

            await Service.CreateAsync(data);

            return(data);
        }
        public async Task Should_Success_GetXlsReport()
        {
            var serviceProvider1 = GetServiceProvider();

            var stockServiceMock = new Mock <IGarmentLeftoverWarehouseStockService>();

            stockServiceMock.Setup(s => s.StockOut(It.IsAny <GarmentLeftoverWarehouseStock>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>()))
            .ReturnsAsync(1);

            stockServiceMock.Setup(s => s.StockIn(It.IsAny <GarmentLeftoverWarehouseStock>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>()))
            .ReturnsAsync(1);

            serviceProvider1
            .Setup(x => x.GetService(typeof(IGarmentLeftoverWarehouseStockService)))
            .Returns(stockServiceMock.Object);

            serviceProvider1
            .Setup(x => x.GetService(typeof(IHttpService)))
            .Returns(new HttpTestService());

            var serviceProvider = new Mock <IServiceProvider>();

            var httpClientService       = new Mock <IHttpService>();
            HttpResponseMessage message = new HttpResponseMessage(System.Net.HttpStatusCode.OK);

            message.Content = new StringContent("{\"apiVersion\":\"1.0\",\"statusCode\":200,\"message\":\"Ok\",\"data\":[{\"Id\":7,\"POSerialNumber\":\"PONo\",\"BeacukaiNo\":\"BC001\",\"CustomsType\":\"A\",\"BeacukaiDate\":\"2018/10/20\"}],\"info\":{\"count\":1,\"page\":1,\"size\":1,\"total\":2,\"order\":{\"date\":\"desc\"},\"select\":[\"Id\",\"CustomsType\",\"BeacukaiDate\",\"BeacukaiNo\",,\"POSerialNumber\"]}}");

            httpClientService
            .Setup(x => x.GetAsync(It.Is <string>(s => s.Contains("garment-beacukai/by-poserialnumber"))))
            .ReturnsAsync(message);

            serviceProvider
            .Setup(x => x.GetService(typeof(IIdentityService)))
            .Returns(new IdentityService()
            {
                Token = "Token", Username = "******"
            });

            serviceProvider
            .Setup(x => x.GetService(typeof(IHttpService)))
            .Returns(httpClientService.Object);


            GarmentLeftoverWarehouseReceiptFabricService service = new GarmentLeftoverWarehouseReceiptFabricService(_dbContext(GetCurrentMethod()), serviceProvider1.Object);
            ReceiptMonitoringService Reportservice = new ReceiptMonitoringService(_dbContext(GetCurrentMethod()), serviceProvider.Object);


            var dataFabric = _dataUtilFabric(service).GetNewData();

            dataFabric.ReceiptDate = dataFabric.ReceiptDate.AddDays(-1);

            await service.CreateAsync(dataFabric); dataFabric = await _dataUtilFabric(service).GetTestData();

            var result1 = Reportservice.GenerateExcelFabric(null, DateTime.Now, 7);

            Assert.NotNull(result1);
        }
Exemple #4
0
        public async Task Create_Error()
        {
            var serviceProvider = GetServiceProvider();

            var stockServiceMock = new Mock <IGarmentLeftoverWarehouseStockService>();

            stockServiceMock.Setup(s => s.StockIn(It.IsAny <GarmentLeftoverWarehouseStock>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>()))
            .ReturnsAsync(1);

            serviceProvider
            .Setup(x => x.GetService(typeof(IGarmentLeftoverWarehouseStockService)))
            .Returns(stockServiceMock.Object);

            serviceProvider
            .Setup(x => x.GetService(typeof(IHttpService)))
            .Returns(new HttpFailTestService());

            GarmentLeftoverWarehouseReceiptFabricService service = new GarmentLeftoverWarehouseReceiptFabricService(_dbContext(GetCurrentMethod()), serviceProvider.Object);

            var data = _dataUtil(service).GetNewData();

            await Assert.ThrowsAnyAsync <Exception>(() => service.CreateAsync(data));
        }