-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathPingsControllerTests.cs
48 lines (43 loc) · 1.7 KB
/
PingsControllerTests.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
using System.Net;
using AutoFixture.Xunit2;
using FluentAssertions;
using HappyCode.NetCoreBoilerplate.Api.BackgroundServices;
using HappyCode.NetCoreBoilerplate.Api.Controllers;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Xunit;
namespace HappyCode.NetCoreBoilerplate.Api.UnitTests.Controllers
{
public class PingsControllerTests : ControllerTestsBase<PingsController>
{
[Theory, AutoData]
public void GetWebsitePingStatusCode_should_return_Ok_with_expected_result(HttpStatusCode code)
{
//given
var pingServiceMock = Mocker.GetMock<IPingService>();
pingServiceMock.SetupGet(x => x.WebsiteStatusCode)
.Returns(code);
//when
var result = Controller.GetWebsitePingStatusCode() as OkObjectResult;
//then
result.Should().NotBeNull();
result.StatusCode.Should().Be(StatusCodes.Status200OK);
result.Value.Should().BeAssignableTo<string>();
var value = result.Value as string;
value.Should().Contain(code.ToString());
value.Should().Contain(((int)code).ToString());
}
[Fact]
public void GetRandomStatusCode_should_return_Ok_with_expected_result()
{
//when
var result = Controller.GetRandomStatusCode() as OkObjectResult;
//then
result.Should().NotBeNull();
result.StatusCode.Should().Be(StatusCodes.Status200OK);
result.Value.Should().BeAssignableTo<string>();
var value = result.Value as string;
value.Should().NotBeNullOrEmpty();
}
}
}