public void UploadFile_WithException_FileNotFound()
        {
            string header     = "Kode, Nama,Path,Report Type,Nature,Cash Account";
            var    mockFacade = new Mock <ICOAService>();

            mockFacade.Setup(f => f.UploadData(It.IsAny <List <COAModel> >())).Verifiable();
            mockFacade.Setup(f => f.CsvHeader).Returns(header.Split(',').ToList());
            mockFacade.Setup(f => f.UploadValidate(ref It.Ref <List <COAViewModel> > .IsAny, It.IsAny <List <KeyValuePair <string, StringValues> > >())).Returns(new Tuple <bool, List <object> >(false, new List <object>()));
            COAProfile profile = new COAProfile();

            var mockMapper = new Mock <IMapper>();

            mockMapper.Setup(x => x.ConfigurationProvider).Returns(new MapperConfiguration(cfg => cfg.AddProfile(profile)));

            mockMapper.Setup(x => x.Map <List <COAModel> >(It.IsAny <List <COAViewModel> >())).Returns(new List <COAModel>()
            {
                Model
            });
            var mockIdentityService = new Mock <IIdentityService>();
            var mockValidateService = new Mock <IValidateService>();

            var controller = GetController((mockIdentityService, mockValidateService, mockFacade, mockMapper));

            controller.ControllerContext.HttpContext.Request.Headers["x-timezone-offset"] = $"{It.IsAny<int>()}";
            controller.ControllerContext.HttpContext.Request.Headers.Add("Content-Type", "multipart/form-data");
            var file = new FormFile(new MemoryStream(Encoding.UTF8.GetBytes(header + "\n" + header)), 0, Encoding.UTF8.GetBytes(header + "\n" + header).LongLength, "Data", "test.csv");

            controller.ControllerContext.HttpContext.Request.Form = new FormCollection(new Dictionary <string, StringValues>(), new FormFileCollection {
            });

            var response = controller.PostCSVFileAsync();

            Assert.Equal((int)HttpStatusCode.BadRequest, GetStatusCode(response.Result));
        }
Пример #2
0
        public void UploadFile_WithoutException_ReturnOK()
        {
            string header     = "Kode, Nama,Path,Report Type,Nature,Cash Account,Balance";
            string isi        = "2112.12.2.12, Nama,Path,Report Type,Nature,Cash Account, 1";
            var    mockFacade = new Mock <ICOAService>();

            mockFacade.Setup(f => f.UploadData(It.IsAny <List <COAModel> >())).Returns(Task.CompletedTask);
            mockFacade.Setup(f => f.CsvHeader).Returns(header.Split(',').ToList());

            mockFacade.Setup(f => f.UploadValidate(ref It.Ref <List <COAViewModel> > .IsAny, It.IsAny <List <KeyValuePair <string, StringValues> > >())).Returns(new Tuple <bool, List <object> >(true, new List <object>()));
            COAProfile profile = new COAProfile();

            var mockMapper = new Mock <IMapper>();

            mockMapper.Setup(x => x.ConfigurationProvider).Returns(new MapperConfiguration(cfg => cfg.AddProfile(profile)));
            var model = new COAModel()
            {
                Code        = "2112.12.2.12",
                Name        = "Nama",
                Path        = "Path",
                ReportType  = "report",
                Nature      = "nature",
                CashAccount = "cash"
            };

            mockMapper.Setup(x => x.Map <List <COAModel> >(It.IsAny <List <COAViewModel> >())).Returns(new List <COAModel>()
            {
                model
            });
            var mockIdentityService = new Mock <IIdentityService>();
            var mockValidateService = new Mock <IValidateService>();

            var controller = GetController((mockIdentityService, mockValidateService, mockFacade, mockMapper));

            controller.ControllerContext.HttpContext.Request.Headers["x-timezone-offset"] = $"{It.IsAny<int>()}";
            controller.ControllerContext.HttpContext.Request.Headers.Add("Content-Type", "multipart/form-data");
            var file = new FormFile(new MemoryStream(Encoding.UTF8.GetBytes(header + "\n" + isi)), 0, Encoding.UTF8.GetBytes(header + "\n" + isi).LongLength, "Data", "test.csv");

            controller.ControllerContext.HttpContext.Request.Form = new FormCollection(new Dictionary <string, StringValues>(), new FormFileCollection {
                file
            });

            var response = controller.PostCSVFileAsync();

            Assert.NotNull(response.Result);
        }