public void GivenRegisterSnapshotCalledMultipleTimesWhenQueryExecutedThenShouldCallAllCallbacks() { var query = new QuerySnapshotHost <IdType>(Query); var firstCallback = false; var secondCallback = false; query.RegisterSnap(e => firstCallback = true); query.RegisterSnap(e => secondCallback = true); var _ = query.Skip(2).Take(3).ToList(); Assert.True(firstCallback && secondCallback); }
public void GivenNullWhenRegisterSnapshotCalledThenShouldThrowArgumentNull() { var query = new QuerySnapshotHost <IdType>(Query); Assert.Throws <System.ArgumentNullException>( () => query.RegisterSnap(null)); }
public void GivenRegisterSnapshotCalledWhenQueryExecutedTwiceThenShouldCallbackTwice() { var query = new QuerySnapshotHost <IdType>(Query); int callCount = 0; query.RegisterSnap(e => callCount++); var _ = query.Skip(2).Take(3).ToList(); var __ = query.Skip(3).Take(2).ToList(); Assert.Equal(2, callCount); }
public void GivenRegisterSnapshotCalledWhenUnregisterCalledThenShouldStopCallingBack() { var query = new QuerySnapshotHost <IdType>(Query); int callCount = 0; var key = query.RegisterSnap(e => callCount++); var _ = query.Skip(2).Take(3).ToList(); query.UnregisterSnap(key); var __ = query.Skip(3).Take(2).ToList(); Assert.Equal(1, callCount); }
public void GivenRegisterSnapshotCalledWhenQueryExecutedThenShouldCallbackOnce() { var query = new QuerySnapshotHost <IdType>(Query); Expression target = null; query.RegisterSnap(e => target = e); var _ = query.Skip(2).Take(3).ToList(); Assert.NotNull(target); Assert.True(target.AsEnumerable() .MethodsWithNameForType(typeof(Queryable), nameof(Enumerable.Take)) .Any()); }
public void GivenRegisterSnapshotCalledWhenQueryExecutedWithProjectionThenShouldCallbackOnce() { var query = new QuerySnapshotHost <IdType>(Query); Expression target = null; void CaptureSnap(Expression e) { target = e; } query.RegisterSnap(CaptureSnap); var _ = query.Skip(2).Take(3).Select(i => new { i.Id, i.IdVal }).ToList(); Assert.NotNull(target); Assert.True(target.AsEnumerable() .MethodsWithNameForType(typeof(Queryable), nameof(Enumerable.Take)) .Any()); }