Beispiel #1
0
        public void IndexHappyTest()
        {
            IEnumerable <Candidate> expected = new List <Candidate>
            {
                new Candidate
                {
                    Id         = 1,
                    GenotypeId = 1
                },
                new Candidate
                {
                    Id         = 2,
                    GenotypeId = 2
                }
            };

            var mockRepo = new Mock <IPlantBreedingRepo>();

            mockRepo.Setup(r => r.GetCandidates()).Returns(expected);

            var controller = new CandidatesController(mockRepo.Object);
            var response   = controller.Index() as RedirectToRouteResult;

            Assert.IsNotNull(response);
            Assert.AreEqual("List", response.RouteValues["action"]);
        }
Beispiel #2
0
        public async Task GetAsync_ReturnsAListOfCandidatesWithTheirScores()
        {
            // Arrange
            mock.Setup(m => m.GetCandidatesAsync())
            .Returns(Task.Run(() => PopulateCandidatesWithResults()));

            var candidatesController = new CandidatesController(mock.Object);

            var expected = PopulateCandidatesWithResults();

            // Act
            var result = await candidatesController.GetCandidatesAsync();

            // Assert
            var okObjectResult = result as OkObjectResult;

            Assert.IsNotNull(okObjectResult);

            var actual = okObjectResult.Value as IEnumerable <CandidateWithResultModel>;

            Assert.IsNotNull(actual);

            Assert.AreEqual(expected.Count(), actual.Count());

            for (int i = 0; i < expected.Count(); i++)
            {
                Assert.AreEqual(expected.ElementAt(i).TestTitle, actual.ElementAt(i).TestTitle);
                Assert.AreEqual(expected.ElementAt(i).Score, actual.ElementAt(i).Score);
            }
        }
Beispiel #3
0
        public void GETCandidatesForCrossHappyTest()
        {
            var expected = new List <Candidate>
            {
                new Candidate
                {
                    Year = DateTime.Now.Year
                },
                new Candidate
                {
                    Year = DateTime.Now.Year
                }
            };

            var mockRepo = new Mock <IPlantBreedingRepo>();

            mockRepo.Setup(r => r.GetCandidates()).Returns(expected);

            var result = new CandidatesController(mockRepo.Object).CandidatesForCross() as ViewResult;

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Model);
            Assert.IsNotNull(result.Model as IEnumerable <Candidate>);

            var actual = result.Model as IEnumerable <Candidate>;

            Assert.AreEqual(expected.Count(), actual.Count());
            Assert.IsTrue(Enumerable.SequenceEqual(expected, actual));
        }
Beispiel #4
0
        public void DetailsHappyTest()
        {
            int?id       = 12;
            var expected = new Candidate
            {
                Id         = 1,
                GenotypeId = 1
            };

            var mockRepo = new Mock <IPlantBreedingRepo>();

            mockRepo.Setup(r => r.GetCandidate(id.Value)).Returns(expected);

            var controller = new CandidatesController(mockRepo.Object);

            var response = controller.Details(id) as ViewResult;

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Model);
            Assert.IsNotNull(response.Model as Candidate);

            var actual = response.Model as Candidate;

            Assert.AreEqual(expected, actual);
        }
        public void Equal_Random_Image_Id_Value()
        {
            string image_value_1 = CandidatesController.GenerateImageId();
            string image_value_2 = CandidatesController.GenerateImageId();

            Assert.NotEqual(image_value_1, image_value_2);
        }
Beispiel #6
0
        public void SaveCandidate_EnsureWorks_And_DataPersists()
        {
            Candidate candidate = new Candidate
            {
                FirstName   = "Eduardo",
                LastName_1  = "Perez",
                Email       = "*****@*****.**",
                PhoneNumber = "(442) 123-4567"
            };

            var controller = new CandidatesController();

            controller.Request       = new HttpRequestMessage();
            controller.Configuration = new HttpConfiguration();

            //insert
            var result = controller.SaveCandidateData(candidate);

            Assert.AreEqual(HttpStatusCode.Created, result.StatusCode);
            Candidate c;

            Assert.IsTrue(result.TryGetContentValue <Candidate>(out c));
            Assert.IsNotNull(c.id);
            Assert.AreEqual("Eduardo", c.FirstName);
            _inserted_id = c.id;

            //update
            candidate.id         = _inserted_id;
            candidate.LastName_2 = "updated lastname_2";
            result = controller.SaveCandidateData(candidate, candidate.id);
            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
            c = null;
            Assert.IsTrue(result.TryGetContentValue <Candidate>(out c));
            Assert.IsNotNull(c.id);
            Assert.AreEqual(candidate.LastName_2, c.LastName_2);

            result = controller.GetCandidateData(_inserted_id);

            Assert.IsNotNull(result);
            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
            c = null;
            Assert.IsTrue(result.TryGetContentValue <Candidate>(out c));
            Assert.AreEqual("Eduardo", c.FirstName);

            //luego buscar algo que no existe
            result = controller.GetCandidateData("3");
            Assert.IsNotNull(result);
            Assert.AreEqual(HttpStatusCode.NotFound, result.StatusCode);

            //y por ultimo el borrado de lo creado
            result = controller.DeleteCandidate(_inserted_id);
            Assert.IsNotNull(result);
            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);

            //y  borrado de lo que no existe
            result = controller.DeleteCandidate("3");
            Assert.IsNotNull(result);
            Assert.AreEqual(HttpStatusCode.NotFound, result.StatusCode);
        }
Beispiel #7
0
        public void TestIndexView()

        {
            var        controller = new CandidatesController();
            ViewResult result     = controller.Index();

            Assert.AreEqual("Index", result.ViewName);
        }
Beispiel #8
0
        public void TestDetailsView()
        {
            var controller = new CandidatesController();

            var result    = controller.Details(2) as ViewResult;
            var candidate = (Candidate)result.Model;

            Assert.AreEqual("Meredith", candidate.FirstName);
        }
Beispiel #9
0
        private void AddCandidateBtn_Click(object sender, EventArgs e)
        {
            var controller = new CandidatesController();
            var firstName  = FirstNameTxtBox.Text;
            var lastName   = LastNameTxtBox.Text;
            var phone      = PhoneNumberTxtBox.Text;
            var email      = EmailTxtBox.Text;

            controller.AddCandidate(firstName, lastName, email, phone, Resume);
        }
Beispiel #10
0
 public CandidatesControllerTests()
 {
     _mockAccessTokenService = new Mock <ICandidateAccessTokenService>();
     _mockNotifyService      = new Mock <INotifyService>();
     _mockCrm    = new Mock <ICrmService>();
     _controller = new CandidatesController(
         _mockAccessTokenService.Object,
         _mockNotifyService.Object,
         _mockCrm.Object);
 }
 public CandidatesControllerTests()
 {
     _mockTokenService = new Mock <ICandidateAccessTokenService>();
     _mockCrm          = new Mock <ICrmService>();
     _mockJobClient    = new Mock <IBackgroundJobClient>();
     _request          = new ExistingCandidateRequest {
         Email = "*****@*****.**", FirstName = "John", LastName = "Doe"
     };
     _controller = new CandidatesController(_mockTokenService.Object, _mockCrm.Object, _mockJobClient.Object);
 }
        public async void Delete_Candidate_OK(int id)
        {
            var _controller = new CandidatesController(new DummyRepositoryFacade());

            _controller.Request       = new System.Net.Http.HttpRequestMessage();
            _controller.Configuration = new System.Web.Http.HttpConfiguration();

            var actionResponse = await _controller.Remove(id).ExecuteAsync(new System.Threading.CancellationToken());

            Assert.AreEqual(HttpStatusCode.OK, actionResponse.StatusCode);
        }
Beispiel #13
0
        public void GETDeleteBadIdTest()
        {
            int?id = null;

            var controller = new CandidatesController();

            var response = controller.Delete(id) as HttpStatusCodeResult;

            Assert.IsNotNull(response);
            Assert.IsTrue(response.StatusCode == 400);
        }
Beispiel #14
0
        public void GETCandidatesForCrossEmptyTest()
        {
            var expected = new List <Candidate>();

            var mockRepo = new Mock <IPlantBreedingRepo>();

            mockRepo.Setup(r => r.GetCandidates()).Returns(expected);

            var result = new CandidatesController(mockRepo.Object).CandidatesForCross() as HttpNotFoundResult;

            Assert.IsNotNull(result);
        }
        public async void Get_Candidate_BadId(int id)
        {
            var _controller = new CandidatesController(new DummyRepositoryFacade());

            _controller.Request       = new System.Net.Http.HttpRequestMessage();
            _controller.Configuration = new System.Web.Http.HttpConfiguration();

            var result   = _controller.Get(id);
            var response = await result.ExecuteAsync(new System.Threading.CancellationToken());

            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
        }
Beispiel #16
0
        public void POSTCandidatesForCrossTest()
        {
            int candidate1 = 12, candidate2 = 13;

            var result = new CandidatesController().CandidatesForCross(candidate1, candidate2) as RedirectToRouteResult;

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.RouteValues);
            Assert.IsNotNull(result.RouteValues["action"]);
            Assert.IsNotNull(result.RouteValues["controller"]);
            Assert.IsNotNull(result.RouteValues["action"].ToString() == "CreateFromCandidate");
            Assert.IsNotNull(result.RouteValues["controller"].ToString() == "Families");
        }
        public void Get_Candidate(int id)
        {
            var _controller = new CandidatesController(new DummyRepositoryFacade());

            _controller.Request       = new System.Net.Http.HttpRequestMessage();
            _controller.Configuration = new System.Web.Http.HttpConfiguration();

            var jsonResult = _controller.Get(id);
            var result     = jsonResult as JsonResult <CandidateDTO>;

            Assert.AreEqual("TESTNAME", result.Content.FirstName);
            Assert.AreEqual(id, result.Content.Id);
        }
Beispiel #18
0
        public CandidatesControllerTests()
        {
            _mockTokenService = new Mock <ICandidateAccessTokenService>();
            _mockCrm          = new Mock <ICrmService>();
            _mockJobClient    = new Mock <IBackgroundJobClient>();
            _mockDateTime     = new Mock <IDateTimeProvider>();
            _request          = new ExistingCandidateRequest {
                Email = "*****@*****.**", FirstName = "John", LastName = "Doe"
            };
            _controller = new CandidatesController(_mockTokenService.Object, _mockCrm.Object, _mockJobClient.Object, _mockDateTime.Object);

            // Freeze time.
            _mockDateTime.Setup(m => m.UtcNow).Returns(DateTime.UtcNow);
        }
        public async Task Shoud_Get_EcartType_In_CandidateService()
        {
            double ecartType = 2.6;

            var mockService = Substitute.For <ICandidatesService>();

            mockService.GetEcartTypeAsync().Returns(ecartType);
            var logger = Substitute.For <ILog>();
            var candidateController = new CandidatesController(mockService, logger);
            var result = await candidateController.GetEcartTypeAsync();

            var okResult = result as OkObjectResult;

            Assert.AreEqual(200, okResult.StatusCode);
        }
 public void SetUp()
 {
     SetupCandidateResorces();
     _service = new Mock <ICandidateService>();
     MockGetAllCadnidatesAsync();
     MockGetCandidateAsync();
     MockAddCandidateAsync();
     MockUpdateCandidateAsync();
     MockDeleteSkillAsync();
     _controller     = new CandidatesController(_service.Object);
     _filterResource = new FilterResource()
     {
         SkillId = 1
     };
 }
Beispiel #21
0
        public void GETDeleteNullTest()
        {
            int?      id       = 12;
            Candidate expected = null;

            var mockRepo = new Mock <IPlantBreedingRepo>();

            mockRepo.Setup(r => r.GetCandidate(id.Value)).Returns(expected);

            var controller = new CandidatesController(mockRepo.Object);

            var response = controller.Delete(id) as HttpNotFoundResult;

            Assert.IsNotNull(response);
            Assert.IsTrue(response.StatusCode == 404);
        }
Beispiel #22
0
        public void Create_Post()

        {
            var controller = new CandidatesController();


            Candidate          candidate = GetCandidate(9, "roger", "test");
            CandidateViewModel cvm       = new CandidateViewModel();

            cvm.SelectedAllSkills = getSkill();
            cvm.Candidate         = candidate;
            controller.Create(cvm);

            IEnumerable <Candidate> candidates = getAllCandidate();

            Assert.IsTrue(candidates.Contains(candidate));
        }
        public void Put_Candidate_OK(int id, string testname)
        {
            var _controller = new CandidatesController(new DummyRepositoryFacade());

            _controller.Request       = new HttpRequestMessage();
            _controller.Configuration = new HttpConfiguration();

            var getResult     = _controller.Get(id);
            var jsonGetResult = getResult as JsonResult <CandidateDTO>;
            var candidateDto  = jsonGetResult.Content;

            candidateDto.FirstName = testname;

            var putResult         = _controller.Put(id, candidateDto);
            var jsonPutResult     = getResult as JsonResult <CandidateDTO>;
            var candidateAfterPut = jsonPutResult.Content;

            Assert.AreEqual(testname, candidateAfterPut.FirstName);
        }
Beispiel #24
0
        public void POSTDeleteHappyCase()
        {
            int id        = 1;
            var crossType = new Candidate
            {
                Id         = 1,
                GenotypeId = 1
            };

            var mockRepo = new Mock <IPlantBreedingRepo>();

            var controller = new CandidatesController(mockRepo.Object);

            var response = controller.DeleteConfirmed(id) as RedirectToRouteResult;

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.RouteValues);
            Assert.AreEqual("Index", response.RouteValues["action"]);
        }
        [DataRow(8)] // Un autre moyen de passer des paramètres pour les tests
        public async Task Shoud_Get_Average_In_CandidateService(double average)
        {
            var candidates = new List <CandidateDTO>()
            {
                new CandidateDTO("minamba", "camara", "c#", 10),
                new CandidateDTO("naruto", "uzumaki", "php", 8),
                new CandidateDTO("sasuke", "uchiha", "python", 15),
            };

            var mockService = Substitute.For <ICandidatesService>();

            mockService.GetCandidatesAsync().Returns(candidates);
            var logger = Substitute.For <ILog>();
            var candidateController = new CandidatesController(mockService, logger);
            var result = await candidateController.GetAverageAsync();

            var okResult = result as OkObjectResult;


            Assert.AreEqual(200, okResult.StatusCode);
        }
Beispiel #26
0
        public async Task GetCandidatesStantdardDeviationAsync_ShouldReturnTheStantdardDeviationOfTheCandidatesScores()
        {
            // Arrange
            mock.Setup(m => m.GetCandidatesStantdardDeviationAsync())
            .Returns(Task.Run(() => CalculateStdDeviation(PopulateCandidatesWithResults())));

            var candidatesController = new CandidatesController(mock.Object);

            double expected = CalculateStdDeviation(PopulateCandidatesWithResults());

            // Act
            var result = await candidatesController.GetCandidatesStantdardDeviationAsync();

            // Assert
            var okObjectResult = result as OkObjectResult;

            Assert.IsNotNull(okObjectResult);

            var actual = okObjectResult.Value;

            Assert.AreEqual(expected, actual);
        }
Beispiel #27
0
        public void SaveCandidate_ValidateParams()
        {
            Candidate candidate = new Candidate
            {
                id          = "5",
                FirstName   = "Eduardo",
                LastName_1  = "Perez",
                Email       = "*****@*****.**",
                PhoneNumber = "(442) 123-4567"
            };

            var controller = new CandidatesController();

            controller.Request       = new HttpRequestMessage();
            controller.Configuration = new HttpConfiguration();

            var result = controller.SaveCandidateData(candidate, "6");

            Assert.AreEqual(HttpStatusCode.Conflict, result.StatusCode);

            candidate.id = null;
            result       = controller.SaveCandidateData(candidate, "5");
            Assert.AreEqual(HttpStatusCode.Conflict, result.StatusCode);

            candidate.id    = "5";
            candidate.Email = "";
            result          = controller.SaveCandidateData(candidate, "5");
            Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode);

            candidate.Email       = "*****@*****.**";
            candidate.PhoneNumber = "";
            result = controller.SaveCandidateData(candidate);
            Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode);

            candidate.PhoneNumber = "(442) 123-4567";
            candidate.FirstName   = null;
            result = controller.SaveCandidateData(candidate);
            Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode);
        }
Beispiel #28
0
        public async Task GetCandidatesAverageAsync_ShouldReturnTheAverageOfTheCandidatesScores()
        {
            // Arrange
            mock.Setup(m => m.GetCandidatesAverageAsync())
            .Returns(Task.Run(() => PopulateCandidatesWithResults().Average(c => c.Score)));

            var candidatesController = new CandidatesController(mock.Object);

            double expected = PopulateCandidatesWithResults().Average(c => c.Score);

            // Act
            var result = await candidatesController.GetCandidatesAverageAsync();

            // Assert
            var okObjectResult = result as OkObjectResult;

            Assert.IsNotNull(okObjectResult);

            var actual = okObjectResult.Value;

            Assert.AreEqual(expected, actual);
        }
        public async Task Shoud_Add_CandidateTest_In_CandidateService()
        {
            var candidate = new Candidate()
            {
                FirstName = "Minamba",
                LastName  = "Camara",
                Test      = new TestModel()
                {
                    Title = "c#"
                }
            };

            var mockService = Substitute.For <ICandidatesService>();

            mockService.AddCandidateTestAsync(candidate).Returns(candidate);
            var logger = Substitute.For <ILog>();
            var candidateController = new CandidatesController(mockService, logger);
            var result = await candidateController.AddCandidateTestAsync(candidate);

            var okResult = result as CreatedAtActionResult;

            Assert.AreEqual(201, okResult.StatusCode);
        }
        public async Task Shoud_Get_Candidates_In_Controller()
        {
            var candidates = new List <CandidateDTO>()
            {
                new CandidateDTO("camara", "minamba", "c#", 12),
                new CandidateDTO("uzumaki", "naruto", "python", 14),
                new CandidateDTO("uchiha", "sasuke", ".net core", 18)
            };
            var candidateService = Substitute.For <ICandidatesService>();
            var logger           = Substitute.For <ILog>();

            candidateService.GetCandidatesAsync().Returns(candidates);
            var CandidateController = new CandidatesController(candidateService, logger);

            var result = await CandidateController.GetCandidatesAsync();

            var okResult = result as OkObjectResult;

            //string serialize1 = JsonConvert.SerializeObject(candidates);
            //string serialize2 = JsonConvert.SerializeObject(result);

            Assert.AreEqual(200, okResult.StatusCode);
            /* Assert.AreEqual(serialize1, serialize2);*/ //Test return objects
        }