Пример #1
0
        public void Validation_Missing_Parameter2()
        {
            var args = new ParameterCollection(new FakeParameter("status", 1));
            var result = new ScalarCommandResult("UPDATE User SET Status = @status", args) { Result = "Hello correct" };
            var sut = new FakeCommand(new[] { result });

            sut.CommandText = "UPDATE User SET Status = @status";
            sut.AddParameter("status", 1);
            sut.AddParameter("id", 22);
            sut.ExecuteScalar();
        }
        public void Validation_Missing_Parameter2()
        {
            var args   = new ParameterCollection(new FakeParameter("status", 1));
            var result = new ScalarCommandResult("UPDATE User SET Status = @status", args)
            {
                Result = "Hello correct"
            };
            var sut = new FakeCommand(new[] { result });

            sut.CommandText = "UPDATE User SET Status = @status";
            sut.AddParameter("status", 1);
            sut.AddParameter("id", 22);
            Assert.Throws <CommandValidationException>(() => sut.ExecuteScalar());
        }
        public void ReturnTable()
        {
            var sut = new FakeCommand();

            sut.Setup(new ScalarCommandResult()
            {
                Result = "Hello"
            });
            sut.Setup(new NonQueryCommandResult()
            {
                Result = 0
            });

            sut.CommandText = "SELECT 2";
            var result = sut.ExecuteScalar();

            sut.CommandText = "UPDATE XXXX SET UserId = @userId";
            sut.AddParameter("userId", 1);
            var result2 = sut.ExecuteNonQuery();


            Assert.Equal("Hello", result);
            Assert.Equal("UPDATE XXXX SET UserId = @userId", sut.CommandsList[1].CommandText);
            Assert.Equal(1, sut.CommandsList[1].Parameters[0].Value);
        }
Пример #4
0
        public void Validation_Invalid_parameter_value()
        {
            var args = new ParameterCollection(new FakeParameter("myName", "World correct"));
            var result = new ScalarCommandResult("SELECT 1 FROM Y WHERE Name = @myName", args) { Result = "Hello" };
            var sut = new FakeCommand(new[] { result });

            sut.CommandText = "SELECT 1 FROM Y WHERE Name = @myName";
            sut.AddParameter("myName", "World");
            Assert.Throws<CommandValidationException>(() => sut.ExecuteScalar());
        }
Пример #5
0
        public void Validation_Unmatched_Parameter()
        {
            var args = new ParameterCollection();
            var result = new ScalarCommandResult("SELECT 1 FROM Y WHERE Name = @myName", args) { Result = "Hello correct" };
            // you can also sue the Setup method instead of the constructor
            var sut = new FakeCommand(new[] { result });

            sut.CommandText = "SELECT 1 FROM Y WHERE Name = @myName";
            sut.AddParameter("myName", "World");
            Assert.Throws<CommandValidationException>(() => sut.ExecuteScalar());
        }
Пример #6
0
        public void Validation_Correct_WithParameter()
        {
            var args = new ParameterCollection(new FakeParameter("myName", "World"));
            var result = new ScalarCommandResult("SELECT 1 FROM Y WHERE Name = @myName", args) { Result = "Hello" };
            var sut = new FakeCommand(new[] { result});

            sut.CommandText = "SELECT 1 FROM Y WHERE Name = @myName";
            sut.AddParameter("myName", "World");
            var actual = sut.ExecuteScalar();

            Assert.Equal("Hello", actual);
        }
        public void Validation_Invalid_parameter_value()
        {
            var args   = new ParameterCollection(new FakeParameter("myName", "World correct"));
            var result = new ScalarCommandResult("SELECT 1 FROM Y WHERE Name = @myName", args)
            {
                Result = "Hello"
            };
            var sut = new FakeCommand(new[] { result });

            sut.CommandText = "SELECT 1 FROM Y WHERE Name = @myName";
            sut.AddParameter("myName", "World");
            Assert.Throws <CommandValidationException>(() => sut.ExecuteScalar());
        }
        public void Validation_Unmatched_Parameter()
        {
            var args   = new ParameterCollection();
            var result = new ScalarCommandResult("SELECT 1 FROM Y WHERE Name = @myName", args)
            {
                Result = "Hello correct"
            };
            // you can also sue the Setup method instead of the constructor
            var sut = new FakeCommand(new[] { result });

            sut.CommandText = "SELECT 1 FROM Y WHERE Name = @myName";
            sut.AddParameter("myName", "World");
            Assert.Throws <CommandValidationException>(() => sut.ExecuteScalar());
        }
        public void Validation_Correct_WithParameter()
        {
            var args   = new ParameterCollection(new FakeParameter("myName", "World"));
            var result = new ScalarCommandResult("SELECT 1 FROM Y WHERE Name = @myName", args)
            {
                Result = "Hello"
            };
            var sut = new FakeCommand(new[] { result });

            sut.CommandText = "SELECT 1 FROM Y WHERE Name = @myName";
            sut.AddParameter("myName", "World");
            var actual = sut.ExecuteScalar();

            Assert.Equal("Hello", actual);
        }
Пример #10
0
        public void ReturnTable()
        {
            var sut = new FakeCommand();
            sut.Setup(new ScalarCommandResult() { Result = "Hello" });
            sut.Setup(new NonQueryCommandResult() { Result = 0 });

            sut.CommandText = "SELECT 2";
            var result = sut.ExecuteScalar();

            sut.CommandText = "UPDATE XXXX SET UserId = @userId";
            sut.AddParameter("userId", 1);
            var result2 = sut.ExecuteNonQuery();


            Assert.Equal("Hello", result);
            Assert.Equal("UPDATE XXXX SET UserId = @userId", sut.CommandsList[1].CommandText);
            Assert.Equal(1, sut.CommandsList[1].Parameters[0].Value);
        }