public void IndexShouldRenderAllAvailableFilesWithProcessed()
        {
            var files = new List <FileInfo> {
                new FileInfo("path1"),
                new FileInfo("path2"),
                new FileInfo("path3")
            };
            var dataFile  = new DataFile(files.ElementAt(1).Name, (int)StatusHelper.Processing);
            var dataFiles = new List <DataFile> {
                dataFile
            };

            BatchController.PathHelper = PathHelperTest.Object;
            PathHelperTest.Setup(x => x.IsExistReceivingDirectory()).Returns(true);
            PathHelperTest.Setup(x => x.AvalaibleFiles()).Returns(files);
            FileRepositoryMock.Setup(x => x.FindAll()).Returns(dataFiles);

            ActionResult actual = BatchController.Index();

            Assert.IsInstanceOf(typeof(ViewResult), actual);
            var result      = actual as ViewResult;
            var resultModel = result.Model as FilesViewModel;

            Assert.AreEqual(3, resultModel.Files.Count);
            Assert.AreEqual("path1", resultModel.Files.ElementAt(0).Name);
            Assert.AreEqual("path3", resultModel.Files.ElementAt(2).Name);
            DataFileViewModel testedFile = resultModel.Files.ElementAt(1);

            Assert.AreEqual("path2", testedFile.Name);
            Assert.AreEqual((int)StatusHelper.Processing, testedFile.Status);
        }
        public ActionResult SaveAsJSON(DataFileViewModel data)
        {
            var model           = data;
            var formatedData    = FormatInputData(model);
            var rand            = new Random();
            var indexFormatFile = FormatFile.JSON;

            var currFile = Server.MapPath("~/Files/" + rand.Next().ToString() + "." + indexFormatFile.ToString());

            using (var file = System.IO.File.CreateText(currFile))
            {
                var serializer = new JsonSerializer();
                serializer.Serialize(file, formatedData);
                file.Close();
                return(SendFile(currFile, indexFormatFile));
            }
        }
        public IList FormatInputData(DataFileViewModel model)
        {
            IList[] returnedValue = new IList[2];
            returnedValue[0] = new List <EditBookViewModel>();
            returnedValue[1] = new List <EditNewsPaperViewModel>();

            for (int i = 0; i < model.CT.Length; i++)
            {
                if (model.CT[i] == "Book")
                {
                    var item = bookService.GetBook(model.CId[i]);
                    returnedValue[0].Add(item);
                }
                else
                {
                    var item = paperService.GetNewsPaper(model.CId[i]);
                    returnedValue[1].Add(item);
                }
            }
            return(returnedValue);
        }
        public FileResult SaveAsXML(DataFileViewModel data)
        {
            var model           = data;
            var formatedData    = FormatInputData(model);
            var rand            = new Random();
            var indexFormatFile = FormatFile.XML;

            var currFile = Server.MapPath("~/Files/" + rand.Next().ToString() + "." + indexFormatFile.ToString());

            using (var file = System.IO.File.CreateText(currFile))
            {
                var serializer = new XmlSerializer(typeof(List <EditBookViewModel>));
                serializer.Serialize(file, formatedData[0]);
            }
            using (var file = System.IO.File.AppendText(currFile))
            {
                var serializer = new XmlSerializer(typeof(List <EditNewsPaperViewModel>));
                serializer.Serialize(file, formatedData[1]);
            }
            return(SendFile(currFile, indexFormatFile));
        }