File tree Expand file tree Collapse file tree 2 files changed +45
-10
lines changed Expand file tree Collapse file tree 2 files changed +45
-10
lines changed Original file line number Diff line number Diff line change
1
+ using System . IO ;
2
+ using System . Threading . Tasks ;
3
+ using NGitLab . Models ;
4
+ using NUnit . Framework ;
5
+
6
+ namespace NGitLab . Mock . Tests ;
7
+
8
+ public class FileTests
9
+ {
10
+ [ TestCase ( "README.md" , true ) ]
11
+ [ TestCase ( "does-not-exist.md" , false ) ]
12
+ public async Task Test_get_raw_file_async ( string fileToLookUp , bool expectSuccess )
13
+ {
14
+ // Arrange
15
+ using var server = new GitLabServer ( ) ;
16
+ var user = server . Users . AddNew ( ) ;
17
+ var project = user . Namespace . Projects . AddNew ( project => project . Visibility = VisibilityLevel . Internal ) ;
18
+ var initCommit = project . Repository . Commit ( user , "Initial commit" ,
19
+ [
20
+ File . CreateFromText ( "README.md" , "This is the initial content" ) ,
21
+ ] ) ;
22
+
23
+ var client = server . CreateClient ( user ) ;
24
+ var filesClient = client . GetRepository ( project . Id ) . Files ;
25
+
26
+ string downloadedContent = null ;
27
+
28
+ // Act/Assert
29
+ if ( expectSuccess )
30
+ {
31
+ await filesClient . GetRawAsync ( fileToLookUp , async stream =>
32
+ {
33
+ using var streamReader = new StreamReader ( stream ) ;
34
+ downloadedContent = await streamReader . ReadToEndAsync ( ) . ConfigureAwait ( false ) ;
35
+ } ) ;
36
+ Assert . That ( downloadedContent , Is . EqualTo ( "This is the initial content" ) ) ;
37
+ }
38
+ else
39
+ {
40
+ Assert . ThrowsAsync < GitLabException > ( async ( ) => await filesClient . GetRawAsync ( fileToLookUp , _ => Task . CompletedTask ) . ConfigureAwait ( false ) ) ;
41
+ }
42
+ }
43
+ }
Original file line number Diff line number Diff line change 1
1
using System ;
2
- using System . Threading ;
3
2
4
3
namespace NGitLab . Mock . Clients ;
5
4
6
5
internal sealed class ClientContext
7
6
{
8
- private readonly object _operationLock = new ( ) ;
9
-
10
7
public ClientContext ( GitLabServer server , User user )
11
8
{
12
9
Server = server ;
@@ -22,22 +19,17 @@ public ClientContext(GitLabServer server, User user)
22
19
public IDisposable BeginOperationScope ( )
23
20
{
24
21
Server . RaiseOnClientOperation ( ) ;
25
- Monitor . Enter ( _operationLock ) ;
26
- return new Releaser ( _operationLock ) ;
22
+ return new Releaser ( ) ;
27
23
}
28
24
29
25
private sealed class Releaser : IDisposable
30
26
{
31
- private readonly object _operationLock ;
32
-
33
- public Releaser ( object operationLock )
27
+ public Releaser ( )
34
28
{
35
- _operationLock = operationLock ;
36
29
}
37
30
38
31
public void Dispose ( )
39
32
{
40
- Monitor . Exit ( _operationLock ) ;
41
33
}
42
34
}
43
35
}
You can’t perform that action at this time.
0 commit comments