public async Task <PurchasingDispositionExpeditionModel> GetTestData()
        {
            PurchasingDispositionExpeditionModel model = GetNewData();
            await Service.CreateAsync(model);

            return(await Service.ReadByIdAsync(model.Id));
        }
        public async Task Should_Success_Delete_Acceptance_Cashier()
        {
            PurchasingDispositionExpeditionService service = new PurchasingDispositionExpeditionService(GetServiceProvider().Object, _dbContext(GetCurrentMethod()));
            var model = await _dataUtil(service).GetTestData();

            PurchasingDispositionAcceptanceViewModel data = new PurchasingDispositionAcceptanceViewModel()
            {
                Role = "CASHIER",
                PurchasingDispositionExpedition = new List <PurchasingDispositionAcceptanceItemViewModel>()
                {
                    new PurchasingDispositionAcceptanceItemViewModel()
                    {
                        DispositionNo = model.DispositionNo,
                        Id            = model.Id
                    }
                }
            };
            var acceptedResponse = await service.PurchasingDispositionAcceptance(data);

            var newModel = await service.ReadByIdAsync(model.Id);

            var deleteResponse = await service.DeletePurchasingDispositionAcceptance(newModel.Id);

            Assert.NotEqual(0, deleteResponse);
        }
Пример #3
0
        public async Task Should_Success_Generate_Excel()
        {
            var serviceProvider = new Mock <IServiceProvider>();

            serviceProvider
            .Setup(x => x.GetService(typeof(IHttpClientService)))
            .Returns(new HttpClientFromPurchasingDisposition());

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

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

            var postedModel = _dataUtil(service).GetNewData();
            HttpClientFromPurchasingDisposition httpClientFromPurchasingDisposition = new HttpClientFromPurchasingDisposition();

            postedModel.DispositionNo = httpClientFromPurchasingDisposition.GetPurchasingDispositionViewModel().DispositionNo;
            await service.CreateAsync(postedModel);

            var model = await service.ReadByIdAsync(postedModel.Id);

            var reportResponse = await service.GenerateExcelAsync(1, 25, "{}", "{}", null, null, 7);

            Assert.NotNull(reportResponse);
        }
        public async Task Update_Throws_NotImplementedException()
        {
            PurchasingDispositionExpeditionService service = new PurchasingDispositionExpeditionService(GetServiceProvider().Object, _dbContext(GetCurrentMethod()));
            PurchasingDispositionExpeditionModel   model   = await _dataUtil(service).GetTestData2();

            var newModel = await service.ReadByIdAsync(model.Id);

            await Assert.ThrowsAsync <NotImplementedException>(() => service.Update(newModel.Id, newModel, "", 7));
        }
        public async Task Should_Success_Get_Data_By_Id()
        {
            PurchasingDispositionExpeditionService service = new PurchasingDispositionExpeditionService(GetServiceProvider().Object, _dbContext(GetCurrentMethod()));
            PurchasingDispositionExpeditionModel   model   = await _dataUtil(service).GetTestData();

            var Response = await service.ReadByIdAsync(model.Id);

            Assert.NotNull(Response);
        }
        public async Task Should_Success_Delete_With_two_Datas()
        {
            PurchasingDispositionExpeditionService service = new PurchasingDispositionExpeditionService(GetServiceProvider().Object, _dbContext(GetCurrentMethod()));
            PurchasingDispositionExpeditionModel   model   = await _dataUtil(service).GetTestData2();

            var newModel = await service.ReadByIdAsync(model.Id);

            var Response = await service.DeleteAsync(newModel.Id);

            Assert.NotEqual(0, Response);
        }
        public async Task Should_Fail_Delete_Acceptance()
        {
            PurchasingDispositionExpeditionService service = new PurchasingDispositionExpeditionService(GetServiceProvider().Object, _dbContext(GetCurrentMethod()));
            var model = await _dataUtil(service).GetTestData();

            PurchasingDispositionAcceptanceViewModel data = new PurchasingDispositionAcceptanceViewModel()
            {
                Role = "CASHIER",
                PurchasingDispositionExpedition = new List <PurchasingDispositionAcceptanceItemViewModel>()
                {
                    new PurchasingDispositionAcceptanceItemViewModel()
                    {
                        DispositionNo = model.DispositionNo,
                        Id            = model.Id
                    }
                }
            };
            var acceptedResponse = await service.PurchasingDispositionAcceptance(data);

            var newModel = await service.ReadByIdAsync(model.Id);

            service = new PurchasingDispositionExpeditionService(GetServiceProviderWrongHttpClient().Object, _dbContext(GetCurrentMethod()));
            await Assert.ThrowsAnyAsync <Exception>(() => service.DeletePurchasingDispositionAcceptance(newModel.Id));
        }
        public async Task Should_Success_Generate_Excel()
        {
            var    serviceProvider = new Mock <IServiceProvider>();
            var    vm     = new HttpClientFromPurchasingDisposition().GetPurchasingDispositionViewModel();
            string vmJson = JsonConvert.SerializeObject(vm);
            PurchasingDispositionResponseViewModel response = new PurchasingDispositionResponseViewModel()
            {
                apiVersion = "1.0.0",
                data       = new List <PurchasingDispositionViewModel>()
                {
                    vm
                },
                info = new APIInfo()
                {
                    count = 1,
                    order = new
                    {
                        LastModifiedUtc = "asc"
                    },
                    page  = 1,
                    size  = 25,
                    total = 1,
                },
                message    = "OK",
                statusCode = "200"
            };
            string responseJson = JsonConvert.SerializeObject(response);

            //serviceProvider
            //    .Setup(x => x.GetService(typeof(IHttpClientService)))
            //    .Returns(new HttpClientFromPurchasingDisposition());

            serviceProvider
            .Setup(x => x.GetService(typeof(IIdentityService)))
            .Returns(new IdentityService()
            {
                Token = "Token", Username = "******", TimezoneOffset = 7
            });
            var httpClientService = new Mock <IHttpClientService>();

            httpClientService
            .Setup(x => x.GetAsync(It.Is <string>(s => s.Contains("purchasing-dispositions"))))
            .ReturnsAsync(new HttpResponseMessage()
            {
                Content = new StringContent(responseJson, Encoding.UTF8, "application/json"), StatusCode = HttpStatusCode.OK
            });
            httpClientService
            .Setup(x => x.GetAsync(It.Is <string>(s => s.Contains("external-purchase-orders"))))
            .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(new ExternalPurchaseOrderDataUtil().GetResultFormatterOkString())
            });
            httpClientService
            .Setup(x => x.GetAsync(It.Is <string>(s => s.Contains("unit-payment-orders"))))
            .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(new UnitPaymentOrderDataUtil().GetResultFormatterOkString())
            });
            httpClientService
            .Setup(x => x.PutAsync(It.Is <string>(s => s.Contains("purchasing-dispositions/update")), It.IsAny <HttpContent>()))
            .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK));


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

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

            var postedModel = _dataUtil(service).GetNewData();
            HttpClientFromPurchasingDisposition httpClientFromPurchasingDisposition = new HttpClientFromPurchasingDisposition();

            postedModel.DispositionNo = httpClientFromPurchasingDisposition.GetPurchasingDispositionViewModel().DispositionNo;
            await service.CreateAsync(postedModel);

            var model = await service.ReadByIdAsync(postedModel.Id);

            var reportResponse = await service.GenerateExcelAsync(1, 25, "{}", "{}", null, DateTimeOffset.UtcNow.AddDays(2), 7);

            Assert.NotNull(reportResponse);
        }