Example #1
0
        public void ShouldCreateWhenCantDeserializeMachines()
        {
            client.When(x => x.Paginate(Arg.Any <string>(), Arg.Any <object>(), Arg.Any <Func <ResourceCollection <MachineResource>, bool> >()))
            .Throw(new OctopusDeserializationException(1, "Can not deserialize"));

            environments.Items.Add(new EnvironmentResource {
                Id = "environments-1", Name = "UAT", Links = LinkCollection.Self("/api/environments/environments-1").Add("Machines", "/api/environments/environments-1/machines")
            });
            environments.Items.Add(new EnvironmentResource {
                Id = "environments-2", Name = "Production", Links = LinkCollection.Self("/api/environments/environments-2").Add("Machines", "/api/environments/environments-2/machines")
            });

            operation.TentacleThumbprint = "ABCDEF";
            operation.TentaclePort       = 10930;
            operation.MachineName        = "Mymachine";
            operation.TentacleHostname   = "Mymachine.test.com";
            operation.CommunicationStyle = CommunicationStyle.TentaclePassive;
            operation.EnvironmentNames   = new[] { "Production" };

            operation.Execute(serverEndpoint);

            client.Received().Create("/api/machines", Arg.Is <MachineResource>(m =>
                                                                               m.Name == "Mymachine" &&
                                                                               ((ListeningTentacleEndpointResource)m.Endpoint).Uri == "https://mymachine.test.com:10930/" &&
                                                                               m.EnvironmentIds.First() == "environments-2"));
        }
Example #2
0
        public void SetUp()
        {
            clientFactory = Substitute.For <IOctopusClientFactory>();
            client        = Substitute.For <IOctopusClient>();
            clientFactory.CreateClient(Arg.Any <OctopusServerEndpoint>()).Returns(client);
            operation      = new RegisterMachineOperation(clientFactory);
            serverEndpoint = new OctopusServerEndpoint("http://octopus", "ABC123");

            environments = new ResourceCollection <EnvironmentResource>(new EnvironmentResource[0], LinkCollection.Self("/foo"));
            machines     = new ResourceCollection <MachineResource>(new MachineResource[0], LinkCollection.Self("/foo"));
            client.RootDocument.Returns(new RootResource {
                Links = LinkCollection.Self("/api").Add("Environments", "/api/environments").Add("Machines", "/api/machines")
            });

            client.When(x => x.Paginate(Arg.Any <string>(), Arg.Any <object>(), Arg.Any <Func <ResourceCollection <EnvironmentResource>, bool> >()))
            .Do(ci => ci.Arg <Func <ResourceCollection <EnvironmentResource>, bool> >()(environments));

            client.When(x => x.Paginate(Arg.Any <string>(), Arg.Any <object>(), Arg.Any <Func <ResourceCollection <MachineResource>, bool> >()))
            .Do(ci => ci.Arg <Func <ResourceCollection <MachineResource>, bool> >()(machines));

            client.List <MachineResource>(Arg.Any <string>(), Arg.Any <object>()).Returns(machines);
        }