public void UserStoreInterface_FindByIdAsync_ThrowsWhenDisposed() { var instance = new SecurityStore(null) as IUserStore <User, int>; instance.Dispose(); var exception = Assert.Throws <ObjectDisposedException>(() => instance.FindByIdAsync(new Random().Next(0, int.MaxValue)).Result); exception.ShouldNotBeNull(); exception.ObjectName.ShouldEqual(instance.GetType().Name); }
public void UserStoreInterface_FindByIdAsync_DelegatesToDataDependency(int userId, bool expectFound) { var entities = new Mock <IWriteEntities>(MockBehavior.Strict); var instance = new SecurityStore(entities.Object) as IUserStore <User, int>; var data = new[] { new FakeUser(1), new FakeUser(2), new FakeUser(3) }.AsQueryable(); var dbSet = new Mock <DbSet <User> >(MockBehavior.Strict).SetupDataAsync(data); entities.Setup(x => x.Get <User>()).Returns(dbSet.Object); Expression <Func <IQueryable <User>, bool> > expectedData = x => ReferenceEquals(x, dbSet.Object); entities.Setup(x => x.EagerLoad(It.Is(expectedData), It.IsAny <Expression <Func <User, object> > >())).Returns(dbSet.Object); var result = instance.FindByIdAsync(userId).Result; (result != null).ShouldEqual(expectFound); if (expectFound) { result.ShouldEqual(data.Single(x => userId.Equals(x.Id))); } entities.Verify(x => x.Get <User>(), Times.Once); }