コード例 #1
0
        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);
            }
        }
コード例 #2
0
        public async void Perf22UpdatePostAddTagOk()
        {
            int postId;

            using (var db = new SampleWebAppDb())
                postId = db.Posts.Include(x => x.Tags).AsNoTracking().First().PostId;

            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var setupService  = new UpdateSetupServiceAsync <Post, DetailPostDtoAsync>(db);
                var updateService = new UpdateServiceAsync <Post, DetailPostDtoAsync>(db);

                //ATTEMPT
                var setupStatus = await setupService.GetOriginalAsync(postId);

                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);

                setupStatus.Result.LogSpecificName("End");

                //VERIFY
                status.IsValid.ShouldEqual(true, status.Errors);
                foreach (var log in setupStatus.Result.LogOfCalls)
                {
                    Console.WriteLine(log);
                }
            }
        }
コード例 #3
0
        public async void Check08UpdateWithListDtoCorrectOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                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);
                var updatedPost = db.Posts.Include(x => x.Tags).First();
                updatedPost.Title.ShouldEqual(setupStatus.Result.Title);
                updatedPost.Blogger.ShouldNotEqualNull();
                CollectionAssert.AreEqual(firstPost.Tags.Select(x => x.TagId), updatedPost.Tags.Select(x => x.TagId));
            }
        }
コード例 #4
0
        public async void Perf06UpdateWithListDtoOk()
        {
            int postId;

            using (var db = new SampleWebAppDb())
                postId = db.Posts.Include(x => x.Tags).AsNoTracking().First().PostId;

            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var service      = new UpdateServiceAsync <Post, SimplePostDtoAsync>(db);
                var setupService = new UpdateSetupServiceAsync <Post, SimplePostDtoAsync>(db);

                //ATTEMPT
                var setupStatus = await setupService.GetOriginalAsync(postId);

                setupStatus.Result.Title = Guid.NewGuid().ToString();
                var status = await service.UpdateAsync(setupStatus.Result);

                setupStatus.Result.LogSpecificName("End");

                //VERIFY
                status.IsValid.ShouldEqual(true, status.Errors);
                foreach (var log in setupStatus.Result.LogOfCalls)
                {
                    Console.WriteLine(log);
                }
            }
        }
コード例 #5
0
        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));
            }
        }
コード例 #6
0
        public async 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 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();
                setupStatus.Result.LastUpdated = new DateTime();
                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);
                Assert.GreaterOrEqual(db.Posts.First().LastUpdated.Subtract(originalDateTime).Milliseconds, 400);
            }
        }
コード例 #7
0
        public async void Check01UpdateSetupFlowOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var service = new UpdateSetupServiceAsync<Tag, SimpleTagDtoAsync>(db);
                var firstTag = db.Tags.First();

                //ATTEMPT
                var status = await service.GetOriginalAsync(firstTag.TagId);

                //VERIFY
                status.IsValid.ShouldEqual(true, status.Errors);
                status.Result.FunctionsCalledCommaDelimited.ShouldEqual("DetailDtoFromDataInAsync,SetupSecondaryDataAsync");
            }
        }
コード例 #8
0
        public async void Check01UpdateSetupFlowOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var service  = new UpdateSetupServiceAsync <Tag, SimpleTagDtoAsync>(db);
                var firstTag = db.Tags.First();

                //ATTEMPT
                var status = await service.GetOriginalAsync(firstTag.TagId);

                //VERIFY
                status.IsValid.ShouldEqual(true, status.Errors);
                status.Result.FunctionsCalledCommaDelimited.ShouldEqual("DetailDtoFromDataInAsync,SetupSecondaryDataAsync");
            }
        }
コード例 #9
0
        public async void Check05UpdateSetupNotFoundBad()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var service = new UpdateSetupServiceAsync <Post, SimplePostDtoAsync>(db);

                //ATTEMPT
                var status = await service.GetOriginalAsync(0);

                //VERIFY
                status.IsValid.ShouldEqual(false);
                status.Errors.Count.ShouldEqual(1);
                status.Errors[0].ErrorMessage.ShouldEqual("We could not find an entry using that filter. Has it been deleted by someone else?");
                status.Result.ShouldNotEqualNull();
            }
        }
コード例 #10
0
        public async void Check16UpdateSetupServiceOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var setupService = new UpdateSetupServiceAsync <Post, DetailPostDtoAsync>(db);
                var firstPost    = db.Posts.First();

                //ATTEMPT
                var status = await setupService.GetOriginalAsync(firstPost.PostId);

                //VERIFY
                status.IsValid.ShouldEqual(true, status.Errors);
                status.Result.Bloggers.KeyValueList.Count.ShouldEqual(db.Blogs.Count() + 1);
                status.Result.UserChosenTags.AllPossibleOptions.Count.ShouldEqual(db.Tags.Count());
            }
        }
コード例 #11
0
        public async Task Check05UpdateSetupServicePost()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var firstPostUntracked = db.Posts.AsNoTracking().First();
                var service            = new UpdateSetupServiceAsync(db);

                //ATTEMPT
                var status = await service.GetOriginalAsync <Post>(firstPostUntracked.PostId);

                //VERIFY
                status.IsValid.ShouldEqual(true, status.Errors);
                status.Result.ShouldNotEqualNull();
                status.Result.PostId.ShouldEqual(firstPostUntracked.PostId);
            }
        }
コード例 #12
0
        public static async Task UpdatePostGSelectViaDtoAsync(this SampleWebAppDb db, int postId)
        {
            var setupService = new UpdateSetupServiceAsync(db);
            var setupStatus  = await setupService.GetOriginalAsync <DetailPostDtoAsync>(postId);

            setupStatus.IsValid.ShouldEqual(true, setupStatus.Errors);

            var guidString = Guid.NewGuid().ToString("N");

            setupStatus.Result.Title   = guidString;
            setupStatus.Result.Content = guidString;
            setupStatus.Result.Tags    = new Collection <Tag> {
                db.Tags.First()
            };

            var service = new UpdateServiceAsync(db);
            var status  = await service.UpdateAsync(setupStatus.Result);

            status.IsValid.ShouldEqual(true, status.Errors);
        }
コード例 #13
0
        public async void Check05UpdateSetupOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var service   = new UpdateSetupServiceAsync <Post, SimplePostDtoAsync>(db);
                var firstPost = db.Posts.Include(x => x.Tags).AsNoTracking().First();

                //ATTEMPT
                var status = await service.GetOriginalAsync(firstPost.PostId);

                status.Result.LogSpecificName("End");

                //VERIFY
                status.IsValid.ShouldEqual(true, status.Errors);
                status.Result.PostId.ShouldEqual(firstPost.PostId);
                status.Result.BloggerName.ShouldEqual(firstPost.Blogger.Name);
                status.Result.Title.ShouldEqual(firstPost.Title);
                CollectionAssert.AreEqual(firstPost.Tags.Select(x => x.TagId), status.Result.Tags.Select(x => x.TagId));
            }
        }
コード例 #14
0
        public async void Perf05UpdateSetupOk()
        {
            int postId;

            using (var db = new SampleWebAppDb())
                postId = db.Posts.Include(x => x.Tags).AsNoTracking().First().PostId;

            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var service = new UpdateSetupServiceAsync <Post, SimplePostDtoAsync>(db);

                //ATTEMPT
                var status = await service.GetOriginalAsync(postId);

                status.Result.LogSpecificName("End");

                //VERIFY
                foreach (var log in status.Result.LogOfCalls)
                {
                    Console.WriteLine(log);
                }
            }
        }
コード例 #15
0
        public async void Check09UpdateWithListDtoBad()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                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 = "Can't I ask a question?";
                var status = await service.UpdateAsync(setupStatus.Result);

                setupStatus.Result.LogSpecificName("End");

                //VERIFY
                status.IsValid.ShouldEqual(false);
                status.Errors.Count.ShouldEqual(1);
                status.Errors[0].ErrorMessage.ShouldEqual("Sorry, but you can't ask a question, i.e. the title can't end with '?'.");
            }
        }
コード例 #16
0
        public async void Check25UpdatePostFailRunsSetupSecondaryDataAgainOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                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 = null;                   //that will fail
                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(false);
                setupStatus.Result.Bloggers.KeyValueList.Count.ShouldEqual(db.Blogs.Count() + 1);
                setupStatus.Result.UserChosenTags.AllPossibleOptions.Count.ShouldEqual(db.Tags.Count());
            }
        }
コード例 #17
0
        public async void Check05UpdateSetupNotFoundBad()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var service = new UpdateSetupServiceAsync<Post, SimplePostDtoAsync>(db);

                //ATTEMPT
                var status = await service.GetOriginalAsync(0);

                //VERIFY
                status.IsValid.ShouldEqual(false);
                status.Errors.Count.ShouldEqual(1);
                status.Errors[0].ErrorMessage.ShouldEqual("We could not find an entry using that filter. Has it been deleted by someone else?");
                status.Result.ShouldNotEqualNull();
            }
        }
コード例 #18
0
        public async void Perf06UpdateWithListDtoOk()
        {
            int postId;
            using (var db = new SampleWebAppDb())
                postId = db.Posts.Include(x => x.Tags).AsNoTracking().First().PostId;

            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var service = new UpdateServiceAsync<Post, SimplePostDtoAsync>(db);
                var setupService = new UpdateSetupServiceAsync<Post, SimplePostDtoAsync>(db);

                //ATTEMPT
                var setupStatus = await setupService.GetOriginalAsync(postId);
                setupStatus.Result.Title = Guid.NewGuid().ToString();
                var status = await service.UpdateAsync(setupStatus.Result);
                setupStatus.Result.LogSpecificName("End");

                //VERIFY
                status.IsValid.ShouldEqual(true, status.Errors);
                foreach (var log in setupStatus.Result.LogOfCalls) { Console.WriteLine(log); }
                
            }
        }
コード例 #19
0
        public async void Perf22UpdatePostAddTagOk()
        {
            int postId;
            using (var db = new SampleWebAppDb())
                postId = db.Posts.Include(x => x.Tags).AsNoTracking().First().PostId;

            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var setupService = new UpdateSetupServiceAsync<Post, DetailPostDtoAsync>(db);
                var updateService = new UpdateServiceAsync<Post, DetailPostDtoAsync>(db);

                //ATTEMPT
                var setupStatus = await setupService.GetOriginalAsync(postId);
                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);
                setupStatus.Result.LogSpecificName("End");

                //VERIFY
                status.IsValid.ShouldEqual(true, status.Errors);
                foreach (var log in setupStatus.Result.LogOfCalls) { Console.WriteLine(log); }
            }
        }
コード例 #20
0
        public async void Perf16UpdateSetupServiceOk()
        {
            int postId;
            using (var db = new SampleWebAppDb())
                postId = db.Posts.Include(x => x.Tags).AsNoTracking().First().PostId;

            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var setupService = new UpdateSetupServiceAsync<Post, DetailPostDtoAsync>(db);

                //ATTEMPT
                var status = await setupService.GetOriginalAsync(postId);
                status.Result.LogSpecificName("End");

                //VERIFY
                foreach (var log in status.Result.LogOfCalls) { Console.WriteLine(log); }
            }
        }
コード例 #21
0
        public async Task Check05UpdateSetupServicePost()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var firstPostUntracked = db.Posts.AsNoTracking().First();
                var service = new UpdateSetupServiceAsync(db);

                //ATTEMPT
                var status = await service.GetOriginalAsync<Post>(firstPostUntracked.PostId);

                //VERIFY
                status.IsValid.ShouldEqual(true, status.Errors);
                status.Result.ShouldNotEqualNull();
                status.Result.PostId.ShouldEqual(firstPostUntracked.PostId);
            }
        }
コード例 #22
0
        public async 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 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();
                setupStatus.Result.LastUpdated = new DateTime();
                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);
                Assert.GreaterOrEqual(db.Posts.First().LastUpdated.Subtract(originalDateTime).Milliseconds, 400);
            }
        }
コード例 #23
0
        public async void Check09UpdateWithListDtoBad()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                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 = "Can't I ask a question?";
                var status = await service.UpdateAsync(setupStatus.Result);
                setupStatus.Result.LogSpecificName("End");

                //VERIFY
                status.IsValid.ShouldEqual(false);
                status.Errors.Count.ShouldEqual(1);
                status.Errors[0].ErrorMessage.ShouldEqual("Sorry, but you can't ask a question, i.e. the title can't end with '?'.");
            }
        }
コード例 #24
0
        public async void Check05UpdateSetupOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var service = new UpdateSetupServiceAsync<Post, SimplePostDtoAsync>(db);
                var firstPost = db.Posts.Include(x => x.Tags).AsNoTracking().First();

                //ATTEMPT
                var status = await service.GetOriginalAsync(firstPost.PostId);
                status.Result.LogSpecificName("End");

                //VERIFY
                status.IsValid.ShouldEqual(true, status.Errors);
                status.Result.PostId.ShouldEqual(firstPost.PostId);
                status.Result.BloggerName.ShouldEqual(firstPost.Blogger.Name);
                status.Result.Title.ShouldEqual(firstPost.Title);
                CollectionAssert.AreEqual(firstPost.Tags.Select(x => x.TagId), status.Result.Tags.Select(x => x.TagId));
            }
        }
コード例 #25
0
        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);
                
            }
        }
コード例 #26
0
        public async void Check08UpdateWithListDtoCorrectOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                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);
                var updatedPost = db.Posts.Include(x => x.Tags).First();
                updatedPost.Title.ShouldEqual(setupStatus.Result.Title);
                updatedPost.Blogger.ShouldNotEqualNull();
                CollectionAssert.AreEqual(firstPost.Tags.Select(x => x.TagId), updatedPost.Tags.Select(x => x.TagId));

            }
        }