Commit 69dc80a9 authored by Michael Herndon's avatar Michael Herndon

WIP: AB#1 Mettle is now functional

 - fixed the issues with deserializing to MettleTestCase instead of XUnitTestCase
 - fixed issues with parameter injection for test methods.
 - enabled the ServiceProviderFactoryAttribute to inject dependencies for test messages
parent 3f244da2
......@@ -54,11 +54,11 @@ namespace Mettle.Xunit.Sdk
for (int i = 0; i < parameters.Length; i++)
parameterTypes[i] = parameters[i].ParameterType;
testMethodArguments = testMethodArguments ?? new object[0];
if(parameters.Length != testMethodArguments.Length)
var args = testMethodArguments ?? new object[0];
if(parameters.Length != args.Length)
{
var methodArgs = new object[parameters.Length];
Array.Copy(testMethodArguments, methodArgs, testMethodArguments.Length);
Array.Copy(args, methodArgs, args.Length);
for(var i = 0; i < parameters.Length; i++)
{
var obj = methodArgs[i];
......@@ -67,9 +67,11 @@ namespace Mettle.Xunit.Sdk
methodArgs[i] = obj;
}
args = methodArgs;
}
TestMethodArguments = Reflector.ConvertArguments(testMethodArguments, parameterTypes);
TestMethodArguments = Reflector.ConvertArguments(args, parameterTypes);
}
/// <summary>
......
......@@ -83,7 +83,7 @@ namespace Mettle.Xunit.Sdk
var testMethod = new TestMethod(testClass, methodInfo);
var defaultMethodDisplay = (TestMethodDisplay)int.Parse(parts[2]);
var defaultMethodDisplayOptions = (TestMethodDisplayOptions)int.Parse(parts[3]);
return new XunitTestCase(DiagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testMethod);
return new MettleTestCase(DiagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testMethod, null);
}
}
......
......@@ -10,7 +10,7 @@ namespace Mettle
new ConcurrentDictionary<Type, Func<IServiceProvider, object>>();
protected SimpleServiceProvider()
public SimpleServiceProvider()
{
factories.TryAdd(typeof(IAssert), (s) => { return AssertImpl.Current; });
}
......
......@@ -2,17 +2,58 @@ using System;
using Mettle;
using Xunit;
[assembly:ServiceProviderFactory(FactoryType = typeof(Mettle.Xunit.Tests.ServiceBuilder))]
namespace Mettle.Xunit.Tests
{
public class ServiceBuilder : IServiceProviderFactory
{
public IServiceProvider CreateProvider()
{
var provider = new SimpleServiceProvider();
return provider;
}
}
public class ServiceBuilder2: IServiceProviderFactory
{
public IServiceProvider CreateProvider()
{
var provider = new SimpleServiceProvider();
provider.AddTransient(typeof(UnitTestData), (s) => { return new UnitTestData(); });
return provider;
}
}
public class UnitTestData
{
public string Name { get; set; } = "test";
}
public class UnitTest1
{
[UnitTest]
public void Test1()
public void Test1(IAssert assert)
{
assert.Ok("a" == "a");
Console.Write("Test");
}
[UnitTest]
[ServiceProviderFactory(FactoryType = typeof(ServiceBuilder2))]
public void Test3(UnitTestData data)
{
var assert = AssertImpl.Current;
assert.NotNull(data);
}
[Fact]
public void Test2()
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment