/
CachedCredentialProviderTest.cs
53 lines (42 loc) · 1.67 KB
/
CachedCredentialProviderTest.cs
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
// Copyright Bastian Eicher
// Licensed under the MIT License
using System;
using System.Net;
using FluentAssertions;
using Moq;
using Xunit;
namespace NanoByte.Common.Net
{
/// <summary>
/// Contains unit tests for <see cref="CachedCredentialProvider"/>
/// </summary>
public class CachedCredentialProviderTest : IDisposable
{
private readonly Mock<ICredentialProvider> _innerMock = new Mock<ICredentialProvider>(MockBehavior.Strict);
private readonly CachedCredentialProvider _provider;
public CachedCredentialProviderTest()
{
_provider = new CachedCredentialProvider(_innerMock.Object);
}
public void Dispose() => _innerMock.VerifyAll();
[Fact]
public void TestGetCredential()
{
var uriOuter = new Uri("http://domain/dir/file");
var uriInner = new Uri("http://domain/dir/");
var credential = new NetworkCredential("userName", "password");
_innerMock.Setup(x => x.GetCredential(uriInner, null)).Returns(credential);
_provider.GetCredential(uriOuter, null).Should().BeSameAs(credential);
_provider.GetCredential(uriOuter, null).Should().BeSameAs(credential);
_innerMock.Verify(x => x.GetCredential(uriInner, null), Times.Exactly(1));
}
[Fact]
public void TestReportInvalid()
{
var uriOuter = new Uri("http://domain/dir/file");
var uriInner = new Uri("http://domain/dir/");
_innerMock.Setup(x => x.ReportInvalid(uriInner));
_provider.ReportInvalid(uriOuter);
}
}
}