public void ReturnsCsvOfSkillsNames() { // Arrange var expected = "illustrator (5), oration (4), kotlin (3)"; var testId = 23; var testSkills = new List <CandidateSkill> { new CandidateSkill { CandidateId = testId, Name = "illustrator", Weighting = 5 }, new CandidateSkill { CandidateId = testId, Name = "oration", Weighting = 4 }, new CandidateSkill { CandidateId = testId, Name = "kotlin", Weighting = 3 } }; // Act var actual = CandidateHelper.GetCandidatesSkillsCsv(testSkills); // Assert Assert.AreEqual(expected, actual); }
public void ReturnsEmptyStringWhenNullName() { // Arrange var expected = string.Empty; // Act var actual = CandidateHelper.GetFirstName(null); // Assert Assert.AreEqual(expected, actual); }
public void ReturnsLastNameWhenNameEqualsTwoNames() { // Arrange var expected = "Chan"; var testName = "Bravo Chan"; // Act var actual = CandidateHelper.GetLastName(testName); // Assert Assert.AreEqual(expected, actual); }
public void ReturnEmptyStringWhenNameEmpty() { // Arrange var expected = string.Empty; var testName = string.Empty; // Act var actual = CandidateHelper.GetFirstName(testName); // Assert Assert.AreEqual(expected, actual); }
public void ReturnFirstNameWhenNameIncludesMoreThanTwoNames() { // Arrange var expected = "Thomasine"; var testName = "Thomasine From To"; // Act var actual = CandidateHelper.GetFirstName(testName); // Assert Assert.AreEqual(expected, actual); }
public void ReturnsCandidateIdOnAllSkills() { // Arrange var testId = 20; var testSkillTags = "fundraising, swift, creativity, reliable, cooking"; var testWeightings = new List <int> { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; // Act var actual = CandidateHelper.GetCandidateSkills(testId, testSkillTags, testWeightings); // Assert Assert.AreEqual(5, actual.Count()); Assert.IsTrue(actual.All(s => s.CandidateId == testId)); }
public void ReturnListWithCorrectWeightingsWhenDuplicatedSkillsRemoved() { // Arrange var testId = 20; var testSkillTags = "reliable, reliable, ms-office, xcode, detail"; var testWeightings = new List <int> { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; // Act var actual = CandidateHelper.GetCandidateSkills(testId, testSkillTags, testWeightings); // Assert Assert.AreEqual(4, actual.Count()); Assert.AreEqual(testWeightings[0], actual[0].Weighting); Assert.AreEqual(testWeightings[1], actual[1].Weighting); Assert.AreEqual(testWeightings[2], actual[2].Weighting); Assert.AreEqual(testWeightings[3], actual[3].Weighting); }
private async Task <IReadOnlyList <Candidate> > RetrieveAllCandidatesWithWeightedSkills() { var weightings = GetStrengthWeightings(); var sourceItems = await GetSourceCandidates(); var candidates = new List <Candidate>(); foreach (var item in sourceItems) { var candidate = CandidateHelper.GetCandidateEntity(item, weightings); candidates.Add(candidate); } var orderedCandidates = candidates .OrderBy(c => c.LastName) .ThenBy(c => c.FirstName) .ToList(); return(orderedCandidates); }
public void ReturnListWithZeroWeightingsWhenMoreSkillsThanWeighting() { // Arrange var testId = 20; var testSkillTags = "fundraising, swift, creativity, reliable, cooking"; var testWeightings = new List <int> { 5, 2, 1 }; // Act var actual = CandidateHelper.GetCandidateSkills(testId, testSkillTags, testWeightings); // Assert Assert.AreEqual(5, actual.Count()); Assert.AreEqual(testWeightings[0], actual[0].Weighting); Assert.AreEqual(testWeightings[1], actual[1].Weighting); Assert.AreEqual(testWeightings[2], actual[2].Weighting); Assert.AreEqual(0, actual[3].Weighting); Assert.AreEqual(0, actual[4].Weighting); }
public void ReturnListWithCorrectWeightings() { // Arrange var testId = 20; var testSkillTags = "fundraising, swift, creativity, reliable, cooking"; var testWeightings = new List <int> { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; // Act var actual = CandidateHelper.GetCandidateSkills(testId, testSkillTags, testWeightings); // Assert Assert.AreEqual(5, actual.Count()); Assert.AreEqual(testWeightings[0], actual[0].Weighting); Assert.AreEqual(testWeightings[1], actual[1].Weighting); Assert.AreEqual(testWeightings[2], actual[2].Weighting); Assert.AreEqual(testWeightings[3], actual[3].Weighting); Assert.AreEqual(testWeightings[4], actual[4].Weighting); }
public void ReturnListFromCsvWithNoSpaces() { // Arrange var testId = 20; var testSkillTags = "fundraising, swift, creativity, reliable, cooking"; var testWeightings = new List <int> { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; // Act var actual = CandidateHelper.GetCandidateSkills(testId, testSkillTags, testWeightings); // Assert Assert.AreEqual(5, actual.Count()); Assert.AreEqual("fundraising", actual[0].Name); Assert.AreEqual("swift", actual[1].Name); Assert.AreEqual("creativity", actual[2].Name); Assert.AreEqual("reliable", actual[3].Name); Assert.AreEqual("cooking", actual[4].Name); }
private static void Assert(bool shouldSetDormant, bool shouldSendReminder, SendAccountRemindersStrategy strategy, Mock <IHousekeepingStrategy> successor, Mock <IUserWriteRepository> userWriteRepository, Mock <ICandidateWriteRepository> candidateWriteRepository, Mock <ICommunicationService> communicationService, User user, Candidate candidate) { User savedUser = null; userWriteRepository.Setup(r => r.Save(It.IsAny <User>())).Callback <User>(u => savedUser = u); Candidate savedCandidate = null; candidateWriteRepository.Setup(r => r.Save(It.IsAny <Candidate>())).Callback <Candidate>(c => savedCandidate = c); CommunicationToken[] communicationTokens = null; communicationService.Setup(s => s.SendMessageToCandidate(user.EntityId, MessageTypes.SendDormantAccountReminder, It.IsAny <IEnumerable <CommunicationToken> >())) .Callback <Guid, MessageTypes, IEnumerable <CommunicationToken> >((id, mt, ct) => { communicationTokens = ct.ToArray(); }); strategy.Handle(user, candidate); if (shouldSetDormant) { //User and Candidate were updated userWriteRepository.Verify(r => r.Save(It.IsAny <User>()), Times.Once); savedUser.Should().NotBeNull(); candidateWriteRepository.Verify(r => r.Save(It.IsAny <Candidate>()), Times.Once); savedCandidate.Should().NotBeNull(); //User was set as dormant and comms were disabled savedUser.Status.Should().Be(UserStatuses.Dormant); CandidateHelper.IndividualCommunicationPreferences(savedCandidate.CommunicationPreferences) .Any(p => p.EnableEmail && p.EnableText) .Should() .BeFalse(); } else { //User and Candidate were not updated userWriteRepository.Verify(r => r.Save(It.IsAny <User>()), Times.Never); candidateWriteRepository.Verify(r => r.Save(It.IsAny <Candidate>()), Times.Never); savedUser.Should().BeNull(); savedCandidate.Should().BeNull(); } if (shouldSendReminder) { //Strategy handled the request successor.Verify(s => s.Handle(user, candidate), Times.Never); //Message was sent communicationService.Verify(s => s.SendMessageToCandidate(candidate.EntityId, MessageTypes.SendDormantAccountReminder, It.IsAny <IEnumerable <CommunicationToken> >()), Times.Once); communicationTokens.Should().NotBeNull(); var lastLogin = user.LastLogin ?? DateTime.UtcNow; var lastLoginInDays = (DateTime.UtcNow - lastLogin).Days; var lastLoginInDaysFormatted = lastLoginInDays > 270 ? "almost a year" : string.Format("{0} days", lastLoginInDays); var expectedCommunicationTokens = new[] { new CommunicationToken(CommunicationTokens.CandidateFirstName, candidate.RegistrationDetails.FirstName), new CommunicationToken(CommunicationTokens.LastLogin, lastLoginInDaysFormatted), new CommunicationToken(CommunicationTokens.AccountExpiryDate, lastLogin.AddDays(365).ToLongDateString()), new CommunicationToken(CommunicationTokens.Username, candidate.RegistrationDetails.EmailAddress) }; communicationTokens.ShouldBeEquivalentTo(expectedCommunicationTokens); } else { //Strategy did not handle the request successor.Verify(s => s.Handle(user, candidate), Times.Once); //Message was not sent communicationService.Verify(s => s.SendMessageToCandidate(user.EntityId, MessageTypes.SendActivationCodeReminder, It.IsAny <IEnumerable <CommunicationToken> >()), Times.Never); communicationTokens.Should().BeNull(); } }
public void TestNewRegistration() { SecurityService securityService = new SecurityService(); string realPassword = "******"; //tests the lower casing of the password as well User expectedUser = UserHelper.Get(null, "First_name", false, "Last_name", "1234567890", UserRoles.Candidate, "", "1234567890"); expectedUser.password = securityService.HashUserNameAndPassword(expectedUser.phone_number.ToString(), realPassword); Candidate expectedCandidate = CandidateHelper.Get("cfn", "cln", 1234567891, Castes.Jain, HighestEducations.BE_BTECH, FamilyTypes.Joint, Genders.Female, Religions.HINDU); Address expectedUserAddress = AddressHelper.Get("ual1", "ual2", Districts.NASHIK, States.GUJRAT, Talukas.SHIROL, 123); Address expectedCandidateAddress = AddressHelper.Get("cal1", "cal2", Districts.KOLHAPUR, States.GOA, Talukas.DAUND, 345); NewRegistrationViewModel newRegistration = new NewRegistrationViewModel(); newRegistration.address_line_1 = expectedUserAddress.address_line_1; newRegistration.address_line_2 = expectedUserAddress.address_line_2; newRegistration.candidate_address_line_1 = expectedCandidateAddress.address_line_1; newRegistration.candidate_address_line_2 = expectedCandidateAddress.address_line_2; newRegistration.candidate_district_id = expectedCandidateAddress.district_id; newRegistration.candidate_first_name = expectedCandidate.first_name; newRegistration.candidate_last_name = expectedCandidate.last_name; newRegistration.candidate_phone_number = expectedCandidate.phone_number; newRegistration.candidate_state_id = expectedCandidateAddress.state_id; newRegistration.candidate_taluka_id = expectedCandidateAddress.taluka_id; newRegistration.caste_id = expectedCandidate.caste_id; newRegistration.district_id = expectedUserAddress.district_id; newRegistration.education_id = expectedCandidate.education_id; newRegistration.familytype_id = expectedCandidate.family_type_id; newRegistration.first_name = expectedUser.first_name; newRegistration.gender_id = expectedCandidate.gender_id; newRegistration.language = new int[] { Languages.Marathi, Languages.Hindi }; newRegistration.last_name = expectedUser.last_name; newRegistration.phone_number = Convert.ToInt64(expectedUser.phone_number); newRegistration.religion_id = expectedCandidate.religion_id; newRegistration.state_id = expectedUserAddress.state_id; newRegistration.taluka_id = expectedUserAddress.taluka_id; newRegistration.zip_code = expectedUserAddress.zip_code; newRegistration.candidate_zip_code = expectedCandidateAddress.zip_code; RegistrationService registrationService = new RegistrationService(this.connectionStringService, securityService, IOptionsHelper.Get()); var response = registrationService.RegisterNewCandidate(newRegistration); Assert.True(response.IsSuccess, "Registration Response Failed."); Assert.Equal("1234567890", response.Data.user_name); Assert.Equal(realPassword, response.Data.password); //User User actualUser = connectionForTest .QueryFirst <User>("Select * from user_table where user_name = @user_name", new { expectedUser.user_name }); Assert.NotNull(actualUser); UserHelper.Assrt(expectedUser, actualUser); //UserAddress Address actualUserAddress = connectionForTest .QueryFirst <Address>("Select * from address where id = @address_id", new { actualUser.address_id }); Assert.NotNull(actualUserAddress); AddressHelper.Assrt(expectedUserAddress, actualUserAddress); //Candidate Candidate actualCandidate = connectionForTest .QueryFirst <Candidate>("Select * from Candidate where user_id = @id", new { actualUser.id }); Assert.NotNull(actualCandidate); CandidateHelper.Assrt(expectedCandidate, actualCandidate); //Candidate Address Address actualCandidateAddress = connectionForTest .QueryFirst <Address>("Select * from address where id = @address_id", new { actualCandidate.address_id }); Assert.NotNull(actualCandidateAddress); AddressHelper.Assrt(expectedCandidateAddress, actualCandidateAddress); }