Example #1
0
        public async Task EFRepository_GetByIdAsync_AsExpected()
        {
            try
            {
                Guid?id = null;
                using (var ctx = new TestDbContext())
                {
                    var w = new WebSite
                    {
                        Url = "https://blogs.msdn.net"
                    };
                    ctx.Add(w);
                    ctx.Add(new WebSite
                    {
                        Url = "https://www.microsoft.com"
                    });
                    await ctx.SaveChangesAsync().ConfigureAwait(false);

                    id = w.Id;
                }

                using (var repo = new TestBlogEFRepository())
                {
                    var result = await repo.GetByIdAsync(id).ConfigureAwait(false);

                    result.Should().NotBeNull();
                    result.Url.Should().Be("https://blogs.msdn.net");
                }
            }
            finally
            {
                DeleteAll();
            }
        }