fix ViewResult (importing namespace)

This commit is contained in:
Rafsanul Hasan 2019-04-04 10:18:15 +06:00
parent a846f041cd
commit 4c530da377
No known key found for this signature in database
GPG Key ID: 4BBF45E04D0AD72B

View File

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