From 86f5ac1a8782da350ce63510c88711122ef9e1f2 Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Sat, 13 Oct 2018 14:52:37 -0500 Subject: [PATCH] add GetCommitDatesAsyncShould tests --- .../GitHub/GetCommitDatesAsyncShould.cs | 38 ++++++++++++++++--- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/tests/FilterLists.Services.Tests/GitHub/GetCommitDatesAsyncShould.cs b/tests/FilterLists.Services.Tests/GitHub/GetCommitDatesAsyncShould.cs index e2b0bae23..6ade397a0 100644 --- a/tests/FilterLists.Services.Tests/GitHub/GetCommitDatesAsyncShould.cs +++ b/tests/FilterLists.Services.Tests/GitHub/GetCommitDatesAsyncShould.cs @@ -9,17 +9,43 @@ namespace FilterLists.Services.Tests.GitHub public class GetCommitDatesAsyncShould { [Fact] - public async Task ReturnCorrectCommitDatesForValidGitHubRawUrl() + public async Task ReturnCorrectFirstAndLastCommitDatesForValidGitHubRawUrl() { - const string rawFileUrl = "https://raw.githubusercontent.com/collinbarrett/FilterLists/master/LICENSE"; - var expectedCommitDates = new CommitDates + const string url = "https://raw.githubusercontent.com/collinbarrett/FilterLists/master/LICENSE"; + var expectedDates = new CommitDates { First = DateTime.Parse("2016-12-10T20:28:16.0000000"), Last = DateTime.Parse("2018-01-24T00:08:21.0000000") }; - var actualCommitDates = await new GitHubService().GetCommitDatesAsync(rawFileUrl); - Assert.Equal(expectedCommitDates.First, actualCommitDates.First); - Assert.Equal(expectedCommitDates.Last, actualCommitDates.Last); + var actualDates = await new GitHubService().GetCommitDatesAsync(url); + Assert.Equal(expectedDates.First, actualDates.First); + Assert.Equal(expectedDates.Last, actualDates.Last); + } + + [Fact] + public async Task ReturnNullForInvalidGitHubRawUrl() + { + const string url = "https://github.com/collinbarrett/FilterLists/blob/master/.gitattributes"; + var actualDates = await new GitHubService().GetCommitDatesAsync(url); + Assert.Null(actualDates); + } + + [Fact] + public async Task ReturnNullForValidGitHubRawUrlToNonexistentFile() + { + const string url = "https://github.com/collinbarrett/FilterLists/blob/master/doesnotexist"; + var actualDates = await new GitHubService().GetCommitDatesAsync(url); + Assert.Null(actualDates); + } + + [Fact] + public async Task ReturnSameFirstAndLastCommitDatesForValidGitHubRawUrlWithOnlyOneCommit() + { + const string url = "https://raw.githubusercontent.com/collinbarrett/FilterLists/master/.gitattributes"; + var expectedDate = DateTime.Parse("2017-04-08T00:05:26.0000000"); + var actualDates = await new GitHubService().GetCommitDatesAsync(url); + Assert.Equal(expectedDate, actualDates.First); + Assert.Equal(expectedDate, actualDates.Last); } } } \ No newline at end of file