public void CreateCommandDefinition_creates_valid_CachingCommandDefinition_for_CachingCommand()
        {
            var command = Mock.Of <DbCommand>();
            var mockCommandDefinition = new Mock <DbCommandDefinition>();

            mockCommandDefinition.Setup(d => d.CreateCommand()).Returns(command);
            var commandTreeFacts   = new CommandTreeFacts(null, true, true);
            var transactionHandler = new Mock <CacheTransactionHandler>(Mock.Of <ICache>()).Object;
            var cachingPolicy      = Mock.Of <CachingPolicy>();

            var cachingCommand = new CachingCommand(command, commandTreeFacts, transactionHandler, cachingPolicy);

            var mockProviderServices = new Mock <DbProviderServices>();

            mockProviderServices.Setup(s => s.CreateCommandDefinition(command)).Returns(mockCommandDefinition.Object);

            var newCommandDefinition =
                new CachingProviderServices(
                    mockProviderServices.Object, new Mock <CacheTransactionHandler>(Mock.Of <ICache>()).Object)
                .CreateCommandDefinition(cachingCommand);

            Assert.IsType <CachingCommandDefinition>(newCommandDefinition);
            mockProviderServices.Verify(s => s.CreateCommandDefinition(command), Times.Once);

            var newCommand = (CachingCommand)newCommandDefinition.CreateCommand();

            Assert.Same(command, newCommand.WrappedCommand);
            Assert.Same(commandTreeFacts, newCommand.CommandTreeFacts);
            Assert.Same(transactionHandler, newCommand.CacheTransactionHandler);
            Assert.Same(cachingPolicy, newCommand.CachingPolicy);
        }
Exemplo n.º 2
0
 public CachingCommandDefinition(DbCommandDefinition commandDefinition, CommandTreeFacts commandTreeFacts, CacheTransactionHandler cacheTransactionHandler, CachingPolicy cachingPolicy)
 {
     _commandDefintion        = commandDefinition;
     _commandTreeFacts        = commandTreeFacts;
     _cacheTransactionHandler = cacheTransactionHandler;
     _cachingPolicy           = cachingPolicy;
 }
Exemplo n.º 3
0
        public void Nondeterministic_functions_discovered_for_queries()
        {
            var f =
                EdmFunction.Create(
                    "CURRENTDATETIME", "EDM", DataSpace.CSpace,
                    new EdmFunctionPayload()
            {
                ReturnParameters = new []
                {
                    FunctionParameter.Create(
                        "ReturnValue",
                        PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String),
                        ParameterMode.ReturnValue)
                }
            },
                    null);

            var commandTreeFacts =
                new CommandTreeFacts(
                    new DbQueryCommandTree(
                        new MetadataWorkspace(),
                        DataSpace.CSpace,
                        f.Invoke(),
                        validate: false));

            Assert.True(commandTreeFacts.UsesNonDeterministicFunctions);
        }
        public void CreateCommandDefinition_creates_valid_CachingCommandDefinition_for_CachingCommand()
        {
            var command = Mock.Of<DbCommand>();
            var mockCommandDefinition = new Mock<DbCommandDefinition>();
            mockCommandDefinition.Setup(d => d.CreateCommand()).Returns(command);
            var commandTreeFacts = new CommandTreeFacts(null, true, true);
            var transactionHandler = new Mock<CacheTransactionHandler>(Mock.Of<ICache>()).Object;
            var cachingPolicy = Mock.Of<CachingPolicy>();

            var cachingCommand = new CachingCommand(command, commandTreeFacts, transactionHandler, cachingPolicy);

            var mockProviderServices = new Mock<DbProviderServices>();
            mockProviderServices.Setup(s => s.CreateCommandDefinition(command)).Returns(mockCommandDefinition.Object);

            var newCommandDefinition =
                new CachingProviderServices(
                    mockProviderServices.Object, new Mock<CacheTransactionHandler>(Mock.Of<ICache>()).Object)
                        .CreateCommandDefinition(cachingCommand);

            Assert.IsType<CachingCommandDefinition>(newCommandDefinition);
            mockProviderServices.Verify(s => s.CreateCommandDefinition(command), Times.Once);

            var newCommand = (CachingCommand)newCommandDefinition.CreateCommand();
            Assert.Same(command, newCommand.WrappedCommand);
            Assert.Same(commandTreeFacts, newCommand.CommandTreeFacts);
            Assert.Same(transactionHandler, newCommand.CacheTransactionHandler);
            Assert.Same(cachingPolicy, newCommand.CachingPolicy);
        }
 public CachingCommandDefinition(DbCommandDefinition commandDefinition, CommandTreeFacts commandTreeFacts, CacheTransactionHandler cacheTransactionHandler, CachingPolicy cachingPolicy)
 {
     _commandDefintion = commandDefinition;
     _commandTreeFacts = commandTreeFacts;
     _cacheTransactionHandler = cacheTransactionHandler;
     _cachingPolicy = cachingPolicy;
 }
Exemplo n.º 6
0
        public CachingCommand(DbCommand command, CommandTreeFacts commandTreeFacts, CacheTransactionHandler cacheTransactionHandler, CachingPolicy cachingPolicy)
        {
            Debug.Assert(command != null, "command is null");
            Debug.Assert(commandTreeFacts != null, "commandTreeFacts is null");
            Debug.Assert(cacheTransactionHandler != null, "cacheTransactionHandler is null");
            Debug.Assert(cachingPolicy != null, "cachingPolicy is null");

            _command                 = command;
            _commandTreeFacts        = commandTreeFacts;
            _cacheTransactionHandler = cacheTransactionHandler;
            _cachingPolicy           = cachingPolicy;
        }
Exemplo n.º 7
0
        public CachingCommand(DbCommand command, CommandTreeFacts commandTreeFacts, CacheTransactionHandler cacheTransactionHandler, CachingPolicy cachingPolicy)
        {
            Debug.Assert(command != null, "command is null");
            Debug.Assert(commandTreeFacts != null, "commandTreeFacts is null");
            Debug.Assert(cacheTransactionHandler != null, "cacheTransactionHandler is null");
            Debug.Assert(cachingPolicy != null, "cachingPolicy is null");

            _command = command;
            _commandTreeFacts = commandTreeFacts;
            _cacheTransactionHandler = cacheTransactionHandler;
            _cachingPolicy = cachingPolicy;
        }
Exemplo n.º 8
0
        public void IsQuery_true_for_DbQueryCommandTree()
        {
            var commandTreeFacts =
                new CommandTreeFacts(
                    new DbQueryCommandTree(
                        new MetadataWorkspace(),
                        DataSpace.CSpace,
                        TypeUsage.CreateDefaultTypeUsage(
                            PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)).Null(),
                        validate: false));

            Assert.True(commandTreeFacts.IsQuery);
        }
Exemplo n.º 9
0
        public void MetadataWorkspace_initialized_from_DbQueryCommandTree()
        {
            var workspace = new MetadataWorkspace();

            var commandTreeFacts =
                new CommandTreeFacts(
                    new DbQueryCommandTree(
                        workspace,
                        DataSpace.CSpace,
                        TypeUsage.CreateDefaultTypeUsage(
                            PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)).Null(),
                        validate: false));

            Assert.Same(workspace, commandTreeFacts.MetadataWorkspace);
        }
Exemplo n.º 10
0
        public void Affected_entity_sets_discovered_for_modification_commands()
        {
            var entityType = EntityType.Create("e", "ns", DataSpace.CSpace, new string[0], new EdmMember[0], null);
            var entitySet = EntitySet.Create("es", "ns", null, null, entityType, null);
            EntityContainer.Create("ec", DataSpace.CSpace, new[] { entitySet }, null, null);

            var commandTreeFacts =
                new CommandTreeFacts(
                    new DbInsertCommandTree(
                        new MetadataWorkspace(),
                        DataSpace.CSpace,
                        entitySet.Scan().Bind(),
                        new List<DbModificationClause>().AsReadOnly(),
                        TypeUsage.CreateDefaultTypeUsage(entityType).Null()));

            Assert.Equal(
                new[] { "es" },
                commandTreeFacts.AffectedEntitySets.Select(s => s.Name));
        }
Exemplo n.º 11
0
        public void Affected_entity_sets_discovered_for_modification_commands()
        {
            var entityType = EntityType.Create("e", "ns", DataSpace.CSpace, new string[0], new EdmMember[0], null);
            var entitySet  = EntitySet.Create("es", "ns", null, null, entityType, null);

            EntityContainer.Create("ec", DataSpace.CSpace, new[] { entitySet }, null, null);

            var commandTreeFacts =
                new CommandTreeFacts(
                    new DbInsertCommandTree(
                        new MetadataWorkspace(),
                        DataSpace.CSpace,
                        entitySet.Scan().Bind(),
                        new List <DbModificationClause>().AsReadOnly(),
                        TypeUsage.CreateDefaultTypeUsage(entityType).Null()));

            Assert.Equal(
                new[] { "es" },
                commandTreeFacts.AffectedEntitySets.Select(s => s.Name));
        }
Exemplo n.º 12
0
        public void Affected_entity_sets_and_functions_discovered_for_queries()
        {
            var e1 = EntityType.Create("e1", "ns", DataSpace.CSpace, new string[0], new EdmMember[0], null);
            var e2 = EntityType.Create("e2", "ns", DataSpace.CSpace, new string[0], new EdmMember[0], null);
            var es1 = EntitySet.Create("es1", "ns", null, null, e1, null);
            var es2 = EntitySet.Create("es2", "ns", null, null, e2, null);
            EntityContainer.Create("ec", DataSpace.CSpace, new[] { es1, es2 }, null, null);

            var commandTreeFacts =
                new CommandTreeFacts(
                    new DbQueryCommandTree(
                        new MetadataWorkspace(),
                        DataSpace.CSpace,
                        es1.Scan().Exists().And(es2.Scan().Exists()),
                        validate: false));

            Assert.Equal(
                new[] { "es1", "es2" },
                commandTreeFacts.AffectedEntitySets.Select(s => s.Name));

            Assert.False(commandTreeFacts.UsesNonDeterministicFunctions);
        }
Exemplo n.º 13
0
        public void Affected_entity_sets_and_functions_discovered_for_queries()
        {
            var e1  = EntityType.Create("e1", "ns", DataSpace.CSpace, new string[0], new EdmMember[0], null);
            var e2  = EntityType.Create("e2", "ns", DataSpace.CSpace, new string[0], new EdmMember[0], null);
            var es1 = EntitySet.Create("es1", "ns", null, null, e1, null);
            var es2 = EntitySet.Create("es2", "ns", null, null, e2, null);

            EntityContainer.Create("ec", DataSpace.CSpace, new[] { es1, es2 }, null, null);

            var commandTreeFacts =
                new CommandTreeFacts(
                    new DbQueryCommandTree(
                        new MetadataWorkspace(),
                        DataSpace.CSpace,
                        es1.Scan().Exists().And(es2.Scan().Exists()),
                        validate: false));

            Assert.Equal(
                new[] { "es1", "es2" },
                commandTreeFacts.AffectedEntitySets.Select(s => s.Name));

            Assert.False(commandTreeFacts.UsesNonDeterministicFunctions);
        }
Exemplo n.º 14
0
        public void IsQuery_true_for_DbQueryCommandTree()
        {
            var commandTreeFacts =
                new CommandTreeFacts(
                    new DbQueryCommandTree(
                        new MetadataWorkspace(),
                        DataSpace.CSpace,
                        TypeUsage.CreateDefaultTypeUsage(
                            PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)).Null(),
                            validate: false));

            Assert.True(commandTreeFacts.IsQuery);
        }
Exemplo n.º 15
0
        public void Nondeterministic_functions_discovered_for_queries()
        {
            var f =
                EdmFunction.Create(
                    "CURRENTDATETIME", "EDM", DataSpace.CSpace,
                    new EdmFunctionPayload()
                    {
                        ReturnParameters = new []
                        {
                            FunctionParameter.Create(
                                "ReturnValue",
                                PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String),
                                ParameterMode.ReturnValue)
                        }
                    },
                    null);

            var commandTreeFacts =
                new CommandTreeFacts(
                    new DbQueryCommandTree(
                        new MetadataWorkspace(),
                        DataSpace.CSpace,
                        f.Invoke(),
                        validate: false));

            Assert.True(commandTreeFacts.UsesNonDeterministicFunctions);
        }
Exemplo n.º 16
0
        public void MetadataWorkspace_initialized_from_DbQueryCommandTree()
        {
            var workspace = new MetadataWorkspace();

            var commandTreeFacts =
                new CommandTreeFacts(
                    new DbQueryCommandTree(
                        workspace,
                        DataSpace.CSpace,
                        TypeUsage.CreateDefaultTypeUsage(
                            PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)).Null(),
                            validate: false));

            Assert.Same(workspace, commandTreeFacts.MetadataWorkspace);
        }