public async void Check11CreatePostOk() { using (var db = new SampleWebAppDb()) { //SETUP var snap = new DbSnapShot(db); var service = new CreateServiceAsync <Post, DetailPostDtoAsync>(db); var setupService = new CreateSetupServiceAsync <Post, DetailPostDtoAsync>(db); //ATTEMPT var dto = await setupService.GetDtoAsync(); dto.Title = Guid.NewGuid().ToString(); dto.Content = "something to fill it as can't be empty"; dto.Bloggers.SelectedValue = db.Blogs.First().BlogId.ToString("D"); dto.UserChosenTags.FinalSelection = db.Tags.OrderBy(x => x.TagId).Take(2).ToList().Select(x => x.TagId.ToString("D")).ToArray(); var status = await service.CreateAsync(dto); //VERIFY status.IsValid.ShouldEqual(true, status.Errors); snap.CheckSnapShot(db, 1, 2); var post = db.Posts.Include(x => x.Tags).OrderByDescending(x => x.PostId).First(); post.Title.ShouldEqual(dto.Title); post.BlogId.ShouldEqual(db.Blogs.First().BlogId); CollectionAssert.AreEqual(db.Tags.OrderBy(x => x.TagId).Take(2).Select(x => x.TagId), post.Tags.Select(x => x.TagId)); } }
public async void Check22UpdatePostAddTagOk() { using (var db = new SampleWebAppDb()) { //SETUP var snap = new DbSnapShot(db); var setupService = new UpdateSetupServiceAsync <Post, DetailPostDtoAsync>(db); var updateService = new UpdateServiceAsync <Post, DetailPostDtoAsync>(db); var firstPost = db.Posts.First(); //ATTEMPT var setupStatus = await setupService.GetOriginalAsync(firstPost.PostId); setupStatus.IsValid.ShouldEqual(true, setupStatus.Errors); setupStatus.Result.Title = Guid.NewGuid().ToString(); setupStatus.Result.Bloggers.SelectedValue = db.Blogs.First().BlogId.ToString("D"); setupStatus.Result.UserChosenTags.FinalSelection = db.Tags.Take(3).ToList().Select(x => x.TagId.ToString("D")).ToArray(); var status = await updateService.UpdateAsync(setupStatus.Result); //VERIFY status.IsValid.ShouldEqual(true, status.Errors); snap.CheckSnapShot(db, 0, 1); var post = db.Posts.Include(x => x.Tags).Single(x => x.PostId == firstPost.PostId); post.Title.ShouldEqual(setupStatus.Result.Title); post.BlogId.ShouldEqual(db.Blogs.First().BlogId); CollectionAssert.AreEquivalent(db.Tags.Take(3).Select(x => x.TagId), post.Tags.Select(x => x.TagId)); } }
public void Check06UpdateWithKeyPropertiesInWrongOrderOk() { using (var db = new SampleWebAppDb()) { //SETUP var snap = new DbSnapShot(db); var firstGrade = db.PostTagGrades.Include(x => x.TagPart).Include(x => x.PostPart).First(); var service = new UpdateService <PostTagGrade, SimpleTagPostGradeDto>(db); var setupService = new UpdateSetupService <PostTagGrade, SimpleTagPostGradeDto>(db); //ATTEMPT var setupStatus = setupService.GetOriginal(firstGrade.PostId, firstGrade.TagId); setupStatus.IsValid.ShouldEqual(true, setupStatus.Errors); setupStatus.Result.Grade = 999; var status = service.Update(setupStatus.Result); setupStatus.Result.LogSpecificName("End"); //VERIFY status.IsValid.ShouldEqual(true, status.Errors); status.SuccessMessage.ShouldEqual("Successfully updated PostTagGrade."); snap.CheckSnapShot(db); var updatedfirstGrade = db.PostTagGrades.First(); updatedfirstGrade.Grade.ShouldEqual(999); } }
public async void Check06UpdateWithListDtoOk() { using (var db = new SampleWebAppDb()) { //SETUP var snap = new DbSnapShot(db); var firstPost = db.Posts.Include(x => x.Tags).AsNoTracking().First(); var service = new UpdateServiceAsync <Post, SimplePostDtoAsync>(db); var setupService = new UpdateSetupServiceAsync <Post, SimplePostDtoAsync>(db); //ATTEMPT var setupStatus = await setupService.GetOriginalAsync(firstPost.PostId); setupStatus.IsValid.ShouldEqual(true, setupStatus.Errors); setupStatus.Result.Title = Guid.NewGuid().ToString(); var status = await service.UpdateAsync(setupStatus.Result); setupStatus.Result.LogSpecificName("End"); //VERIFY status.IsValid.ShouldEqual(true, status.Errors); status.SuccessMessage.ShouldEqual("Successfully updated Post."); snap.CheckSnapShot(db); } }
public void Check07UpdateWithListDtoCheckDateOk() { using (var db = new SampleWebAppDb()) { //SETUP var snap = new DbSnapShot(db); var firstPost = db.Posts.Include(x => x.Tags).AsNoTracking().First(); var originalDateTime = firstPost.LastUpdated; Thread.Sleep(400); var service = new UpdateService <Post, SimplePostDto>(db); var setupService = new UpdateSetupService <Post, SimplePostDto>(db); //ATTEMPT var setupStatus = setupService.GetOriginal(firstPost.PostId); setupStatus.Result.Title = Guid.NewGuid().ToString(); var status = service.Update(setupStatus.Result); setupStatus.Result.LogSpecificName("End"); //VERIFY status.IsValid.ShouldEqual(true, status.Errors); status.SuccessMessage.ShouldEqual("Successfully updated Post."); snap.CheckSnapShot(db); Assert.GreaterOrEqual(db.Posts.First().LastUpdated.Subtract(originalDateTime).Milliseconds, 400); } }
public async void Check07UpdateDirectPostCorrectOk() { using (var db = new SampleWebAppDb()) { //SETUP var snap = new DbSnapShot(db); var firstPostUntrackedNoIncludes = db.Posts.AsNoTracking().First(); var firstPostUntrackedWithIncludes = db.Posts.AsNoTracking().Include(x => x.Tags).First(); var service = new UpdateServiceAsync <Post>(db); //ATTEMPT firstPostUntrackedNoIncludes.Title = Guid.NewGuid().ToString(); var status = await service.UpdateAsync(firstPostUntrackedNoIncludes); //VERIFY status.IsValid.ShouldEqual(true, status.Errors); snap.CheckSnapShot(db); var updatedPost = db.Posts.Include(x => x.Tags).First(); updatedPost.Title.ShouldEqual(firstPostUntrackedNoIncludes.Title); updatedPost.Content.ShouldEqual(firstPostUntrackedWithIncludes.Content); updatedPost.Blogger.ShouldNotEqualNull(); updatedPost.Blogger.Name.ShouldEqual(firstPostUntrackedWithIncludes.Blogger.Name); CollectionAssert.AreEqual(firstPostUntrackedWithIncludes.Tags.Select(x => x.TagId), updatedPost.Tags.Select(x => x.TagId)); } }
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); } }
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); } }
public void Check02FillComputedNPostOk() { using (var db = new SampleWebAppDb()) { //SETUP const int numToCreate = 20; var snap = new DbSnapShot(); //empty //ATTEMPT db.FillComputedNPost(numToCreate); //VERIFY snap.CheckSnapShot(db, numToCreate, numToCreate, 2, 2); (db.Posts.Max(x => x.PostId) - db.Posts.Min(x => x.PostId)).ShouldEqual(numToCreate - 1); //check numbers are consecutive } }
public void Check01PostTagGradeDeleteOk() { using (var db = new SampleWebAppDb()) { //SETUP var snap = new DbSnapShot(db); var service = new DeleteService(db); var firstPtgUntracked = db.PostTagGrades.AsNoTracking().First(); //ATTEMPT var status = service.Delete <PostTagGrade>(firstPtgUntracked.PostId, firstPtgUntracked.TagId); //VERIFY status.IsValid.ShouldEqual(true, status.Errors); snap.CheckSnapShot(db, 0, 0, 0, 0, -1); } }
public void Check10DeleteDirectOk() { using (var db = new SampleWebAppDb()) { //SETUP var snap = new DbSnapShot(db); var firstPostUntracked = db.Posts.AsNoTracking().First(); var service = new DeleteService(db); //ATTEMPT var status = service.Delete <Post>(firstPostUntracked.PostId); //VERIFY status.IsValid.ShouldEqual(true, status.Errors); status.SuccessMessage.ShouldEqual("Successfully deleted Post."); snap.CheckSnapShot(db, -1, -2, 0, 0, -2); } }
public async void Check11DeleteWithRelationshipsDirectOk() { using (var db = new SampleWebAppDb()) { //SETUP var snap = new DbSnapShot(db); var firstPostUntracked = db.Posts.AsNoTracking().First(); var service = new DeleteServiceAsync(db); //ATTEMPT var status = await service.DeleteWithRelationshipsAsync <Post>(DeleteBloggerWithPost, firstPostUntracked.PostId); //VERIFY status.IsValid.ShouldEqual(true, status.Errors); status.SuccessMessage.ShouldEqual("Successfully deleted Post and given relationships."); snap.CheckSnapShot(db, -1, -2, -1, 0, -2); } }
public void Check27DeleteConnectedPostOk() { using (var db = new SampleWebAppDb()) { //SETUP var snap = new DbSnapShot(db); var lastPost = db.Posts.Include(x => x.Tags).ToList().Last(); var numTags = lastPost.Tags.Count; //ATTEMPT db.Posts.Remove(lastPost); var status = db.SaveChangesWithChecking(); //VERIFY status.IsValid.ShouldEqual(true, status.Errors); snap.CheckSnapShot(db, -1, -numTags); } }
public async Task Check06UpdateDirectOk() { using (var db = new SampleWebAppDb()) { //SETUP var snap = new DbSnapShot(db); var firstPostUntracked = db.Posts.AsNoTracking().First(); var service = new UpdateServiceAsync(db); //ATTEMPT firstPostUntracked.Title = Guid.NewGuid().ToString(); var status = await service.UpdateAsync(firstPostUntracked); //VERIFY status.IsValid.ShouldEqual(true, status.Errors); status.SuccessMessage.ShouldEqual("Successfully updated Post."); snap.CheckSnapShot(db); } }
public async void Check12DeleteWithRelationshipsDirectFailOk() { using (var db = new SampleWebAppDb()) { //SETUP var snap = new DbSnapShot(db); var firstPostUntracked = db.Posts.AsNoTracking().First(); var service = new DeleteServiceAsync(db); //ATTEMPT var status = await service.DeleteWithRelationshipsAsync <Post>(FailDeleteRelationships, firstPostUntracked.PostId); //VERIFY status.IsValid.ShouldEqual(false); status.Errors.Count.ShouldEqual(1); status.Errors[0].ErrorMessage.ShouldEqual("I failed."); snap.CheckSnapShot(db); } }
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); } }
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); } }
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); } }
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); } }
public void Check25UpdatePostToAddTagOk() { using (var db = new SampleWebAppDb()) { //SETUP var snap = new DbSnapShot(db); var badTag = db.Tags.Single(x => x.Slug == "bad"); var firstPost = db.Posts.First(); //ATTEMPT db.Entry(firstPost).Collection(x => x.Tags).Load(); firstPost.Tags.Add(badTag); var status = db.SaveChangesWithChecking(); //VERIFY status.IsValid.ShouldEqual(true, status.Errors); snap.CheckSnapShot(db, 0, 1); firstPost = db.Blogs.Include(x => x.Posts.Select(y => y.Tags)).First().Posts.First(); firstPost.Tags.Count.ShouldEqual(3); } }
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); } }
public async Task Check07UpdateDirectDtoOk() { using (var db = new SampleWebAppDb()) { //SETUP var snap = new DbSnapShot(db); var firstPostUntrackedNoIncludes = db.Posts.AsNoTracking().First(); var service = new UpdateServiceAsync(db); var setupStatus = await(new UpdateSetupServiceAsync(db)).GetOriginalAsync <SimplePostDtoAsync>(firstPostUntrackedNoIncludes.PostId); setupStatus.IsValid.ShouldEqual(true, setupStatus.Errors); //ATTEMPT setupStatus.Result.Title = Guid.NewGuid().ToString(); var status = await service.UpdateAsync(setupStatus.Result); //VERIFY status.IsValid.ShouldEqual(true, status.Errors); snap.CheckSnapShot(db); var updatedPost = db.Posts.Include(x => x.Tags).First(); updatedPost.Title.ShouldEqual(setupStatus.Result.Title); updatedPost.Content.ShouldEqual(firstPostUntrackedNoIncludes.Content); } }
public void Check31CheckCreateDataOk() { using (var db = new SampleWebAppDb()) { //SETUP var snap = new DbSnapShot(db); var firstPostUntracked = db.Posts.AsNoTracking().First(); //ATTEMPT firstPostUntracked.Title = Guid.NewGuid().ToString(); firstPostUntracked.Blogger = db.Blogs.First(); firstPostUntracked.Tags = db.Tags.Take(2).ToList(); db.Posts.Add(firstPostUntracked); var status = db.SaveChangesWithChecking(); //VERIFY status.IsValid.ShouldEqual(true, status.Errors); snap.CheckSnapShot(db, 1, 2); var loadedPost = db.Posts.Include(x => x.Blogger).Include(x => x.Tags).Single(x => x.PostId == firstPostUntracked.PostId); loadedPost.Blogger.BlogId.ShouldEqual(db.Blogs.First().BlogId); CollectionAssert.AreEquivalent(db.Tags.Take(2).Select(x => x.TagId), loadedPost.Tags.Select(x => x.TagId)); } }
public void Check32DeleteViaRemoveOk() { using (var db = new SampleWebAppDb()) { //SETUP var snap = new DbSnapShot(db); var firstPostTagGrades = db.PostTagGrades.AsNoTracking().First(); //ATTEMPT var ptgToDelete = new PostTagGrade { PostId = firstPostTagGrades.PostId, TagId = firstPostTagGrades.TagId }; db.PostTagGrades.Attach(ptgToDelete); db.PostTagGrades.Remove(ptgToDelete); var status = db.SaveChangesWithChecking(); //VERIFY status.IsValid.ShouldEqual(true, status.Errors); snap.CheckSnapShot(db, 0, 0, 0, 0, -1); } }
public async Task Check11CreateDirectOk() { using (var db = new SampleWebAppDb()) { //SETUP var snap = new DbSnapShot(db); var service = new CreateServiceAsync(db); var firstPostUntracked = db.Posts.Include(x => x.Tags).AsNoTracking().First(); var tagsTracked = db.Tags.ToList().Where(x => firstPostUntracked.Tags.Any(y => y.TagId == x.TagId)).ToList(); //ATTEMPT firstPostUntracked.Title = Guid.NewGuid().ToString(); firstPostUntracked.Tags = tagsTracked; var status = await service.CreateAsync(firstPostUntracked); //VERIFY status.IsValid.ShouldEqual(true); snap.CheckSnapShot(db, 1, 2); var updatedPost = db.Posts.OrderByDescending(x => x.PostId).Include(x => x.Tags).First(); updatedPost.Title.ShouldEqual(firstPostUntracked.Title); updatedPost.BlogId.ShouldEqual(firstPostUntracked.BlogId); CollectionAssert.AreEqual(firstPostUntracked.Tags.Select(x => x.TagId), updatedPost.Tags.Select(x => x.TagId)); } }
public void Check30CheckCreateLastUpdatedOk() { using (var db = new SampleWebAppDb()) { //SETUP var snap = new DbSnapShot(db); var firstPostUntracked = db.Posts.AsNoTracking().First(); var originalDateTime = firstPostUntracked.LastUpdated; Thread.Sleep(400); //ATTEMPT firstPostUntracked.Title = Guid.NewGuid().ToString(); firstPostUntracked.Blogger = db.Blogs.First(); firstPostUntracked.Tags = db.Tags.Take(2).ToList(); db.Posts.Add(firstPostUntracked); var status = db.SaveChangesWithChecking(); //VERIFY status.IsValid.ShouldEqual(true, status.Errors); snap.CheckSnapShot(db, 1, 2); var loadedPost = db.Posts.Single(x => x.PostId == firstPostUntracked.PostId); Assert.GreaterOrEqual(loadedPost.LastUpdated.Subtract(originalDateTime).Milliseconds, 400); } }