예제 #1
0
        [Test] public void ExecuateNonQueryFallsBackToLoop()
        {
            var collection = new Dictionary <string, int>
            {
                { "a", 2 },
                { "b", 5 },
                { "x", 3 }
            };
            IDbParameters parameters = _mockery.StrictMock <IDbParameters>();

            foreach (var pair in collection)
            {
                Expect.Call(_converter(pair.Key)).Return(parameters);
                int toReturn = pair.Value;
                Expect.Call(_adoOperations.ExecuteNonQuery(CommandType.Text, _sql, (ICommandSetter)null))
                .IgnoreArguments().Do(new Func <CommandType, string, ICommandSetter, int>(
                                          delegate(CommandType cmdType, string cmdText, ICommandSetter setter)
                {
                    Assert.AreEqual(CommandType.Text, cmdType);
                    Assert.AreEqual(_sql, cmdText);
                    return(toReturn);
                }
                                          ));
            }

            _mockery.ReplayAll();
            int result = AdoOperationsExtension.ExecuteNonQuery(_adoOperations, CommandType.Text, _sql, collection.Keys, _converter);

            Assert.That(result, Is.EqualTo(10));
            _mockery.VerifyAll();
        }
예제 #2
0
        [Test] public void ExecutNonQueryChokesOnNullDataToParameters()
        {
            Exception e = Assert.Throws <ArgumentNullException>(
                () => AdoOperationsExtension.ExecuteNonQuery(_adoOperations, CommandType.Text, _sql, new string[1], null));

            StringAssert.Contains("dataToParameters", e.Message);
        }
예제 #3
0
        [Test] public void ExecutNonQueryChokesOnNullCommandText()
        {
            Exception e = Assert.Throws <ArgumentNullException>(
                () => AdoOperationsExtension.ExecuteNonQuery(_adoOperations, CommandType.Text, null, new string[1], _converter));

            StringAssert.Contains("cmdText", e.Message);
        }
예제 #4
0
        [Test] public void ExecutNonQueryReturnsZeroOnEmptyColleciton()
        {
            int result = AdoOperationsExtension.ExecuteNonQuery(_adoOperations, CommandType.Text, _sql, null, _converter);

            Assert.That(result, Is.EqualTo(0));
            result = AdoOperationsExtension.ExecuteNonQuery(_adoOperations, CommandType.Text, _sql, new string[0], _converter);
            Assert.That(result, Is.EqualTo(0));
        }
예제 #5
0
        [Test] public void ExecuteNonQueryCallsBatchExecutor()
        {
            var collection = new[] { "x", "y", "c", "r" };

            _adoOperations = _mockery.StrictMultiMock <IAdoOperations>(typeof(IBatchExecutorFactory));
            var factory       = (IBatchExecutorFactory)_adoOperations;
            var batchExecutor = _mockery.StrictMock <IBatchExecutor>();

            Expect.Call(factory.GetExecutor()).Return(batchExecutor);
            Expect.Call(batchExecutor.ExecuteNonQuery(_adoOperations, CommandType.Text, _sql, collection, _converter)).Return(10);

            _mockery.ReplayAll();
            int result = AdoOperationsExtension.ExecuteNonQuery(_adoOperations, CommandType.Text, _sql, collection, _converter);

            Assert.That(result, Is.EqualTo(10));
            _mockery.VerifyAll();
        }