Пример #1
0
 public RedisQueryModelVisitorTests()
     : base(new RedisQueryCompilationContext(
                QueryTestType.Model(),
                new LinqOperatorProvider(),
                new ResultOperatorHandler()))
 {
 }
Пример #2
0
        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++;
            }
        }
Пример #3
0
        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);
        }
Пример #4
0
        public void Can_construct_RedisQueryCompilationContext()
        {
            var model = QueryTestType.Model();

            Assert.DoesNotThrow(() =>
                                new RedisQueryCompilationContext(
                                    model,
                                    new LinqOperatorProvider(),
                                    new ResultOperatorHandler()));
        }
Пример #5
0
        public void Can_construct_RedisQueryContext()
        {
            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 stateManager      = stateManagerMock.Object;

            var redisQueryContext = new RedisQueryContext(model, logger, stateManager, redisDatabaseMock.Object);

            Assert.Equal(model, redisQueryContext.Model);
            Assert.Equal(logger, redisQueryContext.Logger);
        }
Пример #6
0
        public void CreateQueryModelVisitor_returns_new_visitor()
        {
            var model = QueryTestType.Model();
            var redisQueryCompilationContext =
                new RedisQueryCompilationContext(
                    model,
                    new LinqOperatorProvider(),
                    new ResultOperatorHandler());

            var parentVisitor = new RedisQueryModelVisitor(redisQueryCompilationContext);
            var visitor       = redisQueryCompilationContext.CreateQueryModelVisitor(parentVisitor);

            Assert.IsType <RedisQueryModelVisitor>(visitor);
            Assert.False(ReferenceEquals(visitor, parentVisitor));
        }
Пример #7
0
        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);
        }
Пример #8
0
        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));
        }