PageRenderTime 54ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/MusicStore.UnitTest/ProductQueryTest.cs

https://github.com/satish860/MusicStoreAPI
C# | 58 lines | 53 code | 5 blank | 0 comment | 0 complexity | e753a1705ae6e26fd33c89a77aa4f417 MD5 | raw file
  1. using MusicStore.Api.Models;
  2. using MusicStore.Api.Query;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using MusicStore.Api;
  9. using FluentAssertions;
  10. using NUnit.Framework;
  11. using System.Web.Http.SelfHost;
  12. namespace MusicStore.UnitTest
  13. {
  14. [TestFixture]
  15. public class ProductQueryTest
  16. {
  17. [TestFixtureSetUp]
  18. public void SetUp()
  19. {
  20. new MusicStoreBootStrap(new HttpSelfHostConfiguration("http://localhost:8008"))
  21. .ConfigureDatabaseForTest()
  22. .SeedDatabase();
  23. }
  24. [Test]
  25. public void Should_be_able_to_Query_for_the_First_product_without_send_Page_Number()
  26. {
  27. IQueryFor<PagedResult, ListOfProducts> Query = TestInstance.ProductQuery;
  28. ListOfProducts ProductList = Query.Execute(PagedResult.ForPage(1));
  29. ProductList.Products.Select(p => p.Id).Should().ContainInOrder(Enumerable.Range(1, 10));
  30. }
  31. [Test]
  32. public void Should_be_able_to_Query_for_Page_numbers_with_it()
  33. {
  34. IQueryFor<PagedResult, ListOfProducts> Query = TestInstance.ProductQuery;
  35. ListOfProducts ProductList = Query.Execute(PagedResult.ForPage(2));
  36. ProductList.Products.Select(p => p.Id).Should().ContainInOrder(Enumerable.Range(11, 8));
  37. }
  38. [Test]
  39. public void Should_be_able_to_Get_the_Total_Count_of_Products_only_for_the_first_time()
  40. {
  41. IQueryFor<PagedResult, ListOfProducts> Query = TestInstance.ProductQuery;
  42. ListOfProducts ProductList = Query.Execute(PagedResult.ForPage(1));
  43. ProductList.PageCount.Should().Be(2);
  44. }
  45. [Test]
  46. public void Should_not_Return_total_Count_if_the_Page_number_is_Not_1()
  47. {
  48. IQueryFor<PagedResult, ListOfProducts> Query = TestInstance.ProductQuery;
  49. ListOfProducts ProductList = Query.Execute(PagedResult.ForPage(2));
  50. ProductList.PageCount.Should().Be(2);
  51. }
  52. }
  53. }