本文整理汇总了C#中Castle.ActiveRecord.Tests.Model.Blog类的典型用法代码示例。如果您正苦于以下问题:C# Blog类的具体用法?C# Blog怎么用?C# Blog使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Blog类属于Castle.ActiveRecord.Tests.Model命名空间,在下文中一共展示了Blog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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);
}
示例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 );
}
示例4: Post
public Post(Blog blog, String title, String contents, String category)
{
_blog = blog;
_title = title;
_contents = contents;
_category = category;
}
示例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();
}
示例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 );
}
}
示例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 );
}
示例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();
}
}
示例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);
}
示例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);
}
}
示例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 );
}
示例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;
}
}
示例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);
}
示例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);
}
示例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);
}
}