예제 #1
0
        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 PostSuccessfuly()
        {
            bool calledUpdate = false;
            var  mockRep      = new Mock <ICandidateServices>();

            mockRep.Setup(x => x.Update(candidateDetailViewModel)).Callback(() => calledUpdate = true);
            CandidateController candidateController = new CandidateController(mockRep.Object);;

            candidateController.Post(candidateDetailViewModel);
            Assert.IsTrue(calledUpdate);
        }
예제 #3
0
        public void PostMethodInternalServerError()
        {
            //Arrange
            Candidate updateCandidate = new Candidate
            {
                CandidateId = "123",
                FirstName   = "bob"
            };

            Mock <ICandidateRepository> mockCandidateRepository = new Mock <ICandidateRepository>();

            mockCandidateRepository.Setup(x => x.InsertCandidateToDatabase(updateCandidate)).Returns(false);
            CandidateController controller = new CandidateController(mockCandidateRepository.Object);

            //Act
            IHttpActionResult response = controller.Post(updateCandidate);

            Assert.IsInstanceOfType(response, typeof(InternalServerErrorResult));
        }
예제 #4
0
        public void PostTest()
        {
            //Arrange
            Candidate updateCandidate = new Candidate
            {
                CandidateId = "123",
                FirstName   = "bob"
            };

            Mock <ICandidateRepository> mockCandidateRepository = new Mock <ICandidateRepository>();

            mockCandidateRepository.Setup(x => x.InsertCandidateToDatabase(updateCandidate)).Returns(true);

            CandidateController controller = new CandidateController(mockCandidateRepository.Object);

            //Act
            IHttpActionResult response = controller.Post(updateCandidate);
            var contentResult          = response as CreatedAtRouteNegotiatedContentResult <Candidate>;

            //Assert
            Assert.IsNotNull(contentResult);
            Assert.AreEqual("DefaultApi", contentResult.RouteName);
            Assert.AreEqual("123", contentResult.RouteValues["id"]);
        }
예제 #5
0
        public void Should_Be_Ok_When_Post()
        {
            var fakes       = new Fakes();
            var fakeService = fakes.FakeCandidateService().Object;
            var expected    = new CandidateDTO()
            {
                UserId         = 5,
                AccelerationId = 1,
                CompanyId      = 1,
                Status         = 99
            };

            var controller = new CandidateController(fakeService, fakes.Mapper);
            var result     = controller.Post(expected);

            Assert.IsType <OkObjectResult>(result.Result);
            var actual = (result.Result as OkObjectResult).Value as CandidateDTO;

            Assert.NotNull(actual);
            Assert.Equal(expected.UserId, actual.UserId);
            Assert.Equal(expected.AccelerationId, actual.AccelerationId);
            Assert.Equal(expected.CompanyId, actual.CompanyId);
            Assert.Equal(expected.Status, actual.Status);
        }