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 _getFileConfig; private IActionResult _result; public FileConfigurationControllerTests() { _getFileConfig = new Mock(); _controller = new FileConfigurationController(_getFileConfig.Object); } [Fact] public void should_return_file_configuration() { var expected = new OkResponse(new FileConfiguration()); this.Given(x => x.GivenTheGetConfigurationReturns(expected)) .When(x => x.WhenIGetTheFileConfiguration()) .Then(x => x.TheTheGetFileConfigurationIsCalledCorrectly()) .BDDfy(); } private void GivenTheGetConfigurationReturns(Response fileConfiguration) { _getFileConfig .Setup(x => x.Invoke()) .Returns(fileConfiguration); } private void WhenIGetTheFileConfiguration() { _result = _controller.Get(); } private void TheTheGetFileConfigurationIsCalledCorrectly() { _getFileConfig .Verify(x => x.Invoke(), Times.Once); } } }