public void Query() { var context = _contextFunc(); var syncStatusContext = new SyncStatusDbContext(context.Database.Connection.ConnectionString); syncStatusContext.SyncStatusServerObjects.Add( new SyncStatusServerObject("a", "1") { LastChange = new DateTimeOffset(new DateTime(2017, 2, 1)), Tag0 = "all" } ); syncStatusContext.SyncStatusServerObjects.Add( new SyncStatusServerObject("a", "2") { LastChange = new DateTimeOffset(new DateTime(2017, 2, 2)), Tag0 = "tag1" } ); syncStatusContext.SyncStatusServerObjects.Add( new SyncStatusServerObject("a", "3") { LastChange = new DateTimeOffset(new DateTime(2017, 2, 3)), Tag0 = "tag1", Tag1 = "all" } ); syncStatusContext.SyncStatusServerObjects.Add( new SyncStatusServerObject("a", "4") { LastChange = new DateTimeOffset(new DateTime(2017, 2, 10)), Tag0 = "all" } ); syncStatusContext.SaveChanges(); var user = new LimitedUser(new[] { "all", "tag0", "tag1" }); var result1 = _processor.CreateQuery(new DownloadDataRequest() { LastChangeTime = new Dictionary <string, DateTimeOffset>() { }, Types = new[] { "a" }, }, user, syncStatusContext).ToList(); string.Join(", ", result1.Select(x => x.MobilePrimaryKey)) .Should().BeEquivalentTo("1, 2, 3, 4"); var result2 = _processor.CreateQuery(new DownloadDataRequest() { LastChangeTime = new Dictionary <string, DateTimeOffset>() { { "all", new DateTimeOffset(new DateTime(2017, 2, 3, 1, 0, 0)) } }, Types = new[] { "a" }, }, user, syncStatusContext).ToList(); string.Join(", ", result2.Select(x => x.MobilePrimaryKey)) .Should().BeEquivalentTo("2, 3, 4"); var result3 = _processor.CreateQuery(new DownloadDataRequest() { LastChangeTime = new Dictionary <string, DateTimeOffset>() { { "all", new DateTimeOffset(new DateTime(2017, 2, 3, 1, 0, 0)) }, { "tag1", new DateTimeOffset(new DateTime(2017, 2, 2, 1, 0, 0)) }, }, Types = new[] { "a" }, }, user, syncStatusContext).ToList(); string.Join(", ", result3.Select(x => x.MobilePrimaryKey)) .Should().BeEquivalentTo("3, 4"); }