예제 #1
0
            public async Task RequestsTheLicensesEndpoint()
            {
                IReadOnlyList <LicenseMetadata> response = new ReadOnlyCollection <LicenseMetadata>(new List <LicenseMetadata>()
                {
                    new LicenseMetadata("foo1", "node-id-1", "foo2", "something", "http://example.com/foo1", true),
                    new LicenseMetadata("bar1", "node-id-1", "bar2", "something else", "http://example.com/bar1", false)
                });

                var connection = Substitute.For <IApiConnection>();

                connection.GetAll <LicenseMetadata>(Arg.Is <Uri>(u => u.ToString() == "licenses"), null, "application/vnd.github.drax-preview+json", Args.ApiOptions)
                .Returns(Task.FromResult(response));
                var client = new MiscellaneousClient(connection);

                var licenses = await client.GetAllLicenses();

                Assert.Equal(2, licenses.Count);
                Assert.Equal("foo1", licenses[0].Key);
                Assert.Equal("foo2", licenses[0].Name);
                Assert.Equal("http://example.com/foo1", licenses[0].Url);
                Assert.Equal("bar1", licenses[1].Key);
                Assert.Equal("bar2", licenses[1].Name);
                Assert.Equal("http://example.com/bar1", licenses[1].Url);
                connection.Received()
                .GetAll <LicenseMetadata>(Arg.Is <Uri>(u => u.ToString() == "licenses"), null, AcceptHeaders.LicensesApiPreview, Args.ApiOptions);
            }
예제 #2
0
            public async Task RequestsTheMetadataEndpoint()
            {
                var meta = new Meta(
                    false,
                    "12345ABCDE",
                    new[] { "1.1.1.1/24", "1.1.1.2/24" },
                    new[] { "1.1.2.1/24", "1.1.2.2/24" },
                    new[] { "1.1.3.1/24", "1.1.3.2/24" },
                    new[] { "1.1.4.1", "1.1.4.2" }
                    );

                var apiConnection = Substitute.For <IApiConnection>();

                apiConnection.Get <Meta>(Arg.Is <Uri>(u => u.ToString() == "meta")).Returns(Task.FromResult(meta));
                var client = new MiscellaneousClient(apiConnection);

                var result = await client.GetMetadata();

                Assert.False(result.VerifiablePasswordAuthentication);
                Assert.Equal("12345ABCDE", result.GitHubServicesSha);
                Assert.Equal(result.Hooks, new[] { "1.1.1.1/24", "1.1.1.2/24" });
                Assert.Equal(result.Git, new[] { "1.1.2.1/24", "1.1.2.2/24" });
                Assert.Equal(result.Pages, new[] { "1.1.3.1/24", "1.1.3.2/24" });
                Assert.Equal(result.Importer, new[] { "1.1.4.1", "1.1.4.2" });

                apiConnection.Received()
                .Get <Meta>(Arg.Is <Uri>(u => u.ToString() == "meta"));
            }
            public async Task RequestsTheMetadataEndpoint()
            {
                IApiResponse <Meta> response = new ApiResponse <Meta>
                                               (
                    new Response(),
                    new Meta(
                        false,
                        "12345ABCDE",
                        new[] { "1.1.1.1/24", "1.1.1.2/24" },
                        new[] { "1.1.2.1/24", "1.1.2.2/24" },
                        new[] { "1.1.3.1/24", "1.1.3.2/24" },
                        new[] { "1.1.4.1", "1.1.4.2" }
                        )
                                               );
                var connection = Substitute.For <IConnection>();

                connection.Get <Meta>(Args.Uri, null, null)
                .Returns(Task.FromResult(response));
                var client = new MiscellaneousClient(connection);

                var result = await client.GetMetadata();

                Assert.Equal(result.VerifiablePasswordAuthentication, false);
                Assert.Equal(result.GitHubServicesSha, "12345ABCDE");
                Assert.Equal(result.Hooks, new[] { "1.1.1.1/24", "1.1.1.2/24" });
                Assert.Equal(result.Git, new[] { "1.1.2.1/24", "1.1.2.2/24" });
                Assert.Equal(result.Pages, new[] { "1.1.3.1/24", "1.1.3.2/24" });
                Assert.Equal(result.Importer, new[] { "1.1.4.1", "1.1.4.2" });

                connection.Received()
                .Get <Meta>(Arg.Is <Uri>(u => u.ToString() == "meta"), null, null);
            }
            public async Task RequestsTheEmojiEndpoint()
            {
                var links  = new Dictionary <string, Uri>();
                var scopes = new List <string>();
                IResponse <Dictionary <string, string> > response = new ApiResponse <Dictionary <string, string> >
                {
                    ApiInfo      = new ApiInfo(links, scopes, scopes, "", new RateLimit(new Dictionary <string, string>())),
                    BodyAsObject = new Dictionary <string, string>
                    {
                        { "foo", "http://example.com/foo.gif" },
                        { "bar", "http://example.com/bar.gif" }
                    }
                };
                var connection = Substitute.For <IConnection>();

                connection.GetAsync <Dictionary <string, string> >(Args.Uri, null, null).Returns(Task.FromResult(response));
                var client = new MiscellaneousClient(connection);

                var emojis = await client.GetEmojis();

                Assert.Equal(2, emojis.Count);
                Assert.Equal("foo", emojis[0].Name);
                connection.Received()
                .GetAsync <Dictionary <string, string> >(Arg.Is <Uri>(u => u.ToString() == "emojis"), null, null);
            }
        public RegisterNewDonorPage(ClientFactory clientFactory)
        {
            InitializeComponent();
            personnelClient     = clientFactory.GetPersonnelClient();
            miscellaneousClient = clientFactory.GetMiscellaneousClient();

            Loaded += RegisterNewDonorPage_Loaded;
        }
        public MainPage(ClientFactory clientFactory)
        {
            InitializeComponent();
            miscellaneousClient = clientFactory.GetMiscellaneousClient();

            HonoraryDonors = new ObservableCollection <DonorScore>();

            this.Loaded += MainPage_Loaded;
        }
예제 #7
0
            public async Task RequestsTheRecourceRateLimitEndpoint()
            {
                IApiResponse <MiscellaneousRateLimit> response = new ApiResponse <MiscellaneousRateLimit>
                                                                 (
                    new Response(),
                    new MiscellaneousRateLimit(
                        new ResourceRateLimit(
                            new RateLimit(5000, 4999, 1372700873),
                            new RateLimit(30, 18, 1372700873)
                            ),
                        new RateLimit(100, 75, 1372700873)
                        )
                                                                 );
                var connection = Substitute.For <IConnection>();

                connection.Get <MiscellaneousRateLimit>(Args.Uri, null, null).Returns(Task.FromResult(response));
                var client = new MiscellaneousClient(connection);

                var result = await client.GetRateLimits();

                // Test the core limits
                Assert.Equal(5000, result.Resources.Core.Limit);
                Assert.Equal(4999, result.Resources.Core.Remaining);
                Assert.Equal(1372700873, result.Resources.Core.ResetAsUtcEpochSeconds);
                var expectedReset = DateTimeOffset.ParseExact(
                    "Mon 01 Jul 2013 5:47:53 PM -00:00",
                    "ddd dd MMM yyyy h:mm:ss tt zzz",
                    CultureInfo.InvariantCulture);

                Assert.Equal(expectedReset, result.Resources.Core.Reset);

                // Test the search limits
                Assert.Equal(30, result.Resources.Search.Limit);
                Assert.Equal(18, result.Resources.Search.Remaining);
                Assert.Equal(1372700873, result.Resources.Search.ResetAsUtcEpochSeconds);
                expectedReset = DateTimeOffset.ParseExact(
                    "Mon 01 Jul 2013 5:47:53 PM -00:00",
                    "ddd dd MMM yyyy h:mm:ss tt zzz",
                    CultureInfo.InvariantCulture);
                Assert.Equal(expectedReset, result.Resources.Search.Reset);

                // Test the depreciated rate limits
                Assert.Equal(100, result.Rate.Limit);
                Assert.Equal(75, result.Rate.Remaining);
                Assert.Equal(1372700873, result.Rate.ResetAsUtcEpochSeconds);
                expectedReset = DateTimeOffset.ParseExact(
                    "Mon 01 Jul 2013 5:47:53 PM -00:00",
                    "ddd dd MMM yyyy h:mm:ss tt zzz",
                    CultureInfo.InvariantCulture);
                Assert.Equal(expectedReset, result.Rate.Reset);

                connection.Received()
                .Get <MiscellaneousRateLimit>(Arg.Is <Uri>(u => u.ToString() == "rate_limit"), null, null);
            }
예제 #8
0
        public PersonnelDonationsPage(ClientFactory clientFactory)
        {
            InitializeComponent();
            personnelClient     = clientFactory.GetPersonnelClient();
            miscellaneousClient = clientFactory.GetMiscellaneousClient();

            Donations         = new ObservableCollection <BloodDonation>();
            FilteredDonations = new ObservableCollection <BloodDonation>();

            Loaded += PersonnelDonationsPage_Loaded;
        }
            public async Task RequestsTheRecourceRateLimitEndpoint()
            {
                IApiResponse<MiscellaneousRateLimit> response = new ApiResponse<MiscellaneousRateLimit>
                (
                    new Response(),
                    new MiscellaneousRateLimit(
                        new ResourceRateLimit(
                            new RateLimit(5000, 4999, 1372700873),
                            new RateLimit(30, 18, 1372700873)
                        ),
                        new RateLimit(100, 75, 1372700873)
                    )
                );
                var connection = Substitute.For<IConnection>();
                connection.Get<MiscellaneousRateLimit>(Args.Uri, null, null).Returns(Task.FromResult(response));
                var client = new MiscellaneousClient(connection);

                var result = await client.GetRateLimits();

                // Test the core limits
                Assert.Equal(5000, result.Resources.Core.Limit);
                Assert.Equal(4999, result.Resources.Core.Remaining);
                Assert.Equal(1372700873, result.Resources.Core.ResetAsUtcEpochSeconds);
                var expectedReset = DateTimeOffset.ParseExact(
                    "Mon 01 Jul 2013 5:47:53 PM -00:00",
                    "ddd dd MMM yyyy h:mm:ss tt zzz",
                    CultureInfo.InvariantCulture);
                Assert.Equal(expectedReset, result.Resources.Core.Reset);

                // Test the search limits
                Assert.Equal(30, result.Resources.Search.Limit);
                Assert.Equal(18, result.Resources.Search.Remaining);
                Assert.Equal(1372700873, result.Resources.Search.ResetAsUtcEpochSeconds);
                expectedReset = DateTimeOffset.ParseExact(
                    "Mon 01 Jul 2013 5:47:53 PM -00:00",
                    "ddd dd MMM yyyy h:mm:ss tt zzz",
                    CultureInfo.InvariantCulture);
                Assert.Equal(expectedReset, result.Resources.Search.Reset);

                // Test the depreciated rate limits
                Assert.Equal(100, result.Rate.Limit);
                Assert.Equal(75, result.Rate.Remaining);
                Assert.Equal(1372700873, result.Rate.ResetAsUtcEpochSeconds);
                expectedReset = DateTimeOffset.ParseExact(
                    "Mon 01 Jul 2013 5:47:53 PM -00:00",
                    "ddd dd MMM yyyy h:mm:ss tt zzz",
                    CultureInfo.InvariantCulture);
                Assert.Equal(expectedReset, result.Rate.Reset);

                connection.Received()
                    .Get<MiscellaneousRateLimit>(Arg.Is<Uri>(u => u.ToString() == "rate_limit"), null, null);
            }
            public async Task RequestsTheEmojiEndpoint()
            {
                IApiResponse<string> response = new ApiResponse<string>(new Response(), "<strong>Test</strong>");
                var connection = Substitute.For<IConnection>();
                connection.Post<string>(Args.Uri, "**Test**", "text/html", "text/plain")
                    .Returns(Task.FromResult(response));
                var client = new MiscellaneousClient(connection);

                var html = await client.RenderRawMarkdown("**Test**");

                Assert.Equal("<strong>Test</strong>", html);
                connection.Received()
                    .Post<string>(Arg.Is<Uri>(u => u.ToString() == "markdown/raw"),
                    "**Test**",
                    "text/html",
                    "text/plain");
            }
예제 #11
0
        public MainWindow()
        {
            InitializeComponent();
            clientFactory     = new ClientFactory();
            MainFrame.Content = new MainPage(clientFactory);

            miscellaneousClient = clientFactory.GetMiscellaneousClient();

            var personnelClient = clientFactory.GetPersonnelClient();
            var donorClient     = clientFactory.GetDonorClient();

            personnelClient.OnLogout += WhenPersonnelLoggedOff;
            donorClient.OnLogout     += WhenDonorLoggedOff;

            personnelClient.OnLogin += WhenPersonnelLoggedIn;
            donorClient.OnLogin     += WhenDonorLoggedIn;
        }
예제 #12
0
            public async Task RequestsTheEmojiEndpoint()
            {
                IApiResponse <string> response = new ApiResponse <string>(new Response(), "<strong>Test</strong>");
                var connection = Substitute.For <IConnection>();

                connection.Post <string>(Args.Uri, "**Test**", "text/html", "text/plain")
                .Returns(Task.FromResult(response));
                var client = new MiscellaneousClient(connection);

                var html = await client.RenderRawMarkdown("**Test**");

                Assert.Equal("<strong>Test</strong>", html);
                connection.Received()
                .Post <string>(Arg.Is <Uri>(u => u.ToString() == "markdown/raw"),
                               "**Test**",
                               "text/html",
                               "text/plain");
            }
            public async Task RequestsTheEmojiEndpoint()
            {
                IApiResponse<Dictionary<string, string>> response = new ApiResponse<Dictionary<string, string>>
                (
                    new Response(),
                    new Dictionary<string, string>
                    {
                        { "foo", "http://example.com/foo.gif" },
                        { "bar", "http://example.com/bar.gif" }
                    }
                );
                var connection = Substitute.For<IConnection>();
                connection.Get<Dictionary<string, string>>(Args.Uri, null, null).Returns(Task.FromResult(response));
                var client = new MiscellaneousClient(connection);

                var emojis = await client.GetEmojis();

                Assert.Equal(2, emojis.Count);
                Assert.Equal("foo", emojis[0].Name);
                connection.Received()
                    .Get<Dictionary<string, string>>(Arg.Is<Uri>(u => u.ToString() == "emojis"), null, null);
            }
예제 #14
0
            public async Task RequestsTheMarkdownEndpoint()
            {
                var response = "<strong>Test</strong>";

                var payload = new NewArbitraryMarkdown("testMarkdown", "gfm", "testContext");

                var apiConnection = Substitute.For <IApiConnection>();

                apiConnection.Post <string>(Args.Uri, payload, "text/html", "text/plain")
                .Returns(Task.FromResult(response));

                var client = new MiscellaneousClient(apiConnection);

                var html = await client.RenderArbitraryMarkdown(payload);

                Assert.Equal("<strong>Test</strong>", html);
                apiConnection.Received()
                .Post <string>(Arg.Is <Uri>(u => u.ToString() == "markdown"),
                               payload,
                               "text/html",
                               "text/plain");
            }
예제 #15
0
            public async Task RequestsTheEmojiEndpoint()
            {
                IReadOnlyList <Emoji> response = new List <Emoji>
                {
                    { new Emoji("foo", "http://example.com/foo.gif") },
                    { new Emoji("bar", "http://example.com/bar.gif") }
                };

                var apiConnection = Substitute.For <IApiConnection>();

                apiConnection.GetAll <Emoji>(Args.Uri)
                .Returns(Task.FromResult(response));

                var client = new MiscellaneousClient(apiConnection);

                var emojis = await client.GetAllEmojis();

                Assert.Equal(2, emojis.Count);
                Assert.Equal("foo", emojis[0].Name);
                apiConnection.Received()
                .GetAll <Emoji>(Arg.Is <Uri>(u => u.ToString() == "emojis"));
            }
            public async Task RequestsTheEmojiEndpoint()
            {
                var links = new Dictionary<string, Uri>();
                var scopes = new List<string>();
                IResponse<string> response = new ApiResponse<string>
                {
                    ApiInfo = new ApiInfo(links, scopes, scopes, "", new RateLimit(new Dictionary<string, string>())),
                    Body = "<strong>Test</strong>"
                };
                var connection = Substitute.For<IConnection>();
                connection.PostAsync<string>(Args.Uri, "**Test**", "text/html", "text/plain")
                    .Returns(Task.FromResult(response));
                var client = new MiscellaneousClient(connection);

                var html = await client.RenderRawMarkdown("**Test**");

                Assert.Equal("<strong>Test</strong>", html);
                connection.Received()
                    .PostAsync<string>(Arg.Is<Uri>(u => u.ToString() == "markdown/raw"),
                    "**Test**",
                    "text/html",
                    "text/plain");
            }
예제 #17
0
            public async Task RequestsTheRawMarkdownEndpoint()
            {
                var markdown      = "**Test**";
                var response      = "<strong>Test</strong>";
                var apiConnection = Substitute.For <IApiConnection>();

                apiConnection.Post <string>(
                    Arg.Is <Uri>(u => u.ToString() == "markdown/raw"),
                    markdown,
                    "text/html",
                    "text/plain")
                .Returns(Task.FromResult(response));
                var client = new MiscellaneousClient(apiConnection);

                var html = await client.RenderRawMarkdown(markdown);

                Assert.Equal("<strong>Test</strong>", html);
                apiConnection.Received()
                .Post <string>(Arg.Is <Uri>(u => u.ToString() == "markdown/raw"),
                               markdown,
                               "text/html",
                               "text/plain");
            }
예제 #18
0
            public async Task RequestsTheEmojiEndpoint()
            {
                IApiResponse <Dictionary <string, string> > response = new ApiResponse <Dictionary <string, string> >
                                                                       (
                    new Response(),
                    new Dictionary <string, string>
                {
                    { "foo", "http://example.com/foo.gif" },
                    { "bar", "http://example.com/bar.gif" }
                }
                                                                       );
                var connection = Substitute.For <IConnection>();

                connection.Get <Dictionary <string, string> >(Args.Uri, null, null).Returns(Task.FromResult(response));
                var client = new MiscellaneousClient(connection);

                var emojis = await client.GetAllEmojis();

                Assert.Equal(2, emojis.Count);
                Assert.Equal("foo", emojis[0].Name);
                connection.Received()
                .Get <Dictionary <string, string> >(Arg.Is <Uri>(u => u.ToString() == "emojis"), null, null);
            }
            public async Task RequestsTheEmojiEndpoint()
            {
                var links = new Dictionary<string, Uri>();
                var scopes = new List<string>();
                IResponse<Dictionary<string, string>> response = new ApiResponse<Dictionary<string, string>>
                {
                    ApiInfo = new ApiInfo(links, scopes, scopes, "", new RateLimit(new Dictionary<string, string>())),
                    BodyAsObject = new Dictionary<string, string>
                    {
                        { "foo", "http://example.com/foo.gif" },
                        { "bar", "http://example.com/bar.gif" }
                    }
                };
                var connection = Substitute.For<IConnection>();
                connection.GetAsync<Dictionary<string, string>>(Args.Uri, null, null).Returns(Task.FromResult(response));
                var client = new MiscellaneousClient(connection);

                var emojis = await client.GetEmojis();

                Assert.Equal(2, emojis.Count);
                connection.Received()
                    .GetAsync<Dictionary<string, string>>(Arg.Is<Uri>(u => u.ToString() == "emojis"), null, null);
            }
            public async Task RequestsTheEmojiEndpoint()
            {
                var links  = new Dictionary <string, Uri>();
                var scopes = new List <string>();
                IResponse <string> response = new ApiResponse <string>
                {
                    ApiInfo = new ApiInfo(links, scopes, scopes, "", new RateLimit(new Dictionary <string, string>())),
                    Body    = "<strong>Test</strong>"
                };
                var connection = Substitute.For <IConnection>();

                connection.PostAsync <string>(Args.Uri, "**Test**", "text/html", "text/plain")
                .Returns(Task.FromResult(response));
                var client = new MiscellaneousClient(connection);

                var html = await client.RenderRawMarkdown("**Test**");

                Assert.Equal("<strong>Test</strong>", html);
                connection.Received()
                .PostAsync <string>(Arg.Is <Uri>(u => u.ToString() == "markdown/raw"),
                                    "**Test**",
                                    "text/html",
                                    "text/plain");
            }
            public async Task RequestsTheMetadataEndpoint()
            {
                IApiResponse<Meta> response = new ApiResponse<Meta>
                (
                    new Response(),
                    new Meta(
                        false,
                        "12345ABCDE",
                        new[] { "1.1.1.1/24", "1.1.1.2/24" },
                        new[] { "1.1.2.1/24", "1.1.2.2/24" },
                        new[] { "1.1.3.1/24", "1.1.3.2/24" },
                        new[] { "1.1.4.1", "1.1.4.2" }
                    )
                );
                var connection = Substitute.For<IConnection>();
                connection.Get<Meta>(Args.Uri, null, null)
                    .Returns(Task.FromResult(response));
                var client = new MiscellaneousClient(connection);

                var result = await client.GetMetadata();

                Assert.Equal(result.VerifiablePasswordAuthentication, false);
                Assert.Equal(result.GitHubServicesSha, "12345ABCDE");
                Assert.Equal(result.Hooks, new[] { "1.1.1.1/24", "1.1.1.2/24" });
                Assert.Equal(result.Git, new[] { "1.1.2.1/24", "1.1.2.2/24" });
                Assert.Equal(result.Pages, new[] { "1.1.3.1/24", "1.1.3.2/24" });
                Assert.Equal(result.Importer, new[] { "1.1.4.1", "1.1.4.2" });

                connection.Received()
                    .Get<Meta>(Arg.Is<Uri>(u => u.ToString() == "meta"), null, null);
            }
예제 #22
0
            public void EnsuresNonNullArguments()
            {
                var client = new MiscellaneousClient(Substitute.For <IApiConnection>());

                Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllLicenses(null));
            }