Пример #1
0
 public RedisQueryModelVisitorTests()
     : base(new RedisQueryCompilationContext(
                QueryTestType.Model(),
                new LinqOperatorProvider(),
                new ResultOperatorHandler()))
 {
 }
 public RedisQueryModelVisitorTests()
     : base(new RedisQueryCompilationContext(
                QueryTestType.Model(),
                new LoggerFactory().Create("Fake"),
                new LinqOperatorProvider(),
                new ResultOperatorHandler(),
                new QueryMethodProvider()))
 {
 }
        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 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));
        }
        public void GetValueReaders_returns_ObjectArrayReaders_over_an_enumerable_of_object_arrays()
        {
            var configurationMock           = new Mock <DbContextConfiguration>();
            var redisDatabaseMock           = new Mock <RedisDatabase>(configurationMock.Object);
            var materializationStrategyMock = new Mock <IQueryBuffer>();
            var stateManagerMockMock        = new Mock <StateManager>();

            var redisQueryContextMock
                = new Mock <RedisQueryContext>(
                      NullLogger.Instance,
                      materializationStrategyMock.Object,
                      stateManagerMockMock.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());
            var i = 1;

            foreach (var reader in readers)
            {
                Assert.Equal(i, reader.ReadValue <int>(0));
                Assert.Equal("SomeValue" + i, reader.ReadValue <string>(1));
                i++;
            }
        }
        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));
        }