Unit/integration test updates/additions
- Add Integration test verifying Options dependency injection mechanism works with Config Server data - Fix some unit test so they run on OSX
This commit is contained in:
Родитель
fb1c99228c
Коммит
76fe21d657
|
@ -17,9 +17,23 @@
|
|||
using Spring.Extensions.Configuration.Server.Test;
|
||||
using Xunit;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.AspNet.TestHost;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Hosting;
|
||||
|
||||
namespace Spring.Extensions.Configuration.Server.IntegrationTest
|
||||
{
|
||||
//
|
||||
// NOTE: Some of the tests assume an running Java config server is started
|
||||
// with repository data for application: foo, profile: development
|
||||
//
|
||||
// The easiest way to get that to happen is clone the spring-cloud-config
|
||||
// repo and run the config-server.
|
||||
// eg. git clone https://github.com/spring-cloud/spring-cloud-config.git
|
||||
// cd spring-cloud-config\spring-cloud-config-server
|
||||
// mvn spring-boot:run
|
||||
//
|
||||
|
||||
public class ConfigServerConfigurationExtensionsIntegrationTest
|
||||
{
|
||||
public ConfigServerConfigurationExtensionsIntegrationTest()
|
||||
|
@ -27,9 +41,10 @@ namespace Spring.Extensions.Configuration.Server.IntegrationTest
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void SpringCloudConfigServer_DefaultData()
|
||||
public void SpringCloudConfigServer_ReturnsExpectedDefaultData()
|
||||
{
|
||||
// Arrange
|
||||
|
||||
// Arrange
|
||||
var appsettings = @"
|
||||
{
|
||||
'spring': {
|
||||
|
@ -47,7 +62,7 @@ namespace Spring.Extensions.Configuration.Server.IntegrationTest
|
|||
var configurationBuilder = new ConfigurationBuilder();
|
||||
configurationBuilder.AddJsonFile(path);
|
||||
|
||||
// Act and Assert
|
||||
// Act and Assert (expects Spring Cloud Config server to be running)
|
||||
configurationBuilder.AddConfigServer();
|
||||
IConfigurationRoot root = configurationBuilder.Build();
|
||||
|
||||
|
@ -59,6 +74,23 @@ namespace Spring.Extensions.Configuration.Server.IntegrationTest
|
|||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void SpringCloudConfigServer_ReturnsExpectedDefaultData_AsInjectedOptions()
|
||||
{
|
||||
// Arrange
|
||||
var builder = new WebHostBuilder().UseStartup<TestServerStartup>();
|
||||
|
||||
// Act and Assert (TestServer expects Spring Cloud Config server to be running)
|
||||
using (var server = new TestServer(builder)) {
|
||||
var client = server.CreateClient();
|
||||
string result = await client.GetStringAsync("http://localhost/Home/VerifyAsInjectedOptions");
|
||||
|
||||
Assert.Equal("spam" +
|
||||
"bar"+
|
||||
"Spring Cloud Samples" +
|
||||
"https://github.com/spring-cloud-samples", result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Spring.Extensions.Configuration.Server.IntegrationTest
|
||||
{
|
||||
public class ConfigServerOptions
|
||||
{
|
||||
public string Bar { get; set; }
|
||||
public string Foo { get; set; }
|
||||
public Info Info { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class Info
|
||||
{
|
||||
public string Description { get; set; }
|
||||
public string Url { get; set; }
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Extensions.OptionsModel;
|
||||
|
||||
namespace Spring.Extensions.Configuration.Server.IntegrationTest
|
||||
{
|
||||
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private ConfigServerOptions _options;
|
||||
public HomeController(IOptions<ConfigServerOptions> options)
|
||||
{
|
||||
_options = options.Value;
|
||||
}
|
||||
[HttpGet]
|
||||
public string VerifyAsInjectedOptions()
|
||||
{
|
||||
return _options.Bar + _options.Foo + _options.Info.Description + _options.Info.Url;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Spring.Extensions.Configuration.Server.Test;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Spring.Extensions.Configuration.Server.IntegrationTest
|
||||
{
|
||||
class TestServerStartup
|
||||
{
|
||||
public IConfiguration Configuration { get; set; }
|
||||
|
||||
|
||||
public TestServerStartup()
|
||||
{
|
||||
// These settings match the default java config server
|
||||
var appsettings = @"
|
||||
{
|
||||
'spring': {
|
||||
'cloud': {
|
||||
'config': {
|
||||
'uri': 'http://localhost:8888',
|
||||
'name': 'foo',
|
||||
'environment': 'development'
|
||||
}
|
||||
}
|
||||
}
|
||||
}";
|
||||
var path = ConfigServerTestHelpers.CreateTempFile(appsettings);
|
||||
var builder = new ConfigurationBuilder()
|
||||
.AddJsonFile(path)
|
||||
.AddConfigServer();
|
||||
Configuration = builder.Build();
|
||||
|
||||
}
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddOptions();
|
||||
services.Configure<ConfigServerOptions>(Configuration);
|
||||
|
||||
services.AddMvc();
|
||||
}
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
|
||||
app.UseMvc(routes =>
|
||||
routes.MapRoute(
|
||||
name: "VerifyAsInjectedOptions",
|
||||
template: "{controller=Home}/{action=VerifyAsInjectedOptions}")
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"description": "Integration test project for Spring.Extensions.Configuration.Test",
|
||||
"authors": [ "dtillman" ],
|
||||
|
@ -13,6 +13,8 @@
|
|||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Hosting": "1.0.0-*",
|
||||
"Microsoft.AspNet.Mvc": "6.0.0-*",
|
||||
"Microsoft.Extensions.Configuration": "1.0.0-*",
|
||||
"Microsoft.Extensions.Configuration.Json": "1.0.0-*",
|
||||
"Spring.Extensions.Configuration.Server": "1.0.0-*",
|
||||
|
|
|
@ -30,7 +30,27 @@ namespace Spring.Extensions.Configuration.Server.Test
|
|||
|
||||
// Act and Assert
|
||||
var ex = Assert.Throws<ArgumentNullException>(() => ConfigServerConfigurationExtensions.AddConfigServer(configurationBuilder));
|
||||
Assert.Equal("Value cannot be null.\r\nParameter name: " + nameof(configurationBuilder), ex.Message);
|
||||
Assert.Contains(nameof(configurationBuilder), ex.Message);
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddConfigService_AddsConfigServerProviderToProvidersList()
|
||||
{
|
||||
// Arrange
|
||||
var configurationBuilder = new ConfigurationBuilder();
|
||||
|
||||
// Act and Assert
|
||||
configurationBuilder.AddConfigServer();
|
||||
|
||||
ConfigServerConfigurationProvider configServerProvider = null;
|
||||
foreach (IConfigurationProvider provider in configurationBuilder.Providers)
|
||||
{
|
||||
configServerProvider = provider as ConfigServerConfigurationProvider;
|
||||
if (configServerProvider != null)
|
||||
break;
|
||||
}
|
||||
Assert.NotNull(configServerProvider);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace Spring.Extensions.Configuration.Server.Test
|
|||
|
||||
// Act and Assert
|
||||
var ex = Assert.Throws<ArgumentNullException>(() => new ConfigServerConfigurationProvider(settings));
|
||||
Assert.Equal("Value cannot be null.\r\nParameter name: " + nameof(settings), ex.Message);
|
||||
Assert.Contains(nameof(settings), ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -47,7 +47,7 @@ namespace Spring.Extensions.Configuration.Server.Test
|
|||
|
||||
// Act and Assert
|
||||
var ex = Assert.Throws<ArgumentNullException>(() => new ConfigServerConfigurationProvider(settings, httpClient));
|
||||
Assert.Equal("Value cannot be null.\r\nParameter name: " + nameof(httpClient), ex.Message);
|
||||
Assert.Contains(nameof(httpClient), ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"description": "Unit test project for Spring.Extensions.Configuration.Server",
|
||||
"authors": [ "dtillman" ],
|
||||
|
|
Загрузка…
Ссылка в новой задаче