public void PostCommandItemObjectCountIncrementWhenValidObject() { //Arrange var command = new CommandCreateDto { HowTo = "Do Somethting", Platform = "Some Platform", Line = "Some Command" }; var oldCount = _dbContext.Commands.Count(); //Act var result = _controller.CreateCommand(command); //Assert Assert.Equal(oldCount + 1, _dbContext.Commands.Count()); }
public void CreateCommand_ReturnsCorrectObjectType_WhenValidOjbectGiven() { mockRepo.Setup(repo => repo.GetCommandById(1)).Returns(GetCommands(1)[0]); var controller = new CommandsController(mockRepo.Object, mapper); var result = controller.CreateCommand(new CommandCreateDto { }); Assert.IsType <CreatedAtRouteResult>(result); }
public void CreateCommand_Returns201Created_WhenValidObjectSubmitted() { mockRepo.Setup(repo => repo.GetCommandById(1)).Returns(new Command { Id = 1, HowTo = "mock", Platform = "Mock", CommandLine = "Mock" }); var controller = new CommandsController(mockRepo.Object, mapper); var result = controller.CreateCommand(new CommandCreateDto { }); Assert.IsType <CreatedAtRouteResult>(result.Result); }
public void CreateCommand_Returns201Created_WhenValidObjectSubmitted() { //Arrange mockRepo.Setup(repo => repo.GetCommandById(1)).Returns(GetCommand(1)); var controller = new CommandsController(mockRepo.Object, mapper); //Act var result = controller.CreateCommand(new CommandCreateDto()); //Assert Assert.IsType <CreatedAtRouteResult>(result.Result); }
public void CreateCommand_ReturnsCorrectResourceType_WhenValidObjectSubmitted() { //Arrange mockRepo.Setup(repo => repo.GetCommandById(1)).Returns(GetCommand(1)); var controller = new CommandsController(mockRepo.Object, mapper); //Act var result = controller.CreateCommand(new CommandCreateDto()); //Assert Assert.IsType <ActionResult <CommandReadDto> >(result); }
public void CreateCommand_ReturnsCorrectResourceType_WhenValidObjectSubmitted() { mockRepo.Setup(repo => repo.GetCommandById(1)).Returns(new Command { Id = 1, HowTo = "mock", Platform = "Mock", CommandLine = "Mock" }); var controller = new CommandsController(mockRepo.Object, mapper); var result = controller.CreateCommand(new CommandCreateDto { }); Assert.IsType <ActionResult <CommandReadDto> >(result); }
public override void LoadData() { if (AllowedToRun()) { _timedBlockControllers.Add(new TimedBlockController(_timedBlockControllers.Count, true)); //..add blocks by Id, and add times Cmd_SetTimes(BLOCK_TIMES.Split(' ')); } else { } CommandsController.Init(); if (!MyAPIGateway.Multiplayer.IsServer) { CommandsController.CreateCommand("ping", (cmdParams) => { Log.Write("Sending ping to server"); byte[] msgData = MyAPIGateway.Utilities.SerializeToBinary("ping"); MyAPIGateway.Multiplayer.SendMessageToServer(Log.MSG_LOG, msgData, true); }); MyAPIGateway.Multiplayer.RegisterMessageHandler(Log.MSG_LOG, ServerMessageHandler); } #region Block Commands CommandsController.CreateCommand("tbListBlocks", (cmdParams) => { Cmd_ListBlocks(); }, false, true); #endregion #region Timed Block Commands CommandsController.CreateCommand("tbListTimes", (cmdParams) => { Cmd_ListTimes(); }, false, true); CommandsController.CreateCommand("tbGetNextTime", (cmdParams) => { Cmd_GetNextTime(); }, false, true); CommandsController.CreateCommand("tbStatus", (cmdParams) => { Cmd_GetStatus(); }, false, true); CommandsController.CreateCommand("tbEnable", (cmdParams) => { Cmd_Enable(); }); CommandsController.CreateCommand("tbDisable", (cmdParams) => { Cmd_Disable(); }); #endregion }
public void CreateCommand_Returns201CreatedResult_WhenValidObjectSubmitted() { _apiRepoMock.Setup(repo => repo.GetCommandById(1)).Returns(new Command() { Id = 1, HowTo = "mock", Platform = "Mock", CommandLine = "Mock" }); var controller = new CommandsController(_apiRepoMock.Object, _mapper); var actual = controller.CreateCommand(new CommandCreateDto()); Assert.IsType <CreatedAtRouteResult>(actual.Result); }
public void CreateCommand_ReturnsCreatedStatus_WhenValidObjectSubmitted() { _apiRepoMock.Setup(repo => repo.GetCommandById(1)).Returns(new Command() { Id = 1, HowTo = "mock", Platform = "Mock", CommandLine = "Mock" }); var controller = new CommandsController(_apiRepoMock.Object, _mapper); var actual = controller.CreateCommand(new CommandCreateDto()); Assert.IsType <ActionResult <CommandReadDto> >(actual); }
public void CreateCommand_Returns201Created_WhenValidObjectProvided() { // Arrange mockRepository.Setup(repo => repo.GetCommandById(1)).Returns(new Command { Id = 1, HowTo = "Mock", Platform = "Mock", CommandLine = "Mock" }); var controller = new CommandsController(mockRepository.Object, mapper); // Act var result = controller.CreateCommand(new CommandCreateDTO { }); // Assert Assert.IsType <CreatedAtRouteResult>(result.Result); }
public void CreateCommand_Return_OkResult() { //Arrange var commandResponse = new List <Command> { new Command { Id = 1, HowTo = "web api Unit", Line = "create webapi testing", Platform = "asp.net core" }, new Command { Id = 2, HowTo = "Integration testing", Line = "testing", Platform = ".net framework" }, new Command { Id = 3, HowTo = "web api", Line = "create webapi", Platform = "asp.net mvc" }, new Command { Id = 4, HowTo = "razor page", Line = "web ui", Platform = "asp.net framework" } }; var commandDto = new CommandDTO { Id = 5, HowTo = "Add Details", Line = "checking", Platform = "asp.net core" }; var command = new Command { Id = 5, HowTo = "Add Details", Line = "checking", Platform = "asp.net core" }; _commanderMock.Setup(x => x.CreateCommand(It.IsAny <Command>())).Returns(command) .Callback((Command cmd) => { cmd.Id = commandResponse.Count + 1; commandResponse.Add(cmd); }).Verifiable(); var controller = new CommandsController(_commanderMock.Object, _mapperMock, _logger.Object, _telemetryClient); //Act var response = controller.CreateCommand(commandDto); //Assert Assert.IsType <OkObjectResult>(response); }
public void CreateContextTest() { using (var context = new CommanderContext(ContextOptions)) { var sqlRepo = new SqlCommanderRepo(context); var controller = new CommandsController(sqlRepo, getMapper()); var request = new CommandCreateDto { HowTo = "Unit Test 1", Line = "Unit Test 1", Platform = "Unit Test 1" }; var resp = controller.CreateCommand(request); _output.WriteLine($"{resp.ToString()}"); //Assert.IsType(, resp.Result); } }
public void CreateCommand_InvalidData_Return_BadRequestResult() { //Arrange var commandDto = new CommandDTO { Id = 1, HowTo = "Test HowTo can't be more than twenty characteres", Line = "checking", Platform = "asp.net core" }; var command = new Command { Id = 1, HowTo = "Test HowTo can't be more than twenty characteres", Line = "checking", Platform = "asp.net core" }; _commanderMock.Setup(x => x.CreateCommand(command)).Returns(command); var controller = new CommandsController(_commanderMock.Object, _mapperMock, _logger.Object, _telemetryClient); controller.ModelState.AddModelError("test", "Error Message"); //Act var response = controller.CreateCommand(commandDto); //Assert Assert.IsType <BadRequestResult>(response); }
public void CreateCommand_ReturnCorrectResourceType_WhenValidObjectSubmitted() { // Arrange _mockRespository .Setup(repo => repo.GetCommandById(1)) .Returns(new Command { Id = 1, HowTo = "Mock", Platform = "Mock", CommandLine = "Mock" }); var controller = new CommandsController(_mockRespository.Object, _mapper); // Act var result = controller.CreateCommand(new CommandCreateDTO { }); // Assert Assert.IsType <ActionResult <CommandReadDTO> >(result); }