Example #1
0
        public async Task ConnectionDetails_InstanceNotAvailable_NotFoundReturned()
        {
            //Arrange
            var fakeMediator = Substitute.For <IMediator>();

            fakeMediator
            .Send(
                Arg.Is <GetLightsailInstanceByNameQuery>(arg =>
                                                         arg.Name == "some-instance-name"),
                default)
            .Returns((Instance)null);

            var mapper = AutoMapperFactory.CreateValidMapper();

            var controller = new ClustersController(
                fakeMediator,
                mapper);

            controller.FakeAuthentication("some-identity-name");

            //Act
            var result = await controller.ConnectionDetails("some-instance-name");

            //Assert
            var response = result as NotFoundObjectResult;

            Assert.IsNotNull(response);
        }
Example #2
0
        public async Task Destroy_ClusterNotFound_ClusterNotFoundValidationErrorReturned()
        {
            //Arrange
            var fakeClusterId = Guid.NewGuid();

            var fakeMediator = Substitute.For <IMediator>();

            fakeMediator
            .Send(Arg.Is <GetClusterForUserQuery>(args =>
                                                  args.ClusterId == fakeClusterId))
            .Returns((Cluster)null);

            fakeMediator
            .Send(Arg.Any <EnsureUserForIdentityCommand>())
            .Returns(new User());

            var mapper = AutoMapperFactory.CreateValidMapper();

            var controller = new ClustersController(
                fakeMediator,
                mapper);

            controller.FakeAuthentication("some-identity-name");

            //Act
            var result = await controller.Destroy(fakeClusterId);

            //Assert
            var response = result.GetValidationProblemDetails();

            Assert.IsNotNull(response);

            Assert.AreEqual("CLUSTER_NOT_FOUND", response.Type);
        }
Example #3
0
        public async Task Deploy_WindowsPathSeparatorsInFiles_DeployToClusterCommandFiredWithUnixPathSeparatorsInFiles()
        {
            //Arrange
            var fakeMediator = Substitute.For <IMediator>();

            fakeMediator
            .Send(Arg.Any <EnsureUserForIdentityCommand>())
            .Returns(new User());

            fakeMediator
            .Send(Arg.Any <GetRepositoryLoginForUserQuery>())
            .Returns(new RepositoryLoginResponse(
                         "dummy",
                         "dummy"));

            fakeMediator
            .Send(Arg.Any <EnsureRepositoryWithNameCommand>())
            .Returns(new RepositoryResponse(
                         "dummy",
                         "dummy",
                         new AmazonUser(),
                         new AmazonUser()));

            var fakeMapper = Substitute.For <IMapper>();

            var controller = new ClustersController(
                fakeMediator,
                fakeMapper);

            controller.FakeAuthentication("some-identity-name");

            //Act
            var result = await controller.Deploy(new DeployToClusterRequest()
            {
                DockerComposeYmlFilePaths = new[] { "some-docker-compose-contents" },
                Files = new []
                {
                    new FileRequest()
                    {
                        Contents = Array.Empty <byte>(),
                        Path     = "some\\windows\\path\\separator\\path"
                    }
                }
            });

            //Assert
            Assert.IsNotNull(result);

            await fakeMediator
            .Received(1)
            .Send(Arg.Is <DeployToClusterCommand>(args =>
                                                  args.Files.Single().Path == "some/windows/path/separator/path"));
        }
Example #4
0
        public async Task Deploy_UserIdGiven_DeployToClusterCommandFiredWithAuthorizationFromRepository()
        {
            //Arrange
            var readUser  = new AmazonUser();
            var writeUser = new AmazonUser();

            var fakeMediator = Substitute.For <IMediator>();

            fakeMediator
            .Send(Arg.Any <EnsureUserForIdentityCommand>())
            .Returns(new User());

            fakeMediator
            .Send(Arg.Is <GetRepositoryLoginForUserQuery>(arg =>
                                                          arg.AmazonUser == readUser))
            .Returns(new RepositoryLoginResponse(
                         "some-username",
                         "some-password"));

            fakeMediator
            .Send(Arg.Is <EnsureRepositoryWithNameCommand>(arg => arg.UserId != null))
            .Returns(new RepositoryResponse(
                         "dummy",
                         "some-host-name",
                         readUser,
                         writeUser));

            var fakeMapper = Substitute.For <IMapper>();

            var controller = new ClustersController(
                fakeMediator,
                fakeMapper);

            controller.FakeAuthentication("some-identity-name");

            //Act
            var result = await controller.Deploy(new DeployToClusterRequest()
            {
                DockerComposeYmlFilePaths = new[] { "some-docker-compose-contents" }
            });

            //Assert
            Assert.IsNotNull(result);

            await fakeMediator
            .Received(1)
            .Send(Arg.Is <DeployToClusterCommand>(args =>
                                                  args.Authentication.Single().Username == "some-username" &&
                                                  args.Authentication.Single().Password == "some-password" &&
                                                  args.Authentication.Single().RegistryHostName == "some-host-name"));
        }
Example #5
0
        public async Task ConnectionDetails_ConnectionDetailsPresentOnInstance_ConnectionDetailsReturned()
        {
            //Arrange
            var fakeMediator = Substitute.For <IMediator>();

            fakeMediator
            .Send(
                Arg.Is <GetConnectionDetailsQuery>(arg =>
                                                   arg.ClusterId == "some-instance-name"),
                default)
            .Returns(new Dogger.Domain.Queries.Clusters.GetConnectionDetails.ConnectionDetailsResponse(
                         "some-ip-address",
                         "some-host-name",
                         new []
            {
                new ExposedPort()
                {
                    Port     = 23,
                    Protocol = SocketProtocol.Tcp
                },
                new ExposedPort()
                {
                    Port     = 25,
                    Protocol = SocketProtocol.Udp
                }
            }));

            var mapper = AutoMapperFactory.CreateValidMapper();

            var controller = new ClustersController(
                fakeMediator,
                mapper);

            controller.FakeAuthentication("some-identity-name");

            //Act
            var result = await controller.ConnectionDetails("some-instance-name");

            //Assert
            var response = result.ToObject <ConnectionDetailsResponse>();

            Assert.IsNotNull(response);

            var allPorts = response.Ports.ToArray();

            Assert.AreEqual(2, allPorts.Length);

            Assert.IsTrue(allPorts.Any(x => x.Port == 23 && x.Protocol == SocketProtocol.Tcp));
            Assert.IsTrue(allPorts.Any(x => x.Port == 25 && x.Protocol == SocketProtocol.Udp));
        }
Example #6
0
        public async Task Deploy_ClusterQueryTooBroadExceptionThrown_TooBroadValidationErrorReturned()
        {
            //Arrange
            var fakeMediator = Substitute.For <IMediator>();

            fakeMediator
            .Send(Arg.Any <DeployToClusterCommand>())
            .Throws(new ClusterQueryTooBroadException("dummy"));

            fakeMediator
            .Send(Arg.Any <GetRepositoryLoginForUserQuery>())
            .Returns(new RepositoryLoginResponse(
                         "dummy",
                         "dummy"));

            fakeMediator
            .Send(Arg.Any <EnsureRepositoryWithNameCommand>())
            .Returns(new RepositoryResponse(
                         "dummy",
                         "dummy",
                         new AmazonUser(),
                         new AmazonUser()));

            fakeMediator
            .Send(Arg.Any <EnsureUserForIdentityCommand>())
            .Returns(new User());

            var mapper = AutoMapperFactory.CreateValidMapper();

            var controller = new ClustersController(
                fakeMediator,
                mapper);

            controller.FakeAuthentication("some-identity-name");

            //Act
            var result = await controller.Deploy(new DeployToClusterRequest()
            {
                DockerComposeYmlFilePaths = new[] { "some-docker-compose-contents" }
            });

            //Assert
            var response = result.GetValidationProblemDetails();

            Assert.IsNotNull(response);

            Assert.AreEqual("TOO_BROAD", response.Type);
        }
Example #7
0
        public async Task Deploy_NoClusterIdGiven_DeployToClusterCommandFiredWithNoClusterId()
        {
            //Arrange
            var fakeMediator = Substitute.For <IMediator>();

            fakeMediator
            .Send(Arg.Any <EnsureUserForIdentityCommand>())
            .Returns(new User());

            fakeMediator
            .Send(Arg.Any <GetRepositoryLoginForUserQuery>())
            .Returns(new RepositoryLoginResponse(
                         "dummy",
                         "dummy"));

            fakeMediator
            .Send(Arg.Any <EnsureRepositoryWithNameCommand>())
            .Returns(new RepositoryResponse(
                         "dummy",
                         "dummy",
                         new AmazonUser(),
                         new AmazonUser()));

            var fakeMapper = Substitute.For <IMapper>();

            var controller = new ClustersController(
                fakeMediator,
                fakeMapper);

            controller.FakeAuthentication("some-identity-name");

            //Act
            var result = await controller.Deploy(new DeployToClusterRequest()
            {
                DockerComposeYmlFilePaths = new[] { "some-docker-compose-contents" }
            });

            //Assert
            Assert.IsNotNull(result);

            await fakeMediator
            .Received(1)
            .Send(Arg.Is <DeployToClusterCommand>(args =>
                                                  args.ClusterId == default));
        }
Example #8
0
        public async Task Destroy_ClusterIdGiven_DeleteInstanceByNameFiredWithClusterForUserAndClusterId()
        {
            //Arrange
            var fakeClusterId = Guid.NewGuid();

            var fakeMediator = Substitute.For <IMediator>();

            fakeMediator
            .Send(Arg.Any <EnsureUserForIdentityCommand>())
            .Returns(new User());

            fakeMediator
            .Send(Arg.Is <GetClusterForUserQuery>(args =>
                                                  args.ClusterId == fakeClusterId))
            .Returns(new Cluster()
            {
                Instances = new List <Dogger.Domain.Models.Instance>()
                {
                    new Dogger.Domain.Models.Instance()
                    {
                        Name = "some-instance-name"
                    }
                }
            });

            var fakeMapper = Substitute.For <IMapper>();

            var controller = new ClustersController(
                fakeMediator,
                fakeMapper);

            controller.FakeAuthentication("some-identity-name");

            //Act
            var result = await controller.Destroy(fakeClusterId);

            //Assert
            Assert.IsNotNull(result);

            await fakeMediator
            .Received(1)
            .Send(Arg.Is <DeleteInstanceByNameCommand>(args =>
                                                       args.Name == "some-instance-name"));
        }
Example #9
0
        public async Task Get_OneInstanceFound_InstanceReturned()
        {
            //Arrange
            var fakeMediator = Substitute.For <IMediator>();

            fakeMediator
            .Send(
                Arg.Is <EnsureUserForIdentityCommand>(
                    args => args.IdentityName == "some-identity-name"),
                default)
            .Returns(new User());

            fakeMediator
            .Send(Arg.Any <GetProvisionedClustersWithInstancesForUserQuery>(), default)
            .Returns(new[]
            {
                RandomObjectFactory.Create <UserClusterResponse>()
            });

            var mapper = AutoMapperFactory.CreateValidMapper();

            var controller = new ClustersController(
                fakeMediator,
                mapper);

            controller.FakeAuthentication("some-identity-name");

            //Act
            var result = await controller.Get();

            //Assert
            var clusters = result.ToArray();

            Assert.AreEqual(1, clusters.Length);
            Assert.AreEqual(1, clusters.Single().Instances.Count());
        }