Exemplo n.º 1
0
 public Option <SuccessResult, ErrorResult> Create(CreateCharacterCommand command)
 {
     return(_createCharacterCommandValidator
            .Validate(command)
            .OnSuccess(errorBuilder =>
     {
         _characterRepository.Insert(_mapper.Map(command));
     }));
 }
Exemplo n.º 2
0
        public void GivenThatCharacterIsNull_WhenTryingToMapIt_ThenArgumentNullExceptionIsThrown()
        {
            var urlHelper = CreateUrlHelper("http://localhost/api/characters/1");
            var mapper    = new CharacterMapper();

            var mappedCharacter = mapper.Map(null, urlHelper);
        }
Exemplo n.º 3
0
        public void GivenThatUrlHelperIsNull_WhenTryingToMapCharacter_ThenArgumentNullExceptionIsThrown()
        {
            var character = MockRepository.GenerateMock <ICharacter>();

            character.Stub(x => x.Identifier).Return(1);
            var mapper = new CharacterMapper();

            var mappedCharacter = mapper.Map(character, null);
        }
        public void GivenThatCharacterHasCulture_WhenTryingToMapCharacter_ThenMappedCharacterHasSameCulture()
        {
            var character = MockRepository.GenerateMock<ICharacter>();
            character.Stub(x => x.Identifier).Return(1);
            character.Stub(x => x.Culture).Return("testCulture");
            var mapper = new CharacterMapper();

            var mappedCharacter = mapper.Map(character, CreateUrlHelper("http://localhost/api/characters/1"));

            Assert.AreEqual(character.Culture, mappedCharacter.Culture);
        }
Exemplo n.º 5
0
        public void GivenThatCharacterHasIdentifierOfOne_WhenTryingToMapCharacter_ThenMappedCharacterUrlIsCorrectWithIdentifierInIt()
        {
            var character = MockRepository.GenerateMock <ICharacter>();

            character.Stub(x => x.Identifier).Return(1);
            var mapper = new CharacterMapper();

            var mappedCharacter = mapper.Map(character, CreateUrlHelper("http://localhost/api/characters/1"));

            Assert.AreEqual("http://localhost/api/characters/1", mappedCharacter.URL);
        }
Exemplo n.º 6
0
        public void GivenThatCharacterHasCulture_WhenTryingToMapCharacter_ThenMappedCharacterHasSameCulture()
        {
            var character = MockRepository.GenerateMock <ICharacter>();

            character.Stub(x => x.Identifier).Return(1);
            character.Stub(x => x.Culture).Return("testCulture");
            var mapper = new CharacterMapper();

            var mappedCharacter = mapper.Map(character, CreateUrlHelper("http://localhost/api/characters/1"));

            Assert.AreEqual(character.Culture, mappedCharacter.Culture);
        }
Exemplo n.º 7
0
        public void GivenThatCharacterIsDead_WhenTryingToMapCharacter_ThenMappedCharacterHasSameDiedData()
        {
            var character = MockRepository.GenerateMock <ICharacter>();

            character.Stub(x => x.Identifier).Return(1);
            character.Stub(x => x.Died).Return("someYear");
            var mapper = new CharacterMapper();

            var mappedCharacter = mapper.Map(character, CreateUrlHelper("http://localhost/api/characters/1"));

            Assert.AreEqual(character.Died, mappedCharacter.Died);
        }
        public void GivenThatCharacterHasAliases_WhenTryingToMapCharacter_ThenMappedCharacterHasSameAliases()
        {
            var character = MockRepository.GenerateMock<ICharacter>();
            character.Stub(x => x.Identifier).Return(1);
            character.Stub(x => x.Aliases).Return(new List<string> { "firstAlias", });
            var mapper = new CharacterMapper();

            var mappedCharacter = mapper.Map(character, CreateUrlHelper("http://localhost/api/characters/1"));

            Assert.AreEqual(character.Aliases.Count, mappedCharacter.Aliases.Count());
            Assert.AreEqual(character.Aliases.ElementAt(0), mappedCharacter.Aliases.ElementAt(0));
        }
        public void GivenThatCharacterHasBooks_WhenTryingToMapCharacter_ThenMappedCharacterBooksContainsCorrectUrls()
        {
            var book = MockRepository.GenerateMock<IBook>();
            book.Stub(x => x.Identifier).Return(10);
            var characer = MockRepository.GenerateMock<ICharacter>();
            characer.Stub(x => x.Identifier).Return(1);
            characer.Stub(x => x.Books).Return(new List<IBook> { book });
            var mapper = new CharacterMapper();

            var mappedCharacter = mapper.Map(characer, CreateUrlHelper("http://localhost/api/characters/1"));

            Assert.AreEqual(1, mappedCharacter.Books.Count());
            Assert.AreEqual("http://localhost/api/books/10", mappedCharacter.Books.ElementAt(0));
        }
        public void GivenThatCharacterHasAllegiance_WhenTryingToMapCharacter_ThenMappedCharacterAllegiancesContainsCorrectUrls()
        {
            var house = MockRepository.GenerateMock<IHouse>();
            house.Stub(x => x.Identifier).Return(1);
            var character = MockRepository.GenerateMock<ICharacter>();
            character.Stub(x => x.Allegiances).Return(new List<IHouse> { house });
            character.Stub(x => x.Identifier).Return(1);
            var mapper = new CharacterMapper();

            var mappedCharacter = mapper.Map(character, CreateUrlHelper("http://localhost/api/characters/1"));

            Assert.AreEqual(1, mappedCharacter.Allegiances.Count());
            Assert.AreEqual("http://localhost/api/houses/1", mappedCharacter.Allegiances.ElementAt(0));
        }
Exemplo n.º 11
0
        public void GivenThatCharacterHasSpouse_WhenTryingToMapCharacter_ThenMappedCharacterSpouseContainsCorrectUrl()
        {
            var spouse = MockRepository.GenerateMock <ICharacter>();

            spouse.Stub(x => x.Identifier).Return(2);
            var character = MockRepository.GenerateMock <ICharacter>();

            character.Stub(x => x.Identifier).Return(1);
            character.Stub(x => x.Spouse).Return(spouse);
            var mapper = new CharacterMapper();

            var mappedCharacter = mapper.Map(character, CreateUrlHelper("http://localhost/api/characters/1"));

            Assert.AreEqual($"http://localhost/api/characters/{character.Spouse.Identifier}", mappedCharacter.Spouse);
        }
Exemplo n.º 12
0
        public void GivenThatCharacterHasTvSeries_WhenTryingToMapCharacter_ThenMappedCharacterHasSameTvSeries()
        {
            var character = MockRepository.GenerateMock <ICharacter>();

            character.Stub(x => x.Identifier).Return(1);
            character.Stub(x => x.TvSeries).Return(new List <string> {
                "Season 1",
            });
            var mapper = new CharacterMapper(new GenderMapper());

            var mappedCharacter = mapper.Map(character, CreateUrlHelper("http://localhost/api/characters/1"));

            Assert.AreEqual(character.TvSeries.Count, mappedCharacter.TvSeries.Count());
            Assert.AreEqual(character.TvSeries.ElementAt(0), mappedCharacter.TvSeries.ElementAt(0));
        }
Exemplo n.º 13
0
        public void GivenThatCharacterHasMother_WhenTryingToMapCharacter_ThenMappedCharacterMotherContainsCorrectUrl()
        {
            var mother = MockRepository.GenerateMock <ICharacter>();

            mother.Stub(x => x.Identifier).Return(1000);
            var character = MockRepository.GenerateMock <ICharacter>();

            character.Stub(x => x.Identifier).Return(1);
            character.Stub(x => x.Mother).Return(mother);
            var mapper = new CharacterMapper(new GenderMapper());

            var mappedCharacter = mapper.Map(character, CreateUrlHelper("http://localhost/api/characters/1"));

            Assert.AreEqual($"http://localhost/api/characters/{character.Mother.Identifier}", mappedCharacter.Mother);
        }
Exemplo n.º 14
0
        public void GivenThatCharacterHasPlayedBy_WhenTryingToMapCharacter_ThenMappedCharacterHasSamePlayedBy()
        {
            var character = MockRepository.GenerateMock <ICharacter>();

            character.Stub(x => x.Identifier).Return(1);
            character.Stub(x => x.PlayedBy).Return(new List <string> {
                "Some Actor",
            });
            var mapper = new CharacterMapper();

            var mappedCharacter = mapper.Map(character, CreateUrlHelper("http://localhost/api/characters/1"));

            Assert.AreEqual(character.PlayedBy.Count, mappedCharacter.PlayedBy.Count());
            Assert.AreEqual(character.PlayedBy.ElementAt(0), mappedCharacter.PlayedBy.ElementAt(0));
        }
Exemplo n.º 15
0
        public void GivenThatCharacterHasPovBooks_WhenTryingToMapCharacter_ThenMappedCharacterPovBooksContainsCorrectUrls()
        {
            var book = MockRepository.GenerateMock <IBook>();

            book.Stub(x => x.Identifier).Return(10);
            var characer = MockRepository.GenerateMock <ICharacter>();

            characer.Stub(x => x.Identifier).Return(1);
            characer.Stub(x => x.PovBooks).Return(new List <IBook> {
                book
            });
            var mapper = new CharacterMapper();

            var mappedCharacter = mapper.Map(characer, CreateUrlHelper("http://localhost/api/characters/1"));

            Assert.AreEqual(1, mappedCharacter.PovBooks.Count());
            Assert.AreEqual("http://localhost/api/books/10", mappedCharacter.PovBooks.ElementAt(0));
        }
Exemplo n.º 16
0
        /// <summary>
        /// Retorna un personaje a partir de su identificador
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <Character> SearchCharacter(int id)
        {
            Character result;

            CharacterApi characterApi;
            PlanetApi    planetApi;
            SpeciesApi   speciesApi;

            this.searchCharacterWithCache(id, out characterApi);
            this.searchPlanetWithCache(characterApi.homeworld, out planetApi);
            this.searchSpeciesWithCache(characterApi.species.FirstOrDefault(), out speciesApi);

            List <Rating> ratings = _ratingRepository.GetRatingsByCharacterId(id);

            result = CharacterMapper.Map(characterApi, planetApi, speciesApi, ratings);

            return(await Task.FromResult(result));
        }
Exemplo n.º 17
0
        public void GivenThatCharacterHasAllegiance_WhenTryingToMapCharacter_ThenMappedCharacterAllegiancesContainsCorrectUrls()
        {
            var house = MockRepository.GenerateMock <IHouse>();

            house.Stub(x => x.Identifier).Return(1);
            var character = MockRepository.GenerateMock <ICharacter>();

            character.Stub(x => x.Allegiances).Return(new List <IHouse> {
                house
            });
            character.Stub(x => x.Identifier).Return(1);
            var mapper = new CharacterMapper();

            var mappedCharacter = mapper.Map(character, CreateUrlHelper("http://localhost/api/characters/1"));


            Assert.AreEqual(1, mappedCharacter.Allegiances.Count());
            Assert.AreEqual("http://localhost/api/houses/1", mappedCharacter.Allegiances.ElementAt(0));
        }
Exemplo n.º 18
0
        public async Task <Character> GetCharacterAsync(IAuthenticationScope authenticationScope, CharacterKind characterKind)
        {
            var mapper      = new CharacterMapper();
            var artisanSlug = EnumConversionHelper.CharacterIdentifierToString(characterKind);

            using (var client = CreateClient(authenticationScope))
            {
                var characterClass = await client.GetCharacterClassAsync(artisanSlug);

                /* GetApiSkill only extends active skills with runes, all the other properties are already retrieved via GetCharacterClass */
                var activeApiSkills = new List <CharacterApiSkillDto>();
                foreach (var skill in characterClass.Skills.Actives)
                {
                    var apiSkill = await client.GetApiSkillAsync(artisanSlug, skill.Slug);

                    activeApiSkills.Add(apiSkill);
                }

                mapper.Actives = activeApiSkills;
                return(mapper.Map(characterClass));
            }
        }
        public void GivenThatCharacterHasIdentifierOfOne_WhenTryingToMapCharacter_ThenMappedCharacterUrlIsCorrectWithIdentifierInIt()
        {
            var character = MockRepository.GenerateMock<ICharacter>();
            character.Stub(x => x.Identifier).Return(1);
            var mapper = new CharacterMapper();

            var mappedCharacter = mapper.Map(character, CreateUrlHelper("http://localhost/api/characters/1"));

            Assert.AreEqual("http://localhost/api/characters/1", mappedCharacter.URL);
        }
        public void GivenThatCharacterIsNull_WhenTryingToMapIt_ThenArgumentNullExceptionIsThrown()
        {
            var urlHelper = CreateUrlHelper("http://localhost/api/characters/1");
            var mapper = new CharacterMapper();

            var mappedCharacter = mapper.Map(null, urlHelper);
        }
        public void GivenThatCharacterHasFather_WhenTryingToMapCharacter_ThenMappedCharacterFatherContainsCorrectUrl()
        {
            var father = MockRepository.GenerateMock<ICharacter>();
            father.Stub(x => x.Identifier).Return(2);
            var character = MockRepository.GenerateMock<ICharacter>();
            character.Stub(x => x.Identifier).Return(1);
            character.Stub(x => x.Father).Return(father);
            var mapper = new CharacterMapper();

            var mappedCharacter = mapper.Map(character, CreateUrlHelper("http://localhost/api/characters/1"));

            Assert.AreEqual($"http://localhost/api/characters/{character.Father.Identifier}", mappedCharacter.Father);
        }
        public void GivenThatCharacterWasBorn_WhenTryingToMapCharacter_ThenMappedCharacterHasSameBornData()
        {
            var character = MockRepository.GenerateMock<ICharacter>();
            character.Stub(x => x.Identifier).Return(1);
            character.Stub(x => x.Born).Return("someYear");
            var mapper = new CharacterMapper();

            var mappedCharacter = mapper.Map(character, CreateUrlHelper("http://localhost/api/characters/1"));

            Assert.AreEqual(character.Born, mappedCharacter.Born);
        }
        public void GivenThatUrlHelperIsNull_WhenTryingToMapCharacter_ThenArgumentNullExceptionIsThrown()
        {
            var character = MockRepository.GenerateMock<ICharacter>();
            character.Stub(x => x.Identifier).Return(1);
            var mapper = new CharacterMapper();

            var mappedCharacter = mapper.Map(character, null);
        }