public async Task GetUser_Throws_NotFoundException() { var dbSetMock = new Mock <DbSet <ApplicationUser> >(); var dbContextMock = new Mock <ApplicationDbContext>(); dbContextMock.Setup(s => s.Set <ApplicationUser>()).Returns(dbSetMock.Object); var userManagerMock = GetUserManagerMock <ApplicationUser>(); userManagerMock.Setup(u => u.FindByIdAsync(It.IsAny <String>())).Returns(Task.FromResult <ApplicationUser>(null)); var roleManagerMock = GetRoleManagerMock <IdentityRole>().Object; ApplicationUsersRepository applicationUsersRepository = new ApplicationUsersRepository( dbContextMock.Object, userManagerMock.Object, roleManagerMock ); await Assert.ThrowsAsync <NotFoundException>(async() => { await applicationUsersRepository.GetUser(Guid.NewGuid()); }); }
public async Task GetUser_ReturnsUser() { var dbSetMock = new Mock <DbSet <ApplicationUser> >(); var dbContextMock = new Mock <ApplicationDbContext>(); dbContextMock.Setup(s => s.Set <ApplicationUser>()).Returns(dbSetMock.Object); var userManagerMock = GetUserManagerMock <ApplicationUser>(); userManagerMock.Setup(u => u.FindByIdAsync(It.IsAny <String>())).Returns(Task.FromResult(new ApplicationUser())); var roleManagerMock = GetRoleManagerMock <IdentityRole>().Object; ApplicationUsersRepository applicationUsersRepository = new ApplicationUsersRepository( dbContextMock.Object, userManagerMock.Object, roleManagerMock ); var user = await applicationUsersRepository.GetUser(Guid.NewGuid()); Assert.NotNull(user); Assert.IsAssignableFrom <ApplicationUser>(user); }