Skip to content

Commit

Permalink
Documentation, auto create, flexible creation options
Browse files Browse the repository at this point in the history
  • Loading branch information
cwinland committed Jul 28, 2022
1 parent 464972b commit 76a80a9
Show file tree
Hide file tree
Showing 287 changed files with 34,305 additions and 222 deletions.
10 changes: 5 additions & 5 deletions FastMoq.Tests/MocksTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,13 +449,13 @@ public void GetTypeFromInterfaceWithNonInterface()
public void IsValidConstructor()
{
var constructor = Mocks.FindConstructor(typeof(TestClassNormal), false, Mocks.GetObject<IFileSystem>());
var isValid = Mocker.IsValidConstructor(constructor.Key, Mocks.GetObject<IFileSystem>());
var isValid = Mocker.IsValidConstructor(constructor.ConstructorInfo, Mocks.GetObject<IFileSystem>());
isValid.Should().BeTrue();

isValid = Mocker.IsValidConstructor(constructor.Key, Mocks.GetObject<IFileSystem>(), 12);
isValid = Mocker.IsValidConstructor(constructor.ConstructorInfo, Mocks.GetObject<IFileSystem>(), 12);
isValid.Should().BeFalse();

isValid = Mocker.IsValidConstructor(constructor.Key, 12);
isValid = Mocker.IsValidConstructor(constructor.ConstructorInfo, 12);
isValid.Should().BeFalse();
}

Expand All @@ -473,14 +473,14 @@ public void RemoveMock()
private void CheckBestConstructor(object data, bool expected, bool nonPublic)
{
var constructor = Mocks.FindConstructor(true, typeof(TestClassNormal), nonPublic);
var isValid = Mocker.IsValidConstructor(constructor.Key, data);
var isValid = Mocker.IsValidConstructor(constructor.ConstructorInfo, data);
isValid.Should().Be(expected);
}

private void CheckConstructorByArgs(object data, bool expected, bool nonPublic)
{
var constructor = Mocks.FindConstructor(typeof(TestClassNormal), nonPublic, data);
var isValid = Mocker.IsValidConstructor(constructor.Key, data);
var isValid = Mocker.IsValidConstructor(constructor.ConstructorInfo, data);
isValid.Should().Be(expected);
}

Expand Down
16 changes: 16 additions & 0 deletions FastMoq.Tests/TestClassOne.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,28 @@

namespace FastMoq.Tests
{
/// <summary>
/// Class TestClassOne.
/// Implements the <see cref="FastMoq.Tests.ITestClassOne" />
/// </summary>
/// <seealso cref="FastMoq.Tests.ITestClassOne" />
public class TestClassOne : ITestClassOne
{
/// <summary>
/// Initializes a new instance of the <see cref="TestClassOne"/> class.
/// </summary>
/// <param name="fileSystem">The file system.</param>
public TestClassOne(IFileSystem fileSystem) { }

/// <summary>
/// Initializes a new instance of the <see cref="TestClassOne"/> class.
/// </summary>
/// <param name="file">The file.</param>
internal TestClassOne(IFile file) { }
}

/// <summary>
/// Interface ITestClassOne
/// </summary>
public interface ITestClassOne { }
}
21 changes: 21 additions & 0 deletions FastMoq/ConstructorModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Reflection;

namespace FastMoq
{
internal class ConstructorModel
{
internal ConstructorInfo ConstructorInfo { get; }
internal object?[] ParameterList { get; }

internal ConstructorModel(ConstructorInfo constructorInfo, List<object?> parameterList)
{
ConstructorInfo = constructorInfo;
ParameterList = parameterList.ToArray();
}

internal ConstructorModel(KeyValuePair<ConstructorInfo, List<object?>> kvp) : this(kvp.Key, kvp.Value)
{

}
}
}
1 change: 1 addition & 0 deletions FastMoq/FastMoq.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
</PropertyGroup>
<PropertyGroup>
<GenerateNuspecDependsOn>$(GenerateNuspecDependsOn);SetPackageVersion</GenerateNuspecDependsOn>
<GenerateDocumentationFile>False</GenerateDocumentationFile>
</PropertyGroup>
<Target Name="SetPackageVersion">
<PropertyGroup>
Expand Down
37 changes: 35 additions & 2 deletions FastMoq/MockModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@

namespace FastMoq
{
/// <summary>
/// Class MockModel.
/// Implements the <see cref="FastMoq.MockModel" />
/// </summary>
/// <typeparam name="T"></typeparam>
/// <seealso cref="FastMoq.MockModel" />
public class MockModel<T> : MockModel where T : class
{
#region Properties

/// <summary>
/// Gets or sets the mock.
/// </summary>
/// <value>The mock.</value>
public new Mock<T> Mock
{
get => (Mock<T>) base.Mock;
Expand All @@ -14,13 +24,21 @@ public class MockModel<T> : MockModel where T : class

#endregion

/// <summary>
/// Initializes a new instance of the <see cref="MockModel{T}"/> class.
/// </summary>
/// <param name="mock">The mock.</param>
internal MockModel(Mock mock) : base(typeof(T), mock) { }

/// <summary>
/// Initializes a new instance of the <see cref="MockModel{T}"/> class.
/// </summary>
/// <param name="mockModel">The mock model.</param>
internal MockModel(MockModel mockModel) : base(mockModel.Type, mockModel.Mock) { }
}

/// <summary>
/// Class MockModel.
/// Contains Mock and Type information.
/// </summary>
public class MockModel
{
Expand All @@ -38,12 +56,27 @@ public class MockModel
/// <value>The type.</value>
public Type Type { get; set; }

/// <summary>
/// Gets or sets a value indicating whether [non public].
/// </summary>
/// <value><c>true</c> if [non public]; otherwise, <c>false</c>.</value>
public bool NonPublic { get; set; } = false;

#endregion

internal MockModel(Type type, Mock mock)
/// <summary>
/// Initializes a new instance of the <see cref="MockModel"/> class.
/// </summary>
/// <param name="type">The type.</param>
/// <param name="mock">The mock.</param>
/// <param name="nonPublic">if set to <c>true</c> [non public].</param>
/// <exception cref="System.ArgumentNullException">type</exception>
/// <exception cref="System.ArgumentNullException">mock</exception>
internal MockModel(Type type, Mock mock, bool nonPublic = false)
{
Type = type ?? throw new ArgumentNullException(nameof(type));
Mock = mock ?? throw new ArgumentNullException(nameof(mock));
NonPublic = nonPublic;
}
}
}
Loading

0 comments on commit 76a80a9

Please sign in to comment.