Ejemplo n.º 1
0
        public ActionResult <SingleDiceRollComponent> PostSingleWithCommand([FromBody] SingleDiceRollComponent component)
        {
            if (component.SelectedCommand == null)
            {
                return(BadRequest("No selected command provided."));
            }

            var request = component.SelectedCommand.Payload.ExecutionData.ToObject <DiceRollRequest>();

            if (request == null || request.RollCount == 0 || !Enum.TryParse(typeof(DieType), request.DieType, out var dieType))
            {
                return(BadRequest("Invalid payload"));
            }

            var rolls = _manager.RollDie((DieType)dieType, request.RollCount);

            component.RollValues = rolls.Select(x => x.RollValue).ToList();
            component.AvailableCommands.Clear();
            component.AvailableCommands.Add(GetNewSingleRollComponent(component.DieType));
            return(component);
        }
Ejemplo n.º 2
0
        public void PostSingleWithCommand_Returns_expected()
        {
            //Arrange
            var rolls   = _fixture.CreateMany <Die>().ToList();
            var command = new CommandComponent
            {
                CommandName  = "RollDice",
                FriendlyName = "Roll Dice",
                IsEnabled    = true,
                IsVisible    = true,
                Payload      = new CommandPayload
                {
                    ExecutionData = JObject.FromObject(new DiceRollRequest {
                        DieType = "D12", RollCount = 1
                    })
                }
            };

            var request = new SingleDiceRollComponent
            {
                DieType           = "D12",
                SelectedCommand   = command,
                AvailableCommands = new List <CommandComponent> {
                    command
                }
            };

            var expected = request;

            _manager.Setup(x => x.RollDie(It.IsAny <DieType>(), It.IsAny <uint>()))
            .Returns(rolls);

            //Act
            var actual = _sut.PostSingleWithCommand(request);

            //Assert
            expected.RollValues = rolls.Select(x => x.RollValue).ToList();
            actual.Value.Should().BeEquivalentTo(expected);
        }