public async Task Can_Find_A_Collection_By_id()
        {
            //Given
            var toBeFound = await Database.OnceAndSaveAsync(async db =>
            {
                var collections = new[]
                {
                    new Collection {
                        Name = "Collection1"
                    },
                    new Collection {
                        Name = "Collection2"
                    },
                };
                await db.Collections.AddRangeAsync(collections);
                return(collections.First());
            });

            //When
            var found = await Database.OnceAsync(async db =>
            {
                var repository = new CollectionRepository(db);
                return(await repository.FindAsync(toBeFound.Id));
            });

            //Then
            Assert.Equal(toBeFound.Name, found.Name);
        }
        public async Task Found_Collection_Should_Not_Be_Tracked()
        {
            //Given
            const string realName     = "A Collection";
            var          collectionId = await Database.OnceAsync(async db =>
            {
                var repo       = new CollectionRepository(db);
                var collection = new Collection {
                    Name = realName
                };
                await repo.AddAsync(collection);
                return(collection.Id);
            });

            //When
            await Database.OnceAsync(async db =>
            {
                var repo       = new CollectionRepository(db);
                var collection = await repo.FindAsync(collectionId);

                collection.Name = "Manipulated Name";
                await db.SaveChangesAsync();
            });

            //Then
            var result = await Database.OnceAsync(async db =>
                                                  await db.Collections.FindAsync(collectionId));

            Assert.Equal(realName, result.Name);
        }
Exemple #3
0
        public async Task <IActionResult> RemoveAsync(int id)
        {
            var collection = await _repository.FindAsync(id);

            await _repository.RemoveAsync(collection);

            return(new OkResult());
        }
Exemple #4
0
 public async Task <Collection> ShowAsync(int id)
 {
     return(await _repository.FindAsync(id));
 }