mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-05-03 04:52:50 +08:00
53 lines
1.6 KiB
C#
53 lines
1.6 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Moq;
|
|
using Ocelot.Configuration.File;
|
|
using Ocelot.Controllers;
|
|
using Ocelot.Responses;
|
|
using Ocelot.Services;
|
|
using TestStack.BDDfy;
|
|
using Xunit;
|
|
|
|
namespace Ocelot.UnitTests.Controllers
|
|
{
|
|
public class FileConfigurationControllerTests
|
|
{
|
|
private FileConfigurationController _controller;
|
|
private Mock<IGetFileConfiguration> _getFileConfig;
|
|
private IActionResult _result;
|
|
|
|
public FileConfigurationControllerTests()
|
|
{
|
|
_getFileConfig = new Mock<IGetFileConfiguration>();
|
|
_controller = new FileConfigurationController(_getFileConfig.Object);
|
|
}
|
|
|
|
[Fact]
|
|
public void should_return_file_configuration()
|
|
{
|
|
var expected = new OkResponse<FileConfiguration>(new FileConfiguration());
|
|
|
|
this.Given(x => x.GivenTheGetConfigurationReturns(expected))
|
|
.When(x => x.WhenIGetTheFileConfiguration())
|
|
.Then(x => x.TheTheGetFileConfigurationIsCalledCorrectly())
|
|
.BDDfy();
|
|
}
|
|
|
|
private void GivenTheGetConfigurationReturns(Response<FileConfiguration> fileConfiguration)
|
|
{
|
|
_getFileConfig
|
|
.Setup(x => x.Invoke())
|
|
.Returns(fileConfiguration);
|
|
}
|
|
|
|
private void WhenIGetTheFileConfiguration()
|
|
{
|
|
_result = _controller.Get();
|
|
}
|
|
|
|
private void TheTheGetFileConfigurationIsCalledCorrectly()
|
|
{
|
|
_getFileConfig
|
|
.Verify(x => x.Invoke(), Times.Once);
|
|
}
|
|
}
|
|
} |