#296 change so tests pass on windows

This commit is contained in:
Tom Pallister 2018-04-17 21:51:41 +01:00
parent b7ff73729f
commit e94df4749c
4 changed files with 30 additions and 31 deletions

View File

@ -1,10 +1,9 @@
using System;
using System.Collections.Generic;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Memory;
namespace Ocelot.DependencyInjection namespace Ocelot.DependencyInjection
{ {
using System;
using System.Collections.Generic;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Memory;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
@ -16,12 +15,16 @@ namespace Ocelot.DependencyInjection
[Obsolete("Please set BaseUrl in ocelot.json GlobalConfiguration.BaseUrl")] [Obsolete("Please set BaseUrl in ocelot.json GlobalConfiguration.BaseUrl")]
public static IConfigurationBuilder AddOcelotBaseUrl(this IConfigurationBuilder builder, string baseUrl) public static IConfigurationBuilder AddOcelotBaseUrl(this IConfigurationBuilder builder, string baseUrl)
{ {
var memorySource = new MemoryConfigurationSource(); var memorySource = new MemoryConfigurationSource
memorySource.InitialData = new List<KeyValuePair<string, string>>
{ {
new KeyValuePair<string, string>("BaseUrl", baseUrl) InitialData = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("BaseUrl", baseUrl)
}
}; };
builder.Add(memorySource); builder.Add(memorySource);
return builder; return builder;
} }
@ -35,11 +38,12 @@ namespace Ocelot.DependencyInjection
.Where(path => reg.IsMatch(path)).Where(x => x.Count(s => s == '.') == 3) .Where(path => reg.IsMatch(path)).Where(x => x.Count(s => s == '.') == 3)
.ToList(); .ToList();
FileConfiguration ocelotConfig = new FileConfiguration(); var fileConfiguration = new FileConfiguration();
foreach (var file in files) foreach (var file in files)
{ {
if(files.Count > 1 && file == "./ocelot.json") // windows and unix sigh...
if(files.Count > 1 && (file == "./ocelot.json" || file == ".\\ocelot.json"))
{ {
continue; continue;
} }
@ -48,16 +52,17 @@ namespace Ocelot.DependencyInjection
var config = JsonConvert.DeserializeObject<FileConfiguration>(lines); var config = JsonConvert.DeserializeObject<FileConfiguration>(lines);
if(file == "./ocelot.global.json") // windows and unix sigh...
if (file == "./ocelot.global.json" || file == ".\\ocelot.global.json")
{ {
ocelotConfig.GlobalConfiguration = config.GlobalConfiguration; fileConfiguration.GlobalConfiguration = config.GlobalConfiguration;
} }
ocelotConfig.Aggregates.AddRange(config.Aggregates); fileConfiguration.Aggregates.AddRange(config.Aggregates);
ocelotConfig.ReRoutes.AddRange(config.ReRoutes); fileConfiguration.ReRoutes.AddRange(config.ReRoutes);
} }
var json = JsonConvert.SerializeObject(ocelotConfig); var json = JsonConvert.SerializeObject(fileConfiguration);
File.WriteAllText("ocelot.json", json); File.WriteAllText("ocelot.json", json);

View File

@ -12,14 +12,14 @@ using Ocelot.Configuration.Repository;
namespace Ocelot.UnitTests.Configuration namespace Ocelot.UnitTests.Configuration
{ {
public class FileConfigurationRepositoryTests : IDisposable public class FileConfigurationRepositoryTests
{ {
private readonly Mock<IHostingEnvironment> _hostingEnvironment = new Mock<IHostingEnvironment>(); private readonly Mock<IHostingEnvironment> _hostingEnvironment = new Mock<IHostingEnvironment>();
private IFileConfigurationRepository _repo; private IFileConfigurationRepository _repo;
private FileConfiguration _result; private FileConfiguration _result;
private FileConfiguration _fileConfiguration; private FileConfiguration _fileConfiguration;
// This is a bit dirty and it is dev.dev so that the configuration tests // This is a bit dirty and it is dev.dev so that the ConfigurationBuilderExtensionsTests
// cant pick it up if they run in parralel..sigh these are not really unit // cant pick it up if they run in parralel..sigh these are not really unit
// tests but whatever... // tests but whatever...
private string _environmentName = "DEV.DEV"; private string _environmentName = "DEV.DEV";
@ -225,10 +225,5 @@ namespace Ocelot.UnitTests.Configuration
ReRoutes = reRoutes ReRoutes = reRoutes
}; };
} }
public void Dispose()
{
File.Delete($"./ocelot.{_environmentName}.json");
}
} }
} }

View File

@ -149,6 +149,7 @@ namespace Ocelot.UnitTests.Configuration
.Then(x => ThenTheFollowingDownstreamIsReturned(downstream)) .Then(x => ThenTheFollowingDownstreamIsReturned(downstream))
.BDDfy(); .BDDfy();
} }
[Fact] [Fact]
public void should_add_trace_id_header() public void should_add_trace_id_header()
{ {

View File

@ -1,16 +1,14 @@
using Microsoft.Extensions.Configuration; namespace Ocelot.UnitTests.DependencyInjection
using Ocelot.DependencyInjection;
using Shouldly;
using TestStack.BDDfy;
using Xunit;
namespace Ocelot.UnitTests.DependencyInjection
{ {
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using Newtonsoft.Json; using Newtonsoft.Json;
using Ocelot.Configuration.File; using Ocelot.Configuration.File;
using Microsoft.Extensions.Configuration;
using Ocelot.DependencyInjection;
using Shouldly;
using TestStack.BDDfy;
using Xunit;
public class ConfigurationBuilderExtensionsTests public class ConfigurationBuilderExtensionsTests
{ {