Add Platform.IsCloudFoundry property to check for VCAP_APPLICATION

This commit is contained in:
Dave Tillman 2018-06-13 10:15:29 -06:00
Родитель ad1455d1a9
Коммит 1fb7f924d9
2 изменённых файлов: 36 добавлений и 0 удалений

Просмотреть файл

@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.Runtime.InteropServices;
namespace Steeltoe.Common
@ -20,9 +21,12 @@ namespace Steeltoe.Common
{
public const string NET_FRAMEWORK = ".NET Framework";
public const string NET_CORE = ".NET Core";
public const string VCAP_APPLICATION = "VCAP_APPLICATION";
public static bool IsFullFramework => RuntimeInformation.FrameworkDescription.StartsWith(NET_FRAMEWORK);
public static bool IsNetCore => RuntimeInformation.FrameworkDescription.StartsWith(NET_CORE);
public static bool IsCloudFoundry => Environment.GetEnvironmentVariable(VCAP_APPLICATION) != null;
}
}

Просмотреть файл

@ -0,0 +1,32 @@
// Copyright 2017 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using Xunit;
namespace Steeltoe.Common.Test
{
public class PlatformTest
{
[Fact]
public void IsCloudFoundry_ReturnsExpected()
{
Assert.False(Platform.IsCloudFoundry);
Environment.SetEnvironmentVariable("VCAP_APPLICATION", "somevalue");
Assert.True(Platform.IsCloudFoundry);
Environment.SetEnvironmentVariable("VCAP_APPLICATION", null);
Assert.False(Platform.IsCloudFoundry);
}
}
}