示例#1
0
        public void Excel_ReportAllTypeSuccess()
        {
            var serviceProvider21 = new Mock <IServiceProvider>();

            var httpClientService = new Mock <IHttpService>();

            httpClientService
            .Setup(x => x.GetAsync(It.Is <string>(s => s.Contains("garment-shipping/local-cover-letters"))))
            .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.InternalServerError)
            {
                Content = new StringContent(JsonConvert.SerializeObject(new List <Dictionary <string, Object> >()))
            });

            httpClientService
            .Setup(x => x.GetAsync(It.Is <string>(s => s.Contains("master/garmentProducts"))))
            .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.InternalServerError)
            {
                Content = new StringContent(JsonConvert.SerializeObject(new List <Dictionary <string, Object> >()))
            });


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

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

            GarmentLeftoverWarehouseReportExpenditureService service = new GarmentLeftoverWarehouseReportExpenditureService(serviceProvider21.Object, _dbContext(GetCurrentMethod()));



            var result = service.GenerateExcel(DateTime.Now.AddDays(-1), DateTime.Now, "", 1);

            Assert.IsType <MemoryStream>(result);
        }
示例#2
0
        public async Task GetReportFabric_Success()
        {
            var serviceProvider21 = new Mock <IServiceProvider>();

            var httpClientService = new Mock <IHttpService>();

            //httpClientService
            //    .Setup(x => x.GetAsync(It.Is<string>(s => s.Contains("garment-shipping/local-cover-letters"))))
            //    .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(JsonConvert.SerializeObject(new List<Dictionary<string, Object>>())) });

            //httpClientService
            //    .Setup(x => x.GetAsync(It.Is<string>(s => s.Contains("master/garmentProducts"))))
            //    .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(JsonConvert.SerializeObject(new List<Dictionary<string, Object>>())) });

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

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

            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\"]}}");

            HttpResponseMessage message2 = new HttpResponseMessage(System.Net.HttpStatusCode.OK);

            message2.Content = new StringContent("{\"apiVersion\":\"1.0\",\"statusCode\":200,\"message\":\"Ok\",\"data\":{\"Id\":\"7\",\"Composition\":\"Composition\",\"Const\":\"Const\",\"Yarn\":\"Yarn\",\"Width\":\"Width\"},\"info\":{\"count\":1,\"page\":1,\"size\":1,\"total\":2,\"order\":{\"date\":\"desc\"},\"select\":[\"Id\",\"CustomsType\",\"BeacukaiDate\",\"BeacukaiNo\",,\"POSerialNumber\"]}}");

            HttpResponseMessage message3 = new HttpResponseMessage(System.Net.HttpStatusCode.OK);

            message3.Content = new StringContent("{\"apiVersion\":\"1.0\",\"statusCode\":200,\"message\":\"Ok\",\"data\":[{\"Id\":\"7\",\"bcNo\":\"bcNo\",\"bcDate\":\"2018/10/20\",\"noteNo\":\"LocalSalesNoteNo\"}],\"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);

            httpClientService
            .Setup(x => x.GetAsync(It.Is <string>(s => s.Contains("master/garmentProducts"))))
            .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.InternalServerError)
            {
                Content = new StringContent(JsonConvert.SerializeObject(new List <Dictionary <string, Object> >()))
            });

            httpClientService
            .Setup(x => x.GetAsync(It.Is <string>(s => s.Contains("garment-shipping/local-cover-letters"))))
            .ReturnsAsync(message3);



            httpClientService
            .Setup(x => x.GetAsync(It.Is <string>(s => s.Contains("master/garmentProducts"))))
            .ReturnsAsync(message2);


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

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

            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);

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

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

            GarmentLeftoverWarehouseReportExpenditureService service = new GarmentLeftoverWarehouseReportExpenditureService(serviceProvider21.Object, _dbContext(GetCurrentMethod()));

            GarmentLeftoverWarehouseExpenditureFabricService serviceexpend = new GarmentLeftoverWarehouseExpenditureFabricService(_dbContext(GetCurrentMethod()), serviceProvider21.Object);


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

            await serviceexpend.CreateAsync(dataFabric);

            //GarmentLeftoverWarehouseReportExpenditureService service = new GarmentLeftoverWarehouseReportExpenditureService(serviceProvider21.Object,_dbContext(GetCurrentMethod()));

            var result = service.GetReport(DateTime.Now.AddDays(-1), DateTime.Now, "FABRIC", 1, 25, "{}", 1);

            Assert.NotNull(result);
        }