Esempio n. 1
0
        public async void SubscriberRepositoryTest()
        {
            var repo = new SubscriberRepository(_logger, false);

            var firstSubscriber = new Subscriber("Amir", "*****@*****.**");
            await repo.AddAsync(firstSubscriber);

            var id = firstSubscriber.Id;

            repo.Detach(firstSubscriber);

            var secondSubscriber = new Subscriber("Amir", "*****@*****.**");

            await Assert.ThrowsAsync <Microsoft.EntityFrameworkCore.DbUpdateException>(
                () => repo.AddAsync(secondSubscriber)
                );

            Assert.Throws <Microsoft.EntityFrameworkCore.DbUpdateException>(
                () => {
                repo.Add(secondSubscriber);
            });

            //we should reconnect to see the deleted objects
            repo = new SubscriberRepository(_logger, false);

            repo.Delete(id);

            var count = repo.GetAll().Count();

            Assert.Equal(0, count);
        }