public async Task EnsureNonNullArguments() { var client = new StatisticsClient(Substitute.For <IApiConnection>()); await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetCodeFrequency(null, "name")); await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetCodeFrequency("owner", null)); await Assert.ThrowsAsync <ArgumentException>(() => client.GetCodeFrequency("", "name")); await Assert.ThrowsAsync <ArgumentException>(() => client.GetCodeFrequency("owner", "")); }
public async Task RequestsCorrectUrl() { var expectedEndPoint = new Uri("/repos/username/repositoryName/stats/code_frequency", UriKind.Relative); long firstTimestamp = 159670861; long secondTimestamp = 0; IReadOnlyList <long[]> data = new ReadOnlyCollection <long[]>(new[] { new[] { firstTimestamp, 10, 52 }, new[] { secondTimestamp, 0, 9 } }); var client = Substitute.For <IApiConnection>(); client.GetQueuedOperation <long[]>(expectedEndPoint, Args.CancellationToken) .Returns(Task.FromResult(data)); var statisticsClient = new StatisticsClient(client); var codeFrequency = await statisticsClient.GetCodeFrequency("username", "repositoryName"); Assert.Equal(2, codeFrequency.AdditionsAndDeletionsByWeek.Count); Assert.Equal(firstTimestamp.FromUnixTime(), codeFrequency.AdditionsAndDeletionsByWeek[0].Timestamp); Assert.Equal(10, codeFrequency.AdditionsAndDeletionsByWeek[0].Additions); Assert.Equal(52, codeFrequency.AdditionsAndDeletionsByWeek[0].Deletions); Assert.Equal(secondTimestamp.FromUnixTime(), codeFrequency.AdditionsAndDeletionsByWeek[1].Timestamp); Assert.Equal(0, codeFrequency.AdditionsAndDeletionsByWeek[1].Additions); Assert.Equal(9, codeFrequency.AdditionsAndDeletionsByWeek[1].Deletions); }
public async Task RequestsCorrectUrlWithRepositoryIdWithCancellationToken() { var expectedEndPoint = new Uri("repositories/1/stats/code_frequency", UriKind.Relative); var cancellationToken = new CancellationToken(); long firstTimestamp = 159670861; long secondTimestamp = 0; IReadOnlyList <long[]> data = new ReadOnlyCollection <long[]>(new[] { new[] { firstTimestamp, 10, 52 }, new[] { secondTimestamp, 0, 9 } }); var connection = Substitute.For <IApiConnection>(); connection.GetQueuedOperation <long[]>(expectedEndPoint, cancellationToken) .Returns(Task.FromResult(data)); var client = new StatisticsClient(connection); var codeFrequency = await client.GetCodeFrequency(1, cancellationToken); Assert.Equal(2, codeFrequency.AdditionsAndDeletionsByWeek.Count); Assert.Equal(DateTimeOffset.FromUnixTimeSeconds(firstTimestamp), codeFrequency.AdditionsAndDeletionsByWeek[0].Timestamp); Assert.Equal(10, codeFrequency.AdditionsAndDeletionsByWeek[0].Additions); Assert.Equal(52, codeFrequency.AdditionsAndDeletionsByWeek[0].Deletions); Assert.Equal(DateTimeOffset.FromUnixTimeSeconds(secondTimestamp), codeFrequency.AdditionsAndDeletionsByWeek[1].Timestamp); Assert.Equal(0, codeFrequency.AdditionsAndDeletionsByWeek[1].Additions); Assert.Equal(9, codeFrequency.AdditionsAndDeletionsByWeek[1].Deletions); }
public void RequestsCorrectUrl() { var expectedEndPoint = new Uri("/repos/username/repositoryName/stats/code_frequency", UriKind.Relative); var client = Substitute.For <IApiConnection>(); var statisticsClient = new StatisticsClient(client); statisticsClient.GetCodeFrequency("username", "repositoryName"); client.Received().GetQueuedOperation <IEnumerable <long[]> >(expectedEndPoint, Args.CancellationToken); }
public async Task ThrowsIfGivenNullRepositoryName() { var statisticsClient = new StatisticsClient(Substitute.For <IApiConnection>()); await Assert.ThrowsAsync <ArgumentNullException>(() => statisticsClient.GetCodeFrequency("owner", null)); }
public async Task EnsureNonNullArguments() { var client = new StatisticsClient(Substitute.For<IApiConnection>()); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetCodeFrequency(null, "name")); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetCodeFrequency("owner", null)); await Assert.ThrowsAsync<ArgumentException>(() => client.GetCodeFrequency("", "name")); await Assert.ThrowsAsync<ArgumentException>(() => client.GetCodeFrequency("owner", "")); }
public async Task RequestsCorrectUrlWithRepositoryIdWithCancellationToken() { var expectedEndPoint = new Uri("repositories/1/stats/code_frequency", UriKind.Relative); var cancellationToken = new CancellationToken(); long firstTimestamp = 159670861; long secondTimestamp = 0; IReadOnlyList<long[]> data = new ReadOnlyCollection<long[]>(new[] { new[] { firstTimestamp, 10, 52 }, new[] { secondTimestamp, 0, 9 } }); var connection = Substitute.For<IApiConnection>(); connection.GetQueuedOperation<long[]>(expectedEndPoint, cancellationToken) .Returns(Task.FromResult(data)); var client = new StatisticsClient(connection); var codeFrequency = await client.GetCodeFrequency(1, cancellationToken); Assert.Equal(2, codeFrequency.AdditionsAndDeletionsByWeek.Count); Assert.Equal(firstTimestamp.FromUnixTime(), codeFrequency.AdditionsAndDeletionsByWeek[0].Timestamp); Assert.Equal(10, codeFrequency.AdditionsAndDeletionsByWeek[0].Additions); Assert.Equal(52, codeFrequency.AdditionsAndDeletionsByWeek[0].Deletions); Assert.Equal(secondTimestamp.FromUnixTime(), codeFrequency.AdditionsAndDeletionsByWeek[1].Timestamp); Assert.Equal(0, codeFrequency.AdditionsAndDeletionsByWeek[1].Additions); Assert.Equal(9, codeFrequency.AdditionsAndDeletionsByWeek[1].Deletions); }
public async Task ThrowsIfGivenNullOwner() { var statisticsClient = new StatisticsClient(Substitute.For<IApiConnection>()); await AssertEx.Throws<ArgumentNullException>(() => statisticsClient.GetCodeFrequency(null, "repositoryName")); }
public void RequestsCorrectUrl() { var expectedEndPoint = new Uri("/repos/username/repositoryName/stats/code_frequency", UriKind.Relative); var client = Substitute.For<IApiConnection>(); var statisticsClient = new StatisticsClient(client); statisticsClient.GetCodeFrequency("username", "repositoryName"); client.Received().GetQueuedOperation<IEnumerable<long[]>>(expectedEndPoint, Args.CancellationToken); }
public async Task ThrowsIfGivenNullRepositoryName() { var statisticsClient = new StatisticsClient(Substitute.For<IApiConnection>()); await Assert.ThrowsAsync<ArgumentNullException>(() => statisticsClient.GetCodeFrequency("owner", null)); }
public async Task ThrowsIfGivenNullOwner() { var statisticsClient = new StatisticsClient(Substitute.For <IApiConnection>()); await AssertEx.Throws <ArgumentNullException>(() => statisticsClient.GetCodeFrequency(null, "repositoryName")); }