public void All_ReturnsAll() { using (IDataContext livekartFakeContext = new LiveKartFakeContext()) using (IUnitOfWork unitOfWork = new UnitOfWork(livekartFakeContext)) using (CountryController controller = new CountryController(unitOfWork)) { //arrenge //act var countries = controller.All(); //assert Assert.IsInstanceOfType(countries, typeof(List <Country>)); } }
public async void All_Not_Exists() { CountryControllerMockFacade mock = new CountryControllerMockFacade(); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult <List <ApiCountryResponseModel> >(new List <ApiCountryResponseModel>())); CountryController controller = new CountryController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.All(1000, 0); response.Should().BeOfType <OkObjectResult>(); (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK); var items = (response as OkObjectResult).Value as List <ApiCountryResponseModel>; items.Should().BeEmpty(); mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>())); }
public void All_When_No_Page_Id() { // arrange var serviceMock = new Mock <ICountryService>(MockBehavior.Strict); var controller = new CountryController(serviceMock.Object); var serviceResult = new PagedCountryListingServiceModel(); serviceMock.Setup(s => s.AllCountriesAsync(1, null)).ReturnsAsync(serviceResult); // act var result = controller.All().Result; // assert Assert.IsAssignableFrom <ViewResult>(result); var model = (result as ViewResult)?.Model; Assert.True(model != null); Assert.IsAssignableFrom <PagedCountryListingServiceModel>(model); Assert.True(model as PagedCountryListingServiceModel == serviceResult); serviceMock.VerifyAll(); }