Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/handle exceptions while scanning #6

Merged
merged 2 commits into from
Jul 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ nCrunchTemp*
*.ncrunchproject*
*.ncrunchsolution*
*.swp
*.user
99 changes: 99 additions & 0 deletions Main/CodeAnalysis.ruleset
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Custom Rulset" Description="Custom Rulset" ToolsVersion="14.0">
<Rules AnalyzerId="AsyncUsageAnalyzers" RuleNamespace="AsyncUsageAnalyzers">
<Rule Id="UseConfigureAwait" Action="Warning" />
</Rules>
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
<Rule Id="CA1001" Action="Warning" />
<Rule Id="CA1009" Action="Warning" />
<Rule Id="CA1016" Action="Warning" />
<Rule Id="CA1032" Action="None" />
<Rule Id="CA1033" Action="Warning" />
<Rule Id="CA1049" Action="Warning" />
<Rule Id="CA1060" Action="Warning" />
<Rule Id="CA1061" Action="Warning" />
<Rule Id="CA1063" Action="Warning" />
<Rule Id="CA1065" Action="Warning" />
<Rule Id="CA1301" Action="Warning" />
<Rule Id="CA1400" Action="Warning" />
<Rule Id="CA1401" Action="Warning" />
<Rule Id="CA1403" Action="Warning" />
<Rule Id="CA1404" Action="Warning" />
<Rule Id="CA1405" Action="Warning" />
<Rule Id="CA1410" Action="Warning" />
<Rule Id="CA1415" Action="Warning" />
<Rule Id="CA1707" Action="None" />
<Rule Id="CA1720" Action="None" />
<Rule Id="CA1821" Action="Warning" />
<Rule Id="CA1900" Action="Warning" />
<Rule Id="CA1901" Action="Warning" />
<Rule Id="CA2002" Action="Warning" />
<Rule Id="CA2100" Action="Warning" />
<Rule Id="CA2101" Action="Warning" />
<Rule Id="CA2108" Action="Warning" />
<Rule Id="CA2111" Action="Warning" />
<Rule Id="CA2112" Action="Warning" />
<Rule Id="CA2114" Action="Warning" />
<Rule Id="CA2116" Action="Warning" />
<Rule Id="CA2117" Action="Warning" />
<Rule Id="CA2122" Action="Warning" />
<Rule Id="CA2123" Action="Warning" />
<Rule Id="CA2124" Action="Warning" />
<Rule Id="CA2126" Action="Warning" />
<Rule Id="CA2131" Action="Warning" />
<Rule Id="CA2132" Action="Warning" />
<Rule Id="CA2133" Action="Warning" />
<Rule Id="CA2134" Action="Warning" />
<Rule Id="CA2137" Action="Warning" />
<Rule Id="CA2138" Action="Warning" />
<Rule Id="CA2140" Action="Warning" />
<Rule Id="CA2141" Action="Warning" />
<Rule Id="CA2146" Action="Warning" />
<Rule Id="CA2147" Action="Warning" />
<Rule Id="CA2149" Action="Warning" />
<Rule Id="CA2200" Action="Warning" />
<Rule Id="CA2202" Action="Warning" />
<Rule Id="CA2207" Action="Warning" />
<Rule Id="CA2212" Action="Warning" />
<Rule Id="CA2213" Action="Warning" />
<Rule Id="CA2214" Action="Warning" />
<Rule Id="CA2216" Action="Warning" />
<Rule Id="CA2220" Action="Warning" />
<Rule Id="CA2229" Action="Warning" />
<Rule Id="CA2231" Action="Warning" />
<Rule Id="CA2232" Action="Warning" />
<Rule Id="CA2235" Action="Warning" />
<Rule Id="CA2236" Action="Warning" />
<Rule Id="CA2237" Action="Warning" />
<Rule Id="CA2238" Action="Warning" />
<Rule Id="CA2240" Action="Warning" />
<Rule Id="CA2241" Action="Warning" />
<Rule Id="CA2242" Action="Warning" />
<Rule Id="CA1012" Action="Warning" />
</Rules>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SA1003" Action="None" />
<Rule Id="SA1009" Action="None" />
<Rule Id="SA1026" Action="None" />
<Rule Id="SA1101" Action="None" />
<Rule Id="SA1111" Action="None" />
<Rule Id="SA1118" Action="None" />
<Rule Id="SA1127" Action="None" />
<Rule Id="SA1200" Action="None" />
<Rule Id="SA1201" Action="None" />
<Rule Id="SA1202" Action="None" />
<Rule Id="SA1204" Action="None" />
<Rule Id="SA1305" Action="Warning" />
<Rule Id="SA1309" Action="None" />
<Rule Id="SA1402" Action="None" />
<Rule Id="SA1412" Action="Warning" />
<Rule Id="SA1500" Action="None" />
<Rule Id="SA1513" Action="None" />
<Rule Id="SA1516" Action="None" />
<Rule Id="SA1600" Action="None" />
<Rule Id="SA1609" Action="None" />
<Rule Id="SA1623" Action="None" />
<Rule Id="SA1642" Action="None" />
<Rule Id="SA1648" Action="None" />
</Rules>
</RuleSet>
21 changes: 21 additions & 0 deletions Main/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<!-- this file is automatically imported by dotnet, by naming convention, when doing a build -->

<!-- use the same stylecop rules across the solution -->
<PropertyGroup>
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)CodeAnalysis.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<ItemGroup>
<AdditionalFiles Include="$(MSBuildThisFileDirectory)stylecop.json">
<Link>StyleCop.json</Link>
</AdditionalFiles>
</ItemGroup>

<!-- ignore a few temporary files -->
<PropertyGroup>
<DefaultItemExcludes>$(DefaultItemExcludes);**\*.swp;**\*.bak</DefaultItemExcludes>
</PropertyGroup>

</Project>
7 changes: 7 additions & 0 deletions Main/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2018 Kaleb Pederson Software LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Kaleb Pederson Software LLC. All rights reserved.
// Licensed under the MIT license. See LICENSE file alongside the solution file for full license information.

using System;
using System.Collections;
using System.Linq;
Expand All @@ -6,27 +9,12 @@

namespace NUnit.Extension.DependencyInjection.Tests
{
public class TestWithSingleObjectDependency
{
public TestWithSingleObjectDependency(object obj)
{
}
}

public class TestWithTwoObjectDependency
{
public TestWithTwoObjectDependency(object obj, object obj2)
{
}
}


[TestFixture]
public class DependencyInjectingTestFixtureAttributeTests
{
internal class ValidInjectionFactory : IInjectionFactory
{
public static Func<Type, object> FactoryFunc = null;
public static Func<Type, object> FactoryFunc { get; set; }

/// <inheritdoc />
public void Initialize(ITypeDiscoverer typeDiscoverer)
Expand All @@ -52,15 +40,15 @@ public void Discover(object container)
public void Ctor_throws_nothing_if_no_arguments_provided()
{
Assert.That(
() => new DependencyInjectingTestFixtureAttribute(),
() => new DependencyInjectingBaseTestFixtureAttribute(),
Throws.Nothing
);
}

[Test]
public void BuildFrom_throws_an_ArgumentOutOfRangeException_if_factoryType_does_not_implement_IInjectionFactory()
{
var attr = new DependencyInjectingTestFixtureAttribute(typeof(IEnumerable), typeof(ValidTypeDiscoverer));
var attr = new DependencyInjectingBaseTestFixtureAttribute(typeof(IEnumerable), typeof(ValidTypeDiscoverer));
Assert.That(
() => attr.BuildFrom(new TypeWrapper(typeof(IEnumerable))),
Throws.InstanceOf<ArgumentOutOfRangeException>()
Expand All @@ -70,7 +58,7 @@ public void BuildFrom_throws_an_ArgumentOutOfRangeException_if_factoryType_does_
[Test]
public void BuildFrom_does_not_throw_for_valid_type_implementing_IInjectionFactory()
{
var attr = new DependencyInjectingTestFixtureAttribute(typeof(ValidInjectionFactory), typeof(ValidTypeDiscoverer));
var attr = new DependencyInjectingBaseTestFixtureAttribute(typeof(ValidInjectionFactory), typeof(ValidTypeDiscoverer));
Assert.That(
() => attr.BuildFrom(new TypeWrapper(typeof(ValidInjectionFactory))),
Throws.Nothing
Expand All @@ -82,11 +70,25 @@ public void BuildFrom_does_not_throw_for_valid_type_implementing_IInjectionFacto
public void BuildFrom_returns_a_single_TestSuite_named_after_the_test_class(Type type)
{
ValidInjectionFactory.FactoryFunc = t => new object();
var attr = new DependencyInjectingTestFixtureAttribute(typeof(ValidInjectionFactory), typeof(ValidTypeDiscoverer));
var suite = attr.BuildFrom(new TypeWrapper(type));
var attr = new DependencyInjectingBaseTestFixtureAttribute(typeof(ValidInjectionFactory), typeof(ValidTypeDiscoverer));
var suite = attr.BuildFrom(new TypeWrapper(type)).ToList();
Assert.That(suite, Is.Not.Null);
Assert.That(suite.Count(), Is.EqualTo(1));
Assert.That(suite.First().Name, Is.EqualTo(type.Name));
}
}

public class TestWithSingleObjectDependency
{
public TestWithSingleObjectDependency(object obj)
{
}
}

public class TestWithTwoObjectDependency
{
public TestWithTwoObjectDependency(object obj, object obj2)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Linq;
// Copyright (c) Kaleb Pederson Software LLC. All rights reserved.
// Licensed under the MIT license. See LICENSE file alongside the solution file for full license information.

using System.Linq;
using NUnit.Framework;

namespace NUnit.Extension.DependencyInjection.Tests
Expand All @@ -10,21 +13,20 @@ public class InjectingTestSuiteBuilderTests
public void GetParametersFor_returns_TestFixtureParameters_with_injected_instances()
{
var i = 0;
var objects = new [] {new object(), new object()};
var objects = new [] { new object(), new object() };
DependencyInjectingTestFixtureAttributeTests.ValidInjectionFactory.FactoryFunc = t => objects[i++ % 2];
var attr = new InjectingTestSuiteBuilder(
new StaticInjectionFactoryTypeSelector(
typeof(DependencyInjectingTestFixtureAttributeTests.ValidInjectionFactory)),
typeof(DependencyInjectingTestFixtureAttributeTests.ValidInjectionFactory)),
new StaticTypeDiscovererTypeSelector(
typeof(DependencyInjectingTestFixtureAttributeTests.ValidTypeDiscoverer))
);
var suite = attr.GetParametersFor(typeof(TestWithTwoObjectDependency));
var suite = attr.GetParametersFor(typeof(TestWithTwoObjectDependency)).ToList();
Assert.That(suite, Is.Not.Null);
Assert.That(suite.Count(), Is.EqualTo(1));
var testFixtureData = suite.First();
Assert.That(testFixtureData.TestName, Is.EqualTo(nameof(TestWithTwoObjectDependency)));
Assert.That(testFixtureData.Arguments, Is.EqualTo(objects));
}

}
}