示例#1
0
        public void ShouldExecuteOnTransactionForMultipleSets()
        {
            var sut = new SqlServerConnection("Data Source=.;Initial Catalog=DbSessionTests;Integrated Security=True;");

            sut.ExecuteBatchOnTransaction("INSERT INTO TestTable VALUES(@Id, @Value)", new []
            {
                new ParameterSet {
                    new Parameter <int>("Id", 77), new Parameter <int>("Value", 77)
                },
                new ParameterSet {
                    new Parameter <int>("Id", 78), new Parameter <int>("Value", 78)
                }
            });
            sut.Commit();

            using (var connection = new SqlConnection("Data Source=.;Initial Catalog=DbSessionTests;Integrated Security=True;"))
            {
                var command = connection.CreateCommand();
                command.CommandText = "SELECT TestValue FROM TestTable WHERE Id = 77";
                connection.Open();
                var result = int.Parse(command.ExecuteScalar().ToString());

                Assert.That(result, Is.EqualTo(77));

                command.CommandText = "SELECT TestValue FROM TestTable WHERE Id = 78";
                result = int.Parse(command.ExecuteScalar().ToString());
                Assert.That(result, Is.EqualTo(78));
            }
        }