public async void RepositoryCreateCategoryAndJobTest()
        {
            int nextId = RandomNumberHelper.NextInteger();

            using (var context = new JobAssistantContext(helper.Options)) {
                var category = new Category {
                    CategoryId = nextId, Name = "Test Category " + nextId
                };
                var job = new Job {
                    JobId = nextId, Name = "Test Job " + nextId
                };
                category.Jobs = new List <Job>();
                category.Jobs.Add(job);

                var repositoryUnderTest = new Repository(context);
                await repositoryUnderTest.Create <Category>(category);
            }

            using (var context = new JobAssistantContext(helper.Options)) {
                var repositoryUnderTest = new Repository(context);
                var parentCategory      = repositoryUnderTest.All <Category>().Include(c => c.Jobs).Single(c => c.CategoryId == nextId);
                Assert.NotNull(parentCategory);
                Assert.NotNull(parentCategory.Jobs);
                Assert.Equal(1, parentCategory.Jobs.Count);
                var childJob = parentCategory.Jobs.Single(j => j.JobId == nextId);
                Assert.Equal("Test Job " + nextId, childJob.Name);
                context.Remove(parentCategory);
                context.SaveChanges();
                var hasCategory = context.Categories.Any(c => c.CategoryId == nextId);
                Assert.False(hasCategory);
            }
        }
Exemple #2
0
        private bool disposedValue; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    context.Remove(toolUnderTest);
                }

                disposedValue = true;
            }
        }