コード例 #1
0
        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>());
        }
コード例 #2
0
        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>();
        }
コード例 #3
0
        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>());
        }
コード例 #4
0
        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();
        }
コード例 #5
0
        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>());
        }
コード例 #6
0
        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?>());
        }