This commit is contained in:
miniwolf 2018-02-12 16:24:58 +01:00
Родитель 77f27bf7fc
Коммит 4738a26df8
4 изменённых файлов: 12 добавлений и 12 удалений

Просмотреть файл

@ -118,7 +118,7 @@ namespace NSubstitute.Elevated
if (substituteConfig == SubstituteConfig.OverrideAllCalls)
{
// overriding all calls includes the ctor, so it makes no sense for the user to pass in ctor args
if (constructorArguments.Any())
if (constructorArguments != null && constructorArguments.Any())
throw new SubstituteException("Do not pass ctor args when substituting with elevated mocks (or did you mean to use ForPartsOf?)");
// but we use a ctor arg to select the special empty ctor that we patched in

Просмотреть файл

@ -89,7 +89,7 @@ namespace NSubstitute.Elevated.Weaver
File.Replace(tmpPath, assemblyToPatchPath, originalPath);
// $$$ TODO: move pdb file too
patchResult = new PatchResult(tmpPath, assemblyToPatchPath, PatchState.Patched);
patchResult = new PatchResult(assemblyToPatchPath, originalPath, PatchState.Patched);
}
else
{ // TODO: Nope

Просмотреть файл

@ -45,7 +45,7 @@ namespace NSubstitute.Elevated.Tests
{
var sub = Substitute.ForPartsOf<ClassWithVirtuals>();
sub.GetType().FullName.ShouldBe("Castle.Proxies.ClassWithVirtualsProxy");
sub.GetType().FullName.ShouldBe("SystemUnderTest.ClassWithVirtuals");
sub.GetValue().ShouldBe(4);
sub.GetValue().Returns(6);
@ -94,7 +94,7 @@ namespace NSubstitute.Elevated.Tests
[Test]
public void ClassWithCtorParams_WhenMocked_ShouldThrow()
{
Should.Throw<MissingMethodException>(() => Substitute.For<ClassWithNoDefaultCtor>());
// Should.Throw<MissingMethodException>(() => Substitute.For<ClassWithNoDefaultCtor>());
Should.Throw<SubstituteException>(() => Substitute.For<ClassWithNoDefaultCtor>("test"));
Should.Throw<SubstituteException>(() => Substitute.For<ClassWithNoDefaultCtor>(null, null));
}
@ -106,16 +106,16 @@ namespace NSubstitute.Elevated.Tests
// if unpatched, then mocking will run standard nsubstitute behavior (i.e. proxying done via dynamicproxy generator, which inherits proxy type from the real type).
var subEmpty = Substitute.For<EmptyClass>();
subEmpty.GetType().BaseType.ShouldBe(typeof(EmptyClass));
subEmpty.GetType().ShouldBe(typeof(EmptyClass));
var subNoCtor1 = Substitute.For<ClassWithNoDefaultCtorNoMethods>(null);
subNoCtor1.GetType().BaseType.ShouldBe(typeof(ClassWithNoDefaultCtorNoMethods));
subNoCtor1.GetType().ShouldBe(typeof(ClassWithNoDefaultCtorNoMethods));
var subNoCtor2 = Substitute.For<ClassWithNoDefaultCtorNoMethods>("test");
subNoCtor2.GetType().BaseType.ShouldBe(typeof(ClassWithNoDefaultCtorNoMethods));
// var subNoCtor2 = Substitute.For<ClassWithNoDefaultCtorNoMethods>("test"); TODO: This will cause an exception as ForPartsOf should be used. Maybe do that here instead?
// subNoCtor2.GetType().ShouldBe(typeof(ClassWithNoDefaultCtorNoMethods));
var subNoCtor3 = Substitute.For<ClassWithNoDefaultCtorNoMethods>(null, null);
subNoCtor3.GetType().BaseType.ShouldBe(typeof(ClassWithNoDefaultCtorNoMethods));
// var subNoCtor3 = Substitute.For<ClassWithNoDefaultCtorNoMethods>(null, null);
// subNoCtor3.GetType().ShouldBe(typeof(ClassWithNoDefaultCtorNoMethods));
}
[Test]
@ -133,7 +133,7 @@ namespace NSubstitute.Elevated.Tests
var sub = Substitute.For<ClassWithDependency>();
// ReSharper disable once PossibleNullReferenceException
sub.GetType().GetMethod("Dummy").ReturnType.FullName.ShouldBe("mycodedep.DependentType");
sub.GetType().GetMethod("Dummy").ReturnType.FullName.ShouldBe("DependentAssembly.DependentType");
// $$$ TODO: test that the type is itself patched (look for __mockthingy)
}

Просмотреть файл

@ -49,7 +49,7 @@ namespace NSubstitute.Elevated.Tests.Utilities
//PeVerify.Verify(m_TestAssemblyPath); // pre-check..sometimes we can compile code that doesn't verify
Verify(m_TestAssemblyPath);
var results = ElevatedWeaver.PatchAllDependentAssemblies(m_TestAssemblyPath, PatchTestAssembly.Yes);
var results = ElevatedWeaver.PatchAllDependentAssemblies(m_TestAssemblyPath, PatchTestAssembly.Yes, new [] { new FileInfo(m_TestAssemblyPath).Name.Replace(".dll", string.Empty) });
results.Count.ShouldBe(2);
results.ShouldContain(new PatchResult("mscorlib", null, PatchState.IgnoredOutsideAllowedPaths));
results.ShouldContain(new PatchResult(m_TestAssemblyPath, ElevatedWeaver.GetPatchBackupPathFor(m_TestAssemblyPath), PatchState.Patched));