public override void AssertSingleResult <TItem1, TItem2>( Func <IQueryable <TItem1>, IQueryable <TItem2>, object> actualQuery, Func <IQueryable <TItem1>, IQueryable <TItem2>, object> expectedQuery, Action <object, object> asserter = null, int entryCount = 0) { using (var context = _contextCreator()) { var actual = actualQuery( SetExtractor.Set <TItem1>(context), SetExtractor.Set <TItem2>(context)); var expected = expectedQuery( ExpectedData.Set <TItem1>(), ExpectedData.Set <TItem2>()); if (asserter == null && expected != null) { _entityAsserters.TryGetValue(expected.GetType(), out asserter); } if (asserter != null) { asserter(expected, actual); } else { Assert.Equal(expected, actual); } Assert.Equal(entryCount, context.ChangeTracker.Entries().Count()); } }
public override async Task AssertQueryScalar <TItem1, TItem2, TItem3, TResult>( Func <IQueryable <TItem1>, IQueryable <TItem2>, IQueryable <TItem3>, IQueryable <TResult> > actualQuery, Func <IQueryable <TItem1>, IQueryable <TItem2>, IQueryable <TItem3>, IQueryable <TResult> > expectedQuery, bool assertOrder = false, bool isAsync = false) { using (var context = _contextCreator()) { var actual = isAsync ? await actualQuery( SetExtractor.Set <TItem1>(context), SetExtractor.Set <TItem2>(context), SetExtractor.Set <TItem3>(context)).ToArrayAsync() : actualQuery( SetExtractor.Set <TItem1>(context), SetExtractor.Set <TItem2>(context), SetExtractor.Set <TItem3>(context)).ToArray(); var expected = expectedQuery( ExpectedData.Set <TItem1>(), ExpectedData.Set <TItem2>(), ExpectedData.Set <TItem3>()).ToArray(); TestHelpers.AssertResults( expected, actual, e => e, Assert.Equal, assertOrder); } }
public override async Task <List <object> > AssertIncludeQuery <TItem1>( Func <IQueryable <TItem1>, IQueryable <object> > actualQuery, Func <IQueryable <TItem1>, IQueryable <object> > expectedQuery, List <IExpectedInclude> expectedIncludes, Func <dynamic, object> elementSorter = null, List <Func <dynamic, object> > clientProjections = null, bool assertOrder = false, int entryCount = 0, bool isAsync = false) { using (var context = _contextCreator()) { var actual = isAsync ? await actualQuery( SetExtractor.Set <TItem1>(context)).ToListAsync() : actualQuery( SetExtractor.Set <TItem1>(context)).ToList(); var expected = expectedQuery(ExpectedData.Set <TItem1>()).ToList(); if (!assertOrder) { if (elementSorter == null) { var firstNonNullableElement = expected.FirstOrDefault(e => e != null); if (firstNonNullableElement != null) { _entitySorters.TryGetValue(firstNonNullableElement.GetType(), out elementSorter); } } if (elementSorter != null) { actual = actual.OrderBy(elementSorter).ToList(); expected = expected.OrderBy(elementSorter).ToList(); } } if (clientProjections != null) { foreach (var clientProjection in clientProjections) { var projectedActual = actual.Select(clientProjection).ToList(); var projectedExpected = expected.Select(clientProjection).ToList(); _includeResultAsserter.AssertResult(projectedExpected, projectedActual, expectedIncludes); } } else { _includeResultAsserter.AssertResult(expected, actual, expectedIncludes); } Assert.Equal(entryCount, context.ChangeTracker.Entries().Count()); return(actual); } }
public override async Task AssertQuery <TItem1, TItem2, TItem3>( Func <IQueryable <TItem1>, IQueryable <TItem2>, IQueryable <TItem3>, IQueryable <object> > actualQuery, Func <IQueryable <TItem1>, IQueryable <TItem2>, IQueryable <TItem3>, IQueryable <object> > expectedQuery, Func <dynamic, object> elementSorter = null, Action <dynamic, dynamic> elementAsserter = null, bool assertOrder = false, int entryCount = 0, bool isAsync = false) { using (var context = _contextCreator()) { var actual = isAsync ? await actualQuery( SetExtractor.Set <TItem1>(context), SetExtractor.Set <TItem2>(context), SetExtractor.Set <TItem3>(context)).ToArrayAsync() : actualQuery( SetExtractor.Set <TItem1>(context), SetExtractor.Set <TItem2>(context), SetExtractor.Set <TItem3>(context)).ToArray(); var expected = expectedQuery( ExpectedData.Set <TItem1>(), ExpectedData.Set <TItem2>(), ExpectedData.Set <TItem3>()).ToArray(); if (!assertOrder && elementSorter == null && expected.Length > 0 && expected[0] != null) { _entitySorters.TryGetValue(expected[0].GetType(), out elementSorter); } if (elementAsserter == null && expected.Length > 0 && expected[0] != null) { _entityAsserters.TryGetValue(expected[0].GetType(), out elementAsserter); } TestHelpers.AssertResults( expected, actual, elementSorter, elementAsserter, assertOrder); Assert.Equal(entryCount, context.ChangeTracker.Entries().Count()); } }
public override void AssertQueryScalar <TItem1, TResult>( Func <IQueryable <TItem1>, IQueryable <TResult?> > actualQuery, Func <IQueryable <TItem1>, IQueryable <TResult?> > expectedQuery, bool assertOrder = false) { using (var context = _contextCreator()) { var actual = actualQuery(SetExtractor.Set <TItem1>(context)).ToArray(); var expected = expectedQuery(ExpectedData.Set <TItem1>()).ToArray(); TestHelpers.AssertResultsNullable( expected, actual, e => e, Assert.Equal, assertOrder); } }