Пример #1
0
        public async Task RetrieveNewCharacterIdFromRepository()
        {
            var expectedCharacter = new Domain.RpgCharacter();

            repository.Create().Returns(expectedCharacter);

            var response = await handler.Handle(new CreateRpgCharacterRequest(), CancellationToken.None);

            response.CharacterId.Should().Be(expectedCharacter.Id);
        }
Пример #2
0
        public async Task <RpgCharacter> Create()
        {
            var newCharacter = new Domain.RpgCharacter();
            var newRecord    = ToRecord(newCharacter);
            var storedEntity = await context.RpgCharacters.AddAsync(newRecord);

            await context.SaveChangesAsync();

            newCharacter = FromRecord(storedEntity.Entity);
            return(newCharacter);
        }
        public async Task ReturnTheCharacterRequested()
        {
            var givenCharacter    = new Domain.RpgCharacter();
            var expectedCharacter = new HttpModels.RpgCharacter {
                Level = givenCharacter.Level, Health = givenCharacter.Health
            };

            mediator.Send(Arg.Any <GetRpgCharacterRequest>()).Returns(new GetRpgCharacterResponse(givenCharacter));
            hashids.Decode(Arg.Any <string>()).Returns(new[] { NumericId });

            var actionResult = await controller.Get(StringId);

            await mediator.Received().Send(Arg.Is <GetRpgCharacterRequest>(req => req.Id == NumericId));

            hashids.Received().Decode(StringId);
            actionResult.Result.Should().BeOfType <OkObjectResult>();
            var correctResult = actionResult.Result as OkObjectResult;

            correctResult?.Value.Should().BeEquivalentTo(expectedCharacter);
        }
Пример #4
0
 private RpgCharacter ToHttpModel(Domain.RpgCharacter character) =>
 new RpgCharacter
 {
     Health = character.Health, Level = character.Level
 };
 public GetRpgCharacterResponse(Domain.RpgCharacter character)
 {
     Character = character;
 }