forked from JeringTech/Javascript.NodeJS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpClientServiceUnitTests.cs
More file actions
45 lines (40 loc) · 1.58 KB
/
Copy pathHttpClientServiceUnitTests.cs
File metadata and controls
45 lines (40 loc) · 1.58 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
using Microsoft.Extensions.Options;
using Moq;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using Xunit;
namespace Jering.Javascript.NodeJS.Tests
{
public class HttpClientServiceUnitTests
{
private readonly MockRepository _mockRepository = new(MockBehavior.Default);
[Theory]
[MemberData(nameof(Constructor_SetsTimeout_Data))]
public void Constructor_SetsTimeout(int dummyTimeoutMS, TimeSpan expectedTimeoutMS)
{
// Arrange
var dummyOptions = new OutOfProcessNodeJSServiceOptions() { TimeoutMS = dummyTimeoutMS };
Mock<IOptions<OutOfProcessNodeJSServiceOptions>> mockOptionsAccessor = _mockRepository.Create<IOptions<OutOfProcessNodeJSServiceOptions>>();
mockOptionsAccessor.Setup(o => o.Value).Returns(dummyOptions);
using var dummyHttpClient = new HttpClient();
// Act
var result = new HttpClientService(dummyHttpClient, mockOptionsAccessor.Object);
// Assert
Assert.NotNull(result);
Assert.Equal(expectedTimeoutMS, result.Timeout);
}
public static IEnumerable<object[]> Constructor_SetsTimeout_Data()
{
return new object[][]
{
// -1 == infinite
new object[]{ -1, Timeout.InfiniteTimeSpan},
// All other values == value + 1000
new object[]{ 0, TimeSpan.FromMilliseconds(1000)},
new object[]{ 1000, TimeSpan.FromMilliseconds(2000)}
};
}
}
}