public void Add()
        {
            var url     = "http://example.com";
            var options = new DbContextOptionsBuilder <BloggingContext>().UseInMemoryDatabase("db").Options;

            using (var context = new BloggingContext(options))
            {
                var service = new BloggingService(context);
                service.Add(new Blog {
                    Url = url
                });
            }

            using (var context = new BloggingContext(options))
            {
                var blogs = context.Blogs;

                Assert.AreEqual(1, blogs.Count());
                Assert.AreEqual(url, blogs.First().Url);
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Initializer.Initialize();

            BloggingService bloggingService = new BloggingService();

            bloggingService.Add(new Blog()
            {
                Name  = "How to use EF",
                Posts = new List <Post>()
                {
                    new Post()
                    {
                        Title   = "Good Article",
                        Content = "It's what i am looking for."
                    }
                }
            });
            Console.WriteLine("OK");

            Console.ReadKey();
        }
Beispiel #3
0
 public BlogController(BloggingContext db)
 {
     this.service = new BloggingService(db);
 }