diff --git a/src/Services/Catalog/Catalog.UnitTests/Application/CatalogControllerTest.cs b/src/Services/Catalog/Catalog.UnitTests/Application/CatalogControllerTest.cs index 7410551e4..52a2d7ebe 100644 --- a/src/Services/Catalog/Catalog.UnitTests/Application/CatalogControllerTest.cs +++ b/src/Services/Catalog/Catalog.UnitTests/Application/CatalogControllerTest.cs @@ -1,5 +1,4 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.eShopOnContainers.WebMVC.Controllers; +using Microsoft.eShopOnContainers.WebMVC.Controllers; using Microsoft.eShopOnContainers.WebMVC.Services; using Microsoft.eShopOnContainers.WebMVC.ViewModels; using Microsoft.eShopOnContainers.WebMVC.ViewModels.CatalogViewModels; @@ -8,83 +7,80 @@ using System.Collections.Generic; using System.Threading.Tasks; using Xunit; using CatalogModel = Microsoft.eShopOnContainers.WebMVC.ViewModels.Catalog; +using ViewResult = Microsoft.AspNetCore.Mvc.ViewResult; namespace UnitTest.Catalog.Application { - public class CatalogControllerTest - { - private readonly Mock _catalogServiceMock; + public class CatalogControllerTest + { + private readonly Mock _catalogServiceMock; - public CatalogControllerTest() - { - _catalogServiceMock = new Mock(); - } + public CatalogControllerTest() + => _catalogServiceMock = new Mock(); - [Fact] - public async Task Get_catalog_items_success() - { - //Arrange - var fakeBrandFilterApplied = 1; - var fakeTypesFilterApplied = 2; - var fakePage = 2; - var fakeCatalog = GetFakeCatalog(); + [Fact] + public async Task Get_catalog_items_success() + { + //Arrange + var fakeBrandFilterApplied = 1; + var fakeTypesFilterApplied = 2; + var fakePage = 2; + var fakeCatalog = GetFakeCatalog(); - var expectedNumberOfPages = 5; - var expectedTotalPages = 50; - var expectedCurrentPage = 2; + var expectedNumberOfPages = 5; + var expectedTotalPages = 50; + var expectedCurrentPage = 2; - _catalogServiceMock.Setup(x => x.GetCatalogItems - ( - It.Is(y => y == fakePage), - It.IsAny(), - It.Is(y => y == fakeBrandFilterApplied), - It.Is(y => y == fakeTypesFilterApplied) - )) - .Returns(Task.FromResult(fakeCatalog)); + _catalogServiceMock.Setup(x => x.GetCatalogItems + ( + It.Is(y => y == fakePage), + It.IsAny(), + It.Is(y => y == fakeBrandFilterApplied), + It.Is(y => y == fakeTypesFilterApplied) + )) + .Returns(Task.FromResult(fakeCatalog)); - //Act - var orderController = new CatalogController(_catalogServiceMock.Object); - var actionResult = await orderController.Index(fakeBrandFilterApplied, fakeTypesFilterApplied, fakePage, null); + //Act + var orderController = new CatalogController(_catalogServiceMock.Object); + var actionResult = await orderController.Index(fakeBrandFilterApplied, fakeTypesFilterApplied, fakePage, null); - //Assert - var viewResult = Assert.IsType(actionResult); - var model = Assert.IsAssignableFrom(viewResult.ViewData.Model); - Assert.Equal(model.PaginationInfo.TotalPages, expectedNumberOfPages); - Assert.Equal(model.PaginationInfo.TotalItems, expectedTotalPages); - Assert.Equal(model.PaginationInfo.ActualPage, expectedCurrentPage); - Assert.Empty(model.PaginationInfo.Next); - Assert.Empty(model.PaginationInfo.Previous); - } - - private CatalogModel GetFakeCatalog() - { - return new CatalogModel() - { - PageSize = 10, - Count = 50, - PageIndex = 2, - Data = new List() - { - new CatalogItem() - { - Id = 1, - Name = "fakeItemA", - CatalogTypeId = 1 - }, - new CatalogItem() - { - Id = 2, - Name = "fakeItemB", - CatalogTypeId = 1 - }, - new CatalogItem() - { - Id = 3, - Name = "fakeItemC", - CatalogTypeId = 1 - } - } - }; - } - } + //Assert + var viewResult = Assert.IsType(actionResult); + var model = Assert.IsAssignableFrom(viewResult.ViewData.Model); + Assert.Equal(model.PaginationInfo.TotalPages, expectedNumberOfPages); + Assert.Equal(model.PaginationInfo.TotalItems, expectedTotalPages); + Assert.Equal(model.PaginationInfo.ActualPage, expectedCurrentPage); + Assert.Empty(model.PaginationInfo.Next); + Assert.Empty(model.PaginationInfo.Previous); + } + + private CatalogModel GetFakeCatalog() + => new CatalogModel() + { + PageSize = 10, + Count = 50, + PageIndex = 2, + Data = new List() + { + new CatalogItem() + { + Id = 1, + Name = "fakeItemA", + CatalogTypeId = 1 + }, + new CatalogItem() + { + Id = 2, + Name = "fakeItemB", + CatalogTypeId = 1 + }, + new CatalogItem() + { + Id = 3, + Name = "fakeItemC", + CatalogTypeId = 1 + } + } + }; + } }