public async Task GetEnvironment_WhenCalled_MissingQueryParameters_ReturnsBadRequest() { var mockedRepo = new Mock <IHomeRepository>(); var room = new Room() { Name = "test_room_1", Id = Guid.Parse("00000000-0000-0000-0000-000000000001") }; var startDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); var endDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); mockedRepo.Setup(repo => repo.GetRoom(Guid.Parse("00000000-0000-0000-0000-000000000001"))).ReturnsAsync(room); mockedRepo.Setup(repo => repo.GetEnvironmentReadings(Guid.Parse("00000000-0000-0000-0000-000000000001"), startDate, endDate)).ReturnsAsync((List <Environment>)null); 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.GetEnvironment("00000000-0000-0000-0000-000000000001", startDate, endDate); var contentResult = result as BadRequestResult; Assert.NotNull(contentResult); }
public async Task GetEnvironment_WhenCalled_UnknownRoom_ReturnsNotFound() { var mockedRepo = new Mock <IHomeRepository>(); var room = new Room() { Name = "test_room_1", Id = Guid.Parse("00000000-0000-0000-0000-000000000001") }; var startDate = DateTime.UtcNow.Subtract(new TimeSpan(1, 0, 0, 0)); var endDate = DateTime.UtcNow; mockedRepo.Setup(repo => repo.GetRoom(Guid.Parse("00000000-0000-0000-0000-000000000001"))).ReturnsAsync((Room)null); mockedRepo.Setup(repo => repo.GetEnvironmentReadings(Guid.Parse("00000000-0000-0000-0000-000000000001"), startDate, endDate)).ReturnsAsync((List <Environment>)null); 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.GetEnvironment("00000000-0000-0000-0000-000000000001", startDate, endDate); var contentResult = result as NotFoundResult; Assert.NotNull(contentResult); }