Exemplo n.º 1
0
            public async Task EnsureNonNullArguments()
            {
                var client = new StatisticsClient(Substitute.For <IApiConnection>());

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetPunchCard(null, "name"));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetPunchCard("owner", null));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetPunchCard("", "name"));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetPunchCard("owner", ""));
            }
            public void RequestsCorrectUrl()
            {
                var expectedEndPoint = new Uri("/repos/username/repositoryName/stats/punch_card", UriKind.Relative);

                var client           = Substitute.For <IApiConnection>();
                var statisticsClient = new StatisticsClient(client);

                statisticsClient.GetPunchCard("username", "repositoryName");

                client.Received().GetQueuedOperation <IEnumerable <int[]> >(expectedEndPoint, Args.CancellationToken);
            }
            public async Task RetrievesPunchCard()
            {
                var expectedEndPoint = new Uri("/repos/username/repositoryName/stats/punch_card", UriKind.Relative);

                var client = Substitute.For <IApiConnection>();
                IReadOnlyList <int[]> data = new ReadOnlyCollection <int[]>(new[] { new[] { 2, 8, 42 } });

                client.GetQueuedOperation <int[]>(expectedEndPoint, Args.CancellationToken)
                .Returns(Task.FromResult(data));
                var statisticsClient = new StatisticsClient(client);

                var result = await statisticsClient.GetPunchCard("username", "repositoryName");

                Assert.Equal(1, result.PunchPoints.Count);
                Assert.Equal(DayOfWeek.Tuesday, result.PunchPoints[0].DayOfWeek);
                Assert.Equal(8, result.PunchPoints[0].HourOfTheDay);
                Assert.Equal(42, result.PunchPoints[0].CommitCount);
            }
Exemplo n.º 4
0
            public async Task RequestsCorrectUrlWithRepositoryIdWithCancellationToken()
            {
                var expectedEndPoint  = new Uri("repositories/1/stats/punch_card", UriKind.Relative);
                var cancellationToken = new CancellationToken();

                var connection             = Substitute.For <IApiConnection>();
                IReadOnlyList <int[]> data = new ReadOnlyCollection <int[]>(new[] { new[] { 2, 8, 42 } });

                connection.GetQueuedOperation <int[]>(expectedEndPoint, cancellationToken)
                .Returns(Task.FromResult(data));
                var client = new StatisticsClient(connection);

                var result = await client.GetPunchCard(1, cancellationToken);

                Assert.Equal(1, result.PunchPoints.Count);
                Assert.Equal(DayOfWeek.Tuesday, result.PunchPoints[0].DayOfWeek);
                Assert.Equal(8, result.PunchPoints[0].HourOfTheDay);
                Assert.Equal(42, result.PunchPoints[0].CommitCount);
            }
 public async Task ThrowsIfGivenNullRepositoryName()
 {
     var statisticsClient = new StatisticsClient(Substitute.For <IApiConnection>());
     await Assert.ThrowsAsync <ArgumentNullException>(() => statisticsClient.GetPunchCard("owner", null));
 }
            public async Task EnsureNonNullArguments()
            {
                var client = new StatisticsClient(Substitute.For<IApiConnection>());

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetPunchCard(null, "name"));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetPunchCard("owner", null));

                await Assert.ThrowsAsync<ArgumentException>(() => client.GetPunchCard("", "name"));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetPunchCard("owner", ""));
            }
            public async Task RequestsCorrectUrlWithRepositoryIdWithCancellationToken()
            {
                var expectedEndPoint = new Uri("repositories/1/stats/punch_card", UriKind.Relative);
                var cancellationToken = new CancellationToken();

                var connection = Substitute.For<IApiConnection>();
                IReadOnlyList<int[]> data = new ReadOnlyCollection<int[]>(new[] { new[] { 2, 8, 42 } });

                connection.GetQueuedOperation<int[]>(expectedEndPoint, cancellationToken)
                    .Returns(Task.FromResult(data));
                var client = new StatisticsClient(connection);

                var result = await client.GetPunchCard(1, cancellationToken);

                Assert.Equal(1, result.PunchPoints.Count);
                Assert.Equal(DayOfWeek.Tuesday, result.PunchPoints[0].DayOfWeek);
                Assert.Equal(8, result.PunchPoints[0].HourOfTheDay);
                Assert.Equal(42, result.PunchPoints[0].CommitCount);
            }
Exemplo n.º 8
0
 public async Task ThrowsIfGivenNullRepositoryName()
 {
     var statisticsClient = new StatisticsClient(Substitute.For<IApiConnection>());
     await AssertEx.Throws<ArgumentNullException>(() => statisticsClient.GetPunchCard("owner", null));
 }
Exemplo n.º 9
0
            public void RequestsCorrectUrl()
            {
                var expectedEndPoint = new Uri("/repos/username/repositoryName/stats/punch_card", UriKind.Relative);

                var client = Substitute.For<IApiConnection>();
                var statisticsClient = new StatisticsClient(client);

                statisticsClient.GetPunchCard("username", "repositoryName");

                client.Received().GetQueuedOperation<IEnumerable<int[]>>(expectedEndPoint, Args.CancellationToken);
            }
 public async Task ThrowsIfGivenNullOwner()
 {
     var statisticsClient = new StatisticsClient(Substitute.For<IApiConnection>());
     await Assert.ThrowsAsync<ArgumentNullException>(() => statisticsClient.GetPunchCard(null, "repositoryName"));
 }
            public async Task RetrievesPunchCard()
            {
                var expectedEndPoint = new Uri("/repos/username/repositoryName/stats/punch_card", UriKind.Relative);

                var client = Substitute.For<IApiConnection>();
                IReadOnlyList<int[]> data = new ReadOnlyCollection<int[]>(new[] { new[] { 2, 8, 42 } });
                client.GetQueuedOperation<int[]>(expectedEndPoint, Args.CancellationToken)
                    .Returns(Task.FromResult(data));
                var statisticsClient = new StatisticsClient(client);

                var result = await statisticsClient.GetPunchCard("username", "repositoryName");

                Assert.Equal(1, result.PunchPoints.Count);
                Assert.Equal(DayOfWeek.Tuesday, result.PunchPoints[0].DayOfWeek);
                Assert.Equal(8, result.PunchPoints[0].HourOfTheDay);
                Assert.Equal(42, result.PunchPoints[0].CommitCount);
            }
 public async Task ThrowsIfGivenNullOwner()
 {
     var statisticsClient = new StatisticsClient(Substitute.For <IApiConnection>());
     await AssertEx.Throws <ArgumentNullException>(() => statisticsClient.GetPunchCard(null, "repositoryName"));
 }