public void WhenDeleted_DoesNotCallContainerExists() { // Arrange var mockDockerClient = Substitute.For <IDockerClient>(); var mockCommandFactory = Substitute.For <IRunCommands>(); var sut = new DockerContainer(mockDockerClient, mockCommandFactory, ExpectedId, new DockerPortMapping[0]) { Deleted = true }; // Act Assert.CatchAsync(async() => await sut.MonitorStatsFor(TimeSpan.Zero)); // Assert mockDockerClient.DidNotReceive().ContainerExistsAsync(Arg.Any <string>()); }
public void WhenDeleted_ThrowsDockerContainerDeletedException() { // Arrange var mockDockerClient = Substitute.For <IDockerClient>(); var mockCommandFactory = Substitute.For <IRunCommands>(); var sut = new DockerContainer(mockDockerClient, mockCommandFactory, ExpectedId, new DockerPortMapping[0]) { Deleted = true }; // Act var exception = Assert.CatchAsync(async() => await sut.MonitorStatsFor(TimeSpan.Zero)); // Assert exception.Should().BeOfType <DockerContainerDeletedException>(); }
public async Task WhenMonitorStatsForFails_CallsContainerExists() { // Arrange var mockDockerClient = BuildMockDockerClient(true, true); var mockCommand = MotherFor.CommandWrapper.ThatFails().WithExitCode(-1).Build(); var mockCommandFactory = MotherFor.CommandFactory .ForWorkingDirectory(_workingDirectory) .ForCommandReturn(DockerCommands.Container.GetStats(ExpectedId), mockCommand) .Build(); var sut = new DockerContainer(mockDockerClient, mockCommandFactory, ExpectedId, new DockerPortMapping[0]); // Act Assert.CatchAsync(async() => await sut.MonitorStatsFor(TimeSpan.Zero)); // Assert await mockDockerClient.Received(1).ContainerExistsAsync(Arg.Any <string>()); }
public void WhenContainerExistsFails_ItDoesNotSetDeletedState() { // Arrange var mockDockerClient = BuildMockDockerClient(false, true); var mockCommand = MotherFor.CommandWrapper.ThatFails().WithExitCode(-1).Build(); var mockCommandFactory = MotherFor.CommandFactory .ForWorkingDirectory(_workingDirectory) .ForCommandReturn(DockerCommands.Container.GetStats(ExpectedId), mockCommand) .Build(); var sut = new DockerContainer(mockDockerClient, mockCommandFactory, ExpectedId, new DockerPortMapping[0]); // Act Assert.CatchAsync(async() => await sut.MonitorStatsFor(TimeSpan.Zero)); // Assert sut.Deleted.Should().BeFalse(); }
public async Task WhenMonitorStatsForSucceeds_DoesNotCallContainerExists() { // Arrange var mockDockerClient = BuildMockDockerClient(true, true); var mockCommand = MotherFor.CommandWrapper.ThatSucceeds() .WithOutput(MotherFor.ContainerStatsJson(1m, 1m).Build()) .Build(); var mockCommandFactory = MotherFor.CommandFactory .ForWorkingDirectory(_workingDirectory) .ForCommandReturn(DockerCommands.Container.GetStats(ExpectedId), mockCommand) .Build(); var sut = new DockerContainer(mockDockerClient, mockCommandFactory, ExpectedId, new DockerPortMapping[0]); // Act await sut.MonitorStatsFor(TimeSpan.Zero); // Assert await mockDockerClient.DidNotReceive().ContainerExistsAsync(Arg.Any <string>()); }
public async Task WhenNotDeleted_CallsMonitorStatsForCommand() { // Arrange var mockDockerClient = BuildMockDockerClient(true, true); var mockCommand = MotherFor.CommandWrapper .ThatSucceeds() .WithOutput(MotherFor.ContainerStatsJson(1m, 1m).Build()) .Build(); var mockCommandFactory = MotherFor.CommandFactory .ForWorkingDirectory(_workingDirectory) .ForCommandReturn(DockerCommands.Container.GetStats(ExpectedId), mockCommand) .Build(); var sut = new DockerContainer(mockDockerClient, mockCommandFactory, ExpectedId, new DockerPortMapping[0]); // Act await sut.MonitorStatsFor(TimeSpan.Zero); // Assert mockCommandFactory.Received().RunCommand(DockerCommands.Container.GetStats(ExpectedId), _workingDirectory, Arg.Any <CancellationToken?>()); }