Skip to content

Commit

Permalink
Remove obsolete methods (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
twsouthwick authored Jan 27, 2021
1 parent f1b76bb commit 9e7498b
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 131 deletions.
20 changes: 0 additions & 20 deletions AutofacContrib.NSubstitute.Tests/ExampleFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,26 +166,6 @@ public void Example_test_with_concrete_object_provided()
Assert.That(result, Is.EqualTo(val1 + val2));
}

[Test]
[Obsolete]
public void Example_test_with_substitute_for_concrete_resolved_from_autofac()
{
const int val1 = 2;
const int val2 = 3;
const int val3 = 4;

using var mock = AutoSubstitute.Configure()
.ResolveAndSubstituteFor<ConcreteClassWithDependency>(new TypedParameter(typeof(int), val1))
.Build();

mock.Resolve<IDependency2>().SomeOtherMethod().Returns(val2);
mock.Resolve<IDependency1>().SomeMethod(val1).Returns(val3);

var result = mock.Resolve<MyClassWithConcreteDependencyThatHasDependencies>().AMethod();

Assert.That(result, Is.EqualTo(val2 * val3 * 2));
}

[Test]
public void Example_provide_service()
{
Expand Down
19 changes: 0 additions & 19 deletions AutofacContrib.NSubstitute.Tests/SubstituteForFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,6 @@ public ConcreteTest(Concrete1 c1)
public Concrete3 Get() => _c2.Get();
}

[Test]
[Obsolete]
public void Example_test_with_substitute_for_concrete_obsolete()
{
const int val1 = 3;
const int val2 = 2;
const int val3 = 10;

using var utoSubstitute = AutoSubstitute.Configure()
.SubstituteFor<ConcreteClass>(val2).Configure(c => c.Add(Arg.Any<int>()).Returns(val3))
.Build();

utoSubstitute.Resolve<IDependency2>().SomeOtherMethod().Returns(val1);

var result = utoSubstitute.Resolve<MyClassWithConcreteDependency>().AMethod();

Assert.That(result, Is.EqualTo(val3));
}

[Test]
public void Example_test_with_substitute_for_concrete()
{
Expand Down
14 changes: 0 additions & 14 deletions AutofacContrib.NSubstitute.Tests/TypesToSkipForMockingFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,6 @@ public void WithoutOption()
Assert.AreEqual(impl2.Value, items[1]);
}

[Test]
[Obsolete]
public void ManuallyAddTypeToSkip()
{
var mock = AutoSubstitute.Configure()
.ConfigureOptions(options =>
{
options.TypesToSkipForMocking.Add(typeof(IDependency));
})
.Build();

Assert.Throws<ComponentNotRegisteredException>(() => mock.Resolve<IDependency>());
}

[Test]
public void ManuallyCheckTypeToSkip()
{
Expand Down
14 changes: 0 additions & 14 deletions AutofacContrib.NSubstitute/AutoMock.cs

This file was deleted.

19 changes: 0 additions & 19 deletions AutofacContrib.NSubstitute/AutoSubstituteBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,25 +231,6 @@ public SubstituteForBuilder<TService> SubstituteForPartsOf<TService>(params obje
where TService : class
=> CreateSubstituteForBuilder(() => Substitute.ForPartsOf<TService>(parameters), false);

/// <summary>
/// Registers to the container and returns a substitute for a given concrete class using autofac to resolve the constructor parameters.
/// This is used for concrete classes where NSubstitutes won't be created by default by the container when using Resolve.
/// For advanced uses consider using directly <see cref="Substitute.For{TService}"/> and then calling <see cref="Provide{TService}(TService)"/> so that type is used on dependencies for other Resolved types.
/// </summary>
/// <typeparam name="TService">The type to register and return a substitute for</typeparam>
/// <param name="parameters">Any constructor parameters that Autofac can't resolve automatically</param>
/// <returns>The current <see cref="AutoSubstituteBuilder"/>.</returns>
[Obsolete("Use a Provide method instead")]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public AutoSubstituteBuilder ResolveAndSubstituteFor<TService>(params Parameter[] parameters) where TService : class
{
_builder.RegisterType<TService>()
.WithParameters(parameters)
.InstancePerLifetimeScope();

return this;
}

private SubstituteForBuilder<TService> CreateSubstituteForBuilder<TService>(Func<TService> factory, bool isSubstituteFor)
where TService : class
{
Expand Down
14 changes: 0 additions & 14 deletions AutofacContrib.NSubstitute/AutoSubstituteOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,6 @@ public AutoSubstituteOptions()
/// </summary>
public ICollection<Action<IRegistrationBuilder<object, ConcreteReflectionActivatorData, SingleRegistrationStyle>>> ConfigureAnyConcreteTypeRegistration { get; } = new List<Action<IRegistrationBuilder<object, ConcreteReflectionActivatorData, SingleRegistrationStyle>>>();

/// <summary>
/// Gets a collection of types that will be skipped during generation of NSubstitute mocks.
/// </summary>
[Obsolete("Use a custom MockHandler instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
public ICollection<Type> TypesToSkipForMocking => _typesToSkipForMocking;

/// <summary>
/// Gets or sets a flag indicating whether mocks should be excluded for provided values. This will automatically add values given to Provide methods to <see cref="TypesToSkipForMocking"/>.
/// </summary>
[Obsolete]
[EditorBrowsable(EditorBrowsableState.Never)]
public bool AutomaticallySkipMocksForProvidedValues { get; set; }

/// <summary>
/// Gets or sets a factory to create an <see cref="IContainer"/> given a <see cref="ContainerBuilder"/>. This defaults to simply calling <see cref="ContainerBuilder.Build()"/>.
/// </summary>
Expand Down
22 changes: 1 addition & 21 deletions AutofacContrib.NSubstitute/MockHandlers/MockHandler.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using Autofac;
using AutofacContrib.NSubstitute.MockHandlers;
using NSubstitute.Core;
using System;
using System.ComponentModel;
using AutofacContrib.NSubstitute.MockHandlers;

namespace AutofacContrib.NSubstitute
{
Expand All @@ -15,28 +11,12 @@ protected MockHandler()
{
}

/// <summary>
/// Provides a way to manage mocks after creation but before returned from the container registry.
/// </summary>
/// <param name="instance">The mock instance.</param>
/// <param name="type">The type the mock was created for.</param>
/// <param name="context">The current component context.</param>
/// <param name="substitutionContext">The current substitution context.</param>
[Obsolete]
[EditorBrowsable(EditorBrowsableState.Never)]
protected virtual void OnMockCreated(object instance, Type type, IComponentContext context, ISubstitutionContext substitutionContext)
{
}

/// <summary>
/// Provides a way to manage mocks after creation but before returned from the container registry.
/// </summary>
/// <param name="context">Created context.</param>
protected internal virtual void OnMockCreated(MockCreatedContext context)
{
#pragma warning disable CS0612 // Type or member is obsolete
OnMockCreated(context.Instance, context.Type, context.Context, context.SubstitutionContext);
#pragma warning restore CS0612 // Type or member is obsolete
}

/// <summary>
Expand Down
10 changes: 0 additions & 10 deletions AutofacContrib.NSubstitute/SubstituteForBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ internal SubstituteForBuilder(

internal ISubstitutionContext Context => SubstitutionContext.Current;

/// <summary>
/// Allows for configuration of the service.
/// </summary>
/// <param name="action">The delegate to configure the service.</param>
/// <returns>The original <see cref="AutoSubstituteBuilder"/>.</returns>
[Obsolete("Use ConfigureSubstitute instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
public AutoSubstituteBuilder Configure(Action<TService> action)
=> ConfigureSubstitute((s, _) => action(s));

/// <summary>
/// Allows for configuration of the service.
/// </summary>
Expand Down
11 changes: 11 additions & 0 deletions BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
AutofacContrib.NSubstitute (AutoSubstitute) Breaking Changes
============================================================

Version 7.0.0
-------------

Removed obsolete methods that were in the project.

### Reason
They built up some unnecessary cruft and had easy replacements

### Workaround
Update to the latest 6.x package and review obsolete messages.

Version 6.0.0
-------------

Expand Down

0 comments on commit 9e7498b

Please sign in to comment.