public void GetValueReaders_returns_ObjectArrayReaders_over_an_enumerable_of_object_arrays() { var configurationMock = new Mock <DbContextConfiguration>(); var redisDatabaseMock = new Mock <RedisDatabase>(configurationMock.Object); var stateManagerMock = new Mock <StateManager>(); var redisQueryContextMock = new Mock <RedisQueryContext>( QueryTestType.Model(), NullLogger.Instance, stateManagerMock.Object, redisDatabaseMock.Object); var resultsFromDatabase = new List <object[]> { new object[] { 1, "SomeValue1" }, new object[] { 2, "SomeValue2" } }; redisQueryContextMock.Setup(m => m.GetResultsFromRedis(It.IsAny <RedisQuery>())).Returns(resultsFromDatabase); var entityType = QueryTestType.EntityType(); var redisQuery = new RedisQuery(entityType); var readers = redisQuery.GetValueReaders(redisQueryContextMock.Object); Assert.Equal(2, readers.Count()); int i = 1; foreach (var reader in readers) { Assert.Equal(i, reader.ReadValue <int>(0)); Assert.Equal("SomeValue" + i, reader.ReadValue <string>(1)); i++; } }
private static IEnumerable <IValueReader> ExecuteProjectionQueryExpression( QueryContext queryContext, RedisQuery redisQuery) { var redisQueryContext = (RedisQueryContext)queryContext; return(redisQueryContext .GetResultsEnumerable(redisQuery) .Select(objectArray => new ObjectArrayValueReader(objectArray))); }
public void Constructor_stores_EntityType_and_produces_empty_SelectedProperties() { var entityType = QueryTestType.EntityType(); var redisQuery = new RedisQuery(entityType); Assert.Equal(entityType, redisQuery.EntityType); Assert.Empty(redisQuery.SelectedProperties); }
private static IEnumerable <TEntity> ExecuteMaterializationQueryExpression <TEntity>( QueryContext queryContext, RedisQuery redisQuery) where TEntity : class, new() { var redisQueryContext = (RedisQueryContext)queryContext; return(redisQueryContext .GetResultsEnumerable(redisQuery) .Select(objectArray => (TEntity)redisQueryContext.QueryBuffer .GetEntity(redisQuery.EntityType, new ObjectArrayValueReader(objectArray)))); }
private RedisQuery FindOrCreateQuery(IQuerySource querySource) { var entityType = QueryCompilationContext.Model.GetEntityType(querySource.ItemType); RedisQuery redisQuery; if (!_queriesBySource.TryGetValue(querySource, out redisQuery)) { redisQuery = new RedisQuery(entityType); _queriesBySource[querySource] = redisQuery; } return(redisQuery); }
public virtual RedisQuery FindOrCreateQuery([NotNull] IQuerySource querySource) { Check.NotNull(querySource, "querySource"); var entityType = QueryCompilationContext.Model.GetEntityType(querySource.ItemType); RedisQuery redisQuery; if (!_queriesBySource.TryGetValue(querySource, out redisQuery)) { redisQuery = new RedisQuery(entityType); _queriesBySource[querySource] = redisQuery; } return(redisQuery); }
public void GetResultsFromRedis_RedisQuery_calls_RedisDatabase_GetResults() { var model = QueryTestType.Model(); var logger = NullLogger.Instance; var configurationMock = new Mock <DbContextConfiguration>(); var redisDatabaseMock = new Mock <RedisDatabase>(configurationMock.Object); var stateManagerMock = new Mock <StateManager>(); var redisQueryContext = new RedisQueryContext(model, logger, stateManagerMock.Object, redisDatabaseMock.Object); var entityType = QueryTestType.EntityType(); var redisQuery = new RedisQuery(entityType); redisQueryContext.GetResultsFromRedis(redisQuery); redisDatabaseMock.Verify(m => m.GetResults(redisQuery), Times.Once); redisDatabaseMock.Verify(m => m.GetMaterializedResults <QueryTestType>(entityType), Times.Never); }
public void AddProperty_updates_SelectedProperties_and_subsequent_GetProjectionIndex_is_correct() { // add 1 property var entityType = QueryTestType.EntityType(); var redisQuery = new RedisQuery(entityType); var someValueProperty = entityType.GetProperty("SomeValue"); redisQuery.AddProperty(someValueProperty); Assert.True((new List <IProperty>() { someValueProperty }).SequenceEqual(redisQuery.SelectedProperties)); Assert.Equal(0, redisQuery.GetProjectionIndex(someValueProperty)); // add a different property var idProperty = entityType.GetProperty("Id"); redisQuery.AddProperty(idProperty); Assert.True((new List <IProperty>() { someValueProperty, idProperty }).SequenceEqual(redisQuery.SelectedProperties)); Assert.Equal(0, redisQuery.GetProjectionIndex(someValueProperty)); Assert.Equal(1, redisQuery.GetProjectionIndex(idProperty)); // add the 1st property again - adds to end of list redisQuery.AddProperty(someValueProperty); Assert.True((new List <IProperty>() { someValueProperty, idProperty, someValueProperty }).SequenceEqual(redisQuery.SelectedProperties)); // Note: GetProjectionIndex(someValueProperty) returns the _first_ index at which that property is returned Assert.Equal(0, redisQuery.GetProjectionIndex(someValueProperty)); Assert.Equal(1, redisQuery.GetProjectionIndex(idProperty)); }
public virtual IEnumerable <object[]> GetResultsFromRedis([NotNull] RedisQuery redisQuery) { Check.NotNull(redisQuery, "redisQuery"); return(_redisDatabase.GetResults(redisQuery)); }