當前位置: 首頁>>代碼示例>>C#>>正文


C# DataClasses.SampleWebAppDb類代碼示例

本文整理匯總了C#中Tests.DataClasses.SampleWebAppDb的典型用法代碼示例。如果您正苦於以下問題:C# SampleWebAppDb類的具體用法?C# SampleWebAppDb怎麽用?C# SampleWebAppDb使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SampleWebAppDb類屬於Tests.DataClasses命名空間,在下文中一共展示了SampleWebAppDb類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: 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);
            }
        }
開發者ID:JonPSmith,項目名稱:GenericServices,代碼行數:25,代碼來源:Tests02Validation.cs

示例2: Check02DatabaseDataLinksOk

        public void Check02DatabaseDataLinksOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                DataLayerInitialise.InitialiseThis();
                var filepath = TestFileHelpers.GetTestFileFilePath("DbContentSimple.xml");

                //ATTEMPT
                DataLayerInitialise.ResetDatabaseToTestData(db, filepath);

                //VERIFY
                var allPosts = db.Posts.Include(x => x.Blogger).Include(x => x.Tags).ToList();
                allPosts[0].Blogger.Name.ShouldEqual("Fred Bloggs");
                string.Join(",", allPosts[0].Tags.Select(x => x.Slug)).ShouldEqual("ugly,bad");
                allPosts[1].Blogger.Name.ShouldEqual("Jon Smith");
                string.Join(",", allPosts[1].Tags.Select(x => x.Slug)).ShouldEqual("good,ugly");
                allPosts[2].Blogger.Name.ShouldEqual("Jon Smith");
                string.Join(",", allPosts[2].Tags.Select(x => x.Slug)).ShouldEqual("bad");

                db.PostTagGrades.Count().ShouldEqual(2);
                db.PostTagGrades.ToList().All( x => x.PostId == allPosts[0].PostId).ShouldEqual(true);
                string.Join(",", db.PostTagGrades.Include(x => x.TagPart).Select(x => x.TagPart.Slug)).ShouldEqual("bad,ugly");
            }
        }
開發者ID:huoxudong125,項目名稱:GenericServices,代碼行數:25,代碼來源:Tests01Setup.cs

示例3: DbSnapShot

 public DbSnapShot(SampleWebAppDb db)
 {
     NumBlogs = db.Blogs.Count();
     NumPostTagLinks = db.Database.SqlQuery<int>("SELECT COUNT(*) FROM dbo.TagPosts").First();
     NumPosts = db.Posts.Count();
     NumTags = db.Tags.Count();
     NumPostTagGrades = db.PostTagGrades.Count();
 }
開發者ID:huoxudong125,項目名稱:GenericServices,代碼行數:8,代碼來源:DbSnapShot.cs

示例4: SetUpFixture

 public void SetUpFixture()
 {
     using (var db = new SampleWebAppDb())
     {
         DataLayerInitialise.InitialiseThis();
         var filepath = TestFileHelpers.GetTestFileFilePath("DbContentSimple.xml");
         DataLayerInitialise.ResetDatabaseToTestData(db, filepath);
     }
 }
開發者ID:huoxudong125,項目名稱:GenericServices,代碼行數:9,代碼來源:Test02UpdateServiceAsync.cs

示例5: Main

        static void Main(string[] args)
        {
            using (var db = new SampleWebAppDb())
            {
                var firstId = db.Posts.First().PostId;
                RunCommand1(db);
                RunCommand2(db);
            }

        }
開發者ID:huoxudong125,項目名稱:GenericServices,代碼行數:10,代碼來源:Program.cs

示例6: CheckSnapShot

        public void CheckSnapShot(SampleWebAppDb db, int postsChange = 0, int postTagLinkChange = 0, int blogsChange = 0, int tagsChange = 0, int postTagGradesChange = 0)
        {
            var newSnap = new DbSnapShot(db);

            newSnap.NumPosts.ShouldEqual( NumPosts + postsChange, "posts wrong");
            newSnap.NumPostTagLinks.ShouldEqual(NumPostTagLinks + postTagLinkChange, "posttaglinks wrong");
            newSnap.NumBlogs.ShouldEqual(NumBlogs + blogsChange, "blogs wrong");
            newSnap.NumTags.ShouldEqual(NumTags + tagsChange, "tags wrong");
            newSnap.NumPostTagGrades.ShouldEqual(NumPostTagGrades + postTagGradesChange, "postTagGrades wrong");
        }
開發者ID:huoxudong125,項目名稱:GenericServices,代碼行數:10,代碼來源:DbSnapShot.cs

示例7: Check01ReadBlogsNoPostsOk

        public void Check01ReadBlogsNoPostsOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP

                //ATTEMPT
                var blogs = db.Blogs.ToList();

                //VERIFY
                blogs.Count.ShouldEqual(2);
                blogs.All( x => x.Posts == null).ShouldEqual(true);
            }
        }
開發者ID:huoxudong125,項目名稱:GenericServices,代碼行數:14,代碼來源:Tests04ReadWrite.cs

示例8: Check01CreateSetupFlowOk

        public void Check01CreateSetupFlowOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var service = new CreateSetupService<Tag, SimpleTagDto>(db);

                //ATTEMPT
                var dto = service.GetDto();

                //VERIFY
                dto.FunctionsCalledCommaDelimited.ShouldEqual("SetupSecondaryData");
            }
        }
開發者ID:huoxudong125,項目名稱:GenericServices,代碼行數:14,代碼來源:Test01CreateService.cs

示例9: Test02NoSingleExceptionSetBad

        public void Test02NoSingleExceptionSetBad()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                GenericServicesConfig.RealiseSingleExceptionMethod = null;

                //ATTEMPT
                var ex = Assert.Throws<InvalidOperationException>(() => db.Posts.RealiseSingleWithErrorChecking());

                //VERIFY
                ex.Message.ShouldEqual("Sequence contains more than one element");
            }
        }
開發者ID:huoxudong125,項目名稱:GenericServices,代碼行數:14,代碼來源:Test10RealiseSingleException.cs

示例10: FixtureSetup

        public void FixtureSetup()
        {
            //This remembers the SqlErrorTextDict
            _rememberDefaultSqlErrorTextDict =
                GenericServicesConfig.SqlErrorDict.Select(x => new KeyValuePair<int, string>(x.Key, x.Value))
                    .ToList();
            GenericServicesConfig.ClearSqlHandlerDict();

            using (var db = new SampleWebAppDb())
            {
                DataLayerInitialise.InitialiseThis();
                var filepath = TestFileHelpers.GetTestFileFilePath("DbContentSimple.xml");
                DataLayerInitialise.ResetDatabaseToTestData(db, filepath);
            }
        }
開發者ID:JonPSmith,項目名稱:GenericServices,代碼行數:15,代碼來源:Test02SqlDict.cs

示例11: Test01NoSingleExceptionSetOk

        public void Test01NoSingleExceptionSetOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var id = db.Posts.First().PostId;
                GenericServicesConfig.RealiseSingleExceptionMethod = null;

                //ATTEMPT
                var status = db.Posts.Where(x => x.PostId == id).RealiseSingleWithErrorChecking();

                //VERIFY
                status.IsValid.ShouldEqual(true, status.Errors);
            }
        }
開發者ID:huoxudong125,項目名稱:GenericServices,代碼行數:15,代碼來源:Test10RealiseSingleException.cs

示例12: Check06ListEfViaDtoOk

        public async void Check06ListEfViaDtoOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var timer = new Stopwatch();
                timer.Start();

                //ATTEMPT
                await db.ListPostEfViaDtoAsync(0);
                timer.Stop();

                //VERIFY
                Console.WriteLine("Ef operation took {0} ms", timer.ElapsedMilliseconds);
            }
        }
開發者ID:huoxudong125,項目名稱:GenericServices,代碼行數:16,代碼來源:Perf04EfPostAsync.cs

示例13: Check01DetailFlowOk

        public void Check01DetailFlowOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                var service = new DetailService<Tag, SimpleTagDto>(db);
                var firstTag = db.Tags.First();

                //ATTEMPT
                var status = service.GetDetailUsingWhere(x => x.TagId == firstTag.TagId);

                //VERIFY
                status.IsValid.ShouldEqual(true, status.Errors);
                status.Result.FunctionsCalledCommaDelimited.ShouldEqual("DetailDtoFromDataIn");
            }
        }
開發者ID:huoxudong125,項目名稱:GenericServices,代碼行數:16,代碼來源:Test03DetailService.cs

示例14: Check01UpdateSetupFlowOk

        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");
            }
        }
開發者ID:huoxudong125,項目名稱:GenericServices,代碼行數:16,代碼來源:Test02UpdateServiceAsync.cs

示例15: 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();
        }
開發者ID:huoxudong125,項目名稱:GenericServices,代碼行數:16,代碼來源:DataLayerInitialise.cs


注:本文中的Tests.DataClasses.SampleWebAppDb類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。