Mercurial > pub > bltoolkit
view UnitTests/CS/Data/OutputParameter.cs @ 9:1e85f66cf767 default tip
update bltoolkit
author | nickolay |
---|---|
date | Thu, 05 Apr 2018 20:53:26 +0300 |
parents | f990fcb411a9 |
children |
line wrap: on
line source
using System; using System.Data; using BLToolkit.Data; using BLToolkit.Data.DataProvider; using BLToolkit.DataAccess; using NUnit.Framework; namespace Data { [TestFixture] public class OutputParameter { [Test] public void DirectTest() { using (DbManager db = new DbManager()) { string paramName = (string) db.DataProvider.Convert("name", ConvertType.NameToQueryParameter); string fieldName = (string) db.DataProvider.Convert("FirstName", ConvertType.NameToQueryField); db.SetCommand(string.Format("SELECT {0} = {1} FROM Person WHERE PersonID = 1", paramName, fieldName) , db.OutputParameter(paramName, DbType.String, 50)) .ExecuteNonQuery(); Assert.AreEqual("John", db.Parameter(paramName).Value); } } public abstract class TestAccessor : DataAccessor { [SqlQuery("SELECT {0} = {1} FROM Person WHERE PersonID = 1")] public abstract void SelectJohn([ParamSize(50), ParamDbType(DbType.String)] out string name, [Format] string paramName, [Format] string FieldName); } [Test] public void AccessorTest() { using (DbManager db = new DbManager()) { string paramName = (string)db.DataProvider.Convert("name", ConvertType.NameToQueryParameter); string fieldName = (string)db.DataProvider.Convert("FirstName", ConvertType.NameToQueryField); TestAccessor ta = (TestAccessor)TestAccessor.CreateInstance(typeof(TestAccessor), db); string actual; ta.SelectJohn(out actual, paramName, fieldName); Assert.AreEqual("John", actual); } } } }