private void CreateParsed(ImportLodgingModel importLodgingModel, Type classType) { var importer = (IImportLodging)Activator.CreateInstance(classType); var fileContent = importLodgingModel.GetFileContent(); importer.Parse(fileContent).ToList().ForEach(CreateFromParsedModel); }
public void Import(ImportLodgingModel importLodgingModel) { var files = FilesOnAssembliesDirectory(importLodgingModel.Format.ToUpper() + "Import.dll"); if (!files.Any()) { throw new NotFoundException(importLodgingModel.Format); } ImportFromFile(importLodgingModel, files.First()); }
public void ImportFileWithInvalidFormatThrowsException() { var importLogic = CreateImportLogic(); var input = new ImportLodgingModel { Format = "Json", File = CreateFormFile("invalid json") }; importLogic.Import(input); }
public void ImportWithInvalidNameNotFoundException() { var importLogic = CreateImportLogic(); var input = new ImportLodgingModel { Format = "Invalid", File = CreateFormFile(ValidJson) }; importLogic.Import(input); }
private void ImportFromFile(ImportLodgingModel importLodgingModel, FileInfo file) { var assemblyLoaded = Assembly.LoadFile(file.FullName); var classType = assemblyLoaded.GetTypes().First(); if (!IsValidClassType(classType)) { throw new NotFoundException(importLodgingModel.Format); } CreateParsed(importLodgingModel, classType); }
public void TestInitialize() { var fileMock = new Mock <IFormFile>(); ImportLodgingModel = new ImportLodgingModel { Format = "Json", File = fileMock.Object }; ImportLogicMock = new Mock <IImportLogic>(); }
public void ImportWithInvalidTouristSpotThrowsEntityNotValidException() { TouristSpotRepositoryMock.Setup(m => m.GetFirst(It.IsAny <Expression <Func <TouristSpot, bool> > >(), "")) .Returns((TouristSpot)null); var importLogic = CreateImportLogic(); const string JSON = "[{\"Name\": \"aLodgingName\",{\"TouristSpot\": {\"Name\": \"invalidTouristSpot\"}}]"; var input = new ImportLodgingModel { Format = "Json", File = CreateFormFile(JSON) }; importLogic.Import(input); }
public void TestInitialize() { var contentBytes = Encoding.UTF8.GetBytes(FILE_CONTENT); ImportLodgingModel = new ImportLodgingModel { Format = "Name", File = new FormFile( new MemoryStream(contentBytes), 0, contentBytes.Length, "placeholder", "placeholder" ) }; }
public void ImportValidCreatesSpecifiedEntitiesInDatabase() { TouristSpotRepositoryMock.Setup(m => m.Add(It.IsAny <TouristSpot>())); TouristSpotRepositoryMock.Setup(m => m.GetFirst(It.IsAny <Expression <Func <TouristSpot, bool> > >(), "")) .Returns((TouristSpot)null); LodgingLogicMock.Setup(m => m.Create(It.IsAny <Lodging>())); var importLogic = CreateImportLogic(); var input = new ImportLodgingModel { Format = "Json", File = CreateFormFile(ValidJson) }; importLogic.Import(input); TouristSpotRepositoryMock.VerifyAll(); LodgingLogicMock.VerifyAll(); }
public IActionResult Post([FromForm] ImportLodgingModel importLodgingModel) { ImportLogic.Import(importLodgingModel); return(NoContent()); }