public void ByUserLoginInfo_Enumerable_CanAllowNull() { var data = new[] { new LocalMembership { User = new User { Name = FakeData.String() }, }, new LocalMembership { User = new User { Name = FakeData.String() }, }, new LocalMembership { User = new User { Name = FakeData.String() }, }, }; foreach (var localMembership in data) { for (var i = 0; i < 3; i++) { string loginProvider = FakeData.String(); string providerKey = FakeData.String(); var remoteMembership = new ProxiedRemoteMembership(loginProvider, providerKey); localMembership.User.RemoteMemberships.Add(remoteMembership); } } var userLoginInfo = new UserLoginInfo(FakeData.String(), FakeData.String()); data.AsEnumerable().ByUserLoginInfo(userLoginInfo).ShouldBeNull(); }
public void Handler_ReturnsNullUser_WhenNotFound_ByUserLoginInfo() { const string loginProvider = "loginProvider"; var providerKey = Guid.NewGuid().ToString(); var remoteMembershipId = new RemoteMembershipId { LoginProvider = loginProvider, ProviderKey = Guid.NewGuid().ToString(), }; 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 ByUserLoginInfoAsync_Enumerable_CanAllowNull() { var data = new[] { new User { Name = FakeData.String(), }, new User { Name = FakeData.String(), }, new User { Name = FakeData.String(), }, }; foreach (var user in data) { for (var i = 0; i < 3; i++) { string loginProvider = FakeData.String(); string providerKey = FakeData.String(); var remoteMembership = new ProxiedRemoteMembership(loginProvider, providerKey); user.RemoteMemberships.Add(remoteMembership); } } var dbSet = new Mock <DbSet <User> >(MockBehavior.Strict).SetupDataAsync(data.AsQueryable()); var userLoginInfo = new UserLoginInfo(FakeData.String(), FakeData.String()); dbSet.Object.AsEnumerable().ByUserLoginInfoAsync(userLoginInfo).Result.ShouldBeNull(); }
public void ComponentProperties_DelegateTo_CompositeId() { var entity = new RemoteMembership { Id = { LoginProvider = "provider1", ProviderKey = "key1" } }; entity.LoginProvider.ShouldEqual(entity.Id.LoginProvider); entity.ProviderKey.ShouldEqual(entity.Id.ProviderKey); entity = new ProxiedRemoteMembership("provider2", "key2"); entity.LoginProvider.ShouldEqual(entity.Id.LoginProvider); entity.ProviderKey.ShouldEqual(entity.Id.ProviderKey); }
public void ByUserLoginInfoAsync_Enumerable_CanDisallowNull() { var data = new[] { new LocalMembership { User = new User { Name = FakeData.String() }, }, new LocalMembership { User = new User { Name = FakeData.String() }, }, new LocalMembership { User = new User { Name = FakeData.String() }, }, }; foreach (var localMembership in data) { for (var i = 0; i < 3; i++) { string loginProvider = FakeData.String(); string providerKey = FakeData.String(); var remoteMembership = new ProxiedRemoteMembership(loginProvider, providerKey); localMembership.User.RemoteMemberships.Add(remoteMembership); } } var dbSet = new Mock <DbSet <LocalMembership> >(MockBehavior.Strict).SetupDataAsync(data.AsQueryable()); var existingRemoteMembership = data[0].User.RemoteMemberships.First(); var userLoginInfo = new UserLoginInfo( existingRemoteMembership.LoginProvider, existingRemoteMembership.ProviderKey); dbSet.Object.AsEnumerable().ByUserLoginInfoAsync(userLoginInfo, false).Result.ShouldNotBeNull(); userLoginInfo = new UserLoginInfo(FakeData.String(), FakeData.String()); var exception = Assert.Throws <InvalidOperationException>(() => dbSet.Object.AsEnumerable().ByUserLoginInfoAsync(userLoginInfo, false).Result); Assert.NotNull(exception); exception.Message.IndexOf("Sequence contains no matching element", StringComparison.CurrentCulture) .ShouldEqual(0); }
public void ByUserLoginInfo_Enumerable_CanDisallowNull() { var data = new[] { new User { Name = FakeData.String(), }, new User { Name = FakeData.String(), }, new User { Name = FakeData.String(), }, }; foreach (var user in data) { for (var i = 0; i < 3; i++) { string loginProvider = FakeData.String(); string providerKey = FakeData.String(); var remoteMembership = new ProxiedRemoteMembership(loginProvider, providerKey); user.RemoteMemberships.Add(remoteMembership); } } var existingRemoteMembership = data[0].RemoteMemberships.First(); var userLoginInfo = new UserLoginInfo( existingRemoteMembership.LoginProvider, existingRemoteMembership.ProviderKey); data.AsEnumerable().ByUserLoginInfo(userLoginInfo, false).ShouldNotBeNull(); userLoginInfo = new UserLoginInfo(FakeData.String(), FakeData.String()); var exception = Assert.Throws <InvalidOperationException>(() => data.AsEnumerable().ByUserLoginInfo(userLoginInfo, false)); Assert.NotNull(exception); exception.Message.IndexOf("Sequence contains no matching element", StringComparison.CurrentCulture) .ShouldEqual(0); }
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 ByUserLoginInfoAsync_Enumerable_CanDisallowNull() { var data = new[] { new LocalMembership { User = new User { Name = FakeData.String() }, }, new LocalMembership { User = new User { Name = FakeData.String() }, }, new LocalMembership { User = new User { Name = FakeData.String() }, }, }; foreach (var localMembership in data) { for (var i = 0; i < 3; i++) { string loginProvider = FakeData.String(); string providerKey = FakeData.String(); var remoteMembership = new ProxiedRemoteMembership(loginProvider, providerKey); localMembership.User.RemoteMemberships.Add(remoteMembership); } } var dbSet = new Mock<DbSet<LocalMembership>>(MockBehavior.Strict).SetupDataAsync(data.AsQueryable()); var existingRemoteMembership = data[0].User.RemoteMemberships.First(); var userLoginInfo = new UserLoginInfo( existingRemoteMembership.LoginProvider, existingRemoteMembership.ProviderKey); dbSet.Object.AsEnumerable().ByUserLoginInfoAsync(userLoginInfo, false).Result.ShouldNotBeNull(); userLoginInfo = new UserLoginInfo(FakeData.String(), FakeData.String()); var exception = Assert.Throws<InvalidOperationException>(() => dbSet.Object.AsEnumerable().ByUserLoginInfoAsync(userLoginInfo, false).Result); Assert.NotNull(exception); exception.Message.IndexOf("Sequence contains no matching element", StringComparison.CurrentCulture) .ShouldEqual(0); }
public void ByUserLoginInfoAsync_Enumerable_CanAllowNull() { var data = new[] { new LocalMembership { User = new User { Name = FakeData.String() }, }, new LocalMembership { User = new User { Name = FakeData.String() }, }, new LocalMembership { User = new User { Name = FakeData.String() }, }, }; foreach (var localMembership in data) { for (var i = 0; i < 3; i++) { string loginProvider = FakeData.String(); string providerKey = FakeData.String(); var remoteMembership = new ProxiedRemoteMembership(loginProvider, providerKey); localMembership.User.RemoteMemberships.Add(remoteMembership); } } var dbSet = new Mock<DbSet<LocalMembership>>(MockBehavior.Strict).SetupDataAsync(data.AsQueryable()); var userLoginInfo = new UserLoginInfo(FakeData.String(), FakeData.String()); dbSet.Object.AsEnumerable().ByUserLoginInfoAsync(userLoginInfo).Result.ShouldBeNull(); }
public void ByUserLoginInfo_Enumerable_CanDisallowNull() { var data = new[] { new User { Name = FakeData.String(), }, new User { Name = FakeData.String(), }, new User { Name = FakeData.String(), }, }; foreach (var user in data) { for (var i = 0; i < 3; i++) { string loginProvider = FakeData.String(); string providerKey = FakeData.String(); var remoteMembership = new ProxiedRemoteMembership(loginProvider, providerKey); user.RemoteMemberships.Add(remoteMembership); } } var existingRemoteMembership = data[0].RemoteMemberships.First(); var userLoginInfo = new UserLoginInfo( existingRemoteMembership.LoginProvider, existingRemoteMembership.ProviderKey); data.AsEnumerable().ByUserLoginInfo(userLoginInfo, false).ShouldNotBeNull(); userLoginInfo = new UserLoginInfo(FakeData.String(), FakeData.String()); var exception = Assert.Throws<InvalidOperationException>(() => data.AsEnumerable().ByUserLoginInfo(userLoginInfo, false)); Assert.NotNull(exception); exception.Message.IndexOf("Sequence contains no matching element", StringComparison.CurrentCulture) .ShouldEqual(0); }