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.");
            }
        }
Esempio n. 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.");
        }
Esempio n. 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);
        }