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());
        }
Esempio n. 3
0
        public void ImportFileWithInvalidFormatThrowsException()
        {
            var importLogic = CreateImportLogic();
            var input       = new ImportLodgingModel
            {
                Format = "Json",
                File   = CreateFormFile("invalid json")
            };

            importLogic.Import(input);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 6
0
        public void TestInitialize()
        {
            var fileMock = new Mock <IFormFile>();

            ImportLodgingModel = new ImportLodgingModel
            {
                Format = "Json",
                File   = fileMock.Object
            };

            ImportLogicMock = new Mock <IImportLogic>();
        }
Esempio n. 7
0
        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"
                    )
            };
        }
Esempio n. 9
0
        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());
 }