public void DataTestMethod(string searchString, int expectedItemsCount) { var result = _controller.Get(searchString).Result; var value = (result as OkObjectResult).Value as IEnumerable <Person>; Assert.AreEqual(value.Count(), expectedItemsCount); }
public void Get() { //Arrange var result = Builder <Person> .CreateListOfSize(3) .TheFirst(1) .Build(); var personDtoList = Builder <PersonDTO> .CreateListOfSize(3) .TheFirst(1) .Build(); _personService .Setup(o => o.GetAsync()) .ReturnsAsync(result); _mapper .Setup(o => o.Map <IEnumerable <PersonDTO> >(It.IsAny <IEnumerable <Person> >())) .Returns(personDtoList); //Act var response = _controller.Get().Result; var resultDto = (response.Result as OkObjectResult).Value as IEnumerable <PersonDTO>; //Assert Assert.NotNull(resultDto); Assert.IsType <List <PersonDTO> >(resultDto); }
public void Get_WhenCalled_Returns200OKResult() { //Arrange //Act var result = _testPersonController.Get(); //Assert Assert.IsType <OkObjectResult>(result.Result); }
public void TestGetAll() { IEnumerable <Person> persons = _controller.Get(); Assert.AreEqual(3, persons.Count()); Person person = _controller.Get(1); //get by id Assert.AreEqual("mimka", person.Username); }
public async void GetById_ExistingIdPassed_ReturnOkObjectResult() { //Arrange var rep = new PersonRepository(); var personId = rep.GetAll().First().Id; //Act var okResult = await _controller.Get(personId); //Assert Assert.IsType <OkObjectResult>(okResult); }
public async System.Threading.Tasks.Task ShouldReturnKnownPeople() { var l = new DummyLogger(); var r = new MockPersonRepository(); var c = new PersonController(l, r); var p = r.GetAll().First(); var fname = p.FirstName; var lname = p.LastName; Assert.NotEmpty(await c.Get(fname)); Assert.NotEmpty(await c.Get(lname)); }
public void Get_All_Ok() { var result = _controller.Get(); Assert.IsInstanceOf <OkObjectResult>(result.Result); var okResult = result.Result as OkObjectResult; Assert.AreEqual(200, okResult.StatusCode); var data = okResult.Value as List <Person>; Assert.AreEqual(5, data.Count); Assert.AreEqual("Gandelf", data[0].Name); }
public async Task GetById_PersonWithIdInRepository_ReturnsSuccessWithPerson() { //Arrange const int Id = 0; Person expected = PersonGenerator.Generate(); expected.Id = Id; Mock <IPersonRepository> repository = new Mock <IPersonRepository>(); repository.Setup(r => r.GetAsync(Id)) .Returns(Task.FromResult(expected)); PersonController controller = new PersonController(repository.Object); //Act IActionResult result = await controller.Get(Id); //Assert ObjectResult resultWithValue = Assert.IsType <ObjectResult>(result); Person actual = Assert.IsType <Person>(resultWithValue.Value); Assert.Equal(expected, actual, PersonEqualityComparer.Default); }
public void GetAllPersonsCaseNotEmpty() { var listReturn = new List <Person>(); Person person1 = new Person() { Name = "Nicolas", Surname = "Fierro", Phone = "+598123456", Email = "*****@*****.**" }; Person person2 = new Person() { Name = "Pepe", Surname = "Argento", Phone = "+598654789", Email = "*****@*****.**" }; listReturn.Add(person1); listReturn.Add(person2); var mock = new Mock <IPersonService>(MockBehavior.Strict); mock.Setup(service => service.GetAll()).Returns(listReturn); var controller = new PersonController(mock.Object); var result = controller.Get(); var okResult = result as OkObjectResult; var value = okResult.Value as List <Person>; mock.VerifyAll(); Assert.AreEqual(value, listReturn); }
public void GetById() { PersonController controller = new PersonController(); Person result = controller.Get(17); Assert.AreEqual("Nice", result.FirstName); }
public void TestPersonListing() { var expectedList = new List <PersonModel>(); expectedList.Add(new PersonModel() { Firstname = "Fornavn", Lastname = "Etternavn", Streetname = "Gate", Zip = "5000" }); expectedList.Add(new PersonModel() { Firstname = "Fornavn2", Lastname = "Etternavn2", Streetname = "Gate2", Zip = "5001" }); var dal = new MockPersonDbDal(expectedList); var personController = new PersonController(dal); var result = personController.Get(); Assert.AreEqual(2, result.Count()); Assert.AreEqual(expectedList.First().Firstname, result.First().Firstname); }
public void GetOneTest() { var optionsBuilder = new DbContextOptionsBuilder <HallOfFameContext>() .UseInMemoryDatabase("userdbstore"); using (var context = new HallOfFameContext(optionsBuilder.Options)) { PersonController controller = new PersonController(context); var result = controller.Get(1); var result2 = controller.Get(10); Assert.IsType <OkObjectResult>(result); Assert.IsType <NotFoundResult>(result2); } }
public void PersonController_Add_Update() { var Name_Original = "Added Person"; var Name_Updated = "Updated Person"; var PersonController = new PersonController(); var ItemsAtStart = PersonController.Current().Count(); var Person = PersonController.Add(new Person() { Name = Name_Original, DateOfBirth = DateTime.Now }); Person.Name = Name_Updated; PersonController.Update(Person); Person = PersonController.Get(Person.InstanceId); var ItemsAtEnd = PersonController.Current().Count(); //Make sure our count increased by 1. Assert.AreEqual(ItemsAtStart + 1, ItemsAtEnd); //Make sure that we have the updated name. Assert.AreEqual(Name_Updated, Person.Name); }
public async System.Threading.Tasks.Task ShouldCrashOnDemand() { var l = new DummyLogger(); var r = new MockPersonRepository(); var c = new PersonController(l, r); await Assert.ThrowsAnyAsync <Exception>(() => c.Get("err")); }
public void Get_WhenCalled_ReturnsOkResult() { // Act var result = _controller.Get(); // Assert Assert.IsType <OkObjectResult>(result); }
public void GetPerson_IdIsNull_ReturnsBadRequest() { // Act var badRequestResult = _controller.Get(null); // Assert Assert.IsType <BadRequestObjectResult>(badRequestResult.Result); }
public void Get() { PersonController personController = new PersonController(); Person[] persons = personController.Get().ToArray(); Assert.IsNotNull(persons); }
public async System.Threading.Tasks.Task ShouldNotCrashOnNullQuery() { var l = new DummyLogger(); var r = new MockPersonRepository(); var c = new PersonController(l, r); Assert.Empty(await c.Get(null)); }
public async System.Threading.Tasks.Task ShouldNotReturnUnknownPeople() { var l = new DummyLogger(); var r = new MockPersonRepository(); var c = new PersonController(l, r); Assert.Empty(await c.Get("XXX")); }
public void GetAllContacts() { var testPersons = GetTestPersons(); var controller = new PersonController(); var result = (List <Person>)(controller.Get() as OkObjectResult).Value; Assert.AreEqual(testPersons.Count, result.Count); }
public void Get() { var controller = new PersonController(_personService); var getResponse = controller.Get(91); Assert.IsNotNull(getResponse); Assert.IsInstanceOfType(getResponse, typeof(FormattedContentResult <Person>)); }
public void Post() { // Arrange PersonController controller = new PersonController(); Person per = new Person() { Id = 0, FirstName = "Rohan", LastName = "Jas", Phone = "5614456156", EmailAddress = "*****@*****.**", Status = true }; //controller.Post(per); IEnumerable <Person> resultBeforepost = controller.Get(); controller.Post(per); IEnumerable <Person> resultAfterpost = controller.Get(); Assert.AreEqual(resultBeforepost.Count() + 1, resultAfterpost.Count()); // Assert }
public void GetPersonByIdReturnsAPerson() { //Arrange var personId = 1; Person person = new Person { Id = 1 }; _personService.Setup(p => p.Get(personId)).Returns(person); //Act var controllerReturn = _personController.Get(personId).Result as ObjectResult; var returnedObject = controllerReturn.Value as Person; //Assert Assert.AreEqual(200, controllerReturn.StatusCode.Value); Assert.IsInstanceOf <Person>(returnedObject); Assert.AreEqual(1, returnedObject.Id); }
public void Get_ShouldReturnNumberOfPersonData() { // Arrange //Call this method to seed the test data and to create a instance of Mock Object of In Memory Entity Setup(); expected = 3; //Act //Calling Web Api HTTP Get Action Method var httpResult = personController.Get(); //Converting the httpresult to Content Result var conNegResult = httpResult as NegotiatedContentResult <object>; //Casting the Content of Content Result to Target Object list = ((List <CompletePerson>)conNegResult.Content); //Assert Assert.AreEqual(expected, lst.Count); }
public void Delete() { // Arrange PersonController controller = new PersonController(); controller.Delete(18); Person per = controller.Get(18); Assert.AreEqual(null, per); }
public void Get() { // Arrange PersonController controller = new PersonController(); // Act IEnumerable <Person> result = controller.Get(); // Assert Assert.IsNotNull(result); Assert.AreNotEqual(0, result.Count()); }
public void PersonController_GetList_Empty_Successfull() { var manager = new Mock <IManager>(); manager.Setup(x => x.GetPersonList()).Returns(Task.FromResult(_emptyPersons)); var controller = new PersonController(manager.Object); var result = controller.Get().Result; Assert.AreEqual(0, result.ToList().Count()); }
public void TestGet() { var controller = new PersonController(); //var testPersons = GetTestPersons(); var result = controller.Get(); var contentResult = result as OkNegotiatedContentResult <IEnumerable <Person> >; Assert.IsNotNull(contentResult); }
public async Task Get_NoPeopleInRepository_ReturnsEmptyCollection() { //Arrange Mock <IPersonRepository> repository = new Mock <IPersonRepository>(); PersonController controller = new PersonController(repository.Object); //Act IEnumerable <Person> result = await controller.Get(); //Assert Assert.Empty(result); }
public void Verify_PersonController() { var persons = personController.Get(); Person person = new Person { firstName = "One", lastName = "Two" }; var result = personController.Post(person); Assert.That(persons.Count, Is.GreaterThan(0)); Assert.That(result, Is.EqualTo(true)); }
public async Task CanGetPersons() { _mockPersonService.Setup(s => s.GetPersonsAsync(It.IsAny <CancellationToken>())).ReturnsAsync(new[] { new Person() }); IActionResult result = await _personController.Get(new CancellationToken()); OkObjectResult okResult = Assert.IsType <OkObjectResult>(result); GridData <Person> gridData = Assert.IsType <GridData <Person> >(okResult.Value); Assert.Single(gridData.Data); _mockPersonService.Verify(s => s.GetPersonsAsync(It.IsAny <CancellationToken>()), Times.Once); _mockPersonService.VerifyNoOtherCalls(); }
public void PersonController_Add() { //This should add a person to the database and make sure that they got added. var Name_Original = "Added Person"; var PersonController = new PersonController(); var ItemsAtStart = PersonController.Current().Count(); var Person = PersonController.Add(new Person() { Name = Name_Original, DateOfBirth = DateTime.Now, }); var ItemsAtEnd = PersonController.Current().Count(); Person = PersonController.Get(Person.InstanceId); //The items in our list should have increased by 1. Assert.AreEqual(ItemsAtStart + 1, ItemsAtEnd); Assert.AreEqual(Name_Original, Person.Name); }
public void PersonController_Add_Update_Archive() { var Name_Original = "Added Person"; var Name_Updated = "Updated Person"; var PersonController = new PersonController(); var ItemsAtStart = PersonController.Current().Count(); var Person = PersonController.Add(new Person() { Name = Name_Original, DateOfBirth = DateTime.Now }); Person.Name = Name_Updated; PersonController.Update(Person); PersonController.Archive(Person); Person = PersonController.Get(Person.InstanceId); var ItemsAtEnd = PersonController.Current().Count(); //Make sure our count hasn't changed since the item was archived. Assert.AreEqual(ItemsAtStart, ItemsAtEnd); }