public void Post() { // Arrange CandidateController controller = SetUpController(); // count before IEnumerable <Candidate> list1 = controller.Get(); int countBefore = list1.Count(); // Act Candidate candidate = new Candidate() { name = "Some Guy", developer = true, qa = true }; var response = controller.Post(candidate); // Assert Location // For this mock DB, 10 will be the next generated 01 Assert.AreEqual(String.Format("http://localhost{0}/softclouds/candidate/10", sPortConfig), response.Headers.Location.AbsoluteUri); // Response status s/b 201 created Assert.AreEqual(response.StatusCode, HttpStatusCode.Created); /// It might be wiser to have a return count method and test that list1 = controller.Get(); int countAfter = list1.Count(); Assert.AreEqual(countAfter, countBefore + 1); }
public void GetTestReturnsResults() { mockedCandidatedDataRepository.Setup(mock => mock.RetrieveAllCandidates()).Returns(manyCandidates); IEnumerable <CandidateDomainObject> candidates = candidateController.Get(); mockedCandidatedDataRepository.Verify(mock => mock.RetrieveAllCandidates()); }
public void ShouldAddRelocationPlaces() { var httpResult = controller.Get(1); var response = httpResult as JsonResult <CandidateDTO>; var candidate = response.Content; int countryId = context.Countries.First().Id; int cityId = context.Cities.First().Id; var newRelocationPlace = new RelocationPlaceDTO { CountryId = countryId, CityId = cityId }; var places = candidate.RelocationPlaces.ToList(); places.Add(newRelocationPlace); candidate.RelocationPlaces = places; var newHttpResult = controller.Put(candidate.Id, candidate); var newResponse = newHttpResult as JsonResult <CandidateDTO>; var newCandidate = newResponse.Content; Assert.IsTrue(newCandidate.RelocationPlaces.Any(x => x.CityId == cityId && x.CountryId == countryId)); }
public void GetTest() { //Arrange Mock <ICandidateRepository> mockCandidateRepository = new Mock <ICandidateRepository>(); mockCandidateRepository.Setup(x => x.GetAllCandidates()).Returns(CreateCandidates()); CandidateController controller = new CandidateController(mockCandidateRepository.Object); //Act IHttpActionResult actionResult = controller.Get(); var contentResult = actionResult as OkNegotiatedContentResult <List <Candidate> >; List <Candidate> candidates = contentResult.Content ?? throw new ArgumentNullException("contentResult.Content"); //Assert Assert.IsNotNull(candidates); Assert.AreEqual(candidates.Count, 9); int id = 1; for (int i = 0; i < candidates.Count; i++) { Assert.AreEqual(candidates[i].CandidateId, id.ToString()); Assert.AreEqual(candidates[i].FirstName, $"FirstName{id.ToString()}"); Assert.AreEqual(candidates[i].Surname, $"Surname{id.ToString()}"); id++; } }
public void Delete() { // Arrange CandidateController controller = SetUpController(); // count before IEnumerable <Candidate> list1 = controller.Get(); int countBefore = list1.Count(); var response = controller.Delete(5); /// It might be wiser to have a return count method and test that list1 = controller.Get(); int countAfter = list1.Count(); Assert.AreEqual(countAfter, countBefore - 1); // Response status s/b 200 OK Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); }
public void GetById() { // Arrange CandidateController controller = SetUpController(); // Act Candidate result = controller.Get(5); // Assert Assert.AreEqual(result.name, "Guy 5"); }
public void GetWithIdWrongIdTest() { //Arrange Mock <ICandidateRepository> mockCandidateRepository = new Mock <ICandidateRepository>(); CandidateController controller = new CandidateController(mockCandidateRepository.Object); //Act IHttpActionResult actionResult = controller.Get(100); //Assert Assert.IsInstanceOfType(actionResult, typeof(NotFoundResult)); }
public void GetDetailSuccessfuly() { bool calledGetDetail = false; var mockRep = new Mock <ICandidateServices>(); mockRep.Setup(x => x.GetDetail(1)).Callback(() => calledGetDetail = true); CandidateController candidateController = new CandidateController(mockRep.Object);; var vm = candidateController.Get(1); Assert.IsTrue(calledGetDetail); }
public void Put() { // Arrange CandidateController controller = SetUpController(); Candidate candidateBefore = controller.Get(7); // Act candidateBefore.name = "Some Guy"; var response = controller.Put(7, candidateBefore); Candidate candidateAfter = controller.Get(7); // Response status s/b 200 OK Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); // Name was changed Assert.AreEqual(candidateAfter.name, "Some Guy"); // No change Assert.AreEqual(candidateAfter.phone, candidateBefore.phone); }
public void CanGetAllCandidates() { var candidates = CreateCandidates(); _repo.Setup(r => r.GetCandidates()).Returns(candidates.AsEnumerable()); var result = _controller.Get(); var okResult = (OkObjectResult)result.Result; var resultValue = (IEnumerable <Candidate>)okResult.Value; _repo.Verify(r => r.GetCandidates(), Times.Once); Assert.AreEqual(candidates.Count(), resultValue.Count()); }
public void Get() { // Arrange CandidateController controller = SetUpController(); // Act IEnumerable <Candidate> result = controller.Get(); // Assert Assert.IsNotNull(result); Assert.AreEqual(result.Count(), 9); // assuming no sorting Assert.AreEqual(result.ElementAt(0).name, "Guy 1"); }
public void Should_Be_Ok_When_Find_By_Id(int userId, int accelerationId, int companyId) { var fakes = new Fakes(); var fakeService = fakes.FakeCandidateService().Object; var expected = fakes.Mapper.Map <CandidateDTO>(fakeService.FindById(userId, accelerationId, companyId)); var controller = new CandidateController(fakeService, fakes.Mapper); var result = controller.Get(userId, accelerationId, companyId); Assert.IsType <OkObjectResult>(result.Result); var actual = (result.Result as OkObjectResult).Value as CandidateDTO; Assert.NotNull(actual); Assert.Equal(expected, actual, new CandidateDTOIdComparer()); }
public void GetWithIdTest() { //Arrange Mock <ICandidateRepository> mockCandidateRepository = new Mock <ICandidateRepository>(); mockCandidateRepository.Setup(x => x.GetCandidateById(12)).Returns(new Candidate { CandidateId = "12", FirstName = "bob" }); CandidateController controller = new CandidateController(mockCandidateRepository.Object); //Act IHttpActionResult actionResult = controller.Get(12); var contentResult = actionResult as OkNegotiatedContentResult <Candidate>; //Assert mockCandidateRepository.Verify(x => x.GetCandidateById(12), Times.Exactly(1)); Assert.IsNotNull(contentResult); Assert.IsNotNull(contentResult.Content); Assert.IsNotNull(contentResult.Content.FirstName); Assert.AreEqual(contentResult.Content.CandidateId, "12"); }
public void ShouldAddSources() { var httpResult = controller.Get(1); var response = httpResult as JsonResult <CandidateDTO>; var candidate = response.Content; var candidateSource = candidate.Sources.First(); string newPath = "path"; candidateSource.Path = newPath; var newHttpResult = controller.Put(candidate.Id, candidate); var newResponse = newHttpResult as JsonResult <CandidateDTO>; var newCandidate = newResponse.Content; Assert.IsTrue(newCandidate.Sources.Any(x => x.Path == newPath)); }