public async Task Create_WithCorrectData_ShouldSuccessfullyCreate() { string errorMessagePrefix = "WheelRimService Create() method does not work properly."; var context = SntDbContextInMemoryFactory.InitializeContext(); await SeedData(context); this.wheelRimService = new WheelRimService(context); WheelRimServiceModel testProduct = new WheelRimServiceModel { Model = "Atom Ant", Brand = "Palmer Tech", Material = "atomsteel", Price = 209.59M, YearOfProduction = 2018, Picture = "src/pics/somethingfunny/atomant", Offset = 205, PCD = "65", CentralLukeDiameter = 15, Status = Models.Enums.AvailabilityStatus.InStock, Description = "Wield the power of Atom Ant!" }; bool actualResult = await this.wheelRimService.Create(testProduct); Assert.True(actualResult, errorMessagePrefix); }
public async Task EditWheelRim_WithCorrectData_ShouldEditProductCorrectly() { string errorMessagePrefix = "WheelRimService EditWheelRim() method does not work properly."; var context = SntDbContextInMemoryFactory.InitializeContext(); await SeedData(context); this.wheelRimService = new WheelRimService(context); WheelRimServiceModel expectedData = context.WheelRims.First().To <WheelRimServiceModel>(); expectedData.Model = "EdittedModelame"; expectedData.Price = 0.01M; expectedData.YearOfProduction = 1998; expectedData.Picture = "Editted_Picture"; await this.wheelRimService.EditWheelRim(expectedData); WheelRimServiceModel actualData = context.Tyres.First().To <WheelRimServiceModel>(); Assert.True(actualData.Model == expectedData.Model, errorMessagePrefix + " " + "Model not editted properly."); Assert.True(actualData.Price == expectedData.Price, errorMessagePrefix + " " + "Price not editted properly."); Assert.True(actualData.YearOfProduction == expectedData.YearOfProduction, errorMessagePrefix + " " + "YearOfProduction not editted properly."); Assert.True(actualData.Picture == expectedData.Picture, errorMessagePrefix + " " + "Picture not editted properly."); }
public async Task GetWheelRimById_WithExistentId_ShouldReturnCorrectResult() { string errorMessagePrefix = "WheelRimService GetWheelRimById() method does not work properly."; var context = SntDbContextInMemoryFactory.InitializeContext(); await SeedData(context); this.wheelRimService = new WheelRimService(context); WheelRimServiceModel expectedData = context.WheelRims.First().To <WheelRimServiceModel>(); WheelRimServiceModel actualData = this.wheelRimService.GetWheelRimById(expectedData.Id); Assert.True(expectedData.Model == actualData.Model, errorMessagePrefix + " " + "Model is not returned properly."); Assert.True(expectedData.Brand == actualData.Brand, errorMessagePrefix + " " + "Brand is not returned properly."); Assert.True(expectedData.PCD == actualData.PCD, errorMessagePrefix + " " + "PCD is not returned properly."); Assert.True(expectedData.Status == actualData.Status, errorMessagePrefix + " " + "Status is not returned properly."); Assert.True(expectedData.CentralLukeDiameter == actualData.CentralLukeDiameter, errorMessagePrefix + " " + "CentralLukeDiameter is not returned properly."); Assert.True(expectedData.Material == actualData.Material, errorMessagePrefix + " " + "Material is not returned properly."); Assert.True(expectedData.Description == actualData.Description, errorMessagePrefix + " " + "Description is not returned properly."); Assert.True(expectedData.Offset == actualData.Offset, errorMessagePrefix + " " + "Offset is not returned properly."); Assert.True(expectedData.YearOfProduction == actualData.YearOfProduction, errorMessagePrefix + " " + "YearOfProduction is not returned properly."); Assert.True(expectedData.Price == actualData.Price, errorMessagePrefix + " " + "Price is not returned properly."); Assert.True(expectedData.Picture == actualData.Picture, errorMessagePrefix + " " + "Picture is not returned properly."); }
public async Task GetWheelRimById_WithNonExistentId_ShouldReturnNull() { string errorMessagePrefix = "WheelRimService GetWheelRimById() method does not work properly."; var context = SntDbContextInMemoryFactory.InitializeContext(); await SeedData(context); this.wheelRimService = new WheelRimService(context); WheelRimServiceModel actualData = this.wheelRimService.GetWheelRimById("stamat"); Assert.True(actualData == null, errorMessagePrefix); }
public async Task EditWheelRim_WithCorrectData_ShouldPassSuccessfully() { string errorMessagePrefix = "WheelRimService EditWheelRim() method does not work properly."; var context = SntDbContextInMemoryFactory.InitializeContext(); await SeedData(context); this.wheelRimService = new WheelRimService(context); WheelRimServiceModel expectedData = context.WheelRims.First().To <WheelRimServiceModel>(); bool actualData = await this.wheelRimService.EditWheelRim(expectedData); Assert.True(actualData, errorMessagePrefix); }
public async Task <IActionResult> Create(WheelRimCreateInputModel wheelRimCreateInputModel) { if (!this.ModelState.IsValid) { return(this.View(wheelRimCreateInputModel)); } string imageUrl = await this.cloudinaryService.UploadPictureAsync( wheelRimCreateInputModel.Picture, wheelRimCreateInputModel.Model); WheelRimServiceModel wheelRimServiceModel = AutoMapper.Mapper.Map <WheelRimServiceModel>(wheelRimCreateInputModel); wheelRimServiceModel.Picture = imageUrl; await this.wheelRimService.Create(wheelRimServiceModel); return(this.Redirect("/")); }
public async Task EditWheelRim_WithNonExistentTyreId_ShouldThrowArgumentNullException() { string errorMessagePrefix = "WheelRimService EditWheelRim() method does not work properly."; var context = SntDbContextInMemoryFactory.InitializeContext(); await SeedData(context); this.wheelRimService = new WheelRimService(context); WheelRimServiceModel expectedData = context.WheelRims.First().To <WheelRimServiceModel>(); expectedData.Id = "1"; expectedData.Model = "EdittedModelame"; expectedData.Price = 0.01M; expectedData.YearOfProduction = 1998; expectedData.Picture = "Editted_Picture"; await Assert.ThrowsAsync <ArgumentNullException>(() => this.wheelRimService.EditWheelRim(expectedData)); }
public async Task <IActionResult> Edit(WheelRimServiceModel wheelRimServiceModel) { await this.wheelRimService.EditWheelRim(wheelRimServiceModel); return(this.Redirect("/Administration/WheelRim/AllWheelRims")); }