本文整理汇总了C#中Tests.DataClasses.SampleWebAppDb.SaveChangesWithChecking方法的典型用法代码示例。如果您正苦于以下问题:C# SampleWebAppDb.SaveChangesWithChecking方法的具体用法?C# SampleWebAppDb.SaveChangesWithChecking怎么用?C# SampleWebAppDb.SaveChangesWithChecking使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tests.DataClasses.SampleWebAppDb
的用法示例。
在下文中一共展示了SampleWebAppDb.SaveChangesWithChecking方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Check01ValidateTagOk
public void Check01ValidateTagOk()
{
using (var db = new SampleWebAppDb())
{
//SETUP
var snap = new DbSnapShot(db);
//ATTEMPT
var dupTag = new Tag { Name = "non-duplicate slug", Slug = Guid.NewGuid().ToString("N") };
db.Tags.Add(dupTag);
var status = db.SaveChangesWithChecking();
//VERIFY
status.IsValid.ShouldEqual(true, status.Errors);
snap.CheckSnapShot(db, 0,0,0,1);
}
}
示例2: Check02ValidateTagError
public void Check02ValidateTagError()
{
using (var db = new SampleWebAppDb())
{
//SETUP
var existingTag = db.Tags.First();
//ATTEMPT
var dupTag = new Tag {Name = "duplicate slug", Slug = existingTag.Slug};
db.Tags.Add(dupTag);
var status = db.SaveChangesWithChecking();
//VERIFY
status.IsValid.ShouldEqual(false);
status.Errors.Count.ShouldEqual(1);
status.Errors[0].ErrorMessage.ShouldEqual("The Slug on tag 'duplicate slug' must be unique.");
}
}
示例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: Check22CheckUpdateLastUpdatedOk
public void Check22CheckUpdateLastUpdatedOk()
{
using (var db = new SampleWebAppDb())
{
//SETUP
var snap = new DbSnapShot(db);
var firstPost = db.Posts.First();
var originalDateTime = firstPost.LastUpdated;
Thread.Sleep(400);
//ATTEMPT
firstPost.Title = Guid.NewGuid().ToString();
var status = db.SaveChangesWithChecking();
//VERIFY
status.IsValid.ShouldEqual(true, status.Errors);
snap.CheckSnapShot(db);
Assert.GreaterOrEqual(db.Posts.First().LastUpdated.Subtract(originalDateTime).Milliseconds, 400);
}
}
示例5: Check21CheckUpdateSimpleOk
public void Check21CheckUpdateSimpleOk()
{
using (var db = new SampleWebAppDb())
{
//SETUP
var snap = new DbSnapShot(db);
var newGuid = Guid.NewGuid().ToString();
//ATTEMPT
var firstPost = db.Posts.First();
firstPost.Title = newGuid;
var status = db.SaveChangesWithChecking();
//VERIFY
status.IsValid.ShouldEqual(true, status.Errors);
snap.CheckSnapShot(db);
db.Posts.First().Title.ShouldEqual(newGuid);
}
}
示例6: Check20AddPostOk
public void Check20AddPostOk()
{
using (var db = new SampleWebAppDb())
{
//SETUP
var snap = new DbSnapShot(db);
//ATTEMPT
var uglyTag = db.Tags.Single(x => x.Slug == "ugly");
var jonBlogger = db.Blogs.First();
var newPost = new Post
{
Blogger = jonBlogger,
Content = "a few simple words.",
Title = "A new post",
Tags = new[] { uglyTag }
};
db.Posts.Add(newPost);
var status = db.SaveChangesWithChecking();
//VERIFY
status.IsValid.ShouldEqual(true, status.Errors);
snap.CheckSnapShot(db, 1, 1);
var uglyPosts = db.Tags.Include(x => x.Posts).Single(y => y.Slug == "ugly").Posts;
uglyPosts.Count.ShouldEqual(3);
}
}
示例7: 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.");
}
}
示例8: Check21ValidatePostContentTwoErrors
public void Check21ValidatePostContentTwoErrors()
{
using (var db = new SampleWebAppDb())
{
//SETUP
var existingTag = db.Tags.First();
var existingBlogger = db.Blogs.First();
//ATTEMPT
var newPost = new Post()
{
Blogger = existingBlogger,
Title = "Test post",
Content = "Should not end sentence with sheep. Nor end sentence with lamb.",
Tags = new[] { existingTag }
};
db.Posts.Add(newPost);
var status = db.SaveChangesWithChecking();
//VERIFY
status.IsValid.ShouldEqual(false);
status.Errors.Count.ShouldEqual(2);
status.Errors[0].ErrorMessage.ShouldEqual("Sorry. Not allowed to end a sentance with 'sheep'.");
status.Errors[1].ErrorMessage.ShouldEqual("Sorry. Not allowed to end a sentance with 'lamb'.");
}
}
示例9: Check28DeleteViaAttachOk
public void Check28DeleteViaAttachOk()
{
using (var db = new SampleWebAppDb())
{
//SETUP
var snap = new DbSnapShot(db);
var lastPost = db.Posts.Include(x => x.Tags).AsNoTracking().ToList().Last();
var numTags = lastPost.Tags.Count;
//ATTEMPT
var postToDelete = new Post {PostId = lastPost.PostId};
db.Posts.Attach(postToDelete);
db.Posts.Remove(postToDelete);
var status = db.SaveChangesWithChecking();
//VERIFY
status.IsValid.ShouldEqual(true, status.Errors);
snap.CheckSnapShot(db, -1, -numTags);
}
}
示例10: Test01ValidateTagCaughtByHandleDictError
public void Test01ValidateTagCaughtByHandleDictError()
{
//SETUP
GenericServicesConfig.AddToSqlHandlerDict(2601, TestExceptionCatch);
using (var db = new SampleWebAppDb())
{
var existingTag = db.Tags.First();
//ATTEMPT
var dupTag = new Tag { Name = "duplicate slug", Slug = existingTag.Slug };
db.Tags.Add(dupTag);
var status = db.SaveChangesWithChecking();
//VERIFY
status.IsValid.ShouldEqual(false);
status.Errors.Count.ShouldEqual(1);
status.Errors[0].ErrorMessage.ShouldEqual("SQL error 2601. Following class types had errors: Tag.");
}
}
示例11: Test10ValidateTagCaughtBySqlDict
public void Test10ValidateTagCaughtBySqlDict()
{
//SETUP
GenericServicesConfig.AddToSqlHandlerDict(2601, TestExceptionNoCatch);
using (var db = new SampleWebAppDb())
{
var existingTag = db.Tags.First();
//ATTEMPT
var dupTag = new Tag { Name = "duplicate slug", Slug = existingTag.Slug };
db.Tags.Add(dupTag);
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.");
}
}
示例12: Check02ValidateTagError
public void Check02ValidateTagError()
{
using (var db = new SampleWebAppDb())
{
//SETUP
var existingTag = db.Tags.First();
//ATTEMPT
var dupTag = new Tag { Name = "duplicate slug", Slug = existingTag.Slug };
db.Tags.Add(dupTag);
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.");
}
}
示例13: Check15ValidatePostTitleError
public void Check15ValidatePostTitleError()
{
using (var db = new SampleWebAppDb())
{
//SETUP
var existingTag = db.Tags.First();
var existingBlogger = db.Blogs.First();
//ATTEMPT
var newPost = new Post()
{
Blogger = existingBlogger,
Title = "Test post!",
Content = "Nothing special",
Tags = new[] { existingTag }
};
db.Posts.Add(newPost);
var status = db.SaveChangesWithChecking();
//VERIFY
status.IsValid.ShouldEqual(false);
status.Errors.Count.ShouldEqual(1);
status.Errors[0].ErrorMessage.ShouldEqual("Sorry, but you can't get too excited and include a ! in the title.");
}
}
示例14: Check10ValidatePostOk
public void Check10ValidatePostOk()
{
using (var db = new SampleWebAppDb())
{
//SETUP
var snap = new DbSnapShot(db);
var existingTag = db.Tags.First();
var existingBlogger = db.Blogs.First();
//ATTEMPT
var newPost = new Post()
{
Blogger = existingBlogger,
Title = "Test post",
Content = "Nothing special",
Tags = new[] { existingTag }
};
db.Posts.Add(newPost);
var status = db.SaveChangesWithChecking();
//VERIFY
status.IsValid.ShouldEqual(true, status.Errors);
snap.CheckSnapShot(db,1,1);
}
}
示例15: Check26ReplaceTagsOk
public void Check26ReplaceTagsOk()
{
using (var db = new SampleWebAppDb())
{
//SETUP
var snap = new DbSnapShot(db);
var firstPost = db.Posts.First();
var tagsNotInFirstPostTracked = db.Tags.Where(x => x.Posts.All(y => y.PostId != firstPost.PostId)).ToList();
//ATTEMPT
db.Entry(firstPost).Collection(x => x.Tags).Load();
firstPost.Tags = tagsNotInFirstPostTracked;
var status = db.SaveChangesWithChecking();
//VERIFY
status.IsValid.ShouldEqual(true, status.Errors);
snap.CheckSnapShot(db, 0, -1);
firstPost = db.Posts.Include(x => x.Tags).First();
firstPost.Tags.Count.ShouldEqual(1);
}
}