public void Handler_ReturnsNullRemoteMembership_WhenNotFound_ByUserId() { var userId = FakeData.Id(); var otherUserId = FakeData.Id(userId); var loginProvider = FakeData.String(); var providerKey = FakeData.String(); var userLoginInfo = new UserLoginInfo(loginProvider, providerKey); var remoteMemberships = new[] { new ProxiedRemoteMembership(loginProvider, providerKey) { UserId = otherUserId, }, new ProxiedRemoteMembership(FakeData.String(), FakeData.String()) { UserId = userId, }, }; var data = remoteMemberships.AsQueryable(); var query = new RemoteMembershipByUser(userId, userLoginInfo); var dbSet = new Mock <DbSet <RemoteMembership> >(MockBehavior.Strict).SetupDataAsync(data); var entities = new Mock <IReadEntities>(MockBehavior.Strict); var entitySet = new EntitySet <RemoteMembership>(dbSet.Object, entities.Object); entities.Setup(x => x.Query <RemoteMembership>()).Returns(entitySet); var handler = new HandleRemoteMembershipByUserQuery(entities.Object); RemoteMembership result = handler.Handle(query).Result; result.ShouldBeNull(); entities.Verify(x => x.Query <RemoteMembership>(), Times.Once); }
public void Handler_ReturnsNullRemoteMembership_WhenUserLoginInfoIsNull_ByUserId() { var userId = new Random().Next(1, int.MaxValue - 3); var loginProvider = Guid.NewGuid().ToString(); var providerKey = Guid.NewGuid().ToString(); var remoteMemberships = new[] { new ProxiedRemoteMembership(loginProvider, providerKey) { UserId = userId + 1, }, new ProxiedRemoteMembership(Guid.NewGuid().ToString(), Guid.NewGuid().ToString()) { UserId = userId, }, }; var data = remoteMemberships.AsQueryable(); var query = new RemoteMembershipByUser(userId, null); var dbSet = new Mock <DbSet <RemoteMembership> >(MockBehavior.Strict).SetupDataAsync(data); var entities = new Mock <IReadEntities>(MockBehavior.Strict); var entitySet = new EntitySet <RemoteMembership>(dbSet.Object, entities.Object); entities.Setup(x => x.Query <RemoteMembership>()).Returns(entitySet); var handler = new HandleRemoteMembershipByUserQuery(entities.Object); RemoteMembership result = handler.Handle(query).Result; result.ShouldBeNull(); entities.Verify(x => x.Query <RemoteMembership>(), Times.Never); }
public void Handler_ReturnsNonNullRemoteMembership_WhenFound_ByUserName() { var userName = FakeData.String(); var loginProvider = FakeData.String(); var providerKey = FakeData.String(); var userLoginInfo = new UserLoginInfo(loginProvider, providerKey); var user = new User { Name = userName }; var otherUser = new User { Name = FakeData.String() }; var remoteMemberships = new[] { new ProxiedRemoteMembership(loginProvider, providerKey) { User = otherUser, }, new ProxiedRemoteMembership(FakeData.String(), FakeData.String()) { User = user, }, new ProxiedRemoteMembership(loginProvider, providerKey) { User = user, }, }; var data = remoteMemberships.AsQueryable(); var query = new RemoteMembershipByUser(userName, userLoginInfo); var dbSet = new Mock <DbSet <RemoteMembership> >(MockBehavior.Strict).SetupDataAsync(data); var entities = new Mock <IReadEntities>(MockBehavior.Strict); var entitySet = new EntitySet <RemoteMembership>(dbSet.Object, entities.Object); entities.Setup(x => x.Query <RemoteMembership>()).Returns(entitySet); var handler = new HandleRemoteMembershipByUserQuery(entities.Object); RemoteMembership result = handler.Handle(query).Result; result.ShouldNotBeNull(); Func <ProxiedRemoteMembership, bool> expectedRemoteMembership = x => x.User.Name == userName && x.LoginProvider == loginProvider && x.ProviderKey == providerKey; result.ShouldEqual(remoteMemberships.Single(expectedRemoteMembership)); entities.Verify(x => x.Query <RemoteMembership>(), Times.Once); }
public void Handler_ReturnsNonNullRemoteMembership_WhenFound_ByUserId() { var userId = new Random().Next(1, int.MaxValue - 3); var loginProvider = Guid.NewGuid().ToString(); var providerKey = Guid.NewGuid().ToString(); var userLoginInfo = new UserLoginInfo(loginProvider, providerKey); var remoteMemberships = new[] { new ProxiedRemoteMembership(loginProvider, providerKey) { UserId = userId + 1, }, new ProxiedRemoteMembership(Guid.NewGuid().ToString(), Guid.NewGuid().ToString()) { UserId = userId, }, new ProxiedRemoteMembership(loginProvider, providerKey) { UserId = userId, }, }; var data = remoteMemberships.AsQueryable(); var query = new RemoteMembershipByUser(userId, userLoginInfo); var dbSet = new Mock <DbSet <RemoteMembership> >(MockBehavior.Strict).SetupDataAsync(data); var entities = new Mock <IReadEntities>(MockBehavior.Strict); var entitySet = new EntitySet <RemoteMembership>(dbSet.Object, entities.Object); entities.Setup(x => x.Query <RemoteMembership>()).Returns(entitySet); var handler = new HandleRemoteMembershipByUserQuery(entities.Object); RemoteMembership result = handler.Handle(query).Result; result.ShouldNotBeNull(); Func <ProxiedRemoteMembership, bool> expectedRemoteMembership = x => x.UserId == userId && x.LoginProvider == loginProvider && x.ProviderKey == providerKey; result.ShouldEqual(remoteMemberships.Single(expectedRemoteMembership)); entities.Verify(x => x.Query <RemoteMembership>(), Times.Once); }