Esempio n. 1
0
        public async void GetAsync_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.GetAsync(ResourceUtils.NonExistentId));
            }
        }
Esempio n. 2
0
        public async void GetAsync_ReturnsResource()
        {
            //Arrange
            var options = InMemoryUtils.ProduceFreshDbContextOptions();
            var oldSet  = ResourceUtils.TestSet;

            using (var context = new ApplicationDbContext(options))
            {
                context.Resources.Add(ResourceUtils.TestSet.First());
                context.SaveChanges();
            }

            //Act
            using (var context = new ApplicationDbContext(options))
            {
                IBasicRepositoryAsync <Resource, int> repo = new ResourcesRepository(context);
                var result = await repo.GetAsync(context.Resources.First().Id);

                //Assert
                Assert.IsAssignableFrom <Resource>(result);
            }
        }