public void Constructor_TakeARestaurantService_NotNull()
        {
            //Arrange
            var restaurantService = new RestaurantService();

            //Act
            var importExportData = new ImportExportDataService(restaurantService);

            //Assert
            Assert.IsNotNull(importExportData);
        }
        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());
        }
Exemplo n.º 3
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);
        }