public async Task ResultShouldBeSuccess() { var search = new JobSearch(); var app = new JobApplication(search, "Microsoft", "Developer"); await AddAsync(app); var command = new SubmitApplicationCommand { ApplicationId = app.Id, SubmittedOn = DateTime.Now }; var response = await SendAsync(command); response.IsSuccess.ShouldBeTrue(); }
private void InitializeTestEntities() { _search = new JobSearch(); _user = new User { Email = _startingEmail, Password = PasswordUtils.CreatePasswordHash(_startingEmail, _oldPassword), LastVisitedJobSearch = _search, FullName = "starting name" }; _unitOfWork.Users.Add(_user); _unitOfWork.Commit(); }
public void CreateCompanyList(JobSearch jobsearch) { ExistingCompanyList = jobsearch.Companies .OrderBy(x => x.Name) .Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }) .ToList(); ExistingCompanyList.Insert(0, new SelectListItem { Text = "<None Selected>", Value = "0" }); }
public void Does_Not_Return_Entities_Not_In_Search_Results() { // Setup JobSearch search = new JobSearch(); Company company = new Company { JobSearch = search }, company2 = new Company { JobSearch = search }; Contact contact = new Contact { Company = company }, contact2 = new Contact { Company = company }; Task task = new Task { Company = company }, task2 = new Task { Company = company }; _unitOfWork.Companies.Add(company); _unitOfWork.Companies.Add(company2); _unitOfWork.Contacts.Add(contact); _unitOfWork.Contacts.Add(contact2); _unitOfWork.Tasks.Add(task); _unitOfWork.Tasks.Add(task2); _unitOfWork.Commit(); // Result for ISearchProvider.Search() to return SearchProviderResult searchResult = new SearchProviderResult(); searchResult.FoundCompanyIds.Add(company.Id); searchResult.FoundContactIds.Add(contact.Id); searchResult.FoundTaskIds.Add(task.Id); var mock = new Mock <ISearchProvider>(); mock.Setup(x => x.SearchByJobSearchId("Query", search.Id)).Returns(searchResult); // Act SearchResultEntities result = new EntitySearchQuery(_unitOfWork, mock.Object).WithSearchQuery("Query").WithJobSearchId(search.Id).Execute(); // Verify Assert.IsNotNull(result, "Search results returned a null result"); Assert.IsFalse(result.Companies.Contains(company2), "Search results incorrectly contained the 2nd company"); Assert.IsFalse(result.Contacts.Contains(contact2), "Search results incorrectly contained the 2nd contact"); Assert.IsFalse(result.Tasks.Contains(task2), "Search results incorrectly contained the 2nd task"); }
public void Can_Find_Result_Entities_From_Database() { // Setup JobSearch search = new JobSearch(); Company company1 = new Company { JobSearch = search }, company2 = new Company { JobSearch = search }; Contact contact = new Contact { Company = company1 }; Task task = new Task { Company = company1 }; _unitOfWork.Companies.Add(company1); _unitOfWork.Companies.Add(company2); _unitOfWork.Contacts.Add(contact); _unitOfWork.Tasks.Add(task); _unitOfWork.Commit(); // Result for ISearchProvider.Search() to return SearchProviderResult searchResult = new SearchProviderResult(); searchResult.FoundCompanyIds.Add(company1.Id); searchResult.FoundCompanyIds.Add(company2.Id); searchResult.FoundContactIds.Add(contact.Id); searchResult.FoundTaskIds.Add(task.Id); var mock = new Mock <ISearchProvider>(); mock.Setup(x => x.SearchByJobSearchId("Query", search.Id)).Returns(searchResult); // Act SearchResultEntities result = new EntitySearchQuery(_unitOfWork, mock.Object).WithSearchQuery("Query").WithJobSearchId(search.Id).Execute(); // Verify Assert.IsNotNull(result, "Search provider returned a null result"); Assert.AreEqual(2, result.Companies.Count, "Incorrect number of companies was returned"); Assert.AreEqual(1, result.Contacts.Count, "Incorrect number of contacts was returned"); Assert.AreEqual(1, result.Tasks.Count, "incorrect number of tasks was returned"); Assert.IsTrue(result.Companies.Contains(company1), "Returned company list did not contain the first company"); Assert.IsTrue(result.Companies.Contains(company2), "Returned company list did not conain the second company"); Assert.AreEqual(contact, result.Contacts[0], "Returned contact was incorrect"); Assert.AreEqual(task, result.Tasks[0], "Returned task was incorrect"); }
/// <summary> /// Executes the command /// </summary> /// <returns></returns> /// <exception cref="MJLEntityNotFoundException">Thrown when the specified user is not found</exception> public virtual JobSearch Execute() { var context = _serviceFactory.GetService <MyJobLeadsDbContext>(); // Retrieve the user var user = context.Users.Where(x => x.Id == _userId).FirstOrDefault(); if (user == null) { throw new MJLEntityNotFoundException(typeof(User), _userId); } // Retrieve the milestone this job search should start with //var milestone = _serviceFactory.GetService<StartingMilestoneQuery>() // .Execute(new StartingMilestoneQueryParams { OrganizationId = user.OrganizationId }); // Create the job search var search = new JobSearch { Name = _name, Description = _description, User = user, Companies = new List <Company>(), History = new List <JobSearchHistory>() }; // Create the history record search.History.Add(new JobSearchHistory { Name = _name, Description = _description, AuthoringUser = user, HistoryAction = MJLConstants.HistoryInsert, DateModified = DateTime.Now }); // Perform validation var validator = _serviceFactory.GetService <IValidator <JobSearch> >(); validator.ValidateAndThrow(search); context.JobSearches.Add(search); context.SaveChanges(); return(search); }
public void Can_Get_Number_Of_Member_Contacts() { // Setup var org1 = new Organization(); var org2 = new Organization(); var user1 = new User { Organization = org1, IsOrganizationAdmin = true }; var user2 = new User { Organization = org2 }; var js1 = new JobSearch { User = user1 }; var js2 = new JobSearch { User = user2 }; var company1 = new Company { JobSearch = js1 }; var company2 = new Company { JobSearch = js2 }; var contact1 = new Contact { Company = company1 }; var contact2 = new Contact { Company = company2 }; var contact3 = new Contact { Company = company1 }; _context.Contacts.Add(contact1); _context.Contacts.Add(contact2); _context.Contacts.Add(contact3); _context.SaveChanges(); // Act var result = new OrganizationByAdministeringUserQuery(_context).Execute(new OrganizationByAdministeringUserQueryParams { AdministeringUserId = user1.Id }); // Verify Assert.AreEqual(2, result.NumContacts, "Number of contacts was incorrect"); }
public void User_Associated_With_Contacts_JobSearch_Is_Authorized() { // Setup User user = new User(); JobSearch jobSearch = new JobSearch { User = user }; _unitOfWork.JobSearches.Add(jobSearch); _unitOfWork.Commit(); // Act bool result = new IsUserAuthorizedForJobSearchQuery(_unitOfWork).WithUserId(user.Id).WithJobSearchId(jobSearch.Id).Execute(); // Verify Assert.IsTrue(result, "User was incorrectly not authorized for the job search"); }
public void Milestone_Progress_Is_1_When_Milestone_Has_No_Metrics() { // Setup JobSearch search = new JobSearch { CurrentMilestone = new MilestoneConfig { JobSearchMetrics = new JobSearchMetrics() }, Metrics = new JobSearchMetrics() }; // Act JobSearchMilestoneProgress result = new JobSearchMilestoneProgress(search); // Verify Assert.AreEqual(1, result.TotalProgress, "Milestone's total progress value was incorrect"); }
public PageList <Job> GetJobs(JobSearch search) { search.Page.OrderField = "j.CreateTime"; string sql = @" SELECT j.AutoID, j.PlanID, j.UserAutoID, j.PlanTitle, j.IsComplete, j.CreateTime, j.UpdateTime, j.Variables, j.Name, j.PlanAutoID, j.DecimalCount, j.JobType, j.DeleteFlag FROM dbo.JobDB j (NOLOCK) WHERE j.DeleteFlag= 0 "; var param = ""; if (search.BeginDate.HasValue) { param += " AND j.CreateTime >= @BeginDate "; } if (search.EndDate.HasValue) { param += " AND j.CreateTime <= @EndDate "; } if (search.IsComplete >= 0) { param += " AND j.IsComplete = @IsComplete "; } if (!string.IsNullOrEmpty(search.Author)) { param += " AND j.UserAutoID = @Author "; } if (!string.IsNullOrEmpty(search.PlanName)) { param += " AND j.PlanTitle Like '%" + search.PlanName + "%' "; } if (!string.IsNullOrEmpty(search.JobName)) { param += " AND j.Name Like '%" + search.JobName + "%' "; } return(QueryPage <Job>(sql, search, search.Page)); }
public void Execute_Doesnt_Change_Description_If_SetDescription_Not_Called() { // Setup InitializeTestEntities(); // Act new EditJobSearchCommand(_unitOfWork).WithJobSearchId(_jobSearch.Id) .SetName("New Name") .CalledByUserId(_user.Id) .Execute(); // Verify JobSearch result = _unitOfWork.JobSearches.Fetch().Single(); Assert.AreEqual("New Name", result.Name, "The JobSearch had an incorrect name"); Assert.AreEqual("Test Description", result.Description, "The JobSearch had an incorrect description"); }
public async Task ShouldSubmit() { var search = new JobSearch(); var app = new JobApplication(search, "Microsoft", "Developer"); await AddAsync(app); var command = new SubmitApplicationCommand { ApplicationId = app.Id, SubmittedOn = DateTime.Now }; await SendAsync(command); var submittedApp = await FindAsync <JobApplication>(app.Id, collectionIncludes : new string[] { nameof(JobApplication.Transitions) }); submittedApp.CurrentStatus.ShouldBe(ApplicationStatuses.SUBMITTED); }
public async Task <IActionResult> Upsert(int?id) { JobSearch obj = new JobSearch(); if (id == null) { //true for insert or create return(View(obj)); } obj = await _jsRepo.GetAsync(SD.JobSearchAPIPath, id.GetValueOrDefault()); if (obj == null) { //update return(NotFound()); } return(View(obj)); }
public void Can_Add_To_Hidden_Company_Status_List() { // Setup InitializeTestEntities(); _jobSearch.HiddenCompanyStatuses = "status1;status2;"; _unitOfWork.Commit(); // Act new EditJobSearchCommand(_unitOfWork).WithJobSearchId(_jobSearch.Id) .HideCompanyStatus("new1") .HideCompanyStatus("new2") .CalledByUserId(_user.Id) .Execute(); JobSearch result = _unitOfWork.JobSearches.Fetch().Single(); // Verify Assert.AreEqual("status1;status2;new1;new2;", result.HiddenCompanyStatuses, "Hidden company statuses value was incorrect"); }
public static async Task SeedTestData(ApplicationDbContext context) { if (!context.JobSearches.Any()) { var search = new JobSearch() { Title = "Job Search 2020" }; context.JobSearches.Add(search); var resumeContents = "References:<ol><li><i>available</i></li><li>upon</li><li>request</li></ol>"; var application1 = new JobApplication(search, "Microsoft", "Junior Developer") { JobDescription = "Try not to break Windows.<br />Must <strong>love</strong>: <ul><li>C#</li></ul><br>We value diversity.", JobDescriptionFormat = Formats.HTML, CoverLetter = "Hello, I would like a job. Please see my resume.", Location = Location.Toronto, Resume = resumeContents, ResumeFormat = Formats.HTML }; new TransitionManager(application1).Submit(); application1.RecordEmployerContact("Hi, we have received your application and if we can be bothered we'll be in touch.", "Jane Doe", "Application received"); context.Applications.Add(application1); var application2 = new JobApplication(search, "Facebook", "Junior Stooge #3") { JobDescription = "We need someone to fix our facial recognition algorithm to be able to identity minorities.", JobDescriptionFormat = Formats.HTML, CoverLetter = "Hello, I would like a job. Please see my resume.", Location = Location.Remote, Resume = resumeContents, ResumeFormat = Formats.HTML }; var manager2 = new TransitionManager(application2); manager2.Submit(); application2.RecordEmployerContact("Hi, we have received your application and if we can be bothered we'll be in touch.", "Tim Apple", "Application received"); manager2.Close(ApplicationResolution.REJECTED); application2.RecordEmployerContact("No thanks. Don't call us.", "Tim Apple", "Your rejection"); context.Applications.Add(application2); await context.SaveChangesAsync(); } }
private void InitializeTestEntities() { _user1 = new User(); _user2 = new User(); _search1 = new JobSearch { User = _user1 }; _search2 = new JobSearch { User = _user2 }; _search3 = new JobSearch { User = _user1 }; _unitOfWork.JobSearches.Add(_search1); _unitOfWork.JobSearches.Add(_search2); _unitOfWork.JobSearches.Add(_search3); _unitOfWork.Commit(); }
public static bool Save(JobSearch model) { string sqlStr = "select count(1) from JobSearch where 1=1 "; List <MySqlParameter> pms = new List <MySqlParameter>(); using (DbCommand cmd = db.GetSqlStringCommand(sqlStr)) { cmd.Parameters.AddRange(pms.ToArray()); int i = (int)db.ExecuteScalar(cmd); if (i > 0) { return(Update(model)); } else { return(Insert(model)); } } }
public void New_JobSearch_Queries_For_Organizations_Starting_MilestoneConfig_When_User_In_Organization() { // Setup InitializeTestEntities(); MilestoneConfig config = new MilestoneConfig(); _unitOfWork.MilestoneConfigs.Add(config); _unitOfWork.Commit(); _startingMilestoneQuery.Setup(x => x.Execute(It.Is <StartingMilestoneQueryParams>(y => y.OrganizationId == _org.Id))).Returns(config); // Act new CreateJobSearchForUserCommand(_serviceFactory.Object).ForUserId(_user.Id).Execute(); // Verify JobSearch result = _unitOfWork.JobSearches.Fetch().Single(); Assert.AreEqual(config, result.CurrentMilestone, "Job Search's current milestone was incorrect"); }
private void InitializeTestEntities() { _searchProvider = new Mock <ISearchProvider>(); _jobSearch = new JobSearch(); _company = new Company { JobSearch = _jobSearch }; _user = new User(); _unitOfWork.Users.Add(_user); _unitOfWork.Companies.Add(_company); _unitOfWork.Commit(); // Mocks _companyAuthMock = new Mock <IProcess <CompanyQueryAuthorizationParams, AuthorizationResultViewModel> >(); _companyAuthMock.Setup(x => x.Execute(It.IsAny <CompanyQueryAuthorizationParams>())).Returns(new AuthorizationResultViewModel { UserAuthorized = true }); _serviceFactory = new Mock <IServiceFactory>(); _serviceFactory.Setup(x => x.GetService <IUnitOfWork>()).Returns(_unitOfWork); _searchProvider = new Mock <ISearchProvider>(); _serviceFactory.Setup(x => x.GetService <ISearchProvider>()).Returns(_searchProvider.Object); Mock <UserByIdQuery> userQuery = new Mock <UserByIdQuery>(_unitOfWork); userQuery.Setup(x => x.Execute()).Returns(_user); _serviceFactory.Setup(x => x.GetService <UserByIdQuery>()).Returns(userQuery.Object); Mock <CompanyByIdQuery> companyQuery = QueryTestUtils.GenerateCompanyByIdQueryMock(); companyQuery.Setup(x => x.Execute()).Returns(_company); _serviceFactory.Setup(x => x.GetService <CompanyByIdQuery>()).Returns(companyQuery.Object); _updateMetricsCmd = new Mock <UpdateJobSearchMetricsCommand>(_serviceFactory.Object); _serviceFactory.Setup(x => x.GetService <UpdateJobSearchMetricsCommand>()).Returns(_updateMetricsCmd.Object); _validator = new Mock <IValidator <Contact> >(); _validator.Setup(x => x.Validate(It.IsAny <Contact>())).Returns(new ValidationResult()); _serviceFactory.Setup(x => x.GetService <IValidator <Contact> >()).Returns(_validator.Object); }
public void Can_Create_Job_Search() { // Setup InitializeTestEntities(); // Act new CreateJobSearchForUserCommand(_serviceFactory.Object).ForUserId(_user.Id) .WithName("Test Name") .WithDescription("Test Desc") .Execute(); // Verify JobSearch result = _unitOfWork.JobSearches.Fetch().FirstOrDefault(); Assert.IsNotNull(result, "No Jobsearch was created"); Assert.AreEqual(_user.Id, result.User.Id, "Jobsearch had an incorrect user id value"); Assert.AreEqual("Test Name", result.Name, "JobSearch had an incorrect name value"); Assert.AreEqual("Test Desc", result.Description, "JobSearch had an incorrect description value"); Assert.AreEqual(_user.Id, result.User.Id, "JobSearch had an incorrect user id value"); }
public static List <JobSearch> Search(string sqlStr, params DbParameter[] parameters) { List <JobSearch> list = new List <JobSearch>(); using (DbCommand cmd = db.GetSqlStringCommand(sqlStr)) { cmd.Parameters.AddRange(parameters); DataSet ds = db.ExecuteDataSet(cmd); if (ds != null && ds.Tables.Count > 0) { DataTable table = ds.Tables[0]; foreach (DataRow dr in table.Rows) { JobSearch model = new JobSearch(dr); list.Add(model); } } } return(list); }
public void Progress_Is_One_When_JobSearch_NumCompaniesCreated_Is_Greater_Than_Milestone() { // Setup MilestoneConfig milestone = new MilestoneConfig { JobSearchMetrics = new JobSearchMetrics { NumCompaniesCreated = 3 } }; JobSearch jobSearch = new JobSearch { Metrics = new JobSearchMetrics { NumCompaniesCreated = 4 }, CurrentMilestone = milestone }; // Execute JobSearchMilestoneProgress result = new JobSearchMilestoneProgress(jobSearch); // Verify Assert.AreEqual(1, result.NumCompaniesCreatedProgress, "NumCompaniesCreatedProgress's value was incorrect"); }
public string Post(JobSearchModel searchModel) { string success = "ERROR: "; try { var jobSearch = new JobSearch(); jobSearch.Id = Guid.NewGuid().ToString(); jobSearch.PersonId = searchModel.PersonId; jobSearch.SearchName = searchModel.SearchName; jobSearch.Initiated = DateTime.Parse(searchModel.Initiated); using (GetaJobContext db = new GetaJobContext()) { db.JobSearches.Add(jobSearch); db.SaveChanges(); success = jobSearch.Id.ToString(); } } catch (Exception ex) { success = Helpers.ErrorDetails(ex); } return(success); }
public void Can_Calculate_NumContactsCreatedProgress() { // Setup MilestoneConfig milestone = new MilestoneConfig { JobSearchMetrics = new JobSearchMetrics { NumContactsCreated = 5 } }; JobSearch jobSearch = new JobSearch { Metrics = new JobSearchMetrics { NumContactsCreated = 2 }, CurrentMilestone = milestone }; // Execute JobSearchMilestoneProgress result = new JobSearchMilestoneProgress(jobSearch); // Verify Assert.AreEqual(((decimal)2 / (decimal)5), result.NumContactsCreatedProgress, "NumContactsCreatedProgress's value was incorrect"); }
public void Progess_Is_One_When_Milestone_NumInPersonInterviewTasksCreated_Is_Zero() { // Setup MilestoneConfig milestone = new MilestoneConfig { JobSearchMetrics = new JobSearchMetrics { NumInPersonInterviewTasksCreated = 0 } }; JobSearch jobSearch = new JobSearch { Metrics = new JobSearchMetrics { NumInPersonInterviewTasksCreated = 2 }, CurrentMilestone = milestone }; // Execute JobSearchMilestoneProgress result = new JobSearchMilestoneProgress(jobSearch); // Verify Assert.AreEqual(1, result.NumInPersonInterviewTasksCreatedProgress, "NumInPersonInterviewTasksCreatedProgress's value was incorrect"); }
public async Task <IActionResult> Upsert(JobSearch obj) { if (ModelState.IsValid) { var files = HttpContext.Request.Form.Files; if (files.Count > 0) { byte[] p1 = null; using (var fs1 = files[0].OpenReadStream()) { using (var ms1 = new MemoryStream()) { fs1.CopyTo(ms1); p1 = ms1.ToArray(); } } obj.Picture = p1; } else { var objFromDb = await _jsRepo.GetAsync(SD.JobSearchAPIPath, obj.Id); obj.Picture = objFromDb.Picture; } if (obj.Id == 0) { await _jsRepo.CreateAsync(SD.JobSearchAPIPath, obj); } else { await _jsRepo.UpdateAsync(SD.JobSearchAPIPath + obj.Id, obj); } return(RedirectToAction(nameof(Index))); } else { return(View(obj)); } }
public async Task ShouldReturnResults() { var search = new JobSearch { Title = "Search test" }; //await AddAsync(search); var a1 = new JobApplication(search, "Microsoft", "CEO"); var a2 = new JobApplication(search, "Salesforce", "Janitor"); await AddAsync(a1); await AddAsync(a2); var query = new GetApplicationsQuery { ParentSearchId = search.Id }; var result = await SendAsync(query); result.Applications.Count.ShouldBe(2); result.Applications.Where(a => a.OrganizationName == "Microsoft").Any().ShouldBeTrue(); result.Applications.Where(a => a.OrganizationName == "Salesforce").Any().ShouldBeTrue(); }
public async Task ShouldReturn() { var search = new JobSearch() { Title = "Test search" }; await AddAsync(search); var app = new JobApplication(search, "Microsoft", "Junior Developer"); await AddAsync(app); var query = new GetApplicationQuery { Id = app.Id }; var result = await SendAsync(query); result.ShouldNotBeNull(); result.OrganizationName.ShouldBe("Microsoft"); result.JobTitle.ShouldBe("Junior Developer"); }
protected void CreateContactsWorksheet(XLWorkbook workbook, JobSearch jobSearch) { // Create the worksheet var sheet = workbook.Worksheets.Add("Contacts"); // Create the headers sheet.Cell(1, 1).Value = "Name"; sheet.Cell(1, 2).Value = "Company"; sheet.Cell(1, 3).Value = "Title"; sheet.Cell(1, 4).Value = "Direct Phone"; sheet.Cell(1, 5).Value = "Extension"; sheet.Cell(1, 6).Value = "Mobile Phone"; sheet.Cell(1, 7).Value = "Email"; sheet.Cell(1, 8).Value = "Assistant"; sheet.Cell(1, 9).Value = "Referred By"; sheet.Cell(1, 10).Value = "Notes"; sheet.Row(1).Style.Font.Bold = true; // Write the data var contacts = jobSearch.Companies.SelectMany(x => x.Contacts).ToList(); for (int x = 0; x < contacts.Count; x++) { int row = x + 2; sheet.Cell(row, 1).Value = contacts[x].Name; sheet.Cell(row, 2).Value = contacts[x].Company.Name; sheet.Cell(row, 3).Value = contacts[x].Title; sheet.Cell(row, 4).Value = contacts[x].DirectPhone; sheet.Cell(row, 5).Value = contacts[x].Extension; sheet.Cell(row, 6).Value = contacts[x].MobilePhone; sheet.Cell(row, 7).Value = contacts[x].Email; sheet.Cell(row, 8).Value = contacts[x].Assistant; sheet.Cell(row, 9).Value = contacts[x].ReferredBy; sheet.Cell(row, 10).Value = contacts[x].Notes; } }
public virtual ActionResult Edit(JobSearch jobSearch) { try { // Determine if we are editing or adding a jobsearch if (jobSearch.Id == 0) { jobSearch = _createJobSearchCommand.ForUserId(CurrentUserId) .WithName(jobSearch.Name) .WithDescription(jobSearch.Description) .Execute(); } else { _editJobSearchCommand.WithJobSearchId(jobSearch.Id) .SetName(jobSearch.Name) .SetDescription(jobSearch.Description) .CalledByUserId(CurrentUserId) .Execute(); } // Set the current user's last visited job search to this one _editUserCommand.WithUserId(CurrentUserId).SetLastVisitedJobSearchId(jobSearch.Id).Execute(); return(RedirectToAction(MVC.Task.Index())); } // Show validation errors to the user and allow them to fix them catch (ValidationException ex) { foreach (var error in ex.Errors) { ModelState.AddModelError(error.PropertyName, error.ErrorMessage); } return(View(jobSearch)); } }