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(); }
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() { _task1 = new Task { Name = "Task 1" }; _task2 = new Task { Name = "Task 2" }; _task3 = new Task { Name = "Task 3" }; _unitOfWork.Tasks.Add(_task1); _unitOfWork.Tasks.Add(_task2); _unitOfWork.Tasks.Add(_task3); _unitOfWork.Commit(); }
public EditTaskViewModel(Task task) { Id = task.Id; Name = task.Name; TaskDate = task.TaskDate; Completed = task.CompletionDate != null; AssociatedContactId = Convert.ToInt32(task.ContactId); Company = new CompanySummaryViewModel(task.Company); Contact = new ContactSummaryViewModel(task.Contact); Category = task.Category; Notes = task.Notes; AssociatedContactId = task.ContactId ?? 0; AvailableCategoryList = new List<string>(); }
public void Search_Finds_Task_By_Name() { // Setup Task task = new Task { Id = 2, Name = "Name", Company = new Company { JobSearch = new JobSearch { Id = 4 } } }; _provider.Index(task); // Act SearchProviderResult result = _provider.SearchByJobSearchId("Name", 4); // Verify Assert.IsNotNull(result); Assert.AreEqual(0, result.FoundCompanyIds.Count, "Found company count was incorrect"); Assert.AreEqual(0, result.FoundContactIds.Count, "Found contact count was incorrect"); Assert.AreEqual(1, result.FoundTaskIds.Count, "Found task count was incorrect"); Assert.AreEqual(task.Id, result.FoundTaskIds[0], "Found task id value was incorrect"); }
public void Search_Returns_No_Results_With_No_Match() { // Setup Company company = new Company { Id = 2, JobSearch = new JobSearch { Id = 5 } }; Contact contact = new Contact { Id = 3, Company = new Company { JobSearch = new JobSearch { Id = 5 } } }; Task task = new Task { Id = 4, Company = new Company { JobSearch = new JobSearch { Id = 5 } } }; _provider.Index(company); _provider.Index(contact); _provider.Index(task); // Act SearchProviderResult result = _provider.SearchByJobSearchId("Test", 5); // Verify Assert.IsNotNull(result, "Search provider result was null"); Assert.AreEqual(0, result.FoundCompanyIds.Count, "Search provider result's found company list item count was incorrect"); Assert.AreEqual(0, result.FoundContactIds.Count, "Search provider result's found contact list item count was incorrect"); Assert.AreEqual(0, result.FoundTaskIds.Count, "Search provider result's found task list item count was incorrect"); }
public void ReIndexing_Task_Updates_Existing_Contact_Document() { // Setup Task task = new Task { Id = 3, Name = "Name1", Company = new Company { JobSearch = new JobSearch { Id = 5 } } }; _provider.Index(task); task.Name = "Name2"; // Act _provider.Index(task); // Verify IndexSearcher searcher; TopDocs hits = SearchIndex(LuceneSearchProvider.Constants.TASK_ID, "3", out searcher); Assert.AreEqual(1, hits.scoreDocs.Length, "Incorrect number of documents returned"); Document doc = searcher.Doc(hits.scoreDocs[0].doc); Assert.AreEqual("Name2", doc.Get(LuceneSearchProvider.Constants.TASK_NAME), "Document had an incorrect name"); }
public void Can_Remove_Task_From_Index() { // Setup Task task = new Task { Id = 3, Company = new Company { JobSearch = new JobSearch { Id = 5 } } }; _provider.Index(task); // Act _provider.Remove(task); // Verify IndexSearcher searcher; TopDocs hits = SearchIndex(LuceneSearchProvider.Constants.TASK_ID, "3", out searcher); Assert.AreEqual(0, hits.scoreDocs.Length, "Incorrect number of documents returned"); }
public void Can_Index_Multiple_Tasks() { // Setup Task task1 = new Task { Id = 3, Name = "Name", Company = new Company { JobSearch = new JobSearch { Id = 5 } } }; Task task2 = new Task { Id = 4, Name = "Name", Company = new Company { JobSearch = new JobSearch { Id = 5 } } }; // Act _provider.Index(task1); _provider.Index(task2); // Verify IndexSearcher searcher; TopDocs hits = SearchIndex(LuceneSearchProvider.Constants.TASK_NAME, "Name", out searcher); Assert.AreEqual(2, hits.scoreDocs.Length, "Incorrect number of documents returned"); }
public void Tasks_Null_Properties_Index_As_Empty_String() { // Setup Task task = new Task { Id = 3, Company = new Company { JobSearch = new JobSearch { Id = 5 } } }; // Act _provider.Index(task); // Verify IndexSearcher searcher; TopDocs hits = SearchIndex(LuceneSearchProvider.Constants.TASK_ID, "3", out searcher); Assert.AreEqual(1, hits.scoreDocs.Length, "Incorrect number of documents returned"); Document doc = searcher.Doc(hits.scoreDocs[0].doc); Assert.AreEqual("3", doc.Get(LuceneSearchProvider.Constants.TASK_ID), "Document had an incorrect contact id value"); Assert.AreEqual(string.Empty, doc.Get(LuceneSearchProvider.Constants.TASK_NAME), "Document had an incorrect name value"); }
public void Can_Index_Tasks() { // Setup DateTime testdate = DateTime.Now; Task task = new Task { Id = 3, Name = "Name", TaskDate = testdate, Category = "Category", Company = new Company { JobSearch = new JobSearch { Id = 7 } } }; // Act _provider.Index(task); // Verify IndexSearcher searcher; TopDocs hits = SearchIndex(LuceneSearchProvider.Constants.TASK_ID, "3", out searcher); Assert.AreEqual(1, hits.scoreDocs.Length, "Incorrect number of documents returned"); Document doc = searcher.Doc(hits.scoreDocs[0].doc); Assert.AreEqual("3", doc.Get(LuceneSearchProvider.Constants.TASK_ID), "Document had an incorrect contact id value"); Assert.AreEqual("Name", doc.Get(LuceneSearchProvider.Constants.TASK_NAME), "Document had an incorrect name value"); Assert.AreEqual("7", doc.Get(LuceneSearchProvider.Constants.JOBSEARCH_ID), "Document had an incorrect job search id value"); Assert.AreEqual("Category", doc.Get(LuceneSearchProvider.Constants.TASK_CATEGORY), "Document had an incorrect category value"); }
public void Remove(Task task) { if (task == null) throw new ArgumentNullException("Can't remove the index for a null task"); // Delete all documents with a matching task id var writer = OpenIndex(); writer.DeleteDocuments(new Term(Constants.TASK_ID, task.Id.ToString())); writer.Optimize(); writer.Close(); }
public void Index(Task task) { if (task == null) throw new ArgumentNullException("Can't index a null task"); // Create a document for the task var document = new Document(); document.Add(new Field(Constants.TASK_ID, task.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); document.Add(new Field(Constants.TASK_NAME, task.Name ?? string.Empty, Field.Store.YES, Field.Index.ANALYZED)); document.Add(new Field(Constants.TASK_CATEGORY, task.Category ?? string.Empty, Field.Store.YES, Field.Index.ANALYZED)); document.Add(new Field(Constants.JOBSEARCH_ID, task.Company.JobSearch.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); // Remove any previous documents for the task and add the new one Remove(task); var writer = OpenIndex(); try { writer.AddDocument(document); writer.Optimize(); } finally { // Make sure the writer attempts to close even if an exception occurs, to prevent stale locks writer.Close(); } }
/// <summary> /// Executes the command /// </summary> /// <returns></returns> /// <exception cref="MJLEntityNotFoundException">Thrown when the specified company, calling user, or contact is not found</exception> public virtual Task Execute(CreateTaskCommandParams cmdParams) { var unitOfWork = _serviceFactory.GetService<IUnitOfWork>(); // Retrieve the user creating the task var user = _serviceFactory.GetService<UserByIdQuery>().WithUserId(cmdParams.RequestedUserId).Execute(); if (user == null) throw new MJLEntityNotFoundException(typeof(User), cmdParams.RequestedUserId); // Retrieve the company var company = _serviceFactory.GetService<CompanyByIdQuery>().WithCompanyId(cmdParams.CompanyId) .RequestedByUserId(cmdParams.RequestedUserId) .Execute(); if (company == null) throw new MJLEntityNotFoundException(typeof(Company), cmdParams.CompanyId); // Retrieve the contact if one is specified Contact contact = null; if (cmdParams.ContactId != 0) { contact = _serviceFactory.GetService<ContactByIdQuery>() .WithContactId(cmdParams.ContactId) .RequestedByUserId(cmdParams.RequestedUserId) .Execute(); if (contact == null) throw new MJLEntityNotFoundException(typeof(Contact), cmdParams.ContactId); } // Create the Task var task = new Task { Company = company, Name = cmdParams.Name, TaskDate = cmdParams.TaskDate, Contact = contact, Category = cmdParams.Category, Notes = cmdParams.Notes, History = new List<TaskHistory>() }; // Create history record task.History.Add(new TaskHistory { Name = cmdParams.Name, TaskDate = cmdParams.TaskDate, Category = cmdParams.Category, Notes = cmdParams.Notes, HistoryAction = MJLConstants.HistoryInsert, DateModified = DateTime.Now, AuthoringUser = user }); // Perform Validation var validation = _serviceFactory.GetService<IValidator<Task>>(); validation.ValidateAndThrow(task); unitOfWork.Tasks.Add(task); unitOfWork.Commit(); // Index the task with the search provider _serviceFactory.GetService<ISearchProvider>().Index(task); // Update the metrics for the job search _serviceFactory.GetService<UpdateJobSearchMetricsCommand>() .Execute(new UpdateJobSearchMetricsCmdParams { JobSearchId = (int)company.JobSearchID }); return task; }