public async void PutRoom_ReturnsOk_WhenSuccessful() { mockMapper.Setup(m => m.Map <Room>(It.IsAny <RoomViewModel>())) .Returns(kitchen); mockMapper.Setup(m => m.Map <RoomViewModel>(It.IsAny <Room>())) .Returns(kitchenViewModel); mockRepo.Setup(r => r.GetRoomById(kitchenId)) .Returns(kitchen); mockRepo.Setup(r => r.SaveAllAsync()) .Returns(Task.FromResult(true)); var result = await controller.Put(kitchenId, kitchenViewModel); var okResult = result.Should().BeAssignableTo <OkObjectResult>().Subject; var viewModel = okResult.Value.Should().BeAssignableTo <RoomViewModel>().Subject; viewModel.Name.Should().Be("Kitchen"); }
public async Task Put_WhenCalled_BadObject_ReturnsBadRequest() { var mockedRepo = new Mock <IHomeRepository>(); var room = new Room() { Name = "test_room_1" }; mockedRepo.Setup(repo => repo.EditRoom(room)).ReturnsAsync(false); var mockedListenerClient = new Mock <ISensorListenerAPI>(); mockedListenerClient.Setup(client => client.NotifyHomeyTopic <double>("test", 0)); var controller = new RoomsController(mockedRepo.Object, mockedListenerClient.Object); var result = await controller.Put(room); var contentResult = result as BadRequestResult; Assert.NotNull(contentResult); }