Beispiel #1
0
        public async Task Insert_Id_AlreadySet_AsExpected()
        {
            try
            {
                using (var adapater = GetRepository())
                {
                    var b = new WebSite
                    {
                        Url = "http://www.microsoft.com"
                    };
                    b.FakePersistenceId(Guid.NewGuid());
                    adapater.MarkForInsert(b);
                    await adapater.SaveAsync().ConfigureAwait(false);
                }

                using (var ctx = new TestDbContext())
                {
                    var testB = ctx.Set <WebSite>().ToList();
                    testB.Should().HaveCount(1);
                    testB[0].Url.Should().Be("http://www.microsoft.com");
                }
            }
            finally
            {
                DeleteAll();
            }
        }
        public async Task GetByIdAsync_Guid_AsExpected()
        {
            try
            {
                Guid id         = Guid.NewGuid();
                var  collection = GetCollection <WebSite>();
                var  site1      = new WebSite
                {
                    Url = "https://blogs.msdn.net",
                };
                var site2 = new WebSite
                {
                    Url = "https://www.microsoft.com"
                };
                site1.FakePersistenceId(id);
                await collection.InsertManyAsync(new[] { site1, site2 });

                using (var repo = new RepositoryBase(new MongoDataReaderAdapter(), new MongoDataWriterAdapter()))
                {
                    var result = await repo.GetByIdAsync <WebSite>(id).ConfigureAwait(false);

                    result.Should().NotBeNull();
                    result.Url.Should().Be("https://blogs.msdn.net");
                }
            }
            finally
            {
                DeleteAll();
            }
        }
Beispiel #3
0
        public async Task Update_NotExisting_InBDD_AsExpected()
        {
            try
            {
                using (var repo = new RepositoryBase(new MongoDataReaderAdapter(), new MongoDataWriterAdapter()))
                {
                    var b = new WebSite
                    {
                        Url = "http://www.microsoft.com"
                    };
                    b.FakePersistenceId(Guid.NewGuid());
                    repo.MarkForUpdate(b);
                }
                using (var repo = new RepositoryBase(new MongoDataReaderAdapter(), new MongoDataWriterAdapter()))
                {
                    var testB = await repo.GetAsync <WebSite>().ToListAsync().ConfigureAwait(false);

                    testB.Should().HaveCount(0);
                }
            }
            finally
            {
                DeleteAll();
            }
        }
Beispiel #4
0
        public async Task Logical_Deletion()
        {
            try
            {
                Guid id         = Guid.NewGuid();
                var  collection = GetCollection <WebSite>();
                var  website    = new WebSite
                {
                    Url        = "https://blogs.msdn.net",
                    HyperLinks = new List <Hyperlink>
                    {
                        new Hyperlink
                        {
                            Value = "https://blogs.msdn.net"
                        },
                        new Hyperlink
                        {
                            Value = "https://blogs2.msdn.net"
                        }
                    }
                };
                website.FakePersistenceId(id);
                await collection.InsertOneAsync(website);

                using (var repo = new RepositoryBase(new MongoDataReaderAdapter(), new MongoDataWriterAdapter()))
                {
                    (await repo.GetAsync <WebSite>().CountAsync()).Should().Be(1);
                    (await repo.GetAsync <WebSite>(includeDeleted: true).CountAsync()).Should().Be(1);
                }
                using (var repo = new RepositoryBase(new MongoDataReaderAdapter(), new MongoDataWriterAdapter()))
                {
                    var entity = await repo.GetAsync <WebSite>().FirstOrDefaultAsync();

                    entity.Should().NotBeNull();
                    repo.MarkForDelete(entity);
                    await repo.SaveAsync().ConfigureAwait(false);
                }
                using (var repo = new RepositoryBase(new MongoDataReaderAdapter(), new MongoDataWriterAdapter()))
                {
                    (await repo.GetAsync <WebSite>(includeDeleted: true).CountAsync()).Should().Be(1);
                    var entity = await repo.GetAsync <WebSite>(includeDeleted : true).FirstOrDefaultAsync();

                    entity.DeletionDate.Should().BeSameDateAs(DateTime.Today);
                    (await repo.GetAsync <WebSite>().CountAsync()).Should().Be(0);
                }
            }
            finally
            {
                DeleteAll();
            }
        }
Beispiel #5
0
 public async Task Update_NotExisting_InBDD_AsExpected()
 {
     try
     {
         using (var repo = new RepositoryBase(new MongoDataReaderAdapter(), new MongoDataWriterAdapter()))
         {
             var b = new WebSite
             {
                 Url = "http://www.microsoft.com"
             };
             b.FakePersistenceId(Guid.NewGuid());
             repo.MarkForUpdate(b);
             await Assert.ThrowsAsync <InvalidOperationException>(repo.SaveAsync);
         }
     }
     finally
     {
         DeleteAll();
     }
 }
Beispiel #6
0
 public async Task Update_NotExisting_InBDD_Should_Throw_EFException()
 {
     try
     {
         using (var adapater = GetRepository())
         {
             var b = new WebSite
             {
                 Url = "http://www.microsoft.com"
             };
             b.FakePersistenceId(Guid.NewGuid());
             adapater.MarkForUpdate(b);
             await Assert.ThrowsAsync <DbUpdateConcurrencyException>(adapater.SaveAsync);
         }
     }
     finally
     {
         DeleteAll();
     }
 }