-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
separate typeinfo and testclass interfaces to avoid hack
- Loading branch information
1 parent
4d98319
commit 9ff9a4c
Showing
10 changed files
with
123 additions
and
97 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
86 changes: 25 additions & 61 deletions
86
src/SpecFlow.xUnitAdapter.SpecFlowPlugin/TestArtifacts/SpecFlowFeatureTestClass.cs
This file contains 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 |
---|---|---|
@@ -1,84 +1,48 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using TechTalk.SpecFlow.Parser; | ||
using System; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
namespace SpecFlow.xUnitAdapter.SpecFlowPlugin.TestArtifacts | ||
{ | ||
public abstract class SpecFlowFeatureTestClass : LongLivedMarshalByRefObject, ITypeInfo, IReflectionTypeInfo, ITestClass | ||
public class SpecFlowFeatureTestClass : LongLivedMarshalByRefObject, ITestClass | ||
{ | ||
public string FeatureName { get; set; } | ||
public string RelativePath { get; private set; } | ||
public SpecFlowProjectAssemblyInfo SpecFlowProject { get; private set; } | ||
|
||
public virtual string FeatureFilePath { get; protected set; } | ||
|
||
IAssemblyInfo ITypeInfo.Assembly => SpecFlowProject; | ||
string ITypeInfo.Name => (FeatureName ?? RelativePath).Replace(".", ""); | ||
Type IReflectionTypeInfo.Type { get { return typeof(SpecFlowGenericFixtureType); } } | ||
|
||
public ITypeInfo Class => this; | ||
public ITypeInfo Class { get; private set; } | ||
public ITestCollection TestCollection { get; private set; } | ||
|
||
#region ITypeInfo default implementation | ||
IEnumerable<IAttributeInfo> ITypeInfo.GetCustomAttributes(string assemblyQualifiedAttributeTypeName) => Enumerable.Empty<IAttributeInfo>(); | ||
IEnumerable<ITypeInfo> ITypeInfo.GetGenericArguments() => Enumerable.Empty<ITypeInfo>(); | ||
IMethodInfo ITypeInfo.GetMethod(string methodName, bool includePrivateMethod) => null; | ||
IEnumerable<IMethodInfo> ITypeInfo.GetMethods(bool includePrivateMethods) => Enumerable.Empty<IMethodInfo>(); | ||
ITypeInfo ITypeInfo.BaseType => null; | ||
IEnumerable<ITypeInfo> ITypeInfo.Interfaces => Enumerable.Empty<ITypeInfo>(); | ||
bool ITypeInfo.IsAbstract => false; | ||
bool ITypeInfo.IsGenericParameter => false; | ||
bool ITypeInfo.IsGenericType => false; | ||
bool ITypeInfo.IsSealed => false; | ||
bool ITypeInfo.IsValueType => false; | ||
#endregion | ||
|
||
protected SpecFlowFeatureTestClass() { } | ||
public SpecFlowFeatureTypeInfo FeatureTypeInfo => (SpecFlowFeatureTypeInfo)Class; | ||
|
||
protected SpecFlowFeatureTestClass(SpecFlowProjectAssemblyInfo specFlowProject, string relativePath) | ||
[Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")] | ||
public SpecFlowFeatureTestClass() | ||
{ | ||
SpecFlowProject = specFlowProject; | ||
RelativePath = relativePath; | ||
} | ||
|
||
internal void Hack_SetTestCollection(ITestCollection testCollection) | ||
public SpecFlowFeatureTestClass(ITestCollection testCollection, ITypeInfo typeInfo) | ||
{ | ||
TestCollection = testCollection; | ||
} | ||
|
||
protected ISpecFlowSourceMapper SpecFlowSourceMapper { get; } = new SpecFlowSourceMapperV1(); | ||
if (!(typeInfo is SpecFlowFeatureTypeInfo)) | ||
throw new ArgumentException($"Must me an instance of {nameof(SpecFlowFeatureTypeInfo)}", "typeInfo"); | ||
|
||
public virtual void Deserialize(IXunitSerializationInfo data) | ||
{ | ||
SpecFlowProject = data.GetValue<SpecFlowProjectAssemblyInfo>("SpecFlowProject"); | ||
RelativePath = data.GetValue<string>("RelativePath"); | ||
TestCollection = data.GetValue<ITestCollection>("TestCollection"); | ||
TestCollection = testCollection; | ||
Class = typeInfo; | ||
} | ||
|
||
public virtual void Serialize(IXunitSerializationInfo data) | ||
public void Serialize(IXunitSerializationInfo info) | ||
{ | ||
data.AddValue("SpecFlowProject", SpecFlowProject); | ||
data.AddValue("RelativePath", RelativePath); | ||
data.AddValue("TestCollection", TestCollection); | ||
info.AddValue("TestCollection", TestCollection); | ||
info.AddValue("SpecFlowProject", FeatureTypeInfo.SpecFlowProject); | ||
info.AddValue("RelativePath", FeatureTypeInfo.RelativePath); | ||
info.AddValue("TypeInfoKind", Class.GetType().Name); | ||
} | ||
|
||
protected SpecFlowDocument ParseDocument(string content, string path, SpecFlowGherkinParser parser) | ||
public void Deserialize(IXunitSerializationInfo info) | ||
{ | ||
var sourceMap = this.SpecFlowSourceMapper.ReadSourceMap(content); | ||
|
||
this.FeatureFilePath = sourceMap?.SourcePath ?? path; | ||
|
||
return parser.Parse(new StringReader(content), this.FeatureFilePath); | ||
TestCollection = info.GetValue<ITestCollection>("TestCollection"); | ||
var specFlowProject = info.GetValue<SpecFlowProjectAssemblyInfo>("SpecFlowProject"); | ||
var relativePath = info.GetValue<string>("RelativePath"); | ||
var typeInfoKind = info.GetValue<string>("TypeInfoKind"); | ||
if (typeInfoKind == nameof(FeatureFileTypeInfo)) | ||
Class = new FeatureFileTypeInfo(specFlowProject, relativePath); | ||
else if (typeInfoKind == nameof(EmbeddedFeatureTypeInfo)) | ||
Class = new EmbeddedFeatureTypeInfo(specFlowProject, relativePath); | ||
} | ||
|
||
public abstract SpecFlowDocument GetDocument(); | ||
|
||
public abstract Task<SpecFlowDocument> GetDocumentAsync(); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/SpecFlow.xUnitAdapter.SpecFlowPlugin/TestArtifacts/SpecFlowFeatureTypeInfo.cs
This file contains 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,61 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using TechTalk.SpecFlow.Parser; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace SpecFlow.xUnitAdapter.SpecFlowPlugin.TestArtifacts | ||
{ | ||
public abstract class SpecFlowFeatureTypeInfo : LongLivedMarshalByRefObject, ITypeInfo, IReflectionTypeInfo | ||
{ | ||
public string FeatureName { get; set; } | ||
public string RelativePath { get; } | ||
public SpecFlowProjectAssemblyInfo SpecFlowProject { get; } | ||
|
||
public virtual string FeatureFilePath { get; protected set; } | ||
|
||
IAssemblyInfo ITypeInfo.Assembly => SpecFlowProject; | ||
string ITypeInfo.Name => (FeatureName ?? RelativePath).Replace(".", ""); | ||
Type IReflectionTypeInfo.Type => typeof(SpecFlowGenericFixtureType); | ||
|
||
#region ITypeInfo default implementation | ||
IEnumerable<IAttributeInfo> ITypeInfo.GetCustomAttributes(string assemblyQualifiedAttributeTypeName) => Enumerable.Empty<IAttributeInfo>(); | ||
IEnumerable<ITypeInfo> ITypeInfo.GetGenericArguments() => Enumerable.Empty<ITypeInfo>(); | ||
IMethodInfo ITypeInfo.GetMethod(string methodName, bool includePrivateMethod) => null; | ||
IEnumerable<IMethodInfo> ITypeInfo.GetMethods(bool includePrivateMethods) => Enumerable.Empty<IMethodInfo>(); | ||
ITypeInfo ITypeInfo.BaseType => null; | ||
IEnumerable<ITypeInfo> ITypeInfo.Interfaces => Enumerable.Empty<ITypeInfo>(); | ||
bool ITypeInfo.IsAbstract => false; | ||
bool ITypeInfo.IsGenericParameter => false; | ||
bool ITypeInfo.IsGenericType => false; | ||
bool ITypeInfo.IsSealed => false; | ||
bool ITypeInfo.IsValueType => false; | ||
#endregion | ||
|
||
protected SpecFlowFeatureTypeInfo() { } | ||
|
||
protected SpecFlowFeatureTypeInfo(SpecFlowProjectAssemblyInfo specFlowProject, string relativePath) | ||
{ | ||
SpecFlowProject = specFlowProject; | ||
RelativePath = relativePath; | ||
} | ||
|
||
protected ISpecFlowSourceMapper SpecFlowSourceMapper { get; } = new SpecFlowSourceMapperV1(); | ||
|
||
protected SpecFlowDocument ParseDocument(string content, string path, SpecFlowGherkinParser parser) | ||
{ | ||
var sourceMap = this.SpecFlowSourceMapper.ReadSourceMap(content); | ||
|
||
this.FeatureFilePath = sourceMap?.SourcePath ?? path; | ||
|
||
return parser.Parse(new StringReader(content), this.FeatureFilePath); | ||
} | ||
|
||
public abstract SpecFlowDocument GetDocument(); | ||
|
||
public abstract Task<SpecFlowDocument> GetDocumentAsync(); | ||
} | ||
} |
This file contains 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