PageRenderTime 53ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/MusicStore.AcceptanceTest/1.3CategoriesSpec.cs

https://github.com/satish860/MusicStoreAPI
C# | 75 lines | 62 code | 13 blank | 0 comment | 0 complexity | 57b1417431a29a56e80a5ff62489a240 MD5 | raw file
  1. using FluentAssertions;
  2. using MusicStore.Api;
  3. using Newtonsoft.Json.Linq;
  4. using NSpec;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.Web.Http.SelfHost;
  8. using System.Linq;
  9. using MusicStore.Api.Models;
  10. using System.Net.Http;
  11. namespace MusicStore.AcceptanceTest
  12. {
  13. public class CategorySpec : nspec
  14. {
  15. public void Given_all_the_Products_With_Category()
  16. {
  17. JArray ActualResult = null;
  18. IEnumerable<CategoryCountViewModel> ExpectedResult = null;
  19. IEnumerable<CategoryCountViewModel> ActualModel = null;
  20. beforeAll = () =>
  21. {
  22. var client = HttpClientFactory.CreateClient();
  23. var response = client.GetAsync("/api/category").Result;
  24. ExpectedResult = new List<CategoryCountViewModel> {
  25. new CategoryCountViewModel{CategoryName="Mobile",Count=4},
  26. new CategoryCountViewModel{CategoryName="Laptop",Count=4},
  27. new CategoryCountViewModel{CategoryName="Camera",Count=2},
  28. new CategoryCountViewModel{CategoryName="Home Accesories",Count=2},
  29. new CategoryCountViewModel{CategoryName="Books",Count=2},
  30. new CategoryCountViewModel{CategoryName="Electronics",Count=1},
  31. new CategoryCountViewModel{CategoryName="Kitchen",Count=1},
  32. new CategoryCountViewModel{CategoryName="TV",Count=2}
  33. };
  34. ActualResult = JArray.Parse(response.Content.ReadAsStringAsync().Result);
  35. ActualModel = ActualResult.ToObject<IEnumerable<CategoryCountViewModel>>();
  36. };
  37. it["Should be possible to get all the category"] = () =>
  38. {
  39. ActualModel.Should().BeEquivalentTo(ExpectedResult);
  40. };
  41. it["Should be possible to get all the Count of the Category"] = () =>
  42. {
  43. ActualModel.First().Count.should_be(4);
  44. };
  45. it["Should be possible to get the url for Products By category"] = () =>
  46. {
  47. ActualModel.First().ProductUrl.should_be("http://localhost:8082/api/Products/GetByCategory/Mobile");
  48. };
  49. }
  50. public void Given_the_Product_url_With_The_Category_name()
  51. {
  52. it["Should be possible to get the Products by Category"] = () =>
  53. {
  54. var client = HttpClientFactory.CreateClient();
  55. HttpResponseMessage message = client.GetAsync("/api/Products/GetByCategory/Mobile").Result;
  56. JObject jsonObject=JObject.Parse(message.Content.ReadAsStringAsync().Result);
  57. ListOfProducts products=jsonObject.ToObject<ListOfProducts>();
  58. products.Products.Select(p => p.Id).should_be(Enumerable.Range(1, 4));
  59. };
  60. }
  61. }
  62. }