本文整理匯總了C#中Tests.DataClasses.SampleWebAppDb.SaveChanges方法的典型用法代碼示例。如果您正苦於以下問題:C# SampleWebAppDb.SaveChanges方法的具體用法?C# SampleWebAppDb.SaveChanges怎麽用?C# SampleWebAppDb.SaveChanges使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Tests.DataClasses.SampleWebAppDb
的用法示例。
在下文中一共展示了SampleWebAppDb.SaveChanges方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ResetDatabaseToTestData
public static void ResetDatabaseToTestData(SampleWebAppDb context, string filepathOfXmlFile)
{
context.Posts.RemoveRange( context.Posts);
context.Tags.RemoveRange( context.Tags);
context.Blogs.RemoveRange( context.Blogs);
context.PostTagGrades.RemoveRange(context.PostTagGrades);
context.PostLinks.RemoveRange(context.PostLinks);
context.SaveChanges();
var loader = new LoadDbDataFromXml(filepathOfXmlFile);
context.Blogs.AddRange(loader.Bloggers); //note: The order things appear in the database are not obvious
//have to add these by hand
context.PostTagGrades.AddRange(loader.PostTagGrades);
context.SaveChanges();
}
示例2: SetUp
public void SetUp()
{
using (var db = new SampleWebAppDb())
{
DataLayerInitialise.InitialiseThis();
var filepath = TestFileHelpers.GetTestFileFilePath("DbContentSimple.xml");
DataLayerInitialise.ResetDatabaseToTestData(db, filepath);
db.SaveChanges();
}
}
示例3: Check01DeleteFailBecauseOfForeignKeyBad
public void Check01DeleteFailBecauseOfForeignKeyBad()
{
using (var db = new SampleWebAppDb())
{
//SETUP
var post = db.Posts.First();
db.PostLinks.Add(new PostLink {PostPart = post});
db.SaveChanges();
}
using (var db = new SampleWebAppDb())
{
//ATTEMPT
db.Posts.Remove(db.Posts.First());
var status = db.SaveChangesWithChecking();
//VERIFY
status.IsValid.ShouldEqual(false);
status.Errors.Count.ShouldEqual(1);
status.Errors[0].ErrorMessage.ShouldEqual("This operation failed because another data entry uses this entry.");
}
}
示例4: Check02UniqueKeyErrorBad
public void Check02UniqueKeyErrorBad()
{
//NOTE: To test this I needed to comment out the ValidateEntity method in SampleWebAppDb
var tagGuid = Guid.NewGuid().ToString("N");
using (var db = new SampleWebAppDb())
{
//SETUP
db.Tags.Add(new Tag { Name = tagGuid, Slug = tagGuid});
db.SaveChanges();
}
using (var db = new SampleWebAppDb())
{
//ATTEMPT
db.Tags.Add(new Tag { Name = tagGuid, Slug = tagGuid });
var status = db.SaveChangesWithChecking();
//VERIFY
status.IsValid.ShouldEqual(false);
status.Errors.Count.ShouldEqual(1);
status.Errors[0].ErrorMessage.ShouldEqual("One of the properties is marked as Unique index and there is already an entry with that value.");
}
}
示例5: Check05CauseBothErrorsBad
public void Check05CauseBothErrorsBad()
{
//NOTE: To test this I needed to comment out the ValidateEntity method in SampleWebAppDb
var tagGuid = Guid.NewGuid().ToString("N");
using (var db = new SampleWebAppDb())
{
//SETUP
var post = db.Posts.First();
db.PostLinks.Add(new PostLink { PostPart = post });
db.Tags.Add(new Tag { Name = tagGuid, Slug = tagGuid });
db.SaveChanges();
}
using (var db = new SampleWebAppDb())
{
//ATTEMPT
db.Posts.Remove(db.Posts.First());
db.Tags.Add(new Tag { Name = tagGuid, Slug = tagGuid });
var status = db.SaveChangesWithChecking();
//VERIFY
status.IsValid.ShouldEqual(false);
status.Errors.Count.ShouldEqual(1); //for these two cases we only get one error
status.Errors[0].ErrorMessage.ShouldEqual("One of the properties is marked as Unique index and there is already an entry with that value.");
}
}