-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathGitHubRepositoryLoaderTests.cs
More file actions
165 lines (140 loc) · 5.06 KB
/
GitHubRepositoryLoaderTests.cs
File metadata and controls
165 lines (140 loc) · 5.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// Copyright (c) 2022-2025, Atypical Consulting SRL
// All rights reserved... but seriously, we're open to sharing if you ask nicely!
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.
namespace VirtualFileSystem.GitHub.Tests;
public class GitHubRepositoryLoaderTests
{
private readonly GitHubRepositoryLoader _loader;
public GitHubRepositoryLoaderTests()
{
_loader = new GitHubRepositoryLoader();
}
[Theory]
[InlineData("https://github.com/owner/repo", "owner", "repo")]
[InlineData("https://github.com/microsoft/dotnet", "microsoft", "dotnet")]
[InlineData("https://www.github.com/owner/repo", "owner", "repo")]
[InlineData("http://github.com/owner/repo", "owner", "repo")]
[InlineData("https://github.com/owner/repo/", "owner", "repo")]
[InlineData("https://github.com/owner/repo.git", "owner", "repo")]
[InlineData("https://github.com/owner/repo/tree/main", "owner", "repo")]
[InlineData("https://github.com/owner/repo/blob/main/README.md", "owner", "repo")]
[InlineData("https://github.com/owner-name/repo-name", "owner-name", "repo-name")]
[InlineData("https://github.com/owner_name/repo_name", "owner_name", "repo_name")]
public void TryParseGitHubUrl_WithValidUrls_ShouldReturnTrue(string url, string expectedOwner, string expectedRepo)
{
// Act
var result = _loader.TryParseGitHubUrl(url, out var owner, out var repo);
// Assert
result.ShouldBeTrue();
owner.ShouldBe(expectedOwner);
repo.ShouldBe(expectedRepo);
}
[Theory]
[InlineData("")]
[InlineData(null)]
[InlineData("not-a-url")]
[InlineData("https://gitlab.com/owner/repo")]
[InlineData("https://bitbucket.org/owner/repo")]
[InlineData("https://github.com/")]
[InlineData("https://github.com/owner")]
[InlineData("ftp://github.com/owner/repo")]
public void TryParseGitHubUrl_WithInvalidUrls_ShouldReturnFalse(string? url)
{
// Act
var result = _loader.TryParseGitHubUrl(url!, out var owner, out var repo);
// Assert
result.ShouldBeFalse();
owner.ShouldBeEmpty();
repo.ShouldBeEmpty();
}
[Fact]
public void Constructor_WithDefaultOptions_ShouldNotThrow()
{
// Act & Assert
var action = () => new GitHubRepositoryLoader();
action.ShouldNotThrow();
}
[Fact]
public void Constructor_WithAccessToken_ShouldNotThrow()
{
// Act & Assert
var action = () => new GitHubRepositoryLoader("test-token");
action.ShouldNotThrow();
}
[Fact]
public void Constructor_WithOptions_ShouldNotThrow()
{
// Arrange
var options = new GitHubLoaderOptions(
AccessToken: "test-token",
Branch: "main",
MaxFileSize: 5_000_000);
// Act & Assert
var action = () => new GitHubRepositoryLoader(options);
action.ShouldNotThrow();
}
[Fact]
public async Task LoadRepositoryAsync_WithNullVfs_ShouldThrowArgumentNullException()
{
// Arrange & Act
var action = () => _loader.LoadRepositoryAsync(null!, "owner", "repo");
// Assert
var ex = await Should.ThrowAsync<ArgumentNullException>(action);
ex.ParamName.ShouldBe("vfs");
}
[Theory]
[InlineData("")]
[InlineData(" ")]
[InlineData(null)]
public async Task LoadRepositoryAsync_WithInvalidOwner_ShouldThrowArgumentException(string? owner)
{
// Arrange
var vfs = new VFS();
// Act
var action = () => _loader.LoadRepositoryAsync(vfs, owner!, "repo");
// Assert
var ex = await Should.ThrowAsync<ArgumentException>(action);
ex.ParamName.ShouldBe("owner");
}
[Theory]
[InlineData("")]
[InlineData(" ")]
[InlineData(null)]
public async Task LoadRepositoryAsync_WithInvalidRepository_ShouldThrowArgumentException(string? repository)
{
// Arrange
var vfs = new VFS();
// Act
var action = () => _loader.LoadRepositoryAsync(vfs, "owner", repository!);
// Assert
var ex = await Should.ThrowAsync<ArgumentException>(action);
ex.ParamName.ShouldBe("repository");
}
[Fact]
public async Task LoadRepositoryFromUrlAsync_WithInvalidUrl_ShouldThrowArgumentException()
{
// Arrange
var vfs = new VFS();
// Act
var action = () => _loader.LoadRepositoryFromUrlAsync(vfs, "not-a-valid-url");
// Assert
var ex = await Should.ThrowAsync<ArgumentException>(action);
ex.ParamName.ShouldBe("repositoryUrl");
}
[Fact]
public async Task TryLoadRepositoryAsync_WithNonExistentRepo_ShouldReturnFalse()
{
// Arrange
var vfs = new VFS();
// Act
var (success, result) = await _loader.TryLoadRepositoryAsync(
vfs,
"non-existent-owner-12345",
"non-existent-repo-67890");
// Assert
success.ShouldBeFalse();
result.ShouldBeNull();
}
}