public void TestDisplayAllMoqModel() { var ListPerson = new List <Person>(); ListPerson.Add(new Person { imie = "Kasia", nazwisko = "Kowalska" }); Mock <IPersonSharingContext> context = new Mock <IPersonSharingContext>(); context.Setup(x => x.Persons).Returns(ListPerson.AsQueryable()); var controller = new PersonController(context.Object); var result = controller.All() as ViewResult; var model = ((ViewResult)result).Model as List <Person>; Assert.IsTrue(model.Count == 1); }
public void ChceckTypeListInAll() { var ListPerson = new List <Person>(); ListPerson.Add(new Person { imie = "Kasia", nazwisko = "Kowalska" }); Mock <IPersonSharingContext> context = new Mock <IPersonSharingContext>(); context.Setup(x => x.Persons).Returns(ListPerson.AsQueryable()); var controller = new PersonController(context.Object); var result = controller.All() as ViewResult; var model = ((ViewResult)result).Model as List <Person>; Assert.AreEqual(typeof(List <Person>), result.Model.GetType()); Assert.IsTrue(model.Count == 1); }
public async void All_Not_Exists() { PersonControllerMockFacade mock = new PersonControllerMockFacade(); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult <List <ApiPersonServerResponseModel> >(new List <ApiPersonServerResponseModel>())); PersonController controller = new PersonController(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, string.Empty); response.Should().BeOfType <OkObjectResult>(); (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK); var items = (response as OkObjectResult).Value as List <ApiPersonServerResponseModel>; items.Should().BeEmpty(); mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())); }
public void ChceckTypeListInAll() { var context = new FakePersonSharingContext(); context.Persons = new[] { new Person { personId = 1, imie = "Kasia", nazwisko = "Kowalska", pesel = "675678787", adresId = 1 }, new Person { personId = 2, imie = "Basia", nazwisko = "Kowalska", pesel = null, adresId = 2 }, new Person { personId = 3, imie = "Masia", nazwisko = "Kowalska", pesel = null, adresId = 3 } }.AsQueryable(); var controller = new PersonController(context); var result = controller.All() as ViewResult; Assert.AreEqual(typeof(List <Person>), result.Model.GetType()); }
public void TestDisplayAll() { var context = new FakePersonSharingContext(); context.Persons = new[] { new Person { personId = 1, imie = "Kasia", nazwisko = "Kowalska", pesel = "675678787", adresId = 1 }, new Person { personId = 2, imie = "Basia", nazwisko = "Kowalska", pesel = null, adresId = 2 }, new Person { personId = 3, imie = "Masia", nazwisko = "Kowalska", pesel = null, adresId = 3 } }.AsQueryable(); var controller = new PersonController(context); var result = controller.All() as ViewResult; var modelPersons = (IEnumerable <Person>)result.Model; Assert.AreEqual(3, modelPersons.Count()); }