public void Check22UpdatePostAddTagOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var snap          = new DbSnapShot(db);
                var setupService  = new UpdateSetupService <Post, DetailPostDto>(db);
                var updateService = new UpdateService <Post, DetailPostDto>(db);
                var firstPost     = db.Posts.First();

                //ATTEMPT
                var setupStatus = setupService.GetOriginal(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 = updateService.Update(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));
            }
        }
Beispiel #2
0
        public 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 UpdateSetupService <Post, DetailPostDto>(db);
                var updateService = new UpdateService <Post, DetailPostDto>(db);

                //ATTEMPT
                var setupStatus = setupService.GetOriginal(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 = updateService.Update(setupStatus.Result);
                setupStatus.Result.LogSpecificName("End");

                //VERIFY
                status.IsValid.ShouldEqual(true, status.Errors);
                foreach (var log in setupStatus.Result.LogOfCalls)
                {
                    Console.WriteLine(log);
                }
            }
        }
        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);
            }
        }
Beispiel #4
0
        public 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 snap         = new DbSnapShot(db);
                var service      = new UpdateService <Post, SimplePostDto>(db);
                var setupService = new UpdateSetupService <Post, SimplePostDto>(db);

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

                //VERIFY
                status.IsValid.ShouldEqual(true, status.Errors);
                foreach (var log in setupStatus.Result.LogOfCalls)
                {
                    Console.WriteLine(log);
                }
            }
        }
        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);
            }
        }
Beispiel #6
0
        public void Check01UpdateSetupFlowOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var service  = new UpdateSetupService <Tag, SimpleTagDto>(db);
                var firstTag = db.Tags.First();

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

                //VERIFY
                status.IsValid.ShouldEqual(true, status.Errors);
                status.Result.FunctionsCalledCommaDelimited.ShouldEqual("DetailDtoFromDataIn,SetupSecondaryData");
            }
        }
        public void Test05UpdateSetupOrderDetailViaServiceOk()
        {
            using (var db = new AdventureWorksLt2012())
            {
                //SETUP
                var service          = new UpdateSetupService(db);
                var firstOrderHeader = db.SalesOrderHeaders.First();

                //ATTEMPT
                var status = service.GetOriginal <CrudSalesOrderDto>(firstOrderHeader.SalesOrderID);

                //VERIFY
                status.ShouldBeValid();
                status.Result.ShipToOptions.KeyValueList.Count.ShouldBeGreaterThan(0);
            }
        }
        public void Check01UpdateSetupFlowOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var service = new UpdateSetupService<Tag, SimpleTagDto>(db);
                var firstTag = db.Tags.First();

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

                //VERIFY
                status.IsValid.ShouldEqual(true, status.Errors);
                status.Result.FunctionsCalledCommaDelimited.ShouldEqual("DetailDtoFromDataIn,SetupSecondaryData");
            }
        }
        public void Test05UpdateSetupOrderDetailViaServiceOk()
        {
            using (var db = new AdventureWorksLt2012())
            {
                //SETUP
                var service = new UpdateSetupService(db);
                var firstOrderHeader = db.SalesOrderHeaders.First();

                //ATTEMPT
                var status = service.GetOriginal<CrudSalesOrderDto>(firstOrderHeader.SalesOrderID);

                //VERIFY
                status.ShouldBeValid();
                status.Result.ShipToOptions.KeyValueList.Count.ShouldBeGreaterThan(0);

            }
        }
Beispiel #10
0
        public void Check05UpdateSetupServiceDto()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var firstPostUntracked = db.Posts.AsNoTracking().First();
                var service            = new UpdateSetupService(db);

                //ATTEMPT
                var status = service.GetOriginal <SimplePostDto>(firstPostUntracked.PostId);

                //VERIFY
                status.IsValid.ShouldEqual(true);
                status.Result.ShouldNotEqualNull();
                status.Result.PostId.ShouldEqual(firstPostUntracked.PostId);
            }
        }
        public void Check16UpdateSetupServiceOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var setupService = new UpdateSetupService <Post, DetailPostDto>(db);
                var firstPost    = db.Posts.First();

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

                //VERIFY
                status.IsValid.ShouldEqual(true);
                status.Result.Bloggers.KeyValueList.Count.ShouldEqual(db.Blogs.Count() + 1);
                status.Result.UserChosenTags.AllPossibleOptions.Count.ShouldEqual(db.Tags.Count());
            }
        }
Beispiel #12
0
        public void Check05UpdateSetupNotFoundBad()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var service = new UpdateSetupService <Post, SimplePostDto>(db);

                //ATTEMPT
                var status = service.GetOriginal(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();
            }
        }
        public void Check05UpdateSetupOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var service    = new UpdateSetupService <PostTagGrade, SimplePostTagGradeDto>(db);
                var firstGrade = db.PostTagGrades.Include(x => x.TagPart).Include(x => x.PostPart).First();

                //ATTEMPT
                var status = service.GetOriginal(firstGrade.PostId, firstGrade.TagId);
                status.Result.LogSpecificName("End");

                //VERIFY
                status.IsValid.ShouldEqual(true, status.Errors);
                status.Result.PostId.ShouldEqual(firstGrade.PostId);
                status.Result.TagPartName.ShouldEqual(firstGrade.TagPart.Name);
                status.Result.PostPartTitle.ShouldEqual(firstGrade.PostPart.Title);
            }
        }
Beispiel #14
0
        public void Check05UpdateSetupOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var service   = new UpdateSetupService <Post, SimplePostDto>(db);
                var firstPost = db.Posts.Include(x => x.Tags).AsNoTracking().First();

                //ATTEMPT
                var status = service.GetOriginal(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));
            }
        }
        public void Check10UpdateBadMisingKeyOk()
        {
            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, BadPostTagGradeMissingKeyDto>(db);
                var setupService = new UpdateSetupService <PostTagGrade, BadPostTagGradeMissingKeyDto>(db);

                //ATTEMPT
                var setupStatus = setupService.GetOriginal(firstGrade.PostId, firstGrade.TagId);
                setupStatus.IsValid.ShouldEqual(true, setupStatus.Errors);
                setupStatus.Result.Grade = 999;
                var ex = Assert.Throws <MissingPrimaryKeyException>(() => service.Update(setupStatus.Result));

                //VERIFY
                ex.Message.ShouldEqual("The dto must contain all the key(s) properties from the data class.");
            }
        }
Beispiel #16
0
        public static void UpdatePostGSelectViaDto(this SampleWebAppDb db, int postId)
        {
            var setupService = new UpdateSetupService(db);
            var setupStatus  = setupService.GetOriginal <DetailPostDto>(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 UpdateService(db);
            var status  = service.Update(setupStatus.Result);

            status.IsValid.ShouldEqual(true, status.Errors);
        }
Beispiel #17
0
        public 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 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);
            }
        }
Beispiel #18
0
        public 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 UpdateSetupService <Post, SimplePostDto>(db);

                //ATTEMPT
                var status = service.GetOriginal(postId);
                status.Result.LogSpecificName("End");

                //VERIFY
                foreach (var log in status.Result.LogOfCalls)
                {
                    Console.WriteLine(log);
                }
            }
        }
Beispiel #19
0
        public void Check07UpdateWithListDtoCorrectOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var firstPost    = db.Posts.Include(x => x.Tags).AsNoTracking().First();
                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);
                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));
            }
        }
        public void Check25UpdatePostFailRunsSetupSecondaryDataAgainOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var setupService  = new UpdateSetupService <Post, DetailPostDto>(db);
                var updateService = new UpdateService <Post, DetailPostDto>(db);
                var firstPost     = db.Posts.First();

                //ATTEMPT
                var setupStatus = setupService.GetOriginal(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 = updateService.Update(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());
            }
        }
Beispiel #21
0
        public void Test06AddressUpdateViaServiceOk()
        {
            using (var db = new AdventureWorksLt2012())
            {
                //SETUP
                var setupService            = new UpdateSetupService(db);
                var service                 = new UpdateService(db);
                var lastCustomerWithAddress = db.Customers.Include(x => x.CustomerAddresses).Where(x => x.CustomerAddresses.Count > 0).AsNoTracking().OrderByDescending(x => x.CustomerID).First();

                //ATTEMPT
                var setupStatus = setupService.GetOriginal <CrudCustomerAddressDto>(lastCustomerWithAddress.CustomerID,
                                                                                    lastCustomerWithAddress.CustomerAddresses.Last().AddressID);
                setupStatus.IsValid.ShouldEqual(true, setupStatus.Errors);

                setupStatus.Result.Address.AddressLine2 = Guid.NewGuid().ToString("D");
                var status = service.Update(setupStatus.Result);

                //VERIFY
                status.IsValid.ShouldEqual(true, status.Errors);
                var newLastCustomer = db.Customers.AsNoTracking().Include(x => x.CustomerAddresses.Select(y => y.Address)).OrderByDescending(x => x.CustomerID).First();
                newLastCustomer.CustomerAddresses.Count.ShouldEqual(lastCustomerWithAddress.CustomerAddresses.Count);
                newLastCustomer.CustomerAddresses.OrderByDescending(x => x.AddressID).First().Address.AddressLine2.ShouldEqual(setupStatus.Result.Address.AddressLine2);
            }
        }
        public void Test10UpdateSalesOrderViaServiceOk()
        {
            using (var db = new AdventureWorksLt2012())
            {
                //SETUP
                var setupService     = new UpdateSetupService(db);
                var service          = new UpdateService(db);
                var firstOrderHeader = db.SalesOrderHeaders.AsNoTracking().First();
                var newComment       = Guid.NewGuid().ToString("N");

                //ATTEMPT
                var status = setupService.GetOriginal <CrudSalesOrderDto>(firstOrderHeader.SalesOrderID);
                status.ShouldBeValid();
                status.Result.Comment = newComment;
                status.Result.Status  = 99;                 //should not be copied back
                var updateStatus = service.Update(status.Result);

                //VERIFY
                updateStatus.ShouldBeValid();
                var readBack = db.SalesOrderHeaders.Single(x => x.SalesOrderID == firstOrderHeader.SalesOrderID);
                readBack.Comment.ShouldEqual(newComment);
                readBack.Status.ShouldEqual(firstOrderHeader.Status);
            }
        }
        public 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 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);
                
            }
        }
        public void Check10UpdateBadMisingKeyOk()
        {
            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, BadPostTagGradeMissingKeyDto>(db);
                var setupService = new UpdateSetupService<PostTagGrade, BadPostTagGradeMissingKeyDto>(db);

                //ATTEMPT
                var setupStatus = setupService.GetOriginal(firstGrade.PostId, firstGrade.TagId);
                setupStatus.IsValid.ShouldEqual(true, setupStatus.Errors);
                setupStatus.Result.Grade = 999;
                var ex = Assert.Throws<MissingPrimaryKeyException>( () => service.Update(setupStatus.Result));

                //VERIFY
                ex.Message.ShouldEqual("The dto must contain all the key(s) properties from the data class.");
            }
        }
        public void Test06AddressUpdateViaServiceOk()
        {
            using (var db = new AdventureWorksLt2012())
            {
                //SETUP
                var setupService = new UpdateSetupService(db);
                var service = new UpdateService(db);
                var lastCustomerWithAddress = db.Customers.Include(x => x.CustomerAddresses).Where( x => x.CustomerAddresses.Count > 0).AsNoTracking().OrderByDescending(x => x.CustomerID).First();

                //ATTEMPT
                var setupStatus = setupService.GetOriginal<CrudCustomerAddressDto>(lastCustomerWithAddress.CustomerID,
                    lastCustomerWithAddress.CustomerAddresses.Last().AddressID);
                setupStatus.IsValid.ShouldEqual(true, setupStatus.Errors);

                setupStatus.Result.Address.AddressLine2 = Guid.NewGuid().ToString("D");
                var status = service.Update(setupStatus.Result);

                //VERIFY
                status.IsValid.ShouldEqual(true, status.Errors);
                var newLastCustomer = db.Customers.AsNoTracking().Include(x => x.CustomerAddresses.Select(y => y.Address)).OrderByDescending(x => x.CustomerID).First();
                newLastCustomer.CustomerAddresses.Count.ShouldEqual(lastCustomerWithAddress.CustomerAddresses.Count);
                newLastCustomer.CustomerAddresses.OrderByDescending(x => x.AddressID).First().Address.AddressLine2.ShouldEqual(setupStatus.Result.Address.AddressLine2);
            }
        }
        public 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 UpdateSetupService<Post, DetailPostDto>(db);
                var updateService = new UpdateService<Post, DetailPostDto>(db);

                //ATTEMPT
                var setupStatus = setupService.GetOriginal(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 = updateService.Update(setupStatus.Result);
                setupStatus.Result.LogSpecificName("End");

                //VERIFY
                status.IsValid.ShouldEqual(true, status.Errors);
                foreach (var log in setupStatus.Result.LogOfCalls) { Console.WriteLine(log); }
            }
        }
        public void Check05UpdateSetupServiceDto()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var firstPostUntracked = db.Posts.AsNoTracking().First();
                var service = new UpdateSetupService(db);

                //ATTEMPT
                var status = service.GetOriginal<SimplePostDto>(firstPostUntracked.PostId);

                //VERIFY
                status.IsValid.ShouldEqual(true);
                status.Result.ShouldNotEqualNull();
                status.Result.PostId.ShouldEqual(firstPostUntracked.PostId);
            }
        }
        public void Test10UpdateSalesOrderViaServiceOk()
        {
            using (var db = new AdventureWorksLt2012())
            {
                //SETUP
                var setupService = new UpdateSetupService(db);
                var service = new UpdateService(db);
                var firstOrderHeader = db.SalesOrderHeaders.AsNoTracking().First();
                var newComment = Guid.NewGuid().ToString("N");

                //ATTEMPT
                var status = setupService.GetOriginal<CrudSalesOrderDto>(firstOrderHeader.SalesOrderID) ;
                status.ShouldBeValid();
                status.Result.Comment = newComment;
                status.Result.Status = 99;                  //should not be copied back
                var updateStatus = service.Update(status.Result);

                //VERIFY
                updateStatus.ShouldBeValid();
                var readBack = db.SalesOrderHeaders.Single(x => x.SalesOrderID == firstOrderHeader.SalesOrderID);
                readBack.Comment.ShouldEqual(newComment);
                readBack.Status.ShouldEqual(firstOrderHeader.Status);
            }
        }
        public void Check05UpdateSetupNotFoundBad()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var service = new UpdateSetupService<Post, SimplePostDto>(db);

                //ATTEMPT
                var status = service.GetOriginal(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();
            }
        }
        public void Check05UpdateSetupOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var service = new UpdateSetupService<Post, SimplePostDto>(db);
                var firstPost = db.Posts.Include(x => x.Tags).AsNoTracking().First();

                //ATTEMPT
                var status = service.GetOriginal(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));
            }
        }
        public 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 snap = new DbSnapShot(db);
                var service = new UpdateService<Post, SimplePostDto>(db);
                var setupService = new UpdateSetupService<Post, SimplePostDto>(db);

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

                //VERIFY
                status.IsValid.ShouldEqual(true, status.Errors);
                foreach (var log in setupStatus.Result.LogOfCalls) { Console.WriteLine(log); }
                
            }
        }
        public void Check25UpdatePostFailRunsSetupSecondaryDataAgainOk()
        {

            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var setupService = new UpdateSetupService<Post, DetailPostDto>(db);
                var updateService = new UpdateService<Post, DetailPostDto>(db);
                var firstPost = db.Posts.First();

                //ATTEMPT
                var setupStatus = setupService.GetOriginal(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 = updateService.Update(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());
            }
        }
        public void Check22UpdatePostAddTagOk()
        {

            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var snap = new DbSnapShot(db);
                var setupService = new UpdateSetupService<Post, DetailPostDto>(db);
                var updateService = new UpdateService<Post, DetailPostDto>(db);
                var firstPost = db.Posts.First();

                //ATTEMPT
                var setupStatus = setupService.GetOriginal(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 = updateService.Update(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 Check16UpdateSetupServiceOk()
        {

            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var setupService = new UpdateSetupService<Post, DetailPostDto>(db);
                var firstPost = db.Posts.First();

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

                //VERIFY
                status.IsValid.ShouldEqual(true);
                status.Result.Bloggers.KeyValueList.Count.ShouldEqual(db.Blogs.Count() + 1);
                status.Result.UserChosenTags.AllPossibleOptions.Count.ShouldEqual(db.Tags.Count());
            }
        }
        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 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 void Check08UpdateWithListDtoCorrectOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var firstPost = db.Posts.Include(x => x.Tags).AsNoTracking().First();
                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);
                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));

            }
        }
        public 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 UpdateSetupService<Post, SimplePostDto>(db);

                //ATTEMPT
                var status = service.GetOriginal(postId);
                status.Result.LogSpecificName("End");

                //VERIFY
                foreach (var log in status.Result.LogOfCalls) { Console.WriteLine(log); }
            }
        }
        public void Check05UpdateSetupOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var service = new UpdateSetupService<PostTagGrade, SimplePostTagGradeDto>(db);
                var firstGrade = db.PostTagGrades.Include(x => x.TagPart).Include(x => x.PostPart).First();

                //ATTEMPT
                var status = service.GetOriginal(firstGrade.PostId, firstGrade.TagId);
                status.Result.LogSpecificName("End");

                //VERIFY
                status.IsValid.ShouldEqual(true, status.Errors);
                status.Result.PostId.ShouldEqual(firstGrade.PostId);
                status.Result.TagPartName.ShouldEqual(firstGrade.TagPart.Name);
                status.Result.PostPartTitle.ShouldEqual(firstGrade.PostPart.Title);
            }
        }