public async Task Logs_InstanceNotAvailable_NotFoundReturned() { //Arrange var fakeMediator = Substitute.For <IMediator>(); fakeMediator .Send( Arg.Any <GetInstanceByNameQuery>(), default) .Returns((Dogger.Domain.Models.Instance)null); var mapper = AutoMapperFactory.CreateValidMapper(); var controller = new ClustersController( fakeMediator, mapper); //Act var result = await controller.Logs("some-instance-name"); //Assert var response = result as NotFoundObjectResult; Assert.IsNotNull(response); }
public async Task Logs_InstanceAvailable_LogsForInstanceReturned() { //Arrange var fakeMediator = Substitute.For <IMediator>(); fakeMediator .Send(Arg.Is <GetContainerLogsQuery>(arg => arg.InstanceName == "some-instance-name")) .Returns(new[] { new ContainerLogsResponse( new ContainerResponse() { Id = "some-id", Names = new[] { "some-name" }, Image = "some-image" }, "some-logs") }); fakeMediator .Send( Arg.Is <GetInstanceByNameQuery>(arg => arg.Name == "some-instance-name"), default) .Returns(new Dogger.Domain.Models.Instance()); var mapper = AutoMapperFactory.CreateValidMapper(); var controller = new ClustersController( fakeMediator, mapper); //Act var result = await controller.Logs("some-instance-name"); //Assert var response = result.ToObject <LogsResponse[]>(); Assert.IsNotNull(response); Assert.AreEqual(1, response.Length); var logsResponse = response.Single(); Assert.AreEqual("some-id", logsResponse.ContainerId); Assert.AreEqual("some-image", logsResponse.ContainerImage); Assert.AreEqual("some-logs", logsResponse.Logs); }
public async Task Logs_ProtectedInstanceProvided_UnauthorizedReturned() { //Arrange var fakeMediator = Substitute.For <IMediator>(); var mapper = AutoMapperFactory.CreateValidMapper(); var controller = new ClustersController( fakeMediator, mapper); //Act var result = await controller.Logs("main-protected"); //Assert var response = result as UnauthorizedObjectResult; Assert.IsNotNull(response); }