本文整理汇总了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.");
}
}