Mercurial > pub > bltoolkit
diff UnitTests/CS/DataAccess/CreateEntityTest.cs @ 0:f990fcb411a9
Копия текущей версии из github
author | cin |
---|---|
date | Thu, 27 Mar 2014 21:46:09 +0400 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UnitTests/CS/DataAccess/CreateEntityTest.cs Thu Mar 27 21:46:09 2014 +0400 @@ -0,0 +1,59 @@ +using System; + +using NUnit.Framework; + +using BLToolkit.Reflection; +using BLToolkit.DataAccess; +using BLToolkit.Data; +using BLToolkit.TypeBuilder; + +namespace DataAccess +{ + [TestFixture] + public class CreateEntityTest + { + public abstract class Entity + { + public abstract int Id { get; set; } + public abstract String Name { get; set; } + + public static Entity CreateInstance() { return TypeAccessor<Entity>.CreateInstanceEx(); } + } + + public abstract class EntityAccessor : DataAccessor<Entity> + { +#if SQLITE || SQLCE + [SqlQuery("SELECT * FROM Person")] +#else + [SprocName("Person_SelectAll")] +#endif + public abstract int Insert(Entity entity); + + public static EntityAccessor CreateInstance(DbManager dbManager) + { + return DataAccessor.CreateInstance<EntityAccessor>(dbManager); + } + } + + [Test] + public void Test() + { + TypeFactory.SetGlobalAssembly("CreateEntityTest.dll"); + + DbManager db = new DbManager(); + + try + { + Entity entity = Entity.CreateInstance(); + EntityAccessor accessor = EntityAccessor.CreateInstance(db); + + accessor.Insert(entity); + } + finally + { + db.Dispose(); + TypeFactory.SaveGlobalAssembly(); + } + } + } +}