public void Handler_ReturnsUser_ById() { using (var dbContext = new EntityDbContext()) { var userName = Guid.NewGuid().ToString(); var user = new User { Name = userName }; dbContext.Create(user); var rowsAffected = dbContext.SaveChangesAsync().Result; var handler = new HandleUserByQuery(dbContext); var result = handler.Handle(new UserBy(user.Id) { EagerLoad = new Expression <Func <User, object> >[] { x => x.Permissions, } }).Result; Assert.NotNull(result); result.ShouldEqual(user); rowsAffected.ShouldEqual(1); } }
public void Handler_ReturnsNullUser_WhenNotFound_ById() { var userId = FakeData.Id(); var otherUserId = FakeData.Id(userId); var data = new[] { new ProxiedUser(otherUserId) }.AsQueryable(); var query = new UserBy(userId); var dbSet = new Mock<DbSet<User>>(MockBehavior.Strict).SetupDataAsync(data); var entities = new Mock<IReadEntities>(MockBehavior.Strict); var entitySet = new EntitySet<User>(dbSet.Object, entities.Object); entities.Setup(x => x.Query<User>()).Returns(entitySet); var handler = new HandleUserByQuery(entities.Object); User result = handler.Handle(query).Result; result.ShouldBeNull(); entities.Verify(x => x.Query<User>(), Times.Once); }
public void Handler_ReturnsUser_ByName_CaseInsensitively() { using (var dbContext = new EntityDbContext()) { var userName = Guid.NewGuid().ToString().ToUpper(); var user = new User { Name = userName }; dbContext.Create(user); var rowsAffected = dbContext.SaveChangesAsync().Result; var handler = new HandleUserByQuery(dbContext); var result = handler.Handle(new UserBy(userName.ToLower())).Result; Assert.NotNull(result); result.ShouldEqual(user); rowsAffected.ShouldEqual(1); } }
public void Handler_ReturnsUser_ById() { using (var dbContext = new EntityDbContext()) { var userName = Guid.NewGuid().ToString(); var user = new User { Name = userName }; dbContext.Create(user); var rowsAffected = dbContext.SaveChangesAsync().Result; var handler = new HandleUserByQuery(dbContext); var result = handler.Handle(new UserBy(user.Id) { EagerLoad = new Expression<Func<User, object>>[] { x => x.Permissions, } }).Result; Assert.NotNull(result); result.ShouldEqual(user); rowsAffected.ShouldEqual(1); } }
public void Handler_ReturnsNonNullUser_WhenFound_ByName() { var userName = FakeData.String(); var data = new[] { new User { Name = userName } }.AsQueryable(); var query = new UserBy(userName); var dbSet = new Mock<DbSet<User>>(MockBehavior.Strict).SetupDataAsync(data); var entities = new Mock<IReadEntities>(MockBehavior.Strict); var entitySet = new EntitySet<User>(dbSet.Object, entities.Object); entities.Setup(x => x.Query<User>()).Returns(entitySet); var handler = new HandleUserByQuery(entities.Object); var result = handler.Handle(query).Result; result.ShouldNotBeNull(); result.ShouldEqual(data.Single()); entities.Verify(x => x.Query<User>(), Times.Once); }
public void Handler_ReturnsNullUser_WhenNotFound_ByUserLoginInfo() { var loginProvider = FakeData.String(); var providerKey = FakeData.String(); var remoteMembershipId = new RemoteMembershipId { LoginProvider = loginProvider, ProviderKey = FakeData.String(), }; var remoteMembership = new ProxiedRemoteMembership(remoteMembershipId); var user = new User(); user.RemoteMemberships.Add(remoteMembership); var data = new[] { user }.AsQueryable(); var query = new UserBy(new UserLoginInfo(loginProvider, providerKey)); var dbSet = new Mock<DbSet<User>>(MockBehavior.Strict).SetupDataAsync(data); var entities = new Mock<IReadEntities>(MockBehavior.Strict); var entitySet = new EntitySet<User>(dbSet.Object, entities.Object); entities.Setup(x => x.Query<User>()).Returns(entitySet); var handler = new HandleUserByQuery(entities.Object); var result = handler.Handle(query).Result; result.ShouldBeNull(); entities.Verify(x => x.Query<User>(), Times.Once); }
public void Handler_ReturnsNullUser_WhenAuthenticatedButNotFound_ByPrincipal() { var userId = FakeData.Id(); var otherUserId = FakeData.Id(userId); var claims = new[] { new Claim(ClaimTypes.NameIdentifier, userId.ToString(CultureInfo.InvariantCulture)), }; var identity = new ClaimsIdentity(claims, "authenticationType"); var principal = new GenericPrincipal(identity, null); var data = new[] { new ProxiedUser(otherUserId) }.AsQueryable(); var query = new UserBy(principal); var dbSet = new Mock<DbSet<User>>(MockBehavior.Strict).SetupDataAsync(data); var entities = new Mock<IReadEntities>(MockBehavior.Strict); var entitySet = new EntitySet<User>(dbSet.Object, entities.Object); entities.Setup(x => x.Query<User>()).Returns(entitySet); var handler = new HandleUserByQuery(entities.Object); var result = handler.Handle(query).Result; result.ShouldBeNull(); entities.Verify(x => x.Query<User>(), Times.Once); }