public async void ShouldReturnBadRequestWhenUnitIsntFound() { int unitId = 1; decimal dataPointValue = 3.14M; IDataPointRepository dataPointRepository = Mock.Of<IDataPointRepository>(); IDeviceRepository deviceRepository = Mock.Of<IDeviceRepository>(); PublishController controller = new PublishController(dataPointRepository, deviceRepository); IHttpActionResult result = await controller.CreateDataPoint(unitId, dataPointValue); var response = result as BadRequestErrorMessageResult; Assert.NotNull(response); Assert.Equal("Unit not found.", response.Message); }
public async void ShouldReturnOkWhenGivenAnExistingUnit() { int unitId = 1; decimal dataPointValue = 3.14M; Mock<IDeviceRepository> deviceRepositoryMock = new Mock<IDeviceRepository>(); deviceRepositoryMock.Setup(device => device.GetUnitAsync(It.IsAny<int>())) .Returns(Task.FromResult(new Domain.Unit())); IDataPointRepository dataPointRepository = Mock.Of<IDataPointRepository>(); IDeviceRepository deviceRepository = deviceRepositoryMock.Object; PublishController controller = new PublishController(dataPointRepository, deviceRepository); IHttpActionResult result = await controller.CreateDataPoint(unitId, dataPointValue); Assert.IsType<OkResult>(result); }