Example #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.KillAsync());

            // Assert
            mockDockerClient.DidNotReceive().ContainerExistsAsync(Arg.Any <string>());
        }
Example #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.KillAsync());

            // Assert
            exception.Should().BeOfType <DockerContainerDeletedException>();
        }
        public void WhenRemoveFails_ThrowsDockerCommandException()
        {
            // 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
            var exception = Assert.CatchAsync(async() => await sut.KillAsync());

            // Assert
            exception.Should().BeOfType <DockerCommandException>();
        }
Example #4
0
        public async Task WhenKillFails_CallsContainerExists()
        {
            // Arrange
            var mockDockerClient = BuildMockDockerClient(true, true);

            var mockCommand = MotherFor.CommandWrapper.ThatFails().WithExitCode(-1).Build();

            var mockCommandFactory = MotherFor.CommandFactory
                                     .ForWorkingDirectory(_workingDirectory)
                                     .ForCommandReturn(DockerCommands.Container.Kill(ExpectedId), mockCommand)
                                     .Build();

            var sut = new DockerContainer(mockDockerClient, mockCommandFactory, ExpectedId, new DockerPortMapping[0]);

            // Act
            Assert.CatchAsync(async() => await sut.KillAsync());

            // Assert
            await mockDockerClient.Received(1).ContainerExistsAsync(Arg.Any <string>());
        }
Example #5
0
        public async Task WhenKillSucceeds_DoesNotCallContainerExists()
        {
            // Arrange
            var mockDockerClient = BuildMockDockerClient(true, true);

            var mockCommand = MotherFor.CommandWrapper.ThatSucceeds().Build();

            var mockCommandFactory = MotherFor.CommandFactory
                                     .ForWorkingDirectory(_workingDirectory)
                                     .ForCommandReturn(DockerCommands.Container.Kill(ExpectedId), mockCommand)
                                     .Build();

            var sut = new DockerContainer(mockDockerClient, mockCommandFactory, ExpectedId, new DockerPortMapping[0]);

            // Act
            await sut.KillAsync();

            // Assert
            await mockDockerClient.DidNotReceive().ContainerExistsAsync(Arg.Any <string>());
        }
Example #6
0
        public async Task WhenNotDeleted_CallsKillCommand()
        {
            // Arrange
            var mockDockerClient = BuildMockDockerClient(true, true);

            var mockCommand = MotherFor.CommandWrapper.ThatSucceeds().Build();

            var mockCommandFactory = MotherFor.CommandFactory
                                     .ForWorkingDirectory(_workingDirectory)
                                     .ForCommandReturn(DockerCommands.Container.Kill(ExpectedId), mockCommand)
                                     .Build();

            var sut = new DockerContainer(mockDockerClient, mockCommandFactory, ExpectedId, new DockerPortMapping[0]);

            // Act
            await sut.KillAsync();

            // Assert
            mockCommandFactory.Received(1).RunCommand(DockerCommands.Container.Kill(ExpectedId), _workingDirectory, Arg.Any <CancellationToken?>());
        }
Example #7
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.Kill(ExpectedId), mockCommand)
                                     .Build();

            var sut = new DockerContainer(mockDockerClient, mockCommandFactory, ExpectedId, new DockerPortMapping[0]);

            // Act
            Assert.CatchAsync(async() => await sut.KillAsync());

            // Assert
            sut.Deleted.Should().BeFalse();
        }