Skip to content

Commit

Permalink
#531: FIXED: CodeGen/Couchbase unit tests are failing for VS 16.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jefflill committed May 22, 2019
1 parent d9ec0af commit 5516361
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Lib/Neon.Common/Data/RoundtripDataHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static void PersistableInitialize()
return;
}

foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
foreach (var assembly in AppDomain.CurrentDomain.GetUserAssemblies())
{
foreach (var type in assembly.GetTypes())
{
Expand Down
64 changes: 64 additions & 0 deletions Lib/Neon.Common/System/AppDomainExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//-----------------------------------------------------------------------------
// FILE: AppDomainExtensions.cs
// CONTRIBUTOR: Jeff Lill
// COPYRIGHT: Copyright (c) 2016-2019 by neonFORGE, LLC. All rights reserved.
//
// 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 System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace System
{
/// <summary>
/// Implements <see cref="AppDomain"/> extension methods.
/// </summary>
public static class AppDomainExtensions
{
/// <summary>
/// Enumerates all non <b>System</b> and <b>Microsoft</b> assemblies currently
/// loaded in the <see cref="AppDomain"/>. This can be used as a performance
/// optimization when you only need to scan user assemblies.
/// </summary>
/// <param name="appDomain"></param>
/// <returns>The enumerated assemblies.</returns>
/// <remarks>
/// We also use this to work around this Visual Studio bug:
/// <a href="https://github.com/nforgeio/neonKUBE/issues/531"/>
/// </remarks>
public static IEnumerable<Assembly> GetUserAssemblies(this AppDomain appDomain)
{
return appDomain.GetAssemblies()
.Where(assembly =>
{
var fullName = assembly.FullName;
if (fullName == "System" || fullName == "Microsoft")
{
return false;
}
else
{
return !(fullName.StartsWith("System.") || fullName.StartsWith("Microsoft."));
}
});
}
}
}
4 changes: 1 addition & 3 deletions Lib/Neon.Kube.Hosting/HostingLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,9 @@ public static void Initialize()
// end then use the environment specified in the attributes to determine
// which hosting manager class to instantiate and return.

var assemblies = AppDomain.CurrentDomain.GetAssemblies();

environmentToHostingManager = new Dictionary<HostingEnvironments, Type>();

foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
foreach (var assembly in AppDomain.CurrentDomain.GetUserAssemblies())
{
foreach (var type in assembly.GetTypes())
{
Expand Down
2 changes: 1 addition & 1 deletion Lib/Neon.Xunit/Fixtures/TestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private static void EnsureReset()
{
resetMethods = new List<MethodInfo>();

foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
foreach (var assembly in AppDomain.CurrentDomain.GetUserAssemblies())
{
Type[] assemblyTypes;

Expand Down
64 changes: 64 additions & 0 deletions Test/Test.Neon.Common/System/Test_AppDomainExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//-----------------------------------------------------------------------------
// FILE: Test_AppDomainExtensions.cs
// CONTRIBUTOR: Jeff Lill
// COPYRIGHT: Copyright (c) 2016-2019 by neonFORGE, LLC. All rights reserved.
//
// 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 System.Collections.Generic;
using System.IO;
using System.Net;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Newtonsoft;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

using Neon.Common;
using Neon.Collections;
using Neon.Net;
using Neon.Retry;
using Neon.Xunit;

using Xunit;

namespace TestCommon
{
public class Test_AppDomainExtensions
{
[Fact]
[Trait(TestCategory.CategoryTrait, TestCategory.NeonCommon)]
public void GetUserAssemblies()
{
// Verify that we see no [System*] or [Microsoft*] related assemblies and
// also that we scan types from the assemblies that are returned, to verify
// that this method works around this issue:
//
// https://github.com/nforgeio/neonKUBE/issues/531

foreach (var assembly in AppDomain.CurrentDomain.GetUserAssemblies())
{
Assert.NotEqual("System", assembly.FullName);
Assert.NotEqual("Microsoft", assembly.FullName);

Assert.False(assembly.FullName.StartsWith("System."));
Assert.False(assembly.FullName.StartsWith("Microsoft."));

assembly.GetTypes().ToArray();
}
}
}
}

0 comments on commit 5516361

Please sign in to comment.