private void InitializeTestEntities() { _jobsearch1 = new JobSearch { Companies = new List<Company>() }; _jobsearch2 = new JobSearch { Companies = new List<Company>() }; _company1 = new Company { Contacts = new List<Contact>(), Tasks = new List<Task>(), JobSearch = _jobsearch1 }; _company2 = new Company { Contacts = new List<Contact>(), Tasks = new List<Task>(), JobSearch = _jobsearch2 }; _contact1 = new Contact { Tasks = new List<Task>(), Company = _company1 }; _contact2 = new Contact { Tasks = new List<Task>(), Company = _company2 }; _contactTask1 = new Task { Contact = _contact1, CompletionDate = null, TaskDate = new DateTime(2011, 1, 2, 5, 4, 5) }; _contactTask2 = new Task { Contact = _contact2, CompletionDate = null, TaskDate = new DateTime(2011, 1, 2, 6, 4, 5) }; _companyTask1 = new Task { Company = _company1, CompletionDate = null, TaskDate = new DateTime(2011, 1, 2, 1, 4, 5) }; _companyTask2 = new Task { Company = _company2, CompletionDate = null, TaskDate = new DateTime(2011, 1, 2, 2, 4, 5) }; _closedTask1 = new Task { Company = _company1, CompletionDate = DateTime.Now, TaskDate = new DateTime(2011, 1, 2, 3, 4, 5) }; _closedTask2 = new Task { Company = _company2, CompletionDate = DateTime.Now, TaskDate = new DateTime(2011, 1, 2, 4, 4, 5) }; _unitOfWork.JobSearches.Add(_jobsearch1); _unitOfWork.JobSearches.Add(_jobsearch2); _unitOfWork.Companies.Add(_company1); _unitOfWork.Companies.Add(_company2); _unitOfWork.Contacts.Add(_contact1); _unitOfWork.Contacts.Add(_contact2); _unitOfWork.Tasks.Add(_contactTask1); _unitOfWork.Tasks.Add(_contactTask2); _unitOfWork.Tasks.Add(_companyTask1); _unitOfWork.Tasks.Add(_companyTask2); _unitOfWork.Tasks.Add(_closedTask1); _unitOfWork.Tasks.Add(_closedTask2); _unitOfWork.Commit(); }
public void InitializeEntities() { _search = new JobSearch { Name = "Name" }; }
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); } }
public void User_Not_Authorized_When_Contact_Doesnt_Belong_To_User_Jobsearch() { // Setup var user = new User(); var user2 = new User(); var search = new JobSearch { User = user }; var company = new Company { JobSearch = search }; var contact = new Contact { Company = company }; _context.Contacts.Add(contact); _context.Users.Add(user2); _context.SaveChanges(); IProcess<ContactAutorizationParams, AuthorizationResultViewModel> process = new AuthorizationProcesses(_context); // Act AuthorizationResultViewModel result = process.Execute(new ContactAutorizationParams { ContactId = contact.Id, RequestingUserId = user2.Id }); // Verify Assert.IsNotNull(result, "Result was null"); Assert.IsFalse(result.UserAuthorized, "User was incorrectly authorized"); }
private void InitializeTestEntities() { _changedDate = new DateTime(2011, 1, 2, 3, 4, 5); _startDate = new DateTime(2011, 2, 3, 4, 5, 6); _jobSearch = new JobSearch(); Company company = new Company { JobSearch = _jobSearch }; _user = new User(); _contact = new Contact { Company = company }; _task = new Task { Name = "Starting Name", CompletionDate = null, TaskDate = _startDate, Category = "Starting Category", Company = company, Notes = "Starting Notes", History = new List<TaskHistory>() }; _unitOfWork.Users.Add(_user); _unitOfWork.Tasks.Add(_task); _unitOfWork.Contacts.Add(_contact); _unitOfWork.Commit(); // Mocks _contactAuthMock = new Mock<IProcess<ContactAutorizationParams, AuthorizationResultViewModel>>(); _contactAuthMock.Setup(x => x.Execute(It.IsAny<ContactAutorizationParams>())).Returns(new AuthorizationResultViewModel { UserAuthorized = true }); _taskAuthMock = new Mock<IProcess<TaskAuthorizationParams, AuthorizationResultViewModel>>(); _taskAuthMock.Setup(x => x.Execute(It.IsAny<TaskAuthorizationParams>())).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); _userQuery = new Mock<UserByIdQuery>(_unitOfWork); _userQuery.Setup(x => x.Execute()).Returns(_user); _serviceFactory.Setup(x => x.GetService<UserByIdQuery>()).Returns(_userQuery.Object); _contactQuery = new Mock<ContactByIdQuery>(_unitOfWork, _contactAuthMock.Object); _contactQuery.Setup(x => x.Execute()).Returns(_contact); _serviceFactory.Setup(x => x.GetService<ContactByIdQuery>()).Returns(_contactQuery.Object); _taskQuery = new Mock<TaskByIdQuery>(_unitOfWork, _taskAuthMock.Object); _taskQuery.Setup(x => x.Execute()).Returns(_task); _serviceFactory.Setup(x => x.GetService<TaskByIdQuery>()).Returns(_taskQuery.Object); _updateMetricsCmd = new Mock<UpdateJobSearchMetricsCommand>(_serviceFactory.Object); _serviceFactory.Setup(x => x.GetService<UpdateJobSearchMetricsCommand>()).Returns(_updateMetricsCmd.Object); _validator = new Mock<IValidator<Task>>(); _validator.Setup(x => x.Validate(It.IsAny<Task>())).Returns(new ValidationResult()); _serviceFactory.Setup(x => x.GetService<IValidator<Task>>()).Returns(_validator.Object); }
private void InitializeTestEntities() { _jobSearch = new JobSearch { Name = "Test Name", Description = "Test Description", History = new List<JobSearchHistory>() }; _user = new User(); _unitOfWork.Users.Add(_user); _unitOfWork.JobSearches.Add(_jobSearch); _unitOfWork.Commit(); }
private void InitializeTestEntities() { _search = new JobSearch(); _unitOfWork.JobSearches.Add(_search); _unitOfWork.Commit(); // Mocks _serviceFactory = new Mock<IServiceFactory>(); _serviceFactory.Setup(x => x.GetService<IUnitOfWork>()).Returns(_unitOfWork); }
public JobSearchCompanyListViewModel(JobSearch jobSearch) { if (jobSearch == null) throw new ArgumentNullException("jobSearch"); JobSearchId = jobSearch.Id; SetHiddenStatusList(jobSearch.HiddenCompanyStatuses); UsedStatuses = jobSearch.Companies.Select(x => x.LeadStatus).Distinct().ToList(); TotalCompanyCount = jobSearch.Companies.Count(); // Only show companies with statuses not on the hidden status list Companies = jobSearch.Companies.Where(x => !HiddenStatuses.Contains(x.LeadStatus)).ToList(); }
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 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 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 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 void Uncompleted_Jobsearch_Milestone_Doesnt_Progress_To_Next_Milestone() { // Setup MilestoneConfig ms2 = new MilestoneConfig(); MilestoneConfig ms1 = new MilestoneConfig { JobSearchMetrics = new JobSearchMetrics { NumCompaniesCreated = 2 }, NextMilestone = ms2 }; JobSearch search = new JobSearch { Metrics = new JobSearchMetrics { NumCompaniesCreated = 1 }, CurrentMilestone = ms1 }; _unitOfWork.JobSearches.Add(search); _unitOfWork.Commit(); Mock<JobSearchByIdQuery> jobSearchQuery = new Mock<JobSearchByIdQuery>(_unitOfWork); jobSearchQuery.Setup(x => x.WithJobSearchId(It.IsAny<int>())).Returns(jobSearchQuery.Object); jobSearchQuery.Setup(x => x.Execute()).Returns(search); _serviceFactory.Setup(x => x.GetService<JobSearchByIdQuery>()).Returns(jobSearchQuery.Object); // Act new StartNextJobSearchMilestoneCommand(_serviceFactory.Object) .Execute(new StartNextJobSearchMilestoneCommandParams { JobSearchId = search.Id }); // Verify JobSearch result = _unitOfWork.JobSearches.Fetch().Single(); Assert.AreEqual(ms1, result.CurrentMilestone, "Job search's CurrentMilestone was incorrect"); }
public void InitializeTestEntities() { var search = new JobSearch { User = new User { FullName = "Full Name" } }; _comp1 = new Company { Name = "company", Phone = "555-333-2323", State = "FL", Zip = "33445", City = "City", LeadStatus = "Status1", Notes = "notes 1", JobSearch = search }; _comp2 = new Company { Name = "company2", Phone = "666-333-2323", State = "NY", Zip = "23456", City = "City2", LeadStatus = "Status2", Notes = "notes 2", JobSearch = search }; _contact1 = new Contact { Company = _comp1, Name = "Contact 1", DirectPhone = "111-222-3333", Extension = "23", MobilePhone = "222-333-4444", Assistant = "Assistant 1", Email = "email 1", Notes = "notes 1", ReferredBy = "referred 1", Title = "title 1" }; _contact2 = new Contact { Company = _comp2, Name = "Contact 2", DirectPhone = "666-222-3333", Extension = "25", MobilePhone = "777-333-4444", Assistant = "Assistant 2", Email = "email 2", Notes = "notes 2", ReferredBy = "referred 2", Title = "title 2" }; _context.Contacts.Add(_contact1); _context.Contacts.Add(_contact2); _context.SaveChanges(); // Create the export process class _jsQueryMock = new Mock<JobSearchByIdQuery>(_unitOfWork); _jsQueryMock.Setup(x => x.Execute()).Returns(search); _jsQueryMock.Setup(x => x.WithJobSearchId(It.IsAny<int>())).Returns(_jsQueryMock.Object); _process = new JobSearchExportProcess(_jsQueryMock.Object); }
public void Milestone_Total_Progress_Is_Calculated_Correctly() { // Setup JobSearch search = new JobSearch { CurrentMilestone = new MilestoneConfig { JobSearchMetrics = new JobSearchMetrics { NumCompaniesCreated = 4, NumContactsCreated = 4 } }, Metrics = new JobSearchMetrics { NumCompaniesCreated = 3, NumContactsCreated = 2 } }; // Act JobSearchMilestoneProgress result = new JobSearchMilestoneProgress(search); // Verify Assert.AreEqual((decimal)0.625, result.TotalProgress, "Milestone's total progress value was incorrect"); }
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 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 void Jobsearch_Marked_As_Milestones_Completed_When_Last_Milestone_Is_Completed() { // Setup var ms = new MilestoneConfig { JobSearchMetrics = new JobSearchMetrics() }; var search = new JobSearch { Metrics = new JobSearchMetrics(), CurrentMilestone = ms }; _context.MilestoneConfigs.Add(ms); _context.JobSearches.Add(search); _context.SaveChanges(); Mock<JobSearchByIdQuery> jobSearchQuery = new Mock<JobSearchByIdQuery>(_unitOfWork); jobSearchQuery.Setup(x => x.WithJobSearchId(It.IsAny<int>())).Returns(jobSearchQuery.Object); jobSearchQuery.Setup(x => x.Execute()).Returns(search); _serviceFactory.Setup(x => x.GetService<JobSearchByIdQuery>()).Returns(jobSearchQuery.Object); // Act new StartNextJobSearchMilestoneCommand(_serviceFactory.Object) .Execute(new StartNextJobSearchMilestoneCommandParams { JobSearchId = search.Id }); // Verify Assert.IsTrue(search.MilestonesCompleted, "Job search is not marked as completing all milestones"); }
/// <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; }