コード例 #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);
        }
コード例 #2
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));
        }