Exemplo n.º 1
0
        public ActionResult Serialisation(SerialisationViewModel serialisationVM)
        {
            var serialisationService = new ImportExportDataService(_restaurantService);

            try {
                if (serialisationVM.IsImport)
                {
                    //Check if file exists
                    var fileInfo = new System.IO.FileInfo(serialisationVM.Path);
                    serialisationService.ImportData(serialisationVM.Path);
                }
                else
                {
                    serialisationService.ExportData(serialisationVM.Path);
                }
                return(RedirectToAction(nameof(Index)));
            } catch (Exception e)
            {
                serialisationVM.Error = e.Message;
                return(View(serialisationVM));
            }
        }
        public void ExportData_TakeARestaurantService_JsonCreatedAndNotEmpty()
        {
            //Arrange
            string resultFromJson;

            var mockRestaurantService = new Mock <IRestaurantService>();

            mockRestaurantService.Setup(x => x.GetAll()).Returns(restaurantsDb);

            var importExportData = new ImportExportDataService(mockRestaurantService.Object);

            //Act
            importExportData.ExportData(filePath);

            using (var streamReader = new StreamReader(filePath))
            {
                resultFromJson = streamReader.ReadToEnd();
            }

            //Assert
            Assert.IsNotNull(resultFromJson);
        }