Skip to content

Commit

Permalink
Change return type
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminMichaelis committed Feb 2, 2024
1 parent 3e4b38e commit 4280c54
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 11 additions & 2 deletions Moq.AutoMock.Tests/DescribeWithSelfMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public void It_can_register_a_custom_default_value_provider_for_a_self_mock_with

var mock = mocker.WithSelfMock<IService2, Service2>(defaultValue: DefaultValue.Custom, defaultValueProvider: provider);

Assert.AreEqual(provider, Mock.Get(mock).DefaultValueProvider);
Assert.AreEqual(provider, mock.DefaultValueProvider);
}

[TestMethod]
Expand All @@ -24,7 +24,7 @@ public void It_uses_default_value_provider_for_a_self_mock_with_interface()

var mock = mocker.WithSelfMock<IService2, Service2>();

Assert.AreEqual(provider, Mock.Get(mock).DefaultValueProvider);
Assert.AreEqual(provider, mock.DefaultValueProvider);
}

[TestMethod]
Expand Down Expand Up @@ -98,5 +98,14 @@ public void It_uses_default_value_provider_for_a_self_mock_with_class_type()

Assert.AreEqual(provider, Mock.Get(mock).DefaultValueProvider);
}

[TestMethod]
public void WithSelfMock_returns_mock_of_service()
{
var mocker = new AutoMocker();
var mockService = mocker.WithSelfMock<IService2, Service2>();

Assert.IsInstanceOfType<Mock<IService2>>(mockService);
}
}

6 changes: 3 additions & 3 deletions Moq.AutoMock/AutoMocker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ public T CreateSelfMock<T>(
/// <param name="defaultValue">Sets the DefaultValue property on the created Mock.</param>
/// <param name="defaultValueProvider">The instance that will be used to produce default return values for unexpected invocations.</param>
/// <param name="callBase">Sets the CallBase property on the created Mock.</param>
/// <returns>An instance with virtual and abstract members mocked</returns>
public TImplementation WithSelfMock<TService, TImplementation>(
/// <returns>A mock of the service</returns>
public Mock<TService> WithSelfMock<TService, TImplementation>(
bool enablePrivate = false,
MockBehavior? mockBehavior = null,
DefaultValue? defaultValue = null,
Expand All @@ -325,7 +325,7 @@ public TImplementation WithSelfMock<TService, TImplementation>(
typeMap[typeof(TImplementation)] = new MockInstance(selfMock);
typeMap[typeof(TService)] = new MockInstance(selfMock.As<TService>());
});
return selfMock.Object;
return selfMock.As<TService>();
}

/// <summary>
Expand Down

0 comments on commit 4280c54

Please sign in to comment.