Пример #1
0
        public async Task CreateAsync_given_character_adds_it()
        {
            var entity  = default(Character);
            var context = new Mock <IFuturamaContext>();

            context.Setup(c => c.Characters.Add(It.IsAny <Character>())).Callback <Character>(t => entity = t);

            using (var repository = new CharacterRepository(context.Object))
            {
                var character = new CharacterCreateDTO
                {
                    ActorId = 1,
                    Name    = "Name",
                    Species = "Species",
                    Planet  = "Planet",
                    Image   = "Image"
                };
                await repository.CreateAsync(character);
            }

            Assert.Equal(1, entity.ActorId);
            Assert.Equal("Name", entity.Name);
            Assert.Equal("Species", entity.Species);
            Assert.Equal("Planet", entity.Planet);
            Assert.Equal("Image", entity.Image);
        }
Пример #2
0
        public async Task CreateAsync_given_dto_returns_created_Character()
        {
            using (var connection = await CreateConnectionAsync())
                using (var context = await CreateContextAsync(connection))
                {
                    context.Actors.Add(new Actor {
                        Name = "John DiMaggio"
                    });
                    await context.SaveChangesAsync();

                    var repository = new CharacterRepository(context);
                    var dto        = new CharacterCreateUpdateDTO
                    {
                        ActorId = 1,
                        Name    = "Bender",
                        Species = "Robot",
                        Planet  = "Earth"
                    };

                    var character = await repository.CreateAsync(dto);

                    Assert.Equal(1, character.Id);
                    Assert.Equal(1, character.ActorId);
                    Assert.Equal("Bender", character.Name);
                    Assert.Equal("Robot", character.Species);
                    Assert.Equal("Earth", character.Planet);
                }
        }
Пример #3
0
        public async Task After_added_character_should_found_new_character()
        {
            //arrange
            var newCharacter = new Character()
            {
                CharacterId = 100,
                Name        = "Yoda"
            };
            var repository = new CharacterRepository(DbContext, new UnitOfWork(DbContext));

            //act
            await repository.CreateAsync(newCharacter);

            //assert
            Assert.Equal(newCharacter, DbContext.Characters.Find(newCharacter.CharacterId));
        }
        public async Task Create_given_character_calls_SaveChangesAsync()
        {
            var context = new Mock <IFuturamaContext>();

            context.Setup(c => c.Characters.Add(It.IsAny <Character>()));

            using (var repository = new CharacterRepository(context.Object))
            {
                var character = new CharacterCreateUpdateDTO
                {
                    Name    = "Name",
                    Species = "Species",
                };
                await repository.CreateAsync(character);
            }

            context.Verify(c => c.SaveChangesAsync(default(CancellationToken)));
        }
Пример #5
0
        public async Task After_deleted_character_should_not_give_deleted_character()
        {
            //arrange
            var newCharacter = new Character()
            {
                CharacterId = 100,
                Name        = "Yoda"
            };
            var repository = new CharacterRepository(DbContext, new UnitOfWork(DbContext));

            //act
            await repository.CreateAsync(newCharacter);

            await repository.DeleteAsync(newCharacter.CharacterId);

            //assert
            DbContext.Characters.Find(newCharacter.CharacterId).Should().BeNull();
        }
Пример #6
0
        public async Task After_modified_character_should_give_modified_character()
        {
            //arrange
            var newCharacter = new Character()
            {
                CharacterId = 100,
                Name        = "Yoda"
            };
            var repository = new CharacterRepository(DbContext, new UnitOfWork(DbContext));

            //act
            await repository.CreateAsync(newCharacter);

            newCharacter.Name = "Luke";
            await repository.UpdateAsync(newCharacter.CharacterId, newCharacter);

            //assert
            Assert.Equal(newCharacter, DbContext.Characters.Find(newCharacter.CharacterId));
        }
        public async Task Create_given_character_returns_new_Id()
        {
            var entity = default(Character);

            var context = new Mock <IFuturamaContext>();

            context.Setup(c => c.Characters.Add(It.IsAny <Character>()))
            .Callback <Character>(t => entity = t);
            context.Setup(c => c.SaveChangesAsync(default(CancellationToken)))
            .Returns(Task.FromResult(0))
            .Callback(() => entity.Id = 42);

            using (var repository = new CharacterRepository(context.Object))
            {
                var character = new CharacterCreateUpdateDTO
                {
                    Name    = "Name",
                    Species = "Species",
                };
                var id = await repository.CreateAsync(character);

                Assert.Equal(42, id);
            }
        }