public async Task EFRepository_Insert_Id_AlreadySet_AsExpected()
        {
            try
            {
                using (var repo = new TestBlogEFRepository())
                {
                    var b = new WebSite
                    {
                        Url = "http://www.microsoft.com"
                    };
                    typeof(WebSite).GetProperty("Id").SetValue(b, Guid.NewGuid());
                    repo.MarkForInsert(b);
                    await repo.SaveAsync().ConfigureAwait(false);
                }

                using (var repo = new TestBlogEFRepository())
                {
                    var testB = await repo.GetAsync().ToListAsync().ConfigureAwait(false);

                    testB.Should().HaveCount(1);
                    testB[0].Url.Should().Be("http://www.microsoft.com");
                }
            }
            finally
            {
                DeleteAll();
            }
        }
Beispiel #2
0
        public async Task EFRepository_Insert_AsExpected()
        {
            try
            {
                using (var repo = new TestBlogEFRepository())
                {
                    var b = new WebSite
                    {
                        Url = "http://www.microsoft.com"
                    };
                    repo.MarkForInsert(b);
                    await repo.SaveAsync().ConfigureAwait(false);
                }

                using (var repo = new TestBlogEFRepository())
                {
                    var testB = await repo.GetAsync().ToList().ConfigureAwait(false);

                    testB.Should().HaveCount(1);
                    testB[0].Url.Should().Be("http://www.microsoft.com");
                }
            }
            finally
            {
                DeleteAll();
            }
        }
        public async Task EFRepository_Update_Blog_Should_Update_Posts_But_Not_User()
        {
            try
            {
                var site = new WebSite();
                site.Url   = "http://msdn.dotnet.com";
                site.Posts = new List <Post>();
                site.Posts.Add(new Post
                {
                    Content  = "test content",
                    WebSite  = site,
                    QuickUrl = "http://msdn.dotnet.com/test",
                });
                var user = new User
                {
                    Name     = "toto",
                    LastName = "titi"
                };
                user.Posts = new List <Post>();
                user.Posts.Add(site.Posts.First());
                user.Comments = new List <Comment>();
                user.Comments.Add(new Comment("test comment", user, site.Posts.First()));

                site.Posts.First().Writer = user;

                using (var repo = new TestBlogEFRepository())
                {
                    repo.MarkForInsert(site);
                    await repo.SaveAsync().ConfigureAwait(false);
                }

                WebSite dbSite = null;
                using (var repo = new TestBlogEFRepository())
                {
                    dbSite = repo.GetWithPostAndComment();
                }
                dbSite.Should().NotBeNull();

                var post = dbSite.Posts.First();

                post.QuickUrl        += "2";
                post.Writer.LastName += "2";
                post.Writer.Name     += "2";
                post.Writer.Comments.First().Value += "2";

                using (var repo = new TestBlogEFRepository())
                {
                    repo.MarkForUpdate(dbSite);
                    await repo.SaveAsync().ConfigureAwait(false);
                }

                using (var repo = new TestBlogEFRepository())
                {
                    dbSite = repo.GetWithPostAndComment();
                    dbSite.Should().NotBeNull();
                    post = dbSite.Posts.First();

                    post.QuickUrl.Should().Be("http://msdn.dotnet.com/test2");
                    post.Writer.Comments.First().Value.Should().Be("test comment2");
                    post.Writer.LastName.Should().Be("titi");
                    post.Writer.Name.Should().Be("toto");
                }
            }
            finally
            {
                DeleteAll();
            }
        }