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 CompanyServiceModel { User = new UserServiceModel { UserName = user.UserName } }; var companyService = new CompanyService(new EfRepository <User>(context), new EfRepository <Company>(context)); var result = await companyService.CreateAsync(serviceModel); Assert.False(result); var dbModels = await context.Companies.AnyAsync(); Assert.False(dbModels); }
public async Task Init() { var options = new DbContextOptionsBuilder <MISDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; this.dbContext = new MISDbContext(options); var userService = new UserService(this.dbContext); var companyService = new CompanyService(this.dbContext, userService); var company = await companyService.CreateAsync(CompanyName, CompanyAddress); this.warehouseService = new WareHouseService(this.dbContext, companyService); }
public async Task CreateAsync_WithNonExistentUser_ReturnsFalse() { var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options); var serviceModel = new CompanyServiceModel { CompanyName = "CompanyName" }; var companyService = new CompanyService(new EfRepository <User>(context), new EfRepository <Company>(context)); var result = await companyService.CreateAsync(serviceModel); Assert.False(result); var dbModels = await context.Companies.AnyAsync(); Assert.False(dbModels); }
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 CompanyServiceModel { CompanyName = "TestCompanyName", User = new UserServiceModel { UserName = user.UserName } }; var companyService = new CompanyService(new EfRepository <User>(context), new EfRepository <Company>(context)); var result = await companyService.CreateAsync(serviceModel); Assert.True(result); var dbModel = context.Companies.SingleOrDefault(); Assert.NotNull(dbModel); Assert.Equal(user.Id, dbModel.UserId); }