-
Notifications
You must be signed in to change notification settings - Fork 116
Tighter validation over Binding Class inheritance #924
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
Draft
clrudolphi
wants to merge
3
commits into
main
Choose a base branch
from
Fix676_InheritanceOfBindings
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...RuntimeTests/Bindings/Discovery/BindingSourceProcessorTestsWithInheritedBindingClasses.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| using FluentAssertions; | ||
| using Reqnroll.Bindings.Discovery; | ||
| using Reqnroll.RuntimeTests.Bindings.Discovery.TestSubjects; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using Xunit; | ||
|
|
||
| namespace Reqnroll.RuntimeTests.Bindings.Discovery; | ||
|
|
||
| public class BindingSourceProcessorTestsWithInheritedBindingClasses | ||
| { | ||
| private BindingSourceProcessorStub CreateBindingSourceProcessor() | ||
| { | ||
| //NOTE: BindingSourceProcessor is abstract, to test its base functionality we need to instantiate a subclass | ||
| return new BindingSourceProcessorStub(); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData(typeof(TestSubjects.DerivedBoundClassBoundMethods_InheritsFromBaseClassNoBindingNoBoundMethods), true, 1, new string[] { })] | ||
| [InlineData(typeof(TestSubjects.DerivedBoundClassBoundMethods_InheritsFromBaseClassNoBindingWithBoundMethods), true, 2, new string[] { })] | ||
| [InlineData(typeof(TestSubjects.DerivedBoundClassBoundMethods_InheritsFromBaseClassWithBindingNoBoundMethods), false, 0, new string[] { "Binding types cannot inherit from other binding types" })] | ||
| [InlineData(typeof(TestSubjects.DerivedBoundClassBoundMethods_InheritsFromBaseClassWithBindingWithBoundMethods), false, 0, new string[] { "Binding types cannot inherit from other binding types" })] | ||
| [InlineData(typeof(TestSubjects.DerivedBoundClassBoundMethodswithBindingaAttributes_InheritsFromBaseClassNoBindingNoBoundMethod), true, 1, new string[] { })] | ||
| [InlineData(typeof(TestSubjects.DerivedBoundClassBoundMethodswithBindingaAttributes_InheritsFromBaseClassNoBindingBoundMethod), true, 1, new string[] { })] | ||
| [InlineData(typeof(TestSubjects.DerivedBoundClassBoundMethodswithBindingaAttributes_InheritsFromBaseClassWithBindingNoBoundMethod), false, 0, new string[] { "Binding types cannot inherit from other binding types" })] | ||
| [InlineData(typeof(TestSubjects.DerivedBoundClassBoundMethodswithBindingaAttributes_InheritsFromBaseClassWithBindingBoundMethod), false, 0, new string[] { "Binding types cannot inherit from other binding types" })] | ||
| [InlineData(typeof(TestSubjects.DerivedBoundClassOverriddenMethodsWithoutBindingAttributes_InheritsFromBaseClassNoBindingBoundMethods), true, 1, new string[] { })] | ||
| [InlineData(typeof(TestSubjects.DerivedBoundClassOverriddenMethodsWithoutBindingAttributes_InheritsFromBaseClassWithBindingBoundMethods), false, 0, new string[] { "Binding types cannot inherit from other binding types" })] | ||
| [InlineData(typeof(TestSubjects.DerivedUnBoundClassNoBoundMethods_InheritsFromBaseClassNoBindingNoBoundMethods), false, 0, new string[] { })] | ||
| [InlineData(typeof(TestSubjects.DerivedUnBoundClassNoBoundMethods_InheritsFromBaseClassNoBindingWithBoundMethods), false, 0, new string[] { })] | ||
| [InlineData(typeof(TestSubjects.DerivedUnBoundClassNoBoundMethods_InheritsFromBaseClassWithBindingNoBoundMethods), true, 0, new string[] { })] | ||
| [InlineData(typeof(TestSubjects.DerivedUnBoundClassNoBoundMethods_InheritsFromBaseClassWithBindingWithBoundMethods), true, 1, new string[] { })] | ||
| [InlineData(typeof(TestSubjects.DerivedUnboundClassWithBoundMethods_InheritsFromBaseClassNoBindingNoBoundMethods), false, 0, new string[] { })] | ||
| [InlineData(typeof(TestSubjects.DerivedUnboundClassWithBoundMethods_InheritsFromBaseClassNoBindingWithBoundMethods), false, 0, new string[] { })] | ||
| [InlineData(typeof(TestSubjects.DerivedUnboundClassWithBoundMethods_InheritsFromBaseClassWithBindingNoBoundMethods), true, 1, new string[] { })] | ||
| [InlineData(typeof(TestSubjects.DerivedUnboundClassWithBoundMethods_InheritsFromBaseClassWithBindingWithBoundMethods), true, 2, new string[] { })] | ||
| [InlineData(typeof(TestSubjects.DerivedUnBoundClassOveriddenMethodsWithBindingAttributes_InheritsFromBaseClassNoBindingNoBoundMethods), false, 0, new string[] { })] | ||
| [InlineData(typeof(TestSubjects.DerivedUnBoundClassOveriddenMethodsWithBindingAttributes_InheritsFromBaseClassNoBindingWithBoundMethods), false, 0, new string[] { })] | ||
| [InlineData(typeof(TestSubjects.DerivedUnBoundClassOveriddenMethodsWithBindingAttributes_InheritsFromBaseClassWithBindingNoBoundMethods), true, 1, new string[] { })] | ||
| [InlineData(typeof(TestSubjects.DerivedUnBoundClassOveriddenMethodsWithBindingAttributes_InheritsFromBaseClassWithBindingWithBoundMethods), true, 1, new string[] { })] | ||
| [InlineData(typeof(TestSubjects.DerivedUnBoundClassOverriddenMethodsWithoutBindingAttributes_InheritsFromBaseClassNoBindingNoBoundMethods), false, 0, new string[] { })] | ||
| [InlineData(typeof(TestSubjects.DerivedUnBoundClassOverriddenMethodsWithoutBindingAttributes_InheritsFromBaseClassNoBindingWithBoundMethods), false, 0, new string[] { })] | ||
| [InlineData(typeof(TestSubjects.DerivedUnBoundClassOverriddenMethodsWithoutBindingAttributes_InheritsFromBaseClassWithBindingNoBoundMethods), true, 0, new string[] { })] | ||
| [InlineData(typeof(TestSubjects.DerivedUnBoundClassOverriddenMethodsWithoutBindingAttributes_InheritsFromBaseClassWithBindingWithBoundMethods), true, 1, new string[] { })] | ||
| public void ProcessType_WithInheritedBindingClasses_ShouldFindBoundMethods(Type bindingClassType, bool outcome, int expectedBoundMethodCount, IEnumerable<string> expectedErrors) | ||
| { | ||
| //ARRANGE | ||
| var sut = CreateBindingSourceProcessor(); | ||
| var builder = new RuntimeBindingRegistryBuilder(sut, new ReqnrollAttributesFilter(), null, null, null); | ||
| //ACT | ||
| builder.BuildBindingsFromType(bindingClassType).Should().Be(outcome); | ||
| sut.BuildingCompleted(); | ||
| //ASSERT | ||
| sut.StepDefinitionBindings.Should().HaveCount(expectedBoundMethodCount); | ||
|
|
||
| foreach (var expectedError in expectedErrors) | ||
| { | ||
| sut.ValidationErrors.Should().Contain(m => m.Contains(expectedError)); | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| } |
39 changes: 39 additions & 0 deletions
39
Tests/Reqnroll.RuntimeTests/Bindings/Discovery/TestSubjects/BaseClasses.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Reqnroll.RuntimeTests.Bindings.Discovery.TestSubjects; | ||
|
|
||
| internal class BaseClassNoBindingNoBoundMethods | ||
| { | ||
| public virtual void UnBoundMethod() | ||
| { | ||
| } | ||
| } | ||
|
|
||
| internal class BaseClassNoBindingWithBoundMethods | ||
| { | ||
| [Given("something")] | ||
| public virtual void GivenSomething() { } | ||
|
|
||
| public virtual void UnBoundMethod() | ||
| { | ||
| } | ||
| } | ||
|
|
||
| [Binding] | ||
| internal class BaseClassWithBindingNoBoundMethods | ||
| { | ||
| public virtual void UnBoundMethod() | ||
| { | ||
| } | ||
| } | ||
|
|
||
| [Binding] | ||
| internal class BaseClassWithBindingWithBoundMethods | ||
| { | ||
| [Given("something")] | ||
| public virtual void GivenSomething() { } | ||
| } |
39 changes: 39 additions & 0 deletions
39
Tests/Reqnroll.RuntimeTests/Bindings/Discovery/TestSubjects/DerivedBoundClassBoundMethods.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Reqnroll.RuntimeTests.Bindings.Discovery.TestSubjects; | ||
|
|
||
| [Binding] | ||
| internal class DerivedBoundClassBoundMethods_InheritsFromBaseClassNoBindingNoBoundMethods : BaseClassNoBindingNoBoundMethods | ||
| { | ||
| public override void UnBoundMethod() { } | ||
|
|
||
| [Given("derived something")] | ||
| public void GivenDerivedSomething() { } | ||
| } | ||
|
|
||
| [Binding] | ||
| internal class DerivedBoundClassBoundMethods_InheritsFromBaseClassWithBindingNoBoundMethods : BaseClassWithBindingNoBoundMethods | ||
| { | ||
| public override void UnBoundMethod() { } | ||
|
|
||
| [Given("derived something")] | ||
| public void GivenDerivedSomething() { } | ||
| } | ||
|
|
||
| [Binding] | ||
| internal class DerivedBoundClassBoundMethods_InheritsFromBaseClassNoBindingWithBoundMethods : BaseClassNoBindingWithBoundMethods | ||
| { | ||
| [Given("derived something")] | ||
| public void GivenDerivedSomething() { } | ||
| } | ||
|
|
||
| [Binding] | ||
| internal class DerivedBoundClassBoundMethods_InheritsFromBaseClassWithBindingWithBoundMethods : BaseClassWithBindingWithBoundMethods | ||
| { | ||
| [Given("derived something")] | ||
| public void GivenDerivedSomething() { } | ||
| } |
23 changes: 23 additions & 0 deletions
23
...ings/Discovery/TestSubjects/DerivedBoundClassOverriddenMethodsWithoutBindingAttributes.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Reqnroll.RuntimeTests.Bindings.Discovery.TestSubjects; | ||
|
|
||
| [Binding] | ||
| internal class DerivedBoundClassOverriddenMethodsWithoutBindingAttributes_InheritsFromBaseClassNoBindingBoundMethods : BaseClassNoBindingWithBoundMethods | ||
| { | ||
| public override void GivenSomething() | ||
| { | ||
| } | ||
| } | ||
|
|
||
| [Binding] | ||
| internal class DerivedBoundClassOverriddenMethodsWithoutBindingAttributes_InheritsFromBaseClassWithBindingBoundMethods : BaseClassWithBindingWithBoundMethods | ||
| { | ||
| public override void GivenSomething() | ||
| { | ||
| } | ||
| } |
47 changes: 47 additions & 0 deletions
47
...ndings/Discovery/TestSubjects/DerivedBoundClassOverriddenMethodswithBindingaAttributes.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Reqnroll.RuntimeTests.Bindings.Discovery.TestSubjects; | ||
|
|
||
| [Binding] | ||
| internal class DerivedBoundClassBoundMethodswithBindingaAttributes_InheritsFromBaseClassNoBindingNoBoundMethod : BaseClassNoBindingNoBoundMethods | ||
| { | ||
| [Given("derived something")] | ||
| public override void UnBoundMethod() | ||
| { | ||
| base.UnBoundMethod(); | ||
| } | ||
| } | ||
|
|
||
| [Binding] | ||
| internal class DerivedBoundClassBoundMethodswithBindingaAttributes_InheritsFromBaseClassNoBindingBoundMethod : BaseClassNoBindingWithBoundMethods | ||
| { | ||
| [Given("something")] | ||
| public override void GivenSomething() | ||
| { | ||
| base.GivenSomething(); | ||
| } | ||
| } | ||
|
|
||
| [Binding] | ||
| internal class DerivedBoundClassBoundMethodswithBindingaAttributes_InheritsFromBaseClassWithBindingNoBoundMethod : BaseClassWithBindingNoBoundMethods | ||
| { | ||
| [Given("derived something")] | ||
| public override void UnBoundMethod() | ||
| { | ||
| base.UnBoundMethod(); | ||
| } | ||
| } | ||
|
|
||
| [Binding] | ||
| internal class DerivedBoundClassBoundMethodswithBindingaAttributes_InheritsFromBaseClassWithBindingBoundMethod : BaseClassWithBindingWithBoundMethods | ||
| { | ||
| [Given("something")] | ||
| public override void GivenSomething() | ||
| { | ||
| base.GivenSomething(); | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
...eqnroll.RuntimeTests/Bindings/Discovery/TestSubjects/DerivedUnBoundClassNoBoundMethods.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Reqnroll.RuntimeTests.Bindings.Discovery.TestSubjects; | ||
|
|
||
| internal class DerivedUnBoundClassNoBoundMethods_InheritsFromBaseClassNoBindingNoBoundMethods : BaseClassNoBindingNoBoundMethods | ||
| { | ||
| public void AnotherUnBoundMethod() | ||
| { | ||
| } | ||
| } | ||
|
|
||
| internal class DerivedUnBoundClassNoBoundMethods_InheritsFromBaseClassNoBindingWithBoundMethods : BaseClassNoBindingWithBoundMethods | ||
| { | ||
| public void AnotherUnBoundMethod() | ||
| { | ||
| } | ||
| } | ||
|
|
||
| internal class DerivedUnBoundClassNoBoundMethods_InheritsFromBaseClassWithBindingNoBoundMethods : BaseClassWithBindingNoBoundMethods | ||
| { | ||
| public void AnotherUnBoundMethod() | ||
| { | ||
| } | ||
| } | ||
|
|
||
| internal class DerivedUnBoundClassNoBoundMethods_InheritsFromBaseClassWithBindingWithBoundMethods : BaseClassWithBindingWithBoundMethods | ||
| { | ||
| public void AnotherUnBoundMethod() | ||
| { | ||
| } | ||
| } |
40 changes: 40 additions & 0 deletions
40
...ndings/Discovery/TestSubjects/DerivedUnBoundClassOveriddenMethodsWithBindingAttributes.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Reqnroll.RuntimeTests.Bindings.Discovery.TestSubjects; | ||
|
|
||
| internal class DerivedUnBoundClassOveriddenMethodsWithBindingAttributes_InheritsFromBaseClassNoBindingNoBoundMethods : BaseClassNoBindingNoBoundMethods | ||
| { | ||
| [Given("derived something")] | ||
| public override void UnBoundMethod() | ||
| { | ||
| } | ||
| } | ||
|
|
||
| internal class DerivedUnBoundClassOveriddenMethodsWithBindingAttributes_InheritsFromBaseClassNoBindingWithBoundMethods : BaseClassNoBindingWithBoundMethods | ||
| { | ||
| [Given("derived something")] | ||
| public override void GivenSomething() | ||
| { | ||
| } | ||
| } | ||
|
|
||
|
|
||
| internal class DerivedUnBoundClassOveriddenMethodsWithBindingAttributes_InheritsFromBaseClassWithBindingNoBoundMethods : BaseClassWithBindingNoBoundMethods | ||
| { | ||
| [Given("derived something")] | ||
| public override void UnBoundMethod() | ||
| { | ||
| } | ||
| } | ||
|
|
||
| internal class DerivedUnBoundClassOveriddenMethodsWithBindingAttributes_InheritsFromBaseClassWithBindingWithBoundMethods : BaseClassWithBindingWithBoundMethods | ||
| { | ||
| [Given("derived something")] | ||
| public override void GivenSomething() | ||
| { | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A safer approach for this would be the following (background: IBindingType instances that correspond to a .NET type must be
RuntimeBindingType).However even with this approach the problem is that the decision about what makes a type "binding type" is duplicated between here and
RuntimeBindingRegistryBuilder. Altogether maybe a better approach would be to collect all "recognized" binding types inProcessType(in a field, like we do for_stepDefinitionBindingBuilders) and scan through all of them in theBuildingCompletedand check if they are among each-others parents.