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 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 void CreateCommandDefinition_creates_valid_DbCommandDefinition_for_DbCommand() { var command = Mock.Of<DbCommand>(); var mockCommandDefinition = new Mock<DbCommandDefinition>(); mockCommandDefinition.Setup(d => d.CreateCommand()).Returns(command); 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(command); Assert.IsNotType<CachingCommandDefinition>(newCommandDefinition); mockProviderServices.Verify(s => s.CreateCommandDefinition(command), Times.Once); var newCommand = newCommandDefinition.CreateCommand(); Assert.Same(command, newCommand); }
public void CreateCommandDefinition_creates_valid_DbCommandDefinition_for_DbCommand() { var command = Mock.Of <DbCommand>(); var mockCommandDefinition = new Mock <DbCommandDefinition>(); mockCommandDefinition.Setup(d => d.CreateCommand()).Returns(command); 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(command); Assert.IsNotType <CachingCommandDefinition>(newCommandDefinition); mockProviderServices.Verify(s => s.CreateCommandDefinition(command), Times.Once); var newCommand = newCommandDefinition.CreateCommand(); Assert.Same(command, newCommand); }