示例#1
0
 /// <summary>
 /// Instantiates a new GitHub Enterprise API client.
 /// </summary>
 /// <param name="apiConnection">An API connection</param>
 public EnterpriseClient(IApiConnection apiConnection) : base(apiConnection)
 {
     AdminStats            = new EnterpriseAdminStatsClient(apiConnection);
     Ldap                  = new EnterpriseLdapClient(apiConnection);
     License               = new EnterpriseLicenseClient(apiConnection);
     Organization          = new EnterpriseOrganizationClient(apiConnection);
     SearchIndexing        = new EnterpriseSearchIndexingClient(apiConnection);
     PreReceiveEnvironment = new EnterprisePreReceiveEnvironmentsClient(apiConnection);
 }
            public async Task RequestsTheCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new EnterprisePreReceiveEnvironmentsClient(connection);

                await client.Get(1);

                connection.Received().Get <PreReceiveEnvironment>(Arg.Is <Uri>(u => u.ToString() == "admin/pre-receive-environments/1"),
                                                                  null,
                                                                  "application/vnd.github.eye-scream-preview+json");
            }
            public async Task EnsuresNonNullArguments()
            {
                var client = new EnterprisePreReceiveEnvironmentsClient(Substitute.For <IApiConnection>());

                Assert.Throws <ArgumentNullException>(() => new NewPreReceiveEnvironment(null, "url"));
                Assert.Throws <ArgumentException>(() => new NewPreReceiveEnvironment("", "url"));
                Assert.Throws <ArgumentNullException>(() => new NewPreReceiveEnvironment("name", null));
                Assert.Throws <ArgumentException>(() => new NewPreReceiveEnvironment("name", ""));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.Create(null));
            }
            public async Task RequestsTheCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new EnterprisePreReceiveEnvironmentsClient(connection);

                await client.TriggerDownload(1);

                connection.Received().Post <PreReceiveEnvironmentDownload>(Arg.Is <Uri>(u => u.ToString() == "admin/pre-receive-environments/1/downloads"),
                                                                           Arg.Any <object>(),
                                                                           "application/vnd.github.eye-scream-preview+json");
            }
            public async Task RequestsCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new EnterprisePreReceiveEnvironmentsClient(connection);
                var data       = new NewPreReceiveEnvironment("name", "url");

                await client.Create(data);

                connection.Received().Post <PreReceiveEnvironment>(Arg.Is <Uri>(u => u.ToString() == "admin/pre-receive-environments"),
                                                                   data,
                                                                   "application/vnd.github.eye-scream-preview+json");
            }
            public async Task RequestsTheCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new EnterprisePreReceiveEnvironmentsClient(connection);
                var data       = new UpdatePreReceiveEnvironment
                {
                    Name     = "name",
                    ImageUrl = "url"
                };

                await client.Edit(1, data);

                connection.Received().Patch <PreReceiveEnvironment>(Arg.Is <Uri>(u => u.ToString() == "admin/pre-receive-environments/1"),
                                                                    data,
                                                                    "application/vnd.github.eye-scream-preview+json");
            }
            public async Task RequestsCorrectUrlWithApiOptions()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new EnterprisePreReceiveEnvironmentsClient(connection);

                var options = new ApiOptions
                {
                    PageSize  = 1,
                    PageCount = 1,
                    StartPage = 1
                };

                await client.GetAll(options);

                connection.Received().GetAll <PreReceiveEnvironment>(Arg.Is <Uri>(u => u.ToString() == "admin/pre-receive-environments"),
                                                                     null,
                                                                     "application/vnd.github.eye-scream-preview+json",
                                                                     options);
            }
            public async Task EnsuresNonNullArguments()
            {
                var client = new EnterprisePreReceiveEnvironmentsClient(Substitute.For <IApiConnection>());

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.Edit(1, null));
            }