コード例 #1
0
        public static void ResetBlogs(SampleWebAppDb context, TestDataSelection selection)
        {
            try
            {
                context.Posts.ToList().ForEach(x => context.Posts.Remove(x));
                context.Tags.ToList().ForEach(x => context.Tags.Remove(x));
                context.Blogs.ToList().ForEach(x => context.Blogs.Remove(x));
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                _logger.Critical("Exception when resetting the blogs", ex);
                throw;
            }

            var bloggers = LoadDbDataFromXml.FormBlogsWithPosts(XmlBlogsDataFileManifestPath[selection]);

            context.Blogs.AddRange(bloggers);
            var status = context.SaveChangesWithChecking();

            if (!status.IsValid)
            {
                _logger.CriticalFormat("Error when resetting courses data. Error:\n{0}",
                                       string.Join(",", status.Errors));
                throw new FormatException("problem writing to database. See log.");
            }
        }
コード例 #2
0
        public void Check02XmlFileLoadBad()
        {
            //SETUP

            //ATTEMPT
            var ex = Assert.Throws <NullReferenceException>(() => LoadDbDataFromXml.FormBlogsWithPosts("badname.xml"));

            //VERIFY
            ex.Message.ShouldStartWith("Could not find the xml file you asked for.");
        }
コード例 #3
0
        public void Check01XmlFileLoadOk()
        {
            //SETUP

            //ATTEMPT
            var bloggers = LoadDbDataFromXml.FormBlogsWithPosts("DataLayer.Startup.Internal.BlogsContentSimple.xml").ToList();

            //VERIFY
            bloggers.Count().ShouldEqual(2);
            bloggers.SelectMany(x => x.Posts).Count().ShouldEqual(3);
            bloggers.SelectMany(x => x.Posts.SelectMany(y => y.Tags)).Distinct().Count().ShouldEqual(3);
        }
コード例 #4
0
        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();
        }