public void SetUp()
        {
            clientFactory = Substitute.For <IOctopusClientFactory>();
            client        = Substitute.For <IOctopusAsyncClient>();
            clientFactory.CreateAsyncClient(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"));
            machinePolicies = new ResourceCollection <MachinePolicyResource>(new MachinePolicyResource[0], LinkCollection.Self("/foo"));
            var rootDocument = new RootResource
            {
                ApiVersion = "3.0.0",
                Version    = "2099.0.0",
                Links      = LinkCollection.Self("/api")
                             .Add("Environments", "/api/environments")
                             .Add("Machines", "/api/machines")
                             .Add("MachinePolicies", "/api/machinepolicies")
                             .Add("CurrentUser", "/api/users/me")
                             .Add("SpaceHome", "/api/spaces")
            };

            client.Get <RootResource>(Arg.Any <string>()).Returns(rootDocument);
            client.Repository.LoadRootDocument().Returns(rootDocument);
            client.Get <SpaceResource[]>(Arg.Any <string>())
            .Returns(new[] { new SpaceResource()
                             {
                                 Id = "Spaces-1", IsDefault = true
                             } });
            client.Get <UserResource>(Arg.Any <string>()).Returns(new UserResource()
            {
                Links =
                {
                    { "Spaces", "" }
                }
            });
            client.Repository.HasLink(Arg.Any <string>()).Returns(ci => rootDocument.HasLink(ci.Arg <string>()));
            client.Repository.Link(Arg.Any <string>()).Returns(ci => rootDocument.Link(ci.Arg <string>()));

            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.When(x => x.Paginate(Arg.Any <string>(), Arg.Any <object>(), Arg.Any <Func <ResourceCollection <MachinePolicyResource>, bool> >()))
            .Do(ci => ci.Arg <Func <ResourceCollection <MachinePolicyResource>, bool> >()(machinePolicies));

            client.List <MachineResource>(Arg.Any <string>(), Arg.Any <object>()).Returns(machines);
        }
Beispiel #2
0
        public void SetUp()
        {
            clientFactory = Substitute.For <IOctopusClientFactory>();
            client        = Substitute.For <IOctopusAsyncClient>();
            clientFactory.CreateAsyncClient(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);
        }