Example #1
0
        public async void DeleteAsync_ChangesQuantity()
        {
            //Arrange
            var contextOptions = InMemoryUtils.ProduceFreshDbContextOptions();
            var oldModel       = ResourceUtils.TestSet.First();
            int oldQuantity;

            using (var context = new ApplicationDbContext(contextOptions))
            {
                context.Resources.Add(oldModel);
                context.SaveChanges();
                oldQuantity = context.Resources.Count();
            }

            //Act
            using (var context = new ApplicationDbContext(contextOptions))
            {
                IBasicRepositoryAsync <Resource, int> repo = new ResourcesRepository(context);
                await repo.DeleteAsync(oldModel.Id);
            }

            //Assert
            using (var context = new ApplicationDbContext(contextOptions))
            {
                Assert.Equal(1, oldQuantity);
                Assert.Empty(context.Resources);
            }
        }
Example #2
0
        public async void DeleteAsync_ThrowsNotFound_OnNonExistent()
        {
            //Arrange
            var contextOptions = InMemoryUtils.ProduceFreshDbContextOptions();
            var oldModel       = ResourceUtils.TestSet.First();

            using (var context = new ApplicationDbContext(contextOptions))
            {
                context.Resources.Add(oldModel);
                context.SaveChanges();
            }
            var newModel = ResourceUtils.TestSet.Last();

            using (var context = new ApplicationDbContext(contextOptions))
            {
                IBasicRepositoryAsync <Resource, int> repo = new ResourcesRepository(context);

                //Assert-Act
                await Assert.ThrowsAsync <CurrentEntryNotFoundException>(() => repo.DeleteAsync(ResourceUtils.NonExistentId));
            }
        }