public async Task Should_Not_Create_Ability_If_Name_Not_Unique()
        {
            // Arrange
            var data    = BogusViewModel.AbilityViewModelFaker();
            var ability = new Ability()
            {
                Id     = data.Id,
                Name   = data.Name,
                Effect = data.Effect
            };

            var service = new AbilityServicesImpl(
                abilitiesRepository.Object,
                mapper.Object
                );

            mapper.Setup(x => x.Map <Ability>(data)).Returns(ability);
            abilitiesRepository.Setup(x => x.ExistsById(data.Id)).ReturnsAsync(false);
            abilitiesRepository.Setup(x => x.ExistsByName(data.Name))
            .ReturnsAsync(true);

            // Act

            // Assert
            await Assert.ThrowsAsync <AbilityException>(
                () => service.CreateAbility(data)
                );
        }
        public async Task Should_Create_New_Ability()
        {
            // Arrange
            var data    = BogusViewModel.AbilityViewModelFaker();
            var ability = new Ability()
            {
                Id     = data.Id,
                Name   = data.Name,
                Effect = data.Effect
            };

            var service = new AbilityServicesImpl(
                abilitiesRepository.Object,
                mapper.Object
                );

            mapper.Setup(x => x.Map <Ability>(data)).Returns(ability);
            abilitiesRepository.Setup(x => x.ExistsById(data.Id)).ReturnsAsync(false);
            abilitiesRepository.Setup(x => x.ExistsByName(data.Name))
            .ReturnsAsync(false);
            abilitiesRepository.Setup(x => x.CreateAbility(ability))
            .ReturnsAsync(ability);
            mapper.Setup(x => x.Map <AbilityViewModel>(ability)).Returns(data);

            // Act
            var response = await service.CreateAbility(data);

            // Assert
            Assert.InRange(response.Id, 1, 260);
            Assert.NotNull(response.Name);
            Assert.NotNull(response.Effect);
        }
Ejemplo n.º 3
0
        public async Task Should_Return_401_Status_Code_If_Admin_Not_Authenticated()
        {
            // Arrange
            var client = factory.CreateClient();

            var data = BogusViewModel.AbilityViewModelFaker();

            // Act
            var response = await PerformRequest(client, data);

            // Assert
            Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
        }
Ejemplo n.º 4
0
        public async Task Should_Return_400_Status_Code_If_Ability_Id_Not_Unique()
        {
            // Arrange
            var client = factory.CreateClient();
            await factory.AuthenticateAsync(client);

            var data = BogusViewModel.AbilityViewModelFaker();

            data.Id = 1;

            // Act
            var response = await PerformRequest(client, data);

            // Assert
            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
        }
        public async Task Should_Return_201_Status_Code_With_Valid_ViewModel()
        {
            // var actionValue = Assert.IsAssignableFrom<IEnumerable<CustomerAddressViewModel>>(actionResult.Value);
            // Arrange
            var data = BogusViewModel.AbilityViewModelFaker();

            abilityServices.Setup(x => x.CreateAbility(data)).ReturnsAsync(data);

            var abilitiesController = new AbilitiesController(abilityServices.Object);

            // Act
            var response = await abilitiesController.Create(data);

            // Assert
            Assert.NotNull(response);
            Assert.IsType <CreatedResult>(response.Result);
        }
Ejemplo n.º 6
0
        public async Task Should_Return_201_Status_Code_With_Valid_ViewModel()
        {
            // Arrange
            var data = BogusViewModel.PokemonViewModelFaker();

            var responseData = data;

            responseData.Abilities = BogusViewModel.AbilityViewModelFaker(2);

            pokemonServices.Setup(x => x.CreatePokemon(data)).ReturnsAsync(
                responseData
                );

            var pokemonController = new PokemonController(pokemonServices.Object);

            // Act
            var response = await pokemonController.Create(data, photo);

            // Assert
            Assert.NotNull(response);
            Assert.IsType <CreatedResult>(response.Result);
        }