예제 #1
0
        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);
        }
예제 #2
0
        public async Task Mapped_Found_Collection_Should_Not_Be_Tracked()
        {
            //Given
            const string realName     = "A Collection";
            const int    itemsCount   = 3;
            var          collectionId = await Database.OnceAsync(async db =>
            {
                var repo       = new CollectionRepository(db);
                var collection = new Collection {
                    Name = realName
                };
                for (var i = 0; i < itemsCount; i++)
                {
                    collection.TodoItems.Add(new TodoItem {
                        Name = $"Item{i}"
                    });
                }
                await repo.AddAsync(collection);
                return(collection.Id);
            });

            //When
            await Database.OnceAsync(async db =>
            {
                var repo  = new CollectionRepository(db);
                var found = await repo.FindAndMapAsync(collectionId, collection => new
                {
                    Collection     = collection,
                    TodoItemsCount = collection.TodoItems.Count,
                });

                Assert.Equal(itemsCount, found.TodoItemsCount);

                found.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);
        }
예제 #3
0
        public async Task Can_Add_A_New_Collection()
        {
            //Given
            var collection = new Collection {
                Name = "A Collection"
            };

            //When
            await Database.OnceAsync(async db =>
            {
                var repository = new CollectionRepository(db);
                await repository.AddAsync(collection);
            });

            //Then
            var isExists = await Database.OnceAsync(async db =>
                                                    await db.Collections.AnyAsync(c => c.Name.Equals(collection.Name)));

            Assert.True(isExists);
        }