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

Port old routing/autovalue tests to new suite #699

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System;
using NSubstitute.Routing.AutoValues;
using NSubstitute.Specs.Infrastructure;
using NUnit.Framework;

namespace NSubstitute.Specs.Routing.AutoValues
{
public class AutoArrayProviderSpecs : ConcernFor<AutoArrayProvider>
public class AutoArrayProviderSpecs
{
AutoArrayProvider sut = CreateSubjectUnderTest();

[Test]
public void Can_provide_value_for_arrays()
{
Expand All @@ -28,7 +29,7 @@ public void Provides_empty_array_value()
Assert.That(array, Is.Empty);
}

public override AutoArrayProvider CreateSubjectUnderTest()
private static AutoArrayProvider CreateSubjectUnderTest()
{
return new AutoArrayProvider();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#if NET45 || NETSTANDARD1_3
using NSubstitute.Routing.AutoValues;
using NSubstitute.Specs.Infrastructure;
using NUnit.Framework;
using System.Linq;
using System.Collections.Generic;

namespace NSubstitute.Specs.Routing.AutoValues
{
public class AutoQueryableProviderSpecs : ConcernFor<AutoQueryableProvider>
public class AutoQueryableProviderSpecs
{

AutoQueryableProvider sut = new AutoQueryableProvider();

[Test]
public void Can_provide_value_for_queryables()
{
Expand Down Expand Up @@ -76,11 +77,6 @@ public void Substitute_should_automock_queryable()
Assert.DoesNotThrow(() => queryable.Any());
}

public override AutoQueryableProvider CreateSubjectUnderTest()
{
return new AutoQueryableProvider();
}

public interface IFoo2
{
IQueryable<object> GetObject();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System;
using NSubstitute.Routing.AutoValues;
using NSubstitute.Specs.Infrastructure;
using NUnit.Framework;

namespace NSubstitute.Specs.Routing.AutoValues
{
public class AutoStringProviderSpecs : ConcernFor<AutoStringProvider>
public class AutoStringProviderSpecs
{
AutoStringProvider sut = CreateSubjectUnderTest();

[Test]
public void Can_provide_value_for_string()
{
Expand All @@ -25,7 +26,7 @@ public void Can_not_provide_a_value_for_an_int_because_that_would_be_silly()
Assert.That(sut.CanProvideValueFor(typeof(int)), Is.False);
}

public override AutoStringProvider CreateSubjectUnderTest()
private static AutoStringProvider CreateSubjectUnderTest()
{
return new AutoStringProvider();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,52 @@
using System;
using System.Collections.Generic;
using NSubstitute.Core;
using NSubstitute.Routing.AutoValues;
using NSubstitute.Specs.Infrastructure;
using NSubstitute.Specs.SampleStructures;
using NUnit.Framework;

namespace NSubstitute.Specs.Routing.AutoValues
{
public class AutoSubstituteProviderSpecs : ConcernFor<AutoSubstituteProvider>
public class AutoSubstituteProviderSpecs
{
private ISubstituteFactory _substituteFactory;
public interface IFoo
{
void Goo();
string Bar(int aNumber, string aString);
event EventHandler Boo;
}

private class TestSubstituteFactory : ISubstituteFactory
{
private IDictionary<Type, object> stubs = new Dictionary<Type, object>();
public void StubCreateFor<T>(object o) => stubs[typeof(T)] = o;
public object Create(Type[] typesToProxy, object[] constructorArguments) => stubs[typesToProxy[0]];

public object CreatePartial(Type[] typesToProxy, object[] constructorArguments)
{
throw new NotImplementedException();
}
}

private TestSubstituteFactory _substituteFactory;

private AutoSubstituteProvider sut;

public AutoSubstituteProviderSpecs()
{
_substituteFactory = new TestSubstituteFactory();
sut = new AutoSubstituteProvider(_substituteFactory);
}

[Test]
public void Can_provide_value_for_interface()
{
Assert.That(sut.CanProvideValueFor(typeof (IFoo)));
Assert.That(sut.CanProvideValueFor(typeof(IFoo)));
}

[Test]
public void Can_provide_value_for_delegates()
{
Assert.That(sut.CanProvideValueFor(typeof (Func<int>)));
Assert.That(sut.CanProvideValueFor(typeof(Func<int>)));
}

[Test]
Expand Down Expand Up @@ -71,19 +97,9 @@ public void Should_not_provide_value_for_value_type()
public void Should_create_substitute_for_type()
{
var autoValue = new object();
_substituteFactory.stub(x => x.Create(new[] {typeof (IFoo)}, new object[0])).Return(autoValue);

Assert.That(sut.GetValue(typeof (IFoo)), Is.SameAs(autoValue));
}
_substituteFactory.StubCreateFor<IFoo>(autoValue);

public override void Context()
{
_substituteFactory = mock<ISubstituteFactory>();
}

public override AutoSubstituteProvider CreateSubjectUnderTest()
{
return new AutoSubstituteProvider(_substituteFactory);
Assert.That(sut.GetValue(typeof(IFoo)), Is.SameAs(autoValue));
}

public class TestClasses
Expand Down Expand Up @@ -139,7 +155,7 @@ public class VirtualClassWithInternalConstructor { internal VirtualClassWithInte

public class PureVirtualClassWithAPublicStaticMethod
{
public static void StaticMethod() {}
public static void StaticMethod() { }
}

public class PureVirtualClassWithAPublicStaticProperty
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
#if (NET4 || NET45)
using System;
using System.Threading.Tasks;
using NSubstitute.Routing.AutoValues;
using NSubstitute.Specs.Infrastructure;
using NUnit.Framework;
using System.Collections.Generic;

namespace NSubstitute.Specs.Routing.AutoValues
{
public class AutoTaskProviderSpecs : ConcernFor<AutoTaskProvider>
public class AutoTaskProviderSpecs
{
private IAutoValueProvider _testValuesProvider;
private class TestAutoValueProvider : IAutoValueProvider {
private IDictionary<Type, object> stubs = new Dictionary<Type, object>();
public void Stub<T>(T value) => stubs[typeof(T)] = value;
public bool CanProvideValueFor(Type type) => stubs.ContainsKey(type);
public object GetValue(Type type) => stubs[type];
}

private TestAutoValueProvider _testValuesProvider;
private AutoTaskProvider sut;

public AutoTaskProviderSpecs()
{
_testValuesProvider = new TestAutoValueProvider();
sut = new AutoTaskProvider(
new Lazy<IReadOnlyCollection<IAutoValueProvider>>( () => new [] { _testValuesProvider })
);
}

[Test]
public void Should_create_substitute_with_another_auto_value_provider_if_available()
{
const string autoValue = "test";
_testValuesProvider.stub(x => x.CanProvideValueFor(typeof(string))).Return(true);
_testValuesProvider.stub(x => x.GetValue(typeof(string))).Return(autoValue);
_testValuesProvider.Stub(autoValue);

var type = typeof (Task<string>);
Assert.True(sut.CanProvideValueFor(type));
Expand Down Expand Up @@ -66,16 +81,6 @@ public void Substitute_should_automock_task()
Assert.Null(task.Result);
}

public override void Context()
{
_testValuesProvider = mock<IAutoValueProvider>();
}

public override AutoTaskProvider CreateSubjectUnderTest()
{
return new AutoTaskProvider(() => new[] { _testValuesProvider });
}

public interface IFoo2
{
Task<object> GetObjectAsync();
Expand Down

This file was deleted.