Exemplo n.º 1
0
        public async Task Get_Command_Success()
        {
            // Arrange
            var fakeId          = 1;
            var fakeToken       = "token";
            var fakeRequest     = "request";
            var fakeDescription = "description";
            var fakeResponse    = "response";

            var fakeCommand = GetCommandFake(fakeId, fakeToken, fakeRequest, fakeDescription, fakeResponse);

            _commandRepositoryMock.Setup(x => x.GetCommandAsync(It.IsAny <int>()))
            .Returns(Task.FromResult(fakeCommand));

            // Act
            var commandsController = new CommandsController(
                _commandRepositoryMock.Object
                );

            var actionResult = await commandsController.GetCommandByIdAsync(fakeId);

            // Assert
            Assert.AreEqual((actionResult.Result as OkObjectResult).StatusCode, (int)System.Net.HttpStatusCode.OK);
            Assert.AreEqual((((ObjectResult)actionResult.Result).Value as Command).Id, fakeCommand.Id);
        }
        public void GetCommandById_Returns404NotFound_WhenNonExistentIDProvided()
        {
            // Arrange
            _mockApiRepo.Setup(repo => repo.GetCommandByIdAsync(0)).Returns(() => null);
            var controller = new CommandsController(_mockApiRepo.Object, _mapper);

            // Act
            var result = controller.GetCommandByIdAsync(1).Result;

            // Assert

            Assert.IsType <NotFoundResult>(result.Result);
        }
Exemplo n.º 3
0
        public async Task Get_Command_With_Zero_Id_Should_Return_Bad_Request()
        {
            //Arrange
            var fakeCommandId = 0;

            // Act
            var commandsController = new CommandsController(
                _commandRepositoryMock.Object
                );

            var actionResult = (await commandsController.GetCommandByIdAsync(fakeCommandId)).Result as BadRequestResult;

            // Assert
            Assert.NotNull(actionResult);
        }
Exemplo n.º 4
0
        public async Task Get_Command_Which_Does_Not_Exist()
        {
            // Arrange
            var fakeCommandId = 1;

            _commandRepositoryMock.Setup(x => x.GetCommandAsync(It.IsAny <int>()))
            .Returns(Task.FromResult((Command)null));

            // Act
            var commandsController = new CommandsController(
                _commandRepositoryMock.Object
                );

            var actionResult = (await commandsController.GetCommandByIdAsync(fakeCommandId)).Result as NotFoundResult;

            // Assert
            Assert.NotNull(actionResult);
        }