public void With_id_of_any_seed_job_Then_that_seed_job_is_deleted_and_is_returned(int id) { Job deletedJob; Job missingJob; int initialJobCount; int newJobCount; using (var context = DSCContextFactory.InMemoryContext()) { var repository = new Models.JobRepository(context); initialJobCount = context.Jobs.Count(); deletedJob = repository.Delete(context.Jobs.Find(id)); newJobCount = context.Jobs.Count(); missingJob = context.Jobs.Find(id); } Assert.True(newJobCount == initialJobCount - 1, "Job count is incorrect"); Assert.Null(missingJob); Assert.IsType <Job>(deletedJob); }
public void With_a_new_job_Then_a_new_job_is_added_and_returned_with_a_new_id_value() { var newJob = new Job { Name = "new job", IsCompleted = false }; Job savedJob; int initialJobCount; int newJobCount; using (var context = DSCContextFactory.InMemoryContext()) { var repository = new Models.JobRepository(context); initialJobCount = context.Jobs.Count(); savedJob = repository.Save(newJob); newJobCount = context.Jobs.Count(); } Assert.True(newJobCount == initialJobCount + 1, "Job count is incorrect"); Assert.True(Comparator.JobsAreIdentical(newJob, savedJob), "Jobs are not identical"); Assert.True(savedJob.Id == newJobCount, "Job has incorrect Id value"); }
public void Then_correct_result_type_is_returned(int id, Type resultType) { using (var context = DSCContextFactory.InMemoryContext()) { var controller = new Controllers.JobController(new Models.JobRepository(context)); var result = controller.Get(id); Assert.IsType(resultType, result); } }
public When_Get_without_parameter_executes() { using (var context = DSCContextFactory.InMemoryContext()) { var controller = new Controllers.JobController(new JobRepository(context)); _result = controller.Get(); var data = ((ObjectResult)_result).Value; _jobs = ((IEnumerable <Job>)data).ToList(); } }
public void With_id_of_any_seed_job_Then_that_seed_job_is_returned(int id) { Job job; using (var context = DSCContextFactory.InMemoryContext()) { var repository = new Models.JobRepository(context); job = repository.GetById(id); } var seedDataJob = SeedData.Jobs().FirstOrDefault(j => j.Name.EndsWith(id.ToString())); Assert.True(Comparator.JobsAreIdentical(seedDataJob, job), "Jobs are not identical"); }
public void With_a_valid_parameter_value_Then_a_job_is_contained_in_the_ObjectResult(int id) { using (var context = DSCContextFactory.InMemoryContext()) { var controller = new Controllers.JobController(new Models.JobRepository(context)); var result = controller.Get(id); var data = ((ObjectResult)result).Value as Job; Assert.IsType <Job>(data); var seedDataJob = SeedData.Jobs().FirstOrDefault(j => j.Name.EndsWith(id.ToString())); Assert.True(data.Name == seedDataJob.Name); } }
public void With_a_existing_job_Then_an_existing_job_is_edited_and_returned(int id) { Job existingJob; Job savedJob; using (var context = DSCContextFactory.InMemoryContext()) { var repository = new Models.JobRepository(context); existingJob = context.Jobs.Find(id); existingJob.Name = existingJob.Name + "{mod}"; existingJob.IsCompleted = !existingJob.IsCompleted; savedJob = repository.Save(existingJob); } Assert.True(existingJob == savedJob, "Jobs are not equal"); }
public void Then_a_complete_list_of_seed_jobs_is_returned() { IEnumerable <Job> jobs; using (var context = DSCContextFactory.InMemoryContext()) { var repository = new JobRepository(context); jobs = repository.GetList(); } Assert.True(jobs.Any(), "There are not any jobs"); Assert.All(jobs, j => Assert.IsType <Job>(j)); var seedDataCount = SeedData.Jobs().Count(); Assert.True(jobs.Count() == seedDataCount, "There are not " + seedDataCount + " jobs"); }
public JobRepository(DSCContext context) { _context = context; DSCContextFactory.InitializeDatabase(_context); }