public async Task ReturnRoleName_WhenValidUserIdIsPassed() { var userStoreMock = new Mock <IUserStore <User> >(); var userManager = new UserManager <User>(userStoreMock.Object, null, null, null, null, null, null, null, null); var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>() .UseInMemoryDatabase(databaseName: "ReturnRoleName_WhenValidUserIdIsPassed") .UseInternalServiceProvider(serviceProvider).Options; var user = new User(); var role = new IdentityRole("User"); IdentityUserRole <string> userRole; using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { bedeSlotsContext.Roles.Add(role); bedeSlotsContext.Users.Add(user); userRole = new IdentityUserRole <string>() { UserId = user.Id, RoleId = role.Id }; bedeSlotsContext.UserRoles.Add(userRole); bedeSlotsContext.SaveChanges(); } using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { var sut = new Data.UserService(bedeSlotsContext, userManager); var result = await sut.GetUserRoleNameAsync(user.Id); Assert.IsTrue(result == role.Name); } }
public async Task ThrowServiceException_WhenNullArgumentIsPassed() { var userStoreMock = new Mock <IUserStore <User> >(); var userManager = new UserManager <User>(userStoreMock.Object, null, null, null, null, null, null, null, null); var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>() .UseInMemoryDatabase(databaseName: "ThrowServiceException_WhenNullArgumentIsPassed") .UseInternalServiceProvider(serviceProvider).Options; var transactionServiceMock = new Mock <ITransactionService>(); using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { var sut = new Data.UserService(bedeSlotsContext, userManager); await Assert.ThrowsExceptionAsync <ServiceException>(async() => await sut.GetUserRoleNameAsync(null)); } }