Beispiel #1
0
        public async Task CreateAsync_WithInvalidModel_ReturnsFalse()
        {
            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var user = new User
            {
                UserName = "******"
            };

            await context.Users.AddAsync(user);

            context.SaveChanges();

            var serviceModel = new JobSeekerServiceModel
            {
                User = new UserServiceModel
                {
                    UserName = user.UserName
                }
            };

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

            var result = await jobSeekerService.CreateAsync(serviceModel);

            Assert.False(result);

            var dbModel = await context.JobSeekers.AnyAsync();

            Assert.False(dbModel);
        }
Beispiel #2
0
        public async Task CreateAsync_WithValidModel_WorksCorrectly()
        {
            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var user = new User
            {
                UserName = "******"
            };

            await context.Users.AddAsync(user);

            context.SaveChanges();

            var serviceModel = new JobSeekerServiceModel
            {
                FirstName = "TestFirstName",
                LastName  = "TestLastName",
                User      = new UserServiceModel
                {
                    UserName = user.UserName
                }
            };

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

            var result = await jobSeekerService.CreateAsync(serviceModel);

            Assert.True(result);

            var dbModel = context.JobSeekers.SingleOrDefault();

            Assert.NotNull(dbModel);

            Assert.Equal(user.Id, dbModel.UserId);
        }
Beispiel #3
0
        public async Task CreateAsync_WithNonExistentUser_ReturnsFalse()
        {
            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var serviceModel = new JobSeekerServiceModel
            {
                FirstName = "TestFirstName",
                LastName  = "TestLastName"
            };

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

            var result = await jobSeekerService.CreateAsync(serviceModel);

            Assert.False(result);

            var dbModel = await context.JobSeekers.AnyAsync();

            Assert.False(dbModel);
        }