Skip to content

Commit

Permalink
Adding the form of importer of lodgings and improvement about guard o…
Browse files Browse the repository at this point in the history
…f authorization
  • Loading branch information
joaquinlamela committed Nov 25, 2020
1 parent 9847870 commit 64887f0
Show file tree
Hide file tree
Showing 24 changed files with 565 additions and 294 deletions.
8 changes: 4 additions & 4 deletions Uru_NaturalBooking/Importation/ReflectionLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public IEnumerable<IImport> GetAvailableImporters()
}
}

public List<Parameter> GetTheParametersRequired(string importerPath)
public List<Parameter> GetTheParametersRequired(string importerFileName)
{
List<Parameter> listOfParametersRequired = new List<Parameter>();
Assembly dll = Assembly.UnsafeLoadFrom(importerPath);
Assembly dll = Assembly.UnsafeLoadFrom(Directory.GetCurrentDirectory() + "\\" + importerFileName);

IEnumerable<Type> types = dll.GetTypes().Where(i => typeof(IImport).IsAssignableFrom(i));
foreach (Type type in types)
Expand All @@ -55,10 +55,10 @@ public List<Parameter> GetTheParametersRequired(string importerPath)
return listOfParametersRequired;
}

public List<LodgingModelForImport> ImportLodgings(string importerPath, List<Parameter> parameterValues)
public List<LodgingModelForImport> ImportLodgings(string importerFileName, List<Parameter> parameterValues)
{
List<LodgingModelForImport> lodgingToImport = new List<LodgingModelForImport>();
Assembly dll = Assembly.UnsafeLoadFrom(importerPath);
Assembly dll = Assembly.UnsafeLoadFrom(Directory.GetCurrentDirectory() + "\\"+importerFileName);

IEnumerable<Type> types = dll.GetTypes().Where(i => typeof(IImport).IsAssignableFrom(i));
foreach (Type type in types)
Expand Down
42 changes: 21 additions & 21 deletions Uru_NaturalBooking/ImportationTest/ReflectionLogicTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void GettingAvailablesImporterOk()
public void GetTheParametersOfJSONDllTestOk()
{
ReflectionLogic reflectionLogic = new ReflectionLogic();
List<Parameter> parametersOfImporterJson = reflectionLogic.GetTheParametersRequired(Directory.GetCurrentDirectory() + "\\Importers\\ImporterJson.dll");
List<Parameter> parametersOfImporterJson = reflectionLogic.GetTheParametersRequired( "\\Importers\\ImporterJson.dll");
JsonImporter importerJson = new JsonImporter();

CollectionAssert.AreEqual(importerJson.GetParameter(), parametersOfImporterJson);
Expand All @@ -38,7 +38,7 @@ public void GetTheParametersOfJSONDllTestOk()
public void GetTheParametersOfXmlDllTestOk()
{
ReflectionLogic reflectionLogic = new ReflectionLogic();
List<Parameter> parametersOfImporterXml = reflectionLogic.GetTheParametersRequired(Directory.GetCurrentDirectory() + "\\Importers\\ImporterXml.dll");
List<Parameter> parametersOfImporterXml = reflectionLogic.GetTheParametersRequired("\\Importers\\ImporterXml.dll");
XmlImporter importerXml = new XmlImporter();

CollectionAssert.AreEqual(importerXml.GetParameter(), parametersOfImporterXml);
Expand All @@ -49,16 +49,16 @@ public void GetTheParametersOfXmlDllTestOk()
public void FailInGetParametersOfJsonDllWithoutConstructorTest()
{
ReflectionLogic reflectionLogic = new ReflectionLogic();
List<Parameter> parametersOfImporterJson = reflectionLogic.GetTheParametersRequired(Directory.GetCurrentDirectory() + "\\ImporterWithoutConstructor\\ImporterJsonWithoutConstructor.dll");
List<Parameter> parametersOfImporterJson = reflectionLogic.GetTheParametersRequired( "\\ImporterWithoutConstructor\\ImporterJsonWithoutConstructor.dll");
}

[TestMethod]
public void ImportingLodgingsTestOfJsonDllOk()
{
ReflectionLogic reflectionLogic = new ReflectionLogic();
List<Parameter> listOfParameters = reflectionLogic.GetTheParametersRequired(Directory.GetCurrentDirectory() + "\\Importers\\ImporterJson.dll");
List<Parameter> listOfParameters = reflectionLogic.GetTheParametersRequired( "\\Importers\\ImporterJson.dll");
listOfParameters[0].Value = Directory.GetCurrentDirectory() + "\\FilesToImport\\Lodgings.json";
List<LodgingModelForImport> lodgingsImported = reflectionLogic.ImportLodgings(Directory.GetCurrentDirectory() + "\\Importers\\ImporterJson.dll", listOfParameters);
List<LodgingModelForImport> lodgingsImported = reflectionLogic.ImportLodgings( "\\Importers\\ImporterJson.dll", listOfParameters);

TouristSpotModelForImport touristSpotModel = new TouristSpotModelForImport()
{
Expand Down Expand Up @@ -90,7 +90,7 @@ public void ImportingLodgingsTestOfJsonDllOk()
public void ImportingLodgingsTestOfXmlDllOk()
{
ReflectionLogic reflectionLogic = new ReflectionLogic();
string pathOfXmlDll = Directory.GetCurrentDirectory() + "\\Importers\\ImporterXml.dll";
string pathOfXmlDll = "\\Importers\\ImporterXml.dll";
List<Parameter> listOfParameters = reflectionLogic.GetTheParametersRequired(pathOfXmlDll);
listOfParameters[0].Value = Directory.GetCurrentDirectory() + "\\FilesToImport\\Lodgings.xml";
List<LodgingModelForImport> lodgingsImported = reflectionLogic.ImportLodgings(pathOfXmlDll, listOfParameters);
Expand Down Expand Up @@ -125,18 +125,18 @@ public void ImportingLodgingsTestOfXmlDllOk()
public void FailInImportLodgingWithMoreParametersInJsonDllTest()
{
ReflectionLogic reflectionLogic = new ReflectionLogic();
List<Parameter> listOfParameters = reflectionLogic.GetTheParametersRequired(Directory.GetCurrentDirectory() + "\\Importers\\ImporterJson.dll");
List<Parameter> listOfParameters = reflectionLogic.GetTheParametersRequired("\\Importers\\ImporterJson.dll");
listOfParameters[0].Value = Directory.GetCurrentDirectory() + "\\FilesToImport\\Lodgings.json";
listOfParameters.Add(new Parameter());
reflectionLogic.ImportLodgings(Directory.GetCurrentDirectory() + "\\Importers\\ImporterJson.dll", listOfParameters);
reflectionLogic.ImportLodgings("\\Importers\\ImporterJson.dll", listOfParameters);
}

[TestMethod]
[ExpectedException(typeof(ImportationException))]
public void FailInImportLodgingWithMoreParametersInXmlDllTest()
{
ReflectionLogic reflectionLogic = new ReflectionLogic();
string pathOfXmlDll = Directory.GetCurrentDirectory() + "\\Importers\\ImporterXml.dll";
string pathOfXmlDll = "\\Importers\\ImporterXml.dll";
List<Parameter> listOfParameters = reflectionLogic.GetTheParametersRequired(pathOfXmlDll);
listOfParameters[0].Value = Directory.GetCurrentDirectory() + "\\FilesToImport\\Lodgings.xml";
listOfParameters.Add(new Parameter());
Expand All @@ -148,7 +148,7 @@ public void FailInImportLodgingWithMoreParametersInXmlDllTest()
public void FailInImportLodgingWithBadDllTest()
{
ReflectionLogic reflectionLogic = new ReflectionLogic();
string pathOfDll = Directory.GetCurrentDirectory() + "\\ImporterWithoutConstructor\\ImporterJsonWithoutConstructor.dll";
string pathOfDll = "\\ImporterWithoutConstructor\\ImporterJsonWithoutConstructor.dll";
List<Parameter> listOfParametersExpected = new List<Parameter>()
{
new Parameter()
Expand All @@ -166,7 +166,7 @@ public void FailInImportLodgingWithBadDllTest()
public void FailInImportLodgingWrongPathOfFileJsonDllTest()
{
ReflectionLogic reflectionLogic = new ReflectionLogic();
string pathOfDll = Directory.GetCurrentDirectory() + "\\Importers\\ImporterJson.dll";
string pathOfDll = "\\Importers\\ImporterJson.dll";
List<Parameter> listOfParametersExpected = new List<Parameter>()
{
new Parameter()
Expand All @@ -184,7 +184,7 @@ public void FailInImportLodgingWrongPathOfFileJsonDllTest()
public void FailInImportLodgingWrongPathOfFileXmlDllTest()
{
ReflectionLogic reflectionLogic = new ReflectionLogic();
string pathOfXmlDll = Directory.GetCurrentDirectory() + "\\Importers\\ImporterXml.dll";
string pathOfXmlDll = "\\Importers\\ImporterXml.dll";
List<Parameter> listOfParametersExpected = new List<Parameter>()
{
new Parameter()
Expand All @@ -202,7 +202,7 @@ public void FailInImportLodgingWrongPathOfFileXmlDllTest()
public void FailInImportLodgingEmptyPathOfFileJsonDllTest()
{
ReflectionLogic reflectionLogic = new ReflectionLogic();
string pathOfDll = Directory.GetCurrentDirectory() + "\\Importers\\ImporterJson.dll";
string pathOfDll = "\\Importers\\ImporterJson.dll";
List<Parameter> listOfParametersExpected = new List<Parameter>()
{
new Parameter()
Expand All @@ -220,7 +220,7 @@ public void FailInImportLodgingEmptyPathOfFileJsonDllTest()
public void FailInImportLodgingEmptyPathOfFileXmlDllTest()
{
ReflectionLogic reflectionLogic = new ReflectionLogic();
string pathOfXmlDll = Directory.GetCurrentDirectory() + "\\Importers\\ImporterXml.dll";
string pathOfXmlDll = "\\Importers\\ImporterXml.dll";
List<Parameter> listOfParametersExpected = new List<Parameter>()
{
new Parameter()
Expand All @@ -238,7 +238,7 @@ public void FailInImportLodgingEmptyPathOfFileXmlDllTest()
public void FailInImportLodgingNullPathOfFileJsonDllTest()
{
ReflectionLogic reflectionLogic = new ReflectionLogic();
string pathOfDll = Directory.GetCurrentDirectory() + "\\Importers\\ImporterJson.dll";
string pathOfDll = "\\Importers\\ImporterJson.dll";
List<Parameter> listOfParametersExpected = new List<Parameter>()
{
new Parameter()
Expand All @@ -256,7 +256,7 @@ public void FailInImportLodgingNullPathOfFileJsonDllTest()
public void FailInImportLodgingNullPathOfFileXmlDllTest()
{
ReflectionLogic reflectionLogic = new ReflectionLogic();
string pathOfXmlDll = Directory.GetCurrentDirectory() + "\\Importers\\ImporterXml.dll";
string pathOfXmlDll = "\\Importers\\ImporterXml.dll";
List<Parameter> listOfParametersExpected = new List<Parameter>()
{
new Parameter()
Expand All @@ -274,7 +274,7 @@ public void FailInImportLodgingNullPathOfFileXmlDllTest()
public void FailInImportLodgingWrongPathOfDirectoryJSONDllTest()
{
ReflectionLogic reflectionLogic = new ReflectionLogic();
string pathOfDll = Directory.GetCurrentDirectory() + "\\Importers\\ImporterJson.dll";
string pathOfDll = "\\Importers\\ImporterJson.dll";
List<Parameter> listOfParametersExpected = new List<Parameter>()
{
new Parameter()
Expand All @@ -292,7 +292,7 @@ public void FailInImportLodgingWrongPathOfDirectoryJSONDllTest()
public void FailInImportLodgingWrongPathOfDirectoryXMLDllTest()
{
ReflectionLogic reflectionLogic = new ReflectionLogic();
string pathOfXmlDll = Directory.GetCurrentDirectory() + "\\Importers\\ImporterXml.dll";
string pathOfXmlDll = "\\Importers\\ImporterXml.dll";
List<Parameter> listOfParametersExpected = new List<Parameter>()
{
new Parameter()
Expand All @@ -310,7 +310,7 @@ public void FailInImportLodgingWrongPathOfDirectoryXMLDllTest()
public void FailInImportLodgingWithErrorInJSONFileTest()
{
ReflectionLogic reflectionLogic = new ReflectionLogic();
string pathOfDll = Directory.GetCurrentDirectory() + "\\Importers\\ImporterJson.dll";
string pathOfDll = "\\Importers\\ImporterJson.dll";
List<Parameter> listOfParametersExpected = new List<Parameter>()
{
new Parameter()
Expand All @@ -328,7 +328,7 @@ public void FailInImportLodgingWithErrorInJSONFileTest()
public void FailInImportLodgingWithReadErrorInJSONFileTest()
{
ReflectionLogic reflectionLogic = new ReflectionLogic();
string pathOfDll = Directory.GetCurrentDirectory() + "\\Importers\\ImporterJson.dll";
string pathOfDll = "\\Importers\\ImporterJson.dll";
List<Parameter> listOfParametersExpected = new List<Parameter>()
{
new Parameter()
Expand All @@ -346,7 +346,7 @@ public void FailInImportLodgingWithReadErrorInJSONFileTest()
public void FailInImportLodgingWithInvalidOperationInXMLFileTest()
{
ReflectionLogic reflectionLogic = new ReflectionLogic();
string pathOfXmlDll = Directory.GetCurrentDirectory() + "\\Importers\\ImporterXml.dll";
string pathOfXmlDll = "\\Importers\\ImporterXml.dll";
List<Parameter> listOfParametersExpected = new List<Parameter>()
{
new Parameter()
Expand Down
17 changes: 17 additions & 0 deletions Uru_NaturalBooking/WebApi/FilesToImport/Lodgings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[{
"name": "Sol y Luna Hotel",
"description": "El Sol y Luna Home & Spa ofrece alojamiento independiente con WiFi gratis en Punta del Este, a 300 metros de las playas Brava y Mansa.",
"quantityOfStars": 5,
"address": "Av. Chiverta esquina Arazatí, Aidy Grill,",
"images": ["https://cf.bstatic.com/xdata/images/hotel/max1280x900/40311205.webp?k=2d889779bbf27e507231b75672c9463553f63e57d5565378bdfb9895a88d83f4&o="],
"pricePerNight": 200.0,
"isAvailable": true,
"touristSpot": {
"id": "2E792C77-5DAD-43B8-88F3-FE0A26D21F16",
"name": "Punta del Este",
"description": "La naturaleza abunda",
"regionId": "fc775bb9-8cc8-4fdc-bca6-16e06bcd322b",
"imagePath": "Desktop\\pde.jpg",
"listOfCategoriesId": ["baa98b33-eafe-4d62-bb62-859a8e36d3a9"]
}
}]
24 changes: 24 additions & 0 deletions Uru_NaturalBooking/WebApi/FilesToImport/Lodgings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Lodgings>
<LodgingModelForImport>
<Name>Hotel Enjoy Conrad</Name>
<Description>Un lugar magico donde podes vivir.</Description>
<QuantityOfStars>5</QuantityOfStars>
<Address>Playa Mansa parada 21</Address>
<Images>
<ImagePath>Desktop\conrad.jpg</ImagePath>
</Images>
<PricePerNight>200</PricePerNight>
<IsAvailable>true</IsAvailable>
<TouristSpot>
<Id>7cb8a7ab-8511-473f-803f-6b39118e79c1</Id>
<Name>Punta del Este</Name>
<Description>La naturaleza abunda</Description>
<RegionId>fc775bb9-8cc8-4fdc-bca6-16e06bcd322b</RegionId>
<ImagePath>Desktop\pde.jpg</ImagePath>
<ListOfCategoriesId>
<CategoryId>baa98b33-eafe-4d62-bb62-859a8e36d3a9 </CategoryId>
</ListOfCategoriesId>
</TouristSpot>
</LodgingModelForImport>
</Lodgings>
17 changes: 17 additions & 0 deletions Uru_NaturalBooking/WebApi/FilesToImport/LodgingsV2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "Hotel Enjoy Conrad",
"description": "Un lugar magico donde podes vivir.",
"quantityOfStars": 5,
"address": "Playa Mansa parada 21",
"images": ["Desktop\\conrad.jpg"],
"pricePerNight": 200.0,
"isAvailable": true,
"touristSpot": {
"id": "7cb8a7ab-8511-473f-803f-6b39118e79c1",
"name": "Punta del Este",
"description": "La naturaleza abunda",
"regionId": "fc775bb9-8cc8-4fdc-bca6-16e06bcd322b",
"imagePath": "Desktop\\pde.jpg",
"listOfCategoriesId": ["baa98b33-eafe-4d62-bb62-859a8e36d3a9"]
}
}
24 changes: 24 additions & 0 deletions Uru_NaturalBooking/WebApi/FilesToImport/LodgingsV2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Lodgings>
<LodgingModelForImport>
<Name>Hotel Enjoy Conrad</Name>
<Description>Un lugar magico donde podes vivir.</Description>
<QuantityOfStars>5</QuantityOfStars>
<Address>Playa Mansa parada 21</Address>
<Images>
<ImagePath>Desktop\conrad.jpg
</Images>
<PricePerNight>200</PricePerNight>
<IsAvailable>true</IsAvailable>
<TouristSpot>
<Id>7cb8a7ab-8511-473f-803f-6b39118e79c1</Id>
<Name>Punta del Este</Name>
<Description>La naturaleza abunda</Description>
<RegionId>fc775bb9-8cc8-4fdc-bca6-16e06bcd322b</RegionId>
<ImagePath>Desktop\pde.jpg</ImagePath>
<ListOfCategoriesId>
<CategoryId> baa98b33-eafe-4d62-bb62-859a8e36d3a9 </CategoryId>
</ListOfCategoriesId>
</TouristSpot>
</LodgingModelForImport>
</Lodgings>
17 changes: 17 additions & 0 deletions Uru_NaturalBooking/WebApi/FilesToImport/LodgingsV3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[{
"name": "Hotel Enjoy Conrad"
"description": "Un lugar magico donde podes vivir.",
"quantityOfStars": 5,
"address": "Playa Mansa parada 21",
"images": ["Desktop\\conrad.jpg"],
"pricePerNight": 200.0,
"isAvailable": true,
"touristSpot": {
"id": "7cb8a7ab-8511-473f-803f-6b39118e79c1",
"name": "Punta del Este",
"description": "La naturaleza abunda",
"regionId": "fc775bb9-8cc8-4fdc-bca6-16e06bcd322b",
"imagePath": "Desktop\\pde.jpg",
"listOfCategoriesId": ["baa98b33-eafe-4d62-bb62-859a8e36d3a9"]
}
}]
1 change: 1 addition & 0 deletions Uru_NaturalBooking/WebApi/FilesToImport/LodgingsV4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[{
"name": "Radisson Montevideo",
"description": "El Radisson Montevideo Victoria Plaza está ubicado en pleno centro de la ciudad, frente a la plaza Independencia, y ofrece vistas impresionantes a la bahía del puerto.",
"quantityOfStars": 5,
"address": "Av. Chiverta esquina Arazatí, Aidy Grill,",
"images": ["https://cf.bstatic.com/xdata/images/hotel/max1280x900/243870469.webp?k=90b563f90738836c1fb2d2d5dc3f4ad4cf554e650e5bd0299de37ea83670c598&o=",
"https://cf.bstatic.com/xdata/images/hotel/max1280x900/235263569.webp?k=5737be570389ede64b0ae2d041d25a7ef8a1b1e30f8e2fd2e1182eff10b9c798&o=",
"https://cf.bstatic.com/xdata/images/hotel/max1280x900/202384310.webp?k=e6f86721bdd95f10721aa47d1590dc1594538c94381d39eb010ad972a2d47088&o="],
"pricePerNight": 300.0,
"isAvailable": true,
"touristSpot": {
"id": "2637476F-B402-412D-B4CD-086808EE7B51",
"name": "Punta del Este",
"description": "La naturaleza abunda",
"regionId": "fc775bb9-8cc8-4fdc-bca6-16e06bcd322b",
"imagePath": "Desktop\\pde.jpg",
"listOfCategoriesId": ["baa98b33-eafe-4d62-bb62-859a8e36d3a9"]
}
},{
"name": "Sol y Luna Hotel",
"description": "El Sol y Luna Home & Spa ofrece alojamiento independiente con WiFi gratis en Punta del Este, a 300 metros de las playas Brava y Mansa.",
"quantityOfStars": 5,
"address": "Av. Chiverta esquina Arazatí, Aidy Grill,",
"images": ["https://cf.bstatic.com/xdata/images/hotel/max1280x900/40311205.webp?k=2d889779bbf27e507231b75672c9463553f63e57d5565378bdfb9895a88d83f4&o="],
"pricePerNight": 200.0,
"isAvailable": true,
"touristSpot": {
"id": "2E792C77-5DAD-43B8-88F3-FE0A26D21F16",
"name": "Punta del Este",
"description": "La naturaleza abunda",
"regionId": "fc775bb9-8cc8-4fdc-bca6-16e06bcd322b",
"imagePath": "Desktop\\pde.jpg",
"listOfCategoriesId": ["baa98b33-eafe-4d62-bb62-859a8e36d3a9"]
}
}
]
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 64887f0

Please sign in to comment.