/// <summary> /// Gets the specified identifier. /// </summary> /// <param name="id">The identifier.</param> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public Domain.MobileDeCar Get(int id) { MobileDeCar mobileDeCarDb = null; using (DmvEntities db = new DmvEntities()) { mobileDeCarDb = db.MobileDeCar.Include("DmvCalculation").Where(c => c.IsDeleted == false && c.Id == id).FirstOrDefault(); } Domain.MobileDeCar mobileDeCarEntity = Mapper.Map <Domain.MobileDeCar>(mobileDeCarDb); return(mobileDeCarEntity); }
/// <summary> /// Saves the specified mobile de car. /// </summary> /// <param name="mobileDeCar">The mobile de car.</param> /// <returns></returns> public async Task <Domain.MobileDeCar> Save(Domain.MobileDeCar mobileDeCar) { MobileDeCar mobileDeCarDb = Mapper.Map <MobileDeCar>(mobileDeCar); using (DmvEntities db = new DmvEntities()) { mobileDeCarDb = db.MobileDeCar.Add(mobileDeCarDb); await db.SaveChangesAsync(); } Domain.MobileDeCar mobileDeCarEntity = Mapper.Map <Domain.MobileDeCar>(mobileDeCarDb); return(mobileDeCarEntity); }
public async void ImportCarFromMobileDeCcm() { // arrange IMobileDeProcessor mobileDeProcessor = ServiceLocator.Instance.Resolve <IMobileDeProcessor>(); ImportMobileDe importMobileDe = new ImportMobileDe() { Url = _testCarUrlOK1, VehicleTypeId = VehicleTypeEnum.Car }; // act MobileDeCar mobileDeCar = await mobileDeProcessor.ImportCarFromMobileDe(importMobileDe); //assert Assert.IsTrue(mobileDeCar.DmvCalculation.EngineDisplacementCcm > 0); }
public async void ImportCarFromMobileDeFuel(string url) { // arrange IMobileDeProcessor mobileDeProcessor = ServiceLocator.Instance.Resolve <IMobileDeProcessor>(); ImportMobileDe importMobileDe = new ImportMobileDe() { Url = url, VehicleTypeId = VehicleTypeEnum.Car }; // act MobileDeCar mobileDeCar = await mobileDeProcessor.ImportCarFromMobileDe(importMobileDe); //assert Assert.IsTrue(mobileDeCar.DmvCalculation.FuelTypeId == FuelTypeEnum.PetrolRest); }
public async void ImportCarFromMobileDeEuro(string url, EuroExhaustTypeEnum expected) { // arrange IMobileDeProcessor mobileDeProcessor = ServiceLocator.Instance.Resolve <IMobileDeProcessor>(); ImportMobileDe importMobileDe = new ImportMobileDe() { Url = url, VehicleTypeId = VehicleTypeEnum.Car }; // act MobileDeCar mobileDeCar = await mobileDeProcessor.ImportCarFromMobileDe(importMobileDe); //assert Assert.IsTrue(mobileDeCar.DmvCalculation.EuroExhaustTypeId == expected); }
public async void ParseGetCo2_GivenWebPageSample_GetValueImportCarFromMobileDeTestCo2(string url, int result) { // arrange IMobileDeProcessor mobileDeProcessor = ServiceLocator.Instance.Resolve <IMobileDeProcessor>(); ImportMobileDe importMobileDe = new ImportMobileDe() { Url = url, VehicleTypeId = VehicleTypeEnum.Car }; // act MobileDeCar mobileDeCar = await mobileDeProcessor.ImportCarFromMobileDe(importMobileDe); //assert Assert.IsTrue(mobileDeCar.DmvCalculation.Co2EmissionsValue == result); }
public DmvCalculationResult(DmvCalculation dmvCalculation, MobileDeCar mobileDeCar) : this(dmvCalculation) { this.MobileDeCar = mobileDeCar; }
/// <summary> /// Imports the car from mobile de. /// </summary> /// <param name="importMobileDe">The import mobile de.</param> /// <returns></returns> public async Task <MobileDeCar> ImportCarFromMobileDe(ImportMobileDe importMobileDe) { WebPageParser webPageParser = new WebPageParser(); await webPageParser.ParseWebPage(importMobileDe.Url); MobileDeCar mobileDeCar = new MobileDeCar(); // Default setting for car mobileDeCar.Url = importMobileDe.Url; mobileDeCar.DmvCalculation.VehicleTypeId = importMobileDe.VehicleTypeId; mobileDeCar.DmvCalculation.DateOfCalculation = DateTime.UtcNow; mobileDeCar.DmvCalculation.EngineTypeId = EngineTypeEnum.FourTactsRest; mobileDeCar.UserId = ServiceLocator.Instance.Resolve <IUserProvider>().GetCurrentUserId(); // string resultNode = null; string webPageNode = null; webPageNode = webPageParser.GetWebPageNode("co2EmissionValue"); if (webPageNode != null) { resultNode = webPageParser.GetWebPageNodeNumericContent(webPageNode); mobileDeCar.DmvCalculation.Co2EmissionsValue = Convert.ToInt16(resultNode); } webPageNode = webPageParser.GetWebPageNode("kW ("); if (webPageNode != null) { resultNode = webPageParser.GetWebPageNodeNumericContent(webPageNode); mobileDeCar.DmvCalculation.EnginePowerKw = Convert.ToInt16(resultNode); } webPageNode = webPageParser.GetWebPageNode("\nEuro"); if (webPageNode != null) { resultNode = webPageParser.GetWebPageNodeStringContent(webPageNode); mobileDeCar.DmvCalculation.EuroExhaustTypeId = EnumHelper.GetEnumValue <EuroExhaustTypeEnum>(resultNode); } else { // Defaut EURO mobileDeCar.DmvCalculation.EuroExhaustTypeId = EuroExhaustTypeEnum.Euro1; } //By law every EURO5+ have to have DPF filter, most of them had for the EURO4 if ((int)mobileDeCar.DmvCalculation.EuroExhaustTypeId < 4) { mobileDeCar.DmvCalculation.DieselParticlesAbove005Limit = true; } // Set default and handlig of the FuelType mobileDeCar.DmvCalculation.FuelTypeId = FuelTypeEnum.PetrolRest; webPageNode = webPageParser.GetWebPageNode("p>\nPetrol"); webPageNode = webPageNode ?? webPageParser.GetWebPageNode("p>\nBenzin"); webPageNode = webPageNode ?? webPageParser.GetWebPageNode("p>\nHybrid (Benzin"); if (webPageNode != null) { resultNode = webPageParser.GetWebPageNodeStringContent(webPageNode); mobileDeCar.DmvCalculation.FuelTypeId = FuelTypeEnum.PetrolRest; } webPageNode = webPageParser.GetWebPageNode("p>\nDiesel"); webPageNode = webPageNode ?? webPageParser.GetWebPageNode("p>\nHybrid (Diesel"); if (webPageNode != null) { resultNode = webPageParser.GetWebPageNodeStringContent(webPageNode); mobileDeCar.DmvCalculation.FuelTypeId = FuelTypeEnum.Diesel; } webPageNode = webPageParser.GetWebPageNode(" cm³"); if (webPageNode != null) { resultNode = webPageParser.GetWebPageNodeNumericContent(webPageNode); mobileDeCar.DmvCalculation.EngineDisplacementCcm = Convert.ToInt32(resultNode); } webPageNode = webPageParser.GetWebPageNode("pricePrimaryCountryOfSale priceGross"); if (webPageNode != null) { resultNode = webPageParser.GetWebPageNodeNumericContent(webPageNode); mobileDeCar.DmvCalculation.VehicleValue = Convert.ToInt32(resultNode); } webPageNode = webPageParser.GetWebPageNode("h1>\n"); if (webPageNode != null) { mobileDeCar.Model = "Not known"; mobileDeCar.Maker = "Not known"; resultNode = webPageParser.GetWebPageNodeStringContent(webPageNode); mobileDeCar.Model = resultNode; mobileDeCar.Maker = resultNode.Split(' ').FirstOrDefault(); } webPageNode = webPageParser.GetWebPageNode("img class=\"currentImage\" src"); if (webPageNode != null) { resultNode = webPageParser.GetWebPageAttributeStringContent(webPageNode, "src"); mobileDeCar.ImageUrl = resultNode; } return(mobileDeCar); }