예제 #1
0
        public void CharacterRepository_Get()
        {
            //seed a character
            var character = _repoHelper.SeedCharacters().First();

            //get the character
            var characterDb = _characterRepo.Get(character.Id);

            //check to see if the db returns what we gave it
            var comparer = new PropertyComparer <Character>();

            Assert.IsTrue(comparer.Equals(character, characterDb));
        }
        public FullCharacterDTO Get(string playerName, string characterId)
        {
            var resp = new HttpResponseMessage();

            try
            {
                var character = _characterRepository.Get(characterId);
                if (character == null)
                {
                    resp.StatusCode   = HttpStatusCode.NotFound;
                    resp.Content      = new StringContent(string.Format("Character not found with Id = {0}", characterId));
                    resp.ReasonPhrase = "Character Not Found";
                    throw new HttpResponseException(resp);
                }
                if (character.PlayerAccountName != playerName)
                {
                    resp.StatusCode   = HttpStatusCode.Conflict;
                    resp.Content      = new StringContent(string.Format("Character found but is not associated with the given player Id"));
                    resp.ReasonPhrase = "Mismatch character Id and player Id";
                    throw new HttpResponseException(resp);
                }
                var characterDTO = CharacterMapper.FullDTOFromCharacter(character);
                return(characterDTO);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void Handle(RollAbilityScoresCommand command)
        {
            var character = repository.Get(command.CharacterUiD);

            Guard.With <CharacterNotFoundException>()
            .Against(
                character == null,
                command.CharacterUiD);

            Guard.With <InvalidCharacterStateException>()
            .Against(
                character.IsCompleted(),
                command.CharacterUiD);

            var characterWithRolledAbilityScores = character.SetStrength(command.Strength)
                                                   .SetDexterity(command.Dexterity)
                                                   .SetCharisma(command.Charisma)
                                                   .SetWisdom(command.Wisdom)
                                                   .SetConstitution(command.Constitution)
                                                   .SetIntelligence(command.Intelligence);

            characterWithRolledAbilityScores.RegisterDomainEvent(
                new AbilityScoresRolled(
                    command.CharacterUiD,
                    command.Strength,
                    command.Dexterity,
                    command.Constitution,
                    command.Intelligence,
                    command.Wisdom,
                    command.Charisma));

            repository.Update(characterWithRolledAbilityScores);

            unitOfWork.Commit();
        }
예제 #4
0
        public void CharacterRepository_AddCharacter_ValidCall()
        {
            //Arrange
            List <CharacterDM> charList = CreateTestData.GetListOfCharacters();

            var mockSet = new Mock <DbSet <CharacterDM> >()
                          .SetupData(charList, o =>
            {
                return(charList.Single(x => x.Character_id.CompareTo(o.First()) == 0));
            });

            using (var mockContext = AutoMock.GetLoose())
            {
                mockContext.Mock <CharacterContext>()
                .Setup(x => x.Set <CharacterDM>()).Returns(mockSet.Object);
                ICharacterRepository toTest = mockContext.Create <CharacterRepository>();
                var expected = CreateTestData.getSampleCharacter();
                expected.Character_id = Guid.Parse("33855fe6-807a-46e3-850f-ada7dacfc435");

                //Act
                toTest.Add(expected);
                var actual = toTest.Get(expected.Character_id);

                //Assert
                actual.Should().NotBeNull();
                expected.Should().NotBeNull();
                actual.Should().BeOfType <CharacterDM>();
                expected.Should().BeOfType <CharacterDM>();
                actual.Should().BeEquivalentTo(expected);
            }
        }
예제 #5
0
        public void CharacterRepository_GetCharacter_ValidCall()
        {
            //Arrange
            //1. Create the test data.
            List <CharacterDM> charList = CreateTestData.GetListOfCharacters();

            //2. Create a mock set, one that properly responds to EntityFramework's .Find()
            //from the charList, return the first object that has a character_id that matches the given character_id.
            var mockSet = new Mock <DbSet <CharacterDM> >()
                          .SetupData(charList, o =>
            {
                return(charList.Single(x => x.Character_id.CompareTo(o.First()) == 0));
            });

            using (var mockContext = AutoMock.GetLoose())
            {
                //Act
                //3. Use the mockSet to properly create the mockContext.
                mockContext.Mock <CharacterContext>()
                .Setup(x => x.Set <CharacterDM>()).Returns(mockSet.Object);

                //4. Create a instance of the Character repository, injecting mockContext via the constructor.
                ICharacterRepository toTest = mockContext.Create <CharacterRepository>();
                var expected = CreateTestData.getSampleCharacter();
                var actual   = toTest.Get(expected.Character_id);


                //Assert
                actual.Should().NotBeNull();
                expected.Should().NotBeNull();
                actual.Should().BeOfType <CharacterDM>();
                expected.Should().BeOfType <CharacterDM>();
                actual.Should().BeEquivalentTo(expected);
            }
        }
        public MarvelQuery(
            ICharacterRepository characterRepository,
            IComicRepository comicRepository,
            IEventRepository eventRepository,
            ISerieRepository serieRepository)
        {
            Field <CharacterType>(
                "character",
                arguments: new QueryArguments(new QueryArgument <IntGraphType> {
                Name = "marvelId"
            }),
                resolve: context => characterRepository.Get(context.GetArgument <int>("marvelId")));
            Field <CharacterType>(
                "characters",
                resolve: context => characterRepository.GetAll());

            Field <ListGraphType <ComicType> >(
                "comics",
                resolve: context => comicRepository.GetAll());

            Field <EventType>(
                "events",
                resolve: context => eventRepository.GetAll());

            Field <SerieType>(
                "series",
                resolve: context => serieRepository.GetAll());
        }
예제 #7
0
        public async Task <IActionResult> GetCharactersFromMongo(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("GetCharactersFromMongo called");

            return(new OkObjectResult(await _characterRepository.Get()));
        }
예제 #8
0
        public IActionResult Edit(int id)
        {
            // Create an edit view
            // Look up cat object from catId in the database
            // Show an edit view to the user, displaying the cat object
            Character c = characterRepository.Get(id);


            return(View("Edit", ViewModelCreator.EditCharacterVm(raceRepository, c)));
        }
        public void Handle(ChooseCharacterRaceCommand command)
        {
            var character = repository.Get(command.CharacterUiD);

            Guard.With <CharacterNotFoundException>().Against(character is null, command.CharacterUiD);
            Guard.With <InvalidCharacterStateException>()
            .Against(
                character.IsCompleted(),
                command.CharacterUiD);

            character.SetRace(command.Race);

            character.RegisterDomainEvent(new CharacterRaceChosen(command.Race, command.CharacterUiD));

            repository.Update(character);

            unitOfWork.Commit();
        }
예제 #10
0
 public async Task <IEnumerable <Character> > Get([FromQuery] string house, [FromServices] ICharacterRepository characterRepository)
 {
     return(await characterRepository.Get(house));
 }
예제 #11
0
 public CharacterDto Handle(GetCharacterByIdQuery query) => repository.Get(query.CharacterId).ToDto();
        public async Task <CharacterDto> Handle(GetCharacterQuery query, CancellationToken cancellationToken)
        {
            var character = await _characterRepository.Get(query.CharacterId);

            return(_mapper.Map <CharacterDto>(character));
        }
예제 #13
0
 public IEnumerable <Character> Get()
 {
     return(_globalService.Get().Select(u => u.ToClient()));
 }
예제 #14
0
 public IEnumerable <C.Character> Get()
 {
     return(_service.Get());
 }