This repository was archived by the owner on Jun 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 75
merge initial legacy support into master #40
Merged
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
973fd6d
Initial support for a legacy API shim
kzu b83445a
Add codegen support for new Mock<T>
kzu a58ad2d
Setup should happen as soon as possible
kzu 72a1a28
Make sure we use the test calling assembly
adalon df46b70
Added SkipBehavior support for behavior pipeline
adalon 5aaca90
Add new behavior for setup scope runs
kzu 0c2ff79
Add setup overloads to avoid the mock T argument
kzu 60237fe
Added AsMoq extension method
adalon eda348b
Simplify Behavior implementation by using SkipBehaviors
kzu edc7b68
Revert "Add setup overloads to avoid the mock T argument"
kzu efeefc3
Fix failing tests
kzu 4e9d640
Move setup scope to Moq
kzu 004e96e
Fix visiblity of various Sdk-like classes in the Moq main assembly
kzu 91b4853
Added CallBase support
adalon 58a67fe
Don't run FixupImports twice
kzu 3f191e7
Ensure both analyzers and codefixers have NuGetPackageId metadata
kzu 4c5db10
Optimize codegen performance for real world solutions
kzu e159b48
Do not clean unused namespaces, since it is costly for little benefit
kzu 814afdc
Bump to latest Roslyn for VS2017 and updated supported code fix names
kzu 708db5b
Ensure a clean restore is performed always, add CI feed
kzu 20b9fd2
Set proper names for CallBase tests
adalon 6143a8a
Bump TFV to the 16.0+ official one supporting NS2
kzu e5b1c4e
Properly generate code for generic mocks
kzu d9bbc2e
Add support for mocking generic types
kzu 34a6c49
Move OverrideAllMembersCodeFix to CodeFix assembly to avoid csc error
kzu 1e97239
Don't assume mocked types will be public
kzu e30d526
Cleanup and encapsulate the batch code fixer and avoid state capturing
kzu f4b4be4
Delete OverrideAllMembersCodeFix class that moved to CodeFix
kzu d5e5fd7
Re-enable end to end tests for VB since they work now
kzu cfddaf2
Fix roslyn internals tests from moved RoslynInternals.cs file
kzu 2e4f6e8
Fix minor style issues flagged by codefactor.io
kzu 462cf05
Unify naming conventions for runtime lookup
kzu 83a22b0
Minor docs tweaks to CallBase
kzu db87731
Drastically simplify As<T> support by adding new Mock<T...Tn>
kzu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member | ||
| using System.ComponentModel; | ||
| using static Moq.Syntax; | ||
|
|
||
| namespace Moq | ||
| { | ||
| /// <summary>Supports the legacy API.</summary> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public static class It | ||
| { | ||
| /// <summary>Supports the legacy API.</summary> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public static T IsAny<T>() => Any<T>(); | ||
| } | ||
| } | ||
| #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member | ||
| using System; | ||
| using System.ComponentModel; | ||
| using Moq.Sdk; | ||
|
|
||
| namespace Moq | ||
| { | ||
| /// <summary>Supports the legacy API.</summary> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public class MockSetup<TTarget> | ||
| { | ||
| readonly TTarget target; | ||
| readonly IMock<TTarget> mock; | ||
| readonly Action<TTarget> action; | ||
|
|
||
| /// <summary>Supports the legacy API.</summary> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public MockSetup(TTarget target, IMock<TTarget> mock, Action<TTarget> action) | ||
| { | ||
| this.target = target; | ||
| this.mock = mock; | ||
| this.action = action; | ||
| } | ||
|
|
||
| #region Callback | ||
|
|
||
| /// <summary>Supports the legacy API.</summary> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public MockSetup<TTarget> Callback<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> action) | ||
| { | ||
| target.Setup(action).Callback(action); | ||
| return this; | ||
| } | ||
|
|
||
| /// <summary>Supports the legacy API.</summary> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public MockSetup<TTarget> Callback<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> action) | ||
| { | ||
| target.Setup(action).Callback(action); | ||
| return this; | ||
| } | ||
|
|
||
| /// <summary>Supports the legacy API.</summary> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public MockSetup<TTarget> Callback<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> action) | ||
| { | ||
| target.Setup(action).Callback(action); | ||
| return this; | ||
| } | ||
|
|
||
| /// <summary>Supports the legacy API.</summary> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public MockSetup<TTarget> Callback<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> action) | ||
| { | ||
| target.Setup(action).Callback(action); | ||
| return this; | ||
| } | ||
|
|
||
| /// <summary>Supports the legacy API.</summary> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public MockSetup<TTarget> Callback<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> action) | ||
| { | ||
| target.Setup(action).Callback(action); | ||
| return this; | ||
| } | ||
|
|
||
| /// <summary>Supports the legacy API.</summary> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public MockSetup<TTarget> Callback<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> action) | ||
| { | ||
| target.Setup(action).Callback(action); | ||
| return this; | ||
| } | ||
|
|
||
| /// <summary>Supports the legacy API.</summary> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public MockSetup<TTarget> Callback<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> action) | ||
| { | ||
| target.Setup(action).Callback(action); | ||
| return this; | ||
| } | ||
|
|
||
| /// <summary>Supports the legacy API.</summary> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public MockSetup<TTarget> Callback<T1, T2, T3, T4, T5, T6, T7, T8, T9>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9> action) | ||
| { | ||
| target.Setup(action).Callback(action); | ||
| return this; | ||
| } | ||
|
|
||
| /// <summary>Supports the legacy API.</summary> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public MockSetup<TTarget> Callback<T1, T2, T3, T4, T5, T6, T7, T8>(Action<T1, T2, T3, T4, T5, T6, T7, T8> action) | ||
| { | ||
| target.Setup(action).Callback(action); | ||
| return this; | ||
| } | ||
|
|
||
| /// <summary>Supports the legacy API.</summary> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public MockSetup<TTarget> Callback<T1, T2, T3, T4, T5, T6, T7>(Action<T1, T2, T3, T4, T5, T6, T7> action) | ||
| { | ||
| target.Setup(action).Callback(action); | ||
| return this; | ||
| } | ||
|
|
||
| /// <summary>Supports the legacy API.</summary> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public MockSetup<TTarget> Callback<T1, T2, T3, T4, T5, T6>(Action<T1, T2, T3, T4, T5, T6> action) | ||
| { | ||
| target.Setup(action).Callback(action); | ||
| return this; | ||
| } | ||
|
|
||
| /// <summary>Supports the legacy API.</summary> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public MockSetup<TTarget> Callback<T1, T2, T3, T4, T5>(Action<T1, T2, T3, T4, T5> action) | ||
| { | ||
| target.Setup(action).Callback(action); | ||
| return this; | ||
| } | ||
|
|
||
| /// <summary>Supports the legacy API.</summary> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public MockSetup<TTarget> Callback<T1, T2, T3, T4>(Action<T1, T2, T3, T4> action) | ||
| { | ||
| target.Setup(action).Callback(action); | ||
| return this; | ||
| } | ||
|
|
||
| /// <summary>Supports the legacy API.</summary> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public MockSetup<TTarget> Callback<T1, T2, T3>(Action<T1, T2, T3> action) | ||
| { | ||
| target.Setup(action).Callback(action); | ||
| return this; | ||
| } | ||
|
|
||
| /// <summary>Supports the legacy API.</summary> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public MockSetup<TTarget> Callback<T1, T2>(Action<T1, T2> action) | ||
| { | ||
| target.Setup(action).Callback(action); | ||
| return this; | ||
| } | ||
|
|
||
| /// <summary>Supports the legacy API.</summary> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public MockSetup<TTarget> Callback<T>(Action<T> action) | ||
| { | ||
| target.Setup(action).Callback(action); | ||
| return this; | ||
| } | ||
|
|
||
| /// <summary>Supports the legacy API.</summary> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public MockSetup<TTarget> Callback(Action action) | ||
| { | ||
| target.Setup(action).Callback(action); | ||
| return this; | ||
| } | ||
|
|
||
| #endregion | ||
|
|
||
| /// <summary>Supports the legacy API.</summary> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public void Verifiable() => target.Setup(action).Verifiable(); | ||
|
|
||
| /// <summary>Supports the legacy API.</summary> | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public MockSetup<TTarget> Throws(Exception exception) | ||
| { | ||
| target.Setup(action).Throws(exception); | ||
| return this; | ||
| } | ||
| } | ||
| } | ||
| #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For legacy support Once should be a method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, but it never made sense as a method in the first place, since it has no parameters :(.
The good thing is that this is the new API overload. The old API overloads could still provide backwards compatible members, I think.