public async void CanUpdateAFlummery() { //Arrange var flummery01 = new Flummery { Name = "flummery01", Manufacturer = "acme01", Price = 9.99m, Calories = 1500, Weight = 0.25m, Compliment = "Damned with faint praise" }; var testService = BuildFlummeryService(); var savedFlummery = testService.CreateFlummery(flummery01); var updatedFlummery01 = new Flummery { Id = savedFlummery.Id, Name = "update-flummery01", Manufacturer = "update-acme01" }; //Act var testFlummery = await testService.UpdateFlummery(updatedFlummery01); //Assert Assert.NotNull(testFlummery); Assert.Equal(savedFlummery.Id, testFlummery.Id); Assert.Equal("update-flummery01", testFlummery.Name); Assert.Equal("update-acme01", testFlummery.Manufacturer); }
/// <summary> /// Add the imageURI to the flummery being updated /// </summary> /// <param name="flummeryId">Id of flummery to add image to</param> /// <param name="imageURI">Image URI to add to the flummery, stored in cloud storage</param> /// <returns>Task of completion of updated Flummery</returns> public async Task <Flummery> UpdateStoreDbFor(int flummeryId, string imageURI) { Flummery flummery = await _flummeryInventory.GetFlummeryBy(flummeryId); flummery.ImageUrl = imageURI; return(await _flummeryInventory.UpdateFlummery(flummery)); }
public async void CanDeleteAFlummery() { //Arrange var flummery01 = new Flummery { Name = "flummery01", Manufacturer = "acme01", Price = 9.99m, Calories = 1500, Weight = 0.25m, Compliment = "Damned with faint praise" }; var testService = BuildFlummeryService(); var savedFlummery = testService.CreateFlummery(flummery01); var flummeriesBeforeDelete = await testService.GetAllFlummeries(); //Act await testService.DeleteFlummery(savedFlummery.Id); var nullFlummery = await testService.GetFlummeryBy(savedFlummery.Id); var flummeriesAfterDelete = await testService.GetAllFlummeries(); //Assert Assert.Null(nullFlummery); Assert.Equal(flummeriesBeforeDelete.Count - 1, flummeriesAfterDelete.Count); }
/// <summary> /// Updates a Flummery object in the database. /// </summary> /// <param name="flummeryVM"> /// Flummery: the object with updated information /// </param> /// <returns> /// Task<Flummery>: the Flummery object reflecting what was saved to the database, wrapped in a Task /// </returns> public async Task <Flummery> UpdateFlummery(Flummery flummery) { _context.Entry(flummery).State = EntityState.Modified; await _context.SaveChangesAsync(); return(flummery); }
public async void CanGetAFlummeryBySearch() { //Arrange var flummery01 = new Flummery { Name = "flummery01", Manufacturer = "acme01", Price = 9.99m, Calories = 1500, Weight = 0.25m, Compliment = "Damned with faint praise" }; var flummery02 = new Flummery { Name = "flummery02", Manufacturer = "acme02", Price = 9.99m, Calories = 1500, Weight = 0.25m, Compliment = "Damned with faint praise" }; var flummery03 = new Flummery { Name = "flummery03", Manufacturer = "acme03", Price = 9.99m, Calories = 1500, Weight = 0.25m, Compliment = "Damned with faint praise" }; var testService = BuildFlummeryService(); var throwAway01 = await testService.CreateFlummery(flummery01); var throwAway02 = await testService.CreateFlummery(flummery02); var throwAway03 = await testService.CreateFlummery(flummery03); //Act var matchingFlummeries = await testService.GetFlummeriesForSearch("flummery02"); //Assert Assert.NotNull(matchingFlummeries); Assert.True(matchingFlummeries.Count >= 1); bool containsTarget = false; foreach (var flummery in matchingFlummeries) { if (flummery.Name == "flummery02" && flummery.Manufacturer == "acme02") { containsTarget = true; } } Assert.True(containsTarget); }
/// <summary> /// Handle creation of the Flummery with Bound information from Page. /// </summary> /// <returns>Newly created flummery</returns> public async Task <Flummery> CreateFlum() { Flummery flum = new Flummery { Name = Input.Name, Manufacturer = Input.Manufacturer, Price = Input.Price, Calories = Input.Calories, Weight = Input.Weight, Compliment = Input.Compliment }; flum = await _flummery.CreateFlummery(flum); return(flum); }
public async void CanGetAllFlummeries() { //Arrange var flummery01 = new Flummery { Name = "flummery01", Manufacturer = "acme01", Price = 9.99m, Calories = 1500, Weight = 0.25m, Compliment = "Damned with faint praise" }; var flummery02 = new Flummery { Name = "flummery02", Manufacturer = "acme02", Price = 9.99m, Calories = 1500, Weight = 0.25m, Compliment = "Damned with faint praise" }; var flummery03 = new Flummery { Name = "flummery03", Manufacturer = "acme03", Price = 9.99m, Calories = 1500, Weight = 0.25m, Compliment = "Damned with faint praise" }; var testService = BuildFlummeryService(); var throwAway01 = await testService.CreateFlummery(flummery01); var throwAway02 = await testService.CreateFlummery(flummery02); var throwAway03 = await testService.CreateFlummery(flummery03); //Act var allFlummeries = await testService.GetAllFlummeries(); //Assert Assert.NotNull(allFlummeries); Assert.True(allFlummeries.Count >= 3); }
public async Task BuildRegistrationEmail(string emailAddress, string name) { string templateId = "d-d26e9bcbfef6438ab53fd65fca39da27"; List <EmailItem> featuredFlums = new List <EmailItem>(); List <int> usedNums = new List <int>(); Random rand = new Random(); for (int i = 0; i < 2; i++) { int temp = rand.Next(1, 10); while (usedNums.Contains(temp)) { temp = rand.Next(1, 10); } usedNums.Add(temp); Flummery flum = await _flummery.GetFlummeryBy(temp); featuredFlums.Add(new EmailItem { Id = flum.Id, ImgSrc = flum.ImageUrl, ItemName = flum.Name, ItemPrice = flum.Price }); } List <Personalization> personalizations = new List <Personalization>(); personalizations.Add(new Personalization() { Tos = new List <EmailAddress> { new EmailAddress(emailAddress) }, Subject = "Thanks for your purchase!", TemplateData = new RegistrationTemplateData() { FullName = name, Date = DateTime.Now.ToString(), DisplayItems = featuredFlums } }); await _email.SendEmail(templateId, personalizations); }
/// <summary> /// Get the specified flummeries information and display to the page, redirect to Products if it can't be found /// </summary> /// <param name="id">ID of flummery to edit</param> /// <returns>Page with the specified flummery info or redirection to Admin dash if it's not found</returns> public async Task <IActionResult> OnGet(int id) { Id = id; Flummery flum = await _flummery.GetFlummeryBy(id); if (flum != null) { Input = new ItemUploadViewModel { Manufacturer = flum.Manufacturer, Name = flum.Name, Calories = flum.Calories, Weight = flum.Weight, Price = flum.Price, Compliment = flum.Compliment, }; ImgUrl = flum.ImageUrl; return(Page()); } return(RedirectToPage("/Admin/Index")); }
/// <summary> /// Update the specified flummery in the database /// </summary> /// <param name="id">Id of flummery being updated</param> /// <returns>Updated flummery</returns> public async Task <Flummery> UpdateFlum(int id) { Flummery flum = new Flummery { Id = id, Name = Input.Name, Manufacturer = Input.Manufacturer, Price = Input.Price, Calories = Input.Calories, Weight = Input.Weight, Compliment = Input.Compliment }; if (Input.ImageFile == null) { flum.ImageUrl = ImgUrl; } flum = await _flummery.UpdateFlummery(flum); return(flum); }
/// <summary> /// Sets the bound Flummery property for the Razor Page. /// </summary> /// <param name="id"> /// int: a flummery item ID /// </param> public async Task OnGet(int id) { Flummery = await _flummeryInventory.GetFlummeryBy(id); }
public async void CanGetAllFlummeriesReordered() { //Arrange var flummery01 = new Flummery { Name = "flummery01", Manufacturer = "acme01", Price = 9.99m, Calories = 1500, Weight = 0.25m, Compliment = "Damned with faint praise" }; var flummery02 = new Flummery { Name = "flummery02", Manufacturer = "acme02", Price = 9.99m, Calories = 1500, Weight = 0.25m, Compliment = "Damned with faint praise" }; var flummery03 = new Flummery { Name = "flummery03", Manufacturer = "acme03", Price = 9.99m, Calories = 1500, Weight = 0.25m, Compliment = "Damned with faint praise" }; var testService = BuildFlummeryService(); var throwAway01 = await testService.CreateFlummery(flummery01); var throwAway02 = await testService.CreateFlummery(flummery02); var throwAway03 = await testService.CreateFlummery(flummery03); //Act var revAlphaFlummeries = await testService.GetFlummeriesOrderedBy("alphabeticalRev"); //Assert Assert.NotNull(revAlphaFlummeries); Assert.True(revAlphaFlummeries.Count >= 3); bool inOrder = true; Flummery foundFlummery03 = null; Flummery foundFlummery02 = null; Flummery foundFlummery01 = null; foreach (var flummery in revAlphaFlummeries) { if (flummery.Name == "flummery03" && flummery.Manufacturer == "acme03") { foundFlummery03 = flummery; if (foundFlummery02 != null || foundFlummery01 != null) { inOrder = false; break; } } if (flummery.Name == "flummery02" && flummery.Manufacturer == "acme02") { foundFlummery02 = flummery; if (foundFlummery03 == null || foundFlummery01 != null) { inOrder = false; break; } } if (flummery.Name == "flummery01" && flummery.Manufacturer == "acme01") { foundFlummery01 = flummery; if (foundFlummery03 == null || foundFlummery02 == null) { inOrder = false; break; } } } Assert.True(inOrder); Assert.NotNull(foundFlummery03); Assert.NotNull(foundFlummery02); Assert.NotNull(foundFlummery01); }