Skip to content

Commit

Permalink
Updates RouteScanner to skip testing libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Offen committed Aug 9, 2019
1 parent f36b953 commit 0e0254d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 96 deletions.
2 changes: 1 addition & 1 deletion src/Grapevine.Tests/Grapevine.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="11.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="NSubstitute" Version="4.0.0" />
<PackageReference Include="OpenCover" Version="4.6.519" />
<PackageReference Include="ReportGenerator" Version="2.5.1" />
Expand Down
2 changes: 1 addition & 1 deletion src/Grapevine.Tests/Server/PublicFolderFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void NoParameters()
[Fact]
public void AbsolutePathShouldNotChange()
{
const string path = @"C:\temp";
const string path = @"C:\temp\kjhgf";

var folder = new PublicFolder(path);

Expand Down
121 changes: 32 additions & 89 deletions src/Grapevine.Tests/Server/RouteScannerFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -634,110 +634,53 @@ public class ScanMethod
[Fact]
public void ReturnsRoutesAndLogs()
{
//ReflectionTypeLoadException exception = null;
//var attempts = 0;

//do
//{
// attempts++;
// exception = null;

// try
// {
var logger = new InMemoryLogger();
var scanner = new RouteScanner { Logger = logger };

logger.Logs.ShouldBeEmpty();

var routes = scanner.Scan();

routes.ShouldNotBeNull();
routes.ShouldNotBeEmpty();
routes.Count.ShouldBeGreaterThanOrEqualTo(2);
logger.Logs.ShouldNotBeEmpty();
// }
// catch (ReflectionTypeLoadException ex)
// {
// exception = ex;
// Thread.Sleep(417);
// }
//} while (exception != null || attempts > 5);

//if (exception != null) throw exception;
var logger = new InMemoryLogger();
var scanner = new RouteScanner { Logger = logger };

logger.Logs.ShouldBeEmpty();

var routes = scanner.Scan();

routes.ShouldNotBeNull();
routes.ShouldNotBeEmpty();
routes.Count.ShouldBeGreaterThanOrEqualTo(2);
logger.Logs.ShouldNotBeEmpty();
}

[Fact]
public void ReturnsRoutesAndLogsWithInclusions()
{
//ReflectionTypeLoadException exception = null;
//var attempts = 0;

//do
//{
// attempts++;
// exception = null;

// try
// {
var logger = new InMemoryLogger();
var scanner = new RouteScanner { Logger = logger };

scanner.Include(Assembly.GetExecutingAssembly());
logger.Logs.ShouldBeEmpty();

var routes = scanner.Scan();

routes.ShouldNotBeNull();
routes.Count.ShouldBe(2);
logger.Logs.ShouldNotBeEmpty();
// }
// catch (ReflectionTypeLoadException ex)
// {
// exception = ex;
// Thread.Sleep(231);
// }
//} while (exception != null || attempts > 5);

//if (exception != null) throw exception;
var logger = new InMemoryLogger();
var scanner = new RouteScanner { Logger = logger };

scanner.Include(Assembly.GetExecutingAssembly());
logger.Logs.ShouldBeEmpty();

var routes = scanner.Scan();

routes.ShouldNotBeNull();
routes.Count.ShouldBe(2);
logger.Logs.ShouldNotBeEmpty();
}

[Fact]
public void ReturnsRoutesAndLogsWithExclusions()
{
//ReflectionTypeLoadException exception = null;
//var attempts = 0;

//do
//{
// attempts++;
// exception = null;

// try
// {
var logger = new InMemoryLogger();
var scanner = new RouteScanner { Logger = logger };

logger.Logs.ShouldBeEmpty();
var logger = new InMemoryLogger();
var scanner = new RouteScanner { Logger = logger };

var routesBefore = scanner.Scan();
logger.Logs.ShouldBeEmpty();

scanner.Exclude(Assembly.GetExecutingAssembly());
var routesBefore = scanner.Scan();

var routesAfter = scanner.Scan();
scanner.Exclude(Assembly.GetExecutingAssembly());

routesBefore.ShouldNotBeNull();
routesAfter.ShouldNotBeNull();
(routesBefore.Count - routesAfter.Count).ShouldBe(2);
logger.Logs.ShouldNotBeEmpty();
// }
// catch (ReflectionTypeLoadException ex)
// {
// exception = ex;
// Thread.Sleep(780);
// }
//} while (exception != null || attempts > 5);
var routesAfter = scanner.Scan();

//if (exception != null) throw exception;
routesBefore.ShouldNotBeNull();
routesAfter.ShouldNotBeNull();
(routesBefore.Count - routesAfter.Count).ShouldBe(2);
logger.Logs.ShouldNotBeEmpty();
}
}

Expand Down
23 changes: 20 additions & 3 deletions src/Grapevine/Grapevine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,30 @@

<PropertyGroup>
<TargetFrameworks>net4;netstandard2.0</TargetFrameworks>
<PackageId>Grapevine</PackageId>
<PackageVersion>$(Version)</PackageVersion>
<Authors>Scott Offen</Authors>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
<FileVersion>4.1.1.0</FileVersion>
<Copyright>© 2014-2019 Scott Offen</Copyright>
<Version>4.1.1.0</Version>
<Owners>Scott Offen</Owners>
<Title>The embeddable, unopinionated minimalist rest framework for .NET</Title>
<Description>The embeddable, unopinionated minimalist rest framework for .NET</Description>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageTags>rest http api web router client server express json xml embedded</PackageTags>
<AssemblyVersion>4.1.2.0</AssemblyVersion>
<FileVersion>4.1.2.0</FileVersion>
<Version>4.1.2.0</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<RepositoryUrl>https://github.com/sukona/Grapevine</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageProjectUrl>https://github.com/sukona/Grapevine/wiki</PackageProjectUrl>
<PackageIconUrl>https://raw.githubusercontent.com/sukona/Grapevine/master/img/grapevine.png</PackageIconUrl>
</PropertyGroup>

<ItemGroup>
<None Include="..\..\LICENSE" Pack="true" Visible="false" PackagePath=""/>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Security.Permissions">
<Version>4.5.0</Version>
Expand Down
9 changes: 7 additions & 2 deletions src/Grapevine/Server/RouteScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,12 @@ static RouteScanner()
foreach (
var assembly in
AppDomain.CurrentDomain.GetAssemblies()
.Where(a => !a.GlobalAssemblyCache && a.GetName().Name != "Grapevine" && !a.GetName().Name.StartsWith("vshost"))
.Where(a => !a.GlobalAssemblyCache
&& a.GetName().Name != "Grapevine"
&& !a.GetName().Name.StartsWith("vshost")
&& !a.GetName().Name.StartsWith("xunit")
&& !a.GetName().Name.StartsWith("Shouldly")
)
#if NETSTANDARD
.Where(x => !x.GetName().Name.Contains("TestPlatform"))
#endif
Expand Down Expand Up @@ -274,7 +279,7 @@ public IList<IRoute> Scan()
}
catch (ReflectionTypeLoadException ex)
{
foreach (var loaderEx in ex.LoaderExceptions)
foreach (var loaderEx in ex.LoaderExceptions)
{
Debug.WriteLine(loaderEx);
Console.WriteLine(loaderEx);
Expand Down

0 comments on commit 0e0254d

Please sign in to comment.