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

            sut.ExecuteOnTransaction("INSERT INTO TestTable VALUES(3, @Value)", new ParameterSet {
                new Parameter <int>("Value", 7)
            });
            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 = 3";
                connection.Open();
                var result = int.Parse(command.ExecuteScalar().ToString());

                Assert.That(result, Is.EqualTo(7));
            }
        }
示例#2
0
        public void ShouldExecuteProcedureOnTransaction()
        {
            var sut = new SqlServerConnection("Data Source=.;Initial Catalog=DbSessionTests;Integrated Security=True;");

            sut.ExecuteOnTransaction(
                "dbo.TestProc",
                new ParameterSet {
                new Parameter <int>("ParOne", 100), new Parameter <int>("ParTwo", 101)
            },
                CommandType.StoredProcedure);

            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 = 100";
                connection.Open();
                var result = int.Parse(command.ExecuteScalar().ToString());

                Assert.That(result, Is.EqualTo(101));
            }
        }