コード例 #1
0
        public async Task GetAllJobSeekers_WithData_WorksCorrectly()
        {
            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var expectedResults = new[] { "JobSeeker1", "JobSeeker2", "JobSeeker3" }
            .OrderBy(j => j)
            .ToArray();

            foreach (var model in expectedResults)
            {
                context.JobSeekers.Add(new JobSeeker()
                {
                    FirstName = model,
                    LastName  = model,
                    User      = new User
                    {
                        UserName = model
                    }
                });
            }

            await context.SaveChangesAsync();

            var jobSeekerService = new JobSeekerService(new EfRepository <User>(context),
                                                        new EfRepository <JobSeeker>(context));

            var actualResults = (await jobSeekerService.GetAllJobSeekers())
                                .Select(j => j.FirstName)
                                .OrderBy(j => j)
                                .ToArray();

            Assert.Equal(expectedResults, actualResults);
        }
コード例 #2
0
        public async Task GetAllJobSeekers_WithNoData_ReturnsNull()
        {
            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var jobSeekerService = new JobSeekerService(new EfRepository <User>(context),
                                                        new EfRepository <JobSeeker>(context));

            var actualResults = await jobSeekerService.GetAllJobSeekers();

            Assert.Empty(actualResults);
        }