public void ImportData_TakeARestaurantService_DatabaseIsPopulated()
        {
            //Arrange
            var result = new List <Restaurant>();

            var mockRestaurantService = new Mock <IRestaurantService>();

            mockRestaurantService
            .Setup(x => x.Create(It.IsAny <Restaurant>()))
            .Callback((Restaurant restaurant) => result.Add(restaurant));

            var importExportData = new ImportExportDataService(mockRestaurantService.Object);

            //Act
            importExportData.ImportData(filePath);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(7, result.Count());
        }
Ejemplo n.º 2
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));
            }
        }