本文整理汇总了C#中Castle.ActiveRecord.Tests.Model.Blog类的典型用法代码示例。如果您正苦于以下问题:C# Blog类的具体用法?C# Blog怎么用?C# Blog使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Blog类属于Castle.ActiveRecord.Tests.Model命名空间,在下文中一共展示了Blog类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: SimpleOperations
public void SimpleOperations()
{
ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Post), typeof(Blog));
Recreate();
Post.DeleteAll();
Blog.DeleteAll();
Blog[] blogs = Blog.FindAll();
Assert.IsNotNull(blogs);
Assert.AreEqual(0, blogs.Length);
Blog blog = new Blog();
blog.Name = "hammett's blog";
blog.Author = "hamilton verissimo";
blog.Save();
blogs = Blog.FindAll();
Assert.IsNotNull(blogs);
Assert.AreEqual(1, blogs.Length);
Blog retrieved = blogs[0];
Assert.IsNotNull(retrieved);
Assert.AreEqual(blog.Name, retrieved.Name);
Assert.AreEqual(blog.Author, retrieved.Author);
}
开发者ID:ralescano,项目名称:castle,代码行数:28,代码来源:ActiveRecordTestCase.cs
示例2: RollbackVote
public void RollbackVote()
{
ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Post), typeof(Blog));
Recreate();
Post.DeleteAll();
Blog.DeleteAll();
using(TransactionScope transaction = new TransactionScope())
{
Blog blog = new Blog();
blog.Author = "hammett";
blog.Name = "some name";
blog.Save();
Post post = new Post(blog, "title", "post contents", "Castle");
post.Save();
// pretend something went wrong
transaction.VoteRollBack();
}
Blog[] blogs = Blog.FindAll();
Assert.AreEqual(0, blogs.Length);
Post[] posts = Post.FindAll();
Assert.AreEqual(0, posts.Length);
}
开发者ID:sheefa,项目名称:Castle.ActiveRecord,代码行数:29,代码来源:TransactionScopeTestCase.cs
示例3: MoreThanOneConnectionWithinTheSessionScope
public void MoreThanOneConnectionWithinTheSessionScope()
{
SqlConnection conn = CreateSqlConnection();
SqlConnection conn2 = CreateSqlConnection2();
using(new SessionScope())
{
foreach(SqlConnection connection in new SqlConnection[] { conn, conn2 })
{
connection.Open();
using(new DifferentDatabaseScope(connection))
{
Blog blog = new Blog();
blog.Name = "hammett's blog";
blog.Author = "hamilton verissimo";
blog.Create();
}
}
}
OtherDbBlog[] blogs2 = OtherDbBlog.FindAll();
Assert.IsNotNull( blogs2 );
Assert.AreEqual( 1, blogs2.Length );
Blog[] blogs = Blog.FindAll();
Assert.IsNotNull( blogs );
Assert.AreEqual( 1, blogs.Length );
}
开发者ID:zhoufoxcn,项目名称:ActiveRecord,代码行数:29,代码来源:DifferentDatabaseScopeTestCase.cs
示例4: Post
public Post(Blog blog, String title, String contents, String category)
{
_blog = blog;
_title = title;
_contents = contents;
_category = category;
}
开发者ID:zhoufoxcn,项目名称:ActiveRecord,代码行数:7,代码来源:Post.cs
示例5: Prepare
// overrides the setup in the base class
public void Prepare()
{
ActiveRecordStarter.ResetInitializationFlag();
ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Blog), typeof(Post));
ActiveRecordStarter.CreateSchema();
Post.DeleteAll();
Blog.DeleteAll();
Blog blog = new Blog();
blog.Name = "hammett's blog";
blog.Author = "hamilton verissimo";
blog.Save();
Post p;
p = new Post(blog, "a", "b", "c");
p.Save();
p = new Post(blog, "d", "e", "c");
p.Save();
p = new Post(blog, "f", "g", "h");
p.Save();
}
开发者ID:sheefa,项目名称:Castle.ActiveRecord,代码行数:28,代码来源:CountQueryTestCase.cs
示例6: MoreThanOneConnectionWithinTheSessionScope
public void MoreThanOneConnectionWithinTheSessionScope()
{
using(var conn = CreateSqlConnection())
using(var conn2 = CreateSqlConnection2())
using(new SessionScope())
{
foreach(var connection in new [] { conn, conn2 })
{
connection.Open();
using(new DifferentDatabaseScope(connection))
{
var blog = new Blog {Name = "hammett's blog", Author = "hamilton verissimo"};
blog.Create();
}
}
}
using (new SessionScope()) {
var blogs2 = OtherDbBlog.FindAll().ToArray();
Assert.IsNotNull( blogs2 );
Assert.AreEqual( 1, blogs2.Length );
var blogs = Blog.FindAll().ToArray();
Assert.IsNotNull( blogs );
Assert.AreEqual( 1, blogs.Length );
}
}
开发者ID:shosca,项目名称:ActiveRecord,代码行数:28,代码来源:DifferentDatabaseScopeTestCase.cs
示例7: SimpleCase
public void SimpleCase()
{
Blog blog = new Blog();
blog.Name = "hammett's blog";
blog.Author = "hamilton verissimo";
blog.Save();
SqlConnection conn = CreateSqlConnection();
using(conn)
{
conn.Open();
using(new DifferentDatabaseScope(conn))
{
blog.Create();
}
}
Blog[] blogs = Blog.FindAll();
Assert.IsNotNull( blogs );
Assert.AreEqual( 1, blogs.Length );
OtherDbBlog[] blogs2 = OtherDbBlog.FindAll();
Assert.IsNotNull( blogs2 );
Assert.AreEqual( 1, blogs2.Length );
}
开发者ID:ralescano,项目名称:castle,代码行数:27,代码来源:DifferentDatabaseScopeTestCase.cs
示例8: FillData
public void FillData()
{
ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Blog),typeof(Post));
Recreate();
for (int i = 1; i <= 10; i++)
{
var blog = new Blog(i) { Name = "n" + i };
blog.Create();
}
}
开发者ID:zhoufoxcn,项目名称:ActiveRecord,代码行数:11,代码来源:ActiveRecordDetachedQueryTestCase.cs
示例9: JoinedTable
public void JoinedTable()
{
ActiveRecordStarter.Initialize(GetConfigSource(),
typeof(Post),
typeof(Blog),
typeof(Company),
typeof(Person));
Recreate();
Post.DeleteAll();
Blog.DeleteAll();
Company.DeleteAll();
Person.DeleteAll();
Blog blog = new Blog();
blog.Name = "Ronalodo's blog";
blog.Author = "Christiano Ronalodo";
blog.Save();
Person person = new Person();
person.Name = "Ronaldo";
person.FullName = new FullName();
person.FullName.First = "Christiano";
person.FullName.Last = "Ronaldo";
person.Address = "123 Nutmeg";
person.City = "Lisbon";
person.Blog = blog;
person.Save();
Person[] people = Person.FindAll();
Assert.AreEqual( 1, people.Length );
Person personLoaded = people[0];
Assert.AreEqual(person.Name, personLoaded.Name);
Assert.AreEqual(person.FullName.First, personLoaded.FullName.First);
Assert.AreEqual(person.FullName.Last, personLoaded.FullName.Last);
Assert.AreEqual(person.Address, personLoaded.Address);
Assert.AreEqual(person.City, personLoaded.City);
Assert.AreEqual(blog.Id, personLoaded.Blog.Id);
Assert.AreEqual(blog.Name, personLoaded.Blog.Name);
personLoaded.FullName.Middle = "Goal";
personLoaded.Address = "200 Hatrick";
personLoaded.Update();
people = Person.FindAll();
Assert.AreEqual(1, people.Length);
Person personUpdated = people[0];
Assert.AreEqual(personLoaded.FullName.Middle, personUpdated.FullName.Middle);
Assert.AreEqual(personLoaded.Address, personUpdated.Address);
}
开发者ID:ralescano,项目名称:castle,代码行数:54,代码来源:JoinedTableTestCase.cs
示例10: AnExceptionInvalidatesTheScopeAndPreventItsFlushing
public void AnExceptionInvalidatesTheScopeAndPreventItsFlushing()
{
ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Post), typeof(Blog));
Recreate();
Post.DeleteAll();
Blog.DeleteAll();
Blog blog;
Post post;
// Prepare
using(new SessionScope())
{
blog = new Blog();
blog.Author = "hammett";
blog.Name = "some name";
blog.Save();
post = new Post(blog, "title", "contents", "castle");
post.Save();
}
using(SessionScope session = new SessionScope())
{
Assert.IsFalse(session.HasSessionError);
try
{
// Forcing an exception
post = new Post(new Blog(100), "title", "contents", "castle");
post.SaveAndFlush();
Assert.Fail("Expecting exception as this operation violates a FK constraint");
}
catch(ActiveRecordException)
{
// Exception expected
}
Assert.IsTrue(session.HasSessionError);
}
}
开发者ID:zhoufoxcn,项目名称:ActiveRecord,代码行数:42,代码来源:SessionScopeTestCase.cs
示例11: UsingSessionScope
public void UsingSessionScope()
{
ISession session1, session2;
using(new SessionScope())
{
Blog blog = new Blog();
blog.Name = "hammett's blog";
blog.Author = "hamilton verissimo";
blog.Save();
session1 = blog.CurrentSession;
Assert.IsNotNull(session1);
SqlConnection conn = CreateSqlConnection();
using(conn)
{
conn.Open();
using(new DifferentDatabaseScope(conn))
{
blog.Create();
session2 = blog.CurrentSession;
Assert.IsNotNull(session2);
Assert.IsFalse( Object.ReferenceEquals(session1, session2) );
}
}
}
Blog[] blogs = Blog.FindAll();
Assert.IsNotNull( blogs );
Assert.AreEqual( 1, blogs.Length );
OtherDbBlog[] blogs2 = OtherDbBlog.FindAll();
Assert.IsNotNull( blogs2 );
Assert.AreEqual( 1, blogs2.Length );
}
开发者ID:ralescano,项目名称:castle,代码行数:40,代码来源:DifferentDatabaseScopeTestCase.cs
示例12: TestBehaviour
private void TestBehaviour(DefaultFlushType flushType, FlushMode sessionScopeMode, FlushMode transactionScopeMode)
{
ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Post), typeof(Blog));
Recreate();
Post.DeleteAll();
Blog.DeleteAll();
DefaultFlushType originalDefaultFlushType = ActiveRecordStarter.ConfigurationSource.DefaultFlushType;
try
{
((InPlaceConfigurationSource)ActiveRecordStarter.ConfigurationSource).DefaultFlushType = flushType;
Blog blog = new Blog(); // just for CurrentSession
using (new SessionScope())
{
Blog.FindAll();
Assert.AreEqual(sessionScopeMode, blog.CurrentSession.FlushMode);
using (new TransactionScope())
{
Blog.FindAll();
Assert.AreEqual(transactionScopeMode, blog.CurrentSession.FlushMode);
}
// Properly reset?
Blog.FindAll();
Assert.AreEqual(sessionScopeMode, blog.CurrentSession.FlushMode);
}
}
finally
{
// Restore Default Flush type we corrupted before.
((InPlaceConfigurationSource)ActiveRecordStarter.ConfigurationSource).DefaultFlushType = originalDefaultFlushType;
}
}
开发者ID:zhoufoxcn,项目名称:ActiveRecord,代码行数:37,代码来源:ScopeDefaultFlushingBehaviourTestCase.cs
示例13: SimpleOperations2
public void SimpleOperations2()
{
ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Post), typeof(Blog));
Recreate();
Post.DeleteAll();
Blog.DeleteAll();
Blog[] blogs = Blog.FindAll();
Assert.IsNotNull(blogs);
Assert.AreEqual(0, blogs.Length);
Blog blog = new Blog();
blog.Name = "hammett's blog";
blog.Author = "hamilton verissimo";
blog.Create();
blogs = Blog.FindAll();
Assert.AreEqual(blog.Name, blogs[0].Name);
Assert.AreEqual(blog.Author, blogs[0].Author);
Assert.IsNotNull(blogs);
Assert.AreEqual(1, blogs.Length);
blog.Name = "something else1";
blog.Author = "something else2";
blog.Update();
blogs = Blog.FindAll();
Assert.IsNotNull(blogs);
Assert.AreEqual(1, blogs.Length);
Assert.AreEqual(blog.Name, blogs[0].Name);
Assert.AreEqual(blog.Author, blogs[0].Author);
}
开发者ID:ralescano,项目名称:castle,代码行数:36,代码来源:ActiveRecordTestCase.cs
示例14: DifferentSessionScopesUseDifferentCaches
public void DifferentSessionScopesUseDifferentCaches()
{
ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Post), typeof(Blog));
Recreate();
Post.DeleteAll();
Blog.DeleteAll();
int blogId = 0;
using (new SessionScope())
{
Blog blog = new Blog();
blog.Author = "MZY";
blog.Name = "FooBar";
blog.Save(); // Flushes due to IDENTITY
blogId = blog.Id;
}
using (new SessionScope())
{
Blog blog = Blog.Find(blogId);
blog.Name = "FooBarBaz";
//Assert.AreEqual(FlushMode.Auto, blog.CurrentSession.FlushMode);
//Assert.IsTrue(blog.CurrentSession.Transaction.IsActive);
Assert.AreEqual(DefaultFlushType.Classic, ActiveRecordStarter.ConfigurationSource.DefaultFlushType);
// Flushes automatically
Assert.AreEqual(1, Blog.FindByProperty("Name", "FooBarBaz").Length);
}
using (new SessionScope())
{
Blog blog = Blog.Find(blogId);
blog.Name = "FooBar";
using (new SessionScope())
{
// Not flushed here
Assert.AreEqual(0, Blog.FindByProperty("Name", "FooBar").Length);
}
}
// Here it is flushed
Assert.AreEqual(1, Blog.FindByProperty("Name", "FooBar").Length);
}
开发者ID:sheefa,项目名称:Castle.ActiveRecord,代码行数:46,代码来源:SessionScopeTestCase.cs
示例15: SessionScopeFlushModeNever
public void SessionScopeFlushModeNever()
{
ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Post), typeof(Blog));
Recreate();
Post.DeleteAll();
Blog.DeleteAll();
using(new SessionScope(FlushAction.Never))
{
Blog blog = new Blog();
blog.Author = "hammett";
blog.Name = "some name";
//This gets flushed automatically because of the identity field
blog.Save();
Blog[] blogs = Blog.FindAll();
Assert.AreEqual(1, blogs.Length);
//This change won't be saved to the db
blog.Author = "A New Author";
blog.Save();
//The change should not be in the db
blogs = Blog.FindByProperty("Author", "A New Author");
Assert.AreEqual(0, blogs.Length);
SessionScope.Current.Flush();
//The change should now be in the db
blogs = Blog.FindByProperty("Author", "A New Author");
Assert.AreEqual(1, blogs.Length);
//This change will be save to the db because it uses the SaveNow method
blog.Name = "A New Name";
blog.SaveAndFlush();
//The change should now be in the db
blogs = Blog.FindByProperty("Name", "A New Name");
Assert.AreEqual(1, blogs.Length);
//This deletion should not get to the db
blog.Delete();
blogs = Blog.FindAll();
Assert.AreEqual(1, blogs.Length);
SessionScope.Current.Flush();
//The deletion should now be in the db
blogs = Blog.FindAll();
Assert.AreEqual(0, blogs.Length);
}
}
开发者ID:sheefa,项目名称:Castle.ActiveRecord,代码行数:55,代码来源:SessionScopeTestCase.cs
示例16: NestedSessionScopeUsage
public void NestedSessionScopeUsage()
{
ActiveRecordStarter.Initialize( GetConfigSource(), typeof(Post), typeof(Blog) );
Recreate();
Post.DeleteAll();
Blog.DeleteAll();
using(new SessionScope())
{
Blog blog = new Blog();
using(new SessionScope())
{
blog.Author = "hammett";
blog.Name = "some name";
blog.Save();
}
using(new SessionScope())
{
Post post = new Post(blog, "title", "post contents", "Castle");
post.Save();
}
}
Blog[] blogs = Blog.FindAll();
Assert.AreEqual( 1, blogs.Length );
Post[] posts = Post.FindAll();
Assert.AreEqual( 1, posts.Length );
}
开发者ID:sheefa,项目名称:Castle.ActiveRecord,代码行数:32,代码来源:SessionScopeTestCase.cs
示例17: ExistsByCriterion
public void ExistsByCriterion()
{
ActiveRecordStarter.Initialize(GetConfigSource());
ActiveRecordStarter.RegisterTypes(typeof(Blog), typeof(Post));
Recreate();
Blog[] blogs = Blog.FindAll();
Assert.IsNotNull(blogs);
Assert.AreEqual(0, blogs.Length);
Blog blog = new Blog();
blog.Name = "hammett's blog";
blog.Author = "hamilton verissimo";
blog.Save();
Assert.IsTrue(blog.Id > 0);
Assert.IsTrue(Blog.Exists(
Expression.Eq("Name", blog.Name),
Expression.Eq("Author", blog.Author)));
blog = new Blog();
blog.Name = "chad's blog";
blog.Author = "chad humphries";
blog.Save();
Assert.IsTrue(Blog.Exists(
Expression.Eq("Name", blog.Name),
Expression.Eq("Author", blog.Author)));
Assert.IsFalse(Blog.Exists(
Expression.Eq("Name", "/\ndrew's Blog"),
Expression.Eq("Author", "Andrew Peters")));
}
开发者ID:ralescano,项目名称:castle,代码行数:34,代码来源:ActiveRecordTestCase.cs
示例18: NestedTransactionWithRollbackOnDispose
public void NestedTransactionWithRollbackOnDispose()
{
ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Post), typeof(Blog));
Recreate();
Post.DeleteAll();
Blog.DeleteAll();
using(new TransactionScope())
{
Blog blog = new Blog();
using(TransactionScope t1 = new TransactionScope(TransactionMode.Inherits, OnDispose.Rollback))
{
blog.Author = "hammett";
blog.Name = "some name";
blog.Save();
t1.VoteCommit();
}
using(TransactionScope t2 = new TransactionScope(TransactionMode.Inherits, OnDispose.Rollback))
{
Post post = new Post(blog, "title", "post contents", "Castle");
try
{
post.SaveWithException();
t2.VoteCommit(); // Will never be called
}
catch(Exception)
{
// t2.VoteRollBack();
}
}
}
Blog[] blogs = Blog.FindAll();
Assert.AreEqual(0, blogs.Length);
Post[] posts = Post.FindAll();
Assert.AreEqual(0, posts.Length);
}
开发者ID:sheefa,项目名称:Castle.ActiveRecord,代码行数:44,代码来源:TransactionScopeTestCase.cs
示例19: ExistsTest
public void ExistsTest()
{
ActiveRecordStarter.Initialize(GetConfigSource());
ActiveRecordStarter.RegisterTypes(typeof(Blog), typeof(Post));
Recreate();
Blog blog = new Blog();
blog.Name = "hammett's blog";
blog.Author = "hamilton verissimo";
blog.Save();
Assert.IsTrue(blog.Id > 0);
Assert.IsTrue(Blog.Exists(blog.Id));
blog = new Blog();
blog.Name = "chad's blog";
blog.Author = "chad humphries";
blog.Save();
Assert.IsTrue(Blog.Exists(blog.Id));
Assert.IsFalse(Blog.Exists(1000));
}
开发者ID:ralescano,项目名称:castle,代码行数:23,代码来源:ActiveRecordTestCase.cs
示例20: FetchCount
public void FetchCount()
{
ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Post), typeof(Blog));
Recreate();
Post.DeleteAll();
Blog.DeleteAll();
Assert.AreEqual(0, Post.FetchCount());
Assert.AreEqual(0, Blog.FetchCount());
Blog[] blogs = Blog.FindAll();
Assert.IsNotNull(blogs);
Assert.AreEqual(0, blogs.Length);
Assert.IsFalse(Blog.Exists());
Blog blog = new Blog();
blog.Name = "hammett's blog";
blog.Author = "hamilton verissimo";
blog.Save();
Assert.AreEqual(1, Blog.FetchCount());
Assert.IsTrue(Blog.Exists());
blogs = Blog.FindAll();
Assert.IsNotNull(blogs);
Assert.AreEqual(1, blogs.Length);
Blog blog2 = new Blog();
blog2.Name = "joe's blog";
blog2.Author = "joe doe";
blog2.Save();
Assert.AreEqual(2, Blog.FetchCount());
Assert.AreEqual(1, Blog.FetchCount("name=?", "hammett's blog"));
Assert.IsTrue(Blog.Exists("name=?", "hammett's blog"));
Blog retrieved = blogs[0];
Assert.IsNotNull(retrieved);
Assert.AreEqual(blog.Name, retrieved.Name);
Assert.AreEqual(blog.Author, retrieved.Author);
Assert.AreEqual(1, Blog.FetchCount(
Expression.Eq("Name", blog.Name),
Expression.Eq("Author", blog.Author)));
Assert.AreEqual(0, Blog.FetchCount(
Expression.Eq("Name", "/\ndrew's Blog"),
Expression.Eq("Author", "Andrew Peters")));
}
开发者ID:ralescano,项目名称:castle,代码行数:52,代码来源:ActiveRecordTestCase.cs
注:本文中的Castle.ActiveRecord.Tests.Model.Blog类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论