From 108bd3000ea5f2cc6229b598926294a96892a22b Mon Sep 17 00:00:00 2001 From: Kent Boogaart Date: Sun, 19 Mar 2017 10:16:22 +1030 Subject: [PATCH 1/9] Make code netstandard compliant --- Src/PCLMock/Utility/ObjectExtensions.cs | 3 ++- Src/PCLMock/Visitors/ArgumentFilterVisitor.cs | 4 +++- Src/PCLMock/WhenContinuation.cs | 12 ++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Src/PCLMock/Utility/ObjectExtensions.cs b/Src/PCLMock/Utility/ObjectExtensions.cs index 2f5b569..8b4a381 100644 --- a/Src/PCLMock/Utility/ObjectExtensions.cs +++ b/Src/PCLMock/Utility/ObjectExtensions.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Globalization; + using System.Linq; using System.Reflection; using System.Text; @@ -111,7 +112,7 @@ public static string ToDebugString(this object @this) if (@this is Enum) { var @enum = (Enum)@this; - var isFlags = @this.GetType().GetCustomAttributes(typeof(FlagsAttribute), false).Length > 0; + var isFlags = @this.GetType().GetTypeInfo().GetCustomAttributes(typeof(FlagsAttribute), false).Any(); var result = new StringBuilder(); if (isFlags) diff --git a/Src/PCLMock/Visitors/ArgumentFilterVisitor.cs b/Src/PCLMock/Visitors/ArgumentFilterVisitor.cs index 2c57bb6..8268f9e 100644 --- a/Src/PCLMock/Visitors/ArgumentFilterVisitor.cs +++ b/Src/PCLMock/Visitors/ArgumentFilterVisitor.cs @@ -42,7 +42,9 @@ protected override Expression VisitMethodCall(MethodCallExpression node) var filterMethod = node .Method .DeclaringType - .GetMethods(BindingFlags.Static | BindingFlags.NonPublic) + .GetTypeInfo() + .DeclaredMethods + .Where(declaredMethod => declaredMethod.IsStatic && declaredMethod.IsPublic) .Where(x => x.Name == node.Method.Name + "Filter" && x.GetParameters().Length == node.Arguments.Count) .FirstOrDefault(); diff --git a/Src/PCLMock/WhenContinuation.cs b/Src/PCLMock/WhenContinuation.cs index 762c26a..ce2f32b 100644 --- a/Src/PCLMock/WhenContinuation.cs +++ b/Src/PCLMock/WhenContinuation.cs @@ -76,7 +76,7 @@ internal T GetOutParameterValue(int parameterIndex) throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Out parameter at index {0} has a value of type '{1}' but type '{2}' was expected.", parameterIndex, value.GetType().FullName, typeof(T).FullName)); } } - else if (typeof(T).IsValueType) + else if (typeof(T).GetTypeInfo().IsValueType) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Out parameter at index {0} has a null value specified but it is a value type ('{1}') so cannot be null.", parameterIndex, typeof(T).FullName)); } @@ -101,7 +101,7 @@ internal T GetRefParameterValue(int parameterIndex, T defaultValue) throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Ref parameter at index {0} has a value of type '{1}' but type '{2}' was expected.", parameterIndex, value.GetType().FullName, typeof(T).FullName)); } } - else if (typeof(T).IsValueType) + else if (typeof(T).GetTypeInfo().IsValueType) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Ref parameter at index {0} has a null value specified but it is a value type ('{1}') so cannot be null.", parameterIndex, typeof(T).FullName)); } @@ -189,7 +189,7 @@ private sealed class ActionTypeComparer : IEqualityComparer private ActionTypeComparer() { } - + public bool Equals(Type expectedType, Type receivedType) { Debug.Assert(expectedType != null); @@ -200,7 +200,7 @@ public bool Equals(Type expectedType, Type receivedType) return true; } - return expectedType.IsAssignableFrom(receivedType); + return expectedType.GetTypeInfo().IsAssignableFrom(receivedType.GetTypeInfo()); } public int GetHashCode(Type obj) @@ -356,7 +356,7 @@ internal override object Apply(object mockedObject, params object[] args) if (this.doAction != null) { - args = this.ValidateActionArgs("Do", this.doAction.Method.GetParameters().Select(x => x.ParameterType).ToArray(), args); + args = this.ValidateActionArgs("Do", this.doAction.GetMethodInfo().GetParameters().Select(x => x.ParameterType).ToArray(), args); this.doAction.DynamicInvoke(args); } @@ -525,7 +525,7 @@ internal override object Apply(object mockedObject, params object[] args) if (this.returnAction != null) { - args = this.ValidateActionArgs("Return", this.returnAction.Method.GetParameters().Select(x => x.ParameterType).ToArray(), args); + args = this.ValidateActionArgs("Return", this.returnAction.GetMethodInfo().GetParameters().Select(x => x.ParameterType).ToArray(), args); return this.returnAction.DynamicInvoke(args); } From 780f350d61d079b5ed4cf1af11fd893f302782e1 Mon Sep 17 00:00:00 2001 From: Kent Boogaart Date: Fri, 14 Apr 2017 10:00:52 +0930 Subject: [PATCH 2/9] WIP: netstandard upgrade --- Src/PCLMock.CodeGeneration/DotNetWorkspace.cs | 29 + Src/PCLMock.CodeGeneration/Generator.cs | 13 +- .../PCLMock.CodeGeneration.csproj | 179 +-- .../Plugins/Disposables.cs | 3 +- .../Plugins/ObservableBasedAsynchrony.cs | 3 +- Src/PCLMock.CodeGeneration_OLD/Context.cs | 76 ++ Src/PCLMock.CodeGeneration_OLD/Extensions.cs | 111 ++ Src/PCLMock.CodeGeneration_OLD/Generator.cs | 1127 +++++++++++++++++ Src/PCLMock.CodeGeneration_OLD/IPlugin.cs | 77 ++ Src/PCLMock.CodeGeneration_OLD/Language.cs | 8 + .../LanguageExtensions.cs | 21 + .../Logging/ILogSink.cs | 14 + .../Logging/LogLevel.cs | 12 + .../Logging/LogSinkExtensions.cs | 80 ++ .../Logging/NullLogSink.cs | 19 + .../Logging/StringLogSink.cs | 30 + .../Models/Configuration.cs | 226 ++++ .../Models/Filter.cs | 18 + .../Models/FilterType.cs | 8 + .../Models/Plugin.cs | 14 + .../Models/Transformation.cs | 18 + .../PCLMock.CodeGeneration.csproj | 161 +++ .../PCLMock.CodeGeneration.v3.ncrunchproject | 11 + .../Plugins/Collections.cs | 498 ++++++++ .../Plugins/Disposables.cs | 93 ++ .../Plugins/ObservableBasedAsynchrony.cs | 172 +++ .../Plugins/TaskBasedAsynchrony.cs | 141 +++ .../Properties/AssemblyInfo.cs | 8 + .../SyntaxGeneratorExtensions.cs | 45 + .../XmlBasedGenerator.cs | 68 + .../app.config | 0 .../packages.config | 0 Src/PCLMock.sln | 28 +- Src/PCLMock/PCLMock.csproj | 87 +- .../ArgumentFilters/IsAnyArgumentFilter.cs | 44 + .../ArgumentFilters/IsArgumentFilter.cs | 45 + .../IsBetweenArgumentFilter.cs | 66 + .../IsGreaterThanArgumentFilter.cs | 53 + .../IsGreaterThanOrEqualToArgumentFilter.cs | 53 + .../ArgumentFilters/IsInArgumentFilter.cs | 79 ++ .../ArgumentFilters/IsLikeArgumentFilter.cs | 56 + .../ArgumentFilters/IsNullArgumentFilter.cs | 44 + .../ArgumentFilters/IsOfTypeArgumentFilter.cs | 44 + .../LogicalNotArgumentFilter.cs | 47 + .../ArgumentFilters/MatchesArgumentFilter.cs | 54 + Src/PCLMock_OLD/IArgumentFilter.cs | 7 + Src/PCLMock_OLD/It.cs | 485 +++++++ Src/PCLMock_OLD/MockBase.cs | 451 +++++++ Src/PCLMock_OLD/MockBehavior.cs | 21 + Src/PCLMock_OLD/PCLMock.csproj | 85 ++ Src/PCLMock_OLD/PCLMock.v3.ncrunchproject | 11 + Src/PCLMock_OLD/Properties/AssemblyInfo.cs | 8 + .../Utility/ArgumentFilterCollection.cs | 85 ++ Src/PCLMock_OLD/Utility/ContinuationKey.cs | 51 + .../Utility/ContinuationKeyType.cs | 8 + Src/PCLMock_OLD/Utility/Invocation.cs | 18 + Src/PCLMock_OLD/Utility/ObjectExtensions.cs | 142 +++ .../Utility/WhenContinuationCollection.cs | 47 + Src/PCLMock_OLD/VerificationException.cs | 27 + Src/PCLMock_OLD/VerifyContinuation.cs | 182 +++ .../Visitors/ArgumentFilterVisitor.cs | 98 ++ .../Visitors/ArgumentFiltersVisitor.cs | 71 ++ Src/PCLMock_OLD/Visitors/ArgumentsVisitor.cs | 59 + .../Visitors/SelectorStringVisitor.cs | 52 + Src/PCLMock_OLD/Visitors/ValueExtractor.cs | 62 + Src/PCLMock_OLD/WhenContinuation.cs | 535 ++++++++ Src/Rebracer.xml | 6 +- 67 files changed, 6227 insertions(+), 267 deletions(-) create mode 100644 Src/PCLMock.CodeGeneration/DotNetWorkspace.cs create mode 100644 Src/PCLMock.CodeGeneration_OLD/Context.cs create mode 100644 Src/PCLMock.CodeGeneration_OLD/Extensions.cs create mode 100644 Src/PCLMock.CodeGeneration_OLD/Generator.cs create mode 100644 Src/PCLMock.CodeGeneration_OLD/IPlugin.cs create mode 100644 Src/PCLMock.CodeGeneration_OLD/Language.cs create mode 100644 Src/PCLMock.CodeGeneration_OLD/LanguageExtensions.cs create mode 100644 Src/PCLMock.CodeGeneration_OLD/Logging/ILogSink.cs create mode 100644 Src/PCLMock.CodeGeneration_OLD/Logging/LogLevel.cs create mode 100644 Src/PCLMock.CodeGeneration_OLD/Logging/LogSinkExtensions.cs create mode 100644 Src/PCLMock.CodeGeneration_OLD/Logging/NullLogSink.cs create mode 100644 Src/PCLMock.CodeGeneration_OLD/Logging/StringLogSink.cs create mode 100644 Src/PCLMock.CodeGeneration_OLD/Models/Configuration.cs create mode 100644 Src/PCLMock.CodeGeneration_OLD/Models/Filter.cs create mode 100644 Src/PCLMock.CodeGeneration_OLD/Models/FilterType.cs create mode 100644 Src/PCLMock.CodeGeneration_OLD/Models/Plugin.cs create mode 100644 Src/PCLMock.CodeGeneration_OLD/Models/Transformation.cs create mode 100644 Src/PCLMock.CodeGeneration_OLD/PCLMock.CodeGeneration.csproj create mode 100644 Src/PCLMock.CodeGeneration_OLD/PCLMock.CodeGeneration.v3.ncrunchproject create mode 100644 Src/PCLMock.CodeGeneration_OLD/Plugins/Collections.cs create mode 100644 Src/PCLMock.CodeGeneration_OLD/Plugins/Disposables.cs create mode 100644 Src/PCLMock.CodeGeneration_OLD/Plugins/ObservableBasedAsynchrony.cs create mode 100644 Src/PCLMock.CodeGeneration_OLD/Plugins/TaskBasedAsynchrony.cs create mode 100644 Src/PCLMock.CodeGeneration_OLD/Properties/AssemblyInfo.cs create mode 100644 Src/PCLMock.CodeGeneration_OLD/SyntaxGeneratorExtensions.cs create mode 100644 Src/PCLMock.CodeGeneration_OLD/XmlBasedGenerator.cs rename Src/{PCLMock.CodeGeneration => PCLMock.CodeGeneration_OLD}/app.config (100%) rename Src/{PCLMock.CodeGeneration => PCLMock.CodeGeneration_OLD}/packages.config (100%) create mode 100644 Src/PCLMock_OLD/ArgumentFilters/IsAnyArgumentFilter.cs create mode 100644 Src/PCLMock_OLD/ArgumentFilters/IsArgumentFilter.cs create mode 100644 Src/PCLMock_OLD/ArgumentFilters/IsBetweenArgumentFilter.cs create mode 100644 Src/PCLMock_OLD/ArgumentFilters/IsGreaterThanArgumentFilter.cs create mode 100644 Src/PCLMock_OLD/ArgumentFilters/IsGreaterThanOrEqualToArgumentFilter.cs create mode 100644 Src/PCLMock_OLD/ArgumentFilters/IsInArgumentFilter.cs create mode 100644 Src/PCLMock_OLD/ArgumentFilters/IsLikeArgumentFilter.cs create mode 100644 Src/PCLMock_OLD/ArgumentFilters/IsNullArgumentFilter.cs create mode 100644 Src/PCLMock_OLD/ArgumentFilters/IsOfTypeArgumentFilter.cs create mode 100644 Src/PCLMock_OLD/ArgumentFilters/LogicalNotArgumentFilter.cs create mode 100644 Src/PCLMock_OLD/ArgumentFilters/MatchesArgumentFilter.cs create mode 100644 Src/PCLMock_OLD/IArgumentFilter.cs create mode 100644 Src/PCLMock_OLD/It.cs create mode 100644 Src/PCLMock_OLD/MockBase.cs create mode 100644 Src/PCLMock_OLD/MockBehavior.cs create mode 100644 Src/PCLMock_OLD/PCLMock.csproj create mode 100644 Src/PCLMock_OLD/PCLMock.v3.ncrunchproject create mode 100644 Src/PCLMock_OLD/Properties/AssemblyInfo.cs create mode 100644 Src/PCLMock_OLD/Utility/ArgumentFilterCollection.cs create mode 100644 Src/PCLMock_OLD/Utility/ContinuationKey.cs create mode 100644 Src/PCLMock_OLD/Utility/ContinuationKeyType.cs create mode 100644 Src/PCLMock_OLD/Utility/Invocation.cs create mode 100644 Src/PCLMock_OLD/Utility/ObjectExtensions.cs create mode 100644 Src/PCLMock_OLD/Utility/WhenContinuationCollection.cs create mode 100644 Src/PCLMock_OLD/VerificationException.cs create mode 100644 Src/PCLMock_OLD/VerifyContinuation.cs create mode 100644 Src/PCLMock_OLD/Visitors/ArgumentFilterVisitor.cs create mode 100644 Src/PCLMock_OLD/Visitors/ArgumentFiltersVisitor.cs create mode 100644 Src/PCLMock_OLD/Visitors/ArgumentsVisitor.cs create mode 100644 Src/PCLMock_OLD/Visitors/SelectorStringVisitor.cs create mode 100644 Src/PCLMock_OLD/Visitors/ValueExtractor.cs create mode 100644 Src/PCLMock_OLD/WhenContinuation.cs diff --git a/Src/PCLMock.CodeGeneration/DotNetWorkspace.cs b/Src/PCLMock.CodeGeneration/DotNetWorkspace.cs new file mode 100644 index 0000000..ff035a2 --- /dev/null +++ b/Src/PCLMock.CodeGeneration/DotNetWorkspace.cs @@ -0,0 +1,29 @@ +namespace PCLMock.CodeGeneration +{ + using System; + using System.Collections.Generic; + using Microsoft.DotNet.ProjectModel; + + // adapted from https://github.com/OmniSharp/omnisharp-roslyn/blob/a4dced28f5f3b38d806134e89a6896c9d8075997/src/OmniSharp.DotNet/DotNetWorkspace.cs + public sealed class DotNetWorkspace : Workspace + { + public DotNetWorkspace(string initialPath) + : base(ProjectReaderSettings.ReadFromEnvironment(), true) + { + } + + public IReadOnlyList GetProjectContexts(string projectPath) => + (IReadOnlyList)GetProjectContextCollection(projectPath)?.ProjectContexts.AsReadOnly() ?? Array.Empty(); + + protected override IEnumerable BuildProjectContexts(Project project) + { + foreach (var framework in project.GetTargetFrameworks()) + { + yield return CreateBaseProjectBuilder(project) + .AsDesignTime() + .WithTargetFramework(framework.FrameworkName) + .Build(); + } + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration/Generator.cs b/Src/PCLMock.CodeGeneration/Generator.cs index 9832eaf..3a8aad4 100644 --- a/Src/PCLMock.CodeGeneration/Generator.cs +++ b/Src/PCLMock.CodeGeneration/Generator.cs @@ -4,13 +4,14 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; + using System.Reflection; using System.Threading.Tasks; using Logging; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editing; - using Microsoft.CodeAnalysis.MSBuild; + //using Microsoft.CodeAnalysis.MSBuild; public static class Generator { @@ -29,14 +30,14 @@ Changes to this file may cause incorrect behaviour and will be lost public async static Task> GenerateMocksAsync( ILogSink logSink, Language language, - string solutionPath, + string initialPath, Func interfacePredicate, Func mockNamespaceSelector, Func mockNameSelector, IImmutableList plugins) { - var workspace = MSBuildWorkspace.Create(); - var solution = await workspace.OpenSolutionAsync(solutionPath); + var workspace = new DotNetWorkspace(initialPath); + var solution = await workspace.OpenSolutionAsync(initialPath); return await GenerateMocksAsync( logSink, @@ -65,7 +66,7 @@ public async static Task> GenerateMocksAsync( { var compilation = await project.GetCompilationAsync(); // make sure the compilation has a reference to PCLMock - compilation = compilation.AddReferences(MetadataReference.CreateFromFile(typeof(MockBase<>).Assembly.Location)); + compilation = compilation.AddReferences(MetadataReference.CreateFromFile(typeof(MockBase<>).GetTypeInfo().Assembly.Location)); foreach (var plugin in plugins) { @@ -235,7 +236,7 @@ private static IEnumerable GetClassAttributesSyntax( .LiteralExpression("PCLMock"), context .SyntaxGenerator - .LiteralExpression(typeof(MockBase<>).Assembly.GetName().Version.ToString())); + .LiteralExpression(typeof(MockBase<>).GetTypeInfo().Assembly.GetName().Version.ToString())); yield return context .SyntaxGenerator .Attribute( diff --git a/Src/PCLMock.CodeGeneration/PCLMock.CodeGeneration.csproj b/Src/PCLMock.CodeGeneration/PCLMock.CodeGeneration.csproj index a80d3ed..0f23b5b 100644 --- a/Src/PCLMock.CodeGeneration/PCLMock.CodeGeneration.csproj +++ b/Src/PCLMock.CodeGeneration/PCLMock.CodeGeneration.csproj @@ -1,167 +1,26 @@ - - - + + - Debug - AnyCPU - {6E077796-0241-4191-A866-0EA52B9BD946} - Library - Properties - PCLMock.CodeGeneration - PCLMock.CodeGeneration - v4.5.2 - 512 - + netcoreapp1.1 + false + + + $(PackageTargetFallback);portable-net45+win8+wp8+wpa81 - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\Microsoft.CodeAnalysis.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.dll - True - - - ..\packages\Microsoft.CodeAnalysis.CSharp.1.3.2\lib\net45\Microsoft.CodeAnalysis.CSharp.dll - True - - - ..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.1.3.2\lib\net45\Microsoft.CodeAnalysis.CSharp.Workspaces.dll - True - - - ..\packages\Microsoft.CodeAnalysis.VisualBasic.1.3.2\lib\net45\Microsoft.CodeAnalysis.VisualBasic.dll - True - - - ..\packages\Microsoft.CodeAnalysis.VisualBasic.Workspaces.1.3.2\lib\net45\Microsoft.CodeAnalysis.VisualBasic.Workspaces.dll - True - - - ..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.Workspaces.dll - True - - - ..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.Workspaces.Desktop.dll - True - - - - ..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll - True - - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.AttributedModel.dll - True - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.Convention.dll - True - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.Hosting.dll - True - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.Runtime.dll - True - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.TypedParts.dll - True - - - - ..\packages\Rx-Core.2.2.5\lib\net45\System.Reactive.Core.dll - True - - - ..\packages\Rx-Interfaces.2.2.5\lib\net45\System.Reactive.Interfaces.dll - True - - - ..\packages\Rx-Linq.2.2.5\lib\net45\System.Reactive.Linq.dll - True - - - ..\packages\Rx-PlatformServices.2.2.5\lib\net45\System.Reactive.PlatformServices.dll - True - - - ..\packages\System.Reflection.Metadata.1.4.2\lib\portable-net45+win8\System.Reflection.Metadata.dll - True - - - - - - - - - - Properties\AssemblyInfoCommon.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - {a02c0394-4dad-4422-97bb-4a90d89cee66} - PCLMock - - + - - - Designer - + + + + + + + - - + - - \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration/Plugins/Disposables.cs b/Src/PCLMock.CodeGeneration/Plugins/Disposables.cs index 56e9f54..3695b8f 100644 --- a/Src/PCLMock.CodeGeneration/Plugins/Disposables.cs +++ b/Src/PCLMock.CodeGeneration/Plugins/Disposables.cs @@ -2,6 +2,7 @@ namespace PCLMock.CodeGeneration.Plugins { using System; using System.Reactive.Disposables; + using System.Reflection; using Logging; using Microsoft.CodeAnalysis; @@ -29,7 +30,7 @@ public sealed class Disposables : IPlugin /// public Compilation InitializeCompilation(Compilation compilation) => - compilation.AddReferences(MetadataReference.CreateFromFile(typeof(Disposable).Assembly.Location)); + compilation.AddReferences(MetadataReference.CreateFromFile(typeof(Disposable).GetTypeInfo().Assembly.Location)); /// public SyntaxNode GetDefaultValueSyntax( diff --git a/Src/PCLMock.CodeGeneration/Plugins/ObservableBasedAsynchrony.cs b/Src/PCLMock.CodeGeneration/Plugins/ObservableBasedAsynchrony.cs index 7fcd868..605d290 100644 --- a/Src/PCLMock.CodeGeneration/Plugins/ObservableBasedAsynchrony.cs +++ b/Src/PCLMock.CodeGeneration/Plugins/ObservableBasedAsynchrony.cs @@ -3,6 +3,7 @@ namespace PCLMock.CodeGeneration.Plugins using System; using System.Linq; using System.Reactive.Linq; + using System.Reflection; using Logging; using Microsoft.CodeAnalysis; @@ -41,7 +42,7 @@ public sealed class ObservableBasedAsynchrony : IPlugin /// public Compilation InitializeCompilation(Compilation compilation) => - compilation.AddReferences(MetadataReference.CreateFromFile(typeof(Observable).Assembly.Location)); + compilation.AddReferences(MetadataReference.CreateFromFile(typeof(Observable).GetTypeInfo().Assembly.Location)); /// public SyntaxNode GetDefaultValueSyntax( diff --git a/Src/PCLMock.CodeGeneration_OLD/Context.cs b/Src/PCLMock.CodeGeneration_OLD/Context.cs new file mode 100644 index 0000000..9a96e72 --- /dev/null +++ b/Src/PCLMock.CodeGeneration_OLD/Context.cs @@ -0,0 +1,76 @@ +namespace PCLMock.CodeGeneration +{ + using System.Collections.Immutable; + using Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.Editing; + using PCLMock.CodeGeneration.Logging; + + /// + /// Contains contextual information for code generation. + /// + public sealed class Context + { + private readonly ILogSink logSink; + private readonly Language language; + private readonly IImmutableList plugins; + private readonly SyntaxGenerator syntaxGenerator; + private readonly SemanticModel semanticModel; + + /// + /// Creates a new instance of the Context class. + /// + /// + /// The log sink. + /// + /// + /// The language in which code is being generated. + /// + /// + /// A list of all plugins. + /// + /// + /// The syntax generator. + /// + /// + /// The semantic model. + /// + public Context( + ILogSink logSink, + Language language, + IImmutableList plugins, + SyntaxGenerator syntaxGenerator, + SemanticModel semanticModel) + { + this.logSink = logSink; + this.language = language; + this.plugins = plugins; + this.syntaxGenerator = syntaxGenerator; + this.semanticModel = semanticModel; + } + + /// + /// Gets the log sink. + /// + public ILogSink LogSink => this.logSink; + + /// + /// Gets the language. + /// + public Language Language => this.language; + + /// + /// Gets a list of all plugins. + /// + public IImmutableList Plugins => this.plugins; + + /// + /// Gets the syntax generator. + /// + public SyntaxGenerator SyntaxGenerator => this.syntaxGenerator; + + /// + /// Gets the semantic model. + /// + public SemanticModel SemanticModel => this.semanticModel; + } +} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Extensions.cs b/Src/PCLMock.CodeGeneration_OLD/Extensions.cs new file mode 100644 index 0000000..a2e57b8 --- /dev/null +++ b/Src/PCLMock.CodeGeneration_OLD/Extensions.cs @@ -0,0 +1,111 @@ +namespace PCLMock.CodeGeneration +{ + using System; + using System.Linq; + using Microsoft.CodeAnalysis; + + public static class Extensions + { + /// + /// Gets a unique name that can be used within the scope of the specified symbol. + /// + /// + /// The symbol within which the name must be unique. + /// + /// + /// A proposed (default) name. + /// + /// + /// A unique name. + /// + public static string GetUniqueName(this IPropertySymbol within, string proposed = "x") + { + while (within.Parameters.Any(x => x.Name == proposed)) + { + proposed = "_" + proposed; + } + + return proposed; + } + + /// + /// Gets a unique name that can be used within the scope of the specified symbol. + /// + /// + /// The symbol within which the name must be unique. + /// + /// + /// A proposed (default) name. + /// + /// + /// A unique name. + /// + public static string GetUniqueName(this IMethodSymbol within, string proposed = "x") + { + while (within.Parameters.Any(x => x.Name == proposed)) + { + proposed = "_" + proposed; + } + + return proposed; + } + + /// + /// Gets a unique name that can be used within the scope of the specified symbol. + /// + /// + /// The symbol within which the name must be unique. + /// + /// + /// A proposed (default) name. + /// + /// + /// A unique name. + /// + public static string GetUniqueName(this ISymbol within, string proposed = "x") + { + var propertySymbol = within as IPropertySymbol; + + if (propertySymbol != null) + { + return propertySymbol.GetUniqueName(proposed); + } + + var methodSymbol = within as IMethodSymbol; + + if (methodSymbol != null) + { + return methodSymbol.GetUniqueName(proposed); + } + + throw new NotSupportedException(); + } + + /// + /// Gets a unique name for a parameter within the scope of the specified symbol. + /// + /// + /// The symbol within which the name must be unique. + /// + /// + /// The parameter symbol. + /// + /// + /// A unique name for the parameter. + /// + public static string GetNameForParameter(this IMethodSymbol within, IParameterSymbol parameterSymbol) + { + switch (parameterSymbol.RefKind) + { + case RefKind.None: + return parameterSymbol.Name; + case RefKind.Ref: + return within.GetUniqueName(parameterSymbol.Name); + case RefKind.Out: + return within.GetUniqueName(parameterSymbol.Name); + default: + throw new NotSupportedException("Unknown parameter ref kind: " + parameterSymbol.RefKind); + } + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Generator.cs b/Src/PCLMock.CodeGeneration_OLD/Generator.cs new file mode 100644 index 0000000..9832eaf --- /dev/null +++ b/Src/PCLMock.CodeGeneration_OLD/Generator.cs @@ -0,0 +1,1127 @@ +namespace PCLMock.CodeGeneration +{ + using System; + using System.Collections.Generic; + using System.Collections.Immutable; + using System.Linq; + using System.Threading.Tasks; + using Logging; + using Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.CSharp; + using Microsoft.CodeAnalysis.CSharp.Syntax; + using Microsoft.CodeAnalysis.Editing; + using Microsoft.CodeAnalysis.MSBuild; + + public static class Generator + { + private static readonly Type logSource = typeof(Generator); + + private const string headerComment = +@"----------------------------------------------------------------------- + + This code was generated from a template. + + Changes to this file may cause incorrect behaviour and will be lost + if the code is regenerated. + +------------------------------------------------------------------------"; + + public async static Task> GenerateMocksAsync( + ILogSink logSink, + Language language, + string solutionPath, + Func interfacePredicate, + Func mockNamespaceSelector, + Func mockNameSelector, + IImmutableList plugins) + { + var workspace = MSBuildWorkspace.Create(); + var solution = await workspace.OpenSolutionAsync(solutionPath); + + return await GenerateMocksAsync( + logSink, + language, + solution, + interfacePredicate, + mockNamespaceSelector, + mockNameSelector, + plugins); + } + + public async static Task> GenerateMocksAsync( + ILogSink logSink, + Language language, + Solution solution, + Func interfacePredicate, + Func mockNamespaceSelector, + Func mockNameSelector, + IImmutableList plugins) + { + var syntaxGenerator = SyntaxGenerator.GetGenerator(solution.Workspace, language.ToSyntaxGeneratorLanguageName()); + var compilations = await Task.WhenAll( + solution + .Projects + .Select(async project => + { + var compilation = await project.GetCompilationAsync(); + // make sure the compilation has a reference to PCLMock + compilation = compilation.AddReferences(MetadataReference.CreateFromFile(typeof(MockBase<>).Assembly.Location)); + + foreach (var plugin in plugins) + { + compilation = plugin.InitializeCompilation(compilation); + } + + if (logSink.IsEnabled) + { + logSink.Debug(logSource, "Compilation generated for project '{0}' with references:", project.Name); + + foreach (var reference in compilation.References) + { + logSink.Debug(logSource, "- {0}", reference.Display); + } + } + + return compilation; + })); + + return compilations + .SelectMany( + compilation => + GetSymbolsRecursive(compilation.SourceModule.GlobalNamespace) + .OfType() + .Where(typeSymbol => typeSymbol.TypeKind == TypeKind.Interface && !typeSymbol.IsImplicitlyDeclared) + .Where(typeSymbol => interfacePredicate == null || interfacePredicate(typeSymbol)) + .Select(interfaceSymbol => new + { + InterfaceSymbol = interfaceSymbol, + Compilation = compilation + })) + .Select( + x => + { + var @namespace = mockNamespaceSelector(x.InterfaceSymbol); + var name = mockNameSelector(x.InterfaceSymbol); + + if (logSink.IsEnabled) + { + logSink.Positive( + logSource, + "Generating mock for interface '{0}' with namespace '{1}', name '{2}'.", + x.InterfaceSymbol, + @namespace, + name); + } + + var semanticModel = x.Compilation.GetSemanticModel(x.InterfaceSymbol.DeclaringSyntaxReferences.First().SyntaxTree); + var context = new Context(logSink, language, plugins, syntaxGenerator, semanticModel); + return GenerateMock(context, x.InterfaceSymbol, @namespace, name, plugins); + }) + .Select((syntaxNode, i) => i == 0 ? syntaxGenerator.WithLeadingComments(syntaxNode, headerComment, language) : syntaxNode) + .ToImmutableList(); + } + + private static SyntaxNode GenerateMock( + Context context, + INamedTypeSymbol interfaceSymbol, + string mockNamespace, + string mockName, + IImmutableList plugins) + { + var namespaceSyntax = GetNamespaceDeclarationSyntax(context, mockNamespace); + var classSyntax = GetClassDeclarationSyntax(context, mockName, interfaceSymbol); + + classSyntax = context + .SyntaxGenerator + .AddAttributes(classSyntax, GetClassAttributesSyntax(context)); + classSyntax = context + .SyntaxGenerator + .AddMembers(classSyntax, GetMemberDeclarations(context, mockName, interfaceSymbol, plugins)); + namespaceSyntax = context + .SyntaxGenerator + .AddMembers(namespaceSyntax, classSyntax); + + return context + .SyntaxGenerator + .CompilationUnit(namespaceSyntax) + .NormalizeWhitespace(); + } + + private static SyntaxNode GetNamespaceDeclarationSyntax( + Context context, + string @namespace) + { + return context + .SyntaxGenerator + .NamespaceDeclaration(@namespace); + } + + private static SyntaxNode GetClassDeclarationSyntax( + Context context, + string name, + INamedTypeSymbol interfaceSymbol) + { + var interfaceType = context + .SyntaxGenerator + .TypeExpression(interfaceSymbol); + var mockBaseType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("PCLMock.MockBase`1"); + + if (mockBaseType == null) + { + throw new InvalidOperationException("Failed to find type in PCLMock assembly. Are you sure this project has a reference to PCLMock?"); + } + + var baseType = context + .SyntaxGenerator + .TypeExpression( + mockBaseType + .Construct(interfaceSymbol)); + + var accessibility = interfaceSymbol.DeclaredAccessibility == Accessibility.NotApplicable + ? Accessibility.Public + : interfaceSymbol.DeclaredAccessibility; + + var classDeclaration = context + .SyntaxGenerator + .ClassDeclaration( + name, + accessibility: accessibility, + modifiers: DeclarationModifiers.Partial, + typeParameters: interfaceSymbol.TypeParameters.Select(x => x.Name), + baseType: baseType, + interfaceTypes: new[] { interfaceType }); + + // TODO: tidy this up once this issue is rectified: https://github.com/dotnet/roslyn/issues/1658 + foreach (var typeParameter in interfaceSymbol.TypeParameters) + { + if (typeParameter.HasConstructorConstraint || + typeParameter.HasReferenceTypeConstraint || + typeParameter.HasValueTypeConstraint || + typeParameter.ConstraintTypes.Length > 0) + { + var kinds = (typeParameter.HasConstructorConstraint ? SpecialTypeConstraintKind.Constructor : SpecialTypeConstraintKind.None) | + (typeParameter.HasReferenceTypeConstraint ? SpecialTypeConstraintKind.ReferenceType : SpecialTypeConstraintKind.None) | + (typeParameter.HasValueTypeConstraint ? SpecialTypeConstraintKind.ValueType : SpecialTypeConstraintKind.None); + + classDeclaration = context + .SyntaxGenerator + .WithTypeConstraint( + classDeclaration, + typeParameter.Name, + kinds: kinds, + types: typeParameter.ConstraintTypes.Select(t => context.SyntaxGenerator.TypeExpression(t))); + } + } + + return classDeclaration; + } + + private static IEnumerable GetClassAttributesSyntax( + Context context) + { + // GENERATED CODE: + // + // [System.CodeDom.Compiler.GeneratedCode("PCLMock", "[version]")] + // [System.Runtime.CompilerServices.CompilerGenerated)] + yield return context + .SyntaxGenerator + .Attribute( + "System.CodeDom.Compiler.GeneratedCode", + context + .SyntaxGenerator + .LiteralExpression("PCLMock"), + context + .SyntaxGenerator + .LiteralExpression(typeof(MockBase<>).Assembly.GetName().Version.ToString())); + yield return context + .SyntaxGenerator + .Attribute( + "System.Runtime.CompilerServices.CompilerGenerated"); + } + + private static SyntaxNode GetConstructorDeclarationSyntax( + Context context, + string name) + { + // GENERATED CODE: + // + // public Name(MockBehavior behavior = MockBehavior.Strict) + // : base(behavior) + // { + // ConfigureBehaviorGenerated(); + // ConfigureBehavior(); + // + // if (behavior == MockBehavior.Loose) + // { + // ConfigureLooseBehaviorGenerated(); + // ConfigureLooseBehavior(); + // } + // } + var mockBehaviorType = context + .SyntaxGenerator + .TypeExpression( + context + .SemanticModel + .Compilation + .GetTypeByMetadataName("PCLMock.MockBehavior")); + + return context + .SyntaxGenerator + .ConstructorDeclaration( + name, + parameters: new[] + { + context + .SyntaxGenerator + .ParameterDeclaration( + "behavior", + mockBehaviorType, + initializer: context.SyntaxGenerator.MemberAccessExpression(mockBehaviorType, "Strict")) + }, + accessibility: Accessibility.Public, + baseConstructorArguments: new[] { context.SyntaxGenerator.IdentifierName("behavior") }, + statements: new[] + { + context + .SyntaxGenerator + .InvocationExpression( + context + .SyntaxGenerator + .IdentifierName("ConfigureBehaviorGenerated")), + context + .SyntaxGenerator + .InvocationExpression( + context + .SyntaxGenerator + .IdentifierName("ConfigureBehavior")), + context + .SyntaxGenerator + .IfStatement( + context + .SyntaxGenerator + .ValueEqualsExpression( + context + .SyntaxGenerator + .IdentifierName("behavior"), + context + .SyntaxGenerator + .MemberAccessExpression(mockBehaviorType, "Loose")), + new[] + { + context + .SyntaxGenerator + .InvocationExpression( + context + .SyntaxGenerator + .IdentifierName("ConfigureLooseBehaviorGenerated")), + context + .SyntaxGenerator + .InvocationExpression( + context + .SyntaxGenerator + .IdentifierName("ConfigureLooseBehavior")) + }) + }); + } + + private static SyntaxNode GetConfigureBehaviorGeneratedSyntax( + Context context, + INamedTypeSymbol interfaceSymbol, + IImmutableList plugins, + MockBehavior behavior) + { + var statements = GetMembersRecursive(interfaceSymbol) + .Select(symbol => GetConfigureBehaviorGeneratedForSymbol(context, interfaceSymbol, symbol, plugins, behavior)) + .Where(syntaxNode => syntaxNode != null) + .ToImmutableList(); + + return context + .SyntaxGenerator + .MethodDeclaration( + behavior == MockBehavior.Strict ? "ConfigureBehaviorGenerated" : "ConfigureLooseBehaviorGenerated", + accessibility: Accessibility.Private, + statements: statements); + } + + private static SyntaxNode GetConfigureBehaviorGeneratedForSymbol( + Context context, + INamedTypeSymbol interfaceSymbol, + ISymbol symbol, + IImmutableList plugins, + MockBehavior behavior) + { + context + .LogSink + .Debug(logSource, "Considering symbol '{0}'.", symbol); + + var propertySymbol = symbol as IPropertySymbol; + var methodSymbol = symbol as IMethodSymbol; + + INamedTypeSymbol returnType = null; + + if (propertySymbol != null) + { + if (propertySymbol.GetMethod == null) + { + context + .LogSink + .Debug(logSource, "Ignoring symbol '{0}' because it is a write-only property.", symbol); + return null; + } + + returnType = propertySymbol.GetMethod.ReturnType as INamedTypeSymbol; + } + else if (methodSymbol != null) + { + if (methodSymbol.AssociatedSymbol != null) + { + context + .LogSink + .Debug(logSource, "Ignoring symbol '{0}' because it is a method with an associated symbol.", symbol); + return null; + } + + if (methodSymbol.IsGenericMethod) + { + context + .LogSink + .Debug(logSource, "Ignoring symbol '{0}' because it is a generic method.", symbol); + return null; + } + + returnType = methodSymbol.ReturnType as INamedTypeSymbol; + } + else + { + context + .LogSink + .Debug(logSource, "Ignoring symbol '{0}' because it is neither a property nor a method.", symbol); + return null; + } + + if (returnType == null) + { + context + .LogSink + .Warn(logSource, "Ignoring symbol '{0}' because its return type could not be determined (it's probably a sgeneric).", symbol); + return null; + } + + var defaultValueSyntax = plugins + .Select(plugin => plugin.GetDefaultValueSyntax(context, behavior, symbol, returnType)) + .Where(syntax => syntax != null) + .FirstOrDefault(); + + if (defaultValueSyntax == null) + { + return null; + } + + var itType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("PCLMock.It"); + + if (itType == null) + { + context + .LogSink + .Error(logSource, "Failed to resolve It class."); + return null; + } + + var isAnyMethod = itType + .GetMembers("IsAny") + .Single(); + + if (isAnyMethod == null) + { + context + .LogSink + .Error(logSource, "Failed to resolve IsAny method."); + return null; + } + + var lambdaParameterName = symbol.GetUniqueName(); + SyntaxNode lambdaExpression; + + if (propertySymbol != null) + { + if (!propertySymbol.IsIndexer) + { + // GENERATED CODE: + // + // this + // .When(x => x.SymbolName) + lambdaExpression = context + .SyntaxGenerator + .MemberAccessExpression( + context + .SyntaxGenerator + .IdentifierName(lambdaParameterName), + propertySymbol.Name); + } + else + { + // GENERATED CODE: + // + // this + // .When(x => x[It.IsAny(), It.IsAny() ...) + var whenArguments = propertySymbol + .Parameters + .Select( + parameter => + context + .SyntaxGenerator + .InvocationExpression( + context + .SyntaxGenerator + .MemberAccessExpression( + context + .SyntaxGenerator + .TypeExpression(itType), + context + .SyntaxGenerator + .GenericName( + "IsAny", + typeArguments: new[] + { + parameter.Type + })))); + + lambdaExpression = context + .SyntaxGenerator + .ElementAccessExpression( + context + .SyntaxGenerator + .IdentifierName(lambdaParameterName), + arguments: whenArguments); + } + } + else + { + // GENERATED CODE: + // + // this + // .When(x => x.SymbolName(It.IsAny(), It.IsAny() ...) + var whenArguments = methodSymbol + .Parameters + .Select( + parameter => + context + .SyntaxGenerator + .InvocationExpression( + context + .SyntaxGenerator + .MemberAccessExpression( + context + .SyntaxGenerator + .TypeExpression(itType), + context + .SyntaxGenerator + .GenericName( + "IsAny", + typeArguments: new[] + { + parameter.Type + })))); + + lambdaExpression = context + .SyntaxGenerator + .InvocationExpression( + context + .SyntaxGenerator + .MemberAccessExpression( + context + .SyntaxGenerator + .IdentifierName(lambdaParameterName), + methodSymbol.Name), + arguments: whenArguments); + } + + var whenLambdaArgument = context + .SyntaxGenerator + .ValueReturningLambdaExpression( + lambdaParameterName, + lambdaExpression); + + var whenInvocation = context + .SyntaxGenerator + .InvocationExpression( + context + .SyntaxGenerator + .MemberAccessExpression( + context + .SyntaxGenerator + .ThisExpression(), + context + .SyntaxGenerator + .IdentifierName("When")), + whenLambdaArgument); + + var result = context + .SyntaxGenerator + .ExpressionStatement( + context + .SyntaxGenerator + .InvocationExpression( + context + .SyntaxGenerator + .MemberAccessExpression( + whenInvocation, + context + .SyntaxGenerator + .IdentifierName("Return")), + arguments: new[] + { + defaultValueSyntax + })); + + return result; + } + + private static SyntaxNode GetConfigureBehaviorMethodSyntax( + Context context) + { + // GENERATED CODE: + // + // partial void ConfigureBehavior(); + return context + .SyntaxGenerator + .MethodDeclaration( + "ConfigureBehavior", + accessibility: context.Language == Language.VisualBasic ? Accessibility.Private : Accessibility.NotApplicable, + modifiers: DeclarationModifiers.Partial); + } + + private static SyntaxNode GetConfigureLooseBehaviorMethodSyntax( + Context context) + { + // GENERATED CODE: + // + // partial void ConfigureLooseBehavior(); + return context + .SyntaxGenerator + .MethodDeclaration( + "ConfigureLooseBehavior", + accessibility: context.Language == Language.VisualBasic ? Accessibility.Private : Accessibility.NotApplicable, + modifiers: DeclarationModifiers.Partial); + } + + private static IEnumerable GetMemberDeclarations( + Context context, + string name, + INamedTypeSymbol interfaceSymbol, + IImmutableList plugins) + { + return + new SyntaxNode[] + { + GetConstructorDeclarationSyntax(context, name), + GetConfigureBehaviorGeneratedSyntax(context, interfaceSymbol, plugins, MockBehavior.Strict), + GetConfigureBehaviorGeneratedSyntax(context, interfaceSymbol, plugins, MockBehavior.Loose), + GetConfigureBehaviorMethodSyntax(context), + GetConfigureLooseBehaviorMethodSyntax(context) + } + .Concat( + GetMembersRecursive(interfaceSymbol) + .Select(x => GetMemberDeclarationSyntax(context, x)) + .Where(x => x != null) + .GroupBy(x => x, SyntaxNodeEqualityComparer.Instance) + .Where(group => group.Count() == 1) + .SelectMany(group => group) + .Select(x => context.SyntaxGenerator.AsPublicInterfaceImplementation(x, context.SyntaxGenerator.TypeExpression(interfaceSymbol)))); + } + + private static IEnumerable GetMembersRecursive(INamedTypeSymbol interfaceSymbol) + { + foreach (var member in interfaceSymbol.GetMembers()) + { + yield return member; + } + + foreach (var implementedInterface in interfaceSymbol.Interfaces) + { + foreach (var member in GetMembersRecursive(implementedInterface)) + { + yield return member; + } + } + } + + private static SyntaxNode GetMemberDeclarationSyntax( + Context context, + ISymbol symbol) + { + var propertySymbol = symbol as IPropertySymbol; + + if (propertySymbol != null) + { + return GetPropertyDeclarationSyntax(context, propertySymbol); + } + + var methodSymbol = symbol as IMethodSymbol; + + if (methodSymbol != null) + { + return GetMethodDeclarationSyntax(context, methodSymbol); + } + + // unsupported symbol type, but we don't error - the user can supplement our code as necessary because it's a partial class + return null; + } + + private static SyntaxNode GetPropertyDeclarationSyntax( + Context context, + IPropertySymbol propertySymbol) + { + var getAccessorStatements = GetPropertyGetAccessorsSyntax(context, propertySymbol).ToList(); + var setAccessorStatements = GetPropertySetAccessorsSyntax(context, propertySymbol).ToList(); + var declarationModifiers = DeclarationModifiers.None; + + if (getAccessorStatements.Count == 0) + { + declarationModifiers = declarationModifiers.WithIsWriteOnly(true); + + // set-only properties are not currently supported + return null; + } + + if (setAccessorStatements.Count == 0) + { + declarationModifiers = declarationModifiers.WithIsReadOnly(true); + } + + if (!propertySymbol.IsIndexer) + { + return context + .SyntaxGenerator + .PropertyDeclaration( + propertySymbol.Name, + context + .SyntaxGenerator + .TypeExpression(propertySymbol.Type), + accessibility: Accessibility.Public, + modifiers: declarationModifiers, + getAccessorStatements: getAccessorStatements, + setAccessorStatements: setAccessorStatements); + } + else + { + var parameters = propertySymbol + .Parameters + .Select(x => context.SyntaxGenerator.ParameterDeclaration(x.Name, context.SyntaxGenerator.TypeExpression(x.Type))) + .ToList(); + + return context + .SyntaxGenerator + .IndexerDeclaration( + parameters, + context.SyntaxGenerator.TypeExpression(propertySymbol.Type), + accessibility: Accessibility.Public, + modifiers: declarationModifiers, + getAccessorStatements: getAccessorStatements, + setAccessorStatements: setAccessorStatements); + } + } + + private static IEnumerable GetPropertyGetAccessorsSyntax( + Context context, + IPropertySymbol propertySymbol) + { + if (propertySymbol.GetMethod == null) + { + yield break; + } + + var lambdaParameterName = propertySymbol.GetUniqueName(); + + if (!propertySymbol.IsIndexer) + { + // GENERATED CODE: + // + // return this.Apply(x => x.PropertyName); + yield return context + .SyntaxGenerator + .ReturnStatement( + context + .SyntaxGenerator + .InvocationExpression( + context + .SyntaxGenerator + .MemberAccessExpression( + context + .SyntaxGenerator + .ThisExpression(), + "Apply"), + context + .SyntaxGenerator + .ValueReturningLambdaExpression( + lambdaParameterName, + context + .SyntaxGenerator + .MemberAccessExpression( + context + .SyntaxGenerator + .IdentifierName(lambdaParameterName), + context + .SyntaxGenerator + .IdentifierName(propertySymbol.Name))))); + } + else + { + // GENERATED CODE: + // + // return this.Apply(x => x[first, second]); + var arguments = propertySymbol + .Parameters + .Select(x => context.SyntaxGenerator.Argument(context.SyntaxGenerator.IdentifierName(x.Name))) + .ToList(); + + yield return context + .SyntaxGenerator + .ReturnStatement( + context + .SyntaxGenerator + .InvocationExpression( + context + .SyntaxGenerator + .MemberAccessExpression( + context + .SyntaxGenerator + .ThisExpression(), + "Apply"), + context + .SyntaxGenerator + .ValueReturningLambdaExpression( + lambdaParameterName, + context + .SyntaxGenerator + .ElementAccessExpression( + context + .SyntaxGenerator + .IdentifierName(lambdaParameterName), + arguments)))); + } + } + + private static IEnumerable GetPropertySetAccessorsSyntax( + Context context, + IPropertySymbol propertySymbol) + { + if (propertySymbol.SetMethod == null) + { + yield break; + } + + var lambdaParameterName = propertySymbol.GetUniqueName(); + + if (!propertySymbol.IsIndexer) + { + // GENERATED CODE: + // + // this.ApplyPropertySet(x => x.PropertyName, value); + yield return context + .SyntaxGenerator + .InvocationExpression( + context + .SyntaxGenerator + .MemberAccessExpression( + context + .SyntaxGenerator + .ThisExpression(), + "ApplyPropertySet"), + context + .SyntaxGenerator + .ValueReturningLambdaExpression( + lambdaParameterName, + context + .SyntaxGenerator + .MemberAccessExpression( + context + .SyntaxGenerator + .IdentifierName(lambdaParameterName), + context + .SyntaxGenerator + .IdentifierName(propertySymbol.Name))), + context + .SyntaxGenerator + .IdentifierName("value")); + } + else + { + // GENERATED CODE: + // + // this.ApplyPropertySet(x => x[first, second], value); + var arguments = propertySymbol + .Parameters + .Select(x => context.SyntaxGenerator.Argument(context.SyntaxGenerator.IdentifierName(x.Name))) + .ToList(); + + yield return context + .SyntaxGenerator + .InvocationExpression( + context + .SyntaxGenerator + .MemberAccessExpression( + context + .SyntaxGenerator + .ThisExpression(), + "ApplyPropertySet"), + context + .SyntaxGenerator + .ValueReturningLambdaExpression( + lambdaParameterName, + context + .SyntaxGenerator + .ElementAccessExpression( + context + .SyntaxGenerator + .IdentifierName(lambdaParameterName), + arguments)), + context + .SyntaxGenerator + .IdentifierName("value")); + } + } + + private static SyntaxNode GetMethodDeclarationSyntax( + Context context, + IMethodSymbol methodSymbol) + { + if (methodSymbol.MethodKind != MethodKind.Ordinary) + { + return null; + } + + var methodDeclaration = context + .SyntaxGenerator + .MethodDeclaration(methodSymbol); + methodDeclaration = context + .SyntaxGenerator + .WithModifiers( + methodDeclaration, + context + .SyntaxGenerator + .GetModifiers(methodDeclaration) + .WithIsAbstract(false)); + methodDeclaration = context + .SyntaxGenerator + .WithStatements( + methodDeclaration, + GetMethodStatementsSyntax(context, methodSymbol)); + + var csharpMethodDeclaration = methodDeclaration as MethodDeclarationSyntax; + + if (csharpMethodDeclaration != null) + { + // remove trailing semi-colon from the declaration + methodDeclaration = csharpMethodDeclaration.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.None)); + } + + return methodDeclaration; + } + + private static IEnumerable GetMethodStatementsSyntax( + Context context, + IMethodSymbol methodSymbol) + { + // GENERATED CODE (for every ref or out parameter): + // + // string someOutParameter; + // var someRefParameter = default(int); + for (var i = 0; i < methodSymbol.Parameters.Length; ++i) + { + var parameter = methodSymbol.Parameters[i]; + + if (parameter.RefKind == RefKind.Out) + { + yield return context + .SyntaxGenerator + .LocalDeclarationStatement( + context + .SyntaxGenerator + .TypeExpression(parameter.Type), + methodSymbol.GetNameForParameter(parameter)); + } + else if (parameter.RefKind == RefKind.Ref) + { + yield return context + .SyntaxGenerator + .LocalDeclarationStatement( + methodSymbol.GetNameForParameter(parameter), + initializer: context.SyntaxGenerator.DefaultExpression(context.SyntaxGenerator.TypeExpression(parameter.Type))); + } + } + + var arguments = methodSymbol + .Parameters + .Select(x => + context + .SyntaxGenerator + .Argument( + x.RefKind, + context + .SyntaxGenerator + .IdentifierName(methodSymbol.GetNameForParameter(x)))) + .ToList(); + + var typeArguments = methodSymbol + .TypeArguments + .Select(x => context.SyntaxGenerator.TypeExpression(x)) + .ToList(); + + var lambdaParameterName = methodSymbol.GetUniqueName(); + + var lambdaInvocation = context + .SyntaxGenerator + .MemberAccessExpression( + context + .SyntaxGenerator + .IdentifierName(lambdaParameterName), + methodSymbol.Name); + + if (typeArguments.Count > 0) + { + lambdaInvocation = context + .SyntaxGenerator + .WithTypeArguments( + lambdaInvocation, + typeArguments); + } + + // GENERATED CODE (for every ref or out parameter): + // + // someOutParameter = this.GetOutParameterValue(x => x.TheMethod(out someOutParameter), parameterIndex: 0); + // someRefParameter = this.GetRefParameterValue(x => x.TheMethod(ref someRefParameter), parameterIndex: 0); + for (var i = 0; i < methodSymbol.Parameters.Length; ++i) + { + var parameter = methodSymbol.Parameters[i]; + + if (parameter.RefKind == RefKind.Out || parameter.RefKind == RefKind.Ref) + { + var nameOfMethodToCall = parameter.RefKind == RefKind.Out ? "GetOutParameterValue" : "GetRefParameterValue"; + + yield return context + .SyntaxGenerator + .AssignmentStatement( + context + .SyntaxGenerator + .IdentifierName(parameter.Name), + context + .SyntaxGenerator + .InvocationExpression( + context + .SyntaxGenerator + .MemberAccessExpression( + context + .SyntaxGenerator + .ThisExpression(), + context + .SyntaxGenerator + .GenericName( + nameOfMethodToCall, + typeArguments: context.SyntaxGenerator.TypeExpression(parameter.Type))), + arguments: new[] + { + context + .SyntaxGenerator + .ValueReturningLambdaExpression( + lambdaParameterName, + context + .SyntaxGenerator + .InvocationExpression( + lambdaInvocation, + arguments: arguments)), + context + .SyntaxGenerator + .LiteralExpression(i) + })); + } + } + + // GENERATED CODE: + // + // [return] this.Apply(x => x.SomeMethod(param1, param2)); + var applyInvocation = context + .SyntaxGenerator + .InvocationExpression( + context + .SyntaxGenerator + .MemberAccessExpression( + context + .SyntaxGenerator + .ThisExpression(), + "Apply"), + context + .SyntaxGenerator + .ValueReturningLambdaExpression( + lambdaParameterName, + context + .SyntaxGenerator + .InvocationExpression( + lambdaInvocation, + arguments: arguments))); + + if (!methodSymbol.ReturnsVoid) + { + applyInvocation = context + .SyntaxGenerator + .ReturnStatement(applyInvocation); + } + + yield return applyInvocation; + } + + private static IEnumerable GetSymbolsRecursive(INamespaceSymbol namespaceSymbol) + { + // using a heap-based stack here instead of recursive call just to be sure we don't overflow the stack + var stack = new Stack(); + stack.Push(namespaceSymbol); + + while (stack.Count > 0) + { + var namespaceSymbolToProcess = stack.Pop(); + + yield return namespaceSymbolToProcess; + + foreach (var namespaceMember in namespaceSymbolToProcess.GetMembers()) + { + var namespaceMemberAsNamespace = namespaceMember as INamespaceSymbol; + + if (namespaceMemberAsNamespace != null) + { + stack.Push(namespaceMemberAsNamespace); + } + else + { + yield return namespaceMember; + } + } + } + } + + private sealed class SyntaxNodeEqualityComparer : IEqualityComparer + { + public static readonly SyntaxNodeEqualityComparer Instance = new SyntaxNodeEqualityComparer(); + + private SyntaxNodeEqualityComparer() + { + } + + public bool Equals(SyntaxNode x, SyntaxNode y) => + x.IsEquivalentTo(y, topLevel: true); + + // We have to ensure like syntax nodes have the same hash code in order for Equals to even be called + // Unfortunately, Roslyn does not implement GetHashCode, so we can't use that. We also don't want to + // use ToString because then we may as well have just grouped by it and because it includes the + // implementation, not just the declaration. To do this "properly", we'd have to write a recursive + // hash code calculator, using similar logic to what IsEquivalentTo gives us. + public int GetHashCode(SyntaxNode obj) => + 0; + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/IPlugin.cs b/Src/PCLMock.CodeGeneration_OLD/IPlugin.cs new file mode 100644 index 0000000..be5293e --- /dev/null +++ b/Src/PCLMock.CodeGeneration_OLD/IPlugin.cs @@ -0,0 +1,77 @@ +namespace PCLMock.CodeGeneration +{ + using Microsoft.CodeAnalysis; + + /// + /// Defines the interface for a plugin. + /// + /// + /// + /// Plugins are able to participate in generating code at specific points in the mock code generation process. + /// For example, they might generate a default return value for any method returning a Task. + /// + /// + /// The participating plugins are configured by adding them to the + /// instance passed into . + /// + /// + public interface IPlugin + { + /// + /// Gets a human-friendly name for the plugin, for identification in debug output. + /// + string Name + { + get; + } + + /// + /// Perform any initialization against the compilation. + /// + /// + /// + /// This method is called once per compilation and per plugin, before any code is generated. If no initialization is required, + /// plugins should simply return the provided compilation. + /// + /// + /// + /// The compilation. + /// + /// + /// The initialized compilation. + /// + Compilation InitializeCompilation(Compilation compilation); + + /// + /// Called to generate the default value for a given symbol. + /// + /// + /// + /// The code generation engine calls this method for each discovered symbol (property/method) that returns a value. + /// The first plugin to return a value will have that syntax incorporated into the mock's ConfigureBehaviorGenerated + /// or ConfigureLooseBehaviorGenerated method, depending on the value of . + /// + /// + /// + /// A context for the operation. + /// + /// + /// Indicates whether the default value is being generated for strict or loose behavioral semantics. + /// + /// + /// The symbol. + /// + /// + /// The symbol's return type. + /// + /// + /// An instance of containing the default value, or if no default value is + /// relevant. + /// + SyntaxNode GetDefaultValueSyntax( + Context context, + MockBehavior behavior, + ISymbol symbol, + INamedTypeSymbol returnType); + } +} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Language.cs b/Src/PCLMock.CodeGeneration_OLD/Language.cs new file mode 100644 index 0000000..d7419ff --- /dev/null +++ b/Src/PCLMock.CodeGeneration_OLD/Language.cs @@ -0,0 +1,8 @@ +namespace PCLMock.CodeGeneration +{ + public enum Language + { + CSharp, + VisualBasic + } +} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/LanguageExtensions.cs b/Src/PCLMock.CodeGeneration_OLD/LanguageExtensions.cs new file mode 100644 index 0000000..2c59a4d --- /dev/null +++ b/Src/PCLMock.CodeGeneration_OLD/LanguageExtensions.cs @@ -0,0 +1,21 @@ +namespace PCLMock.CodeGeneration +{ + using System; + using Microsoft.CodeAnalysis; + + public static class LanguageExtensions + { + public static string ToSyntaxGeneratorLanguageName(this Language @this) + { + switch (@this) + { + case Language.CSharp: + return LanguageNames.CSharp; + case Language.VisualBasic: + return LanguageNames.VisualBasic; + default: + throw new NotSupportedException(); + } + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Logging/ILogSink.cs b/Src/PCLMock.CodeGeneration_OLD/Logging/ILogSink.cs new file mode 100644 index 0000000..f49b627 --- /dev/null +++ b/Src/PCLMock.CodeGeneration_OLD/Logging/ILogSink.cs @@ -0,0 +1,14 @@ +namespace PCLMock.CodeGeneration.Logging +{ + using System; + + public interface ILogSink + { + bool IsEnabled + { + get; + } + + void Log(Type source, LogLevel level, string message); + } +} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Logging/LogLevel.cs b/Src/PCLMock.CodeGeneration_OLD/Logging/LogLevel.cs new file mode 100644 index 0000000..b63881d --- /dev/null +++ b/Src/PCLMock.CodeGeneration_OLD/Logging/LogLevel.cs @@ -0,0 +1,12 @@ +namespace PCLMock.CodeGeneration.Logging +{ + public enum LogLevel + { + Debug, + Info, + Warn, + Positive, + Negative, + Error + } +} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Logging/LogSinkExtensions.cs b/Src/PCLMock.CodeGeneration_OLD/Logging/LogSinkExtensions.cs new file mode 100644 index 0000000..22a55e1 --- /dev/null +++ b/Src/PCLMock.CodeGeneration_OLD/Logging/LogSinkExtensions.cs @@ -0,0 +1,80 @@ +namespace PCLMock.CodeGeneration.Logging +{ + using System; + using System.Globalization; + + public static class LogSinkExtensions + { + public static void Log(this ILogSink @this, Type source, LogLevel level, string format, params object[] args) + { + var message = string.Format(CultureInfo.InvariantCulture, format, args); + @this.Log(source, level, message); + } + + public static void Debug(this ILogSink @this, Type source, string message) + { + @this.Log(source, LogLevel.Debug, message); + } + + public static void Debug(this ILogSink @this, Type source, string format, params object[] args) + { + var message = string.Format(CultureInfo.InvariantCulture, format, args); + @this.Log(source, LogLevel.Debug, message); + } + + public static void Info(this ILogSink @this, Type source, string message) + { + @this.Log(source, LogLevel.Info, message); + } + + public static void Info(this ILogSink @this, Type source, string format, params object[] args) + { + var message = string.Format(CultureInfo.InvariantCulture, format, args); + @this.Log(source, LogLevel.Info, message); + } + + public static void Warn(this ILogSink @this, Type source, string message) + { + @this.Log(source, LogLevel.Warn, message); + } + + public static void Warn(this ILogSink @this, Type source, string format, params object[] args) + { + var message = string.Format(CultureInfo.InvariantCulture, format, args); + @this.Log(source, LogLevel.Warn, message); + } + + public static void Positive(this ILogSink @this, Type source, string message) + { + @this.Log(source, LogLevel.Positive, message); + } + + public static void Positive(this ILogSink @this, Type source, string format, params object[] args) + { + var message = string.Format(CultureInfo.InvariantCulture, format, args); + @this.Log(source, LogLevel.Positive, message); + } + + public static void Negative(this ILogSink @this, Type source, string message) + { + @this.Log(source, LogLevel.Negative, message); + } + + public static void Negative(this ILogSink @this, Type source, string format, params object[] args) + { + var message = string.Format(CultureInfo.InvariantCulture, format, args); + @this.Log(source, LogLevel.Negative, message); + } + + public static void Error(this ILogSink @this, Type source, string message) + { + @this.Log(source, LogLevel.Error, message); + } + + public static void Error(this ILogSink @this, Type source, string format, params object[] args) + { + var message = string.Format(CultureInfo.InvariantCulture, format, args); + @this.Log(source, LogLevel.Error, message); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Logging/NullLogSink.cs b/Src/PCLMock.CodeGeneration_OLD/Logging/NullLogSink.cs new file mode 100644 index 0000000..232e41e --- /dev/null +++ b/Src/PCLMock.CodeGeneration_OLD/Logging/NullLogSink.cs @@ -0,0 +1,19 @@ +namespace PCLMock.CodeGeneration.Logging +{ + using System; + + public sealed class NullLogSink : ILogSink + { + public static readonly NullLogSink Instance = new NullLogSink(); + + private NullLogSink() + { + } + + public bool IsEnabled => false; + + public void Log(Type source, LogLevel level, string message) + { + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Logging/StringLogSink.cs b/Src/PCLMock.CodeGeneration_OLD/Logging/StringLogSink.cs new file mode 100644 index 0000000..d89e991 --- /dev/null +++ b/Src/PCLMock.CodeGeneration_OLD/Logging/StringLogSink.cs @@ -0,0 +1,30 @@ +namespace PCLMock.CodeGeneration.Logging +{ + using System; + using System.Text; + + public sealed class StringLogSink : ILogSink + { + private readonly StringBuilder stringBuilder; + + public StringLogSink() + { + this.stringBuilder = new StringBuilder(); + } + + public bool IsEnabled => true; + + public void Log(Type source, LogLevel level, string message) => + this + .stringBuilder + .Append("[") + .Append(source.FullName) + .Append("] [") + .Append(level) + .Append("] ") + .AppendLine(message); + + public override string ToString() => + this.stringBuilder.ToString(); + } +} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Models/Configuration.cs b/Src/PCLMock.CodeGeneration_OLD/Models/Configuration.cs new file mode 100644 index 0000000..38af944 --- /dev/null +++ b/Src/PCLMock.CodeGeneration_OLD/Models/Configuration.cs @@ -0,0 +1,226 @@ +namespace PCLMock.CodeGeneration.Models +{ + using System; + using System.Collections.Generic; + using System.Collections.Immutable; + using System.Globalization; + using System.Linq; + using System.Text; + using System.Text.RegularExpressions; + using System.Xml.Linq; + using System.Xml.XPath; + using Logging; + using Microsoft.CodeAnalysis; + + public sealed class Configuration + { + private static readonly Type logSource = typeof(Configuration); + + private readonly ILogSink logSink; + private readonly IImmutableList namespaceTransformations; + private readonly IImmutableList nameTransformations; + private readonly IImmutableList interfaceFilters; + private readonly IImmutableList plugins; + + public Configuration( + ILogSink logSink, + IEnumerable namespaceTransformations, + IEnumerable nameTransformations, + IEnumerable interfaceFilters, + IEnumerable plugins) + { + this.logSink = logSink; + this.namespaceTransformations = namespaceTransformations.ToImmutableList(); + this.nameTransformations = nameTransformations.ToImmutableList(); + this.interfaceFilters = interfaceFilters.ToImmutableList(); + this.plugins = plugins.ToImmutableList(); + + if (logSink.IsEnabled) + { + var namespaceTransformationsLog = this + .namespaceTransformations + .Aggregate( + new StringBuilder(), + (sb, next) => sb.Append(" - Namespaces matching '").Append(next.Pattern).Append("' will be replaced with '").Append(next.Replacement).AppendLine("'."), sb => sb.ToString()); + var nameTransformationsLog = this + .nameTransformations + .Aggregate( + new StringBuilder(), + (sb, next) => sb.Append(" - Names matching '").Append(next.Pattern).Append("' will be replaced with '").Append(next.Replacement).AppendLine("'."), sb => sb.ToString()); + var interfaceFiltersLog = this + .interfaceFilters + .Aggregate( + new StringBuilder(), + (sb, next) => sb.Append(" - Interfaces matching '").Append(next.Pattern).Append("' will be '").Append(next.Type == FilterType.Include ? "included" : "excluded").AppendLine("."), sb => sb.ToString()); + var pluginsLog = this + .plugins + .Aggregate( + new StringBuilder(), + (sb, next) => sb.Append(" - Plugin with assembly-qualified name '").Append(next.AssemblyQualifiedName).AppendLine("' will be applied.")); + logSink.Debug(logSource, $"Created configuration with the following rules:{Environment.NewLine}{namespaceTransformationsLog}{nameTransformationsLog}{interfaceFiltersLog}{pluginsLog}"); + } + } + + public IImmutableList NamespaceTransformations => this.namespaceTransformations; + + public IImmutableList NameTransformations => this.nameTransformations; + + public IImmutableList InterfaceFilters => this.interfaceFilters; + + public IImmutableList Plugins => this.plugins; + + public static Configuration FromXDocument(ILogSink logSink, XDocument document) + { + var namespaceTransformations = document + .Root + .XPathSelectElements("./NamespaceTransformations/Transformation") + .Select(x => new Transformation(x.Element("Pattern").Value, x.Element("Replacement").Value)); + var nameTransformations = document + .Root + .XPathSelectElements("./NameTransformations/Transformation") + .Select(x => new Transformation(x.Element("Pattern").Value, x.Element("Replacement").Value)); + var interfaceFilters = document + .Root + .XPathSelectElements("./Interfaces") + .Single() + .Nodes() + .OfType() + .Select(x => new Filter(ParseFilterType(x.Name.LocalName), x.Element("Pattern").Value)); + var plugins = document + .Root + .XPathSelectElements("./Plugins/Plugin") + .Select(x => new Plugin(x.Value)); + return new Configuration(logSink, namespaceTransformations, nameTransformations, interfaceFilters, plugins); + } + + public Func GetInterfacePredicate() + { + return symbol => + { + var name = string.Format( + CultureInfo.InvariantCulture, + "{0}, {1}", + symbol.ToDisplayString(), + symbol.ContainingAssembly.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat)); + var include = false; + + this.logSink.Info(logSource, "Determining inclusivity of interface: '{0}'.", name); + + foreach (var filter in this.InterfaceFilters) + { + if (include && filter.Type == FilterType.Exclude) + { + include = !Regex.IsMatch(name, filter.Pattern); + } + else if (!include && filter.Type == FilterType.Include) + { + include = Regex.IsMatch(name, filter.Pattern); + } + + if (this.logSink.IsEnabled) + { + this.logSink.Debug( + logSource, + " - after {0} filter '{1}', it is {2}.", + filter.Type == FilterType.Include ? "inclusion" : "exclusion", + filter.Pattern, + include ? "included" : "excluded"); + } + } + + if (logSink.IsEnabled) + { + this.logSink.Log( + logSource, + include ? LogLevel.Positive : LogLevel.Negative, + "'{0}' has been {1}.", + name, + include ? "included" : "excluded"); + } + + return include; + }; + } + + public Func GetNamespaceSelector() + { + return symbol => ApplyTransformations(this.logSink, "namespace", symbol.ContainingNamespace.ToString(), this.NamespaceTransformations); + } + + public Func GetNameSelector() + { + return symbol => ApplyTransformations(this.logSink, "name", symbol.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat), this.NameTransformations); + } + + public IImmutableList GetPlugins() + { + var resolvedPlugins = new List(this.plugins.Count); + + foreach (var plugin in this.plugins) + { + this.logSink.Info(logSource, "Attempting to resolve plugin from type name '{0}'.", plugin.AssemblyQualifiedName); + var type = Type.GetType(plugin.AssemblyQualifiedName); + + if (type == null) + { + this.logSink.Error(logSource, "Failed to resolve plugin from type name '{0}'.", plugin.AssemblyQualifiedName); + continue; + } + + try + { + var resolvedPlugin = Activator.CreateInstance(type); + + if (!(resolvedPlugin is IPlugin)) + { + this.logSink.Error(logSource, "Resolved plugin '{0}' does not implement '{1}'.", resolvedPlugin.GetType().AssemblyQualifiedName, typeof(IPlugin).AssemblyQualifiedName); + continue; + } + + resolvedPlugins.Add((IPlugin)resolvedPlugin); + } + catch (Exception ex) + { + this.logSink.Error(logSource, "Failed to create plugin from type name '{0}'. Exception was: {1}", plugin.AssemblyQualifiedName, ex); + } + } + + return resolvedPlugins.ToImmutableList(); + } + + private static string ApplyTransformations(ILogSink logSink, string type, string input, IImmutableList transformations) + { + logSink.Info(logSource, "Applying {0} transformations to input: '{1}'.", type, input); + + foreach (var transformation in transformations) + { + input = Regex.Replace(input, transformation.Pattern, transformation.Replacement); + + if (logSink.IsEnabled) + { + logSink.Debug( + logSource, + " - after transformation '{0}' -> '{1}', input is now '{2}'.", + transformation.Pattern, + transformation.Replacement, + input); + } + } + + return input; + } + + private static FilterType ParseFilterType(string text) + { + switch (text) + { + case "Include": + return FilterType.Include; + case "Exclude": + return FilterType.Exclude; + default: + throw new NotSupportedException("Filter type '" + text + "' not supported."); + } + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Models/Filter.cs b/Src/PCLMock.CodeGeneration_OLD/Models/Filter.cs new file mode 100644 index 0000000..63f6ee6 --- /dev/null +++ b/Src/PCLMock.CodeGeneration_OLD/Models/Filter.cs @@ -0,0 +1,18 @@ +namespace PCLMock.CodeGeneration.Models +{ + public sealed class Filter + { + private readonly FilterType type; + private readonly string pattern; + + public Filter(FilterType type, string pattern) + { + this.type = type; + this.pattern = pattern; + } + + public FilterType Type => this.type; + + public string Pattern => this.pattern; + } +} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Models/FilterType.cs b/Src/PCLMock.CodeGeneration_OLD/Models/FilterType.cs new file mode 100644 index 0000000..54cc101 --- /dev/null +++ b/Src/PCLMock.CodeGeneration_OLD/Models/FilterType.cs @@ -0,0 +1,8 @@ +namespace PCLMock.CodeGeneration.Models +{ + public enum FilterType + { + Include, + Exclude + } +} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Models/Plugin.cs b/Src/PCLMock.CodeGeneration_OLD/Models/Plugin.cs new file mode 100644 index 0000000..b0cc09f --- /dev/null +++ b/Src/PCLMock.CodeGeneration_OLD/Models/Plugin.cs @@ -0,0 +1,14 @@ +namespace PCLMock.CodeGeneration.Models +{ + public sealed class Plugin + { + private readonly string assemblyQualifiedName; + + public Plugin(string assemblyQualifiedName) + { + this.assemblyQualifiedName = assemblyQualifiedName; + } + + public string AssemblyQualifiedName => this.assemblyQualifiedName; + } +} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Models/Transformation.cs b/Src/PCLMock.CodeGeneration_OLD/Models/Transformation.cs new file mode 100644 index 0000000..9d0be40 --- /dev/null +++ b/Src/PCLMock.CodeGeneration_OLD/Models/Transformation.cs @@ -0,0 +1,18 @@ +namespace PCLMock.CodeGeneration.Models +{ + public sealed class Transformation + { + private readonly string pattern; + private readonly string replacement; + + public Transformation(string pattern, string replacement) + { + this.pattern = pattern; + this.replacement = replacement; + } + + public string Pattern => this.pattern; + + public string Replacement => this.replacement; + } +} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/PCLMock.CodeGeneration.csproj b/Src/PCLMock.CodeGeneration_OLD/PCLMock.CodeGeneration.csproj new file mode 100644 index 0000000..6ac3d63 --- /dev/null +++ b/Src/PCLMock.CodeGeneration_OLD/PCLMock.CodeGeneration.csproj @@ -0,0 +1,161 @@ + + + + + Debug + AnyCPU + {6E077796-0241-4191-A866-0EA52B9BD946} + Library + Properties + PCLMock.CodeGeneration + PCLMock.CodeGeneration + v4.5.2 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Microsoft.CodeAnalysis.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.dll + True + + + ..\packages\Microsoft.CodeAnalysis.CSharp.1.3.2\lib\net45\Microsoft.CodeAnalysis.CSharp.dll + True + + + ..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.1.3.2\lib\net45\Microsoft.CodeAnalysis.CSharp.Workspaces.dll + True + + + ..\packages\Microsoft.CodeAnalysis.VisualBasic.1.3.2\lib\net45\Microsoft.CodeAnalysis.VisualBasic.dll + True + + + ..\packages\Microsoft.CodeAnalysis.VisualBasic.Workspaces.1.3.2\lib\net45\Microsoft.CodeAnalysis.VisualBasic.Workspaces.dll + True + + + ..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.Workspaces.dll + True + + + ..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.Workspaces.Desktop.dll + True + + + + ..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll + True + + + + ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.AttributedModel.dll + True + + + ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.Convention.dll + True + + + ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.Hosting.dll + True + + + ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.Runtime.dll + True + + + ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.TypedParts.dll + True + + + + ..\packages\Rx-Core.2.2.5\lib\net45\System.Reactive.Core.dll + True + + + ..\packages\Rx-Interfaces.2.2.5\lib\net45\System.Reactive.Interfaces.dll + True + + + ..\packages\Rx-Linq.2.2.5\lib\net45\System.Reactive.Linq.dll + True + + + ..\packages\Rx-PlatformServices.2.2.5\lib\net45\System.Reactive.PlatformServices.dll + True + + + ..\packages\System.Reflection.Metadata.1.4.2\lib\portable-net45+win8\System.Reflection.Metadata.dll + True + + + + + + + + + + Properties\AssemblyInfoCommon.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Designer + + + + + + + + + \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/PCLMock.CodeGeneration.v3.ncrunchproject b/Src/PCLMock.CodeGeneration_OLD/PCLMock.CodeGeneration.v3.ncrunchproject new file mode 100644 index 0000000..ab5b48b --- /dev/null +++ b/Src/PCLMock.CodeGeneration_OLD/PCLMock.CodeGeneration.v3.ncrunchproject @@ -0,0 +1,11 @@ + + + Disabled + Disabled + Disabled + Disabled + Disabled + False + True + + \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Plugins/Collections.cs b/Src/PCLMock.CodeGeneration_OLD/Plugins/Collections.cs new file mode 100644 index 0000000..baf6a7c --- /dev/null +++ b/Src/PCLMock.CodeGeneration_OLD/Plugins/Collections.cs @@ -0,0 +1,498 @@ +namespace PCLMock.CodeGeneration.Plugins +{ + using System; + using Logging; + using Microsoft.CodeAnalysis; + + /// + /// A plugin that generates appropriate default return values for any member that returns a collection. + /// + /// + /// + /// This plugin generates return specifications for any member returning a standard collection type. That is, + /// it returns IEnumerable<T>, ICollection<T>, IReadOnlyCollection<T>, + /// IList<T>, IReadOnlyList<T>, IDictionary<TKey, TValue>, + /// IReadOnlyDictionary<TKey, TValue>, ISet<T> IImmutableList<T>, + /// IImmutableDictionary<TKey, TValue>, IImmutableQueue<T>, + /// IImmutableSet<T>, or IImmutableStack<T>. + /// + /// + /// The generated specification simply returns a default instance of an appropriate type. This has the + /// (usually desirable) effect of ensuring any collection-like member returns an empty collection by default + /// rather than . + /// + /// + /// Members for which specifications cannot be generated are ignored. This of course includes members that do not + /// return collections, but also set-only properties, generic methods, and any members that return custom + /// collection subtypes. + /// + /// + public sealed class Collections : IPlugin + { + private static readonly Type logSource = typeof(Collections); + + public string Name => "Collections"; + + /// + public Compilation InitializeCompilation(Compilation compilation) => + compilation; + + /// + public SyntaxNode GetDefaultValueSyntax( + Context context, + MockBehavior behavior, + ISymbol symbol, + INamedTypeSymbol returnType) + { + if (behavior == MockBehavior.Loose) + { + return null; + } + + if (!returnType.IsGenericType) + { + context + .LogSink + .Debug(logSource, "Ignoring symbol '{0}' because its return type is not a generic type, so it cannot be one of the supported collection types."); + return null; + } + + SyntaxNode returnValueSyntax; + + if (!TryGetReturnValueSyntaxForEnumerableReturnType(context, returnType, out returnValueSyntax) && + !TryGetReturnValueSyntaxForCollectionReturnType(context, returnType, out returnValueSyntax) && + !TryGetReturnValueSyntaxForDictionaryReturnType(context, returnType, out returnValueSyntax) && + !TryGetReturnValueSyntaxForSetReturnType(context, returnType, out returnValueSyntax) && + !TryGetReturnValueSyntaxForImmutableListReturnType(context, returnType, out returnValueSyntax) && + !TryGetReturnValueSyntaxForImmutableDictionaryReturnType(context, returnType, out returnValueSyntax) && + !TryGetReturnValueSyntaxForImmutableQueueReturnType(context, returnType, out returnValueSyntax) && + !TryGetReturnValueSyntaxForImmutableSetReturnType(context, returnType, out returnValueSyntax) && + !TryGetReturnValueSyntaxForImmutableStackReturnType(context, returnType, out returnValueSyntax)) + { + context + .LogSink + .Debug(logSource, "Ignoring symbol '{0}' because it does not return a supported collection type.", symbol); + return null; + } + + return returnValueSyntax; + } + + private static bool TryGetReturnValueSyntaxForEnumerableReturnType( + Context context, + INamedTypeSymbol returnType, + out SyntaxNode returnValueSyntax) + { + var enumerableInterfaceType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("System.Collections.Generic.IEnumerable`1"); + + if (returnType.ConstructedFrom != enumerableInterfaceType) + { + returnValueSyntax = null; + return false; + } + + var enumerableType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("System.Linq.Enumerable"); + + if (enumerableType == null) + { + context + .LogSink + .Warn(logSource, "Failed to resolve Enumerable class."); + returnValueSyntax = null; + return false; + } + + returnValueSyntax = context + .SyntaxGenerator + .InvocationExpression( + context + .SyntaxGenerator + .WithTypeArguments( + context + .SyntaxGenerator + .MemberAccessExpression( + context + .SyntaxGenerator + .TypeExpression(enumerableType), + "Empty"), + context + .SyntaxGenerator + .TypeExpression(returnType.TypeArguments[0]))); + return true; + } + + private static bool TryGetReturnValueSyntaxForCollectionReturnType( + Context context, + INamedTypeSymbol returnType, + out SyntaxNode returnValueSyntax) + { + var collectionInterfaceType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("System.Collections.Generic.ICollection`1"); + + var readOnlyCollectionInterfaceType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("System.Collections.Generic.IReadOnlyCollection`1"); + + var listInterfaceType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("System.Collections.Generic.IList`1"); + + var readOnlyListInterfaceType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("System.Collections.Generic.IReadOnlyList`1"); + + if (returnType.ConstructedFrom != collectionInterfaceType && + returnType.ConstructedFrom != readOnlyCollectionInterfaceType && + returnType.ConstructedFrom != listInterfaceType && + returnType.ConstructedFrom != readOnlyListInterfaceType) + { + returnValueSyntax = null; + return false; + } + + var listType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("System.Collections.Generic.List`1"); + + if (listType == null) + { + context + .LogSink + .Warn(logSource, "Failed to resolve List class."); + returnValueSyntax = null; + return false; + } + + returnValueSyntax = context + .SyntaxGenerator + .ObjectCreationExpression( + listType.Construct(returnType.TypeArguments[0])).NormalizeWhitespace(); + return true; + } + + private static bool TryGetReturnValueSyntaxForDictionaryReturnType( + Context context, + INamedTypeSymbol returnType, + out SyntaxNode returnValueSyntax) + { + var dictionaryInterfaceType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("System.Collections.Generic.IDictionary`2"); + + var readOnlyDictionaryInterfaceType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("System.Collections.Generic.IReadOnlyDictionary`2"); + + if (returnType.ConstructedFrom != dictionaryInterfaceType && + returnType.ConstructedFrom != readOnlyDictionaryInterfaceType) + { + returnValueSyntax = null; + return false; + } + + var dictionaryType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("System.Collections.Generic.Dictionary`2"); + + if (dictionaryType == null) + { + context + .LogSink + .Warn(logSource, "Failed to resolve Dictionary class."); + returnValueSyntax = null; + return false; + } + + returnValueSyntax = context + .SyntaxGenerator + .ObjectCreationExpression( + dictionaryType.Construct(returnType.TypeArguments[0], returnType.TypeArguments[1])).NormalizeWhitespace(); + return true; + } + + private static bool TryGetReturnValueSyntaxForSetReturnType( + Context context, + INamedTypeSymbol returnType, + out SyntaxNode returnValueSyntax) + { + var setInterfaceType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("System.Collections.Generic.ISet`1"); + + if (returnType.ConstructedFrom != setInterfaceType) + { + returnValueSyntax = null; + return false; + } + + var dictionaryType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("System.Collections.Generic.HashSet`1"); + + if (dictionaryType == null) + { + context + .LogSink + .Warn(logSource, "Failed to resolve HashSet class."); + returnValueSyntax = null; + return false; + } + + returnValueSyntax = context + .SyntaxGenerator + .ObjectCreationExpression( + dictionaryType.Construct(returnType.TypeArguments[0])).NormalizeWhitespace(); + return true; + } + + private static bool TryGetReturnValueSyntaxForImmutableListReturnType( + Context context, + INamedTypeSymbol returnType, + out SyntaxNode returnValueSyntax) + { + var immutableListInterfaceType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("System.Collections.Immutable.IImmutableList`1"); + + if (returnType.ConstructedFrom != immutableListInterfaceType) + { + returnValueSyntax = null; + return false; + } + + var immutableListType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("System.Collections.Immutable.ImmutableList"); + + if (immutableListType == null) + { + context + .LogSink + .Warn(logSource, "Failed to resolve ImmutableList class."); + returnValueSyntax = null; + return false; + } + + returnValueSyntax = context + .SyntaxGenerator + .MemberAccessExpression( + context + .SyntaxGenerator + .WithTypeArguments( + context + .SyntaxGenerator + .TypeExpression(immutableListType), + context + .SyntaxGenerator + .TypeExpression(returnType.TypeArguments[0])), + "Empty"); + return true; + } + + private static bool TryGetReturnValueSyntaxForImmutableDictionaryReturnType( + Context context, + INamedTypeSymbol returnType, + out SyntaxNode returnValueSyntax) + { + var immutableDictionaryInterfaceType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("System.Collections.Immutable.IImmutableDictionary`2"); + + if (returnType.ConstructedFrom != immutableDictionaryInterfaceType) + { + returnValueSyntax = null; + return false; + } + + var immutableDictionaryType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("System.Collections.Immutable.ImmutableDictionary"); + + if (immutableDictionaryType == null) + { + context + .LogSink + .Warn(logSource, "Failed to resolve ImmutableDictionary class."); + returnValueSyntax = null; + return false; + } + + returnValueSyntax = context + .SyntaxGenerator + .MemberAccessExpression( + context + .SyntaxGenerator + .WithTypeArguments( + context + .SyntaxGenerator + .TypeExpression(immutableDictionaryType), + context + .SyntaxGenerator + .TypeExpression(returnType.TypeArguments[0]), + context + .SyntaxGenerator + .TypeExpression(returnType.TypeArguments[1])), + "Empty"); + return true; + } + + private static bool TryGetReturnValueSyntaxForImmutableQueueReturnType( + Context context, + INamedTypeSymbol returnType, + out SyntaxNode returnValueSyntax) + { + var immutableQueueInterfaceType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("System.Collections.Immutable.IImmutableQueue`1"); + + if (returnType.ConstructedFrom != immutableQueueInterfaceType) + { + returnValueSyntax = null; + return false; + } + + var immutableQueueType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("System.Collections.Immutable.ImmutableQueue"); + + if (immutableQueueType == null) + { + context + .LogSink + .Warn(logSource, "Failed to resolve ImmutableQueue class."); + returnValueSyntax = null; + return false; + } + + returnValueSyntax = context + .SyntaxGenerator + .MemberAccessExpression( + context + .SyntaxGenerator + .WithTypeArguments( + context + .SyntaxGenerator + .TypeExpression(immutableQueueType), + context + .SyntaxGenerator + .TypeExpression(returnType.TypeArguments[0])), + "Empty"); + return true; + } + + private static bool TryGetReturnValueSyntaxForImmutableSetReturnType( + Context context, + INamedTypeSymbol returnType, + out SyntaxNode returnValueSyntax) + { + var immutableSetInterfaceType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("System.Collections.Immutable.IImmutableSet`1"); + + if (returnType.ConstructedFrom != immutableSetInterfaceType) + { + returnValueSyntax = null; + return false; + } + + var immutableSetType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("System.Collections.Immutable.ImmutableHashSet"); + + if (immutableSetType == null) + { + context + .LogSink + .Warn(logSource, "Failed to resolve ImmutableSet class."); + returnValueSyntax = null; + return false; + } + + returnValueSyntax = context + .SyntaxGenerator + .MemberAccessExpression( + context + .SyntaxGenerator + .WithTypeArguments( + context + .SyntaxGenerator + .TypeExpression(immutableSetType), + context + .SyntaxGenerator + .TypeExpression(returnType.TypeArguments[0])), + "Empty"); + return true; + } + + private static bool TryGetReturnValueSyntaxForImmutableStackReturnType( + Context context, + INamedTypeSymbol returnType, + out SyntaxNode returnValueSyntax) + { + var immutableStackInterfaceType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("System.Collections.Immutable.IImmutableStack`1"); + + if (returnType.ConstructedFrom != immutableStackInterfaceType) + { + returnValueSyntax = null; + return false; + } + + var immutableStackType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("System.Collections.Immutable.ImmutableStack"); + + if (immutableStackType == null) + { + context + .LogSink + .Warn(logSource, "Failed to resolve ImmutableStack class."); + returnValueSyntax = null; + return false; + } + + returnValueSyntax = context + .SyntaxGenerator + .MemberAccessExpression( + context + .SyntaxGenerator + .WithTypeArguments( + context + .SyntaxGenerator + .TypeExpression(immutableStackType), + context + .SyntaxGenerator + .TypeExpression(returnType.TypeArguments[0])), + "Empty"); + return true; + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Plugins/Disposables.cs b/Src/PCLMock.CodeGeneration_OLD/Plugins/Disposables.cs new file mode 100644 index 0000000..56e9f54 --- /dev/null +++ b/Src/PCLMock.CodeGeneration_OLD/Plugins/Disposables.cs @@ -0,0 +1,93 @@ +namespace PCLMock.CodeGeneration.Plugins +{ + using System; + using System.Reactive.Disposables; + using Logging; + using Microsoft.CodeAnalysis; + + /// + /// A plugin that generates appropriate default return values for any member that returns . + /// + /// + /// + /// This plugin generates return specifications for any member returning . The returned + /// value is an instance of System.Reactive.Disposables.Disposable.Empty. Since the Disposable type + /// is defined by Reactive Extensions, the target code must have a reference in order for the specification to be + /// generated. + /// + /// + /// Members for which specifications cannot be generated are ignored. This of course includes members that do not + /// return , but also set-only properties, generic methods, and any members that return + /// custom disposable subtypes. + /// + /// + public sealed class Disposables : IPlugin + { + private static readonly Type logSource = typeof(Disposables); + + public string Name => "Disposables"; + + /// + public Compilation InitializeCompilation(Compilation compilation) => + compilation.AddReferences(MetadataReference.CreateFromFile(typeof(Disposable).Assembly.Location)); + + /// + public SyntaxNode GetDefaultValueSyntax( + Context context, + MockBehavior behavior, + ISymbol symbol, + INamedTypeSymbol returnType) + { + if (behavior == MockBehavior.Loose) + { + return null; + } + + var disposableInterfaceType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("System.IDisposable"); + + if (disposableInterfaceType == null) + { + context + .LogSink + .Warn(logSource, "Failed to resolve IDisposable type."); + return null; + } + + if (returnType != disposableInterfaceType) + { + context + .LogSink + .Debug(logSource, "Ignoring symbol '{0}' because its return type is not IDisposable."); + return null; + } + + var disposableType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("System.Reactive.Disposables.Disposable"); + + if (disposableType == null) + { + context + .LogSink + .Debug(logSource, "Ignoring symbol '{0}' because Disposable type could not be resolved (probably a missing reference to System.Reactive.Core)."); + return null; + } + + var result = context + .SyntaxGenerator + .MemberAccessExpression( + context + .SyntaxGenerator + .TypeExpression(disposableType), + context + .SyntaxGenerator + .IdentifierName("Empty")); + + return result; + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Plugins/ObservableBasedAsynchrony.cs b/Src/PCLMock.CodeGeneration_OLD/Plugins/ObservableBasedAsynchrony.cs new file mode 100644 index 0000000..7fcd868 --- /dev/null +++ b/Src/PCLMock.CodeGeneration_OLD/Plugins/ObservableBasedAsynchrony.cs @@ -0,0 +1,172 @@ +namespace PCLMock.CodeGeneration.Plugins +{ + using System; + using System.Linq; + using System.Reactive.Linq; + using Logging; + using Microsoft.CodeAnalysis; + + /// + /// A plugin that generates appropriate default return values for any member that uses observable-based + /// asynchrony. + /// + /// + /// + /// This plugin generates default return specifications for properties and methods that use observable-based asynchrony. + /// That is, they return an object of type . For such members, a specification is generated + /// such that an actual observable will be returned rather than returning . + /// + /// + /// The observable returned depends on the member type. For properties, an empty observable is returned (i.e. + /// Observable.Empty<T>. For methods, an observable with a single default item is returned (i.e. + /// Observable.Return<T>(default(T)). + /// + /// + /// The idea of these defaults is to best-guess the semantics of the observable. Typically, observables returned from + /// methods represent asynchronous operations, so the returned value represents the result of that operation. Observables + /// returned by properties, on the other hand, will typically have collection semantics. That is, they represent zero or + /// more asynchronously-received items. + /// + /// + /// Members for which specifications cannot be generated are ignored. This of course includes members that do not use + /// observable-based asynchrony, but also set-only properties, generic methods, and any members that return custom + /// subtypes. + /// + /// + public sealed class ObservableBasedAsynchrony : IPlugin + { + private static readonly Type logSource = typeof(ObservableBasedAsynchrony); + + public string Name => "Observable-based Asynchrony"; + + /// + public Compilation InitializeCompilation(Compilation compilation) => + compilation.AddReferences(MetadataReference.CreateFromFile(typeof(Observable).Assembly.Location)); + + /// + public SyntaxNode GetDefaultValueSyntax( + Context context, + MockBehavior behavior, + ISymbol symbol, + INamedTypeSymbol returnType) + { + if (behavior == MockBehavior.Loose) + { + return null; + } + + var observableInterfaceType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("System.IObservable`1"); + + var observableType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("System.Reactive.Linq.Observable"); + + if (observableInterfaceType == null) + { + context + .LogSink + .Warn(logSource, "Failed to resolve System.IObservable."); + return null; + } + + if (observableType == null) + { + context + .LogSink + .Warn(logSource, "Failed to resolve System.Reactive.Linq.Observable."); + return null; + } + + var isObservable = returnType.IsGenericType && returnType.ConstructedFrom == observableInterfaceType; + + if (!isObservable) + { + context + .LogSink + .Debug(logSource, "Ignoring symbol '{0}' because it does not return IObservable.", symbol); + return null; + } + + var observableInnerType = returnType.TypeArguments[0]; + SyntaxNode observableInvocation; + var propertySymbol = symbol as IPropertySymbol; + + if (propertySymbol != null) + { + // properties are given collection semantics by returning Observable.Empty() + observableInvocation = context + .SyntaxGenerator + .InvocationExpression( + context + .SyntaxGenerator + .WithTypeArguments( + context + .SyntaxGenerator + .MemberAccessExpression( + context + .SyntaxGenerator + .TypeExpression(observableType), + "Empty"), + context + .SyntaxGenerator + .TypeExpression(observableInnerType))); + } + else + { + // methods are given async operation semantics by returning Observable.Return(...) + observableInvocation = context + .SyntaxGenerator + .InvocationExpression( + context + .SyntaxGenerator + .WithTypeArguments( + context + .SyntaxGenerator + .MemberAccessExpression( + context + .SyntaxGenerator + .TypeExpression(observableType), + "Return"), + context + .SyntaxGenerator + .TypeExpression(observableInnerType)), + arguments: new[] + { + GetDefaultRecursive(context, behavior, symbol, observableInnerType) + }); + } + + return observableInvocation; + } + + private static SyntaxNode GetDefaultRecursive( + Context context, + MockBehavior behavior, + ISymbol symbol, + ITypeSymbol returnType) + { + var namedTypeSymbol = returnType as INamedTypeSymbol; + + if (namedTypeSymbol != null) + { + var recursiveDefault = context + .Plugins + .Select(plugin => plugin.GetDefaultValueSyntax(context, behavior, symbol, namedTypeSymbol)) + .Where(defaultValueSyntax => defaultValueSyntax != null) + .FirstOrDefault(); + + if (recursiveDefault != null) + { + return recursiveDefault; + } + } + + // recursive resolution not possible, so fallback to default(T) + return context.SyntaxGenerator.DefaultExpression(returnType); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Plugins/TaskBasedAsynchrony.cs b/Src/PCLMock.CodeGeneration_OLD/Plugins/TaskBasedAsynchrony.cs new file mode 100644 index 0000000..bc71e23 --- /dev/null +++ b/Src/PCLMock.CodeGeneration_OLD/Plugins/TaskBasedAsynchrony.cs @@ -0,0 +1,141 @@ +namespace PCLMock.CodeGeneration.Plugins +{ + using System; + using System.Linq; + using Logging; + using Microsoft.CodeAnalysis; + + /// + /// A plugin that generates appropriate default return values for any member that uses TPL-based + /// asynchrony. + /// + /// + /// + /// This plugin generates default return specifications for properties and methods that use TPL-based asynchrony. + /// SThat is, they return an object of type or + /// . In either case, a specification is generated for the member + /// such that a task with a default value will be returned rather than returning . + /// + /// + /// For members that return non-generic tasks, the specification will return Task.FromResult(false). For + /// members that return generic tasks, the specification will return Task.FromResult(default(T)) where + /// T is the task's result type. + /// + /// + /// Members for which specifications cannot be generated are ignored. This of course includes members that do not use + /// TPL-based asynchrony, but also set-only properties, generic methods, and any members that return custom + /// subclasses. + /// + /// + public sealed class TaskBasedAsynchrony : IPlugin + { + private static readonly Type logSource = typeof(TaskBasedAsynchrony); + + public string Name => "Task-based Asynchrony"; + + /// + public Compilation InitializeCompilation(Compilation compilation) => + compilation; + + /// + public SyntaxNode GetDefaultValueSyntax( + Context context, + MockBehavior behavior, + ISymbol symbol, + INamedTypeSymbol returnType) + { + if (behavior == MockBehavior.Loose) + { + return null; + } + + var taskBaseType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("System.Threading.Tasks.Task"); + + var genericTaskBaseType = context + .SemanticModel + .Compilation + .GetTypeByMetadataName("System.Threading.Tasks.Task`1"); + + if (taskBaseType == null || genericTaskBaseType == null) + { + context + .LogSink + .Warn(logSource, "Failed to resolve Task classes."); + return null; + } + + var isGenericTask = returnType.IsGenericType && returnType.ConstructedFrom == genericTaskBaseType; + var isTask = returnType == taskBaseType; + + if (!isTask && !isGenericTask) + { + context + .LogSink + .Debug(logSource, "Ignoring symbol '{0}' because it does not return a Task or Task.", symbol); + return null; + } + + ITypeSymbol taskType = context + .SemanticModel + .Compilation + .GetSpecialType(SpecialType.System_Boolean); + + if (isGenericTask) + { + taskType = returnType.TypeArguments[0]; + } + + var fromResultInvocation = context + .SyntaxGenerator + .InvocationExpression( + context + .SyntaxGenerator + .WithTypeArguments( + context + .SyntaxGenerator + .MemberAccessExpression( + context + .SyntaxGenerator + .TypeExpression(taskBaseType), + "FromResult"), + context + .SyntaxGenerator + .TypeExpression(taskType)), + arguments: new[] + { + GetDefaultRecursive(context, behavior, symbol, taskType) + }); + + return fromResultInvocation; + } + + private static SyntaxNode GetDefaultRecursive( + Context context, + MockBehavior behavior, + ISymbol symbol, + ITypeSymbol returnType) + { + var namedTypeSymbol = returnType as INamedTypeSymbol; + + if (namedTypeSymbol != null) + { + var recursiveDefault = context + .Plugins + .Select(plugin => plugin.GetDefaultValueSyntax(context, behavior, symbol, namedTypeSymbol)) + .Where(defaultValueSyntax => defaultValueSyntax != null) + .FirstOrDefault(); + + if (recursiveDefault != null) + { + return recursiveDefault; + } + } + + // recursive resolution not possible, so fallback to default(T) + return context.SyntaxGenerator.DefaultExpression(returnType); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Properties/AssemblyInfo.cs b/Src/PCLMock.CodeGeneration_OLD/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..1dbe046 --- /dev/null +++ b/Src/PCLMock.CodeGeneration_OLD/Properties/AssemblyInfo.cs @@ -0,0 +1,8 @@ +using System; +using System.Reflection; +using System.Runtime.CompilerServices; + +[assembly: AssemblyTitle("PCLMock.CodeGeneration")] +[assembly: AssemblyDescription("Contains code generation logic for PCLMock.")] +[assembly: InternalsVisibleTo("PCLMock.CodeGeneration")] +[assembly: CLSCompliantAttribute(false)] \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/SyntaxGeneratorExtensions.cs b/Src/PCLMock.CodeGeneration_OLD/SyntaxGeneratorExtensions.cs new file mode 100644 index 0000000..7769c66 --- /dev/null +++ b/Src/PCLMock.CodeGeneration_OLD/SyntaxGeneratorExtensions.cs @@ -0,0 +1,45 @@ +namespace PCLMock.CodeGeneration +{ + using System; + using System.Linq; + using System.Text; + using Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.CSharp; + using Microsoft.CodeAnalysis.CSharp.Syntax; + using Microsoft.CodeAnalysis.Editing; + using VB = Microsoft.CodeAnalysis.VisualBasic; + using VBSyntax = Microsoft.CodeAnalysis.VisualBasic.Syntax; + + // stuff that isn't on SyntaxGenerator that probably should be + // might PR some of this stuff back to Roslyn at some point + internal static class SyntaxGeneratorExtensions + { + public static SyntaxNode TypeOf(this SyntaxGenerator @this, SyntaxNode type, Language language) + { + switch (language) + { + case Language.CSharp: + return SyntaxFactory.TypeOfExpression((TypeSyntax)type); + case Language.VisualBasic: + return VB.SyntaxFactory.GetTypeExpression((VBSyntax.TypeSyntax)type); + default: + throw new NotSupportedException(); + } + } + + public static SyntaxNode WithLeadingComments(this SyntaxGenerator @this, SyntaxNode node, string comments, Language language) + { + comments = comments + .Split(new[] { "\r\n", "\n", "\r" }, StringSplitOptions.None) + .Select(x => language == Language.CSharp ? "// " + x : "' " + x) + .Aggregate(new StringBuilder(), (sb, next) => sb.AppendLine(next), x => x.ToString()); + + node = node.WithLeadingTrivia( + language == Language.CSharp + ? SyntaxFactory.ParseLeadingTrivia(comments) + : VB.SyntaxFactory.ParseLeadingTrivia(comments)); + + return node; + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/XmlBasedGenerator.cs b/Src/PCLMock.CodeGeneration_OLD/XmlBasedGenerator.cs new file mode 100644 index 0000000..350c612 --- /dev/null +++ b/Src/PCLMock.CodeGeneration_OLD/XmlBasedGenerator.cs @@ -0,0 +1,68 @@ +namespace PCLMock.CodeGeneration +{ + using System; + using System.Collections.Immutable; + using System.IO; + using System.Linq; + using System.Text; + using System.Threading.Tasks; + using System.Xml.Linq; + using Logging; + using Microsoft.CodeAnalysis; + using PCLMock.CodeGeneration.Models; + + public static class XmlBasedGenerator + { + private static readonly Type logSource = typeof(XmlBasedGenerator); + + public static string GenerateMocks( + ILogSink logSink, + string solutionPath, + string xmlPath, + string language) + { + var castLanguage = (Language)Enum.Parse(typeof(Language), language); + return GenerateMocks(logSink, castLanguage, solutionPath, xmlPath); + } + + public static string GenerateMocks( + ILogSink logSink, + Language language, + string solutionPath, + string xmlPath) + { + return GenerateMocksAsync(logSink, language, solutionPath, xmlPath) + .Result + .Select(x => x.ToFullString()) + .Aggregate(new StringBuilder(), (current, next) => current.AppendLine(next), x => x.ToString()); + } + + public async static Task> GenerateMocksAsync( + ILogSink logSink, + Language language, + string solutionPath, + string xmlPath) + { + if (!File.Exists(xmlPath)) + { + var message = $"XML input file '{xmlPath}' no found."; + logSink.Error(logSource, message); + throw new IOException(message); + } + + logSink.Info(logSource, "Loading XML input file '{0}'.", xmlPath); + + var document = XDocument.Load(xmlPath); + var configuration = Configuration.FromXDocument(logSink, document); + + return await Generator.GenerateMocksAsync( + logSink, + language, + solutionPath, + configuration.GetInterfacePredicate(), + configuration.GetNamespaceSelector(), + configuration.GetNameSelector(), + configuration.GetPlugins()); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration/app.config b/Src/PCLMock.CodeGeneration_OLD/app.config similarity index 100% rename from Src/PCLMock.CodeGeneration/app.config rename to Src/PCLMock.CodeGeneration_OLD/app.config diff --git a/Src/PCLMock.CodeGeneration/packages.config b/Src/PCLMock.CodeGeneration_OLD/packages.config similarity index 100% rename from Src/PCLMock.CodeGeneration/packages.config rename to Src/PCLMock.CodeGeneration_OLD/packages.config diff --git a/Src/PCLMock.sln b/Src/PCLMock.sln index d5776ed..1a40a64 100644 --- a/Src/PCLMock.sln +++ b/Src/PCLMock.sln @@ -1,10 +1,8 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25123.0 +# Visual Studio 15 +VisualStudioVersion = 15.0.26228.9 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PCLMock", "PCLMock\PCLMock.csproj", "{A02C0394-4DAD-4422-97BB-4A90D89CEE66}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PCLMock.UnitTests", "PCLMock.UnitTests\PCLMock.UnitTests.csproj", "{05115055-0BBC-49D5-8966-2B90325F2F08}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".build", ".build", "{A1B3C179-EFB2-437F-A9FF-16BD29DE2292}" @@ -13,30 +11,24 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".build", ".build", "{A1B3C1 ..\build.fsx = ..\build.fsx EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PCLMock.CodeGeneration", "PCLMock.CodeGeneration\PCLMock.CodeGeneration.csproj", "{6E077796-0241-4191-A866-0EA52B9BD946}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PCLMock.CodeGeneration.T4", "PCLMock.CodeGeneration.T4\PCLMock.CodeGeneration.T4.csproj", "{F482A52C-3D60-429D-9152-3FFB5D35CBFF}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PCLMock.CodeGeneration.Console", "PCLMock.CodeGeneration.Console\PCLMock.CodeGeneration.Console.csproj", "{B56824C1-B58E-42FB-A528-518638A7DA15}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PCLMock.CodeGeneration", "PCLMock.CodeGeneration\PCLMock.CodeGeneration.csproj", "{49C812A9-5C76-4567-947F-B21A38FE4EC1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PCLMock", "PCLMock\PCLMock.csproj", "{2F34337F-05B9-4B38-A072-46409A3B2ACE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {A02C0394-4DAD-4422-97BB-4A90D89CEE66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A02C0394-4DAD-4422-97BB-4A90D89CEE66}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A02C0394-4DAD-4422-97BB-4A90D89CEE66}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A02C0394-4DAD-4422-97BB-4A90D89CEE66}.Release|Any CPU.Build.0 = Release|Any CPU {05115055-0BBC-49D5-8966-2B90325F2F08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {05115055-0BBC-49D5-8966-2B90325F2F08}.Debug|Any CPU.Build.0 = Debug|Any CPU {05115055-0BBC-49D5-8966-2B90325F2F08}.Release|Any CPU.ActiveCfg = Release|Any CPU {05115055-0BBC-49D5-8966-2B90325F2F08}.Release|Any CPU.Build.0 = Release|Any CPU - {6E077796-0241-4191-A866-0EA52B9BD946}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6E077796-0241-4191-A866-0EA52B9BD946}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6E077796-0241-4191-A866-0EA52B9BD946}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6E077796-0241-4191-A866-0EA52B9BD946}.Release|Any CPU.Build.0 = Release|Any CPU {F482A52C-3D60-429D-9152-3FFB5D35CBFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {F482A52C-3D60-429D-9152-3FFB5D35CBFF}.Debug|Any CPU.Build.0 = Debug|Any CPU {F482A52C-3D60-429D-9152-3FFB5D35CBFF}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -45,6 +37,14 @@ Global {B56824C1-B58E-42FB-A528-518638A7DA15}.Debug|Any CPU.Build.0 = Debug|Any CPU {B56824C1-B58E-42FB-A528-518638A7DA15}.Release|Any CPU.ActiveCfg = Release|Any CPU {B56824C1-B58E-42FB-A528-518638A7DA15}.Release|Any CPU.Build.0 = Release|Any CPU + {49C812A9-5C76-4567-947F-B21A38FE4EC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {49C812A9-5C76-4567-947F-B21A38FE4EC1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {49C812A9-5C76-4567-947F-B21A38FE4EC1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {49C812A9-5C76-4567-947F-B21A38FE4EC1}.Release|Any CPU.Build.0 = Release|Any CPU + {2F34337F-05B9-4B38-A072-46409A3B2ACE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2F34337F-05B9-4B38-A072-46409A3B2ACE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2F34337F-05B9-4B38-A072-46409A3B2ACE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2F34337F-05B9-4B38-A072-46409A3B2ACE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Src/PCLMock/PCLMock.csproj b/Src/PCLMock/PCLMock.csproj index 3216692..aac5c3a 100644 --- a/Src/PCLMock/PCLMock.csproj +++ b/Src/PCLMock/PCLMock.csproj @@ -1,85 +1,8 @@ - - - + + - 10.0 - Debug - AnyCPU - {A02C0394-4DAD-4422-97BB-4A90D89CEE66} - Library - Properties - PCLMock - PCLMock - v4.0 - Profile336 - 512 - {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + netstandard1.0 + false - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - bin\Debug\PCLMock.xml - true - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - bin\Release\PCLMock.xml - true - - - - - - - - - - - - - - - - Properties\AssemblyInfoCommon.cs - - - - - - - - - - - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/Src/PCLMock_OLD/ArgumentFilters/IsAnyArgumentFilter.cs b/Src/PCLMock_OLD/ArgumentFilters/IsAnyArgumentFilter.cs new file mode 100644 index 0000000..2c33dfe --- /dev/null +++ b/Src/PCLMock_OLD/ArgumentFilters/IsAnyArgumentFilter.cs @@ -0,0 +1,44 @@ +namespace PCLMock.ArgumentFilters +{ + using System; + using PCLMock.Utility; + + internal sealed class IsAnyArgumentFilter : IArgumentFilter, IEquatable> + { + public static readonly IsAnyArgumentFilter Instance = new IsAnyArgumentFilter(); + + private IsAnyArgumentFilter() + { + } + + public bool Matches(object argument) + { + return true; + } + + public override string ToString() + { + return "It.IsAny<" + typeof(T).ToDebugString() + ">()"; + } + + public bool Equals(IsAnyArgumentFilter other) + { + if (other == null) + { + return false; + } + + return true; + } + + public override bool Equals(object obj) + { + return this.Equals(obj as IsAnyArgumentFilter); + } + + public override int GetHashCode() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock_OLD/ArgumentFilters/IsArgumentFilter.cs b/Src/PCLMock_OLD/ArgumentFilters/IsArgumentFilter.cs new file mode 100644 index 0000000..86d38bb --- /dev/null +++ b/Src/PCLMock_OLD/ArgumentFilters/IsArgumentFilter.cs @@ -0,0 +1,45 @@ +namespace PCLMock.ArgumentFilters +{ + using System; + using PCLMock.Utility; + + internal sealed class IsArgumentFilter : IArgumentFilter, IEquatable + { + private readonly object expected; + + public IsArgumentFilter(object expected) + { + this.expected = expected; + } + + public bool Matches(object argument) + { + return object.Equals(argument, this.expected); + } + + public override string ToString() + { + return "It.Is(" + this.expected.ToDebugString() + ")"; + } + + public bool Equals(IsArgumentFilter other) + { + if (other == null) + { + return false; + } + + return this.Matches(other.expected); + } + + public override bool Equals(object obj) + { + return this.Equals(obj as IsArgumentFilter); + } + + public override int GetHashCode() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock_OLD/ArgumentFilters/IsBetweenArgumentFilter.cs b/Src/PCLMock_OLD/ArgumentFilters/IsBetweenArgumentFilter.cs new file mode 100644 index 0000000..634af32 --- /dev/null +++ b/Src/PCLMock_OLD/ArgumentFilters/IsBetweenArgumentFilter.cs @@ -0,0 +1,66 @@ +namespace PCLMock.ArgumentFilters +{ + using System; + using System.Collections.Generic; + using PCLMock.Utility; + + internal sealed class IsBetweenArgumentFilter : IArgumentFilter, IEquatable> + where T : IComparable + { + private readonly T minimum; + private readonly T maximum; + + public IsBetweenArgumentFilter(T minimum, T maximum) + { + this.minimum = minimum; + this.maximum = maximum; + + // to make our job easier below, we ensure that we can rely on knowing the lower end of the range versus the upper + if (Comparer.Default.Compare(this.minimum, this.maximum) > 0) + { + this.minimum = maximum; + this.maximum = minimum; + } + } + + public bool Matches(object argument) + { + if (argument != null && !(argument is T)) + { + // shouldn't happen + return false; + } + + return + Comparer.Default.Compare((T)argument, this.minimum) >= 0 && + Comparer.Default.Compare((T)argument, this.maximum) <= 0; + } + + public override string ToString() + { + return "It.IsBetween(" + this.minimum.ToDebugString() + ", " + this.maximum.ToDebugString() + ")"; + } + + public bool Equals(IsBetweenArgumentFilter other) + { + if (other == null) + { + return false; + } + + return + Comparer.Default.Compare(this.minimum, other.minimum) == 0 && + Comparer.Default.Compare(this.maximum, other.maximum) == 0; + } + + public override bool Equals(object obj) + { + return this.Equals(obj as IsBetweenArgumentFilter); + } + + public override int GetHashCode() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock_OLD/ArgumentFilters/IsGreaterThanArgumentFilter.cs b/Src/PCLMock_OLD/ArgumentFilters/IsGreaterThanArgumentFilter.cs new file mode 100644 index 0000000..a008e8e --- /dev/null +++ b/Src/PCLMock_OLD/ArgumentFilters/IsGreaterThanArgumentFilter.cs @@ -0,0 +1,53 @@ +namespace PCLMock.ArgumentFilters +{ + using System; + using System.Collections.Generic; + using PCLMock.Utility; + + internal sealed class IsGreaterThanArgumentFilter : IArgumentFilter, IEquatable> + where T : IComparable + { + private readonly T value; + + public IsGreaterThanArgumentFilter(T value) + { + this.value = value; + } + + public bool Matches(object argument) + { + if (argument != null && !(argument is T)) + { + // shouldn't happen + return false; + } + + return Comparer.Default.Compare((T)argument, this.value) > 0; + } + + public override string ToString() + { + return "It.IsGreaterThan(" + this.value.ToDebugString() + ")"; + } + + public bool Equals(IsGreaterThanArgumentFilter other) + { + if (other == null) + { + return false; + } + + return Comparer.Default.Compare(this.value, other.value) == 0; + } + + public override bool Equals(object obj) + { + return this.Equals(obj as IsGreaterThanArgumentFilter); + } + + public override int GetHashCode() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock_OLD/ArgumentFilters/IsGreaterThanOrEqualToArgumentFilter.cs b/Src/PCLMock_OLD/ArgumentFilters/IsGreaterThanOrEqualToArgumentFilter.cs new file mode 100644 index 0000000..ea6dbac --- /dev/null +++ b/Src/PCLMock_OLD/ArgumentFilters/IsGreaterThanOrEqualToArgumentFilter.cs @@ -0,0 +1,53 @@ +namespace PCLMock.ArgumentFilters +{ + using System; + using System.Collections.Generic; + using PCLMock.Utility; + + internal sealed class IsGreaterThanOrEqualToArgumentFilter : IArgumentFilter, IEquatable> + where T : IComparable + { + private readonly T value; + + public IsGreaterThanOrEqualToArgumentFilter(T value) + { + this.value = value; + } + + public bool Matches(object argument) + { + if (argument != null && !(argument is T)) + { + // shouldn't happen + return false; + } + + return Comparer.Default.Compare((T)argument, this.value) >= 0; + } + + public override string ToString() + { + return "It.IsGreaterThanOrEqualTo(" + this.value.ToDebugString() + ")"; + } + + public bool Equals(IsGreaterThanOrEqualToArgumentFilter other) + { + if (other == null) + { + return false; + } + + return Comparer.Default.Compare(this.value, other.value) == 0; + } + + public override bool Equals(object obj) + { + return this.Equals(obj as IsGreaterThanOrEqualToArgumentFilter); + } + + public override int GetHashCode() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock_OLD/ArgumentFilters/IsInArgumentFilter.cs b/Src/PCLMock_OLD/ArgumentFilters/IsInArgumentFilter.cs new file mode 100644 index 0000000..cd2dbbd --- /dev/null +++ b/Src/PCLMock_OLD/ArgumentFilters/IsInArgumentFilter.cs @@ -0,0 +1,79 @@ +namespace PCLMock.ArgumentFilters +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + using PCLMock.Utility; + + internal sealed class IsInArgumentFilter : IArgumentFilter, IEquatable> + { + private readonly ISet expected; + + public IsInArgumentFilter(params T[] expected) + { + this.expected = new HashSet(expected ?? new T[0]); + } + + public bool Matches(object argument) + { + if (argument != null && !(argument is T)) + { + // shouldn't happen + return false; + } + + return this.expected.Contains((T)argument); + } + + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("It.IsIn("); + var first = true; + + this.expected.Aggregate( + sb, + (running, next) => + { + if (!first) + { + sb.Append(", "); + } + + first = false; + sb.Append(next.ToDebugString()); + return sb; + }); + + sb.Append(")"); + + return sb.ToString(); + } + + public bool Equals(IsInArgumentFilter other) + { + if (other == null) + { + return false; + } + + if (this.expected.Count != other.expected.Count) + { + return false; + } + + return this.expected.IsSubsetOf(other.expected); + } + + public override bool Equals(object obj) + { + return this.Equals(obj as IsInArgumentFilter); + } + + public override int GetHashCode() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock_OLD/ArgumentFilters/IsLikeArgumentFilter.cs b/Src/PCLMock_OLD/ArgumentFilters/IsLikeArgumentFilter.cs new file mode 100644 index 0000000..7a87b7d --- /dev/null +++ b/Src/PCLMock_OLD/ArgumentFilters/IsLikeArgumentFilter.cs @@ -0,0 +1,56 @@ +namespace PCLMock.ArgumentFilters +{ + using System; + using System.Diagnostics; + using System.Text.RegularExpressions; + using PCLMock.Utility; + + internal sealed class IsLikeArgumentFilter : IArgumentFilter, IEquatable + { + private readonly Regex expression; + + public IsLikeArgumentFilter(string pattern, RegexOptions options) + { + Debug.Assert(pattern != null); + this.expression = new Regex(pattern, options); + } + + public bool Matches(object argument) + { + if (argument == null || !(argument is string)) + { + return false; + } + + return this.expression.IsMatch((string)argument); + } + + public override string ToString() + { + return "It.IsLike(" + this.expression.ToString().ToDebugString() + ")"; + } + + public bool Equals(IsLikeArgumentFilter other) + { + if (other == null) + { + return false; + } + + return + this.expression.Options == other.expression.Options && + string.Equals(this.expression.ToString(), other.expression.ToString(), StringComparison.Ordinal); + } + + public override bool Equals(object obj) + { + return this.Equals(obj as IsLikeArgumentFilter); + } + + public override int GetHashCode() + { + throw new NotImplementedException(); + } + } + +} diff --git a/Src/PCLMock_OLD/ArgumentFilters/IsNullArgumentFilter.cs b/Src/PCLMock_OLD/ArgumentFilters/IsNullArgumentFilter.cs new file mode 100644 index 0000000..2074b79 --- /dev/null +++ b/Src/PCLMock_OLD/ArgumentFilters/IsNullArgumentFilter.cs @@ -0,0 +1,44 @@ +namespace PCLMock.ArgumentFilters +{ + using System; + using PCLMock.Utility; + + internal sealed class IsNullArgumentFilter : IArgumentFilter, IEquatable> + { + public static readonly IsNullArgumentFilter Instance = new IsNullArgumentFilter(); + + private IsNullArgumentFilter() + { + } + + public bool Matches(object argument) + { + return argument == null; + } + + public override string ToString() + { + return "It.IsNull<" + typeof(T).ToDebugString() + ">()"; + } + + public bool Equals(IsNullArgumentFilter other) + { + if (other == null) + { + return false; + } + + return true; + } + + public override bool Equals(object obj) + { + return this.Equals(obj as IsNullArgumentFilter); + } + + public override int GetHashCode() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock_OLD/ArgumentFilters/IsOfTypeArgumentFilter.cs b/Src/PCLMock_OLD/ArgumentFilters/IsOfTypeArgumentFilter.cs new file mode 100644 index 0000000..8238f58 --- /dev/null +++ b/Src/PCLMock_OLD/ArgumentFilters/IsOfTypeArgumentFilter.cs @@ -0,0 +1,44 @@ +namespace PCLMock.ArgumentFilters +{ + using System; + using PCLMock.Utility; + + internal sealed class IsOfTypeArgumentFilter : IArgumentFilter, IEquatable> + { + public static readonly IsOfTypeArgumentFilter Instance = new IsOfTypeArgumentFilter(); + + private IsOfTypeArgumentFilter() + { + } + + public bool Matches(object argument) + { + return argument is T; + } + + public override string ToString() + { + return "It.IsOfType<" + typeof(T).ToDebugString() + ">()"; + } + + public bool Equals(IsOfTypeArgumentFilter other) + { + if (other == null) + { + return false; + } + + return true; + } + + public override bool Equals(object obj) + { + return this.Equals(obj as IsOfTypeArgumentFilter); + } + + public override int GetHashCode() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock_OLD/ArgumentFilters/LogicalNotArgumentFilter.cs b/Src/PCLMock_OLD/ArgumentFilters/LogicalNotArgumentFilter.cs new file mode 100644 index 0000000..56392aa --- /dev/null +++ b/Src/PCLMock_OLD/ArgumentFilters/LogicalNotArgumentFilter.cs @@ -0,0 +1,47 @@ +namespace PCLMock.ArgumentFilters +{ + using System; + using System.Diagnostics; + using System.Globalization; + + internal sealed class LogicalNotArgumentFilter : IArgumentFilter, IEquatable + { + private readonly IArgumentFilter child; + + public LogicalNotArgumentFilter(IArgumentFilter child) + { + Debug.Assert(child != null); + this.child = child; + } + + public bool Matches(object argument) + { + return !this.child.Matches(argument); + } + + public override string ToString() + { + return string.Format(CultureInfo.InvariantCulture, "NOT({0})", this.child); + } + + public bool Equals(LogicalNotArgumentFilter other) + { + if (other == null) + { + return false; + } + + return this.child.Equals(other.child); + } + + public override bool Equals(object obj) + { + return this.Equals(obj as LogicalNotArgumentFilter); + } + + public override int GetHashCode() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock_OLD/ArgumentFilters/MatchesArgumentFilter.cs b/Src/PCLMock_OLD/ArgumentFilters/MatchesArgumentFilter.cs new file mode 100644 index 0000000..1223ced --- /dev/null +++ b/Src/PCLMock_OLD/ArgumentFilters/MatchesArgumentFilter.cs @@ -0,0 +1,54 @@ +namespace PCLMock.ArgumentFilters +{ + using System; + using System.Diagnostics; + using PCLMock.Utility; + + internal sealed class MatchesArgumentFilter : IArgumentFilter, IEquatable> + { + private readonly Func predicate; + + public MatchesArgumentFilter(Func predicate) + { + Debug.Assert(predicate != null); + + this.predicate = predicate; + } + + public bool Matches(object argument) + { + if (argument != null && !(argument is T)) + { + // shouldn't happen + return false; + } + + return this.predicate((T)argument); + } + + public override string ToString() + { + return "It.Matches<" + typeof(T).ToDebugString() + ">()"; + } + + public bool Equals(MatchesArgumentFilter other) + { + if (other == null) + { + return false; + } + + return this.predicate == other.predicate; + } + + public override bool Equals(object obj) + { + return this.Equals(obj as MatchesArgumentFilter); + } + + public override int GetHashCode() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock_OLD/IArgumentFilter.cs b/Src/PCLMock_OLD/IArgumentFilter.cs new file mode 100644 index 0000000..c893474 --- /dev/null +++ b/Src/PCLMock_OLD/IArgumentFilter.cs @@ -0,0 +1,7 @@ +namespace PCLMock +{ + internal interface IArgumentFilter + { + bool Matches(object argument); + } +} \ No newline at end of file diff --git a/Src/PCLMock_OLD/It.cs b/Src/PCLMock_OLD/It.cs new file mode 100644 index 0000000..3ea68e4 --- /dev/null +++ b/Src/PCLMock_OLD/It.cs @@ -0,0 +1,485 @@ +namespace PCLMock +{ + using System; + using System.Text.RegularExpressions; + using PCLMock.ArgumentFilters; + + /// + /// Facilitates the filtering of arguments when interacting with mocks. + /// + /// + /// + /// This class provides a number of methods that can be used to filter arguments in calls to or . + /// Consider the following example: + /// + /// + /// + /// + /// x.SomeMethod("abc", It.IsAny(), It.IsNotNull())) + /// .Return(50); + /// ]]> + /// + /// + /// + /// + /// In this case, the specification will only match if the first argument to SomeMethod is "abc" and the third argument is not . + /// The second argument can be anything. + /// + /// + /// Note that the implementation of all public methods is simply to return a default instance of T. The actual implementation is resolved and applied + /// at run-time. + /// + /// + public static class It + { + /// + /// Specifies that any object of type is valid. + /// + /// + /// The type of object. + /// + /// + /// A default instance of type T. + /// + public static T IsAny() + { + return default(T); + } + + /// + /// Specifies that only values that equate to are to be accepted. + /// + /// + /// The type of the expected value. + /// + /// + /// The expected value. + /// + /// + /// A default instance of type T. + /// + public static T Is(T expected) + { + return default(T); + } + + /// + /// Specifies that only values that do not equate to are to be accepted. + /// + /// + /// The type of the unexpected value. + /// + /// + /// The value that is not expected. + /// + /// + /// A default instance of type T. + /// + public static T IsNot(T notExpected) + { + return default(T); + } + + /// + /// Specifies that only values between and are to be accepted. + /// + /// + /// The type of the value. + /// + /// + /// An inclusive value representing one end of the range of values accepted. + /// + /// + /// An inclusive value representing the other end of the range of values accepted. + /// + /// + /// A default instance of type T. + /// + public static T IsBetween(T first, T second) + where T : IComparable + { + return default(T); + } + + /// + /// Specifies that only values not between and are to be accepted. + /// + /// + /// The type of the value. + /// + /// + /// An inclusive value representing one end of the range of values not accepted. + /// + /// + /// An inclusive value representing the other end of the range of values not accepted. + /// + /// + /// A default instance of type T. + /// + public static T IsNotBetween(T first, T second) + where T : IComparable + { + return default(T); + } + + /// + /// Specifies that only values greater than are to be accepted. + /// + /// + /// The type of the value. + /// + /// + /// The exclusive minimum expected value. + /// + /// + /// A default instance of type T. + /// + public static T IsGreaterThan(T value) + where T : IComparable + { + return default(T); + } + + /// + /// Specifies that only values less than are to be accepted. + /// + /// + /// The type of the value. + /// + /// + /// The exclusive maximum expected value. + /// + /// + /// A default instance of type T. + /// + public static T IsLessThan(T value) + where T : IComparable + { + return default(T); + } + + /// + /// Specifies that only values greater than or equal to are to be accepted. + /// + /// + /// The type of the value. + /// + /// + /// The inclusive minimum expected value. + /// + /// + /// A default instance of type T. + /// + public static T IsGreaterThanOrEqualTo(T value) + where T : IComparable + { + return default(T); + } + + /// + /// Specifies that only values less than or equal to are to be accepted. + /// + /// + /// The type of the value. + /// + /// + /// The inclusive maximum expected value. + /// + /// + /// A default instance of type T. + /// + public static T IsLessThanOrEqualTo(T value) + where T : IComparable + { + return default(T); + } + + /// + /// Specifies that only values that are within are to be accepted. + /// + /// + /// The type of the expected value. + /// + /// + /// The set of expected values. + /// + /// + /// A default instance of type T. + /// + public static T IsIn(params T[] expected) + { + return default(T); + } + + /// + /// Specifies that only values that are like (a regular expression) are to be accepted. + /// + /// + /// The regular expression pattern used to match values. + /// + /// + /// . + /// + public static string IsLike(string pattern) + { + return null; + } + + /// + /// Specifies that only values that are like (a regular expression) are to be accepted. + /// + /// + /// The regular expression pattern used to match values. + /// + /// + /// Optional options for the regular expression used when matching. + /// + /// + /// . + /// + public static string IsLike(string pattern, RegexOptions options = RegexOptions.None) + { + return null; + } + + /// + /// Specifies that only values that are not like (a regular expression) are to be accepted. + /// + /// + /// The regular expression pattern used to match values. + /// + /// + /// . + /// + public static string IsNotLike(string pattern) + { + return null; + } + + /// + /// Specifies that only values that are not like (a regular expression) are to be accepted. + /// + /// + /// The regular expression pattern used to match values. + /// + /// + /// Optional options for the regular expression used when matching. + /// + /// + /// . + /// + public static string IsNotLike(string pattern, RegexOptions options = RegexOptions.None) + { + return null; + } + + /// + /// Specifies that only values are to be accepted. + /// + /// + /// The type of the expected value. + /// + /// + /// A default instance of type T. + /// + public static T IsNull() + where T : class + { + return default(T); + } + + /// + /// Specifies that only non- values are to be accepted. + /// + /// + /// The type of the expected value. + /// + /// + /// A default instance of type T. + /// + public static T IsNotNull() + where T : class + { + return default(T); + } + + /// + /// Specifies that only values of type are to be accepted. + /// + /// + /// The expected type. + /// + /// + /// A default instance of type T. + /// + public static T IsOfType() + { + return default(T); + } + + /// + /// Specifies that only values not of type are to be accepted. + /// + /// + /// The unexpected type. + /// + /// + /// A default instance of type T. + /// + public static T IsNotOfType() + { + return default(T); + } + + /// + /// Specifies that only values for which the given predicate returns are to be accepted. + /// + /// + /// The type of the expected value. + /// + /// + /// The predicate that will be invoked to check the value. + /// + /// + /// A default instance of type T. + /// + public static T Matches(Func predicate) + { + return default(T); + } + + // the internal methods below must: + // 1. have the same name as their public counterpart above, but with a "Filter" suffix + // 2. return an implementation of IArgumentFilter that encapsulates the logic for the filter + + internal static IArgumentFilter IsAnyFilter() + { + return IsAnyArgumentFilter.Instance; + } + + internal static IArgumentFilter IsFilter(T expected) + { + return new IsArgumentFilter(expected); + } + + internal static IArgumentFilter IsNotFilter(T notExpected) + { + return new LogicalNotArgumentFilter(new IsArgumentFilter(notExpected)); + } + + internal static IArgumentFilter IsBetweenFilter(T first, T second) + where T : IComparable + { + return new IsBetweenArgumentFilter(first, second); + } + + internal static IArgumentFilter IsNotBetweenFilter(T first, T second) + where T : IComparable + { + return new LogicalNotArgumentFilter(new IsBetweenArgumentFilter(first, second)); + } + + internal static IArgumentFilter IsGreaterThanFilter(T value) + where T : IComparable + { + return new IsGreaterThanArgumentFilter(value); + } + + internal static IArgumentFilter IsLessThanFilter(T value) + where T : IComparable + { + return new LogicalNotArgumentFilter(new IsGreaterThanOrEqualToArgumentFilter(value)); + } + + internal static IArgumentFilter IsGreaterThanOrEqualToFilter(T value) + where T : IComparable + { + return new IsGreaterThanOrEqualToArgumentFilter(value); + } + + internal static IArgumentFilter IsLessThanOrEqualToFilter(T value) + where T : IComparable + { + return new LogicalNotArgumentFilter(new IsGreaterThanArgumentFilter(value)); + } + + internal static IArgumentFilter IsInFilter(params T[] expected) + { + return new IsInArgumentFilter(expected); + } + + internal static IArgumentFilter IsLikeFilter(string pattern) + { + if (pattern == null) + { + throw new ArgumentNullException("pattern"); + } + + return new IsLikeArgumentFilter(pattern, RegexOptions.None); + } + + internal static IArgumentFilter IsLikeFilter(string pattern, RegexOptions options) + { + if (pattern == null) + { + throw new ArgumentNullException("pattern"); + } + + return new IsLikeArgumentFilter(pattern, options); + } + + internal static IArgumentFilter IsNotLikeFilter(string pattern) + { + if (pattern == null) + { + throw new ArgumentNullException("pattern"); + } + + return new LogicalNotArgumentFilter(new IsLikeArgumentFilter(pattern, RegexOptions.None)); + } + + internal static IArgumentFilter IsNotLikeFilter(string pattern, RegexOptions options) + { + if (pattern == null) + { + throw new ArgumentNullException("pattern"); + } + + return new LogicalNotArgumentFilter(new IsLikeArgumentFilter(pattern, options)); + } + + internal static IArgumentFilter IsNullFilter() + where T : class + { + return IsNullArgumentFilter.Instance; + } + + internal static IArgumentFilter IsNotNullFilter() + where T : class + { + return new LogicalNotArgumentFilter(IsNullArgumentFilter.Instance); + } + + internal static IArgumentFilter IsOfTypeFilter() + { + return IsOfTypeArgumentFilter.Instance; + } + + internal static IArgumentFilter IsNotOfTypeFilter() + { + return new LogicalNotArgumentFilter(IsOfTypeArgumentFilter.Instance); + } + + internal static IArgumentFilter MatchesFilter(Func predicate) + { + if (predicate == null) + { + throw new ArgumentNullException("predicate"); + } + + return new MatchesArgumentFilter(predicate); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock_OLD/MockBase.cs b/Src/PCLMock_OLD/MockBase.cs new file mode 100644 index 0000000..229d450 --- /dev/null +++ b/Src/PCLMock_OLD/MockBase.cs @@ -0,0 +1,451 @@ +namespace PCLMock +{ + using System; + using System.Collections.Generic; + using System.Globalization; + using System.Linq.Expressions; + using PCLMock.Utility; + using PCLMock.Visitors; + + /// + /// A base class from which mock objects must be derived. + /// + /// + /// + /// Mock objects should derive from this base class. Typically, you will want to mock an interface. Please see the online documentation for more information. + /// + /// + /// + /// The type being mocked. + /// + public abstract class MockBase + { + private const string mockedObjectErrorTemplate = @"The default implementation of MockBase<{0}> is unable to automatically determine an instance of type {0} to be used as the mocked object. You should override MockedObject in {1} and return the mocked object. +Full mock type name: {2} +Full mocked object type name: {3}"; + + private const string noContinuationErrorTemplate = @"{0} '{1}', for which no specifications have been configured, was invoked on a strict mock. You must either configure specifications via calls to When on the mock, or use a loose mock by passing in MockBehavior.Loose to the mock's constructor."; + + private static readonly object[] emptyArgs = new object[0]; + private static readonly ArgumentFilterCollection emptyArgumentFilters = new ArgumentFilterCollection(); + + private readonly IDictionary continuations; + private readonly object continuationsSync; + private readonly MockBehavior behavior; + + /// + /// Initializes a new instance of the MockBase class. + /// + /// + /// The behavior to be used by this mock. + /// + protected MockBase(MockBehavior behavior) + { + this.continuations = new Dictionary(); + this.continuationsSync = new object(); + this.behavior = behavior; + } + + /// + /// Gets the behavior of this mock. + /// + public MockBehavior Behavior + { + get { return this.behavior; } + } + + /// + /// Gets the mocked object. + /// + /// + /// It is not typically necessary to override this property unless mocking a class. + /// + public virtual TMock MockedObject + { + get + { + object toCast = this; + + if (!(toCast is TMock)) + { + throw new InvalidOperationException( + string.Format( + CultureInfo.InvariantCulture, + mockedObjectErrorTemplate, + typeof(TMock).Name, + this.GetType().Name, + this.GetType().FullName, + typeof(TMock).FullName)); + } + + return (TMock)toCast; + } + } + + /// + /// Begins the specification of what the mock should do when a given member is accessed. + /// + /// + /// An expression that resolves to the member. + /// + /// + /// A continuation object with which the actions to be performed can be configured. + /// + public WhenContinuation When(Expression> selector) + { + if (selector == null) + { + throw new ArgumentNullException("selector"); + } + + var continuation = new WhenContinuation(selector, ArgumentFiltersVisitor.FindArgumentFiltersWithin(selector.Body) ?? emptyArgumentFilters); + this.AddOrReplaceWhenContinuation(selector, continuation); + return continuation; + } + + /// + /// Begins the specification of what the mock should do when a given member is accessed. + /// + /// + /// An expression that resolves to the member. + /// + /// + /// A continuation object with which the actions to be performed can be configured. + /// + public WhenContinuation When(Expression> selector) + { + if (selector == null) + { + throw new ArgumentNullException("selector"); + } + + var continuation = new WhenContinuation(selector, ArgumentFiltersVisitor.FindArgumentFiltersWithin(selector.Body) ?? emptyArgumentFilters); + this.AddOrReplaceWhenContinuation(selector, continuation); + return continuation; + } + + /// + /// Begins the specification of what the mock should do when a given property is set. + /// + /// + /// The type of the property. + /// + /// + /// An expression that resolves the property. + /// + /// + /// An optional expression that can provide filtering against the property value being set. + /// + /// + /// A continuation object with which the actions to be performed can be configured. + /// + public WhenContinuation WhenPropertySet(Expression> propertySelector, Expression> valueFilterSelector = null) + { + if (propertySelector == null) + { + throw new ArgumentNullException("propertySelector"); + } + + if (valueFilterSelector == null) + { + valueFilterSelector = () => It.IsAny(); + } + + var filters = new ArgumentFilterCollection(); + filters.Add(ArgumentFilterVisitor.FindArgumentFilterWithin(valueFilterSelector.Body)); + var continuation = new WhenContinuation(propertySelector, filters); + this.AddOrReplaceWhenContinuation(propertySelector, continuation); + return continuation; + } + + /// + /// Begins a verification specification. + /// + /// + /// An expression that resolves to the member being verified. + /// + /// + /// A continuation object with which the verification can be specified. + /// + public VerifyContinuation Verify(Expression> selector) + { + if (selector == null) + { + throw new ArgumentNullException("selector"); + } + + var whenContinuationCollection = this.EnsureWhenContinuationCollection(selector); + return new VerifyContinuation(selector, whenContinuationCollection, ArgumentFiltersVisitor.FindArgumentFiltersWithin(selector.Body) ?? emptyArgumentFilters); + } + + /// + /// Begins a verification specification. + /// + /// + /// + /// An expression that resolves to the member being verified. + /// + /// + /// A continuation object with which the verification can be specified. + /// + public VerifyContinuation Verify(Expression> selector) + { + if (selector == null) + { + throw new ArgumentNullException("selector"); + } + + var whenContinuationCollection = this.EnsureWhenContinuationCollection(selector); + return new VerifyContinuation(selector, whenContinuationCollection, ArgumentFiltersVisitor.FindArgumentFiltersWithin(selector.Body) ?? emptyArgumentFilters); + } + + /// + /// Begins a verification specification for a property set. + /// + /// + /// The type of the property. + /// + /// + /// An expression that resolves to the property being verified. + /// + /// + /// An optional expression that can provide filtering against the property value being set. + /// + /// + /// A continuation object with which the verification can be specified. + /// + public VerifyContinuation VerifyPropertySet(Expression> propertySelector, Expression> valueFilterSelector = null) + { + if (propertySelector == null) + { + throw new ArgumentNullException("propertySelector"); + } + + if (valueFilterSelector == null) + { + valueFilterSelector = () => It.IsAny(); + } + + var whenContinuationCollection = this.EnsureWhenContinuationCollection(propertySelector); + var filters = new ArgumentFilterCollection(); + filters.Add(ArgumentFilterVisitor.FindArgumentFilterWithin(valueFilterSelector.Body)); + return new VerifyContinuation(propertySelector, whenContinuationCollection, filters); + } + + /// + /// Applies any specifications configured via for a given member. + /// + /// + /// An expression that resolves to the member. + /// + protected void Apply(Expression> selector) + { + var args = ArgumentsVisitor.FindArgumentsWithin(selector.Body) ?? emptyArgs; + WhenContinuationCollection whenContinuationCollection; + var continuation = this.GetWhenContinuation(selector, args, out whenContinuationCollection); + whenContinuationCollection.AddInvocation(new Invocation(args)); + + if (continuation == null) + { + return; + } + + continuation.Apply(this.MockedObject, args); + } + + /// + /// Applies any specifications configured via for a given member. + /// + /// + /// An expression that resolves to the member. + /// + protected TMember Apply(Expression> selector) + { + var args = ArgumentsVisitor.FindArgumentsWithin(selector.Body) ?? emptyArgs; + WhenContinuationCollection whenContinuationCollection; + var continuation = this.GetWhenContinuation(selector, args, out whenContinuationCollection); + whenContinuationCollection.AddInvocation(new Invocation(args)); + + if (continuation == null) + { + return default(TMember); + } + + return (TMember)continuation.Apply(this.MockedObject, args); + } + + /// + /// Applies any specifications configured via for a given property setter. + /// + /// + /// An expression that resolves to the property being set. + /// + /// + /// The value being assigned to the property. + /// + protected void ApplyPropertySet(Expression> selector, object value) + { + // base arguments would be any indexers to the property + var indexerArgs = ArgumentsVisitor.FindArgumentsWithin(selector.Body) ?? emptyArgs; + var args = new object[indexerArgs.Length + 1]; + Array.Copy(indexerArgs, args, indexerArgs.Length); + args[args.Length - 1] = value; + + WhenContinuationCollection whenContinuationCollection; + var continuation = this.GetWhenContinuation(selector, args, out whenContinuationCollection); + whenContinuationCollection.AddInvocation(new Invocation(args)); + + if (continuation == null) + { + return; + } + + continuation.Apply(this.MockedObject, args); + } + + /// + /// Gets the value for an out parameter for a given method at a given parameter index. + /// + /// + /// The type of the out parameter. + /// + /// + /// An expression that resolves to the method. + /// + /// + /// The zero-based index of the parameter. + /// + /// + /// The value assigned to that out parameter. + /// + protected T GetOutParameterValue(Expression> selector, int parameterIndex) + { + var continuation = this.GetWhenContinuation(selector, null); + + if (continuation == null) + { + return default(T); + } + + return continuation.GetOutParameterValue(parameterIndex); + } + + /// + /// Gets the value for a ref parameter for a given method at a given parameter index. + /// + /// + /// The type of the ref parameter. + /// + /// + /// An expression that resolves to the method. + /// + /// + /// The zero-based index of the parameter. + /// + /// + /// An optional default value for the ref parameter, which defaults to the default value of type . + /// + /// + /// The value assigned to that ref parameter. + /// + protected T GetRefParameterValue(Expression> selector, int parameterIndex, T defaultValue = default(T)) + { + var continuation = this.GetWhenContinuation(selector, null); + + if (continuation == null) + { + return default(T); + } + + return continuation.GetRefParameterValue(parameterIndex, defaultValue); + } + + private static ContinuationKey GetContinuationKey(LambdaExpression selector) + { + var methodCallExpression = selector.Body as MethodCallExpression; + + if (methodCallExpression != null) + { + if (methodCallExpression.Object == null) + { + throw new InvalidOperationException("Specifications against extension methods cannot be provided: " + methodCallExpression); + } + + if (methodCallExpression.Object.NodeType != ExpressionType.Parameter) + { + throw new InvalidOperationException("Specifications against methods cannot be chained: " + methodCallExpression); + } + + return new ContinuationKey(methodCallExpression.Method); + } + + var memberExpression = selector.Body as MemberExpression; + + if (memberExpression != null) + { + if (memberExpression.Expression.NodeType != ExpressionType.Parameter) + { + throw new InvalidOperationException("Specifications against properties cannot be chained: " + memberExpression); + } + + return new ContinuationKey(memberExpression.Member); + } + + throw new InvalidOperationException("Unable to determine the details of the member being mocked."); + } + + private WhenContinuationCollection EnsureWhenContinuationCollection(LambdaExpression memberSelector) + { + var continuationKey = GetContinuationKey(memberSelector); + + lock (this.continuationsSync) + { + WhenContinuationCollection result; + + if (!this.continuations.TryGetValue(continuationKey, out result)) + { + result = new WhenContinuationCollection(); + this.continuations[continuationKey] = result; + } + + return result; + } + } + + private void AddOrReplaceWhenContinuation(LambdaExpression memberSelector, WhenContinuation continuation) + { + lock (this.continuationsSync) + { + var whenContinuationCollection = this.EnsureWhenContinuationCollection(memberSelector); + + // first remove any existing filtered continuation that matches the one we're trying to add to avoid memory leaks + whenContinuationCollection.Remove(continuation); + whenContinuationCollection.Add(continuation); + } + } + + private WhenContinuation GetWhenContinuation(LambdaExpression memberSelector, object[] args) + { + WhenContinuationCollection whenContinuationCollection; + return this.GetWhenContinuation(memberSelector, args, out whenContinuationCollection); + } + + private WhenContinuation GetWhenContinuation(LambdaExpression memberSelector, object[] args, out WhenContinuationCollection whenContinuationCollection) + { + var continuationKey = GetContinuationKey(memberSelector); + + lock (this.continuationsSync) + { + whenContinuationCollection = this.EnsureWhenContinuationCollection(memberSelector); + var whenContinuation = whenContinuationCollection.FindWhenContinuation(args); + + if (whenContinuation == null && this.behavior == MockBehavior.Strict) + { + throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, noContinuationErrorTemplate, continuationKey.Type, continuationKey.MemberInfo.Name)); + } + + return whenContinuation; + } + } + } +} \ No newline at end of file diff --git a/Src/PCLMock_OLD/MockBehavior.cs b/Src/PCLMock_OLD/MockBehavior.cs new file mode 100644 index 0000000..5e7ce30 --- /dev/null +++ b/Src/PCLMock_OLD/MockBehavior.cs @@ -0,0 +1,21 @@ +namespace PCLMock +{ + /// + /// Defines possible mock behaviors. + /// + public enum MockBehavior + { + + /// + /// Any invocation against the mock must have a specification (configured via ). If a member of the mock + /// is invoked and it does not have a specification, an exception is thrown. + /// + Strict, + + /// + /// Invocations against the mock are not required to have specifications. If a member of the mock is invoked and it does not have a specification + /// and that member needs to return a value, the default value for the member's type is returned. + /// + Loose + } +} \ No newline at end of file diff --git a/Src/PCLMock_OLD/PCLMock.csproj b/Src/PCLMock_OLD/PCLMock.csproj new file mode 100644 index 0000000..3216692 --- /dev/null +++ b/Src/PCLMock_OLD/PCLMock.csproj @@ -0,0 +1,85 @@ + + + + + 10.0 + Debug + AnyCPU + {A02C0394-4DAD-4422-97BB-4A90D89CEE66} + Library + Properties + PCLMock + PCLMock + v4.0 + Profile336 + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + bin\Debug\PCLMock.xml + true + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + bin\Release\PCLMock.xml + true + + + + + + + + + + + + + + + + Properties\AssemblyInfoCommon.cs + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Src/PCLMock_OLD/PCLMock.v3.ncrunchproject b/Src/PCLMock_OLD/PCLMock.v3.ncrunchproject new file mode 100644 index 0000000..ab5b48b --- /dev/null +++ b/Src/PCLMock_OLD/PCLMock.v3.ncrunchproject @@ -0,0 +1,11 @@ + + + Disabled + Disabled + Disabled + Disabled + Disabled + False + True + + \ No newline at end of file diff --git a/Src/PCLMock_OLD/Properties/AssemblyInfo.cs b/Src/PCLMock_OLD/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..208bb83 --- /dev/null +++ b/Src/PCLMock_OLD/Properties/AssemblyInfo.cs @@ -0,0 +1,8 @@ +using System; +using System.Reflection; +using System.Runtime.CompilerServices; + +[assembly: AssemblyTitle("PCLMock")] +[assembly: AssemblyDescription("Contains the implementation of PCLMock.")] +[assembly: InternalsVisibleTo("PCLMock.UnitTests")] +[assembly: CLSCompliantAttribute(true)] \ No newline at end of file diff --git a/Src/PCLMock_OLD/Utility/ArgumentFilterCollection.cs b/Src/PCLMock_OLD/Utility/ArgumentFilterCollection.cs new file mode 100644 index 0000000..608a1de --- /dev/null +++ b/Src/PCLMock_OLD/Utility/ArgumentFilterCollection.cs @@ -0,0 +1,85 @@ +namespace PCLMock.Utility +{ + using System; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Diagnostics; + using System.Linq; + + // a collection of IArgumentFilter objects + internal sealed class ArgumentFilterCollection : Collection, IEquatable + { + public ArgumentFilterCollection() + { + } + + public ArgumentFilterCollection(IEnumerable filters) + : base(filters.ToList()) + { + } + + public bool Matches(object[] args) + { + Debug.Assert(args != null); + + if (args.Length != this.Count) + { + return false; + } + + for (var i = 0; i < args.Length; ++i) + { + var filter = this[i]; + + if (filter == null) + { + continue; + } + + if (!filter.Matches(args[i])) + { + return false; + } + } + + return true; + } + + public bool Equals(ArgumentFilterCollection other) + { + if (other == null) + { + return false; + } + + if (this.Count != other.Count) + { + return false; + } + + for (var i = 0; i < this.Count; ++i) + { + Debug.Assert(this[i] != null); + Debug.Assert(other[i] != null); + + // filters implement equality semantics, so this is totally OK + if (!this[i].Equals(other[i])) + { + return false; + } + } + + return true; + } + + public override bool Equals(object obj) + { + return this.Equals(obj as ArgumentFilterCollection); + } + + public override int GetHashCode() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock_OLD/Utility/ContinuationKey.cs b/Src/PCLMock_OLD/Utility/ContinuationKey.cs new file mode 100644 index 0000000..e9dd877 --- /dev/null +++ b/Src/PCLMock_OLD/Utility/ContinuationKey.cs @@ -0,0 +1,51 @@ +namespace PCLMock.Utility +{ + using System; + using System.Diagnostics; + using System.Reflection; + + internal struct ContinuationKey : IEquatable + { + private readonly MemberInfo memberInfo; + + public ContinuationKey(MemberInfo memberInfo) + { + Debug.Assert(memberInfo is MethodInfo || memberInfo is PropertyInfo); + this.memberInfo = memberInfo; + } + + public ContinuationKeyType Type + { + get { return this.memberInfo is MethodInfo ? ContinuationKeyType.Method : ContinuationKeyType.Property; } + } + + public MemberInfo MemberInfo + { + get { return this.memberInfo; } + } + + public bool Equals(ContinuationKey other) + { + Debug.Assert(this.memberInfo != null); + Debug.Assert(other.memberInfo != null); + + return other.memberInfo.Equals(this.memberInfo); + } + + public override bool Equals(object obj) + { + if (!(obj is ContinuationKey)) + { + return false; + } + + return this.Equals((ContinuationKey)obj); + } + + public override int GetHashCode() + { + Debug.Assert(this.memberInfo != null); + return this.memberInfo.GetHashCode(); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock_OLD/Utility/ContinuationKeyType.cs b/Src/PCLMock_OLD/Utility/ContinuationKeyType.cs new file mode 100644 index 0000000..25be581 --- /dev/null +++ b/Src/PCLMock_OLD/Utility/ContinuationKeyType.cs @@ -0,0 +1,8 @@ +namespace PCLMock.Utility +{ + internal enum ContinuationKeyType + { + Method, + Property + } +} \ No newline at end of file diff --git a/Src/PCLMock_OLD/Utility/Invocation.cs b/Src/PCLMock_OLD/Utility/Invocation.cs new file mode 100644 index 0000000..881813e --- /dev/null +++ b/Src/PCLMock_OLD/Utility/Invocation.cs @@ -0,0 +1,18 @@ +namespace PCLMock.Utility +{ + // records details about an invocation + internal struct Invocation + { + private readonly object[] arguments; + + public Invocation(object[] arguments) + { + this.arguments = arguments; + } + + public object[] Arguments + { + get { return this.arguments; } + } + } +} \ No newline at end of file diff --git a/Src/PCLMock_OLD/Utility/ObjectExtensions.cs b/Src/PCLMock_OLD/Utility/ObjectExtensions.cs new file mode 100644 index 0000000..8b4a381 --- /dev/null +++ b/Src/PCLMock_OLD/Utility/ObjectExtensions.cs @@ -0,0 +1,142 @@ +namespace PCLMock.Utility +{ + using System; + using System.Collections.Generic; + using System.Globalization; + using System.Linq; + using System.Reflection; + using System.Text; + + internal static class ToDebugStringExtensions + { + private static readonly IDictionary typeToNameMappings = new Dictionary + { + { typeof(bool), "bool" }, + { typeof(byte), "byte" }, + { typeof(sbyte), "sbyte" }, + { typeof(char), "char" }, + { typeof(decimal), "decimal" }, + { typeof(double), "double" }, + { typeof(float), "float" }, + { typeof(int), "int" }, + { typeof(uint), "uint" }, + { typeof(long), "long" }, + { typeof(ulong), "ulong" }, + { typeof(object), "object" }, + { typeof(short), "short" }, + { typeof(ushort), "ushort" }, + { typeof(string), "string" } + }; + + public static string ToDebugString(this Type @this) + { + if (@this == null) + { + throw new ArgumentNullException("@this"); + } + + string result; + + if (typeToNameMappings.TryGetValue(@this, out result)) + { + return result; + } + + var underlyingNullableType = Nullable.GetUnderlyingType(@this); + + if (underlyingNullableType != null) + { + return underlyingNullableType.ToDebugString() + "?"; + } + + return @this.FullName; + } + + public static string ToDebugString(this object @this) + { + if (@this == null) + { + return "null"; + } + + if (@this is Type) + { + return ((Type)@this).ToDebugString(); + } + + if (@this is string) + { + return "\"" + @this + "\""; + } + + if (@this is bool) + { + return @this.ToString().ToLowerInvariant(); + } + + if (@this is int) + { + return @this.ToString(); + } + + if (@this is uint) + { + return @this.ToString() + "U"; + } + + if (@this is long) + { + return @this.ToString() + "L"; + } + + if (@this is ulong) + { + return @this.ToString() + "UL"; + } + + if (@this is float) + { + return ((float)@this).ToString(CultureInfo.InvariantCulture) + "F"; + } + + if (@this is double) + { + return ((double)@this).ToString(CultureInfo.InvariantCulture) + "D"; + } + + if (@this is decimal) + { + return ((decimal)@this).ToString(CultureInfo.InvariantCulture) + "M"; + } + + if (@this is Enum) + { + var @enum = (Enum)@this; + var isFlags = @this.GetType().GetTypeInfo().GetCustomAttributes(typeof(FlagsAttribute), false).Any(); + var result = new StringBuilder(); + + if (isFlags) + { + foreach (Enum value in Enum.GetValues(@this.GetType())) + { + if (@enum.HasFlag(value)) + { + if (result.Length != 0) + { + result.Append(" | "); + } + + result.Append(@this.GetType().Name).Append(".").Append(value); + } + } + + return result.ToString(); + } + + return @this.GetType().Name + "." + @this; + } + + return @this.ToString() + " [" + @this.GetType().ToDebugString() + "]"; + } + } +} \ No newline at end of file diff --git a/Src/PCLMock_OLD/Utility/WhenContinuationCollection.cs b/Src/PCLMock_OLD/Utility/WhenContinuationCollection.cs new file mode 100644 index 0000000..77a0b85 --- /dev/null +++ b/Src/PCLMock_OLD/Utility/WhenContinuationCollection.cs @@ -0,0 +1,47 @@ +namespace PCLMock.Utility +{ + using System.Collections.Generic; + using System.Collections.ObjectModel; + + // a collection of WhenContinuation objects and a record of all invocations therein + internal sealed class WhenContinuationCollection : Collection + { + private readonly List invocations; + private readonly object sync; + + public WhenContinuationCollection() + { + this.invocations = new List(); + this.sync = new object(); + } + + public IEnumerable Invocations + { + get { return this.invocations; } + } + + public void AddInvocation(Invocation invocation) + { + lock (this.sync) + { + this.invocations.Add(invocation); + } + } + + public WhenContinuation FindWhenContinuation(object[] args) + { + // we loop backwards so that more recently registered continuations take a higher precedence + for (var i = this.Count - 1; i >= 0; --i) + { + var continuation = this[i]; + + if (args == null || continuation.Filters == null || continuation.Filters.Matches(args)) + { + return continuation; + } + } + + return null; + } + } +} \ No newline at end of file diff --git a/Src/PCLMock_OLD/VerificationException.cs b/Src/PCLMock_OLD/VerificationException.cs new file mode 100644 index 0000000..79d175c --- /dev/null +++ b/Src/PCLMock_OLD/VerificationException.cs @@ -0,0 +1,27 @@ +namespace PCLMock +{ + using System; + + /// + /// The exception type used to indicate a verification failure. + /// + public sealed class VerificationException : Exception + { + /// + public VerificationException() + { + } + + /// + public VerificationException(string message) + : base(message) + { + } + + /// + public VerificationException(string message, Exception innerException) + : base(message, innerException) + { + } + } +} \ No newline at end of file diff --git a/Src/PCLMock_OLD/VerifyContinuation.cs b/Src/PCLMock_OLD/VerifyContinuation.cs new file mode 100644 index 0000000..d0c5e10 --- /dev/null +++ b/Src/PCLMock_OLD/VerifyContinuation.cs @@ -0,0 +1,182 @@ +namespace PCLMock +{ + using System.Collections.Generic; + using System.Diagnostics; + using System.Globalization; + using System.Linq; + using System.Linq.Expressions; + using PCLMock.Utility; + using PCLMock.Visitors; + + /// + /// Facilitates the expression of verifications against a member in a . + /// + public sealed class VerifyContinuation + { + private readonly Expression selector; + private readonly WhenContinuationCollection whenContinuationCollection; + private readonly ArgumentFilterCollection filters; + + internal VerifyContinuation(Expression selector, WhenContinuationCollection whenContinuationCollection, ArgumentFilterCollection filters) + { + Debug.Assert(selector != null); + Debug.Assert(whenContinuationCollection != null); + Debug.Assert(filters != null); + + this.selector = selector; + this.whenContinuationCollection = whenContinuationCollection; + this.filters = filters; + } + + /// + /// Verifies that the member was not called. + /// + public void WasNotCalled() + { + var invocations = this.GetMatchingInvocations(); + + if (invocations.Count > 0) + { + ThrowVerificationException( + "Verification that {0} was not called failed because it was called {1} time{2}.", + this.GetSelectorString(), + invocations.Count, + invocations.Count == 1 ? string.Empty : "s"); + } + } + + /// + /// Verifies that the member was called exactly one time. + /// + public void WasCalledExactlyOnce() + { + var invocations = this.GetMatchingInvocations(); + + if (invocations.Count != 1) + { + ThrowVerificationException( + "Verification that {0} was called exactly once failed because it was called {1} time{2}.", + this.GetSelectorString(), + invocations.Count, + invocations.Count == 1 ? string.Empty : "s"); + } + } + + /// + /// Verifies that the member was called one or more times. + /// + public void WasCalledAtLeastOnce() + { + var invocations = this.GetMatchingInvocations(); + + if (invocations.Count == 0) + { + ThrowVerificationException( + "Verification that {0} was called at least once failed because it was called 0 times.", + this.GetSelectorString()); + } + } + + /// + /// Verifies that the member was either not called, or only called once. + /// + public void WasCalledAtMostOnce() + { + var invocations = this.GetMatchingInvocations(); + + if (invocations.Count > 1) + { + ThrowVerificationException( + "Verification that {0} was called at most once failed because it was called {1} times.", + this.GetSelectorString(), + invocations.Count); + } + } + + /// + /// Verifies that the member was called exactly time. + /// + /// + /// The number of times the member must have been called. + /// + public void WasCalledExactly(int times) + { + var invocations = this.GetMatchingInvocations(); + + if (invocations.Count != times) + { + ThrowVerificationException( + "Verification that {0} was called exactly {1} time{2} failed because it was called {3} time{4}.", + this.GetSelectorString(), + times, + times == 1 ? string.Empty : "s", + invocations.Count, + invocations.Count == 1 ? string.Empty : "s"); + } + } + + /// + /// Verifies that the member was called or more times. + /// + /// + /// The minimum number of times the member must have been called. + /// + public void WasCalledAtLeast(int times) + { + var invocations = this.GetMatchingInvocations(); + + if (invocations.Count < times) + { + ThrowVerificationException( + "Verification that {0} was called at least {1} time{2} failed because it was called {3} time{4}.", + this.GetSelectorString(), + times, + times == 1 ? string.Empty : "s", + invocations.Count, + invocations.Count == 1 ? string.Empty : "s"); + } + } + + /// + /// Verifies that the member called or fewer times. + /// + /// + /// The maximum number of times the member must have been called. + /// + public void WasCalledAtMost(int times) + { + var invocations = this.GetMatchingInvocations(); + + if (invocations.Count > times) + { + ThrowVerificationException( + "Verification that {0} was called at most {1} time{2} failed because it was called {3} time{4}.", + this.GetSelectorString(), + times, + times == 1 ? string.Empty : "s", + invocations.Count, + invocations.Count == 1 ? string.Empty : "s"); + } + } + + private static void ThrowVerificationException(string format, params object[] args) + { + throw new VerificationException(string.Format(CultureInfo.InvariantCulture, format, args)); + } + + private string GetSelectorString() + { + var visitor = new SelectorStringVisitor(); + visitor.Visit(this.selector); + return visitor.ToString(); + } + + private IList GetMatchingInvocations() + { + return this + .whenContinuationCollection.Invocations + .Where(x => this.filters.Matches(x.Arguments)) + .ToList(); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock_OLD/Visitors/ArgumentFilterVisitor.cs b/Src/PCLMock_OLD/Visitors/ArgumentFilterVisitor.cs new file mode 100644 index 0000000..8268f9e --- /dev/null +++ b/Src/PCLMock_OLD/Visitors/ArgumentFilterVisitor.cs @@ -0,0 +1,98 @@ +namespace PCLMock.Visitors +{ + using System.Diagnostics; + using System.Linq; + using System.Linq.Expressions; + using System.Reflection; + using PCLMock.ArgumentFilters; + + // find a single argument filter at the root of the given expression + internal sealed class ArgumentFilterVisitor : ExpressionVisitor + { + private IArgumentFilter argumentFilter; + + private ArgumentFilterVisitor() + { + } + + public static bool TryFindArgumentFilterWithin(Expression expression, out IArgumentFilter argumentFilter) + { + Debug.Assert(expression != null); + + var visitor = new ArgumentFilterVisitor(); + visitor.Visit(expression); + argumentFilter = visitor.argumentFilter; + return argumentFilter != null; + } + + public static IArgumentFilter FindArgumentFilterWithin(Expression expression) + { + IArgumentFilter argumentFilter; + + if (!TryFindArgumentFilterWithin(expression, out argumentFilter)) + { + return null; + } + + return argumentFilter; + } + + protected override Expression VisitMethodCall(MethodCallExpression node) + { + var filterMethod = node + .Method + .DeclaringType + .GetTypeInfo() + .DeclaredMethods + .Where(declaredMethod => declaredMethod.IsStatic && declaredMethod.IsPublic) + .Where(x => x.Name == node.Method.Name + "Filter" && x.GetParameters().Length == node.Arguments.Count) + .FirstOrDefault(); + + if (filterMethod != null && filterMethod.ReturnType == typeof(IArgumentFilter)) + { + if (node.Method.IsGenericMethod) + { + filterMethod = filterMethod.MakeGenericMethod(node.Method.GetGenericArguments()); + } + + var argumentsToFilterMethod = new object[node.Arguments.Count]; + + for (var i = 0; i < argumentsToFilterMethod.Length; ++i) + { + argumentsToFilterMethod[i] = ValueExtractor.FindValueWithin(node.Arguments[i]); + } + + this.argumentFilter = filterMethod.Invoke(null, argumentsToFilterMethod) as IArgumentFilter; + } + else + { + object value; + + if (ValueExtractor.TryFindValueWithin(node, out value)) + { + this.argumentFilter = new IsArgumentFilter(value); + } + } + + return node; + } + + public override Expression Visit(Expression node) + { + if (node.NodeType == ExpressionType.Convert || node.NodeType == ExpressionType.Call) + { + return base.Visit(node); + } + + object value; + + if (ValueExtractor.TryFindValueWithin(node, out value)) + { + this.argumentFilter = new IsArgumentFilter(value); + return node; + } + + return node; + } + } +} \ No newline at end of file diff --git a/Src/PCLMock_OLD/Visitors/ArgumentFiltersVisitor.cs b/Src/PCLMock_OLD/Visitors/ArgumentFiltersVisitor.cs new file mode 100644 index 0000000..a72a3ae --- /dev/null +++ b/Src/PCLMock_OLD/Visitors/ArgumentFiltersVisitor.cs @@ -0,0 +1,71 @@ +namespace PCLMock.Visitors +{ + using System; + using System.Diagnostics; + using System.Linq; + using System.Linq.Expressions; + using PCLMock.ArgumentFilters; + using PCLMock.Utility; + + // find a set of argument filters for a method call + internal sealed class ArgumentFiltersVisitor : ExpressionVisitor + { + private ArgumentFilterCollection argumentFilters; + + private ArgumentFiltersVisitor() + { + } + + public static bool TryFindArgumentFiltersWithin(Expression expression, out ArgumentFilterCollection argumentFilters) + { + Debug.Assert(expression != null); + + var visitor = new ArgumentFiltersVisitor(); + + try + { + visitor.Visit(expression); + argumentFilters = visitor.argumentFilters; + return argumentFilters != null && argumentFilters.All(x => x != null); + } + catch (Exception) + { + } + + argumentFilters = null; + return false; + } + + public static ArgumentFilterCollection FindArgumentFiltersWithin(Expression expression) + { + ArgumentFilterCollection argumentFilters; + + if (!TryFindArgumentFiltersWithin(expression, out argumentFilters)) + { + return null; + } + + return argumentFilters; + } + + protected override Expression VisitMethodCall(MethodCallExpression node) + { + this.argumentFilters = new ArgumentFilterCollection(); + var methodParameters = node.Method.GetParameters(); + + for (var i = 0; i < methodParameters.Length; ++i) + { + if (methodParameters[i].ParameterType.IsByRef || methodParameters[i].IsOut) + { + this.argumentFilters.Add(IsAnyArgumentFilter.Instance); + } + else + { + this.argumentFilters.Add(ArgumentFilterVisitor.FindArgumentFilterWithin(node.Arguments[i])); + } + } + + return Expression.Constant(this.argumentFilters); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock_OLD/Visitors/ArgumentsVisitor.cs b/Src/PCLMock_OLD/Visitors/ArgumentsVisitor.cs new file mode 100644 index 0000000..dbed8e4 --- /dev/null +++ b/Src/PCLMock_OLD/Visitors/ArgumentsVisitor.cs @@ -0,0 +1,59 @@ +namespace PCLMock.Visitors +{ + using System; + using System.Diagnostics; + using System.Linq; + using System.Linq.Expressions; + + // finds the values of all arguments in a method invocation expression + internal sealed class ArgumentsVisitor : ExpressionVisitor + { + private object[] arguments; + + private ArgumentsVisitor() + { + } + + public static bool TryFindArgumentsWithin(Expression expression, out object[] arguments) + { + Debug.Assert(expression != null); + + var visitor = new ArgumentsVisitor(); + + try + { + visitor.Visit(expression); + arguments = visitor.arguments; + + return arguments != null; + } + catch (Exception) + { + } + + arguments = null; + return false; + } + + public static object[] FindArgumentsWithin(Expression expression) + { + object[] arguments; + + if (!TryFindArgumentsWithin(expression, out arguments)) + { + return null; + } + + return arguments; + } + + protected override Expression VisitMethodCall(MethodCallExpression node) + { + this.arguments = node.Arguments + .Select(x => ValueExtractor.FindValueWithin(x)) + .ToArray(); + + return Expression.Constant(this.arguments); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock_OLD/Visitors/SelectorStringVisitor.cs b/Src/PCLMock_OLD/Visitors/SelectorStringVisitor.cs new file mode 100644 index 0000000..49f765e --- /dev/null +++ b/Src/PCLMock_OLD/Visitors/SelectorStringVisitor.cs @@ -0,0 +1,52 @@ +namespace PCLMock.Visitors +{ + using System.Linq.Expressions; + using System.Text; + using PCLMock.Utility; + + // converts the given expression into a string that can be used for debugging purposes + internal sealed class SelectorStringVisitor : ExpressionVisitor + { + private readonly StringBuilder stringBuilder; + + public SelectorStringVisitor() + { + this.stringBuilder = new StringBuilder(); + } + + protected override Expression VisitMember(MemberExpression node) + { + this.stringBuilder.Append(node.Member.Name); + return base.VisitMember(node); + } + + protected override Expression VisitMethodCall(MethodCallExpression node) + { + this.stringBuilder.Append(node.Method.Name).Append("("); + + ArgumentFilterCollection argumentFilters; + + if (ArgumentFiltersVisitor.TryFindArgumentFiltersWithin(node, out argumentFilters)) + { + for (var i = 0; i < argumentFilters.Count; ++i) + { + if (i > 0) + { + this.stringBuilder.Append(", "); + } + + this.stringBuilder.Append(argumentFilters[i].ToString()); + } + } + + this.stringBuilder.Append(")"); + + return node; + } + + public override string ToString() + { + return this.stringBuilder.ToString(); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock_OLD/Visitors/ValueExtractor.cs b/Src/PCLMock_OLD/Visitors/ValueExtractor.cs new file mode 100644 index 0000000..c8f84aa --- /dev/null +++ b/Src/PCLMock_OLD/Visitors/ValueExtractor.cs @@ -0,0 +1,62 @@ +namespace PCLMock.Visitors +{ + using System; + using System.Diagnostics; + using System.Linq.Expressions; + + // extracts values from an expression + // + // examples: + // null extracts null + // "foo" extracts "foo" + // foo extracts the value of local variable foo + // new [] { 1, 2, 3 } extracts int[] { 1, 2, 3 } + // int.MinValue extracts minimum int value + // DateTime.MaxValue extracts the maximum DateTime value + // new DateTime(...) extracts the specified DateTime value + // DateTime.FromSeconds(1) extracts the specified DateTime value + // i => i % 2 == 0 extracts the lambda i => i % 2 == 0 + internal static class ValueExtractor + { + public static bool TryFindValueWithin(Expression expression, out object value) + { + Debug.Assert(expression != null); + + var methodCallExpression = expression as MethodCallExpression; + + if (methodCallExpression != null && methodCallExpression.Method.ReturnType == typeof(void)) + { + value = null; + return false; + } + + try + { + value = Expression + .Lambda(expression) + .Compile() + .DynamicInvoke(); + + return true; + } + catch (Exception) + { + } + + value = null; + return false; + } + + public static object FindValueWithin(Expression expression) + { + object value; + + if (!TryFindValueWithin(expression, out value)) + { + return null; + } + + return value; + } + } +} \ No newline at end of file diff --git a/Src/PCLMock_OLD/WhenContinuation.cs b/Src/PCLMock_OLD/WhenContinuation.cs new file mode 100644 index 0000000..ce2f32b --- /dev/null +++ b/Src/PCLMock_OLD/WhenContinuation.cs @@ -0,0 +1,535 @@ +namespace PCLMock +{ + using System; + using System.Collections.Generic; + using System.Diagnostics; + using System.Globalization; + using System.Linq; + using System.Linq.Expressions; + using System.Reflection; + using System.Text; + using PCLMock.Utility; + using PCLMock.Visitors; + + /// + /// Facilitates the expression of specifications for what a should do when a given member is invoked. + /// + public abstract class WhenContinuation : IEquatable + { + private readonly Expression selector; + private readonly ArgumentFilterCollection filters; + private readonly IDictionary outAndRefAssignments; + + internal WhenContinuation(Expression selector, IEnumerable filters) + { + Debug.Assert(selector != null); + Debug.Assert(filters != null); + + this.selector = selector; + this.filters = new ArgumentFilterCollection(filters); + this.outAndRefAssignments = new Dictionary(); + } + + internal ArgumentFilterCollection Filters + { + get { return this.filters; } + } + + /// + public bool Equals(WhenContinuation other) + { + if (other == null) + { + return false; + } + + return this.filters.Equals(other.filters); + } + + /// + public override bool Equals(object obj) + { + return this.Equals(obj as WhenContinuation); + } + + /// + public override int GetHashCode() + { + throw new NotImplementedException(); + } + + internal abstract object Apply(object mockedObject, params object[] args); + + internal T GetOutParameterValue(int parameterIndex) + { + object value; + + if (!this.outAndRefAssignments.TryGetValue(parameterIndex, out value)) + { + throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "No value for out parameter at index {0} has been specified.", parameterIndex)); + } + + if (value != null) + { + if (!(value is T)) + { + throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Out parameter at index {0} has a value of type '{1}' but type '{2}' was expected.", parameterIndex, value.GetType().FullName, typeof(T).FullName)); + } + } + else if (typeof(T).GetTypeInfo().IsValueType) + { + throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Out parameter at index {0} has a null value specified but it is a value type ('{1}') so cannot be null.", parameterIndex, typeof(T).FullName)); + } + + return (T)value; + } + + internal T GetRefParameterValue(int parameterIndex, T defaultValue) + { + object value; + + if (!this.outAndRefAssignments.TryGetValue(parameterIndex, out value)) + { + // ref parameters need not be included in the specifications, in which case the caller can provide the default value to assign + return defaultValue; + } + + if (value != null) + { + if (!(value is T)) + { + throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Ref parameter at index {0} has a value of type '{1}' but type '{2}' was expected.", parameterIndex, value.GetType().FullName, typeof(T).FullName)); + } + } + else if (typeof(T).GetTypeInfo().IsValueType) + { + throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Ref parameter at index {0} has a null value specified but it is a value type ('{1}') so cannot be null.", parameterIndex, typeof(T).FullName)); + } + + return (T)value; + } + + internal object[] ValidateActionArgs(string actionType, Type[] expected, object[] received) + { + if (expected.Length == 0) + { + // target action expects no arguments, so it effectively doesn't matter what arguments we received - we can still invoke the action + return new object[0]; + } + + var @throw = false; + var receivedTypes = received.Select(x => x == null ? null : x.GetType()); + + if (received.Length != expected.Length) + { + @throw = true; + } + else + { + @throw = !expected.SequenceEqual(receivedTypes, ActionTypeComparer.Instance); + } + + if (@throw) + { + var receivedText = this.ConvertTypesToString(receivedTypes); + var expectedText = this.ConvertTypesToString(expected); + var message = string.Format(CultureInfo.InvariantCulture, "Could not execute the {0} action associated with this mocked member due to a parameter mismatch. Expected: {1} Received: {2}", actionType, expectedText, receivedText); + throw new InvalidOperationException(message); + } + + return received; + } + + internal string GetSelectorString() + { + var visitor = new SelectorStringVisitor(); + visitor.Visit(this.selector); + return visitor.ToString(); + } + + /// + /// Assigns a specified value to an out or ref parameter, so that invocations against the member being specified will result in + /// the corresponding out or ref parameter being set to the specified value. + /// + /// + /// The zero-based index of the parameter. + /// + /// + /// The value to assign to the out or ref parameter. + /// + protected void AssignOutOrRefParameter(int parameterIndex, object value) + { + this.outAndRefAssignments[parameterIndex] = value; + } + + private string ConvertTypesToString(IEnumerable types) + { + return types + .Aggregate( + new StringBuilder(), + (sb, type) => + { + if (sb.Length > 0) + { + sb.Append(", "); + } + + sb.Append(type == null ? "" : type.FullName); + + return sb; + }, + sb => sb.Insert(0, "(").Append(")")) + .ToString(); + } + + private sealed class ActionTypeComparer : IEqualityComparer + { + public static readonly ActionTypeComparer Instance = new ActionTypeComparer(); + + private ActionTypeComparer() + { + } + + public bool Equals(Type expectedType, Type receivedType) + { + Debug.Assert(expectedType != null); + + if (receivedType == null) + { + // one of the arguments provided to the action must have been null, so we can't know the type and just have to assume it's OK + return true; + } + + return expectedType.GetTypeInfo().IsAssignableFrom(receivedType.GetTypeInfo()); + } + + public int GetHashCode(Type obj) + { + return obj == null ? 0 : obj.GetHashCode(); + } + } + } + + /// + /// Facilitates the expression of specifications for what a should do when a given member is invoked. + /// + /// + /// The type of the object being mocked. + /// + public class WhenContinuation : WhenContinuation + { + private Exception exception; + private Delegate doAction; + + internal WhenContinuation(Expression selector, IEnumerable filters) + : base(selector, filters) + { + } + + /// + /// Requests that an exception be thrown if the member is accessed. + /// + /// + /// This overload simply throws an . + /// + public void Throw() + { + this.Throw(new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Mock has been configured to throw when accessing {0}.", this.GetSelectorString()))); + } + + /// + /// Requests that an exception be thrown if the member is accessed. + /// + /// + /// The exception to be thrown. + /// + public void Throw(Exception exception) + { + this.exception = exception; + } + + /// + public new WhenContinuation AssignOutOrRefParameter(int parameterIndex, object value) + { + base.AssignOutOrRefParameter(parameterIndex, value); + return this; + } + + /// + /// Requests that an action be invoked if the member is accessed. + /// + /// + /// The action to be invoked. + /// + /// + /// A continuation object so that the specification can be resumed. + /// + public WhenContinuation Do(Action doAction) + { + this.SetDoAction(doAction); + return this; + } + + /// + /// Requests that an action be invoked if the member is accessed. + /// + /// + /// The action to be invoked. + /// + /// + /// A continuation object so that the specification can be resumed. + /// + public WhenContinuation Do(Action doAction) + { + this.SetDoAction(doAction); + return this; + } + + /// + /// Requests that an action be invoked if the member is accessed. + /// + /// + /// The action to be invoked. + /// + /// + /// A continuation object so that the specification can be resumed. + /// + public WhenContinuation Do(Action doAction) + { + this.SetDoAction(doAction); + return this; + } + + /// + /// Requests that an action be invoked if the member is accessed. + /// + /// + /// The action to be invoked. + /// + /// + /// A continuation object so that the specification can be resumed. + /// + public WhenContinuation Do(Action doAction) + { + this.SetDoAction(doAction); + return this; + } + + /// + /// Requests that an action be invoked if the member is accessed. + /// + /// + /// The action to be invoked. + /// + /// + /// A continuation object so that the specification can be resumed. + /// + public WhenContinuation Do(Action doAction) + { + this.SetDoAction(doAction); + return this; + } + + /// + /// Requests that an action be invoked if the member is accessed. + /// + /// + /// The action to be invoked. + /// + /// + /// A continuation object so that the specification can be resumed. + /// + public WhenContinuation Do(Action doAction) + { + this.SetDoAction(doAction); + return this; + } + + internal override object Apply(object mockedObject, params object[] args) + { + Debug.Assert(args != null); + + if (this.exception != null) + { + throw this.exception; + } + + if (this.doAction != null) + { + args = this.ValidateActionArgs("Do", this.doAction.GetMethodInfo().GetParameters().Select(x => x.ParameterType).ToArray(), args); + this.doAction.DynamicInvoke(args); + } + + return null; + } + + private void SetDoAction(Delegate doAction) + { + if (this.doAction != null) + { + throw new InvalidOperationException("Do can only be specified once per mocked invocation."); + } + + this.doAction = doAction; + } + } + + /// + /// Facilitates the expression of specifications for what a should do when a given member is invoked. + /// + /// + /// The type of the object being mocked. + /// + /// + /// The type being returned by the member being specified. + /// + public sealed class WhenContinuation : WhenContinuation + { + private TMember returnValue; + private Delegate returnAction; + + internal WhenContinuation(Expression selector, IEnumerable filters) + : base(selector, filters) + { + } + + /// + public new WhenContinuation AssignOutOrRefParameter(int parameterIndex, object value) + { + base.AssignOutOrRefParameter(parameterIndex, value); + return this; + } + + /// + public new WhenContinuation Do(Action doAction) + { + base.Do(doAction); + return this; + } + + /// + public new WhenContinuation Do(Action doAction) + { + base.Do(doAction); + return this; + } + + /// + public new WhenContinuation Do(Action doAction) + { + base.Do(doAction); + return this; + } + + /// + public new WhenContinuation Do(Action doAction) + { + base.Do(doAction); + return this; + } + + /// + public new WhenContinuation Do(Action doAction) + { + base.Do(doAction); + return this; + } + + /// + public new WhenContinuation Do(Action doAction) + { + base.Do(doAction); + return this; + } + + /// + /// Requests that a specified value be returned if the member is accessed. + /// + /// + /// The value to return. + /// + public void Return(TMember value) + { + this.returnValue = value; + } + + /// + /// Requests that a Func be invoked to obtain a return value if the member is accessed. + /// + /// + /// The Func that will be invoked to obtain the return value. + /// + public void Return(Func returnAction) + { + this.returnAction = returnAction; + } + + /// + /// Requests that a Func be invoked to obtain a return value if the member is accessed. + /// + /// + /// The Func that will be invoked to obtain the return value. + /// + public void Return(Func returnAction) + { + this.returnAction = returnAction; + } + + /// + /// Requests that a Func be invoked to obtain a return value if the member is accessed. + /// + /// + /// The Func that will be invoked to obtain the return value. + /// + public void Return(Func returnAction) + { + this.returnAction = returnAction; + } + + /// + /// Requests that a Func be invoked to obtain a return value if the member is accessed. + /// + /// + /// The Func that will be invoked to obtain the return value. + /// + public void Return(Func returnAction) + { + this.returnAction = returnAction; + } + + /// + /// Requests that a Func be invoked to obtain a return value if the member is accessed. + /// + /// + /// The Func that will be invoked to obtain the return value. + /// + public void Return(Func returnAction) + { + this.returnAction = returnAction; + } + + /// + /// Requests that a Func be invoked to obtain a return value if the member is accessed. + /// + /// + /// The Func that will be invoked to obtain the return value. + /// + public void Return(Func returnAction) + { + this.returnAction = returnAction; + } + + internal override object Apply(object mockedObject, params object[] args) + { + base.Apply(mockedObject, args); + + if (this.returnAction != null) + { + args = this.ValidateActionArgs("Return", this.returnAction.GetMethodInfo().GetParameters().Select(x => x.ParameterType).ToArray(), args); + return this.returnAction.DynamicInvoke(args); + } + + return this.returnValue; + } + } +} \ No newline at end of file diff --git a/Src/Rebracer.xml b/Src/Rebracer.xml index e66ac9c..27dd7c4 100644 --- a/Src/Rebracer.xml +++ b/Src/Rebracer.xml @@ -40,7 +40,7 @@ 1 0 1 - 0 + 1 0 1 1 @@ -331,8 +331,8 @@ 0 0 0 - 0 - 0 + 1 + 1 false From 5e6f3de094b30145fa71123e2a4730f10851e7d9 Mon Sep 17 00:00:00 2001 From: Kent Boogaart Date: Wed, 25 Oct 2017 08:37:14 +1030 Subject: [PATCH 3/9] WIP: Buildalyzer usage --- .gitignore | 3 + Src/PCLMock.CodeGeneration.Console/App.config | 38 - .../PCLMock.CodeGeneration.Console.csproj | 154 +-- ...k.CodeGeneration.Console.v3.ncrunchproject | 5 - .../Properties/launchSettings.json | 9 + .../packages.config | 105 +- Src/PCLMock.CodeGeneration/DotNetWorkspace.cs | 29 - Src/PCLMock.CodeGeneration/Generator.cs | 22 +- .../Logging/BuildalyzerLogFactory.cs | 68 + .../PCLMock.CodeGeneration.csproj | 16 +- .../Plugins/Disposables.cs | 5 +- .../Plugins/ObservableBasedAsynchrony.cs | 5 +- .../Plugins/TaskBasedAsynchrony.cs | 6 +- Src/PCLMock.CodeGeneration_OLD/Context.cs | 76 -- Src/PCLMock.CodeGeneration_OLD/Extensions.cs | 111 -- Src/PCLMock.CodeGeneration_OLD/Generator.cs | 1127 ----------------- Src/PCLMock.CodeGeneration_OLD/IPlugin.cs | 77 -- Src/PCLMock.CodeGeneration_OLD/Language.cs | 8 - .../LanguageExtensions.cs | 21 - .../Logging/ILogSink.cs | 14 - .../Logging/LogLevel.cs | 12 - .../Logging/LogSinkExtensions.cs | 80 -- .../Logging/NullLogSink.cs | 19 - .../Logging/StringLogSink.cs | 30 - .../Models/Configuration.cs | 226 ---- .../Models/Filter.cs | 18 - .../Models/FilterType.cs | 8 - .../Models/Plugin.cs | 14 - .../Models/Transformation.cs | 18 - .../PCLMock.CodeGeneration.csproj | 161 --- .../PCLMock.CodeGeneration.v3.ncrunchproject | 11 - .../Plugins/Collections.cs | 498 -------- .../Plugins/Disposables.cs | 93 -- .../Plugins/ObservableBasedAsynchrony.cs | 172 --- .../Plugins/TaskBasedAsynchrony.cs | 141 --- .../Properties/AssemblyInfo.cs | 8 - .../SyntaxGeneratorExtensions.cs | 45 - .../XmlBasedGenerator.cs | 68 - Src/PCLMock.CodeGeneration_OLD/app.config | 31 - .../packages.config | 34 - Src/PCLMock.sln | 9 +- 41 files changed, 213 insertions(+), 3382 deletions(-) delete mode 100644 Src/PCLMock.CodeGeneration.Console/App.config delete mode 100644 Src/PCLMock.CodeGeneration.Console/PCLMock.CodeGeneration.Console.v3.ncrunchproject create mode 100644 Src/PCLMock.CodeGeneration.Console/Properties/launchSettings.json delete mode 100644 Src/PCLMock.CodeGeneration/DotNetWorkspace.cs create mode 100644 Src/PCLMock.CodeGeneration/Logging/BuildalyzerLogFactory.cs delete mode 100644 Src/PCLMock.CodeGeneration_OLD/Context.cs delete mode 100644 Src/PCLMock.CodeGeneration_OLD/Extensions.cs delete mode 100644 Src/PCLMock.CodeGeneration_OLD/Generator.cs delete mode 100644 Src/PCLMock.CodeGeneration_OLD/IPlugin.cs delete mode 100644 Src/PCLMock.CodeGeneration_OLD/Language.cs delete mode 100644 Src/PCLMock.CodeGeneration_OLD/LanguageExtensions.cs delete mode 100644 Src/PCLMock.CodeGeneration_OLD/Logging/ILogSink.cs delete mode 100644 Src/PCLMock.CodeGeneration_OLD/Logging/LogLevel.cs delete mode 100644 Src/PCLMock.CodeGeneration_OLD/Logging/LogSinkExtensions.cs delete mode 100644 Src/PCLMock.CodeGeneration_OLD/Logging/NullLogSink.cs delete mode 100644 Src/PCLMock.CodeGeneration_OLD/Logging/StringLogSink.cs delete mode 100644 Src/PCLMock.CodeGeneration_OLD/Models/Configuration.cs delete mode 100644 Src/PCLMock.CodeGeneration_OLD/Models/Filter.cs delete mode 100644 Src/PCLMock.CodeGeneration_OLD/Models/FilterType.cs delete mode 100644 Src/PCLMock.CodeGeneration_OLD/Models/Plugin.cs delete mode 100644 Src/PCLMock.CodeGeneration_OLD/Models/Transformation.cs delete mode 100644 Src/PCLMock.CodeGeneration_OLD/PCLMock.CodeGeneration.csproj delete mode 100644 Src/PCLMock.CodeGeneration_OLD/PCLMock.CodeGeneration.v3.ncrunchproject delete mode 100644 Src/PCLMock.CodeGeneration_OLD/Plugins/Collections.cs delete mode 100644 Src/PCLMock.CodeGeneration_OLD/Plugins/Disposables.cs delete mode 100644 Src/PCLMock.CodeGeneration_OLD/Plugins/ObservableBasedAsynchrony.cs delete mode 100644 Src/PCLMock.CodeGeneration_OLD/Plugins/TaskBasedAsynchrony.cs delete mode 100644 Src/PCLMock.CodeGeneration_OLD/Properties/AssemblyInfo.cs delete mode 100644 Src/PCLMock.CodeGeneration_OLD/SyntaxGeneratorExtensions.cs delete mode 100644 Src/PCLMock.CodeGeneration_OLD/XmlBasedGenerator.cs delete mode 100644 Src/PCLMock.CodeGeneration_OLD/app.config delete mode 100644 Src/PCLMock.CodeGeneration_OLD/packages.config diff --git a/.gitignore b/.gitignore index c24f904..d823299 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,9 @@ Gen/ # FAKE .fake +# Visual Studio 2015 cache/options directory +.vs/ + # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets !packages/*/build/ diff --git a/Src/PCLMock.CodeGeneration.Console/App.config b/Src/PCLMock.CodeGeneration.Console/App.config deleted file mode 100644 index b1e17a2..0000000 --- a/Src/PCLMock.CodeGeneration.Console/App.config +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Src/PCLMock.CodeGeneration.Console/PCLMock.CodeGeneration.Console.csproj b/Src/PCLMock.CodeGeneration.Console/PCLMock.CodeGeneration.Console.csproj index 87228f1..8e450a5 100644 --- a/Src/PCLMock.CodeGeneration.Console/PCLMock.CodeGeneration.Console.csproj +++ b/Src/PCLMock.CodeGeneration.Console/PCLMock.CodeGeneration.Console.csproj @@ -1,137 +1,19 @@ - - - - - Debug - AnyCPU - {B56824C1-B58E-42FB-A528-518638A7DA15} - Exe - Properties - PCLMock.CodeGeneration.Console - PCLMockCodeGen - v4.5.2 - 512 - True - - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\Microsoft.CodeAnalysis.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.dll - True - - - ..\packages\Microsoft.CodeAnalysis.CSharp.1.3.2\lib\net45\Microsoft.CodeAnalysis.CSharp.dll - True - - - ..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.1.3.2\lib\net45\Microsoft.CodeAnalysis.CSharp.Workspaces.dll - True - - - ..\packages\Microsoft.CodeAnalysis.VisualBasic.1.3.2\lib\net45\Microsoft.CodeAnalysis.VisualBasic.dll - True - - - ..\packages\Microsoft.CodeAnalysis.VisualBasic.Workspaces.1.3.2\lib\net45\Microsoft.CodeAnalysis.VisualBasic.Workspaces.dll - True - - - ..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.Workspaces.dll - True - - - ..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.Workspaces.Desktop.dll - True - - - ..\packages\PowerArgs.2.8.0.0\lib\net45\PowerArgs.dll - True - - - - ..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll - True - - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.AttributedModel.dll - True - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.Convention.dll - True - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.Hosting.dll - True - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.Runtime.dll - True - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.TypedParts.dll - True - - - - ..\packages\System.Reflection.Metadata.1.4.2\lib\portable-net45+win8\System.Reflection.Metadata.dll - True - - - - - - - - - - Properties\AssemblyInfoCommon.cs - - - - - - - - - - - - - {6e077796-0241-4191-a866-0ea52b9bd946} - PCLMock.CodeGeneration - - - - - - - - + + + + Exe + netcoreapp2.0 + false + + + + + + + + + + + + \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration.Console/PCLMock.CodeGeneration.Console.v3.ncrunchproject b/Src/PCLMock.CodeGeneration.Console/PCLMock.CodeGeneration.Console.v3.ncrunchproject deleted file mode 100644 index 319cd52..0000000 --- a/Src/PCLMock.CodeGeneration.Console/PCLMock.CodeGeneration.Console.v3.ncrunchproject +++ /dev/null @@ -1,5 +0,0 @@ - - - True - - \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration.Console/Properties/launchSettings.json b/Src/PCLMock.CodeGeneration.Console/Properties/launchSettings.json new file mode 100644 index 0000000..326623c --- /dev/null +++ b/Src/PCLMock.CodeGeneration.Console/Properties/launchSettings.json @@ -0,0 +1,9 @@ +{ + "profiles": { + "PCLMock.CodeGeneration.Console": { + "commandName": "Project", + "commandLineArgs": "-SolutionFile QUT.Core.sln -ConfigurationFile .\\UnitTests\\Mocks.xml -OutputFile .\\UnitTests\\Mocks.g.cs -Verbose true", + "workingDirectory": "C:\\Users\\Kent\\Repository\\QUT\\Src\\" + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration.Console/packages.config b/Src/PCLMock.CodeGeneration.Console/packages.config index 37a30fa..767e5c9 100644 --- a/Src/PCLMock.CodeGeneration.Console/packages.config +++ b/Src/PCLMock.CodeGeneration.Console/packages.config @@ -1,30 +1,81 @@  - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration/DotNetWorkspace.cs b/Src/PCLMock.CodeGeneration/DotNetWorkspace.cs deleted file mode 100644 index ff035a2..0000000 --- a/Src/PCLMock.CodeGeneration/DotNetWorkspace.cs +++ /dev/null @@ -1,29 +0,0 @@ -namespace PCLMock.CodeGeneration -{ - using System; - using System.Collections.Generic; - using Microsoft.DotNet.ProjectModel; - - // adapted from https://github.com/OmniSharp/omnisharp-roslyn/blob/a4dced28f5f3b38d806134e89a6896c9d8075997/src/OmniSharp.DotNet/DotNetWorkspace.cs - public sealed class DotNetWorkspace : Workspace - { - public DotNetWorkspace(string initialPath) - : base(ProjectReaderSettings.ReadFromEnvironment(), true) - { - } - - public IReadOnlyList GetProjectContexts(string projectPath) => - (IReadOnlyList)GetProjectContextCollection(projectPath)?.ProjectContexts.AsReadOnly() ?? Array.Empty(); - - protected override IEnumerable BuildProjectContexts(Project project) - { - foreach (var framework in project.GetTargetFrameworks()) - { - yield return CreateBaseProjectBuilder(project) - .AsDesignTime() - .WithTargetFramework(framework.FrameworkName) - .Build(); - } - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration/Generator.cs b/Src/PCLMock.CodeGeneration/Generator.cs index 3a8aad4..bf72e29 100644 --- a/Src/PCLMock.CodeGeneration/Generator.cs +++ b/Src/PCLMock.CodeGeneration/Generator.cs @@ -6,12 +6,13 @@ using System.Linq; using System.Reflection; using System.Threading.Tasks; + using Buildalyzer; + using Buildalyzer.Workspaces; using Logging; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editing; - //using Microsoft.CodeAnalysis.MSBuild; public static class Generator { @@ -36,8 +37,9 @@ public async static Task> GenerateMocksAsync( Func mockNameSelector, IImmutableList plugins) { - var workspace = new DotNetWorkspace(initialPath); - var solution = await workspace.OpenSolutionAsync(initialPath); + var buildalyzerLogFactory = new BuildalyzerLogFactory(logSink); + var manager = new AnalyzerManager(initialPath, loggerFactory: buildalyzerLogFactory); + var solution = manager.GetWorkspace().CurrentSolution; return await GenerateMocksAsync( logSink, @@ -62,7 +64,8 @@ public async static Task> GenerateMocksAsync( var compilations = await Task.WhenAll( solution .Projects - .Select(async project => + .Select( + async project => { var compilation = await project.GetCompilationAsync(); // make sure the compilation has a reference to PCLMock @@ -93,11 +96,12 @@ public async static Task> GenerateMocksAsync( .OfType() .Where(typeSymbol => typeSymbol.TypeKind == TypeKind.Interface && !typeSymbol.IsImplicitlyDeclared) .Where(typeSymbol => interfacePredicate == null || interfacePredicate(typeSymbol)) - .Select(interfaceSymbol => new - { - InterfaceSymbol = interfaceSymbol, - Compilation = compilation - })) + .Select( + interfaceSymbol => new + { + InterfaceSymbol = interfaceSymbol, + Compilation = compilation + })) .Select( x => { diff --git a/Src/PCLMock.CodeGeneration/Logging/BuildalyzerLogFactory.cs b/Src/PCLMock.CodeGeneration/Logging/BuildalyzerLogFactory.cs new file mode 100644 index 0000000..106d0cf --- /dev/null +++ b/Src/PCLMock.CodeGeneration/Logging/BuildalyzerLogFactory.cs @@ -0,0 +1,68 @@ +namespace PCLMock.CodeGeneration.Logging +{ + using System; + using System.Reactive.Disposables; + using Microsoft.Extensions.Logging; + + public sealed class BuildalyzerLogFactory : ILoggerFactory + { + private readonly ILogSink logSink; + + public BuildalyzerLogFactory(ILogSink logSink) + { + this.logSink = logSink; + } + + public void AddProvider(ILoggerProvider provider) + { + } + + public ILogger CreateLogger(string categoryName) => + new Logger(this.logSink, categoryName); + + public void Dispose() + { + } + + private sealed class Logger : ILogger + { + private readonly ILogSink logSink; + private readonly string categoryName; + + public Logger(ILogSink logSink, string categoryName) + { + this.logSink = logSink; + this.categoryName = categoryName; + } + + public IDisposable BeginScope(TState state) => + Disposable.Empty; + + public bool IsEnabled(Microsoft.Extensions.Logging.LogLevel logLevel) => + true; + + public void Log(Microsoft.Extensions.Logging.LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) => + this.logSink.Log( + typeof(BuildalyzerLogFactory), + ToLogLevel(logLevel), + formatter(state, exception)); + + private static LogLevel ToLogLevel(Microsoft.Extensions.Logging.LogLevel logLevel) + { + switch (logLevel) + { + case Microsoft.Extensions.Logging.LogLevel.Debug: + case Microsoft.Extensions.Logging.LogLevel.Trace: + case Microsoft.Extensions.Logging.LogLevel.None: + return LogLevel.Debug; + case Microsoft.Extensions.Logging.LogLevel.Information: + return LogLevel.Info; + case Microsoft.Extensions.Logging.LogLevel.Warning: + return LogLevel.Warn; + default: + return LogLevel.Error; + } + } + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration/PCLMock.CodeGeneration.csproj b/Src/PCLMock.CodeGeneration/PCLMock.CodeGeneration.csproj index 0f23b5b..b7c239b 100644 --- a/Src/PCLMock.CodeGeneration/PCLMock.CodeGeneration.csproj +++ b/Src/PCLMock.CodeGeneration/PCLMock.CodeGeneration.csproj @@ -1,23 +1,17 @@  - netcoreapp1.1 + netstandard2.0 false - - - $(PackageTargetFallback);portable-net45+win8+wp8+wpa81 + + - - - - + + diff --git a/Src/PCLMock.CodeGeneration/Plugins/Disposables.cs b/Src/PCLMock.CodeGeneration/Plugins/Disposables.cs index 3695b8f..9e2c69a 100644 --- a/Src/PCLMock.CodeGeneration/Plugins/Disposables.cs +++ b/Src/PCLMock.CodeGeneration/Plugins/Disposables.cs @@ -30,7 +30,10 @@ public sealed class Disposables : IPlugin /// public Compilation InitializeCompilation(Compilation compilation) => - compilation.AddReferences(MetadataReference.CreateFromFile(typeof(Disposable).GetTypeInfo().Assembly.Location)); + compilation + .AddReferences( + MetadataReference.CreateFromFile(typeof(IDisposable).GetTypeInfo().Assembly.Location), + MetadataReference.CreateFromFile(typeof(Disposable).GetTypeInfo().Assembly.Location)); /// public SyntaxNode GetDefaultValueSyntax( diff --git a/Src/PCLMock.CodeGeneration/Plugins/ObservableBasedAsynchrony.cs b/Src/PCLMock.CodeGeneration/Plugins/ObservableBasedAsynchrony.cs index 605d290..50e7f46 100644 --- a/Src/PCLMock.CodeGeneration/Plugins/ObservableBasedAsynchrony.cs +++ b/Src/PCLMock.CodeGeneration/Plugins/ObservableBasedAsynchrony.cs @@ -42,7 +42,10 @@ public sealed class ObservableBasedAsynchrony : IPlugin /// public Compilation InitializeCompilation(Compilation compilation) => - compilation.AddReferences(MetadataReference.CreateFromFile(typeof(Observable).GetTypeInfo().Assembly.Location)); + compilation + .AddReferences( + MetadataReference.CreateFromFile(typeof(IObservable<>).GetTypeInfo().Assembly.Location), + MetadataReference.CreateFromFile(typeof(Observable).GetTypeInfo().Assembly.Location)); /// public SyntaxNode GetDefaultValueSyntax( diff --git a/Src/PCLMock.CodeGeneration/Plugins/TaskBasedAsynchrony.cs b/Src/PCLMock.CodeGeneration/Plugins/TaskBasedAsynchrony.cs index bc71e23..cc892d2 100644 --- a/Src/PCLMock.CodeGeneration/Plugins/TaskBasedAsynchrony.cs +++ b/Src/PCLMock.CodeGeneration/Plugins/TaskBasedAsynchrony.cs @@ -2,6 +2,8 @@ namespace PCLMock.CodeGeneration.Plugins { using System; using System.Linq; + using System.Reflection; + using System.Threading.Tasks; using Logging; using Microsoft.CodeAnalysis; @@ -35,7 +37,9 @@ public sealed class TaskBasedAsynchrony : IPlugin /// public Compilation InitializeCompilation(Compilation compilation) => - compilation; + compilation + .AddReferences( + MetadataReference.CreateFromFile(typeof(Task).GetTypeInfo().Assembly.Location)); /// public SyntaxNode GetDefaultValueSyntax( diff --git a/Src/PCLMock.CodeGeneration_OLD/Context.cs b/Src/PCLMock.CodeGeneration_OLD/Context.cs deleted file mode 100644 index 9a96e72..0000000 --- a/Src/PCLMock.CodeGeneration_OLD/Context.cs +++ /dev/null @@ -1,76 +0,0 @@ -namespace PCLMock.CodeGeneration -{ - using System.Collections.Immutable; - using Microsoft.CodeAnalysis; - using Microsoft.CodeAnalysis.Editing; - using PCLMock.CodeGeneration.Logging; - - /// - /// Contains contextual information for code generation. - /// - public sealed class Context - { - private readonly ILogSink logSink; - private readonly Language language; - private readonly IImmutableList plugins; - private readonly SyntaxGenerator syntaxGenerator; - private readonly SemanticModel semanticModel; - - /// - /// Creates a new instance of the Context class. - /// - /// - /// The log sink. - /// - /// - /// The language in which code is being generated. - /// - /// - /// A list of all plugins. - /// - /// - /// The syntax generator. - /// - /// - /// The semantic model. - /// - public Context( - ILogSink logSink, - Language language, - IImmutableList plugins, - SyntaxGenerator syntaxGenerator, - SemanticModel semanticModel) - { - this.logSink = logSink; - this.language = language; - this.plugins = plugins; - this.syntaxGenerator = syntaxGenerator; - this.semanticModel = semanticModel; - } - - /// - /// Gets the log sink. - /// - public ILogSink LogSink => this.logSink; - - /// - /// Gets the language. - /// - public Language Language => this.language; - - /// - /// Gets a list of all plugins. - /// - public IImmutableList Plugins => this.plugins; - - /// - /// Gets the syntax generator. - /// - public SyntaxGenerator SyntaxGenerator => this.syntaxGenerator; - - /// - /// Gets the semantic model. - /// - public SemanticModel SemanticModel => this.semanticModel; - } -} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Extensions.cs b/Src/PCLMock.CodeGeneration_OLD/Extensions.cs deleted file mode 100644 index a2e57b8..0000000 --- a/Src/PCLMock.CodeGeneration_OLD/Extensions.cs +++ /dev/null @@ -1,111 +0,0 @@ -namespace PCLMock.CodeGeneration -{ - using System; - using System.Linq; - using Microsoft.CodeAnalysis; - - public static class Extensions - { - /// - /// Gets a unique name that can be used within the scope of the specified symbol. - /// - /// - /// The symbol within which the name must be unique. - /// - /// - /// A proposed (default) name. - /// - /// - /// A unique name. - /// - public static string GetUniqueName(this IPropertySymbol within, string proposed = "x") - { - while (within.Parameters.Any(x => x.Name == proposed)) - { - proposed = "_" + proposed; - } - - return proposed; - } - - /// - /// Gets a unique name that can be used within the scope of the specified symbol. - /// - /// - /// The symbol within which the name must be unique. - /// - /// - /// A proposed (default) name. - /// - /// - /// A unique name. - /// - public static string GetUniqueName(this IMethodSymbol within, string proposed = "x") - { - while (within.Parameters.Any(x => x.Name == proposed)) - { - proposed = "_" + proposed; - } - - return proposed; - } - - /// - /// Gets a unique name that can be used within the scope of the specified symbol. - /// - /// - /// The symbol within which the name must be unique. - /// - /// - /// A proposed (default) name. - /// - /// - /// A unique name. - /// - public static string GetUniqueName(this ISymbol within, string proposed = "x") - { - var propertySymbol = within as IPropertySymbol; - - if (propertySymbol != null) - { - return propertySymbol.GetUniqueName(proposed); - } - - var methodSymbol = within as IMethodSymbol; - - if (methodSymbol != null) - { - return methodSymbol.GetUniqueName(proposed); - } - - throw new NotSupportedException(); - } - - /// - /// Gets a unique name for a parameter within the scope of the specified symbol. - /// - /// - /// The symbol within which the name must be unique. - /// - /// - /// The parameter symbol. - /// - /// - /// A unique name for the parameter. - /// - public static string GetNameForParameter(this IMethodSymbol within, IParameterSymbol parameterSymbol) - { - switch (parameterSymbol.RefKind) - { - case RefKind.None: - return parameterSymbol.Name; - case RefKind.Ref: - return within.GetUniqueName(parameterSymbol.Name); - case RefKind.Out: - return within.GetUniqueName(parameterSymbol.Name); - default: - throw new NotSupportedException("Unknown parameter ref kind: " + parameterSymbol.RefKind); - } - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Generator.cs b/Src/PCLMock.CodeGeneration_OLD/Generator.cs deleted file mode 100644 index 9832eaf..0000000 --- a/Src/PCLMock.CodeGeneration_OLD/Generator.cs +++ /dev/null @@ -1,1127 +0,0 @@ -namespace PCLMock.CodeGeneration -{ - using System; - using System.Collections.Generic; - using System.Collections.Immutable; - using System.Linq; - using System.Threading.Tasks; - using Logging; - using Microsoft.CodeAnalysis; - using Microsoft.CodeAnalysis.CSharp; - using Microsoft.CodeAnalysis.CSharp.Syntax; - using Microsoft.CodeAnalysis.Editing; - using Microsoft.CodeAnalysis.MSBuild; - - public static class Generator - { - private static readonly Type logSource = typeof(Generator); - - private const string headerComment = -@"----------------------------------------------------------------------- - - This code was generated from a template. - - Changes to this file may cause incorrect behaviour and will be lost - if the code is regenerated. - -------------------------------------------------------------------------"; - - public async static Task> GenerateMocksAsync( - ILogSink logSink, - Language language, - string solutionPath, - Func interfacePredicate, - Func mockNamespaceSelector, - Func mockNameSelector, - IImmutableList plugins) - { - var workspace = MSBuildWorkspace.Create(); - var solution = await workspace.OpenSolutionAsync(solutionPath); - - return await GenerateMocksAsync( - logSink, - language, - solution, - interfacePredicate, - mockNamespaceSelector, - mockNameSelector, - plugins); - } - - public async static Task> GenerateMocksAsync( - ILogSink logSink, - Language language, - Solution solution, - Func interfacePredicate, - Func mockNamespaceSelector, - Func mockNameSelector, - IImmutableList plugins) - { - var syntaxGenerator = SyntaxGenerator.GetGenerator(solution.Workspace, language.ToSyntaxGeneratorLanguageName()); - var compilations = await Task.WhenAll( - solution - .Projects - .Select(async project => - { - var compilation = await project.GetCompilationAsync(); - // make sure the compilation has a reference to PCLMock - compilation = compilation.AddReferences(MetadataReference.CreateFromFile(typeof(MockBase<>).Assembly.Location)); - - foreach (var plugin in plugins) - { - compilation = plugin.InitializeCompilation(compilation); - } - - if (logSink.IsEnabled) - { - logSink.Debug(logSource, "Compilation generated for project '{0}' with references:", project.Name); - - foreach (var reference in compilation.References) - { - logSink.Debug(logSource, "- {0}", reference.Display); - } - } - - return compilation; - })); - - return compilations - .SelectMany( - compilation => - GetSymbolsRecursive(compilation.SourceModule.GlobalNamespace) - .OfType() - .Where(typeSymbol => typeSymbol.TypeKind == TypeKind.Interface && !typeSymbol.IsImplicitlyDeclared) - .Where(typeSymbol => interfacePredicate == null || interfacePredicate(typeSymbol)) - .Select(interfaceSymbol => new - { - InterfaceSymbol = interfaceSymbol, - Compilation = compilation - })) - .Select( - x => - { - var @namespace = mockNamespaceSelector(x.InterfaceSymbol); - var name = mockNameSelector(x.InterfaceSymbol); - - if (logSink.IsEnabled) - { - logSink.Positive( - logSource, - "Generating mock for interface '{0}' with namespace '{1}', name '{2}'.", - x.InterfaceSymbol, - @namespace, - name); - } - - var semanticModel = x.Compilation.GetSemanticModel(x.InterfaceSymbol.DeclaringSyntaxReferences.First().SyntaxTree); - var context = new Context(logSink, language, plugins, syntaxGenerator, semanticModel); - return GenerateMock(context, x.InterfaceSymbol, @namespace, name, plugins); - }) - .Select((syntaxNode, i) => i == 0 ? syntaxGenerator.WithLeadingComments(syntaxNode, headerComment, language) : syntaxNode) - .ToImmutableList(); - } - - private static SyntaxNode GenerateMock( - Context context, - INamedTypeSymbol interfaceSymbol, - string mockNamespace, - string mockName, - IImmutableList plugins) - { - var namespaceSyntax = GetNamespaceDeclarationSyntax(context, mockNamespace); - var classSyntax = GetClassDeclarationSyntax(context, mockName, interfaceSymbol); - - classSyntax = context - .SyntaxGenerator - .AddAttributes(classSyntax, GetClassAttributesSyntax(context)); - classSyntax = context - .SyntaxGenerator - .AddMembers(classSyntax, GetMemberDeclarations(context, mockName, interfaceSymbol, plugins)); - namespaceSyntax = context - .SyntaxGenerator - .AddMembers(namespaceSyntax, classSyntax); - - return context - .SyntaxGenerator - .CompilationUnit(namespaceSyntax) - .NormalizeWhitespace(); - } - - private static SyntaxNode GetNamespaceDeclarationSyntax( - Context context, - string @namespace) - { - return context - .SyntaxGenerator - .NamespaceDeclaration(@namespace); - } - - private static SyntaxNode GetClassDeclarationSyntax( - Context context, - string name, - INamedTypeSymbol interfaceSymbol) - { - var interfaceType = context - .SyntaxGenerator - .TypeExpression(interfaceSymbol); - var mockBaseType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("PCLMock.MockBase`1"); - - if (mockBaseType == null) - { - throw new InvalidOperationException("Failed to find type in PCLMock assembly. Are you sure this project has a reference to PCLMock?"); - } - - var baseType = context - .SyntaxGenerator - .TypeExpression( - mockBaseType - .Construct(interfaceSymbol)); - - var accessibility = interfaceSymbol.DeclaredAccessibility == Accessibility.NotApplicable - ? Accessibility.Public - : interfaceSymbol.DeclaredAccessibility; - - var classDeclaration = context - .SyntaxGenerator - .ClassDeclaration( - name, - accessibility: accessibility, - modifiers: DeclarationModifiers.Partial, - typeParameters: interfaceSymbol.TypeParameters.Select(x => x.Name), - baseType: baseType, - interfaceTypes: new[] { interfaceType }); - - // TODO: tidy this up once this issue is rectified: https://github.com/dotnet/roslyn/issues/1658 - foreach (var typeParameter in interfaceSymbol.TypeParameters) - { - if (typeParameter.HasConstructorConstraint || - typeParameter.HasReferenceTypeConstraint || - typeParameter.HasValueTypeConstraint || - typeParameter.ConstraintTypes.Length > 0) - { - var kinds = (typeParameter.HasConstructorConstraint ? SpecialTypeConstraintKind.Constructor : SpecialTypeConstraintKind.None) | - (typeParameter.HasReferenceTypeConstraint ? SpecialTypeConstraintKind.ReferenceType : SpecialTypeConstraintKind.None) | - (typeParameter.HasValueTypeConstraint ? SpecialTypeConstraintKind.ValueType : SpecialTypeConstraintKind.None); - - classDeclaration = context - .SyntaxGenerator - .WithTypeConstraint( - classDeclaration, - typeParameter.Name, - kinds: kinds, - types: typeParameter.ConstraintTypes.Select(t => context.SyntaxGenerator.TypeExpression(t))); - } - } - - return classDeclaration; - } - - private static IEnumerable GetClassAttributesSyntax( - Context context) - { - // GENERATED CODE: - // - // [System.CodeDom.Compiler.GeneratedCode("PCLMock", "[version]")] - // [System.Runtime.CompilerServices.CompilerGenerated)] - yield return context - .SyntaxGenerator - .Attribute( - "System.CodeDom.Compiler.GeneratedCode", - context - .SyntaxGenerator - .LiteralExpression("PCLMock"), - context - .SyntaxGenerator - .LiteralExpression(typeof(MockBase<>).Assembly.GetName().Version.ToString())); - yield return context - .SyntaxGenerator - .Attribute( - "System.Runtime.CompilerServices.CompilerGenerated"); - } - - private static SyntaxNode GetConstructorDeclarationSyntax( - Context context, - string name) - { - // GENERATED CODE: - // - // public Name(MockBehavior behavior = MockBehavior.Strict) - // : base(behavior) - // { - // ConfigureBehaviorGenerated(); - // ConfigureBehavior(); - // - // if (behavior == MockBehavior.Loose) - // { - // ConfigureLooseBehaviorGenerated(); - // ConfigureLooseBehavior(); - // } - // } - var mockBehaviorType = context - .SyntaxGenerator - .TypeExpression( - context - .SemanticModel - .Compilation - .GetTypeByMetadataName("PCLMock.MockBehavior")); - - return context - .SyntaxGenerator - .ConstructorDeclaration( - name, - parameters: new[] - { - context - .SyntaxGenerator - .ParameterDeclaration( - "behavior", - mockBehaviorType, - initializer: context.SyntaxGenerator.MemberAccessExpression(mockBehaviorType, "Strict")) - }, - accessibility: Accessibility.Public, - baseConstructorArguments: new[] { context.SyntaxGenerator.IdentifierName("behavior") }, - statements: new[] - { - context - .SyntaxGenerator - .InvocationExpression( - context - .SyntaxGenerator - .IdentifierName("ConfigureBehaviorGenerated")), - context - .SyntaxGenerator - .InvocationExpression( - context - .SyntaxGenerator - .IdentifierName("ConfigureBehavior")), - context - .SyntaxGenerator - .IfStatement( - context - .SyntaxGenerator - .ValueEqualsExpression( - context - .SyntaxGenerator - .IdentifierName("behavior"), - context - .SyntaxGenerator - .MemberAccessExpression(mockBehaviorType, "Loose")), - new[] - { - context - .SyntaxGenerator - .InvocationExpression( - context - .SyntaxGenerator - .IdentifierName("ConfigureLooseBehaviorGenerated")), - context - .SyntaxGenerator - .InvocationExpression( - context - .SyntaxGenerator - .IdentifierName("ConfigureLooseBehavior")) - }) - }); - } - - private static SyntaxNode GetConfigureBehaviorGeneratedSyntax( - Context context, - INamedTypeSymbol interfaceSymbol, - IImmutableList plugins, - MockBehavior behavior) - { - var statements = GetMembersRecursive(interfaceSymbol) - .Select(symbol => GetConfigureBehaviorGeneratedForSymbol(context, interfaceSymbol, symbol, plugins, behavior)) - .Where(syntaxNode => syntaxNode != null) - .ToImmutableList(); - - return context - .SyntaxGenerator - .MethodDeclaration( - behavior == MockBehavior.Strict ? "ConfigureBehaviorGenerated" : "ConfigureLooseBehaviorGenerated", - accessibility: Accessibility.Private, - statements: statements); - } - - private static SyntaxNode GetConfigureBehaviorGeneratedForSymbol( - Context context, - INamedTypeSymbol interfaceSymbol, - ISymbol symbol, - IImmutableList plugins, - MockBehavior behavior) - { - context - .LogSink - .Debug(logSource, "Considering symbol '{0}'.", symbol); - - var propertySymbol = symbol as IPropertySymbol; - var methodSymbol = symbol as IMethodSymbol; - - INamedTypeSymbol returnType = null; - - if (propertySymbol != null) - { - if (propertySymbol.GetMethod == null) - { - context - .LogSink - .Debug(logSource, "Ignoring symbol '{0}' because it is a write-only property.", symbol); - return null; - } - - returnType = propertySymbol.GetMethod.ReturnType as INamedTypeSymbol; - } - else if (methodSymbol != null) - { - if (methodSymbol.AssociatedSymbol != null) - { - context - .LogSink - .Debug(logSource, "Ignoring symbol '{0}' because it is a method with an associated symbol.", symbol); - return null; - } - - if (methodSymbol.IsGenericMethod) - { - context - .LogSink - .Debug(logSource, "Ignoring symbol '{0}' because it is a generic method.", symbol); - return null; - } - - returnType = methodSymbol.ReturnType as INamedTypeSymbol; - } - else - { - context - .LogSink - .Debug(logSource, "Ignoring symbol '{0}' because it is neither a property nor a method.", symbol); - return null; - } - - if (returnType == null) - { - context - .LogSink - .Warn(logSource, "Ignoring symbol '{0}' because its return type could not be determined (it's probably a sgeneric).", symbol); - return null; - } - - var defaultValueSyntax = plugins - .Select(plugin => plugin.GetDefaultValueSyntax(context, behavior, symbol, returnType)) - .Where(syntax => syntax != null) - .FirstOrDefault(); - - if (defaultValueSyntax == null) - { - return null; - } - - var itType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("PCLMock.It"); - - if (itType == null) - { - context - .LogSink - .Error(logSource, "Failed to resolve It class."); - return null; - } - - var isAnyMethod = itType - .GetMembers("IsAny") - .Single(); - - if (isAnyMethod == null) - { - context - .LogSink - .Error(logSource, "Failed to resolve IsAny method."); - return null; - } - - var lambdaParameterName = symbol.GetUniqueName(); - SyntaxNode lambdaExpression; - - if (propertySymbol != null) - { - if (!propertySymbol.IsIndexer) - { - // GENERATED CODE: - // - // this - // .When(x => x.SymbolName) - lambdaExpression = context - .SyntaxGenerator - .MemberAccessExpression( - context - .SyntaxGenerator - .IdentifierName(lambdaParameterName), - propertySymbol.Name); - } - else - { - // GENERATED CODE: - // - // this - // .When(x => x[It.IsAny(), It.IsAny() ...) - var whenArguments = propertySymbol - .Parameters - .Select( - parameter => - context - .SyntaxGenerator - .InvocationExpression( - context - .SyntaxGenerator - .MemberAccessExpression( - context - .SyntaxGenerator - .TypeExpression(itType), - context - .SyntaxGenerator - .GenericName( - "IsAny", - typeArguments: new[] - { - parameter.Type - })))); - - lambdaExpression = context - .SyntaxGenerator - .ElementAccessExpression( - context - .SyntaxGenerator - .IdentifierName(lambdaParameterName), - arguments: whenArguments); - } - } - else - { - // GENERATED CODE: - // - // this - // .When(x => x.SymbolName(It.IsAny(), It.IsAny() ...) - var whenArguments = methodSymbol - .Parameters - .Select( - parameter => - context - .SyntaxGenerator - .InvocationExpression( - context - .SyntaxGenerator - .MemberAccessExpression( - context - .SyntaxGenerator - .TypeExpression(itType), - context - .SyntaxGenerator - .GenericName( - "IsAny", - typeArguments: new[] - { - parameter.Type - })))); - - lambdaExpression = context - .SyntaxGenerator - .InvocationExpression( - context - .SyntaxGenerator - .MemberAccessExpression( - context - .SyntaxGenerator - .IdentifierName(lambdaParameterName), - methodSymbol.Name), - arguments: whenArguments); - } - - var whenLambdaArgument = context - .SyntaxGenerator - .ValueReturningLambdaExpression( - lambdaParameterName, - lambdaExpression); - - var whenInvocation = context - .SyntaxGenerator - .InvocationExpression( - context - .SyntaxGenerator - .MemberAccessExpression( - context - .SyntaxGenerator - .ThisExpression(), - context - .SyntaxGenerator - .IdentifierName("When")), - whenLambdaArgument); - - var result = context - .SyntaxGenerator - .ExpressionStatement( - context - .SyntaxGenerator - .InvocationExpression( - context - .SyntaxGenerator - .MemberAccessExpression( - whenInvocation, - context - .SyntaxGenerator - .IdentifierName("Return")), - arguments: new[] - { - defaultValueSyntax - })); - - return result; - } - - private static SyntaxNode GetConfigureBehaviorMethodSyntax( - Context context) - { - // GENERATED CODE: - // - // partial void ConfigureBehavior(); - return context - .SyntaxGenerator - .MethodDeclaration( - "ConfigureBehavior", - accessibility: context.Language == Language.VisualBasic ? Accessibility.Private : Accessibility.NotApplicable, - modifiers: DeclarationModifiers.Partial); - } - - private static SyntaxNode GetConfigureLooseBehaviorMethodSyntax( - Context context) - { - // GENERATED CODE: - // - // partial void ConfigureLooseBehavior(); - return context - .SyntaxGenerator - .MethodDeclaration( - "ConfigureLooseBehavior", - accessibility: context.Language == Language.VisualBasic ? Accessibility.Private : Accessibility.NotApplicable, - modifiers: DeclarationModifiers.Partial); - } - - private static IEnumerable GetMemberDeclarations( - Context context, - string name, - INamedTypeSymbol interfaceSymbol, - IImmutableList plugins) - { - return - new SyntaxNode[] - { - GetConstructorDeclarationSyntax(context, name), - GetConfigureBehaviorGeneratedSyntax(context, interfaceSymbol, plugins, MockBehavior.Strict), - GetConfigureBehaviorGeneratedSyntax(context, interfaceSymbol, plugins, MockBehavior.Loose), - GetConfigureBehaviorMethodSyntax(context), - GetConfigureLooseBehaviorMethodSyntax(context) - } - .Concat( - GetMembersRecursive(interfaceSymbol) - .Select(x => GetMemberDeclarationSyntax(context, x)) - .Where(x => x != null) - .GroupBy(x => x, SyntaxNodeEqualityComparer.Instance) - .Where(group => group.Count() == 1) - .SelectMany(group => group) - .Select(x => context.SyntaxGenerator.AsPublicInterfaceImplementation(x, context.SyntaxGenerator.TypeExpression(interfaceSymbol)))); - } - - private static IEnumerable GetMembersRecursive(INamedTypeSymbol interfaceSymbol) - { - foreach (var member in interfaceSymbol.GetMembers()) - { - yield return member; - } - - foreach (var implementedInterface in interfaceSymbol.Interfaces) - { - foreach (var member in GetMembersRecursive(implementedInterface)) - { - yield return member; - } - } - } - - private static SyntaxNode GetMemberDeclarationSyntax( - Context context, - ISymbol symbol) - { - var propertySymbol = symbol as IPropertySymbol; - - if (propertySymbol != null) - { - return GetPropertyDeclarationSyntax(context, propertySymbol); - } - - var methodSymbol = symbol as IMethodSymbol; - - if (methodSymbol != null) - { - return GetMethodDeclarationSyntax(context, methodSymbol); - } - - // unsupported symbol type, but we don't error - the user can supplement our code as necessary because it's a partial class - return null; - } - - private static SyntaxNode GetPropertyDeclarationSyntax( - Context context, - IPropertySymbol propertySymbol) - { - var getAccessorStatements = GetPropertyGetAccessorsSyntax(context, propertySymbol).ToList(); - var setAccessorStatements = GetPropertySetAccessorsSyntax(context, propertySymbol).ToList(); - var declarationModifiers = DeclarationModifiers.None; - - if (getAccessorStatements.Count == 0) - { - declarationModifiers = declarationModifiers.WithIsWriteOnly(true); - - // set-only properties are not currently supported - return null; - } - - if (setAccessorStatements.Count == 0) - { - declarationModifiers = declarationModifiers.WithIsReadOnly(true); - } - - if (!propertySymbol.IsIndexer) - { - return context - .SyntaxGenerator - .PropertyDeclaration( - propertySymbol.Name, - context - .SyntaxGenerator - .TypeExpression(propertySymbol.Type), - accessibility: Accessibility.Public, - modifiers: declarationModifiers, - getAccessorStatements: getAccessorStatements, - setAccessorStatements: setAccessorStatements); - } - else - { - var parameters = propertySymbol - .Parameters - .Select(x => context.SyntaxGenerator.ParameterDeclaration(x.Name, context.SyntaxGenerator.TypeExpression(x.Type))) - .ToList(); - - return context - .SyntaxGenerator - .IndexerDeclaration( - parameters, - context.SyntaxGenerator.TypeExpression(propertySymbol.Type), - accessibility: Accessibility.Public, - modifiers: declarationModifiers, - getAccessorStatements: getAccessorStatements, - setAccessorStatements: setAccessorStatements); - } - } - - private static IEnumerable GetPropertyGetAccessorsSyntax( - Context context, - IPropertySymbol propertySymbol) - { - if (propertySymbol.GetMethod == null) - { - yield break; - } - - var lambdaParameterName = propertySymbol.GetUniqueName(); - - if (!propertySymbol.IsIndexer) - { - // GENERATED CODE: - // - // return this.Apply(x => x.PropertyName); - yield return context - .SyntaxGenerator - .ReturnStatement( - context - .SyntaxGenerator - .InvocationExpression( - context - .SyntaxGenerator - .MemberAccessExpression( - context - .SyntaxGenerator - .ThisExpression(), - "Apply"), - context - .SyntaxGenerator - .ValueReturningLambdaExpression( - lambdaParameterName, - context - .SyntaxGenerator - .MemberAccessExpression( - context - .SyntaxGenerator - .IdentifierName(lambdaParameterName), - context - .SyntaxGenerator - .IdentifierName(propertySymbol.Name))))); - } - else - { - // GENERATED CODE: - // - // return this.Apply(x => x[first, second]); - var arguments = propertySymbol - .Parameters - .Select(x => context.SyntaxGenerator.Argument(context.SyntaxGenerator.IdentifierName(x.Name))) - .ToList(); - - yield return context - .SyntaxGenerator - .ReturnStatement( - context - .SyntaxGenerator - .InvocationExpression( - context - .SyntaxGenerator - .MemberAccessExpression( - context - .SyntaxGenerator - .ThisExpression(), - "Apply"), - context - .SyntaxGenerator - .ValueReturningLambdaExpression( - lambdaParameterName, - context - .SyntaxGenerator - .ElementAccessExpression( - context - .SyntaxGenerator - .IdentifierName(lambdaParameterName), - arguments)))); - } - } - - private static IEnumerable GetPropertySetAccessorsSyntax( - Context context, - IPropertySymbol propertySymbol) - { - if (propertySymbol.SetMethod == null) - { - yield break; - } - - var lambdaParameterName = propertySymbol.GetUniqueName(); - - if (!propertySymbol.IsIndexer) - { - // GENERATED CODE: - // - // this.ApplyPropertySet(x => x.PropertyName, value); - yield return context - .SyntaxGenerator - .InvocationExpression( - context - .SyntaxGenerator - .MemberAccessExpression( - context - .SyntaxGenerator - .ThisExpression(), - "ApplyPropertySet"), - context - .SyntaxGenerator - .ValueReturningLambdaExpression( - lambdaParameterName, - context - .SyntaxGenerator - .MemberAccessExpression( - context - .SyntaxGenerator - .IdentifierName(lambdaParameterName), - context - .SyntaxGenerator - .IdentifierName(propertySymbol.Name))), - context - .SyntaxGenerator - .IdentifierName("value")); - } - else - { - // GENERATED CODE: - // - // this.ApplyPropertySet(x => x[first, second], value); - var arguments = propertySymbol - .Parameters - .Select(x => context.SyntaxGenerator.Argument(context.SyntaxGenerator.IdentifierName(x.Name))) - .ToList(); - - yield return context - .SyntaxGenerator - .InvocationExpression( - context - .SyntaxGenerator - .MemberAccessExpression( - context - .SyntaxGenerator - .ThisExpression(), - "ApplyPropertySet"), - context - .SyntaxGenerator - .ValueReturningLambdaExpression( - lambdaParameterName, - context - .SyntaxGenerator - .ElementAccessExpression( - context - .SyntaxGenerator - .IdentifierName(lambdaParameterName), - arguments)), - context - .SyntaxGenerator - .IdentifierName("value")); - } - } - - private static SyntaxNode GetMethodDeclarationSyntax( - Context context, - IMethodSymbol methodSymbol) - { - if (methodSymbol.MethodKind != MethodKind.Ordinary) - { - return null; - } - - var methodDeclaration = context - .SyntaxGenerator - .MethodDeclaration(methodSymbol); - methodDeclaration = context - .SyntaxGenerator - .WithModifiers( - methodDeclaration, - context - .SyntaxGenerator - .GetModifiers(methodDeclaration) - .WithIsAbstract(false)); - methodDeclaration = context - .SyntaxGenerator - .WithStatements( - methodDeclaration, - GetMethodStatementsSyntax(context, methodSymbol)); - - var csharpMethodDeclaration = methodDeclaration as MethodDeclarationSyntax; - - if (csharpMethodDeclaration != null) - { - // remove trailing semi-colon from the declaration - methodDeclaration = csharpMethodDeclaration.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.None)); - } - - return methodDeclaration; - } - - private static IEnumerable GetMethodStatementsSyntax( - Context context, - IMethodSymbol methodSymbol) - { - // GENERATED CODE (for every ref or out parameter): - // - // string someOutParameter; - // var someRefParameter = default(int); - for (var i = 0; i < methodSymbol.Parameters.Length; ++i) - { - var parameter = methodSymbol.Parameters[i]; - - if (parameter.RefKind == RefKind.Out) - { - yield return context - .SyntaxGenerator - .LocalDeclarationStatement( - context - .SyntaxGenerator - .TypeExpression(parameter.Type), - methodSymbol.GetNameForParameter(parameter)); - } - else if (parameter.RefKind == RefKind.Ref) - { - yield return context - .SyntaxGenerator - .LocalDeclarationStatement( - methodSymbol.GetNameForParameter(parameter), - initializer: context.SyntaxGenerator.DefaultExpression(context.SyntaxGenerator.TypeExpression(parameter.Type))); - } - } - - var arguments = methodSymbol - .Parameters - .Select(x => - context - .SyntaxGenerator - .Argument( - x.RefKind, - context - .SyntaxGenerator - .IdentifierName(methodSymbol.GetNameForParameter(x)))) - .ToList(); - - var typeArguments = methodSymbol - .TypeArguments - .Select(x => context.SyntaxGenerator.TypeExpression(x)) - .ToList(); - - var lambdaParameterName = methodSymbol.GetUniqueName(); - - var lambdaInvocation = context - .SyntaxGenerator - .MemberAccessExpression( - context - .SyntaxGenerator - .IdentifierName(lambdaParameterName), - methodSymbol.Name); - - if (typeArguments.Count > 0) - { - lambdaInvocation = context - .SyntaxGenerator - .WithTypeArguments( - lambdaInvocation, - typeArguments); - } - - // GENERATED CODE (for every ref or out parameter): - // - // someOutParameter = this.GetOutParameterValue(x => x.TheMethod(out someOutParameter), parameterIndex: 0); - // someRefParameter = this.GetRefParameterValue(x => x.TheMethod(ref someRefParameter), parameterIndex: 0); - for (var i = 0; i < methodSymbol.Parameters.Length; ++i) - { - var parameter = methodSymbol.Parameters[i]; - - if (parameter.RefKind == RefKind.Out || parameter.RefKind == RefKind.Ref) - { - var nameOfMethodToCall = parameter.RefKind == RefKind.Out ? "GetOutParameterValue" : "GetRefParameterValue"; - - yield return context - .SyntaxGenerator - .AssignmentStatement( - context - .SyntaxGenerator - .IdentifierName(parameter.Name), - context - .SyntaxGenerator - .InvocationExpression( - context - .SyntaxGenerator - .MemberAccessExpression( - context - .SyntaxGenerator - .ThisExpression(), - context - .SyntaxGenerator - .GenericName( - nameOfMethodToCall, - typeArguments: context.SyntaxGenerator.TypeExpression(parameter.Type))), - arguments: new[] - { - context - .SyntaxGenerator - .ValueReturningLambdaExpression( - lambdaParameterName, - context - .SyntaxGenerator - .InvocationExpression( - lambdaInvocation, - arguments: arguments)), - context - .SyntaxGenerator - .LiteralExpression(i) - })); - } - } - - // GENERATED CODE: - // - // [return] this.Apply(x => x.SomeMethod(param1, param2)); - var applyInvocation = context - .SyntaxGenerator - .InvocationExpression( - context - .SyntaxGenerator - .MemberAccessExpression( - context - .SyntaxGenerator - .ThisExpression(), - "Apply"), - context - .SyntaxGenerator - .ValueReturningLambdaExpression( - lambdaParameterName, - context - .SyntaxGenerator - .InvocationExpression( - lambdaInvocation, - arguments: arguments))); - - if (!methodSymbol.ReturnsVoid) - { - applyInvocation = context - .SyntaxGenerator - .ReturnStatement(applyInvocation); - } - - yield return applyInvocation; - } - - private static IEnumerable GetSymbolsRecursive(INamespaceSymbol namespaceSymbol) - { - // using a heap-based stack here instead of recursive call just to be sure we don't overflow the stack - var stack = new Stack(); - stack.Push(namespaceSymbol); - - while (stack.Count > 0) - { - var namespaceSymbolToProcess = stack.Pop(); - - yield return namespaceSymbolToProcess; - - foreach (var namespaceMember in namespaceSymbolToProcess.GetMembers()) - { - var namespaceMemberAsNamespace = namespaceMember as INamespaceSymbol; - - if (namespaceMemberAsNamespace != null) - { - stack.Push(namespaceMemberAsNamespace); - } - else - { - yield return namespaceMember; - } - } - } - } - - private sealed class SyntaxNodeEqualityComparer : IEqualityComparer - { - public static readonly SyntaxNodeEqualityComparer Instance = new SyntaxNodeEqualityComparer(); - - private SyntaxNodeEqualityComparer() - { - } - - public bool Equals(SyntaxNode x, SyntaxNode y) => - x.IsEquivalentTo(y, topLevel: true); - - // We have to ensure like syntax nodes have the same hash code in order for Equals to even be called - // Unfortunately, Roslyn does not implement GetHashCode, so we can't use that. We also don't want to - // use ToString because then we may as well have just grouped by it and because it includes the - // implementation, not just the declaration. To do this "properly", we'd have to write a recursive - // hash code calculator, using similar logic to what IsEquivalentTo gives us. - public int GetHashCode(SyntaxNode obj) => - 0; - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/IPlugin.cs b/Src/PCLMock.CodeGeneration_OLD/IPlugin.cs deleted file mode 100644 index be5293e..0000000 --- a/Src/PCLMock.CodeGeneration_OLD/IPlugin.cs +++ /dev/null @@ -1,77 +0,0 @@ -namespace PCLMock.CodeGeneration -{ - using Microsoft.CodeAnalysis; - - /// - /// Defines the interface for a plugin. - /// - /// - /// - /// Plugins are able to participate in generating code at specific points in the mock code generation process. - /// For example, they might generate a default return value for any method returning a Task. - /// - /// - /// The participating plugins are configured by adding them to the - /// instance passed into . - /// - /// - public interface IPlugin - { - /// - /// Gets a human-friendly name for the plugin, for identification in debug output. - /// - string Name - { - get; - } - - /// - /// Perform any initialization against the compilation. - /// - /// - /// - /// This method is called once per compilation and per plugin, before any code is generated. If no initialization is required, - /// plugins should simply return the provided compilation. - /// - /// - /// - /// The compilation. - /// - /// - /// The initialized compilation. - /// - Compilation InitializeCompilation(Compilation compilation); - - /// - /// Called to generate the default value for a given symbol. - /// - /// - /// - /// The code generation engine calls this method for each discovered symbol (property/method) that returns a value. - /// The first plugin to return a value will have that syntax incorporated into the mock's ConfigureBehaviorGenerated - /// or ConfigureLooseBehaviorGenerated method, depending on the value of . - /// - /// - /// - /// A context for the operation. - /// - /// - /// Indicates whether the default value is being generated for strict or loose behavioral semantics. - /// - /// - /// The symbol. - /// - /// - /// The symbol's return type. - /// - /// - /// An instance of containing the default value, or if no default value is - /// relevant. - /// - SyntaxNode GetDefaultValueSyntax( - Context context, - MockBehavior behavior, - ISymbol symbol, - INamedTypeSymbol returnType); - } -} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Language.cs b/Src/PCLMock.CodeGeneration_OLD/Language.cs deleted file mode 100644 index d7419ff..0000000 --- a/Src/PCLMock.CodeGeneration_OLD/Language.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace PCLMock.CodeGeneration -{ - public enum Language - { - CSharp, - VisualBasic - } -} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/LanguageExtensions.cs b/Src/PCLMock.CodeGeneration_OLD/LanguageExtensions.cs deleted file mode 100644 index 2c59a4d..0000000 --- a/Src/PCLMock.CodeGeneration_OLD/LanguageExtensions.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace PCLMock.CodeGeneration -{ - using System; - using Microsoft.CodeAnalysis; - - public static class LanguageExtensions - { - public static string ToSyntaxGeneratorLanguageName(this Language @this) - { - switch (@this) - { - case Language.CSharp: - return LanguageNames.CSharp; - case Language.VisualBasic: - return LanguageNames.VisualBasic; - default: - throw new NotSupportedException(); - } - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Logging/ILogSink.cs b/Src/PCLMock.CodeGeneration_OLD/Logging/ILogSink.cs deleted file mode 100644 index f49b627..0000000 --- a/Src/PCLMock.CodeGeneration_OLD/Logging/ILogSink.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace PCLMock.CodeGeneration.Logging -{ - using System; - - public interface ILogSink - { - bool IsEnabled - { - get; - } - - void Log(Type source, LogLevel level, string message); - } -} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Logging/LogLevel.cs b/Src/PCLMock.CodeGeneration_OLD/Logging/LogLevel.cs deleted file mode 100644 index b63881d..0000000 --- a/Src/PCLMock.CodeGeneration_OLD/Logging/LogLevel.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace PCLMock.CodeGeneration.Logging -{ - public enum LogLevel - { - Debug, - Info, - Warn, - Positive, - Negative, - Error - } -} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Logging/LogSinkExtensions.cs b/Src/PCLMock.CodeGeneration_OLD/Logging/LogSinkExtensions.cs deleted file mode 100644 index 22a55e1..0000000 --- a/Src/PCLMock.CodeGeneration_OLD/Logging/LogSinkExtensions.cs +++ /dev/null @@ -1,80 +0,0 @@ -namespace PCLMock.CodeGeneration.Logging -{ - using System; - using System.Globalization; - - public static class LogSinkExtensions - { - public static void Log(this ILogSink @this, Type source, LogLevel level, string format, params object[] args) - { - var message = string.Format(CultureInfo.InvariantCulture, format, args); - @this.Log(source, level, message); - } - - public static void Debug(this ILogSink @this, Type source, string message) - { - @this.Log(source, LogLevel.Debug, message); - } - - public static void Debug(this ILogSink @this, Type source, string format, params object[] args) - { - var message = string.Format(CultureInfo.InvariantCulture, format, args); - @this.Log(source, LogLevel.Debug, message); - } - - public static void Info(this ILogSink @this, Type source, string message) - { - @this.Log(source, LogLevel.Info, message); - } - - public static void Info(this ILogSink @this, Type source, string format, params object[] args) - { - var message = string.Format(CultureInfo.InvariantCulture, format, args); - @this.Log(source, LogLevel.Info, message); - } - - public static void Warn(this ILogSink @this, Type source, string message) - { - @this.Log(source, LogLevel.Warn, message); - } - - public static void Warn(this ILogSink @this, Type source, string format, params object[] args) - { - var message = string.Format(CultureInfo.InvariantCulture, format, args); - @this.Log(source, LogLevel.Warn, message); - } - - public static void Positive(this ILogSink @this, Type source, string message) - { - @this.Log(source, LogLevel.Positive, message); - } - - public static void Positive(this ILogSink @this, Type source, string format, params object[] args) - { - var message = string.Format(CultureInfo.InvariantCulture, format, args); - @this.Log(source, LogLevel.Positive, message); - } - - public static void Negative(this ILogSink @this, Type source, string message) - { - @this.Log(source, LogLevel.Negative, message); - } - - public static void Negative(this ILogSink @this, Type source, string format, params object[] args) - { - var message = string.Format(CultureInfo.InvariantCulture, format, args); - @this.Log(source, LogLevel.Negative, message); - } - - public static void Error(this ILogSink @this, Type source, string message) - { - @this.Log(source, LogLevel.Error, message); - } - - public static void Error(this ILogSink @this, Type source, string format, params object[] args) - { - var message = string.Format(CultureInfo.InvariantCulture, format, args); - @this.Log(source, LogLevel.Error, message); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Logging/NullLogSink.cs b/Src/PCLMock.CodeGeneration_OLD/Logging/NullLogSink.cs deleted file mode 100644 index 232e41e..0000000 --- a/Src/PCLMock.CodeGeneration_OLD/Logging/NullLogSink.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace PCLMock.CodeGeneration.Logging -{ - using System; - - public sealed class NullLogSink : ILogSink - { - public static readonly NullLogSink Instance = new NullLogSink(); - - private NullLogSink() - { - } - - public bool IsEnabled => false; - - public void Log(Type source, LogLevel level, string message) - { - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Logging/StringLogSink.cs b/Src/PCLMock.CodeGeneration_OLD/Logging/StringLogSink.cs deleted file mode 100644 index d89e991..0000000 --- a/Src/PCLMock.CodeGeneration_OLD/Logging/StringLogSink.cs +++ /dev/null @@ -1,30 +0,0 @@ -namespace PCLMock.CodeGeneration.Logging -{ - using System; - using System.Text; - - public sealed class StringLogSink : ILogSink - { - private readonly StringBuilder stringBuilder; - - public StringLogSink() - { - this.stringBuilder = new StringBuilder(); - } - - public bool IsEnabled => true; - - public void Log(Type source, LogLevel level, string message) => - this - .stringBuilder - .Append("[") - .Append(source.FullName) - .Append("] [") - .Append(level) - .Append("] ") - .AppendLine(message); - - public override string ToString() => - this.stringBuilder.ToString(); - } -} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Models/Configuration.cs b/Src/PCLMock.CodeGeneration_OLD/Models/Configuration.cs deleted file mode 100644 index 38af944..0000000 --- a/Src/PCLMock.CodeGeneration_OLD/Models/Configuration.cs +++ /dev/null @@ -1,226 +0,0 @@ -namespace PCLMock.CodeGeneration.Models -{ - using System; - using System.Collections.Generic; - using System.Collections.Immutable; - using System.Globalization; - using System.Linq; - using System.Text; - using System.Text.RegularExpressions; - using System.Xml.Linq; - using System.Xml.XPath; - using Logging; - using Microsoft.CodeAnalysis; - - public sealed class Configuration - { - private static readonly Type logSource = typeof(Configuration); - - private readonly ILogSink logSink; - private readonly IImmutableList namespaceTransformations; - private readonly IImmutableList nameTransformations; - private readonly IImmutableList interfaceFilters; - private readonly IImmutableList plugins; - - public Configuration( - ILogSink logSink, - IEnumerable namespaceTransformations, - IEnumerable nameTransformations, - IEnumerable interfaceFilters, - IEnumerable plugins) - { - this.logSink = logSink; - this.namespaceTransformations = namespaceTransformations.ToImmutableList(); - this.nameTransformations = nameTransformations.ToImmutableList(); - this.interfaceFilters = interfaceFilters.ToImmutableList(); - this.plugins = plugins.ToImmutableList(); - - if (logSink.IsEnabled) - { - var namespaceTransformationsLog = this - .namespaceTransformations - .Aggregate( - new StringBuilder(), - (sb, next) => sb.Append(" - Namespaces matching '").Append(next.Pattern).Append("' will be replaced with '").Append(next.Replacement).AppendLine("'."), sb => sb.ToString()); - var nameTransformationsLog = this - .nameTransformations - .Aggregate( - new StringBuilder(), - (sb, next) => sb.Append(" - Names matching '").Append(next.Pattern).Append("' will be replaced with '").Append(next.Replacement).AppendLine("'."), sb => sb.ToString()); - var interfaceFiltersLog = this - .interfaceFilters - .Aggregate( - new StringBuilder(), - (sb, next) => sb.Append(" - Interfaces matching '").Append(next.Pattern).Append("' will be '").Append(next.Type == FilterType.Include ? "included" : "excluded").AppendLine("."), sb => sb.ToString()); - var pluginsLog = this - .plugins - .Aggregate( - new StringBuilder(), - (sb, next) => sb.Append(" - Plugin with assembly-qualified name '").Append(next.AssemblyQualifiedName).AppendLine("' will be applied.")); - logSink.Debug(logSource, $"Created configuration with the following rules:{Environment.NewLine}{namespaceTransformationsLog}{nameTransformationsLog}{interfaceFiltersLog}{pluginsLog}"); - } - } - - public IImmutableList NamespaceTransformations => this.namespaceTransformations; - - public IImmutableList NameTransformations => this.nameTransformations; - - public IImmutableList InterfaceFilters => this.interfaceFilters; - - public IImmutableList Plugins => this.plugins; - - public static Configuration FromXDocument(ILogSink logSink, XDocument document) - { - var namespaceTransformations = document - .Root - .XPathSelectElements("./NamespaceTransformations/Transformation") - .Select(x => new Transformation(x.Element("Pattern").Value, x.Element("Replacement").Value)); - var nameTransformations = document - .Root - .XPathSelectElements("./NameTransformations/Transformation") - .Select(x => new Transformation(x.Element("Pattern").Value, x.Element("Replacement").Value)); - var interfaceFilters = document - .Root - .XPathSelectElements("./Interfaces") - .Single() - .Nodes() - .OfType() - .Select(x => new Filter(ParseFilterType(x.Name.LocalName), x.Element("Pattern").Value)); - var plugins = document - .Root - .XPathSelectElements("./Plugins/Plugin") - .Select(x => new Plugin(x.Value)); - return new Configuration(logSink, namespaceTransformations, nameTransformations, interfaceFilters, plugins); - } - - public Func GetInterfacePredicate() - { - return symbol => - { - var name = string.Format( - CultureInfo.InvariantCulture, - "{0}, {1}", - symbol.ToDisplayString(), - symbol.ContainingAssembly.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat)); - var include = false; - - this.logSink.Info(logSource, "Determining inclusivity of interface: '{0}'.", name); - - foreach (var filter in this.InterfaceFilters) - { - if (include && filter.Type == FilterType.Exclude) - { - include = !Regex.IsMatch(name, filter.Pattern); - } - else if (!include && filter.Type == FilterType.Include) - { - include = Regex.IsMatch(name, filter.Pattern); - } - - if (this.logSink.IsEnabled) - { - this.logSink.Debug( - logSource, - " - after {0} filter '{1}', it is {2}.", - filter.Type == FilterType.Include ? "inclusion" : "exclusion", - filter.Pattern, - include ? "included" : "excluded"); - } - } - - if (logSink.IsEnabled) - { - this.logSink.Log( - logSource, - include ? LogLevel.Positive : LogLevel.Negative, - "'{0}' has been {1}.", - name, - include ? "included" : "excluded"); - } - - return include; - }; - } - - public Func GetNamespaceSelector() - { - return symbol => ApplyTransformations(this.logSink, "namespace", symbol.ContainingNamespace.ToString(), this.NamespaceTransformations); - } - - public Func GetNameSelector() - { - return symbol => ApplyTransformations(this.logSink, "name", symbol.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat), this.NameTransformations); - } - - public IImmutableList GetPlugins() - { - var resolvedPlugins = new List(this.plugins.Count); - - foreach (var plugin in this.plugins) - { - this.logSink.Info(logSource, "Attempting to resolve plugin from type name '{0}'.", plugin.AssemblyQualifiedName); - var type = Type.GetType(plugin.AssemblyQualifiedName); - - if (type == null) - { - this.logSink.Error(logSource, "Failed to resolve plugin from type name '{0}'.", plugin.AssemblyQualifiedName); - continue; - } - - try - { - var resolvedPlugin = Activator.CreateInstance(type); - - if (!(resolvedPlugin is IPlugin)) - { - this.logSink.Error(logSource, "Resolved plugin '{0}' does not implement '{1}'.", resolvedPlugin.GetType().AssemblyQualifiedName, typeof(IPlugin).AssemblyQualifiedName); - continue; - } - - resolvedPlugins.Add((IPlugin)resolvedPlugin); - } - catch (Exception ex) - { - this.logSink.Error(logSource, "Failed to create plugin from type name '{0}'. Exception was: {1}", plugin.AssemblyQualifiedName, ex); - } - } - - return resolvedPlugins.ToImmutableList(); - } - - private static string ApplyTransformations(ILogSink logSink, string type, string input, IImmutableList transformations) - { - logSink.Info(logSource, "Applying {0} transformations to input: '{1}'.", type, input); - - foreach (var transformation in transformations) - { - input = Regex.Replace(input, transformation.Pattern, transformation.Replacement); - - if (logSink.IsEnabled) - { - logSink.Debug( - logSource, - " - after transformation '{0}' -> '{1}', input is now '{2}'.", - transformation.Pattern, - transformation.Replacement, - input); - } - } - - return input; - } - - private static FilterType ParseFilterType(string text) - { - switch (text) - { - case "Include": - return FilterType.Include; - case "Exclude": - return FilterType.Exclude; - default: - throw new NotSupportedException("Filter type '" + text + "' not supported."); - } - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Models/Filter.cs b/Src/PCLMock.CodeGeneration_OLD/Models/Filter.cs deleted file mode 100644 index 63f6ee6..0000000 --- a/Src/PCLMock.CodeGeneration_OLD/Models/Filter.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace PCLMock.CodeGeneration.Models -{ - public sealed class Filter - { - private readonly FilterType type; - private readonly string pattern; - - public Filter(FilterType type, string pattern) - { - this.type = type; - this.pattern = pattern; - } - - public FilterType Type => this.type; - - public string Pattern => this.pattern; - } -} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Models/FilterType.cs b/Src/PCLMock.CodeGeneration_OLD/Models/FilterType.cs deleted file mode 100644 index 54cc101..0000000 --- a/Src/PCLMock.CodeGeneration_OLD/Models/FilterType.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace PCLMock.CodeGeneration.Models -{ - public enum FilterType - { - Include, - Exclude - } -} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Models/Plugin.cs b/Src/PCLMock.CodeGeneration_OLD/Models/Plugin.cs deleted file mode 100644 index b0cc09f..0000000 --- a/Src/PCLMock.CodeGeneration_OLD/Models/Plugin.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace PCLMock.CodeGeneration.Models -{ - public sealed class Plugin - { - private readonly string assemblyQualifiedName; - - public Plugin(string assemblyQualifiedName) - { - this.assemblyQualifiedName = assemblyQualifiedName; - } - - public string AssemblyQualifiedName => this.assemblyQualifiedName; - } -} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Models/Transformation.cs b/Src/PCLMock.CodeGeneration_OLD/Models/Transformation.cs deleted file mode 100644 index 9d0be40..0000000 --- a/Src/PCLMock.CodeGeneration_OLD/Models/Transformation.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace PCLMock.CodeGeneration.Models -{ - public sealed class Transformation - { - private readonly string pattern; - private readonly string replacement; - - public Transformation(string pattern, string replacement) - { - this.pattern = pattern; - this.replacement = replacement; - } - - public string Pattern => this.pattern; - - public string Replacement => this.replacement; - } -} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/PCLMock.CodeGeneration.csproj b/Src/PCLMock.CodeGeneration_OLD/PCLMock.CodeGeneration.csproj deleted file mode 100644 index 6ac3d63..0000000 --- a/Src/PCLMock.CodeGeneration_OLD/PCLMock.CodeGeneration.csproj +++ /dev/null @@ -1,161 +0,0 @@ - - - - - Debug - AnyCPU - {6E077796-0241-4191-A866-0EA52B9BD946} - Library - Properties - PCLMock.CodeGeneration - PCLMock.CodeGeneration - v4.5.2 - 512 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\Microsoft.CodeAnalysis.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.dll - True - - - ..\packages\Microsoft.CodeAnalysis.CSharp.1.3.2\lib\net45\Microsoft.CodeAnalysis.CSharp.dll - True - - - ..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.1.3.2\lib\net45\Microsoft.CodeAnalysis.CSharp.Workspaces.dll - True - - - ..\packages\Microsoft.CodeAnalysis.VisualBasic.1.3.2\lib\net45\Microsoft.CodeAnalysis.VisualBasic.dll - True - - - ..\packages\Microsoft.CodeAnalysis.VisualBasic.Workspaces.1.3.2\lib\net45\Microsoft.CodeAnalysis.VisualBasic.Workspaces.dll - True - - - ..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.Workspaces.dll - True - - - ..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.Workspaces.Desktop.dll - True - - - - ..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll - True - - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.AttributedModel.dll - True - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.Convention.dll - True - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.Hosting.dll - True - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.Runtime.dll - True - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.TypedParts.dll - True - - - - ..\packages\Rx-Core.2.2.5\lib\net45\System.Reactive.Core.dll - True - - - ..\packages\Rx-Interfaces.2.2.5\lib\net45\System.Reactive.Interfaces.dll - True - - - ..\packages\Rx-Linq.2.2.5\lib\net45\System.Reactive.Linq.dll - True - - - ..\packages\Rx-PlatformServices.2.2.5\lib\net45\System.Reactive.PlatformServices.dll - True - - - ..\packages\System.Reflection.Metadata.1.4.2\lib\portable-net45+win8\System.Reflection.Metadata.dll - True - - - - - - - - - - Properties\AssemblyInfoCommon.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Designer - - - - - - - - - \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/PCLMock.CodeGeneration.v3.ncrunchproject b/Src/PCLMock.CodeGeneration_OLD/PCLMock.CodeGeneration.v3.ncrunchproject deleted file mode 100644 index ab5b48b..0000000 --- a/Src/PCLMock.CodeGeneration_OLD/PCLMock.CodeGeneration.v3.ncrunchproject +++ /dev/null @@ -1,11 +0,0 @@ - - - Disabled - Disabled - Disabled - Disabled - Disabled - False - True - - \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Plugins/Collections.cs b/Src/PCLMock.CodeGeneration_OLD/Plugins/Collections.cs deleted file mode 100644 index baf6a7c..0000000 --- a/Src/PCLMock.CodeGeneration_OLD/Plugins/Collections.cs +++ /dev/null @@ -1,498 +0,0 @@ -namespace PCLMock.CodeGeneration.Plugins -{ - using System; - using Logging; - using Microsoft.CodeAnalysis; - - /// - /// A plugin that generates appropriate default return values for any member that returns a collection. - /// - /// - /// - /// This plugin generates return specifications for any member returning a standard collection type. That is, - /// it returns IEnumerable<T>, ICollection<T>, IReadOnlyCollection<T>, - /// IList<T>, IReadOnlyList<T>, IDictionary<TKey, TValue>, - /// IReadOnlyDictionary<TKey, TValue>, ISet<T> IImmutableList<T>, - /// IImmutableDictionary<TKey, TValue>, IImmutableQueue<T>, - /// IImmutableSet<T>, or IImmutableStack<T>. - /// - /// - /// The generated specification simply returns a default instance of an appropriate type. This has the - /// (usually desirable) effect of ensuring any collection-like member returns an empty collection by default - /// rather than . - /// - /// - /// Members for which specifications cannot be generated are ignored. This of course includes members that do not - /// return collections, but also set-only properties, generic methods, and any members that return custom - /// collection subtypes. - /// - /// - public sealed class Collections : IPlugin - { - private static readonly Type logSource = typeof(Collections); - - public string Name => "Collections"; - - /// - public Compilation InitializeCompilation(Compilation compilation) => - compilation; - - /// - public SyntaxNode GetDefaultValueSyntax( - Context context, - MockBehavior behavior, - ISymbol symbol, - INamedTypeSymbol returnType) - { - if (behavior == MockBehavior.Loose) - { - return null; - } - - if (!returnType.IsGenericType) - { - context - .LogSink - .Debug(logSource, "Ignoring symbol '{0}' because its return type is not a generic type, so it cannot be one of the supported collection types."); - return null; - } - - SyntaxNode returnValueSyntax; - - if (!TryGetReturnValueSyntaxForEnumerableReturnType(context, returnType, out returnValueSyntax) && - !TryGetReturnValueSyntaxForCollectionReturnType(context, returnType, out returnValueSyntax) && - !TryGetReturnValueSyntaxForDictionaryReturnType(context, returnType, out returnValueSyntax) && - !TryGetReturnValueSyntaxForSetReturnType(context, returnType, out returnValueSyntax) && - !TryGetReturnValueSyntaxForImmutableListReturnType(context, returnType, out returnValueSyntax) && - !TryGetReturnValueSyntaxForImmutableDictionaryReturnType(context, returnType, out returnValueSyntax) && - !TryGetReturnValueSyntaxForImmutableQueueReturnType(context, returnType, out returnValueSyntax) && - !TryGetReturnValueSyntaxForImmutableSetReturnType(context, returnType, out returnValueSyntax) && - !TryGetReturnValueSyntaxForImmutableStackReturnType(context, returnType, out returnValueSyntax)) - { - context - .LogSink - .Debug(logSource, "Ignoring symbol '{0}' because it does not return a supported collection type.", symbol); - return null; - } - - return returnValueSyntax; - } - - private static bool TryGetReturnValueSyntaxForEnumerableReturnType( - Context context, - INamedTypeSymbol returnType, - out SyntaxNode returnValueSyntax) - { - var enumerableInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Generic.IEnumerable`1"); - - if (returnType.ConstructedFrom != enumerableInterfaceType) - { - returnValueSyntax = null; - return false; - } - - var enumerableType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Linq.Enumerable"); - - if (enumerableType == null) - { - context - .LogSink - .Warn(logSource, "Failed to resolve Enumerable class."); - returnValueSyntax = null; - return false; - } - - returnValueSyntax = context - .SyntaxGenerator - .InvocationExpression( - context - .SyntaxGenerator - .WithTypeArguments( - context - .SyntaxGenerator - .MemberAccessExpression( - context - .SyntaxGenerator - .TypeExpression(enumerableType), - "Empty"), - context - .SyntaxGenerator - .TypeExpression(returnType.TypeArguments[0]))); - return true; - } - - private static bool TryGetReturnValueSyntaxForCollectionReturnType( - Context context, - INamedTypeSymbol returnType, - out SyntaxNode returnValueSyntax) - { - var collectionInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Generic.ICollection`1"); - - var readOnlyCollectionInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Generic.IReadOnlyCollection`1"); - - var listInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Generic.IList`1"); - - var readOnlyListInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Generic.IReadOnlyList`1"); - - if (returnType.ConstructedFrom != collectionInterfaceType && - returnType.ConstructedFrom != readOnlyCollectionInterfaceType && - returnType.ConstructedFrom != listInterfaceType && - returnType.ConstructedFrom != readOnlyListInterfaceType) - { - returnValueSyntax = null; - return false; - } - - var listType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Generic.List`1"); - - if (listType == null) - { - context - .LogSink - .Warn(logSource, "Failed to resolve List class."); - returnValueSyntax = null; - return false; - } - - returnValueSyntax = context - .SyntaxGenerator - .ObjectCreationExpression( - listType.Construct(returnType.TypeArguments[0])).NormalizeWhitespace(); - return true; - } - - private static bool TryGetReturnValueSyntaxForDictionaryReturnType( - Context context, - INamedTypeSymbol returnType, - out SyntaxNode returnValueSyntax) - { - var dictionaryInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Generic.IDictionary`2"); - - var readOnlyDictionaryInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Generic.IReadOnlyDictionary`2"); - - if (returnType.ConstructedFrom != dictionaryInterfaceType && - returnType.ConstructedFrom != readOnlyDictionaryInterfaceType) - { - returnValueSyntax = null; - return false; - } - - var dictionaryType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Generic.Dictionary`2"); - - if (dictionaryType == null) - { - context - .LogSink - .Warn(logSource, "Failed to resolve Dictionary class."); - returnValueSyntax = null; - return false; - } - - returnValueSyntax = context - .SyntaxGenerator - .ObjectCreationExpression( - dictionaryType.Construct(returnType.TypeArguments[0], returnType.TypeArguments[1])).NormalizeWhitespace(); - return true; - } - - private static bool TryGetReturnValueSyntaxForSetReturnType( - Context context, - INamedTypeSymbol returnType, - out SyntaxNode returnValueSyntax) - { - var setInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Generic.ISet`1"); - - if (returnType.ConstructedFrom != setInterfaceType) - { - returnValueSyntax = null; - return false; - } - - var dictionaryType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Generic.HashSet`1"); - - if (dictionaryType == null) - { - context - .LogSink - .Warn(logSource, "Failed to resolve HashSet class."); - returnValueSyntax = null; - return false; - } - - returnValueSyntax = context - .SyntaxGenerator - .ObjectCreationExpression( - dictionaryType.Construct(returnType.TypeArguments[0])).NormalizeWhitespace(); - return true; - } - - private static bool TryGetReturnValueSyntaxForImmutableListReturnType( - Context context, - INamedTypeSymbol returnType, - out SyntaxNode returnValueSyntax) - { - var immutableListInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Immutable.IImmutableList`1"); - - if (returnType.ConstructedFrom != immutableListInterfaceType) - { - returnValueSyntax = null; - return false; - } - - var immutableListType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Immutable.ImmutableList"); - - if (immutableListType == null) - { - context - .LogSink - .Warn(logSource, "Failed to resolve ImmutableList class."); - returnValueSyntax = null; - return false; - } - - returnValueSyntax = context - .SyntaxGenerator - .MemberAccessExpression( - context - .SyntaxGenerator - .WithTypeArguments( - context - .SyntaxGenerator - .TypeExpression(immutableListType), - context - .SyntaxGenerator - .TypeExpression(returnType.TypeArguments[0])), - "Empty"); - return true; - } - - private static bool TryGetReturnValueSyntaxForImmutableDictionaryReturnType( - Context context, - INamedTypeSymbol returnType, - out SyntaxNode returnValueSyntax) - { - var immutableDictionaryInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Immutable.IImmutableDictionary`2"); - - if (returnType.ConstructedFrom != immutableDictionaryInterfaceType) - { - returnValueSyntax = null; - return false; - } - - var immutableDictionaryType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Immutable.ImmutableDictionary"); - - if (immutableDictionaryType == null) - { - context - .LogSink - .Warn(logSource, "Failed to resolve ImmutableDictionary class."); - returnValueSyntax = null; - return false; - } - - returnValueSyntax = context - .SyntaxGenerator - .MemberAccessExpression( - context - .SyntaxGenerator - .WithTypeArguments( - context - .SyntaxGenerator - .TypeExpression(immutableDictionaryType), - context - .SyntaxGenerator - .TypeExpression(returnType.TypeArguments[0]), - context - .SyntaxGenerator - .TypeExpression(returnType.TypeArguments[1])), - "Empty"); - return true; - } - - private static bool TryGetReturnValueSyntaxForImmutableQueueReturnType( - Context context, - INamedTypeSymbol returnType, - out SyntaxNode returnValueSyntax) - { - var immutableQueueInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Immutable.IImmutableQueue`1"); - - if (returnType.ConstructedFrom != immutableQueueInterfaceType) - { - returnValueSyntax = null; - return false; - } - - var immutableQueueType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Immutable.ImmutableQueue"); - - if (immutableQueueType == null) - { - context - .LogSink - .Warn(logSource, "Failed to resolve ImmutableQueue class."); - returnValueSyntax = null; - return false; - } - - returnValueSyntax = context - .SyntaxGenerator - .MemberAccessExpression( - context - .SyntaxGenerator - .WithTypeArguments( - context - .SyntaxGenerator - .TypeExpression(immutableQueueType), - context - .SyntaxGenerator - .TypeExpression(returnType.TypeArguments[0])), - "Empty"); - return true; - } - - private static bool TryGetReturnValueSyntaxForImmutableSetReturnType( - Context context, - INamedTypeSymbol returnType, - out SyntaxNode returnValueSyntax) - { - var immutableSetInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Immutable.IImmutableSet`1"); - - if (returnType.ConstructedFrom != immutableSetInterfaceType) - { - returnValueSyntax = null; - return false; - } - - var immutableSetType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Immutable.ImmutableHashSet"); - - if (immutableSetType == null) - { - context - .LogSink - .Warn(logSource, "Failed to resolve ImmutableSet class."); - returnValueSyntax = null; - return false; - } - - returnValueSyntax = context - .SyntaxGenerator - .MemberAccessExpression( - context - .SyntaxGenerator - .WithTypeArguments( - context - .SyntaxGenerator - .TypeExpression(immutableSetType), - context - .SyntaxGenerator - .TypeExpression(returnType.TypeArguments[0])), - "Empty"); - return true; - } - - private static bool TryGetReturnValueSyntaxForImmutableStackReturnType( - Context context, - INamedTypeSymbol returnType, - out SyntaxNode returnValueSyntax) - { - var immutableStackInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Immutable.IImmutableStack`1"); - - if (returnType.ConstructedFrom != immutableStackInterfaceType) - { - returnValueSyntax = null; - return false; - } - - var immutableStackType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Immutable.ImmutableStack"); - - if (immutableStackType == null) - { - context - .LogSink - .Warn(logSource, "Failed to resolve ImmutableStack class."); - returnValueSyntax = null; - return false; - } - - returnValueSyntax = context - .SyntaxGenerator - .MemberAccessExpression( - context - .SyntaxGenerator - .WithTypeArguments( - context - .SyntaxGenerator - .TypeExpression(immutableStackType), - context - .SyntaxGenerator - .TypeExpression(returnType.TypeArguments[0])), - "Empty"); - return true; - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Plugins/Disposables.cs b/Src/PCLMock.CodeGeneration_OLD/Plugins/Disposables.cs deleted file mode 100644 index 56e9f54..0000000 --- a/Src/PCLMock.CodeGeneration_OLD/Plugins/Disposables.cs +++ /dev/null @@ -1,93 +0,0 @@ -namespace PCLMock.CodeGeneration.Plugins -{ - using System; - using System.Reactive.Disposables; - using Logging; - using Microsoft.CodeAnalysis; - - /// - /// A plugin that generates appropriate default return values for any member that returns . - /// - /// - /// - /// This plugin generates return specifications for any member returning . The returned - /// value is an instance of System.Reactive.Disposables.Disposable.Empty. Since the Disposable type - /// is defined by Reactive Extensions, the target code must have a reference in order for the specification to be - /// generated. - /// - /// - /// Members for which specifications cannot be generated are ignored. This of course includes members that do not - /// return , but also set-only properties, generic methods, and any members that return - /// custom disposable subtypes. - /// - /// - public sealed class Disposables : IPlugin - { - private static readonly Type logSource = typeof(Disposables); - - public string Name => "Disposables"; - - /// - public Compilation InitializeCompilation(Compilation compilation) => - compilation.AddReferences(MetadataReference.CreateFromFile(typeof(Disposable).Assembly.Location)); - - /// - public SyntaxNode GetDefaultValueSyntax( - Context context, - MockBehavior behavior, - ISymbol symbol, - INamedTypeSymbol returnType) - { - if (behavior == MockBehavior.Loose) - { - return null; - } - - var disposableInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.IDisposable"); - - if (disposableInterfaceType == null) - { - context - .LogSink - .Warn(logSource, "Failed to resolve IDisposable type."); - return null; - } - - if (returnType != disposableInterfaceType) - { - context - .LogSink - .Debug(logSource, "Ignoring symbol '{0}' because its return type is not IDisposable."); - return null; - } - - var disposableType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Reactive.Disposables.Disposable"); - - if (disposableType == null) - { - context - .LogSink - .Debug(logSource, "Ignoring symbol '{0}' because Disposable type could not be resolved (probably a missing reference to System.Reactive.Core)."); - return null; - } - - var result = context - .SyntaxGenerator - .MemberAccessExpression( - context - .SyntaxGenerator - .TypeExpression(disposableType), - context - .SyntaxGenerator - .IdentifierName("Empty")); - - return result; - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Plugins/ObservableBasedAsynchrony.cs b/Src/PCLMock.CodeGeneration_OLD/Plugins/ObservableBasedAsynchrony.cs deleted file mode 100644 index 7fcd868..0000000 --- a/Src/PCLMock.CodeGeneration_OLD/Plugins/ObservableBasedAsynchrony.cs +++ /dev/null @@ -1,172 +0,0 @@ -namespace PCLMock.CodeGeneration.Plugins -{ - using System; - using System.Linq; - using System.Reactive.Linq; - using Logging; - using Microsoft.CodeAnalysis; - - /// - /// A plugin that generates appropriate default return values for any member that uses observable-based - /// asynchrony. - /// - /// - /// - /// This plugin generates default return specifications for properties and methods that use observable-based asynchrony. - /// That is, they return an object of type . For such members, a specification is generated - /// such that an actual observable will be returned rather than returning . - /// - /// - /// The observable returned depends on the member type. For properties, an empty observable is returned (i.e. - /// Observable.Empty<T>. For methods, an observable with a single default item is returned (i.e. - /// Observable.Return<T>(default(T)). - /// - /// - /// The idea of these defaults is to best-guess the semantics of the observable. Typically, observables returned from - /// methods represent asynchronous operations, so the returned value represents the result of that operation. Observables - /// returned by properties, on the other hand, will typically have collection semantics. That is, they represent zero or - /// more asynchronously-received items. - /// - /// - /// Members for which specifications cannot be generated are ignored. This of course includes members that do not use - /// observable-based asynchrony, but also set-only properties, generic methods, and any members that return custom - /// subtypes. - /// - /// - public sealed class ObservableBasedAsynchrony : IPlugin - { - private static readonly Type logSource = typeof(ObservableBasedAsynchrony); - - public string Name => "Observable-based Asynchrony"; - - /// - public Compilation InitializeCompilation(Compilation compilation) => - compilation.AddReferences(MetadataReference.CreateFromFile(typeof(Observable).Assembly.Location)); - - /// - public SyntaxNode GetDefaultValueSyntax( - Context context, - MockBehavior behavior, - ISymbol symbol, - INamedTypeSymbol returnType) - { - if (behavior == MockBehavior.Loose) - { - return null; - } - - var observableInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.IObservable`1"); - - var observableType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Reactive.Linq.Observable"); - - if (observableInterfaceType == null) - { - context - .LogSink - .Warn(logSource, "Failed to resolve System.IObservable."); - return null; - } - - if (observableType == null) - { - context - .LogSink - .Warn(logSource, "Failed to resolve System.Reactive.Linq.Observable."); - return null; - } - - var isObservable = returnType.IsGenericType && returnType.ConstructedFrom == observableInterfaceType; - - if (!isObservable) - { - context - .LogSink - .Debug(logSource, "Ignoring symbol '{0}' because it does not return IObservable.", symbol); - return null; - } - - var observableInnerType = returnType.TypeArguments[0]; - SyntaxNode observableInvocation; - var propertySymbol = symbol as IPropertySymbol; - - if (propertySymbol != null) - { - // properties are given collection semantics by returning Observable.Empty() - observableInvocation = context - .SyntaxGenerator - .InvocationExpression( - context - .SyntaxGenerator - .WithTypeArguments( - context - .SyntaxGenerator - .MemberAccessExpression( - context - .SyntaxGenerator - .TypeExpression(observableType), - "Empty"), - context - .SyntaxGenerator - .TypeExpression(observableInnerType))); - } - else - { - // methods are given async operation semantics by returning Observable.Return(...) - observableInvocation = context - .SyntaxGenerator - .InvocationExpression( - context - .SyntaxGenerator - .WithTypeArguments( - context - .SyntaxGenerator - .MemberAccessExpression( - context - .SyntaxGenerator - .TypeExpression(observableType), - "Return"), - context - .SyntaxGenerator - .TypeExpression(observableInnerType)), - arguments: new[] - { - GetDefaultRecursive(context, behavior, symbol, observableInnerType) - }); - } - - return observableInvocation; - } - - private static SyntaxNode GetDefaultRecursive( - Context context, - MockBehavior behavior, - ISymbol symbol, - ITypeSymbol returnType) - { - var namedTypeSymbol = returnType as INamedTypeSymbol; - - if (namedTypeSymbol != null) - { - var recursiveDefault = context - .Plugins - .Select(plugin => plugin.GetDefaultValueSyntax(context, behavior, symbol, namedTypeSymbol)) - .Where(defaultValueSyntax => defaultValueSyntax != null) - .FirstOrDefault(); - - if (recursiveDefault != null) - { - return recursiveDefault; - } - } - - // recursive resolution not possible, so fallback to default(T) - return context.SyntaxGenerator.DefaultExpression(returnType); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Plugins/TaskBasedAsynchrony.cs b/Src/PCLMock.CodeGeneration_OLD/Plugins/TaskBasedAsynchrony.cs deleted file mode 100644 index bc71e23..0000000 --- a/Src/PCLMock.CodeGeneration_OLD/Plugins/TaskBasedAsynchrony.cs +++ /dev/null @@ -1,141 +0,0 @@ -namespace PCLMock.CodeGeneration.Plugins -{ - using System; - using System.Linq; - using Logging; - using Microsoft.CodeAnalysis; - - /// - /// A plugin that generates appropriate default return values for any member that uses TPL-based - /// asynchrony. - /// - /// - /// - /// This plugin generates default return specifications for properties and methods that use TPL-based asynchrony. - /// SThat is, they return an object of type or - /// . In either case, a specification is generated for the member - /// such that a task with a default value will be returned rather than returning . - /// - /// - /// For members that return non-generic tasks, the specification will return Task.FromResult(false). For - /// members that return generic tasks, the specification will return Task.FromResult(default(T)) where - /// T is the task's result type. - /// - /// - /// Members for which specifications cannot be generated are ignored. This of course includes members that do not use - /// TPL-based asynchrony, but also set-only properties, generic methods, and any members that return custom - /// subclasses. - /// - /// - public sealed class TaskBasedAsynchrony : IPlugin - { - private static readonly Type logSource = typeof(TaskBasedAsynchrony); - - public string Name => "Task-based Asynchrony"; - - /// - public Compilation InitializeCompilation(Compilation compilation) => - compilation; - - /// - public SyntaxNode GetDefaultValueSyntax( - Context context, - MockBehavior behavior, - ISymbol symbol, - INamedTypeSymbol returnType) - { - if (behavior == MockBehavior.Loose) - { - return null; - } - - var taskBaseType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Threading.Tasks.Task"); - - var genericTaskBaseType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Threading.Tasks.Task`1"); - - if (taskBaseType == null || genericTaskBaseType == null) - { - context - .LogSink - .Warn(logSource, "Failed to resolve Task classes."); - return null; - } - - var isGenericTask = returnType.IsGenericType && returnType.ConstructedFrom == genericTaskBaseType; - var isTask = returnType == taskBaseType; - - if (!isTask && !isGenericTask) - { - context - .LogSink - .Debug(logSource, "Ignoring symbol '{0}' because it does not return a Task or Task.", symbol); - return null; - } - - ITypeSymbol taskType = context - .SemanticModel - .Compilation - .GetSpecialType(SpecialType.System_Boolean); - - if (isGenericTask) - { - taskType = returnType.TypeArguments[0]; - } - - var fromResultInvocation = context - .SyntaxGenerator - .InvocationExpression( - context - .SyntaxGenerator - .WithTypeArguments( - context - .SyntaxGenerator - .MemberAccessExpression( - context - .SyntaxGenerator - .TypeExpression(taskBaseType), - "FromResult"), - context - .SyntaxGenerator - .TypeExpression(taskType)), - arguments: new[] - { - GetDefaultRecursive(context, behavior, symbol, taskType) - }); - - return fromResultInvocation; - } - - private static SyntaxNode GetDefaultRecursive( - Context context, - MockBehavior behavior, - ISymbol symbol, - ITypeSymbol returnType) - { - var namedTypeSymbol = returnType as INamedTypeSymbol; - - if (namedTypeSymbol != null) - { - var recursiveDefault = context - .Plugins - .Select(plugin => plugin.GetDefaultValueSyntax(context, behavior, symbol, namedTypeSymbol)) - .Where(defaultValueSyntax => defaultValueSyntax != null) - .FirstOrDefault(); - - if (recursiveDefault != null) - { - return recursiveDefault; - } - } - - // recursive resolution not possible, so fallback to default(T) - return context.SyntaxGenerator.DefaultExpression(returnType); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/Properties/AssemblyInfo.cs b/Src/PCLMock.CodeGeneration_OLD/Properties/AssemblyInfo.cs deleted file mode 100644 index 1dbe046..0000000 --- a/Src/PCLMock.CodeGeneration_OLD/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System; -using System.Reflection; -using System.Runtime.CompilerServices; - -[assembly: AssemblyTitle("PCLMock.CodeGeneration")] -[assembly: AssemblyDescription("Contains code generation logic for PCLMock.")] -[assembly: InternalsVisibleTo("PCLMock.CodeGeneration")] -[assembly: CLSCompliantAttribute(false)] \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/SyntaxGeneratorExtensions.cs b/Src/PCLMock.CodeGeneration_OLD/SyntaxGeneratorExtensions.cs deleted file mode 100644 index 7769c66..0000000 --- a/Src/PCLMock.CodeGeneration_OLD/SyntaxGeneratorExtensions.cs +++ /dev/null @@ -1,45 +0,0 @@ -namespace PCLMock.CodeGeneration -{ - using System; - using System.Linq; - using System.Text; - using Microsoft.CodeAnalysis; - using Microsoft.CodeAnalysis.CSharp; - using Microsoft.CodeAnalysis.CSharp.Syntax; - using Microsoft.CodeAnalysis.Editing; - using VB = Microsoft.CodeAnalysis.VisualBasic; - using VBSyntax = Microsoft.CodeAnalysis.VisualBasic.Syntax; - - // stuff that isn't on SyntaxGenerator that probably should be - // might PR some of this stuff back to Roslyn at some point - internal static class SyntaxGeneratorExtensions - { - public static SyntaxNode TypeOf(this SyntaxGenerator @this, SyntaxNode type, Language language) - { - switch (language) - { - case Language.CSharp: - return SyntaxFactory.TypeOfExpression((TypeSyntax)type); - case Language.VisualBasic: - return VB.SyntaxFactory.GetTypeExpression((VBSyntax.TypeSyntax)type); - default: - throw new NotSupportedException(); - } - } - - public static SyntaxNode WithLeadingComments(this SyntaxGenerator @this, SyntaxNode node, string comments, Language language) - { - comments = comments - .Split(new[] { "\r\n", "\n", "\r" }, StringSplitOptions.None) - .Select(x => language == Language.CSharp ? "// " + x : "' " + x) - .Aggregate(new StringBuilder(), (sb, next) => sb.AppendLine(next), x => x.ToString()); - - node = node.WithLeadingTrivia( - language == Language.CSharp - ? SyntaxFactory.ParseLeadingTrivia(comments) - : VB.SyntaxFactory.ParseLeadingTrivia(comments)); - - return node; - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/XmlBasedGenerator.cs b/Src/PCLMock.CodeGeneration_OLD/XmlBasedGenerator.cs deleted file mode 100644 index 350c612..0000000 --- a/Src/PCLMock.CodeGeneration_OLD/XmlBasedGenerator.cs +++ /dev/null @@ -1,68 +0,0 @@ -namespace PCLMock.CodeGeneration -{ - using System; - using System.Collections.Immutable; - using System.IO; - using System.Linq; - using System.Text; - using System.Threading.Tasks; - using System.Xml.Linq; - using Logging; - using Microsoft.CodeAnalysis; - using PCLMock.CodeGeneration.Models; - - public static class XmlBasedGenerator - { - private static readonly Type logSource = typeof(XmlBasedGenerator); - - public static string GenerateMocks( - ILogSink logSink, - string solutionPath, - string xmlPath, - string language) - { - var castLanguage = (Language)Enum.Parse(typeof(Language), language); - return GenerateMocks(logSink, castLanguage, solutionPath, xmlPath); - } - - public static string GenerateMocks( - ILogSink logSink, - Language language, - string solutionPath, - string xmlPath) - { - return GenerateMocksAsync(logSink, language, solutionPath, xmlPath) - .Result - .Select(x => x.ToFullString()) - .Aggregate(new StringBuilder(), (current, next) => current.AppendLine(next), x => x.ToString()); - } - - public async static Task> GenerateMocksAsync( - ILogSink logSink, - Language language, - string solutionPath, - string xmlPath) - { - if (!File.Exists(xmlPath)) - { - var message = $"XML input file '{xmlPath}' no found."; - logSink.Error(logSource, message); - throw new IOException(message); - } - - logSink.Info(logSource, "Loading XML input file '{0}'.", xmlPath); - - var document = XDocument.Load(xmlPath); - var configuration = Configuration.FromXDocument(logSink, document); - - return await Generator.GenerateMocksAsync( - logSink, - language, - solutionPath, - configuration.GetInterfacePredicate(), - configuration.GetNamespaceSelector(), - configuration.GetNameSelector(), - configuration.GetPlugins()); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration_OLD/app.config b/Src/PCLMock.CodeGeneration_OLD/app.config deleted file mode 100644 index 0f23969..0000000 --- a/Src/PCLMock.CodeGeneration_OLD/app.config +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Src/PCLMock.CodeGeneration_OLD/packages.config b/Src/PCLMock.CodeGeneration_OLD/packages.config deleted file mode 100644 index 9ee5e32..0000000 --- a/Src/PCLMock.CodeGeneration_OLD/packages.config +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Src/PCLMock.sln b/Src/PCLMock.sln index 1a40a64..403f23f 100644 --- a/Src/PCLMock.sln +++ b/Src/PCLMock.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26228.9 +VisualStudioVersion = 15.0.27004.2002 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PCLMock.UnitTests", "PCLMock.UnitTests\PCLMock.UnitTests.csproj", "{05115055-0BBC-49D5-8966-2B90325F2F08}" EndProject @@ -15,9 +15,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PCLMock.CodeGeneration.T4", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PCLMock.CodeGeneration.Console", "PCLMock.CodeGeneration.Console\PCLMock.CodeGeneration.Console.csproj", "{B56824C1-B58E-42FB-A528-518638A7DA15}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PCLMock.CodeGeneration", "PCLMock.CodeGeneration\PCLMock.CodeGeneration.csproj", "{49C812A9-5C76-4567-947F-B21A38FE4EC1}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PCLMock.CodeGeneration", "PCLMock.CodeGeneration\PCLMock.CodeGeneration.csproj", "{49C812A9-5C76-4567-947F-B21A38FE4EC1}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PCLMock", "PCLMock\PCLMock.csproj", "{2F34337F-05B9-4B38-A072-46409A3B2ACE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PCLMock", "PCLMock\PCLMock.csproj", "{2F34337F-05B9-4B38-A072-46409A3B2ACE}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -49,4 +49,7 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {EB004448-798E-4E0A-83D2-4913F9AE04F1} + EndGlobalSection EndGlobal From c94c30b66801076defbf981506a553dae22a24b0 Mon Sep 17 00:00:00 2001 From: Kent Boogaart Date: Thu, 10 May 2018 13:13:38 +1000 Subject: [PATCH 4/9] dependency upgrades --- .../PCLMock.CodeGeneration.Console.csproj | 4 ++-- .../Properties/launchSettings.json | 2 +- Src/PCLMock.CodeGeneration/Generator.cs | 9 ++++++++- Src/PCLMock.CodeGeneration/PCLMock.CodeGeneration.csproj | 8 ++++---- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Src/PCLMock.CodeGeneration.Console/PCLMock.CodeGeneration.Console.csproj b/Src/PCLMock.CodeGeneration.Console/PCLMock.CodeGeneration.Console.csproj index 8e450a5..8482805 100644 --- a/Src/PCLMock.CodeGeneration.Console/PCLMock.CodeGeneration.Console.csproj +++ b/Src/PCLMock.CodeGeneration.Console/PCLMock.CodeGeneration.Console.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/Src/PCLMock.CodeGeneration.Console/Properties/launchSettings.json b/Src/PCLMock.CodeGeneration.Console/Properties/launchSettings.json index 326623c..8a54b78 100644 --- a/Src/PCLMock.CodeGeneration.Console/Properties/launchSettings.json +++ b/Src/PCLMock.CodeGeneration.Console/Properties/launchSettings.json @@ -3,7 +3,7 @@ "PCLMock.CodeGeneration.Console": { "commandName": "Project", "commandLineArgs": "-SolutionFile QUT.Core.sln -ConfigurationFile .\\UnitTests\\Mocks.xml -OutputFile .\\UnitTests\\Mocks.g.cs -Verbose true", - "workingDirectory": "C:\\Users\\Kent\\Repository\\QUT\\Src\\" + "workingDirectory": "C:\\Users\\kent\\Repository\\QUT\\Src" } } } \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration/Generator.cs b/Src/PCLMock.CodeGeneration/Generator.cs index bf72e29..8f04722 100644 --- a/Src/PCLMock.CodeGeneration/Generator.cs +++ b/Src/PCLMock.CodeGeneration/Generator.cs @@ -9,6 +9,7 @@ using Buildalyzer; using Buildalyzer.Workspaces; using Logging; + using Microsoft.Build.Framework; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -38,7 +39,13 @@ public async static Task> GenerateMocksAsync( IImmutableList plugins) { var buildalyzerLogFactory = new BuildalyzerLogFactory(logSink); - var manager = new AnalyzerManager(initialPath, loggerFactory: buildalyzerLogFactory); + var options = new AnalyzerManagerOptions + { + CleanBeforeCompile = true, + LoggerFactory = buildalyzerLogFactory, + LoggerVerbosity = LoggerVerbosity.Detailed, + }; + var manager = new AnalyzerManager(initialPath, options); var solution = manager.GetWorkspace().CurrentSolution; return await GenerateMocksAsync( diff --git a/Src/PCLMock.CodeGeneration/PCLMock.CodeGeneration.csproj b/Src/PCLMock.CodeGeneration/PCLMock.CodeGeneration.csproj index b7c239b..ccf4378 100644 --- a/Src/PCLMock.CodeGeneration/PCLMock.CodeGeneration.csproj +++ b/Src/PCLMock.CodeGeneration/PCLMock.CodeGeneration.csproj @@ -6,12 +6,12 @@ - - + + - - + + From 945a00380292e6607e1d3d9ba90c2716b4e8bb3e Mon Sep 17 00:00:00 2001 From: Kent Boogaart Date: Thu, 10 May 2018 16:09:42 +1000 Subject: [PATCH 5/9] Reinstate unit tests --- .../DuplicateMemberOutput_CSharp.txt | 2 +- .../GenericInterfaceOutput_CSharp.txt | 5 +- .../IndexersOutput_CSharp.txt | 8 +- .../InheritingInterfaceOutput_CSharp.txt | 6 +- ...terfaceWithGenericMethodsOutput_CSharp.txt | 8 +- .../InternalInterfaceOutput_CSharp.txt | 12 +- .../NameClashOutput_CSharp.txt | 14 +- .../NonMockableMembersOutput_CSharp.txt | 4 +- .../OutAndRefOutput_CSharp.txt | 40 +- .../PartialInterfaceOutput_CSharp.txt | 6 +- .../SimpleInterfaceOutput_CSharp.txt | 12 +- .../CollectionsOutput_CSharp.txt | 44 +- .../DictionariesOutput_CSharp.txt | 52 +- .../EnumerablesOutput_CSharp.txt | 30 +- .../ImmutableDictionariesOutput_CSharp.txt | 36 +- .../ImmutableListsOutput_CSharp.txt | 54 +- .../ImmutableQueuesOutput_CSharp.txt | 32 +- .../ImmutableSetsOutput_CSharp.txt | 46 +- .../ImmutableStacksOutput_CSharp.txt | 32 +- .../ListsOutput_CSharp.txt | 52 +- .../RecursiveOutput_CSharp.txt | 6 +- .../SetsOutput_CSharp.txt | 54 +- .../DisposablesOutput_CSharp.txt | 8 +- .../GenericInterfaceOutput_CSharp.txt | 4 +- .../NonObservableBasedOutput_CSharp.txt | 18 +- .../ObservableBasedOutput_CSharp.txt | 30 +- .../RecursiveOutput_CSharp.txt | 6 +- .../GenericInterfaceOutput_CSharp.txt | 6 +- .../GenericTaskOutput_CSharp.txt | 30 +- .../NonGenericTaskOutput_CSharp.txt | 18 +- .../NonTaskBasedOutput_CSharp.txt | 18 +- .../RecursiveOutput_CSharp.txt | 6 +- .../PCLMock.UnitTests.csproj | 437 +----- ...UnitTests.netstandard2.0.v3.ncrunchproject | 5 + .../Visitors/ArgumentsVisitorFixture.cs | 2 +- .../IsAnyArgumentFilterFixture.cs | 59 + .../IsArgumentFilterFixture.cs | 61 + .../IsBetweenArgumentFilterFixture.cs | 85 ++ .../IsGreaterThanArgumentFilterFixture.cs | 62 + ...eaterThanOrEqualToArgumentFilterFixture.cs | 62 + .../IsInArgumentFilterFixture.cs | 66 + .../IsLikeArgumentFilterFixture.cs | 50 + .../IsNullArgumentFilterFixture.cs | 44 + .../IsOfTypeArgumentFilterFixture.cs | 45 + .../LogicalNotArgumentFilterFixture.cs | 41 + .../MatchesArgumentFilterFixture.cs | 57 + .../CodeGeneration/GeneratorFixture.cs | 91 ++ .../DuplicateMemberInput_CSharp.txt | 29 + .../DuplicateMemberOutput_CSharp.txt | 38 + .../GenericInterfaceInput_CSharp.txt | 14 + .../GenericInterfaceOutput_CSharp.txt | 46 + .../IndexersInput_CSharp.txt | 18 + .../IndexersOutput_CSharp.txt | 57 + .../InheritingInterfaceInput_CSharp.txt | 9 + .../InheritingInterfaceOutput_CSharp.txt | 41 + ...nterfaceWithGenericMethodsInput_CSharp.txt | 14 + ...terfaceWithGenericMethodsOutput_CSharp.txt | 53 + .../InternalInterfaceInput_CSharp.txt | 26 + .../InternalInterfaceOutput_CSharp.txt | 69 + .../NameClashInput_CSharp.txt | 16 + .../NameClashOutput_CSharp.txt | 58 + .../NonMockableMembersInput_CSharp.txt | 13 + .../NonMockableMembersOutput_CSharp.txt | 41 + .../OutAndRefInput_CSharp.txt | 12 + .../OutAndRefOutput_CSharp.txt | 67 + .../PartialInterfaceInput_CSharp.txt | 15 + .../PartialInterfaceOutput_CSharp.txt | 44 + .../SimpleInterfaceInput_CSharp.txt | 26 + .../SimpleInterfaceInput_VisualBasic.txt | 0 .../SimpleInterfaceOutput_CSharp.txt | 69 + .../SimpleInterfaceOutput_VisualBasic.txt | 0 .../Models/ConfigurationFixture.cs | 46 + .../ConfigurationFixtureResources/Input.txt | 96 ++ .../Plugins/CollectionsFixture.cs | 102 ++ .../CollectionsInput_CSharp.txt | 52 + .../CollectionsOutput_CSharp.txt | 217 +++ .../DictionariesInput_CSharp.txt | 52 + .../DictionariesOutput_CSharp.txt | 265 ++++ .../EnumerablesInput_CSharp.txt | 47 + .../EnumerablesOutput_CSharp.txt | 172 +++ .../ImmutableDictionariesInput_CSharp.txt | 47 + .../ImmutableDictionariesOutput_CSharp.txt | 216 +++ .../ImmutableListsInput_CSharp.txt | 47 + .../ImmutableListsOutput_CSharp.txt | 244 +++ .../ImmutableQueuesInput_CSharp.txt | 47 + .../ImmutableQueuesOutput_CSharp.txt | 193 +++ .../ImmutableSetsInput_CSharp.txt | 47 + .../ImmutableSetsOutput_CSharp.txt | 246 +++ .../ImmutableStacksInput_CSharp.txt | 47 + .../ImmutableStacksOutput_CSharp.txt | 193 +++ .../ListsInput_CSharp.txt | 52 + .../ListsOutput_CSharp.txt | 240 +++ .../RecursiveInput_CSharp.txt | 10 + .../RecursiveOutput_CSharp.txt | 45 + .../SetsInput_CSharp.txt | 47 + .../SetsOutput_CSharp.txt | 258 ++++ .../Plugins/DisposablesFixture.cs | 79 + .../DisposablesInput_CSharp.txt | 35 + .../DisposablesOutput_CSharp.txt | 77 + .../ObservableBasedAsynchronyFixture.cs | 82 + .../GenericInterfaceInput_CSharp.txt | 11 + .../GenericInterfaceOutput_CSharp.txt | 43 + .../NonObservableBasedInput_CSharp.txt | 34 + .../NonObservableBasedOutput_CSharp.txt | 82 + .../ObservableBasedInput_CSharp.txt | 40 + .../ObservableBasedOutput_CSharp.txt | 87 ++ .../RecursiveInput_CSharp.txt | 6 + .../RecursiveOutput_CSharp.txt | 34 + .../Plugins/TaskBasedAsynchronyFixture.cs | 82 + .../GenericInterfaceInput_CSharp.txt | 11 + .../GenericInterfaceOutput_CSharp.txt | 43 + .../GenericTaskInput_CSharp.txt | 40 + .../GenericTaskOutput_CSharp.txt | 87 ++ .../NonGenericTaskInput_CSharp.txt | 40 + .../NonGenericTaskOutput_CSharp.txt | 87 ++ .../NonTaskBasedInput_CSharp.txt | 34 + .../NonTaskBasedOutput_CSharp.txt | 82 + .../RecursiveInput_CSharp.txt | 6 + .../RecursiveOutput_CSharp.txt | 34 + Src/PCLMock.UnitTests_OLD/Extensions.cs | 11 + Src/PCLMock.UnitTests_OLD/MockBaseFixture.cs | 1328 +++++++++++++++++ .../PCLMock.UnitTests.csproj | 400 +++++ .../PCLMock.UnitTests.v3.ncrunchproject | 0 .../Properties/AssemblyInfo.cs | 6 + .../Utility/ObjectExtensionsFixture.cs | 72 + .../Visitors/ArgumentFilterVisitorFixture.cs | 87 ++ .../Visitors/ArgumentFiltersVisitorFixture.cs | 67 + .../Visitors/ArgumentsVisitorFixture.cs | 59 + .../Visitors/SelectorStringVisitorFixture.cs | 101 ++ .../Visitors/ValueExtractorFixture.cs | 139 ++ .../app.config | 0 .../packages.config | 0 Src/PCLMock/Visitors/ArgumentFilterVisitor.cs | 2 +- 133 files changed, 8350 insertions(+), 747 deletions(-) create mode 100644 Src/PCLMock.UnitTests/PCLMock.UnitTests.netstandard2.0.v3.ncrunchproject create mode 100644 Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsAnyArgumentFilterFixture.cs create mode 100644 Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsArgumentFilterFixture.cs create mode 100644 Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsBetweenArgumentFilterFixture.cs create mode 100644 Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsGreaterThanArgumentFilterFixture.cs create mode 100644 Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsGreaterThanOrEqualToArgumentFilterFixture.cs create mode 100644 Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsInArgumentFilterFixture.cs create mode 100644 Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsLikeArgumentFilterFixture.cs create mode 100644 Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsNullArgumentFilterFixture.cs create mode 100644 Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsOfTypeArgumentFilterFixture.cs create mode 100644 Src/PCLMock.UnitTests_OLD/ArgumentFilters/LogicalNotArgumentFilterFixture.cs create mode 100644 Src/PCLMock.UnitTests_OLD/ArgumentFilters/MatchesArgumentFilterFixture.cs create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixture.cs create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/DuplicateMemberInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/DuplicateMemberOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/GenericInterfaceInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/GenericInterfaceOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/IndexersInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/IndexersOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InheritingInterfaceInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InheritingInterfaceOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InterfaceWithGenericMethodsInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InterfaceWithGenericMethodsOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InternalInterfaceInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InternalInterfaceOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NameClashInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NameClashOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NonMockableMembersInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NonMockableMembersOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/OutAndRefInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/OutAndRefOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/PartialInterfaceInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/PartialInterfaceOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceInput_CSharp.txt rename Src/{PCLMock.UnitTests => PCLMock.UnitTests_OLD}/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceInput_VisualBasic.txt (100%) create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceOutput_CSharp.txt rename Src/{PCLMock.UnitTests => PCLMock.UnitTests_OLD}/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceOutput_VisualBasic.txt (100%) create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Models/ConfigurationFixture.cs create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Models/ConfigurationFixtureResources/Input.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixture.cs create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/CollectionsInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/CollectionsOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/DictionariesInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/DictionariesOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/EnumerablesInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/EnumerablesOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableDictionariesInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableDictionariesOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableListsInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableListsOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableQueuesInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableQueuesOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableSetsInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableSetsOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableStacksInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableStacksOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ListsInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ListsOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/RecursiveInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/RecursiveOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/SetsInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/SetsOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/DisposablesFixture.cs create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/DisposablesFixtureResources/DisposablesInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/DisposablesFixtureResources/DisposablesOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixture.cs create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/GenericInterfaceInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/NonObservableBasedInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/NonObservableBasedOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/RecursiveInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixture.cs create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericInterfaceInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericTaskInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericTaskOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonGenericTaskInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonGenericTaskOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonTaskBasedInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonTaskBasedOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/RecursiveInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests_OLD/Extensions.cs create mode 100644 Src/PCLMock.UnitTests_OLD/MockBaseFixture.cs create mode 100644 Src/PCLMock.UnitTests_OLD/PCLMock.UnitTests.csproj rename Src/{PCLMock.UnitTests => PCLMock.UnitTests_OLD}/PCLMock.UnitTests.v3.ncrunchproject (100%) create mode 100644 Src/PCLMock.UnitTests_OLD/Properties/AssemblyInfo.cs create mode 100644 Src/PCLMock.UnitTests_OLD/Utility/ObjectExtensionsFixture.cs create mode 100644 Src/PCLMock.UnitTests_OLD/Visitors/ArgumentFilterVisitorFixture.cs create mode 100644 Src/PCLMock.UnitTests_OLD/Visitors/ArgumentFiltersVisitorFixture.cs create mode 100644 Src/PCLMock.UnitTests_OLD/Visitors/ArgumentsVisitorFixture.cs create mode 100644 Src/PCLMock.UnitTests_OLD/Visitors/SelectorStringVisitorFixture.cs create mode 100644 Src/PCLMock.UnitTests_OLD/Visitors/ValueExtractorFixture.cs rename Src/{PCLMock.UnitTests => PCLMock.UnitTests_OLD}/app.config (100%) rename Src/{PCLMock.UnitTests => PCLMock.UnitTests_OLD}/packages.config (100%) diff --git a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/DuplicateMemberOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/DuplicateMemberOutput_CSharp.txt index dbeedc2..ddc3095 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/DuplicateMemberOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/DuplicateMemberOutput_CSharp.txt @@ -4,7 +4,7 @@ [System.Runtime.CompilerServices.CompilerGenerated] public partial class Mock : global::PCLMock.MockBase, global::IThirdInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); diff --git a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/GenericInterfaceOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/GenericInterfaceOutput_CSharp.txt index 72e3bca..d8c1971 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/GenericInterfaceOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/GenericInterfaceOutput_CSharp.txt @@ -2,9 +2,10 @@ { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - public partial class Mock : global::PCLMock.MockBase>, global::IGenericInterface where TFirst : global::System.IComparable, new ()where TSecond : struct + public partial class Mock : global::PCLMock.MockBase>, global::IGenericInterface where TFirst : global::System.IComparable, new() + where TSecond : struct { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); diff --git a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/IndexersOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/IndexersOutput_CSharp.txt index 16d88d4..936e514 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/IndexersOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/IndexersOutput_CSharp.txt @@ -4,7 +4,7 @@ [System.Runtime.CompilerServices.CompilerGenerated] public partial class Mock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -25,7 +25,7 @@ partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); - public System.Int32 this[System.Int32 i] + public global::System.Int32 this[global::System.Int32 i] { get { @@ -33,7 +33,7 @@ } } - public System.String this[System.Int32 i, System.Single j] + public global::System.String this[global::System.Int32 i, global::System.Single j] { get { @@ -41,7 +41,7 @@ } } - public System.String this[System.Int32 i, System.Single j, System.Double d] + public global::System.String this[global::System.Int32 i, global::System.Single j, global::System.Double d] { get { diff --git a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/InheritingInterfaceOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/InheritingInterfaceOutput_CSharp.txt index 430dc63..5ce2653 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/InheritingInterfaceOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/InheritingInterfaceOutput_CSharp.txt @@ -4,7 +4,7 @@ [System.Runtime.CompilerServices.CompilerGenerated] public partial class Mock : global::PCLMock.MockBase, global::IInheritingInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -25,7 +25,7 @@ partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); - public System.Int32 SomeProperty + public global::System.Int32 SomeProperty { get { @@ -33,7 +33,7 @@ } } - public System.Object Clone() + public global::System.Object Clone() { return this.Apply(x => x.Clone()); } diff --git a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/InterfaceWithGenericMethodsOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/InterfaceWithGenericMethodsOutput_CSharp.txt index 70d3674..c65ec9e 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/InterfaceWithGenericMethodsOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/InterfaceWithGenericMethodsOutput_CSharp.txt @@ -4,7 +4,7 @@ [System.Runtime.CompilerServices.CompilerGenerated] public partial class Mock : global::PCLMock.MockBase, global::IInterfaceWithGenericMethods { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -35,7 +35,7 @@ return this.Apply(x => x.NonVoidMethodWithGenericParameter()); } - public void VoidMethodWithGenericArguments(TFirst first, TSecond second, TThird third, System.String somethingElse) + public void VoidMethodWithGenericArguments(TFirst first, TSecond second, TThird third, global::System.String somethingElse) { this.Apply(x => x.VoidMethodWithGenericArguments(first, second, third, somethingElse)); } @@ -45,7 +45,9 @@ return this.Apply(x => x.NonVoidMethodWithGenericArguments(input)); } - public TSecond MethodWithTypeConstraints(TFirst input, System.Int32 option)where TFirst : IComparable, new ()where TSecond : struct + public TSecond MethodWithTypeConstraints(TFirst input, global::System.Int32 option) + where TFirst : IComparable, new() + where TSecond : struct { return this.Apply(x => x.MethodWithTypeConstraints(input, option)); } diff --git a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/InternalInterfaceOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/InternalInterfaceOutput_CSharp.txt index 7b1e5cc..e337cde 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/InternalInterfaceOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/InternalInterfaceOutput_CSharp.txt @@ -4,7 +4,7 @@ [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase, global::IInternalInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -25,7 +25,7 @@ partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); - public System.Int32 GetProperty + public global::System.Int32 GetProperty { get { @@ -33,7 +33,7 @@ } } - public System.Int32 GetSetProperty + public global::System.Int32 GetSetProperty { get { @@ -51,17 +51,17 @@ this.Apply(x => x.VoidMethod()); } - public void VoidMethodWithArguments(System.Int32 i, System.String s) + public void VoidMethodWithArguments(global::System.Int32 i, global::System.String s) { this.Apply(x => x.VoidMethodWithArguments(i, s)); } - public System.String NonVoidMethod() + public global::System.String NonVoidMethod() { return this.Apply(x => x.NonVoidMethod()); } - public System.String NonVoidMethodWithArguments(System.Int32 i, System.String s) + public global::System.String NonVoidMethodWithArguments(global::System.Int32 i, global::System.String s) { return this.Apply(x => x.NonVoidMethodWithArguments(i, s)); } diff --git a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/NameClashOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/NameClashOutput_CSharp.txt index e7f6409..3d3bdf8 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/NameClashOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/NameClashOutput_CSharp.txt @@ -4,7 +4,7 @@ [System.Runtime.CompilerServices.CompilerGenerated] public partial class Mock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -25,7 +25,7 @@ partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); - public System.Int32 this[System.Int32 x] + public global::System.Int32 this[global::System.Int32 x] { get { @@ -38,20 +38,20 @@ } } - public void SomeMethod(System.Int32 x) + public void SomeMethod(global::System.Int32 x) { this.Apply(_x => _x.SomeMethod(x)); } - public void SomeMethod(System.Int32 x, System.Int32 _x) + public void SomeMethod(global::System.Int32 x, global::System.Int32 _x) { this.Apply(__x => __x.SomeMethod(x, _x)); } - public void SomeMethod(out System.Single f, System.Single _f) + public void SomeMethod(out global::System.Single f, global::System.Single _f) { - System.Single __f; - f = (this.GetOutParameterValue(x => x.SomeMethod(out __f, _f), 0)); + global::System.Single __f; + f = (this.GetOutParameterValue(x => x.SomeMethod(out __f, _f), 0)); this.Apply(x => x.SomeMethod(out __f, _f)); } } diff --git a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/NonMockableMembersOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/NonMockableMembersOutput_CSharp.txt index f238c17..5f1292b 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/NonMockableMembersOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/NonMockableMembersOutput_CSharp.txt @@ -4,7 +4,7 @@ [System.Runtime.CompilerServices.CompilerGenerated] public partial class Mock : global::PCLMock.MockBase, global::IInterfaceWithNonMockableMembers { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -25,7 +25,7 @@ partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); - public System.Int32 SomeProperty + public global::System.Int32 SomeProperty { get { diff --git a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/OutAndRefOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/OutAndRefOutput_CSharp.txt index 44e322d..e736939 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/OutAndRefOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/OutAndRefOutput_CSharp.txt @@ -4,7 +4,7 @@ [System.Runtime.CompilerServices.CompilerGenerated] public partial class Mock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -25,42 +25,42 @@ partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); - public void SomeMethod(out System.Int32 i) + public void SomeMethod(out global::System.Int32 i) { - System.Int32 _i; - i = (this.GetOutParameterValue(x => x.SomeMethod(out _i), 0)); + global::System.Int32 _i; + i = (this.GetOutParameterValue(x => x.SomeMethod(out _i), 0)); this.Apply(x => x.SomeMethod(out _i)); } - public void SomeMethod(out System.Double d, System.Int32 i) + public void SomeMethod(out global::System.Double d, global::System.Int32 i) { - System.Double _d; - d = (this.GetOutParameterValue(x => x.SomeMethod(out _d, i), 0)); + global::System.Double _d; + d = (this.GetOutParameterValue(x => x.SomeMethod(out _d, i), 0)); this.Apply(x => x.SomeMethod(out _d, i)); } - public void SomeMethod(System.Int32 i, out System.Double d) + public void SomeMethod(global::System.Int32 i, out global::System.Double d) { - System.Double _d; - d = (this.GetOutParameterValue(x => x.SomeMethod(i, out _d), 1)); + global::System.Double _d; + d = (this.GetOutParameterValue(x => x.SomeMethod(i, out _d), 1)); this.Apply(x => x.SomeMethod(i, out _d)); } - public void SomeMethod(ref System.Int32 i, out System.String s) + public void SomeMethod(ref global::System.Int32 i, out global::System.String s) { - var _i = default (System.Int32); - System.String _s; - i = (this.GetRefParameterValue(x => x.SomeMethod(ref _i, out _s), 0)); - s = (this.GetOutParameterValue(x => x.SomeMethod(ref _i, out _s), 1)); + var _i = default(global::System.Int32); + global::System.String _s; + i = (this.GetRefParameterValue(x => x.SomeMethod(ref _i, out _s), 0)); + s = (this.GetOutParameterValue(x => x.SomeMethod(ref _i, out _s), 1)); this.Apply(x => x.SomeMethod(ref _i, out _s)); } - public void SomeMethod(ref System.Int32 i, out System.String s, System.Double d) + public void SomeMethod(ref global::System.Int32 i, out global::System.String s, global::System.Double d) { - var _i = default (System.Int32); - System.String _s; - i = (this.GetRefParameterValue(x => x.SomeMethod(ref _i, out _s, d), 0)); - s = (this.GetOutParameterValue(x => x.SomeMethod(ref _i, out _s, d), 1)); + var _i = default(global::System.Int32); + global::System.String _s; + i = (this.GetRefParameterValue(x => x.SomeMethod(ref _i, out _s, d), 0)); + s = (this.GetOutParameterValue(x => x.SomeMethod(ref _i, out _s, d), 1)); this.Apply(x => x.SomeMethod(ref _i, out _s, d)); } } diff --git a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/PartialInterfaceOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/PartialInterfaceOutput_CSharp.txt index 7c12142..a93ebdf 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/PartialInterfaceOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/PartialInterfaceOutput_CSharp.txt @@ -4,7 +4,7 @@ [System.Runtime.CompilerServices.CompilerGenerated] public partial class Mock : global::PCLMock.MockBase, global::IPartialInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -25,7 +25,7 @@ partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); - public System.Int32 Property1 + public global::System.Int32 Property1 { get { @@ -33,7 +33,7 @@ } } - public System.Int32 Property2 + public global::System.Int32 Property2 { get { diff --git a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceOutput_CSharp.txt index 63fb4a9..9bd310d 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceOutput_CSharp.txt @@ -4,7 +4,7 @@ [System.Runtime.CompilerServices.CompilerGenerated] public partial class Mock : global::PCLMock.MockBase, global::ISimpleInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -25,7 +25,7 @@ partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); - public System.Int32 GetProperty + public global::System.Int32 GetProperty { get { @@ -33,7 +33,7 @@ } } - public System.Int32 GetSetProperty + public global::System.Int32 GetSetProperty { get { @@ -51,17 +51,17 @@ this.Apply(x => x.VoidMethod()); } - public void VoidMethodWithArguments(System.Int32 i, System.String s) + public void VoidMethodWithArguments(global::System.Int32 i, global::System.String s) { this.Apply(x => x.VoidMethodWithArguments(i, s)); } - public System.String NonVoidMethod() + public global::System.String NonVoidMethod() { return this.Apply(x => x.NonVoidMethod()); } - public System.String NonVoidMethodWithArguments(System.Int32 i, System.String s) + public global::System.String NonVoidMethodWithArguments(global::System.Int32 i, global::System.String s) { return this.Apply(x => x.NonVoidMethodWithArguments(i, s)); } diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/CollectionsOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/CollectionsOutput_CSharp.txt index cc8d809..d110a16 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/CollectionsOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/CollectionsOutput_CSharp.txt @@ -12,7 +12,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase>, global::ICustomCollection { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -43,22 +43,22 @@ namespace The.Namespace this.Apply(x => x.Clear()); } - public System.Boolean Contains(T item) + public global::System.Boolean Contains(T item) { return this.Apply(x => x.Contains(item)); } - public void CopyTo(T[] array, System.Int32 arrayIndex) + public void CopyTo(T[] array, global::System.Int32 arrayIndex) { this.Apply(x => x.CopyTo(array, arrayIndex)); } - public System.Boolean Remove(T item) + public global::System.Boolean Remove(T item) { return this.Apply(x => x.Remove(item)); } - public System.Int32 Count + public global::System.Int32 Count { get { @@ -66,7 +66,7 @@ namespace The.Namespace } } - public System.Boolean IsReadOnly + public global::System.Boolean IsReadOnly { get { @@ -86,7 +86,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -99,10 +99,10 @@ namespace The.Namespace private void ConfigureBehaviorGenerated() { - this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.List()); - this.When(x => x.SomeReadOnlyProperty).Return(new global::System.Collections.Generic.List()); - this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.List()); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.List()); + this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.List()); + this.When(x => x.SomeReadOnlyProperty).Return(new global::System.Collections.Generic.List()); + this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.List()); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.List()); } private void ConfigureLooseBehaviorGenerated() @@ -111,7 +111,7 @@ namespace The.Namespace partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); - public global::System.Collections.Generic.ICollection SomeProperty + public global::System.Collections.Generic.ICollection SomeProperty { get { @@ -119,7 +119,7 @@ namespace The.Namespace } } - public global::System.Collections.Generic.IReadOnlyCollection SomeReadOnlyProperty + public global::System.Collections.Generic.IReadOnlyCollection SomeReadOnlyProperty { get { @@ -127,17 +127,17 @@ namespace The.Namespace } } - public global::System.Collections.Generic.ICollection SomeMethod() + public global::System.Collections.Generic.ICollection SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public global::System.Collections.Generic.ICollection SomeMethod(System.Int32 i, System.Single f) + public global::System.Collections.Generic.ICollection SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } - public global::System.Collections.Generic.ICollection SomeGenericMethod() + public global::System.Collections.Generic.ICollection SomeGenericMethod() { return this.Apply(x => x.SomeGenericMethod()); } @@ -147,7 +147,7 @@ namespace The.Namespace return this.Apply(x => x.SomeOtherGenericMethod()); } - public global::ICustomCollection SomeCustomProperty + public global::ICustomCollection SomeCustomProperty { get { @@ -155,12 +155,12 @@ namespace The.Namespace } } - public global::ICustomCollection SomeMethod() + public global::ICustomCollection SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public global::ICustomCollection SomeMethod(System.Int32 i, System.Single f) + public global::ICustomCollection SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } @@ -172,7 +172,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -187,7 +187,7 @@ namespace The.Namespace { this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.List()); this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.List()); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.List()); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.List()); } private void ConfigureLooseBehaviorGenerated() @@ -209,7 +209,7 @@ namespace The.Namespace return this.Apply(x => x.SomeMethod()); } - public global::System.Collections.Generic.ICollection SomeMethod(System.Int32 i, System.Single f) + public global::System.Collections.Generic.ICollection SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/DictionariesOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/DictionariesOutput_CSharp.txt index cbac9bc..f4dfdf3 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/DictionariesOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/DictionariesOutput_CSharp.txt @@ -12,7 +12,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase>, global::ICustomDictionary { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -35,7 +35,7 @@ namespace The.Namespace partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); - public System.Boolean ContainsKey(TKey key) + public global::System.Boolean ContainsKey(TKey key) { return this.Apply(x => x.ContainsKey(key)); } @@ -45,12 +45,12 @@ namespace The.Namespace this.Apply(x => x.Add(key, value)); } - public System.Boolean Remove(TKey key) + public global::System.Boolean Remove(TKey key) { return this.Apply(x => x.Remove(key)); } - public System.Boolean TryGetValue(TKey key, out TValue value) + public global::System.Boolean TryGetValue(TKey key, out TValue value) { TValue _value; value = (this.GetOutParameterValue(x => x.TryGetValue(key, out _value), 1)); @@ -96,22 +96,22 @@ namespace The.Namespace this.Apply(x => x.Clear()); } - public System.Boolean Contains(global::System.Collections.Generic.KeyValuePair item) + public global::System.Boolean Contains(global::System.Collections.Generic.KeyValuePair item) { return this.Apply(x => x.Contains(item)); } - public void CopyTo(global::System.Collections.Generic.KeyValuePair[] array, System.Int32 arrayIndex) + public void CopyTo(global::System.Collections.Generic.KeyValuePair[] array, global::System.Int32 arrayIndex) { this.Apply(x => x.CopyTo(array, arrayIndex)); } - public System.Boolean Remove(global::System.Collections.Generic.KeyValuePair item) + public global::System.Boolean Remove(global::System.Collections.Generic.KeyValuePair item) { return this.Apply(x => x.Remove(item)); } - public System.Int32 Count + public global::System.Int32 Count { get { @@ -119,7 +119,7 @@ namespace The.Namespace } } - public System.Boolean IsReadOnly + public global::System.Boolean IsReadOnly { get { @@ -134,7 +134,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -147,10 +147,10 @@ namespace The.Namespace private void ConfigureBehaviorGenerated() { - this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.Dictionary()); - this.When(x => x.SomeReadOnlyProperty).Return(new global::System.Collections.Generic.Dictionary()); - this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.Dictionary()); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.Dictionary()); + this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.Dictionary()); + this.When(x => x.SomeReadOnlyProperty).Return(new global::System.Collections.Generic.Dictionary()); + this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.Dictionary()); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.Dictionary()); } private void ConfigureLooseBehaviorGenerated() @@ -159,7 +159,7 @@ namespace The.Namespace partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); - public global::System.Collections.Generic.IDictionary SomeProperty + public global::System.Collections.Generic.IDictionary SomeProperty { get { @@ -167,7 +167,7 @@ namespace The.Namespace } } - public global::System.Collections.Generic.IReadOnlyDictionary SomeReadOnlyProperty + public global::System.Collections.Generic.IReadOnlyDictionary SomeReadOnlyProperty { get { @@ -175,27 +175,27 @@ namespace The.Namespace } } - public global::System.Collections.Generic.IDictionary SomeMethod() + public global::System.Collections.Generic.IDictionary SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public global::System.Collections.Generic.IDictionary SomeMethod(System.Int32 i, System.Single f) + public global::System.Collections.Generic.IDictionary SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } - public global::System.Collections.Generic.IDictionary SomeGenericMethod() + public global::System.Collections.Generic.IDictionary SomeGenericMethod() { return this.Apply(x => x.SomeGenericMethod()); } - public global::System.Collections.Generic.IDictionary SomeOtherGenericMethod() + public global::System.Collections.Generic.IDictionary SomeOtherGenericMethod() { return this.Apply(x => x.SomeOtherGenericMethod()); } - public global::ICustomDictionary SomeCustomProperty + public global::ICustomDictionary SomeCustomProperty { get { @@ -203,12 +203,12 @@ namespace The.Namespace } } - public global::ICustomDictionary SomeMethod() + public global::ICustomDictionary SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public global::ICustomDictionary SomeMethod(System.Int32 i, System.Single f) + public global::ICustomDictionary SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } @@ -220,7 +220,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -235,7 +235,7 @@ namespace The.Namespace { this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.Dictionary()); this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.Dictionary()); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.Dictionary()); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.Dictionary()); } private void ConfigureLooseBehaviorGenerated() @@ -257,7 +257,7 @@ namespace The.Namespace return this.Apply(x => x.SomeMethod()); } - public global::System.Collections.Generic.IDictionary SomeMethod(System.Int32 i, System.Single f) + public global::System.Collections.Generic.IDictionary SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/EnumerablesOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/EnumerablesOutput_CSharp.txt index b446501..e910ee1 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/EnumerablesOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/EnumerablesOutput_CSharp.txt @@ -12,7 +12,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase>, global::ICustomEnumerable { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -50,7 +50,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -63,9 +63,9 @@ namespace The.Namespace private void ConfigureBehaviorGenerated() { - this.When(x => x.SomeProperty).Return(global::System.Linq.Enumerable.Empty()); - this.When(x => x.SomeMethod()).Return(global::System.Linq.Enumerable.Empty()); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Linq.Enumerable.Empty()); + this.When(x => x.SomeProperty).Return(global::System.Linq.Enumerable.Empty()); + this.When(x => x.SomeMethod()).Return(global::System.Linq.Enumerable.Empty()); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Linq.Enumerable.Empty()); } private void ConfigureLooseBehaviorGenerated() @@ -74,7 +74,7 @@ namespace The.Namespace partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); - public global::System.Collections.Generic.IEnumerable SomeProperty + public global::System.Collections.Generic.IEnumerable SomeProperty { get { @@ -82,17 +82,17 @@ namespace The.Namespace } } - public global::System.Collections.Generic.IEnumerable SomeMethod() + public global::System.Collections.Generic.IEnumerable SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public global::System.Collections.Generic.IEnumerable SomeMethod(System.Int32 i, System.Single f) + public global::System.Collections.Generic.IEnumerable SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } - public global::System.Collections.Generic.IEnumerable SomeGenericMethod() + public global::System.Collections.Generic.IEnumerable SomeGenericMethod() { return this.Apply(x => x.SomeGenericMethod()); } @@ -102,7 +102,7 @@ namespace The.Namespace return this.Apply(x => x.SomeOtherGenericMethod()); } - public global::ICustomEnumerable SomeCustomProperty + public global::ICustomEnumerable SomeCustomProperty { get { @@ -110,12 +110,12 @@ namespace The.Namespace } } - public global::ICustomEnumerable SomeMethod() + public global::ICustomEnumerable SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public global::ICustomEnumerable SomeMethod(System.Int32 i, System.Single f) + public global::ICustomEnumerable SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } @@ -127,7 +127,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -142,7 +142,7 @@ namespace The.Namespace { this.When(x => x.SomeProperty).Return(global::System.Linq.Enumerable.Empty()); this.When(x => x.SomeMethod()).Return(global::System.Linq.Enumerable.Empty()); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Linq.Enumerable.Empty()); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Linq.Enumerable.Empty()); } private void ConfigureLooseBehaviorGenerated() @@ -164,7 +164,7 @@ namespace The.Namespace return this.Apply(x => x.SomeMethod()); } - public global::System.Collections.Generic.IEnumerable SomeMethod(System.Int32 i, System.Single f) + public global::System.Collections.Generic.IEnumerable SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableDictionariesOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableDictionariesOutput_CSharp.txt index b4aae18..891f1c1 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableDictionariesOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableDictionariesOutput_CSharp.txt @@ -12,7 +12,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase>, global::ICustomImmutableDictionary { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -75,12 +75,12 @@ namespace The.Namespace return this.Apply(x => x.Remove(key)); } - public System.Boolean Contains(global::System.Collections.Generic.KeyValuePair pair) + public global::System.Boolean Contains(global::System.Collections.Generic.KeyValuePair pair) { return this.Apply(x => x.Contains(pair)); } - public System.Boolean TryGetKey(TKey equalKey, out TKey actualKey) + public global::System.Boolean TryGetKey(TKey equalKey, out TKey actualKey) { TKey _actualKey; actualKey = (this.GetOutParameterValue(x => x.TryGetKey(equalKey, out _actualKey), 1)); @@ -94,7 +94,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -107,9 +107,9 @@ namespace The.Namespace private void ConfigureBehaviorGenerated() { - this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); - this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); + this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); + this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); } private void ConfigureLooseBehaviorGenerated() @@ -118,7 +118,7 @@ namespace The.Namespace partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); - public global::System.Collections.Immutable.IImmutableDictionary SomeProperty + public global::System.Collections.Immutable.IImmutableDictionary SomeProperty { get { @@ -126,27 +126,27 @@ namespace The.Namespace } } - public global::System.Collections.Immutable.IImmutableDictionary SomeMethod() + public global::System.Collections.Immutable.IImmutableDictionary SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public global::System.Collections.Immutable.IImmutableDictionary SomeMethod(System.Int32 i, System.Single f) + public global::System.Collections.Immutable.IImmutableDictionary SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } - public global::System.Collections.Immutable.IImmutableDictionary SomeGenericMethod() + public global::System.Collections.Immutable.IImmutableDictionary SomeGenericMethod() { return this.Apply(x => x.SomeGenericMethod()); } - public global::System.Collections.Immutable.IImmutableDictionary SomeOtherGenericMethod() + public global::System.Collections.Immutable.IImmutableDictionary SomeOtherGenericMethod() { return this.Apply(x => x.SomeOtherGenericMethod()); } - public global::ICustomImmutableDictionary SomeCustomProperty + public global::ICustomImmutableDictionary SomeCustomProperty { get { @@ -154,12 +154,12 @@ namespace The.Namespace } } - public global::ICustomImmutableDictionary SomeMethod() + public global::ICustomImmutableDictionary SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public global::ICustomImmutableDictionary SomeMethod(System.Int32 i, System.Single f) + public global::ICustomImmutableDictionary SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } @@ -171,7 +171,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -186,7 +186,7 @@ namespace The.Namespace { this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); } private void ConfigureLooseBehaviorGenerated() @@ -208,7 +208,7 @@ namespace The.Namespace return this.Apply(x => x.SomeMethod()); } - public global::System.Collections.Immutable.IImmutableDictionary SomeMethod(System.Int32 i, System.Single f) + public global::System.Collections.Immutable.IImmutableDictionary SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableListsOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableListsOutput_CSharp.txt index 39b17a1..0f48725 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableListsOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableListsOutput_CSharp.txt @@ -12,7 +12,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase>, global::ICustomImmutableList { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -28,14 +28,14 @@ namespace The.Namespace this.When(x => x.Clear()).Return(global::System.Collections.Immutable.ImmutableList.Empty); this.When(x => x.Add(global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); this.When(x => x.AddRange(global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableList.Empty); - this.When(x => x.Insert(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); - this.When(x => x.InsertRange(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableList.Empty); + this.When(x => x.Insert(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); + this.When(x => x.InsertRange(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableList.Empty); this.When(x => x.Remove(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableList.Empty); this.When(x => x.RemoveAll(global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableList.Empty); this.When(x => x.RemoveRange(global::PCLMock.It.IsAny>(), global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableList.Empty); - this.When(x => x.RemoveRange(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); - this.When(x => x.RemoveAt(global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); - this.When(x => x.SetItem(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); + this.When(x => x.RemoveRange(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); + this.When(x => x.RemoveAt(global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); + this.When(x => x.SetItem(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); this.When(x => x.Replace(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableList.Empty); } @@ -50,12 +50,12 @@ namespace The.Namespace return this.Apply(x => x.Clear()); } - public System.Int32 IndexOf(T item, System.Int32 index, System.Int32 count, global::System.Collections.Generic.IEqualityComparer equalityComparer) + public global::System.Int32 IndexOf(T item, global::System.Int32 index, global::System.Int32 count, global::System.Collections.Generic.IEqualityComparer equalityComparer) { return this.Apply(x => x.IndexOf(item, index, count, equalityComparer)); } - public System.Int32 LastIndexOf(T item, System.Int32 index, System.Int32 count, global::System.Collections.Generic.IEqualityComparer equalityComparer) + public global::System.Int32 LastIndexOf(T item, global::System.Int32 index, global::System.Int32 count, global::System.Collections.Generic.IEqualityComparer equalityComparer) { return this.Apply(x => x.LastIndexOf(item, index, count, equalityComparer)); } @@ -70,12 +70,12 @@ namespace The.Namespace return this.Apply(x => x.AddRange(items)); } - public global::System.Collections.Immutable.IImmutableList Insert(System.Int32 index, T element) + public global::System.Collections.Immutable.IImmutableList Insert(global::System.Int32 index, T element) { return this.Apply(x => x.Insert(index, element)); } - public global::System.Collections.Immutable.IImmutableList InsertRange(System.Int32 index, global::System.Collections.Generic.IEnumerable items) + public global::System.Collections.Immutable.IImmutableList InsertRange(global::System.Int32 index, global::System.Collections.Generic.IEnumerable items) { return this.Apply(x => x.InsertRange(index, items)); } @@ -95,17 +95,17 @@ namespace The.Namespace return this.Apply(x => x.RemoveRange(items, equalityComparer)); } - public global::System.Collections.Immutable.IImmutableList RemoveRange(System.Int32 index, System.Int32 count) + public global::System.Collections.Immutable.IImmutableList RemoveRange(global::System.Int32 index, global::System.Int32 count) { return this.Apply(x => x.RemoveRange(index, count)); } - public global::System.Collections.Immutable.IImmutableList RemoveAt(System.Int32 index) + public global::System.Collections.Immutable.IImmutableList RemoveAt(global::System.Int32 index) { return this.Apply(x => x.RemoveAt(index)); } - public global::System.Collections.Immutable.IImmutableList SetItem(System.Int32 index, T value) + public global::System.Collections.Immutable.IImmutableList SetItem(global::System.Int32 index, T value) { return this.Apply(x => x.SetItem(index, value)); } @@ -122,7 +122,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -135,9 +135,9 @@ namespace The.Namespace private void ConfigureBehaviorGenerated() { - this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableList.Empty); - this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableList.Empty); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); + this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableList.Empty); + this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableList.Empty); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); } private void ConfigureLooseBehaviorGenerated() @@ -146,7 +146,7 @@ namespace The.Namespace partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); - public global::System.Collections.Immutable.IImmutableList SomeProperty + public global::System.Collections.Immutable.IImmutableList SomeProperty { get { @@ -154,17 +154,17 @@ namespace The.Namespace } } - public global::System.Collections.Immutable.IImmutableList SomeMethod() + public global::System.Collections.Immutable.IImmutableList SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public global::System.Collections.Immutable.IImmutableList SomeMethod(System.Int32 i, System.Single f) + public global::System.Collections.Immutable.IImmutableList SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } - public global::System.Collections.Immutable.IImmutableList SomeGenericMethod() + public global::System.Collections.Immutable.IImmutableList SomeGenericMethod() { return this.Apply(x => x.SomeGenericMethod()); } @@ -174,7 +174,7 @@ namespace The.Namespace return this.Apply(x => x.SomeOtherGenericMethod()); } - public ICustomIImmutableList SomeCustomProperty + public ICustomIImmutableList SomeCustomProperty { get { @@ -182,12 +182,12 @@ namespace The.Namespace } } - public ICustomIImmutableList SomeMethod() + public ICustomIImmutableList SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public ICustomIImmutableList SomeMethod(System.Int32 i, System.Single f) + public ICustomIImmutableList SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } @@ -199,7 +199,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -214,7 +214,7 @@ namespace The.Namespace { this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableList.Empty); this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableList.Empty); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); } private void ConfigureLooseBehaviorGenerated() @@ -236,7 +236,7 @@ namespace The.Namespace return this.Apply(x => x.SomeMethod()); } - public global::System.Collections.Immutable.IImmutableList SomeMethod(System.Int32 i, System.Single f) + public global::System.Collections.Immutable.IImmutableList SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableQueuesOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableQueuesOutput_CSharp.txt index f91b3ae..38fddc7 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableQueuesOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableQueuesOutput_CSharp.txt @@ -12,7 +12,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase>, global::ICustomImmutableQueue { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -56,7 +56,7 @@ namespace The.Namespace return this.Apply(x => x.Dequeue()); } - public System.Boolean IsEmpty + public global::System.Boolean IsEmpty { get { @@ -71,7 +71,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -84,9 +84,9 @@ namespace The.Namespace private void ConfigureBehaviorGenerated() { - this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); - this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); + this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); + this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); } private void ConfigureLooseBehaviorGenerated() @@ -95,7 +95,7 @@ namespace The.Namespace partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); - public global::System.Collections.Immutable.IImmutableQueue SomeProperty + public global::System.Collections.Immutable.IImmutableQueue SomeProperty { get { @@ -103,17 +103,17 @@ namespace The.Namespace } } - public global::System.Collections.Immutable.IImmutableQueue SomeMethod() + public global::System.Collections.Immutable.IImmutableQueue SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public global::System.Collections.Immutable.IImmutableQueue SomeMethod(System.Int32 i, System.Single f) + public global::System.Collections.Immutable.IImmutableQueue SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } - public global::System.Collections.Immutable.IImmutableQueue SomeGenericMethod() + public global::System.Collections.Immutable.IImmutableQueue SomeGenericMethod() { return this.Apply(x => x.SomeGenericMethod()); } @@ -123,7 +123,7 @@ namespace The.Namespace return this.Apply(x => x.SomeOtherGenericMethod()); } - public ICustomIImmutableQueue SomeCustomProperty + public ICustomIImmutableQueue SomeCustomProperty { get { @@ -131,12 +131,12 @@ namespace The.Namespace } } - public ICustomIImmutableQueue SomeMethod() + public ICustomIImmutableQueue SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public ICustomIImmutableQueue SomeMethod(System.Int32 i, System.Single f) + public ICustomIImmutableQueue SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } @@ -148,7 +148,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -163,7 +163,7 @@ namespace The.Namespace { this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); } private void ConfigureLooseBehaviorGenerated() @@ -185,7 +185,7 @@ namespace The.Namespace return this.Apply(x => x.SomeMethod()); } - public global::System.Collections.Immutable.IImmutableQueue SomeMethod(System.Int32 i, System.Single f) + public global::System.Collections.Immutable.IImmutableQueue SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableSetsOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableSetsOutput_CSharp.txt index c0f0849..a5dc5a6 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableSetsOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableSetsOutput_CSharp.txt @@ -12,7 +12,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase>, global::ICustomImmutableSet { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -45,7 +45,7 @@ namespace The.Namespace return this.Apply(x => x.Clear()); } - public System.Boolean Contains(T value) + public global::System.Boolean Contains(T value) { return this.Apply(x => x.Contains(value)); } @@ -60,7 +60,7 @@ namespace The.Namespace return this.Apply(x => x.Remove(value)); } - public System.Boolean TryGetValue(T equalValue, out T actualValue) + public global::System.Boolean TryGetValue(T equalValue, out T actualValue) { T _actualValue; actualValue = (this.GetOutParameterValue(x => x.TryGetValue(equalValue, out _actualValue), 1)); @@ -87,32 +87,32 @@ namespace The.Namespace return this.Apply(x => x.Union(other)); } - public System.Boolean SetEquals(global::System.Collections.Generic.IEnumerable other) + public global::System.Boolean SetEquals(global::System.Collections.Generic.IEnumerable other) { return this.Apply(x => x.SetEquals(other)); } - public System.Boolean IsProperSubsetOf(global::System.Collections.Generic.IEnumerable other) + public global::System.Boolean IsProperSubsetOf(global::System.Collections.Generic.IEnumerable other) { return this.Apply(x => x.IsProperSubsetOf(other)); } - public System.Boolean IsProperSupersetOf(global::System.Collections.Generic.IEnumerable other) + public global::System.Boolean IsProperSupersetOf(global::System.Collections.Generic.IEnumerable other) { return this.Apply(x => x.IsProperSupersetOf(other)); } - public System.Boolean IsSubsetOf(global::System.Collections.Generic.IEnumerable other) + public global::System.Boolean IsSubsetOf(global::System.Collections.Generic.IEnumerable other) { return this.Apply(x => x.IsSubsetOf(other)); } - public System.Boolean IsSupersetOf(global::System.Collections.Generic.IEnumerable other) + public global::System.Boolean IsSupersetOf(global::System.Collections.Generic.IEnumerable other) { return this.Apply(x => x.IsSupersetOf(other)); } - public System.Boolean Overlaps(global::System.Collections.Generic.IEnumerable other) + public global::System.Boolean Overlaps(global::System.Collections.Generic.IEnumerable other) { return this.Apply(x => x.Overlaps(other)); } @@ -124,7 +124,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -137,9 +137,9 @@ namespace The.Namespace private void ConfigureBehaviorGenerated() { - this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); - this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); + this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); + this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); } private void ConfigureLooseBehaviorGenerated() @@ -148,7 +148,7 @@ namespace The.Namespace partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); - public global::System.Collections.Immutable.IImmutableSet SomeProperty + public global::System.Collections.Immutable.IImmutableSet SomeProperty { get { @@ -156,17 +156,17 @@ namespace The.Namespace } } - public global::System.Collections.Immutable.IImmutableSet SomeMethod() + public global::System.Collections.Immutable.IImmutableSet SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public global::System.Collections.Immutable.IImmutableSet SomeMethod(System.Int32 i, System.Single f) + public global::System.Collections.Immutable.IImmutableSet SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } - public global::System.Collections.Immutable.IImmutableSet SomeGenericMethod() + public global::System.Collections.Immutable.IImmutableSet SomeGenericMethod() { return this.Apply(x => x.SomeGenericMethod()); } @@ -176,7 +176,7 @@ namespace The.Namespace return this.Apply(x => x.SomeOtherGenericMethod()); } - public ICustomIImmutableSet SomeCustomProperty + public ICustomIImmutableSet SomeCustomProperty { get { @@ -184,12 +184,12 @@ namespace The.Namespace } } - public ICustomIImmutableSet SomeMethod() + public ICustomIImmutableSet SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public ICustomIImmutableSet SomeMethod(System.Int32 i, System.Single f) + public ICustomIImmutableSet SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } @@ -201,7 +201,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -216,7 +216,7 @@ namespace The.Namespace { this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); } private void ConfigureLooseBehaviorGenerated() @@ -238,7 +238,7 @@ namespace The.Namespace return this.Apply(x => x.SomeMethod()); } - public global::System.Collections.Immutable.IImmutableSet SomeMethod(System.Int32 i, System.Single f) + public global::System.Collections.Immutable.IImmutableSet SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableStacksOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableStacksOutput_CSharp.txt index 592ddf8..b17fcd5 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableStacksOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableStacksOutput_CSharp.txt @@ -12,7 +12,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase>, global::ICustomImmutableStack { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -56,7 +56,7 @@ namespace The.Namespace return this.Apply(x => x.Peek()); } - public System.Boolean IsEmpty + public global::System.Boolean IsEmpty { get { @@ -71,7 +71,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -84,9 +84,9 @@ namespace The.Namespace private void ConfigureBehaviorGenerated() { - this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableStack.Empty); - this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableStack.Empty); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableStack.Empty); + this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableStack.Empty); + this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableStack.Empty); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableStack.Empty); } private void ConfigureLooseBehaviorGenerated() @@ -95,7 +95,7 @@ namespace The.Namespace partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); - public global::System.Collections.Immutable.IImmutableStack SomeProperty + public global::System.Collections.Immutable.IImmutableStack SomeProperty { get { @@ -103,17 +103,17 @@ namespace The.Namespace } } - public global::System.Collections.Immutable.IImmutableStack SomeMethod() + public global::System.Collections.Immutable.IImmutableStack SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public global::System.Collections.Immutable.IImmutableStack SomeMethod(System.Int32 i, System.Single f) + public global::System.Collections.Immutable.IImmutableStack SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } - public global::System.Collections.Immutable.IImmutableStack SomeGenericMethod() + public global::System.Collections.Immutable.IImmutableStack SomeGenericMethod() { return this.Apply(x => x.SomeGenericMethod()); } @@ -123,7 +123,7 @@ namespace The.Namespace return this.Apply(x => x.SomeOtherGenericMethod()); } - public ICustomIImmutableStack SomeCustomProperty + public ICustomIImmutableStack SomeCustomProperty { get { @@ -131,12 +131,12 @@ namespace The.Namespace } } - public ICustomIImmutableStack SomeMethod() + public ICustomIImmutableStack SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public ICustomIImmutableStack SomeMethod(System.Int32 i, System.Single f) + public ICustomIImmutableStack SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } @@ -148,7 +148,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -163,7 +163,7 @@ namespace The.Namespace { this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableStack.Empty); this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableStack.Empty); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableStack.Empty); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableStack.Empty); } private void ConfigureLooseBehaviorGenerated() @@ -185,7 +185,7 @@ namespace The.Namespace return this.Apply(x => x.SomeMethod()); } - public global::System.Collections.Immutable.IImmutableStack SomeMethod(System.Int32 i, System.Single f) + public global::System.Collections.Immutable.IImmutableStack SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ListsOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ListsOutput_CSharp.txt index de6f78d..9fdb54e 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ListsOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ListsOutput_CSharp.txt @@ -12,7 +12,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase>, global::ICustomList { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -33,22 +33,22 @@ namespace The.Namespace partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); - public System.Int32 IndexOf(T item) + public global::System.Int32 IndexOf(T item) { return this.Apply(x => x.IndexOf(item)); } - public void Insert(System.Int32 index, T item) + public void Insert(global::System.Int32 index, T item) { this.Apply(x => x.Insert(index, item)); } - public void RemoveAt(System.Int32 index) + public void RemoveAt(global::System.Int32 index) { this.Apply(x => x.RemoveAt(index)); } - public T this[System.Int32 index] + public T this[global::System.Int32 index] { get { @@ -71,22 +71,22 @@ namespace The.Namespace this.Apply(x => x.Clear()); } - public System.Boolean Contains(T item) + public global::System.Boolean Contains(T item) { return this.Apply(x => x.Contains(item)); } - public void CopyTo(T[] array, System.Int32 arrayIndex) + public void CopyTo(T[] array, global::System.Int32 arrayIndex) { this.Apply(x => x.CopyTo(array, arrayIndex)); } - public System.Boolean Remove(T item) + public global::System.Boolean Remove(T item) { return this.Apply(x => x.Remove(item)); } - public System.Int32 Count + public global::System.Int32 Count { get { @@ -94,7 +94,7 @@ namespace The.Namespace } } - public System.Boolean IsReadOnly + public global::System.Boolean IsReadOnly { get { @@ -109,7 +109,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -122,10 +122,10 @@ namespace The.Namespace private void ConfigureBehaviorGenerated() { - this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.List()); - this.When(x => x.SomeReadOnlyProperty).Return(new global::System.Collections.Generic.List()); - this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.List()); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.List()); + this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.List()); + this.When(x => x.SomeReadOnlyProperty).Return(new global::System.Collections.Generic.List()); + this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.List()); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.List()); } private void ConfigureLooseBehaviorGenerated() @@ -134,7 +134,7 @@ namespace The.Namespace partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); - public global::System.Collections.Generic.IList SomeProperty + public global::System.Collections.Generic.IList SomeProperty { get { @@ -142,7 +142,7 @@ namespace The.Namespace } } - public global::System.Collections.Generic.IReadOnlyList SomeReadOnlyProperty + public global::System.Collections.Generic.IReadOnlyList SomeReadOnlyProperty { get { @@ -150,17 +150,17 @@ namespace The.Namespace } } - public global::System.Collections.Generic.IList SomeMethod() + public global::System.Collections.Generic.IList SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public global::System.Collections.Generic.IList SomeMethod(System.Int32 i, System.Single f) + public global::System.Collections.Generic.IList SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } - public global::System.Collections.Generic.IList SomeGenericMethod() + public global::System.Collections.Generic.IList SomeGenericMethod() { return this.Apply(x => x.SomeGenericMethod()); } @@ -170,7 +170,7 @@ namespace The.Namespace return this.Apply(x => x.SomeOtherGenericMethod()); } - public global::ICustomList SomeCustomProperty + public global::ICustomList SomeCustomProperty { get { @@ -178,12 +178,12 @@ namespace The.Namespace } } - public global::ICustomList SomeMethod() + public global::ICustomList SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public global::ICustomList SomeMethod(System.Int32 i, System.Single f) + public global::ICustomList SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } @@ -195,7 +195,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -210,7 +210,7 @@ namespace The.Namespace { this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.List()); this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.List()); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.List()); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.List()); } private void ConfigureLooseBehaviorGenerated() @@ -232,7 +232,7 @@ namespace The.Namespace return this.Apply(x => x.SomeMethod()); } - public global::System.Collections.Generic.IList SomeMethod(System.Int32 i, System.Single f) + public global::System.Collections.Generic.IList SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/RecursiveOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/RecursiveOutput_CSharp.txt index 398cc38..0c4199c 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/RecursiveOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/RecursiveOutput_CSharp.txt @@ -12,7 +12,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -25,7 +25,7 @@ namespace The.Namespace private void ConfigureBehaviorGenerated() { - this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.List>>()); + this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.List>>()); } private void ConfigureLooseBehaviorGenerated() @@ -34,7 +34,7 @@ namespace The.Namespace partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); - public global::System.Collections.Generic.IList>> SomeProperty + public global::System.Collections.Generic.IList>> SomeProperty { get { diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/SetsOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/SetsOutput_CSharp.txt index d91626d..138326e 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/SetsOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/SetsOutput_CSharp.txt @@ -12,7 +12,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase>, global::ICustomSet { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -33,7 +33,7 @@ namespace The.Namespace partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); - public System.Boolean Add(T item) + public global::System.Boolean Add(T item) { return this.Apply(x => x.Add(item)); } @@ -58,32 +58,32 @@ namespace The.Namespace this.Apply(x => x.SymmetricExceptWith(other)); } - public System.Boolean IsSubsetOf(global::System.Collections.Generic.IEnumerable other) + public global::System.Boolean IsSubsetOf(global::System.Collections.Generic.IEnumerable other) { return this.Apply(x => x.IsSubsetOf(other)); } - public System.Boolean IsSupersetOf(global::System.Collections.Generic.IEnumerable other) + public global::System.Boolean IsSupersetOf(global::System.Collections.Generic.IEnumerable other) { return this.Apply(x => x.IsSupersetOf(other)); } - public System.Boolean IsProperSupersetOf(global::System.Collections.Generic.IEnumerable other) + public global::System.Boolean IsProperSupersetOf(global::System.Collections.Generic.IEnumerable other) { return this.Apply(x => x.IsProperSupersetOf(other)); } - public System.Boolean IsProperSubsetOf(global::System.Collections.Generic.IEnumerable other) + public global::System.Boolean IsProperSubsetOf(global::System.Collections.Generic.IEnumerable other) { return this.Apply(x => x.IsProperSubsetOf(other)); } - public System.Boolean Overlaps(global::System.Collections.Generic.IEnumerable other) + public global::System.Boolean Overlaps(global::System.Collections.Generic.IEnumerable other) { return this.Apply(x => x.Overlaps(other)); } - public System.Boolean SetEquals(global::System.Collections.Generic.IEnumerable other) + public global::System.Boolean SetEquals(global::System.Collections.Generic.IEnumerable other) { return this.Apply(x => x.SetEquals(other)); } @@ -98,22 +98,22 @@ namespace The.Namespace this.Apply(x => x.Clear()); } - public System.Boolean Contains(T item) + public global::System.Boolean Contains(T item) { return this.Apply(x => x.Contains(item)); } - public void CopyTo(T[] array, System.Int32 arrayIndex) + public void CopyTo(T[] array, global::System.Int32 arrayIndex) { this.Apply(x => x.CopyTo(array, arrayIndex)); } - public System.Boolean Remove(T item) + public global::System.Boolean Remove(T item) { return this.Apply(x => x.Remove(item)); } - public System.Int32 Count + public global::System.Int32 Count { get { @@ -121,7 +121,7 @@ namespace The.Namespace } } - public System.Boolean IsReadOnly + public global::System.Boolean IsReadOnly { get { @@ -136,7 +136,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -149,9 +149,9 @@ namespace The.Namespace private void ConfigureBehaviorGenerated() { - this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.HashSet()); - this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.HashSet()); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.HashSet()); + this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.HashSet()); + this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.HashSet()); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.HashSet()); } private void ConfigureLooseBehaviorGenerated() @@ -160,7 +160,7 @@ namespace The.Namespace partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); - public global::System.Collections.Generic.ISet SomeProperty + public global::System.Collections.Generic.ISet SomeProperty { get { @@ -168,17 +168,17 @@ namespace The.Namespace } } - public global::System.Collections.Generic.ISet SomeMethod() + public global::System.Collections.Generic.ISet SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public global::System.Collections.Generic.ISet SomeMethod(System.Int32 i, System.Single f) + public global::System.Collections.Generic.ISet SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } - public global::System.Collections.Generic.ISet SomeGenericMethod() + public global::System.Collections.Generic.ISet SomeGenericMethod() { return this.Apply(x => x.SomeGenericMethod()); } @@ -188,7 +188,7 @@ namespace The.Namespace return this.Apply(x => x.SomeOtherGenericMethod()); } - public global::ICustomSet SomeCustomProperty + public global::ICustomSet SomeCustomProperty { get { @@ -196,12 +196,12 @@ namespace The.Namespace } } - public global::ICustomSet SomeMethod() + public global::ICustomSet SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public global::ICustomSet SomeMethod(System.Int32 i, System.Single f) + public global::ICustomSet SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } @@ -213,7 +213,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -228,7 +228,7 @@ namespace The.Namespace { this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.HashSet()); this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.HashSet()); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.HashSet()); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.HashSet()); } private void ConfigureLooseBehaviorGenerated() @@ -250,7 +250,7 @@ namespace The.Namespace return this.Apply(x => x.SomeMethod()); } - public global::System.Collections.Generic.ISet SomeMethod(System.Int32 i, System.Single f) + public global::System.Collections.Generic.ISet SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/DisposablesFixtureResources/DisposablesOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/DisposablesFixtureResources/DisposablesOutput_CSharp.txt index d40c0c3..286276c 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/DisposablesFixtureResources/DisposablesOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/DisposablesFixtureResources/DisposablesOutput_CSharp.txt @@ -4,7 +4,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -19,7 +19,7 @@ namespace The.Namespace { this.When(x => x.SomeProperty).Return(global::System.Reactive.Disposables.Disposable.Empty); this.When(x => x.SomeMethod()).Return(global::System.Reactive.Disposables.Disposable.Empty); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Reactive.Disposables.Disposable.Empty); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Reactive.Disposables.Disposable.Empty); } private void ConfigureLooseBehaviorGenerated() @@ -41,7 +41,7 @@ namespace The.Namespace return this.Apply(x => x.SomeMethod()); } - public global::System.IDisposable SomeMethod(System.Int32 i, System.Single f) + public global::System.IDisposable SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } @@ -69,7 +69,7 @@ namespace The.Namespace return this.Apply(x => x.SomeMethod()); } - public global::ICustomDisposable SomeMethod(System.Int32 i, System.Single f) + public global::ICustomDisposable SomeMethod(global::System.Int32 i, global::System.Single f) { return this.Apply(x => x.SomeMethod(i, f)); } diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt index e5a5797..b14fa92 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt @@ -4,7 +4,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase>, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -18,7 +18,7 @@ namespace The.Namespace private void ConfigureBehaviorGenerated() { this.When(x => x.SomeProperty).Return(global::System.Reactive.Linq.Observable.Empty()); - this.When(x => x.SomeMethod()).Return(global::System.Reactive.Linq.Observable.Return(default (T))); + this.When(x => x.SomeMethod()).Return(global::System.Reactive.Linq.Observable.Return(default(T))); } private void ConfigureLooseBehaviorGenerated() diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/NonObservableBasedOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/NonObservableBasedOutput_CSharp.txt index 4e15c3d..823841b 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/NonObservableBasedOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/NonObservableBasedOutput_CSharp.txt @@ -4,7 +4,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -25,7 +25,7 @@ namespace The.Namespace partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); - public System.Int32 SomeProperty + public global::System.Int32 SomeProperty { get { @@ -33,7 +33,7 @@ namespace The.Namespace } } - public System.String SomeOtherProperty + public global::System.String SomeOtherProperty { get { @@ -41,7 +41,7 @@ namespace The.Namespace } } - public System.Int32 this[System.Int32 i, System.Single f] + public global::System.Int32 this[global::System.Int32 i, global::System.Single f] { get { @@ -54,27 +54,27 @@ namespace The.Namespace this.Apply(x => x.SomeMethod()); } - public System.String SomeMethod() + public global::System.String SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public System.Int32 SomeMethod() + public global::System.Int32 SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public System.Object SomeMethod() + public global::System.Object SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public System.Int32 SomeMethod() + public global::System.Int32 SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public System.Int32 SomeMethod() + public global::System.Int32 SomeMethod() { return this.Apply(x => x.SomeMethod()); } diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedOutput_CSharp.txt index 556d664..1b235e4 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedOutput_CSharp.txt @@ -4,7 +4,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -17,11 +17,11 @@ namespace The.Namespace private void ConfigureBehaviorGenerated() { - this.When(x => x.SomeProperty).Return(global::System.Reactive.Linq.Observable.Empty()); - this.When(x => x.SomeOtherProperty).Return(global::System.Reactive.Linq.Observable.Empty()); - this.When(x => x[global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny()]).Return(global::System.Reactive.Linq.Observable.Empty()); - this.When(x => x.SomeMethod()).Return(global::System.Reactive.Linq.Observable.Return(0)); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Reactive.Linq.Observable.Return(null)); + this.When(x => x.SomeProperty).Return(global::System.Reactive.Linq.Observable.Empty()); + this.When(x => x.SomeOtherProperty).Return(global::System.Reactive.Linq.Observable.Empty()); + this.When(x => x[global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny()]).Return(global::System.Reactive.Linq.Observable.Empty()); + this.When(x => x.SomeMethod()).Return(global::System.Reactive.Linq.Observable.Return(0)); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Reactive.Linq.Observable.Return(null)); } private void ConfigureLooseBehaviorGenerated() @@ -30,7 +30,7 @@ namespace The.Namespace partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); - public global::System.IObservable SomeProperty + public global::System.IObservable SomeProperty { get { @@ -38,7 +38,7 @@ namespace The.Namespace } } - public global::System.IObservable SomeOtherProperty + public global::System.IObservable SomeOtherProperty { get { @@ -46,7 +46,7 @@ namespace The.Namespace } } - public global::System.IObservable this[System.Int32 i, System.Single f] + public global::System.IObservable this[global::System.Int32 i, global::System.Single f] { get { @@ -54,32 +54,32 @@ namespace The.Namespace } } - public global::System.IObservable SomeMethod() + public global::System.IObservable SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public global::System.IObservable SomeMethod(System.String s, System.Int32 i) + public global::System.IObservable SomeMethod(global::System.String s, global::System.Int32 i) { return this.Apply(x => x.SomeMethod(s, i)); } - public global::System.IObservable SomeMethod() + public global::System.IObservable SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public global::System.IObservable SomeMethod() + public global::System.IObservable SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public global::ICustomObservable SomeMethod() + public global::ICustomObservable SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public global::ICustomObservable SomeMethod(System.String s, System.Int32 i) + public global::ICustomObservable SomeMethod(global::System.String s, global::System.Int32 i) { return this.Apply(x => x.SomeMethod(s, i)); } diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt index 18c534e..9abb768 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt @@ -4,7 +4,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -17,7 +17,7 @@ namespace The.Namespace private void ConfigureBehaviorGenerated() { - this.When(x => x.SomeMethod()).Return(global::System.Reactive.Linq.Observable.Return>(global::System.Reactive.Linq.Observable.Return(0))); + this.When(x => x.SomeMethod()).Return(global::System.Reactive.Linq.Observable.Return>(global::System.Reactive.Linq.Observable.Return(0))); } private void ConfigureLooseBehaviorGenerated() @@ -26,7 +26,7 @@ namespace The.Namespace partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); - public global::System.IObservable> SomeMethod() + public global::System.IObservable> SomeMethod() { return this.Apply(x => x.SomeMethod()); } diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt index f3f8e7b..7744c10 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt @@ -4,7 +4,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase>, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -17,8 +17,8 @@ namespace The.Namespace private void ConfigureBehaviorGenerated() { - this.When(x => x.SomeProperty).Return(global::System.Threading.Tasks.Task.FromResult(default (T))); - this.When(x => x.SomeMethod()).Return(global::System.Threading.Tasks.Task.FromResult(default (T))); + this.When(x => x.SomeProperty).Return(global::System.Threading.Tasks.Task.FromResult(default(T))); + this.When(x => x.SomeMethod()).Return(global::System.Threading.Tasks.Task.FromResult(default(T))); } private void ConfigureLooseBehaviorGenerated() diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericTaskOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericTaskOutput_CSharp.txt index 112eee5..48721eb 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericTaskOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericTaskOutput_CSharp.txt @@ -4,7 +4,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -17,11 +17,11 @@ namespace The.Namespace private void ConfigureBehaviorGenerated() { - this.When(x => x.SomeProperty).Return(global::System.Threading.Tasks.Task.FromResult(0)); - this.When(x => x.SomeOtherProperty).Return(global::System.Threading.Tasks.Task.FromResult(null)); - this.When(x => x[global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny()]).Return(global::System.Threading.Tasks.Task.FromResult(0)); - this.When(x => x.SomeMethod()).Return(global::System.Threading.Tasks.Task.FromResult(0)); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Threading.Tasks.Task.FromResult(null)); + this.When(x => x.SomeProperty).Return(global::System.Threading.Tasks.Task.FromResult(0)); + this.When(x => x.SomeOtherProperty).Return(global::System.Threading.Tasks.Task.FromResult(null)); + this.When(x => x[global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny()]).Return(global::System.Threading.Tasks.Task.FromResult(0)); + this.When(x => x.SomeMethod()).Return(global::System.Threading.Tasks.Task.FromResult(0)); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Threading.Tasks.Task.FromResult(null)); } private void ConfigureLooseBehaviorGenerated() @@ -30,7 +30,7 @@ namespace The.Namespace partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); - public global::System.Threading.Tasks.Task SomeProperty + public global::System.Threading.Tasks.Task SomeProperty { get { @@ -38,7 +38,7 @@ namespace The.Namespace } } - public global::System.Threading.Tasks.Task SomeOtherProperty + public global::System.Threading.Tasks.Task SomeOtherProperty { get { @@ -46,7 +46,7 @@ namespace The.Namespace } } - public global::System.Threading.Tasks.Task this[System.Int32 i, System.Single f] + public global::System.Threading.Tasks.Task this[global::System.Int32 i, global::System.Single f] { get { @@ -54,32 +54,32 @@ namespace The.Namespace } } - public global::System.Threading.Tasks.Task SomeMethod() + public global::System.Threading.Tasks.Task SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public global::System.Threading.Tasks.Task SomeMethod(System.String s, System.Int32 i) + public global::System.Threading.Tasks.Task SomeMethod(global::System.String s, global::System.Int32 i) { return this.Apply(x => x.SomeMethod(s, i)); } - public global::System.Threading.Tasks.Task SomeMethod() + public global::System.Threading.Tasks.Task SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public global::System.Threading.Tasks.Task SomeMethod() + public global::System.Threading.Tasks.Task SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public global::CustomTask SomeMethod() + public global::CustomTask SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public global::CustomTask SomeMethod(System.String s, System.Int32 i) + public global::CustomTask SomeMethod(global::System.String s, global::System.Int32 i) { return this.Apply(x => x.SomeMethod(s, i)); } diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonGenericTaskOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonGenericTaskOutput_CSharp.txt index 3406772..e4da0ea 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonGenericTaskOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonGenericTaskOutput_CSharp.txt @@ -4,7 +4,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -17,11 +17,11 @@ namespace The.Namespace private void ConfigureBehaviorGenerated() { - this.When(x => x.SomeProperty).Return(global::System.Threading.Tasks.Task.FromResult(false)); - this.When(x => x.SomeOtherProperty).Return(global::System.Threading.Tasks.Task.FromResult(false)); - this.When(x => x[global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny()]).Return(global::System.Threading.Tasks.Task.FromResult(false)); - this.When(x => x.SomeMethod()).Return(global::System.Threading.Tasks.Task.FromResult(false)); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Threading.Tasks.Task.FromResult(false)); + this.When(x => x.SomeProperty).Return(global::System.Threading.Tasks.Task.FromResult(false)); + this.When(x => x.SomeOtherProperty).Return(global::System.Threading.Tasks.Task.FromResult(false)); + this.When(x => x[global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny()]).Return(global::System.Threading.Tasks.Task.FromResult(false)); + this.When(x => x.SomeMethod()).Return(global::System.Threading.Tasks.Task.FromResult(false)); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Threading.Tasks.Task.FromResult(false)); } private void ConfigureLooseBehaviorGenerated() @@ -46,7 +46,7 @@ namespace The.Namespace } } - public global::System.Threading.Tasks.Task this[System.Int32 i, System.Single f] + public global::System.Threading.Tasks.Task this[global::System.Int32 i, global::System.Single f] { get { @@ -59,7 +59,7 @@ namespace The.Namespace return this.Apply(x => x.SomeMethod()); } - public global::System.Threading.Tasks.Task SomeMethod(System.String s, System.Int32 i) + public global::System.Threading.Tasks.Task SomeMethod(global::System.String s, global::System.Int32 i) { return this.Apply(x => x.SomeMethod(s, i)); } @@ -79,7 +79,7 @@ namespace The.Namespace return this.Apply(x => x.SomeMethod()); } - public global::CustomTask SomeMethod(System.String s, System.Int32 i) + public global::CustomTask SomeMethod(global::System.String s, global::System.Int32 i) { return this.Apply(x => x.SomeMethod(s, i)); } diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonTaskBasedOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonTaskBasedOutput_CSharp.txt index 4e15c3d..823841b 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonTaskBasedOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonTaskBasedOutput_CSharp.txt @@ -4,7 +4,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -25,7 +25,7 @@ namespace The.Namespace partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); - public System.Int32 SomeProperty + public global::System.Int32 SomeProperty { get { @@ -33,7 +33,7 @@ namespace The.Namespace } } - public System.String SomeOtherProperty + public global::System.String SomeOtherProperty { get { @@ -41,7 +41,7 @@ namespace The.Namespace } } - public System.Int32 this[System.Int32 i, System.Single f] + public global::System.Int32 this[global::System.Int32 i, global::System.Single f] { get { @@ -54,27 +54,27 @@ namespace The.Namespace this.Apply(x => x.SomeMethod()); } - public System.String SomeMethod() + public global::System.String SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public System.Int32 SomeMethod() + public global::System.Int32 SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public System.Object SomeMethod() + public global::System.Object SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public System.Int32 SomeMethod() + public global::System.Int32 SomeMethod() { return this.Apply(x => x.SomeMethod()); } - public System.Int32 SomeMethod() + public global::System.Int32 SomeMethod() { return this.Apply(x => x.SomeMethod()); } diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt index 3ecfeca..15758c1 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt @@ -4,7 +4,7 @@ namespace The.Namespace [System.Runtime.CompilerServices.CompilerGenerated] internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); @@ -17,7 +17,7 @@ namespace The.Namespace private void ConfigureBehaviorGenerated() { - this.When(x => x.SomeMethod()).Return(global::System.Threading.Tasks.Task.FromResult>(global::System.Threading.Tasks.Task.FromResult(0))); + this.When(x => x.SomeMethod()).Return(global::System.Threading.Tasks.Task.FromResult>(global::System.Threading.Tasks.Task.FromResult(0))); } private void ConfigureLooseBehaviorGenerated() @@ -26,7 +26,7 @@ namespace The.Namespace partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); - public global::System.Threading.Tasks.Task> SomeMethod() + public global::System.Threading.Tasks.Task> SomeMethod() { return this.Apply(x => x.SomeMethod()); } diff --git a/Src/PCLMock.UnitTests/PCLMock.UnitTests.csproj b/Src/PCLMock.UnitTests/PCLMock.UnitTests.csproj index 54156e8..39ada30 100644 --- a/Src/PCLMock.UnitTests/PCLMock.UnitTests.csproj +++ b/Src/PCLMock.UnitTests/PCLMock.UnitTests.csproj @@ -1,400 +1,43 @@ - - - - - - Debug - AnyCPU - {05115055-0BBC-49D5-8966-2B90325F2F08} - Library - Properties - PCLMock.UnitTests - PCLMock.UnitTests - v4.5.2 - 512 - - - - True - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\Microsoft.CodeAnalysis.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.dll - True - - - ..\packages\Microsoft.CodeAnalysis.CSharp.1.3.2\lib\net45\Microsoft.CodeAnalysis.CSharp.dll - True - - - ..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.1.3.2\lib\net45\Microsoft.CodeAnalysis.CSharp.Workspaces.dll - True - - - ..\packages\Microsoft.CodeAnalysis.VisualBasic.1.3.2\lib\net45\Microsoft.CodeAnalysis.VisualBasic.dll - True - - - ..\packages\Microsoft.CodeAnalysis.VisualBasic.Workspaces.1.3.2\lib\net45\Microsoft.CodeAnalysis.VisualBasic.Workspaces.dll - True - - - ..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.Workspaces.dll - True - - - ..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.Workspaces.Desktop.dll - True - - - - ..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll - True - - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.AttributedModel.dll - True - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.Convention.dll - True - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.Hosting.dll - True - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.Runtime.dll - True - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.TypedParts.dll - True - - - - ..\packages\Rx-Core.2.2.5\lib\net45\System.Reactive.Core.dll - True - - - ..\packages\Rx-Interfaces.2.2.5\lib\net45\System.Reactive.Interfaces.dll - True - - - ..\packages\Rx-Linq.2.2.5\lib\net45\System.Reactive.Linq.dll - True - - - ..\packages\Rx-PlatformServices.2.2.5\lib\net45\System.Reactive.PlatformServices.dll - True - - - ..\packages\System.Reflection.Metadata.1.4.2\lib\portable-net45+win8\System.Reflection.Metadata.dll - True - - - - - - - - ..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll - True - - - ..\packages\xunit.assert.2.2.0\lib\netstandard1.1\xunit.assert.dll - True - - - ..\packages\xunit.extensibility.core.2.2.0\lib\netstandard1.1\xunit.core.dll - True - - - ..\packages\xunit.extensibility.execution.2.2.0\lib\net452\xunit.execution.desktop.dll - True - - - - - Properties\AssemblyInfoCommon.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {6e077796-0241-4191-a866-0ea52b9bd946} - PCLMock.CodeGeneration - - - {a02c0394-4dad-4422-97bb-4a90d89cee66} - PCLMock - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + PCLMock.UnitTests + PCLMock.UnitTests + net471;netstandard2.0 + false + true + latest + IOperation + + + $(PackageTargetFallback);portable-net45+win8+wp8+wpa81 - - - + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/PCLMock.UnitTests.netstandard2.0.v3.ncrunchproject b/Src/PCLMock.UnitTests/PCLMock.UnitTests.netstandard2.0.v3.ncrunchproject new file mode 100644 index 0000000..319cd52 --- /dev/null +++ b/Src/PCLMock.UnitTests/PCLMock.UnitTests.netstandard2.0.v3.ncrunchproject @@ -0,0 +1,5 @@ + + + True + + \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/Visitors/ArgumentsVisitorFixture.cs b/Src/PCLMock.UnitTests/Visitors/ArgumentsVisitorFixture.cs index 3adca9d..6dbf955 100644 --- a/Src/PCLMock.UnitTests/Visitors/ArgumentsVisitorFixture.cs +++ b/Src/PCLMock.UnitTests/Visitors/ArgumentsVisitorFixture.cs @@ -12,7 +12,7 @@ public void can_find_arguments_in_parameterless_method_call() { var arguments = ArgumentsVisitor.FindArgumentsWithin(GetExpression(() => Console.WriteLine())); Assert.NotNull(arguments); - Assert.Equal(0, arguments.Length); + Assert.Empty(arguments); } [Fact] diff --git a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsAnyArgumentFilterFixture.cs b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsAnyArgumentFilterFixture.cs new file mode 100644 index 0000000..ec405c0 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsAnyArgumentFilterFixture.cs @@ -0,0 +1,59 @@ +namespace PCLMock.ArgumentFilters.UnitTests +{ + using PCLMock.ArgumentFilters; + using Xunit; + using Xunit.Extensions; + + public sealed class IsAnyArgumentFilterFixture + { + [Fact] + public void matches_returns_true_for_null() + { + Assert.True(IsAnyArgumentFilter.Instance.Matches(null)); + } + + [Theory] + [InlineData(null)] + [InlineData("")] + [InlineData("hello")] + [InlineData("world")] + [InlineData(0)] + [InlineData(1)] + [InlineData(-1)] + [InlineData(38)] + [InlineData(int.MaxValue)] + [InlineData(int.MinValue)] + public void matches_returns_true_for_any_value(object value) + { + Assert.True(IsAnyArgumentFilter.Instance.Matches(value)); + Assert.True(IsAnyArgumentFilter.Instance.Matches(value)); + Assert.True(IsAnyArgumentFilter.Instance.Matches(value)); + } + + [Fact] + public void has_a_nice_string_representation() + { + Assert.Equal("It.IsAny()", IsAnyArgumentFilter.Instance.ToString()); + Assert.Equal("It.IsAny()", IsAnyArgumentFilter.Instance.ToString()); + Assert.Equal("It.IsAny()", IsAnyArgumentFilter.Instance.ToString()); + } + + [Fact] + public void equals_returns_false_if_given_null() + { + Assert.False(IsAnyArgumentFilter.Instance.Equals(null)); + } + + [Fact] + public void equals_returns_false_if_given_a_filter_for_a_different_type() + { + Assert.False(IsAnyArgumentFilter.Instance.Equals(IsAnyArgumentFilter.Instance)); + } + + [Fact] + public void equals_returns_true_if_given_a_filter_of_the_same_type() + { + Assert.True(IsAnyArgumentFilter.Instance.Equals(IsAnyArgumentFilter.Instance)); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsArgumentFilterFixture.cs b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsArgumentFilterFixture.cs new file mode 100644 index 0000000..fbce729 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsArgumentFilterFixture.cs @@ -0,0 +1,61 @@ +namespace PCLMock.ArgumentFilters.UnitTests +{ + using PCLMock.ArgumentFilters; + using Xunit; + using Xunit.Extensions; + + public sealed class IsArgumentFilterFixture + { + [Fact] + public void matches_works_with_null() + { + Assert.True(new IsArgumentFilter(null).Matches(null)); + } + + [Theory] + [InlineData("hello", "world", false)] + [InlineData("hello", null, false)] + [InlineData(null, "hello", false)] + [InlineData(1, 2, false)] + [InlineData(1, 1f, false)] + [InlineData("hello", "hello", true)] + [InlineData(null, null, true)] + [InlineData(13, 13, true)] + [InlineData(56f, 56f, true)] + public void matches_returns_correct_value(object firstValue, object secondValue, bool expectedResult) + { + Assert.Equal(expectedResult, new IsArgumentFilter(firstValue).Matches(secondValue)); + } + + [Fact] + public void has_a_nice_string_representation() + { + Assert.Equal("It.Is(\"hello\")", new IsArgumentFilter("hello").ToString()); + Assert.Equal("It.Is(10)", new IsArgumentFilter(10).ToString()); + Assert.Equal("It.Is(15.182M)", new IsArgumentFilter(15.182m).ToString()); + Assert.Equal("It.Is(null)", new IsArgumentFilter(null).ToString()); + } + + [Fact] + public void equals_returns_false_if_given_a_filter_for_a_different_type() + { + Assert.False(new IsArgumentFilter("foo").Equals(new IsArgumentFilter(10))); + } + + [Fact] + public void equals_returns_false_if_given_a_filter_with_a_different_expected_value() + { + Assert.False(new IsArgumentFilter("foo").Equals(new IsArgumentFilter("bar"))); + Assert.False(new IsArgumentFilter("foo").Equals(new IsArgumentFilter(null))); + Assert.False(new IsArgumentFilter(null).Equals(new IsArgumentFilter("foo"))); + } + + [Fact] + public void equals_returns_true_if_given_a_filter_with_the_same_expected_value() + { + Assert.True(new IsArgumentFilter("foo").Equals(new IsArgumentFilter("foo"))); + Assert.True(new IsArgumentFilter(150).Equals(new IsArgumentFilter(150))); + Assert.True(new IsArgumentFilter(null).Equals(new IsArgumentFilter(null))); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsBetweenArgumentFilterFixture.cs b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsBetweenArgumentFilterFixture.cs new file mode 100644 index 0000000..ed2a48f --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsBetweenArgumentFilterFixture.cs @@ -0,0 +1,85 @@ +namespace PCLMock.ArgumentFilters.UnitTests +{ + using PCLMock.ArgumentFilters; + using Xunit; + + public sealed class IsBetweenArgumentFilterFixture + { + [Fact] + public void matches_returns_true_if_value_is_equal_to_the_minimum() + { + Assert.True(new IsBetweenArgumentFilter(5, 10).Matches(5)); + Assert.True(new IsBetweenArgumentFilter(5.152m, 10.3m).Matches(5.152m)); + Assert.True(new IsBetweenArgumentFilter(null, "abc").Matches(null)); + } + + [Fact] + public void matches_returns_true_if_value_is_equal_to_the_maximum() + { + Assert.True(new IsBetweenArgumentFilter(5, 10).Matches(10)); + Assert.True(new IsBetweenArgumentFilter(5.152m, 10.3m).Matches(10.3m)); + Assert.True(new IsBetweenArgumentFilter(null, "abc").Matches("abc")); + } + + [Fact] + public void matches_returns_false_if_value_is_less_than_the_minimum() + { + Assert.False(new IsBetweenArgumentFilter(5, 10).Matches(4)); + Assert.False(new IsBetweenArgumentFilter(5.152m, 10.3m).Matches(5.151m)); + } + + [Fact] + public void matches_returns_false_if_value_is_greater_than_the_maximum() + { + Assert.False(new IsBetweenArgumentFilter(5, 10).Matches(11)); + Assert.False(new IsBetweenArgumentFilter(5.152m, 10.3m).Matches(10.301m)); + } + + [Fact] + public void matches_returns_true_if_value_is_within_the_minimum_and_maximum() + { + Assert.True(new IsBetweenArgumentFilter(5, 10).Matches(6)); + Assert.True(new IsBetweenArgumentFilter(5.152m, 10.3m).Matches(6.1m)); + Assert.True(new IsBetweenArgumentFilter(null, "abc").Matches("a")); + Assert.True(new IsBetweenArgumentFilter(5, 5).Matches(5)); + } + + [Fact] + public void has_a_nice_string_representation() + { + Assert.Equal("It.IsBetween(5, 10)", new IsBetweenArgumentFilter(5, 10).ToString()); + Assert.Equal("It.IsBetween(12.36M, 15.182M)", new IsBetweenArgumentFilter(12.36m, 15.182m).ToString()); + Assert.Equal("It.IsBetween(null, \"abc\")", new IsBetweenArgumentFilter(null, "abc").ToString()); + } + + [Fact] + public void equals_returns_false_if_given_a_filter_for_a_different_type() + { + Assert.False(new IsBetweenArgumentFilter(null, "foo").Equals(new IsBetweenArgumentFilter(1, 10))); + } + + [Fact] + public void equals_returns_false_if_given_a_filter_with_a_different_range() + { + Assert.False(new IsBetweenArgumentFilter(5, 10).Equals(new IsBetweenArgumentFilter(6, 10))); + Assert.False(new IsBetweenArgumentFilter(5.2387m, 10.127m).Equals(new IsBetweenArgumentFilter(5.2387m, 10.1271m))); + Assert.False(new IsBetweenArgumentFilter("foo", "bar").Equals(new IsBetweenArgumentFilter("foo", null))); + } + + [Fact] + public void equals_returns_true_if_given_a_filter_with_the_same_range() + { + Assert.True(new IsBetweenArgumentFilter(5, 10).Equals(new IsBetweenArgumentFilter(5, 10))); + Assert.True(new IsBetweenArgumentFilter(5.2387m, 10.127m).Equals(new IsBetweenArgumentFilter(5.2387m, 10.127m))); + Assert.True(new IsBetweenArgumentFilter("foo", "bar").Equals(new IsBetweenArgumentFilter("foo", "bar"))); + } + + [Fact] + public void ranges_are_automatically_inverted_as_necessary() + { + Assert.True(new IsBetweenArgumentFilter(5, 10).Equals(new IsBetweenArgumentFilter(10, 5))); + Assert.True(new IsBetweenArgumentFilter(5.2387m, 10.127m).Equals(new IsBetweenArgumentFilter(10.127m, 5.2387m))); + Assert.True(new IsBetweenArgumentFilter("foo", "bar").Equals(new IsBetweenArgumentFilter("bar", "foo"))); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsGreaterThanArgumentFilterFixture.cs b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsGreaterThanArgumentFilterFixture.cs new file mode 100644 index 0000000..1b8a3e3 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsGreaterThanArgumentFilterFixture.cs @@ -0,0 +1,62 @@ +namespace PCLMock.ArgumentFilters.UnitTests +{ + using PCLMock.ArgumentFilters; + using Xunit; + + public sealed class IsGreaterThanArgumentFilterFixture + { + [Fact] + public void matches_returns_false_if_value_is_equal_to_specified_value() + { + Assert.False(new IsGreaterThanArgumentFilter(5).Matches(5)); + Assert.False(new IsGreaterThanArgumentFilter(5.152m).Matches(5.152m)); + Assert.False(new IsGreaterThanArgumentFilter(null).Matches(null)); + } + + [Fact] + public void matches_returns_true_if_value_is_greater_than_specified_value() + { + Assert.True(new IsGreaterThanArgumentFilter(5).Matches(6)); + Assert.True(new IsGreaterThanArgumentFilter(5.152m).Matches(5.153m)); + Assert.True(new IsGreaterThanArgumentFilter(null).Matches("foo")); + } + + [Fact] + public void matches_returns_false_if_value_is_less_than_specified_value() + { + Assert.False(new IsGreaterThanArgumentFilter(5).Matches(4)); + Assert.False(new IsGreaterThanArgumentFilter(5.142m).Matches(5.141m)); + Assert.False(new IsGreaterThanArgumentFilter("foo").Matches(null)); + } + + [Fact] + public void has_a_nice_string_representation() + { + Assert.Equal("It.IsGreaterThan(10)", new IsGreaterThanArgumentFilter(10).ToString()); + Assert.Equal("It.IsGreaterThan(15.182M)", new IsGreaterThanArgumentFilter(15.182m).ToString()); + Assert.Equal("It.IsGreaterThan(null)", new IsGreaterThanArgumentFilter(null).ToString()); + } + + [Fact] + public void equals_returns_false_if_given_a_filter_for_a_different_type() + { + Assert.False(new IsGreaterThanArgumentFilter("foo").Equals(new IsGreaterThanArgumentFilter(10))); + } + + [Fact] + public void equals_returns_false_if_given_a_filter_with_a_different_specified_value() + { + Assert.False(new IsGreaterThanArgumentFilter("foo").Equals(new IsGreaterThanArgumentFilter("bar"))); + Assert.False(new IsGreaterThanArgumentFilter("foo").Equals(new IsGreaterThanArgumentFilter(null))); + Assert.False(new IsGreaterThanArgumentFilter(null).Equals(new IsGreaterThanArgumentFilter("foo"))); + } + + [Fact] + public void equals_returns_true_if_given_a_filter_with_the_same_specified_value() + { + Assert.True(new IsGreaterThanArgumentFilter("foo").Equals(new IsGreaterThanArgumentFilter("foo"))); + Assert.True(new IsGreaterThanArgumentFilter(150).Equals(new IsGreaterThanArgumentFilter(150))); + Assert.True(new IsGreaterThanArgumentFilter(null).Equals(new IsGreaterThanArgumentFilter(null))); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsGreaterThanOrEqualToArgumentFilterFixture.cs b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsGreaterThanOrEqualToArgumentFilterFixture.cs new file mode 100644 index 0000000..05e81e1 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsGreaterThanOrEqualToArgumentFilterFixture.cs @@ -0,0 +1,62 @@ +namespace PCLMock.ArgumentFilters.UnitTests +{ + using PCLMock.ArgumentFilters; + using Xunit; + + public sealed class IsGreaterThanOrEqualToArgumentFilterFixture + { + [Fact] + public void matches_returns_true_if_value_is_equal_to_specified_value() + { + Assert.True(new IsGreaterThanOrEqualToArgumentFilter(5).Matches(5)); + Assert.True(new IsGreaterThanOrEqualToArgumentFilter(5.152m).Matches(5.152m)); + Assert.True(new IsGreaterThanOrEqualToArgumentFilter(null).Matches(null)); + } + + [Fact] + public void matches_returns_true_if_value_is_greater_than_specified_value() + { + Assert.True(new IsGreaterThanOrEqualToArgumentFilter(5).Matches(6)); + Assert.True(new IsGreaterThanOrEqualToArgumentFilter(5.152m).Matches(5.153m)); + Assert.True(new IsGreaterThanOrEqualToArgumentFilter(null).Matches("foo")); + } + + [Fact] + public void matches_returns_false_if_value_is_less_than_specified_value() + { + Assert.False(new IsGreaterThanOrEqualToArgumentFilter(5).Matches(4)); + Assert.False(new IsGreaterThanOrEqualToArgumentFilter(5.142m).Matches(5.141m)); + Assert.False(new IsGreaterThanOrEqualToArgumentFilter("foo").Matches(null)); + } + + [Fact] + public void has_a_nice_string_representation() + { + Assert.Equal("It.IsGreaterThanOrEqualTo(10)", new IsGreaterThanOrEqualToArgumentFilter(10).ToString()); + Assert.Equal("It.IsGreaterThanOrEqualTo(15.182M)", new IsGreaterThanOrEqualToArgumentFilter(15.182m).ToString()); + Assert.Equal("It.IsGreaterThanOrEqualTo(null)", new IsGreaterThanOrEqualToArgumentFilter(null).ToString()); + } + + [Fact] + public void equals_returns_false_if_given_a_filter_for_a_different_type() + { + Assert.False(new IsGreaterThanOrEqualToArgumentFilter("foo").Equals(new IsGreaterThanOrEqualToArgumentFilter(10))); + } + + [Fact] + public void equals_returns_false_if_given_a_filter_with_a_different_specified_value() + { + Assert.False(new IsGreaterThanOrEqualToArgumentFilter("foo").Equals(new IsGreaterThanOrEqualToArgumentFilter("bar"))); + Assert.False(new IsGreaterThanOrEqualToArgumentFilter("foo").Equals(new IsGreaterThanOrEqualToArgumentFilter(null))); + Assert.False(new IsGreaterThanOrEqualToArgumentFilter(null).Equals(new IsGreaterThanOrEqualToArgumentFilter("foo"))); + } + + [Fact] + public void equals_returns_true_if_given_a_filter_with_the_same_specified_value() + { + Assert.True(new IsGreaterThanOrEqualToArgumentFilter("foo").Equals(new IsGreaterThanOrEqualToArgumentFilter("foo"))); + Assert.True(new IsGreaterThanOrEqualToArgumentFilter(150).Equals(new IsGreaterThanOrEqualToArgumentFilter(150))); + Assert.True(new IsGreaterThanOrEqualToArgumentFilter(null).Equals(new IsGreaterThanOrEqualToArgumentFilter(null))); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsInArgumentFilterFixture.cs b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsInArgumentFilterFixture.cs new file mode 100644 index 0000000..98e083b --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsInArgumentFilterFixture.cs @@ -0,0 +1,66 @@ +namespace PCLMock.ArgumentFilters.UnitTests +{ + using PCLMock.ArgumentFilters; + using Xunit; + + public sealed class IsInArgumentFilterFixture + { + [Fact] + public void matches_returns_false_if_no_values_are_provided() + { + Assert.False(new IsInArgumentFilter().Matches("foo")); + Assert.False(new IsInArgumentFilter().Matches(null)); + } + + [Fact] + public void matches_returns_false_if_value_is_not_in_set_of_expected_values() + { + Assert.False(new IsInArgumentFilter("hello", "world").Matches("Hello")); + Assert.False(new IsInArgumentFilter(1, 2, 3, 5, 8, 13).Matches(11)); + Assert.False(new IsInArgumentFilter("hello", "world").Matches(null)); + } + + [Fact] + public void matches_returns_true_if_value_is_in_set_of_expected_values() + { + Assert.True(new IsInArgumentFilter("hello", "world").Matches("world")); + Assert.True(new IsInArgumentFilter(1, 2, 3, 5, 8, 13).Matches(5)); + Assert.True(new IsInArgumentFilter("hello", null, "world").Matches(null)); + } + + [Fact] + public void has_a_nice_string_representation() + { + // being that a HashSet is used as the underlying storage mechanism, the order of items isn't really predictable here + Assert.Equal("It.IsIn(\"hello\", \"world\")", new IsInArgumentFilter("hello", "world").ToString()); + Assert.Equal("It.IsIn(3, 5, 10)", new IsInArgumentFilter(3, 5, 10).ToString()); + Assert.Equal("It.IsIn(15.182M, 2.812M)", new IsInArgumentFilter(15.182m, 2.812M).ToString()); + Assert.Equal("It.IsIn(\"foo\", null)", new IsInArgumentFilter("foo", null).ToString()); + } + + [Fact] + public void equals_returns_false_if_given_a_filter_for_a_different_type() + { + Assert.False(new IsInArgumentFilter("foo").Equals(new IsInArgumentFilter(10))); + } + + [Fact] + public void equals_returns_false_if_given_a_filter_with_different_expected_values() + { + Assert.False(new IsInArgumentFilter("foo").Equals(new IsInArgumentFilter("bar"))); + Assert.False(new IsInArgumentFilter("foo").Equals(new IsInArgumentFilter("foo", "bar"))); + Assert.False(new IsInArgumentFilter("foo").Equals(new IsInArgumentFilter(null))); + Assert.False(new IsInArgumentFilter(null).Equals(new IsInArgumentFilter("foo"))); + } + + [Fact] + public void equals_returns_true_if_given_a_filter_with_the_same_expected_values() + { + Assert.True(new IsInArgumentFilter("foo").Equals(new IsInArgumentFilter("foo"))); + Assert.True(new IsInArgumentFilter(null).Equals(new IsInArgumentFilter(null))); + Assert.True(new IsInArgumentFilter("foo", "bar").Equals(new IsInArgumentFilter("bar", "foo"))); + Assert.True(new IsInArgumentFilter("foo", null, "bar").Equals(new IsInArgumentFilter(null, "bar", "foo"))); + Assert.True(new IsInArgumentFilter(1, 0, 150, -29).Equals(new IsInArgumentFilter(150, -29, 0, 1))); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsLikeArgumentFilterFixture.cs b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsLikeArgumentFilterFixture.cs new file mode 100644 index 0000000..115dc80 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsLikeArgumentFilterFixture.cs @@ -0,0 +1,50 @@ +namespace PCLMock.ArgumentFilters.UnitTests +{ + using System.Text.RegularExpressions; + using PCLMock.ArgumentFilters; + using Xunit; + + public sealed class IsLikeArgumentFilterFixture + { + [Fact] + public void matches_returns_false_if_values_do_not_match() + { + Assert.False(new IsLikeArgumentFilter("[hH]ello", RegexOptions.None).Matches("world")); + Assert.False(new IsLikeArgumentFilter("hello", RegexOptions.None).Matches(null)); + } + + [Fact] + public void matches_returns_true_if_values_match() + { + Assert.True(new IsLikeArgumentFilter("[hH]ello", RegexOptions.None).Matches("Hello")); + Assert.True(new IsLikeArgumentFilter("[hH]ello", RegexOptions.None).Matches("hello")); + Assert.True(new IsLikeArgumentFilter("hello.", RegexOptions.IgnoreCase).Matches("HELLO!")); + } + + [Fact] + public void has_a_nice_string_representation() + { + Assert.Equal("It.IsLike(\"[hH]ello\")", new IsLikeArgumentFilter("[hH]ello", RegexOptions.None).ToString()); + } + + [Fact] + public void equals_returns_false_if_given_a_filter_with_a_different_pattern() + { + Assert.False(new IsLikeArgumentFilter("foo", RegexOptions.None).Equals(new IsLikeArgumentFilter("bar", RegexOptions.None))); + Assert.False(new IsLikeArgumentFilter("foo", RegexOptions.None).Equals(new IsLikeArgumentFilter("Foo", RegexOptions.None))); + } + + [Fact] + public void equals_returns_false_if_given_a_filter_with_different_options() + { + Assert.False(new IsLikeArgumentFilter("foo", RegexOptions.None).Equals(new IsLikeArgumentFilter("foo", RegexOptions.Multiline))); + } + + [Fact] + public void equals_returns_true_if_given_a_filter_with_the_same_pattern_and_options() + { + Assert.True(new IsLikeArgumentFilter("foo", RegexOptions.None).Equals(new IsLikeArgumentFilter("foo", RegexOptions.None))); + Assert.True(new IsLikeArgumentFilter("foo", RegexOptions.Multiline | RegexOptions.Compiled).Equals(new IsLikeArgumentFilter("foo", RegexOptions.Multiline | RegexOptions.Compiled))); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsNullArgumentFilterFixture.cs b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsNullArgumentFilterFixture.cs new file mode 100644 index 0000000..29dbc32 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsNullArgumentFilterFixture.cs @@ -0,0 +1,44 @@ +namespace PCLMock.ArgumentFilters.UnitTests +{ + using System; + using System.Text; + using PCLMock.ArgumentFilters; + using Xunit; + + public sealed class IsNullArgumentFilterFixture + { + [Fact] + public void matches_returns_false_if_value_is_not_null() + { + Assert.False(IsNullArgumentFilter.Instance.Matches("hello")); + Assert.False(IsNullArgumentFilter.Instance.Matches("world")); + } + + [Fact] + public void matches_returns_true_if_value_is_null() + { + Assert.True(IsNullArgumentFilter.Instance.Matches(null)); + } + + [Fact] + public void has_a_nice_string_representation() + { + Assert.Equal("It.IsNull()", IsNullArgumentFilter.Instance.ToString()); + Assert.Equal("It.IsNull()", IsNullArgumentFilter.Instance.ToString()); + Assert.Equal("It.IsNull()", IsNullArgumentFilter.Instance.ToString()); + } + + [Fact] + public void equals_returns_false_if_given_a_filter_for_a_different_type() + { + Assert.False(IsNullArgumentFilter.Instance.Equals(IsNullArgumentFilter.Instance)); + } + + [Fact] + public void equals_returns_true_if_given_a_filter_for_the_same_type() + { + Assert.True(IsNullArgumentFilter.Instance.Equals(IsNullArgumentFilter.Instance)); + Assert.True(IsNullArgumentFilter.Instance.Equals(IsNullArgumentFilter.Instance)); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsOfTypeArgumentFilterFixture.cs b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsOfTypeArgumentFilterFixture.cs new file mode 100644 index 0000000..cce6f7c --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsOfTypeArgumentFilterFixture.cs @@ -0,0 +1,45 @@ +namespace PCLMock.ArgumentFilters.UnitTests +{ + using System; + using System.Text; + using PCLMock.ArgumentFilters; + using Xunit; + + public sealed class IsOfTypeArgumentFilterFixture + { + [Fact] + public void matches_returns_false_if_value_is_not_of_specified_type() + { + Assert.False(IsOfTypeArgumentFilter.Instance.Matches(1)); + Assert.False(IsOfTypeArgumentFilter.Instance.Matches(new StringBuilder())); + } + + [Fact] + public void matches_returns_true_if_value_is_of_specified_type() + { + Assert.True(IsOfTypeArgumentFilter.Instance.Matches("foo")); + Assert.True(IsOfTypeArgumentFilter.Instance.Matches(1)); + } + + [Fact] + public void has_a_nice_string_representation() + { + Assert.Equal("It.IsOfType()", IsOfTypeArgumentFilter.Instance.ToString()); + } + + [Fact] + public void equals_returns_false_if_given_a_filter_for_a_different_type() + { + Assert.False(IsOfTypeArgumentFilter.Instance.Equals(IsOfTypeArgumentFilter.Instance)); + Assert.False(IsOfTypeArgumentFilter>.Instance.Equals(IsOfTypeArgumentFilter>.Instance)); + } + + [Fact] + public void equals_returns_true_if_given_a_filter_for_the_same_type() + { + Assert.True(IsOfTypeArgumentFilter.Instance.Equals(IsOfTypeArgumentFilter.Instance)); + Assert.True(IsOfTypeArgumentFilter.Instance.Equals(IsOfTypeArgumentFilter.Instance)); + Assert.True(IsOfTypeArgumentFilter.Instance.Equals(IsOfTypeArgumentFilter.Instance)); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/LogicalNotArgumentFilterFixture.cs b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/LogicalNotArgumentFilterFixture.cs new file mode 100644 index 0000000..531437d --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/LogicalNotArgumentFilterFixture.cs @@ -0,0 +1,41 @@ +namespace PCLMock.ArgumentFilters.UnitTests +{ + using PCLMock.ArgumentFilters; + using Xunit; + + public sealed class LogicalNotArgumentFilterFixture + { + [Fact] + public void matches_returns_opposite_of_what_child_returns() + { + var child = new IsArgumentFilter("foo"); + var argumentFilter = new LogicalNotArgumentFilter(child); + + Assert.False(argumentFilter.Matches("foo")); + Assert.True(argumentFilter.Matches("bar")); + } + + [Fact] + public void has_a_nice_string_representation() + { + var child = new IsArgumentFilter("foo"); + var argumentFilter = new LogicalNotArgumentFilter(child); + + Assert.Equal("NOT(It.Is(\"foo\"))", argumentFilter.ToString()); + } + + [Fact] + public void equals_returns_uses_childs_equality_to_determine_result() + { + var child1 = new IsArgumentFilter("foo"); + var child2 = new IsArgumentFilter("bar"); + var child3 = new IsArgumentFilter("foo"); + var argumentFilter1 = new LogicalNotArgumentFilter(child1); + var argumentFilter2 = new LogicalNotArgumentFilter(child2); + var argumentFilter3 = new LogicalNotArgumentFilter(child3); + + Assert.False(argumentFilter1.Equals(argumentFilter2)); + Assert.True(argumentFilter1.Equals(argumentFilter3)); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/MatchesArgumentFilterFixture.cs b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/MatchesArgumentFilterFixture.cs new file mode 100644 index 0000000..e65b64c --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/MatchesArgumentFilterFixture.cs @@ -0,0 +1,57 @@ +namespace PCLMock.ArgumentFilters.UnitTests +{ + using System; + using PCLMock.ArgumentFilters; + using Xunit; + using Xunit.Extensions; + + public sealed class MatchesArgumentFilterFixture + { + [Theory] + [InlineData(0, true)] + [InlineData(1, false)] + [InlineData(2, true)] + [InlineData(3, false)] + [InlineData(4, true)] + public void matches_returns_correct_value(object value, bool expectedResult) + { + Assert.Equal(expectedResult, new MatchesArgumentFilter(x => x % 2 == 0).Matches(value)); + } + + [Fact] + public void has_a_nice_string_representation() + { + Assert.Equal("It.Matches()", new MatchesArgumentFilter(_ => true).ToString()); + Assert.Equal("It.Matches()", new MatchesArgumentFilter(_ => true).ToString()); + } + + [Fact] + public void equals_returns_false_if_given_a_filter_for_a_different_type() + { + Assert.False(new MatchesArgumentFilter(_ => true).Equals(new MatchesArgumentFilter(_ => true))); + } + + [Fact] + public void equals_returns_false_if_given_a_filter_with_a_different_predicate() + { + Assert.False(new MatchesArgumentFilter(_ => true).Equals(new MatchesArgumentFilter(_ => false))); + Assert.False(new MatchesArgumentFilter(_ => false).Equals(new MatchesArgumentFilter(_ => true))); + Assert.False(new MatchesArgumentFilter(_ => true).Equals(new MatchesArgumentFilter(_ => false))); + Assert.False(new MatchesArgumentFilter(_ => false).Equals(new MatchesArgumentFilter(_ => true))); + } + + [Fact] + public void equals_returns_true_if_given_a_filter_with_the_same_predicate() + { + Func stringTruePredicate = _ => true; + Func stringFalsePredicate = _ => false; + Func intTruePredicate = _ => true; + Func intFalsePredicate = _ => false; + + Assert.True(new MatchesArgumentFilter(stringTruePredicate).Equals(new MatchesArgumentFilter(stringTruePredicate))); + Assert.True(new MatchesArgumentFilter(stringFalsePredicate).Equals(new MatchesArgumentFilter(stringFalsePredicate))); + Assert.True(new MatchesArgumentFilter(intTruePredicate).Equals(new MatchesArgumentFilter(intTruePredicate))); + Assert.True(new MatchesArgumentFilter(intFalsePredicate).Equals(new MatchesArgumentFilter(intFalsePredicate))); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixture.cs b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixture.cs new file mode 100644 index 0000000..3242e8e --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixture.cs @@ -0,0 +1,91 @@ +namespace PCLMock.UnitTests.CodeGeneration +{ + using System; + using System.Collections.Immutable; + using System.IO; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.Text; + using PCLMock.CodeGeneration; + using PCLMock.CodeGeneration.Logging; + using Xunit; + + public sealed class GeneratorFixture + { + [Theory] + [InlineData("SimpleInterface", Language.CSharp)] + [InlineData("InternalInterface", Language.CSharp)] + [InlineData("InterfaceWithGenericMethods", Language.CSharp)] + [InlineData("GenericInterface", Language.CSharp)] + [InlineData("NonMockableMembers", Language.CSharp)] + [InlineData("PartialInterface", Language.CSharp)] + [InlineData("InheritingInterface", Language.CSharp)] + [InlineData("DuplicateMember", Language.CSharp)] + [InlineData("NameClash", Language.CSharp)] + [InlineData("Indexers", Language.CSharp)] + [InlineData("OutAndRef", Language.CSharp)] + // TODO: VB is totally borked - calls to syntaxGenerator.WithStatements don't seem to add the statements! Will need to look into this at a later date + //[InlineData("SimpleInterface", Language.VisualBasic)] + //[InlineData("InterfaceWithGenericMethods", Language.VisualBasic)] + //[InlineData("GenericInterface", Language.VisualBasic)] + //[InlineData("InterfaceWithNonMockableMembers", Language.VisualBasic)] + //[InlineData("PartialInterface", Language.VisualBasic)] + //[InlineData("InheritingInterface", Language.VisualBasic)] + public async Task can_generate_mocks(string resourceBaseName, Language language) + { + var inputResourceName = "PCLMock.UnitTests.CodeGeneration.GeneratorFixtureResources." + resourceBaseName + "Input_" + language.ToString() + ".txt"; + var outputResourceName = "PCLMock.UnitTests.CodeGeneration.GeneratorFixtureResources." + resourceBaseName + "Output_" + language.ToString() + ".txt"; + + using (var inputStream = this.GetType().Assembly.GetManifestResourceStream(inputResourceName)) + using (var outputStream = this.GetType().Assembly.GetManifestResourceStream(outputResourceName)) + using (var outputStreamReader = new StreamReader(outputStream)) + { + var workspace = new AdhocWorkspace(); + var projectId = ProjectId.CreateNewId(); + var versionStamp = VersionStamp.Create(); + var projectInfo = ProjectInfo.Create( + projectId, + versionStamp, + "AdhocProject", + "AdhocProject", + language.ToSyntaxGeneratorLanguageName(), + metadataReferences: new[] + { + MetadataReference.CreateFromFile(typeof(object).Assembly.Location), + MetadataReference.CreateFromFile(typeof(Uri).Assembly.Location), + MetadataReference.CreateFromFile(typeof(MockBase<>).Assembly.Location) + }); + var project = workspace.AddProject(projectInfo); + workspace.AddDocument(projectId, "Source.cs", SourceText.From(inputStream)); + var solution = workspace.CurrentSolution; + + var results = + (await Generator.GenerateMocksAsync( + NullLogSink.Instance, + language, + solution, + x => true, + x => "The.Namespace", + x => "Mock", + ImmutableList.Empty)); + var result = results + .Last() + .ToString() + .NormalizeLineEndings(); + + var expectedCode = outputStreamReader.ReadToEnd(); + + // make sure version changes don't break the tests + expectedCode = expectedCode + .Replace("$VERSION$", typeof(MockBase<>).Assembly.GetName().Version.ToString()) + .NormalizeLineEndings(); + + // useful when converting generated code to something that can be pasted into an expectation file + var sanitisedResult = result.Replace(typeof(MockBase<>).Assembly.GetName().Version.ToString(), "$VERSION$"); + + Assert.Equal(expectedCode, result); + } + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/DuplicateMemberInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/DuplicateMemberInput_CSharp.txt new file mode 100644 index 0000000..9dab51f --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/DuplicateMemberInput_CSharp.txt @@ -0,0 +1,29 @@ +using System; + +public interface IFirstInterface +{ + void FirstMethod(); + + int DuplicateProperty + { + get; + } + + void DuplicateMethod(); +} + +public interface ISecondInterface +{ + void SecondMethod(); + + int DuplicateProperty + { + get; + } + + void DuplicateMethod(); +} + +public interface IThirdInterface : IFirstInterface, ISecondInterface +{ +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/DuplicateMemberOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/DuplicateMemberOutput_CSharp.txt new file mode 100644 index 0000000..dbeedc2 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/DuplicateMemberOutput_CSharp.txt @@ -0,0 +1,38 @@ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + public partial class Mock : global::PCLMock.MockBase, global::IThirdInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public void FirstMethod() + { + this.Apply(x => x.FirstMethod()); + } + + public void SecondMethod() + { + this.Apply(x => x.SecondMethod()); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/GenericInterfaceInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/GenericInterfaceInput_CSharp.txt new file mode 100644 index 0000000..943c5db --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/GenericInterfaceInput_CSharp.txt @@ -0,0 +1,14 @@ +using System; + +public interface IGenericInterface + where TFirst : IComparable, new() + where TSecond : struct +{ + TFirst SomeProperty + { + get; + set; + } + + TFirst DoSomething(TSecond input); +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/GenericInterfaceOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/GenericInterfaceOutput_CSharp.txt new file mode 100644 index 0000000..72e3bca --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/GenericInterfaceOutput_CSharp.txt @@ -0,0 +1,46 @@ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + public partial class Mock : global::PCLMock.MockBase>, global::IGenericInterface where TFirst : global::System.IComparable, new ()where TSecond : struct + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public TFirst SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + + set + { + this.ApplyPropertySet(x => x.SomeProperty, value); + } + } + + public TFirst DoSomething(TSecond input) + { + return this.Apply(x => x.DoSomething(input)); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/IndexersInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/IndexersInput_CSharp.txt new file mode 100644 index 0000000..5bc673d --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/IndexersInput_CSharp.txt @@ -0,0 +1,18 @@ +public interface ISomeInterface +{ + int this[int i] + { + get; + } + + string this[int i, float j] + { + get; + } + + string this[int i, float j, double d] + { + get; + set; + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/IndexersOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/IndexersOutput_CSharp.txt new file mode 100644 index 0000000..16d88d4 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/IndexersOutput_CSharp.txt @@ -0,0 +1,57 @@ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + public partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public System.Int32 this[System.Int32 i] + { + get + { + return this.Apply(x => x[i]); + } + } + + public System.String this[System.Int32 i, System.Single j] + { + get + { + return this.Apply(x => x[i, j]); + } + } + + public System.String this[System.Int32 i, System.Single j, System.Double d] + { + get + { + return this.Apply(x => x[i, j, d]); + } + + set + { + this.ApplyPropertySet(x => x[i, j, d], value); + } + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InheritingInterfaceInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InheritingInterfaceInput_CSharp.txt new file mode 100644 index 0000000..f5726ea --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InheritingInterfaceInput_CSharp.txt @@ -0,0 +1,9 @@ +using System; + +public interface IInheritingInterface : ICloneable +{ + int SomeProperty + { + get; + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InheritingInterfaceOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InheritingInterfaceOutput_CSharp.txt new file mode 100644 index 0000000..430dc63 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InheritingInterfaceOutput_CSharp.txt @@ -0,0 +1,41 @@ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + public partial class Mock : global::PCLMock.MockBase, global::IInheritingInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public System.Int32 SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + + public System.Object Clone() + { + return this.Apply(x => x.Clone()); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InterfaceWithGenericMethodsInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InterfaceWithGenericMethodsInput_CSharp.txt new file mode 100644 index 0000000..de2882d --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InterfaceWithGenericMethodsInput_CSharp.txt @@ -0,0 +1,14 @@ +public interface IInterfaceWithGenericMethods +{ + void VoidMethodWithGenericParameter(); + + T NonVoidMethodWithGenericParameter(); + + void VoidMethodWithGenericArguments(TFirst first, TSecond second, TThird third, string somethingElse); + + TSecond NonVoidMethodWithGenericArguments(TFirst input); + + TSecond MethodWithTypeConstraints(TFirst input, int option) + where TFirst : IComparable, new() + where TSecond : struct; +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InterfaceWithGenericMethodsOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InterfaceWithGenericMethodsOutput_CSharp.txt new file mode 100644 index 0000000..70d3674 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InterfaceWithGenericMethodsOutput_CSharp.txt @@ -0,0 +1,53 @@ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + public partial class Mock : global::PCLMock.MockBase, global::IInterfaceWithGenericMethods + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public void VoidMethodWithGenericParameter() + { + this.Apply(x => x.VoidMethodWithGenericParameter()); + } + + public T NonVoidMethodWithGenericParameter() + { + return this.Apply(x => x.NonVoidMethodWithGenericParameter()); + } + + public void VoidMethodWithGenericArguments(TFirst first, TSecond second, TThird third, System.String somethingElse) + { + this.Apply(x => x.VoidMethodWithGenericArguments(first, second, third, somethingElse)); + } + + public TSecond NonVoidMethodWithGenericArguments(TFirst input) + { + return this.Apply(x => x.NonVoidMethodWithGenericArguments(input)); + } + + public TSecond MethodWithTypeConstraints(TFirst input, System.Int32 option)where TFirst : IComparable, new ()where TSecond : struct + { + return this.Apply(x => x.MethodWithTypeConstraints(input, option)); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InternalInterfaceInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InternalInterfaceInput_CSharp.txt new file mode 100644 index 0000000..440a1de --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InternalInterfaceInput_CSharp.txt @@ -0,0 +1,26 @@ +internal interface IInternalInterface +{ + int GetProperty + { + get; + } + + int SetProperty + { + set; + } + + int GetSetProperty + { + get; + set; + } + + void VoidMethod(); + + void VoidMethodWithArguments(int i, string s); + + string NonVoidMethod(); + + string NonVoidMethodWithArguments(int i, string s); +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InternalInterfaceOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InternalInterfaceOutput_CSharp.txt new file mode 100644 index 0000000..7b1e5cc --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InternalInterfaceOutput_CSharp.txt @@ -0,0 +1,69 @@ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase, global::IInternalInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public System.Int32 GetProperty + { + get + { + return this.Apply(x => x.GetProperty); + } + } + + public System.Int32 GetSetProperty + { + get + { + return this.Apply(x => x.GetSetProperty); + } + + set + { + this.ApplyPropertySet(x => x.GetSetProperty, value); + } + } + + public void VoidMethod() + { + this.Apply(x => x.VoidMethod()); + } + + public void VoidMethodWithArguments(System.Int32 i, System.String s) + { + this.Apply(x => x.VoidMethodWithArguments(i, s)); + } + + public System.String NonVoidMethod() + { + return this.Apply(x => x.NonVoidMethod()); + } + + public System.String NonVoidMethodWithArguments(System.Int32 i, System.String s) + { + return this.Apply(x => x.NonVoidMethodWithArguments(i, s)); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NameClashInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NameClashInput_CSharp.txt new file mode 100644 index 0000000..d5f31b5 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NameClashInput_CSharp.txt @@ -0,0 +1,16 @@ +using System; + +public interface ISomeInterface +{ + int this[int x] + { + get; + set; + } + + void SomeMethod(int x); + + void SomeMethod(int x, int _x); + + void SomeMethod(out float f, float _f); +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NameClashOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NameClashOutput_CSharp.txt new file mode 100644 index 0000000..e7f6409 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NameClashOutput_CSharp.txt @@ -0,0 +1,58 @@ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + public partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public System.Int32 this[System.Int32 x] + { + get + { + return this.Apply(_x => _x[x]); + } + + set + { + this.ApplyPropertySet(_x => _x[x], value); + } + } + + public void SomeMethod(System.Int32 x) + { + this.Apply(_x => _x.SomeMethod(x)); + } + + public void SomeMethod(System.Int32 x, System.Int32 _x) + { + this.Apply(__x => __x.SomeMethod(x, _x)); + } + + public void SomeMethod(out System.Single f, System.Single _f) + { + System.Single __f; + f = (this.GetOutParameterValue(x => x.SomeMethod(out __f, _f), 0)); + this.Apply(x => x.SomeMethod(out __f, _f)); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NonMockableMembersInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NonMockableMembersInput_CSharp.txt new file mode 100644 index 0000000..74c7124 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NonMockableMembersInput_CSharp.txt @@ -0,0 +1,13 @@ +using System; + +public interface IInterfaceWithNonMockableMembers +{ + int SomeProperty + { + get; + set; + } + + // PCLMock does not yet support mocking events (and possibly never will) + event EventHandler SomeEvent; +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NonMockableMembersOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NonMockableMembersOutput_CSharp.txt new file mode 100644 index 0000000..f238c17 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NonMockableMembersOutput_CSharp.txt @@ -0,0 +1,41 @@ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + public partial class Mock : global::PCLMock.MockBase, global::IInterfaceWithNonMockableMembers + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public System.Int32 SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + + set + { + this.ApplyPropertySet(x => x.SomeProperty, value); + } + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/OutAndRefInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/OutAndRefInput_CSharp.txt new file mode 100644 index 0000000..bf5e9be --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/OutAndRefInput_CSharp.txt @@ -0,0 +1,12 @@ +public interface ISomeInterface +{ + void SomeMethod(out int i); + + void SomeMethod(out double d, int i); + + void SomeMethod(int i, out double d); + + void SomeMethod(ref int i, out string s); + + void SomeMethod(ref int i, out string s, double d); +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/OutAndRefOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/OutAndRefOutput_CSharp.txt new file mode 100644 index 0000000..44e322d --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/OutAndRefOutput_CSharp.txt @@ -0,0 +1,67 @@ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + public partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public void SomeMethod(out System.Int32 i) + { + System.Int32 _i; + i = (this.GetOutParameterValue(x => x.SomeMethod(out _i), 0)); + this.Apply(x => x.SomeMethod(out _i)); + } + + public void SomeMethod(out System.Double d, System.Int32 i) + { + System.Double _d; + d = (this.GetOutParameterValue(x => x.SomeMethod(out _d, i), 0)); + this.Apply(x => x.SomeMethod(out _d, i)); + } + + public void SomeMethod(System.Int32 i, out System.Double d) + { + System.Double _d; + d = (this.GetOutParameterValue(x => x.SomeMethod(i, out _d), 1)); + this.Apply(x => x.SomeMethod(i, out _d)); + } + + public void SomeMethod(ref System.Int32 i, out System.String s) + { + var _i = default (System.Int32); + System.String _s; + i = (this.GetRefParameterValue(x => x.SomeMethod(ref _i, out _s), 0)); + s = (this.GetOutParameterValue(x => x.SomeMethod(ref _i, out _s), 1)); + this.Apply(x => x.SomeMethod(ref _i, out _s)); + } + + public void SomeMethod(ref System.Int32 i, out System.String s, System.Double d) + { + var _i = default (System.Int32); + System.String _s; + i = (this.GetRefParameterValue(x => x.SomeMethod(ref _i, out _s, d), 0)); + s = (this.GetOutParameterValue(x => x.SomeMethod(ref _i, out _s, d), 1)); + this.Apply(x => x.SomeMethod(ref _i, out _s, d)); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/PartialInterfaceInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/PartialInterfaceInput_CSharp.txt new file mode 100644 index 0000000..80ddc6f --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/PartialInterfaceInput_CSharp.txt @@ -0,0 +1,15 @@ +public partial interface IPartialInterface +{ + int Property1 + { + get; + } +} + +public partial interface IPartialInterface +{ + int Property2 + { + get; + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/PartialInterfaceOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/PartialInterfaceOutput_CSharp.txt new file mode 100644 index 0000000..7c12142 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/PartialInterfaceOutput_CSharp.txt @@ -0,0 +1,44 @@ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + public partial class Mock : global::PCLMock.MockBase, global::IPartialInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public System.Int32 Property1 + { + get + { + return this.Apply(x => x.Property1); + } + } + + public System.Int32 Property2 + { + get + { + return this.Apply(x => x.Property2); + } + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceInput_CSharp.txt new file mode 100644 index 0000000..27c5137 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceInput_CSharp.txt @@ -0,0 +1,26 @@ +public interface ISimpleInterface +{ + int GetProperty + { + get; + } + + int SetProperty + { + set; + } + + int GetSetProperty + { + get; + set; + } + + void VoidMethod(); + + void VoidMethodWithArguments(int i, string s); + + string NonVoidMethod(); + + string NonVoidMethodWithArguments(int i, string s); +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceInput_VisualBasic.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceInput_VisualBasic.txt similarity index 100% rename from Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceInput_VisualBasic.txt rename to Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceInput_VisualBasic.txt diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceOutput_CSharp.txt new file mode 100644 index 0000000..63fb4a9 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceOutput_CSharp.txt @@ -0,0 +1,69 @@ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + public partial class Mock : global::PCLMock.MockBase, global::ISimpleInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public System.Int32 GetProperty + { + get + { + return this.Apply(x => x.GetProperty); + } + } + + public System.Int32 GetSetProperty + { + get + { + return this.Apply(x => x.GetSetProperty); + } + + set + { + this.ApplyPropertySet(x => x.GetSetProperty, value); + } + } + + public void VoidMethod() + { + this.Apply(x => x.VoidMethod()); + } + + public void VoidMethodWithArguments(System.Int32 i, System.String s) + { + this.Apply(x => x.VoidMethodWithArguments(i, s)); + } + + public System.String NonVoidMethod() + { + return this.Apply(x => x.NonVoidMethod()); + } + + public System.String NonVoidMethodWithArguments(System.Int32 i, System.String s) + { + return this.Apply(x => x.NonVoidMethodWithArguments(i, s)); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceOutput_VisualBasic.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceOutput_VisualBasic.txt similarity index 100% rename from Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceOutput_VisualBasic.txt rename to Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceOutput_VisualBasic.txt diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Models/ConfigurationFixture.cs b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Models/ConfigurationFixture.cs new file mode 100644 index 0000000..6fdbf04 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Models/ConfigurationFixture.cs @@ -0,0 +1,46 @@ +namespace PCLMock.UnitTests.CodeGeneration.Models +{ + using System.Xml.Linq; + using PCLMock.CodeGeneration.Logging; + using PCLMock.CodeGeneration.Models; + using Xunit; + + public sealed class ConfigurationFixture + { + [Fact] + public void from_xdocument_works_as_expected() + { + var inputResourceName = "PCLMock.UnitTests.CodeGeneration.Models.ConfigurationFixtureResources.Input.txt"; + + using (var inputStream = this.GetType().Assembly.GetManifestResourceStream(inputResourceName)) + { + var document = XDocument.Load(inputStream); + var configuration = Configuration.FromXDocument(NullLogSink.Instance, document); + + Assert.Equal(2, configuration.NamespaceTransformations.Count); + Assert.Equal("(?.+)", configuration.NamespaceTransformations[0].Pattern); + Assert.Equal("${name}.Mocks", configuration.NamespaceTransformations[0].Replacement); + Assert.Equal("Up", configuration.NamespaceTransformations[1].Pattern); + Assert.Equal("Down", configuration.NamespaceTransformations[1].Replacement); + + Assert.Equal(3, configuration.NameTransformations.Count); + Assert.Equal("I(?[A-Z].*)", configuration.NameTransformations[0].Pattern); + Assert.Equal("${name}", configuration.NameTransformations[0].Replacement); + Assert.Equal("(?[A-Z].*)\\<.*\\>", configuration.NameTransformations[1].Pattern); + Assert.Equal("${name}", configuration.NameTransformations[1].Replacement); + Assert.Equal("(?.+)", configuration.NameTransformations[2].Pattern); + Assert.Equal("${name}Mock", configuration.NameTransformations[2].Replacement); + + Assert.Equal(2, configuration.InterfaceFilters.Count); + Assert.Equal(FilterType.Include, configuration.InterfaceFilters[0].Type); + Assert.Equal(".*", configuration.InterfaceFilters[0].Pattern); + Assert.Equal(FilterType.Exclude, configuration.InterfaceFilters[1].Type); + Assert.Equal("FooBar", configuration.InterfaceFilters[1].Pattern); + + Assert.Equal(2, configuration.Plugins.Count); + Assert.Equal("Foo.Bar.Something, PCLMock.CodeGeneration", configuration.Plugins[0].AssemblyQualifiedName); + Assert.Equal("Foo.Bar.Baz, SomeAssembly", configuration.Plugins[1].AssemblyQualifiedName); + } + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Models/ConfigurationFixtureResources/Input.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Models/ConfigurationFixtureResources/Input.txt new file mode 100644 index 0000000..92fa89c --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Models/ConfigurationFixtureResources/Input.txt @@ -0,0 +1,96 @@ + + + + + + + + + .+)]]> + ${name}.Mocks + + + + + + + Up + Down + + + + + + + + [A-Z].*)]]> + ${name} + + + + [A-Z].*)\<.*\>]]> + ${name} + + + + .+)]]> + ${name}Mock + + + + + + + + + .* + + + + + FooBar + + + + + + + Foo.Bar.Something, PCLMock.CodeGeneration + Foo.Bar.Baz, SomeAssembly + + \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixture.cs b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixture.cs new file mode 100644 index 0000000..fe29c93 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixture.cs @@ -0,0 +1,102 @@ +namespace PCLMock.UnitTests.CodeGeneration.Plugins +{ + using System; + using System.Collections.Immutable; + using System.IO; + using System.Linq; + using System.Reactive.Linq; + using System.Text; + using System.Threading.Tasks; + using Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.Text; + using PCLMock.CodeGeneration; + using PCLMock.CodeGeneration.Logging; + using PCLMock.CodeGeneration.Plugins; + using Xunit; + + public sealed class CollectionsFixture + { + [Theory] + [InlineData("Enumerables", Language.CSharp)] + [InlineData("Collections", Language.CSharp)] + [InlineData("Lists", Language.CSharp)] + [InlineData("Dictionaries", Language.CSharp)] + [InlineData("Sets", Language.CSharp)] + [InlineData("ImmutableLists", Language.CSharp)] + [InlineData("ImmutableDictionaries", Language.CSharp)] + [InlineData("ImmutableQueues", Language.CSharp)] + [InlineData("ImmutableSets", Language.CSharp)] + [InlineData("ImmutableStacks", Language.CSharp)] + [InlineData("Recursive", Language.CSharp)] + public async Task can_generate_mocks(string resourceBaseName, Language language) + { + var inputResourceName = "PCLMock.UnitTests.CodeGeneration.Plugins.CollectionsFixtureResources." + resourceBaseName + "Input_" + language.ToString() + ".txt"; + var outputResourceName = "PCLMock.UnitTests.CodeGeneration.Plugins.CollectionsFixtureResources." + resourceBaseName + "Output_" + language.ToString() + ".txt"; + + using (var inputStream = this.GetType().Assembly.GetManifestResourceStream(inputResourceName)) + using (var outputStream = this.GetType().Assembly.GetManifestResourceStream(outputResourceName)) + using (var outputStreamReader = new StreamReader(outputStream)) + { + var workspace = new AdhocWorkspace(); + var projectId = ProjectId.CreateNewId(); + var versionStamp = VersionStamp.Create(); + var projectInfo = ProjectInfo.Create( + projectId, + versionStamp, + "AdhocProject", + "AdhocProject", + language.ToSyntaxGeneratorLanguageName(), + metadataReferences: new[] + { + MetadataReference.CreateFromFile(typeof(object).Assembly.Location), + MetadataReference.CreateFromFile(typeof(Uri).Assembly.Location), + MetadataReference.CreateFromFile(typeof(MockBase<>).Assembly.Location), + MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location), + MetadataReference.CreateFromFile(typeof(ImmutableList).Assembly.Location) + }); + var project = workspace.AddProject(projectInfo); + workspace.AddDocument(projectId, "Source.cs", SourceText.From(inputStream)); + var solution = workspace.CurrentSolution; + + var results = + (await Generator.GenerateMocksAsync( + NullLogSink.Instance, + language, + solution, + x => true, + x => "The.Namespace", + x => "Mock", + new IPlugin[] + { + new Collections() + }.ToImmutableList())); + var result = results + .Aggregate( + new StringBuilder(), + (acc, next) => + { + if (next != null) + { + acc.AppendLine(next.ToFullString()); + } + + return acc; + }, + acc => acc.ToString()) + .NormalizeLineEndings(); + + var expectedCode = outputStreamReader.ReadToEnd(); + + // make sure version changes don't break the tests + expectedCode = expectedCode + .Replace("$VERSION$", typeof(MockBase<>).Assembly.GetName().Version.ToString()) + .NormalizeLineEndings(); + + // useful when converting generated code to something that can be pasted into an expectation file + var sanitisedResult = result.Replace(typeof(MockBase<>).Assembly.GetName().Version.ToString(), "$VERSION$"); + + Assert.Equal(expectedCode, result); + } + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/CollectionsInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/CollectionsInput_CSharp.txt new file mode 100644 index 0000000..1c237cf --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/CollectionsInput_CSharp.txt @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; + +interface ICustomCollection : ICollection +{ +} + +interface ISomeInterface +{ + ICollection SomeProperty + { + get; + } + + // expecting this to be ignored because it's set-only + ICollection SomeSetOnlyProperty + { + set; + } + + IReadOnlyCollection SomeReadOnlyProperty + { + get; + } + + ICollection SomeMethod(); + ICollection SomeMethod(int i, float f); + + // should all be ignored because they're generic + ICollection SomeGenericMethod(); + ICollection SomeOtherGenericMethod(); + + // should be ignored because they're a custom enumerable type + ICustomCollection SomeCustomProperty + { + get; + } + + ICustomCollection SomeMethod(); + ICustomCollection SomeMethod(int i, float f); +} + +interface ISomeGenericInterface +{ + ICollection SomeProperty + { + get; + } + + ICollection SomeMethod(); + ICollection SomeMethod(int i, float f); +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/CollectionsOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/CollectionsOutput_CSharp.txt new file mode 100644 index 0000000..cc8d809 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/CollectionsOutput_CSharp.txt @@ -0,0 +1,217 @@ +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase>, global::ICustomCollection + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public void Add(T item) + { + this.Apply(x => x.Add(item)); + } + + public void Clear() + { + this.Apply(x => x.Clear()); + } + + public System.Boolean Contains(T item) + { + return this.Apply(x => x.Contains(item)); + } + + public void CopyTo(T[] array, System.Int32 arrayIndex) + { + this.Apply(x => x.CopyTo(array, arrayIndex)); + } + + public System.Boolean Remove(T item) + { + return this.Apply(x => x.Remove(item)); + } + + public System.Int32 Count + { + get + { + return this.Apply(x => x.Count); + } + } + + public System.Boolean IsReadOnly + { + get + { + return this.Apply(x => x.IsReadOnly); + } + } + + public global::System.Collections.Generic.IEnumerator GetEnumerator() + { + return this.Apply(x => x.GetEnumerator()); + } + } +} +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.List()); + this.When(x => x.SomeReadOnlyProperty).Return(new global::System.Collections.Generic.List()); + this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.List()); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.List()); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Collections.Generic.ICollection SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + + public global::System.Collections.Generic.IReadOnlyCollection SomeReadOnlyProperty + { + get + { + return this.Apply(x => x.SomeReadOnlyProperty); + } + } + + public global::System.Collections.Generic.ICollection SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::System.Collections.Generic.ICollection SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + + public global::System.Collections.Generic.ICollection SomeGenericMethod() + { + return this.Apply(x => x.SomeGenericMethod()); + } + + public global::System.Collections.Generic.ICollection SomeOtherGenericMethod() + { + return this.Apply(x => x.SomeOtherGenericMethod()); + } + + public global::ICustomCollection SomeCustomProperty + { + get + { + return this.Apply(x => x.SomeCustomProperty); + } + } + + public global::ICustomCollection SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::ICustomCollection SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + } +} +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.List()); + this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.List()); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.List()); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Collections.Generic.ICollection SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + + public global::System.Collections.Generic.ICollection SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::System.Collections.Generic.ICollection SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + } +} diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/DictionariesInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/DictionariesInput_CSharp.txt new file mode 100644 index 0000000..be2eb9f --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/DictionariesInput_CSharp.txt @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; + +interface ICustomDictionary : IDictionary +{ +} + +interface ISomeInterface +{ + IDictionary SomeProperty + { + get; + } + + // expecting this to be ignored because it's set-only + IDictionary SomeSetOnlyProperty + { + set; + } + + IReadOnlyDictionary SomeReadOnlyProperty + { + get; + } + + IDictionary SomeMethod(); + IDictionary SomeMethod(int i, float f); + + // should all be ignored because they're generic + IDictionary SomeGenericMethod(); + IDictionary SomeOtherGenericMethod(); + + // should be ignored because they're a custom enumerable type + ICustomDictionary SomeCustomProperty + { + get; + } + + ICustomDictionary SomeMethod(); + ICustomDictionary SomeMethod(int i, float f); +} + +interface ISomeGenericInterface +{ + IDictionary SomeProperty + { + get; + } + + IDictionary SomeMethod(); + IDictionary SomeMethod(int i, float f); +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/DictionariesOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/DictionariesOutput_CSharp.txt new file mode 100644 index 0000000..cbac9bc --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/DictionariesOutput_CSharp.txt @@ -0,0 +1,265 @@ +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase>, global::ICustomDictionary + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.Keys).Return(new global::System.Collections.Generic.List()); + this.When(x => x.Values).Return(new global::System.Collections.Generic.List()); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public System.Boolean ContainsKey(TKey key) + { + return this.Apply(x => x.ContainsKey(key)); + } + + public void Add(TKey key, TValue value) + { + this.Apply(x => x.Add(key, value)); + } + + public System.Boolean Remove(TKey key) + { + return this.Apply(x => x.Remove(key)); + } + + public System.Boolean TryGetValue(TKey key, out TValue value) + { + TValue _value; + value = (this.GetOutParameterValue(x => x.TryGetValue(key, out _value), 1)); + return this.Apply(x => x.TryGetValue(key, out _value)); + } + + public TValue this[TKey key] + { + get + { + return this.Apply(x => x[key]); + } + + set + { + this.ApplyPropertySet(x => x[key], value); + } + } + + public global::System.Collections.Generic.ICollection Keys + { + get + { + return this.Apply(x => x.Keys); + } + } + + public global::System.Collections.Generic.ICollection Values + { + get + { + return this.Apply(x => x.Values); + } + } + + public void Add(global::System.Collections.Generic.KeyValuePair item) + { + this.Apply(x => x.Add(item)); + } + + public void Clear() + { + this.Apply(x => x.Clear()); + } + + public System.Boolean Contains(global::System.Collections.Generic.KeyValuePair item) + { + return this.Apply(x => x.Contains(item)); + } + + public void CopyTo(global::System.Collections.Generic.KeyValuePair[] array, System.Int32 arrayIndex) + { + this.Apply(x => x.CopyTo(array, arrayIndex)); + } + + public System.Boolean Remove(global::System.Collections.Generic.KeyValuePair item) + { + return this.Apply(x => x.Remove(item)); + } + + public System.Int32 Count + { + get + { + return this.Apply(x => x.Count); + } + } + + public System.Boolean IsReadOnly + { + get + { + return this.Apply(x => x.IsReadOnly); + } + } + } +} +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.Dictionary()); + this.When(x => x.SomeReadOnlyProperty).Return(new global::System.Collections.Generic.Dictionary()); + this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.Dictionary()); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.Dictionary()); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Collections.Generic.IDictionary SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + + public global::System.Collections.Generic.IReadOnlyDictionary SomeReadOnlyProperty + { + get + { + return this.Apply(x => x.SomeReadOnlyProperty); + } + } + + public global::System.Collections.Generic.IDictionary SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::System.Collections.Generic.IDictionary SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + + public global::System.Collections.Generic.IDictionary SomeGenericMethod() + { + return this.Apply(x => x.SomeGenericMethod()); + } + + public global::System.Collections.Generic.IDictionary SomeOtherGenericMethod() + { + return this.Apply(x => x.SomeOtherGenericMethod()); + } + + public global::ICustomDictionary SomeCustomProperty + { + get + { + return this.Apply(x => x.SomeCustomProperty); + } + } + + public global::ICustomDictionary SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::ICustomDictionary SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + } +} +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.Dictionary()); + this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.Dictionary()); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.Dictionary()); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Collections.Generic.IDictionary SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + + public global::System.Collections.Generic.IDictionary SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::System.Collections.Generic.IDictionary SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + } +} diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/EnumerablesInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/EnumerablesInput_CSharp.txt new file mode 100644 index 0000000..305935d --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/EnumerablesInput_CSharp.txt @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; + +interface ICustomEnumerable : IEnumerable +{ +} + +interface ISomeInterface +{ + IEnumerable SomeProperty + { + get; + } + + // expecting this to be ignored because it's set-only + IEnumerable SomeSetOnlyProperty + { + set; + } + + IEnumerable SomeMethod(); + IEnumerable SomeMethod(int i, float f); + + // should all be ignored because they're generic + IEnumerable SomeGenericMethod(); + IEnumerable SomeOtherGenericMethod(); + + // should be ignored because they're a custom enumerable type + ICustomEnumerable SomeCustomProperty + { + get; + } + + ICustomEnumerable SomeMethod(); + ICustomEnumerable SomeMethod(int i, float f); +} + +interface ISomeGenericInterface +{ + IEnumerable SomeProperty + { + get; + } + + IEnumerable SomeMethod(); + IEnumerable SomeMethod(int i, float f); +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/EnumerablesOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/EnumerablesOutput_CSharp.txt new file mode 100644 index 0000000..b446501 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/EnumerablesOutput_CSharp.txt @@ -0,0 +1,172 @@ +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase>, global::ICustomEnumerable + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Collections.Generic.IEnumerator GetEnumerator() + { + return this.Apply(x => x.GetEnumerator()); + } + + public global::System.Collections.IEnumerator GetEnumerator() + { + return this.Apply(x => x.GetEnumerator()); + } + } +} +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeProperty).Return(global::System.Linq.Enumerable.Empty()); + this.When(x => x.SomeMethod()).Return(global::System.Linq.Enumerable.Empty()); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Linq.Enumerable.Empty()); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Collections.Generic.IEnumerable SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + + public global::System.Collections.Generic.IEnumerable SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::System.Collections.Generic.IEnumerable SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + + public global::System.Collections.Generic.IEnumerable SomeGenericMethod() + { + return this.Apply(x => x.SomeGenericMethod()); + } + + public global::System.Collections.Generic.IEnumerable SomeOtherGenericMethod() + { + return this.Apply(x => x.SomeOtherGenericMethod()); + } + + public global::ICustomEnumerable SomeCustomProperty + { + get + { + return this.Apply(x => x.SomeCustomProperty); + } + } + + public global::ICustomEnumerable SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::ICustomEnumerable SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + } +} +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeProperty).Return(global::System.Linq.Enumerable.Empty()); + this.When(x => x.SomeMethod()).Return(global::System.Linq.Enumerable.Empty()); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Linq.Enumerable.Empty()); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Collections.Generic.IEnumerable SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + + public global::System.Collections.Generic.IEnumerable SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::System.Collections.Generic.IEnumerable SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + } +} diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableDictionariesInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableDictionariesInput_CSharp.txt new file mode 100644 index 0000000..392a383 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableDictionariesInput_CSharp.txt @@ -0,0 +1,47 @@ +using System; +using System.Collections.Immutable; + +interface ICustomImmutableDictionary : IImmutableDictionary +{ +} + +interface ISomeInterface +{ + IImmutableDictionary SomeProperty + { + get; + } + + // expecting this to be ignored because it's set-only + IImmutableDictionary SomeSetOnlyProperty + { + set; + } + + IImmutableDictionary SomeMethod(); + IImmutableDictionary SomeMethod(int i, float f); + + // should all be ignored because they're generic + IImmutableDictionary SomeGenericMethod(); + IImmutableDictionary SomeOtherGenericMethod(); + + // should be ignored because they're a custom enumerable type + ICustomImmutableDictionary SomeCustomProperty + { + get; + } + + ICustomImmutableDictionary SomeMethod(); + ICustomImmutableDictionary SomeMethod(int i, float f); +} + +interface ISomeGenericInterface +{ + IImmutableDictionary SomeProperty + { + get; + } + + IImmutableDictionary SomeMethod(); + IImmutableDictionary SomeMethod(int i, float f); +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableDictionariesOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableDictionariesOutput_CSharp.txt new file mode 100644 index 0000000..b4aae18 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableDictionariesOutput_CSharp.txt @@ -0,0 +1,216 @@ +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase>, global::ICustomImmutableDictionary + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.Clear()).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); + this.When(x => x.Add(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); + this.When(x => x.AddRange(global::PCLMock.It.IsAny>>())).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); + this.When(x => x.SetItem(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); + this.When(x => x.SetItems(global::PCLMock.It.IsAny>>())).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); + this.When(x => x.RemoveRange(global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); + this.When(x => x.Remove(global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Collections.Immutable.IImmutableDictionary Clear() + { + return this.Apply(x => x.Clear()); + } + + public global::System.Collections.Immutable.IImmutableDictionary Add(TKey key, TValue value) + { + return this.Apply(x => x.Add(key, value)); + } + + public global::System.Collections.Immutable.IImmutableDictionary AddRange(global::System.Collections.Generic.IEnumerable> pairs) + { + return this.Apply(x => x.AddRange(pairs)); + } + + public global::System.Collections.Immutable.IImmutableDictionary SetItem(TKey key, TValue value) + { + return this.Apply(x => x.SetItem(key, value)); + } + + public global::System.Collections.Immutable.IImmutableDictionary SetItems(global::System.Collections.Generic.IEnumerable> items) + { + return this.Apply(x => x.SetItems(items)); + } + + public global::System.Collections.Immutable.IImmutableDictionary RemoveRange(global::System.Collections.Generic.IEnumerable keys) + { + return this.Apply(x => x.RemoveRange(keys)); + } + + public global::System.Collections.Immutable.IImmutableDictionary Remove(TKey key) + { + return this.Apply(x => x.Remove(key)); + } + + public System.Boolean Contains(global::System.Collections.Generic.KeyValuePair pair) + { + return this.Apply(x => x.Contains(pair)); + } + + public System.Boolean TryGetKey(TKey equalKey, out TKey actualKey) + { + TKey _actualKey; + actualKey = (this.GetOutParameterValue(x => x.TryGetKey(equalKey, out _actualKey), 1)); + return this.Apply(x => x.TryGetKey(equalKey, out _actualKey)); + } + } +} +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); + this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Collections.Immutable.IImmutableDictionary SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + + public global::System.Collections.Immutable.IImmutableDictionary SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::System.Collections.Immutable.IImmutableDictionary SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + + public global::System.Collections.Immutable.IImmutableDictionary SomeGenericMethod() + { + return this.Apply(x => x.SomeGenericMethod()); + } + + public global::System.Collections.Immutable.IImmutableDictionary SomeOtherGenericMethod() + { + return this.Apply(x => x.SomeOtherGenericMethod()); + } + + public global::ICustomImmutableDictionary SomeCustomProperty + { + get + { + return this.Apply(x => x.SomeCustomProperty); + } + } + + public global::ICustomImmutableDictionary SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::ICustomImmutableDictionary SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + } +} +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); + this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Collections.Immutable.IImmutableDictionary SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + + public global::System.Collections.Immutable.IImmutableDictionary SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::System.Collections.Immutable.IImmutableDictionary SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + } +} diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableListsInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableListsInput_CSharp.txt new file mode 100644 index 0000000..e5d2523 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableListsInput_CSharp.txt @@ -0,0 +1,47 @@ +using System; +using System.Collections.Immutable; + +interface ICustomImmutableList : IImmutableList +{ +} + +interface ISomeInterface +{ + IImmutableList SomeProperty + { + get; + } + + // expecting this to be ignored because it's set-only + IImmutableList SomeSetOnlyProperty + { + set; + } + + IImmutableList SomeMethod(); + IImmutableList SomeMethod(int i, float f); + + // should all be ignored because they're generic + IImmutableList SomeGenericMethod(); + IImmutableList SomeOtherGenericMethod(); + + // should be ignored because they're a custom enumerable type + ICustomIImmutableList SomeCustomProperty + { + get; + } + + ICustomIImmutableList SomeMethod(); + ICustomIImmutableList SomeMethod(int i, float f); +} + +interface ISomeGenericInterface +{ + IImmutableList SomeProperty + { + get; + } + + IImmutableList SomeMethod(); + IImmutableList SomeMethod(int i, float f); +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableListsOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableListsOutput_CSharp.txt new file mode 100644 index 0000000..39b17a1 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableListsOutput_CSharp.txt @@ -0,0 +1,244 @@ +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase>, global::ICustomImmutableList + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.Clear()).Return(global::System.Collections.Immutable.ImmutableList.Empty); + this.When(x => x.Add(global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); + this.When(x => x.AddRange(global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableList.Empty); + this.When(x => x.Insert(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); + this.When(x => x.InsertRange(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableList.Empty); + this.When(x => x.Remove(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableList.Empty); + this.When(x => x.RemoveAll(global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableList.Empty); + this.When(x => x.RemoveRange(global::PCLMock.It.IsAny>(), global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableList.Empty); + this.When(x => x.RemoveRange(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); + this.When(x => x.RemoveAt(global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); + this.When(x => x.SetItem(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); + this.When(x => x.Replace(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableList.Empty); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Collections.Immutable.IImmutableList Clear() + { + return this.Apply(x => x.Clear()); + } + + public System.Int32 IndexOf(T item, System.Int32 index, System.Int32 count, global::System.Collections.Generic.IEqualityComparer equalityComparer) + { + return this.Apply(x => x.IndexOf(item, index, count, equalityComparer)); + } + + public System.Int32 LastIndexOf(T item, System.Int32 index, System.Int32 count, global::System.Collections.Generic.IEqualityComparer equalityComparer) + { + return this.Apply(x => x.LastIndexOf(item, index, count, equalityComparer)); + } + + public global::System.Collections.Immutable.IImmutableList Add(T value) + { + return this.Apply(x => x.Add(value)); + } + + public global::System.Collections.Immutable.IImmutableList AddRange(global::System.Collections.Generic.IEnumerable items) + { + return this.Apply(x => x.AddRange(items)); + } + + public global::System.Collections.Immutable.IImmutableList Insert(System.Int32 index, T element) + { + return this.Apply(x => x.Insert(index, element)); + } + + public global::System.Collections.Immutable.IImmutableList InsertRange(System.Int32 index, global::System.Collections.Generic.IEnumerable items) + { + return this.Apply(x => x.InsertRange(index, items)); + } + + public global::System.Collections.Immutable.IImmutableList Remove(T value, global::System.Collections.Generic.IEqualityComparer equalityComparer) + { + return this.Apply(x => x.Remove(value, equalityComparer)); + } + + public global::System.Collections.Immutable.IImmutableList RemoveAll(global::System.Predicate match) + { + return this.Apply(x => x.RemoveAll(match)); + } + + public global::System.Collections.Immutable.IImmutableList RemoveRange(global::System.Collections.Generic.IEnumerable items, global::System.Collections.Generic.IEqualityComparer equalityComparer) + { + return this.Apply(x => x.RemoveRange(items, equalityComparer)); + } + + public global::System.Collections.Immutable.IImmutableList RemoveRange(System.Int32 index, System.Int32 count) + { + return this.Apply(x => x.RemoveRange(index, count)); + } + + public global::System.Collections.Immutable.IImmutableList RemoveAt(System.Int32 index) + { + return this.Apply(x => x.RemoveAt(index)); + } + + public global::System.Collections.Immutable.IImmutableList SetItem(System.Int32 index, T value) + { + return this.Apply(x => x.SetItem(index, value)); + } + + public global::System.Collections.Immutable.IImmutableList Replace(T oldValue, T newValue, global::System.Collections.Generic.IEqualityComparer equalityComparer) + { + return this.Apply(x => x.Replace(oldValue, newValue, equalityComparer)); + } + } +} +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableList.Empty); + this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableList.Empty); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Collections.Immutable.IImmutableList SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + + public global::System.Collections.Immutable.IImmutableList SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::System.Collections.Immutable.IImmutableList SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + + public global::System.Collections.Immutable.IImmutableList SomeGenericMethod() + { + return this.Apply(x => x.SomeGenericMethod()); + } + + public global::System.Collections.Immutable.IImmutableList SomeOtherGenericMethod() + { + return this.Apply(x => x.SomeOtherGenericMethod()); + } + + public ICustomIImmutableList SomeCustomProperty + { + get + { + return this.Apply(x => x.SomeCustomProperty); + } + } + + public ICustomIImmutableList SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public ICustomIImmutableList SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + } +} +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableList.Empty); + this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableList.Empty); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Collections.Immutable.IImmutableList SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + + public global::System.Collections.Immutable.IImmutableList SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::System.Collections.Immutable.IImmutableList SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + } +} diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableQueuesInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableQueuesInput_CSharp.txt new file mode 100644 index 0000000..3daf01d --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableQueuesInput_CSharp.txt @@ -0,0 +1,47 @@ +using System; +using System.Collections.Immutable; + +interface ICustomImmutableQueue : IImmutableQueue +{ +} + +interface ISomeInterface +{ + IImmutableQueue SomeProperty + { + get; + } + + // expecting this to be ignored because it's set-only + IImmutableQueue SomeSetOnlyProperty + { + set; + } + + IImmutableQueue SomeMethod(); + IImmutableQueue SomeMethod(int i, float f); + + // should all be ignored because they're generic + IImmutableQueue SomeGenericMethod(); + IImmutableQueue SomeOtherGenericMethod(); + + // should be ignored because they're a custom enumerable type + ICustomIImmutableQueue SomeCustomProperty + { + get; + } + + ICustomIImmutableQueue SomeMethod(); + ICustomIImmutableQueue SomeMethod(int i, float f); +} + +interface ISomeGenericInterface +{ + IImmutableQueue SomeProperty + { + get; + } + + IImmutableQueue SomeMethod(); + IImmutableQueue SomeMethod(int i, float f); +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableQueuesOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableQueuesOutput_CSharp.txt new file mode 100644 index 0000000..f91b3ae --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableQueuesOutput_CSharp.txt @@ -0,0 +1,193 @@ +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase>, global::ICustomImmutableQueue + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.Clear()).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); + this.When(x => x.Enqueue(global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); + this.When(x => x.Dequeue()).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Collections.Immutable.IImmutableQueue Clear() + { + return this.Apply(x => x.Clear()); + } + + public T Peek() + { + return this.Apply(x => x.Peek()); + } + + public global::System.Collections.Immutable.IImmutableQueue Enqueue(T value) + { + return this.Apply(x => x.Enqueue(value)); + } + + public global::System.Collections.Immutable.IImmutableQueue Dequeue() + { + return this.Apply(x => x.Dequeue()); + } + + public System.Boolean IsEmpty + { + get + { + return this.Apply(x => x.IsEmpty); + } + } + } +} +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); + this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Collections.Immutable.IImmutableQueue SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + + public global::System.Collections.Immutable.IImmutableQueue SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::System.Collections.Immutable.IImmutableQueue SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + + public global::System.Collections.Immutable.IImmutableQueue SomeGenericMethod() + { + return this.Apply(x => x.SomeGenericMethod()); + } + + public global::System.Collections.Immutable.IImmutableQueue SomeOtherGenericMethod() + { + return this.Apply(x => x.SomeOtherGenericMethod()); + } + + public ICustomIImmutableQueue SomeCustomProperty + { + get + { + return this.Apply(x => x.SomeCustomProperty); + } + } + + public ICustomIImmutableQueue SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public ICustomIImmutableQueue SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + } +} +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); + this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Collections.Immutable.IImmutableQueue SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + + public global::System.Collections.Immutable.IImmutableQueue SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::System.Collections.Immutable.IImmutableQueue SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + } +} diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableSetsInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableSetsInput_CSharp.txt new file mode 100644 index 0000000..13addfd --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableSetsInput_CSharp.txt @@ -0,0 +1,47 @@ +using System; +using System.Collections.Immutable; + +interface ICustomImmutableSet : IImmutableSet +{ +} + +interface ISomeInterface +{ + IImmutableSet SomeProperty + { + get; + } + + // expecting this to be ignored because it's set-only + IImmutableSet SomeSetOnlyProperty + { + set; + } + + IImmutableSet SomeMethod(); + IImmutableSet SomeMethod(int i, float f); + + // should all be ignored because they're generic + IImmutableSet SomeGenericMethod(); + IImmutableSet SomeOtherGenericMethod(); + + // should be ignored because they're a custom enumerable type + ICustomIImmutableSet SomeCustomProperty + { + get; + } + + ICustomIImmutableSet SomeMethod(); + ICustomIImmutableSet SomeMethod(int i, float f); +} + +interface ISomeGenericInterface +{ + IImmutableSet SomeProperty + { + get; + } + + IImmutableSet SomeMethod(); + IImmutableSet SomeMethod(int i, float f); +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableSetsOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableSetsOutput_CSharp.txt new file mode 100644 index 0000000..c0f0849 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableSetsOutput_CSharp.txt @@ -0,0 +1,246 @@ +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase>, global::ICustomImmutableSet + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.Clear()).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); + this.When(x => x.Add(global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); + this.When(x => x.Remove(global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); + this.When(x => x.Intersect(global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); + this.When(x => x.Except(global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); + this.When(x => x.SymmetricExcept(global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); + this.When(x => x.Union(global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Collections.Immutable.IImmutableSet Clear() + { + return this.Apply(x => x.Clear()); + } + + public System.Boolean Contains(T value) + { + return this.Apply(x => x.Contains(value)); + } + + public global::System.Collections.Immutable.IImmutableSet Add(T value) + { + return this.Apply(x => x.Add(value)); + } + + public global::System.Collections.Immutable.IImmutableSet Remove(T value) + { + return this.Apply(x => x.Remove(value)); + } + + public System.Boolean TryGetValue(T equalValue, out T actualValue) + { + T _actualValue; + actualValue = (this.GetOutParameterValue(x => x.TryGetValue(equalValue, out _actualValue), 1)); + return this.Apply(x => x.TryGetValue(equalValue, out _actualValue)); + } + + public global::System.Collections.Immutable.IImmutableSet Intersect(global::System.Collections.Generic.IEnumerable other) + { + return this.Apply(x => x.Intersect(other)); + } + + public global::System.Collections.Immutable.IImmutableSet Except(global::System.Collections.Generic.IEnumerable other) + { + return this.Apply(x => x.Except(other)); + } + + public global::System.Collections.Immutable.IImmutableSet SymmetricExcept(global::System.Collections.Generic.IEnumerable other) + { + return this.Apply(x => x.SymmetricExcept(other)); + } + + public global::System.Collections.Immutable.IImmutableSet Union(global::System.Collections.Generic.IEnumerable other) + { + return this.Apply(x => x.Union(other)); + } + + public System.Boolean SetEquals(global::System.Collections.Generic.IEnumerable other) + { + return this.Apply(x => x.SetEquals(other)); + } + + public System.Boolean IsProperSubsetOf(global::System.Collections.Generic.IEnumerable other) + { + return this.Apply(x => x.IsProperSubsetOf(other)); + } + + public System.Boolean IsProperSupersetOf(global::System.Collections.Generic.IEnumerable other) + { + return this.Apply(x => x.IsProperSupersetOf(other)); + } + + public System.Boolean IsSubsetOf(global::System.Collections.Generic.IEnumerable other) + { + return this.Apply(x => x.IsSubsetOf(other)); + } + + public System.Boolean IsSupersetOf(global::System.Collections.Generic.IEnumerable other) + { + return this.Apply(x => x.IsSupersetOf(other)); + } + + public System.Boolean Overlaps(global::System.Collections.Generic.IEnumerable other) + { + return this.Apply(x => x.Overlaps(other)); + } + } +} +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); + this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Collections.Immutable.IImmutableSet SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + + public global::System.Collections.Immutable.IImmutableSet SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::System.Collections.Immutable.IImmutableSet SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + + public global::System.Collections.Immutable.IImmutableSet SomeGenericMethod() + { + return this.Apply(x => x.SomeGenericMethod()); + } + + public global::System.Collections.Immutable.IImmutableSet SomeOtherGenericMethod() + { + return this.Apply(x => x.SomeOtherGenericMethod()); + } + + public ICustomIImmutableSet SomeCustomProperty + { + get + { + return this.Apply(x => x.SomeCustomProperty); + } + } + + public ICustomIImmutableSet SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public ICustomIImmutableSet SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + } +} +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); + this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Collections.Immutable.IImmutableSet SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + + public global::System.Collections.Immutable.IImmutableSet SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::System.Collections.Immutable.IImmutableSet SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + } +} diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableStacksInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableStacksInput_CSharp.txt new file mode 100644 index 0000000..801c729 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableStacksInput_CSharp.txt @@ -0,0 +1,47 @@ +using System; +using System.Collections.Immutable; + +interface ICustomImmutableStack : IImmutableStack +{ +} + +interface ISomeInterface +{ + IImmutableStack SomeProperty + { + get; + } + + // expecting this to be ignored because it's set-only + IImmutableStack SomeSetOnlyProperty + { + set; + } + + IImmutableStack SomeMethod(); + IImmutableStack SomeMethod(int i, float f); + + // should all be ignored because they're generic + IImmutableStack SomeGenericMethod(); + IImmutableStack SomeOtherGenericMethod(); + + // should be ignored because they're a custom enumerable type + ICustomIImmutableStack SomeCustomProperty + { + get; + } + + ICustomIImmutableStack SomeMethod(); + ICustomIImmutableStack SomeMethod(int i, float f); +} + +interface ISomeGenericInterface +{ + IImmutableStack SomeProperty + { + get; + } + + IImmutableStack SomeMethod(); + IImmutableStack SomeMethod(int i, float f); +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableStacksOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableStacksOutput_CSharp.txt new file mode 100644 index 0000000..592ddf8 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableStacksOutput_CSharp.txt @@ -0,0 +1,193 @@ +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase>, global::ICustomImmutableStack + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.Clear()).Return(global::System.Collections.Immutable.ImmutableStack.Empty); + this.When(x => x.Push(global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableStack.Empty); + this.When(x => x.Pop()).Return(global::System.Collections.Immutable.ImmutableStack.Empty); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Collections.Immutable.IImmutableStack Clear() + { + return this.Apply(x => x.Clear()); + } + + public global::System.Collections.Immutable.IImmutableStack Push(T value) + { + return this.Apply(x => x.Push(value)); + } + + public global::System.Collections.Immutable.IImmutableStack Pop() + { + return this.Apply(x => x.Pop()); + } + + public T Peek() + { + return this.Apply(x => x.Peek()); + } + + public System.Boolean IsEmpty + { + get + { + return this.Apply(x => x.IsEmpty); + } + } + } +} +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableStack.Empty); + this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableStack.Empty); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableStack.Empty); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Collections.Immutable.IImmutableStack SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + + public global::System.Collections.Immutable.IImmutableStack SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::System.Collections.Immutable.IImmutableStack SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + + public global::System.Collections.Immutable.IImmutableStack SomeGenericMethod() + { + return this.Apply(x => x.SomeGenericMethod()); + } + + public global::System.Collections.Immutable.IImmutableStack SomeOtherGenericMethod() + { + return this.Apply(x => x.SomeOtherGenericMethod()); + } + + public ICustomIImmutableStack SomeCustomProperty + { + get + { + return this.Apply(x => x.SomeCustomProperty); + } + } + + public ICustomIImmutableStack SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public ICustomIImmutableStack SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + } +} +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableStack.Empty); + this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableStack.Empty); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableStack.Empty); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Collections.Immutable.IImmutableStack SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + + public global::System.Collections.Immutable.IImmutableStack SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::System.Collections.Immutable.IImmutableStack SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + } +} diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ListsInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ListsInput_CSharp.txt new file mode 100644 index 0000000..807aad0 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ListsInput_CSharp.txt @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; + +interface ICustomList : IList +{ +} + +interface ISomeInterface +{ + IList SomeProperty + { + get; + } + + // expecting this to be ignored because it's set-only + IList SomeSetOnlyProperty + { + set; + } + + IReadOnlyList SomeReadOnlyProperty + { + get; + } + + IList SomeMethod(); + IList SomeMethod(int i, float f); + + // should all be ignored because they're generic + IList SomeGenericMethod(); + IList SomeOtherGenericMethod(); + + // should be ignored because they're a custom enumerable type + ICustomList SomeCustomProperty + { + get; + } + + ICustomList SomeMethod(); + ICustomList SomeMethod(int i, float f); +} + +interface ISomeGenericInterface +{ + IList SomeProperty + { + get; + } + + IList SomeMethod(); + IList SomeMethod(int i, float f); +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ListsOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ListsOutput_CSharp.txt new file mode 100644 index 0000000..de6f78d --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ListsOutput_CSharp.txt @@ -0,0 +1,240 @@ +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase>, global::ICustomList + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public System.Int32 IndexOf(T item) + { + return this.Apply(x => x.IndexOf(item)); + } + + public void Insert(System.Int32 index, T item) + { + this.Apply(x => x.Insert(index, item)); + } + + public void RemoveAt(System.Int32 index) + { + this.Apply(x => x.RemoveAt(index)); + } + + public T this[System.Int32 index] + { + get + { + return this.Apply(x => x[index]); + } + + set + { + this.ApplyPropertySet(x => x[index], value); + } + } + + public void Add(T item) + { + this.Apply(x => x.Add(item)); + } + + public void Clear() + { + this.Apply(x => x.Clear()); + } + + public System.Boolean Contains(T item) + { + return this.Apply(x => x.Contains(item)); + } + + public void CopyTo(T[] array, System.Int32 arrayIndex) + { + this.Apply(x => x.CopyTo(array, arrayIndex)); + } + + public System.Boolean Remove(T item) + { + return this.Apply(x => x.Remove(item)); + } + + public System.Int32 Count + { + get + { + return this.Apply(x => x.Count); + } + } + + public System.Boolean IsReadOnly + { + get + { + return this.Apply(x => x.IsReadOnly); + } + } + } +} +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.List()); + this.When(x => x.SomeReadOnlyProperty).Return(new global::System.Collections.Generic.List()); + this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.List()); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.List()); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Collections.Generic.IList SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + + public global::System.Collections.Generic.IReadOnlyList SomeReadOnlyProperty + { + get + { + return this.Apply(x => x.SomeReadOnlyProperty); + } + } + + public global::System.Collections.Generic.IList SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::System.Collections.Generic.IList SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + + public global::System.Collections.Generic.IList SomeGenericMethod() + { + return this.Apply(x => x.SomeGenericMethod()); + } + + public global::System.Collections.Generic.IList SomeOtherGenericMethod() + { + return this.Apply(x => x.SomeOtherGenericMethod()); + } + + public global::ICustomList SomeCustomProperty + { + get + { + return this.Apply(x => x.SomeCustomProperty); + } + } + + public global::ICustomList SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::ICustomList SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + } +} +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.List()); + this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.List()); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.List()); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Collections.Generic.IList SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + + public global::System.Collections.Generic.IList SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::System.Collections.Generic.IList SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + } +} diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/RecursiveInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/RecursiveInput_CSharp.txt new file mode 100644 index 0000000..a218371 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/RecursiveInput_CSharp.txt @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; + +interface ISomeInterface +{ + IList>> SomeProperty + { + get; + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/RecursiveOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/RecursiveOutput_CSharp.txt new file mode 100644 index 0000000..398cc38 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/RecursiveOutput_CSharp.txt @@ -0,0 +1,45 @@ +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.List>>()); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Collections.Generic.IList>> SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + } +} diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/SetsInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/SetsInput_CSharp.txt new file mode 100644 index 0000000..b353e30 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/SetsInput_CSharp.txt @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; + +interface ICustomSet : ISet +{ +} + +interface ISomeInterface +{ + ISet SomeProperty + { + get; + } + + // expecting this to be ignored because it's set-only + ISet SomeSetOnlyProperty + { + set; + } + + ISet SomeMethod(); + ISet SomeMethod(int i, float f); + + // should all be ignored because they're generic + ISet SomeGenericMethod(); + ISet SomeOtherGenericMethod(); + + // should be ignored because they're a custom enumerable type + ICustomSet SomeCustomProperty + { + get; + } + + ICustomSet SomeMethod(); + ICustomSet SomeMethod(int i, float f); +} + +interface ISomeGenericInterface +{ + ISet SomeProperty + { + get; + } + + ISet SomeMethod(); + ISet SomeMethod(int i, float f); +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/SetsOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/SetsOutput_CSharp.txt new file mode 100644 index 0000000..d91626d --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/SetsOutput_CSharp.txt @@ -0,0 +1,258 @@ +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase>, global::ICustomSet + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public System.Boolean Add(T item) + { + return this.Apply(x => x.Add(item)); + } + + public void UnionWith(global::System.Collections.Generic.IEnumerable other) + { + this.Apply(x => x.UnionWith(other)); + } + + public void IntersectWith(global::System.Collections.Generic.IEnumerable other) + { + this.Apply(x => x.IntersectWith(other)); + } + + public void ExceptWith(global::System.Collections.Generic.IEnumerable other) + { + this.Apply(x => x.ExceptWith(other)); + } + + public void SymmetricExceptWith(global::System.Collections.Generic.IEnumerable other) + { + this.Apply(x => x.SymmetricExceptWith(other)); + } + + public System.Boolean IsSubsetOf(global::System.Collections.Generic.IEnumerable other) + { + return this.Apply(x => x.IsSubsetOf(other)); + } + + public System.Boolean IsSupersetOf(global::System.Collections.Generic.IEnumerable other) + { + return this.Apply(x => x.IsSupersetOf(other)); + } + + public System.Boolean IsProperSupersetOf(global::System.Collections.Generic.IEnumerable other) + { + return this.Apply(x => x.IsProperSupersetOf(other)); + } + + public System.Boolean IsProperSubsetOf(global::System.Collections.Generic.IEnumerable other) + { + return this.Apply(x => x.IsProperSubsetOf(other)); + } + + public System.Boolean Overlaps(global::System.Collections.Generic.IEnumerable other) + { + return this.Apply(x => x.Overlaps(other)); + } + + public System.Boolean SetEquals(global::System.Collections.Generic.IEnumerable other) + { + return this.Apply(x => x.SetEquals(other)); + } + + public void Add(T item) + { + this.Apply(x => x.Add(item)); + } + + public void Clear() + { + this.Apply(x => x.Clear()); + } + + public System.Boolean Contains(T item) + { + return this.Apply(x => x.Contains(item)); + } + + public void CopyTo(T[] array, System.Int32 arrayIndex) + { + this.Apply(x => x.CopyTo(array, arrayIndex)); + } + + public System.Boolean Remove(T item) + { + return this.Apply(x => x.Remove(item)); + } + + public System.Int32 Count + { + get + { + return this.Apply(x => x.Count); + } + } + + public System.Boolean IsReadOnly + { + get + { + return this.Apply(x => x.IsReadOnly); + } + } + } +} +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.HashSet()); + this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.HashSet()); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.HashSet()); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Collections.Generic.ISet SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + + public global::System.Collections.Generic.ISet SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::System.Collections.Generic.ISet SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + + public global::System.Collections.Generic.ISet SomeGenericMethod() + { + return this.Apply(x => x.SomeGenericMethod()); + } + + public global::System.Collections.Generic.ISet SomeOtherGenericMethod() + { + return this.Apply(x => x.SomeOtherGenericMethod()); + } + + public global::ICustomSet SomeCustomProperty + { + get + { + return this.Apply(x => x.SomeCustomProperty); + } + } + + public global::ICustomSet SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::ICustomSet SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + } +} +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.HashSet()); + this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.HashSet()); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.HashSet()); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Collections.Generic.ISet SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + + public global::System.Collections.Generic.ISet SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::System.Collections.Generic.ISet SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + } +} diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/DisposablesFixture.cs b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/DisposablesFixture.cs new file mode 100644 index 0000000..54372b1 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/DisposablesFixture.cs @@ -0,0 +1,79 @@ +namespace PCLMock.UnitTests.CodeGeneration.Plugins +{ + using System; + using System.Collections.Immutable; + using System.IO; + using System.Linq; + using System.Reactive.Linq; + using System.Threading.Tasks; + using Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.Text; + using PCLMock.CodeGeneration; + using PCLMock.CodeGeneration.Logging; + using PCLMock.CodeGeneration.Plugins; + using Xunit; + + public sealed class DisposablesFixture + { + [Theory] + [InlineData("Disposables", Language.CSharp)] + public async Task can_generate_mocks(string resourceBaseName, Language language) + { + var inputResourceName = "PCLMock.UnitTests.CodeGeneration.Plugins.DisposablesFixtureResources." + resourceBaseName + "Input_" + language.ToString() + ".txt"; + var outputResourceName = "PCLMock.UnitTests.CodeGeneration.Plugins.DisposablesFixtureResources." + resourceBaseName + "Output_" + language.ToString() + ".txt"; + + using (var inputStream = this.GetType().Assembly.GetManifestResourceStream(inputResourceName)) + using (var outputStream = this.GetType().Assembly.GetManifestResourceStream(outputResourceName)) + using (var outputStreamReader = new StreamReader(outputStream)) + { + var workspace = new AdhocWorkspace(); + var projectId = ProjectId.CreateNewId(); + var versionStamp = VersionStamp.Create(); + var projectInfo = ProjectInfo.Create( + projectId, + versionStamp, + "AdhocProject", + "AdhocProject", + language.ToSyntaxGeneratorLanguageName(), + metadataReferences: new[] + { + MetadataReference.CreateFromFile(typeof(object).Assembly.Location), + MetadataReference.CreateFromFile(typeof(Uri).Assembly.Location), + MetadataReference.CreateFromFile(typeof(MockBase<>).Assembly.Location) + }); + var project = workspace.AddProject(projectInfo); + workspace.AddDocument(projectId, "Source.cs", SourceText.From(inputStream)); + var solution = workspace.CurrentSolution; + + var results = + (await Generator.GenerateMocksAsync( + NullLogSink.Instance, + language, + solution, + x => true, + x => "The.Namespace", + x => "Mock", + new IPlugin[] + { + new Disposables() + }.ToImmutableList())); + var result = results + .Last() + .ToString() + .NormalizeLineEndings(); + + var expectedCode = outputStreamReader.ReadToEnd(); + + // make sure version changes don't break the tests + expectedCode = expectedCode + .Replace("$VERSION$", typeof(MockBase<>).Assembly.GetName().Version.ToString()) + .NormalizeLineEndings(); + + // useful when converting generated code to something that can be pasted into an expectation file + var sanitisedResult = result.Replace(typeof(MockBase<>).Assembly.GetName().Version.ToString(), "$VERSION$"); + + Assert.Equal(expectedCode, result); + } + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/DisposablesFixtureResources/DisposablesInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/DisposablesFixtureResources/DisposablesInput_CSharp.txt new file mode 100644 index 0000000..de656b4 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/DisposablesFixtureResources/DisposablesInput_CSharp.txt @@ -0,0 +1,35 @@ +using System; + +interface ICustomDisposable : IDisposable +{ +} + +interface ISomeInterface +{ + IDisposable SomeProperty + { + get; + } + + // expecting this to be ignored because it's set-only + IDisposable SomeSetOnlyProperty + { + set; + } + + IDisposable SomeMethod(); + IDisposable SomeMethod(int i, float f); + + // should all be ignored because they're generic + IDisposable SomeGenericMethod(); + IDisposable SomeOtherGenericMethod(); + + // should be ignored because they're a custom disposable type + ICustomDisposable SomeCustomProperty + { + get; + } + + ICustomDisposable SomeMethod(); + ICustomDisposable SomeMethod(int i, float f); +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/DisposablesFixtureResources/DisposablesOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/DisposablesFixtureResources/DisposablesOutput_CSharp.txt new file mode 100644 index 0000000..d40c0c3 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/DisposablesFixtureResources/DisposablesOutput_CSharp.txt @@ -0,0 +1,77 @@ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeProperty).Return(global::System.Reactive.Disposables.Disposable.Empty); + this.When(x => x.SomeMethod()).Return(global::System.Reactive.Disposables.Disposable.Empty); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Reactive.Disposables.Disposable.Empty); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.IDisposable SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + + public global::System.IDisposable SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::System.IDisposable SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + + public global::System.IDisposable SomeGenericMethod() + { + return this.Apply(x => x.SomeGenericMethod()); + } + + public global::System.IDisposable SomeOtherGenericMethod() + { + return this.Apply(x => x.SomeOtherGenericMethod()); + } + + public global::ICustomDisposable SomeCustomProperty + { + get + { + return this.Apply(x => x.SomeCustomProperty); + } + } + + public global::ICustomDisposable SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::ICustomDisposable SomeMethod(System.Int32 i, System.Single f) + { + return this.Apply(x => x.SomeMethod(i, f)); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixture.cs b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixture.cs new file mode 100644 index 0000000..55b2248 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixture.cs @@ -0,0 +1,82 @@ +namespace PCLMock.UnitTests.CodeGeneration.Plugins +{ + using System; + using System.Collections.Immutable; + using System.IO; + using System.Linq; + using System.Reactive.Linq; + using System.Threading.Tasks; + using Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.Text; + using PCLMock.CodeGeneration; + using PCLMock.CodeGeneration.Logging; + using PCLMock.CodeGeneration.Plugins; + using Xunit; + + public sealed class ObservableBasedAsynchronyFixture + { + [Theory] + [InlineData("NonObservableBased", Language.CSharp)] + [InlineData("ObservableBased", Language.CSharp)] + [InlineData("GenericInterface", Language.CSharp)] + [InlineData("Recursive", Language.CSharp)] + public async Task can_generate_mocks(string resourceBaseName, Language language) + { + var inputResourceName = "PCLMock.UnitTests.CodeGeneration.Plugins.ObservableBasedAsynchronyFixtureResources." + resourceBaseName + "Input_" + language.ToString() + ".txt"; + var outputResourceName = "PCLMock.UnitTests.CodeGeneration.Plugins.ObservableBasedAsynchronyFixtureResources." + resourceBaseName + "Output_" + language.ToString() + ".txt"; + + using (var inputStream = this.GetType().Assembly.GetManifestResourceStream(inputResourceName)) + using (var outputStream = this.GetType().Assembly.GetManifestResourceStream(outputResourceName)) + using (var outputStreamReader = new StreamReader(outputStream)) + { + var workspace = new AdhocWorkspace(); + var projectId = ProjectId.CreateNewId(); + var versionStamp = VersionStamp.Create(); + var projectInfo = ProjectInfo.Create( + projectId, + versionStamp, + "AdhocProject", + "AdhocProject", + language.ToSyntaxGeneratorLanguageName(), + metadataReferences: new[] + { + MetadataReference.CreateFromFile(typeof(object).Assembly.Location), + MetadataReference.CreateFromFile(typeof(Uri).Assembly.Location), + MetadataReference.CreateFromFile(typeof(MockBase<>).Assembly.Location) + }); + var project = workspace.AddProject(projectInfo); + workspace.AddDocument(projectId, "Source.cs", SourceText.From(inputStream)); + var solution = workspace.CurrentSolution; + + var results = + (await Generator.GenerateMocksAsync( + NullLogSink.Instance, + language, + solution, + x => true, + x => "The.Namespace", + x => "Mock", + new IPlugin[] + { + new ObservableBasedAsynchrony() + }.ToImmutableList())); + var result = results + .Last() + .ToString() + .NormalizeLineEndings(); + + var expectedCode = outputStreamReader.ReadToEnd(); + + // make sure version changes don't break the tests + expectedCode = expectedCode + .Replace("$VERSION$", typeof(MockBase<>).Assembly.GetName().Version.ToString()) + .NormalizeLineEndings(); + + // useful when converting generated code to something that can be pasted into an expectation file + var sanitisedResult = result.Replace(typeof(MockBase<>).Assembly.GetName().Version.ToString(), "$VERSION$"); + + Assert.Equal(expectedCode, result); + } + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/GenericInterfaceInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/GenericInterfaceInput_CSharp.txt new file mode 100644 index 0000000..6d4cd6f --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/GenericInterfaceInput_CSharp.txt @@ -0,0 +1,11 @@ +using System; + +interface ISomeInterface +{ + IObservable SomeProperty + { + get; + } + + IObservable SomeMethod(); +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt new file mode 100644 index 0000000..e5a5797 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt @@ -0,0 +1,43 @@ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase>, global::ISomeInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeProperty).Return(global::System.Reactive.Linq.Observable.Empty()); + this.When(x => x.SomeMethod()).Return(global::System.Reactive.Linq.Observable.Return(default (T))); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.IObservable SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + + public global::System.IObservable SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/NonObservableBasedInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/NonObservableBasedInput_CSharp.txt new file mode 100644 index 0000000..203ec18 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/NonObservableBasedInput_CSharp.txt @@ -0,0 +1,34 @@ +interface ISomeInterface +{ + int SomeProperty + { + get; + } + + string SomeOtherProperty + { + get; + } + + int SomeSetOnlyProperty + { + set; + } + + int this[int i, float f] + { + get; + } + + void SomeMethod(); + + string SomeMethod(); + + int SomeMethod(); + + object SomeMethod(); + + int SomeMethod(); + + int SomeMethod(); +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/NonObservableBasedOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/NonObservableBasedOutput_CSharp.txt new file mode 100644 index 0000000..4e15c3d --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/NonObservableBasedOutput_CSharp.txt @@ -0,0 +1,82 @@ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public System.Int32 SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + + public System.String SomeOtherProperty + { + get + { + return this.Apply(x => x.SomeOtherProperty); + } + } + + public System.Int32 this[System.Int32 i, System.Single f] + { + get + { + return this.Apply(x => x[i, f]); + } + } + + public void SomeMethod() + { + this.Apply(x => x.SomeMethod()); + } + + public System.String SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public System.Int32 SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public System.Object SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public System.Int32 SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public System.Int32 SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedInput_CSharp.txt new file mode 100644 index 0000000..2fbaf48 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedInput_CSharp.txt @@ -0,0 +1,40 @@ +using System; + +interface ICustomObservable : IObservable +{ +} + +interface ISomeInterface +{ + IObservable SomeProperty + { + get; + } + + IObservable SomeOtherProperty + { + get; + } + + // expecting this to be ignored because it's set-only + IObservable SomeSetOnlyProperty + { + set; + } + + IObservable this[int i, float f] + { + get; + } + + IObservable SomeMethod(); + IObservable SomeMethod(string s, int i); + + // expecting these to be ignored because of the type parameters + IObservable SomeMethod(); + IObservable SomeMethod(); + + // expecting these two to be ignored because of it being a custom observable (which we have no way of providing a default value for) + ICustomObservable SomeMethod(); + ICustomObservable SomeMethod(string s, int i); +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedOutput_CSharp.txt new file mode 100644 index 0000000..556d664 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedOutput_CSharp.txt @@ -0,0 +1,87 @@ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeProperty).Return(global::System.Reactive.Linq.Observable.Empty()); + this.When(x => x.SomeOtherProperty).Return(global::System.Reactive.Linq.Observable.Empty()); + this.When(x => x[global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny()]).Return(global::System.Reactive.Linq.Observable.Empty()); + this.When(x => x.SomeMethod()).Return(global::System.Reactive.Linq.Observable.Return(0)); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Reactive.Linq.Observable.Return(null)); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.IObservable SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + + public global::System.IObservable SomeOtherProperty + { + get + { + return this.Apply(x => x.SomeOtherProperty); + } + } + + public global::System.IObservable this[System.Int32 i, System.Single f] + { + get + { + return this.Apply(x => x[i, f]); + } + } + + public global::System.IObservable SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::System.IObservable SomeMethod(System.String s, System.Int32 i) + { + return this.Apply(x => x.SomeMethod(s, i)); + } + + public global::System.IObservable SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::System.IObservable SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::ICustomObservable SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::ICustomObservable SomeMethod(System.String s, System.Int32 i) + { + return this.Apply(x => x.SomeMethod(s, i)); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/RecursiveInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/RecursiveInput_CSharp.txt new file mode 100644 index 0000000..95eb6e9 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/RecursiveInput_CSharp.txt @@ -0,0 +1,6 @@ +using System; + +interface ISomeInterface +{ + IObservable> SomeMethod(); +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt new file mode 100644 index 0000000..18c534e --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt @@ -0,0 +1,34 @@ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeMethod()).Return(global::System.Reactive.Linq.Observable.Return>(global::System.Reactive.Linq.Observable.Return(0))); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.IObservable> SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixture.cs b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixture.cs new file mode 100644 index 0000000..b4d6d75 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixture.cs @@ -0,0 +1,82 @@ +namespace PCLMock.UnitTests.CodeGeneration.Plugins +{ + using System; + using System.Collections.Immutable; + using System.IO; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.Text; + using PCLMock.CodeGeneration; + using PCLMock.CodeGeneration.Logging; + using PCLMock.CodeGeneration.Plugins; + using Xunit; + + public sealed class TaskBasedAsynchronyFixture + { + [Theory] + [InlineData("NonTaskBased", Language.CSharp)] + [InlineData("NonGenericTask", Language.CSharp)] + [InlineData("GenericTask", Language.CSharp)] + [InlineData("GenericInterface", Language.CSharp)] + [InlineData("Recursive", Language.CSharp)] + public async Task can_generate_mocks(string resourceBaseName, Language language) + { + var inputResourceName = "PCLMock.UnitTests.CodeGeneration.Plugins.TaskBasedAsynchronyFixtureResources." + resourceBaseName + "Input_" + language.ToString() + ".txt"; + var outputResourceName = "PCLMock.UnitTests.CodeGeneration.Plugins.TaskBasedAsynchronyFixtureResources." + resourceBaseName + "Output_" + language.ToString() + ".txt"; + + using (var inputStream = this.GetType().Assembly.GetManifestResourceStream(inputResourceName)) + using (var outputStream = this.GetType().Assembly.GetManifestResourceStream(outputResourceName)) + using (var outputStreamReader = new StreamReader(outputStream)) + { + var workspace = new AdhocWorkspace(); + var projectId = ProjectId.CreateNewId(); + var versionStamp = VersionStamp.Create(); + var projectInfo = ProjectInfo.Create( + projectId, + versionStamp, + "AdhocProject", + "AdhocProject", + language.ToSyntaxGeneratorLanguageName(), + metadataReferences: new[] + { + MetadataReference.CreateFromFile(typeof(object).Assembly.Location), + MetadataReference.CreateFromFile(typeof(Uri).Assembly.Location), + MetadataReference.CreateFromFile(typeof(MockBase<>).Assembly.Location) + }); + var project = workspace.AddProject(projectInfo); + workspace.AddDocument(projectId, "Source.cs", SourceText.From(inputStream)); + var solution = workspace.CurrentSolution; + + var results = + (await Generator.GenerateMocksAsync( + NullLogSink.Instance, + language, + solution, + x => true, + x => "The.Namespace", + x => "Mock", + new IPlugin[] + { + new TaskBasedAsynchrony() + }.ToImmutableList())); + var result = results + .Last() + .ToString() + .NormalizeLineEndings(); + + var expectedCode = outputStreamReader.ReadToEnd(); + + // make sure version changes don't break the tests + expectedCode = expectedCode + .Replace("$VERSION$", typeof(MockBase<>).Assembly.GetName().Version.ToString()) + .NormalizeLineEndings(); + + // useful when converting generated code to something that can be pasted into an expectation file + var sanitisedResult = result.Replace(typeof(MockBase<>).Assembly.GetName().Version.ToString(), "$VERSION$"); + + Assert.Equal(expectedCode, result); + } + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericInterfaceInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericInterfaceInput_CSharp.txt new file mode 100644 index 0000000..451cda7 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericInterfaceInput_CSharp.txt @@ -0,0 +1,11 @@ +using System.Threading.Tasks; + +interface ISomeInterface +{ + Task SomeProperty + { + get; + } + + Task SomeMethod(); +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt new file mode 100644 index 0000000..f3f8e7b --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt @@ -0,0 +1,43 @@ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase>, global::ISomeInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeProperty).Return(global::System.Threading.Tasks.Task.FromResult(default (T))); + this.When(x => x.SomeMethod()).Return(global::System.Threading.Tasks.Task.FromResult(default (T))); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Threading.Tasks.Task SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + + public global::System.Threading.Tasks.Task SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericTaskInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericTaskInput_CSharp.txt new file mode 100644 index 0000000..0d9e21b --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericTaskInput_CSharp.txt @@ -0,0 +1,40 @@ +using System.Threading.Tasks; + +class CustomTask : Task +{ +} + +interface ISomeInterface +{ + Task SomeProperty + { + get; + } + + Task SomeOtherProperty + { + get; + } + + // expecting this to be ignored because it's set-only + Task SomeSetOnlyProperty + { + set; + } + + Task this[int i, float f] + { + get; + } + + Task SomeMethod(); + Task SomeMethod(string s, int i); + + // expecting these to be ignored because of the type parameters + Task SomeMethod(); + Task SomeMethod(); + + // expecting these two to be ignored because of it being a custom task (which we have no way of providing a default value for) + CustomTask SomeMethod(); + CustomTask SomeMethod(string s, int i); +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericTaskOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericTaskOutput_CSharp.txt new file mode 100644 index 0000000..112eee5 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericTaskOutput_CSharp.txt @@ -0,0 +1,87 @@ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeProperty).Return(global::System.Threading.Tasks.Task.FromResult(0)); + this.When(x => x.SomeOtherProperty).Return(global::System.Threading.Tasks.Task.FromResult(null)); + this.When(x => x[global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny()]).Return(global::System.Threading.Tasks.Task.FromResult(0)); + this.When(x => x.SomeMethod()).Return(global::System.Threading.Tasks.Task.FromResult(0)); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Threading.Tasks.Task.FromResult(null)); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Threading.Tasks.Task SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + + public global::System.Threading.Tasks.Task SomeOtherProperty + { + get + { + return this.Apply(x => x.SomeOtherProperty); + } + } + + public global::System.Threading.Tasks.Task this[System.Int32 i, System.Single f] + { + get + { + return this.Apply(x => x[i, f]); + } + } + + public global::System.Threading.Tasks.Task SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::System.Threading.Tasks.Task SomeMethod(System.String s, System.Int32 i) + { + return this.Apply(x => x.SomeMethod(s, i)); + } + + public global::System.Threading.Tasks.Task SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::System.Threading.Tasks.Task SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::CustomTask SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::CustomTask SomeMethod(System.String s, System.Int32 i) + { + return this.Apply(x => x.SomeMethod(s, i)); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonGenericTaskInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonGenericTaskInput_CSharp.txt new file mode 100644 index 0000000..28bc9f9 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonGenericTaskInput_CSharp.txt @@ -0,0 +1,40 @@ +using System.Threading.Tasks; + +class CustomTask : Task +{ +} + +interface ISomeInterface +{ + Task SomeProperty + { + get; + } + + Task SomeOtherProperty + { + get; + } + + // expecting this to be ignored because it's set-only + Task SomeSetOnlyProperty + { + set; + } + + Task this[int i, float f] + { + get; + } + + Task SomeMethod(); + Task SomeMethod(string s, int i); + + // expecting these to be ignored because of the type parameters + Task SomeMethod(); + Task SomeMethod(); + + // expecting these to be ignored because of it being a custom task (which we have no way of providing a default value for) + CustomTask SomeMethod(); + CustomTask SomeMethod(string s, int i); +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonGenericTaskOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonGenericTaskOutput_CSharp.txt new file mode 100644 index 0000000..3406772 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonGenericTaskOutput_CSharp.txt @@ -0,0 +1,87 @@ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeProperty).Return(global::System.Threading.Tasks.Task.FromResult(false)); + this.When(x => x.SomeOtherProperty).Return(global::System.Threading.Tasks.Task.FromResult(false)); + this.When(x => x[global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny()]).Return(global::System.Threading.Tasks.Task.FromResult(false)); + this.When(x => x.SomeMethod()).Return(global::System.Threading.Tasks.Task.FromResult(false)); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Threading.Tasks.Task.FromResult(false)); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Threading.Tasks.Task SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + + public global::System.Threading.Tasks.Task SomeOtherProperty + { + get + { + return this.Apply(x => x.SomeOtherProperty); + } + } + + public global::System.Threading.Tasks.Task this[System.Int32 i, System.Single f] + { + get + { + return this.Apply(x => x[i, f]); + } + } + + public global::System.Threading.Tasks.Task SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::System.Threading.Tasks.Task SomeMethod(System.String s, System.Int32 i) + { + return this.Apply(x => x.SomeMethod(s, i)); + } + + public global::System.Threading.Tasks.Task SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::System.Threading.Tasks.Task SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::CustomTask SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public global::CustomTask SomeMethod(System.String s, System.Int32 i) + { + return this.Apply(x => x.SomeMethod(s, i)); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonTaskBasedInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonTaskBasedInput_CSharp.txt new file mode 100644 index 0000000..203ec18 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonTaskBasedInput_CSharp.txt @@ -0,0 +1,34 @@ +interface ISomeInterface +{ + int SomeProperty + { + get; + } + + string SomeOtherProperty + { + get; + } + + int SomeSetOnlyProperty + { + set; + } + + int this[int i, float f] + { + get; + } + + void SomeMethod(); + + string SomeMethod(); + + int SomeMethod(); + + object SomeMethod(); + + int SomeMethod(); + + int SomeMethod(); +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonTaskBasedOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonTaskBasedOutput_CSharp.txt new file mode 100644 index 0000000..4e15c3d --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonTaskBasedOutput_CSharp.txt @@ -0,0 +1,82 @@ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public System.Int32 SomeProperty + { + get + { + return this.Apply(x => x.SomeProperty); + } + } + + public System.String SomeOtherProperty + { + get + { + return this.Apply(x => x.SomeOtherProperty); + } + } + + public System.Int32 this[System.Int32 i, System.Single f] + { + get + { + return this.Apply(x => x[i, f]); + } + } + + public void SomeMethod() + { + this.Apply(x => x.SomeMethod()); + } + + public System.String SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public System.Int32 SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public System.Object SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public System.Int32 SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + + public System.Int32 SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/RecursiveInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/RecursiveInput_CSharp.txt new file mode 100644 index 0000000..2b3c522 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/RecursiveInput_CSharp.txt @@ -0,0 +1,6 @@ +using System.Threading.Tasks; + +interface ISomeInterface +{ + Task> SomeMethod(); +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt new file mode 100644 index 0000000..3ecfeca --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt @@ -0,0 +1,34 @@ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + { + public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehaviorGenerated(); + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeMethod()).Return(global::System.Threading.Tasks.Task.FromResult>(global::System.Threading.Tasks.Task.FromResult(0))); + } + + private void ConfigureLooseBehaviorGenerated() + { + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.Threading.Tasks.Task> SomeMethod() + { + return this.Apply(x => x.SomeMethod()); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/Extensions.cs b/Src/PCLMock.UnitTests_OLD/Extensions.cs new file mode 100644 index 0000000..8a64a74 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/Extensions.cs @@ -0,0 +1,11 @@ +namespace PCLMock.UnitTests +{ + public static class Extensions + { + public static string NormalizeLineEndings(this string @this) => + @this + .Replace("\r\n", "\n") + .Replace("\r", "\n") + .Replace("\n", "\r\n"); + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/MockBaseFixture.cs b/Src/PCLMock.UnitTests_OLD/MockBaseFixture.cs new file mode 100644 index 0000000..9fffab7 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/MockBaseFixture.cs @@ -0,0 +1,1328 @@ +namespace PCLMock.UnitTests +{ + using System; + using System.Text.RegularExpressions; + using PCLMock; + using Xunit; + using Xunit.Extensions; + + public sealed class MockBaseFixture + { + [Fact] + public void indexer_properties_can_be_mocked() + { + var mock = new TestTargetMock(); + mock.When(x => x[1]).Return(3); + + Assert.Equal(3, mock[1]); + } + + [Fact] + public void indexer_properties_with_multiple_indexes_can_be_mocked() + { + var mock = new TestTargetMock(); + mock.When(x => x[1, 3]).Return(3); + mock.When(x => x[3, 1]).Return(5); + + Assert.Equal(3, mock[1, 3]); + Assert.Equal(5, mock[3, 1]); + } + + [Fact] + public void apply_throws_if_method_without_specifications_is_invoked_on_a_strict_mock() + { + var mock = new TestTargetMock(); + var ex = Assert.Throws(() => mock.SomeMethod()); + Assert.Equal("Method 'SomeMethod', for which no specifications have been configured, was invoked on a strict mock. You must either configure specifications via calls to When on the mock, or use a loose mock by passing in MockBehavior.Loose to the mock's constructor.", ex.Message); + } + + [Fact] + public void apply_throws_if_property_without_specifications_is_invoked_on_a_strict_mock() + { + var mock = new TestTargetMock(); + var ex = Assert.Throws(() => mock.SomeProperty); + Assert.Equal("Property 'SomeProperty', for which no specifications have been configured, was invoked on a strict mock. You must either configure specifications via calls to When on the mock, or use a loose mock by passing in MockBehavior.Loose to the mock's constructor.", ex.Message); + } + + [Fact] + public void mocked_object_throws_if_the_mocked_object_cannot_be_automatically_determined() + { + var mock = new InvalidMockedObject(); + var ex = Assert.Throws(() => mock.MockedObject); + var expectedMessage = @"The default implementation of MockBase is unable to automatically determine an instance of type UnsealedClass to be used as the mocked object. You should override MockedObject in InvalidMockedObject and return the mocked object. +Full mock type name: PCLMock.UnitTests.MockBaseFixture+InvalidMockedObject +Full mocked object type name: PCLMock.UnitTests.MockBaseFixture+UnsealedClass"; + + Assert.Equal(expectedMessage, ex.Message); + } + + [Fact] + public void mocked_object_attempts_to_cast_the_mock_to_the_mocked_type_by_default() + { + var mock = new TestTargetMock(); + Assert.Same(mock, mock.MockedObject); + } + + [Fact] + public void when_throws_if_property_access_is_chained() + { + var mock = new TestTargetMock(); + var ex = Assert.Throws(() => mock.When(x => x.SomeComplexProperty.Name).Return("foo")); + Assert.Equal("Specifications against properties cannot be chained: x.SomeComplexProperty.Name", ex.Message); + } + + [Fact] + public void when_throws_if_method_access_is_chained() + { + var mock = new TestTargetMock(); + var ex = Assert.Throws(() => mock.When(x => x.SomeComplexMethod().GetAge()).Return(35)); + Assert.Equal("Specifications against methods cannot be chained: x.SomeComplexMethod().GetAge()", ex.Message); + } + + [Fact] + public void when_throws_if_method_is_an_extension_method() + { + var mock = new TestTargetMock(); + var ex = Assert.Throws(() => mock.When(x => x.SomeExtensionMethod()).Return(35)); + Assert.Equal("Specifications against extension methods cannot be provided: x.SomeExtensionMethod()", ex.Message); + } + + [Fact] + public void when_can_be_used_to_specify_result_of_property_getter() + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeProperty).Return(6); + + Assert.Equal(6, mock.SomeProperty); + } + + [Fact] + public void when_can_be_used_to_specify_what_happens_when_a_property_setter_is_accessed() + { + var mock = new TestTargetMock(); + var called = false; + mock.WhenPropertySet(x => x.SomeProperty).Do((_) => called = true); + + mock.SomeProperty = 1; + Assert.True(called); + } + + [Fact] + public void when_can_be_used_to_specify_what_happens_when_a_void_parameterless_method_is_invoked() + { + var mock = new TestTargetMock(); + var called = false; + mock.When(x => x.SomeMethod()).Do(() => called = true); + + mock.SomeMethod(); + Assert.True(called); + } + + [Fact] + public void when_can_be_used_to_specify_what_happens_when_a_void_method_is_invoked() + { + var mock = new TestTargetMock(); + var called = false; + mock.When(x => x.SomeMethod(It.IsAny(), It.IsAny())).Do((_, __) => called = true); + + mock.SomeMethod(1, 1f); + Assert.True(called); + } + + [Fact] + public void when_can_be_used_to_specify_what_happens_when_a_parameterless_method_is_invoked() + { + var mock = new TestTargetMock(); + var called = false; + mock.When(x => x.SomeMethodWithReturnValue()).Do(() => called = true); + + mock.SomeMethodWithReturnValue(); + Assert.True(called); + } + + [Fact] + public void when_can_be_used_to_specify_what_happens_when_a_method_is_invoked() + { + var mock = new TestTargetMock(); + var called = false; + mock.When(x => x.SomeMethodWithReturnValue(It.IsAny(), It.IsAny())).Do((_, __) => called = true); + + mock.SomeMethodWithReturnValue(1, 1f); + Assert.True(called); + } + + [Fact] + public void when_property_set_can_be_used_to_specify_what_happens_when_a_property_is_set() + { + var mock = new TestTargetMock(); + var called = false; + mock.WhenPropertySet(x => x.SomeProperty).Do(() => called = true); + + mock.SomeProperty = 12; + Assert.True(called); + } + + [Fact] + public void when_property_set_can_filter_arguments() + { + var mock = new TestTargetMock(MockBehavior.Loose); + var called = false; + mock.WhenPropertySet(x => x.SomeProperty, () => It.IsIn(1, 2, 3, 5, 8)).Do(() => called = true); + + mock.SomeProperty = 12; + mock.SomeProperty = 11; + Assert.False(called); + + mock.SomeProperty = 5; + Assert.True(called); + } + + [Fact] + public void do_can_specify_an_action_without_parameters() + { + var mock = new TestTargetMock(); + var counter = 0; + mock.When(x => x.SomeMethod()).Do(() => ++counter); + mock.When(x => x.SomeMethodWithReturnValue()).Do(() => ++counter); + + mock.SomeMethod(); + mock.SomeMethodWithReturnValue(); + + Assert.Equal(2, counter); + } + + [Fact] + public void do_can_take_parameters_when_specifying_a_property_set() + { + var mock = new TestTargetMock(); + int capturedValue = 0; + mock.WhenPropertySet(x => x.SomeProperty).Do((int x) => capturedValue = x); + + mock.SomeProperty = 35; + Assert.Equal(35, capturedValue); + } + + [Fact] + public void do_application_does_not_require_any_parameters_be_present_in_the_action() + { + var mock = new TestTargetMock(); + var called = false; + mock.When(x => x.SomeMethod(It.IsAny(), It.IsAny())).Do(() => called = true); + + mock.SomeMethod(1, 1f); + + Assert.True(called); + } + + [Fact] + public void do_application_throws_if_the_parameters_do_not_match_in_number() + { + var mock = new TestTargetMock(); + + mock.When(x => x.SomeMethod(It.IsAny(), It.IsAny())).Do((int i) => { }); + var ex = Assert.Throws(() => mock.SomeMethod(1, 1f)); + Assert.Equal("Could not execute the Do action associated with this mocked member due to a parameter mismatch. Expected: (System.Int32) Received: (System.Int32, System.Single)", ex.Message); + + mock.WhenPropertySet(x => x.SomeProperty).Do((int i, float f) => { }); + ex = Assert.Throws(() => mock.SomeProperty = 31); + Assert.Equal("Could not execute the Do action associated with this mocked member due to a parameter mismatch. Expected: (System.Int32, System.Single) Received: (System.Int32)", ex.Message); + } + + [Fact] + public void do_application_throws_if_the_parameters_do_not_match_in_type() + { + var mock = new TestTargetMock(); + + mock.WhenPropertySet(x => x.SomeProperty).Do((float f) => { }); + var ex = Assert.Throws(() => mock.SomeProperty = 31); + Assert.Equal("Could not execute the Do action associated with this mocked member due to a parameter mismatch. Expected: (System.Single) Received: (System.Int32)", ex.Message); + } + + [Fact] + public void do_can_specify_an_action_with_a_parameter_that_matches_a_propertys_value_type() + { + var mock = new TestTargetMock(); + var value = 0; + mock.WhenPropertySet(x => x.SomeProperty).Do(x => value = x); + + mock.SomeProperty = 31; + + Assert.Equal(31, value); + } + + [Fact] + public void do_can_specify_an_action_with_parameters_that_match_a_methods_argument_types() + { + var mock = new TestTargetMock(); + var iValue = 0; + var fValue = 0f; + mock + .When(x => x.SomeMethod(It.IsAny(), It.IsAny())) + .Do( + (i, f) => + { + iValue = i; + fValue = f; + }); + + mock.SomeMethod(21, 43f); + + Assert.Equal(21, iValue); + Assert.Equal(43f, fValue); + } + + [Fact] + public void return_can_be_used_to_specify_a_constant_return_value_for_property_getter() + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeProperty).Return(108); + + Assert.Equal(108, mock.SomeProperty); + } + + [Fact] + public void return_can_be_used_to_specify_a_constant_return_value_for_a_parameterless_method() + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethodWithReturnValue()).Return(108); + + Assert.Equal(108, mock.SomeMethodWithReturnValue()); + } + + [Fact] + public void return_can_be_used_to_specify_a_constant_return_value_for_a_method_with_parameters() + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethodWithReturnValue(It.IsAny(), It.IsAny())).Return(108); + + Assert.Equal(108, mock.SomeMethodWithReturnValue(1, 1f)); + } + + [Fact] + public void return_can_specify_an_action_without_parameters() + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethodWithReturnValue()).Return(() => 2 + 8); + + Assert.Equal(10, mock.SomeMethodWithReturnValue()); + } + + [Fact] + public void return_application_does_not_require_any_parameters_be_present_in_the_action() + { + var mock = new TestTargetMock(); + var called = false; + mock.WhenPropertySet(x => x.SomeProperty).Do(() => called = true); + + mock.SomeProperty = 21; + + Assert.True(called); + } + + [Fact] + public void return_application_throws_if_the_parameters_do_not_match_in_number() + { + var mock = new TestTargetMock(); + + mock.When(x => x.SomeMethodWithReturnValue()).Return((int i) => 3); + var ex = Assert.Throws(() => mock.SomeMethodWithReturnValue()); + Assert.Equal("Could not execute the Return action associated with this mocked member due to a parameter mismatch. Expected: (System.Int32) Received: ()", ex.Message); + + mock.When(x => x.SomeMethodWithReturnValue()).Return((int i, float f) => 31); + ex = Assert.Throws(() => mock.SomeMethodWithReturnValue()); + Assert.Equal("Could not execute the Return action associated with this mocked member due to a parameter mismatch. Expected: (System.Int32, System.Single) Received: ()", ex.Message); + } + + [Fact] + public void return_application_throws_if_the_parameters_do_not_match_in_type() + { + var mock = new TestTargetMock(); + + mock.When(x => x.SomeMethodWithReturnValue(It.IsAny(), It.IsAny())).Return((string s, int i) => 31); + var ex = Assert.Throws(() => mock.SomeMethodWithReturnValue(1, 1f)); + Assert.Equal("Could not execute the Return action associated with this mocked member due to a parameter mismatch. Expected: (System.String, System.Int32) Received: (System.Int32, System.Single)", ex.Message); + } + + [Fact] + public void return_can_specify_an_action_with_parameters_that_match_a_methods_argument_types() + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethodWithReturnValue(It.IsAny(), It.IsAny())).Return((int i, float f) => i + (int)f); + + Assert.Equal(11, mock.SomeMethodWithReturnValue(3, 8.1f)); + } + + [Fact] + public void throw_throws_an_invalid_operation_exception_by_default() + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeProperty).Throw(); + mock.When(x => x.SomeMethodTakingString("abc")).Throw(); + + var ex = Assert.Throws(() => mock.SomeProperty); + Assert.Equal("Mock has been configured to throw when accessing SomeProperty.", ex.Message); + + ex = Assert.Throws(() => mock.SomeMethodTakingString("abc")); + Assert.Equal("Mock has been configured to throw when accessing SomeMethodTakingString(It.Is(\"abc\")).", ex.Message); + } + + [Fact] + public void throw_can_specify_an_exception_to_throw_on_property_access() + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeProperty).Throw(new InvalidOperationException("Problem!")); + + var ex = Assert.Throws(() => Console.Write(mock.SomeProperty)); + Assert.Equal("Problem!", ex.Message); + } + + [Fact] + public void throw_can_specify_an_exception_to_throw_on_parameterless_method_access() + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethod()).Throw(new InvalidOperationException("Problem!")); + + var ex = Assert.Throws(() => mock.SomeMethod()); + Assert.Equal("Problem!", ex.Message); + } + + [Fact] + public void throw_can_specify_an_exception_to_throw_on_parameterized_method_access() + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethod(It.IsAny(), It.IsAny())).Throw(new InvalidOperationException("Problem!")); + + var ex = Assert.Throws(() => mock.SomeMethod(1, 1f)); + Assert.Equal("Problem!", ex.Message); + } + + [Fact] + public void actions_can_accept_base_types_in_place_of_specific_types() + { + var mock = new TestTargetMock(); + object value = null; + mock.When(x => x.SomeMethodTakingString(It.IsAny())).Do((object o) => value = o); + + mock.SomeMethodTakingString("whatever"); + Assert.Equal("whatever", value); + } + + [Fact] + public void methods_with_out_parameters_require_that_the_out_parameter_be_assigned() + { + var mock = new TestTargetMock(); + var called = false; + string s; + mock.When(x => x.SomeMethodWithOutParameter(out s)).Do(() => called = true); + + var ex = Assert.Throws(() => mock.SomeMethodWithOutParameter(out s)); + Assert.Equal("No value for out parameter at index 0 has been specified.", ex.Message); + Assert.False(called); + } + + [Fact] + public void methods_with_out_parameters_require_that_the_out_parameter_value_be_the_correct_type() + { + var mock = new TestTargetMock(); + var called = false; + string s; + mock.When(x => x.SomeMethodWithOutParameter(out s)).AssignOutOrRefParameter(0, 1).Do(() => called = true); + + var ex = Assert.Throws(() => mock.SomeMethodWithOutParameter(out s)); + Assert.Equal("Out parameter at index 0 has a value of type 'System.Int32' but type 'System.String' was expected.", ex.Message); + Assert.False(called); + } + + [Fact] + public void methods_with_value_type_out_parameters_cannot_have_null_assigned_as_the_value() + { + var mock = new TestTargetMock(); + var called = false; + int i; + mock.When(x => x.SomeMethodWithOutValueParameter(out i)).AssignOutOrRefParameter(0, null).Do(() => called = true); + + var ex = Assert.Throws(() => mock.SomeMethodWithOutValueParameter(out i)); + Assert.Equal("Out parameter at index 0 has a null value specified but it is a value type ('System.Int32') so cannot be null.", ex.Message); + Assert.False(called); + } + + [Fact] + public void methods_with_out_parameters_of_reference_type_can_be_mocked() + { + var mock = new TestTargetMock(); + string s; + mock.When(x => x.SomeMethodWithOutParameter(out s)).AssignOutOrRefParameter(0, "the value"); + + mock.SomeMethodWithOutParameter(out s); + Assert.Equal("the value", s); + } + + [Fact] + public void methods_with_out_parameters_of_value_type_can_be_mocked() + { + var mock = new TestTargetMock(); + int i; + mock.When(x => x.SomeMethodWithOutValueParameter(out i)).AssignOutOrRefParameter(0, 38); + + mock.SomeMethodWithOutValueParameter(out i); + Assert.Equal(38, i); + } + + [Fact] + public void methods_with_ref_parameters_of_reference_type_can_be_mocked() + { + var mock = new TestTargetMock(); + string s = null; + mock.When(x => x.SomeMethodWithRefParameter(ref s)).AssignOutOrRefParameter(0, "the value"); + + mock.SomeMethodWithRefParameter(ref s); + Assert.Equal("the value", s); + } + + [Fact] + public void methods_with_ref_parameters_of_value_type_can_be_mocked() + { + var mock = new TestTargetMock(); + int i = 0; + mock.When(x => x.SomeMethodWithRefValueParameter(ref i)).AssignOutOrRefParameter(0, 38); + + mock.SomeMethodWithRefValueParameter(ref i); + Assert.Equal(38, i); + } + + [Fact] + public void methods_with_ref_parameters_dont_require_a_parameter_assignment_when_configuring_specifications() + { + var mock = new TestTargetMock(); + var called = false; + int i = 0; + mock.When(x => x.SomeMethodWithRefValueParameter(ref i)).Do(() => called = true); + + mock.SomeMethodWithRefValueParameter(ref i); + Assert.True(called); + } + + [Fact] + public void methods_with_a_mixture_of_out_and_ref_parameters_can_be_mocked() + { + var mock = new TestTargetMock(); + var called = false; + int i1; + int i2 = 0; + string s1; + string s2 = null; + mock.When(x => x.SomeMethodWithAMixtureOfParameterTypes(0, null, out i1, out s1, ref i2, ref s2)) + .AssignOutOrRefParameter(2, 38) + .AssignOutOrRefParameter(3, "hello") + .AssignOutOrRefParameter(4, 14) + .AssignOutOrRefParameter(5, "world") + .Do(() => called = true); + + mock.SomeMethodWithAMixtureOfParameterTypes(0, null, out i1, out s1, ref i2, ref s2); + Assert.True(called); + Assert.Equal(38, i1); + Assert.Equal("hello", s1); + Assert.Equal(14, i2); + Assert.Equal("world", s2); + } + + [Fact] + public void virtual_members_in_unsealed_classes_can_be_mocked() + { + var mock = new UnsealedClassMock(); + mock.When(x => x.DoSomething()).Return(true); + + Assert.True(mock.MockedObject.DoSomething()); + } + + [Fact] + public void it_is_any_can_be_used_to_specify_arguments() + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethodWithReturnValue(It.IsAny(), It.IsAny())).Return(35); + + Assert.Equal(35, mock.SomeMethodWithReturnValue(5, 1f)); + } + + [Fact] + public void it_is_can_be_used_explicitly_to_specify_arguments() + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethodWithReturnValue(It.Is(3), It.Is(5f))).Return(35); + + Assert.Equal(35, mock.SomeMethodWithReturnValue(3, 5f)); + } + + [Fact] + public void it_is_can_be_used_implicitly_to_specify_arguments() + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethodWithReturnValue(3, 5f)).Return(35); + + Assert.Equal(35, mock.SomeMethodWithReturnValue(3, 5f)); + } + + [Fact] + public void it_is_not_can_be_used_to_specify_arguments() + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethodWithReturnValue(It.IsNot(3), It.IsNot(5f))).Return(35); + + Assert.Equal(35, mock.SomeMethodWithReturnValue(2, 4f)); + } + + [Fact] + public void it_is_null_be_used_to_specify_arguments() + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethodTakingStringWithReturnValue(It.IsNull())).Return(35); + + Assert.Equal(35, mock.SomeMethodTakingStringWithReturnValue(null)); + } + + [Fact] + public void it_is_not_null_be_used_to_specify_arguments() + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethodTakingStringWithReturnValue(It.IsNotNull())).Return(35); + + Assert.Equal(35, mock.SomeMethodTakingStringWithReturnValue("foo")); + } + + [Fact] + public void it_is_less_than_can_be_used_to_specify_arguments() + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethodWithReturnValue(It.IsLessThan(3), It.IsLessThan(5f))).Return(35); + + Assert.Equal(35, mock.SomeMethodWithReturnValue(2, 4f)); + } + + [Fact] + public void it_is_less_than_or_equal_to_can_be_used_to_specify_arguments() + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethodWithReturnValue(It.IsLessThanOrEqualTo(3), It.IsLessThanOrEqualTo(5f))).Return(35); + + Assert.Equal(35, mock.SomeMethodWithReturnValue(2, 4f)); + } + + [Fact] + public void it_is_greater_than_can_be_used_to_specify_arguments() + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethodWithReturnValue(It.IsGreaterThan(3), It.IsGreaterThan(5f))).Return(35); + + Assert.Equal(35, mock.SomeMethodWithReturnValue(4, 6f)); + } + + [Fact] + public void it_is_greater_than_or_equal_to_can_be_used_to_specify_arguments() + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethodWithReturnValue(It.IsGreaterThanOrEqualTo(3), It.IsGreaterThanOrEqualTo(5f))).Return(35); + + Assert.Equal(35, mock.SomeMethodWithReturnValue(4, 6f)); + } + + [Fact] + public void it_is_between_can_be_used_to_specify_arguments() + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethodWithReturnValue(It.IsBetween(3, 8), It.IsBetween(5f, 10f))).Return(35); + + Assert.Equal(35, mock.SomeMethodWithReturnValue(4, 9f)); + } + + [Fact] + public void it_is_not_between_can_be_used_to_specify_arguments() + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethodWithReturnValue(It.IsNotBetween(3, 8), It.IsNotBetween(5f, 10f))).Return(35); + + Assert.Equal(35, mock.SomeMethodWithReturnValue(2, 11f)); + } + + [Fact] + public void it_is_of_type_can_be_used_to_specify_arguments() + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethodTakingObjectWithReturnValue(It.IsOfType())).Return(30); + mock.When(x => x.SomeMethodTakingObjectWithReturnValue(It.IsOfType())).Return(35); + + Assert.Equal(30, mock.SomeMethodTakingObjectWithReturnValue(4)); + Assert.Equal(35, mock.SomeMethodTakingObjectWithReturnValue("foo")); + } + + [Fact] + public void it_is_not_of_type_can_be_used_to_specify_arguments() + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethodTakingObjectWithReturnValue(It.IsNotOfType())).Return(30); + mock.When(x => x.SomeMethodTakingObjectWithReturnValue(It.IsNotOfType())).Return(35); + + Assert.Equal(35, mock.SomeMethodTakingObjectWithReturnValue(4)); + Assert.Equal(30, mock.SomeMethodTakingObjectWithReturnValue("foo")); + Assert.Equal(35, mock.SomeMethodTakingObjectWithReturnValue(1f)); + } + + [Fact] + public void it_is_in_can_be_used_to_specify_arguments() + { + var mock = new TestTargetMock(MockBehavior.Loose); + mock.When(x => x.SomeMethodTakingObjectWithReturnValue(It.IsIn(1, 2, 3, 5, 8, 13))).Return(30); + + Assert.Equal(30, mock.SomeMethodTakingObjectWithReturnValue(2)); + Assert.Equal(30, mock.SomeMethodTakingObjectWithReturnValue(8)); + Assert.Equal(30, mock.SomeMethodTakingObjectWithReturnValue(13)); + Assert.Equal(0, mock.SomeMethodTakingObjectWithReturnValue(4)); + } + + [Fact] + public void it_is_like_can_be_used_to_specify_arguments() + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethodTakingStringWithReturnValue(It.IsLike(@"[Hh]ello\s*?world."))).Return(30); + + Assert.Equal(30, mock.SomeMethodTakingStringWithReturnValue("hello world!")); + Assert.Equal(30, mock.SomeMethodTakingStringWithReturnValue("Hello world!")); + Assert.Equal(30, mock.SomeMethodTakingStringWithReturnValue("hello \t world.")); + } + + [Fact] + public void it_is_like_can_be_used_with_options_to_specify_arguments() + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethodTakingStringWithReturnValue(It.IsLike(@"[Hh]ello\s*?world.", RegexOptions.IgnoreCase))).Return(30); + + Assert.Equal(30, mock.SomeMethodTakingStringWithReturnValue("HELLO WoRlD!")); + } + + [Fact] + public void it_matches_can_be_used_to_specify_arguments() + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethodTakingStringWithReturnValue(It.Matches(y => y.StartsWith("K")))).Return(30); + mock.When(x => x.SomeMethodTakingStringWithReturnValue(It.Matches(y => y.StartsWith("B")))).Return(29); + + Assert.Equal(30, mock.SomeMethodTakingStringWithReturnValue("Kent")); + Assert.Equal(30, mock.SomeMethodTakingStringWithReturnValue("Kart")); + Assert.Equal(29, mock.SomeMethodTakingStringWithReturnValue("Belinda")); + Assert.Equal(29, mock.SomeMethodTakingStringWithReturnValue("Batman")); + } + + [Fact] + public void argument_filters_can_be_used_to_differentiate_property_set_invocations() + { + var mock = new TestTargetMock(); + var anyCalled = false; + var specificCalled = false; + mock.WhenPropertySet(x => x.SomeProperty).Do(() => anyCalled = true); + mock.WhenPropertySet(x => x.SomeProperty, () => 3).Do(() => specificCalled = true); + + mock.SomeProperty = 30; + Assert.False(specificCalled); + Assert.True(anyCalled); + + mock.SomeProperty = 3; + Assert.True(specificCalled); + } + + [Fact] + public void argument_filters_can_be_used_to_differentiate_method_invocations() + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethodTakingStringWithReturnValue(It.IsAny())).Return(1); + mock.When(x => x.SomeMethodTakingStringWithReturnValue(It.IsLike("[Bb].."))).Return(2); + mock.When(x => x.SomeMethodTakingStringWithReturnValue("foo")).Return(3); + mock.When(x => x.SomeMethodTakingStringWithReturnValue("bar")).Return(4); + + Assert.Equal(4, mock.SomeMethodTakingStringWithReturnValue("bar")); + Assert.Equal(3, mock.SomeMethodTakingStringWithReturnValue("foo")); + Assert.Equal(2, mock.SomeMethodTakingStringWithReturnValue("biz")); + Assert.Equal(2, mock.SomeMethodTakingStringWithReturnValue("buz")); + Assert.Equal(2, mock.SomeMethodTakingStringWithReturnValue("Biz")); + Assert.Equal(1, mock.SomeMethodTakingStringWithReturnValue("whatever")); + Assert.Equal(1, mock.SomeMethodTakingStringWithReturnValue(null)); + } + + [Fact] + public void verify_throws_if_property_access_is_chained() + { + var mock = new TestTargetMock(); + var ex = Assert.Throws(() => mock.Verify(x => x.SomeComplexProperty.Name).WasCalledExactlyOnce()); + Assert.Equal("Specifications against properties cannot be chained: x.SomeComplexProperty.Name", ex.Message); + } + + [Fact] + public void verify_throws_if_method_access_is_chained() + { + var mock = new TestTargetMock(); + var ex = Assert.Throws(() => mock.Verify(x => x.SomeComplexMethod().GetAge()).WasCalledExactlyOnce()); + Assert.Equal("Specifications against methods cannot be chained: x.SomeComplexMethod().GetAge()", ex.Message); + } + + [Fact] + public void verify_throws_if_method_is_an_extension_method() + { + var mock = new TestTargetMock(); + var ex = Assert.Throws(() => mock.Verify(x => x.SomeExtensionMethod()).WasCalledExactlyOnce()); + Assert.Equal("Specifications against extension methods cannot be provided: x.SomeExtensionMethod()", ex.Message); + } + + [Fact] + public void verify_was_not_called_does_not_throw_if_the_member_was_not_invoked() + { + var mock = new TestTargetMock(); + + mock.Verify(x => x.SomeMethod()).WasNotCalled(); + mock.Verify(x => x.SomeMethodTakingString("foo")).WasNotCalled(); + mock.Verify(x => x.SomeMethodTakingString(It.IsAny())).WasNotCalled(); + mock.VerifyPropertySet(x => x.SomeProperty).WasNotCalled(); + mock.VerifyPropertySet(x => x.SomeProperty, () => It.IsAny()).WasNotCalled(); + } + + [Theory] + [InlineData(1, "Verification that SomeMethod() was not called failed because it was called 1 time.")] + [InlineData(2, "Verification that SomeMethod() was not called failed because it was called 2 times.")] + [InlineData(3, "Verification that SomeMethod() was not called failed because it was called 3 times.")] + [InlineData(15, "Verification that SomeMethod() was not called failed because it was called 15 times.")] + public void verify_was_not_called_throws_if_the_member_was_invoked(int callCount, string expectedExceptionMessage) + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethod()); + + for (var i = 0; i < callCount; ++i) + { + mock.SomeMethod(); + } + + var ex = Assert.Throws(() => mock.Verify(x => x.SomeMethod()).WasNotCalled()); + Assert.Equal(expectedExceptionMessage, ex.Message); + } + + [Fact] + public void verify_was_called_exactly_once_does_not_throw_if_the_member_was_called_once() + { + var mock = new TestTargetMock(MockBehavior.Loose); + mock.SomeMethod(); + mock.SomeMethodTakingString("foo"); + mock.SomeProperty = 30; + + mock.Verify(x => x.SomeMethod()).WasCalledExactlyOnce(); + mock.Verify(x => x.SomeMethodTakingString("foo")).WasCalledExactlyOnce(); + mock.Verify(x => x.SomeMethodTakingString(It.IsAny())).WasCalledExactlyOnce(); + mock.VerifyPropertySet(x => x.SomeProperty).WasCalledExactlyOnce(); + mock.VerifyPropertySet(x => x.SomeProperty, () => 30).WasCalledExactlyOnce(); + } + + [Theory] + [InlineData(0, "Verification that SomeMethod() was called exactly once failed because it was called 0 times.")] + [InlineData(2, "Verification that SomeMethod() was called exactly once failed because it was called 2 times.")] + [InlineData(3, "Verification that SomeMethod() was called exactly once failed because it was called 3 times.")] + [InlineData(15, "Verification that SomeMethod() was called exactly once failed because it was called 15 times.")] + public void verify_was_called_exactly_once_throws_if_the_member_was_not_invoked_exactly_once(int callCount, string expectedExceptionMessage) + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethod()); + + for (var i = 0; i < callCount; ++i) + { + mock.SomeMethod(); + } + + var ex = Assert.Throws(() => mock.Verify(x => x.SomeMethod()).WasCalledExactlyOnce()); + Assert.Equal(expectedExceptionMessage, ex.Message); + } + + [Fact] + public void verify_was_called_at_least_once_does_not_throw_if_the_member_was_called_one_or_more_times() + { + var mock = new TestTargetMock(MockBehavior.Loose); + mock.SomeMethod(); + mock.SomeMethodTakingString("foo"); + mock.SomeProperty = 30; + + mock.Verify(x => x.SomeMethod()).WasCalledAtLeastOnce(); + mock.Verify(x => x.SomeMethodTakingString("foo")).WasCalledAtLeastOnce(); + mock.Verify(x => x.SomeMethodTakingString(It.IsAny())).WasCalledAtLeastOnce(); + mock.VerifyPropertySet(x => x.SomeProperty).WasCalledAtLeastOnce(); + mock.VerifyPropertySet(x => x.SomeProperty, () => 30).WasCalledAtLeastOnce(); + + mock.SomeMethod(); + mock.SomeMethodTakingString("foo"); + mock.SomeProperty = 30; + mock.SomeMethod(); + mock.SomeMethodTakingString("foo"); + mock.SomeProperty = 30; + + mock.Verify(x => x.SomeMethod()).WasCalledAtLeastOnce(); + mock.Verify(x => x.SomeMethodTakingString("foo")).WasCalledAtLeastOnce(); + mock.Verify(x => x.SomeMethodTakingString(It.IsAny())).WasCalledAtLeastOnce(); + mock.VerifyPropertySet(x => x.SomeProperty).WasCalledAtLeastOnce(); + mock.VerifyPropertySet(x => x.SomeProperty, () => 30).WasCalledAtLeastOnce(); + } + + [Theory] + [InlineData(0, "Verification that SomeMethod() was called at least once failed because it was called 0 times.")] + public void verify_was_called_at_least_once_throws_if_the_member_was_not_invoked(int callCount, string expectedExceptionMessage) + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethod()); + + for (var i = 0; i < callCount; ++i) + { + mock.SomeMethod(); + } + + var ex = Assert.Throws(() => mock.Verify(x => x.SomeMethod()).WasCalledAtLeastOnce()); + Assert.Equal(expectedExceptionMessage, ex.Message); + } + + [Fact] + public void verify_was_called_at_most_once_does_not_throw_if_the_member_was_called_zero_or_one_times() + { + var mock = new TestTargetMock(MockBehavior.Loose); + + mock.Verify(x => x.SomeMethod()).WasCalledAtMostOnce(); + mock.Verify(x => x.SomeMethodTakingString("foo")).WasCalledAtMostOnce(); + mock.Verify(x => x.SomeMethodTakingString(It.IsAny())).WasCalledAtMostOnce(); + mock.VerifyPropertySet(x => x.SomeProperty).WasCalledAtMostOnce(); + mock.VerifyPropertySet(x => x.SomeProperty, () => 30).WasCalledAtMostOnce(); + + mock.SomeMethod(); + mock.SomeMethodTakingString("foo"); + mock.SomeProperty = 30; + + mock.Verify(x => x.SomeMethod()).WasCalledAtMostOnce(); + mock.Verify(x => x.SomeMethodTakingString("foo")).WasCalledAtMostOnce(); + mock.Verify(x => x.SomeMethodTakingString(It.IsAny())).WasCalledAtMostOnce(); + mock.VerifyPropertySet(x => x.SomeProperty).WasCalledAtMostOnce(); + mock.VerifyPropertySet(x => x.SomeProperty, () => 30).WasCalledAtMostOnce(); + } + + [Theory] + [InlineData(2, "Verification that SomeMethod() was called at most once failed because it was called 2 times.")] + [InlineData(3, "Verification that SomeMethod() was called at most once failed because it was called 3 times.")] + [InlineData(15, "Verification that SomeMethod() was called at most once failed because it was called 15 times.")] + public void verify_was_called_at_most_once_throws_if_the_member_was_invoked_more_than_once(int callCount, string expectedExceptionMessage) + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethod()); + + for (var i = 0; i < callCount; ++i) + { + mock.SomeMethod(); + } + + var ex = Assert.Throws(() => mock.Verify(x => x.SomeMethod()).WasCalledAtMostOnce()); + Assert.Equal(expectedExceptionMessage, ex.Message); + } + + [Fact] + public void verify_was_called_exactly_n_times_does_not_throw_if_the_member_was_called_the_correct_number_of_times() + { + var mock = new TestTargetMock(MockBehavior.Loose); + mock.SomeMethod(); + mock.SomeMethodTakingString("foo"); + mock.SomeMethodTakingString("foo"); + mock.SomeProperty = 30; + + mock.Verify(x => x.SomeMethod()).WasCalledExactly(times: 1); + mock.Verify(x => x.SomeMethodTakingString("foo")).WasCalledExactly(times: 2); + mock.Verify(x => x.SomeMethodTakingString(It.IsAny())).WasCalledExactly(times: 2); + mock.VerifyPropertySet(x => x.SomeProperty).WasCalledExactly(times: 1); + mock.VerifyPropertySet(x => x.SomeProperty, () => 30).WasCalledExactly(times: 1); + } + + [Theory] + [InlineData(2, 1, "Verification that SomeMethod() was called exactly 1 time failed because it was called 2 times.")] + [InlineData(2, 3, "Verification that SomeMethod() was called exactly 3 times failed because it was called 2 times.")] + [InlineData(3, 2, "Verification that SomeMethod() was called exactly 2 times failed because it was called 3 times.")] + [InlineData(15, 20, "Verification that SomeMethod() was called exactly 20 times failed because it was called 15 times.")] + [InlineData(20, 15, "Verification that SomeMethod() was called exactly 15 times failed because it was called 20 times.")] + public void verify_was_called_exactly_n_times_throws_if_the_member_was_not_invoked_exactly_that_number_of_times(int callCount, int verifyCount, string expectedExceptionMessage) + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethod()); + + for (var i = 0; i < callCount; ++i) + { + mock.SomeMethod(); + } + + var ex = Assert.Throws(() => mock.Verify(x => x.SomeMethod()).WasCalledExactly(times: verifyCount)); + Assert.Equal(expectedExceptionMessage, ex.Message); + } + + [Fact] + public void verify_was_called_at_least_n_times_does_not_throw_if_the_member_was_called_that_number_of_times_or_more() + { + var mock = new TestTargetMock(MockBehavior.Loose); + mock.SomeMethod(); + mock.SomeMethodTakingString("foo"); + mock.SomeProperty = 30; + + mock.Verify(x => x.SomeMethod()).WasCalledAtLeast(times: 1); + mock.Verify(x => x.SomeMethodTakingString("foo")).WasCalledAtLeast(times: 1); + mock.Verify(x => x.SomeMethodTakingString(It.IsAny())).WasCalledAtLeast(times: 1); + mock.VerifyPropertySet(x => x.SomeProperty).WasCalledAtLeast(times: 1); + mock.VerifyPropertySet(x => x.SomeProperty, () => 30).WasCalledAtLeast(times: 1); + + mock.SomeMethod(); + mock.SomeMethodTakingString("foo"); + mock.SomeProperty = 30; + mock.SomeMethod(); + mock.SomeMethodTakingString("foo"); + mock.SomeProperty = 30; + + mock.Verify(x => x.SomeMethod()).WasCalledAtLeast(times: 2); + mock.Verify(x => x.SomeMethodTakingString("foo")).WasCalledAtLeast(times: 3); + mock.Verify(x => x.SomeMethodTakingString(It.IsAny())).WasCalledAtLeast(times: 2); + mock.VerifyPropertySet(x => x.SomeProperty).WasCalledAtLeast(times: 3); + mock.VerifyPropertySet(x => x.SomeProperty, () => 30).WasCalledAtLeast(times: 2); + } + + [Theory] + [InlineData(0, 1, "Verification that SomeMethod() was called at least 1 time failed because it was called 0 times.")] + [InlineData(1, 2, "Verification that SomeMethod() was called at least 2 times failed because it was called 1 time.")] + [InlineData(2, 3, "Verification that SomeMethod() was called at least 3 times failed because it was called 2 times.")] + [InlineData(3, 5, "Verification that SomeMethod() was called at least 5 times failed because it was called 3 times.")] + [InlineData(15, 20, "Verification that SomeMethod() was called at least 20 times failed because it was called 15 times.")] + public void verify_was_called_at_least_n_times_throws_if_the_member_was_not_invoked_that_number_of_times_or_more(int callCount, int verifyCount, string expectedExceptionMessage) + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethod()); + + for (var i = 0; i < callCount; ++i) + { + mock.SomeMethod(); + } + + var ex = Assert.Throws(() => mock.Verify(x => x.SomeMethod()).WasCalledAtLeast(times: verifyCount)); + Assert.Equal(expectedExceptionMessage, ex.Message); + } + + [Fact] + public void verify_was_called_at_most_n_times_does_not_throw_if_the_member_was_called_fewer_or_equal_to_that_number_of_times() + { + var mock = new TestTargetMock(MockBehavior.Loose); + + mock.Verify(x => x.SomeMethod()).WasCalledAtMost(times: 1); + mock.Verify(x => x.SomeMethodTakingString("foo")).WasCalledAtMost(times: 1); + mock.Verify(x => x.SomeMethodTakingString(It.IsAny())).WasCalledAtMost(times: 1); + mock.VerifyPropertySet(x => x.SomeProperty).WasCalledAtMost(times: 1); + mock.VerifyPropertySet(x => x.SomeProperty, () => 30).WasCalledAtMost(times: 1); + + mock.SomeMethod(); + mock.SomeMethodTakingString("foo"); + mock.SomeProperty = 30; + + mock.Verify(x => x.SomeMethod()).WasCalledAtMost(times: 1); + mock.Verify(x => x.SomeMethodTakingString("foo")).WasCalledAtMost(times: 1); + mock.Verify(x => x.SomeMethodTakingString(It.IsAny())).WasCalledAtMost(times: 1); + mock.VerifyPropertySet(x => x.SomeProperty).WasCalledAtMost(times: 1); + mock.VerifyPropertySet(x => x.SomeProperty, () => 30).WasCalledAtMost(times: 1); + } + + [Theory] + [InlineData(1, 0, "Verification that SomeMethod() was called at most 0 times failed because it was called 1 time.")] + [InlineData(2, 1, "Verification that SomeMethod() was called at most 1 time failed because it was called 2 times.")] + [InlineData(3, 2, "Verification that SomeMethod() was called at most 2 times failed because it was called 3 times.")] + [InlineData(20, 15, "Verification that SomeMethod() was called at most 15 times failed because it was called 20 times.")] + public void verify_was_called_at_most_n_times_throws_if_the_member_was_invoked_more_than_that_number_of_times(int callCount, int verifyCount, string expectedExceptionMessage) + { + var mock = new TestTargetMock(); + mock.When(x => x.SomeMethod()); + + for (var i = 0; i < callCount; ++i) + { + mock.SomeMethod(); + } + + var ex = Assert.Throws(() => mock.Verify(x => x.SomeMethod()).WasCalledAtMost(times: verifyCount)); + Assert.Equal(expectedExceptionMessage, ex.Message); + } + + [Fact] + public void verification_failures_include_full_information_about_arguments_being_verified() + { + var mock = new TestTargetMock(); + + var ex = Assert.Throws(() => mock.Verify(x => x.SomeMethodTakingString("abc")).WasCalledExactlyOnce()); + Assert.Equal("Verification that SomeMethodTakingString(It.Is(\"abc\")) was called exactly once failed because it was called 0 times.", ex.Message); + + ex = Assert.Throws(() => mock.Verify(x => x.SomeMethodTakingString(It.IsAny())).WasCalledExactlyOnce()); + Assert.Equal("Verification that SomeMethodTakingString(It.IsAny()) was called exactly once failed because it was called 0 times.", ex.Message); + + ex = Assert.Throws(() => mock.Verify(x => x.SomeProperty).WasCalledExactlyOnce()); + Assert.Equal("Verification that SomeProperty was called exactly once failed because it was called 0 times.", ex.Message); + } + + [Fact] + public void verification_takes_into_account_any_argument_filters() + { + var mock = new TestTargetMock(MockBehavior.Loose); + mock.SomeMethodTakingString("foo"); + mock.SomeMethodTakingString("bar"); + mock.SomeMethodTakingString("bar"); + + mock.Verify(x => x.SomeMethodTakingString("foo")).WasCalledExactlyOnce(); + mock.Verify(x => x.SomeMethodTakingString("bar")).WasCalledExactly(times: 2); + mock.Verify(x => x.SomeMethodTakingString(It.IsAny())).WasCalledExactly(times: 3); + } + + [Fact] + public void issue13_repro() + { + var mock = new TestTargetMock(MockBehavior.Loose); + var subMock = new TestSubTargetMock(MockBehavior.Loose); + subMock.When(x => x.Height).Return(3); + + mock.SomeMethodTakingComplexType(subMock); + + mock.Verify(x => x.SomeMethodTakingComplexType(It.Matches(y => y.Height.HasValue))).WasCalledExactlyOnce(); + } + + #region Supporting Members + + private interface ITestSubTarget + { + string Name + { + get; + set; + } + + int? Height + { + get; + } + + int GetAge(); + } + + private interface ITestTarget + { + int SomeProperty + { + get; + set; + } + + int this[int index] + { + get; + set; + } + + int this[int first, int second] + { + get; + set; + } + + ITestSubTarget SomeComplexProperty + { + get; + } + + void SomeMethod(); + + ITestSubTarget SomeComplexMethod(); + + void SomeMethod(int i, float f); + + int SomeMethodWithReturnValue(); + + int SomeMethodWithReturnValue(int i, float f); + + void SomeMethodTakingComplexType(ITestSubTarget a); + + void SomeMethodTakingString(string s); + + int SomeMethodTakingStringWithReturnValue(string s); + + void SomeMethodTakingObject(object o); + + int SomeMethodTakingObjectWithReturnValue(object o); + + void SomeMethodWithOutParameter(out string s); + + void SomeMethodWithOutValueParameter(out int i); + + void SomeMethodWithRefParameter(ref string s); + + void SomeMethodWithRefValueParameter(ref int i); + + bool SomeMethodWithAMixtureOfParameterTypes(int i, string s, out int i2, out string s2, ref int i3, ref string s3); + } + + private sealed class TestSubTargetMock : MockBase, ITestSubTarget + { + public TestSubTargetMock(MockBehavior behavior) + : base(behavior) + { + } + + public int? Height => this.Apply(x => x.Height); + + public string Name + { + get { return this.Apply(x => x.Name); } + set { this.ApplyPropertySet(x => x.Name, value); } + } + + public int GetAge() => this.Apply(x => x.GetAge()); + } + + private sealed class TestTargetMock : MockBase, ITestTarget + { + public TestTargetMock(MockBehavior behavior = MockBehavior.Strict) + : base(behavior) + { + } + + public int SomeProperty + { + get { return this.Apply(x => x.SomeProperty); } + set { this.ApplyPropertySet(x => x.SomeProperty, value); } + } + + public int this[int index] + { + get { return this.Apply(x => x[index]); } + set { this.ApplyPropertySet(x => x[index], value); } + } + + public int this[int first, int second] + { + get { return this.Apply(x => x[first, second]); } + set { this.ApplyPropertySet(x => x[first, second], value); } + } + + public ITestSubTarget SomeComplexProperty => this.Apply(x => x.SomeComplexProperty); + + public void SomeMethod() => + this.Apply(x => x.SomeMethod()); + + public ITestSubTarget SomeComplexMethod() => + this.Apply(x => x.SomeComplexMethod()); + + public void SomeMethod(int i, float f) => + this.Apply(x => x.SomeMethod(i, f)); + + public int SomeMethodWithReturnValue() => + this.Apply(x => x.SomeMethodWithReturnValue()); + + public int SomeMethodWithReturnValue(int i, float f) => + this.Apply(x => x.SomeMethodWithReturnValue(i, f)); + + public void SomeMethodTakingComplexType(ITestSubTarget a) => + this.Apply(x => x.SomeMethodTakingComplexType(a)); + + public void SomeMethodTakingString(string s) => + this.Apply(x => x.SomeMethodTakingString(s)); + + public int SomeMethodTakingStringWithReturnValue(string s) => + this.Apply(x => x.SomeMethodTakingStringWithReturnValue(s)); + + public void SomeMethodTakingObject(object o) => + this.Apply(x => x.SomeMethodTakingObject(o)); + + public int SomeMethodTakingObjectWithReturnValue(object o) => + this.Apply(x => x.SomeMethodTakingObjectWithReturnValue(o)); + + public void SomeMethodWithOutParameter(out string s) + { + string sOut; + s = this.GetOutParameterValue(x => x.SomeMethodWithOutParameter(out sOut), 0); + this.Apply(x => x.SomeMethodWithOutParameter(out sOut)); + } + + public void SomeMethodWithOutValueParameter(out int i) + { + int iOut; + i = this.GetOutParameterValue(x => x.SomeMethodWithOutValueParameter(out iOut), 0); + this.Apply(x => x.SomeMethodWithOutValueParameter(out iOut)); + } + + public void SomeMethodWithRefParameter(ref string s) + { + var sRef = default(string); + s = this.GetRefParameterValue(x => x.SomeMethodWithRefParameter(ref sRef), 0); + this.Apply(x => x.SomeMethodWithRefParameter(ref sRef)); + } + + public void SomeMethodWithRefValueParameter(ref int i) + { + var iRef = default(int); + i = this.GetRefParameterValue(x => x.SomeMethodWithRefValueParameter(ref iRef), 0); + this.Apply(x => x.SomeMethodWithRefValueParameter(ref iRef)); + } + + public bool SomeMethodWithAMixtureOfParameterTypes(int i, string s, out int i2, out string s2, ref int i3, ref string s3) + { + int i2Out; + string s2Out; + var i3Ref = default(int); + var s3Ref = default(string); + i2 = this.GetOutParameterValue(x => x.SomeMethodWithAMixtureOfParameterTypes(i, s, out i2Out, out s2Out, ref i3Ref, ref s3Ref), 2); + s2 = this.GetOutParameterValue(x => x.SomeMethodWithAMixtureOfParameterTypes(i, s, out i2Out, out s2Out, ref i3Ref, ref s3Ref), 3); + i3 = this.GetRefParameterValue(x => x.SomeMethodWithAMixtureOfParameterTypes(i, s, out i2Out, out s2Out, ref i3Ref, ref s3Ref), 4); + s3 = this.GetRefParameterValue(x => x.SomeMethodWithAMixtureOfParameterTypes(i, s, out i2Out, out s2Out, ref i3Ref, ref s3Ref), 5); + return this.Apply(x => x.SomeMethodWithAMixtureOfParameterTypes(i, s, out i2Out, out s2Out, ref i3Ref, ref s3Ref)); + } + } + + private class UnsealedClass + { + public virtual bool DoSomething() => + false; + } + + private class UnsealedClassMock : MockBase + { + private readonly UnsealedClass mockedObject; + + public UnsealedClassMock(MockBehavior behavior = MockBehavior.Strict) + : base(behavior) + { + this.mockedObject = new UnsealedClassSubclass(this); + } + + public override UnsealedClass MockedObject => this.mockedObject; + + private sealed class UnsealedClassSubclass : UnsealedClass + { + private readonly UnsealedClassMock owner; + + public UnsealedClassSubclass(UnsealedClassMock owner) + { + this.owner = owner; + } + + public override bool DoSomething() + { + return this.owner.Apply(x => x.DoSomething()); + } + } + } + + private class InvalidMockedObject : MockBase + { + public InvalidMockedObject(MockBehavior behavior = MockBehavior.Strict) + : base(behavior) + { + } + } + + #endregion + } + + public static class TestExtensions + { + public static int SomeExtensionMethod(this object @this) => + 0; + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/PCLMock.UnitTests.csproj b/Src/PCLMock.UnitTests_OLD/PCLMock.UnitTests.csproj new file mode 100644 index 0000000..54156e8 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/PCLMock.UnitTests.csproj @@ -0,0 +1,400 @@ + + + + + + Debug + AnyCPU + {05115055-0BBC-49D5-8966-2B90325F2F08} + Library + Properties + PCLMock.UnitTests + PCLMock.UnitTests + v4.5.2 + 512 + + + + True + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Microsoft.CodeAnalysis.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.dll + True + + + ..\packages\Microsoft.CodeAnalysis.CSharp.1.3.2\lib\net45\Microsoft.CodeAnalysis.CSharp.dll + True + + + ..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.1.3.2\lib\net45\Microsoft.CodeAnalysis.CSharp.Workspaces.dll + True + + + ..\packages\Microsoft.CodeAnalysis.VisualBasic.1.3.2\lib\net45\Microsoft.CodeAnalysis.VisualBasic.dll + True + + + ..\packages\Microsoft.CodeAnalysis.VisualBasic.Workspaces.1.3.2\lib\net45\Microsoft.CodeAnalysis.VisualBasic.Workspaces.dll + True + + + ..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.Workspaces.dll + True + + + ..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.Workspaces.Desktop.dll + True + + + + ..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll + True + + + + ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.AttributedModel.dll + True + + + ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.Convention.dll + True + + + ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.Hosting.dll + True + + + ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.Runtime.dll + True + + + ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.TypedParts.dll + True + + + + ..\packages\Rx-Core.2.2.5\lib\net45\System.Reactive.Core.dll + True + + + ..\packages\Rx-Interfaces.2.2.5\lib\net45\System.Reactive.Interfaces.dll + True + + + ..\packages\Rx-Linq.2.2.5\lib\net45\System.Reactive.Linq.dll + True + + + ..\packages\Rx-PlatformServices.2.2.5\lib\net45\System.Reactive.PlatformServices.dll + True + + + ..\packages\System.Reflection.Metadata.1.4.2\lib\portable-net45+win8\System.Reflection.Metadata.dll + True + + + + + + + + ..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll + True + + + ..\packages\xunit.assert.2.2.0\lib\netstandard1.1\xunit.assert.dll + True + + + ..\packages\xunit.extensibility.core.2.2.0\lib\netstandard1.1\xunit.core.dll + True + + + ..\packages\xunit.extensibility.execution.2.2.0\lib\net452\xunit.execution.desktop.dll + True + + + + + Properties\AssemblyInfoCommon.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {6e077796-0241-4191-a866-0ea52b9bd946} + PCLMock.CodeGeneration + + + {a02c0394-4dad-4422-97bb-4a90d89cee66} + PCLMock + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/PCLMock.UnitTests.v3.ncrunchproject b/Src/PCLMock.UnitTests_OLD/PCLMock.UnitTests.v3.ncrunchproject similarity index 100% rename from Src/PCLMock.UnitTests/PCLMock.UnitTests.v3.ncrunchproject rename to Src/PCLMock.UnitTests_OLD/PCLMock.UnitTests.v3.ncrunchproject diff --git a/Src/PCLMock.UnitTests_OLD/Properties/AssemblyInfo.cs b/Src/PCLMock.UnitTests_OLD/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..a42eb3a --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/Properties/AssemblyInfo.cs @@ -0,0 +1,6 @@ +using System; +using System.Reflection; + +[assembly: AssemblyTitle("PCLMock.UnitTests")] +[assembly: AssemblyDescription("Contains unit tests for PCLMock.")] +[assembly: CLSCompliantAttribute(false)] \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/Utility/ObjectExtensionsFixture.cs b/Src/PCLMock.UnitTests_OLD/Utility/ObjectExtensionsFixture.cs new file mode 100644 index 0000000..4c0b2bb --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/Utility/ObjectExtensionsFixture.cs @@ -0,0 +1,72 @@ +namespace PCLMock.UnitTests.Utility +{ + using System; + using PCLMock.Utility; + using Xunit; + using Xunit.Extensions; + + public sealed class ToDebugStringExtensionsFixture + { + [Theory] + [InlineData(null, "null")] + [InlineData("foo", "\"foo\"")] + [InlineData(true, "true")] + [InlineData(false, "false")] + [InlineData(35, "35")] + [InlineData(-17, "-17")] + [InlineData(35U, "35U")] + [InlineData(17U, "17U")] + [InlineData(35L, "35L")] + [InlineData(-17L, "-17L")] + [InlineData(35UL, "35UL")] + [InlineData(17UL, "17UL")] + [InlineData(3.4f, "3.4F")] + [InlineData(-3.4f, "-3.4F")] + [InlineData(3.4d, "3.4D")] + [InlineData(-3.4d, "-3.4D")] + [InlineData(typeof(bool), "bool")] + [InlineData(typeof(byte), "byte")] + [InlineData(typeof(sbyte), "sbyte")] + [InlineData(typeof(char), "char")] + [InlineData(typeof(decimal), "decimal")] + [InlineData(typeof(short), "short")] + [InlineData(typeof(ushort), "ushort")] + [InlineData(typeof(int), "int")] + [InlineData(typeof(uint), "uint")] + [InlineData(typeof(long), "long")] + [InlineData(typeof(ulong), "ulong")] + [InlineData(typeof(float), "float")] + [InlineData(typeof(double), "double")] + [InlineData(typeof(string), "string")] + [InlineData(typeof(object), "object")] + [InlineData(typeof(int?), "int?")] + [InlineData(typeof(long?), "long?")] + [InlineData(typeof(float?), "float?")] + [InlineData(typeof(DayOfWeek?), "System.DayOfWeek?")] + [InlineData(typeof(Guid?), "System.Guid?")] + [InlineData(typeof(ToDebugStringExtensionsFixture), "PCLMock.UnitTests.Utility.ToDebugStringExtensionsFixture")] + [InlineData(DayOfWeek.Monday, "DayOfWeek.Monday")] + [InlineData(DayOfWeek.Friday, "DayOfWeek.Friday")] + [InlineData((DayOfWeek)238, "DayOfWeek.238")] + [InlineData(AttributeTargets.Assembly | AttributeTargets.Class, "AttributeTargets.Assembly | AttributeTargets.Class")] + [InlineData(AttributeTargets.Assembly | (AttributeTargets)32768, "AttributeTargets.Assembly")] + public void to_debug_string_returns_expected_result(object o, string expectedResult) + { + Assert.Equal(expectedResult, o.ToDebugString()); + } + + [Fact] + public void to_debug_string_handles_decimals() + { + Assert.Equal("3.461M", 3.461M.ToDebugString()); + Assert.Equal("-3.461M", (-3.461M).ToDebugString()); + } + + [Fact] + public void to_debug_string_handles_anything_else_in_a_generic_fashion() + { + Assert.Equal("00:01:00 [System.TimeSpan]", TimeSpan.FromMinutes(1).ToDebugString()); + Assert.Equal("d527c281-1a18-452d-81ea-e8c2f3a252df [System.Guid]", new Guid("D527C281-1A18-452D-81EA-E8C2F3A252DF").ToDebugString()); + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/Visitors/ArgumentFilterVisitorFixture.cs b/Src/PCLMock.UnitTests_OLD/Visitors/ArgumentFilterVisitorFixture.cs new file mode 100644 index 0000000..3f9279b --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/Visitors/ArgumentFilterVisitorFixture.cs @@ -0,0 +1,87 @@ +namespace PCLMock.UnitTests.Visitors +{ + using System; + using System.Linq.Expressions; + using PCLMock.ArgumentFilters; + using PCLMock.Visitors; + using Xunit; + using Xunit.Extensions; + + public sealed class ArgumentFilterVisitorFixture + { + [Fact] + public void can_find_argument_filter_in_method_call_against_it_class() + { + var argumentFilter = ArgumentFilterVisitor.FindArgumentFilterWithin(GetExpression(() => It.IsAny())); + Assert.NotNull(argumentFilter); + Assert.True(argumentFilter.Matches("foo")); + Assert.True(argumentFilter.Matches("bar")); + Assert.True(argumentFilter.Matches(null)); + + argumentFilter = ArgumentFilterVisitor.FindArgumentFilterWithin(GetExpression(() => It.Is("foo"))); + Assert.NotNull(argumentFilter); + Assert.True(argumentFilter.Matches("foo")); + Assert.False(argumentFilter.Matches("bar")); + + argumentFilter = ArgumentFilterVisitor.FindArgumentFilterWithin(GetExpression(() => It.IsIn(1, 2, 3))); + Assert.NotNull(argumentFilter); + Assert.True(argumentFilter.Matches(1)); + Assert.True(argumentFilter.Matches(3)); + Assert.False(argumentFilter.Matches(4)); + } + + [Theory] + [InlineData(1)] + [InlineData(35)] + [InlineData(3235)] + [InlineData("foo")] + [InlineData("bar")] + [InlineData("baz")] + [InlineData(1f)] + [InlineData(13.1f)] + [InlineData(1d)] + [InlineData(13.1d)] + public void a_constant_being_returned_is_translated_to_an_is_argument_filter(object value) + { + var argumentFilter = ArgumentFilterVisitor.FindArgumentFilterWithin(GetExpression(() => value)); + Assert.NotNull(argumentFilter); + Assert.IsType(argumentFilter); + Assert.True(argumentFilter.Matches(value)); + } + + [Fact] + public void expressions_are_evaluated_and_translated_to_an_is_argument_filter() + { + var argumentFilter = ArgumentFilterVisitor.FindArgumentFilterWithin(GetExpression(() => decimal.MinValue)); + Assert.NotNull(argumentFilter); + Assert.IsType(argumentFilter); + Assert.True(argumentFilter.Matches(decimal.MinValue)); + + argumentFilter = ArgumentFilterVisitor.FindArgumentFilterWithin(GetExpression(() => Tuple.Create(1, "one"))); + Assert.NotNull(argumentFilter); + Assert.IsType(argumentFilter); + Assert.True(argumentFilter.Matches(Tuple.Create(1, "one"))); + } + + [Fact] + public void cannot_find_argument_filter_in_method_call_with_no_arguments() + { + var argumentFilter = ArgumentFilterVisitor.FindArgumentFilterWithin(GetExpression(() => Console.WriteLine())); + Assert.Null(argumentFilter); + } + + #region Supporting Members + + private static Expression GetExpression(Expression root) + { + return root.Body; + } + + private static Expression GetExpression(Expression> root) + { + return root.Body; + } + + #endregion + } +} diff --git a/Src/PCLMock.UnitTests_OLD/Visitors/ArgumentFiltersVisitorFixture.cs b/Src/PCLMock.UnitTests_OLD/Visitors/ArgumentFiltersVisitorFixture.cs new file mode 100644 index 0000000..bb46f1f --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/Visitors/ArgumentFiltersVisitorFixture.cs @@ -0,0 +1,67 @@ +namespace PCLMock.UnitTests.Visitors +{ + using System; + using System.Linq.Expressions; + using PCLMock.ArgumentFilters; + using PCLMock.Utility; + using PCLMock.Visitors; + using Xunit; + + public sealed class ArgumentFiltersVisitorFixture + { + [Fact] + public void can_find_argument_filters_in_a_method_call() + { + var argumentFilters = ArgumentFiltersVisitor.FindArgumentFiltersWithin(GetExpression(() => Console.WriteLine(It.IsAny(), 3, It.IsIn("foo", "bar")))); + Assert.NotNull(argumentFilters); + Assert.Equal(3, argumentFilters.Count); + Assert.True(argumentFilters[0].Matches("foo")); + Assert.True(argumentFilters[0].Matches("bar")); + Assert.True(argumentFilters[0].Matches(null)); + Assert.True(argumentFilters[1].Matches(3)); + Assert.False(argumentFilters[1].Matches(2)); + Assert.True(argumentFilters[2].Matches("foo")); + Assert.True(argumentFilters[2].Matches("bar")); + Assert.False(argumentFilters[2].Matches("baz")); + Assert.False(argumentFilters[2].Matches(3)); + } + + [Fact] + public void out_and_ref_arguments_always_result_in_a_non_discriminatory_filter() + { + int i = 0; + string s; + var argumentFilters = ArgumentFiltersVisitor.FindArgumentFiltersWithin(GetExpression(() => this.SomeMethod(ref i, out s))); + Assert.NotNull(argumentFilters); + Assert.Equal(2, argumentFilters.Count); + Assert.IsType>(argumentFilters[0]); + Assert.IsType>(argumentFilters[1]); + } + + [Fact] + public void cannot_find_argument_filters_if_there_is_a_method_call_but_it_is_not_at_root_level() + { + ArgumentFilterCollection argumentFilters; + Assert.False(ArgumentFiltersVisitor.TryFindArgumentFiltersWithin(GetExpression(() => new[] { Tuple.Create(1, 2) }), out argumentFilters)); + } + + #region Supporting Members + + private static Expression GetExpression(Expression root) + { + return root.Body; + } + + private static Expression GetExpression(Expression> root) + { + return root.Body; + } + + private void SomeMethod(ref int i, out string s) + { + s = null; + } + + #endregion + } +} diff --git a/Src/PCLMock.UnitTests_OLD/Visitors/ArgumentsVisitorFixture.cs b/Src/PCLMock.UnitTests_OLD/Visitors/ArgumentsVisitorFixture.cs new file mode 100644 index 0000000..3adca9d --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/Visitors/ArgumentsVisitorFixture.cs @@ -0,0 +1,59 @@ +namespace PCLMock.UnitTests.Visitors +{ + using System; + using System.Linq.Expressions; + using PCLMock.Visitors; + using Xunit; + + public sealed class ArgumentsVisitorFixture + { + [Fact] + public void can_find_arguments_in_parameterless_method_call() + { + var arguments = ArgumentsVisitor.FindArgumentsWithin(GetExpression(() => Console.WriteLine())); + Assert.NotNull(arguments); + Assert.Equal(0, arguments.Length); + } + + [Fact] + public void can_find_arguments_within_method_call_taking_parameters() + { + var arguments = ArgumentsVisitor.FindArgumentsWithin(GetExpression(() => Console.WriteLine("something {0}, {1}, {2}", 13, DateTime.MinValue, Tuple.Create(1, "one")))); + Assert.NotNull(arguments); + Assert.Equal(4, arguments.Length); + Assert.Equal("something {0}, {1}, {2}", arguments[0]); + Assert.Equal(13, arguments[1]); + Assert.Equal(DateTime.MinValue, arguments[2]); + Assert.Equal(Tuple.Create(1, "one"), arguments[3]); + } + + [Fact] + public void cannot_find_arguments_in_non_method_call() + { + object[] arguments; + Assert.False(ArgumentsVisitor.TryFindArgumentsWithin(GetExpression(() => 13), out arguments)); + Assert.False(ArgumentsVisitor.TryFindArgumentsWithin(GetExpression(() => "foo"), out arguments)); + } + + [Fact] + public void cannot_find_arguments_if_there_is_a_method_call_but_it_is_not_at_root_level() + { + object[] arguments; + Assert.False(ArgumentsVisitor.TryFindArgumentsWithin(GetExpression(() => new[] { Tuple.Create(1, 2) }), out arguments)); + } + + #region Supporting Members + + private static Expression GetExpression(Expression root) + { + return root.Body; + } + + private static Expression GetExpression(Expression> root) + { + return root.Body; + } + + #endregion + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/Visitors/SelectorStringVisitorFixture.cs b/Src/PCLMock.UnitTests_OLD/Visitors/SelectorStringVisitorFixture.cs new file mode 100644 index 0000000..5d5bda4 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/Visitors/SelectorStringVisitorFixture.cs @@ -0,0 +1,101 @@ +namespace PCLMock.UnitTests.Visitors +{ + using System; + using System.Linq.Expressions; + using PCLMock.Visitors; + using Xunit; + + public sealed class SelectorStringVisitorFixture + { + [Fact] + public void accessing_a_read_only_property_yields_the_correct_string_representation() + { + var visitor = new SelectorStringVisitor(); + var expression = GetExpression(x => x.ReadOnlyProperty); + + visitor.Visit(expression); + + Assert.Equal("ReadOnlyProperty", visitor.ToString()); + } + + [Fact] + public void accessing_a_read_write_property_yields_the_correct_string_representation() + { + var visitor = new SelectorStringVisitor(); + var expression = GetExpression(x => x.ReadWriteProperty); + + visitor.Visit(expression); + + Assert.Equal("ReadWriteProperty", visitor.ToString()); + } + + [Fact] + public void accessing_a_method_without_arguments_yields_the_correct_string_representation() + { + var visitor = new SelectorStringVisitor(); + var expression = GetExpression(x => x.MethodWithoutArguments()); + + visitor.Visit(expression); + + Assert.Equal("MethodWithoutArguments()", visitor.ToString()); + } + + [Fact] + public void accessing_a_method_with_arguments_yields_the_correct_string_representation() + { + var visitor = new SelectorStringVisitor(); + var expression = GetExpression(x => x.MethodWithArguments(3, It.IsAny(), null)); + + visitor.Visit(expression); + + Assert.Equal("MethodWithArguments(It.Is(3), It.IsAny(), It.Is(null))", visitor.ToString()); + + visitor = new SelectorStringVisitor(); + expression = GetExpression(x => x.MethodWithArguments(3, It.IsAny(), "abc")); + + visitor.Visit(expression); + + Assert.Equal("MethodWithArguments(It.Is(3), It.IsAny(), It.Is(\"abc\"))", visitor.ToString()); + + visitor = new SelectorStringVisitor(); + var value = TimeSpan.FromSeconds(1); + expression = GetExpression(x => x.MethodWithArguments(3, It.IsAny(), value)); + + visitor.Visit(expression); + + Assert.Equal("MethodWithArguments(It.Is(3), It.IsAny(), It.Is(00:00:01 [System.TimeSpan]))", visitor.ToString()); + } + + #region Supporting Members + + private static Expression GetExpression(Expression> root) + { + return root.Body; + } + + private static Expression GetExpression(Expression> root) + { + return root.Body; + } + + private interface ITestTarget + { + int ReadOnlyProperty + { + get; + } + + int ReadWriteProperty + { + get; + set; + } + + int MethodWithoutArguments(); + + int MethodWithArguments(int i, string s, object o); + } + + #endregion + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/Visitors/ValueExtractorFixture.cs b/Src/PCLMock.UnitTests_OLD/Visitors/ValueExtractorFixture.cs new file mode 100644 index 0000000..b73cbe1 --- /dev/null +++ b/Src/PCLMock.UnitTests_OLD/Visitors/ValueExtractorFixture.cs @@ -0,0 +1,139 @@ +namespace PCLMock.UnitTests.Visitors +{ + using System; + using System.Linq.Expressions; + using PCLMock.Visitors; + using Xunit; + using Xunit.Extensions; + + public sealed class ValueExtractorFixture + { + [Fact] + public void can_find_null_in_an_expression() + { + Assert.Null(ValueExtractor.FindValueWithin(GetExpression(() => null))); + } + + [Theory] + [InlineData(1)] + [InlineData(5)] + [InlineData(52367)] + [InlineData(int.MinValue)] + [InlineData(int.MaxValue)] + [InlineData(Math.PI)] + [InlineData(1L)] + [InlineData(5L)] + [InlineData(52367L)] + [InlineData("foo")] + [InlineData("bar")] + [InlineData(12f)] + [InlineData(12.1d)] + public void can_find_value_in_an_expression_that_simply_returns_a_constant(object value) + { + Assert.Equal(value, ValueExtractor.FindValueWithin(GetExpression(() => value))); + } + + [Fact] + public void can_find_value_in_an_expression_that_returns_a_dereferenced_value() + { + Assert.Equal(DateTime.MinValue, ValueExtractor.FindValueWithin(GetExpression(() => DateTime.MinValue))); + Assert.Equal(decimal.MinValue, ValueExtractor.FindValueWithin(GetExpression(() => decimal.MinValue))); + Assert.Equal(decimal.MaxValue, ValueExtractor.FindValueWithin(GetExpression(() => decimal.MaxValue))); + Assert.Equal(decimal.MinusOne, ValueExtractor.FindValueWithin(GetExpression(() => decimal.MinusOne))); + } + + [Theory] + [InlineData(1)] + [InlineData(19)] + [InlineData(3471)] + [InlineData(1L)] + [InlineData(5L)] + [InlineData(52367L)] + [InlineData("foo")] + [InlineData("bar")] + [InlineData(12f)] + [InlineData(12.1d)] + public void can_find_value_in_an_expression_that_returns_a_local_value(object value) + { + var local = value; + Assert.Equal(value, ValueExtractor.FindValueWithin(GetExpression(() => local))); + } + + [Theory] + [InlineData(new int[] {})] + [InlineData(new [] { 1, 2, 3 })] + [InlineData(new [] { 1, 2, 3, 4, 5 })] + [InlineData(new [] { 1d, 10d, 2937d })] + public void can_find_value_in_an_expression_that_creates_an_array(object array) + { + Assert.Equal(array, ValueExtractor.FindValueWithin(GetExpression(() => array))); + } + + [Fact] + public void can_find_value_in_an_expression_that_news_up_an_object() + { + Assert.Equal(new DateTime(1979, 10, 26), ValueExtractor.FindValueWithin(GetExpression(() => new DateTime(1979, 10, 26)))); + Assert.Equal(Tuple.Create("one", 1), ValueExtractor.FindValueWithin(GetExpression(() => new Tuple("one", 1)))); + } + + [Theory] + [InlineData(1L)] + [InlineData(2L)] + [InlineData(1347L)] + [InlineData(-23897L)] + public void can_find_value_in_an_expression_that_requires_conversion(long value) + { + Assert.Equal((int)value, ValueExtractor.FindValueWithin(GetExpression(() => (int)value))); + } + + [Fact] + public void can_find_value_in_an_expression_that_includes_a_lambda() + { + Expression> expression = x => x % 2 == 0; + var value = ValueExtractor.FindValueWithin(expression); + + Assert.NotNull(value); + var castValue = Assert.IsType>(value); + + Assert.True(castValue(0)); + Assert.False(castValue(1)); + Assert.True(castValue(2)); + Assert.False(castValue(3)); + } + + [Fact] + public void can_find_value_in_a_method_invocation() + { + Assert.Equal(Tuple.Create("one", 1), ValueExtractor.FindValueWithin(GetExpression(() => Tuple.Create("one", 1)))); + Assert.Equal(TimeSpan.FromSeconds(1), ValueExtractor.FindValueWithin(GetExpression(() => TimeSpan.FromSeconds(1)))); + } + + [Fact] + public void can_find_value_in_a_binary_expression() + { + Assert.Equal(7, ValueExtractor.FindValueWithin(GetExpression(() => 3 + 1 + 3))); + Assert.Equal(TimeSpan.FromSeconds(4), ValueExtractor.FindValueWithin(GetExpression(() => TimeSpan.FromSeconds(1) + TimeSpan.FromSeconds(3)))); + } + + [Fact] + public void cannot_find_value_in_a_method_invocation_if_the_method_has_no_return_value() + { + object value; + Assert.False(ValueExtractor.TryFindValueWithin(GetExpression(() => Console.WriteLine()), out value)); + } + + #region Supporting Members + + private static Expression GetExpression(Expression root) + { + return root.Body; + } + + private static Expression GetExpression(Expression> root) + { + return root.Body; + } + + #endregion + } +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/app.config b/Src/PCLMock.UnitTests_OLD/app.config similarity index 100% rename from Src/PCLMock.UnitTests/app.config rename to Src/PCLMock.UnitTests_OLD/app.config diff --git a/Src/PCLMock.UnitTests/packages.config b/Src/PCLMock.UnitTests_OLD/packages.config similarity index 100% rename from Src/PCLMock.UnitTests/packages.config rename to Src/PCLMock.UnitTests_OLD/packages.config diff --git a/Src/PCLMock/Visitors/ArgumentFilterVisitor.cs b/Src/PCLMock/Visitors/ArgumentFilterVisitor.cs index 8268f9e..cf2c358 100644 --- a/Src/PCLMock/Visitors/ArgumentFilterVisitor.cs +++ b/Src/PCLMock/Visitors/ArgumentFilterVisitor.cs @@ -44,7 +44,7 @@ protected override Expression VisitMethodCall(MethodCallExpression node) .DeclaringType .GetTypeInfo() .DeclaredMethods - .Where(declaredMethod => declaredMethod.IsStatic && declaredMethod.IsPublic) + .Where(declaredMethod => declaredMethod.IsStatic) .Where(x => x.Name == node.Method.Name + "Filter" && x.GetParameters().Length == node.Arguments.Count) .FirstOrDefault(); From b798dc3364e6810e3981b6c6c15bcee8efa15b89 Mon Sep 17 00:00:00 2001 From: Kent Boogaart Date: Thu, 10 May 2018 16:39:10 +1000 Subject: [PATCH 6/9] More fixes --- Src/PCLMock.CodeGeneration/Generator.cs | 2 +- .../Plugins/ObservableBasedAsynchrony.cs | 2 ++ .../Plugins/ObservableBasedAsynchronyFixture.cs | 3 ++- .../ObservableBasedInput_CSharp.txt | 6 ++++-- .../ObservableBasedOutput_CSharp.txt | 6 ++++++ 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Src/PCLMock.CodeGeneration/Generator.cs b/Src/PCLMock.CodeGeneration/Generator.cs index 8f04722..7e51c0e 100644 --- a/Src/PCLMock.CodeGeneration/Generator.cs +++ b/Src/PCLMock.CodeGeneration/Generator.cs @@ -418,7 +418,7 @@ private static SyntaxNode GetConfigureBehaviorGeneratedForSymbol( { context .LogSink - .Warn(logSource, "Ignoring symbol '{0}' because its return type could not be determined (it's probably a sgeneric).", symbol); + .Warn(logSource, "Ignoring symbol '{0}' because its return type could not be determined (it's probably a generic).", symbol); return null; } diff --git a/Src/PCLMock.CodeGeneration/Plugins/ObservableBasedAsynchrony.cs b/Src/PCLMock.CodeGeneration/Plugins/ObservableBasedAsynchrony.cs index 50e7f46..21e9099 100644 --- a/Src/PCLMock.CodeGeneration/Plugins/ObservableBasedAsynchrony.cs +++ b/Src/PCLMock.CodeGeneration/Plugins/ObservableBasedAsynchrony.cs @@ -2,6 +2,7 @@ namespace PCLMock.CodeGeneration.Plugins { using System; using System.Linq; + using System.Reactive; using System.Reactive.Linq; using System.Reflection; using Logging; @@ -45,6 +46,7 @@ public Compilation InitializeCompilation(Compilation compilation) => compilation .AddReferences( MetadataReference.CreateFromFile(typeof(IObservable<>).GetTypeInfo().Assembly.Location), + MetadataReference.CreateFromFile(typeof(Unit).GetTypeInfo().Assembly.Location), MetadataReference.CreateFromFile(typeof(Observable).GetTypeInfo().Assembly.Location)); /// diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixture.cs b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixture.cs index 55b2248..46d2751 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixture.cs +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixture.cs @@ -4,6 +4,7 @@ namespace PCLMock.UnitTests.CodeGeneration.Plugins using System.Collections.Immutable; using System.IO; using System.Linq; + using System.Reactive; using System.Reactive.Linq; using System.Threading.Tasks; using Microsoft.CodeAnalysis; @@ -42,7 +43,7 @@ public async Task can_generate_mocks(string resourceBaseName, Language language) { MetadataReference.CreateFromFile(typeof(object).Assembly.Location), MetadataReference.CreateFromFile(typeof(Uri).Assembly.Location), - MetadataReference.CreateFromFile(typeof(MockBase<>).Assembly.Location) + MetadataReference.CreateFromFile(typeof(MockBase<>).Assembly.Location), }); var project = workspace.AddProject(projectInfo); workspace.AddDocument(projectId, "Source.cs", SourceText.From(inputStream)); diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedInput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedInput_CSharp.txt index 2fbaf48..bb39658 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedInput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedInput_CSharp.txt @@ -1,4 +1,5 @@ using System; +using System.Reactive; interface ICustomObservable : IObservable { @@ -27,14 +28,15 @@ interface ISomeInterface get; } - IObservable SomeMethod(); + IObservable SomeMethod(); IObservable SomeMethod(string s, int i); + IObservable SomeOtherMethod(); // expecting these to be ignored because of the type parameters IObservable SomeMethod(); IObservable SomeMethod(); // expecting these two to be ignored because of it being a custom observable (which we have no way of providing a default value for) - ICustomObservable SomeMethod(); + ICustomObservable SomeMethod(); ICustomObservable SomeMethod(string s, int i); } \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedOutput_CSharp.txt index 1b235e4..0d8175d 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedOutput_CSharp.txt @@ -22,6 +22,7 @@ namespace The.Namespace this.When(x => x[global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny()]).Return(global::System.Reactive.Linq.Observable.Empty()); this.When(x => x.SomeMethod()).Return(global::System.Reactive.Linq.Observable.Return(0)); this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Reactive.Linq.Observable.Return(null)); + this.When(x => x.SomeOtherMethod()).Return(global::System.Reactive.Linq.Observable.Return(default(global::System.Reactive.Unit))); } private void ConfigureLooseBehaviorGenerated() @@ -64,6 +65,11 @@ namespace The.Namespace return this.Apply(x => x.SomeMethod(s, i)); } + public global::System.IObservable SomeOtherMethod() + { + return this.Apply(x => x.SomeOtherMethod()); + } + public global::System.IObservable SomeMethod() { return this.Apply(x => x.SomeMethod()); From bd4f909322d91c4731bec6566dffc4949f16469c Mon Sep 17 00:00:00 2001 From: Kent Boogaart Date: Thu, 24 May 2018 10:05:57 +1000 Subject: [PATCH 7/9] Upgrade to latest Roslyn --- Src/PCLMock.CodeGeneration/PCLMock.CodeGeneration.csproj | 4 ++-- Src/PCLMock.UnitTests/PCLMock.UnitTests.csproj | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Src/PCLMock.CodeGeneration/PCLMock.CodeGeneration.csproj b/Src/PCLMock.CodeGeneration/PCLMock.CodeGeneration.csproj index ccf4378..e595f64 100644 --- a/Src/PCLMock.CodeGeneration/PCLMock.CodeGeneration.csproj +++ b/Src/PCLMock.CodeGeneration/PCLMock.CodeGeneration.csproj @@ -10,8 +10,8 @@ - - + + diff --git a/Src/PCLMock.UnitTests/PCLMock.UnitTests.csproj b/Src/PCLMock.UnitTests/PCLMock.UnitTests.csproj index 39ada30..bd1b582 100644 --- a/Src/PCLMock.UnitTests/PCLMock.UnitTests.csproj +++ b/Src/PCLMock.UnitTests/PCLMock.UnitTests.csproj @@ -29,8 +29,8 @@ - - + + From c63cf1451e184b379761a8433d601382494e0ea1 Mon Sep 17 00:00:00 2001 From: Kent Boogaart Date: Thu, 24 May 2018 10:27:43 +1000 Subject: [PATCH 8/9] Use Directory.Build.targets for package references --- Src/Directory.Build.targets | 15 +++++++++++++++ .../PCLMock.CodeGeneration.Console.csproj | 8 ++++---- .../PCLMock.CodeGeneration.csproj | 12 ++++++------ Src/PCLMock.UnitTests/PCLMock.UnitTests.csproj | 8 ++++---- Src/PCLMock.sln | 9 +++++++-- 5 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 Src/Directory.Build.targets diff --git a/Src/Directory.Build.targets b/Src/Directory.Build.targets new file mode 100644 index 0000000..1cad576 --- /dev/null +++ b/Src/Directory.Build.targets @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration.Console/PCLMock.CodeGeneration.Console.csproj b/Src/PCLMock.CodeGeneration.Console/PCLMock.CodeGeneration.Console.csproj index 8482805..caa311a 100644 --- a/Src/PCLMock.CodeGeneration.Console/PCLMock.CodeGeneration.Console.csproj +++ b/Src/PCLMock.CodeGeneration.Console/PCLMock.CodeGeneration.Console.csproj @@ -1,4 +1,4 @@ - + Exe @@ -7,9 +7,9 @@ - - - + + + diff --git a/Src/PCLMock.CodeGeneration/PCLMock.CodeGeneration.csproj b/Src/PCLMock.CodeGeneration/PCLMock.CodeGeneration.csproj index e595f64..63473d9 100644 --- a/Src/PCLMock.CodeGeneration/PCLMock.CodeGeneration.csproj +++ b/Src/PCLMock.CodeGeneration/PCLMock.CodeGeneration.csproj @@ -6,12 +6,12 @@ - - - - - - + + + + + + diff --git a/Src/PCLMock.UnitTests/PCLMock.UnitTests.csproj b/Src/PCLMock.UnitTests/PCLMock.UnitTests.csproj index bd1b582..f996ed3 100644 --- a/Src/PCLMock.UnitTests/PCLMock.UnitTests.csproj +++ b/Src/PCLMock.UnitTests/PCLMock.UnitTests.csproj @@ -29,10 +29,10 @@ - - - - + + + + diff --git a/Src/PCLMock.sln b/Src/PCLMock.sln index 403f23f..017d75d 100644 --- a/Src/PCLMock.sln +++ b/Src/PCLMock.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.27004.2002 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PCLMock.UnitTests", "PCLMock.UnitTests\PCLMock.UnitTests.csproj", "{05115055-0BBC-49D5-8966-2B90325F2F08}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PCLMock.UnitTests", "PCLMock.UnitTests\PCLMock.UnitTests.csproj", "{05115055-0BBC-49D5-8966-2B90325F2F08}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".build", ".build", "{A1B3C179-EFB2-437F-A9FF-16BD29DE2292}" ProjectSection(SolutionItems) = preProject @@ -13,12 +13,17 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".build", ".build", "{A1B3C1 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PCLMock.CodeGeneration.T4", "PCLMock.CodeGeneration.T4\PCLMock.CodeGeneration.T4.csproj", "{F482A52C-3D60-429D-9152-3FFB5D35CBFF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PCLMock.CodeGeneration.Console", "PCLMock.CodeGeneration.Console\PCLMock.CodeGeneration.Console.csproj", "{B56824C1-B58E-42FB-A528-518638A7DA15}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PCLMock.CodeGeneration.Console", "PCLMock.CodeGeneration.Console\PCLMock.CodeGeneration.Console.csproj", "{B56824C1-B58E-42FB-A528-518638A7DA15}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PCLMock.CodeGeneration", "PCLMock.CodeGeneration\PCLMock.CodeGeneration.csproj", "{49C812A9-5C76-4567-947F-B21A38FE4EC1}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PCLMock", "PCLMock\PCLMock.csproj", "{2F34337F-05B9-4B38-A072-46409A3B2ACE}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CB18F837-B055-41A5-A411-0D02C18702D8}" + ProjectSection(SolutionItems) = preProject + Directory.Build.targets = Directory.Build.targets + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU From 79d6ef3ea1a04180e40b6983351fd3c02fba0de3 Mon Sep 17 00:00:00 2001 From: Kent Boogaart Date: Thu, 14 May 2020 20:19:52 +1000 Subject: [PATCH 9/9] Target .NET Standard, add C# source generator and .NET Core tool --- .gitignore | 6 +- Doc/generating-mocks.md | 84 +- Doc/plugins.md | 6 +- README.md | 13 +- Src/AssemblyInfoCommon.cs | 14 - Src/Directory.Build.targets | 37 +- Src/PCLMock.CodeGeneration.Console.nuspec | 19 - .../ConsoleLogSink.cs | 53 - .../Logging/ConsoleLogSink.cs | 33 + .../Logging/LogSinkLogger.cs | 58 + .../Logging/LogSinkLoggerProvider.cs | 22 + .../PCLMock.CodeGeneration.Console.csproj | 35 +- Src/PCLMock.CodeGeneration.Console/Program.cs | 41 +- .../Properties/launchSettings.json | 4 +- .../packages.config | 81 - .../Logging/SourceGeneratorContextLogSink.cs | 46 + .../MockSourceGenerator.cs | 85 ++ ...Mock.CodeGeneration.SourceGenerator.csproj | 38 + Src/PCLMock.CodeGeneration.T4.nuspec | 19 - Src/PCLMock.CodeGeneration.T4/Mocks.tt | 157 -- Src/PCLMock.CodeGeneration.T4/Mocks.xml | 70 - .../PCLMock.CodeGeneration.T4.csproj | 139 -- ...CLMock.CodeGeneration.T4.v3.ncrunchproject | 5 - .../Properties/AssemblyInfo.cs | 8 - Src/PCLMock.CodeGeneration.T4/app.config | 31 - Src/PCLMock.CodeGeneration.T4/packages.config | 29 - Src/PCLMock.CodeGeneration.nuspec | 19 - Src/PCLMock.CodeGeneration/Context.cs | 17 + Src/PCLMock.CodeGeneration/Extensions.cs | 100 ++ Src/PCLMock.CodeGeneration/Generator.cs | 418 ++++-- Src/PCLMock.CodeGeneration/IPlugin.cs | 22 +- .../Logging/BuildalyzerLogFactory.cs | 68 - .../Logging/ILogSink.cs | 9 +- .../Logging/LogEvent.cs | 52 + .../Logging/LogLevel.cs | 11 +- .../Logging/LogSinkExtensions.cs | 150 +- .../Logging/NullLogSink.cs | 6 +- .../Logging/StringLogSink.cs | 13 +- .../Models/Configuration.cs | 105 +- .../PCLMock.CodeGeneration.csproj | 9 +- .../Plugins/Collections.cs | 223 ++- Src/PCLMock.CodeGeneration/Plugins/Default.cs | 62 + .../Plugins/Disposables.cs | 48 +- .../Plugins/ObservableBasedAsynchrony.cs | 86 +- .../Plugins/TaskBasedAsynchrony.cs | 91 +- .../XmlBasedGenerator.cs | 48 +- .../CodeGeneration/GeneratorFixture.cs | 65 +- .../DuplicateMemberInput_CSharp.txt | 4 +- .../DuplicateMemberOutput_CSharp.txt | 127 +- .../GenericInterfaceOutput_CSharp.txt | 21 +- .../IndexersOutput_CSharp.txt | 28 +- .../InheritingInterfaceOutput_CSharp.txt | 23 +- ...nterfaceWithGenericMethodsInput_CSharp.txt | 4 +- ...terfaceWithGenericMethodsOutput_CSharp.txt | 23 +- .../InternalInterfaceOutput_CSharp.txt | 25 +- .../NameClashInput_CSharp.txt | 4 +- .../NameClashOutput_CSharp.txt | 22 +- .../NonMockableMembersOutput_CSharp.txt | 22 +- .../OutAndRefOutput_CSharp.txt | 21 +- .../PartialInterfaceOutput_CSharp.txt | 23 +- .../SimpleInterfaceOutput_CSharp.txt | 25 +- .../Plugins/CollectionsFixture.cs | 85 +- .../CollectionsInput_CSharp.txt | 16 +- .../CollectionsOutput_CSharp.txt | 49 +- .../DictionariesInput_CSharp.txt | 16 +- .../DictionariesOutput_CSharp.txt | 57 +- .../EnumerablesInput_CSharp.txt | 16 +- .../EnumerablesOutput_CSharp.txt | 44 +- .../ImmutableDictionariesInput_CSharp.txt | 17 +- .../ImmutableDictionariesOutput_CSharp.txt | 101 +- .../ImmutableListsInput_CSharp.txt | 19 +- .../ImmutableListsOutput_CSharp.txt | 87 +- .../ImmutableQueuesInput_CSharp.txt | 19 +- .../ImmutableQueuesOutput_CSharp.txt | 53 +- .../ImmutableSetsInput_CSharp.txt | 19 +- .../ImmutableSetsOutput_CSharp.txt | 69 +- .../ImmutableStacksInput_CSharp.txt | 19 +- .../ImmutableStacksOutput_CSharp.txt | 53 +- .../ListsInput_CSharp.txt | 16 +- .../ListsOutput_CSharp.txt | 55 +- .../RecursiveInput_CSharp.txt | 1 - .../RecursiveOutput_CSharp.txt | 9 +- .../SetsInput_CSharp.txt | 16 +- .../SetsOutput_CSharp.txt | 61 +- .../CodeGeneration/Plugins/DefaultFixture.cs | 23 + .../SimpleInput_CSharp.txt | 18 + .../SimpleOutput_CSharp.txt | 66 + .../Plugins/DisposablesFixture.cs | 74 +- .../DisposablesInput_CSharp.txt | 4 +- .../DisposablesOutput_CSharp.txt | 58 +- .../ObservableBasedAsynchronyFixture.cs | 73 +- .../GenericInterfaceOutput_CSharp.txt | 21 +- .../NonObservableBasedInput_CSharp.txt | 21 +- .../NonObservableBasedOutput_CSharp.txt | 45 +- .../ObservableBasedInput_CSharp.txt | 21 +- .../ObservableBasedOutput_CSharp.txt | 76 +- .../RecursiveOutput_CSharp.txt | 21 +- .../Plugins/TaskBasedAsynchronyFixture.cs | 72 +- .../GenericInterfaceOutput_CSharp.txt | 23 +- .../GenericTaskInput_CSharp.txt | 19 +- .../GenericTaskOutput_CSharp.txt | 39 +- .../NonGenericTaskInput_CSharp.txt | 19 +- .../NonGenericTaskOutput_CSharp.txt | 39 +- .../NonTaskBasedInput_CSharp.txt | 21 +- .../NonTaskBasedOutput_CSharp.txt | 45 +- .../RecursiveOutput_CSharp.txt | 21 +- Src/PCLMock.UnitTests/Helpers.cs | 159 ++ .../PCLMock.UnitTests.csproj | 18 +- .../IsAnyArgumentFilterFixture.cs | 59 - .../IsArgumentFilterFixture.cs | 61 - .../IsBetweenArgumentFilterFixture.cs | 85 -- .../IsGreaterThanArgumentFilterFixture.cs | 62 - ...eaterThanOrEqualToArgumentFilterFixture.cs | 62 - .../IsInArgumentFilterFixture.cs | 66 - .../IsLikeArgumentFilterFixture.cs | 50 - .../IsNullArgumentFilterFixture.cs | 44 - .../IsOfTypeArgumentFilterFixture.cs | 45 - .../LogicalNotArgumentFilterFixture.cs | 41 - .../MatchesArgumentFilterFixture.cs | 57 - .../CodeGeneration/GeneratorFixture.cs | 91 -- .../DuplicateMemberInput_CSharp.txt | 29 - .../DuplicateMemberOutput_CSharp.txt | 38 - .../GenericInterfaceInput_CSharp.txt | 14 - .../GenericInterfaceOutput_CSharp.txt | 46 - .../IndexersInput_CSharp.txt | 18 - .../IndexersOutput_CSharp.txt | 57 - .../InheritingInterfaceInput_CSharp.txt | 9 - .../InheritingInterfaceOutput_CSharp.txt | 41 - ...nterfaceWithGenericMethodsInput_CSharp.txt | 14 - ...terfaceWithGenericMethodsOutput_CSharp.txt | 53 - .../InternalInterfaceInput_CSharp.txt | 26 - .../InternalInterfaceOutput_CSharp.txt | 69 - .../NameClashInput_CSharp.txt | 16 - .../NameClashOutput_CSharp.txt | 58 - .../NonMockableMembersInput_CSharp.txt | 13 - .../NonMockableMembersOutput_CSharp.txt | 41 - .../OutAndRefInput_CSharp.txt | 12 - .../OutAndRefOutput_CSharp.txt | 67 - .../PartialInterfaceInput_CSharp.txt | 15 - .../PartialInterfaceOutput_CSharp.txt | 44 - .../SimpleInterfaceInput_CSharp.txt | 26 - .../SimpleInterfaceInput_VisualBasic.txt | 16 - .../SimpleInterfaceOutput_CSharp.txt | 69 - .../SimpleInterfaceOutput_VisualBasic.txt | 60 - .../Models/ConfigurationFixture.cs | 46 - .../ConfigurationFixtureResources/Input.txt | 96 -- .../Plugins/CollectionsFixture.cs | 102 -- .../CollectionsInput_CSharp.txt | 52 - .../CollectionsOutput_CSharp.txt | 217 --- .../DictionariesInput_CSharp.txt | 52 - .../DictionariesOutput_CSharp.txt | 265 ---- .../EnumerablesInput_CSharp.txt | 47 - .../EnumerablesOutput_CSharp.txt | 172 --- .../ImmutableDictionariesInput_CSharp.txt | 47 - .../ImmutableDictionariesOutput_CSharp.txt | 216 --- .../ImmutableListsInput_CSharp.txt | 47 - .../ImmutableListsOutput_CSharp.txt | 244 --- .../ImmutableQueuesInput_CSharp.txt | 47 - .../ImmutableQueuesOutput_CSharp.txt | 193 --- .../ImmutableSetsInput_CSharp.txt | 47 - .../ImmutableSetsOutput_CSharp.txt | 246 --- .../ImmutableStacksInput_CSharp.txt | 47 - .../ImmutableStacksOutput_CSharp.txt | 193 --- .../ListsInput_CSharp.txt | 52 - .../ListsOutput_CSharp.txt | 240 --- .../RecursiveInput_CSharp.txt | 10 - .../RecursiveOutput_CSharp.txt | 45 - .../SetsInput_CSharp.txt | 47 - .../SetsOutput_CSharp.txt | 258 ---- .../Plugins/DisposablesFixture.cs | 79 - .../DisposablesInput_CSharp.txt | 35 - .../DisposablesOutput_CSharp.txt | 77 - .../ObservableBasedAsynchronyFixture.cs | 82 - .../GenericInterfaceInput_CSharp.txt | 11 - .../GenericInterfaceOutput_CSharp.txt | 43 - .../NonObservableBasedInput_CSharp.txt | 34 - .../NonObservableBasedOutput_CSharp.txt | 82 - .../ObservableBasedInput_CSharp.txt | 40 - .../ObservableBasedOutput_CSharp.txt | 87 -- .../RecursiveInput_CSharp.txt | 6 - .../RecursiveOutput_CSharp.txt | 34 - .../Plugins/TaskBasedAsynchronyFixture.cs | 82 - .../GenericInterfaceInput_CSharp.txt | 11 - .../GenericInterfaceOutput_CSharp.txt | 43 - .../GenericTaskInput_CSharp.txt | 40 - .../GenericTaskOutput_CSharp.txt | 87 -- .../NonGenericTaskInput_CSharp.txt | 40 - .../NonGenericTaskOutput_CSharp.txt | 87 -- .../NonTaskBasedInput_CSharp.txt | 34 - .../NonTaskBasedOutput_CSharp.txt | 82 - .../RecursiveInput_CSharp.txt | 6 - .../RecursiveOutput_CSharp.txt | 34 - Src/PCLMock.UnitTests_OLD/Extensions.cs | 11 - Src/PCLMock.UnitTests_OLD/MockBaseFixture.cs | 1328 ----------------- .../PCLMock.UnitTests.csproj | 400 ----- .../PCLMock.UnitTests.v3.ncrunchproject | 11 - .../Properties/AssemblyInfo.cs | 6 - .../Utility/ObjectExtensionsFixture.cs | 72 - .../Visitors/ArgumentFilterVisitorFixture.cs | 87 -- .../Visitors/ArgumentFiltersVisitorFixture.cs | 67 - .../Visitors/ArgumentsVisitorFixture.cs | 59 - .../Visitors/SelectorStringVisitorFixture.cs | 101 -- .../Visitors/ValueExtractorFixture.cs | 139 -- Src/PCLMock.UnitTests_OLD/app.config | 31 - Src/PCLMock.UnitTests_OLD/packages.config | 42 - Src/PCLMock.nuspec | 19 - Src/PCLMock.sln | 40 +- Src/PCLMock/MockBase.cs | 5 +- Src/PCLMock/PCLMock.csproj | 6 + Src/PCLMock/Properties/AssemblyInfo.cs | 2 +- .../ArgumentFilters/IsAnyArgumentFilter.cs | 44 - .../ArgumentFilters/IsArgumentFilter.cs | 45 - .../IsBetweenArgumentFilter.cs | 66 - .../IsGreaterThanArgumentFilter.cs | 53 - .../IsGreaterThanOrEqualToArgumentFilter.cs | 53 - .../ArgumentFilters/IsInArgumentFilter.cs | 79 - .../ArgumentFilters/IsLikeArgumentFilter.cs | 56 - .../ArgumentFilters/IsNullArgumentFilter.cs | 44 - .../ArgumentFilters/IsOfTypeArgumentFilter.cs | 44 - .../LogicalNotArgumentFilter.cs | 47 - .../ArgumentFilters/MatchesArgumentFilter.cs | 54 - Src/PCLMock_OLD/IArgumentFilter.cs | 7 - Src/PCLMock_OLD/It.cs | 485 ------ Src/PCLMock_OLD/MockBase.cs | 451 ------ Src/PCLMock_OLD/MockBehavior.cs | 21 - Src/PCLMock_OLD/PCLMock.csproj | 85 -- Src/PCLMock_OLD/PCLMock.v3.ncrunchproject | 11 - Src/PCLMock_OLD/Properties/AssemblyInfo.cs | 8 - .../Utility/ArgumentFilterCollection.cs | 85 -- Src/PCLMock_OLD/Utility/ContinuationKey.cs | 51 - .../Utility/ContinuationKeyType.cs | 8 - Src/PCLMock_OLD/Utility/Invocation.cs | 18 - Src/PCLMock_OLD/Utility/ObjectExtensions.cs | 142 -- .../Utility/WhenContinuationCollection.cs | 47 - Src/PCLMock_OLD/VerificationException.cs | 27 - Src/PCLMock_OLD/VerifyContinuation.cs | 182 --- .../Visitors/ArgumentFilterVisitor.cs | 98 -- .../Visitors/ArgumentFiltersVisitor.cs | 71 - Src/PCLMock_OLD/Visitors/ArgumentsVisitor.cs | 59 - .../Visitors/SelectorStringVisitor.cs | 52 - Src/PCLMock_OLD/Visitors/ValueExtractor.cs | 62 - Src/PCLMock_OLD/WhenContinuation.cs | 535 ------- Src/Rebracer.xml | 511 ------- build.bat | 4 - build.cake | 90 ++ build.fsx | 241 --- build.ps1 | 43 + build.sh | 38 + tools/packages.config | 4 + 249 files changed, 2898 insertions(+), 14327 deletions(-) delete mode 100644 Src/AssemblyInfoCommon.cs delete mode 100644 Src/PCLMock.CodeGeneration.Console.nuspec delete mode 100644 Src/PCLMock.CodeGeneration.Console/ConsoleLogSink.cs create mode 100644 Src/PCLMock.CodeGeneration.Console/Logging/ConsoleLogSink.cs create mode 100644 Src/PCLMock.CodeGeneration.Console/Logging/LogSinkLogger.cs create mode 100644 Src/PCLMock.CodeGeneration.Console/Logging/LogSinkLoggerProvider.cs delete mode 100644 Src/PCLMock.CodeGeneration.Console/packages.config create mode 100644 Src/PCLMock.CodeGeneration.SourceGenerator/Logging/SourceGeneratorContextLogSink.cs create mode 100644 Src/PCLMock.CodeGeneration.SourceGenerator/MockSourceGenerator.cs create mode 100644 Src/PCLMock.CodeGeneration.SourceGenerator/PCLMock.CodeGeneration.SourceGenerator.csproj delete mode 100644 Src/PCLMock.CodeGeneration.T4.nuspec delete mode 100644 Src/PCLMock.CodeGeneration.T4/Mocks.tt delete mode 100644 Src/PCLMock.CodeGeneration.T4/Mocks.xml delete mode 100644 Src/PCLMock.CodeGeneration.T4/PCLMock.CodeGeneration.T4.csproj delete mode 100644 Src/PCLMock.CodeGeneration.T4/PCLMock.CodeGeneration.T4.v3.ncrunchproject delete mode 100644 Src/PCLMock.CodeGeneration.T4/Properties/AssemblyInfo.cs delete mode 100644 Src/PCLMock.CodeGeneration.T4/app.config delete mode 100644 Src/PCLMock.CodeGeneration.T4/packages.config delete mode 100644 Src/PCLMock.CodeGeneration.nuspec delete mode 100644 Src/PCLMock.CodeGeneration/Logging/BuildalyzerLogFactory.cs create mode 100644 Src/PCLMock.CodeGeneration/Logging/LogEvent.cs create mode 100644 Src/PCLMock.CodeGeneration/Plugins/Default.cs create mode 100644 Src/PCLMock.UnitTests/CodeGeneration/Plugins/DefaultFixture.cs create mode 100644 Src/PCLMock.UnitTests/CodeGeneration/Plugins/DefaultFixtureResources/SimpleInput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests/CodeGeneration/Plugins/DefaultFixtureResources/SimpleOutput_CSharp.txt create mode 100644 Src/PCLMock.UnitTests/Helpers.cs delete mode 100644 Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsAnyArgumentFilterFixture.cs delete mode 100644 Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsArgumentFilterFixture.cs delete mode 100644 Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsBetweenArgumentFilterFixture.cs delete mode 100644 Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsGreaterThanArgumentFilterFixture.cs delete mode 100644 Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsGreaterThanOrEqualToArgumentFilterFixture.cs delete mode 100644 Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsInArgumentFilterFixture.cs delete mode 100644 Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsLikeArgumentFilterFixture.cs delete mode 100644 Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsNullArgumentFilterFixture.cs delete mode 100644 Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsOfTypeArgumentFilterFixture.cs delete mode 100644 Src/PCLMock.UnitTests_OLD/ArgumentFilters/LogicalNotArgumentFilterFixture.cs delete mode 100644 Src/PCLMock.UnitTests_OLD/ArgumentFilters/MatchesArgumentFilterFixture.cs delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixture.cs delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/DuplicateMemberInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/DuplicateMemberOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/GenericInterfaceInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/GenericInterfaceOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/IndexersInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/IndexersOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InheritingInterfaceInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InheritingInterfaceOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InterfaceWithGenericMethodsInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InterfaceWithGenericMethodsOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InternalInterfaceInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InternalInterfaceOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NameClashInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NameClashOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NonMockableMembersInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NonMockableMembersOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/OutAndRefInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/OutAndRefOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/PartialInterfaceInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/PartialInterfaceOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceInput_VisualBasic.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceOutput_VisualBasic.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Models/ConfigurationFixture.cs delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Models/ConfigurationFixtureResources/Input.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixture.cs delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/CollectionsInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/CollectionsOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/DictionariesInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/DictionariesOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/EnumerablesInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/EnumerablesOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableDictionariesInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableDictionariesOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableListsInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableListsOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableQueuesInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableQueuesOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableSetsInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableSetsOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableStacksInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableStacksOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ListsInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ListsOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/RecursiveInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/RecursiveOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/SetsInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/SetsOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/DisposablesFixture.cs delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/DisposablesFixtureResources/DisposablesInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/DisposablesFixtureResources/DisposablesOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixture.cs delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/GenericInterfaceInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/NonObservableBasedInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/NonObservableBasedOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/RecursiveInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixture.cs delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericInterfaceInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericTaskInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericTaskOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonGenericTaskInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonGenericTaskOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonTaskBasedInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonTaskBasedOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/RecursiveInput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt delete mode 100644 Src/PCLMock.UnitTests_OLD/Extensions.cs delete mode 100644 Src/PCLMock.UnitTests_OLD/MockBaseFixture.cs delete mode 100644 Src/PCLMock.UnitTests_OLD/PCLMock.UnitTests.csproj delete mode 100644 Src/PCLMock.UnitTests_OLD/PCLMock.UnitTests.v3.ncrunchproject delete mode 100644 Src/PCLMock.UnitTests_OLD/Properties/AssemblyInfo.cs delete mode 100644 Src/PCLMock.UnitTests_OLD/Utility/ObjectExtensionsFixture.cs delete mode 100644 Src/PCLMock.UnitTests_OLD/Visitors/ArgumentFilterVisitorFixture.cs delete mode 100644 Src/PCLMock.UnitTests_OLD/Visitors/ArgumentFiltersVisitorFixture.cs delete mode 100644 Src/PCLMock.UnitTests_OLD/Visitors/ArgumentsVisitorFixture.cs delete mode 100644 Src/PCLMock.UnitTests_OLD/Visitors/SelectorStringVisitorFixture.cs delete mode 100644 Src/PCLMock.UnitTests_OLD/Visitors/ValueExtractorFixture.cs delete mode 100644 Src/PCLMock.UnitTests_OLD/app.config delete mode 100644 Src/PCLMock.UnitTests_OLD/packages.config delete mode 100644 Src/PCLMock.nuspec delete mode 100644 Src/PCLMock_OLD/ArgumentFilters/IsAnyArgumentFilter.cs delete mode 100644 Src/PCLMock_OLD/ArgumentFilters/IsArgumentFilter.cs delete mode 100644 Src/PCLMock_OLD/ArgumentFilters/IsBetweenArgumentFilter.cs delete mode 100644 Src/PCLMock_OLD/ArgumentFilters/IsGreaterThanArgumentFilter.cs delete mode 100644 Src/PCLMock_OLD/ArgumentFilters/IsGreaterThanOrEqualToArgumentFilter.cs delete mode 100644 Src/PCLMock_OLD/ArgumentFilters/IsInArgumentFilter.cs delete mode 100644 Src/PCLMock_OLD/ArgumentFilters/IsLikeArgumentFilter.cs delete mode 100644 Src/PCLMock_OLD/ArgumentFilters/IsNullArgumentFilter.cs delete mode 100644 Src/PCLMock_OLD/ArgumentFilters/IsOfTypeArgumentFilter.cs delete mode 100644 Src/PCLMock_OLD/ArgumentFilters/LogicalNotArgumentFilter.cs delete mode 100644 Src/PCLMock_OLD/ArgumentFilters/MatchesArgumentFilter.cs delete mode 100644 Src/PCLMock_OLD/IArgumentFilter.cs delete mode 100644 Src/PCLMock_OLD/It.cs delete mode 100644 Src/PCLMock_OLD/MockBase.cs delete mode 100644 Src/PCLMock_OLD/MockBehavior.cs delete mode 100644 Src/PCLMock_OLD/PCLMock.csproj delete mode 100644 Src/PCLMock_OLD/PCLMock.v3.ncrunchproject delete mode 100644 Src/PCLMock_OLD/Properties/AssemblyInfo.cs delete mode 100644 Src/PCLMock_OLD/Utility/ArgumentFilterCollection.cs delete mode 100644 Src/PCLMock_OLD/Utility/ContinuationKey.cs delete mode 100644 Src/PCLMock_OLD/Utility/ContinuationKeyType.cs delete mode 100644 Src/PCLMock_OLD/Utility/Invocation.cs delete mode 100644 Src/PCLMock_OLD/Utility/ObjectExtensions.cs delete mode 100644 Src/PCLMock_OLD/Utility/WhenContinuationCollection.cs delete mode 100644 Src/PCLMock_OLD/VerificationException.cs delete mode 100644 Src/PCLMock_OLD/VerifyContinuation.cs delete mode 100644 Src/PCLMock_OLD/Visitors/ArgumentFilterVisitor.cs delete mode 100644 Src/PCLMock_OLD/Visitors/ArgumentFiltersVisitor.cs delete mode 100644 Src/PCLMock_OLD/Visitors/ArgumentsVisitor.cs delete mode 100644 Src/PCLMock_OLD/Visitors/SelectorStringVisitor.cs delete mode 100644 Src/PCLMock_OLD/Visitors/ValueExtractor.cs delete mode 100644 Src/PCLMock_OLD/WhenContinuation.cs delete mode 100644 Src/Rebracer.xml delete mode 100644 build.bat create mode 100644 build.cake delete mode 100644 build.fsx create mode 100644 build.ps1 create mode 100644 build.sh create mode 100644 tools/packages.config diff --git a/.gitignore b/.gitignore index d823299..d9973f2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ *.suo *.user *.sln.docstates +.ionide/ # Build results @@ -16,8 +17,9 @@ build/ [Oo]bj/ Gen/ -# FAKE -.fake +# Cake +tools/** +!tools/packages.config # Visual Studio 2015 cache/options directory .vs/ diff --git a/Doc/generating-mocks.md b/Doc/generating-mocks.md index d594c56..212a58a 100644 --- a/Doc/generating-mocks.md +++ b/Doc/generating-mocks.md @@ -2,16 +2,16 @@ ## Overview -**PCLMock** includes support for generating mock implementations from interfaces in your code base. Generated code can be either C# or Visual Basic. You have two code generation options: +**PCLMock** includes support for generating mock implementations from interfaces in your code base. The core of this code generation logic is contained in the `PCLMock.CodeGeneration` project, but you will typically use that library via a code generator "front-end". There are two code generator front-ends that ship with PCLMock: -1. A T4-based approach, available via the `PCLMock.CodeGeneration.T4` package. -2. A console-based approach, available via the `PCLMock.CodeGeneration.Console` package. +1. A [C# Source Generator](https://devblogs.microsoft.com/dotnet/introducing-c-source-generators/) (currently in preview, intended to ship with C# 9). +2. A [.NET Core tool](https://docs.microsoft.com/en-us/dotnet/core/tools/global-tools), available via the `PCLMock.CodeGeneration.Console` package. -The T4-based approach integrates into Visual Studio (Xamarin Studio is not currently supported) whereas the console-based approach is a solution-level tool that you can execute how you see fit. In both cases, these tools are driven by an XML configuration file. +In both cases, these tools are driven by an XML configuration file. -## Configuration File +## XML Configuration File -In order to know which interfaces should have mocks generated, and how those mocks should be named, the **PCLMock** code generators rely on an XML configuration file. When you install the T4-based code generator, you get a default configuration file called *Mocks.xml*. +In order to know which interfaces should have mocks generated, and how those mocks should be named, the **PCLMock** code generators rely on an XML configuration file. ### Specifying Namespace Names @@ -75,7 +75,7 @@ Each filter must be either an `Include` or `Exclude` element. In either case, th .*, MyAssembly -``` +``` A more complicated filter arrangement might look like this: @@ -107,35 +107,47 @@ You can read all about plugins [here](plugins.md). To configure plugins, you spe You can include any number of plugins and they will be executed in the order you specify. This is important if more than one plugin might produce specifications for the same member. You should identify which plugin's specifications should take precedence and list it after the other plugins. -## T4-based Generation - -If you're using the T4-based generation approach, you will want to add the `PCLMock.CodeGeneration.T4` package to the project in which your mocks should reside. This is probably your unit test project. +## Generator Front-ends -Once added, you will see two new files in the root of your project: +### Source Generator -* *Mocks.tt* -* *Mocks.xml* +To use the source generator front-end, follow these steps: -*Mocks.xml* is the configuration file discussed above. *Mocks.tt* is the text template that instigates generation of the mocks. If you add a new interface or modify your configuration file, you should right-click *Mocks.tt* and select **Run Custom Tool** in order to re-generate mocks. +1. Use [.NET 5 preview](https://dotnet.microsoft.com/download/dotnet/5.0) and C# 9 preview. +2. Include all relevant PCLMock projects in your solution: `PCLMock`, `PCLMock.CodeGeneration`, and `PCLMock.CodeGeneration.SourceGenerator`. NOTE: this step is only required while source generators are in early preview because the .NET team have not yet provided a mechanism to consume source generators from NuGet packages. Longer term, you won't have to bundle the code. +3. Add a configuration file to your project called `PCLMock.xml` and include it as an additional file: + ```xml + + + + ``` +4. Include the source generator (this step will simplify once source generators can be consumed from a NuGet): + ```xml + + + + ``` -To change the language of the generated code, open *Mocks.tt* and modify the `language` variable as specified in the comments. +One limitation of using source generators (besides the fact that they're in preview) is that source generators can only augment code in the compiling project. This means that generated mocks _must_ reside in the same project as the code being mocked, rather than being incorporated into a separate project (usually a unit tests project). One mitigation would be to add a `Condition` to the `Analyzer` such that it is only included for certain builds where mocks are required, but not for builds intended for deployment. -## Console-based Generation +### .NET Core tool -The `PCLMock.CodeGeneration.Console` package can be added to any project because it is actually a solution-level package. This means no particular project will "own" this package but, rather, the solution will. +To install the PCLMock .NET Core tool globally: -Once added, you'll find an executable called *PCLMockCodeGen.exe* within your solution's *packages\PCLMock.CodeGeneration.Console.$version$\tools* directory. Execution of this tool requires these parameters: +``` +dotnet tool install -g pclmock +``` -* The path of the solution for which mocks are being generated -* The path of the XML configuration file -* The path of the output file which will contain the generated code +You can then execute it with: -You can also optionally force the language of the generated code, although it is inferred from the output file's extension. In addition, to can execute with a `-Verbose` flag gain insight into the decisions PCLMock is making during code generation. +``` +pclmock +``` -An example of executing this tool is: +See the console output for help, but an example of executing this tool is: ``` -.\PCLMockCodeGen.exe "Path\To\MySolution.sln" "Path\To\Mocks.xml" "output.cs" -Verbose +pclmock "Path\To\MySolution.sln" "Path\To\PCLMock.xml" "output.cs" -Verbose ``` ## Supplementing Generated Code @@ -170,7 +182,7 @@ namespace Foo.Bar.Mocks ## Supported Members -The code generator supports everything that **PCLMock** itself supports: +The code generator (regardless of which front-end is used) supports everything that **PCLMock** itself supports: * `get`-only properties * `set`-only properties @@ -183,24 +195,4 @@ The code generator supports everything that **PCLMock** itself supports: * generic interfaces (including type constraints) * generic methods (including type constraints) -If the code generator comes across something the **PCLMock** [doesn't inherently support](defining-mocks.md#limitations), it will just ignore it. You can then supplement the generated partial class so that the mock successfully builds. - -A caveat to this is that duplicate members will be ignored, even if each is supported individually. For example: - -```C# -public interface IFirst -{ - void SomeMethod(); -} - -public interface ISecond -{ - void SomeMethod(); -} - -public interface IThird : IFirst, ISecond -{ -} -``` - -Here, the generated mock for `IThird` will _not_ include a `SomeMethod` implementation. This is because doing so would require either a single implementation, or multiple with one or more implemented explicitly. Either of these two options might result in a mock that is less useful to you than you would like, so the member is simply ignored. This forces you to provide the implementation yourself via a partial class, but affords you the flexibility to choose what that implementation looks like. \ No newline at end of file +If the code generator comes across something the **PCLMock** [doesn't inherently support](defining-mocks.md#limitations), it will just ignore it. You can then supplement the generated partial class so that the mock successfully builds. \ No newline at end of file diff --git a/Doc/plugins.md b/Doc/plugins.md index c774e07..28b0c02 100644 --- a/Doc/plugins.md +++ b/Doc/plugins.md @@ -4,13 +4,13 @@ PCLMock's code generator includes support for plugins. These are implementations of `PCLMock.CodeGeneration.IPlugin`. Plugins are able to participate in the code generation process, generating specifications for the target mock. -PCLMock itself comes with several plugins, discussed below. They are enabled by default, but you can always disable them or replace them with your own. +PCLMock itself comes with several plugins, discussed below. Plugins are not enabled by default (apart from an internal `Default` plugin, which is always enabled), so you'll need to ensure you add them to your configuration. ## The `IPlugin` Interface Plugins must implement the `PCLMock.CodeGeneration.IPlugin` interface. If you're writing your own plugin, you can get this interface by adding the `PCLMock.CodeGeneration` NuGet package. -The `IPlugin` interface defines members that allow you to generate code that applies to all mock instances, or only loose mocks. In either case, you need to return an instance of `Microsoft.CodeAnalysis.SyntaxNode` containing the code you wish to inject into the mock. +The `IPlugin` interface defines members that allow you to generate default values for specific types. Plugins are applied recursively, such that separate plugins can collaborate to provide a default value for complex generic types, such as `Task>`. ## Built-in Plugins @@ -140,4 +140,4 @@ This plugin can be configured thusly: Its purpose is to ensure that any method or property returning `IDisposable` will return `System.Reactive.Disposables.Disposable.Empty` by default. This ensures that consuming code can dispose of the returned value without triggering a `NullReferenceException`. -Naturally, if the target code does not include a reference to _System.Reactive.Core.dll_ then no specification will be generated. +Naturally, if the target code does not include a reference to _System.Reactive.Core.dll_ then no specification will be generated. diff --git a/README.md b/README.md index 58c2832..7aa2f89 100644 --- a/README.md +++ b/README.md @@ -5,19 +5,12 @@ [![Build status](https://ci.appveyor.com/api/projects/status/wj9tyg3m99jogmqw?svg=true)](https://ci.appveyor.com/project/kentcb/pclmock) ## What? - -**PCLMock** is a simple mocking framework in a Portable Class Library. The PCL targets a wide range of platforms including: -* .NET 4.5 -* Windows 8 -* Windows Store -* Windows Phone 8 -* Xamarin iOS -* Xamarin Android +**PCLMock** is a lightweight, but powerful mocking framework targeting .NET Standard 1.0 (it was originally a Portable Class Library, hence the name). ## Why? -Existing mocking frameworks, such as [Moq](https://github.com/Moq/moq4), do not work on platforms running a limited subset of the .NET framework. Writing mocks without the aid of a framework is laborious, error-prone, and results in inconsistent code. **PCLMock** aims to reduce this pain. +At the time of inception, existing mocking frameworks (such as [Moq](https://github.com/Moq/moq4)) rely heavily on reflection and other mechanisms that are not available on more limited .NET runtimes, such as Mono. Writing mocks without the aid of a framework is laborious, error-prone, and results in inconsistent code. **PCLMock** aims to fill this gap. ## Where? @@ -47,7 +40,7 @@ public void some_test() var sut = new Foo(mockService); // some test code here - + mockService .Verify(x => x.Login("me", "123456")) .WasNotCalled(); diff --git a/Src/AssemblyInfoCommon.cs b/Src/AssemblyInfoCommon.cs deleted file mode 100644 index 27f36c2..0000000 --- a/Src/AssemblyInfoCommon.cs +++ /dev/null @@ -1,14 +0,0 @@ -// -using System.Reflection; -using System.Resources; - -[assembly: AssemblyVersionAttribute("5.0.1.0")] -[assembly: AssemblyFileVersionAttribute("5.0.1.0")] -[assembly: AssemblyConfigurationAttribute("Release")] -[assembly: AssemblyCompanyAttribute("Kent Boogaart")] -[assembly: AssemblyProductAttribute("PCLMock")] -[assembly: AssemblyCopyrightAttribute("© Copyright. Kent Boogaart.")] -[assembly: AssemblyTrademarkAttribute("")] -[assembly: AssemblyCultureAttribute("")] -[assembly: NeutralResourcesLanguageAttribute("en-US")] -[assembly: AssemblyInformationalVersionAttribute("5.0.1-alpha")] diff --git a/Src/Directory.Build.targets b/Src/Directory.Build.targets index 1cad576..a481704 100644 --- a/Src/Directory.Build.targets +++ b/Src/Directory.Build.targets @@ -1,15 +1,30 @@ - - - - - - - - - - - + + Kent Boogaart + + https://github.com/kentcb/PCLMock/blob/master/LICENSE + https://github.com/kentcb/PCLMock + Logo64x64.png + https://github.com/kentcb/PCLMock + .NET mono portable pcl mocking ios android xamarin + PCLMock is mocking framework in a PCL, making it usable on platforms such as iOS and Android. + false + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration.Console.nuspec b/Src/PCLMock.CodeGeneration.Console.nuspec deleted file mode 100644 index 837c86a..0000000 --- a/Src/PCLMock.CodeGeneration.Console.nuspec +++ /dev/null @@ -1,19 +0,0 @@ - - - - PCLMock.CodeGeneration.Console - @build.number@ - Kent Boogaart - Kent Boogaart - https://github.com/kentcb/PCLMock/blob/master/LICENSE - https://github.com/kentcb/PCLMock - https://raw.githubusercontent.com/kentcb/PCLMock/master/Art/Logo64x64.png - false - - A console-based code generation tool for PCLMock. This is a solution-level package. - - .NET mocking codegen console - @dependencies@ - @references@ - - \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration.Console/ConsoleLogSink.cs b/Src/PCLMock.CodeGeneration.Console/ConsoleLogSink.cs deleted file mode 100644 index 5deef42..0000000 --- a/Src/PCLMock.CodeGeneration.Console/ConsoleLogSink.cs +++ /dev/null @@ -1,53 +0,0 @@ -namespace PCLMock.CodeGeneration.Console -{ - using System; - using PCLMock.CodeGeneration.Logging; - - public sealed class ConsoleLogSink : ILogSink - { - public static readonly ConsoleLogSink Instance = new ConsoleLogSink(); - - private ConsoleLogSink() - { - } - - public bool IsEnabled => true; - - public void Log(Type source, LogLevel level, string message) - { - var currentColor = Console.ForegroundColor; - ConsoleColor color; - - switch (level) - { - case LogLevel.Debug: - color = ConsoleColor.Gray; - break; - case LogLevel.Info: - color = ConsoleColor.White; - break; - case LogLevel.Warn: - color = ConsoleColor.DarkYellow; - break; - case LogLevel.Negative: - color = ConsoleColor.Yellow; - break; - case LogLevel.Positive: - color = ConsoleColor.Green; - break; - case LogLevel.Error: - color = ConsoleColor.Red; - break; - default: - throw new InvalidOperationException(); - } - - Console.ForegroundColor = color; - Console.Write("["); - Console.Write(source.FullName); - Console.Write("] "); - Console.WriteLine(message); - Console.ForegroundColor = currentColor; - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration.Console/Logging/ConsoleLogSink.cs b/Src/PCLMock.CodeGeneration.Console/Logging/ConsoleLogSink.cs new file mode 100644 index 0000000..fe9dab8 --- /dev/null +++ b/Src/PCLMock.CodeGeneration.Console/Logging/ConsoleLogSink.cs @@ -0,0 +1,33 @@ +namespace PCLMock.CodeGeneration.Console.Logging +{ + using System; + using PCLMock.CodeGeneration.Logging; + + public sealed class ConsoleLogSink : ILogSink + { + public static readonly ConsoleLogSink Instance = new ConsoleLogSink(); + + private ConsoleLogSink() + { + } + + public void Log(LogEvent logEvent) + { + var currentColor = Console.ForegroundColor; + var color = logEvent.Level switch + { + LogLevel.Info => ConsoleColor.White, + LogLevel.Warn => ConsoleColor.DarkYellow, + LogLevel.Error => ConsoleColor.Red, + _ => ConsoleColor.Gray + }; + + Console.ForegroundColor = color; + Console.Write("["); + Console.Write(logEvent.Source ?? "<>"); + Console.Write("] "); + Console.WriteLine(logEvent.FormattedMessage); + Console.ForegroundColor = currentColor; + } + } +} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration.Console/Logging/LogSinkLogger.cs b/Src/PCLMock.CodeGeneration.Console/Logging/LogSinkLogger.cs new file mode 100644 index 0000000..801941a --- /dev/null +++ b/Src/PCLMock.CodeGeneration.Console/Logging/LogSinkLogger.cs @@ -0,0 +1,58 @@ +namespace PCLMock.CodeGeneration.Console.Logging +{ + using System; + using System.Reactive.Disposables; + using MS = Microsoft.Extensions.Logging; + using PCLMock.CodeGeneration.Logging; + + public sealed class LogSinkLogger : MS.ILogger + { + private readonly ILogSink logSink; + + public LogSinkLogger(ILogSink logSink) + { + this.logSink = logSink; + } + + public IDisposable BeginScope(TState state) => Disposable.Empty; + + public bool IsEnabled(MS.LogLevel logLevel) => true; + + public void Log( + MS.LogLevel logLevel, + MS.EventId eventId, + TState state, + Exception exception, + Func formatter) + { + if (logLevel == MS.LogLevel.Trace) + { + return; + } + + var message = formatter(state, exception); + + // Very annoyingly, MSBuild appends new lines onto messages itself. + if (message.EndsWith("\r\n")) + { + message = message.Substring(0, message.Length - 2); + } + + switch (logLevel) + { + case MS.LogLevel.Debug: + logSink.Debug(message); + break; + case MS.LogLevel.Information: + logSink.Info(message); + break; + case MS.LogLevel.Warning: + logSink.Warn(message); + break; + default: + logSink.Error(message); + break; + } + } + } +} diff --git a/Src/PCLMock.CodeGeneration.Console/Logging/LogSinkLoggerProvider.cs b/Src/PCLMock.CodeGeneration.Console/Logging/LogSinkLoggerProvider.cs new file mode 100644 index 0000000..15d8d26 --- /dev/null +++ b/Src/PCLMock.CodeGeneration.Console/Logging/LogSinkLoggerProvider.cs @@ -0,0 +1,22 @@ +namespace PCLMock.CodeGeneration.Console.Logging +{ + using PCLMock.CodeGeneration.Logging; + using MS = Microsoft.Extensions.Logging; + + public sealed class LogSinkLoggerProvider : MS.ILoggerProvider + { + private readonly ILogSink logSink; + + public LogSinkLoggerProvider(ILogSink logSink) + { + this.logSink = logSink; + } + + public MS.ILogger CreateLogger(string categoryName) => + new LogSinkLogger(this.logSink.WithSource(categoryName)); + + public void Dispose() + { + } + } +} diff --git a/Src/PCLMock.CodeGeneration.Console/PCLMock.CodeGeneration.Console.csproj b/Src/PCLMock.CodeGeneration.Console/PCLMock.CodeGeneration.Console.csproj index caa311a..4c45c8f 100644 --- a/Src/PCLMock.CodeGeneration.Console/PCLMock.CodeGeneration.Console.csproj +++ b/Src/PCLMock.CodeGeneration.Console/PCLMock.CodeGeneration.Console.csproj @@ -1,19 +1,28 @@  - - Exe - netcoreapp2.0 - false - + + Exe + netcoreapp3.1 + false + true + True + true + pclmock + - - - - - + + + + + + - - - + + + + + + + \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration.Console/Program.cs b/Src/PCLMock.CodeGeneration.Console/Program.cs index 02ad5b8..dba23a6 100644 --- a/Src/PCLMock.CodeGeneration.Console/Program.cs +++ b/Src/PCLMock.CodeGeneration.Console/Program.cs @@ -1,25 +1,52 @@ namespace PCLMock.CodeGeneration.Console { using System; + using System.Collections.Immutable; using System.IO; + using System.Linq; + using System.Text; + using System.Threading.Tasks; + using Buildalyzer; + using Buildalyzer.Workspaces; using Logging; + using Microsoft.Extensions.Logging; + using PCLMock.CodeGeneration.Logging; using PowerArgs; class Program { - static int Main(string[] args) + static async Task Main(string[] args) { try { var arguments = Args.Parse(args); var language = arguments.Language.GetValueOrDefault(DetermineLanguageByOutputFileName(arguments.OutputFile)); var logSink = arguments.Verbose ? (ILogSink)ConsoleLogSink.Instance : NullLogSink.Instance; - var result = XmlBasedGenerator.GenerateMocks( + var loggerFactory = new LoggerFactory(); + loggerFactory.AddProvider(new LogSinkLoggerProvider(logSink)); + var options = new AnalyzerManagerOptions + { + LoggerFactory = loggerFactory, + }; + var manager = new AnalyzerManager(arguments.SolutionFile, options); + var workspace = manager.GetWorkspace(); + var compilationTasks = workspace + .CurrentSolution + .Projects + .Select(project => project.GetCompilationAsync()); + var compilations = await Task.WhenAll(compilationTasks); + var syntaxNodes = XmlBasedGenerator.GenerateMocks( logSink, language, - arguments.SolutionFile, + compilations.ToImmutableList(), arguments.ConfigurationFile); + var result = syntaxNodes + .Aggregate( + new StringBuilder(), + (acc, next) => acc.AppendLine(next.ToFullString()).AppendLine(), + acc => acc.ToString()); + var log = logSink.ToString(); File.WriteAllText(arguments.OutputFile, result); return 0; } @@ -37,15 +64,11 @@ static int Main(string[] args) } } - private static void WriteLine() - { + private static void WriteLine() => WriteLine(OutputType.Normal, ""); - } - private static void WriteLine(string format, params object[] args) - { + private static void WriteLine(string format, params object[] args) => WriteLine(OutputType.Normal, format, args); - } private static void WriteLine(OutputType outputType, string format, params object[] args) { diff --git a/Src/PCLMock.CodeGeneration.Console/Properties/launchSettings.json b/Src/PCLMock.CodeGeneration.Console/Properties/launchSettings.json index 8a54b78..03012c6 100644 --- a/Src/PCLMock.CodeGeneration.Console/Properties/launchSettings.json +++ b/Src/PCLMock.CodeGeneration.Console/Properties/launchSettings.json @@ -1,9 +1,7 @@ { "profiles": { "PCLMock.CodeGeneration.Console": { - "commandName": "Project", - "commandLineArgs": "-SolutionFile QUT.Core.sln -ConfigurationFile .\\UnitTests\\Mocks.xml -OutputFile .\\UnitTests\\Mocks.g.cs -Verbose true", - "workingDirectory": "C:\\Users\\kent\\Repository\\QUT\\Src" + "commandName": "Project" } } } \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration.Console/packages.config b/Src/PCLMock.CodeGeneration.Console/packages.config deleted file mode 100644 index 767e5c9..0000000 --- a/Src/PCLMock.CodeGeneration.Console/packages.config +++ /dev/null @@ -1,81 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration.SourceGenerator/Logging/SourceGeneratorContextLogSink.cs b/Src/PCLMock.CodeGeneration.SourceGenerator/Logging/SourceGeneratorContextLogSink.cs new file mode 100644 index 0000000..d72de13 --- /dev/null +++ b/Src/PCLMock.CodeGeneration.SourceGenerator/Logging/SourceGeneratorContextLogSink.cs @@ -0,0 +1,46 @@ +namespace PCLMock.CodeGeneration.SourceGenerator.Logging +{ + using Microsoft.CodeAnalysis; + using PCLMock.CodeGeneration.Logging; + + public sealed class SourceGeneratorContextLogSink : ILogSink + { +#pragma warning disable RS2008 // Enable analyzer release tracking + + private static readonly DiagnosticDescriptor diagnosticDescriptor = new DiagnosticDescriptor( + // Every log event originating from PCLMock itself will have the same ID. + id: "PM0100", + title: "PCLMock Source Generation", + messageFormat: "{0}", + category: "mocks", + defaultSeverity: DiagnosticSeverity.Error, + isEnabledByDefault: true); + +#pragma warning restore RS2008 // Enable analyzer release tracking + + private readonly SourceGeneratorContext sourceGeneratorContext; + + public SourceGeneratorContextLogSink(SourceGeneratorContext sourceGeneratorContext) + { + this.sourceGeneratorContext = sourceGeneratorContext; + } + + public void Log(LogEvent logEvent) + { + var effectiveSeverity = logEvent.Level switch + { + LogLevel.Warn => DiagnosticSeverity.Warning, + LogLevel.Error => DiagnosticSeverity.Error, + _ => DiagnosticSeverity.Info + }; + var diagnostic = Diagnostic.Create( + diagnosticDescriptor, + Location.None, + effectiveSeverity, + additionalLocations: null, + properties: null, + logEvent.FormattedMessage); + this.sourceGeneratorContext.ReportDiagnostic(diagnostic); + } + } +} diff --git a/Src/PCLMock.CodeGeneration.SourceGenerator/MockSourceGenerator.cs b/Src/PCLMock.CodeGeneration.SourceGenerator/MockSourceGenerator.cs new file mode 100644 index 0000000..b8845c3 --- /dev/null +++ b/Src/PCLMock.CodeGeneration.SourceGenerator/MockSourceGenerator.cs @@ -0,0 +1,85 @@ +namespace PCLMock.CodeGeneration.SourceGenerator +{ + using System; + using System.Collections.Immutable; + using System.IO; + using System.Linq; + using System.Text; + using Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.Text; + using PCLMock.CodeGeneration.Logging; + using PCLMock.CodeGeneration.SourceGenerator.Logging; + + [Generator] + public sealed class MockSourceGenerator : ISourceGenerator + { + public void Initialize(InitializationContext context) + { + } + + public void Execute(SourceGeneratorContext context) + { + var xmlFiles = context + .AdditionalFiles + .Where(additionalFile => Path.GetFileName(additionalFile.Path) == "PCLMock.xml") + .ToList(); + + if (xmlFiles.Count == 0) + { + ReportDiagnostic(context, "PM0001", "PM0001: No XML configuration found", "No XML configuration file named 'PCLMock.xml' was found. See the documentation for more details.", DiagnosticSeverity.Error); + return; + } + else if (xmlFiles.Count > 1) + { + ReportDiagnostic(context, "PM0002", "PM0002: Multiple XML configurations found", "Multiple XML configuration files named 'PCLMock.xml' were found where only one is expected.", DiagnosticSeverity.Error); + return; + } + + var xmlFile = xmlFiles.Single(); + + if (!File.Exists(xmlFile.Path)) + { + ReportDiagnostic(context, "PM0003", "PM0003: XML configuration file not found", "XML configuration file at '{0}' was not found.", DiagnosticSeverity.Error, xmlFile.Path); + return; + } + + var logSink = new SourceGeneratorContextLogSink(context) + .WithMinimumLevel(LogLevel.Info) + .WithSource(typeof(MockSourceGenerator)); + + try + { + var syntaxNodes = XmlBasedGenerator + .GenerateMocks( + logSink, + Language.CSharp, + ImmutableList.Create(context.Compilation), + xmlFile.Path); + var source = syntaxNodes + .Aggregate( + new StringBuilder(), + (acc, next) => acc.AppendLine(next.ToFullString()), + acc => acc.ToString()); + + context.AddSource($"PCLMock", SourceText.From(source, Encoding.UTF8)); + } + catch (Exception ex) + { + logSink.Error("Failed during mock generation: {0}", ex); + } + } + + private static void ReportDiagnostic(SourceGeneratorContext context, string id, string title, string messageFormat, DiagnosticSeverity defaultSeverity, params object[] messageArgs) + { + var diagnosticDescriptor = new DiagnosticDescriptor( + id: id, + title: title, + messageFormat: messageFormat, + category: "mocks", + defaultSeverity: defaultSeverity, + isEnabledByDefault: true); + var diagnostic = Diagnostic.Create(diagnosticDescriptor, Location.None, messageArgs); + context.ReportDiagnostic(diagnostic); + } + } +} diff --git a/Src/PCLMock.CodeGeneration.SourceGenerator/PCLMock.CodeGeneration.SourceGenerator.csproj b/Src/PCLMock.CodeGeneration.SourceGenerator/PCLMock.CodeGeneration.SourceGenerator.csproj new file mode 100644 index 0000000..473173c --- /dev/null +++ b/Src/PCLMock.CodeGeneration.SourceGenerator/PCLMock.CodeGeneration.SourceGenerator.csproj @@ -0,0 +1,38 @@ + + + + netstandard2.0 + false + true + True + 8.0 + + + true + + + + https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json ;$(RestoreAdditionalProjectSources) + + + + + + + + + + + + + + + + + + diff --git a/Src/PCLMock.CodeGeneration.T4.nuspec b/Src/PCLMock.CodeGeneration.T4.nuspec deleted file mode 100644 index 4648cd6..0000000 --- a/Src/PCLMock.CodeGeneration.T4.nuspec +++ /dev/null @@ -1,19 +0,0 @@ - - - - PCLMock.CodeGeneration.T4 - @build.number@ - Kent Boogaart - Kent Boogaart - https://github.com/kentcb/PCLMock/blob/master/LICENSE - https://github.com/kentcb/PCLMock - https://raw.githubusercontent.com/kentcb/PCLMock/master/Art/Logo64x64.png - false - - Provides T4 code generation support for PCLMock. - - .NET mocking codegen t4 - @dependencies@ - @references@ - - \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration.T4/Mocks.tt b/Src/PCLMock.CodeGeneration.T4/Mocks.tt deleted file mode 100644 index b19e420..0000000 --- a/Src/PCLMock.CodeGeneration.T4/Mocks.tt +++ /dev/null @@ -1,157 +0,0 @@ -<#@ template debug="true" hostspecific="true" language="C#" #> -<#@ CleanupBehavior processor="T4VSHost" CleanupAfterProcessingtemplate="true" #> -<#@ assembly name="System.Core" #> -<#@ assembly name="EnvDTE" #> -<#@ import namespace="System.IO" #> -<#@ import namespace="System.Linq" #> -<#@ import namespace="System.Reflection" #> -<#@ import namespace="EnvDTE" #> -<# -// set this to either "CSharp" or "VisualBasic" -var language = "CSharp"; - -// set this to true to include verbose logging output (you can find it following the generated code) -var verbose = true; - -this.SetFileExtensionForLanguage(language); -this.HookAssemblyResolution(); -var solutionPath = this.DTE.Solution.FileName; -var xmlPath = this.Host.ResolvePath("Mocks.xml"); -var xmlBasedGenerator = Type.GetType("PCLMock.CodeGeneration.XmlBasedGenerator, PCLMock.CodeGeneration"); -var logSinkType = Type.GetType("PCLMock.CodeGeneration.Logging.ILogSink, PCLMock.CodeGeneration"); -var logSinkInstance = Type.GetType("PCLMock.CodeGeneration.Logging.NullLogSink, PCLMock.CodeGeneration").GetField("Instance").GetValue(null); - -if (verbose) -{ - logSinkInstance = Activator.CreateInstance(Type.GetType("PCLMock.CodeGeneration.Logging.StringLogSink, PCLMock.CodeGeneration")); -} - -var generateMethod = xmlBasedGenerator.GetMethod("GenerateMocks", new[] { logSinkType, typeof(string), typeof(string), typeof(string) }); -var result = (string)generateMethod.Invoke(null, new[] { logSinkInstance, solutionPath, xmlPath, language }); - -this.WriteLine(result); - -if (verbose && language == "CSharp") -{ - this.WriteLine("/*"); - this.WriteLine(logSinkInstance.ToString()); - this.WriteLine("*/"); -} -#> -<#+ -private DTE dte; - -private DTE DTE -{ - get - { - if (this.dte == null) - { - var hostServiceProvider = (IServiceProvider)this.Host; - this.dte = (DTE)hostServiceProvider.GetService(typeof(DTE)); - } - - return this.dte; - } -} - -private void SetFileExtensionForLanguage(string language) -{ - switch (language) - { - case "CSharp": - this.Host.SetFileExtension(".g.cs"); - break; - case "VisualBasic": - this.Host.SetFileExtension(".g.vb"); - break; - default: - this.Host.SetFileExtension(".g"); - break; - } -} - -private void HookAssemblyResolution() -{ - var templateDirectory = Path.GetDirectoryName(this.Host.TemplateFile); - var currentDirectory = templateDirectory; - string packagesDirectory = null; - - while (Path.GetPathRoot(currentDirectory) != currentDirectory) - { - var packagesDirectories = Directory.GetDirectories(currentDirectory, "packages"); - - if (packagesDirectories.Length == 0) - { - currentDirectory = Path.GetDirectoryName(currentDirectory); - continue; - } - else if (packagesDirectories.Length > 1) - { - throw new InvalidOperationException("More than one packages directory detected - aborting."); - } - else - { - packagesDirectory = packagesDirectories[0]; - break; - } - } - - if (packagesDirectory == null) - { - throw new InvalidOperationException("Could not find packages directory relative to the template's directory (" + templateDirectory + ")."); - } - - this.Debug("packages directory: {0}", packagesDirectory); - - var packageDirectories = Directory.GetDirectories(packagesDirectory, "PCLMock.CodeGeneration.T4.*"); - - if (packageDirectories.Length == 0) - { - throw new InvalidOperationException("Could not find PCLMock.CodeGeneration.T4 package in packages directory (" + packagesDirectory + ")."); - } - else if (packageDirectories.Length > 1) - { - throw new InvalidOperationException("More than 1 version of the PCLMock.CodeGeneration.T4 package was found in the packages directory (" + packagesDirectory + "). You must choose 1 version and remove the others."); - } - - var packageDirectory = packageDirectories.First(); - this.Debug("package directory: {0}", packageDirectory); - - var assembliesDirectory = Path.Combine(packageDirectory, "tools"); - this.Debug("assemblies directory: {0}", assembliesDirectory); - - if (!Directory.Exists(assembliesDirectory)) - { - throw new InvalidOperationException("Package directory " + packageDirectory + " was found but no 'tools' subdirectory was found within."); - } - - AppDomain.CurrentDomain.AssemblyResolve += (s, e) => - { - this.Debug("resolve: {0}", e.Name); - - var matches = Directory.GetFiles(assembliesDirectory, e.Name + ".dll", SearchOption.TopDirectoryOnly); - - if (matches.Length == 0) - { - this.Debug("Failed to find assembly in assemblies directory ({0}) named '{1}'.", assembliesDirectory, e.Name); - return null; - } - else if (matches.Length > 1) - { - this.Debug("Found more than one potential match for '{0}' in assemblies directory ({0}). Bailing.", e.Name, assembliesDirectory); - return null; - } - - var match = matches.First(); - this.Debug("match: {0}", match); - - return Assembly.LoadFrom(match); - }; -} - -private void Debug(string format, params object[] args) -{ - //this.WriteLine("// " + string.Format(format, args)); -} -#> \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration.T4/Mocks.xml b/Src/PCLMock.CodeGeneration.T4/Mocks.xml deleted file mode 100644 index f3603bb..0000000 --- a/Src/PCLMock.CodeGeneration.T4/Mocks.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - - - - .+)]]> - ${name}.Mocks - - - - - - - - [A-Z].*)]]> - ${name} - - - - [A-Z].*)\<.*\>]]> - ${name} - - - - .+)]]> - ${name}Mock - - - - - - - .* - - - - - - PCLMock.CodeGeneration.Plugins.Collections, PCLMock.CodeGeneration - PCLMock.CodeGeneration.Plugins.TaskBasedAsynchrony, PCLMock.CodeGeneration - PCLMock.CodeGeneration.Plugins.ObservableBasedAsynchrony, PCLMock.CodeGeneration - PCLMock.CodeGeneration.Plugins.Disposables, PCLMock.CodeGeneration - - \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration.T4/PCLMock.CodeGeneration.T4.csproj b/Src/PCLMock.CodeGeneration.T4/PCLMock.CodeGeneration.T4.csproj deleted file mode 100644 index cb5481b..0000000 --- a/Src/PCLMock.CodeGeneration.T4/PCLMock.CodeGeneration.T4.csproj +++ /dev/null @@ -1,139 +0,0 @@ - - - - - Debug - AnyCPU - {F482A52C-3D60-429D-9152-3FFB5D35CBFF} - Library - Properties - PCLMock.CodeGeneration.T4 - PCLMock.CodeGeneration.T4 - v4.5.2 - 512 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\Microsoft.CodeAnalysis.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.dll - True - - - ..\packages\Microsoft.CodeAnalysis.CSharp.1.3.2\lib\net45\Microsoft.CodeAnalysis.CSharp.dll - True - - - ..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.1.3.2\lib\net45\Microsoft.CodeAnalysis.CSharp.Workspaces.dll - True - - - ..\packages\Microsoft.CodeAnalysis.VisualBasic.1.3.2\lib\net45\Microsoft.CodeAnalysis.VisualBasic.dll - True - - - ..\packages\Microsoft.CodeAnalysis.VisualBasic.Workspaces.1.3.2\lib\net45\Microsoft.CodeAnalysis.VisualBasic.Workspaces.dll - True - - - ..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.Workspaces.dll - True - - - ..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.Workspaces.Desktop.dll - True - - - - ..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll - True - - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.AttributedModel.dll - True - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.Convention.dll - True - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.Hosting.dll - True - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.Runtime.dll - True - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.TypedParts.dll - True - - - - ..\packages\System.Reflection.Metadata.1.4.2\lib\portable-net45+win8\System.Reflection.Metadata.dll - True - - - - - - - - - - Properties\AssemblyInfoCommon.cs - - - - - - PreserveNewest - - - Designer - PreserveNewest - - - - - - - - {6e077796-0241-4191-a866-0ea52b9bd946} - PCLMock.CodeGeneration - - - - - - - - - - - - - \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration.T4/PCLMock.CodeGeneration.T4.v3.ncrunchproject b/Src/PCLMock.CodeGeneration.T4/PCLMock.CodeGeneration.T4.v3.ncrunchproject deleted file mode 100644 index 319cd52..0000000 --- a/Src/PCLMock.CodeGeneration.T4/PCLMock.CodeGeneration.T4.v3.ncrunchproject +++ /dev/null @@ -1,5 +0,0 @@ - - - True - - \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration.T4/Properties/AssemblyInfo.cs b/Src/PCLMock.CodeGeneration.T4/Properties/AssemblyInfo.cs deleted file mode 100644 index ad6c22e..0000000 --- a/Src/PCLMock.CodeGeneration.T4/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System; -using System.Reflection; -using System.Runtime.CompilerServices; - -[assembly: AssemblyTitle("PCLMock.CodeGeneration.T4")] -[assembly: AssemblyDescription("Contains T4 code generation support for PCLMock.")] -[assembly: InternalsVisibleTo("PCLMock.CodeGeneration.T4")] -[assembly: CLSCompliantAttribute(false)] \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration.T4/app.config b/Src/PCLMock.CodeGeneration.T4/app.config deleted file mode 100644 index 0f23969..0000000 --- a/Src/PCLMock.CodeGeneration.T4/app.config +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Src/PCLMock.CodeGeneration.T4/packages.config b/Src/PCLMock.CodeGeneration.T4/packages.config deleted file mode 100644 index dc38eff..0000000 --- a/Src/PCLMock.CodeGeneration.T4/packages.config +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration.nuspec b/Src/PCLMock.CodeGeneration.nuspec deleted file mode 100644 index ac80024..0000000 --- a/Src/PCLMock.CodeGeneration.nuspec +++ /dev/null @@ -1,19 +0,0 @@ - - - - PCLMock.CodeGeneration - @build.number@ - Kent Boogaart - Kent Boogaart - https://github.com/kentcb/PCLMock/blob/master/LICENSE - https://github.com/kentcb/PCLMock - https://raw.githubusercontent.com/kentcb/PCLMock/master/Art/Logo64x64.png - false - - Contains the code generation engine and SDK for PCLMock. - - .NET mono portable pcl mocking ios android xamarin - @dependencies@ - @references@ - - \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration/Context.cs b/Src/PCLMock.CodeGeneration/Context.cs index 9a96e72..a4aa20a 100644 --- a/Src/PCLMock.CodeGeneration/Context.cs +++ b/Src/PCLMock.CodeGeneration/Context.cs @@ -72,5 +72,22 @@ public Context( /// Gets the semantic model. /// public SemanticModel SemanticModel => this.semanticModel; + + /// + /// Replaces this context's log sink with . + /// + /// + /// The new log sink. + /// + /// + /// The new context. + /// + public Context WithLogSink(ILogSink logSink) => + new Context( + logSink, + this.language, + this.plugins, + this.syntaxGenerator, + this.semanticModel); } } \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration/Extensions.cs b/Src/PCLMock.CodeGeneration/Extensions.cs index a2e57b8..5ef2575 100644 --- a/Src/PCLMock.CodeGeneration/Extensions.cs +++ b/Src/PCLMock.CodeGeneration/Extensions.cs @@ -1,6 +1,7 @@ namespace PCLMock.CodeGeneration { using System; + using System.Collections.Generic; using System.Linq; using Microsoft.CodeAnalysis; @@ -107,5 +108,104 @@ public static string GetNameForParameter(this IMethodSymbol within, IParameterSy throw new NotSupportedException("Unknown parameter ref kind: " + parameterSymbol.RefKind); } } + + /// + /// Finds all instances of a type named in all references in + /// , optionally including the containing assembly of itself. + /// + /// + /// This extension is required because the default behavior of is useless. See + /// https://github.com/dotnet/roslyn/issues/3864 for more info. + /// + /// + /// The in which to find types. + /// + /// + /// The name of the type to find. + /// + /// + /// If , searches the assembly in which is defined. + /// + /// + /// All types matching . + /// + public static IEnumerable GetTypesByMetadataName(this Compilation within, string fullyQualifiedMetadataName, bool includeSelfAssembly = false) => + within + .References + .Select(within.GetAssemblyOrModuleSymbol) + .OfType() + .Select(assemblySymbol => assemblySymbol.GetTypeByMetadataName(fullyQualifiedMetadataName)) + .Concat( + includeSelfAssembly + ? new[] { within.Assembly.GetTypeByMetadataName(fullyQualifiedMetadataName) } + : Array.Empty()) + .Where(namedType => namedType != null); + + /// + /// Gets a type named within , with the source assembly + /// defined in order of preference by . If a matching type name is found in an assembly + /// not contained in , it is still included but takes a lower precedence than types + /// in assemblies that are contained in (and an undefined precedence relative to other + /// matching types that are not). + /// + /// + /// The in which to find the type. + /// + /// + /// The fully qualified name of the type. + /// + /// + /// The assemblies in which the type must be found, in order of preference. + /// + /// + /// A , or if no matching type could be found. + /// + public static INamedTypeSymbol GetPreferredTypeByMetadataName(this Compilation within, string fullyQualifiedMetadataName, string[] preferredAssemblyNames, bool includeSelfAssembly = false) + { + var assemblyRanksByName = preferredAssemblyNames + .Select((assemblyName, index) => (rank: index, assemblyName)) + .ToDictionary(kvp => kvp.assemblyName, kvp => kvp.rank); + + var result = within + .GetTypesByMetadataName(fullyQualifiedMetadataName, includeSelfAssembly: includeSelfAssembly) + .Select( + type => + { + if (!assemblyRanksByName.TryGetValue(type.ContainingAssembly.Name, out var rank)) + { + return (rank: -1, type); + } + + return (rank, type); + }) + .OrderBy(rankedInfo => rankedInfo.rank) + .FirstOrDefault(); + + return result.type; + } + + /// + /// Do something for every item in . + /// + /// + /// The item type. + /// + /// + /// The enumerable. + /// + /// + /// The action to invoke for every item in . + /// + /// + /// An enumerable that, when materialized, invokes for every item in . + /// + public static IEnumerable Do(this IEnumerable enumerable, Action action) + { + foreach (var item in enumerable) + { + action(item); + yield return item; + } + } } } \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration/Generator.cs b/Src/PCLMock.CodeGeneration/Generator.cs index 7e51c0e..eadfac4 100644 --- a/Src/PCLMock.CodeGeneration/Generator.cs +++ b/Src/PCLMock.CodeGeneration/Generator.cs @@ -5,20 +5,15 @@ using System.Collections.Immutable; using System.Linq; using System.Reflection; - using System.Threading.Tasks; - using Buildalyzer; - using Buildalyzer.Workspaces; using Logging; - using Microsoft.Build.Framework; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editing; + using PCLMock.CodeGeneration.Plugins; public static class Generator { - private static readonly Type logSource = typeof(Generator); - private const string headerComment = @"----------------------------------------------------------------------- @@ -29,105 +24,75 @@ Changes to this file may cause incorrect behaviour and will be lost ------------------------------------------------------------------------"; - public async static Task> GenerateMocksAsync( + public static IImmutableList GenerateMocks( ILogSink logSink, Language language, - string initialPath, - Func interfacePredicate, - Func mockNamespaceSelector, - Func mockNameSelector, - IImmutableList plugins) - { - var buildalyzerLogFactory = new BuildalyzerLogFactory(logSink); - var options = new AnalyzerManagerOptions - { - CleanBeforeCompile = true, - LoggerFactory = buildalyzerLogFactory, - LoggerVerbosity = LoggerVerbosity.Detailed, - }; - var manager = new AnalyzerManager(initialPath, options); - var solution = manager.GetWorkspace().CurrentSolution; - - return await GenerateMocksAsync( - logSink, - language, - solution, - interfacePredicate, - mockNamespaceSelector, - mockNameSelector, - plugins); - } - - public async static Task> GenerateMocksAsync( - ILogSink logSink, - Language language, - Solution solution, + IImmutableList compilations, + IImmutableList plugins, Func interfacePredicate, Func mockNamespaceSelector, - Func mockNameSelector, - IImmutableList plugins) + Func mockNameSelector) { - var syntaxGenerator = SyntaxGenerator.GetGenerator(solution.Workspace, language.ToSyntaxGeneratorLanguageName()); - var compilations = await Task.WhenAll( - solution - .Projects - .Select( - async project => - { - var compilation = await project.GetCompilationAsync(); - // make sure the compilation has a reference to PCLMock - compilation = compilation.AddReferences(MetadataReference.CreateFromFile(typeof(MockBase<>).GetTypeInfo().Assembly.Location)); + logSink = logSink.WithSource(typeof(Generator)); + logSink.Debug("Creating adhoc workspace."); - foreach (var plugin in plugins) - { - compilation = plugin.InitializeCompilation(compilation); - } + var workspace = new AdhocWorkspace(); + var syntaxGenerator = SyntaxGenerator.GetGenerator(workspace, language.ToSyntaxGeneratorLanguageName()); - if (logSink.IsEnabled) - { - logSink.Debug(logSource, "Compilation generated for project '{0}' with references:", project.Name); - - foreach (var reference in compilation.References) - { - logSink.Debug(logSource, "- {0}", reference.Display); - } - } - - return compilation; - })); + // The default plugin is always included last. + plugins = plugins.Add(Default.Instance); return compilations - .SelectMany( - compilation => - GetSymbolsRecursive(compilation.SourceModule.GlobalNamespace) - .OfType() - .Where(typeSymbol => typeSymbol.TypeKind == TypeKind.Interface && !typeSymbol.IsImplicitlyDeclared) - .Where(typeSymbol => interfacePredicate == null || interfacePredicate(typeSymbol)) - .Select( - interfaceSymbol => new - { - InterfaceSymbol = interfaceSymbol, - Compilation = compilation - })) + // Make sure the compilation has a reference to PCLMock, even if the project hosting the code doesn't. That allows us + // to generate the code even if it doesn't end up building due to the missing PCLMock reference. + .Select(compilation => compilation.AddReferences(MetadataReference.CreateFromFile(typeof(MockBase<>).GetTypeInfo().Assembly.Location))) + // Then allow all plugins to tweak the compilation. + .Select(compilation => plugins.Aggregate(compilation, (acc, next) => next.InitializeCompilation(logSink, acc))) + .SelectMany(compilation => GetNamedTypeSymbolsInSource(compilation).Select(namedTypeSymbol => (compilation, namedTypeSymbol))) + .Where(compilationAndSymbol => compilationAndSymbol.namedTypeSymbol.TypeKind == TypeKind.Interface && !compilationAndSymbol.namedTypeSymbol.IsImplicitlyDeclared) + .Where(compilationAndSymbol => interfacePredicate == null || interfacePredicate(compilationAndSymbol.namedTypeSymbol)) .Select( - x => + compilationAndSymbol => { - var @namespace = mockNamespaceSelector(x.InterfaceSymbol); - var name = mockNameSelector(x.InterfaceSymbol); + var syntaxTree = compilationAndSymbol + .namedTypeSymbol + .DeclaringSyntaxReferences + .FirstOrDefault() + ?.SyntaxTree; + + // This is critical for the case of having loaded multiple projects that reference each other. TODO: would be better if GetNamedTypeSymbolsInSource + // only obtained symbols in a given compilation, but that is presenting other issues. + if (!compilationAndSymbol.compilation.ContainsSyntaxTree(syntaxTree)) + { + return (compilationAndSymbol.compilation, compilationAndSymbol.namedTypeSymbol, null); + } - if (logSink.IsEnabled) + var semanticModel = syntaxTree == null ? null : compilationAndSymbol.compilation.GetSemanticModel(syntaxTree); + + if (semanticModel == null) { - logSink.Positive( - logSource, - "Generating mock for interface '{0}' with namespace '{1}', name '{2}'.", - x.InterfaceSymbol, - @namespace, - name); + logSink.Warn( + "Cannot generate mock for included interface '{0}' because no semantic model could be obtained for it.", + compilationAndSymbol.namedTypeSymbol); } - var semanticModel = x.Compilation.GetSemanticModel(x.InterfaceSymbol.DeclaringSyntaxReferences.First().SyntaxTree); - var context = new Context(logSink, language, plugins, syntaxGenerator, semanticModel); - return GenerateMock(context, x.InterfaceSymbol, @namespace, name, plugins); + return (compilationAndSymbol.compilation, compilationAndSymbol.namedTypeSymbol, semanticModel); + }) + .Where(info => info.semanticModel != null) + .Select( + info => + { + var @namespace = mockNamespaceSelector(info.namedTypeSymbol); + var name = mockNameSelector(info.namedTypeSymbol); + + logSink.Info( + "Generating mock for interface '{0}' with namespace '{1}', name '{2}'.", + info.namedTypeSymbol, + @namespace, + name); + + var context = new Context(logSink, language, plugins, syntaxGenerator, info.semanticModel); + return GenerateMock(context, info.namedTypeSymbol, @namespace, name, plugins); }) .Select((syntaxNode, i) => i == 0 ? syntaxGenerator.WithLeadingComments(syntaxNode, headerComment, language) : syntaxNode) .ToImmutableList(); @@ -268,7 +233,6 @@ private static SyntaxNode GetConstructorDeclarationSyntax( // // if (behavior == MockBehavior.Loose) // { - // ConfigureLooseBehaviorGenerated(); // ConfigureLooseBehavior(); // } // } @@ -323,12 +287,6 @@ private static SyntaxNode GetConstructorDeclarationSyntax( .MemberAccessExpression(mockBehaviorType, "Loose")), new[] { - context - .SyntaxGenerator - .InvocationExpression( - context - .SyntaxGenerator - .IdentifierName("ConfigureLooseBehaviorGenerated")), context .SyntaxGenerator .InvocationExpression( @@ -339,40 +297,21 @@ private static SyntaxNode GetConstructorDeclarationSyntax( }); } - private static SyntaxNode GetConfigureBehaviorGeneratedSyntax( - Context context, - INamedTypeSymbol interfaceSymbol, - IImmutableList plugins, - MockBehavior behavior) - { - var statements = GetMembersRecursive(interfaceSymbol) - .Select(symbol => GetConfigureBehaviorGeneratedForSymbol(context, interfaceSymbol, symbol, plugins, behavior)) - .Where(syntaxNode => syntaxNode != null) - .ToImmutableList(); - - return context - .SyntaxGenerator - .MethodDeclaration( - behavior == MockBehavior.Strict ? "ConfigureBehaviorGenerated" : "ConfigureLooseBehaviorGenerated", - accessibility: Accessibility.Private, - statements: statements); - } - private static SyntaxNode GetConfigureBehaviorGeneratedForSymbol( Context context, INamedTypeSymbol interfaceSymbol, ISymbol symbol, IImmutableList plugins, - MockBehavior behavior) + bool isExplicitRequired) { context .LogSink - .Debug(logSource, "Considering symbol '{0}'.", symbol); + .Debug("Considering symbol '{0}' for generation of configure behavior.", symbol); var propertySymbol = symbol as IPropertySymbol; var methodSymbol = symbol as IMethodSymbol; - INamedTypeSymbol returnType = null; + ITypeSymbol returnType = null; if (propertySymbol != null) { @@ -380,7 +319,7 @@ private static SyntaxNode GetConfigureBehaviorGeneratedForSymbol( { context .LogSink - .Debug(logSource, "Ignoring symbol '{0}' because it is a write-only property.", symbol); + .Debug("Ignoring symbol '{0}' because it is a write-only property.", symbol); return null; } @@ -392,7 +331,7 @@ private static SyntaxNode GetConfigureBehaviorGeneratedForSymbol( { context .LogSink - .Debug(logSource, "Ignoring symbol '{0}' because it is a method with an associated symbol.", symbol); + .Debug("Ignoring symbol '{0}' because it is a method with an associated symbol ('{1}').", symbol, methodSymbol.AssociatedSymbol); return null; } @@ -400,7 +339,7 @@ private static SyntaxNode GetConfigureBehaviorGeneratedForSymbol( { context .LogSink - .Debug(logSource, "Ignoring symbol '{0}' because it is a generic method.", symbol); + .Debug("Ignoring symbol '{0}' because it is a generic method.", symbol); return null; } @@ -410,7 +349,7 @@ private static SyntaxNode GetConfigureBehaviorGeneratedForSymbol( { context .LogSink - .Debug(logSource, "Ignoring symbol '{0}' because it is neither a property nor a method.", symbol); + .Debug("Ignoring symbol '{0}' because it is neither a property nor a method.", symbol); return null; } @@ -418,12 +357,12 @@ private static SyntaxNode GetConfigureBehaviorGeneratedForSymbol( { context .LogSink - .Warn(logSource, "Ignoring symbol '{0}' because its return type could not be determined (it's probably a generic).", symbol); + .Debug("Ignoring symbol '{0}' because its return type could not be determined (it's probably a generic).", symbol); return null; } var defaultValueSyntax = plugins - .Select(plugin => plugin.GetDefaultValueSyntax(context, behavior, symbol, returnType)) + .Select(plugin => plugin.GetDefaultValueSyntax(context, symbol, returnType)) .Where(syntax => syntax != null) .FirstOrDefault(); @@ -441,7 +380,7 @@ private static SyntaxNode GetConfigureBehaviorGeneratedForSymbol( { context .LogSink - .Error(logSource, "Failed to resolve It class."); + .Error("Failed to resolve It class."); return null; } @@ -453,7 +392,7 @@ private static SyntaxNode GetConfigureBehaviorGeneratedForSymbol( { context .LogSink - .Error(logSource, "Failed to resolve IsAny method."); + .Error("Failed to resolve IsAny method."); return null; } @@ -519,6 +458,11 @@ private static SyntaxNode GetConfigureBehaviorGeneratedForSymbol( // // this // .When(x => x.SymbolName(It.IsAny(), It.IsAny() ...) + // + // OR (FOR EXPLICIT): + // + // this + // .When(x => ((TypeContainingSymbol)x).SymbolName(It.IsAny(), It.IsAny() ...) var whenArguments = methodSymbol .Parameters .Select( @@ -541,15 +485,28 @@ private static SyntaxNode GetConfigureBehaviorGeneratedForSymbol( parameter.Type })))); + var memberToAccess = context + .SyntaxGenerator + .IdentifierName(lambdaParameterName); + + if (isExplicitRequired) + { + memberToAccess = context + .SyntaxGenerator + .CastExpression( + context + .SyntaxGenerator + .TypeExpression(methodSymbol.ContainingType), + memberToAccess); + } + lambdaExpression = context .SyntaxGenerator .InvocationExpression( context .SyntaxGenerator .MemberAccessExpression( - context - .SyntaxGenerator - .IdentifierName(lambdaParameterName), + memberToAccess, methodSymbol.Name), arguments: whenArguments); } @@ -629,26 +586,76 @@ private static IEnumerable GetMemberDeclarations( INamedTypeSymbol interfaceSymbol, IImmutableList plugins) { + var members = GetDistinctMembersRecursive(interfaceSymbol, context.LogSink) + .ToList(); + + // All members with a flag indicating whether explicit implementation is required. + var membersWithExplicitFlag = members + .Select((member, index) => + { + // Explicit implementation is required if any prior member has the same name and parameters as this one. + var isExplicitRequired = members + .Take(index) + .Any(symbol => ExplicitImplementationRequiredComparer.Instance.Equals(symbol, member)); + return (member, isExplicitRequired); + }) + .ToList(); + + var interfaceTypeExpression = context.SyntaxGenerator.TypeExpression(interfaceSymbol); + + var configureBehaviorStatements = membersWithExplicitFlag + .Select(x => GetConfigureBehaviorGeneratedForSymbol(context, interfaceSymbol, x.member, plugins, x.isExplicitRequired)) + .Where(syntaxNode => syntaxNode != null) + .ToImmutableList(); + var configureBehaviorMethod = context + .SyntaxGenerator + .MethodDeclaration( + "ConfigureBehaviorGenerated", + accessibility: Accessibility.Private, + statements: configureBehaviorStatements); + + var memberDeclarations = membersWithExplicitFlag + .Select( + x => + { + var memberDeclaration = GetMemberDeclarationSyntax(context, x.member, x.isExplicitRequired); + + if (memberDeclaration == null) + { + return null; + } + + var typeContainingMember = context + .SyntaxGenerator + .TypeExpression(x.member.ContainingType); + + if (x.isExplicitRequired) + { + return context + .SyntaxGenerator + .AsPrivateInterfaceImplementation(memberDeclaration, typeContainingMember); + } + else + { + return context + .SyntaxGenerator + .AsPublicInterfaceImplementation(memberDeclaration, typeContainingMember); + } + }) + .Where(x => x != null); + return new SyntaxNode[] { GetConstructorDeclarationSyntax(context, name), - GetConfigureBehaviorGeneratedSyntax(context, interfaceSymbol, plugins, MockBehavior.Strict), - GetConfigureBehaviorGeneratedSyntax(context, interfaceSymbol, plugins, MockBehavior.Loose), + configureBehaviorMethod, GetConfigureBehaviorMethodSyntax(context), GetConfigureLooseBehaviorMethodSyntax(context) } - .Concat( - GetMembersRecursive(interfaceSymbol) - .Select(x => GetMemberDeclarationSyntax(context, x)) - .Where(x => x != null) - .GroupBy(x => x, SyntaxNodeEqualityComparer.Instance) - .Where(group => group.Count() == 1) - .SelectMany(group => group) - .Select(x => context.SyntaxGenerator.AsPublicInterfaceImplementation(x, context.SyntaxGenerator.TypeExpression(interfaceSymbol)))); + .Concat(memberDeclarations); } - private static IEnumerable GetMembersRecursive(INamedTypeSymbol interfaceSymbol) + private static IEnumerable GetMembersRecursive(INamedTypeSymbol interfaceSymbol, ILogSink logSink) { foreach (var member in interfaceSymbol.GetMembers()) { @@ -657,16 +664,21 @@ private static IEnumerable GetMembersRecursive(INamedTypeSymbol interfa foreach (var implementedInterface in interfaceSymbol.Interfaces) { - foreach (var member in GetMembersRecursive(implementedInterface)) + foreach (var member in GetMembersRecursive(implementedInterface, logSink)) { yield return member; } } } + private static IEnumerable GetDistinctMembersRecursive(INamedTypeSymbol interfaceSymbol, ILogSink logSink) => + GetMembersRecursive(interfaceSymbol, logSink) + .Distinct(SymbolEqualityComparer.Default); + private static SyntaxNode GetMemberDeclarationSyntax( Context context, - ISymbol symbol) + ISymbol symbol, + bool isExplicitRequired) { var propertySymbol = symbol as IPropertySymbol; @@ -679,7 +691,7 @@ private static SyntaxNode GetMemberDeclarationSyntax( if (methodSymbol != null) { - return GetMethodDeclarationSyntax(context, methodSymbol); + return GetMethodDeclarationSyntax(context, methodSymbol, isExplicitRequired); } // unsupported symbol type, but we don't error - the user can supplement our code as necessary because it's a partial class @@ -902,7 +914,8 @@ private static IEnumerable GetPropertySetAccessorsSyntax( private static SyntaxNode GetMethodDeclarationSyntax( Context context, - IMethodSymbol methodSymbol) + IMethodSymbol methodSymbol, + bool isExplicitRequired) { if (methodSymbol.MethodKind != MethodKind.Ordinary) { @@ -924,7 +937,7 @@ private static SyntaxNode GetMethodDeclarationSyntax( .SyntaxGenerator .WithStatements( methodDeclaration, - GetMethodStatementsSyntax(context, methodSymbol)); + GetMethodStatementsSyntax(context, methodSymbol, isExplicitRequired)); var csharpMethodDeclaration = methodDeclaration as MethodDeclarationSyntax; @@ -939,7 +952,8 @@ private static SyntaxNode GetMethodDeclarationSyntax( private static IEnumerable GetMethodStatementsSyntax( Context context, - IMethodSymbol methodSymbol) + IMethodSymbol methodSymbol, + bool isExplicitRequired) { // GENERATED CODE (for every ref or out parameter): // @@ -987,13 +1001,25 @@ private static IEnumerable GetMethodStatementsSyntax( .ToList(); var lambdaParameterName = methodSymbol.GetUniqueName(); + var lambdaParameter = context + .SyntaxGenerator + .IdentifierName(lambdaParameterName); + + if (isExplicitRequired) + { + lambdaParameter = context + .SyntaxGenerator + .CastExpression( + context + .SyntaxGenerator + .TypeExpression(methodSymbol.ContainingType), + lambdaParameter); + } var lambdaInvocation = context .SyntaxGenerator .MemberAccessExpression( - context - .SyntaxGenerator - .IdentifierName(lambdaParameterName), + lambdaParameter, methodSymbol.Name); if (typeArguments.Count > 0) @@ -1058,6 +1084,10 @@ private static IEnumerable GetMethodStatementsSyntax( // GENERATED CODE: // // [return] this.Apply(x => x.SomeMethod(param1, param2)); + // + // OR (FOR EXPLICIT): + // + // [return] this.Apply(x => ((TypeContainingSomeMethod)x).SomeMethod(param1, param2)); var applyInvocation = context .SyntaxGenerator .InvocationExpression( @@ -1088,29 +1118,24 @@ private static IEnumerable GetMethodStatementsSyntax( yield return applyInvocation; } - private static IEnumerable GetSymbolsRecursive(INamespaceSymbol namespaceSymbol) + private static IEnumerable GetNamedTypeSymbolsInSource(Compilation compilation) { - // using a heap-based stack here instead of recursive call just to be sure we don't overflow the stack var stack = new Stack(); - stack.Push(namespaceSymbol); + stack.Push(compilation.GlobalNamespace); while (stack.Count > 0) { - var namespaceSymbolToProcess = stack.Pop(); + var @namespace = stack.Pop(); - yield return namespaceSymbolToProcess; - - foreach (var namespaceMember in namespaceSymbolToProcess.GetMembers()) + foreach (var member in @namespace.GetMembers()) { - var namespaceMemberAsNamespace = namespaceMember as INamespaceSymbol; - - if (namespaceMemberAsNamespace != null) + if (member is INamespaceSymbol memberAsNamespace && memberAsNamespace.Locations.Any(x => x.IsInSource)) { - stack.Push(namespaceMemberAsNamespace); + stack.Push(memberAsNamespace); } - else + else if (member is INamedTypeSymbol memberAsNamedTypeSymbol) { - yield return namespaceMember; + yield return memberAsNamedTypeSymbol; } } } @@ -1135,5 +1160,72 @@ public bool Equals(SyntaxNode x, SyntaxNode y) => public int GetHashCode(SyntaxNode obj) => 0; } + + // Considers symbols equal if they would required an explicit implementation to differentiate them in source + // code. That is, they have the same name, parameters, and number of generic type parameters. Properties are + // included in this decision, in which case they have no parameters and no generic type parameters. + private sealed class ExplicitImplementationRequiredComparer : IEqualityComparer + { + public static readonly ExplicitImplementationRequiredComparer Instance = new ExplicitImplementationRequiredComparer(); + + private ExplicitImplementationRequiredComparer() + { + } + + public bool Equals(ISymbol x, ISymbol y) + { + if (x is null) + { + return y is null; + } + else if (y is null) + { + return false; + } + + var xName = x.Name; + var yName = y.Name; + var xParameters = ImmutableArray.Empty; + var yParameters = ImmutableArray.Empty; + var xTypeParameters = ImmutableArray.Empty; + var yTypeParameters = ImmutableArray.Empty; + + if (x is IMethodSymbol xMethod) + { + xParameters = xMethod.Parameters; + xTypeParameters = xMethod.TypeParameters; + } + + if (y is IMethodSymbol yMethod) + { + yParameters = yMethod.Parameters; + yTypeParameters = yMethod.TypeParameters; + } + + return + string.Equals(xName, yName, StringComparison.Ordinal) && + xParameters.SequenceEqual(yParameters) && + xTypeParameters.Length == yTypeParameters.Length; + } + + public int GetHashCode(ISymbol symbol) + { + var name = symbol.Name; + var parameters = ImmutableArray.Empty; + var typeParameters = ImmutableArray.Empty; + + if (symbol is IMethodSymbol methodSymbol) + { + parameters = methodSymbol.Parameters; + typeParameters = methodSymbol.TypeParameters; + } + + var hash = 17; + hash = hash * 23 + name.GetHashCode(); + hash = hash * 23 + parameters.GetHashCode(); + hash = hash * 23 + typeParameters.GetHashCode(); + return hash; + } + } } } \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration/IPlugin.cs b/Src/PCLMock.CodeGeneration/IPlugin.cs index be5293e..1cdbaf8 100644 --- a/Src/PCLMock.CodeGeneration/IPlugin.cs +++ b/Src/PCLMock.CodeGeneration/IPlugin.cs @@ -1,6 +1,7 @@ namespace PCLMock.CodeGeneration { using Microsoft.CodeAnalysis; + using PCLMock.CodeGeneration.Logging; /// /// Defines the interface for a plugin. @@ -34,13 +35,16 @@ string Name /// plugins should simply return the provided compilation. /// /// + /// + /// The current log sink. + /// /// /// The compilation. /// /// /// The initialized compilation. /// - Compilation InitializeCompilation(Compilation compilation); + Compilation InitializeCompilation(ILogSink logSink, Compilation compilation); /// /// Called to generate the default value for a given symbol. @@ -55,23 +59,19 @@ string Name /// /// A context for the operation. /// - /// - /// Indicates whether the default value is being generated for strict or loose behavioral semantics. - /// /// - /// The symbol. + /// The symbol that returns a value of type . /// - /// - /// The symbol's return type. + /// + /// The type for which default value syntax should be generated. /// /// - /// An instance of containing the default value, or if no default value is - /// relevant. + /// An instance of representing the default value, or if no default value could + /// be determined. /// SyntaxNode GetDefaultValueSyntax( Context context, - MockBehavior behavior, ISymbol symbol, - INamedTypeSymbol returnType); + ITypeSymbol typeSymbol); } } \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration/Logging/BuildalyzerLogFactory.cs b/Src/PCLMock.CodeGeneration/Logging/BuildalyzerLogFactory.cs deleted file mode 100644 index 106d0cf..0000000 --- a/Src/PCLMock.CodeGeneration/Logging/BuildalyzerLogFactory.cs +++ /dev/null @@ -1,68 +0,0 @@ -namespace PCLMock.CodeGeneration.Logging -{ - using System; - using System.Reactive.Disposables; - using Microsoft.Extensions.Logging; - - public sealed class BuildalyzerLogFactory : ILoggerFactory - { - private readonly ILogSink logSink; - - public BuildalyzerLogFactory(ILogSink logSink) - { - this.logSink = logSink; - } - - public void AddProvider(ILoggerProvider provider) - { - } - - public ILogger CreateLogger(string categoryName) => - new Logger(this.logSink, categoryName); - - public void Dispose() - { - } - - private sealed class Logger : ILogger - { - private readonly ILogSink logSink; - private readonly string categoryName; - - public Logger(ILogSink logSink, string categoryName) - { - this.logSink = logSink; - this.categoryName = categoryName; - } - - public IDisposable BeginScope(TState state) => - Disposable.Empty; - - public bool IsEnabled(Microsoft.Extensions.Logging.LogLevel logLevel) => - true; - - public void Log(Microsoft.Extensions.Logging.LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) => - this.logSink.Log( - typeof(BuildalyzerLogFactory), - ToLogLevel(logLevel), - formatter(state, exception)); - - private static LogLevel ToLogLevel(Microsoft.Extensions.Logging.LogLevel logLevel) - { - switch (logLevel) - { - case Microsoft.Extensions.Logging.LogLevel.Debug: - case Microsoft.Extensions.Logging.LogLevel.Trace: - case Microsoft.Extensions.Logging.LogLevel.None: - return LogLevel.Debug; - case Microsoft.Extensions.Logging.LogLevel.Information: - return LogLevel.Info; - case Microsoft.Extensions.Logging.LogLevel.Warning: - return LogLevel.Warn; - default: - return LogLevel.Error; - } - } - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration/Logging/ILogSink.cs b/Src/PCLMock.CodeGeneration/Logging/ILogSink.cs index f49b627..598ae89 100644 --- a/Src/PCLMock.CodeGeneration/Logging/ILogSink.cs +++ b/Src/PCLMock.CodeGeneration/Logging/ILogSink.cs @@ -1,14 +1,7 @@ namespace PCLMock.CodeGeneration.Logging { - using System; - public interface ILogSink { - bool IsEnabled - { - get; - } - - void Log(Type source, LogLevel level, string message); + void Log(LogEvent logEvent); } } \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration/Logging/LogEvent.cs b/Src/PCLMock.CodeGeneration/Logging/LogEvent.cs new file mode 100644 index 0000000..5c5d09a --- /dev/null +++ b/Src/PCLMock.CodeGeneration/Logging/LogEvent.cs @@ -0,0 +1,52 @@ +namespace PCLMock.CodeGeneration.Logging +{ + using System.Collections.Immutable; + using System.Globalization; + using System.Linq; + + public struct LogEvent + { + private readonly string source; + private readonly LogLevel level; + private readonly string message; + private readonly ImmutableArray messageArgs; + + public LogEvent( + string source, + LogLevel level, + string message, + ImmutableArray messageArgs) + { + this.source = source; + this.level = level; + this.message = message; + this.messageArgs = messageArgs; + } + + public string Source => this.source; + + public LogLevel Level => this.level; + + public string Message => this.message; + + public ImmutableArray MessageArgs => this.messageArgs; + + public string FormattedMessage + { + get + { + if (this.message == null) + { + return null; + } + + if (this.messageArgs.IsDefaultOrEmpty) + { + return this.message; + } + + return string.Format(CultureInfo.InvariantCulture, this.message, this.messageArgs.ToArray()); + } + } + } +} diff --git a/Src/PCLMock.CodeGeneration/Logging/LogLevel.cs b/Src/PCLMock.CodeGeneration/Logging/LogLevel.cs index b63881d..a3c7667 100644 --- a/Src/PCLMock.CodeGeneration/Logging/LogLevel.cs +++ b/Src/PCLMock.CodeGeneration/Logging/LogLevel.cs @@ -2,11 +2,10 @@ namespace PCLMock.CodeGeneration.Logging { public enum LogLevel { - Debug, - Info, - Warn, - Positive, - Negative, - Error + None = 0, + Debug = 1, + Info = 2, + Warn = 3, + Error = 4 } } \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration/Logging/LogSinkExtensions.cs b/Src/PCLMock.CodeGeneration/Logging/LogSinkExtensions.cs index 22a55e1..7b74933 100644 --- a/Src/PCLMock.CodeGeneration/Logging/LogSinkExtensions.cs +++ b/Src/PCLMock.CodeGeneration/Logging/LogSinkExtensions.cs @@ -1,80 +1,150 @@ namespace PCLMock.CodeGeneration.Logging { using System; - using System.Globalization; + using System.Collections.Immutable; public static class LogSinkExtensions { - public static void Log(this ILogSink @this, Type source, LogLevel level, string format, params object[] args) - { - var message = string.Format(CultureInfo.InvariantCulture, format, args); - @this.Log(source, level, message); - } + public static ILogSink WithSource(this ILogSink @this, Type source) => + new LogSinkWithSource(@this, source.FullName); - public static void Debug(this ILogSink @this, Type source, string message) - { - @this.Log(source, LogLevel.Debug, message); - } + public static ILogSink WithSource(this ILogSink @this, string source) => + new LogSinkWithSource(@this, source); - public static void Debug(this ILogSink @this, Type source, string format, params object[] args) - { - var message = string.Format(CultureInfo.InvariantCulture, format, args); - @this.Log(source, LogLevel.Debug, message); - } + public static ILogSink WithMinimumLevel(this ILogSink @this, LogLevel minimumLevel) => + new LogSinkWithMinimumLevel(@this, minimumLevel); - public static void Info(this ILogSink @this, Type source, string message) + public static void Debug(this ILogSink @this, string message) { - @this.Log(source, LogLevel.Info, message); + var logEvent = new LogEvent( + default, + LogLevel.Debug, + message, + default); + @this.Log(logEvent); } - public static void Info(this ILogSink @this, Type source, string format, params object[] args) + public static void Debug(this ILogSink @this, string message, params object[] messageArgs) { - var message = string.Format(CultureInfo.InvariantCulture, format, args); - @this.Log(source, LogLevel.Info, message); + var logEvent = new LogEvent( + default, + LogLevel.Debug, + message, + ImmutableArray.Create(messageArgs)); + @this.Log(logEvent); } - public static void Warn(this ILogSink @this, Type source, string message) + public static void Info(this ILogSink @this, string message) { - @this.Log(source, LogLevel.Warn, message); + var logEvent = new LogEvent( + default, + LogLevel.Info, + message, + default); + @this.Log(logEvent); } - public static void Warn(this ILogSink @this, Type source, string format, params object[] args) + public static void Info(this ILogSink @this, string message, params object[] messageArgs) { - var message = string.Format(CultureInfo.InvariantCulture, format, args); - @this.Log(source, LogLevel.Warn, message); + var logEvent = new LogEvent( + default, + LogLevel.Info, + message, + ImmutableArray.Create(messageArgs)); + @this.Log(logEvent); } - public static void Positive(this ILogSink @this, Type source, string message) + public static void Warn(this ILogSink @this, string message) { - @this.Log(source, LogLevel.Positive, message); + var logEvent = new LogEvent( + default, + LogLevel.Warn, + message, + default); + @this.Log(logEvent); } - public static void Positive(this ILogSink @this, Type source, string format, params object[] args) + public static void Warn(this ILogSink @this, string message, params object[] messageArgs) { - var message = string.Format(CultureInfo.InvariantCulture, format, args); - @this.Log(source, LogLevel.Positive, message); + var logEvent = new LogEvent( + default, + LogLevel.Warn, + message, + ImmutableArray.Create(messageArgs)); + @this.Log(logEvent); } - public static void Negative(this ILogSink @this, Type source, string message) + public static void Error(this ILogSink @this, string message) { - @this.Log(source, LogLevel.Negative, message); + var logEvent = new LogEvent( + default, + LogLevel.Error, + message, + default); + @this.Log(logEvent); } - public static void Negative(this ILogSink @this, Type source, string format, params object[] args) + public static void Error(this ILogSink @this, string message, params object[] messageArgs) { - var message = string.Format(CultureInfo.InvariantCulture, format, args); - @this.Log(source, LogLevel.Negative, message); + var logEvent = new LogEvent( + default, + LogLevel.Error, + message, + ImmutableArray.Create(messageArgs)); + @this.Log(logEvent); } - public static void Error(this ILogSink @this, Type source, string message) + private sealed class LogSinkWithSource : ILogSink { - @this.Log(source, LogLevel.Error, message); + private readonly ILogSink inner; + private readonly string source; + + public LogSinkWithSource(ILogSink inner, string source) + { + this.inner = inner; + this.source = source; + } + + public void Log(LogEvent logEvent) + { + if (logEvent.Source == null) + { + // Only overwrite the source if it's not already present, otherwise nobody can override our override! + logEvent = new LogEvent( + this.source, + logEvent.Level, + logEvent.Message, + logEvent.MessageArgs); + } + + this.inner.Log(logEvent); + } + + public override string ToString() => this.inner.ToString(); } - public static void Error(this ILogSink @this, Type source, string format, params object[] args) + private sealed class LogSinkWithMinimumLevel : ILogSink { - var message = string.Format(CultureInfo.InvariantCulture, format, args); - @this.Log(source, LogLevel.Error, message); + private readonly ILogSink inner; + private readonly LogLevel minimumLevel; + + public LogSinkWithMinimumLevel(ILogSink inner, LogLevel minimumLevel) + { + this.inner = inner; + this.minimumLevel = minimumLevel; + } + + public void Log(LogEvent logEvent) + { + if (logEvent.Level < this.minimumLevel) + { + return; + } + + this.inner.Log(logEvent); + } + + public override string ToString() => this.inner.ToString(); } } } \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration/Logging/NullLogSink.cs b/Src/PCLMock.CodeGeneration/Logging/NullLogSink.cs index 232e41e..423faa0 100644 --- a/Src/PCLMock.CodeGeneration/Logging/NullLogSink.cs +++ b/Src/PCLMock.CodeGeneration/Logging/NullLogSink.cs @@ -1,7 +1,5 @@ namespace PCLMock.CodeGeneration.Logging { - using System; - public sealed class NullLogSink : ILogSink { public static readonly NullLogSink Instance = new NullLogSink(); @@ -10,9 +8,7 @@ private NullLogSink() { } - public bool IsEnabled => false; - - public void Log(Type source, LogLevel level, string message) + public void Log(LogEvent logEvent) { } } diff --git a/Src/PCLMock.CodeGeneration/Logging/StringLogSink.cs b/Src/PCLMock.CodeGeneration/Logging/StringLogSink.cs index d89e991..9538c7d 100644 --- a/Src/PCLMock.CodeGeneration/Logging/StringLogSink.cs +++ b/Src/PCLMock.CodeGeneration/Logging/StringLogSink.cs @@ -1,6 +1,5 @@ namespace PCLMock.CodeGeneration.Logging { - using System; using System.Text; public sealed class StringLogSink : ILogSink @@ -12,17 +11,17 @@ public StringLogSink() this.stringBuilder = new StringBuilder(); } - public bool IsEnabled => true; - - public void Log(Type source, LogLevel level, string message) => + public void Log(LogEvent logEvent) + { this .stringBuilder .Append("[") - .Append(source.FullName) + .Append(logEvent.Source ?? "<>") .Append("] [") - .Append(level) + .Append(logEvent.Level) .Append("] ") - .AppendLine(message); + .AppendLine(logEvent.FormattedMessage); + } public override string ToString() => this.stringBuilder.ToString(); diff --git a/Src/PCLMock.CodeGeneration/Models/Configuration.cs b/Src/PCLMock.CodeGeneration/Models/Configuration.cs index 38af944..bd1ba2e 100644 --- a/Src/PCLMock.CodeGeneration/Models/Configuration.cs +++ b/Src/PCLMock.CodeGeneration/Models/Configuration.cs @@ -14,8 +14,6 @@ public sealed class Configuration { - private static readonly Type logSource = typeof(Configuration); - private readonly ILogSink logSink; private readonly IImmutableList namespaceTransformations; private readonly IImmutableList nameTransformations; @@ -29,36 +27,34 @@ public Configuration( IEnumerable interfaceFilters, IEnumerable plugins) { - this.logSink = logSink; + this.logSink = logSink + .WithSource(typeof(Configuration)); this.namespaceTransformations = namespaceTransformations.ToImmutableList(); this.nameTransformations = nameTransformations.ToImmutableList(); this.interfaceFilters = interfaceFilters.ToImmutableList(); this.plugins = plugins.ToImmutableList(); - if (logSink.IsEnabled) - { - var namespaceTransformationsLog = this - .namespaceTransformations - .Aggregate( - new StringBuilder(), - (sb, next) => sb.Append(" - Namespaces matching '").Append(next.Pattern).Append("' will be replaced with '").Append(next.Replacement).AppendLine("'."), sb => sb.ToString()); - var nameTransformationsLog = this - .nameTransformations - .Aggregate( - new StringBuilder(), - (sb, next) => sb.Append(" - Names matching '").Append(next.Pattern).Append("' will be replaced with '").Append(next.Replacement).AppendLine("'."), sb => sb.ToString()); - var interfaceFiltersLog = this - .interfaceFilters - .Aggregate( - new StringBuilder(), - (sb, next) => sb.Append(" - Interfaces matching '").Append(next.Pattern).Append("' will be '").Append(next.Type == FilterType.Include ? "included" : "excluded").AppendLine("."), sb => sb.ToString()); - var pluginsLog = this - .plugins - .Aggregate( - new StringBuilder(), - (sb, next) => sb.Append(" - Plugin with assembly-qualified name '").Append(next.AssemblyQualifiedName).AppendLine("' will be applied.")); - logSink.Debug(logSource, $"Created configuration with the following rules:{Environment.NewLine}{namespaceTransformationsLog}{nameTransformationsLog}{interfaceFiltersLog}{pluginsLog}"); - } + var namespaceTransformationsLog = this + .namespaceTransformations + .Aggregate( + new StringBuilder(), + (sb, next) => sb.Append(" - Namespaces matching '").Append(next.Pattern).Append("' will be replaced with '").Append(next.Replacement).AppendLine("'."), sb => sb.ToString()); + var nameTransformationsLog = this + .nameTransformations + .Aggregate( + new StringBuilder(), + (sb, next) => sb.Append(" - Names matching '").Append(next.Pattern).Append("' will be replaced with '").Append(next.Replacement).AppendLine("'."), sb => sb.ToString()); + var interfaceFiltersLog = this + .interfaceFilters + .Aggregate( + new StringBuilder(), + (sb, next) => sb.Append(" - Interfaces matching '").Append(next.Pattern).Append("' will be '").Append(next.Type == FilterType.Include ? "included" : "excluded").AppendLine("."), sb => sb.ToString()); + var pluginsLog = this + .plugins + .Aggregate( + new StringBuilder(), + (sb, next) => sb.Append(" - Plugin with assembly-qualified name '").Append(next.AssemblyQualifiedName).AppendLine("' will be applied.")); + logSink.Debug($"Created configuration with the following rules:{Environment.NewLine}{namespaceTransformationsLog}{nameTransformationsLog}{interfaceFiltersLog}{pluginsLog}"); } public IImmutableList NamespaceTransformations => this.namespaceTransformations; @@ -100,11 +96,11 @@ public Func GetInterfacePredicate() var name = string.Format( CultureInfo.InvariantCulture, "{0}, {1}", - symbol.ToDisplayString(), + symbol, symbol.ContainingAssembly.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat)); var include = false; - this.logSink.Info(logSource, "Determining inclusivity of interface: '{0}'.", name); + this.logSink.Info("Determining inclusivity of interface: '{0}'.", name); foreach (var filter in this.InterfaceFilters) { @@ -117,27 +113,18 @@ public Func GetInterfacePredicate() include = Regex.IsMatch(name, filter.Pattern); } - if (this.logSink.IsEnabled) - { - this.logSink.Debug( - logSource, - " - after {0} filter '{1}', it is {2}.", - filter.Type == FilterType.Include ? "inclusion" : "exclusion", - filter.Pattern, - include ? "included" : "excluded"); - } - } - - if (logSink.IsEnabled) - { - this.logSink.Log( - logSource, - include ? LogLevel.Positive : LogLevel.Negative, - "'{0}' has been {1}.", - name, + this.logSink.Debug( + " - after {0} filter '{1}', it is {2}.", + filter.Type == FilterType.Include ? "inclusion" : "exclusion", + filter.Pattern, include ? "included" : "excluded"); } + this.logSink.Info( + "'{0}' has been {1}.", + name, + include ? "included" : "excluded"); + return include; }; } @@ -158,12 +145,12 @@ public IImmutableList GetPlugins() foreach (var plugin in this.plugins) { - this.logSink.Info(logSource, "Attempting to resolve plugin from type name '{0}'.", plugin.AssemblyQualifiedName); + this.logSink.Info("Attempting to resolve plugin from type name '{0}'.", plugin.AssemblyQualifiedName); var type = Type.GetType(plugin.AssemblyQualifiedName); if (type == null) { - this.logSink.Error(logSource, "Failed to resolve plugin from type name '{0}'.", plugin.AssemblyQualifiedName); + this.logSink.Error("Failed to resolve plugin from type name '{0}'.", plugin.AssemblyQualifiedName); continue; } @@ -173,7 +160,7 @@ public IImmutableList GetPlugins() if (!(resolvedPlugin is IPlugin)) { - this.logSink.Error(logSource, "Resolved plugin '{0}' does not implement '{1}'.", resolvedPlugin.GetType().AssemblyQualifiedName, typeof(IPlugin).AssemblyQualifiedName); + this.logSink.Error("Resolved plugin '{0}' does not implement '{1}'.", resolvedPlugin.GetType().AssemblyQualifiedName, typeof(IPlugin).AssemblyQualifiedName); continue; } @@ -181,7 +168,7 @@ public IImmutableList GetPlugins() } catch (Exception ex) { - this.logSink.Error(logSource, "Failed to create plugin from type name '{0}'. Exception was: {1}", plugin.AssemblyQualifiedName, ex); + this.logSink.Error("Failed to create plugin from type name '{0}'. Exception was: {1}", plugin.AssemblyQualifiedName, ex); } } @@ -190,21 +177,17 @@ public IImmutableList GetPlugins() private static string ApplyTransformations(ILogSink logSink, string type, string input, IImmutableList transformations) { - logSink.Info(logSource, "Applying {0} transformations to input: '{1}'.", type, input); + logSink.Info("Applying {0} transformations to input: '{1}'.", type, input); foreach (var transformation in transformations) { input = Regex.Replace(input, transformation.Pattern, transformation.Replacement); - if (logSink.IsEnabled) - { - logSink.Debug( - logSource, - " - after transformation '{0}' -> '{1}', input is now '{2}'.", - transformation.Pattern, - transformation.Replacement, - input); - } + logSink.Debug( + " - after transformation '{0}' -> '{1}', input is now '{2}'.", + transformation.Pattern, + transformation.Replacement, + input); } return input; diff --git a/Src/PCLMock.CodeGeneration/PCLMock.CodeGeneration.csproj b/Src/PCLMock.CodeGeneration/PCLMock.CodeGeneration.csproj index 63473d9..56ee0bf 100644 --- a/Src/PCLMock.CodeGeneration/PCLMock.CodeGeneration.csproj +++ b/Src/PCLMock.CodeGeneration/PCLMock.CodeGeneration.csproj @@ -3,11 +3,11 @@ netstandard2.0 false + true + True - - @@ -17,4 +17,9 @@ + + + + + \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration/Plugins/Collections.cs b/Src/PCLMock.CodeGeneration/Plugins/Collections.cs index baf6a7c..fb0d9ed 100644 --- a/Src/PCLMock.CodeGeneration/Plugins/Collections.cs +++ b/Src/PCLMock.CodeGeneration/Plugins/Collections.cs @@ -29,66 +29,73 @@ namespace PCLMock.CodeGeneration.Plugins /// public sealed class Collections : IPlugin { - private static readonly Type logSource = typeof(Collections); - public string Name => "Collections"; /// - public Compilation InitializeCompilation(Compilation compilation) => + public Compilation InitializeCompilation(ILogSink logSink, Compilation compilation) => compilation; /// public SyntaxNode GetDefaultValueSyntax( Context context, - MockBehavior behavior, ISymbol symbol, - INamedTypeSymbol returnType) + ITypeSymbol typeSymbol) { - if (behavior == MockBehavior.Loose) + context = context + .WithLogSink( + context + .LogSink + .WithSource(typeof(Collections))); + + if (!(typeSymbol is INamedTypeSymbol namedTypeSymbol)) { + context + .LogSink + .Debug("Ignoring type '{0}' because it is not a named type symbol.", typeSymbol); return null; } - - if (!returnType.IsGenericType) + + if (!namedTypeSymbol.IsGenericType) { context .LogSink - .Debug(logSource, "Ignoring symbol '{0}' because its return type is not a generic type, so it cannot be one of the supported collection types."); + .Debug("Ignoring type '{0}' because its return type is not a generic type, so it cannot be one of the supported collection types.", namedTypeSymbol); return null; } SyntaxNode returnValueSyntax; - if (!TryGetReturnValueSyntaxForEnumerableReturnType(context, returnType, out returnValueSyntax) && - !TryGetReturnValueSyntaxForCollectionReturnType(context, returnType, out returnValueSyntax) && - !TryGetReturnValueSyntaxForDictionaryReturnType(context, returnType, out returnValueSyntax) && - !TryGetReturnValueSyntaxForSetReturnType(context, returnType, out returnValueSyntax) && - !TryGetReturnValueSyntaxForImmutableListReturnType(context, returnType, out returnValueSyntax) && - !TryGetReturnValueSyntaxForImmutableDictionaryReturnType(context, returnType, out returnValueSyntax) && - !TryGetReturnValueSyntaxForImmutableQueueReturnType(context, returnType, out returnValueSyntax) && - !TryGetReturnValueSyntaxForImmutableSetReturnType(context, returnType, out returnValueSyntax) && - !TryGetReturnValueSyntaxForImmutableStackReturnType(context, returnType, out returnValueSyntax)) + if (!TryGetReturnValueSyntaxForEnumerableReturnType(context, namedTypeSymbol, out returnValueSyntax) && + !TryGetReturnValueSyntaxForCollectionReturnType(context, namedTypeSymbol, out returnValueSyntax) && + !TryGetReturnValueSyntaxForDictionaryReturnType(context, namedTypeSymbol, out returnValueSyntax) && + !TryGetReturnValueSyntaxForSetReturnType(context, namedTypeSymbol, out returnValueSyntax) && + !TryGetReturnValueSyntaxForImmutableListReturnType(context, namedTypeSymbol, out returnValueSyntax) && + !TryGetReturnValueSyntaxForImmutableDictionaryReturnType(context, namedTypeSymbol, out returnValueSyntax) && + !TryGetReturnValueSyntaxForImmutableQueueReturnType(context, namedTypeSymbol, out returnValueSyntax) && + !TryGetReturnValueSyntaxForImmutableSetReturnType(context, namedTypeSymbol, out returnValueSyntax) && + !TryGetReturnValueSyntaxForImmutableStackReturnType(context, namedTypeSymbol, out returnValueSyntax)) { context .LogSink - .Debug(logSource, "Ignoring symbol '{0}' because it does not return a supported collection type.", symbol); + .Debug("Type '{0}' is not a supported collection type.", namedTypeSymbol); return null; } + context + .LogSink + .Debug("Generated a default value for type '{0}'.", namedTypeSymbol); + return returnValueSyntax; } private static bool TryGetReturnValueSyntaxForEnumerableReturnType( Context context, - INamedTypeSymbol returnType, + INamedTypeSymbol typeSymbol, out SyntaxNode returnValueSyntax) { - var enumerableInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Generic.IEnumerable`1"); + var isEnumerable = typeSymbol.ConstructedFrom?.ToDisplayString() == "System.Collections.Generic.IEnumerable"; - if (returnType.ConstructedFrom != enumerableInterfaceType) + if (!isEnumerable) { returnValueSyntax = null; return false; @@ -97,13 +104,13 @@ private static bool TryGetReturnValueSyntaxForEnumerableReturnType( var enumerableType = context .SemanticModel .Compilation - .GetTypeByMetadataName("System.Linq.Enumerable"); + .GetPreferredTypeByMetadataName("System.Linq.Enumerable", preferredAssemblyNames: new[] { "System.Linq" }); if (enumerableType == null) { context .LogSink - .Warn(logSource, "Failed to resolve Enumerable class."); + .Warn("The Enumerable type could not be resolved (probably a missing reference to System.Linq)."); returnValueSyntax = null; return false; } @@ -123,39 +130,21 @@ private static bool TryGetReturnValueSyntaxForEnumerableReturnType( "Empty"), context .SyntaxGenerator - .TypeExpression(returnType.TypeArguments[0]))); + .TypeExpression(typeSymbol.TypeArguments[0]))); return true; } private static bool TryGetReturnValueSyntaxForCollectionReturnType( Context context, - INamedTypeSymbol returnType, + INamedTypeSymbol typeSymbol, out SyntaxNode returnValueSyntax) { - var collectionInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Generic.ICollection`1"); - - var readOnlyCollectionInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Generic.IReadOnlyCollection`1"); - - var listInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Generic.IList`1"); - - var readOnlyListInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Generic.IReadOnlyList`1"); + var isCollection = typeSymbol.ConstructedFrom?.ToDisplayString() == "System.Collections.Generic.ICollection"; + var isReadOnlyCollection = typeSymbol.ConstructedFrom?.ToDisplayString() == "System.Collections.Generic.IReadOnlyCollection"; + var isList = typeSymbol.ConstructedFrom?.ToDisplayString() == "System.Collections.Generic.IList"; + var isReadOnlyList = typeSymbol.ConstructedFrom?.ToDisplayString() == "System.Collections.Generic.IReadOnlyList"; - if (returnType.ConstructedFrom != collectionInterfaceType && - returnType.ConstructedFrom != readOnlyCollectionInterfaceType && - returnType.ConstructedFrom != listInterfaceType && - returnType.ConstructedFrom != readOnlyListInterfaceType) + if (!(isCollection || isReadOnlyCollection || isList || isReadOnlyList)) { returnValueSyntax = null; return false; @@ -164,13 +153,13 @@ private static bool TryGetReturnValueSyntaxForCollectionReturnType( var listType = context .SemanticModel .Compilation - .GetTypeByMetadataName("System.Collections.Generic.List`1"); + .GetPreferredTypeByMetadataName("System.Collections.Generic.List`1", preferredAssemblyNames: new[] { "System.Collections" }); if (listType == null) { context .LogSink - .Warn(logSource, "Failed to resolve List class."); + .Warn("The List type could not be resolved (probably a missing reference to System.Collections)."); returnValueSyntax = null; return false; } @@ -178,27 +167,19 @@ private static bool TryGetReturnValueSyntaxForCollectionReturnType( returnValueSyntax = context .SyntaxGenerator .ObjectCreationExpression( - listType.Construct(returnType.TypeArguments[0])).NormalizeWhitespace(); + listType.Construct(typeSymbol.TypeArguments[0])).NormalizeWhitespace(); return true; } private static bool TryGetReturnValueSyntaxForDictionaryReturnType( Context context, - INamedTypeSymbol returnType, + INamedTypeSymbol typeSymbol, out SyntaxNode returnValueSyntax) { - var dictionaryInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Generic.IDictionary`2"); - - var readOnlyDictionaryInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Generic.IReadOnlyDictionary`2"); + var isDictionary = typeSymbol.ConstructedFrom?.ToDisplayString() == "System.Collections.Generic.IDictionary"; + var isReadOnlyDictionary = typeSymbol.ConstructedFrom?.ToDisplayString() == "System.Collections.Generic.IReadOnlyDictionary"; - if (returnType.ConstructedFrom != dictionaryInterfaceType && - returnType.ConstructedFrom != readOnlyDictionaryInterfaceType) + if (!(isDictionary || isReadOnlyDictionary)) { returnValueSyntax = null; return false; @@ -207,13 +188,13 @@ private static bool TryGetReturnValueSyntaxForDictionaryReturnType( var dictionaryType = context .SemanticModel .Compilation - .GetTypeByMetadataName("System.Collections.Generic.Dictionary`2"); + .GetPreferredTypeByMetadataName("System.Collections.Generic.Dictionary`2", preferredAssemblyNames: new[] { "System.Collections" }); if (dictionaryType == null) { context .LogSink - .Warn(logSource, "Failed to resolve Dictionary class."); + .Warn("The Dictionary type could not be resolved (probably a missing reference to System.Collections)."); returnValueSyntax = null; return false; } @@ -221,36 +202,33 @@ private static bool TryGetReturnValueSyntaxForDictionaryReturnType( returnValueSyntax = context .SyntaxGenerator .ObjectCreationExpression( - dictionaryType.Construct(returnType.TypeArguments[0], returnType.TypeArguments[1])).NormalizeWhitespace(); + dictionaryType.Construct(typeSymbol.TypeArguments[0], typeSymbol.TypeArguments[1])).NormalizeWhitespace(); return true; } private static bool TryGetReturnValueSyntaxForSetReturnType( Context context, - INamedTypeSymbol returnType, + INamedTypeSymbol typeSymbol, out SyntaxNode returnValueSyntax) { - var setInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Generic.ISet`1"); + var isSet = typeSymbol.ConstructedFrom?.ToDisplayString() == "System.Collections.Generic.ISet"; - if (returnType.ConstructedFrom != setInterfaceType) + if (!isSet) { returnValueSyntax = null; return false; } - var dictionaryType = context + var hashSetType = context .SemanticModel .Compilation - .GetTypeByMetadataName("System.Collections.Generic.HashSet`1"); + .GetPreferredTypeByMetadataName("System.Collections.Generic.HashSet`1", preferredAssemblyNames: new[] { "System.Collections" }); - if (dictionaryType == null) + if (hashSetType == null) { context .LogSink - .Warn(logSource, "Failed to resolve HashSet class."); + .Warn("The HashSet type could not be resolved (probably a missing reference to System.Collections)."); returnValueSyntax = null; return false; } @@ -258,21 +236,18 @@ private static bool TryGetReturnValueSyntaxForSetReturnType( returnValueSyntax = context .SyntaxGenerator .ObjectCreationExpression( - dictionaryType.Construct(returnType.TypeArguments[0])).NormalizeWhitespace(); + hashSetType.Construct(typeSymbol.TypeArguments[0])).NormalizeWhitespace(); return true; } private static bool TryGetReturnValueSyntaxForImmutableListReturnType( Context context, - INamedTypeSymbol returnType, + INamedTypeSymbol typeSymbol, out SyntaxNode returnValueSyntax) { - var immutableListInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Immutable.IImmutableList`1"); + var isImmutableList = typeSymbol.ConstructedFrom?.ToDisplayString() == "System.Collections.Immutable.IImmutableList"; - if (returnType.ConstructedFrom != immutableListInterfaceType) + if (!isImmutableList) { returnValueSyntax = null; return false; @@ -281,13 +256,13 @@ private static bool TryGetReturnValueSyntaxForImmutableListReturnType( var immutableListType = context .SemanticModel .Compilation - .GetTypeByMetadataName("System.Collections.Immutable.ImmutableList"); + .GetPreferredTypeByMetadataName("System.Collections.Immutable.ImmutableList", preferredAssemblyNames: new[] { "System.Collections.Immutable" }); if (immutableListType == null) { context .LogSink - .Warn(logSource, "Failed to resolve ImmutableList class."); + .Warn("The ImmutableList type could not be resolved (probably a missing reference to System.Collections.Immutable)."); returnValueSyntax = null; return false; } @@ -303,22 +278,19 @@ private static bool TryGetReturnValueSyntaxForImmutableListReturnType( .TypeExpression(immutableListType), context .SyntaxGenerator - .TypeExpression(returnType.TypeArguments[0])), + .TypeExpression(typeSymbol.TypeArguments[0])), "Empty"); return true; } private static bool TryGetReturnValueSyntaxForImmutableDictionaryReturnType( Context context, - INamedTypeSymbol returnType, + INamedTypeSymbol typeSymbol, out SyntaxNode returnValueSyntax) { - var immutableDictionaryInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Immutable.IImmutableDictionary`2"); + var isImmutableDictionary = typeSymbol.ConstructedFrom?.ToDisplayString() == "System.Collections.Immutable.IImmutableDictionary"; - if (returnType.ConstructedFrom != immutableDictionaryInterfaceType) + if (!isImmutableDictionary) { returnValueSyntax = null; return false; @@ -327,13 +299,13 @@ private static bool TryGetReturnValueSyntaxForImmutableDictionaryReturnType( var immutableDictionaryType = context .SemanticModel .Compilation - .GetTypeByMetadataName("System.Collections.Immutable.ImmutableDictionary"); + .GetPreferredTypeByMetadataName("System.Collections.Immutable.ImmutableDictionary", preferredAssemblyNames: new[] { "System.Collections.Immutable" }); if (immutableDictionaryType == null) { context .LogSink - .Warn(logSource, "Failed to resolve ImmutableDictionary class."); + .Warn("The ImmutableDictionary type could not be resolved (probably a missing reference to System.Collections.Immutable)."); returnValueSyntax = null; return false; } @@ -349,25 +321,22 @@ private static bool TryGetReturnValueSyntaxForImmutableDictionaryReturnType( .TypeExpression(immutableDictionaryType), context .SyntaxGenerator - .TypeExpression(returnType.TypeArguments[0]), + .TypeExpression(typeSymbol.TypeArguments[0]), context .SyntaxGenerator - .TypeExpression(returnType.TypeArguments[1])), + .TypeExpression(typeSymbol.TypeArguments[1])), "Empty"); return true; } private static bool TryGetReturnValueSyntaxForImmutableQueueReturnType( Context context, - INamedTypeSymbol returnType, + INamedTypeSymbol typeSymbol, out SyntaxNode returnValueSyntax) { - var immutableQueueInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Immutable.IImmutableQueue`1"); + var isImmutableQueue = typeSymbol.ConstructedFrom?.ToDisplayString() == "System.Collections.Immutable.IImmutableQueue"; - if (returnType.ConstructedFrom != immutableQueueInterfaceType) + if (!isImmutableQueue) { returnValueSyntax = null; return false; @@ -376,13 +345,13 @@ private static bool TryGetReturnValueSyntaxForImmutableQueueReturnType( var immutableQueueType = context .SemanticModel .Compilation - .GetTypeByMetadataName("System.Collections.Immutable.ImmutableQueue"); + .GetPreferredTypeByMetadataName("System.Collections.Immutable.ImmutableQueue", preferredAssemblyNames: new[] { "System.Collections.Immutable" }); if (immutableQueueType == null) { context .LogSink - .Warn(logSource, "Failed to resolve ImmutableQueue class."); + .Warn("The ImmutableDictionary type could not be resolved (probably a missing reference to System.Collections.Immutable)."); returnValueSyntax = null; return false; } @@ -398,37 +367,34 @@ private static bool TryGetReturnValueSyntaxForImmutableQueueReturnType( .TypeExpression(immutableQueueType), context .SyntaxGenerator - .TypeExpression(returnType.TypeArguments[0])), + .TypeExpression(typeSymbol.TypeArguments[0])), "Empty"); return true; } private static bool TryGetReturnValueSyntaxForImmutableSetReturnType( Context context, - INamedTypeSymbol returnType, + INamedTypeSymbol typeSymbol, out SyntaxNode returnValueSyntax) { - var immutableSetInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Immutable.IImmutableSet`1"); + var isImmutableSet = typeSymbol.ConstructedFrom?.ToDisplayString() == "System.Collections.Immutable.IImmutableSet"; - if (returnType.ConstructedFrom != immutableSetInterfaceType) + if (!isImmutableSet) { returnValueSyntax = null; return false; } - var immutableSetType = context + var immutableHashSetType = context .SemanticModel .Compilation - .GetTypeByMetadataName("System.Collections.Immutable.ImmutableHashSet"); + .GetPreferredTypeByMetadataName("System.Collections.Immutable.ImmutableHashSet", preferredAssemblyNames: new[] { "System.Collections.Immutable" }); - if (immutableSetType == null) + if (immutableHashSetType == null) { context .LogSink - .Warn(logSource, "Failed to resolve ImmutableSet class."); + .Warn("The ImmutableHashSet type could not be resolved (probably a missing reference to System.Collections.Immutable)."); returnValueSyntax = null; return false; } @@ -441,25 +407,22 @@ private static bool TryGetReturnValueSyntaxForImmutableSetReturnType( .WithTypeArguments( context .SyntaxGenerator - .TypeExpression(immutableSetType), + .TypeExpression(immutableHashSetType), context .SyntaxGenerator - .TypeExpression(returnType.TypeArguments[0])), + .TypeExpression(typeSymbol.TypeArguments[0])), "Empty"); return true; } private static bool TryGetReturnValueSyntaxForImmutableStackReturnType( Context context, - INamedTypeSymbol returnType, + INamedTypeSymbol typeSymbol, out SyntaxNode returnValueSyntax) { - var immutableStackInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Collections.Immutable.IImmutableStack`1"); + var isImmutableStack = typeSymbol.ConstructedFrom?.ToDisplayString() == "System.Collections.Immutable.IImmutableStack"; - if (returnType.ConstructedFrom != immutableStackInterfaceType) + if (!isImmutableStack) { returnValueSyntax = null; return false; @@ -468,13 +431,13 @@ private static bool TryGetReturnValueSyntaxForImmutableStackReturnType( var immutableStackType = context .SemanticModel .Compilation - .GetTypeByMetadataName("System.Collections.Immutable.ImmutableStack"); + .GetPreferredTypeByMetadataName("System.Collections.Immutable.ImmutableStack", preferredAssemblyNames: new[] { "System.Collections.Immutable" }); if (immutableStackType == null) { context .LogSink - .Warn(logSource, "Failed to resolve ImmutableStack class."); + .Warn("The ImmutableStack type could not be resolved (probably a missing reference to System.Collections.Immutable)."); returnValueSyntax = null; return false; } @@ -490,7 +453,7 @@ private static bool TryGetReturnValueSyntaxForImmutableStackReturnType( .TypeExpression(immutableStackType), context .SyntaxGenerator - .TypeExpression(returnType.TypeArguments[0])), + .TypeExpression(typeSymbol.TypeArguments[0])), "Empty"); return true; } diff --git a/Src/PCLMock.CodeGeneration/Plugins/Default.cs b/Src/PCLMock.CodeGeneration/Plugins/Default.cs new file mode 100644 index 0000000..712015b --- /dev/null +++ b/Src/PCLMock.CodeGeneration/Plugins/Default.cs @@ -0,0 +1,62 @@ +namespace PCLMock.CodeGeneration.Plugins +{ + using Microsoft.CodeAnalysis; + using PCLMock.CodeGeneration.Logging; + using CSharp = Microsoft.CodeAnalysis.CSharp; + + /// + /// A plugin that generates default return values for any member that returns a value. + /// + /// + /// + /// This plugin provides fallback behavior for any member that has not already had a default value generated. It should typically + /// be included last in the configured list of plugins. + /// + /// + internal sealed class Default : IPlugin + { + public static readonly Default Instance = new Default(); + + private Default() + { + } + + public string Name => "Default"; + + public Compilation InitializeCompilation(ILogSink logSink, Compilation compilation) => + compilation; + + public SyntaxNode GetDefaultValueSyntax( + Context context, + ISymbol symbol, + ITypeSymbol typeSymbol) + { + if (typeSymbol.SpecialType == SpecialType.System_Void) + { + return null; + } + + // HACK: TODO: Due to https://github.com/dotnet/roslyn/issues/43945, I am unable to use the below commented code. + // This is because it will produce `null` instead of `default(T)` for value types in referenced assemblies. + // Therefore, I generate a rather clunky `(T)default` instead. However, this is not supported by SyntaxGenerator, + // so I'm using the C#-specific SyntaxFactor to achieve this. + + //return context.SyntaxGenerator.CastExpression( + // typeSymbol, + // context.SyntaxGenerator.DefaultExpression(typeSymbol)); + + // The exact incantation was not easy to figure out here. I eventually stumbled on the answer via this SO answer: + // https://stackoverflow.com/a/46262867/5380 + var defaultKeyword = CSharp.SyntaxFactory.IdentifierName( + CSharp.SyntaxFactory.Identifier( + CSharp.SyntaxFactory.TriviaList(), + CSharp.SyntaxKind.DefaultKeyword, + "default", + "default", + CSharp.SyntaxFactory.TriviaList())); + var castExpression = context.SyntaxGenerator.CastExpression(typeSymbol, defaultKeyword); + + return castExpression; + } + } +} diff --git a/Src/PCLMock.CodeGeneration/Plugins/Disposables.cs b/Src/PCLMock.CodeGeneration/Plugins/Disposables.cs index 9e2c69a..d84ceb3 100644 --- a/Src/PCLMock.CodeGeneration/Plugins/Disposables.cs +++ b/Src/PCLMock.CodeGeneration/Plugins/Disposables.cs @@ -1,8 +1,6 @@ namespace PCLMock.CodeGeneration.Plugins { using System; - using System.Reactive.Disposables; - using System.Reflection; using Logging; using Microsoft.CodeAnalysis; @@ -24,60 +22,44 @@ namespace PCLMock.CodeGeneration.Plugins /// public sealed class Disposables : IPlugin { - private static readonly Type logSource = typeof(Disposables); - public string Name => "Disposables"; /// - public Compilation InitializeCompilation(Compilation compilation) => - compilation - .AddReferences( - MetadataReference.CreateFromFile(typeof(IDisposable).GetTypeInfo().Assembly.Location), - MetadataReference.CreateFromFile(typeof(Disposable).GetTypeInfo().Assembly.Location)); + public Compilation InitializeCompilation(ILogSink logSink, Compilation compilation) => + compilation; /// public SyntaxNode GetDefaultValueSyntax( Context context, - MockBehavior behavior, ISymbol symbol, - INamedTypeSymbol returnType) + ITypeSymbol typeSymbol) { - if (behavior == MockBehavior.Loose) - { - return null; - } - - var disposableInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.IDisposable"); + context = context + .WithLogSink( + context + .LogSink + .WithSource(typeof(Disposables))); - if (disposableInterfaceType == null) - { - context - .LogSink - .Warn(logSource, "Failed to resolve IDisposable type."); - return null; - } + var isDisposable = typeSymbol.ToDisplayString() == "System.IDisposable"; - if (returnType != disposableInterfaceType) + if (!isDisposable) { context .LogSink - .Debug(logSource, "Ignoring symbol '{0}' because its return type is not IDisposable."); + .Debug("Type is not IDisposable (it is '{0}').", typeSymbol); return null; } var disposableType = context .SemanticModel .Compilation - .GetTypeByMetadataName("System.Reactive.Disposables.Disposable"); + .GetPreferredTypeByMetadataName("System.Reactive.Disposables.Disposable", preferredAssemblyNames: new[] { "System.Reactive.Core" }); if (disposableType == null) { context .LogSink - .Debug(logSource, "Ignoring symbol '{0}' because Disposable type could not be resolved (probably a missing reference to System.Reactive.Core)."); + .Warn("The Disposable type could not be resolved (probably a missing reference to System.Reactive.Core)."); return null; } @@ -91,6 +73,10 @@ public SyntaxNode GetDefaultValueSyntax( .SyntaxGenerator .IdentifierName("Empty")); + context + .LogSink + .Debug("Generated a default value (used type '{0}' from assembly '{1}').", disposableType, disposableType.ContainingAssembly); + return result; } } diff --git a/Src/PCLMock.CodeGeneration/Plugins/ObservableBasedAsynchrony.cs b/Src/PCLMock.CodeGeneration/Plugins/ObservableBasedAsynchrony.cs index 21e9099..bd399a4 100644 --- a/Src/PCLMock.CodeGeneration/Plugins/ObservableBasedAsynchrony.cs +++ b/Src/PCLMock.CodeGeneration/Plugins/ObservableBasedAsynchrony.cs @@ -2,15 +2,12 @@ namespace PCLMock.CodeGeneration.Plugins { using System; using System.Linq; - using System.Reactive; using System.Reactive.Linq; - using System.Reflection; using Logging; using Microsoft.CodeAnalysis; /// - /// A plugin that generates appropriate default return values for any member that uses observable-based - /// asynchrony. + /// A plugin that generates appropriate default return values for any member that uses observable-based asynchrony. /// /// /// @@ -37,67 +34,56 @@ namespace PCLMock.CodeGeneration.Plugins /// public sealed class ObservableBasedAsynchrony : IPlugin { - private static readonly Type logSource = typeof(ObservableBasedAsynchrony); - public string Name => "Observable-based Asynchrony"; /// - public Compilation InitializeCompilation(Compilation compilation) => - compilation - .AddReferences( - MetadataReference.CreateFromFile(typeof(IObservable<>).GetTypeInfo().Assembly.Location), - MetadataReference.CreateFromFile(typeof(Unit).GetTypeInfo().Assembly.Location), - MetadataReference.CreateFromFile(typeof(Observable).GetTypeInfo().Assembly.Location)); + public Compilation InitializeCompilation(ILogSink logSink, Compilation compilation) => + compilation; /// public SyntaxNode GetDefaultValueSyntax( Context context, - MockBehavior behavior, ISymbol symbol, - INamedTypeSymbol returnType) + ITypeSymbol typeSymbol) { - if (behavior == MockBehavior.Loose) - { - return null; - } - - var observableInterfaceType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.IObservable`1"); + context = context + .WithLogSink( + context + .LogSink + .WithSource(typeof(ObservableBasedAsynchrony))); - var observableType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Reactive.Linq.Observable"); - - if (observableInterfaceType == null) + if (!(typeSymbol is INamedTypeSymbol namedTypeSymbol)) { context .LogSink - .Warn(logSource, "Failed to resolve System.IObservable."); + .Debug("Ignoring type '{0}' because it is not a named type symbol.", typeSymbol); return null; } - if (observableType == null) + var isObservable = namedTypeSymbol.ConstructedFrom?.ToDisplayString() == "System.IObservable"; + + if (!isObservable) { context .LogSink - .Warn(logSource, "Failed to resolve System.Reactive.Linq.Observable."); + .Debug("Type is not IObservable (it is '{0}').", namedTypeSymbol); return null; } - var isObservable = returnType.IsGenericType && returnType.ConstructedFrom == observableInterfaceType; + var observableType = context + .SemanticModel + .Compilation + .GetPreferredTypeByMetadataName("System.Reactive.Linq.Observable", preferredAssemblyNames: new[] { "System.Reactive.Linq" }); - if (!isObservable) + if (observableType == null) { context .LogSink - .Debug(logSource, "Ignoring symbol '{0}' because it does not return IObservable.", symbol); + .Debug("The Observable type could not be resolved (probably a missing reference to System.Reactive.Linq)."); return null; } - var observableInnerType = returnType.TypeArguments[0]; + var observableInnerType = namedTypeSymbol.TypeArguments[0]; SyntaxNode observableInvocation; var propertySymbol = symbol as IPropertySymbol; @@ -142,37 +128,25 @@ public SyntaxNode GetDefaultValueSyntax( .TypeExpression(observableInnerType)), arguments: new[] { - GetDefaultRecursive(context, behavior, symbol, observableInnerType) + GetDefaultRecursive(context, symbol, observableInnerType) }); } + context + .LogSink + .Debug("Generated a default value (used type '{0}' from assembly '{1}').", observableType, observableType.ContainingAssembly); + return observableInvocation; } private static SyntaxNode GetDefaultRecursive( Context context, - MockBehavior behavior, ISymbol symbol, - ITypeSymbol returnType) - { - var namedTypeSymbol = returnType as INamedTypeSymbol; - - if (namedTypeSymbol != null) - { - var recursiveDefault = context + ITypeSymbol returnType) => + context .Plugins - .Select(plugin => plugin.GetDefaultValueSyntax(context, behavior, symbol, namedTypeSymbol)) + .Select(plugin => plugin.GetDefaultValueSyntax(context, symbol, returnType)) .Where(defaultValueSyntax => defaultValueSyntax != null) .FirstOrDefault(); - - if (recursiveDefault != null) - { - return recursiveDefault; - } - } - - // recursive resolution not possible, so fallback to default(T) - return context.SyntaxGenerator.DefaultExpression(returnType); - } } } \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration/Plugins/TaskBasedAsynchrony.cs b/Src/PCLMock.CodeGeneration/Plugins/TaskBasedAsynchrony.cs index cc892d2..db118f5 100644 --- a/Src/PCLMock.CodeGeneration/Plugins/TaskBasedAsynchrony.cs +++ b/Src/PCLMock.CodeGeneration/Plugins/TaskBasedAsynchrony.cs @@ -1,20 +1,16 @@ namespace PCLMock.CodeGeneration.Plugins { - using System; using System.Linq; - using System.Reflection; - using System.Threading.Tasks; using Logging; using Microsoft.CodeAnalysis; /// - /// A plugin that generates appropriate default return values for any member that uses TPL-based - /// asynchrony. + /// A plugin that generates appropriate default return values for any member that uses TPL-based asynchrony. /// /// /// /// This plugin generates default return specifications for properties and methods that use TPL-based asynchrony. - /// SThat is, they return an object of type or + /// That is, they return an object of type or /// . In either case, a specification is generated for the member /// such that a task with a default value will be returned rather than returning . /// @@ -31,65 +27,64 @@ namespace PCLMock.CodeGeneration.Plugins /// public sealed class TaskBasedAsynchrony : IPlugin { - private static readonly Type logSource = typeof(TaskBasedAsynchrony); - public string Name => "Task-based Asynchrony"; /// - public Compilation InitializeCompilation(Compilation compilation) => - compilation - .AddReferences( - MetadataReference.CreateFromFile(typeof(Task).GetTypeInfo().Assembly.Location)); + public Compilation InitializeCompilation(ILogSink logSink, Compilation compilation) => + compilation; /// public SyntaxNode GetDefaultValueSyntax( Context context, - MockBehavior behavior, ISymbol symbol, - INamedTypeSymbol returnType) + ITypeSymbol typeSymbol) { - if (behavior == MockBehavior.Loose) + context = context + .WithLogSink( + context + .LogSink + .WithSource(typeof(TaskBasedAsynchrony))); + + if (!(typeSymbol is INamedTypeSymbol namedTypeSymbol)) { + context + .LogSink + .Debug("Ignoring type '{0}' because it is not a named type symbol.", typeSymbol); return null; } - var taskBaseType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Threading.Tasks.Task"); - - var genericTaskBaseType = context - .SemanticModel - .Compilation - .GetTypeByMetadataName("System.Threading.Tasks.Task`1"); + var isTask = namedTypeSymbol.ToDisplayString() == "System.Threading.Tasks.Task"; + var isGenericTask = namedTypeSymbol.ConstructedFrom?.ToDisplayString() == "System.Threading.Tasks.Task"; - if (taskBaseType == null || genericTaskBaseType == null) + if (!isTask && !isGenericTask) { context .LogSink - .Warn(logSource, "Failed to resolve Task classes."); + .Debug("Type is not a task (it is '{0}').", namedTypeSymbol); return null; } - var isGenericTask = returnType.IsGenericType && returnType.ConstructedFrom == genericTaskBaseType; - var isTask = returnType == taskBaseType; + var taskType = context + .SemanticModel + .Compilation + .GetPreferredTypeByMetadataName("System.Threading.Tasks.Task", preferredAssemblyNames: new[] { "System.Runtime" }); - if (!isTask && !isGenericTask) + if (taskType == null) { context .LogSink - .Debug(logSource, "Ignoring symbol '{0}' because it does not return a Task or Task.", symbol); + .Debug("The Task type could not be resolved (probably a missing reference to System.Runtime)."); return null; } - ITypeSymbol taskType = context + ITypeSymbol taskInnerType = context .SemanticModel .Compilation .GetSpecialType(SpecialType.System_Boolean); if (isGenericTask) { - taskType = returnType.TypeArguments[0]; + taskInnerType = namedTypeSymbol.TypeArguments[0]; } var fromResultInvocation = context @@ -103,43 +98,31 @@ public SyntaxNode GetDefaultValueSyntax( .MemberAccessExpression( context .SyntaxGenerator - .TypeExpression(taskBaseType), + .TypeExpression(taskType), "FromResult"), context .SyntaxGenerator - .TypeExpression(taskType)), + .TypeExpression(taskInnerType)), arguments: new[] { - GetDefaultRecursive(context, behavior, symbol, taskType) + GetDefaultRecursive(context, symbol, taskInnerType) }); + context + .LogSink + .Debug("Generated a default value (used type '{0}' from assembly '{1}').", taskType, taskType.ContainingAssembly); + return fromResultInvocation; } private static SyntaxNode GetDefaultRecursive( Context context, - MockBehavior behavior, ISymbol symbol, - ITypeSymbol returnType) - { - var namedTypeSymbol = returnType as INamedTypeSymbol; - - if (namedTypeSymbol != null) - { - var recursiveDefault = context + ITypeSymbol returnType) => + context .Plugins - .Select(plugin => plugin.GetDefaultValueSyntax(context, behavior, symbol, namedTypeSymbol)) + .Select(plugin => plugin.GetDefaultValueSyntax(context, symbol, returnType)) .Where(defaultValueSyntax => defaultValueSyntax != null) .FirstOrDefault(); - - if (recursiveDefault != null) - { - return recursiveDefault; - } - } - - // recursive resolution not possible, so fallback to default(T) - return context.SyntaxGenerator.DefaultExpression(returnType); - } } } \ No newline at end of file diff --git a/Src/PCLMock.CodeGeneration/XmlBasedGenerator.cs b/Src/PCLMock.CodeGeneration/XmlBasedGenerator.cs index 350c612..fb879dc 100644 --- a/Src/PCLMock.CodeGeneration/XmlBasedGenerator.cs +++ b/Src/PCLMock.CodeGeneration/XmlBasedGenerator.cs @@ -1,11 +1,7 @@ namespace PCLMock.CodeGeneration { - using System; using System.Collections.Immutable; using System.IO; - using System.Linq; - using System.Text; - using System.Threading.Tasks; using System.Xml.Linq; using Logging; using Microsoft.CodeAnalysis; @@ -13,56 +9,34 @@ public static class XmlBasedGenerator { - private static readonly Type logSource = typeof(XmlBasedGenerator); - - public static string GenerateMocks( - ILogSink logSink, - string solutionPath, - string xmlPath, - string language) - { - var castLanguage = (Language)Enum.Parse(typeof(Language), language); - return GenerateMocks(logSink, castLanguage, solutionPath, xmlPath); - } - - public static string GenerateMocks( + public static IImmutableList GenerateMocks( ILogSink logSink, Language language, - string solutionPath, + IImmutableList compilations, string xmlPath) { - return GenerateMocksAsync(logSink, language, solutionPath, xmlPath) - .Result - .Select(x => x.ToFullString()) - .Aggregate(new StringBuilder(), (current, next) => current.AppendLine(next), x => x.ToString()); - } + logSink = logSink + .WithSource(typeof(XmlBasedGenerator)); - public async static Task> GenerateMocksAsync( - ILogSink logSink, - Language language, - string solutionPath, - string xmlPath) - { if (!File.Exists(xmlPath)) { - var message = $"XML input file '{xmlPath}' no found."; - logSink.Error(logSource, message); - throw new IOException(message); + logSink.Error("XML input file '{0}' not found.", xmlPath); + return ImmutableList.Empty; } - logSink.Info(logSource, "Loading XML input file '{0}'.", xmlPath); + logSink.Info("Loading XML input file '{0}'.", xmlPath); var document = XDocument.Load(xmlPath); var configuration = Configuration.FromXDocument(logSink, document); - return await Generator.GenerateMocksAsync( + return Generator.GenerateMocks( logSink, language, - solutionPath, + compilations, + configuration.GetPlugins(), configuration.GetInterfacePredicate(), configuration.GetNamespaceSelector(), - configuration.GetNameSelector(), - configuration.GetPlugins()); + configuration.GetNameSelector()); } } } \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixture.cs b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixture.cs index 3242e8e..a73b81a 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixture.cs +++ b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixture.cs @@ -1,14 +1,9 @@ namespace PCLMock.UnitTests.CodeGeneration { - using System; - using System.Collections.Immutable; - using System.IO; - using System.Linq; using System.Threading.Tasks; using Microsoft.CodeAnalysis; - using Microsoft.CodeAnalysis.Text; using PCLMock.CodeGeneration; - using PCLMock.CodeGeneration.Logging; + using PCLMock.CodeGeneration.Plugins; using Xunit; public sealed class GeneratorFixture @@ -32,60 +27,14 @@ public sealed class GeneratorFixture //[InlineData("InterfaceWithNonMockableMembers", Language.VisualBasic)] //[InlineData("PartialInterface", Language.VisualBasic)] //[InlineData("InheritingInterface", Language.VisualBasic)] - public async Task can_generate_mocks(string resourceBaseName, Language language) - { - var inputResourceName = "PCLMock.UnitTests.CodeGeneration.GeneratorFixtureResources." + resourceBaseName + "Input_" + language.ToString() + ".txt"; - var outputResourceName = "PCLMock.UnitTests.CodeGeneration.GeneratorFixtureResources." + resourceBaseName + "Output_" + language.ToString() + ".txt"; - - using (var inputStream = this.GetType().Assembly.GetManifestResourceStream(inputResourceName)) - using (var outputStream = this.GetType().Assembly.GetManifestResourceStream(outputResourceName)) - using (var outputStreamReader = new StreamReader(outputStream)) - { - var workspace = new AdhocWorkspace(); - var projectId = ProjectId.CreateNewId(); - var versionStamp = VersionStamp.Create(); - var projectInfo = ProjectInfo.Create( - projectId, - versionStamp, - "AdhocProject", - "AdhocProject", - language.ToSyntaxGeneratorLanguageName(), - metadataReferences: new[] + public Task can_generate_mocks(string testName, Language language) => + Helpers.GenerateAndVerifyMocksUsingEmbeddedResources( + this.GetType(), + testName, + language, + metadataReferences: new[] { MetadataReference.CreateFromFile(typeof(object).Assembly.Location), - MetadataReference.CreateFromFile(typeof(Uri).Assembly.Location), - MetadataReference.CreateFromFile(typeof(MockBase<>).Assembly.Location) }); - var project = workspace.AddProject(projectInfo); - workspace.AddDocument(projectId, "Source.cs", SourceText.From(inputStream)); - var solution = workspace.CurrentSolution; - - var results = - (await Generator.GenerateMocksAsync( - NullLogSink.Instance, - language, - solution, - x => true, - x => "The.Namespace", - x => "Mock", - ImmutableList.Empty)); - var result = results - .Last() - .ToString() - .NormalizeLineEndings(); - - var expectedCode = outputStreamReader.ReadToEnd(); - - // make sure version changes don't break the tests - expectedCode = expectedCode - .Replace("$VERSION$", typeof(MockBase<>).Assembly.GetName().Version.ToString()) - .NormalizeLineEndings(); - - // useful when converting generated code to something that can be pasted into an expectation file - var sanitisedResult = result.Replace(typeof(MockBase<>).Assembly.GetName().Version.ToString(), "$VERSION$"); - - Assert.Equal(expectedCode, result); - } - } } } \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/DuplicateMemberInput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/DuplicateMemberInput_CSharp.txt index 9dab51f..3d5c4b1 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/DuplicateMemberInput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/DuplicateMemberInput_CSharp.txt @@ -1,6 +1,4 @@ -using System; - -public interface IFirstInterface +public interface IFirstInterface { void FirstMethod(); diff --git a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/DuplicateMemberOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/DuplicateMemberOutput_CSharp.txt index ddc3095..99ca56f 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/DuplicateMemberOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/DuplicateMemberOutput_CSharp.txt @@ -1,26 +1,115 @@ -namespace The.Namespace +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ +namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - public partial class Mock : global::PCLMock.MockBase, global::IThirdInterface + public partial class IFirstInterfaceMock : global::PCLMock.MockBase, global::IFirstInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public IFirstInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } private void ConfigureBehaviorGenerated() { + this.When(x => x.DuplicateProperty).Return((global::System.Int32)(default)); } - private void ConfigureLooseBehaviorGenerated() + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public void FirstMethod() + { + this.Apply(x => x.FirstMethod()); + } + + public global::System.Int32 DuplicateProperty { + get + { + return this.Apply(x => x.DuplicateProperty); + } + } + + public void DuplicateMethod() + { + this.Apply(x => x.DuplicateMethod()); + } + } +} +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + public partial class ISecondInterfaceMock : global::PCLMock.MockBase, global::ISecondInterface + { + public ISecondInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.DuplicateProperty).Return((global::System.Int32)(default)); + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public void SecondMethod() + { + this.Apply(x => x.SecondMethod()); + } + + public global::System.Int32 DuplicateProperty + { + get + { + return this.Apply(x => x.DuplicateProperty); + } + } + + public void DuplicateMethod() + { + this.Apply(x => x.DuplicateMethod()); + } + } +} +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + public partial class IThirdInterfaceMock : global::PCLMock.MockBase, global::IThirdInterface + { + public IThirdInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.DuplicateProperty).Return((global::System.Int32)(default)); + this.When(x => x.DuplicateProperty).Return((global::System.Int32)(default)); } partial void ConfigureBehavior(); @@ -30,9 +119,35 @@ this.Apply(x => x.FirstMethod()); } + public global::System.Int32 DuplicateProperty + { + get + { + return this.Apply(x => x.DuplicateProperty); + } + } + + public void DuplicateMethod() + { + this.Apply(x => x.DuplicateMethod()); + } + public void SecondMethod() { this.Apply(x => x.SecondMethod()); } + + global::System.Int32 global::ISecondInterface.DuplicateProperty + { + get + { + return this.Apply(x => x.DuplicateProperty); + } + } + + void global::ISecondInterface.DuplicateMethod() + { + this.Apply(x => ((global::ISecondInterface)(x)).DuplicateMethod()); + } } -} \ No newline at end of file +} diff --git a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/GenericInterfaceOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/GenericInterfaceOutput_CSharp.txt index d8c1971..f2b6cfb 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/GenericInterfaceOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/GenericInterfaceOutput_CSharp.txt @@ -1,17 +1,24 @@ -namespace The.Namespace +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ +namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - public partial class Mock : global::PCLMock.MockBase>, global::IGenericInterface where TFirst : global::System.IComparable, new() + public partial class IGenericInterfaceMock : global::PCLMock.MockBase>, global::IGenericInterface where TFirst : global::System.IComparable, new() where TSecond : struct { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public IGenericInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -20,10 +27,6 @@ { } - private void ConfigureLooseBehaviorGenerated() - { - } - partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); public TFirst SomeProperty @@ -44,4 +47,4 @@ return this.Apply(x => x.DoSomething(input)); } } -} \ No newline at end of file +} diff --git a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/IndexersOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/IndexersOutput_CSharp.txt index 936e514..9cb7bf9 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/IndexersOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/IndexersOutput_CSharp.txt @@ -1,26 +1,32 @@ -namespace The.Namespace +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ +namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - public partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + public partial class ISomeInterfaceMock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } private void ConfigureBehaviorGenerated() { - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x[global::PCLMock.It.IsAny()]).Return((global::System.Int32)(default)); + this.When(x => x[global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny()]).Return((global::System.String)(default)); + this.When(x => x[global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny()]).Return((global::System.String)(default)); } partial void ConfigureBehavior(); @@ -33,7 +39,7 @@ } } - public global::System.String this[global::System.Int32 i, global::System.Single j] + global::System.String global::ISomeInterface.this[global::System.Int32 i, global::System.Single j] { get { @@ -41,7 +47,7 @@ } } - public global::System.String this[global::System.Int32 i, global::System.Single j, global::System.Double d] + global::System.String global::ISomeInterface.this[global::System.Int32 i, global::System.Single j, global::System.Double d] { get { @@ -54,4 +60,4 @@ } } } -} \ No newline at end of file +} diff --git a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/InheritingInterfaceOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/InheritingInterfaceOutput_CSharp.txt index 5ce2653..ed957d4 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/InheritingInterfaceOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/InheritingInterfaceOutput_CSharp.txt @@ -1,26 +1,31 @@ -namespace The.Namespace +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ +namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - public partial class Mock : global::PCLMock.MockBase, global::IInheritingInterface + public partial class IInheritingInterfaceMock : global::PCLMock.MockBase, global::IInheritingInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public IInheritingInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } private void ConfigureBehaviorGenerated() { - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.SomeProperty).Return((global::System.Int32)(default)); + this.When(x => x.Clone()).Return((global::System.Object)(default)); } partial void ConfigureBehavior(); @@ -38,4 +43,4 @@ return this.Apply(x => x.Clone()); } } -} \ No newline at end of file +} diff --git a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/InterfaceWithGenericMethodsInput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/InterfaceWithGenericMethodsInput_CSharp.txt index de2882d..02c80fb 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/InterfaceWithGenericMethodsInput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/InterfaceWithGenericMethodsInput_CSharp.txt @@ -1,4 +1,6 @@ -public interface IInterfaceWithGenericMethods +using System; + +public interface IInterfaceWithGenericMethods { void VoidMethodWithGenericParameter(); diff --git a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/InterfaceWithGenericMethodsOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/InterfaceWithGenericMethodsOutput_CSharp.txt index c65ec9e..a5cd975 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/InterfaceWithGenericMethodsOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/InterfaceWithGenericMethodsOutput_CSharp.txt @@ -1,16 +1,23 @@ -namespace The.Namespace +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ +namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - public partial class Mock : global::PCLMock.MockBase, global::IInterfaceWithGenericMethods + public partial class IInterfaceWithGenericMethodsMock : global::PCLMock.MockBase, global::IInterfaceWithGenericMethods { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public IInterfaceWithGenericMethodsMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -19,10 +26,6 @@ { } - private void ConfigureLooseBehaviorGenerated() - { - } - partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); public void VoidMethodWithGenericParameter() @@ -46,10 +49,10 @@ } public TSecond MethodWithTypeConstraints(TFirst input, global::System.Int32 option) - where TFirst : IComparable, new() + where TFirst : global::System.IComparable, new() where TSecond : struct { return this.Apply(x => x.MethodWithTypeConstraints(input, option)); } } -} \ No newline at end of file +} diff --git a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/InternalInterfaceOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/InternalInterfaceOutput_CSharp.txt index e337cde..4a109c6 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/InternalInterfaceOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/InternalInterfaceOutput_CSharp.txt @@ -1,26 +1,33 @@ -namespace The.Namespace +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ +namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::IInternalInterface + internal partial class IInternalInterfaceMock : global::PCLMock.MockBase, global::IInternalInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public IInternalInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } private void ConfigureBehaviorGenerated() { - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.GetProperty).Return((global::System.Int32)(default)); + this.When(x => x.GetSetProperty).Return((global::System.Int32)(default)); + this.When(x => x.NonVoidMethod()).Return((global::System.String)(default)); + this.When(x => x.NonVoidMethodWithArguments(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return((global::System.String)(default)); } partial void ConfigureBehavior(); @@ -66,4 +73,4 @@ return this.Apply(x => x.NonVoidMethodWithArguments(i, s)); } } -} \ No newline at end of file +} diff --git a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/NameClashInput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/NameClashInput_CSharp.txt index d5f31b5..7b629fa 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/NameClashInput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/NameClashInput_CSharp.txt @@ -1,6 +1,4 @@ -using System; - -public interface ISomeInterface +public interface ISomeInterface { int this[int x] { diff --git a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/NameClashOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/NameClashOutput_CSharp.txt index 3d3bdf8..a3a1456 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/NameClashOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/NameClashOutput_CSharp.txt @@ -1,26 +1,30 @@ -namespace The.Namespace +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ +namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - public partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + public partial class ISomeInterfaceMock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } private void ConfigureBehaviorGenerated() { - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(_x => _x[global::PCLMock.It.IsAny()]).Return((global::System.Int32)(default)); } partial void ConfigureBehavior(); @@ -55,4 +59,4 @@ this.Apply(x => x.SomeMethod(out __f, _f)); } } -} \ No newline at end of file +} diff --git a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/NonMockableMembersOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/NonMockableMembersOutput_CSharp.txt index 5f1292b..7da35f8 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/NonMockableMembersOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/NonMockableMembersOutput_CSharp.txt @@ -1,26 +1,30 @@ -namespace The.Namespace +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ +namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - public partial class Mock : global::PCLMock.MockBase, global::IInterfaceWithNonMockableMembers + public partial class IInterfaceWithNonMockableMembersMock : global::PCLMock.MockBase, global::IInterfaceWithNonMockableMembers { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public IInterfaceWithNonMockableMembersMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } private void ConfigureBehaviorGenerated() { - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.SomeProperty).Return((global::System.Int32)(default)); } partial void ConfigureBehavior(); @@ -38,4 +42,4 @@ } } } -} \ No newline at end of file +} diff --git a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/OutAndRefOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/OutAndRefOutput_CSharp.txt index e736939..331f67a 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/OutAndRefOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/OutAndRefOutput_CSharp.txt @@ -1,16 +1,23 @@ -namespace The.Namespace +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ +namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - public partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + public partial class ISomeInterfaceMock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -19,10 +26,6 @@ { } - private void ConfigureLooseBehaviorGenerated() - { - } - partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); public void SomeMethod(out global::System.Int32 i) @@ -64,4 +67,4 @@ this.Apply(x => x.SomeMethod(ref _i, out _s, d)); } } -} \ No newline at end of file +} diff --git a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/PartialInterfaceOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/PartialInterfaceOutput_CSharp.txt index a93ebdf..e986957 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/PartialInterfaceOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/PartialInterfaceOutput_CSharp.txt @@ -1,26 +1,31 @@ -namespace The.Namespace +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ +namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - public partial class Mock : global::PCLMock.MockBase, global::IPartialInterface + public partial class IPartialInterfaceMock : global::PCLMock.MockBase, global::IPartialInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public IPartialInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } private void ConfigureBehaviorGenerated() { - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.Property1).Return((global::System.Int32)(default)); + this.When(x => x.Property2).Return((global::System.Int32)(default)); } partial void ConfigureBehavior(); @@ -41,4 +46,4 @@ } } } -} \ No newline at end of file +} diff --git a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceOutput_CSharp.txt index 9bd310d..971ddab 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceOutput_CSharp.txt @@ -1,26 +1,33 @@ -namespace The.Namespace +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ +namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - public partial class Mock : global::PCLMock.MockBase, global::ISimpleInterface + public partial class ISimpleInterfaceMock : global::PCLMock.MockBase, global::ISimpleInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISimpleInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } private void ConfigureBehaviorGenerated() { - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.GetProperty).Return((global::System.Int32)(default)); + this.When(x => x.GetSetProperty).Return((global::System.Int32)(default)); + this.When(x => x.NonVoidMethod()).Return((global::System.String)(default)); + this.When(x => x.NonVoidMethodWithArguments(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return((global::System.String)(default)); } partial void ConfigureBehavior(); @@ -66,4 +73,4 @@ return this.Apply(x => x.NonVoidMethodWithArguments(i, s)); } } -} \ No newline at end of file +} diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixture.cs b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixture.cs index fe29c93..971505f 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixture.cs +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixture.cs @@ -1,16 +1,11 @@ namespace PCLMock.UnitTests.CodeGeneration.Plugins { - using System; + using System.Collections.Generic; using System.Collections.Immutable; - using System.IO; using System.Linq; - using System.Reactive.Linq; - using System.Text; using System.Threading.Tasks; using Microsoft.CodeAnalysis; - using Microsoft.CodeAnalysis.Text; using PCLMock.CodeGeneration; - using PCLMock.CodeGeneration.Logging; using PCLMock.CodeGeneration.Plugins; using Xunit; @@ -28,75 +23,21 @@ public sealed class CollectionsFixture [InlineData("ImmutableSets", Language.CSharp)] [InlineData("ImmutableStacks", Language.CSharp)] [InlineData("Recursive", Language.CSharp)] - public async Task can_generate_mocks(string resourceBaseName, Language language) - { - var inputResourceName = "PCLMock.UnitTests.CodeGeneration.Plugins.CollectionsFixtureResources." + resourceBaseName + "Input_" + language.ToString() + ".txt"; - var outputResourceName = "PCLMock.UnitTests.CodeGeneration.Plugins.CollectionsFixtureResources." + resourceBaseName + "Output_" + language.ToString() + ".txt"; - - using (var inputStream = this.GetType().Assembly.GetManifestResourceStream(inputResourceName)) - using (var outputStream = this.GetType().Assembly.GetManifestResourceStream(outputResourceName)) - using (var outputStreamReader = new StreamReader(outputStream)) - { - var workspace = new AdhocWorkspace(); - var projectId = ProjectId.CreateNewId(); - var versionStamp = VersionStamp.Create(); - var projectInfo = ProjectInfo.Create( - projectId, - versionStamp, - "AdhocProject", - "AdhocProject", - language.ToSyntaxGeneratorLanguageName(), - metadataReferences: new[] + public Task can_generate_mocks(string testName, Language language) => + Helpers.GenerateAndVerifyMocksUsingEmbeddedResources( + this.GetType(), + testName, + language, + metadataReferences: new[] { MetadataReference.CreateFromFile(typeof(object).Assembly.Location), - MetadataReference.CreateFromFile(typeof(Uri).Assembly.Location), - MetadataReference.CreateFromFile(typeof(MockBase<>).Assembly.Location), MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location), - MetadataReference.CreateFromFile(typeof(ImmutableList).Assembly.Location) + MetadataReference.CreateFromFile(typeof(HashSet<>).Assembly.Location), + MetadataReference.CreateFromFile(typeof(ImmutableList).Assembly.Location), + }, + new IPlugin[] + { + new Collections(), }); - var project = workspace.AddProject(projectInfo); - workspace.AddDocument(projectId, "Source.cs", SourceText.From(inputStream)); - var solution = workspace.CurrentSolution; - - var results = - (await Generator.GenerateMocksAsync( - NullLogSink.Instance, - language, - solution, - x => true, - x => "The.Namespace", - x => "Mock", - new IPlugin[] - { - new Collections() - }.ToImmutableList())); - var result = results - .Aggregate( - new StringBuilder(), - (acc, next) => - { - if (next != null) - { - acc.AppendLine(next.ToFullString()); - } - - return acc; - }, - acc => acc.ToString()) - .NormalizeLineEndings(); - - var expectedCode = outputStreamReader.ReadToEnd(); - - // make sure version changes don't break the tests - expectedCode = expectedCode - .Replace("$VERSION$", typeof(MockBase<>).Assembly.GetName().Version.ToString()) - .NormalizeLineEndings(); - - // useful when converting generated code to something that can be pasted into an expectation file - var sanitisedResult = result.Replace(typeof(MockBase<>).Assembly.GetName().Version.ToString(), "$VERSION$"); - - Assert.Equal(expectedCode, result); - } - } } } \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/CollectionsInput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/CollectionsInput_CSharp.txt index 1c237cf..7122fd2 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/CollectionsInput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/CollectionsInput_CSharp.txt @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; interface ICustomCollection : ICollection @@ -36,8 +35,8 @@ interface ISomeInterface get; } - ICustomCollection SomeMethod(); - ICustomCollection SomeMethod(int i, float f); + ICustomCollection SomeOtherMethod(); + ICustomCollection SomeOtherMethod(int i, float f); } interface ISomeGenericInterface @@ -49,4 +48,15 @@ interface ISomeGenericInterface ICollection SomeMethod(); ICollection SomeMethod(int i, float f); +} + +namespace The.Namespace +{ + internal partial class ISomeInterfaceMock + { + public ICollection SomeSetOnlyProperty + { + set {} + } + } } \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/CollectionsOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/CollectionsOutput_CSharp.txt index d110a16..c42cb82 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/CollectionsOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/CollectionsOutput_CSharp.txt @@ -10,25 +10,26 @@ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ICustomCollection + internal partial class ICustomCollectionMock : global::PCLMock.MockBase>, global::ICustomCollection { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ICustomCollectionMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } private void ConfigureBehaviorGenerated() { - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.Contains(global::PCLMock.It.IsAny())).Return((global::System.Boolean)(default)); + this.When(x => x.Remove(global::PCLMock.It.IsAny())).Return((global::System.Boolean)(default)); + this.When(x => x.Count).Return((global::System.Int32)(default)); + this.When(x => x.IsReadOnly).Return((global::System.Boolean)(default)); + this.When(x => x.GetEnumerator()).Return((global::System.Collections.Generic.IEnumerator)(default)); + this.When(x => ((global::System.Collections.IEnumerable)(x)).GetEnumerator()).Return((global::System.Collections.IEnumerator)(default)); } partial void ConfigureBehavior(); @@ -78,21 +79,25 @@ namespace The.Namespace { return this.Apply(x => x.GetEnumerator()); } + + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() + { + return this.Apply(x => ((global::System.Collections.IEnumerable)(x)).GetEnumerator()); + } } } namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + internal partial class ISomeInterfaceMock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -103,10 +108,9 @@ namespace The.Namespace this.When(x => x.SomeReadOnlyProperty).Return(new global::System.Collections.Generic.List()); this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.List()); this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.List()); - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.SomeCustomProperty).Return((global::ICustomCollection)(default)); + this.When(x => x.SomeOtherMethod()).Return((global::ICustomCollection)(default)); + this.When(x => x.SomeOtherMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return((global::ICustomCollection)(default)); } partial void ConfigureBehavior(); @@ -155,14 +159,14 @@ namespace The.Namespace } } - public global::ICustomCollection SomeMethod() + public global::ICustomCollection SomeOtherMethod() { - return this.Apply(x => x.SomeMethod()); + return this.Apply(x => x.SomeOtherMethod()); } - public global::ICustomCollection SomeMethod(global::System.Int32 i, global::System.Single f) + public global::ICustomCollection SomeOtherMethod(global::System.Int32 i, global::System.Single f) { - return this.Apply(x => x.SomeMethod(i, f)); + return this.Apply(x => x.SomeOtherMethod(i, f)); } } } @@ -170,15 +174,14 @@ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface + internal partial class ISomeGenericInterfaceMock : global::PCLMock.MockBase>, global::ISomeGenericInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeGenericInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -190,10 +193,6 @@ namespace The.Namespace this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.List()); } - private void ConfigureLooseBehaviorGenerated() - { - } - partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); public global::System.Collections.Generic.ICollection SomeProperty diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/DictionariesInput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/DictionariesInput_CSharp.txt index be2eb9f..27df3f5 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/DictionariesInput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/DictionariesInput_CSharp.txt @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; interface ICustomDictionary : IDictionary @@ -36,8 +35,8 @@ interface ISomeInterface get; } - ICustomDictionary SomeMethod(); - ICustomDictionary SomeMethod(int i, float f); + ICustomDictionary SomeOtherMethod(); + ICustomDictionary SomeOtherMethod(int i, float f); } interface ISomeGenericInterface @@ -49,4 +48,15 @@ interface ISomeGenericInterface IDictionary SomeMethod(); IDictionary SomeMethod(int i, float f); +} + +namespace The.Namespace +{ + internal partial class ISomeInterfaceMock + { + public ICollection SomeSetOnlyProperty + { + set {} + } + } } \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/DictionariesOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/DictionariesOutput_CSharp.txt index f4dfdf3..0a121b6 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/DictionariesOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/DictionariesOutput_CSharp.txt @@ -10,27 +10,31 @@ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ICustomDictionary + internal partial class ICustomDictionaryMock : global::PCLMock.MockBase>, global::ICustomDictionary { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ICustomDictionaryMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } private void ConfigureBehaviorGenerated() { + this.When(x => x.ContainsKey(global::PCLMock.It.IsAny())).Return((global::System.Boolean)(default)); + this.When(x => x.Remove(global::PCLMock.It.IsAny())).Return((global::System.Boolean)(default)); + this.When(x => x.TryGetValue(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return((global::System.Boolean)(default)); this.When(x => x.Keys).Return(new global::System.Collections.Generic.List()); this.When(x => x.Values).Return(new global::System.Collections.Generic.List()); - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.Contains(global::PCLMock.It.IsAny>())).Return((global::System.Boolean)(default)); + this.When(x => x.Remove(global::PCLMock.It.IsAny>())).Return((global::System.Boolean)(default)); + this.When(x => x.Count).Return((global::System.Int32)(default)); + this.When(x => x.IsReadOnly).Return((global::System.Boolean)(default)); + this.When(x => x.GetEnumerator()).Return((global::System.Collections.Generic.IEnumerator>)(default)); + this.When(x => ((global::System.Collections.IEnumerable)(x)).GetEnumerator()).Return((global::System.Collections.IEnumerator)(default)); } partial void ConfigureBehavior(); @@ -126,21 +130,30 @@ namespace The.Namespace return this.Apply(x => x.IsReadOnly); } } + + public global::System.Collections.Generic.IEnumerator> GetEnumerator() + { + return this.Apply(x => x.GetEnumerator()); + } + + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() + { + return this.Apply(x => ((global::System.Collections.IEnumerable)(x)).GetEnumerator()); + } } } namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + internal partial class ISomeInterfaceMock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -151,10 +164,9 @@ namespace The.Namespace this.When(x => x.SomeReadOnlyProperty).Return(new global::System.Collections.Generic.Dictionary()); this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.Dictionary()); this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.Dictionary()); - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.SomeCustomProperty).Return((global::ICustomDictionary)(default)); + this.When(x => x.SomeOtherMethod()).Return((global::ICustomDictionary)(default)); + this.When(x => x.SomeOtherMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return((global::ICustomDictionary)(default)); } partial void ConfigureBehavior(); @@ -203,14 +215,14 @@ namespace The.Namespace } } - public global::ICustomDictionary SomeMethod() + public global::ICustomDictionary SomeOtherMethod() { - return this.Apply(x => x.SomeMethod()); + return this.Apply(x => x.SomeOtherMethod()); } - public global::ICustomDictionary SomeMethod(global::System.Int32 i, global::System.Single f) + public global::ICustomDictionary SomeOtherMethod(global::System.Int32 i, global::System.Single f) { - return this.Apply(x => x.SomeMethod(i, f)); + return this.Apply(x => x.SomeOtherMethod(i, f)); } } } @@ -218,15 +230,14 @@ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface + internal partial class ISomeGenericInterfaceMock : global::PCLMock.MockBase>, global::ISomeGenericInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeGenericInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -238,10 +249,6 @@ namespace The.Namespace this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.Dictionary()); } - private void ConfigureLooseBehaviorGenerated() - { - } - partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); public global::System.Collections.Generic.IDictionary SomeProperty diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/EnumerablesInput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/EnumerablesInput_CSharp.txt index 305935d..5b768ae 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/EnumerablesInput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/EnumerablesInput_CSharp.txt @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; interface ICustomEnumerable : IEnumerable @@ -31,8 +30,8 @@ interface ISomeInterface get; } - ICustomEnumerable SomeMethod(); - ICustomEnumerable SomeMethod(int i, float f); + ICustomEnumerable SomeOtherMethod(); + ICustomEnumerable SomeOtherMethod(int i, float f); } interface ISomeGenericInterface @@ -44,4 +43,15 @@ interface ISomeGenericInterface IEnumerable SomeMethod(); IEnumerable SomeMethod(int i, float f); +} + +namespace The.Namespace +{ + internal partial class ISomeInterfaceMock + { + public ICollection SomeSetOnlyProperty + { + set {} + } + } } \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/EnumerablesOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/EnumerablesOutput_CSharp.txt index e910ee1..4333aec 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/EnumerablesOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/EnumerablesOutput_CSharp.txt @@ -10,25 +10,22 @@ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ICustomEnumerable + internal partial class ICustomEnumerableMock : global::PCLMock.MockBase>, global::ICustomEnumerable { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ICustomEnumerableMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } private void ConfigureBehaviorGenerated() { - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.GetEnumerator()).Return((global::System.Collections.Generic.IEnumerator)(default)); + this.When(x => ((global::System.Collections.IEnumerable)(x)).GetEnumerator()).Return((global::System.Collections.IEnumerator)(default)); } partial void ConfigureBehavior(); @@ -38,9 +35,9 @@ namespace The.Namespace return this.Apply(x => x.GetEnumerator()); } - public global::System.Collections.IEnumerator GetEnumerator() + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { - return this.Apply(x => x.GetEnumerator()); + return this.Apply(x => ((global::System.Collections.IEnumerable)(x)).GetEnumerator()); } } } @@ -48,15 +45,14 @@ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + internal partial class ISomeInterfaceMock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -66,10 +62,9 @@ namespace The.Namespace this.When(x => x.SomeProperty).Return(global::System.Linq.Enumerable.Empty()); this.When(x => x.SomeMethod()).Return(global::System.Linq.Enumerable.Empty()); this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Linq.Enumerable.Empty()); - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.SomeCustomProperty).Return((global::ICustomEnumerable)(default)); + this.When(x => x.SomeOtherMethod()).Return((global::ICustomEnumerable)(default)); + this.When(x => x.SomeOtherMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return((global::ICustomEnumerable)(default)); } partial void ConfigureBehavior(); @@ -110,14 +105,14 @@ namespace The.Namespace } } - public global::ICustomEnumerable SomeMethod() + public global::ICustomEnumerable SomeOtherMethod() { - return this.Apply(x => x.SomeMethod()); + return this.Apply(x => x.SomeOtherMethod()); } - public global::ICustomEnumerable SomeMethod(global::System.Int32 i, global::System.Single f) + public global::ICustomEnumerable SomeOtherMethod(global::System.Int32 i, global::System.Single f) { - return this.Apply(x => x.SomeMethod(i, f)); + return this.Apply(x => x.SomeOtherMethod(i, f)); } } } @@ -125,15 +120,14 @@ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface + internal partial class ISomeGenericInterfaceMock : global::PCLMock.MockBase>, global::ISomeGenericInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeGenericInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -145,10 +139,6 @@ namespace The.Namespace this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Linq.Enumerable.Empty()); } - private void ConfigureLooseBehaviorGenerated() - { - } - partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); public global::System.Collections.Generic.IEnumerable SomeProperty diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableDictionariesInput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableDictionariesInput_CSharp.txt index 392a383..ebaf93b 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableDictionariesInput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableDictionariesInput_CSharp.txt @@ -1,4 +1,4 @@ -using System; +using System.Collections.Generic; using System.Collections.Immutable; interface ICustomImmutableDictionary : IImmutableDictionary @@ -31,8 +31,8 @@ interface ISomeInterface get; } - ICustomImmutableDictionary SomeMethod(); - ICustomImmutableDictionary SomeMethod(int i, float f); + ICustomImmutableDictionary SomeOtherMethod(); + ICustomImmutableDictionary SomeOtherMethod(int i, float f); } interface ISomeGenericInterface @@ -44,4 +44,15 @@ interface ISomeGenericInterface IImmutableDictionary SomeMethod(); IImmutableDictionary SomeMethod(int i, float f); +} + +namespace The.Namespace +{ + internal partial class ISomeInterfaceMock + { + public ICollection SomeSetOnlyProperty + { + set {} + } + } } \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableDictionariesOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableDictionariesOutput_CSharp.txt index 891f1c1..97bcc67 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableDictionariesOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableDictionariesOutput_CSharp.txt @@ -10,15 +10,14 @@ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ICustomImmutableDictionary + internal partial class ICustomImmutableDictionaryMock : global::PCLMock.MockBase>, global::ICustomImmutableDictionary { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ICustomImmutableDictionaryMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -32,10 +31,15 @@ namespace The.Namespace this.When(x => x.SetItems(global::PCLMock.It.IsAny>>())).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); this.When(x => x.RemoveRange(global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); this.When(x => x.Remove(global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.Contains(global::PCLMock.It.IsAny>())).Return((global::System.Boolean)(default)); + this.When(x => x.TryGetKey(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return((global::System.Boolean)(default)); + this.When(x => x.ContainsKey(global::PCLMock.It.IsAny())).Return((global::System.Boolean)(default)); + this.When(x => x.TryGetValue(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return((global::System.Boolean)(default)); + this.When(x => x.Keys).Return(global::System.Linq.Enumerable.Empty()); + this.When(x => x.Values).Return(global::System.Linq.Enumerable.Empty()); + this.When(x => x.Count).Return((global::System.Int32)(default)); + this.When(x => x.GetEnumerator()).Return((global::System.Collections.Generic.IEnumerator>)(default)); + this.When(x => ((global::System.Collections.IEnumerable)(x)).GetEnumerator()).Return((global::System.Collections.IEnumerator)(default)); } partial void ConfigureBehavior(); @@ -86,21 +90,74 @@ namespace The.Namespace actualKey = (this.GetOutParameterValue(x => x.TryGetKey(equalKey, out _actualKey), 1)); return this.Apply(x => x.TryGetKey(equalKey, out _actualKey)); } + + public global::System.Boolean ContainsKey(TKey key) + { + return this.Apply(x => x.ContainsKey(key)); + } + + public global::System.Boolean TryGetValue(TKey key, out TValue value) + { + TValue _value; + value = (this.GetOutParameterValue(x => x.TryGetValue(key, out _value), 1)); + return this.Apply(x => x.TryGetValue(key, out _value)); + } + + public TValue this[TKey key] + { + get + { + return this.Apply(x => x[key]); + } + } + + public global::System.Collections.Generic.IEnumerable Keys + { + get + { + return this.Apply(x => x.Keys); + } + } + + public global::System.Collections.Generic.IEnumerable Values + { + get + { + return this.Apply(x => x.Values); + } + } + + public global::System.Int32 Count + { + get + { + return this.Apply(x => x.Count); + } + } + + public global::System.Collections.Generic.IEnumerator> GetEnumerator() + { + return this.Apply(x => x.GetEnumerator()); + } + + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() + { + return this.Apply(x => ((global::System.Collections.IEnumerable)(x)).GetEnumerator()); + } } } namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + internal partial class ISomeInterfaceMock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -110,10 +167,9 @@ namespace The.Namespace this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.SomeCustomProperty).Return((global::ICustomImmutableDictionary)(default)); + this.When(x => x.SomeOtherMethod()).Return((global::ICustomImmutableDictionary)(default)); + this.When(x => x.SomeOtherMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return((global::ICustomImmutableDictionary)(default)); } partial void ConfigureBehavior(); @@ -154,14 +210,14 @@ namespace The.Namespace } } - public global::ICustomImmutableDictionary SomeMethod() + public global::ICustomImmutableDictionary SomeOtherMethod() { - return this.Apply(x => x.SomeMethod()); + return this.Apply(x => x.SomeOtherMethod()); } - public global::ICustomImmutableDictionary SomeMethod(global::System.Int32 i, global::System.Single f) + public global::ICustomImmutableDictionary SomeOtherMethod(global::System.Int32 i, global::System.Single f) { - return this.Apply(x => x.SomeMethod(i, f)); + return this.Apply(x => x.SomeOtherMethod(i, f)); } } } @@ -169,15 +225,14 @@ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface + internal partial class ISomeGenericInterfaceMock : global::PCLMock.MockBase>, global::ISomeGenericInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeGenericInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -189,10 +244,6 @@ namespace The.Namespace this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); } - private void ConfigureLooseBehaviorGenerated() - { - } - partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); public global::System.Collections.Immutable.IImmutableDictionary SomeProperty diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableListsInput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableListsInput_CSharp.txt index e5d2523..e61d70c 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableListsInput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableListsInput_CSharp.txt @@ -1,4 +1,4 @@ -using System; +using System.Collections.Generic; using System.Collections.Immutable; interface ICustomImmutableList : IImmutableList @@ -26,13 +26,13 @@ interface ISomeInterface IImmutableList SomeOtherGenericMethod(); // should be ignored because they're a custom enumerable type - ICustomIImmutableList SomeCustomProperty + ICustomImmutableList SomeCustomProperty { get; } - ICustomIImmutableList SomeMethod(); - ICustomIImmutableList SomeMethod(int i, float f); + ICustomImmutableList SomeOtherMethod(); + ICustomImmutableList SomeOtherMethod(int i, float f); } interface ISomeGenericInterface @@ -44,4 +44,15 @@ interface ISomeGenericInterface IImmutableList SomeMethod(); IImmutableList SomeMethod(int i, float f); +} + +namespace The.Namespace +{ + internal partial class ISomeInterfaceMock + { + public ICollection SomeSetOnlyProperty + { + set {} + } + } } \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableListsOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableListsOutput_CSharp.txt index 0f48725..d0d88d8 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableListsOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableListsOutput_CSharp.txt @@ -10,15 +10,14 @@ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ICustomImmutableList + internal partial class ICustomImmutableListMock : global::PCLMock.MockBase>, global::ICustomImmutableList { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ICustomImmutableListMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -26,21 +25,22 @@ namespace The.Namespace private void ConfigureBehaviorGenerated() { this.When(x => x.Clear()).Return(global::System.Collections.Immutable.ImmutableList.Empty); + this.When(x => x.IndexOf(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny?>())).Return((global::System.Int32)(default)); + this.When(x => x.LastIndexOf(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny?>())).Return((global::System.Int32)(default)); this.When(x => x.Add(global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); this.When(x => x.AddRange(global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableList.Empty); this.When(x => x.Insert(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); this.When(x => x.InsertRange(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableList.Empty); - this.When(x => x.Remove(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableList.Empty); + this.When(x => x.Remove(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny?>())).Return(global::System.Collections.Immutable.ImmutableList.Empty); this.When(x => x.RemoveAll(global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableList.Empty); - this.When(x => x.RemoveRange(global::PCLMock.It.IsAny>(), global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableList.Empty); + this.When(x => x.RemoveRange(global::PCLMock.It.IsAny>(), global::PCLMock.It.IsAny?>())).Return(global::System.Collections.Immutable.ImmutableList.Empty); this.When(x => x.RemoveRange(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); this.When(x => x.RemoveAt(global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); this.When(x => x.SetItem(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); - this.When(x => x.Replace(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableList.Empty); - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.Replace(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny?>())).Return(global::System.Collections.Immutable.ImmutableList.Empty); + this.When(x => x.Count).Return((global::System.Int32)(default)); + this.When(x => x.GetEnumerator()).Return((global::System.Collections.Generic.IEnumerator)(default)); + this.When(x => ((global::System.Collections.IEnumerable)(x)).GetEnumerator()).Return((global::System.Collections.IEnumerator)(default)); } partial void ConfigureBehavior(); @@ -50,12 +50,12 @@ namespace The.Namespace return this.Apply(x => x.Clear()); } - public global::System.Int32 IndexOf(T item, global::System.Int32 index, global::System.Int32 count, global::System.Collections.Generic.IEqualityComparer equalityComparer) + public global::System.Int32 IndexOf(T item, global::System.Int32 index, global::System.Int32 count, global::System.Collections.Generic.IEqualityComparer? equalityComparer) { return this.Apply(x => x.IndexOf(item, index, count, equalityComparer)); } - public global::System.Int32 LastIndexOf(T item, global::System.Int32 index, global::System.Int32 count, global::System.Collections.Generic.IEqualityComparer equalityComparer) + public global::System.Int32 LastIndexOf(T item, global::System.Int32 index, global::System.Int32 count, global::System.Collections.Generic.IEqualityComparer? equalityComparer) { return this.Apply(x => x.LastIndexOf(item, index, count, equalityComparer)); } @@ -80,7 +80,7 @@ namespace The.Namespace return this.Apply(x => x.InsertRange(index, items)); } - public global::System.Collections.Immutable.IImmutableList Remove(T value, global::System.Collections.Generic.IEqualityComparer equalityComparer) + public global::System.Collections.Immutable.IImmutableList Remove(T value, global::System.Collections.Generic.IEqualityComparer? equalityComparer) { return this.Apply(x => x.Remove(value, equalityComparer)); } @@ -90,7 +90,7 @@ namespace The.Namespace return this.Apply(x => x.RemoveAll(match)); } - public global::System.Collections.Immutable.IImmutableList RemoveRange(global::System.Collections.Generic.IEnumerable items, global::System.Collections.Generic.IEqualityComparer equalityComparer) + public global::System.Collections.Immutable.IImmutableList RemoveRange(global::System.Collections.Generic.IEnumerable items, global::System.Collections.Generic.IEqualityComparer? equalityComparer) { return this.Apply(x => x.RemoveRange(items, equalityComparer)); } @@ -110,25 +110,50 @@ namespace The.Namespace return this.Apply(x => x.SetItem(index, value)); } - public global::System.Collections.Immutable.IImmutableList Replace(T oldValue, T newValue, global::System.Collections.Generic.IEqualityComparer equalityComparer) + public global::System.Collections.Immutable.IImmutableList Replace(T oldValue, T newValue, global::System.Collections.Generic.IEqualityComparer? equalityComparer) { return this.Apply(x => x.Replace(oldValue, newValue, equalityComparer)); } + + public T this[global::System.Int32 index] + { + get + { + return this.Apply(x => x[index]); + } + } + + public global::System.Int32 Count + { + get + { + return this.Apply(x => x.Count); + } + } + + public global::System.Collections.Generic.IEnumerator GetEnumerator() + { + return this.Apply(x => x.GetEnumerator()); + } + + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() + { + return this.Apply(x => ((global::System.Collections.IEnumerable)(x)).GetEnumerator()); + } } } namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + internal partial class ISomeInterfaceMock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -138,10 +163,9 @@ namespace The.Namespace this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableList.Empty); this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableList.Empty); this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.SomeCustomProperty).Return((global::ICustomImmutableList)(default)); + this.When(x => x.SomeOtherMethod()).Return((global::ICustomImmutableList)(default)); + this.When(x => x.SomeOtherMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return((global::ICustomImmutableList)(default)); } partial void ConfigureBehavior(); @@ -174,7 +198,7 @@ namespace The.Namespace return this.Apply(x => x.SomeOtherGenericMethod()); } - public ICustomIImmutableList SomeCustomProperty + public global::ICustomImmutableList SomeCustomProperty { get { @@ -182,14 +206,14 @@ namespace The.Namespace } } - public ICustomIImmutableList SomeMethod() + public global::ICustomImmutableList SomeOtherMethod() { - return this.Apply(x => x.SomeMethod()); + return this.Apply(x => x.SomeOtherMethod()); } - public ICustomIImmutableList SomeMethod(global::System.Int32 i, global::System.Single f) + public global::ICustomImmutableList SomeOtherMethod(global::System.Int32 i, global::System.Single f) { - return this.Apply(x => x.SomeMethod(i, f)); + return this.Apply(x => x.SomeOtherMethod(i, f)); } } } @@ -197,15 +221,14 @@ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface + internal partial class ISomeGenericInterfaceMock : global::PCLMock.MockBase>, global::ISomeGenericInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeGenericInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -217,10 +240,6 @@ namespace The.Namespace this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); } - private void ConfigureLooseBehaviorGenerated() - { - } - partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); public global::System.Collections.Immutable.IImmutableList SomeProperty diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableQueuesInput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableQueuesInput_CSharp.txt index 3daf01d..ec78e2c 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableQueuesInput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableQueuesInput_CSharp.txt @@ -1,4 +1,4 @@ -using System; +using System.Collections.Generic; using System.Collections.Immutable; interface ICustomImmutableQueue : IImmutableQueue @@ -26,13 +26,13 @@ interface ISomeInterface IImmutableQueue SomeOtherGenericMethod(); // should be ignored because they're a custom enumerable type - ICustomIImmutableQueue SomeCustomProperty + ICustomImmutableQueue SomeCustomProperty { get; } - ICustomIImmutableQueue SomeMethod(); - ICustomIImmutableQueue SomeMethod(int i, float f); + ICustomImmutableQueue SomeOtherMethod(); + ICustomImmutableQueue SomeOtherMethod(int i, float f); } interface ISomeGenericInterface @@ -44,4 +44,15 @@ interface ISomeGenericInterface IImmutableQueue SomeMethod(); IImmutableQueue SomeMethod(int i, float f); +} + +namespace The.Namespace +{ + internal partial class ISomeInterfaceMock + { + public ICollection SomeSetOnlyProperty + { + set {} + } + } } \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableQueuesOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableQueuesOutput_CSharp.txt index 38fddc7..f73f4fb 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableQueuesOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableQueuesOutput_CSharp.txt @@ -10,15 +10,14 @@ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ICustomImmutableQueue + internal partial class ICustomImmutableQueueMock : global::PCLMock.MockBase>, global::ICustomImmutableQueue { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ICustomImmutableQueueMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -28,10 +27,9 @@ namespace The.Namespace this.When(x => x.Clear()).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); this.When(x => x.Enqueue(global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); this.When(x => x.Dequeue()).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.IsEmpty).Return((global::System.Boolean)(default)); + this.When(x => x.GetEnumerator()).Return((global::System.Collections.Generic.IEnumerator)(default)); + this.When(x => ((global::System.Collections.IEnumerable)(x)).GetEnumerator()).Return((global::System.Collections.IEnumerator)(default)); } partial void ConfigureBehavior(); @@ -63,21 +61,30 @@ namespace The.Namespace return this.Apply(x => x.IsEmpty); } } + + public global::System.Collections.Generic.IEnumerator GetEnumerator() + { + return this.Apply(x => x.GetEnumerator()); + } + + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() + { + return this.Apply(x => ((global::System.Collections.IEnumerable)(x)).GetEnumerator()); + } } } namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + internal partial class ISomeInterfaceMock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -87,10 +94,9 @@ namespace The.Namespace this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.SomeCustomProperty).Return((global::ICustomImmutableQueue)(default)); + this.When(x => x.SomeOtherMethod()).Return((global::ICustomImmutableQueue)(default)); + this.When(x => x.SomeOtherMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return((global::ICustomImmutableQueue)(default)); } partial void ConfigureBehavior(); @@ -123,7 +129,7 @@ namespace The.Namespace return this.Apply(x => x.SomeOtherGenericMethod()); } - public ICustomIImmutableQueue SomeCustomProperty + public global::ICustomImmutableQueue SomeCustomProperty { get { @@ -131,14 +137,14 @@ namespace The.Namespace } } - public ICustomIImmutableQueue SomeMethod() + public global::ICustomImmutableQueue SomeOtherMethod() { - return this.Apply(x => x.SomeMethod()); + return this.Apply(x => x.SomeOtherMethod()); } - public ICustomIImmutableQueue SomeMethod(global::System.Int32 i, global::System.Single f) + public global::ICustomImmutableQueue SomeOtherMethod(global::System.Int32 i, global::System.Single f) { - return this.Apply(x => x.SomeMethod(i, f)); + return this.Apply(x => x.SomeOtherMethod(i, f)); } } } @@ -146,15 +152,14 @@ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface + internal partial class ISomeGenericInterfaceMock : global::PCLMock.MockBase>, global::ISomeGenericInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeGenericInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -166,10 +171,6 @@ namespace The.Namespace this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); } - private void ConfigureLooseBehaviorGenerated() - { - } - partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); public global::System.Collections.Immutable.IImmutableQueue SomeProperty diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableSetsInput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableSetsInput_CSharp.txt index 13addfd..552599f 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableSetsInput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableSetsInput_CSharp.txt @@ -1,4 +1,4 @@ -using System; +using System.Collections.Generic; using System.Collections.Immutable; interface ICustomImmutableSet : IImmutableSet @@ -26,13 +26,13 @@ interface ISomeInterface IImmutableSet SomeOtherGenericMethod(); // should be ignored because they're a custom enumerable type - ICustomIImmutableSet SomeCustomProperty + ICustomImmutableSet SomeCustomProperty { get; } - ICustomIImmutableSet SomeMethod(); - ICustomIImmutableSet SomeMethod(int i, float f); + ICustomImmutableSet SomeOtherMethod(); + ICustomImmutableSet SomeOtherMethod(int i, float f); } interface ISomeGenericInterface @@ -44,4 +44,15 @@ interface ISomeGenericInterface IImmutableSet SomeMethod(); IImmutableSet SomeMethod(int i, float f); +} + +namespace The.Namespace +{ + internal partial class ISomeInterfaceMock + { + public ICollection SomeSetOnlyProperty + { + set {} + } + } } \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableSetsOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableSetsOutput_CSharp.txt index a5dc5a6..4d47b35 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableSetsOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableSetsOutput_CSharp.txt @@ -10,15 +10,14 @@ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ICustomImmutableSet + internal partial class ICustomImmutableSetMock : global::PCLMock.MockBase>, global::ICustomImmutableSet { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ICustomImmutableSetMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -26,16 +25,23 @@ namespace The.Namespace private void ConfigureBehaviorGenerated() { this.When(x => x.Clear()).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); + this.When(x => x.Contains(global::PCLMock.It.IsAny())).Return((global::System.Boolean)(default)); this.When(x => x.Add(global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); this.When(x => x.Remove(global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); + this.When(x => x.TryGetValue(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return((global::System.Boolean)(default)); this.When(x => x.Intersect(global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); this.When(x => x.Except(global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); this.When(x => x.SymmetricExcept(global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); this.When(x => x.Union(global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.SetEquals(global::PCLMock.It.IsAny>())).Return((global::System.Boolean)(default)); + this.When(x => x.IsProperSubsetOf(global::PCLMock.It.IsAny>())).Return((global::System.Boolean)(default)); + this.When(x => x.IsProperSupersetOf(global::PCLMock.It.IsAny>())).Return((global::System.Boolean)(default)); + this.When(x => x.IsSubsetOf(global::PCLMock.It.IsAny>())).Return((global::System.Boolean)(default)); + this.When(x => x.IsSupersetOf(global::PCLMock.It.IsAny>())).Return((global::System.Boolean)(default)); + this.When(x => x.Overlaps(global::PCLMock.It.IsAny>())).Return((global::System.Boolean)(default)); + this.When(x => x.Count).Return((global::System.Int32)(default)); + this.When(x => x.GetEnumerator()).Return((global::System.Collections.Generic.IEnumerator)(default)); + this.When(x => ((global::System.Collections.IEnumerable)(x)).GetEnumerator()).Return((global::System.Collections.IEnumerator)(default)); } partial void ConfigureBehavior(); @@ -116,21 +122,38 @@ namespace The.Namespace { return this.Apply(x => x.Overlaps(other)); } + + public global::System.Int32 Count + { + get + { + return this.Apply(x => x.Count); + } + } + + public global::System.Collections.Generic.IEnumerator GetEnumerator() + { + return this.Apply(x => x.GetEnumerator()); + } + + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() + { + return this.Apply(x => ((global::System.Collections.IEnumerable)(x)).GetEnumerator()); + } } } namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + internal partial class ISomeInterfaceMock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -140,10 +163,9 @@ namespace The.Namespace this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.SomeCustomProperty).Return((global::ICustomImmutableSet)(default)); + this.When(x => x.SomeOtherMethod()).Return((global::ICustomImmutableSet)(default)); + this.When(x => x.SomeOtherMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return((global::ICustomImmutableSet)(default)); } partial void ConfigureBehavior(); @@ -176,7 +198,7 @@ namespace The.Namespace return this.Apply(x => x.SomeOtherGenericMethod()); } - public ICustomIImmutableSet SomeCustomProperty + public global::ICustomImmutableSet SomeCustomProperty { get { @@ -184,14 +206,14 @@ namespace The.Namespace } } - public ICustomIImmutableSet SomeMethod() + public global::ICustomImmutableSet SomeOtherMethod() { - return this.Apply(x => x.SomeMethod()); + return this.Apply(x => x.SomeOtherMethod()); } - public ICustomIImmutableSet SomeMethod(global::System.Int32 i, global::System.Single f) + public global::ICustomImmutableSet SomeOtherMethod(global::System.Int32 i, global::System.Single f) { - return this.Apply(x => x.SomeMethod(i, f)); + return this.Apply(x => x.SomeOtherMethod(i, f)); } } } @@ -199,15 +221,14 @@ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface + internal partial class ISomeGenericInterfaceMock : global::PCLMock.MockBase>, global::ISomeGenericInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeGenericInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -219,10 +240,6 @@ namespace The.Namespace this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); } - private void ConfigureLooseBehaviorGenerated() - { - } - partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); public global::System.Collections.Immutable.IImmutableSet SomeProperty diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableStacksInput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableStacksInput_CSharp.txt index 801c729..6837618 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableStacksInput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableStacksInput_CSharp.txt @@ -1,4 +1,4 @@ -using System; +using System.Collections.Generic; using System.Collections.Immutable; interface ICustomImmutableStack : IImmutableStack @@ -26,13 +26,13 @@ interface ISomeInterface IImmutableStack SomeOtherGenericMethod(); // should be ignored because they're a custom enumerable type - ICustomIImmutableStack SomeCustomProperty + ICustomImmutableStack SomeCustomProperty { get; } - ICustomIImmutableStack SomeMethod(); - ICustomIImmutableStack SomeMethod(int i, float f); + ICustomImmutableStack SomeOtherMethod(); + ICustomImmutableStack SomeOtherMethod(int i, float f); } interface ISomeGenericInterface @@ -44,4 +44,15 @@ interface ISomeGenericInterface IImmutableStack SomeMethod(); IImmutableStack SomeMethod(int i, float f); +} + +namespace The.Namespace +{ + internal partial class ISomeInterfaceMock + { + public ICollection SomeSetOnlyProperty + { + set {} + } + } } \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableStacksOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableStacksOutput_CSharp.txt index b17fcd5..f212abc 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableStacksOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableStacksOutput_CSharp.txt @@ -10,15 +10,14 @@ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ICustomImmutableStack + internal partial class ICustomImmutableStackMock : global::PCLMock.MockBase>, global::ICustomImmutableStack { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ICustomImmutableStackMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -28,10 +27,9 @@ namespace The.Namespace this.When(x => x.Clear()).Return(global::System.Collections.Immutable.ImmutableStack.Empty); this.When(x => x.Push(global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableStack.Empty); this.When(x => x.Pop()).Return(global::System.Collections.Immutable.ImmutableStack.Empty); - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.IsEmpty).Return((global::System.Boolean)(default)); + this.When(x => x.GetEnumerator()).Return((global::System.Collections.Generic.IEnumerator)(default)); + this.When(x => ((global::System.Collections.IEnumerable)(x)).GetEnumerator()).Return((global::System.Collections.IEnumerator)(default)); } partial void ConfigureBehavior(); @@ -63,21 +61,30 @@ namespace The.Namespace return this.Apply(x => x.IsEmpty); } } + + public global::System.Collections.Generic.IEnumerator GetEnumerator() + { + return this.Apply(x => x.GetEnumerator()); + } + + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() + { + return this.Apply(x => ((global::System.Collections.IEnumerable)(x)).GetEnumerator()); + } } } namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + internal partial class ISomeInterfaceMock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -87,10 +94,9 @@ namespace The.Namespace this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableStack.Empty); this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableStack.Empty); this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableStack.Empty); - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.SomeCustomProperty).Return((global::ICustomImmutableStack)(default)); + this.When(x => x.SomeOtherMethod()).Return((global::ICustomImmutableStack)(default)); + this.When(x => x.SomeOtherMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return((global::ICustomImmutableStack)(default)); } partial void ConfigureBehavior(); @@ -123,7 +129,7 @@ namespace The.Namespace return this.Apply(x => x.SomeOtherGenericMethod()); } - public ICustomIImmutableStack SomeCustomProperty + public global::ICustomImmutableStack SomeCustomProperty { get { @@ -131,14 +137,14 @@ namespace The.Namespace } } - public ICustomIImmutableStack SomeMethod() + public global::ICustomImmutableStack SomeOtherMethod() { - return this.Apply(x => x.SomeMethod()); + return this.Apply(x => x.SomeOtherMethod()); } - public ICustomIImmutableStack SomeMethod(global::System.Int32 i, global::System.Single f) + public global::ICustomImmutableStack SomeOtherMethod(global::System.Int32 i, global::System.Single f) { - return this.Apply(x => x.SomeMethod(i, f)); + return this.Apply(x => x.SomeOtherMethod(i, f)); } } } @@ -146,15 +152,14 @@ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface + internal partial class ISomeGenericInterfaceMock : global::PCLMock.MockBase>, global::ISomeGenericInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeGenericInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -166,10 +171,6 @@ namespace The.Namespace this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableStack.Empty); } - private void ConfigureLooseBehaviorGenerated() - { - } - partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); public global::System.Collections.Immutable.IImmutableStack SomeProperty diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ListsInput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ListsInput_CSharp.txt index 807aad0..3e21475 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ListsInput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ListsInput_CSharp.txt @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; interface ICustomList : IList @@ -36,8 +35,8 @@ interface ISomeInterface get; } - ICustomList SomeMethod(); - ICustomList SomeMethod(int i, float f); + ICustomList SomeOtherMethod(); + ICustomList SomeOtherMethod(int i, float f); } interface ISomeGenericInterface @@ -49,4 +48,15 @@ interface ISomeGenericInterface IList SomeMethod(); IList SomeMethod(int i, float f); +} + +namespace The.Namespace +{ + internal partial class ISomeInterfaceMock + { + public ICollection SomeSetOnlyProperty + { + set {} + } + } } \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ListsOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ListsOutput_CSharp.txt index 9fdb54e..2d7f684 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ListsOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/ListsOutput_CSharp.txt @@ -10,25 +10,27 @@ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ICustomList + internal partial class ICustomListMock : global::PCLMock.MockBase>, global::ICustomList { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ICustomListMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } private void ConfigureBehaviorGenerated() { - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.IndexOf(global::PCLMock.It.IsAny())).Return((global::System.Int32)(default)); + this.When(x => x.Contains(global::PCLMock.It.IsAny())).Return((global::System.Boolean)(default)); + this.When(x => x.Remove(global::PCLMock.It.IsAny())).Return((global::System.Boolean)(default)); + this.When(x => x.Count).Return((global::System.Int32)(default)); + this.When(x => x.IsReadOnly).Return((global::System.Boolean)(default)); + this.When(x => x.GetEnumerator()).Return((global::System.Collections.Generic.IEnumerator)(default)); + this.When(x => ((global::System.Collections.IEnumerable)(x)).GetEnumerator()).Return((global::System.Collections.IEnumerator)(default)); } partial void ConfigureBehavior(); @@ -101,21 +103,30 @@ namespace The.Namespace return this.Apply(x => x.IsReadOnly); } } + + public global::System.Collections.Generic.IEnumerator GetEnumerator() + { + return this.Apply(x => x.GetEnumerator()); + } + + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() + { + return this.Apply(x => ((global::System.Collections.IEnumerable)(x)).GetEnumerator()); + } } } namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + internal partial class ISomeInterfaceMock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -126,10 +137,9 @@ namespace The.Namespace this.When(x => x.SomeReadOnlyProperty).Return(new global::System.Collections.Generic.List()); this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.List()); this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.List()); - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.SomeCustomProperty).Return((global::ICustomList)(default)); + this.When(x => x.SomeOtherMethod()).Return((global::ICustomList)(default)); + this.When(x => x.SomeOtherMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return((global::ICustomList)(default)); } partial void ConfigureBehavior(); @@ -178,14 +188,14 @@ namespace The.Namespace } } - public global::ICustomList SomeMethod() + public global::ICustomList SomeOtherMethod() { - return this.Apply(x => x.SomeMethod()); + return this.Apply(x => x.SomeOtherMethod()); } - public global::ICustomList SomeMethod(global::System.Int32 i, global::System.Single f) + public global::ICustomList SomeOtherMethod(global::System.Int32 i, global::System.Single f) { - return this.Apply(x => x.SomeMethod(i, f)); + return this.Apply(x => x.SomeOtherMethod(i, f)); } } } @@ -193,15 +203,14 @@ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface + internal partial class ISomeGenericInterfaceMock : global::PCLMock.MockBase>, global::ISomeGenericInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeGenericInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -213,10 +222,6 @@ namespace The.Namespace this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.List()); } - private void ConfigureLooseBehaviorGenerated() - { - } - partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); public global::System.Collections.Generic.IList SomeProperty diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/RecursiveInput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/RecursiveInput_CSharp.txt index a218371..e839ada 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/RecursiveInput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/RecursiveInput_CSharp.txt @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; interface ISomeInterface diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/RecursiveOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/RecursiveOutput_CSharp.txt index 0c4199c..497755a 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/RecursiveOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/RecursiveOutput_CSharp.txt @@ -10,15 +10,14 @@ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + internal partial class ISomeInterfaceMock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -28,10 +27,6 @@ namespace The.Namespace this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.List>>()); } - private void ConfigureLooseBehaviorGenerated() - { - } - partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); public global::System.Collections.Generic.IList>> SomeProperty diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/SetsInput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/SetsInput_CSharp.txt index b353e30..804ae45 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/SetsInput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/SetsInput_CSharp.txt @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; interface ICustomSet : ISet @@ -31,8 +30,8 @@ interface ISomeInterface get; } - ICustomSet SomeMethod(); - ICustomSet SomeMethod(int i, float f); + ICustomSet SomeOtherMethod(); + ICustomSet SomeOtherMethod(int i, float f); } interface ISomeGenericInterface @@ -44,4 +43,15 @@ interface ISomeGenericInterface ISet SomeMethod(); ISet SomeMethod(int i, float f); +} + +namespace The.Namespace +{ + internal partial class ISomeInterfaceMock + { + public ICollection SomeSetOnlyProperty + { + set {} + } + } } \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/SetsOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/SetsOutput_CSharp.txt index 138326e..224657f 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/SetsOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/CollectionsFixtureResources/SetsOutput_CSharp.txt @@ -10,25 +10,33 @@ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ICustomSet + internal partial class ICustomSetMock : global::PCLMock.MockBase>, global::ICustomSet { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ICustomSetMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } private void ConfigureBehaviorGenerated() { - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.Add(global::PCLMock.It.IsAny())).Return((global::System.Boolean)(default)); + this.When(x => x.IsSubsetOf(global::PCLMock.It.IsAny>())).Return((global::System.Boolean)(default)); + this.When(x => x.IsSupersetOf(global::PCLMock.It.IsAny>())).Return((global::System.Boolean)(default)); + this.When(x => x.IsProperSupersetOf(global::PCLMock.It.IsAny>())).Return((global::System.Boolean)(default)); + this.When(x => x.IsProperSubsetOf(global::PCLMock.It.IsAny>())).Return((global::System.Boolean)(default)); + this.When(x => x.Overlaps(global::PCLMock.It.IsAny>())).Return((global::System.Boolean)(default)); + this.When(x => x.SetEquals(global::PCLMock.It.IsAny>())).Return((global::System.Boolean)(default)); + this.When(x => x.Contains(global::PCLMock.It.IsAny())).Return((global::System.Boolean)(default)); + this.When(x => x.Remove(global::PCLMock.It.IsAny())).Return((global::System.Boolean)(default)); + this.When(x => x.Count).Return((global::System.Int32)(default)); + this.When(x => x.IsReadOnly).Return((global::System.Boolean)(default)); + this.When(x => x.GetEnumerator()).Return((global::System.Collections.Generic.IEnumerator)(default)); + this.When(x => ((global::System.Collections.IEnumerable)(x)).GetEnumerator()).Return((global::System.Collections.IEnumerator)(default)); } partial void ConfigureBehavior(); @@ -128,21 +136,30 @@ namespace The.Namespace return this.Apply(x => x.IsReadOnly); } } + + public global::System.Collections.Generic.IEnumerator GetEnumerator() + { + return this.Apply(x => x.GetEnumerator()); + } + + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() + { + return this.Apply(x => ((global::System.Collections.IEnumerable)(x)).GetEnumerator()); + } } } namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + internal partial class ISomeInterfaceMock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -152,10 +169,9 @@ namespace The.Namespace this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.HashSet()); this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.HashSet()); this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.HashSet()); - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.SomeCustomProperty).Return((global::ICustomSet)(default)); + this.When(x => x.SomeOtherMethod()).Return((global::ICustomSet)(default)); + this.When(x => x.SomeOtherMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return((global::ICustomSet)(default)); } partial void ConfigureBehavior(); @@ -196,14 +212,14 @@ namespace The.Namespace } } - public global::ICustomSet SomeMethod() + public global::ICustomSet SomeOtherMethod() { - return this.Apply(x => x.SomeMethod()); + return this.Apply(x => x.SomeOtherMethod()); } - public global::ICustomSet SomeMethod(global::System.Int32 i, global::System.Single f) + public global::ICustomSet SomeOtherMethod(global::System.Int32 i, global::System.Single f) { - return this.Apply(x => x.SomeMethod(i, f)); + return this.Apply(x => x.SomeOtherMethod(i, f)); } } } @@ -211,15 +227,14 @@ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface + internal partial class ISomeGenericInterfaceMock : global::PCLMock.MockBase>, global::ISomeGenericInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeGenericInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -231,10 +246,6 @@ namespace The.Namespace this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.HashSet()); } - private void ConfigureLooseBehaviorGenerated() - { - } - partial void ConfigureBehavior(); partial void ConfigureLooseBehavior(); public global::System.Collections.Generic.ISet SomeProperty diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/DefaultFixture.cs b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/DefaultFixture.cs new file mode 100644 index 0000000..f7d9d7f --- /dev/null +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/DefaultFixture.cs @@ -0,0 +1,23 @@ +namespace PCLMock.UnitTests.CodeGeneration.Plugins +{ + using System.Threading.Tasks; + using Microsoft.CodeAnalysis; + using PCLMock.CodeGeneration; + using Xunit; + + public sealed class DefaultFixture + { + [Theory] + [InlineData("Simple", Language.CSharp)] + public Task can_generate_mocks(string testName, Language language) => + // The default plugin is always included last, so we specify no extra plugins here. + Helpers.GenerateAndVerifyMocksUsingEmbeddedResources( + this.GetType(), + testName, + language, + metadataReferences: new[] + { + MetadataReference.CreateFromFile(typeof(object).Assembly.Location), + }); + } +} diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/DefaultFixtureResources/SimpleInput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/DefaultFixtureResources/SimpleInput_CSharp.txt new file mode 100644 index 0000000..47f446c --- /dev/null +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/DefaultFixtureResources/SimpleInput_CSharp.txt @@ -0,0 +1,18 @@ +interface ISomeInterface +{ + string StringProperty + { + get; + } + + int IntProperty + { + get; + } + + void VoidMethod(); + + string StringMethod(); + + int IntMethod(); +} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/DefaultFixtureResources/SimpleOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/DefaultFixtureResources/SimpleOutput_CSharp.txt new file mode 100644 index 0000000..595beb1 --- /dev/null +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/DefaultFixtureResources/SimpleOutput_CSharp.txt @@ -0,0 +1,66 @@ +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class ISomeInterfaceMock : global::PCLMock.MockBase, global::ISomeInterface + { + public ISomeInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.StringProperty).Return((global::System.String)(default)); + this.When(x => x.IntProperty).Return((global::System.Int32)(default)); + this.When(x => x.StringMethod()).Return((global::System.String)(default)); + this.When(x => x.IntMethod()).Return((global::System.Int32)(default)); + } + + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.String StringProperty + { + get + { + return this.Apply(x => x.StringProperty); + } + } + + public global::System.Int32 IntProperty + { + get + { + return this.Apply(x => x.IntProperty); + } + } + + public void VoidMethod() + { + this.Apply(x => x.VoidMethod()); + } + + public global::System.String StringMethod() + { + return this.Apply(x => x.StringMethod()); + } + + public global::System.Int32 IntMethod() + { + return this.Apply(x => x.IntMethod()); + } + } +} diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/DisposablesFixture.cs b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/DisposablesFixture.cs index 54372b1..b9fab27 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/DisposablesFixture.cs +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/DisposablesFixture.cs @@ -1,15 +1,10 @@ namespace PCLMock.UnitTests.CodeGeneration.Plugins { - using System; - using System.Collections.Immutable; - using System.IO; using System.Linq; - using System.Reactive.Linq; + using System.Reactive.Disposables; using System.Threading.Tasks; using Microsoft.CodeAnalysis; - using Microsoft.CodeAnalysis.Text; using PCLMock.CodeGeneration; - using PCLMock.CodeGeneration.Logging; using PCLMock.CodeGeneration.Plugins; using Xunit; @@ -17,63 +12,20 @@ public sealed class DisposablesFixture { [Theory] [InlineData("Disposables", Language.CSharp)] - public async Task can_generate_mocks(string resourceBaseName, Language language) - { - var inputResourceName = "PCLMock.UnitTests.CodeGeneration.Plugins.DisposablesFixtureResources." + resourceBaseName + "Input_" + language.ToString() + ".txt"; - var outputResourceName = "PCLMock.UnitTests.CodeGeneration.Plugins.DisposablesFixtureResources." + resourceBaseName + "Output_" + language.ToString() + ".txt"; - - using (var inputStream = this.GetType().Assembly.GetManifestResourceStream(inputResourceName)) - using (var outputStream = this.GetType().Assembly.GetManifestResourceStream(outputResourceName)) - using (var outputStreamReader = new StreamReader(outputStream)) - { - var workspace = new AdhocWorkspace(); - var projectId = ProjectId.CreateNewId(); - var versionStamp = VersionStamp.Create(); - var projectInfo = ProjectInfo.Create( - projectId, - versionStamp, - "AdhocProject", - "AdhocProject", - language.ToSyntaxGeneratorLanguageName(), - metadataReferences: new[] + public Task can_generate_mocks(string testName, Language language) => + Helpers.GenerateAndVerifyMocksUsingEmbeddedResources( + this.GetType(), + testName, + language, + metadataReferences: new[] { MetadataReference.CreateFromFile(typeof(object).Assembly.Location), - MetadataReference.CreateFromFile(typeof(Uri).Assembly.Location), - MetadataReference.CreateFromFile(typeof(MockBase<>).Assembly.Location) + MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location), + MetadataReference.CreateFromFile(typeof(Disposable).Assembly.Location), + }, + new IPlugin[] + { + new Disposables(), }); - var project = workspace.AddProject(projectInfo); - workspace.AddDocument(projectId, "Source.cs", SourceText.From(inputStream)); - var solution = workspace.CurrentSolution; - - var results = - (await Generator.GenerateMocksAsync( - NullLogSink.Instance, - language, - solution, - x => true, - x => "The.Namespace", - x => "Mock", - new IPlugin[] - { - new Disposables() - }.ToImmutableList())); - var result = results - .Last() - .ToString() - .NormalizeLineEndings(); - - var expectedCode = outputStreamReader.ReadToEnd(); - - // make sure version changes don't break the tests - expectedCode = expectedCode - .Replace("$VERSION$", typeof(MockBase<>).Assembly.GetName().Version.ToString()) - .NormalizeLineEndings(); - - // useful when converting generated code to something that can be pasted into an expectation file - var sanitisedResult = result.Replace(typeof(MockBase<>).Assembly.GetName().Version.ToString(), "$VERSION$"); - - Assert.Equal(expectedCode, result); - } - } } } \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/DisposablesFixtureResources/DisposablesInput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/DisposablesFixtureResources/DisposablesInput_CSharp.txt index de656b4..22c3c16 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/DisposablesFixtureResources/DisposablesInput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/DisposablesFixtureResources/DisposablesInput_CSharp.txt @@ -30,6 +30,6 @@ interface ISomeInterface get; } - ICustomDisposable SomeMethod(); - ICustomDisposable SomeMethod(int i, float f); + ICustomDisposable SomeOtherMethod(); + ICustomDisposable SomeOtherMethod(int i, float f); } \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/DisposablesFixtureResources/DisposablesOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/DisposablesFixtureResources/DisposablesOutput_CSharp.txt index 286276c..36970f8 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/DisposablesFixtureResources/DisposablesOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/DisposablesFixtureResources/DisposablesOutput_CSharp.txt @@ -1,29 +1,63 @@ +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + internal partial class ICustomDisposableMock : global::PCLMock.MockBase, global::ICustomDisposable { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ICustomDisposableMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } private void ConfigureBehaviorGenerated() { - this.When(x => x.SomeProperty).Return(global::System.Reactive.Disposables.Disposable.Empty); - this.When(x => x.SomeMethod()).Return(global::System.Reactive.Disposables.Disposable.Empty); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Reactive.Disposables.Disposable.Empty); } - private void ConfigureLooseBehaviorGenerated() + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public void Dispose() + { + this.Apply(x => x.Dispose()); + } + } +} +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class ISomeInterfaceMock : global::PCLMock.MockBase, global::ISomeInterface + { + public ISomeInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() { + this.When(x => x.SomeProperty).Return(global::System.Reactive.Disposables.Disposable.Empty); + this.When(x => x.SomeMethod()).Return(global::System.Reactive.Disposables.Disposable.Empty); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Reactive.Disposables.Disposable.Empty); + this.When(x => x.SomeCustomProperty).Return((global::ICustomDisposable)(default)); + this.When(x => x.SomeOtherMethod()).Return((global::ICustomDisposable)(default)); + this.When(x => x.SomeOtherMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return((global::ICustomDisposable)(default)); } partial void ConfigureBehavior(); @@ -64,14 +98,14 @@ namespace The.Namespace } } - public global::ICustomDisposable SomeMethod() + public global::ICustomDisposable SomeOtherMethod() { - return this.Apply(x => x.SomeMethod()); + return this.Apply(x => x.SomeOtherMethod()); } - public global::ICustomDisposable SomeMethod(global::System.Int32 i, global::System.Single f) + public global::ICustomDisposable SomeOtherMethod(global::System.Int32 i, global::System.Single f) { - return this.Apply(x => x.SomeMethod(i, f)); + return this.Apply(x => x.SomeOtherMethod(i, f)); } } -} \ No newline at end of file +} diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixture.cs b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixture.cs index 46d2751..205728e 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixture.cs +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixture.cs @@ -1,16 +1,10 @@ namespace PCLMock.UnitTests.CodeGeneration.Plugins { - using System; - using System.Collections.Immutable; - using System.IO; - using System.Linq; using System.Reactive; using System.Reactive.Linq; using System.Threading.Tasks; using Microsoft.CodeAnalysis; - using Microsoft.CodeAnalysis.Text; using PCLMock.CodeGeneration; - using PCLMock.CodeGeneration.Logging; using PCLMock.CodeGeneration.Plugins; using Xunit; @@ -21,63 +15,20 @@ public sealed class ObservableBasedAsynchronyFixture [InlineData("ObservableBased", Language.CSharp)] [InlineData("GenericInterface", Language.CSharp)] [InlineData("Recursive", Language.CSharp)] - public async Task can_generate_mocks(string resourceBaseName, Language language) - { - var inputResourceName = "PCLMock.UnitTests.CodeGeneration.Plugins.ObservableBasedAsynchronyFixtureResources." + resourceBaseName + "Input_" + language.ToString() + ".txt"; - var outputResourceName = "PCLMock.UnitTests.CodeGeneration.Plugins.ObservableBasedAsynchronyFixtureResources." + resourceBaseName + "Output_" + language.ToString() + ".txt"; - - using (var inputStream = this.GetType().Assembly.GetManifestResourceStream(inputResourceName)) - using (var outputStream = this.GetType().Assembly.GetManifestResourceStream(outputResourceName)) - using (var outputStreamReader = new StreamReader(outputStream)) - { - var workspace = new AdhocWorkspace(); - var projectId = ProjectId.CreateNewId(); - var versionStamp = VersionStamp.Create(); - var projectInfo = ProjectInfo.Create( - projectId, - versionStamp, - "AdhocProject", - "AdhocProject", - language.ToSyntaxGeneratorLanguageName(), - metadataReferences: new[] + public Task can_generate_mocks(string testName, Language language) => + Helpers.GenerateAndVerifyMocksUsingEmbeddedResources( + this.GetType(), + testName, + language, + metadataReferences: new[] { MetadataReference.CreateFromFile(typeof(object).Assembly.Location), - MetadataReference.CreateFromFile(typeof(Uri).Assembly.Location), - MetadataReference.CreateFromFile(typeof(MockBase<>).Assembly.Location), + MetadataReference.CreateFromFile(typeof(Unit).Assembly.Location), + MetadataReference.CreateFromFile(typeof(Observable).Assembly.Location), + }, + new IPlugin[] + { + new ObservableBasedAsynchrony(), }); - var project = workspace.AddProject(projectInfo); - workspace.AddDocument(projectId, "Source.cs", SourceText.From(inputStream)); - var solution = workspace.CurrentSolution; - - var results = - (await Generator.GenerateMocksAsync( - NullLogSink.Instance, - language, - solution, - x => true, - x => "The.Namespace", - x => "Mock", - new IPlugin[] - { - new ObservableBasedAsynchrony() - }.ToImmutableList())); - var result = results - .Last() - .ToString() - .NormalizeLineEndings(); - - var expectedCode = outputStreamReader.ReadToEnd(); - - // make sure version changes don't break the tests - expectedCode = expectedCode - .Replace("$VERSION$", typeof(MockBase<>).Assembly.GetName().Version.ToString()) - .NormalizeLineEndings(); - - // useful when converting generated code to something that can be pasted into an expectation file - var sanitisedResult = result.Replace(typeof(MockBase<>).Assembly.GetName().Version.ToString(), "$VERSION$"); - - Assert.Equal(expectedCode, result); - } - } } } \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt index b14fa92..32d6914 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt @@ -1,16 +1,23 @@ +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ISomeInterface + internal partial class ISomeInterfaceMock : global::PCLMock.MockBase>, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } @@ -18,11 +25,7 @@ namespace The.Namespace private void ConfigureBehaviorGenerated() { this.When(x => x.SomeProperty).Return(global::System.Reactive.Linq.Observable.Empty()); - this.When(x => x.SomeMethod()).Return(global::System.Reactive.Linq.Observable.Return(default(T))); - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.SomeMethod()).Return(global::System.Reactive.Linq.Observable.Return((T)(default))); } partial void ConfigureBehavior(); @@ -40,4 +43,4 @@ namespace The.Namespace return this.Apply(x => x.SomeMethod()); } } -} \ No newline at end of file +} diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/NonObservableBasedInput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/NonObservableBasedInput_CSharp.txt index 203ec18..c136010 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/NonObservableBasedInput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/NonObservableBasedInput_CSharp.txt @@ -22,13 +22,24 @@ interface ISomeInterface void SomeMethod(); - string SomeMethod(); + string SomeStringMethod(); - int SomeMethod(); + int SomeIntMethod(); - object SomeMethod(); + object SomeObjectMethod(); - int SomeMethod(); + int SomeGeneric1Method(); - int SomeMethod(); + int SomeGeneric2Method(); +} + +namespace The.Namespace +{ + internal partial class ISomeInterfaceMock + { + public int SomeSetOnlyProperty + { + set {} + } + } } \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/NonObservableBasedOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/NonObservableBasedOutput_CSharp.txt index 823841b..d77111c 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/NonObservableBasedOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/NonObservableBasedOutput_CSharp.txt @@ -1,26 +1,35 @@ +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + internal partial class ISomeInterfaceMock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } private void ConfigureBehaviorGenerated() { - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.SomeProperty).Return((global::System.Int32)(default)); + this.When(x => x.SomeOtherProperty).Return((global::System.String)(default)); + this.When(x => x[global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny()]).Return((global::System.Int32)(default)); + this.When(x => x.SomeStringMethod()).Return((global::System.String)(default)); + this.When(x => x.SomeIntMethod()).Return((global::System.Int32)(default)); + this.When(x => x.SomeObjectMethod()).Return((global::System.Object)(default)); } partial void ConfigureBehavior(); @@ -54,29 +63,29 @@ namespace The.Namespace this.Apply(x => x.SomeMethod()); } - public global::System.String SomeMethod() + public global::System.String SomeStringMethod() { - return this.Apply(x => x.SomeMethod()); + return this.Apply(x => x.SomeStringMethod()); } - public global::System.Int32 SomeMethod() + public global::System.Int32 SomeIntMethod() { - return this.Apply(x => x.SomeMethod()); + return this.Apply(x => x.SomeIntMethod()); } - public global::System.Object SomeMethod() + public global::System.Object SomeObjectMethod() { - return this.Apply(x => x.SomeMethod()); + return this.Apply(x => x.SomeObjectMethod()); } - public global::System.Int32 SomeMethod() + public global::System.Int32 SomeGeneric1Method() { - return this.Apply(x => x.SomeMethod()); + return this.Apply(x => x.SomeGeneric1Method()); } - public global::System.Int32 SomeMethod() + public global::System.Int32 SomeGeneric2Method() { - return this.Apply(x => x.SomeMethod()); + return this.Apply(x => x.SomeGeneric2Method()); } } -} \ No newline at end of file +} diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedInput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedInput_CSharp.txt index bb39658..7a20529 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedInput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedInput_CSharp.txt @@ -1,5 +1,4 @@ using System; -using System.Reactive; interface ICustomObservable : IObservable { @@ -30,13 +29,23 @@ interface ISomeInterface IObservable SomeMethod(); IObservable SomeMethod(string s, int i); - IObservable SomeOtherMethod(); // expecting these to be ignored because of the type parameters - IObservable SomeMethod(); - IObservable SomeMethod(); + IObservable SomeGeneric1Method(); + IObservable SomeGeneric2Method(); // expecting these two to be ignored because of it being a custom observable (which we have no way of providing a default value for) - ICustomObservable SomeMethod(); - ICustomObservable SomeMethod(string s, int i); + ICustomObservable SomeCustomObservableMethod(); + ICustomObservable SomeCustomObservableMethod(string s, int i); +} + +namespace The.Namespace +{ + internal partial class ISomeInterfaceMock + { + public int SomeSetOnlyProperty + { + set {} + } + } } \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedOutput_CSharp.txt index 0d8175d..e5b8e13 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedOutput_CSharp.txt @@ -1,32 +1,65 @@ +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + internal partial class ICustomObservableMock : global::PCLMock.MockBase>, global::ICustomObservable { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ICustomObservableMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } private void ConfigureBehaviorGenerated() { - this.When(x => x.SomeProperty).Return(global::System.Reactive.Linq.Observable.Empty()); - this.When(x => x.SomeOtherProperty).Return(global::System.Reactive.Linq.Observable.Empty()); - this.When(x => x[global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny()]).Return(global::System.Reactive.Linq.Observable.Empty()); - this.When(x => x.SomeMethod()).Return(global::System.Reactive.Linq.Observable.Return(0)); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Reactive.Linq.Observable.Return(null)); - this.When(x => x.SomeOtherMethod()).Return(global::System.Reactive.Linq.Observable.Return(default(global::System.Reactive.Unit))); + this.When(x => x.Subscribe(global::PCLMock.It.IsAny>())).Return((global::System.IDisposable)(default)); } - private void ConfigureLooseBehaviorGenerated() + partial void ConfigureBehavior(); + partial void ConfigureLooseBehavior(); + public global::System.IDisposable Subscribe(global::System.IObserver observer) { + return this.Apply(x => x.Subscribe(observer)); + } + } +} +namespace The.Namespace +{ + [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] + [System.Runtime.CompilerServices.CompilerGenerated] + internal partial class ISomeInterfaceMock : global::PCLMock.MockBase, global::ISomeInterface + { + public ISomeInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + { + ConfigureBehaviorGenerated(); + ConfigureBehavior(); + if ((behavior) == (global::PCLMock.MockBehavior.Loose)) + { + ConfigureLooseBehavior(); + } + } + + private void ConfigureBehaviorGenerated() + { + this.When(x => x.SomeProperty).Return(global::System.Reactive.Linq.Observable.Empty()); + this.When(x => x.SomeOtherProperty).Return(global::System.Reactive.Linq.Observable.Empty()); + this.When(x => x[global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny()]).Return(global::System.Reactive.Linq.Observable.Empty()); + this.When(x => x.SomeMethod()).Return(global::System.Reactive.Linq.Observable.Return((global::System.Int32)(default))); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Reactive.Linq.Observable.Return((global::System.String)(default))); + this.When(x => x.SomeCustomObservableMethod()).Return((global::ICustomObservable)(default)); + this.When(x => x.SomeCustomObservableMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return((global::ICustomObservable)(default)); } partial void ConfigureBehavior(); @@ -65,29 +98,24 @@ namespace The.Namespace return this.Apply(x => x.SomeMethod(s, i)); } - public global::System.IObservable SomeOtherMethod() + public global::System.IObservable SomeGeneric1Method() { - return this.Apply(x => x.SomeOtherMethod()); + return this.Apply(x => x.SomeGeneric1Method()); } - public global::System.IObservable SomeMethod() + public global::System.IObservable SomeGeneric2Method() { - return this.Apply(x => x.SomeMethod()); + return this.Apply(x => x.SomeGeneric2Method()); } - public global::System.IObservable SomeMethod() + public global::ICustomObservable SomeCustomObservableMethod() { - return this.Apply(x => x.SomeMethod()); + return this.Apply(x => x.SomeCustomObservableMethod()); } - public global::ICustomObservable SomeMethod() + public global::ICustomObservable SomeCustomObservableMethod(global::System.String s, global::System.Int32 i) { - return this.Apply(x => x.SomeMethod()); - } - - public global::ICustomObservable SomeMethod(global::System.String s, global::System.Int32 i) - { - return this.Apply(x => x.SomeMethod(s, i)); + return this.Apply(x => x.SomeCustomObservableMethod(s, i)); } } -} \ No newline at end of file +} diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt index 9abb768..db380a8 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt @@ -1,27 +1,30 @@ +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + internal partial class ISomeInterfaceMock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } private void ConfigureBehaviorGenerated() { - this.When(x => x.SomeMethod()).Return(global::System.Reactive.Linq.Observable.Return>(global::System.Reactive.Linq.Observable.Return(0))); - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.SomeMethod()).Return(global::System.Reactive.Linq.Observable.Return>(global::System.Reactive.Linq.Observable.Return((global::System.Int32)(default)))); } partial void ConfigureBehavior(); @@ -31,4 +34,4 @@ namespace The.Namespace return this.Apply(x => x.SomeMethod()); } } -} \ No newline at end of file +} diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixture.cs b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixture.cs index b4d6d75..1ecca1e 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixture.cs +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixture.cs @@ -1,14 +1,8 @@ namespace PCLMock.UnitTests.CodeGeneration.Plugins { - using System; - using System.Collections.Immutable; - using System.IO; - using System.Linq; using System.Threading.Tasks; using Microsoft.CodeAnalysis; - using Microsoft.CodeAnalysis.Text; using PCLMock.CodeGeneration; - using PCLMock.CodeGeneration.Logging; using PCLMock.CodeGeneration.Plugins; using Xunit; @@ -20,63 +14,19 @@ public sealed class TaskBasedAsynchronyFixture [InlineData("GenericTask", Language.CSharp)] [InlineData("GenericInterface", Language.CSharp)] [InlineData("Recursive", Language.CSharp)] - public async Task can_generate_mocks(string resourceBaseName, Language language) - { - var inputResourceName = "PCLMock.UnitTests.CodeGeneration.Plugins.TaskBasedAsynchronyFixtureResources." + resourceBaseName + "Input_" + language.ToString() + ".txt"; - var outputResourceName = "PCLMock.UnitTests.CodeGeneration.Plugins.TaskBasedAsynchronyFixtureResources." + resourceBaseName + "Output_" + language.ToString() + ".txt"; - - using (var inputStream = this.GetType().Assembly.GetManifestResourceStream(inputResourceName)) - using (var outputStream = this.GetType().Assembly.GetManifestResourceStream(outputResourceName)) - using (var outputStreamReader = new StreamReader(outputStream)) - { - var workspace = new AdhocWorkspace(); - var projectId = ProjectId.CreateNewId(); - var versionStamp = VersionStamp.Create(); - var projectInfo = ProjectInfo.Create( - projectId, - versionStamp, - "AdhocProject", - "AdhocProject", - language.ToSyntaxGeneratorLanguageName(), - metadataReferences: new[] + public Task can_generate_mocks(string testName, Language language) => + Helpers.GenerateAndVerifyMocksUsingEmbeddedResources( + this.GetType(), + testName, + language, + metadataReferences: new[] { MetadataReference.CreateFromFile(typeof(object).Assembly.Location), - MetadataReference.CreateFromFile(typeof(Uri).Assembly.Location), - MetadataReference.CreateFromFile(typeof(MockBase<>).Assembly.Location) + MetadataReference.CreateFromFile(typeof(Task).Assembly.Location), + }, + new IPlugin[] + { + new TaskBasedAsynchrony(), }); - var project = workspace.AddProject(projectInfo); - workspace.AddDocument(projectId, "Source.cs", SourceText.From(inputStream)); - var solution = workspace.CurrentSolution; - - var results = - (await Generator.GenerateMocksAsync( - NullLogSink.Instance, - language, - solution, - x => true, - x => "The.Namespace", - x => "Mock", - new IPlugin[] - { - new TaskBasedAsynchrony() - }.ToImmutableList())); - var result = results - .Last() - .ToString() - .NormalizeLineEndings(); - - var expectedCode = outputStreamReader.ReadToEnd(); - - // make sure version changes don't break the tests - expectedCode = expectedCode - .Replace("$VERSION$", typeof(MockBase<>).Assembly.GetName().Version.ToString()) - .NormalizeLineEndings(); - - // useful when converting generated code to something that can be pasted into an expectation file - var sanitisedResult = result.Replace(typeof(MockBase<>).Assembly.GetName().Version.ToString(), "$VERSION$"); - - Assert.Equal(expectedCode, result); - } - } } } \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt index 7744c10..700d5d5 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt @@ -1,28 +1,31 @@ +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ISomeInterface + internal partial class ISomeInterfaceMock : global::PCLMock.MockBase>, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } private void ConfigureBehaviorGenerated() { - this.When(x => x.SomeProperty).Return(global::System.Threading.Tasks.Task.FromResult(default(T))); - this.When(x => x.SomeMethod()).Return(global::System.Threading.Tasks.Task.FromResult(default(T))); - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.SomeProperty).Return(global::System.Threading.Tasks.Task.FromResult((T)(default))); + this.When(x => x.SomeMethod()).Return(global::System.Threading.Tasks.Task.FromResult((T)(default))); } partial void ConfigureBehavior(); @@ -40,4 +43,4 @@ namespace The.Namespace return this.Apply(x => x.SomeMethod()); } } -} \ No newline at end of file +} diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericTaskInput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericTaskInput_CSharp.txt index 0d9e21b..c1c500e 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericTaskInput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericTaskInput_CSharp.txt @@ -1,7 +1,11 @@ +using System; using System.Threading.Tasks; class CustomTask : Task { + CustomTask(Func action) : base(action) + { + } } interface ISomeInterface @@ -35,6 +39,17 @@ interface ISomeInterface Task SomeMethod(); // expecting these two to be ignored because of it being a custom task (which we have no way of providing a default value for) - CustomTask SomeMethod(); - CustomTask SomeMethod(string s, int i); + CustomTask SomeOtherMethod(); + CustomTask SomeOtherMethod(string s, int i); +} + +namespace The.Namespace +{ + internal partial class ISomeInterfaceMock + { + public int SomeSetOnlyProperty + { + set {} + } + } } \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericTaskOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericTaskOutput_CSharp.txt index 48721eb..31ddf40 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericTaskOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericTaskOutput_CSharp.txt @@ -1,31 +1,36 @@ +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + internal partial class ISomeInterfaceMock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } private void ConfigureBehaviorGenerated() { - this.When(x => x.SomeProperty).Return(global::System.Threading.Tasks.Task.FromResult(0)); - this.When(x => x.SomeOtherProperty).Return(global::System.Threading.Tasks.Task.FromResult(null)); - this.When(x => x[global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny()]).Return(global::System.Threading.Tasks.Task.FromResult(0)); - this.When(x => x.SomeMethod()).Return(global::System.Threading.Tasks.Task.FromResult(0)); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Threading.Tasks.Task.FromResult(null)); - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.SomeProperty).Return(global::System.Threading.Tasks.Task.FromResult((global::System.Int32)(default))); + this.When(x => x.SomeOtherProperty).Return(global::System.Threading.Tasks.Task.FromResult((global::System.String)(default))); + this.When(x => x[global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny()]).Return(global::System.Threading.Tasks.Task.FromResult((global::System.Int32)(default))); + this.When(x => x.SomeMethod()).Return(global::System.Threading.Tasks.Task.FromResult((global::System.Int32)(default))); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Threading.Tasks.Task.FromResult((global::System.String)(default))); + this.When(x => x.SomeOtherMethod()).Return((global::CustomTask)(default)); + this.When(x => x.SomeOtherMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return((global::CustomTask)(default)); } partial void ConfigureBehavior(); @@ -74,14 +79,14 @@ namespace The.Namespace return this.Apply(x => x.SomeMethod()); } - public global::CustomTask SomeMethod() + public global::CustomTask SomeOtherMethod() { - return this.Apply(x => x.SomeMethod()); + return this.Apply(x => x.SomeOtherMethod()); } - public global::CustomTask SomeMethod(global::System.String s, global::System.Int32 i) + public global::CustomTask SomeOtherMethod(global::System.String s, global::System.Int32 i) { - return this.Apply(x => x.SomeMethod(s, i)); + return this.Apply(x => x.SomeOtherMethod(s, i)); } } -} \ No newline at end of file +} diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonGenericTaskInput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonGenericTaskInput_CSharp.txt index 28bc9f9..c52cd2e 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonGenericTaskInput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonGenericTaskInput_CSharp.txt @@ -1,7 +1,11 @@ +using System; using System.Threading.Tasks; class CustomTask : Task { + CustomTask(Action action) : base(action) + { + } } interface ISomeInterface @@ -35,6 +39,17 @@ interface ISomeInterface Task SomeMethod(); // expecting these to be ignored because of it being a custom task (which we have no way of providing a default value for) - CustomTask SomeMethod(); - CustomTask SomeMethod(string s, int i); + CustomTask SomeOtherMethod(); + CustomTask SomeOtherMethod(string s, int i); +} + +namespace The.Namespace +{ + internal partial class ISomeInterfaceMock + { + public int SomeSetOnlyProperty + { + set {} + } + } } \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonGenericTaskOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonGenericTaskOutput_CSharp.txt index e4da0ea..09c1740 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonGenericTaskOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonGenericTaskOutput_CSharp.txt @@ -1,31 +1,36 @@ +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + internal partial class ISomeInterfaceMock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } private void ConfigureBehaviorGenerated() { - this.When(x => x.SomeProperty).Return(global::System.Threading.Tasks.Task.FromResult(false)); - this.When(x => x.SomeOtherProperty).Return(global::System.Threading.Tasks.Task.FromResult(false)); - this.When(x => x[global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny()]).Return(global::System.Threading.Tasks.Task.FromResult(false)); - this.When(x => x.SomeMethod()).Return(global::System.Threading.Tasks.Task.FromResult(false)); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Threading.Tasks.Task.FromResult(false)); - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.SomeProperty).Return(global::System.Threading.Tasks.Task.FromResult((global::System.Boolean)(default))); + this.When(x => x.SomeOtherProperty).Return(global::System.Threading.Tasks.Task.FromResult((global::System.Boolean)(default))); + this.When(x => x[global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny()]).Return(global::System.Threading.Tasks.Task.FromResult((global::System.Boolean)(default))); + this.When(x => x.SomeMethod()).Return(global::System.Threading.Tasks.Task.FromResult((global::System.Boolean)(default))); + this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Threading.Tasks.Task.FromResult((global::System.Boolean)(default))); + this.When(x => x.SomeOtherMethod()).Return((global::CustomTask)(default)); + this.When(x => x.SomeOtherMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return((global::CustomTask)(default)); } partial void ConfigureBehavior(); @@ -74,14 +79,14 @@ namespace The.Namespace return this.Apply(x => x.SomeMethod()); } - public global::CustomTask SomeMethod() + public global::CustomTask SomeOtherMethod() { - return this.Apply(x => x.SomeMethod()); + return this.Apply(x => x.SomeOtherMethod()); } - public global::CustomTask SomeMethod(global::System.String s, global::System.Int32 i) + public global::CustomTask SomeOtherMethod(global::System.String s, global::System.Int32 i) { - return this.Apply(x => x.SomeMethod(s, i)); + return this.Apply(x => x.SomeOtherMethod(s, i)); } } -} \ No newline at end of file +} diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonTaskBasedInput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonTaskBasedInput_CSharp.txt index 203ec18..c136010 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonTaskBasedInput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonTaskBasedInput_CSharp.txt @@ -22,13 +22,24 @@ interface ISomeInterface void SomeMethod(); - string SomeMethod(); + string SomeStringMethod(); - int SomeMethod(); + int SomeIntMethod(); - object SomeMethod(); + object SomeObjectMethod(); - int SomeMethod(); + int SomeGeneric1Method(); - int SomeMethod(); + int SomeGeneric2Method(); +} + +namespace The.Namespace +{ + internal partial class ISomeInterfaceMock + { + public int SomeSetOnlyProperty + { + set {} + } + } } \ No newline at end of file diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonTaskBasedOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonTaskBasedOutput_CSharp.txt index 823841b..d77111c 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonTaskBasedOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonTaskBasedOutput_CSharp.txt @@ -1,26 +1,35 @@ +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + internal partial class ISomeInterfaceMock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } private void ConfigureBehaviorGenerated() { - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.SomeProperty).Return((global::System.Int32)(default)); + this.When(x => x.SomeOtherProperty).Return((global::System.String)(default)); + this.When(x => x[global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny()]).Return((global::System.Int32)(default)); + this.When(x => x.SomeStringMethod()).Return((global::System.String)(default)); + this.When(x => x.SomeIntMethod()).Return((global::System.Int32)(default)); + this.When(x => x.SomeObjectMethod()).Return((global::System.Object)(default)); } partial void ConfigureBehavior(); @@ -54,29 +63,29 @@ namespace The.Namespace this.Apply(x => x.SomeMethod()); } - public global::System.String SomeMethod() + public global::System.String SomeStringMethod() { - return this.Apply(x => x.SomeMethod()); + return this.Apply(x => x.SomeStringMethod()); } - public global::System.Int32 SomeMethod() + public global::System.Int32 SomeIntMethod() { - return this.Apply(x => x.SomeMethod()); + return this.Apply(x => x.SomeIntMethod()); } - public global::System.Object SomeMethod() + public global::System.Object SomeObjectMethod() { - return this.Apply(x => x.SomeMethod()); + return this.Apply(x => x.SomeObjectMethod()); } - public global::System.Int32 SomeMethod() + public global::System.Int32 SomeGeneric1Method() { - return this.Apply(x => x.SomeMethod()); + return this.Apply(x => x.SomeGeneric1Method()); } - public global::System.Int32 SomeMethod() + public global::System.Int32 SomeGeneric2Method() { - return this.Apply(x => x.SomeMethod()); + return this.Apply(x => x.SomeGeneric2Method()); } } -} \ No newline at end of file +} diff --git a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt index 15758c1..8e86c30 100644 --- a/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt +++ b/Src/PCLMock.UnitTests/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt @@ -1,27 +1,30 @@ +// ----------------------------------------------------------------------- +// +// This code was generated from a template. +// +// Changes to this file may cause incorrect behaviour and will be lost +// if the code is regenerated. +// +// ------------------------------------------------------------------------ namespace The.Namespace { [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface + internal partial class ISomeInterfaceMock : global::PCLMock.MockBase, global::ISomeInterface { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) + public ISomeInterfaceMock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base(behavior) { ConfigureBehaviorGenerated(); ConfigureBehavior(); if ((behavior) == (global::PCLMock.MockBehavior.Loose)) { - ConfigureLooseBehaviorGenerated(); ConfigureLooseBehavior(); } } private void ConfigureBehaviorGenerated() { - this.When(x => x.SomeMethod()).Return(global::System.Threading.Tasks.Task.FromResult>(global::System.Threading.Tasks.Task.FromResult(0))); - } - - private void ConfigureLooseBehaviorGenerated() - { + this.When(x => x.SomeMethod()).Return(global::System.Threading.Tasks.Task.FromResult>(global::System.Threading.Tasks.Task.FromResult((global::System.Int32)(default)))); } partial void ConfigureBehavior(); @@ -31,4 +34,4 @@ namespace The.Namespace return this.Apply(x => x.SomeMethod()); } } -} \ No newline at end of file +} diff --git a/Src/PCLMock.UnitTests/Helpers.cs b/Src/PCLMock.UnitTests/Helpers.cs new file mode 100644 index 0000000..311a809 --- /dev/null +++ b/Src/PCLMock.UnitTests/Helpers.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.Text; +using Microsoft.CodeAnalysis.VisualBasic; +using PCLMock.CodeGeneration; +using PCLMock.CodeGeneration.Logging; +using Xunit; + +namespace PCLMock.UnitTests +{ + internal static class Helpers + { + public static async Task GenerateAndVerifyMocksUsingEmbeddedResources( + Type fixtureType, + string testName, + Language language, + IEnumerable metadataReferences = default, + IPlugin[] plugins = default, + // Should only be enabled temporarily to overwrite expected output with the actual output, making it easy to update + // expected output files when code changes necessitate. + bool overwriteExpectedOutput = false) + { + var resourceBaseName = $"{fixtureType.FullName}Resources."; + var inputResourceName = $"{resourceBaseName}{testName}Input_{language}.txt"; + var outputResourceName = $"{resourceBaseName}{testName}Output_{language}.txt"; + var platformPath = Path.GetDirectoryName(typeof(object).Assembly.Location); + + // Manually add some references that are always required. + var supplementedMetadataReferences = (metadataReferences ?? Enumerable.Empty()) + .Concat( + new[] + { + MetadataReference.CreateFromFile(Path.Combine(platformPath, "System.Runtime.dll")), + MetadataReference.CreateFromFile(typeof(System.Linq.Expressions.Expression).Assembly.Location), + MetadataReference.CreateFromFile(typeof(object).Assembly.Location), + MetadataReference.CreateFromFile(typeof(MockBase<>).Assembly.Location), + }); + + using (var inputStream = typeof(Helpers).Assembly.GetManifestResourceStream(inputResourceName)) + { + var projectInfo = ProjectInfo.Create( + ProjectId.CreateNewId(), + VersionStamp.Create(), + "AdhocProject", + "AdhocProject", + language.ToSyntaxGeneratorLanguageName(), + compilationOptions: language == Language.CSharp + ? (CompilationOptions)new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) + : new VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary), + metadataReferences: supplementedMetadataReferences); + + // Create an adhoc workspace and project containing the input source. + var workspace = new AdhocWorkspace(); + var project = workspace + .AddProject(projectInfo) + .AddDocument("Source.cs", SourceText.From(inputStream)) + .Project; + var compilation = await project.GetCompilationAsync(); + var diagnostics = compilation.GetDiagnostics(); + + // Ensure there are no issues with the input project, otherwise it might be confusing to understand issues with the generated mocks. + Assert.Empty(diagnostics); + + var logSink = new StringLogSink() + .WithMinimumLevel(LogLevel.Warn); + var generatedMocks = Generator.GenerateMocks( + logSink, + language, + ImmutableList.Create(compilation), + (plugins ?? Enumerable.Empty()).ToImmutableList(), + x => true, + x => "The.Namespace", + x => $"{x.Name}Mock"); + + var log = logSink.ToString(); + // There shouldn't be any errors or warnings in the log or something has gone wrong generating mocks. + Assert.Equal("", log); + + var generatedMocksAggregated = generatedMocks + .Aggregate( + new StringBuilder(), + (acc, next) => + { + if (next != null) + { + acc.AppendLine(next.ToFullString()); + } + + return acc; + }, + acc => acc.ToString()) + .NormalizeLineEndings(); + + using (var outputStream = typeof(Helpers).Assembly.GetManifestResourceStream(outputResourceName)) + using (var outputStreamReader = new StreamReader(outputStream)) + { + var expectedCode = outputStreamReader.ReadToEnd(); + + // make sure version changes don't break the tests + expectedCode = expectedCode + .Replace("$VERSION$", typeof(MockBase<>).Assembly.GetName().Version.ToString()) + .NormalizeLineEndings(); + + // useful when converting generated code to something that can be pasted into an expectation file + var sanitisedResult = generatedMocksAggregated.Replace(typeof(MockBase<>).Assembly.GetName().Version.ToString(), "$VERSION$"); + + if (overwriteExpectedOutput) + { + var currentDirectory = Path.GetDirectoryName(typeof(Helpers).Assembly.Location); + var outputDirectory = Path.Combine(currentDirectory, @"..\..\..\", "CodeGeneration", "Plugins", $"{fixtureType.Name}Resources"); + var outputFileName = Path.Combine(outputDirectory, $"{testName}Output_{language}.txt"); + + if (!File.Exists(outputFileName)) + { + throw new InvalidOperationException(@"Asked to overwrite output, but cannot determine output path."); + } + + File.WriteAllText(outputFileName, sanitisedResult); + + Assert.True(false, "Output successfully overwritten - now disable the overwriteExpectedOutput flag."); + } + + Assert.Equal(expectedCode, generatedMocksAggregated); + } + + // Now combine the original code with the generated code and make sure there are no problems. + var workspaceWithGeneratedCode = new AdhocWorkspace(); + var projectWithGeneratedCode = workspaceWithGeneratedCode + .AddProject(projectInfo) + .AddDocument("Source.cs", SourceText.From(inputStream)) + .Project + .AddDocument("GeneratedSource.cs", SourceText.From(generatedMocksAggregated)) + .Project; + var compilationWithGeneratedCode = await projectWithGeneratedCode.GetCompilationAsync(); + var diagnosticsToIgnore = new HashSet( + new [] + { + // Don't require assembly identities to match exactly because PCLMock is built against netstandard whereas we're running + // tests against a specific platform. This means, e.g. System.Linq.Expressions won't be the exact same assembly. + "CS1701", + }); + var diagnosticsWithGeneratedCode = compilationWithGeneratedCode + .GetDiagnostics() + .Where(diagnostic => !diagnosticsToIgnore.Contains(diagnostic.Id)) + .ToImmutableArray(); + + // Ensure there are no issues with the input project, otherwise it might be confusing to understand issues with the generated mocks. + Assert.Empty(diagnostics); + } + } + } +} diff --git a/Src/PCLMock.UnitTests/PCLMock.UnitTests.csproj b/Src/PCLMock.UnitTests/PCLMock.UnitTests.csproj index f996ed3..f079aff 100644 --- a/Src/PCLMock.UnitTests/PCLMock.UnitTests.csproj +++ b/Src/PCLMock.UnitTests/PCLMock.UnitTests.csproj @@ -3,27 +3,13 @@ PCLMock.UnitTests PCLMock.UnitTests - net471;netstandard2.0 + netcoreapp5.0 false true latest IOperation - - - $(PackageTargetFallback);portable-net45+win8+wp8+wpa81 - - - - - - - - @@ -32,7 +18,9 @@ + + diff --git a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsAnyArgumentFilterFixture.cs b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsAnyArgumentFilterFixture.cs deleted file mode 100644 index ec405c0..0000000 --- a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsAnyArgumentFilterFixture.cs +++ /dev/null @@ -1,59 +0,0 @@ -namespace PCLMock.ArgumentFilters.UnitTests -{ - using PCLMock.ArgumentFilters; - using Xunit; - using Xunit.Extensions; - - public sealed class IsAnyArgumentFilterFixture - { - [Fact] - public void matches_returns_true_for_null() - { - Assert.True(IsAnyArgumentFilter.Instance.Matches(null)); - } - - [Theory] - [InlineData(null)] - [InlineData("")] - [InlineData("hello")] - [InlineData("world")] - [InlineData(0)] - [InlineData(1)] - [InlineData(-1)] - [InlineData(38)] - [InlineData(int.MaxValue)] - [InlineData(int.MinValue)] - public void matches_returns_true_for_any_value(object value) - { - Assert.True(IsAnyArgumentFilter.Instance.Matches(value)); - Assert.True(IsAnyArgumentFilter.Instance.Matches(value)); - Assert.True(IsAnyArgumentFilter.Instance.Matches(value)); - } - - [Fact] - public void has_a_nice_string_representation() - { - Assert.Equal("It.IsAny()", IsAnyArgumentFilter.Instance.ToString()); - Assert.Equal("It.IsAny()", IsAnyArgumentFilter.Instance.ToString()); - Assert.Equal("It.IsAny()", IsAnyArgumentFilter.Instance.ToString()); - } - - [Fact] - public void equals_returns_false_if_given_null() - { - Assert.False(IsAnyArgumentFilter.Instance.Equals(null)); - } - - [Fact] - public void equals_returns_false_if_given_a_filter_for_a_different_type() - { - Assert.False(IsAnyArgumentFilter.Instance.Equals(IsAnyArgumentFilter.Instance)); - } - - [Fact] - public void equals_returns_true_if_given_a_filter_of_the_same_type() - { - Assert.True(IsAnyArgumentFilter.Instance.Equals(IsAnyArgumentFilter.Instance)); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsArgumentFilterFixture.cs b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsArgumentFilterFixture.cs deleted file mode 100644 index fbce729..0000000 --- a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsArgumentFilterFixture.cs +++ /dev/null @@ -1,61 +0,0 @@ -namespace PCLMock.ArgumentFilters.UnitTests -{ - using PCLMock.ArgumentFilters; - using Xunit; - using Xunit.Extensions; - - public sealed class IsArgumentFilterFixture - { - [Fact] - public void matches_works_with_null() - { - Assert.True(new IsArgumentFilter(null).Matches(null)); - } - - [Theory] - [InlineData("hello", "world", false)] - [InlineData("hello", null, false)] - [InlineData(null, "hello", false)] - [InlineData(1, 2, false)] - [InlineData(1, 1f, false)] - [InlineData("hello", "hello", true)] - [InlineData(null, null, true)] - [InlineData(13, 13, true)] - [InlineData(56f, 56f, true)] - public void matches_returns_correct_value(object firstValue, object secondValue, bool expectedResult) - { - Assert.Equal(expectedResult, new IsArgumentFilter(firstValue).Matches(secondValue)); - } - - [Fact] - public void has_a_nice_string_representation() - { - Assert.Equal("It.Is(\"hello\")", new IsArgumentFilter("hello").ToString()); - Assert.Equal("It.Is(10)", new IsArgumentFilter(10).ToString()); - Assert.Equal("It.Is(15.182M)", new IsArgumentFilter(15.182m).ToString()); - Assert.Equal("It.Is(null)", new IsArgumentFilter(null).ToString()); - } - - [Fact] - public void equals_returns_false_if_given_a_filter_for_a_different_type() - { - Assert.False(new IsArgumentFilter("foo").Equals(new IsArgumentFilter(10))); - } - - [Fact] - public void equals_returns_false_if_given_a_filter_with_a_different_expected_value() - { - Assert.False(new IsArgumentFilter("foo").Equals(new IsArgumentFilter("bar"))); - Assert.False(new IsArgumentFilter("foo").Equals(new IsArgumentFilter(null))); - Assert.False(new IsArgumentFilter(null).Equals(new IsArgumentFilter("foo"))); - } - - [Fact] - public void equals_returns_true_if_given_a_filter_with_the_same_expected_value() - { - Assert.True(new IsArgumentFilter("foo").Equals(new IsArgumentFilter("foo"))); - Assert.True(new IsArgumentFilter(150).Equals(new IsArgumentFilter(150))); - Assert.True(new IsArgumentFilter(null).Equals(new IsArgumentFilter(null))); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsBetweenArgumentFilterFixture.cs b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsBetweenArgumentFilterFixture.cs deleted file mode 100644 index ed2a48f..0000000 --- a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsBetweenArgumentFilterFixture.cs +++ /dev/null @@ -1,85 +0,0 @@ -namespace PCLMock.ArgumentFilters.UnitTests -{ - using PCLMock.ArgumentFilters; - using Xunit; - - public sealed class IsBetweenArgumentFilterFixture - { - [Fact] - public void matches_returns_true_if_value_is_equal_to_the_minimum() - { - Assert.True(new IsBetweenArgumentFilter(5, 10).Matches(5)); - Assert.True(new IsBetweenArgumentFilter(5.152m, 10.3m).Matches(5.152m)); - Assert.True(new IsBetweenArgumentFilter(null, "abc").Matches(null)); - } - - [Fact] - public void matches_returns_true_if_value_is_equal_to_the_maximum() - { - Assert.True(new IsBetweenArgumentFilter(5, 10).Matches(10)); - Assert.True(new IsBetweenArgumentFilter(5.152m, 10.3m).Matches(10.3m)); - Assert.True(new IsBetweenArgumentFilter(null, "abc").Matches("abc")); - } - - [Fact] - public void matches_returns_false_if_value_is_less_than_the_minimum() - { - Assert.False(new IsBetweenArgumentFilter(5, 10).Matches(4)); - Assert.False(new IsBetweenArgumentFilter(5.152m, 10.3m).Matches(5.151m)); - } - - [Fact] - public void matches_returns_false_if_value_is_greater_than_the_maximum() - { - Assert.False(new IsBetweenArgumentFilter(5, 10).Matches(11)); - Assert.False(new IsBetweenArgumentFilter(5.152m, 10.3m).Matches(10.301m)); - } - - [Fact] - public void matches_returns_true_if_value_is_within_the_minimum_and_maximum() - { - Assert.True(new IsBetweenArgumentFilter(5, 10).Matches(6)); - Assert.True(new IsBetweenArgumentFilter(5.152m, 10.3m).Matches(6.1m)); - Assert.True(new IsBetweenArgumentFilter(null, "abc").Matches("a")); - Assert.True(new IsBetweenArgumentFilter(5, 5).Matches(5)); - } - - [Fact] - public void has_a_nice_string_representation() - { - Assert.Equal("It.IsBetween(5, 10)", new IsBetweenArgumentFilter(5, 10).ToString()); - Assert.Equal("It.IsBetween(12.36M, 15.182M)", new IsBetweenArgumentFilter(12.36m, 15.182m).ToString()); - Assert.Equal("It.IsBetween(null, \"abc\")", new IsBetweenArgumentFilter(null, "abc").ToString()); - } - - [Fact] - public void equals_returns_false_if_given_a_filter_for_a_different_type() - { - Assert.False(new IsBetweenArgumentFilter(null, "foo").Equals(new IsBetweenArgumentFilter(1, 10))); - } - - [Fact] - public void equals_returns_false_if_given_a_filter_with_a_different_range() - { - Assert.False(new IsBetweenArgumentFilter(5, 10).Equals(new IsBetweenArgumentFilter(6, 10))); - Assert.False(new IsBetweenArgumentFilter(5.2387m, 10.127m).Equals(new IsBetweenArgumentFilter(5.2387m, 10.1271m))); - Assert.False(new IsBetweenArgumentFilter("foo", "bar").Equals(new IsBetweenArgumentFilter("foo", null))); - } - - [Fact] - public void equals_returns_true_if_given_a_filter_with_the_same_range() - { - Assert.True(new IsBetweenArgumentFilter(5, 10).Equals(new IsBetweenArgumentFilter(5, 10))); - Assert.True(new IsBetweenArgumentFilter(5.2387m, 10.127m).Equals(new IsBetweenArgumentFilter(5.2387m, 10.127m))); - Assert.True(new IsBetweenArgumentFilter("foo", "bar").Equals(new IsBetweenArgumentFilter("foo", "bar"))); - } - - [Fact] - public void ranges_are_automatically_inverted_as_necessary() - { - Assert.True(new IsBetweenArgumentFilter(5, 10).Equals(new IsBetweenArgumentFilter(10, 5))); - Assert.True(new IsBetweenArgumentFilter(5.2387m, 10.127m).Equals(new IsBetweenArgumentFilter(10.127m, 5.2387m))); - Assert.True(new IsBetweenArgumentFilter("foo", "bar").Equals(new IsBetweenArgumentFilter("bar", "foo"))); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsGreaterThanArgumentFilterFixture.cs b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsGreaterThanArgumentFilterFixture.cs deleted file mode 100644 index 1b8a3e3..0000000 --- a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsGreaterThanArgumentFilterFixture.cs +++ /dev/null @@ -1,62 +0,0 @@ -namespace PCLMock.ArgumentFilters.UnitTests -{ - using PCLMock.ArgumentFilters; - using Xunit; - - public sealed class IsGreaterThanArgumentFilterFixture - { - [Fact] - public void matches_returns_false_if_value_is_equal_to_specified_value() - { - Assert.False(new IsGreaterThanArgumentFilter(5).Matches(5)); - Assert.False(new IsGreaterThanArgumentFilter(5.152m).Matches(5.152m)); - Assert.False(new IsGreaterThanArgumentFilter(null).Matches(null)); - } - - [Fact] - public void matches_returns_true_if_value_is_greater_than_specified_value() - { - Assert.True(new IsGreaterThanArgumentFilter(5).Matches(6)); - Assert.True(new IsGreaterThanArgumentFilter(5.152m).Matches(5.153m)); - Assert.True(new IsGreaterThanArgumentFilter(null).Matches("foo")); - } - - [Fact] - public void matches_returns_false_if_value_is_less_than_specified_value() - { - Assert.False(new IsGreaterThanArgumentFilter(5).Matches(4)); - Assert.False(new IsGreaterThanArgumentFilter(5.142m).Matches(5.141m)); - Assert.False(new IsGreaterThanArgumentFilter("foo").Matches(null)); - } - - [Fact] - public void has_a_nice_string_representation() - { - Assert.Equal("It.IsGreaterThan(10)", new IsGreaterThanArgumentFilter(10).ToString()); - Assert.Equal("It.IsGreaterThan(15.182M)", new IsGreaterThanArgumentFilter(15.182m).ToString()); - Assert.Equal("It.IsGreaterThan(null)", new IsGreaterThanArgumentFilter(null).ToString()); - } - - [Fact] - public void equals_returns_false_if_given_a_filter_for_a_different_type() - { - Assert.False(new IsGreaterThanArgumentFilter("foo").Equals(new IsGreaterThanArgumentFilter(10))); - } - - [Fact] - public void equals_returns_false_if_given_a_filter_with_a_different_specified_value() - { - Assert.False(new IsGreaterThanArgumentFilter("foo").Equals(new IsGreaterThanArgumentFilter("bar"))); - Assert.False(new IsGreaterThanArgumentFilter("foo").Equals(new IsGreaterThanArgumentFilter(null))); - Assert.False(new IsGreaterThanArgumentFilter(null).Equals(new IsGreaterThanArgumentFilter("foo"))); - } - - [Fact] - public void equals_returns_true_if_given_a_filter_with_the_same_specified_value() - { - Assert.True(new IsGreaterThanArgumentFilter("foo").Equals(new IsGreaterThanArgumentFilter("foo"))); - Assert.True(new IsGreaterThanArgumentFilter(150).Equals(new IsGreaterThanArgumentFilter(150))); - Assert.True(new IsGreaterThanArgumentFilter(null).Equals(new IsGreaterThanArgumentFilter(null))); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsGreaterThanOrEqualToArgumentFilterFixture.cs b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsGreaterThanOrEqualToArgumentFilterFixture.cs deleted file mode 100644 index 05e81e1..0000000 --- a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsGreaterThanOrEqualToArgumentFilterFixture.cs +++ /dev/null @@ -1,62 +0,0 @@ -namespace PCLMock.ArgumentFilters.UnitTests -{ - using PCLMock.ArgumentFilters; - using Xunit; - - public sealed class IsGreaterThanOrEqualToArgumentFilterFixture - { - [Fact] - public void matches_returns_true_if_value_is_equal_to_specified_value() - { - Assert.True(new IsGreaterThanOrEqualToArgumentFilter(5).Matches(5)); - Assert.True(new IsGreaterThanOrEqualToArgumentFilter(5.152m).Matches(5.152m)); - Assert.True(new IsGreaterThanOrEqualToArgumentFilter(null).Matches(null)); - } - - [Fact] - public void matches_returns_true_if_value_is_greater_than_specified_value() - { - Assert.True(new IsGreaterThanOrEqualToArgumentFilter(5).Matches(6)); - Assert.True(new IsGreaterThanOrEqualToArgumentFilter(5.152m).Matches(5.153m)); - Assert.True(new IsGreaterThanOrEqualToArgumentFilter(null).Matches("foo")); - } - - [Fact] - public void matches_returns_false_if_value_is_less_than_specified_value() - { - Assert.False(new IsGreaterThanOrEqualToArgumentFilter(5).Matches(4)); - Assert.False(new IsGreaterThanOrEqualToArgumentFilter(5.142m).Matches(5.141m)); - Assert.False(new IsGreaterThanOrEqualToArgumentFilter("foo").Matches(null)); - } - - [Fact] - public void has_a_nice_string_representation() - { - Assert.Equal("It.IsGreaterThanOrEqualTo(10)", new IsGreaterThanOrEqualToArgumentFilter(10).ToString()); - Assert.Equal("It.IsGreaterThanOrEqualTo(15.182M)", new IsGreaterThanOrEqualToArgumentFilter(15.182m).ToString()); - Assert.Equal("It.IsGreaterThanOrEqualTo(null)", new IsGreaterThanOrEqualToArgumentFilter(null).ToString()); - } - - [Fact] - public void equals_returns_false_if_given_a_filter_for_a_different_type() - { - Assert.False(new IsGreaterThanOrEqualToArgumentFilter("foo").Equals(new IsGreaterThanOrEqualToArgumentFilter(10))); - } - - [Fact] - public void equals_returns_false_if_given_a_filter_with_a_different_specified_value() - { - Assert.False(new IsGreaterThanOrEqualToArgumentFilter("foo").Equals(new IsGreaterThanOrEqualToArgumentFilter("bar"))); - Assert.False(new IsGreaterThanOrEqualToArgumentFilter("foo").Equals(new IsGreaterThanOrEqualToArgumentFilter(null))); - Assert.False(new IsGreaterThanOrEqualToArgumentFilter(null).Equals(new IsGreaterThanOrEqualToArgumentFilter("foo"))); - } - - [Fact] - public void equals_returns_true_if_given_a_filter_with_the_same_specified_value() - { - Assert.True(new IsGreaterThanOrEqualToArgumentFilter("foo").Equals(new IsGreaterThanOrEqualToArgumentFilter("foo"))); - Assert.True(new IsGreaterThanOrEqualToArgumentFilter(150).Equals(new IsGreaterThanOrEqualToArgumentFilter(150))); - Assert.True(new IsGreaterThanOrEqualToArgumentFilter(null).Equals(new IsGreaterThanOrEqualToArgumentFilter(null))); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsInArgumentFilterFixture.cs b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsInArgumentFilterFixture.cs deleted file mode 100644 index 98e083b..0000000 --- a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsInArgumentFilterFixture.cs +++ /dev/null @@ -1,66 +0,0 @@ -namespace PCLMock.ArgumentFilters.UnitTests -{ - using PCLMock.ArgumentFilters; - using Xunit; - - public sealed class IsInArgumentFilterFixture - { - [Fact] - public void matches_returns_false_if_no_values_are_provided() - { - Assert.False(new IsInArgumentFilter().Matches("foo")); - Assert.False(new IsInArgumentFilter().Matches(null)); - } - - [Fact] - public void matches_returns_false_if_value_is_not_in_set_of_expected_values() - { - Assert.False(new IsInArgumentFilter("hello", "world").Matches("Hello")); - Assert.False(new IsInArgumentFilter(1, 2, 3, 5, 8, 13).Matches(11)); - Assert.False(new IsInArgumentFilter("hello", "world").Matches(null)); - } - - [Fact] - public void matches_returns_true_if_value_is_in_set_of_expected_values() - { - Assert.True(new IsInArgumentFilter("hello", "world").Matches("world")); - Assert.True(new IsInArgumentFilter(1, 2, 3, 5, 8, 13).Matches(5)); - Assert.True(new IsInArgumentFilter("hello", null, "world").Matches(null)); - } - - [Fact] - public void has_a_nice_string_representation() - { - // being that a HashSet is used as the underlying storage mechanism, the order of items isn't really predictable here - Assert.Equal("It.IsIn(\"hello\", \"world\")", new IsInArgumentFilter("hello", "world").ToString()); - Assert.Equal("It.IsIn(3, 5, 10)", new IsInArgumentFilter(3, 5, 10).ToString()); - Assert.Equal("It.IsIn(15.182M, 2.812M)", new IsInArgumentFilter(15.182m, 2.812M).ToString()); - Assert.Equal("It.IsIn(\"foo\", null)", new IsInArgumentFilter("foo", null).ToString()); - } - - [Fact] - public void equals_returns_false_if_given_a_filter_for_a_different_type() - { - Assert.False(new IsInArgumentFilter("foo").Equals(new IsInArgumentFilter(10))); - } - - [Fact] - public void equals_returns_false_if_given_a_filter_with_different_expected_values() - { - Assert.False(new IsInArgumentFilter("foo").Equals(new IsInArgumentFilter("bar"))); - Assert.False(new IsInArgumentFilter("foo").Equals(new IsInArgumentFilter("foo", "bar"))); - Assert.False(new IsInArgumentFilter("foo").Equals(new IsInArgumentFilter(null))); - Assert.False(new IsInArgumentFilter(null).Equals(new IsInArgumentFilter("foo"))); - } - - [Fact] - public void equals_returns_true_if_given_a_filter_with_the_same_expected_values() - { - Assert.True(new IsInArgumentFilter("foo").Equals(new IsInArgumentFilter("foo"))); - Assert.True(new IsInArgumentFilter(null).Equals(new IsInArgumentFilter(null))); - Assert.True(new IsInArgumentFilter("foo", "bar").Equals(new IsInArgumentFilter("bar", "foo"))); - Assert.True(new IsInArgumentFilter("foo", null, "bar").Equals(new IsInArgumentFilter(null, "bar", "foo"))); - Assert.True(new IsInArgumentFilter(1, 0, 150, -29).Equals(new IsInArgumentFilter(150, -29, 0, 1))); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsLikeArgumentFilterFixture.cs b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsLikeArgumentFilterFixture.cs deleted file mode 100644 index 115dc80..0000000 --- a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsLikeArgumentFilterFixture.cs +++ /dev/null @@ -1,50 +0,0 @@ -namespace PCLMock.ArgumentFilters.UnitTests -{ - using System.Text.RegularExpressions; - using PCLMock.ArgumentFilters; - using Xunit; - - public sealed class IsLikeArgumentFilterFixture - { - [Fact] - public void matches_returns_false_if_values_do_not_match() - { - Assert.False(new IsLikeArgumentFilter("[hH]ello", RegexOptions.None).Matches("world")); - Assert.False(new IsLikeArgumentFilter("hello", RegexOptions.None).Matches(null)); - } - - [Fact] - public void matches_returns_true_if_values_match() - { - Assert.True(new IsLikeArgumentFilter("[hH]ello", RegexOptions.None).Matches("Hello")); - Assert.True(new IsLikeArgumentFilter("[hH]ello", RegexOptions.None).Matches("hello")); - Assert.True(new IsLikeArgumentFilter("hello.", RegexOptions.IgnoreCase).Matches("HELLO!")); - } - - [Fact] - public void has_a_nice_string_representation() - { - Assert.Equal("It.IsLike(\"[hH]ello\")", new IsLikeArgumentFilter("[hH]ello", RegexOptions.None).ToString()); - } - - [Fact] - public void equals_returns_false_if_given_a_filter_with_a_different_pattern() - { - Assert.False(new IsLikeArgumentFilter("foo", RegexOptions.None).Equals(new IsLikeArgumentFilter("bar", RegexOptions.None))); - Assert.False(new IsLikeArgumentFilter("foo", RegexOptions.None).Equals(new IsLikeArgumentFilter("Foo", RegexOptions.None))); - } - - [Fact] - public void equals_returns_false_if_given_a_filter_with_different_options() - { - Assert.False(new IsLikeArgumentFilter("foo", RegexOptions.None).Equals(new IsLikeArgumentFilter("foo", RegexOptions.Multiline))); - } - - [Fact] - public void equals_returns_true_if_given_a_filter_with_the_same_pattern_and_options() - { - Assert.True(new IsLikeArgumentFilter("foo", RegexOptions.None).Equals(new IsLikeArgumentFilter("foo", RegexOptions.None))); - Assert.True(new IsLikeArgumentFilter("foo", RegexOptions.Multiline | RegexOptions.Compiled).Equals(new IsLikeArgumentFilter("foo", RegexOptions.Multiline | RegexOptions.Compiled))); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsNullArgumentFilterFixture.cs b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsNullArgumentFilterFixture.cs deleted file mode 100644 index 29dbc32..0000000 --- a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsNullArgumentFilterFixture.cs +++ /dev/null @@ -1,44 +0,0 @@ -namespace PCLMock.ArgumentFilters.UnitTests -{ - using System; - using System.Text; - using PCLMock.ArgumentFilters; - using Xunit; - - public sealed class IsNullArgumentFilterFixture - { - [Fact] - public void matches_returns_false_if_value_is_not_null() - { - Assert.False(IsNullArgumentFilter.Instance.Matches("hello")); - Assert.False(IsNullArgumentFilter.Instance.Matches("world")); - } - - [Fact] - public void matches_returns_true_if_value_is_null() - { - Assert.True(IsNullArgumentFilter.Instance.Matches(null)); - } - - [Fact] - public void has_a_nice_string_representation() - { - Assert.Equal("It.IsNull()", IsNullArgumentFilter.Instance.ToString()); - Assert.Equal("It.IsNull()", IsNullArgumentFilter.Instance.ToString()); - Assert.Equal("It.IsNull()", IsNullArgumentFilter.Instance.ToString()); - } - - [Fact] - public void equals_returns_false_if_given_a_filter_for_a_different_type() - { - Assert.False(IsNullArgumentFilter.Instance.Equals(IsNullArgumentFilter.Instance)); - } - - [Fact] - public void equals_returns_true_if_given_a_filter_for_the_same_type() - { - Assert.True(IsNullArgumentFilter.Instance.Equals(IsNullArgumentFilter.Instance)); - Assert.True(IsNullArgumentFilter.Instance.Equals(IsNullArgumentFilter.Instance)); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsOfTypeArgumentFilterFixture.cs b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsOfTypeArgumentFilterFixture.cs deleted file mode 100644 index cce6f7c..0000000 --- a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/IsOfTypeArgumentFilterFixture.cs +++ /dev/null @@ -1,45 +0,0 @@ -namespace PCLMock.ArgumentFilters.UnitTests -{ - using System; - using System.Text; - using PCLMock.ArgumentFilters; - using Xunit; - - public sealed class IsOfTypeArgumentFilterFixture - { - [Fact] - public void matches_returns_false_if_value_is_not_of_specified_type() - { - Assert.False(IsOfTypeArgumentFilter.Instance.Matches(1)); - Assert.False(IsOfTypeArgumentFilter.Instance.Matches(new StringBuilder())); - } - - [Fact] - public void matches_returns_true_if_value_is_of_specified_type() - { - Assert.True(IsOfTypeArgumentFilter.Instance.Matches("foo")); - Assert.True(IsOfTypeArgumentFilter.Instance.Matches(1)); - } - - [Fact] - public void has_a_nice_string_representation() - { - Assert.Equal("It.IsOfType()", IsOfTypeArgumentFilter.Instance.ToString()); - } - - [Fact] - public void equals_returns_false_if_given_a_filter_for_a_different_type() - { - Assert.False(IsOfTypeArgumentFilter.Instance.Equals(IsOfTypeArgumentFilter.Instance)); - Assert.False(IsOfTypeArgumentFilter>.Instance.Equals(IsOfTypeArgumentFilter>.Instance)); - } - - [Fact] - public void equals_returns_true_if_given_a_filter_for_the_same_type() - { - Assert.True(IsOfTypeArgumentFilter.Instance.Equals(IsOfTypeArgumentFilter.Instance)); - Assert.True(IsOfTypeArgumentFilter.Instance.Equals(IsOfTypeArgumentFilter.Instance)); - Assert.True(IsOfTypeArgumentFilter.Instance.Equals(IsOfTypeArgumentFilter.Instance)); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/LogicalNotArgumentFilterFixture.cs b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/LogicalNotArgumentFilterFixture.cs deleted file mode 100644 index 531437d..0000000 --- a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/LogicalNotArgumentFilterFixture.cs +++ /dev/null @@ -1,41 +0,0 @@ -namespace PCLMock.ArgumentFilters.UnitTests -{ - using PCLMock.ArgumentFilters; - using Xunit; - - public sealed class LogicalNotArgumentFilterFixture - { - [Fact] - public void matches_returns_opposite_of_what_child_returns() - { - var child = new IsArgumentFilter("foo"); - var argumentFilter = new LogicalNotArgumentFilter(child); - - Assert.False(argumentFilter.Matches("foo")); - Assert.True(argumentFilter.Matches("bar")); - } - - [Fact] - public void has_a_nice_string_representation() - { - var child = new IsArgumentFilter("foo"); - var argumentFilter = new LogicalNotArgumentFilter(child); - - Assert.Equal("NOT(It.Is(\"foo\"))", argumentFilter.ToString()); - } - - [Fact] - public void equals_returns_uses_childs_equality_to_determine_result() - { - var child1 = new IsArgumentFilter("foo"); - var child2 = new IsArgumentFilter("bar"); - var child3 = new IsArgumentFilter("foo"); - var argumentFilter1 = new LogicalNotArgumentFilter(child1); - var argumentFilter2 = new LogicalNotArgumentFilter(child2); - var argumentFilter3 = new LogicalNotArgumentFilter(child3); - - Assert.False(argumentFilter1.Equals(argumentFilter2)); - Assert.True(argumentFilter1.Equals(argumentFilter3)); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/MatchesArgumentFilterFixture.cs b/Src/PCLMock.UnitTests_OLD/ArgumentFilters/MatchesArgumentFilterFixture.cs deleted file mode 100644 index e65b64c..0000000 --- a/Src/PCLMock.UnitTests_OLD/ArgumentFilters/MatchesArgumentFilterFixture.cs +++ /dev/null @@ -1,57 +0,0 @@ -namespace PCLMock.ArgumentFilters.UnitTests -{ - using System; - using PCLMock.ArgumentFilters; - using Xunit; - using Xunit.Extensions; - - public sealed class MatchesArgumentFilterFixture - { - [Theory] - [InlineData(0, true)] - [InlineData(1, false)] - [InlineData(2, true)] - [InlineData(3, false)] - [InlineData(4, true)] - public void matches_returns_correct_value(object value, bool expectedResult) - { - Assert.Equal(expectedResult, new MatchesArgumentFilter(x => x % 2 == 0).Matches(value)); - } - - [Fact] - public void has_a_nice_string_representation() - { - Assert.Equal("It.Matches()", new MatchesArgumentFilter(_ => true).ToString()); - Assert.Equal("It.Matches()", new MatchesArgumentFilter(_ => true).ToString()); - } - - [Fact] - public void equals_returns_false_if_given_a_filter_for_a_different_type() - { - Assert.False(new MatchesArgumentFilter(_ => true).Equals(new MatchesArgumentFilter(_ => true))); - } - - [Fact] - public void equals_returns_false_if_given_a_filter_with_a_different_predicate() - { - Assert.False(new MatchesArgumentFilter(_ => true).Equals(new MatchesArgumentFilter(_ => false))); - Assert.False(new MatchesArgumentFilter(_ => false).Equals(new MatchesArgumentFilter(_ => true))); - Assert.False(new MatchesArgumentFilter(_ => true).Equals(new MatchesArgumentFilter(_ => false))); - Assert.False(new MatchesArgumentFilter(_ => false).Equals(new MatchesArgumentFilter(_ => true))); - } - - [Fact] - public void equals_returns_true_if_given_a_filter_with_the_same_predicate() - { - Func stringTruePredicate = _ => true; - Func stringFalsePredicate = _ => false; - Func intTruePredicate = _ => true; - Func intFalsePredicate = _ => false; - - Assert.True(new MatchesArgumentFilter(stringTruePredicate).Equals(new MatchesArgumentFilter(stringTruePredicate))); - Assert.True(new MatchesArgumentFilter(stringFalsePredicate).Equals(new MatchesArgumentFilter(stringFalsePredicate))); - Assert.True(new MatchesArgumentFilter(intTruePredicate).Equals(new MatchesArgumentFilter(intTruePredicate))); - Assert.True(new MatchesArgumentFilter(intFalsePredicate).Equals(new MatchesArgumentFilter(intFalsePredicate))); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixture.cs b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixture.cs deleted file mode 100644 index 3242e8e..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixture.cs +++ /dev/null @@ -1,91 +0,0 @@ -namespace PCLMock.UnitTests.CodeGeneration -{ - using System; - using System.Collections.Immutable; - using System.IO; - using System.Linq; - using System.Threading.Tasks; - using Microsoft.CodeAnalysis; - using Microsoft.CodeAnalysis.Text; - using PCLMock.CodeGeneration; - using PCLMock.CodeGeneration.Logging; - using Xunit; - - public sealed class GeneratorFixture - { - [Theory] - [InlineData("SimpleInterface", Language.CSharp)] - [InlineData("InternalInterface", Language.CSharp)] - [InlineData("InterfaceWithGenericMethods", Language.CSharp)] - [InlineData("GenericInterface", Language.CSharp)] - [InlineData("NonMockableMembers", Language.CSharp)] - [InlineData("PartialInterface", Language.CSharp)] - [InlineData("InheritingInterface", Language.CSharp)] - [InlineData("DuplicateMember", Language.CSharp)] - [InlineData("NameClash", Language.CSharp)] - [InlineData("Indexers", Language.CSharp)] - [InlineData("OutAndRef", Language.CSharp)] - // TODO: VB is totally borked - calls to syntaxGenerator.WithStatements don't seem to add the statements! Will need to look into this at a later date - //[InlineData("SimpleInterface", Language.VisualBasic)] - //[InlineData("InterfaceWithGenericMethods", Language.VisualBasic)] - //[InlineData("GenericInterface", Language.VisualBasic)] - //[InlineData("InterfaceWithNonMockableMembers", Language.VisualBasic)] - //[InlineData("PartialInterface", Language.VisualBasic)] - //[InlineData("InheritingInterface", Language.VisualBasic)] - public async Task can_generate_mocks(string resourceBaseName, Language language) - { - var inputResourceName = "PCLMock.UnitTests.CodeGeneration.GeneratorFixtureResources." + resourceBaseName + "Input_" + language.ToString() + ".txt"; - var outputResourceName = "PCLMock.UnitTests.CodeGeneration.GeneratorFixtureResources." + resourceBaseName + "Output_" + language.ToString() + ".txt"; - - using (var inputStream = this.GetType().Assembly.GetManifestResourceStream(inputResourceName)) - using (var outputStream = this.GetType().Assembly.GetManifestResourceStream(outputResourceName)) - using (var outputStreamReader = new StreamReader(outputStream)) - { - var workspace = new AdhocWorkspace(); - var projectId = ProjectId.CreateNewId(); - var versionStamp = VersionStamp.Create(); - var projectInfo = ProjectInfo.Create( - projectId, - versionStamp, - "AdhocProject", - "AdhocProject", - language.ToSyntaxGeneratorLanguageName(), - metadataReferences: new[] - { - MetadataReference.CreateFromFile(typeof(object).Assembly.Location), - MetadataReference.CreateFromFile(typeof(Uri).Assembly.Location), - MetadataReference.CreateFromFile(typeof(MockBase<>).Assembly.Location) - }); - var project = workspace.AddProject(projectInfo); - workspace.AddDocument(projectId, "Source.cs", SourceText.From(inputStream)); - var solution = workspace.CurrentSolution; - - var results = - (await Generator.GenerateMocksAsync( - NullLogSink.Instance, - language, - solution, - x => true, - x => "The.Namespace", - x => "Mock", - ImmutableList.Empty)); - var result = results - .Last() - .ToString() - .NormalizeLineEndings(); - - var expectedCode = outputStreamReader.ReadToEnd(); - - // make sure version changes don't break the tests - expectedCode = expectedCode - .Replace("$VERSION$", typeof(MockBase<>).Assembly.GetName().Version.ToString()) - .NormalizeLineEndings(); - - // useful when converting generated code to something that can be pasted into an expectation file - var sanitisedResult = result.Replace(typeof(MockBase<>).Assembly.GetName().Version.ToString(), "$VERSION$"); - - Assert.Equal(expectedCode, result); - } - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/DuplicateMemberInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/DuplicateMemberInput_CSharp.txt deleted file mode 100644 index 9dab51f..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/DuplicateMemberInput_CSharp.txt +++ /dev/null @@ -1,29 +0,0 @@ -using System; - -public interface IFirstInterface -{ - void FirstMethod(); - - int DuplicateProperty - { - get; - } - - void DuplicateMethod(); -} - -public interface ISecondInterface -{ - void SecondMethod(); - - int DuplicateProperty - { - get; - } - - void DuplicateMethod(); -} - -public interface IThirdInterface : IFirstInterface, ISecondInterface -{ -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/DuplicateMemberOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/DuplicateMemberOutput_CSharp.txt deleted file mode 100644 index dbeedc2..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/DuplicateMemberOutput_CSharp.txt +++ /dev/null @@ -1,38 +0,0 @@ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - public partial class Mock : global::PCLMock.MockBase, global::IThirdInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public void FirstMethod() - { - this.Apply(x => x.FirstMethod()); - } - - public void SecondMethod() - { - this.Apply(x => x.SecondMethod()); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/GenericInterfaceInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/GenericInterfaceInput_CSharp.txt deleted file mode 100644 index 943c5db..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/GenericInterfaceInput_CSharp.txt +++ /dev/null @@ -1,14 +0,0 @@ -using System; - -public interface IGenericInterface - where TFirst : IComparable, new() - where TSecond : struct -{ - TFirst SomeProperty - { - get; - set; - } - - TFirst DoSomething(TSecond input); -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/GenericInterfaceOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/GenericInterfaceOutput_CSharp.txt deleted file mode 100644 index 72e3bca..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/GenericInterfaceOutput_CSharp.txt +++ /dev/null @@ -1,46 +0,0 @@ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - public partial class Mock : global::PCLMock.MockBase>, global::IGenericInterface where TFirst : global::System.IComparable, new ()where TSecond : struct - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public TFirst SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - - set - { - this.ApplyPropertySet(x => x.SomeProperty, value); - } - } - - public TFirst DoSomething(TSecond input) - { - return this.Apply(x => x.DoSomething(input)); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/IndexersInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/IndexersInput_CSharp.txt deleted file mode 100644 index 5bc673d..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/IndexersInput_CSharp.txt +++ /dev/null @@ -1,18 +0,0 @@ -public interface ISomeInterface -{ - int this[int i] - { - get; - } - - string this[int i, float j] - { - get; - } - - string this[int i, float j, double d] - { - get; - set; - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/IndexersOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/IndexersOutput_CSharp.txt deleted file mode 100644 index 16d88d4..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/IndexersOutput_CSharp.txt +++ /dev/null @@ -1,57 +0,0 @@ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - public partial class Mock : global::PCLMock.MockBase, global::ISomeInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public System.Int32 this[System.Int32 i] - { - get - { - return this.Apply(x => x[i]); - } - } - - public System.String this[System.Int32 i, System.Single j] - { - get - { - return this.Apply(x => x[i, j]); - } - } - - public System.String this[System.Int32 i, System.Single j, System.Double d] - { - get - { - return this.Apply(x => x[i, j, d]); - } - - set - { - this.ApplyPropertySet(x => x[i, j, d], value); - } - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InheritingInterfaceInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InheritingInterfaceInput_CSharp.txt deleted file mode 100644 index f5726ea..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InheritingInterfaceInput_CSharp.txt +++ /dev/null @@ -1,9 +0,0 @@ -using System; - -public interface IInheritingInterface : ICloneable -{ - int SomeProperty - { - get; - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InheritingInterfaceOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InheritingInterfaceOutput_CSharp.txt deleted file mode 100644 index 430dc63..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InheritingInterfaceOutput_CSharp.txt +++ /dev/null @@ -1,41 +0,0 @@ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - public partial class Mock : global::PCLMock.MockBase, global::IInheritingInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public System.Int32 SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - - public System.Object Clone() - { - return this.Apply(x => x.Clone()); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InterfaceWithGenericMethodsInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InterfaceWithGenericMethodsInput_CSharp.txt deleted file mode 100644 index de2882d..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InterfaceWithGenericMethodsInput_CSharp.txt +++ /dev/null @@ -1,14 +0,0 @@ -public interface IInterfaceWithGenericMethods -{ - void VoidMethodWithGenericParameter(); - - T NonVoidMethodWithGenericParameter(); - - void VoidMethodWithGenericArguments(TFirst first, TSecond second, TThird third, string somethingElse); - - TSecond NonVoidMethodWithGenericArguments(TFirst input); - - TSecond MethodWithTypeConstraints(TFirst input, int option) - where TFirst : IComparable, new() - where TSecond : struct; -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InterfaceWithGenericMethodsOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InterfaceWithGenericMethodsOutput_CSharp.txt deleted file mode 100644 index 70d3674..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InterfaceWithGenericMethodsOutput_CSharp.txt +++ /dev/null @@ -1,53 +0,0 @@ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - public partial class Mock : global::PCLMock.MockBase, global::IInterfaceWithGenericMethods - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public void VoidMethodWithGenericParameter() - { - this.Apply(x => x.VoidMethodWithGenericParameter()); - } - - public T NonVoidMethodWithGenericParameter() - { - return this.Apply(x => x.NonVoidMethodWithGenericParameter()); - } - - public void VoidMethodWithGenericArguments(TFirst first, TSecond second, TThird third, System.String somethingElse) - { - this.Apply(x => x.VoidMethodWithGenericArguments(first, second, third, somethingElse)); - } - - public TSecond NonVoidMethodWithGenericArguments(TFirst input) - { - return this.Apply(x => x.NonVoidMethodWithGenericArguments(input)); - } - - public TSecond MethodWithTypeConstraints(TFirst input, System.Int32 option)where TFirst : IComparable, new ()where TSecond : struct - { - return this.Apply(x => x.MethodWithTypeConstraints(input, option)); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InternalInterfaceInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InternalInterfaceInput_CSharp.txt deleted file mode 100644 index 440a1de..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InternalInterfaceInput_CSharp.txt +++ /dev/null @@ -1,26 +0,0 @@ -internal interface IInternalInterface -{ - int GetProperty - { - get; - } - - int SetProperty - { - set; - } - - int GetSetProperty - { - get; - set; - } - - void VoidMethod(); - - void VoidMethodWithArguments(int i, string s); - - string NonVoidMethod(); - - string NonVoidMethodWithArguments(int i, string s); -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InternalInterfaceOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InternalInterfaceOutput_CSharp.txt deleted file mode 100644 index 7b1e5cc..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/InternalInterfaceOutput_CSharp.txt +++ /dev/null @@ -1,69 +0,0 @@ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::IInternalInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public System.Int32 GetProperty - { - get - { - return this.Apply(x => x.GetProperty); - } - } - - public System.Int32 GetSetProperty - { - get - { - return this.Apply(x => x.GetSetProperty); - } - - set - { - this.ApplyPropertySet(x => x.GetSetProperty, value); - } - } - - public void VoidMethod() - { - this.Apply(x => x.VoidMethod()); - } - - public void VoidMethodWithArguments(System.Int32 i, System.String s) - { - this.Apply(x => x.VoidMethodWithArguments(i, s)); - } - - public System.String NonVoidMethod() - { - return this.Apply(x => x.NonVoidMethod()); - } - - public System.String NonVoidMethodWithArguments(System.Int32 i, System.String s) - { - return this.Apply(x => x.NonVoidMethodWithArguments(i, s)); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NameClashInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NameClashInput_CSharp.txt deleted file mode 100644 index d5f31b5..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NameClashInput_CSharp.txt +++ /dev/null @@ -1,16 +0,0 @@ -using System; - -public interface ISomeInterface -{ - int this[int x] - { - get; - set; - } - - void SomeMethod(int x); - - void SomeMethod(int x, int _x); - - void SomeMethod(out float f, float _f); -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NameClashOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NameClashOutput_CSharp.txt deleted file mode 100644 index e7f6409..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NameClashOutput_CSharp.txt +++ /dev/null @@ -1,58 +0,0 @@ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - public partial class Mock : global::PCLMock.MockBase, global::ISomeInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public System.Int32 this[System.Int32 x] - { - get - { - return this.Apply(_x => _x[x]); - } - - set - { - this.ApplyPropertySet(_x => _x[x], value); - } - } - - public void SomeMethod(System.Int32 x) - { - this.Apply(_x => _x.SomeMethod(x)); - } - - public void SomeMethod(System.Int32 x, System.Int32 _x) - { - this.Apply(__x => __x.SomeMethod(x, _x)); - } - - public void SomeMethod(out System.Single f, System.Single _f) - { - System.Single __f; - f = (this.GetOutParameterValue(x => x.SomeMethod(out __f, _f), 0)); - this.Apply(x => x.SomeMethod(out __f, _f)); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NonMockableMembersInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NonMockableMembersInput_CSharp.txt deleted file mode 100644 index 74c7124..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NonMockableMembersInput_CSharp.txt +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -public interface IInterfaceWithNonMockableMembers -{ - int SomeProperty - { - get; - set; - } - - // PCLMock does not yet support mocking events (and possibly never will) - event EventHandler SomeEvent; -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NonMockableMembersOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NonMockableMembersOutput_CSharp.txt deleted file mode 100644 index f238c17..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/NonMockableMembersOutput_CSharp.txt +++ /dev/null @@ -1,41 +0,0 @@ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - public partial class Mock : global::PCLMock.MockBase, global::IInterfaceWithNonMockableMembers - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public System.Int32 SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - - set - { - this.ApplyPropertySet(x => x.SomeProperty, value); - } - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/OutAndRefInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/OutAndRefInput_CSharp.txt deleted file mode 100644 index bf5e9be..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/OutAndRefInput_CSharp.txt +++ /dev/null @@ -1,12 +0,0 @@ -public interface ISomeInterface -{ - void SomeMethod(out int i); - - void SomeMethod(out double d, int i); - - void SomeMethod(int i, out double d); - - void SomeMethod(ref int i, out string s); - - void SomeMethod(ref int i, out string s, double d); -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/OutAndRefOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/OutAndRefOutput_CSharp.txt deleted file mode 100644 index 44e322d..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/OutAndRefOutput_CSharp.txt +++ /dev/null @@ -1,67 +0,0 @@ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - public partial class Mock : global::PCLMock.MockBase, global::ISomeInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public void SomeMethod(out System.Int32 i) - { - System.Int32 _i; - i = (this.GetOutParameterValue(x => x.SomeMethod(out _i), 0)); - this.Apply(x => x.SomeMethod(out _i)); - } - - public void SomeMethod(out System.Double d, System.Int32 i) - { - System.Double _d; - d = (this.GetOutParameterValue(x => x.SomeMethod(out _d, i), 0)); - this.Apply(x => x.SomeMethod(out _d, i)); - } - - public void SomeMethod(System.Int32 i, out System.Double d) - { - System.Double _d; - d = (this.GetOutParameterValue(x => x.SomeMethod(i, out _d), 1)); - this.Apply(x => x.SomeMethod(i, out _d)); - } - - public void SomeMethod(ref System.Int32 i, out System.String s) - { - var _i = default (System.Int32); - System.String _s; - i = (this.GetRefParameterValue(x => x.SomeMethod(ref _i, out _s), 0)); - s = (this.GetOutParameterValue(x => x.SomeMethod(ref _i, out _s), 1)); - this.Apply(x => x.SomeMethod(ref _i, out _s)); - } - - public void SomeMethod(ref System.Int32 i, out System.String s, System.Double d) - { - var _i = default (System.Int32); - System.String _s; - i = (this.GetRefParameterValue(x => x.SomeMethod(ref _i, out _s, d), 0)); - s = (this.GetOutParameterValue(x => x.SomeMethod(ref _i, out _s, d), 1)); - this.Apply(x => x.SomeMethod(ref _i, out _s, d)); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/PartialInterfaceInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/PartialInterfaceInput_CSharp.txt deleted file mode 100644 index 80ddc6f..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/PartialInterfaceInput_CSharp.txt +++ /dev/null @@ -1,15 +0,0 @@ -public partial interface IPartialInterface -{ - int Property1 - { - get; - } -} - -public partial interface IPartialInterface -{ - int Property2 - { - get; - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/PartialInterfaceOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/PartialInterfaceOutput_CSharp.txt deleted file mode 100644 index 7c12142..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/PartialInterfaceOutput_CSharp.txt +++ /dev/null @@ -1,44 +0,0 @@ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - public partial class Mock : global::PCLMock.MockBase, global::IPartialInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public System.Int32 Property1 - { - get - { - return this.Apply(x => x.Property1); - } - } - - public System.Int32 Property2 - { - get - { - return this.Apply(x => x.Property2); - } - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceInput_CSharp.txt deleted file mode 100644 index 27c5137..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceInput_CSharp.txt +++ /dev/null @@ -1,26 +0,0 @@ -public interface ISimpleInterface -{ - int GetProperty - { - get; - } - - int SetProperty - { - set; - } - - int GetSetProperty - { - get; - set; - } - - void VoidMethod(); - - void VoidMethodWithArguments(int i, string s); - - string NonVoidMethod(); - - string NonVoidMethodWithArguments(int i, string s); -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceInput_VisualBasic.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceInput_VisualBasic.txt deleted file mode 100644 index 86ddf83..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceInput_VisualBasic.txt +++ /dev/null @@ -1,16 +0,0 @@ -Public Interface ISimpleInterface - ReadOnly Property GetProperty As Int32 - - WriteOnly Property SetProperty As Int32 - - Property GetSetProperty - - Sub VoidMethod() - - Sub VoidMethodWithArguments(i As Int32, s As String) - - Function NonVoidMethod() As String - - Function NonVoidMethodWithArguments(i As Int32, s As String) As String - -End Interface \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceOutput_CSharp.txt deleted file mode 100644 index 63fb4a9..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceOutput_CSharp.txt +++ /dev/null @@ -1,69 +0,0 @@ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - public partial class Mock : global::PCLMock.MockBase, global::ISimpleInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public System.Int32 GetProperty - { - get - { - return this.Apply(x => x.GetProperty); - } - } - - public System.Int32 GetSetProperty - { - get - { - return this.Apply(x => x.GetSetProperty); - } - - set - { - this.ApplyPropertySet(x => x.GetSetProperty, value); - } - } - - public void VoidMethod() - { - this.Apply(x => x.VoidMethod()); - } - - public void VoidMethodWithArguments(System.Int32 i, System.String s) - { - this.Apply(x => x.VoidMethodWithArguments(i, s)); - } - - public System.String NonVoidMethod() - { - return this.Apply(x => x.NonVoidMethod()); - } - - public System.String NonVoidMethodWithArguments(System.Int32 i, System.String s) - { - return this.Apply(x => x.NonVoidMethodWithArguments(i, s)); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceOutput_VisualBasic.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceOutput_VisualBasic.txt deleted file mode 100644 index b55477b..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/GeneratorFixtureResources/SimpleInterfaceOutput_VisualBasic.txt +++ /dev/null @@ -1,60 +0,0 @@ -Namespace The.[Namespace] - - - - Public Partial Class Mock - Inherits Global.PCLMock.MockBase(Of Global.ISimpleInterface) - Implements Global.ISimpleInterface - - Public Sub New(Optional behavior As Global.PCLMock.MockBehavior = Global.PCLMock.MockBehavior.Strict) - MyBase.New(behavior) - ConfigureBehaviorGenerated() - ConfigureBehavior() - If(behavior) = (Global.PCLMock.MockBehavior.Loose) Then - ConfigureLooseBehaviorGenerated() - ConfigureLooseBehavior() - End If - End Sub - - Private Sub ConfigureBehaviorGenerated() - End Sub - - Private Sub ConfigureLooseBehaviorGenerated() - End Sub - - Private Partial Sub ConfigureBehavior() - End Sub - - Private Partial Sub ConfigureLooseBehavior() - End Sub - - Public ReadOnly Property GetProperty As Int32 Implements Global.ISimpleInterface.GetProperty - Get - Return Me.Apply(Function(x) x.GetProperty) - End Get - End Property - - Public Property GetSetProperty As System.Object Implements Global.ISimpleInterface.GetSetProperty - Get - Return Me.Apply(Function(x) x.GetSetProperty) - End Get - - Set(value As System.Object) - Me.ApplyPropertySet(Function(x) x.GetSetProperty, value) - End Set - End Property - - Public Sub VoidMethod() Implements Global.ISimpleInterface.VoidMethod -THERE SHOULD BE SOMETHING HERE! - End Sub - - Public Sub VoidMethodWithArguments(i As Int32, s As System.String) Implements Global.ISimpleInterface.VoidMethodWithArguments - End Sub - - Public Function NonVoidMethod() As System.String Implements Global.ISimpleInterface.NonVoidMethod - End Function - - Public Function NonVoidMethodWithArguments(i As Int32, s As System.String) As System.String Implements Global.ISimpleInterface.NonVoidMethodWithArguments - End Function - End Class -End Namespace diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Models/ConfigurationFixture.cs b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Models/ConfigurationFixture.cs deleted file mode 100644 index 6fdbf04..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Models/ConfigurationFixture.cs +++ /dev/null @@ -1,46 +0,0 @@ -namespace PCLMock.UnitTests.CodeGeneration.Models -{ - using System.Xml.Linq; - using PCLMock.CodeGeneration.Logging; - using PCLMock.CodeGeneration.Models; - using Xunit; - - public sealed class ConfigurationFixture - { - [Fact] - public void from_xdocument_works_as_expected() - { - var inputResourceName = "PCLMock.UnitTests.CodeGeneration.Models.ConfigurationFixtureResources.Input.txt"; - - using (var inputStream = this.GetType().Assembly.GetManifestResourceStream(inputResourceName)) - { - var document = XDocument.Load(inputStream); - var configuration = Configuration.FromXDocument(NullLogSink.Instance, document); - - Assert.Equal(2, configuration.NamespaceTransformations.Count); - Assert.Equal("(?.+)", configuration.NamespaceTransformations[0].Pattern); - Assert.Equal("${name}.Mocks", configuration.NamespaceTransformations[0].Replacement); - Assert.Equal("Up", configuration.NamespaceTransformations[1].Pattern); - Assert.Equal("Down", configuration.NamespaceTransformations[1].Replacement); - - Assert.Equal(3, configuration.NameTransformations.Count); - Assert.Equal("I(?[A-Z].*)", configuration.NameTransformations[0].Pattern); - Assert.Equal("${name}", configuration.NameTransformations[0].Replacement); - Assert.Equal("(?[A-Z].*)\\<.*\\>", configuration.NameTransformations[1].Pattern); - Assert.Equal("${name}", configuration.NameTransformations[1].Replacement); - Assert.Equal("(?.+)", configuration.NameTransformations[2].Pattern); - Assert.Equal("${name}Mock", configuration.NameTransformations[2].Replacement); - - Assert.Equal(2, configuration.InterfaceFilters.Count); - Assert.Equal(FilterType.Include, configuration.InterfaceFilters[0].Type); - Assert.Equal(".*", configuration.InterfaceFilters[0].Pattern); - Assert.Equal(FilterType.Exclude, configuration.InterfaceFilters[1].Type); - Assert.Equal("FooBar", configuration.InterfaceFilters[1].Pattern); - - Assert.Equal(2, configuration.Plugins.Count); - Assert.Equal("Foo.Bar.Something, PCLMock.CodeGeneration", configuration.Plugins[0].AssemblyQualifiedName); - Assert.Equal("Foo.Bar.Baz, SomeAssembly", configuration.Plugins[1].AssemblyQualifiedName); - } - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Models/ConfigurationFixtureResources/Input.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Models/ConfigurationFixtureResources/Input.txt deleted file mode 100644 index 92fa89c..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Models/ConfigurationFixtureResources/Input.txt +++ /dev/null @@ -1,96 +0,0 @@ - - - - - - - - - .+)]]> - ${name}.Mocks - - - - - - - Up - Down - - - - - - - - [A-Z].*)]]> - ${name} - - - - [A-Z].*)\<.*\>]]> - ${name} - - - - .+)]]> - ${name}Mock - - - - - - - - - .* - - - - - FooBar - - - - - - - Foo.Bar.Something, PCLMock.CodeGeneration - Foo.Bar.Baz, SomeAssembly - - \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixture.cs b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixture.cs deleted file mode 100644 index fe29c93..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixture.cs +++ /dev/null @@ -1,102 +0,0 @@ -namespace PCLMock.UnitTests.CodeGeneration.Plugins -{ - using System; - using System.Collections.Immutable; - using System.IO; - using System.Linq; - using System.Reactive.Linq; - using System.Text; - using System.Threading.Tasks; - using Microsoft.CodeAnalysis; - using Microsoft.CodeAnalysis.Text; - using PCLMock.CodeGeneration; - using PCLMock.CodeGeneration.Logging; - using PCLMock.CodeGeneration.Plugins; - using Xunit; - - public sealed class CollectionsFixture - { - [Theory] - [InlineData("Enumerables", Language.CSharp)] - [InlineData("Collections", Language.CSharp)] - [InlineData("Lists", Language.CSharp)] - [InlineData("Dictionaries", Language.CSharp)] - [InlineData("Sets", Language.CSharp)] - [InlineData("ImmutableLists", Language.CSharp)] - [InlineData("ImmutableDictionaries", Language.CSharp)] - [InlineData("ImmutableQueues", Language.CSharp)] - [InlineData("ImmutableSets", Language.CSharp)] - [InlineData("ImmutableStacks", Language.CSharp)] - [InlineData("Recursive", Language.CSharp)] - public async Task can_generate_mocks(string resourceBaseName, Language language) - { - var inputResourceName = "PCLMock.UnitTests.CodeGeneration.Plugins.CollectionsFixtureResources." + resourceBaseName + "Input_" + language.ToString() + ".txt"; - var outputResourceName = "PCLMock.UnitTests.CodeGeneration.Plugins.CollectionsFixtureResources." + resourceBaseName + "Output_" + language.ToString() + ".txt"; - - using (var inputStream = this.GetType().Assembly.GetManifestResourceStream(inputResourceName)) - using (var outputStream = this.GetType().Assembly.GetManifestResourceStream(outputResourceName)) - using (var outputStreamReader = new StreamReader(outputStream)) - { - var workspace = new AdhocWorkspace(); - var projectId = ProjectId.CreateNewId(); - var versionStamp = VersionStamp.Create(); - var projectInfo = ProjectInfo.Create( - projectId, - versionStamp, - "AdhocProject", - "AdhocProject", - language.ToSyntaxGeneratorLanguageName(), - metadataReferences: new[] - { - MetadataReference.CreateFromFile(typeof(object).Assembly.Location), - MetadataReference.CreateFromFile(typeof(Uri).Assembly.Location), - MetadataReference.CreateFromFile(typeof(MockBase<>).Assembly.Location), - MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location), - MetadataReference.CreateFromFile(typeof(ImmutableList).Assembly.Location) - }); - var project = workspace.AddProject(projectInfo); - workspace.AddDocument(projectId, "Source.cs", SourceText.From(inputStream)); - var solution = workspace.CurrentSolution; - - var results = - (await Generator.GenerateMocksAsync( - NullLogSink.Instance, - language, - solution, - x => true, - x => "The.Namespace", - x => "Mock", - new IPlugin[] - { - new Collections() - }.ToImmutableList())); - var result = results - .Aggregate( - new StringBuilder(), - (acc, next) => - { - if (next != null) - { - acc.AppendLine(next.ToFullString()); - } - - return acc; - }, - acc => acc.ToString()) - .NormalizeLineEndings(); - - var expectedCode = outputStreamReader.ReadToEnd(); - - // make sure version changes don't break the tests - expectedCode = expectedCode - .Replace("$VERSION$", typeof(MockBase<>).Assembly.GetName().Version.ToString()) - .NormalizeLineEndings(); - - // useful when converting generated code to something that can be pasted into an expectation file - var sanitisedResult = result.Replace(typeof(MockBase<>).Assembly.GetName().Version.ToString(), "$VERSION$"); - - Assert.Equal(expectedCode, result); - } - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/CollectionsInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/CollectionsInput_CSharp.txt deleted file mode 100644 index 1c237cf..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/CollectionsInput_CSharp.txt +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.Collections.Generic; - -interface ICustomCollection : ICollection -{ -} - -interface ISomeInterface -{ - ICollection SomeProperty - { - get; - } - - // expecting this to be ignored because it's set-only - ICollection SomeSetOnlyProperty - { - set; - } - - IReadOnlyCollection SomeReadOnlyProperty - { - get; - } - - ICollection SomeMethod(); - ICollection SomeMethod(int i, float f); - - // should all be ignored because they're generic - ICollection SomeGenericMethod(); - ICollection SomeOtherGenericMethod(); - - // should be ignored because they're a custom enumerable type - ICustomCollection SomeCustomProperty - { - get; - } - - ICustomCollection SomeMethod(); - ICustomCollection SomeMethod(int i, float f); -} - -interface ISomeGenericInterface -{ - ICollection SomeProperty - { - get; - } - - ICollection SomeMethod(); - ICollection SomeMethod(int i, float f); -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/CollectionsOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/CollectionsOutput_CSharp.txt deleted file mode 100644 index cc8d809..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/CollectionsOutput_CSharp.txt +++ /dev/null @@ -1,217 +0,0 @@ -// ----------------------------------------------------------------------- -// -// This code was generated from a template. -// -// Changes to this file may cause incorrect behaviour and will be lost -// if the code is regenerated. -// -// ------------------------------------------------------------------------ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ICustomCollection - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public void Add(T item) - { - this.Apply(x => x.Add(item)); - } - - public void Clear() - { - this.Apply(x => x.Clear()); - } - - public System.Boolean Contains(T item) - { - return this.Apply(x => x.Contains(item)); - } - - public void CopyTo(T[] array, System.Int32 arrayIndex) - { - this.Apply(x => x.CopyTo(array, arrayIndex)); - } - - public System.Boolean Remove(T item) - { - return this.Apply(x => x.Remove(item)); - } - - public System.Int32 Count - { - get - { - return this.Apply(x => x.Count); - } - } - - public System.Boolean IsReadOnly - { - get - { - return this.Apply(x => x.IsReadOnly); - } - } - - public global::System.Collections.Generic.IEnumerator GetEnumerator() - { - return this.Apply(x => x.GetEnumerator()); - } - } -} -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.List()); - this.When(x => x.SomeReadOnlyProperty).Return(new global::System.Collections.Generic.List()); - this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.List()); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.List()); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Collections.Generic.ICollection SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - - public global::System.Collections.Generic.IReadOnlyCollection SomeReadOnlyProperty - { - get - { - return this.Apply(x => x.SomeReadOnlyProperty); - } - } - - public global::System.Collections.Generic.ICollection SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::System.Collections.Generic.ICollection SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - - public global::System.Collections.Generic.ICollection SomeGenericMethod() - { - return this.Apply(x => x.SomeGenericMethod()); - } - - public global::System.Collections.Generic.ICollection SomeOtherGenericMethod() - { - return this.Apply(x => x.SomeOtherGenericMethod()); - } - - public global::ICustomCollection SomeCustomProperty - { - get - { - return this.Apply(x => x.SomeCustomProperty); - } - } - - public global::ICustomCollection SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::ICustomCollection SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - } -} -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.List()); - this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.List()); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.List()); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Collections.Generic.ICollection SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - - public global::System.Collections.Generic.ICollection SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::System.Collections.Generic.ICollection SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - } -} diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/DictionariesInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/DictionariesInput_CSharp.txt deleted file mode 100644 index be2eb9f..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/DictionariesInput_CSharp.txt +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.Collections.Generic; - -interface ICustomDictionary : IDictionary -{ -} - -interface ISomeInterface -{ - IDictionary SomeProperty - { - get; - } - - // expecting this to be ignored because it's set-only - IDictionary SomeSetOnlyProperty - { - set; - } - - IReadOnlyDictionary SomeReadOnlyProperty - { - get; - } - - IDictionary SomeMethod(); - IDictionary SomeMethod(int i, float f); - - // should all be ignored because they're generic - IDictionary SomeGenericMethod(); - IDictionary SomeOtherGenericMethod(); - - // should be ignored because they're a custom enumerable type - ICustomDictionary SomeCustomProperty - { - get; - } - - ICustomDictionary SomeMethod(); - ICustomDictionary SomeMethod(int i, float f); -} - -interface ISomeGenericInterface -{ - IDictionary SomeProperty - { - get; - } - - IDictionary SomeMethod(); - IDictionary SomeMethod(int i, float f); -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/DictionariesOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/DictionariesOutput_CSharp.txt deleted file mode 100644 index cbac9bc..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/DictionariesOutput_CSharp.txt +++ /dev/null @@ -1,265 +0,0 @@ -// ----------------------------------------------------------------------- -// -// This code was generated from a template. -// -// Changes to this file may cause incorrect behaviour and will be lost -// if the code is regenerated. -// -// ------------------------------------------------------------------------ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ICustomDictionary - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.Keys).Return(new global::System.Collections.Generic.List()); - this.When(x => x.Values).Return(new global::System.Collections.Generic.List()); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public System.Boolean ContainsKey(TKey key) - { - return this.Apply(x => x.ContainsKey(key)); - } - - public void Add(TKey key, TValue value) - { - this.Apply(x => x.Add(key, value)); - } - - public System.Boolean Remove(TKey key) - { - return this.Apply(x => x.Remove(key)); - } - - public System.Boolean TryGetValue(TKey key, out TValue value) - { - TValue _value; - value = (this.GetOutParameterValue(x => x.TryGetValue(key, out _value), 1)); - return this.Apply(x => x.TryGetValue(key, out _value)); - } - - public TValue this[TKey key] - { - get - { - return this.Apply(x => x[key]); - } - - set - { - this.ApplyPropertySet(x => x[key], value); - } - } - - public global::System.Collections.Generic.ICollection Keys - { - get - { - return this.Apply(x => x.Keys); - } - } - - public global::System.Collections.Generic.ICollection Values - { - get - { - return this.Apply(x => x.Values); - } - } - - public void Add(global::System.Collections.Generic.KeyValuePair item) - { - this.Apply(x => x.Add(item)); - } - - public void Clear() - { - this.Apply(x => x.Clear()); - } - - public System.Boolean Contains(global::System.Collections.Generic.KeyValuePair item) - { - return this.Apply(x => x.Contains(item)); - } - - public void CopyTo(global::System.Collections.Generic.KeyValuePair[] array, System.Int32 arrayIndex) - { - this.Apply(x => x.CopyTo(array, arrayIndex)); - } - - public System.Boolean Remove(global::System.Collections.Generic.KeyValuePair item) - { - return this.Apply(x => x.Remove(item)); - } - - public System.Int32 Count - { - get - { - return this.Apply(x => x.Count); - } - } - - public System.Boolean IsReadOnly - { - get - { - return this.Apply(x => x.IsReadOnly); - } - } - } -} -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.Dictionary()); - this.When(x => x.SomeReadOnlyProperty).Return(new global::System.Collections.Generic.Dictionary()); - this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.Dictionary()); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.Dictionary()); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Collections.Generic.IDictionary SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - - public global::System.Collections.Generic.IReadOnlyDictionary SomeReadOnlyProperty - { - get - { - return this.Apply(x => x.SomeReadOnlyProperty); - } - } - - public global::System.Collections.Generic.IDictionary SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::System.Collections.Generic.IDictionary SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - - public global::System.Collections.Generic.IDictionary SomeGenericMethod() - { - return this.Apply(x => x.SomeGenericMethod()); - } - - public global::System.Collections.Generic.IDictionary SomeOtherGenericMethod() - { - return this.Apply(x => x.SomeOtherGenericMethod()); - } - - public global::ICustomDictionary SomeCustomProperty - { - get - { - return this.Apply(x => x.SomeCustomProperty); - } - } - - public global::ICustomDictionary SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::ICustomDictionary SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - } -} -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.Dictionary()); - this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.Dictionary()); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.Dictionary()); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Collections.Generic.IDictionary SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - - public global::System.Collections.Generic.IDictionary SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::System.Collections.Generic.IDictionary SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - } -} diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/EnumerablesInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/EnumerablesInput_CSharp.txt deleted file mode 100644 index 305935d..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/EnumerablesInput_CSharp.txt +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Collections.Generic; - -interface ICustomEnumerable : IEnumerable -{ -} - -interface ISomeInterface -{ - IEnumerable SomeProperty - { - get; - } - - // expecting this to be ignored because it's set-only - IEnumerable SomeSetOnlyProperty - { - set; - } - - IEnumerable SomeMethod(); - IEnumerable SomeMethod(int i, float f); - - // should all be ignored because they're generic - IEnumerable SomeGenericMethod(); - IEnumerable SomeOtherGenericMethod(); - - // should be ignored because they're a custom enumerable type - ICustomEnumerable SomeCustomProperty - { - get; - } - - ICustomEnumerable SomeMethod(); - ICustomEnumerable SomeMethod(int i, float f); -} - -interface ISomeGenericInterface -{ - IEnumerable SomeProperty - { - get; - } - - IEnumerable SomeMethod(); - IEnumerable SomeMethod(int i, float f); -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/EnumerablesOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/EnumerablesOutput_CSharp.txt deleted file mode 100644 index b446501..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/EnumerablesOutput_CSharp.txt +++ /dev/null @@ -1,172 +0,0 @@ -// ----------------------------------------------------------------------- -// -// This code was generated from a template. -// -// Changes to this file may cause incorrect behaviour and will be lost -// if the code is regenerated. -// -// ------------------------------------------------------------------------ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ICustomEnumerable - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Collections.Generic.IEnumerator GetEnumerator() - { - return this.Apply(x => x.GetEnumerator()); - } - - public global::System.Collections.IEnumerator GetEnumerator() - { - return this.Apply(x => x.GetEnumerator()); - } - } -} -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.SomeProperty).Return(global::System.Linq.Enumerable.Empty()); - this.When(x => x.SomeMethod()).Return(global::System.Linq.Enumerable.Empty()); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Linq.Enumerable.Empty()); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Collections.Generic.IEnumerable SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - - public global::System.Collections.Generic.IEnumerable SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::System.Collections.Generic.IEnumerable SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - - public global::System.Collections.Generic.IEnumerable SomeGenericMethod() - { - return this.Apply(x => x.SomeGenericMethod()); - } - - public global::System.Collections.Generic.IEnumerable SomeOtherGenericMethod() - { - return this.Apply(x => x.SomeOtherGenericMethod()); - } - - public global::ICustomEnumerable SomeCustomProperty - { - get - { - return this.Apply(x => x.SomeCustomProperty); - } - } - - public global::ICustomEnumerable SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::ICustomEnumerable SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - } -} -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.SomeProperty).Return(global::System.Linq.Enumerable.Empty()); - this.When(x => x.SomeMethod()).Return(global::System.Linq.Enumerable.Empty()); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Linq.Enumerable.Empty()); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Collections.Generic.IEnumerable SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - - public global::System.Collections.Generic.IEnumerable SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::System.Collections.Generic.IEnumerable SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - } -} diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableDictionariesInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableDictionariesInput_CSharp.txt deleted file mode 100644 index 392a383..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableDictionariesInput_CSharp.txt +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Collections.Immutable; - -interface ICustomImmutableDictionary : IImmutableDictionary -{ -} - -interface ISomeInterface -{ - IImmutableDictionary SomeProperty - { - get; - } - - // expecting this to be ignored because it's set-only - IImmutableDictionary SomeSetOnlyProperty - { - set; - } - - IImmutableDictionary SomeMethod(); - IImmutableDictionary SomeMethod(int i, float f); - - // should all be ignored because they're generic - IImmutableDictionary SomeGenericMethod(); - IImmutableDictionary SomeOtherGenericMethod(); - - // should be ignored because they're a custom enumerable type - ICustomImmutableDictionary SomeCustomProperty - { - get; - } - - ICustomImmutableDictionary SomeMethod(); - ICustomImmutableDictionary SomeMethod(int i, float f); -} - -interface ISomeGenericInterface -{ - IImmutableDictionary SomeProperty - { - get; - } - - IImmutableDictionary SomeMethod(); - IImmutableDictionary SomeMethod(int i, float f); -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableDictionariesOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableDictionariesOutput_CSharp.txt deleted file mode 100644 index b4aae18..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableDictionariesOutput_CSharp.txt +++ /dev/null @@ -1,216 +0,0 @@ -// ----------------------------------------------------------------------- -// -// This code was generated from a template. -// -// Changes to this file may cause incorrect behaviour and will be lost -// if the code is regenerated. -// -// ------------------------------------------------------------------------ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ICustomImmutableDictionary - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.Clear()).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); - this.When(x => x.Add(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); - this.When(x => x.AddRange(global::PCLMock.It.IsAny>>())).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); - this.When(x => x.SetItem(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); - this.When(x => x.SetItems(global::PCLMock.It.IsAny>>())).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); - this.When(x => x.RemoveRange(global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); - this.When(x => x.Remove(global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Collections.Immutable.IImmutableDictionary Clear() - { - return this.Apply(x => x.Clear()); - } - - public global::System.Collections.Immutable.IImmutableDictionary Add(TKey key, TValue value) - { - return this.Apply(x => x.Add(key, value)); - } - - public global::System.Collections.Immutable.IImmutableDictionary AddRange(global::System.Collections.Generic.IEnumerable> pairs) - { - return this.Apply(x => x.AddRange(pairs)); - } - - public global::System.Collections.Immutable.IImmutableDictionary SetItem(TKey key, TValue value) - { - return this.Apply(x => x.SetItem(key, value)); - } - - public global::System.Collections.Immutable.IImmutableDictionary SetItems(global::System.Collections.Generic.IEnumerable> items) - { - return this.Apply(x => x.SetItems(items)); - } - - public global::System.Collections.Immutable.IImmutableDictionary RemoveRange(global::System.Collections.Generic.IEnumerable keys) - { - return this.Apply(x => x.RemoveRange(keys)); - } - - public global::System.Collections.Immutable.IImmutableDictionary Remove(TKey key) - { - return this.Apply(x => x.Remove(key)); - } - - public System.Boolean Contains(global::System.Collections.Generic.KeyValuePair pair) - { - return this.Apply(x => x.Contains(pair)); - } - - public System.Boolean TryGetKey(TKey equalKey, out TKey actualKey) - { - TKey _actualKey; - actualKey = (this.GetOutParameterValue(x => x.TryGetKey(equalKey, out _actualKey), 1)); - return this.Apply(x => x.TryGetKey(equalKey, out _actualKey)); - } - } -} -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); - this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Collections.Immutable.IImmutableDictionary SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - - public global::System.Collections.Immutable.IImmutableDictionary SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::System.Collections.Immutable.IImmutableDictionary SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - - public global::System.Collections.Immutable.IImmutableDictionary SomeGenericMethod() - { - return this.Apply(x => x.SomeGenericMethod()); - } - - public global::System.Collections.Immutable.IImmutableDictionary SomeOtherGenericMethod() - { - return this.Apply(x => x.SomeOtherGenericMethod()); - } - - public global::ICustomImmutableDictionary SomeCustomProperty - { - get - { - return this.Apply(x => x.SomeCustomProperty); - } - } - - public global::ICustomImmutableDictionary SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::ICustomImmutableDictionary SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - } -} -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); - this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableDictionary.Empty); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Collections.Immutable.IImmutableDictionary SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - - public global::System.Collections.Immutable.IImmutableDictionary SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::System.Collections.Immutable.IImmutableDictionary SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - } -} diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableListsInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableListsInput_CSharp.txt deleted file mode 100644 index e5d2523..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableListsInput_CSharp.txt +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Collections.Immutable; - -interface ICustomImmutableList : IImmutableList -{ -} - -interface ISomeInterface -{ - IImmutableList SomeProperty - { - get; - } - - // expecting this to be ignored because it's set-only - IImmutableList SomeSetOnlyProperty - { - set; - } - - IImmutableList SomeMethod(); - IImmutableList SomeMethod(int i, float f); - - // should all be ignored because they're generic - IImmutableList SomeGenericMethod(); - IImmutableList SomeOtherGenericMethod(); - - // should be ignored because they're a custom enumerable type - ICustomIImmutableList SomeCustomProperty - { - get; - } - - ICustomIImmutableList SomeMethod(); - ICustomIImmutableList SomeMethod(int i, float f); -} - -interface ISomeGenericInterface -{ - IImmutableList SomeProperty - { - get; - } - - IImmutableList SomeMethod(); - IImmutableList SomeMethod(int i, float f); -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableListsOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableListsOutput_CSharp.txt deleted file mode 100644 index 39b17a1..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableListsOutput_CSharp.txt +++ /dev/null @@ -1,244 +0,0 @@ -// ----------------------------------------------------------------------- -// -// This code was generated from a template. -// -// Changes to this file may cause incorrect behaviour and will be lost -// if the code is regenerated. -// -// ------------------------------------------------------------------------ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ICustomImmutableList - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.Clear()).Return(global::System.Collections.Immutable.ImmutableList.Empty); - this.When(x => x.Add(global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); - this.When(x => x.AddRange(global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableList.Empty); - this.When(x => x.Insert(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); - this.When(x => x.InsertRange(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableList.Empty); - this.When(x => x.Remove(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableList.Empty); - this.When(x => x.RemoveAll(global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableList.Empty); - this.When(x => x.RemoveRange(global::PCLMock.It.IsAny>(), global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableList.Empty); - this.When(x => x.RemoveRange(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); - this.When(x => x.RemoveAt(global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); - this.When(x => x.SetItem(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); - this.When(x => x.Replace(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableList.Empty); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Collections.Immutable.IImmutableList Clear() - { - return this.Apply(x => x.Clear()); - } - - public System.Int32 IndexOf(T item, System.Int32 index, System.Int32 count, global::System.Collections.Generic.IEqualityComparer equalityComparer) - { - return this.Apply(x => x.IndexOf(item, index, count, equalityComparer)); - } - - public System.Int32 LastIndexOf(T item, System.Int32 index, System.Int32 count, global::System.Collections.Generic.IEqualityComparer equalityComparer) - { - return this.Apply(x => x.LastIndexOf(item, index, count, equalityComparer)); - } - - public global::System.Collections.Immutable.IImmutableList Add(T value) - { - return this.Apply(x => x.Add(value)); - } - - public global::System.Collections.Immutable.IImmutableList AddRange(global::System.Collections.Generic.IEnumerable items) - { - return this.Apply(x => x.AddRange(items)); - } - - public global::System.Collections.Immutable.IImmutableList Insert(System.Int32 index, T element) - { - return this.Apply(x => x.Insert(index, element)); - } - - public global::System.Collections.Immutable.IImmutableList InsertRange(System.Int32 index, global::System.Collections.Generic.IEnumerable items) - { - return this.Apply(x => x.InsertRange(index, items)); - } - - public global::System.Collections.Immutable.IImmutableList Remove(T value, global::System.Collections.Generic.IEqualityComparer equalityComparer) - { - return this.Apply(x => x.Remove(value, equalityComparer)); - } - - public global::System.Collections.Immutable.IImmutableList RemoveAll(global::System.Predicate match) - { - return this.Apply(x => x.RemoveAll(match)); - } - - public global::System.Collections.Immutable.IImmutableList RemoveRange(global::System.Collections.Generic.IEnumerable items, global::System.Collections.Generic.IEqualityComparer equalityComparer) - { - return this.Apply(x => x.RemoveRange(items, equalityComparer)); - } - - public global::System.Collections.Immutable.IImmutableList RemoveRange(System.Int32 index, System.Int32 count) - { - return this.Apply(x => x.RemoveRange(index, count)); - } - - public global::System.Collections.Immutable.IImmutableList RemoveAt(System.Int32 index) - { - return this.Apply(x => x.RemoveAt(index)); - } - - public global::System.Collections.Immutable.IImmutableList SetItem(System.Int32 index, T value) - { - return this.Apply(x => x.SetItem(index, value)); - } - - public global::System.Collections.Immutable.IImmutableList Replace(T oldValue, T newValue, global::System.Collections.Generic.IEqualityComparer equalityComparer) - { - return this.Apply(x => x.Replace(oldValue, newValue, equalityComparer)); - } - } -} -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableList.Empty); - this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableList.Empty); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Collections.Immutable.IImmutableList SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - - public global::System.Collections.Immutable.IImmutableList SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::System.Collections.Immutable.IImmutableList SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - - public global::System.Collections.Immutable.IImmutableList SomeGenericMethod() - { - return this.Apply(x => x.SomeGenericMethod()); - } - - public global::System.Collections.Immutable.IImmutableList SomeOtherGenericMethod() - { - return this.Apply(x => x.SomeOtherGenericMethod()); - } - - public ICustomIImmutableList SomeCustomProperty - { - get - { - return this.Apply(x => x.SomeCustomProperty); - } - } - - public ICustomIImmutableList SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public ICustomIImmutableList SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - } -} -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableList.Empty); - this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableList.Empty); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableList.Empty); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Collections.Immutable.IImmutableList SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - - public global::System.Collections.Immutable.IImmutableList SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::System.Collections.Immutable.IImmutableList SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - } -} diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableQueuesInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableQueuesInput_CSharp.txt deleted file mode 100644 index 3daf01d..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableQueuesInput_CSharp.txt +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Collections.Immutable; - -interface ICustomImmutableQueue : IImmutableQueue -{ -} - -interface ISomeInterface -{ - IImmutableQueue SomeProperty - { - get; - } - - // expecting this to be ignored because it's set-only - IImmutableQueue SomeSetOnlyProperty - { - set; - } - - IImmutableQueue SomeMethod(); - IImmutableQueue SomeMethod(int i, float f); - - // should all be ignored because they're generic - IImmutableQueue SomeGenericMethod(); - IImmutableQueue SomeOtherGenericMethod(); - - // should be ignored because they're a custom enumerable type - ICustomIImmutableQueue SomeCustomProperty - { - get; - } - - ICustomIImmutableQueue SomeMethod(); - ICustomIImmutableQueue SomeMethod(int i, float f); -} - -interface ISomeGenericInterface -{ - IImmutableQueue SomeProperty - { - get; - } - - IImmutableQueue SomeMethod(); - IImmutableQueue SomeMethod(int i, float f); -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableQueuesOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableQueuesOutput_CSharp.txt deleted file mode 100644 index f91b3ae..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableQueuesOutput_CSharp.txt +++ /dev/null @@ -1,193 +0,0 @@ -// ----------------------------------------------------------------------- -// -// This code was generated from a template. -// -// Changes to this file may cause incorrect behaviour and will be lost -// if the code is regenerated. -// -// ------------------------------------------------------------------------ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ICustomImmutableQueue - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.Clear()).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); - this.When(x => x.Enqueue(global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); - this.When(x => x.Dequeue()).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Collections.Immutable.IImmutableQueue Clear() - { - return this.Apply(x => x.Clear()); - } - - public T Peek() - { - return this.Apply(x => x.Peek()); - } - - public global::System.Collections.Immutable.IImmutableQueue Enqueue(T value) - { - return this.Apply(x => x.Enqueue(value)); - } - - public global::System.Collections.Immutable.IImmutableQueue Dequeue() - { - return this.Apply(x => x.Dequeue()); - } - - public System.Boolean IsEmpty - { - get - { - return this.Apply(x => x.IsEmpty); - } - } - } -} -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); - this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Collections.Immutable.IImmutableQueue SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - - public global::System.Collections.Immutable.IImmutableQueue SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::System.Collections.Immutable.IImmutableQueue SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - - public global::System.Collections.Immutable.IImmutableQueue SomeGenericMethod() - { - return this.Apply(x => x.SomeGenericMethod()); - } - - public global::System.Collections.Immutable.IImmutableQueue SomeOtherGenericMethod() - { - return this.Apply(x => x.SomeOtherGenericMethod()); - } - - public ICustomIImmutableQueue SomeCustomProperty - { - get - { - return this.Apply(x => x.SomeCustomProperty); - } - } - - public ICustomIImmutableQueue SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public ICustomIImmutableQueue SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - } -} -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); - this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableQueue.Empty); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Collections.Immutable.IImmutableQueue SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - - public global::System.Collections.Immutable.IImmutableQueue SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::System.Collections.Immutable.IImmutableQueue SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - } -} diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableSetsInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableSetsInput_CSharp.txt deleted file mode 100644 index 13addfd..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableSetsInput_CSharp.txt +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Collections.Immutable; - -interface ICustomImmutableSet : IImmutableSet -{ -} - -interface ISomeInterface -{ - IImmutableSet SomeProperty - { - get; - } - - // expecting this to be ignored because it's set-only - IImmutableSet SomeSetOnlyProperty - { - set; - } - - IImmutableSet SomeMethod(); - IImmutableSet SomeMethod(int i, float f); - - // should all be ignored because they're generic - IImmutableSet SomeGenericMethod(); - IImmutableSet SomeOtherGenericMethod(); - - // should be ignored because they're a custom enumerable type - ICustomIImmutableSet SomeCustomProperty - { - get; - } - - ICustomIImmutableSet SomeMethod(); - ICustomIImmutableSet SomeMethod(int i, float f); -} - -interface ISomeGenericInterface -{ - IImmutableSet SomeProperty - { - get; - } - - IImmutableSet SomeMethod(); - IImmutableSet SomeMethod(int i, float f); -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableSetsOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableSetsOutput_CSharp.txt deleted file mode 100644 index c0f0849..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableSetsOutput_CSharp.txt +++ /dev/null @@ -1,246 +0,0 @@ -// ----------------------------------------------------------------------- -// -// This code was generated from a template. -// -// Changes to this file may cause incorrect behaviour and will be lost -// if the code is regenerated. -// -// ------------------------------------------------------------------------ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ICustomImmutableSet - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.Clear()).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); - this.When(x => x.Add(global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); - this.When(x => x.Remove(global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); - this.When(x => x.Intersect(global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); - this.When(x => x.Except(global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); - this.When(x => x.SymmetricExcept(global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); - this.When(x => x.Union(global::PCLMock.It.IsAny>())).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Collections.Immutable.IImmutableSet Clear() - { - return this.Apply(x => x.Clear()); - } - - public System.Boolean Contains(T value) - { - return this.Apply(x => x.Contains(value)); - } - - public global::System.Collections.Immutable.IImmutableSet Add(T value) - { - return this.Apply(x => x.Add(value)); - } - - public global::System.Collections.Immutable.IImmutableSet Remove(T value) - { - return this.Apply(x => x.Remove(value)); - } - - public System.Boolean TryGetValue(T equalValue, out T actualValue) - { - T _actualValue; - actualValue = (this.GetOutParameterValue(x => x.TryGetValue(equalValue, out _actualValue), 1)); - return this.Apply(x => x.TryGetValue(equalValue, out _actualValue)); - } - - public global::System.Collections.Immutable.IImmutableSet Intersect(global::System.Collections.Generic.IEnumerable other) - { - return this.Apply(x => x.Intersect(other)); - } - - public global::System.Collections.Immutable.IImmutableSet Except(global::System.Collections.Generic.IEnumerable other) - { - return this.Apply(x => x.Except(other)); - } - - public global::System.Collections.Immutable.IImmutableSet SymmetricExcept(global::System.Collections.Generic.IEnumerable other) - { - return this.Apply(x => x.SymmetricExcept(other)); - } - - public global::System.Collections.Immutable.IImmutableSet Union(global::System.Collections.Generic.IEnumerable other) - { - return this.Apply(x => x.Union(other)); - } - - public System.Boolean SetEquals(global::System.Collections.Generic.IEnumerable other) - { - return this.Apply(x => x.SetEquals(other)); - } - - public System.Boolean IsProperSubsetOf(global::System.Collections.Generic.IEnumerable other) - { - return this.Apply(x => x.IsProperSubsetOf(other)); - } - - public System.Boolean IsProperSupersetOf(global::System.Collections.Generic.IEnumerable other) - { - return this.Apply(x => x.IsProperSupersetOf(other)); - } - - public System.Boolean IsSubsetOf(global::System.Collections.Generic.IEnumerable other) - { - return this.Apply(x => x.IsSubsetOf(other)); - } - - public System.Boolean IsSupersetOf(global::System.Collections.Generic.IEnumerable other) - { - return this.Apply(x => x.IsSupersetOf(other)); - } - - public System.Boolean Overlaps(global::System.Collections.Generic.IEnumerable other) - { - return this.Apply(x => x.Overlaps(other)); - } - } -} -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); - this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Collections.Immutable.IImmutableSet SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - - public global::System.Collections.Immutable.IImmutableSet SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::System.Collections.Immutable.IImmutableSet SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - - public global::System.Collections.Immutable.IImmutableSet SomeGenericMethod() - { - return this.Apply(x => x.SomeGenericMethod()); - } - - public global::System.Collections.Immutable.IImmutableSet SomeOtherGenericMethod() - { - return this.Apply(x => x.SomeOtherGenericMethod()); - } - - public ICustomIImmutableSet SomeCustomProperty - { - get - { - return this.Apply(x => x.SomeCustomProperty); - } - } - - public ICustomIImmutableSet SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public ICustomIImmutableSet SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - } -} -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); - this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableHashSet.Empty); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Collections.Immutable.IImmutableSet SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - - public global::System.Collections.Immutable.IImmutableSet SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::System.Collections.Immutable.IImmutableSet SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - } -} diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableStacksInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableStacksInput_CSharp.txt deleted file mode 100644 index 801c729..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableStacksInput_CSharp.txt +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Collections.Immutable; - -interface ICustomImmutableStack : IImmutableStack -{ -} - -interface ISomeInterface -{ - IImmutableStack SomeProperty - { - get; - } - - // expecting this to be ignored because it's set-only - IImmutableStack SomeSetOnlyProperty - { - set; - } - - IImmutableStack SomeMethod(); - IImmutableStack SomeMethod(int i, float f); - - // should all be ignored because they're generic - IImmutableStack SomeGenericMethod(); - IImmutableStack SomeOtherGenericMethod(); - - // should be ignored because they're a custom enumerable type - ICustomIImmutableStack SomeCustomProperty - { - get; - } - - ICustomIImmutableStack SomeMethod(); - ICustomIImmutableStack SomeMethod(int i, float f); -} - -interface ISomeGenericInterface -{ - IImmutableStack SomeProperty - { - get; - } - - IImmutableStack SomeMethod(); - IImmutableStack SomeMethod(int i, float f); -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableStacksOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableStacksOutput_CSharp.txt deleted file mode 100644 index 592ddf8..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ImmutableStacksOutput_CSharp.txt +++ /dev/null @@ -1,193 +0,0 @@ -// ----------------------------------------------------------------------- -// -// This code was generated from a template. -// -// Changes to this file may cause incorrect behaviour and will be lost -// if the code is regenerated. -// -// ------------------------------------------------------------------------ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ICustomImmutableStack - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.Clear()).Return(global::System.Collections.Immutable.ImmutableStack.Empty); - this.When(x => x.Push(global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableStack.Empty); - this.When(x => x.Pop()).Return(global::System.Collections.Immutable.ImmutableStack.Empty); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Collections.Immutable.IImmutableStack Clear() - { - return this.Apply(x => x.Clear()); - } - - public global::System.Collections.Immutable.IImmutableStack Push(T value) - { - return this.Apply(x => x.Push(value)); - } - - public global::System.Collections.Immutable.IImmutableStack Pop() - { - return this.Apply(x => x.Pop()); - } - - public T Peek() - { - return this.Apply(x => x.Peek()); - } - - public System.Boolean IsEmpty - { - get - { - return this.Apply(x => x.IsEmpty); - } - } - } -} -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableStack.Empty); - this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableStack.Empty); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableStack.Empty); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Collections.Immutable.IImmutableStack SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - - public global::System.Collections.Immutable.IImmutableStack SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::System.Collections.Immutable.IImmutableStack SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - - public global::System.Collections.Immutable.IImmutableStack SomeGenericMethod() - { - return this.Apply(x => x.SomeGenericMethod()); - } - - public global::System.Collections.Immutable.IImmutableStack SomeOtherGenericMethod() - { - return this.Apply(x => x.SomeOtherGenericMethod()); - } - - public ICustomIImmutableStack SomeCustomProperty - { - get - { - return this.Apply(x => x.SomeCustomProperty); - } - } - - public ICustomIImmutableStack SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public ICustomIImmutableStack SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - } -} -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.SomeProperty).Return(global::System.Collections.Immutable.ImmutableStack.Empty); - this.When(x => x.SomeMethod()).Return(global::System.Collections.Immutable.ImmutableStack.Empty); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Collections.Immutable.ImmutableStack.Empty); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Collections.Immutable.IImmutableStack SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - - public global::System.Collections.Immutable.IImmutableStack SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::System.Collections.Immutable.IImmutableStack SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - } -} diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ListsInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ListsInput_CSharp.txt deleted file mode 100644 index 807aad0..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ListsInput_CSharp.txt +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.Collections.Generic; - -interface ICustomList : IList -{ -} - -interface ISomeInterface -{ - IList SomeProperty - { - get; - } - - // expecting this to be ignored because it's set-only - IList SomeSetOnlyProperty - { - set; - } - - IReadOnlyList SomeReadOnlyProperty - { - get; - } - - IList SomeMethod(); - IList SomeMethod(int i, float f); - - // should all be ignored because they're generic - IList SomeGenericMethod(); - IList SomeOtherGenericMethod(); - - // should be ignored because they're a custom enumerable type - ICustomList SomeCustomProperty - { - get; - } - - ICustomList SomeMethod(); - ICustomList SomeMethod(int i, float f); -} - -interface ISomeGenericInterface -{ - IList SomeProperty - { - get; - } - - IList SomeMethod(); - IList SomeMethod(int i, float f); -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ListsOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ListsOutput_CSharp.txt deleted file mode 100644 index de6f78d..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/ListsOutput_CSharp.txt +++ /dev/null @@ -1,240 +0,0 @@ -// ----------------------------------------------------------------------- -// -// This code was generated from a template. -// -// Changes to this file may cause incorrect behaviour and will be lost -// if the code is regenerated. -// -// ------------------------------------------------------------------------ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ICustomList - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public System.Int32 IndexOf(T item) - { - return this.Apply(x => x.IndexOf(item)); - } - - public void Insert(System.Int32 index, T item) - { - this.Apply(x => x.Insert(index, item)); - } - - public void RemoveAt(System.Int32 index) - { - this.Apply(x => x.RemoveAt(index)); - } - - public T this[System.Int32 index] - { - get - { - return this.Apply(x => x[index]); - } - - set - { - this.ApplyPropertySet(x => x[index], value); - } - } - - public void Add(T item) - { - this.Apply(x => x.Add(item)); - } - - public void Clear() - { - this.Apply(x => x.Clear()); - } - - public System.Boolean Contains(T item) - { - return this.Apply(x => x.Contains(item)); - } - - public void CopyTo(T[] array, System.Int32 arrayIndex) - { - this.Apply(x => x.CopyTo(array, arrayIndex)); - } - - public System.Boolean Remove(T item) - { - return this.Apply(x => x.Remove(item)); - } - - public System.Int32 Count - { - get - { - return this.Apply(x => x.Count); - } - } - - public System.Boolean IsReadOnly - { - get - { - return this.Apply(x => x.IsReadOnly); - } - } - } -} -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.List()); - this.When(x => x.SomeReadOnlyProperty).Return(new global::System.Collections.Generic.List()); - this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.List()); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.List()); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Collections.Generic.IList SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - - public global::System.Collections.Generic.IReadOnlyList SomeReadOnlyProperty - { - get - { - return this.Apply(x => x.SomeReadOnlyProperty); - } - } - - public global::System.Collections.Generic.IList SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::System.Collections.Generic.IList SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - - public global::System.Collections.Generic.IList SomeGenericMethod() - { - return this.Apply(x => x.SomeGenericMethod()); - } - - public global::System.Collections.Generic.IList SomeOtherGenericMethod() - { - return this.Apply(x => x.SomeOtherGenericMethod()); - } - - public global::ICustomList SomeCustomProperty - { - get - { - return this.Apply(x => x.SomeCustomProperty); - } - } - - public global::ICustomList SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::ICustomList SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - } -} -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.List()); - this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.List()); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.List()); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Collections.Generic.IList SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - - public global::System.Collections.Generic.IList SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::System.Collections.Generic.IList SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - } -} diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/RecursiveInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/RecursiveInput_CSharp.txt deleted file mode 100644 index a218371..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/RecursiveInput_CSharp.txt +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; - -interface ISomeInterface -{ - IList>> SomeProperty - { - get; - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/RecursiveOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/RecursiveOutput_CSharp.txt deleted file mode 100644 index 398cc38..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/RecursiveOutput_CSharp.txt +++ /dev/null @@ -1,45 +0,0 @@ -// ----------------------------------------------------------------------- -// -// This code was generated from a template. -// -// Changes to this file may cause incorrect behaviour and will be lost -// if the code is regenerated. -// -// ------------------------------------------------------------------------ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.List>>()); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Collections.Generic.IList>> SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - } -} diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/SetsInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/SetsInput_CSharp.txt deleted file mode 100644 index b353e30..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/SetsInput_CSharp.txt +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Collections.Generic; - -interface ICustomSet : ISet -{ -} - -interface ISomeInterface -{ - ISet SomeProperty - { - get; - } - - // expecting this to be ignored because it's set-only - ISet SomeSetOnlyProperty - { - set; - } - - ISet SomeMethod(); - ISet SomeMethod(int i, float f); - - // should all be ignored because they're generic - ISet SomeGenericMethod(); - ISet SomeOtherGenericMethod(); - - // should be ignored because they're a custom enumerable type - ICustomSet SomeCustomProperty - { - get; - } - - ICustomSet SomeMethod(); - ICustomSet SomeMethod(int i, float f); -} - -interface ISomeGenericInterface -{ - ISet SomeProperty - { - get; - } - - ISet SomeMethod(); - ISet SomeMethod(int i, float f); -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/SetsOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/SetsOutput_CSharp.txt deleted file mode 100644 index d91626d..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/CollectionsFixtureResources/SetsOutput_CSharp.txt +++ /dev/null @@ -1,258 +0,0 @@ -// ----------------------------------------------------------------------- -// -// This code was generated from a template. -// -// Changes to this file may cause incorrect behaviour and will be lost -// if the code is regenerated. -// -// ------------------------------------------------------------------------ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ICustomSet - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public System.Boolean Add(T item) - { - return this.Apply(x => x.Add(item)); - } - - public void UnionWith(global::System.Collections.Generic.IEnumerable other) - { - this.Apply(x => x.UnionWith(other)); - } - - public void IntersectWith(global::System.Collections.Generic.IEnumerable other) - { - this.Apply(x => x.IntersectWith(other)); - } - - public void ExceptWith(global::System.Collections.Generic.IEnumerable other) - { - this.Apply(x => x.ExceptWith(other)); - } - - public void SymmetricExceptWith(global::System.Collections.Generic.IEnumerable other) - { - this.Apply(x => x.SymmetricExceptWith(other)); - } - - public System.Boolean IsSubsetOf(global::System.Collections.Generic.IEnumerable other) - { - return this.Apply(x => x.IsSubsetOf(other)); - } - - public System.Boolean IsSupersetOf(global::System.Collections.Generic.IEnumerable other) - { - return this.Apply(x => x.IsSupersetOf(other)); - } - - public System.Boolean IsProperSupersetOf(global::System.Collections.Generic.IEnumerable other) - { - return this.Apply(x => x.IsProperSupersetOf(other)); - } - - public System.Boolean IsProperSubsetOf(global::System.Collections.Generic.IEnumerable other) - { - return this.Apply(x => x.IsProperSubsetOf(other)); - } - - public System.Boolean Overlaps(global::System.Collections.Generic.IEnumerable other) - { - return this.Apply(x => x.Overlaps(other)); - } - - public System.Boolean SetEquals(global::System.Collections.Generic.IEnumerable other) - { - return this.Apply(x => x.SetEquals(other)); - } - - public void Add(T item) - { - this.Apply(x => x.Add(item)); - } - - public void Clear() - { - this.Apply(x => x.Clear()); - } - - public System.Boolean Contains(T item) - { - return this.Apply(x => x.Contains(item)); - } - - public void CopyTo(T[] array, System.Int32 arrayIndex) - { - this.Apply(x => x.CopyTo(array, arrayIndex)); - } - - public System.Boolean Remove(T item) - { - return this.Apply(x => x.Remove(item)); - } - - public System.Int32 Count - { - get - { - return this.Apply(x => x.Count); - } - } - - public System.Boolean IsReadOnly - { - get - { - return this.Apply(x => x.IsReadOnly); - } - } - } -} -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.HashSet()); - this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.HashSet()); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.HashSet()); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Collections.Generic.ISet SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - - public global::System.Collections.Generic.ISet SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::System.Collections.Generic.ISet SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - - public global::System.Collections.Generic.ISet SomeGenericMethod() - { - return this.Apply(x => x.SomeGenericMethod()); - } - - public global::System.Collections.Generic.ISet SomeOtherGenericMethod() - { - return this.Apply(x => x.SomeOtherGenericMethod()); - } - - public global::ICustomSet SomeCustomProperty - { - get - { - return this.Apply(x => x.SomeCustomProperty); - } - } - - public global::ICustomSet SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::ICustomSet SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - } -} -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ISomeGenericInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.SomeProperty).Return(new global::System.Collections.Generic.HashSet()); - this.When(x => x.SomeMethod()).Return(new global::System.Collections.Generic.HashSet()); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(new global::System.Collections.Generic.HashSet()); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Collections.Generic.ISet SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - - public global::System.Collections.Generic.ISet SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::System.Collections.Generic.ISet SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - } -} diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/DisposablesFixture.cs b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/DisposablesFixture.cs deleted file mode 100644 index 54372b1..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/DisposablesFixture.cs +++ /dev/null @@ -1,79 +0,0 @@ -namespace PCLMock.UnitTests.CodeGeneration.Plugins -{ - using System; - using System.Collections.Immutable; - using System.IO; - using System.Linq; - using System.Reactive.Linq; - using System.Threading.Tasks; - using Microsoft.CodeAnalysis; - using Microsoft.CodeAnalysis.Text; - using PCLMock.CodeGeneration; - using PCLMock.CodeGeneration.Logging; - using PCLMock.CodeGeneration.Plugins; - using Xunit; - - public sealed class DisposablesFixture - { - [Theory] - [InlineData("Disposables", Language.CSharp)] - public async Task can_generate_mocks(string resourceBaseName, Language language) - { - var inputResourceName = "PCLMock.UnitTests.CodeGeneration.Plugins.DisposablesFixtureResources." + resourceBaseName + "Input_" + language.ToString() + ".txt"; - var outputResourceName = "PCLMock.UnitTests.CodeGeneration.Plugins.DisposablesFixtureResources." + resourceBaseName + "Output_" + language.ToString() + ".txt"; - - using (var inputStream = this.GetType().Assembly.GetManifestResourceStream(inputResourceName)) - using (var outputStream = this.GetType().Assembly.GetManifestResourceStream(outputResourceName)) - using (var outputStreamReader = new StreamReader(outputStream)) - { - var workspace = new AdhocWorkspace(); - var projectId = ProjectId.CreateNewId(); - var versionStamp = VersionStamp.Create(); - var projectInfo = ProjectInfo.Create( - projectId, - versionStamp, - "AdhocProject", - "AdhocProject", - language.ToSyntaxGeneratorLanguageName(), - metadataReferences: new[] - { - MetadataReference.CreateFromFile(typeof(object).Assembly.Location), - MetadataReference.CreateFromFile(typeof(Uri).Assembly.Location), - MetadataReference.CreateFromFile(typeof(MockBase<>).Assembly.Location) - }); - var project = workspace.AddProject(projectInfo); - workspace.AddDocument(projectId, "Source.cs", SourceText.From(inputStream)); - var solution = workspace.CurrentSolution; - - var results = - (await Generator.GenerateMocksAsync( - NullLogSink.Instance, - language, - solution, - x => true, - x => "The.Namespace", - x => "Mock", - new IPlugin[] - { - new Disposables() - }.ToImmutableList())); - var result = results - .Last() - .ToString() - .NormalizeLineEndings(); - - var expectedCode = outputStreamReader.ReadToEnd(); - - // make sure version changes don't break the tests - expectedCode = expectedCode - .Replace("$VERSION$", typeof(MockBase<>).Assembly.GetName().Version.ToString()) - .NormalizeLineEndings(); - - // useful when converting generated code to something that can be pasted into an expectation file - var sanitisedResult = result.Replace(typeof(MockBase<>).Assembly.GetName().Version.ToString(), "$VERSION$"); - - Assert.Equal(expectedCode, result); - } - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/DisposablesFixtureResources/DisposablesInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/DisposablesFixtureResources/DisposablesInput_CSharp.txt deleted file mode 100644 index de656b4..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/DisposablesFixtureResources/DisposablesInput_CSharp.txt +++ /dev/null @@ -1,35 +0,0 @@ -using System; - -interface ICustomDisposable : IDisposable -{ -} - -interface ISomeInterface -{ - IDisposable SomeProperty - { - get; - } - - // expecting this to be ignored because it's set-only - IDisposable SomeSetOnlyProperty - { - set; - } - - IDisposable SomeMethod(); - IDisposable SomeMethod(int i, float f); - - // should all be ignored because they're generic - IDisposable SomeGenericMethod(); - IDisposable SomeOtherGenericMethod(); - - // should be ignored because they're a custom disposable type - ICustomDisposable SomeCustomProperty - { - get; - } - - ICustomDisposable SomeMethod(); - ICustomDisposable SomeMethod(int i, float f); -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/DisposablesFixtureResources/DisposablesOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/DisposablesFixtureResources/DisposablesOutput_CSharp.txt deleted file mode 100644 index d40c0c3..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/DisposablesFixtureResources/DisposablesOutput_CSharp.txt +++ /dev/null @@ -1,77 +0,0 @@ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.SomeProperty).Return(global::System.Reactive.Disposables.Disposable.Empty); - this.When(x => x.SomeMethod()).Return(global::System.Reactive.Disposables.Disposable.Empty); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Reactive.Disposables.Disposable.Empty); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.IDisposable SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - - public global::System.IDisposable SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::System.IDisposable SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - - public global::System.IDisposable SomeGenericMethod() - { - return this.Apply(x => x.SomeGenericMethod()); - } - - public global::System.IDisposable SomeOtherGenericMethod() - { - return this.Apply(x => x.SomeOtherGenericMethod()); - } - - public global::ICustomDisposable SomeCustomProperty - { - get - { - return this.Apply(x => x.SomeCustomProperty); - } - } - - public global::ICustomDisposable SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::ICustomDisposable SomeMethod(System.Int32 i, System.Single f) - { - return this.Apply(x => x.SomeMethod(i, f)); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixture.cs b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixture.cs deleted file mode 100644 index 55b2248..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixture.cs +++ /dev/null @@ -1,82 +0,0 @@ -namespace PCLMock.UnitTests.CodeGeneration.Plugins -{ - using System; - using System.Collections.Immutable; - using System.IO; - using System.Linq; - using System.Reactive.Linq; - using System.Threading.Tasks; - using Microsoft.CodeAnalysis; - using Microsoft.CodeAnalysis.Text; - using PCLMock.CodeGeneration; - using PCLMock.CodeGeneration.Logging; - using PCLMock.CodeGeneration.Plugins; - using Xunit; - - public sealed class ObservableBasedAsynchronyFixture - { - [Theory] - [InlineData("NonObservableBased", Language.CSharp)] - [InlineData("ObservableBased", Language.CSharp)] - [InlineData("GenericInterface", Language.CSharp)] - [InlineData("Recursive", Language.CSharp)] - public async Task can_generate_mocks(string resourceBaseName, Language language) - { - var inputResourceName = "PCLMock.UnitTests.CodeGeneration.Plugins.ObservableBasedAsynchronyFixtureResources." + resourceBaseName + "Input_" + language.ToString() + ".txt"; - var outputResourceName = "PCLMock.UnitTests.CodeGeneration.Plugins.ObservableBasedAsynchronyFixtureResources." + resourceBaseName + "Output_" + language.ToString() + ".txt"; - - using (var inputStream = this.GetType().Assembly.GetManifestResourceStream(inputResourceName)) - using (var outputStream = this.GetType().Assembly.GetManifestResourceStream(outputResourceName)) - using (var outputStreamReader = new StreamReader(outputStream)) - { - var workspace = new AdhocWorkspace(); - var projectId = ProjectId.CreateNewId(); - var versionStamp = VersionStamp.Create(); - var projectInfo = ProjectInfo.Create( - projectId, - versionStamp, - "AdhocProject", - "AdhocProject", - language.ToSyntaxGeneratorLanguageName(), - metadataReferences: new[] - { - MetadataReference.CreateFromFile(typeof(object).Assembly.Location), - MetadataReference.CreateFromFile(typeof(Uri).Assembly.Location), - MetadataReference.CreateFromFile(typeof(MockBase<>).Assembly.Location) - }); - var project = workspace.AddProject(projectInfo); - workspace.AddDocument(projectId, "Source.cs", SourceText.From(inputStream)); - var solution = workspace.CurrentSolution; - - var results = - (await Generator.GenerateMocksAsync( - NullLogSink.Instance, - language, - solution, - x => true, - x => "The.Namespace", - x => "Mock", - new IPlugin[] - { - new ObservableBasedAsynchrony() - }.ToImmutableList())); - var result = results - .Last() - .ToString() - .NormalizeLineEndings(); - - var expectedCode = outputStreamReader.ReadToEnd(); - - // make sure version changes don't break the tests - expectedCode = expectedCode - .Replace("$VERSION$", typeof(MockBase<>).Assembly.GetName().Version.ToString()) - .NormalizeLineEndings(); - - // useful when converting generated code to something that can be pasted into an expectation file - var sanitisedResult = result.Replace(typeof(MockBase<>).Assembly.GetName().Version.ToString(), "$VERSION$"); - - Assert.Equal(expectedCode, result); - } - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/GenericInterfaceInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/GenericInterfaceInput_CSharp.txt deleted file mode 100644 index 6d4cd6f..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/GenericInterfaceInput_CSharp.txt +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -interface ISomeInterface -{ - IObservable SomeProperty - { - get; - } - - IObservable SomeMethod(); -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt deleted file mode 100644 index e5a5797..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt +++ /dev/null @@ -1,43 +0,0 @@ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ISomeInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.SomeProperty).Return(global::System.Reactive.Linq.Observable.Empty()); - this.When(x => x.SomeMethod()).Return(global::System.Reactive.Linq.Observable.Return(default (T))); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.IObservable SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - - public global::System.IObservable SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/NonObservableBasedInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/NonObservableBasedInput_CSharp.txt deleted file mode 100644 index 203ec18..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/NonObservableBasedInput_CSharp.txt +++ /dev/null @@ -1,34 +0,0 @@ -interface ISomeInterface -{ - int SomeProperty - { - get; - } - - string SomeOtherProperty - { - get; - } - - int SomeSetOnlyProperty - { - set; - } - - int this[int i, float f] - { - get; - } - - void SomeMethod(); - - string SomeMethod(); - - int SomeMethod(); - - object SomeMethod(); - - int SomeMethod(); - - int SomeMethod(); -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/NonObservableBasedOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/NonObservableBasedOutput_CSharp.txt deleted file mode 100644 index 4e15c3d..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/NonObservableBasedOutput_CSharp.txt +++ /dev/null @@ -1,82 +0,0 @@ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public System.Int32 SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - - public System.String SomeOtherProperty - { - get - { - return this.Apply(x => x.SomeOtherProperty); - } - } - - public System.Int32 this[System.Int32 i, System.Single f] - { - get - { - return this.Apply(x => x[i, f]); - } - } - - public void SomeMethod() - { - this.Apply(x => x.SomeMethod()); - } - - public System.String SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public System.Int32 SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public System.Object SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public System.Int32 SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public System.Int32 SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedInput_CSharp.txt deleted file mode 100644 index 2fbaf48..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedInput_CSharp.txt +++ /dev/null @@ -1,40 +0,0 @@ -using System; - -interface ICustomObservable : IObservable -{ -} - -interface ISomeInterface -{ - IObservable SomeProperty - { - get; - } - - IObservable SomeOtherProperty - { - get; - } - - // expecting this to be ignored because it's set-only - IObservable SomeSetOnlyProperty - { - set; - } - - IObservable this[int i, float f] - { - get; - } - - IObservable SomeMethod(); - IObservable SomeMethod(string s, int i); - - // expecting these to be ignored because of the type parameters - IObservable SomeMethod(); - IObservable SomeMethod(); - - // expecting these two to be ignored because of it being a custom observable (which we have no way of providing a default value for) - ICustomObservable SomeMethod(); - ICustomObservable SomeMethod(string s, int i); -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedOutput_CSharp.txt deleted file mode 100644 index 556d664..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/ObservableBasedOutput_CSharp.txt +++ /dev/null @@ -1,87 +0,0 @@ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.SomeProperty).Return(global::System.Reactive.Linq.Observable.Empty()); - this.When(x => x.SomeOtherProperty).Return(global::System.Reactive.Linq.Observable.Empty()); - this.When(x => x[global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny()]).Return(global::System.Reactive.Linq.Observable.Empty()); - this.When(x => x.SomeMethod()).Return(global::System.Reactive.Linq.Observable.Return(0)); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Reactive.Linq.Observable.Return(null)); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.IObservable SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - - public global::System.IObservable SomeOtherProperty - { - get - { - return this.Apply(x => x.SomeOtherProperty); - } - } - - public global::System.IObservable this[System.Int32 i, System.Single f] - { - get - { - return this.Apply(x => x[i, f]); - } - } - - public global::System.IObservable SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::System.IObservable SomeMethod(System.String s, System.Int32 i) - { - return this.Apply(x => x.SomeMethod(s, i)); - } - - public global::System.IObservable SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::System.IObservable SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::ICustomObservable SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::ICustomObservable SomeMethod(System.String s, System.Int32 i) - { - return this.Apply(x => x.SomeMethod(s, i)); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/RecursiveInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/RecursiveInput_CSharp.txt deleted file mode 100644 index 95eb6e9..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/RecursiveInput_CSharp.txt +++ /dev/null @@ -1,6 +0,0 @@ -using System; - -interface ISomeInterface -{ - IObservable> SomeMethod(); -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt deleted file mode 100644 index 18c534e..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/ObservableBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt +++ /dev/null @@ -1,34 +0,0 @@ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.SomeMethod()).Return(global::System.Reactive.Linq.Observable.Return>(global::System.Reactive.Linq.Observable.Return(0))); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.IObservable> SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixture.cs b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixture.cs deleted file mode 100644 index b4d6d75..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixture.cs +++ /dev/null @@ -1,82 +0,0 @@ -namespace PCLMock.UnitTests.CodeGeneration.Plugins -{ - using System; - using System.Collections.Immutable; - using System.IO; - using System.Linq; - using System.Threading.Tasks; - using Microsoft.CodeAnalysis; - using Microsoft.CodeAnalysis.Text; - using PCLMock.CodeGeneration; - using PCLMock.CodeGeneration.Logging; - using PCLMock.CodeGeneration.Plugins; - using Xunit; - - public sealed class TaskBasedAsynchronyFixture - { - [Theory] - [InlineData("NonTaskBased", Language.CSharp)] - [InlineData("NonGenericTask", Language.CSharp)] - [InlineData("GenericTask", Language.CSharp)] - [InlineData("GenericInterface", Language.CSharp)] - [InlineData("Recursive", Language.CSharp)] - public async Task can_generate_mocks(string resourceBaseName, Language language) - { - var inputResourceName = "PCLMock.UnitTests.CodeGeneration.Plugins.TaskBasedAsynchronyFixtureResources." + resourceBaseName + "Input_" + language.ToString() + ".txt"; - var outputResourceName = "PCLMock.UnitTests.CodeGeneration.Plugins.TaskBasedAsynchronyFixtureResources." + resourceBaseName + "Output_" + language.ToString() + ".txt"; - - using (var inputStream = this.GetType().Assembly.GetManifestResourceStream(inputResourceName)) - using (var outputStream = this.GetType().Assembly.GetManifestResourceStream(outputResourceName)) - using (var outputStreamReader = new StreamReader(outputStream)) - { - var workspace = new AdhocWorkspace(); - var projectId = ProjectId.CreateNewId(); - var versionStamp = VersionStamp.Create(); - var projectInfo = ProjectInfo.Create( - projectId, - versionStamp, - "AdhocProject", - "AdhocProject", - language.ToSyntaxGeneratorLanguageName(), - metadataReferences: new[] - { - MetadataReference.CreateFromFile(typeof(object).Assembly.Location), - MetadataReference.CreateFromFile(typeof(Uri).Assembly.Location), - MetadataReference.CreateFromFile(typeof(MockBase<>).Assembly.Location) - }); - var project = workspace.AddProject(projectInfo); - workspace.AddDocument(projectId, "Source.cs", SourceText.From(inputStream)); - var solution = workspace.CurrentSolution; - - var results = - (await Generator.GenerateMocksAsync( - NullLogSink.Instance, - language, - solution, - x => true, - x => "The.Namespace", - x => "Mock", - new IPlugin[] - { - new TaskBasedAsynchrony() - }.ToImmutableList())); - var result = results - .Last() - .ToString() - .NormalizeLineEndings(); - - var expectedCode = outputStreamReader.ReadToEnd(); - - // make sure version changes don't break the tests - expectedCode = expectedCode - .Replace("$VERSION$", typeof(MockBase<>).Assembly.GetName().Version.ToString()) - .NormalizeLineEndings(); - - // useful when converting generated code to something that can be pasted into an expectation file - var sanitisedResult = result.Replace(typeof(MockBase<>).Assembly.GetName().Version.ToString(), "$VERSION$"); - - Assert.Equal(expectedCode, result); - } - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericInterfaceInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericInterfaceInput_CSharp.txt deleted file mode 100644 index 451cda7..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericInterfaceInput_CSharp.txt +++ /dev/null @@ -1,11 +0,0 @@ -using System.Threading.Tasks; - -interface ISomeInterface -{ - Task SomeProperty - { - get; - } - - Task SomeMethod(); -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt deleted file mode 100644 index f3f8e7b..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericInterfaceOutput_CSharp.txt +++ /dev/null @@ -1,43 +0,0 @@ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase>, global::ISomeInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.SomeProperty).Return(global::System.Threading.Tasks.Task.FromResult(default (T))); - this.When(x => x.SomeMethod()).Return(global::System.Threading.Tasks.Task.FromResult(default (T))); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Threading.Tasks.Task SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - - public global::System.Threading.Tasks.Task SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericTaskInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericTaskInput_CSharp.txt deleted file mode 100644 index 0d9e21b..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericTaskInput_CSharp.txt +++ /dev/null @@ -1,40 +0,0 @@ -using System.Threading.Tasks; - -class CustomTask : Task -{ -} - -interface ISomeInterface -{ - Task SomeProperty - { - get; - } - - Task SomeOtherProperty - { - get; - } - - // expecting this to be ignored because it's set-only - Task SomeSetOnlyProperty - { - set; - } - - Task this[int i, float f] - { - get; - } - - Task SomeMethod(); - Task SomeMethod(string s, int i); - - // expecting these to be ignored because of the type parameters - Task SomeMethod(); - Task SomeMethod(); - - // expecting these two to be ignored because of it being a custom task (which we have no way of providing a default value for) - CustomTask SomeMethod(); - CustomTask SomeMethod(string s, int i); -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericTaskOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericTaskOutput_CSharp.txt deleted file mode 100644 index 112eee5..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/GenericTaskOutput_CSharp.txt +++ /dev/null @@ -1,87 +0,0 @@ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.SomeProperty).Return(global::System.Threading.Tasks.Task.FromResult(0)); - this.When(x => x.SomeOtherProperty).Return(global::System.Threading.Tasks.Task.FromResult(null)); - this.When(x => x[global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny()]).Return(global::System.Threading.Tasks.Task.FromResult(0)); - this.When(x => x.SomeMethod()).Return(global::System.Threading.Tasks.Task.FromResult(0)); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Threading.Tasks.Task.FromResult(null)); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Threading.Tasks.Task SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - - public global::System.Threading.Tasks.Task SomeOtherProperty - { - get - { - return this.Apply(x => x.SomeOtherProperty); - } - } - - public global::System.Threading.Tasks.Task this[System.Int32 i, System.Single f] - { - get - { - return this.Apply(x => x[i, f]); - } - } - - public global::System.Threading.Tasks.Task SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::System.Threading.Tasks.Task SomeMethod(System.String s, System.Int32 i) - { - return this.Apply(x => x.SomeMethod(s, i)); - } - - public global::System.Threading.Tasks.Task SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::System.Threading.Tasks.Task SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::CustomTask SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::CustomTask SomeMethod(System.String s, System.Int32 i) - { - return this.Apply(x => x.SomeMethod(s, i)); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonGenericTaskInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonGenericTaskInput_CSharp.txt deleted file mode 100644 index 28bc9f9..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonGenericTaskInput_CSharp.txt +++ /dev/null @@ -1,40 +0,0 @@ -using System.Threading.Tasks; - -class CustomTask : Task -{ -} - -interface ISomeInterface -{ - Task SomeProperty - { - get; - } - - Task SomeOtherProperty - { - get; - } - - // expecting this to be ignored because it's set-only - Task SomeSetOnlyProperty - { - set; - } - - Task this[int i, float f] - { - get; - } - - Task SomeMethod(); - Task SomeMethod(string s, int i); - - // expecting these to be ignored because of the type parameters - Task SomeMethod(); - Task SomeMethod(); - - // expecting these to be ignored because of it being a custom task (which we have no way of providing a default value for) - CustomTask SomeMethod(); - CustomTask SomeMethod(string s, int i); -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonGenericTaskOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonGenericTaskOutput_CSharp.txt deleted file mode 100644 index 3406772..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonGenericTaskOutput_CSharp.txt +++ /dev/null @@ -1,87 +0,0 @@ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.SomeProperty).Return(global::System.Threading.Tasks.Task.FromResult(false)); - this.When(x => x.SomeOtherProperty).Return(global::System.Threading.Tasks.Task.FromResult(false)); - this.When(x => x[global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny()]).Return(global::System.Threading.Tasks.Task.FromResult(false)); - this.When(x => x.SomeMethod()).Return(global::System.Threading.Tasks.Task.FromResult(false)); - this.When(x => x.SomeMethod(global::PCLMock.It.IsAny(), global::PCLMock.It.IsAny())).Return(global::System.Threading.Tasks.Task.FromResult(false)); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Threading.Tasks.Task SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - - public global::System.Threading.Tasks.Task SomeOtherProperty - { - get - { - return this.Apply(x => x.SomeOtherProperty); - } - } - - public global::System.Threading.Tasks.Task this[System.Int32 i, System.Single f] - { - get - { - return this.Apply(x => x[i, f]); - } - } - - public global::System.Threading.Tasks.Task SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::System.Threading.Tasks.Task SomeMethod(System.String s, System.Int32 i) - { - return this.Apply(x => x.SomeMethod(s, i)); - } - - public global::System.Threading.Tasks.Task SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::System.Threading.Tasks.Task SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::CustomTask SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public global::CustomTask SomeMethod(System.String s, System.Int32 i) - { - return this.Apply(x => x.SomeMethod(s, i)); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonTaskBasedInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonTaskBasedInput_CSharp.txt deleted file mode 100644 index 203ec18..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonTaskBasedInput_CSharp.txt +++ /dev/null @@ -1,34 +0,0 @@ -interface ISomeInterface -{ - int SomeProperty - { - get; - } - - string SomeOtherProperty - { - get; - } - - int SomeSetOnlyProperty - { - set; - } - - int this[int i, float f] - { - get; - } - - void SomeMethod(); - - string SomeMethod(); - - int SomeMethod(); - - object SomeMethod(); - - int SomeMethod(); - - int SomeMethod(); -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonTaskBasedOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonTaskBasedOutput_CSharp.txt deleted file mode 100644 index 4e15c3d..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/NonTaskBasedOutput_CSharp.txt +++ /dev/null @@ -1,82 +0,0 @@ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public System.Int32 SomeProperty - { - get - { - return this.Apply(x => x.SomeProperty); - } - } - - public System.String SomeOtherProperty - { - get - { - return this.Apply(x => x.SomeOtherProperty); - } - } - - public System.Int32 this[System.Int32 i, System.Single f] - { - get - { - return this.Apply(x => x[i, f]); - } - } - - public void SomeMethod() - { - this.Apply(x => x.SomeMethod()); - } - - public System.String SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public System.Int32 SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public System.Object SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public System.Int32 SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - - public System.Int32 SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/RecursiveInput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/RecursiveInput_CSharp.txt deleted file mode 100644 index 2b3c522..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/RecursiveInput_CSharp.txt +++ /dev/null @@ -1,6 +0,0 @@ -using System.Threading.Tasks; - -interface ISomeInterface -{ - Task> SomeMethod(); -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt b/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt deleted file mode 100644 index 3ecfeca..0000000 --- a/Src/PCLMock.UnitTests_OLD/CodeGeneration/Plugins/TaskBasedAsynchronyFixtureResources/RecursiveOutput_CSharp.txt +++ /dev/null @@ -1,34 +0,0 @@ -namespace The.Namespace -{ - [System.CodeDom.Compiler.GeneratedCode("PCLMock", "$VERSION$")] - [System.Runtime.CompilerServices.CompilerGenerated] - internal partial class Mock : global::PCLMock.MockBase, global::ISomeInterface - { - public Mock(global::PCLMock.MockBehavior behavior = global::PCLMock.MockBehavior.Strict): base (behavior) - { - ConfigureBehaviorGenerated(); - ConfigureBehavior(); - if ((behavior) == (global::PCLMock.MockBehavior.Loose)) - { - ConfigureLooseBehaviorGenerated(); - ConfigureLooseBehavior(); - } - } - - private void ConfigureBehaviorGenerated() - { - this.When(x => x.SomeMethod()).Return(global::System.Threading.Tasks.Task.FromResult>(global::System.Threading.Tasks.Task.FromResult(0))); - } - - private void ConfigureLooseBehaviorGenerated() - { - } - - partial void ConfigureBehavior(); - partial void ConfigureLooseBehavior(); - public global::System.Threading.Tasks.Task> SomeMethod() - { - return this.Apply(x => x.SomeMethod()); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/Extensions.cs b/Src/PCLMock.UnitTests_OLD/Extensions.cs deleted file mode 100644 index 8a64a74..0000000 --- a/Src/PCLMock.UnitTests_OLD/Extensions.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace PCLMock.UnitTests -{ - public static class Extensions - { - public static string NormalizeLineEndings(this string @this) => - @this - .Replace("\r\n", "\n") - .Replace("\r", "\n") - .Replace("\n", "\r\n"); - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/MockBaseFixture.cs b/Src/PCLMock.UnitTests_OLD/MockBaseFixture.cs deleted file mode 100644 index 9fffab7..0000000 --- a/Src/PCLMock.UnitTests_OLD/MockBaseFixture.cs +++ /dev/null @@ -1,1328 +0,0 @@ -namespace PCLMock.UnitTests -{ - using System; - using System.Text.RegularExpressions; - using PCLMock; - using Xunit; - using Xunit.Extensions; - - public sealed class MockBaseFixture - { - [Fact] - public void indexer_properties_can_be_mocked() - { - var mock = new TestTargetMock(); - mock.When(x => x[1]).Return(3); - - Assert.Equal(3, mock[1]); - } - - [Fact] - public void indexer_properties_with_multiple_indexes_can_be_mocked() - { - var mock = new TestTargetMock(); - mock.When(x => x[1, 3]).Return(3); - mock.When(x => x[3, 1]).Return(5); - - Assert.Equal(3, mock[1, 3]); - Assert.Equal(5, mock[3, 1]); - } - - [Fact] - public void apply_throws_if_method_without_specifications_is_invoked_on_a_strict_mock() - { - var mock = new TestTargetMock(); - var ex = Assert.Throws(() => mock.SomeMethod()); - Assert.Equal("Method 'SomeMethod', for which no specifications have been configured, was invoked on a strict mock. You must either configure specifications via calls to When on the mock, or use a loose mock by passing in MockBehavior.Loose to the mock's constructor.", ex.Message); - } - - [Fact] - public void apply_throws_if_property_without_specifications_is_invoked_on_a_strict_mock() - { - var mock = new TestTargetMock(); - var ex = Assert.Throws(() => mock.SomeProperty); - Assert.Equal("Property 'SomeProperty', for which no specifications have been configured, was invoked on a strict mock. You must either configure specifications via calls to When on the mock, or use a loose mock by passing in MockBehavior.Loose to the mock's constructor.", ex.Message); - } - - [Fact] - public void mocked_object_throws_if_the_mocked_object_cannot_be_automatically_determined() - { - var mock = new InvalidMockedObject(); - var ex = Assert.Throws(() => mock.MockedObject); - var expectedMessage = @"The default implementation of MockBase is unable to automatically determine an instance of type UnsealedClass to be used as the mocked object. You should override MockedObject in InvalidMockedObject and return the mocked object. -Full mock type name: PCLMock.UnitTests.MockBaseFixture+InvalidMockedObject -Full mocked object type name: PCLMock.UnitTests.MockBaseFixture+UnsealedClass"; - - Assert.Equal(expectedMessage, ex.Message); - } - - [Fact] - public void mocked_object_attempts_to_cast_the_mock_to_the_mocked_type_by_default() - { - var mock = new TestTargetMock(); - Assert.Same(mock, mock.MockedObject); - } - - [Fact] - public void when_throws_if_property_access_is_chained() - { - var mock = new TestTargetMock(); - var ex = Assert.Throws(() => mock.When(x => x.SomeComplexProperty.Name).Return("foo")); - Assert.Equal("Specifications against properties cannot be chained: x.SomeComplexProperty.Name", ex.Message); - } - - [Fact] - public void when_throws_if_method_access_is_chained() - { - var mock = new TestTargetMock(); - var ex = Assert.Throws(() => mock.When(x => x.SomeComplexMethod().GetAge()).Return(35)); - Assert.Equal("Specifications against methods cannot be chained: x.SomeComplexMethod().GetAge()", ex.Message); - } - - [Fact] - public void when_throws_if_method_is_an_extension_method() - { - var mock = new TestTargetMock(); - var ex = Assert.Throws(() => mock.When(x => x.SomeExtensionMethod()).Return(35)); - Assert.Equal("Specifications against extension methods cannot be provided: x.SomeExtensionMethod()", ex.Message); - } - - [Fact] - public void when_can_be_used_to_specify_result_of_property_getter() - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeProperty).Return(6); - - Assert.Equal(6, mock.SomeProperty); - } - - [Fact] - public void when_can_be_used_to_specify_what_happens_when_a_property_setter_is_accessed() - { - var mock = new TestTargetMock(); - var called = false; - mock.WhenPropertySet(x => x.SomeProperty).Do((_) => called = true); - - mock.SomeProperty = 1; - Assert.True(called); - } - - [Fact] - public void when_can_be_used_to_specify_what_happens_when_a_void_parameterless_method_is_invoked() - { - var mock = new TestTargetMock(); - var called = false; - mock.When(x => x.SomeMethod()).Do(() => called = true); - - mock.SomeMethod(); - Assert.True(called); - } - - [Fact] - public void when_can_be_used_to_specify_what_happens_when_a_void_method_is_invoked() - { - var mock = new TestTargetMock(); - var called = false; - mock.When(x => x.SomeMethod(It.IsAny(), It.IsAny())).Do((_, __) => called = true); - - mock.SomeMethod(1, 1f); - Assert.True(called); - } - - [Fact] - public void when_can_be_used_to_specify_what_happens_when_a_parameterless_method_is_invoked() - { - var mock = new TestTargetMock(); - var called = false; - mock.When(x => x.SomeMethodWithReturnValue()).Do(() => called = true); - - mock.SomeMethodWithReturnValue(); - Assert.True(called); - } - - [Fact] - public void when_can_be_used_to_specify_what_happens_when_a_method_is_invoked() - { - var mock = new TestTargetMock(); - var called = false; - mock.When(x => x.SomeMethodWithReturnValue(It.IsAny(), It.IsAny())).Do((_, __) => called = true); - - mock.SomeMethodWithReturnValue(1, 1f); - Assert.True(called); - } - - [Fact] - public void when_property_set_can_be_used_to_specify_what_happens_when_a_property_is_set() - { - var mock = new TestTargetMock(); - var called = false; - mock.WhenPropertySet(x => x.SomeProperty).Do(() => called = true); - - mock.SomeProperty = 12; - Assert.True(called); - } - - [Fact] - public void when_property_set_can_filter_arguments() - { - var mock = new TestTargetMock(MockBehavior.Loose); - var called = false; - mock.WhenPropertySet(x => x.SomeProperty, () => It.IsIn(1, 2, 3, 5, 8)).Do(() => called = true); - - mock.SomeProperty = 12; - mock.SomeProperty = 11; - Assert.False(called); - - mock.SomeProperty = 5; - Assert.True(called); - } - - [Fact] - public void do_can_specify_an_action_without_parameters() - { - var mock = new TestTargetMock(); - var counter = 0; - mock.When(x => x.SomeMethod()).Do(() => ++counter); - mock.When(x => x.SomeMethodWithReturnValue()).Do(() => ++counter); - - mock.SomeMethod(); - mock.SomeMethodWithReturnValue(); - - Assert.Equal(2, counter); - } - - [Fact] - public void do_can_take_parameters_when_specifying_a_property_set() - { - var mock = new TestTargetMock(); - int capturedValue = 0; - mock.WhenPropertySet(x => x.SomeProperty).Do((int x) => capturedValue = x); - - mock.SomeProperty = 35; - Assert.Equal(35, capturedValue); - } - - [Fact] - public void do_application_does_not_require_any_parameters_be_present_in_the_action() - { - var mock = new TestTargetMock(); - var called = false; - mock.When(x => x.SomeMethod(It.IsAny(), It.IsAny())).Do(() => called = true); - - mock.SomeMethod(1, 1f); - - Assert.True(called); - } - - [Fact] - public void do_application_throws_if_the_parameters_do_not_match_in_number() - { - var mock = new TestTargetMock(); - - mock.When(x => x.SomeMethod(It.IsAny(), It.IsAny())).Do((int i) => { }); - var ex = Assert.Throws(() => mock.SomeMethod(1, 1f)); - Assert.Equal("Could not execute the Do action associated with this mocked member due to a parameter mismatch. Expected: (System.Int32) Received: (System.Int32, System.Single)", ex.Message); - - mock.WhenPropertySet(x => x.SomeProperty).Do((int i, float f) => { }); - ex = Assert.Throws(() => mock.SomeProperty = 31); - Assert.Equal("Could not execute the Do action associated with this mocked member due to a parameter mismatch. Expected: (System.Int32, System.Single) Received: (System.Int32)", ex.Message); - } - - [Fact] - public void do_application_throws_if_the_parameters_do_not_match_in_type() - { - var mock = new TestTargetMock(); - - mock.WhenPropertySet(x => x.SomeProperty).Do((float f) => { }); - var ex = Assert.Throws(() => mock.SomeProperty = 31); - Assert.Equal("Could not execute the Do action associated with this mocked member due to a parameter mismatch. Expected: (System.Single) Received: (System.Int32)", ex.Message); - } - - [Fact] - public void do_can_specify_an_action_with_a_parameter_that_matches_a_propertys_value_type() - { - var mock = new TestTargetMock(); - var value = 0; - mock.WhenPropertySet(x => x.SomeProperty).Do(x => value = x); - - mock.SomeProperty = 31; - - Assert.Equal(31, value); - } - - [Fact] - public void do_can_specify_an_action_with_parameters_that_match_a_methods_argument_types() - { - var mock = new TestTargetMock(); - var iValue = 0; - var fValue = 0f; - mock - .When(x => x.SomeMethod(It.IsAny(), It.IsAny())) - .Do( - (i, f) => - { - iValue = i; - fValue = f; - }); - - mock.SomeMethod(21, 43f); - - Assert.Equal(21, iValue); - Assert.Equal(43f, fValue); - } - - [Fact] - public void return_can_be_used_to_specify_a_constant_return_value_for_property_getter() - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeProperty).Return(108); - - Assert.Equal(108, mock.SomeProperty); - } - - [Fact] - public void return_can_be_used_to_specify_a_constant_return_value_for_a_parameterless_method() - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethodWithReturnValue()).Return(108); - - Assert.Equal(108, mock.SomeMethodWithReturnValue()); - } - - [Fact] - public void return_can_be_used_to_specify_a_constant_return_value_for_a_method_with_parameters() - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethodWithReturnValue(It.IsAny(), It.IsAny())).Return(108); - - Assert.Equal(108, mock.SomeMethodWithReturnValue(1, 1f)); - } - - [Fact] - public void return_can_specify_an_action_without_parameters() - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethodWithReturnValue()).Return(() => 2 + 8); - - Assert.Equal(10, mock.SomeMethodWithReturnValue()); - } - - [Fact] - public void return_application_does_not_require_any_parameters_be_present_in_the_action() - { - var mock = new TestTargetMock(); - var called = false; - mock.WhenPropertySet(x => x.SomeProperty).Do(() => called = true); - - mock.SomeProperty = 21; - - Assert.True(called); - } - - [Fact] - public void return_application_throws_if_the_parameters_do_not_match_in_number() - { - var mock = new TestTargetMock(); - - mock.When(x => x.SomeMethodWithReturnValue()).Return((int i) => 3); - var ex = Assert.Throws(() => mock.SomeMethodWithReturnValue()); - Assert.Equal("Could not execute the Return action associated with this mocked member due to a parameter mismatch. Expected: (System.Int32) Received: ()", ex.Message); - - mock.When(x => x.SomeMethodWithReturnValue()).Return((int i, float f) => 31); - ex = Assert.Throws(() => mock.SomeMethodWithReturnValue()); - Assert.Equal("Could not execute the Return action associated with this mocked member due to a parameter mismatch. Expected: (System.Int32, System.Single) Received: ()", ex.Message); - } - - [Fact] - public void return_application_throws_if_the_parameters_do_not_match_in_type() - { - var mock = new TestTargetMock(); - - mock.When(x => x.SomeMethodWithReturnValue(It.IsAny(), It.IsAny())).Return((string s, int i) => 31); - var ex = Assert.Throws(() => mock.SomeMethodWithReturnValue(1, 1f)); - Assert.Equal("Could not execute the Return action associated with this mocked member due to a parameter mismatch. Expected: (System.String, System.Int32) Received: (System.Int32, System.Single)", ex.Message); - } - - [Fact] - public void return_can_specify_an_action_with_parameters_that_match_a_methods_argument_types() - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethodWithReturnValue(It.IsAny(), It.IsAny())).Return((int i, float f) => i + (int)f); - - Assert.Equal(11, mock.SomeMethodWithReturnValue(3, 8.1f)); - } - - [Fact] - public void throw_throws_an_invalid_operation_exception_by_default() - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeProperty).Throw(); - mock.When(x => x.SomeMethodTakingString("abc")).Throw(); - - var ex = Assert.Throws(() => mock.SomeProperty); - Assert.Equal("Mock has been configured to throw when accessing SomeProperty.", ex.Message); - - ex = Assert.Throws(() => mock.SomeMethodTakingString("abc")); - Assert.Equal("Mock has been configured to throw when accessing SomeMethodTakingString(It.Is(\"abc\")).", ex.Message); - } - - [Fact] - public void throw_can_specify_an_exception_to_throw_on_property_access() - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeProperty).Throw(new InvalidOperationException("Problem!")); - - var ex = Assert.Throws(() => Console.Write(mock.SomeProperty)); - Assert.Equal("Problem!", ex.Message); - } - - [Fact] - public void throw_can_specify_an_exception_to_throw_on_parameterless_method_access() - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethod()).Throw(new InvalidOperationException("Problem!")); - - var ex = Assert.Throws(() => mock.SomeMethod()); - Assert.Equal("Problem!", ex.Message); - } - - [Fact] - public void throw_can_specify_an_exception_to_throw_on_parameterized_method_access() - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethod(It.IsAny(), It.IsAny())).Throw(new InvalidOperationException("Problem!")); - - var ex = Assert.Throws(() => mock.SomeMethod(1, 1f)); - Assert.Equal("Problem!", ex.Message); - } - - [Fact] - public void actions_can_accept_base_types_in_place_of_specific_types() - { - var mock = new TestTargetMock(); - object value = null; - mock.When(x => x.SomeMethodTakingString(It.IsAny())).Do((object o) => value = o); - - mock.SomeMethodTakingString("whatever"); - Assert.Equal("whatever", value); - } - - [Fact] - public void methods_with_out_parameters_require_that_the_out_parameter_be_assigned() - { - var mock = new TestTargetMock(); - var called = false; - string s; - mock.When(x => x.SomeMethodWithOutParameter(out s)).Do(() => called = true); - - var ex = Assert.Throws(() => mock.SomeMethodWithOutParameter(out s)); - Assert.Equal("No value for out parameter at index 0 has been specified.", ex.Message); - Assert.False(called); - } - - [Fact] - public void methods_with_out_parameters_require_that_the_out_parameter_value_be_the_correct_type() - { - var mock = new TestTargetMock(); - var called = false; - string s; - mock.When(x => x.SomeMethodWithOutParameter(out s)).AssignOutOrRefParameter(0, 1).Do(() => called = true); - - var ex = Assert.Throws(() => mock.SomeMethodWithOutParameter(out s)); - Assert.Equal("Out parameter at index 0 has a value of type 'System.Int32' but type 'System.String' was expected.", ex.Message); - Assert.False(called); - } - - [Fact] - public void methods_with_value_type_out_parameters_cannot_have_null_assigned_as_the_value() - { - var mock = new TestTargetMock(); - var called = false; - int i; - mock.When(x => x.SomeMethodWithOutValueParameter(out i)).AssignOutOrRefParameter(0, null).Do(() => called = true); - - var ex = Assert.Throws(() => mock.SomeMethodWithOutValueParameter(out i)); - Assert.Equal("Out parameter at index 0 has a null value specified but it is a value type ('System.Int32') so cannot be null.", ex.Message); - Assert.False(called); - } - - [Fact] - public void methods_with_out_parameters_of_reference_type_can_be_mocked() - { - var mock = new TestTargetMock(); - string s; - mock.When(x => x.SomeMethodWithOutParameter(out s)).AssignOutOrRefParameter(0, "the value"); - - mock.SomeMethodWithOutParameter(out s); - Assert.Equal("the value", s); - } - - [Fact] - public void methods_with_out_parameters_of_value_type_can_be_mocked() - { - var mock = new TestTargetMock(); - int i; - mock.When(x => x.SomeMethodWithOutValueParameter(out i)).AssignOutOrRefParameter(0, 38); - - mock.SomeMethodWithOutValueParameter(out i); - Assert.Equal(38, i); - } - - [Fact] - public void methods_with_ref_parameters_of_reference_type_can_be_mocked() - { - var mock = new TestTargetMock(); - string s = null; - mock.When(x => x.SomeMethodWithRefParameter(ref s)).AssignOutOrRefParameter(0, "the value"); - - mock.SomeMethodWithRefParameter(ref s); - Assert.Equal("the value", s); - } - - [Fact] - public void methods_with_ref_parameters_of_value_type_can_be_mocked() - { - var mock = new TestTargetMock(); - int i = 0; - mock.When(x => x.SomeMethodWithRefValueParameter(ref i)).AssignOutOrRefParameter(0, 38); - - mock.SomeMethodWithRefValueParameter(ref i); - Assert.Equal(38, i); - } - - [Fact] - public void methods_with_ref_parameters_dont_require_a_parameter_assignment_when_configuring_specifications() - { - var mock = new TestTargetMock(); - var called = false; - int i = 0; - mock.When(x => x.SomeMethodWithRefValueParameter(ref i)).Do(() => called = true); - - mock.SomeMethodWithRefValueParameter(ref i); - Assert.True(called); - } - - [Fact] - public void methods_with_a_mixture_of_out_and_ref_parameters_can_be_mocked() - { - var mock = new TestTargetMock(); - var called = false; - int i1; - int i2 = 0; - string s1; - string s2 = null; - mock.When(x => x.SomeMethodWithAMixtureOfParameterTypes(0, null, out i1, out s1, ref i2, ref s2)) - .AssignOutOrRefParameter(2, 38) - .AssignOutOrRefParameter(3, "hello") - .AssignOutOrRefParameter(4, 14) - .AssignOutOrRefParameter(5, "world") - .Do(() => called = true); - - mock.SomeMethodWithAMixtureOfParameterTypes(0, null, out i1, out s1, ref i2, ref s2); - Assert.True(called); - Assert.Equal(38, i1); - Assert.Equal("hello", s1); - Assert.Equal(14, i2); - Assert.Equal("world", s2); - } - - [Fact] - public void virtual_members_in_unsealed_classes_can_be_mocked() - { - var mock = new UnsealedClassMock(); - mock.When(x => x.DoSomething()).Return(true); - - Assert.True(mock.MockedObject.DoSomething()); - } - - [Fact] - public void it_is_any_can_be_used_to_specify_arguments() - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethodWithReturnValue(It.IsAny(), It.IsAny())).Return(35); - - Assert.Equal(35, mock.SomeMethodWithReturnValue(5, 1f)); - } - - [Fact] - public void it_is_can_be_used_explicitly_to_specify_arguments() - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethodWithReturnValue(It.Is(3), It.Is(5f))).Return(35); - - Assert.Equal(35, mock.SomeMethodWithReturnValue(3, 5f)); - } - - [Fact] - public void it_is_can_be_used_implicitly_to_specify_arguments() - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethodWithReturnValue(3, 5f)).Return(35); - - Assert.Equal(35, mock.SomeMethodWithReturnValue(3, 5f)); - } - - [Fact] - public void it_is_not_can_be_used_to_specify_arguments() - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethodWithReturnValue(It.IsNot(3), It.IsNot(5f))).Return(35); - - Assert.Equal(35, mock.SomeMethodWithReturnValue(2, 4f)); - } - - [Fact] - public void it_is_null_be_used_to_specify_arguments() - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethodTakingStringWithReturnValue(It.IsNull())).Return(35); - - Assert.Equal(35, mock.SomeMethodTakingStringWithReturnValue(null)); - } - - [Fact] - public void it_is_not_null_be_used_to_specify_arguments() - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethodTakingStringWithReturnValue(It.IsNotNull())).Return(35); - - Assert.Equal(35, mock.SomeMethodTakingStringWithReturnValue("foo")); - } - - [Fact] - public void it_is_less_than_can_be_used_to_specify_arguments() - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethodWithReturnValue(It.IsLessThan(3), It.IsLessThan(5f))).Return(35); - - Assert.Equal(35, mock.SomeMethodWithReturnValue(2, 4f)); - } - - [Fact] - public void it_is_less_than_or_equal_to_can_be_used_to_specify_arguments() - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethodWithReturnValue(It.IsLessThanOrEqualTo(3), It.IsLessThanOrEqualTo(5f))).Return(35); - - Assert.Equal(35, mock.SomeMethodWithReturnValue(2, 4f)); - } - - [Fact] - public void it_is_greater_than_can_be_used_to_specify_arguments() - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethodWithReturnValue(It.IsGreaterThan(3), It.IsGreaterThan(5f))).Return(35); - - Assert.Equal(35, mock.SomeMethodWithReturnValue(4, 6f)); - } - - [Fact] - public void it_is_greater_than_or_equal_to_can_be_used_to_specify_arguments() - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethodWithReturnValue(It.IsGreaterThanOrEqualTo(3), It.IsGreaterThanOrEqualTo(5f))).Return(35); - - Assert.Equal(35, mock.SomeMethodWithReturnValue(4, 6f)); - } - - [Fact] - public void it_is_between_can_be_used_to_specify_arguments() - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethodWithReturnValue(It.IsBetween(3, 8), It.IsBetween(5f, 10f))).Return(35); - - Assert.Equal(35, mock.SomeMethodWithReturnValue(4, 9f)); - } - - [Fact] - public void it_is_not_between_can_be_used_to_specify_arguments() - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethodWithReturnValue(It.IsNotBetween(3, 8), It.IsNotBetween(5f, 10f))).Return(35); - - Assert.Equal(35, mock.SomeMethodWithReturnValue(2, 11f)); - } - - [Fact] - public void it_is_of_type_can_be_used_to_specify_arguments() - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethodTakingObjectWithReturnValue(It.IsOfType())).Return(30); - mock.When(x => x.SomeMethodTakingObjectWithReturnValue(It.IsOfType())).Return(35); - - Assert.Equal(30, mock.SomeMethodTakingObjectWithReturnValue(4)); - Assert.Equal(35, mock.SomeMethodTakingObjectWithReturnValue("foo")); - } - - [Fact] - public void it_is_not_of_type_can_be_used_to_specify_arguments() - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethodTakingObjectWithReturnValue(It.IsNotOfType())).Return(30); - mock.When(x => x.SomeMethodTakingObjectWithReturnValue(It.IsNotOfType())).Return(35); - - Assert.Equal(35, mock.SomeMethodTakingObjectWithReturnValue(4)); - Assert.Equal(30, mock.SomeMethodTakingObjectWithReturnValue("foo")); - Assert.Equal(35, mock.SomeMethodTakingObjectWithReturnValue(1f)); - } - - [Fact] - public void it_is_in_can_be_used_to_specify_arguments() - { - var mock = new TestTargetMock(MockBehavior.Loose); - mock.When(x => x.SomeMethodTakingObjectWithReturnValue(It.IsIn(1, 2, 3, 5, 8, 13))).Return(30); - - Assert.Equal(30, mock.SomeMethodTakingObjectWithReturnValue(2)); - Assert.Equal(30, mock.SomeMethodTakingObjectWithReturnValue(8)); - Assert.Equal(30, mock.SomeMethodTakingObjectWithReturnValue(13)); - Assert.Equal(0, mock.SomeMethodTakingObjectWithReturnValue(4)); - } - - [Fact] - public void it_is_like_can_be_used_to_specify_arguments() - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethodTakingStringWithReturnValue(It.IsLike(@"[Hh]ello\s*?world."))).Return(30); - - Assert.Equal(30, mock.SomeMethodTakingStringWithReturnValue("hello world!")); - Assert.Equal(30, mock.SomeMethodTakingStringWithReturnValue("Hello world!")); - Assert.Equal(30, mock.SomeMethodTakingStringWithReturnValue("hello \t world.")); - } - - [Fact] - public void it_is_like_can_be_used_with_options_to_specify_arguments() - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethodTakingStringWithReturnValue(It.IsLike(@"[Hh]ello\s*?world.", RegexOptions.IgnoreCase))).Return(30); - - Assert.Equal(30, mock.SomeMethodTakingStringWithReturnValue("HELLO WoRlD!")); - } - - [Fact] - public void it_matches_can_be_used_to_specify_arguments() - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethodTakingStringWithReturnValue(It.Matches(y => y.StartsWith("K")))).Return(30); - mock.When(x => x.SomeMethodTakingStringWithReturnValue(It.Matches(y => y.StartsWith("B")))).Return(29); - - Assert.Equal(30, mock.SomeMethodTakingStringWithReturnValue("Kent")); - Assert.Equal(30, mock.SomeMethodTakingStringWithReturnValue("Kart")); - Assert.Equal(29, mock.SomeMethodTakingStringWithReturnValue("Belinda")); - Assert.Equal(29, mock.SomeMethodTakingStringWithReturnValue("Batman")); - } - - [Fact] - public void argument_filters_can_be_used_to_differentiate_property_set_invocations() - { - var mock = new TestTargetMock(); - var anyCalled = false; - var specificCalled = false; - mock.WhenPropertySet(x => x.SomeProperty).Do(() => anyCalled = true); - mock.WhenPropertySet(x => x.SomeProperty, () => 3).Do(() => specificCalled = true); - - mock.SomeProperty = 30; - Assert.False(specificCalled); - Assert.True(anyCalled); - - mock.SomeProperty = 3; - Assert.True(specificCalled); - } - - [Fact] - public void argument_filters_can_be_used_to_differentiate_method_invocations() - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethodTakingStringWithReturnValue(It.IsAny())).Return(1); - mock.When(x => x.SomeMethodTakingStringWithReturnValue(It.IsLike("[Bb].."))).Return(2); - mock.When(x => x.SomeMethodTakingStringWithReturnValue("foo")).Return(3); - mock.When(x => x.SomeMethodTakingStringWithReturnValue("bar")).Return(4); - - Assert.Equal(4, mock.SomeMethodTakingStringWithReturnValue("bar")); - Assert.Equal(3, mock.SomeMethodTakingStringWithReturnValue("foo")); - Assert.Equal(2, mock.SomeMethodTakingStringWithReturnValue("biz")); - Assert.Equal(2, mock.SomeMethodTakingStringWithReturnValue("buz")); - Assert.Equal(2, mock.SomeMethodTakingStringWithReturnValue("Biz")); - Assert.Equal(1, mock.SomeMethodTakingStringWithReturnValue("whatever")); - Assert.Equal(1, mock.SomeMethodTakingStringWithReturnValue(null)); - } - - [Fact] - public void verify_throws_if_property_access_is_chained() - { - var mock = new TestTargetMock(); - var ex = Assert.Throws(() => mock.Verify(x => x.SomeComplexProperty.Name).WasCalledExactlyOnce()); - Assert.Equal("Specifications against properties cannot be chained: x.SomeComplexProperty.Name", ex.Message); - } - - [Fact] - public void verify_throws_if_method_access_is_chained() - { - var mock = new TestTargetMock(); - var ex = Assert.Throws(() => mock.Verify(x => x.SomeComplexMethod().GetAge()).WasCalledExactlyOnce()); - Assert.Equal("Specifications against methods cannot be chained: x.SomeComplexMethod().GetAge()", ex.Message); - } - - [Fact] - public void verify_throws_if_method_is_an_extension_method() - { - var mock = new TestTargetMock(); - var ex = Assert.Throws(() => mock.Verify(x => x.SomeExtensionMethod()).WasCalledExactlyOnce()); - Assert.Equal("Specifications against extension methods cannot be provided: x.SomeExtensionMethod()", ex.Message); - } - - [Fact] - public void verify_was_not_called_does_not_throw_if_the_member_was_not_invoked() - { - var mock = new TestTargetMock(); - - mock.Verify(x => x.SomeMethod()).WasNotCalled(); - mock.Verify(x => x.SomeMethodTakingString("foo")).WasNotCalled(); - mock.Verify(x => x.SomeMethodTakingString(It.IsAny())).WasNotCalled(); - mock.VerifyPropertySet(x => x.SomeProperty).WasNotCalled(); - mock.VerifyPropertySet(x => x.SomeProperty, () => It.IsAny()).WasNotCalled(); - } - - [Theory] - [InlineData(1, "Verification that SomeMethod() was not called failed because it was called 1 time.")] - [InlineData(2, "Verification that SomeMethod() was not called failed because it was called 2 times.")] - [InlineData(3, "Verification that SomeMethod() was not called failed because it was called 3 times.")] - [InlineData(15, "Verification that SomeMethod() was not called failed because it was called 15 times.")] - public void verify_was_not_called_throws_if_the_member_was_invoked(int callCount, string expectedExceptionMessage) - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethod()); - - for (var i = 0; i < callCount; ++i) - { - mock.SomeMethod(); - } - - var ex = Assert.Throws(() => mock.Verify(x => x.SomeMethod()).WasNotCalled()); - Assert.Equal(expectedExceptionMessage, ex.Message); - } - - [Fact] - public void verify_was_called_exactly_once_does_not_throw_if_the_member_was_called_once() - { - var mock = new TestTargetMock(MockBehavior.Loose); - mock.SomeMethod(); - mock.SomeMethodTakingString("foo"); - mock.SomeProperty = 30; - - mock.Verify(x => x.SomeMethod()).WasCalledExactlyOnce(); - mock.Verify(x => x.SomeMethodTakingString("foo")).WasCalledExactlyOnce(); - mock.Verify(x => x.SomeMethodTakingString(It.IsAny())).WasCalledExactlyOnce(); - mock.VerifyPropertySet(x => x.SomeProperty).WasCalledExactlyOnce(); - mock.VerifyPropertySet(x => x.SomeProperty, () => 30).WasCalledExactlyOnce(); - } - - [Theory] - [InlineData(0, "Verification that SomeMethod() was called exactly once failed because it was called 0 times.")] - [InlineData(2, "Verification that SomeMethod() was called exactly once failed because it was called 2 times.")] - [InlineData(3, "Verification that SomeMethod() was called exactly once failed because it was called 3 times.")] - [InlineData(15, "Verification that SomeMethod() was called exactly once failed because it was called 15 times.")] - public void verify_was_called_exactly_once_throws_if_the_member_was_not_invoked_exactly_once(int callCount, string expectedExceptionMessage) - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethod()); - - for (var i = 0; i < callCount; ++i) - { - mock.SomeMethod(); - } - - var ex = Assert.Throws(() => mock.Verify(x => x.SomeMethod()).WasCalledExactlyOnce()); - Assert.Equal(expectedExceptionMessage, ex.Message); - } - - [Fact] - public void verify_was_called_at_least_once_does_not_throw_if_the_member_was_called_one_or_more_times() - { - var mock = new TestTargetMock(MockBehavior.Loose); - mock.SomeMethod(); - mock.SomeMethodTakingString("foo"); - mock.SomeProperty = 30; - - mock.Verify(x => x.SomeMethod()).WasCalledAtLeastOnce(); - mock.Verify(x => x.SomeMethodTakingString("foo")).WasCalledAtLeastOnce(); - mock.Verify(x => x.SomeMethodTakingString(It.IsAny())).WasCalledAtLeastOnce(); - mock.VerifyPropertySet(x => x.SomeProperty).WasCalledAtLeastOnce(); - mock.VerifyPropertySet(x => x.SomeProperty, () => 30).WasCalledAtLeastOnce(); - - mock.SomeMethod(); - mock.SomeMethodTakingString("foo"); - mock.SomeProperty = 30; - mock.SomeMethod(); - mock.SomeMethodTakingString("foo"); - mock.SomeProperty = 30; - - mock.Verify(x => x.SomeMethod()).WasCalledAtLeastOnce(); - mock.Verify(x => x.SomeMethodTakingString("foo")).WasCalledAtLeastOnce(); - mock.Verify(x => x.SomeMethodTakingString(It.IsAny())).WasCalledAtLeastOnce(); - mock.VerifyPropertySet(x => x.SomeProperty).WasCalledAtLeastOnce(); - mock.VerifyPropertySet(x => x.SomeProperty, () => 30).WasCalledAtLeastOnce(); - } - - [Theory] - [InlineData(0, "Verification that SomeMethod() was called at least once failed because it was called 0 times.")] - public void verify_was_called_at_least_once_throws_if_the_member_was_not_invoked(int callCount, string expectedExceptionMessage) - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethod()); - - for (var i = 0; i < callCount; ++i) - { - mock.SomeMethod(); - } - - var ex = Assert.Throws(() => mock.Verify(x => x.SomeMethod()).WasCalledAtLeastOnce()); - Assert.Equal(expectedExceptionMessage, ex.Message); - } - - [Fact] - public void verify_was_called_at_most_once_does_not_throw_if_the_member_was_called_zero_or_one_times() - { - var mock = new TestTargetMock(MockBehavior.Loose); - - mock.Verify(x => x.SomeMethod()).WasCalledAtMostOnce(); - mock.Verify(x => x.SomeMethodTakingString("foo")).WasCalledAtMostOnce(); - mock.Verify(x => x.SomeMethodTakingString(It.IsAny())).WasCalledAtMostOnce(); - mock.VerifyPropertySet(x => x.SomeProperty).WasCalledAtMostOnce(); - mock.VerifyPropertySet(x => x.SomeProperty, () => 30).WasCalledAtMostOnce(); - - mock.SomeMethod(); - mock.SomeMethodTakingString("foo"); - mock.SomeProperty = 30; - - mock.Verify(x => x.SomeMethod()).WasCalledAtMostOnce(); - mock.Verify(x => x.SomeMethodTakingString("foo")).WasCalledAtMostOnce(); - mock.Verify(x => x.SomeMethodTakingString(It.IsAny())).WasCalledAtMostOnce(); - mock.VerifyPropertySet(x => x.SomeProperty).WasCalledAtMostOnce(); - mock.VerifyPropertySet(x => x.SomeProperty, () => 30).WasCalledAtMostOnce(); - } - - [Theory] - [InlineData(2, "Verification that SomeMethod() was called at most once failed because it was called 2 times.")] - [InlineData(3, "Verification that SomeMethod() was called at most once failed because it was called 3 times.")] - [InlineData(15, "Verification that SomeMethod() was called at most once failed because it was called 15 times.")] - public void verify_was_called_at_most_once_throws_if_the_member_was_invoked_more_than_once(int callCount, string expectedExceptionMessage) - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethod()); - - for (var i = 0; i < callCount; ++i) - { - mock.SomeMethod(); - } - - var ex = Assert.Throws(() => mock.Verify(x => x.SomeMethod()).WasCalledAtMostOnce()); - Assert.Equal(expectedExceptionMessage, ex.Message); - } - - [Fact] - public void verify_was_called_exactly_n_times_does_not_throw_if_the_member_was_called_the_correct_number_of_times() - { - var mock = new TestTargetMock(MockBehavior.Loose); - mock.SomeMethod(); - mock.SomeMethodTakingString("foo"); - mock.SomeMethodTakingString("foo"); - mock.SomeProperty = 30; - - mock.Verify(x => x.SomeMethod()).WasCalledExactly(times: 1); - mock.Verify(x => x.SomeMethodTakingString("foo")).WasCalledExactly(times: 2); - mock.Verify(x => x.SomeMethodTakingString(It.IsAny())).WasCalledExactly(times: 2); - mock.VerifyPropertySet(x => x.SomeProperty).WasCalledExactly(times: 1); - mock.VerifyPropertySet(x => x.SomeProperty, () => 30).WasCalledExactly(times: 1); - } - - [Theory] - [InlineData(2, 1, "Verification that SomeMethod() was called exactly 1 time failed because it was called 2 times.")] - [InlineData(2, 3, "Verification that SomeMethod() was called exactly 3 times failed because it was called 2 times.")] - [InlineData(3, 2, "Verification that SomeMethod() was called exactly 2 times failed because it was called 3 times.")] - [InlineData(15, 20, "Verification that SomeMethod() was called exactly 20 times failed because it was called 15 times.")] - [InlineData(20, 15, "Verification that SomeMethod() was called exactly 15 times failed because it was called 20 times.")] - public void verify_was_called_exactly_n_times_throws_if_the_member_was_not_invoked_exactly_that_number_of_times(int callCount, int verifyCount, string expectedExceptionMessage) - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethod()); - - for (var i = 0; i < callCount; ++i) - { - mock.SomeMethod(); - } - - var ex = Assert.Throws(() => mock.Verify(x => x.SomeMethod()).WasCalledExactly(times: verifyCount)); - Assert.Equal(expectedExceptionMessage, ex.Message); - } - - [Fact] - public void verify_was_called_at_least_n_times_does_not_throw_if_the_member_was_called_that_number_of_times_or_more() - { - var mock = new TestTargetMock(MockBehavior.Loose); - mock.SomeMethod(); - mock.SomeMethodTakingString("foo"); - mock.SomeProperty = 30; - - mock.Verify(x => x.SomeMethod()).WasCalledAtLeast(times: 1); - mock.Verify(x => x.SomeMethodTakingString("foo")).WasCalledAtLeast(times: 1); - mock.Verify(x => x.SomeMethodTakingString(It.IsAny())).WasCalledAtLeast(times: 1); - mock.VerifyPropertySet(x => x.SomeProperty).WasCalledAtLeast(times: 1); - mock.VerifyPropertySet(x => x.SomeProperty, () => 30).WasCalledAtLeast(times: 1); - - mock.SomeMethod(); - mock.SomeMethodTakingString("foo"); - mock.SomeProperty = 30; - mock.SomeMethod(); - mock.SomeMethodTakingString("foo"); - mock.SomeProperty = 30; - - mock.Verify(x => x.SomeMethod()).WasCalledAtLeast(times: 2); - mock.Verify(x => x.SomeMethodTakingString("foo")).WasCalledAtLeast(times: 3); - mock.Verify(x => x.SomeMethodTakingString(It.IsAny())).WasCalledAtLeast(times: 2); - mock.VerifyPropertySet(x => x.SomeProperty).WasCalledAtLeast(times: 3); - mock.VerifyPropertySet(x => x.SomeProperty, () => 30).WasCalledAtLeast(times: 2); - } - - [Theory] - [InlineData(0, 1, "Verification that SomeMethod() was called at least 1 time failed because it was called 0 times.")] - [InlineData(1, 2, "Verification that SomeMethod() was called at least 2 times failed because it was called 1 time.")] - [InlineData(2, 3, "Verification that SomeMethod() was called at least 3 times failed because it was called 2 times.")] - [InlineData(3, 5, "Verification that SomeMethod() was called at least 5 times failed because it was called 3 times.")] - [InlineData(15, 20, "Verification that SomeMethod() was called at least 20 times failed because it was called 15 times.")] - public void verify_was_called_at_least_n_times_throws_if_the_member_was_not_invoked_that_number_of_times_or_more(int callCount, int verifyCount, string expectedExceptionMessage) - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethod()); - - for (var i = 0; i < callCount; ++i) - { - mock.SomeMethod(); - } - - var ex = Assert.Throws(() => mock.Verify(x => x.SomeMethod()).WasCalledAtLeast(times: verifyCount)); - Assert.Equal(expectedExceptionMessage, ex.Message); - } - - [Fact] - public void verify_was_called_at_most_n_times_does_not_throw_if_the_member_was_called_fewer_or_equal_to_that_number_of_times() - { - var mock = new TestTargetMock(MockBehavior.Loose); - - mock.Verify(x => x.SomeMethod()).WasCalledAtMost(times: 1); - mock.Verify(x => x.SomeMethodTakingString("foo")).WasCalledAtMost(times: 1); - mock.Verify(x => x.SomeMethodTakingString(It.IsAny())).WasCalledAtMost(times: 1); - mock.VerifyPropertySet(x => x.SomeProperty).WasCalledAtMost(times: 1); - mock.VerifyPropertySet(x => x.SomeProperty, () => 30).WasCalledAtMost(times: 1); - - mock.SomeMethod(); - mock.SomeMethodTakingString("foo"); - mock.SomeProperty = 30; - - mock.Verify(x => x.SomeMethod()).WasCalledAtMost(times: 1); - mock.Verify(x => x.SomeMethodTakingString("foo")).WasCalledAtMost(times: 1); - mock.Verify(x => x.SomeMethodTakingString(It.IsAny())).WasCalledAtMost(times: 1); - mock.VerifyPropertySet(x => x.SomeProperty).WasCalledAtMost(times: 1); - mock.VerifyPropertySet(x => x.SomeProperty, () => 30).WasCalledAtMost(times: 1); - } - - [Theory] - [InlineData(1, 0, "Verification that SomeMethod() was called at most 0 times failed because it was called 1 time.")] - [InlineData(2, 1, "Verification that SomeMethod() was called at most 1 time failed because it was called 2 times.")] - [InlineData(3, 2, "Verification that SomeMethod() was called at most 2 times failed because it was called 3 times.")] - [InlineData(20, 15, "Verification that SomeMethod() was called at most 15 times failed because it was called 20 times.")] - public void verify_was_called_at_most_n_times_throws_if_the_member_was_invoked_more_than_that_number_of_times(int callCount, int verifyCount, string expectedExceptionMessage) - { - var mock = new TestTargetMock(); - mock.When(x => x.SomeMethod()); - - for (var i = 0; i < callCount; ++i) - { - mock.SomeMethod(); - } - - var ex = Assert.Throws(() => mock.Verify(x => x.SomeMethod()).WasCalledAtMost(times: verifyCount)); - Assert.Equal(expectedExceptionMessage, ex.Message); - } - - [Fact] - public void verification_failures_include_full_information_about_arguments_being_verified() - { - var mock = new TestTargetMock(); - - var ex = Assert.Throws(() => mock.Verify(x => x.SomeMethodTakingString("abc")).WasCalledExactlyOnce()); - Assert.Equal("Verification that SomeMethodTakingString(It.Is(\"abc\")) was called exactly once failed because it was called 0 times.", ex.Message); - - ex = Assert.Throws(() => mock.Verify(x => x.SomeMethodTakingString(It.IsAny())).WasCalledExactlyOnce()); - Assert.Equal("Verification that SomeMethodTakingString(It.IsAny()) was called exactly once failed because it was called 0 times.", ex.Message); - - ex = Assert.Throws(() => mock.Verify(x => x.SomeProperty).WasCalledExactlyOnce()); - Assert.Equal("Verification that SomeProperty was called exactly once failed because it was called 0 times.", ex.Message); - } - - [Fact] - public void verification_takes_into_account_any_argument_filters() - { - var mock = new TestTargetMock(MockBehavior.Loose); - mock.SomeMethodTakingString("foo"); - mock.SomeMethodTakingString("bar"); - mock.SomeMethodTakingString("bar"); - - mock.Verify(x => x.SomeMethodTakingString("foo")).WasCalledExactlyOnce(); - mock.Verify(x => x.SomeMethodTakingString("bar")).WasCalledExactly(times: 2); - mock.Verify(x => x.SomeMethodTakingString(It.IsAny())).WasCalledExactly(times: 3); - } - - [Fact] - public void issue13_repro() - { - var mock = new TestTargetMock(MockBehavior.Loose); - var subMock = new TestSubTargetMock(MockBehavior.Loose); - subMock.When(x => x.Height).Return(3); - - mock.SomeMethodTakingComplexType(subMock); - - mock.Verify(x => x.SomeMethodTakingComplexType(It.Matches(y => y.Height.HasValue))).WasCalledExactlyOnce(); - } - - #region Supporting Members - - private interface ITestSubTarget - { - string Name - { - get; - set; - } - - int? Height - { - get; - } - - int GetAge(); - } - - private interface ITestTarget - { - int SomeProperty - { - get; - set; - } - - int this[int index] - { - get; - set; - } - - int this[int first, int second] - { - get; - set; - } - - ITestSubTarget SomeComplexProperty - { - get; - } - - void SomeMethod(); - - ITestSubTarget SomeComplexMethod(); - - void SomeMethod(int i, float f); - - int SomeMethodWithReturnValue(); - - int SomeMethodWithReturnValue(int i, float f); - - void SomeMethodTakingComplexType(ITestSubTarget a); - - void SomeMethodTakingString(string s); - - int SomeMethodTakingStringWithReturnValue(string s); - - void SomeMethodTakingObject(object o); - - int SomeMethodTakingObjectWithReturnValue(object o); - - void SomeMethodWithOutParameter(out string s); - - void SomeMethodWithOutValueParameter(out int i); - - void SomeMethodWithRefParameter(ref string s); - - void SomeMethodWithRefValueParameter(ref int i); - - bool SomeMethodWithAMixtureOfParameterTypes(int i, string s, out int i2, out string s2, ref int i3, ref string s3); - } - - private sealed class TestSubTargetMock : MockBase, ITestSubTarget - { - public TestSubTargetMock(MockBehavior behavior) - : base(behavior) - { - } - - public int? Height => this.Apply(x => x.Height); - - public string Name - { - get { return this.Apply(x => x.Name); } - set { this.ApplyPropertySet(x => x.Name, value); } - } - - public int GetAge() => this.Apply(x => x.GetAge()); - } - - private sealed class TestTargetMock : MockBase, ITestTarget - { - public TestTargetMock(MockBehavior behavior = MockBehavior.Strict) - : base(behavior) - { - } - - public int SomeProperty - { - get { return this.Apply(x => x.SomeProperty); } - set { this.ApplyPropertySet(x => x.SomeProperty, value); } - } - - public int this[int index] - { - get { return this.Apply(x => x[index]); } - set { this.ApplyPropertySet(x => x[index], value); } - } - - public int this[int first, int second] - { - get { return this.Apply(x => x[first, second]); } - set { this.ApplyPropertySet(x => x[first, second], value); } - } - - public ITestSubTarget SomeComplexProperty => this.Apply(x => x.SomeComplexProperty); - - public void SomeMethod() => - this.Apply(x => x.SomeMethod()); - - public ITestSubTarget SomeComplexMethod() => - this.Apply(x => x.SomeComplexMethod()); - - public void SomeMethod(int i, float f) => - this.Apply(x => x.SomeMethod(i, f)); - - public int SomeMethodWithReturnValue() => - this.Apply(x => x.SomeMethodWithReturnValue()); - - public int SomeMethodWithReturnValue(int i, float f) => - this.Apply(x => x.SomeMethodWithReturnValue(i, f)); - - public void SomeMethodTakingComplexType(ITestSubTarget a) => - this.Apply(x => x.SomeMethodTakingComplexType(a)); - - public void SomeMethodTakingString(string s) => - this.Apply(x => x.SomeMethodTakingString(s)); - - public int SomeMethodTakingStringWithReturnValue(string s) => - this.Apply(x => x.SomeMethodTakingStringWithReturnValue(s)); - - public void SomeMethodTakingObject(object o) => - this.Apply(x => x.SomeMethodTakingObject(o)); - - public int SomeMethodTakingObjectWithReturnValue(object o) => - this.Apply(x => x.SomeMethodTakingObjectWithReturnValue(o)); - - public void SomeMethodWithOutParameter(out string s) - { - string sOut; - s = this.GetOutParameterValue(x => x.SomeMethodWithOutParameter(out sOut), 0); - this.Apply(x => x.SomeMethodWithOutParameter(out sOut)); - } - - public void SomeMethodWithOutValueParameter(out int i) - { - int iOut; - i = this.GetOutParameterValue(x => x.SomeMethodWithOutValueParameter(out iOut), 0); - this.Apply(x => x.SomeMethodWithOutValueParameter(out iOut)); - } - - public void SomeMethodWithRefParameter(ref string s) - { - var sRef = default(string); - s = this.GetRefParameterValue(x => x.SomeMethodWithRefParameter(ref sRef), 0); - this.Apply(x => x.SomeMethodWithRefParameter(ref sRef)); - } - - public void SomeMethodWithRefValueParameter(ref int i) - { - var iRef = default(int); - i = this.GetRefParameterValue(x => x.SomeMethodWithRefValueParameter(ref iRef), 0); - this.Apply(x => x.SomeMethodWithRefValueParameter(ref iRef)); - } - - public bool SomeMethodWithAMixtureOfParameterTypes(int i, string s, out int i2, out string s2, ref int i3, ref string s3) - { - int i2Out; - string s2Out; - var i3Ref = default(int); - var s3Ref = default(string); - i2 = this.GetOutParameterValue(x => x.SomeMethodWithAMixtureOfParameterTypes(i, s, out i2Out, out s2Out, ref i3Ref, ref s3Ref), 2); - s2 = this.GetOutParameterValue(x => x.SomeMethodWithAMixtureOfParameterTypes(i, s, out i2Out, out s2Out, ref i3Ref, ref s3Ref), 3); - i3 = this.GetRefParameterValue(x => x.SomeMethodWithAMixtureOfParameterTypes(i, s, out i2Out, out s2Out, ref i3Ref, ref s3Ref), 4); - s3 = this.GetRefParameterValue(x => x.SomeMethodWithAMixtureOfParameterTypes(i, s, out i2Out, out s2Out, ref i3Ref, ref s3Ref), 5); - return this.Apply(x => x.SomeMethodWithAMixtureOfParameterTypes(i, s, out i2Out, out s2Out, ref i3Ref, ref s3Ref)); - } - } - - private class UnsealedClass - { - public virtual bool DoSomething() => - false; - } - - private class UnsealedClassMock : MockBase - { - private readonly UnsealedClass mockedObject; - - public UnsealedClassMock(MockBehavior behavior = MockBehavior.Strict) - : base(behavior) - { - this.mockedObject = new UnsealedClassSubclass(this); - } - - public override UnsealedClass MockedObject => this.mockedObject; - - private sealed class UnsealedClassSubclass : UnsealedClass - { - private readonly UnsealedClassMock owner; - - public UnsealedClassSubclass(UnsealedClassMock owner) - { - this.owner = owner; - } - - public override bool DoSomething() - { - return this.owner.Apply(x => x.DoSomething()); - } - } - } - - private class InvalidMockedObject : MockBase - { - public InvalidMockedObject(MockBehavior behavior = MockBehavior.Strict) - : base(behavior) - { - } - } - - #endregion - } - - public static class TestExtensions - { - public static int SomeExtensionMethod(this object @this) => - 0; - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/PCLMock.UnitTests.csproj b/Src/PCLMock.UnitTests_OLD/PCLMock.UnitTests.csproj deleted file mode 100644 index 54156e8..0000000 --- a/Src/PCLMock.UnitTests_OLD/PCLMock.UnitTests.csproj +++ /dev/null @@ -1,400 +0,0 @@ - - - - - - Debug - AnyCPU - {05115055-0BBC-49D5-8966-2B90325F2F08} - Library - Properties - PCLMock.UnitTests - PCLMock.UnitTests - v4.5.2 - 512 - - - - True - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\Microsoft.CodeAnalysis.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.dll - True - - - ..\packages\Microsoft.CodeAnalysis.CSharp.1.3.2\lib\net45\Microsoft.CodeAnalysis.CSharp.dll - True - - - ..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.1.3.2\lib\net45\Microsoft.CodeAnalysis.CSharp.Workspaces.dll - True - - - ..\packages\Microsoft.CodeAnalysis.VisualBasic.1.3.2\lib\net45\Microsoft.CodeAnalysis.VisualBasic.dll - True - - - ..\packages\Microsoft.CodeAnalysis.VisualBasic.Workspaces.1.3.2\lib\net45\Microsoft.CodeAnalysis.VisualBasic.Workspaces.dll - True - - - ..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.Workspaces.dll - True - - - ..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.3.2\lib\net45\Microsoft.CodeAnalysis.Workspaces.Desktop.dll - True - - - - ..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll - True - - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.AttributedModel.dll - True - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.Convention.dll - True - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.Hosting.dll - True - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.Runtime.dll - True - - - ..\packages\Microsoft.Composition.1.0.30\lib\portable-net45+win8+wp8+wpa81\System.Composition.TypedParts.dll - True - - - - ..\packages\Rx-Core.2.2.5\lib\net45\System.Reactive.Core.dll - True - - - ..\packages\Rx-Interfaces.2.2.5\lib\net45\System.Reactive.Interfaces.dll - True - - - ..\packages\Rx-Linq.2.2.5\lib\net45\System.Reactive.Linq.dll - True - - - ..\packages\Rx-PlatformServices.2.2.5\lib\net45\System.Reactive.PlatformServices.dll - True - - - ..\packages\System.Reflection.Metadata.1.4.2\lib\portable-net45+win8\System.Reflection.Metadata.dll - True - - - - - - - - ..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll - True - - - ..\packages\xunit.assert.2.2.0\lib\netstandard1.1\xunit.assert.dll - True - - - ..\packages\xunit.extensibility.core.2.2.0\lib\netstandard1.1\xunit.core.dll - True - - - ..\packages\xunit.extensibility.execution.2.2.0\lib\net452\xunit.execution.desktop.dll - True - - - - - Properties\AssemblyInfoCommon.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {6e077796-0241-4191-a866-0ea52b9bd946} - PCLMock.CodeGeneration - - - {a02c0394-4dad-4422-97bb-4a90d89cee66} - PCLMock - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/PCLMock.UnitTests.v3.ncrunchproject b/Src/PCLMock.UnitTests_OLD/PCLMock.UnitTests.v3.ncrunchproject deleted file mode 100644 index d6fafe5..0000000 --- a/Src/PCLMock.UnitTests_OLD/PCLMock.UnitTests.v3.ncrunchproject +++ /dev/null @@ -1,11 +0,0 @@ - - - Disabled - Disabled - Disabled - Disabled - UseStaticAnalysis - False - True - - \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/Properties/AssemblyInfo.cs b/Src/PCLMock.UnitTests_OLD/Properties/AssemblyInfo.cs deleted file mode 100644 index a42eb3a..0000000 --- a/Src/PCLMock.UnitTests_OLD/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,6 +0,0 @@ -using System; -using System.Reflection; - -[assembly: AssemblyTitle("PCLMock.UnitTests")] -[assembly: AssemblyDescription("Contains unit tests for PCLMock.")] -[assembly: CLSCompliantAttribute(false)] \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/Utility/ObjectExtensionsFixture.cs b/Src/PCLMock.UnitTests_OLD/Utility/ObjectExtensionsFixture.cs deleted file mode 100644 index 4c0b2bb..0000000 --- a/Src/PCLMock.UnitTests_OLD/Utility/ObjectExtensionsFixture.cs +++ /dev/null @@ -1,72 +0,0 @@ -namespace PCLMock.UnitTests.Utility -{ - using System; - using PCLMock.Utility; - using Xunit; - using Xunit.Extensions; - - public sealed class ToDebugStringExtensionsFixture - { - [Theory] - [InlineData(null, "null")] - [InlineData("foo", "\"foo\"")] - [InlineData(true, "true")] - [InlineData(false, "false")] - [InlineData(35, "35")] - [InlineData(-17, "-17")] - [InlineData(35U, "35U")] - [InlineData(17U, "17U")] - [InlineData(35L, "35L")] - [InlineData(-17L, "-17L")] - [InlineData(35UL, "35UL")] - [InlineData(17UL, "17UL")] - [InlineData(3.4f, "3.4F")] - [InlineData(-3.4f, "-3.4F")] - [InlineData(3.4d, "3.4D")] - [InlineData(-3.4d, "-3.4D")] - [InlineData(typeof(bool), "bool")] - [InlineData(typeof(byte), "byte")] - [InlineData(typeof(sbyte), "sbyte")] - [InlineData(typeof(char), "char")] - [InlineData(typeof(decimal), "decimal")] - [InlineData(typeof(short), "short")] - [InlineData(typeof(ushort), "ushort")] - [InlineData(typeof(int), "int")] - [InlineData(typeof(uint), "uint")] - [InlineData(typeof(long), "long")] - [InlineData(typeof(ulong), "ulong")] - [InlineData(typeof(float), "float")] - [InlineData(typeof(double), "double")] - [InlineData(typeof(string), "string")] - [InlineData(typeof(object), "object")] - [InlineData(typeof(int?), "int?")] - [InlineData(typeof(long?), "long?")] - [InlineData(typeof(float?), "float?")] - [InlineData(typeof(DayOfWeek?), "System.DayOfWeek?")] - [InlineData(typeof(Guid?), "System.Guid?")] - [InlineData(typeof(ToDebugStringExtensionsFixture), "PCLMock.UnitTests.Utility.ToDebugStringExtensionsFixture")] - [InlineData(DayOfWeek.Monday, "DayOfWeek.Monday")] - [InlineData(DayOfWeek.Friday, "DayOfWeek.Friday")] - [InlineData((DayOfWeek)238, "DayOfWeek.238")] - [InlineData(AttributeTargets.Assembly | AttributeTargets.Class, "AttributeTargets.Assembly | AttributeTargets.Class")] - [InlineData(AttributeTargets.Assembly | (AttributeTargets)32768, "AttributeTargets.Assembly")] - public void to_debug_string_returns_expected_result(object o, string expectedResult) - { - Assert.Equal(expectedResult, o.ToDebugString()); - } - - [Fact] - public void to_debug_string_handles_decimals() - { - Assert.Equal("3.461M", 3.461M.ToDebugString()); - Assert.Equal("-3.461M", (-3.461M).ToDebugString()); - } - - [Fact] - public void to_debug_string_handles_anything_else_in_a_generic_fashion() - { - Assert.Equal("00:01:00 [System.TimeSpan]", TimeSpan.FromMinutes(1).ToDebugString()); - Assert.Equal("d527c281-1a18-452d-81ea-e8c2f3a252df [System.Guid]", new Guid("D527C281-1A18-452D-81EA-E8C2F3A252DF").ToDebugString()); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/Visitors/ArgumentFilterVisitorFixture.cs b/Src/PCLMock.UnitTests_OLD/Visitors/ArgumentFilterVisitorFixture.cs deleted file mode 100644 index 3f9279b..0000000 --- a/Src/PCLMock.UnitTests_OLD/Visitors/ArgumentFilterVisitorFixture.cs +++ /dev/null @@ -1,87 +0,0 @@ -namespace PCLMock.UnitTests.Visitors -{ - using System; - using System.Linq.Expressions; - using PCLMock.ArgumentFilters; - using PCLMock.Visitors; - using Xunit; - using Xunit.Extensions; - - public sealed class ArgumentFilterVisitorFixture - { - [Fact] - public void can_find_argument_filter_in_method_call_against_it_class() - { - var argumentFilter = ArgumentFilterVisitor.FindArgumentFilterWithin(GetExpression(() => It.IsAny())); - Assert.NotNull(argumentFilter); - Assert.True(argumentFilter.Matches("foo")); - Assert.True(argumentFilter.Matches("bar")); - Assert.True(argumentFilter.Matches(null)); - - argumentFilter = ArgumentFilterVisitor.FindArgumentFilterWithin(GetExpression(() => It.Is("foo"))); - Assert.NotNull(argumentFilter); - Assert.True(argumentFilter.Matches("foo")); - Assert.False(argumentFilter.Matches("bar")); - - argumentFilter = ArgumentFilterVisitor.FindArgumentFilterWithin(GetExpression(() => It.IsIn(1, 2, 3))); - Assert.NotNull(argumentFilter); - Assert.True(argumentFilter.Matches(1)); - Assert.True(argumentFilter.Matches(3)); - Assert.False(argumentFilter.Matches(4)); - } - - [Theory] - [InlineData(1)] - [InlineData(35)] - [InlineData(3235)] - [InlineData("foo")] - [InlineData("bar")] - [InlineData("baz")] - [InlineData(1f)] - [InlineData(13.1f)] - [InlineData(1d)] - [InlineData(13.1d)] - public void a_constant_being_returned_is_translated_to_an_is_argument_filter(object value) - { - var argumentFilter = ArgumentFilterVisitor.FindArgumentFilterWithin(GetExpression(() => value)); - Assert.NotNull(argumentFilter); - Assert.IsType(argumentFilter); - Assert.True(argumentFilter.Matches(value)); - } - - [Fact] - public void expressions_are_evaluated_and_translated_to_an_is_argument_filter() - { - var argumentFilter = ArgumentFilterVisitor.FindArgumentFilterWithin(GetExpression(() => decimal.MinValue)); - Assert.NotNull(argumentFilter); - Assert.IsType(argumentFilter); - Assert.True(argumentFilter.Matches(decimal.MinValue)); - - argumentFilter = ArgumentFilterVisitor.FindArgumentFilterWithin(GetExpression(() => Tuple.Create(1, "one"))); - Assert.NotNull(argumentFilter); - Assert.IsType(argumentFilter); - Assert.True(argumentFilter.Matches(Tuple.Create(1, "one"))); - } - - [Fact] - public void cannot_find_argument_filter_in_method_call_with_no_arguments() - { - var argumentFilter = ArgumentFilterVisitor.FindArgumentFilterWithin(GetExpression(() => Console.WriteLine())); - Assert.Null(argumentFilter); - } - - #region Supporting Members - - private static Expression GetExpression(Expression root) - { - return root.Body; - } - - private static Expression GetExpression(Expression> root) - { - return root.Body; - } - - #endregion - } -} diff --git a/Src/PCLMock.UnitTests_OLD/Visitors/ArgumentFiltersVisitorFixture.cs b/Src/PCLMock.UnitTests_OLD/Visitors/ArgumentFiltersVisitorFixture.cs deleted file mode 100644 index bb46f1f..0000000 --- a/Src/PCLMock.UnitTests_OLD/Visitors/ArgumentFiltersVisitorFixture.cs +++ /dev/null @@ -1,67 +0,0 @@ -namespace PCLMock.UnitTests.Visitors -{ - using System; - using System.Linq.Expressions; - using PCLMock.ArgumentFilters; - using PCLMock.Utility; - using PCLMock.Visitors; - using Xunit; - - public sealed class ArgumentFiltersVisitorFixture - { - [Fact] - public void can_find_argument_filters_in_a_method_call() - { - var argumentFilters = ArgumentFiltersVisitor.FindArgumentFiltersWithin(GetExpression(() => Console.WriteLine(It.IsAny(), 3, It.IsIn("foo", "bar")))); - Assert.NotNull(argumentFilters); - Assert.Equal(3, argumentFilters.Count); - Assert.True(argumentFilters[0].Matches("foo")); - Assert.True(argumentFilters[0].Matches("bar")); - Assert.True(argumentFilters[0].Matches(null)); - Assert.True(argumentFilters[1].Matches(3)); - Assert.False(argumentFilters[1].Matches(2)); - Assert.True(argumentFilters[2].Matches("foo")); - Assert.True(argumentFilters[2].Matches("bar")); - Assert.False(argumentFilters[2].Matches("baz")); - Assert.False(argumentFilters[2].Matches(3)); - } - - [Fact] - public void out_and_ref_arguments_always_result_in_a_non_discriminatory_filter() - { - int i = 0; - string s; - var argumentFilters = ArgumentFiltersVisitor.FindArgumentFiltersWithin(GetExpression(() => this.SomeMethod(ref i, out s))); - Assert.NotNull(argumentFilters); - Assert.Equal(2, argumentFilters.Count); - Assert.IsType>(argumentFilters[0]); - Assert.IsType>(argumentFilters[1]); - } - - [Fact] - public void cannot_find_argument_filters_if_there_is_a_method_call_but_it_is_not_at_root_level() - { - ArgumentFilterCollection argumentFilters; - Assert.False(ArgumentFiltersVisitor.TryFindArgumentFiltersWithin(GetExpression(() => new[] { Tuple.Create(1, 2) }), out argumentFilters)); - } - - #region Supporting Members - - private static Expression GetExpression(Expression root) - { - return root.Body; - } - - private static Expression GetExpression(Expression> root) - { - return root.Body; - } - - private void SomeMethod(ref int i, out string s) - { - s = null; - } - - #endregion - } -} diff --git a/Src/PCLMock.UnitTests_OLD/Visitors/ArgumentsVisitorFixture.cs b/Src/PCLMock.UnitTests_OLD/Visitors/ArgumentsVisitorFixture.cs deleted file mode 100644 index 3adca9d..0000000 --- a/Src/PCLMock.UnitTests_OLD/Visitors/ArgumentsVisitorFixture.cs +++ /dev/null @@ -1,59 +0,0 @@ -namespace PCLMock.UnitTests.Visitors -{ - using System; - using System.Linq.Expressions; - using PCLMock.Visitors; - using Xunit; - - public sealed class ArgumentsVisitorFixture - { - [Fact] - public void can_find_arguments_in_parameterless_method_call() - { - var arguments = ArgumentsVisitor.FindArgumentsWithin(GetExpression(() => Console.WriteLine())); - Assert.NotNull(arguments); - Assert.Equal(0, arguments.Length); - } - - [Fact] - public void can_find_arguments_within_method_call_taking_parameters() - { - var arguments = ArgumentsVisitor.FindArgumentsWithin(GetExpression(() => Console.WriteLine("something {0}, {1}, {2}", 13, DateTime.MinValue, Tuple.Create(1, "one")))); - Assert.NotNull(arguments); - Assert.Equal(4, arguments.Length); - Assert.Equal("something {0}, {1}, {2}", arguments[0]); - Assert.Equal(13, arguments[1]); - Assert.Equal(DateTime.MinValue, arguments[2]); - Assert.Equal(Tuple.Create(1, "one"), arguments[3]); - } - - [Fact] - public void cannot_find_arguments_in_non_method_call() - { - object[] arguments; - Assert.False(ArgumentsVisitor.TryFindArgumentsWithin(GetExpression(() => 13), out arguments)); - Assert.False(ArgumentsVisitor.TryFindArgumentsWithin(GetExpression(() => "foo"), out arguments)); - } - - [Fact] - public void cannot_find_arguments_if_there_is_a_method_call_but_it_is_not_at_root_level() - { - object[] arguments; - Assert.False(ArgumentsVisitor.TryFindArgumentsWithin(GetExpression(() => new[] { Tuple.Create(1, 2) }), out arguments)); - } - - #region Supporting Members - - private static Expression GetExpression(Expression root) - { - return root.Body; - } - - private static Expression GetExpression(Expression> root) - { - return root.Body; - } - - #endregion - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/Visitors/SelectorStringVisitorFixture.cs b/Src/PCLMock.UnitTests_OLD/Visitors/SelectorStringVisitorFixture.cs deleted file mode 100644 index 5d5bda4..0000000 --- a/Src/PCLMock.UnitTests_OLD/Visitors/SelectorStringVisitorFixture.cs +++ /dev/null @@ -1,101 +0,0 @@ -namespace PCLMock.UnitTests.Visitors -{ - using System; - using System.Linq.Expressions; - using PCLMock.Visitors; - using Xunit; - - public sealed class SelectorStringVisitorFixture - { - [Fact] - public void accessing_a_read_only_property_yields_the_correct_string_representation() - { - var visitor = new SelectorStringVisitor(); - var expression = GetExpression(x => x.ReadOnlyProperty); - - visitor.Visit(expression); - - Assert.Equal("ReadOnlyProperty", visitor.ToString()); - } - - [Fact] - public void accessing_a_read_write_property_yields_the_correct_string_representation() - { - var visitor = new SelectorStringVisitor(); - var expression = GetExpression(x => x.ReadWriteProperty); - - visitor.Visit(expression); - - Assert.Equal("ReadWriteProperty", visitor.ToString()); - } - - [Fact] - public void accessing_a_method_without_arguments_yields_the_correct_string_representation() - { - var visitor = new SelectorStringVisitor(); - var expression = GetExpression(x => x.MethodWithoutArguments()); - - visitor.Visit(expression); - - Assert.Equal("MethodWithoutArguments()", visitor.ToString()); - } - - [Fact] - public void accessing_a_method_with_arguments_yields_the_correct_string_representation() - { - var visitor = new SelectorStringVisitor(); - var expression = GetExpression(x => x.MethodWithArguments(3, It.IsAny(), null)); - - visitor.Visit(expression); - - Assert.Equal("MethodWithArguments(It.Is(3), It.IsAny(), It.Is(null))", visitor.ToString()); - - visitor = new SelectorStringVisitor(); - expression = GetExpression(x => x.MethodWithArguments(3, It.IsAny(), "abc")); - - visitor.Visit(expression); - - Assert.Equal("MethodWithArguments(It.Is(3), It.IsAny(), It.Is(\"abc\"))", visitor.ToString()); - - visitor = new SelectorStringVisitor(); - var value = TimeSpan.FromSeconds(1); - expression = GetExpression(x => x.MethodWithArguments(3, It.IsAny(), value)); - - visitor.Visit(expression); - - Assert.Equal("MethodWithArguments(It.Is(3), It.IsAny(), It.Is(00:00:01 [System.TimeSpan]))", visitor.ToString()); - } - - #region Supporting Members - - private static Expression GetExpression(Expression> root) - { - return root.Body; - } - - private static Expression GetExpression(Expression> root) - { - return root.Body; - } - - private interface ITestTarget - { - int ReadOnlyProperty - { - get; - } - - int ReadWriteProperty - { - get; - set; - } - - int MethodWithoutArguments(); - - int MethodWithArguments(int i, string s, object o); - } - - #endregion - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/Visitors/ValueExtractorFixture.cs b/Src/PCLMock.UnitTests_OLD/Visitors/ValueExtractorFixture.cs deleted file mode 100644 index b73cbe1..0000000 --- a/Src/PCLMock.UnitTests_OLD/Visitors/ValueExtractorFixture.cs +++ /dev/null @@ -1,139 +0,0 @@ -namespace PCLMock.UnitTests.Visitors -{ - using System; - using System.Linq.Expressions; - using PCLMock.Visitors; - using Xunit; - using Xunit.Extensions; - - public sealed class ValueExtractorFixture - { - [Fact] - public void can_find_null_in_an_expression() - { - Assert.Null(ValueExtractor.FindValueWithin(GetExpression(() => null))); - } - - [Theory] - [InlineData(1)] - [InlineData(5)] - [InlineData(52367)] - [InlineData(int.MinValue)] - [InlineData(int.MaxValue)] - [InlineData(Math.PI)] - [InlineData(1L)] - [InlineData(5L)] - [InlineData(52367L)] - [InlineData("foo")] - [InlineData("bar")] - [InlineData(12f)] - [InlineData(12.1d)] - public void can_find_value_in_an_expression_that_simply_returns_a_constant(object value) - { - Assert.Equal(value, ValueExtractor.FindValueWithin(GetExpression(() => value))); - } - - [Fact] - public void can_find_value_in_an_expression_that_returns_a_dereferenced_value() - { - Assert.Equal(DateTime.MinValue, ValueExtractor.FindValueWithin(GetExpression(() => DateTime.MinValue))); - Assert.Equal(decimal.MinValue, ValueExtractor.FindValueWithin(GetExpression(() => decimal.MinValue))); - Assert.Equal(decimal.MaxValue, ValueExtractor.FindValueWithin(GetExpression(() => decimal.MaxValue))); - Assert.Equal(decimal.MinusOne, ValueExtractor.FindValueWithin(GetExpression(() => decimal.MinusOne))); - } - - [Theory] - [InlineData(1)] - [InlineData(19)] - [InlineData(3471)] - [InlineData(1L)] - [InlineData(5L)] - [InlineData(52367L)] - [InlineData("foo")] - [InlineData("bar")] - [InlineData(12f)] - [InlineData(12.1d)] - public void can_find_value_in_an_expression_that_returns_a_local_value(object value) - { - var local = value; - Assert.Equal(value, ValueExtractor.FindValueWithin(GetExpression(() => local))); - } - - [Theory] - [InlineData(new int[] {})] - [InlineData(new [] { 1, 2, 3 })] - [InlineData(new [] { 1, 2, 3, 4, 5 })] - [InlineData(new [] { 1d, 10d, 2937d })] - public void can_find_value_in_an_expression_that_creates_an_array(object array) - { - Assert.Equal(array, ValueExtractor.FindValueWithin(GetExpression(() => array))); - } - - [Fact] - public void can_find_value_in_an_expression_that_news_up_an_object() - { - Assert.Equal(new DateTime(1979, 10, 26), ValueExtractor.FindValueWithin(GetExpression(() => new DateTime(1979, 10, 26)))); - Assert.Equal(Tuple.Create("one", 1), ValueExtractor.FindValueWithin(GetExpression(() => new Tuple("one", 1)))); - } - - [Theory] - [InlineData(1L)] - [InlineData(2L)] - [InlineData(1347L)] - [InlineData(-23897L)] - public void can_find_value_in_an_expression_that_requires_conversion(long value) - { - Assert.Equal((int)value, ValueExtractor.FindValueWithin(GetExpression(() => (int)value))); - } - - [Fact] - public void can_find_value_in_an_expression_that_includes_a_lambda() - { - Expression> expression = x => x % 2 == 0; - var value = ValueExtractor.FindValueWithin(expression); - - Assert.NotNull(value); - var castValue = Assert.IsType>(value); - - Assert.True(castValue(0)); - Assert.False(castValue(1)); - Assert.True(castValue(2)); - Assert.False(castValue(3)); - } - - [Fact] - public void can_find_value_in_a_method_invocation() - { - Assert.Equal(Tuple.Create("one", 1), ValueExtractor.FindValueWithin(GetExpression(() => Tuple.Create("one", 1)))); - Assert.Equal(TimeSpan.FromSeconds(1), ValueExtractor.FindValueWithin(GetExpression(() => TimeSpan.FromSeconds(1)))); - } - - [Fact] - public void can_find_value_in_a_binary_expression() - { - Assert.Equal(7, ValueExtractor.FindValueWithin(GetExpression(() => 3 + 1 + 3))); - Assert.Equal(TimeSpan.FromSeconds(4), ValueExtractor.FindValueWithin(GetExpression(() => TimeSpan.FromSeconds(1) + TimeSpan.FromSeconds(3)))); - } - - [Fact] - public void cannot_find_value_in_a_method_invocation_if_the_method_has_no_return_value() - { - object value; - Assert.False(ValueExtractor.TryFindValueWithin(GetExpression(() => Console.WriteLine()), out value)); - } - - #region Supporting Members - - private static Expression GetExpression(Expression root) - { - return root.Body; - } - - private static Expression GetExpression(Expression> root) - { - return root.Body; - } - - #endregion - } -} \ No newline at end of file diff --git a/Src/PCLMock.UnitTests_OLD/app.config b/Src/PCLMock.UnitTests_OLD/app.config deleted file mode 100644 index 0f23969..0000000 --- a/Src/PCLMock.UnitTests_OLD/app.config +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Src/PCLMock.UnitTests_OLD/packages.config b/Src/PCLMock.UnitTests_OLD/packages.config deleted file mode 100644 index a1a449c..0000000 --- a/Src/PCLMock.UnitTests_OLD/packages.config +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Src/PCLMock.nuspec b/Src/PCLMock.nuspec deleted file mode 100644 index 56163d0..0000000 --- a/Src/PCLMock.nuspec +++ /dev/null @@ -1,19 +0,0 @@ - - - - PCLMock - @build.number@ - Kent Boogaart - Kent Boogaart - https://github.com/kentcb/PCLMock/blob/master/LICENSE - https://github.com/kentcb/PCLMock - https://raw.githubusercontent.com/kentcb/PCLMock/master/Art/Logo64x64.png - false - - PCLMock is mocking framework in a PCL, making it usable on platforms such as iOS and Android. - - .NET mono portable pcl mocking ios android xamarin - @dependencies@ - @references@ - - \ No newline at end of file diff --git a/Src/PCLMock.sln b/Src/PCLMock.sln index 017d75d..efc0ac7 100644 --- a/Src/PCLMock.sln +++ b/Src/PCLMock.sln @@ -1,20 +1,14 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27004.2002 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30022.13 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PCLMock.UnitTests", "PCLMock.UnitTests\PCLMock.UnitTests.csproj", "{05115055-0BBC-49D5-8966-2B90325F2F08}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".build", ".build", "{A1B3C179-EFB2-437F-A9FF-16BD29DE2292}" ProjectSection(SolutionItems) = preProject ..\build.bat = ..\build.bat ..\build.fsx = ..\build.fsx EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PCLMock.CodeGeneration.T4", "PCLMock.CodeGeneration.T4\PCLMock.CodeGeneration.T4.csproj", "{F482A52C-3D60-429D-9152-3FFB5D35CBFF}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PCLMock.CodeGeneration.Console", "PCLMock.CodeGeneration.Console\PCLMock.CodeGeneration.Console.csproj", "{B56824C1-B58E-42FB-A528-518638A7DA15}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PCLMock.CodeGeneration", "PCLMock.CodeGeneration\PCLMock.CodeGeneration.csproj", "{49C812A9-5C76-4567-947F-B21A38FE4EC1}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PCLMock", "PCLMock\PCLMock.csproj", "{2F34337F-05B9-4B38-A072-46409A3B2ACE}" @@ -24,24 +18,18 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Directory.Build.targets = Directory.Build.targets EndProjectSection EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PCLMock.CodeGeneration.SourceGenerator", "PCLMock.CodeGeneration.SourceGenerator\PCLMock.CodeGeneration.SourceGenerator.csproj", "{725972E8-9AD8-48FA-B13C-EF2B79ADD745}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PCLMock.UnitTests", "PCLMock.UnitTests\PCLMock.UnitTests.csproj", "{EB3BE1E1-59C2-4321-A4BC-B01D76B848AF}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PCLMock.CodeGeneration.Console", "PCLMock.CodeGeneration.Console\PCLMock.CodeGeneration.Console.csproj", "{1DA2035B-C9EF-4256-8D00-781173C1B4A5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {05115055-0BBC-49D5-8966-2B90325F2F08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {05115055-0BBC-49D5-8966-2B90325F2F08}.Debug|Any CPU.Build.0 = Debug|Any CPU - {05115055-0BBC-49D5-8966-2B90325F2F08}.Release|Any CPU.ActiveCfg = Release|Any CPU - {05115055-0BBC-49D5-8966-2B90325F2F08}.Release|Any CPU.Build.0 = Release|Any CPU - {F482A52C-3D60-429D-9152-3FFB5D35CBFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F482A52C-3D60-429D-9152-3FFB5D35CBFF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F482A52C-3D60-429D-9152-3FFB5D35CBFF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F482A52C-3D60-429D-9152-3FFB5D35CBFF}.Release|Any CPU.Build.0 = Release|Any CPU - {B56824C1-B58E-42FB-A528-518638A7DA15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B56824C1-B58E-42FB-A528-518638A7DA15}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B56824C1-B58E-42FB-A528-518638A7DA15}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B56824C1-B58E-42FB-A528-518638A7DA15}.Release|Any CPU.Build.0 = Release|Any CPU {49C812A9-5C76-4567-947F-B21A38FE4EC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {49C812A9-5C76-4567-947F-B21A38FE4EC1}.Debug|Any CPU.Build.0 = Debug|Any CPU {49C812A9-5C76-4567-947F-B21A38FE4EC1}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -50,6 +38,18 @@ Global {2F34337F-05B9-4B38-A072-46409A3B2ACE}.Debug|Any CPU.Build.0 = Debug|Any CPU {2F34337F-05B9-4B38-A072-46409A3B2ACE}.Release|Any CPU.ActiveCfg = Release|Any CPU {2F34337F-05B9-4B38-A072-46409A3B2ACE}.Release|Any CPU.Build.0 = Release|Any CPU + {725972E8-9AD8-48FA-B13C-EF2B79ADD745}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {725972E8-9AD8-48FA-B13C-EF2B79ADD745}.Debug|Any CPU.Build.0 = Debug|Any CPU + {725972E8-9AD8-48FA-B13C-EF2B79ADD745}.Release|Any CPU.ActiveCfg = Release|Any CPU + {725972E8-9AD8-48FA-B13C-EF2B79ADD745}.Release|Any CPU.Build.0 = Release|Any CPU + {EB3BE1E1-59C2-4321-A4BC-B01D76B848AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EB3BE1E1-59C2-4321-A4BC-B01D76B848AF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EB3BE1E1-59C2-4321-A4BC-B01D76B848AF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EB3BE1E1-59C2-4321-A4BC-B01D76B848AF}.Release|Any CPU.Build.0 = Release|Any CPU + {1DA2035B-C9EF-4256-8D00-781173C1B4A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1DA2035B-C9EF-4256-8D00-781173C1B4A5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1DA2035B-C9EF-4256-8D00-781173C1B4A5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1DA2035B-C9EF-4256-8D00-781173C1B4A5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Src/PCLMock/MockBase.cs b/Src/PCLMock/MockBase.cs index 229d450..5cc215e 100644 --- a/Src/PCLMock/MockBase.cs +++ b/Src/PCLMock/MockBase.cs @@ -49,10 +49,7 @@ protected MockBase(MockBehavior behavior) /// /// Gets the behavior of this mock. /// - public MockBehavior Behavior - { - get { return this.behavior; } - } + public MockBehavior Behavior => this.behavior; /// /// Gets the mocked object. diff --git a/Src/PCLMock/PCLMock.csproj b/Src/PCLMock/PCLMock.csproj index aac5c3a..a72061f 100644 --- a/Src/PCLMock/PCLMock.csproj +++ b/Src/PCLMock/PCLMock.csproj @@ -3,6 +3,12 @@ netstandard1.0 false + true + True + + + + \ No newline at end of file diff --git a/Src/PCLMock/Properties/AssemblyInfo.cs b/Src/PCLMock/Properties/AssemblyInfo.cs index 208bb83..42ad5ff 100644 --- a/Src/PCLMock/Properties/AssemblyInfo.cs +++ b/Src/PCLMock/Properties/AssemblyInfo.cs @@ -5,4 +5,4 @@ [assembly: AssemblyTitle("PCLMock")] [assembly: AssemblyDescription("Contains the implementation of PCLMock.")] [assembly: InternalsVisibleTo("PCLMock.UnitTests")] -[assembly: CLSCompliantAttribute(true)] \ No newline at end of file +[assembly: CLSCompliant(true)] \ No newline at end of file diff --git a/Src/PCLMock_OLD/ArgumentFilters/IsAnyArgumentFilter.cs b/Src/PCLMock_OLD/ArgumentFilters/IsAnyArgumentFilter.cs deleted file mode 100644 index 2c33dfe..0000000 --- a/Src/PCLMock_OLD/ArgumentFilters/IsAnyArgumentFilter.cs +++ /dev/null @@ -1,44 +0,0 @@ -namespace PCLMock.ArgumentFilters -{ - using System; - using PCLMock.Utility; - - internal sealed class IsAnyArgumentFilter : IArgumentFilter, IEquatable> - { - public static readonly IsAnyArgumentFilter Instance = new IsAnyArgumentFilter(); - - private IsAnyArgumentFilter() - { - } - - public bool Matches(object argument) - { - return true; - } - - public override string ToString() - { - return "It.IsAny<" + typeof(T).ToDebugString() + ">()"; - } - - public bool Equals(IsAnyArgumentFilter other) - { - if (other == null) - { - return false; - } - - return true; - } - - public override bool Equals(object obj) - { - return this.Equals(obj as IsAnyArgumentFilter); - } - - public override int GetHashCode() - { - throw new NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock_OLD/ArgumentFilters/IsArgumentFilter.cs b/Src/PCLMock_OLD/ArgumentFilters/IsArgumentFilter.cs deleted file mode 100644 index 86d38bb..0000000 --- a/Src/PCLMock_OLD/ArgumentFilters/IsArgumentFilter.cs +++ /dev/null @@ -1,45 +0,0 @@ -namespace PCLMock.ArgumentFilters -{ - using System; - using PCLMock.Utility; - - internal sealed class IsArgumentFilter : IArgumentFilter, IEquatable - { - private readonly object expected; - - public IsArgumentFilter(object expected) - { - this.expected = expected; - } - - public bool Matches(object argument) - { - return object.Equals(argument, this.expected); - } - - public override string ToString() - { - return "It.Is(" + this.expected.ToDebugString() + ")"; - } - - public bool Equals(IsArgumentFilter other) - { - if (other == null) - { - return false; - } - - return this.Matches(other.expected); - } - - public override bool Equals(object obj) - { - return this.Equals(obj as IsArgumentFilter); - } - - public override int GetHashCode() - { - throw new NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock_OLD/ArgumentFilters/IsBetweenArgumentFilter.cs b/Src/PCLMock_OLD/ArgumentFilters/IsBetweenArgumentFilter.cs deleted file mode 100644 index 634af32..0000000 --- a/Src/PCLMock_OLD/ArgumentFilters/IsBetweenArgumentFilter.cs +++ /dev/null @@ -1,66 +0,0 @@ -namespace PCLMock.ArgumentFilters -{ - using System; - using System.Collections.Generic; - using PCLMock.Utility; - - internal sealed class IsBetweenArgumentFilter : IArgumentFilter, IEquatable> - where T : IComparable - { - private readonly T minimum; - private readonly T maximum; - - public IsBetweenArgumentFilter(T minimum, T maximum) - { - this.minimum = minimum; - this.maximum = maximum; - - // to make our job easier below, we ensure that we can rely on knowing the lower end of the range versus the upper - if (Comparer.Default.Compare(this.minimum, this.maximum) > 0) - { - this.minimum = maximum; - this.maximum = minimum; - } - } - - public bool Matches(object argument) - { - if (argument != null && !(argument is T)) - { - // shouldn't happen - return false; - } - - return - Comparer.Default.Compare((T)argument, this.minimum) >= 0 && - Comparer.Default.Compare((T)argument, this.maximum) <= 0; - } - - public override string ToString() - { - return "It.IsBetween(" + this.minimum.ToDebugString() + ", " + this.maximum.ToDebugString() + ")"; - } - - public bool Equals(IsBetweenArgumentFilter other) - { - if (other == null) - { - return false; - } - - return - Comparer.Default.Compare(this.minimum, other.minimum) == 0 && - Comparer.Default.Compare(this.maximum, other.maximum) == 0; - } - - public override bool Equals(object obj) - { - return this.Equals(obj as IsBetweenArgumentFilter); - } - - public override int GetHashCode() - { - throw new NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock_OLD/ArgumentFilters/IsGreaterThanArgumentFilter.cs b/Src/PCLMock_OLD/ArgumentFilters/IsGreaterThanArgumentFilter.cs deleted file mode 100644 index a008e8e..0000000 --- a/Src/PCLMock_OLD/ArgumentFilters/IsGreaterThanArgumentFilter.cs +++ /dev/null @@ -1,53 +0,0 @@ -namespace PCLMock.ArgumentFilters -{ - using System; - using System.Collections.Generic; - using PCLMock.Utility; - - internal sealed class IsGreaterThanArgumentFilter : IArgumentFilter, IEquatable> - where T : IComparable - { - private readonly T value; - - public IsGreaterThanArgumentFilter(T value) - { - this.value = value; - } - - public bool Matches(object argument) - { - if (argument != null && !(argument is T)) - { - // shouldn't happen - return false; - } - - return Comparer.Default.Compare((T)argument, this.value) > 0; - } - - public override string ToString() - { - return "It.IsGreaterThan(" + this.value.ToDebugString() + ")"; - } - - public bool Equals(IsGreaterThanArgumentFilter other) - { - if (other == null) - { - return false; - } - - return Comparer.Default.Compare(this.value, other.value) == 0; - } - - public override bool Equals(object obj) - { - return this.Equals(obj as IsGreaterThanArgumentFilter); - } - - public override int GetHashCode() - { - throw new NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock_OLD/ArgumentFilters/IsGreaterThanOrEqualToArgumentFilter.cs b/Src/PCLMock_OLD/ArgumentFilters/IsGreaterThanOrEqualToArgumentFilter.cs deleted file mode 100644 index ea6dbac..0000000 --- a/Src/PCLMock_OLD/ArgumentFilters/IsGreaterThanOrEqualToArgumentFilter.cs +++ /dev/null @@ -1,53 +0,0 @@ -namespace PCLMock.ArgumentFilters -{ - using System; - using System.Collections.Generic; - using PCLMock.Utility; - - internal sealed class IsGreaterThanOrEqualToArgumentFilter : IArgumentFilter, IEquatable> - where T : IComparable - { - private readonly T value; - - public IsGreaterThanOrEqualToArgumentFilter(T value) - { - this.value = value; - } - - public bool Matches(object argument) - { - if (argument != null && !(argument is T)) - { - // shouldn't happen - return false; - } - - return Comparer.Default.Compare((T)argument, this.value) >= 0; - } - - public override string ToString() - { - return "It.IsGreaterThanOrEqualTo(" + this.value.ToDebugString() + ")"; - } - - public bool Equals(IsGreaterThanOrEqualToArgumentFilter other) - { - if (other == null) - { - return false; - } - - return Comparer.Default.Compare(this.value, other.value) == 0; - } - - public override bool Equals(object obj) - { - return this.Equals(obj as IsGreaterThanOrEqualToArgumentFilter); - } - - public override int GetHashCode() - { - throw new NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock_OLD/ArgumentFilters/IsInArgumentFilter.cs b/Src/PCLMock_OLD/ArgumentFilters/IsInArgumentFilter.cs deleted file mode 100644 index cd2dbbd..0000000 --- a/Src/PCLMock_OLD/ArgumentFilters/IsInArgumentFilter.cs +++ /dev/null @@ -1,79 +0,0 @@ -namespace PCLMock.ArgumentFilters -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using PCLMock.Utility; - - internal sealed class IsInArgumentFilter : IArgumentFilter, IEquatable> - { - private readonly ISet expected; - - public IsInArgumentFilter(params T[] expected) - { - this.expected = new HashSet(expected ?? new T[0]); - } - - public bool Matches(object argument) - { - if (argument != null && !(argument is T)) - { - // shouldn't happen - return false; - } - - return this.expected.Contains((T)argument); - } - - public override string ToString() - { - var sb = new StringBuilder(); - sb.Append("It.IsIn("); - var first = true; - - this.expected.Aggregate( - sb, - (running, next) => - { - if (!first) - { - sb.Append(", "); - } - - first = false; - sb.Append(next.ToDebugString()); - return sb; - }); - - sb.Append(")"); - - return sb.ToString(); - } - - public bool Equals(IsInArgumentFilter other) - { - if (other == null) - { - return false; - } - - if (this.expected.Count != other.expected.Count) - { - return false; - } - - return this.expected.IsSubsetOf(other.expected); - } - - public override bool Equals(object obj) - { - return this.Equals(obj as IsInArgumentFilter); - } - - public override int GetHashCode() - { - throw new NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock_OLD/ArgumentFilters/IsLikeArgumentFilter.cs b/Src/PCLMock_OLD/ArgumentFilters/IsLikeArgumentFilter.cs deleted file mode 100644 index 7a87b7d..0000000 --- a/Src/PCLMock_OLD/ArgumentFilters/IsLikeArgumentFilter.cs +++ /dev/null @@ -1,56 +0,0 @@ -namespace PCLMock.ArgumentFilters -{ - using System; - using System.Diagnostics; - using System.Text.RegularExpressions; - using PCLMock.Utility; - - internal sealed class IsLikeArgumentFilter : IArgumentFilter, IEquatable - { - private readonly Regex expression; - - public IsLikeArgumentFilter(string pattern, RegexOptions options) - { - Debug.Assert(pattern != null); - this.expression = new Regex(pattern, options); - } - - public bool Matches(object argument) - { - if (argument == null || !(argument is string)) - { - return false; - } - - return this.expression.IsMatch((string)argument); - } - - public override string ToString() - { - return "It.IsLike(" + this.expression.ToString().ToDebugString() + ")"; - } - - public bool Equals(IsLikeArgumentFilter other) - { - if (other == null) - { - return false; - } - - return - this.expression.Options == other.expression.Options && - string.Equals(this.expression.ToString(), other.expression.ToString(), StringComparison.Ordinal); - } - - public override bool Equals(object obj) - { - return this.Equals(obj as IsLikeArgumentFilter); - } - - public override int GetHashCode() - { - throw new NotImplementedException(); - } - } - -} diff --git a/Src/PCLMock_OLD/ArgumentFilters/IsNullArgumentFilter.cs b/Src/PCLMock_OLD/ArgumentFilters/IsNullArgumentFilter.cs deleted file mode 100644 index 2074b79..0000000 --- a/Src/PCLMock_OLD/ArgumentFilters/IsNullArgumentFilter.cs +++ /dev/null @@ -1,44 +0,0 @@ -namespace PCLMock.ArgumentFilters -{ - using System; - using PCLMock.Utility; - - internal sealed class IsNullArgumentFilter : IArgumentFilter, IEquatable> - { - public static readonly IsNullArgumentFilter Instance = new IsNullArgumentFilter(); - - private IsNullArgumentFilter() - { - } - - public bool Matches(object argument) - { - return argument == null; - } - - public override string ToString() - { - return "It.IsNull<" + typeof(T).ToDebugString() + ">()"; - } - - public bool Equals(IsNullArgumentFilter other) - { - if (other == null) - { - return false; - } - - return true; - } - - public override bool Equals(object obj) - { - return this.Equals(obj as IsNullArgumentFilter); - } - - public override int GetHashCode() - { - throw new NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock_OLD/ArgumentFilters/IsOfTypeArgumentFilter.cs b/Src/PCLMock_OLD/ArgumentFilters/IsOfTypeArgumentFilter.cs deleted file mode 100644 index 8238f58..0000000 --- a/Src/PCLMock_OLD/ArgumentFilters/IsOfTypeArgumentFilter.cs +++ /dev/null @@ -1,44 +0,0 @@ -namespace PCLMock.ArgumentFilters -{ - using System; - using PCLMock.Utility; - - internal sealed class IsOfTypeArgumentFilter : IArgumentFilter, IEquatable> - { - public static readonly IsOfTypeArgumentFilter Instance = new IsOfTypeArgumentFilter(); - - private IsOfTypeArgumentFilter() - { - } - - public bool Matches(object argument) - { - return argument is T; - } - - public override string ToString() - { - return "It.IsOfType<" + typeof(T).ToDebugString() + ">()"; - } - - public bool Equals(IsOfTypeArgumentFilter other) - { - if (other == null) - { - return false; - } - - return true; - } - - public override bool Equals(object obj) - { - return this.Equals(obj as IsOfTypeArgumentFilter); - } - - public override int GetHashCode() - { - throw new NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock_OLD/ArgumentFilters/LogicalNotArgumentFilter.cs b/Src/PCLMock_OLD/ArgumentFilters/LogicalNotArgumentFilter.cs deleted file mode 100644 index 56392aa..0000000 --- a/Src/PCLMock_OLD/ArgumentFilters/LogicalNotArgumentFilter.cs +++ /dev/null @@ -1,47 +0,0 @@ -namespace PCLMock.ArgumentFilters -{ - using System; - using System.Diagnostics; - using System.Globalization; - - internal sealed class LogicalNotArgumentFilter : IArgumentFilter, IEquatable - { - private readonly IArgumentFilter child; - - public LogicalNotArgumentFilter(IArgumentFilter child) - { - Debug.Assert(child != null); - this.child = child; - } - - public bool Matches(object argument) - { - return !this.child.Matches(argument); - } - - public override string ToString() - { - return string.Format(CultureInfo.InvariantCulture, "NOT({0})", this.child); - } - - public bool Equals(LogicalNotArgumentFilter other) - { - if (other == null) - { - return false; - } - - return this.child.Equals(other.child); - } - - public override bool Equals(object obj) - { - return this.Equals(obj as LogicalNotArgumentFilter); - } - - public override int GetHashCode() - { - throw new NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock_OLD/ArgumentFilters/MatchesArgumentFilter.cs b/Src/PCLMock_OLD/ArgumentFilters/MatchesArgumentFilter.cs deleted file mode 100644 index 1223ced..0000000 --- a/Src/PCLMock_OLD/ArgumentFilters/MatchesArgumentFilter.cs +++ /dev/null @@ -1,54 +0,0 @@ -namespace PCLMock.ArgumentFilters -{ - using System; - using System.Diagnostics; - using PCLMock.Utility; - - internal sealed class MatchesArgumentFilter : IArgumentFilter, IEquatable> - { - private readonly Func predicate; - - public MatchesArgumentFilter(Func predicate) - { - Debug.Assert(predicate != null); - - this.predicate = predicate; - } - - public bool Matches(object argument) - { - if (argument != null && !(argument is T)) - { - // shouldn't happen - return false; - } - - return this.predicate((T)argument); - } - - public override string ToString() - { - return "It.Matches<" + typeof(T).ToDebugString() + ">()"; - } - - public bool Equals(MatchesArgumentFilter other) - { - if (other == null) - { - return false; - } - - return this.predicate == other.predicate; - } - - public override bool Equals(object obj) - { - return this.Equals(obj as MatchesArgumentFilter); - } - - public override int GetHashCode() - { - throw new NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock_OLD/IArgumentFilter.cs b/Src/PCLMock_OLD/IArgumentFilter.cs deleted file mode 100644 index c893474..0000000 --- a/Src/PCLMock_OLD/IArgumentFilter.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace PCLMock -{ - internal interface IArgumentFilter - { - bool Matches(object argument); - } -} \ No newline at end of file diff --git a/Src/PCLMock_OLD/It.cs b/Src/PCLMock_OLD/It.cs deleted file mode 100644 index 3ea68e4..0000000 --- a/Src/PCLMock_OLD/It.cs +++ /dev/null @@ -1,485 +0,0 @@ -namespace PCLMock -{ - using System; - using System.Text.RegularExpressions; - using PCLMock.ArgumentFilters; - - /// - /// Facilitates the filtering of arguments when interacting with mocks. - /// - /// - /// - /// This class provides a number of methods that can be used to filter arguments in calls to or . - /// Consider the following example: - /// - /// - /// - /// - /// x.SomeMethod("abc", It.IsAny(), It.IsNotNull())) - /// .Return(50); - /// ]]> - /// - /// - /// - /// - /// In this case, the specification will only match if the first argument to SomeMethod is "abc" and the third argument is not . - /// The second argument can be anything. - /// - /// - /// Note that the implementation of all public methods is simply to return a default instance of T. The actual implementation is resolved and applied - /// at run-time. - /// - /// - public static class It - { - /// - /// Specifies that any object of type is valid. - /// - /// - /// The type of object. - /// - /// - /// A default instance of type T. - /// - public static T IsAny() - { - return default(T); - } - - /// - /// Specifies that only values that equate to are to be accepted. - /// - /// - /// The type of the expected value. - /// - /// - /// The expected value. - /// - /// - /// A default instance of type T. - /// - public static T Is(T expected) - { - return default(T); - } - - /// - /// Specifies that only values that do not equate to are to be accepted. - /// - /// - /// The type of the unexpected value. - /// - /// - /// The value that is not expected. - /// - /// - /// A default instance of type T. - /// - public static T IsNot(T notExpected) - { - return default(T); - } - - /// - /// Specifies that only values between and are to be accepted. - /// - /// - /// The type of the value. - /// - /// - /// An inclusive value representing one end of the range of values accepted. - /// - /// - /// An inclusive value representing the other end of the range of values accepted. - /// - /// - /// A default instance of type T. - /// - public static T IsBetween(T first, T second) - where T : IComparable - { - return default(T); - } - - /// - /// Specifies that only values not between and are to be accepted. - /// - /// - /// The type of the value. - /// - /// - /// An inclusive value representing one end of the range of values not accepted. - /// - /// - /// An inclusive value representing the other end of the range of values not accepted. - /// - /// - /// A default instance of type T. - /// - public static T IsNotBetween(T first, T second) - where T : IComparable - { - return default(T); - } - - /// - /// Specifies that only values greater than are to be accepted. - /// - /// - /// The type of the value. - /// - /// - /// The exclusive minimum expected value. - /// - /// - /// A default instance of type T. - /// - public static T IsGreaterThan(T value) - where T : IComparable - { - return default(T); - } - - /// - /// Specifies that only values less than are to be accepted. - /// - /// - /// The type of the value. - /// - /// - /// The exclusive maximum expected value. - /// - /// - /// A default instance of type T. - /// - public static T IsLessThan(T value) - where T : IComparable - { - return default(T); - } - - /// - /// Specifies that only values greater than or equal to are to be accepted. - /// - /// - /// The type of the value. - /// - /// - /// The inclusive minimum expected value. - /// - /// - /// A default instance of type T. - /// - public static T IsGreaterThanOrEqualTo(T value) - where T : IComparable - { - return default(T); - } - - /// - /// Specifies that only values less than or equal to are to be accepted. - /// - /// - /// The type of the value. - /// - /// - /// The inclusive maximum expected value. - /// - /// - /// A default instance of type T. - /// - public static T IsLessThanOrEqualTo(T value) - where T : IComparable - { - return default(T); - } - - /// - /// Specifies that only values that are within are to be accepted. - /// - /// - /// The type of the expected value. - /// - /// - /// The set of expected values. - /// - /// - /// A default instance of type T. - /// - public static T IsIn(params T[] expected) - { - return default(T); - } - - /// - /// Specifies that only values that are like (a regular expression) are to be accepted. - /// - /// - /// The regular expression pattern used to match values. - /// - /// - /// . - /// - public static string IsLike(string pattern) - { - return null; - } - - /// - /// Specifies that only values that are like (a regular expression) are to be accepted. - /// - /// - /// The regular expression pattern used to match values. - /// - /// - /// Optional options for the regular expression used when matching. - /// - /// - /// . - /// - public static string IsLike(string pattern, RegexOptions options = RegexOptions.None) - { - return null; - } - - /// - /// Specifies that only values that are not like (a regular expression) are to be accepted. - /// - /// - /// The regular expression pattern used to match values. - /// - /// - /// . - /// - public static string IsNotLike(string pattern) - { - return null; - } - - /// - /// Specifies that only values that are not like (a regular expression) are to be accepted. - /// - /// - /// The regular expression pattern used to match values. - /// - /// - /// Optional options for the regular expression used when matching. - /// - /// - /// . - /// - public static string IsNotLike(string pattern, RegexOptions options = RegexOptions.None) - { - return null; - } - - /// - /// Specifies that only values are to be accepted. - /// - /// - /// The type of the expected value. - /// - /// - /// A default instance of type T. - /// - public static T IsNull() - where T : class - { - return default(T); - } - - /// - /// Specifies that only non- values are to be accepted. - /// - /// - /// The type of the expected value. - /// - /// - /// A default instance of type T. - /// - public static T IsNotNull() - where T : class - { - return default(T); - } - - /// - /// Specifies that only values of type are to be accepted. - /// - /// - /// The expected type. - /// - /// - /// A default instance of type T. - /// - public static T IsOfType() - { - return default(T); - } - - /// - /// Specifies that only values not of type are to be accepted. - /// - /// - /// The unexpected type. - /// - /// - /// A default instance of type T. - /// - public static T IsNotOfType() - { - return default(T); - } - - /// - /// Specifies that only values for which the given predicate returns are to be accepted. - /// - /// - /// The type of the expected value. - /// - /// - /// The predicate that will be invoked to check the value. - /// - /// - /// A default instance of type T. - /// - public static T Matches(Func predicate) - { - return default(T); - } - - // the internal methods below must: - // 1. have the same name as their public counterpart above, but with a "Filter" suffix - // 2. return an implementation of IArgumentFilter that encapsulates the logic for the filter - - internal static IArgumentFilter IsAnyFilter() - { - return IsAnyArgumentFilter.Instance; - } - - internal static IArgumentFilter IsFilter(T expected) - { - return new IsArgumentFilter(expected); - } - - internal static IArgumentFilter IsNotFilter(T notExpected) - { - return new LogicalNotArgumentFilter(new IsArgumentFilter(notExpected)); - } - - internal static IArgumentFilter IsBetweenFilter(T first, T second) - where T : IComparable - { - return new IsBetweenArgumentFilter(first, second); - } - - internal static IArgumentFilter IsNotBetweenFilter(T first, T second) - where T : IComparable - { - return new LogicalNotArgumentFilter(new IsBetweenArgumentFilter(first, second)); - } - - internal static IArgumentFilter IsGreaterThanFilter(T value) - where T : IComparable - { - return new IsGreaterThanArgumentFilter(value); - } - - internal static IArgumentFilter IsLessThanFilter(T value) - where T : IComparable - { - return new LogicalNotArgumentFilter(new IsGreaterThanOrEqualToArgumentFilter(value)); - } - - internal static IArgumentFilter IsGreaterThanOrEqualToFilter(T value) - where T : IComparable - { - return new IsGreaterThanOrEqualToArgumentFilter(value); - } - - internal static IArgumentFilter IsLessThanOrEqualToFilter(T value) - where T : IComparable - { - return new LogicalNotArgumentFilter(new IsGreaterThanArgumentFilter(value)); - } - - internal static IArgumentFilter IsInFilter(params T[] expected) - { - return new IsInArgumentFilter(expected); - } - - internal static IArgumentFilter IsLikeFilter(string pattern) - { - if (pattern == null) - { - throw new ArgumentNullException("pattern"); - } - - return new IsLikeArgumentFilter(pattern, RegexOptions.None); - } - - internal static IArgumentFilter IsLikeFilter(string pattern, RegexOptions options) - { - if (pattern == null) - { - throw new ArgumentNullException("pattern"); - } - - return new IsLikeArgumentFilter(pattern, options); - } - - internal static IArgumentFilter IsNotLikeFilter(string pattern) - { - if (pattern == null) - { - throw new ArgumentNullException("pattern"); - } - - return new LogicalNotArgumentFilter(new IsLikeArgumentFilter(pattern, RegexOptions.None)); - } - - internal static IArgumentFilter IsNotLikeFilter(string pattern, RegexOptions options) - { - if (pattern == null) - { - throw new ArgumentNullException("pattern"); - } - - return new LogicalNotArgumentFilter(new IsLikeArgumentFilter(pattern, options)); - } - - internal static IArgumentFilter IsNullFilter() - where T : class - { - return IsNullArgumentFilter.Instance; - } - - internal static IArgumentFilter IsNotNullFilter() - where T : class - { - return new LogicalNotArgumentFilter(IsNullArgumentFilter.Instance); - } - - internal static IArgumentFilter IsOfTypeFilter() - { - return IsOfTypeArgumentFilter.Instance; - } - - internal static IArgumentFilter IsNotOfTypeFilter() - { - return new LogicalNotArgumentFilter(IsOfTypeArgumentFilter.Instance); - } - - internal static IArgumentFilter MatchesFilter(Func predicate) - { - if (predicate == null) - { - throw new ArgumentNullException("predicate"); - } - - return new MatchesArgumentFilter(predicate); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock_OLD/MockBase.cs b/Src/PCLMock_OLD/MockBase.cs deleted file mode 100644 index 229d450..0000000 --- a/Src/PCLMock_OLD/MockBase.cs +++ /dev/null @@ -1,451 +0,0 @@ -namespace PCLMock -{ - using System; - using System.Collections.Generic; - using System.Globalization; - using System.Linq.Expressions; - using PCLMock.Utility; - using PCLMock.Visitors; - - /// - /// A base class from which mock objects must be derived. - /// - /// - /// - /// Mock objects should derive from this base class. Typically, you will want to mock an interface. Please see the online documentation for more information. - /// - /// - /// - /// The type being mocked. - /// - public abstract class MockBase - { - private const string mockedObjectErrorTemplate = @"The default implementation of MockBase<{0}> is unable to automatically determine an instance of type {0} to be used as the mocked object. You should override MockedObject in {1} and return the mocked object. -Full mock type name: {2} -Full mocked object type name: {3}"; - - private const string noContinuationErrorTemplate = @"{0} '{1}', for which no specifications have been configured, was invoked on a strict mock. You must either configure specifications via calls to When on the mock, or use a loose mock by passing in MockBehavior.Loose to the mock's constructor."; - - private static readonly object[] emptyArgs = new object[0]; - private static readonly ArgumentFilterCollection emptyArgumentFilters = new ArgumentFilterCollection(); - - private readonly IDictionary continuations; - private readonly object continuationsSync; - private readonly MockBehavior behavior; - - /// - /// Initializes a new instance of the MockBase class. - /// - /// - /// The behavior to be used by this mock. - /// - protected MockBase(MockBehavior behavior) - { - this.continuations = new Dictionary(); - this.continuationsSync = new object(); - this.behavior = behavior; - } - - /// - /// Gets the behavior of this mock. - /// - public MockBehavior Behavior - { - get { return this.behavior; } - } - - /// - /// Gets the mocked object. - /// - /// - /// It is not typically necessary to override this property unless mocking a class. - /// - public virtual TMock MockedObject - { - get - { - object toCast = this; - - if (!(toCast is TMock)) - { - throw new InvalidOperationException( - string.Format( - CultureInfo.InvariantCulture, - mockedObjectErrorTemplate, - typeof(TMock).Name, - this.GetType().Name, - this.GetType().FullName, - typeof(TMock).FullName)); - } - - return (TMock)toCast; - } - } - - /// - /// Begins the specification of what the mock should do when a given member is accessed. - /// - /// - /// An expression that resolves to the member. - /// - /// - /// A continuation object with which the actions to be performed can be configured. - /// - public WhenContinuation When(Expression> selector) - { - if (selector == null) - { - throw new ArgumentNullException("selector"); - } - - var continuation = new WhenContinuation(selector, ArgumentFiltersVisitor.FindArgumentFiltersWithin(selector.Body) ?? emptyArgumentFilters); - this.AddOrReplaceWhenContinuation(selector, continuation); - return continuation; - } - - /// - /// Begins the specification of what the mock should do when a given member is accessed. - /// - /// - /// An expression that resolves to the member. - /// - /// - /// A continuation object with which the actions to be performed can be configured. - /// - public WhenContinuation When(Expression> selector) - { - if (selector == null) - { - throw new ArgumentNullException("selector"); - } - - var continuation = new WhenContinuation(selector, ArgumentFiltersVisitor.FindArgumentFiltersWithin(selector.Body) ?? emptyArgumentFilters); - this.AddOrReplaceWhenContinuation(selector, continuation); - return continuation; - } - - /// - /// Begins the specification of what the mock should do when a given property is set. - /// - /// - /// The type of the property. - /// - /// - /// An expression that resolves the property. - /// - /// - /// An optional expression that can provide filtering against the property value being set. - /// - /// - /// A continuation object with which the actions to be performed can be configured. - /// - public WhenContinuation WhenPropertySet(Expression> propertySelector, Expression> valueFilterSelector = null) - { - if (propertySelector == null) - { - throw new ArgumentNullException("propertySelector"); - } - - if (valueFilterSelector == null) - { - valueFilterSelector = () => It.IsAny(); - } - - var filters = new ArgumentFilterCollection(); - filters.Add(ArgumentFilterVisitor.FindArgumentFilterWithin(valueFilterSelector.Body)); - var continuation = new WhenContinuation(propertySelector, filters); - this.AddOrReplaceWhenContinuation(propertySelector, continuation); - return continuation; - } - - /// - /// Begins a verification specification. - /// - /// - /// An expression that resolves to the member being verified. - /// - /// - /// A continuation object with which the verification can be specified. - /// - public VerifyContinuation Verify(Expression> selector) - { - if (selector == null) - { - throw new ArgumentNullException("selector"); - } - - var whenContinuationCollection = this.EnsureWhenContinuationCollection(selector); - return new VerifyContinuation(selector, whenContinuationCollection, ArgumentFiltersVisitor.FindArgumentFiltersWithin(selector.Body) ?? emptyArgumentFilters); - } - - /// - /// Begins a verification specification. - /// - /// - /// - /// An expression that resolves to the member being verified. - /// - /// - /// A continuation object with which the verification can be specified. - /// - public VerifyContinuation Verify(Expression> selector) - { - if (selector == null) - { - throw new ArgumentNullException("selector"); - } - - var whenContinuationCollection = this.EnsureWhenContinuationCollection(selector); - return new VerifyContinuation(selector, whenContinuationCollection, ArgumentFiltersVisitor.FindArgumentFiltersWithin(selector.Body) ?? emptyArgumentFilters); - } - - /// - /// Begins a verification specification for a property set. - /// - /// - /// The type of the property. - /// - /// - /// An expression that resolves to the property being verified. - /// - /// - /// An optional expression that can provide filtering against the property value being set. - /// - /// - /// A continuation object with which the verification can be specified. - /// - public VerifyContinuation VerifyPropertySet(Expression> propertySelector, Expression> valueFilterSelector = null) - { - if (propertySelector == null) - { - throw new ArgumentNullException("propertySelector"); - } - - if (valueFilterSelector == null) - { - valueFilterSelector = () => It.IsAny(); - } - - var whenContinuationCollection = this.EnsureWhenContinuationCollection(propertySelector); - var filters = new ArgumentFilterCollection(); - filters.Add(ArgumentFilterVisitor.FindArgumentFilterWithin(valueFilterSelector.Body)); - return new VerifyContinuation(propertySelector, whenContinuationCollection, filters); - } - - /// - /// Applies any specifications configured via for a given member. - /// - /// - /// An expression that resolves to the member. - /// - protected void Apply(Expression> selector) - { - var args = ArgumentsVisitor.FindArgumentsWithin(selector.Body) ?? emptyArgs; - WhenContinuationCollection whenContinuationCollection; - var continuation = this.GetWhenContinuation(selector, args, out whenContinuationCollection); - whenContinuationCollection.AddInvocation(new Invocation(args)); - - if (continuation == null) - { - return; - } - - continuation.Apply(this.MockedObject, args); - } - - /// - /// Applies any specifications configured via for a given member. - /// - /// - /// An expression that resolves to the member. - /// - protected TMember Apply(Expression> selector) - { - var args = ArgumentsVisitor.FindArgumentsWithin(selector.Body) ?? emptyArgs; - WhenContinuationCollection whenContinuationCollection; - var continuation = this.GetWhenContinuation(selector, args, out whenContinuationCollection); - whenContinuationCollection.AddInvocation(new Invocation(args)); - - if (continuation == null) - { - return default(TMember); - } - - return (TMember)continuation.Apply(this.MockedObject, args); - } - - /// - /// Applies any specifications configured via for a given property setter. - /// - /// - /// An expression that resolves to the property being set. - /// - /// - /// The value being assigned to the property. - /// - protected void ApplyPropertySet(Expression> selector, object value) - { - // base arguments would be any indexers to the property - var indexerArgs = ArgumentsVisitor.FindArgumentsWithin(selector.Body) ?? emptyArgs; - var args = new object[indexerArgs.Length + 1]; - Array.Copy(indexerArgs, args, indexerArgs.Length); - args[args.Length - 1] = value; - - WhenContinuationCollection whenContinuationCollection; - var continuation = this.GetWhenContinuation(selector, args, out whenContinuationCollection); - whenContinuationCollection.AddInvocation(new Invocation(args)); - - if (continuation == null) - { - return; - } - - continuation.Apply(this.MockedObject, args); - } - - /// - /// Gets the value for an out parameter for a given method at a given parameter index. - /// - /// - /// The type of the out parameter. - /// - /// - /// An expression that resolves to the method. - /// - /// - /// The zero-based index of the parameter. - /// - /// - /// The value assigned to that out parameter. - /// - protected T GetOutParameterValue(Expression> selector, int parameterIndex) - { - var continuation = this.GetWhenContinuation(selector, null); - - if (continuation == null) - { - return default(T); - } - - return continuation.GetOutParameterValue(parameterIndex); - } - - /// - /// Gets the value for a ref parameter for a given method at a given parameter index. - /// - /// - /// The type of the ref parameter. - /// - /// - /// An expression that resolves to the method. - /// - /// - /// The zero-based index of the parameter. - /// - /// - /// An optional default value for the ref parameter, which defaults to the default value of type . - /// - /// - /// The value assigned to that ref parameter. - /// - protected T GetRefParameterValue(Expression> selector, int parameterIndex, T defaultValue = default(T)) - { - var continuation = this.GetWhenContinuation(selector, null); - - if (continuation == null) - { - return default(T); - } - - return continuation.GetRefParameterValue(parameterIndex, defaultValue); - } - - private static ContinuationKey GetContinuationKey(LambdaExpression selector) - { - var methodCallExpression = selector.Body as MethodCallExpression; - - if (methodCallExpression != null) - { - if (methodCallExpression.Object == null) - { - throw new InvalidOperationException("Specifications against extension methods cannot be provided: " + methodCallExpression); - } - - if (methodCallExpression.Object.NodeType != ExpressionType.Parameter) - { - throw new InvalidOperationException("Specifications against methods cannot be chained: " + methodCallExpression); - } - - return new ContinuationKey(methodCallExpression.Method); - } - - var memberExpression = selector.Body as MemberExpression; - - if (memberExpression != null) - { - if (memberExpression.Expression.NodeType != ExpressionType.Parameter) - { - throw new InvalidOperationException("Specifications against properties cannot be chained: " + memberExpression); - } - - return new ContinuationKey(memberExpression.Member); - } - - throw new InvalidOperationException("Unable to determine the details of the member being mocked."); - } - - private WhenContinuationCollection EnsureWhenContinuationCollection(LambdaExpression memberSelector) - { - var continuationKey = GetContinuationKey(memberSelector); - - lock (this.continuationsSync) - { - WhenContinuationCollection result; - - if (!this.continuations.TryGetValue(continuationKey, out result)) - { - result = new WhenContinuationCollection(); - this.continuations[continuationKey] = result; - } - - return result; - } - } - - private void AddOrReplaceWhenContinuation(LambdaExpression memberSelector, WhenContinuation continuation) - { - lock (this.continuationsSync) - { - var whenContinuationCollection = this.EnsureWhenContinuationCollection(memberSelector); - - // first remove any existing filtered continuation that matches the one we're trying to add to avoid memory leaks - whenContinuationCollection.Remove(continuation); - whenContinuationCollection.Add(continuation); - } - } - - private WhenContinuation GetWhenContinuation(LambdaExpression memberSelector, object[] args) - { - WhenContinuationCollection whenContinuationCollection; - return this.GetWhenContinuation(memberSelector, args, out whenContinuationCollection); - } - - private WhenContinuation GetWhenContinuation(LambdaExpression memberSelector, object[] args, out WhenContinuationCollection whenContinuationCollection) - { - var continuationKey = GetContinuationKey(memberSelector); - - lock (this.continuationsSync) - { - whenContinuationCollection = this.EnsureWhenContinuationCollection(memberSelector); - var whenContinuation = whenContinuationCollection.FindWhenContinuation(args); - - if (whenContinuation == null && this.behavior == MockBehavior.Strict) - { - throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, noContinuationErrorTemplate, continuationKey.Type, continuationKey.MemberInfo.Name)); - } - - return whenContinuation; - } - } - } -} \ No newline at end of file diff --git a/Src/PCLMock_OLD/MockBehavior.cs b/Src/PCLMock_OLD/MockBehavior.cs deleted file mode 100644 index 5e7ce30..0000000 --- a/Src/PCLMock_OLD/MockBehavior.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace PCLMock -{ - /// - /// Defines possible mock behaviors. - /// - public enum MockBehavior - { - - /// - /// Any invocation against the mock must have a specification (configured via ). If a member of the mock - /// is invoked and it does not have a specification, an exception is thrown. - /// - Strict, - - /// - /// Invocations against the mock are not required to have specifications. If a member of the mock is invoked and it does not have a specification - /// and that member needs to return a value, the default value for the member's type is returned. - /// - Loose - } -} \ No newline at end of file diff --git a/Src/PCLMock_OLD/PCLMock.csproj b/Src/PCLMock_OLD/PCLMock.csproj deleted file mode 100644 index 3216692..0000000 --- a/Src/PCLMock_OLD/PCLMock.csproj +++ /dev/null @@ -1,85 +0,0 @@ - - - - - 10.0 - Debug - AnyCPU - {A02C0394-4DAD-4422-97BB-4A90D89CEE66} - Library - Properties - PCLMock - PCLMock - v4.0 - Profile336 - 512 - {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - bin\Debug\PCLMock.xml - true - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - bin\Release\PCLMock.xml - true - - - - - - - - - - - - - - - - Properties\AssemblyInfoCommon.cs - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Src/PCLMock_OLD/PCLMock.v3.ncrunchproject b/Src/PCLMock_OLD/PCLMock.v3.ncrunchproject deleted file mode 100644 index ab5b48b..0000000 --- a/Src/PCLMock_OLD/PCLMock.v3.ncrunchproject +++ /dev/null @@ -1,11 +0,0 @@ - - - Disabled - Disabled - Disabled - Disabled - Disabled - False - True - - \ No newline at end of file diff --git a/Src/PCLMock_OLD/Properties/AssemblyInfo.cs b/Src/PCLMock_OLD/Properties/AssemblyInfo.cs deleted file mode 100644 index 208bb83..0000000 --- a/Src/PCLMock_OLD/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System; -using System.Reflection; -using System.Runtime.CompilerServices; - -[assembly: AssemblyTitle("PCLMock")] -[assembly: AssemblyDescription("Contains the implementation of PCLMock.")] -[assembly: InternalsVisibleTo("PCLMock.UnitTests")] -[assembly: CLSCompliantAttribute(true)] \ No newline at end of file diff --git a/Src/PCLMock_OLD/Utility/ArgumentFilterCollection.cs b/Src/PCLMock_OLD/Utility/ArgumentFilterCollection.cs deleted file mode 100644 index 608a1de..0000000 --- a/Src/PCLMock_OLD/Utility/ArgumentFilterCollection.cs +++ /dev/null @@ -1,85 +0,0 @@ -namespace PCLMock.Utility -{ - using System; - using System.Collections.Generic; - using System.Collections.ObjectModel; - using System.Diagnostics; - using System.Linq; - - // a collection of IArgumentFilter objects - internal sealed class ArgumentFilterCollection : Collection, IEquatable - { - public ArgumentFilterCollection() - { - } - - public ArgumentFilterCollection(IEnumerable filters) - : base(filters.ToList()) - { - } - - public bool Matches(object[] args) - { - Debug.Assert(args != null); - - if (args.Length != this.Count) - { - return false; - } - - for (var i = 0; i < args.Length; ++i) - { - var filter = this[i]; - - if (filter == null) - { - continue; - } - - if (!filter.Matches(args[i])) - { - return false; - } - } - - return true; - } - - public bool Equals(ArgumentFilterCollection other) - { - if (other == null) - { - return false; - } - - if (this.Count != other.Count) - { - return false; - } - - for (var i = 0; i < this.Count; ++i) - { - Debug.Assert(this[i] != null); - Debug.Assert(other[i] != null); - - // filters implement equality semantics, so this is totally OK - if (!this[i].Equals(other[i])) - { - return false; - } - } - - return true; - } - - public override bool Equals(object obj) - { - return this.Equals(obj as ArgumentFilterCollection); - } - - public override int GetHashCode() - { - throw new NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock_OLD/Utility/ContinuationKey.cs b/Src/PCLMock_OLD/Utility/ContinuationKey.cs deleted file mode 100644 index e9dd877..0000000 --- a/Src/PCLMock_OLD/Utility/ContinuationKey.cs +++ /dev/null @@ -1,51 +0,0 @@ -namespace PCLMock.Utility -{ - using System; - using System.Diagnostics; - using System.Reflection; - - internal struct ContinuationKey : IEquatable - { - private readonly MemberInfo memberInfo; - - public ContinuationKey(MemberInfo memberInfo) - { - Debug.Assert(memberInfo is MethodInfo || memberInfo is PropertyInfo); - this.memberInfo = memberInfo; - } - - public ContinuationKeyType Type - { - get { return this.memberInfo is MethodInfo ? ContinuationKeyType.Method : ContinuationKeyType.Property; } - } - - public MemberInfo MemberInfo - { - get { return this.memberInfo; } - } - - public bool Equals(ContinuationKey other) - { - Debug.Assert(this.memberInfo != null); - Debug.Assert(other.memberInfo != null); - - return other.memberInfo.Equals(this.memberInfo); - } - - public override bool Equals(object obj) - { - if (!(obj is ContinuationKey)) - { - return false; - } - - return this.Equals((ContinuationKey)obj); - } - - public override int GetHashCode() - { - Debug.Assert(this.memberInfo != null); - return this.memberInfo.GetHashCode(); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock_OLD/Utility/ContinuationKeyType.cs b/Src/PCLMock_OLD/Utility/ContinuationKeyType.cs deleted file mode 100644 index 25be581..0000000 --- a/Src/PCLMock_OLD/Utility/ContinuationKeyType.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace PCLMock.Utility -{ - internal enum ContinuationKeyType - { - Method, - Property - } -} \ No newline at end of file diff --git a/Src/PCLMock_OLD/Utility/Invocation.cs b/Src/PCLMock_OLD/Utility/Invocation.cs deleted file mode 100644 index 881813e..0000000 --- a/Src/PCLMock_OLD/Utility/Invocation.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace PCLMock.Utility -{ - // records details about an invocation - internal struct Invocation - { - private readonly object[] arguments; - - public Invocation(object[] arguments) - { - this.arguments = arguments; - } - - public object[] Arguments - { - get { return this.arguments; } - } - } -} \ No newline at end of file diff --git a/Src/PCLMock_OLD/Utility/ObjectExtensions.cs b/Src/PCLMock_OLD/Utility/ObjectExtensions.cs deleted file mode 100644 index 8b4a381..0000000 --- a/Src/PCLMock_OLD/Utility/ObjectExtensions.cs +++ /dev/null @@ -1,142 +0,0 @@ -namespace PCLMock.Utility -{ - using System; - using System.Collections.Generic; - using System.Globalization; - using System.Linq; - using System.Reflection; - using System.Text; - - internal static class ToDebugStringExtensions - { - private static readonly IDictionary typeToNameMappings = new Dictionary - { - { typeof(bool), "bool" }, - { typeof(byte), "byte" }, - { typeof(sbyte), "sbyte" }, - { typeof(char), "char" }, - { typeof(decimal), "decimal" }, - { typeof(double), "double" }, - { typeof(float), "float" }, - { typeof(int), "int" }, - { typeof(uint), "uint" }, - { typeof(long), "long" }, - { typeof(ulong), "ulong" }, - { typeof(object), "object" }, - { typeof(short), "short" }, - { typeof(ushort), "ushort" }, - { typeof(string), "string" } - }; - - public static string ToDebugString(this Type @this) - { - if (@this == null) - { - throw new ArgumentNullException("@this"); - } - - string result; - - if (typeToNameMappings.TryGetValue(@this, out result)) - { - return result; - } - - var underlyingNullableType = Nullable.GetUnderlyingType(@this); - - if (underlyingNullableType != null) - { - return underlyingNullableType.ToDebugString() + "?"; - } - - return @this.FullName; - } - - public static string ToDebugString(this object @this) - { - if (@this == null) - { - return "null"; - } - - if (@this is Type) - { - return ((Type)@this).ToDebugString(); - } - - if (@this is string) - { - return "\"" + @this + "\""; - } - - if (@this is bool) - { - return @this.ToString().ToLowerInvariant(); - } - - if (@this is int) - { - return @this.ToString(); - } - - if (@this is uint) - { - return @this.ToString() + "U"; - } - - if (@this is long) - { - return @this.ToString() + "L"; - } - - if (@this is ulong) - { - return @this.ToString() + "UL"; - } - - if (@this is float) - { - return ((float)@this).ToString(CultureInfo.InvariantCulture) + "F"; - } - - if (@this is double) - { - return ((double)@this).ToString(CultureInfo.InvariantCulture) + "D"; - } - - if (@this is decimal) - { - return ((decimal)@this).ToString(CultureInfo.InvariantCulture) + "M"; - } - - if (@this is Enum) - { - var @enum = (Enum)@this; - var isFlags = @this.GetType().GetTypeInfo().GetCustomAttributes(typeof(FlagsAttribute), false).Any(); - var result = new StringBuilder(); - - if (isFlags) - { - foreach (Enum value in Enum.GetValues(@this.GetType())) - { - if (@enum.HasFlag(value)) - { - if (result.Length != 0) - { - result.Append(" | "); - } - - result.Append(@this.GetType().Name).Append(".").Append(value); - } - } - - return result.ToString(); - } - - return @this.GetType().Name + "." + @this; - } - - return @this.ToString() + " [" + @this.GetType().ToDebugString() + "]"; - } - } -} \ No newline at end of file diff --git a/Src/PCLMock_OLD/Utility/WhenContinuationCollection.cs b/Src/PCLMock_OLD/Utility/WhenContinuationCollection.cs deleted file mode 100644 index 77a0b85..0000000 --- a/Src/PCLMock_OLD/Utility/WhenContinuationCollection.cs +++ /dev/null @@ -1,47 +0,0 @@ -namespace PCLMock.Utility -{ - using System.Collections.Generic; - using System.Collections.ObjectModel; - - // a collection of WhenContinuation objects and a record of all invocations therein - internal sealed class WhenContinuationCollection : Collection - { - private readonly List invocations; - private readonly object sync; - - public WhenContinuationCollection() - { - this.invocations = new List(); - this.sync = new object(); - } - - public IEnumerable Invocations - { - get { return this.invocations; } - } - - public void AddInvocation(Invocation invocation) - { - lock (this.sync) - { - this.invocations.Add(invocation); - } - } - - public WhenContinuation FindWhenContinuation(object[] args) - { - // we loop backwards so that more recently registered continuations take a higher precedence - for (var i = this.Count - 1; i >= 0; --i) - { - var continuation = this[i]; - - if (args == null || continuation.Filters == null || continuation.Filters.Matches(args)) - { - return continuation; - } - } - - return null; - } - } -} \ No newline at end of file diff --git a/Src/PCLMock_OLD/VerificationException.cs b/Src/PCLMock_OLD/VerificationException.cs deleted file mode 100644 index 79d175c..0000000 --- a/Src/PCLMock_OLD/VerificationException.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace PCLMock -{ - using System; - - /// - /// The exception type used to indicate a verification failure. - /// - public sealed class VerificationException : Exception - { - /// - public VerificationException() - { - } - - /// - public VerificationException(string message) - : base(message) - { - } - - /// - public VerificationException(string message, Exception innerException) - : base(message, innerException) - { - } - } -} \ No newline at end of file diff --git a/Src/PCLMock_OLD/VerifyContinuation.cs b/Src/PCLMock_OLD/VerifyContinuation.cs deleted file mode 100644 index d0c5e10..0000000 --- a/Src/PCLMock_OLD/VerifyContinuation.cs +++ /dev/null @@ -1,182 +0,0 @@ -namespace PCLMock -{ - using System.Collections.Generic; - using System.Diagnostics; - using System.Globalization; - using System.Linq; - using System.Linq.Expressions; - using PCLMock.Utility; - using PCLMock.Visitors; - - /// - /// Facilitates the expression of verifications against a member in a . - /// - public sealed class VerifyContinuation - { - private readonly Expression selector; - private readonly WhenContinuationCollection whenContinuationCollection; - private readonly ArgumentFilterCollection filters; - - internal VerifyContinuation(Expression selector, WhenContinuationCollection whenContinuationCollection, ArgumentFilterCollection filters) - { - Debug.Assert(selector != null); - Debug.Assert(whenContinuationCollection != null); - Debug.Assert(filters != null); - - this.selector = selector; - this.whenContinuationCollection = whenContinuationCollection; - this.filters = filters; - } - - /// - /// Verifies that the member was not called. - /// - public void WasNotCalled() - { - var invocations = this.GetMatchingInvocations(); - - if (invocations.Count > 0) - { - ThrowVerificationException( - "Verification that {0} was not called failed because it was called {1} time{2}.", - this.GetSelectorString(), - invocations.Count, - invocations.Count == 1 ? string.Empty : "s"); - } - } - - /// - /// Verifies that the member was called exactly one time. - /// - public void WasCalledExactlyOnce() - { - var invocations = this.GetMatchingInvocations(); - - if (invocations.Count != 1) - { - ThrowVerificationException( - "Verification that {0} was called exactly once failed because it was called {1} time{2}.", - this.GetSelectorString(), - invocations.Count, - invocations.Count == 1 ? string.Empty : "s"); - } - } - - /// - /// Verifies that the member was called one or more times. - /// - public void WasCalledAtLeastOnce() - { - var invocations = this.GetMatchingInvocations(); - - if (invocations.Count == 0) - { - ThrowVerificationException( - "Verification that {0} was called at least once failed because it was called 0 times.", - this.GetSelectorString()); - } - } - - /// - /// Verifies that the member was either not called, or only called once. - /// - public void WasCalledAtMostOnce() - { - var invocations = this.GetMatchingInvocations(); - - if (invocations.Count > 1) - { - ThrowVerificationException( - "Verification that {0} was called at most once failed because it was called {1} times.", - this.GetSelectorString(), - invocations.Count); - } - } - - /// - /// Verifies that the member was called exactly time. - /// - /// - /// The number of times the member must have been called. - /// - public void WasCalledExactly(int times) - { - var invocations = this.GetMatchingInvocations(); - - if (invocations.Count != times) - { - ThrowVerificationException( - "Verification that {0} was called exactly {1} time{2} failed because it was called {3} time{4}.", - this.GetSelectorString(), - times, - times == 1 ? string.Empty : "s", - invocations.Count, - invocations.Count == 1 ? string.Empty : "s"); - } - } - - /// - /// Verifies that the member was called or more times. - /// - /// - /// The minimum number of times the member must have been called. - /// - public void WasCalledAtLeast(int times) - { - var invocations = this.GetMatchingInvocations(); - - if (invocations.Count < times) - { - ThrowVerificationException( - "Verification that {0} was called at least {1} time{2} failed because it was called {3} time{4}.", - this.GetSelectorString(), - times, - times == 1 ? string.Empty : "s", - invocations.Count, - invocations.Count == 1 ? string.Empty : "s"); - } - } - - /// - /// Verifies that the member called or fewer times. - /// - /// - /// The maximum number of times the member must have been called. - /// - public void WasCalledAtMost(int times) - { - var invocations = this.GetMatchingInvocations(); - - if (invocations.Count > times) - { - ThrowVerificationException( - "Verification that {0} was called at most {1} time{2} failed because it was called {3} time{4}.", - this.GetSelectorString(), - times, - times == 1 ? string.Empty : "s", - invocations.Count, - invocations.Count == 1 ? string.Empty : "s"); - } - } - - private static void ThrowVerificationException(string format, params object[] args) - { - throw new VerificationException(string.Format(CultureInfo.InvariantCulture, format, args)); - } - - private string GetSelectorString() - { - var visitor = new SelectorStringVisitor(); - visitor.Visit(this.selector); - return visitor.ToString(); - } - - private IList GetMatchingInvocations() - { - return this - .whenContinuationCollection.Invocations - .Where(x => this.filters.Matches(x.Arguments)) - .ToList(); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock_OLD/Visitors/ArgumentFilterVisitor.cs b/Src/PCLMock_OLD/Visitors/ArgumentFilterVisitor.cs deleted file mode 100644 index 8268f9e..0000000 --- a/Src/PCLMock_OLD/Visitors/ArgumentFilterVisitor.cs +++ /dev/null @@ -1,98 +0,0 @@ -namespace PCLMock.Visitors -{ - using System.Diagnostics; - using System.Linq; - using System.Linq.Expressions; - using System.Reflection; - using PCLMock.ArgumentFilters; - - // find a single argument filter at the root of the given expression - internal sealed class ArgumentFilterVisitor : ExpressionVisitor - { - private IArgumentFilter argumentFilter; - - private ArgumentFilterVisitor() - { - } - - public static bool TryFindArgumentFilterWithin(Expression expression, out IArgumentFilter argumentFilter) - { - Debug.Assert(expression != null); - - var visitor = new ArgumentFilterVisitor(); - visitor.Visit(expression); - argumentFilter = visitor.argumentFilter; - return argumentFilter != null; - } - - public static IArgumentFilter FindArgumentFilterWithin(Expression expression) - { - IArgumentFilter argumentFilter; - - if (!TryFindArgumentFilterWithin(expression, out argumentFilter)) - { - return null; - } - - return argumentFilter; - } - - protected override Expression VisitMethodCall(MethodCallExpression node) - { - var filterMethod = node - .Method - .DeclaringType - .GetTypeInfo() - .DeclaredMethods - .Where(declaredMethod => declaredMethod.IsStatic && declaredMethod.IsPublic) - .Where(x => x.Name == node.Method.Name + "Filter" && x.GetParameters().Length == node.Arguments.Count) - .FirstOrDefault(); - - if (filterMethod != null && filterMethod.ReturnType == typeof(IArgumentFilter)) - { - if (node.Method.IsGenericMethod) - { - filterMethod = filterMethod.MakeGenericMethod(node.Method.GetGenericArguments()); - } - - var argumentsToFilterMethod = new object[node.Arguments.Count]; - - for (var i = 0; i < argumentsToFilterMethod.Length; ++i) - { - argumentsToFilterMethod[i] = ValueExtractor.FindValueWithin(node.Arguments[i]); - } - - this.argumentFilter = filterMethod.Invoke(null, argumentsToFilterMethod) as IArgumentFilter; - } - else - { - object value; - - if (ValueExtractor.TryFindValueWithin(node, out value)) - { - this.argumentFilter = new IsArgumentFilter(value); - } - } - - return node; - } - - public override Expression Visit(Expression node) - { - if (node.NodeType == ExpressionType.Convert || node.NodeType == ExpressionType.Call) - { - return base.Visit(node); - } - - object value; - - if (ValueExtractor.TryFindValueWithin(node, out value)) - { - this.argumentFilter = new IsArgumentFilter(value); - return node; - } - - return node; - } - } -} \ No newline at end of file diff --git a/Src/PCLMock_OLD/Visitors/ArgumentFiltersVisitor.cs b/Src/PCLMock_OLD/Visitors/ArgumentFiltersVisitor.cs deleted file mode 100644 index a72a3ae..0000000 --- a/Src/PCLMock_OLD/Visitors/ArgumentFiltersVisitor.cs +++ /dev/null @@ -1,71 +0,0 @@ -namespace PCLMock.Visitors -{ - using System; - using System.Diagnostics; - using System.Linq; - using System.Linq.Expressions; - using PCLMock.ArgumentFilters; - using PCLMock.Utility; - - // find a set of argument filters for a method call - internal sealed class ArgumentFiltersVisitor : ExpressionVisitor - { - private ArgumentFilterCollection argumentFilters; - - private ArgumentFiltersVisitor() - { - } - - public static bool TryFindArgumentFiltersWithin(Expression expression, out ArgumentFilterCollection argumentFilters) - { - Debug.Assert(expression != null); - - var visitor = new ArgumentFiltersVisitor(); - - try - { - visitor.Visit(expression); - argumentFilters = visitor.argumentFilters; - return argumentFilters != null && argumentFilters.All(x => x != null); - } - catch (Exception) - { - } - - argumentFilters = null; - return false; - } - - public static ArgumentFilterCollection FindArgumentFiltersWithin(Expression expression) - { - ArgumentFilterCollection argumentFilters; - - if (!TryFindArgumentFiltersWithin(expression, out argumentFilters)) - { - return null; - } - - return argumentFilters; - } - - protected override Expression VisitMethodCall(MethodCallExpression node) - { - this.argumentFilters = new ArgumentFilterCollection(); - var methodParameters = node.Method.GetParameters(); - - for (var i = 0; i < methodParameters.Length; ++i) - { - if (methodParameters[i].ParameterType.IsByRef || methodParameters[i].IsOut) - { - this.argumentFilters.Add(IsAnyArgumentFilter.Instance); - } - else - { - this.argumentFilters.Add(ArgumentFilterVisitor.FindArgumentFilterWithin(node.Arguments[i])); - } - } - - return Expression.Constant(this.argumentFilters); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock_OLD/Visitors/ArgumentsVisitor.cs b/Src/PCLMock_OLD/Visitors/ArgumentsVisitor.cs deleted file mode 100644 index dbed8e4..0000000 --- a/Src/PCLMock_OLD/Visitors/ArgumentsVisitor.cs +++ /dev/null @@ -1,59 +0,0 @@ -namespace PCLMock.Visitors -{ - using System; - using System.Diagnostics; - using System.Linq; - using System.Linq.Expressions; - - // finds the values of all arguments in a method invocation expression - internal sealed class ArgumentsVisitor : ExpressionVisitor - { - private object[] arguments; - - private ArgumentsVisitor() - { - } - - public static bool TryFindArgumentsWithin(Expression expression, out object[] arguments) - { - Debug.Assert(expression != null); - - var visitor = new ArgumentsVisitor(); - - try - { - visitor.Visit(expression); - arguments = visitor.arguments; - - return arguments != null; - } - catch (Exception) - { - } - - arguments = null; - return false; - } - - public static object[] FindArgumentsWithin(Expression expression) - { - object[] arguments; - - if (!TryFindArgumentsWithin(expression, out arguments)) - { - return null; - } - - return arguments; - } - - protected override Expression VisitMethodCall(MethodCallExpression node) - { - this.arguments = node.Arguments - .Select(x => ValueExtractor.FindValueWithin(x)) - .ToArray(); - - return Expression.Constant(this.arguments); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock_OLD/Visitors/SelectorStringVisitor.cs b/Src/PCLMock_OLD/Visitors/SelectorStringVisitor.cs deleted file mode 100644 index 49f765e..0000000 --- a/Src/PCLMock_OLD/Visitors/SelectorStringVisitor.cs +++ /dev/null @@ -1,52 +0,0 @@ -namespace PCLMock.Visitors -{ - using System.Linq.Expressions; - using System.Text; - using PCLMock.Utility; - - // converts the given expression into a string that can be used for debugging purposes - internal sealed class SelectorStringVisitor : ExpressionVisitor - { - private readonly StringBuilder stringBuilder; - - public SelectorStringVisitor() - { - this.stringBuilder = new StringBuilder(); - } - - protected override Expression VisitMember(MemberExpression node) - { - this.stringBuilder.Append(node.Member.Name); - return base.VisitMember(node); - } - - protected override Expression VisitMethodCall(MethodCallExpression node) - { - this.stringBuilder.Append(node.Method.Name).Append("("); - - ArgumentFilterCollection argumentFilters; - - if (ArgumentFiltersVisitor.TryFindArgumentFiltersWithin(node, out argumentFilters)) - { - for (var i = 0; i < argumentFilters.Count; ++i) - { - if (i > 0) - { - this.stringBuilder.Append(", "); - } - - this.stringBuilder.Append(argumentFilters[i].ToString()); - } - } - - this.stringBuilder.Append(")"); - - return node; - } - - public override string ToString() - { - return this.stringBuilder.ToString(); - } - } -} \ No newline at end of file diff --git a/Src/PCLMock_OLD/Visitors/ValueExtractor.cs b/Src/PCLMock_OLD/Visitors/ValueExtractor.cs deleted file mode 100644 index c8f84aa..0000000 --- a/Src/PCLMock_OLD/Visitors/ValueExtractor.cs +++ /dev/null @@ -1,62 +0,0 @@ -namespace PCLMock.Visitors -{ - using System; - using System.Diagnostics; - using System.Linq.Expressions; - - // extracts values from an expression - // - // examples: - // null extracts null - // "foo" extracts "foo" - // foo extracts the value of local variable foo - // new [] { 1, 2, 3 } extracts int[] { 1, 2, 3 } - // int.MinValue extracts minimum int value - // DateTime.MaxValue extracts the maximum DateTime value - // new DateTime(...) extracts the specified DateTime value - // DateTime.FromSeconds(1) extracts the specified DateTime value - // i => i % 2 == 0 extracts the lambda i => i % 2 == 0 - internal static class ValueExtractor - { - public static bool TryFindValueWithin(Expression expression, out object value) - { - Debug.Assert(expression != null); - - var methodCallExpression = expression as MethodCallExpression; - - if (methodCallExpression != null && methodCallExpression.Method.ReturnType == typeof(void)) - { - value = null; - return false; - } - - try - { - value = Expression - .Lambda(expression) - .Compile() - .DynamicInvoke(); - - return true; - } - catch (Exception) - { - } - - value = null; - return false; - } - - public static object FindValueWithin(Expression expression) - { - object value; - - if (!TryFindValueWithin(expression, out value)) - { - return null; - } - - return value; - } - } -} \ No newline at end of file diff --git a/Src/PCLMock_OLD/WhenContinuation.cs b/Src/PCLMock_OLD/WhenContinuation.cs deleted file mode 100644 index ce2f32b..0000000 --- a/Src/PCLMock_OLD/WhenContinuation.cs +++ /dev/null @@ -1,535 +0,0 @@ -namespace PCLMock -{ - using System; - using System.Collections.Generic; - using System.Diagnostics; - using System.Globalization; - using System.Linq; - using System.Linq.Expressions; - using System.Reflection; - using System.Text; - using PCLMock.Utility; - using PCLMock.Visitors; - - /// - /// Facilitates the expression of specifications for what a should do when a given member is invoked. - /// - public abstract class WhenContinuation : IEquatable - { - private readonly Expression selector; - private readonly ArgumentFilterCollection filters; - private readonly IDictionary outAndRefAssignments; - - internal WhenContinuation(Expression selector, IEnumerable filters) - { - Debug.Assert(selector != null); - Debug.Assert(filters != null); - - this.selector = selector; - this.filters = new ArgumentFilterCollection(filters); - this.outAndRefAssignments = new Dictionary(); - } - - internal ArgumentFilterCollection Filters - { - get { return this.filters; } - } - - /// - public bool Equals(WhenContinuation other) - { - if (other == null) - { - return false; - } - - return this.filters.Equals(other.filters); - } - - /// - public override bool Equals(object obj) - { - return this.Equals(obj as WhenContinuation); - } - - /// - public override int GetHashCode() - { - throw new NotImplementedException(); - } - - internal abstract object Apply(object mockedObject, params object[] args); - - internal T GetOutParameterValue(int parameterIndex) - { - object value; - - if (!this.outAndRefAssignments.TryGetValue(parameterIndex, out value)) - { - throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "No value for out parameter at index {0} has been specified.", parameterIndex)); - } - - if (value != null) - { - if (!(value is T)) - { - throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Out parameter at index {0} has a value of type '{1}' but type '{2}' was expected.", parameterIndex, value.GetType().FullName, typeof(T).FullName)); - } - } - else if (typeof(T).GetTypeInfo().IsValueType) - { - throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Out parameter at index {0} has a null value specified but it is a value type ('{1}') so cannot be null.", parameterIndex, typeof(T).FullName)); - } - - return (T)value; - } - - internal T GetRefParameterValue(int parameterIndex, T defaultValue) - { - object value; - - if (!this.outAndRefAssignments.TryGetValue(parameterIndex, out value)) - { - // ref parameters need not be included in the specifications, in which case the caller can provide the default value to assign - return defaultValue; - } - - if (value != null) - { - if (!(value is T)) - { - throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Ref parameter at index {0} has a value of type '{1}' but type '{2}' was expected.", parameterIndex, value.GetType().FullName, typeof(T).FullName)); - } - } - else if (typeof(T).GetTypeInfo().IsValueType) - { - throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Ref parameter at index {0} has a null value specified but it is a value type ('{1}') so cannot be null.", parameterIndex, typeof(T).FullName)); - } - - return (T)value; - } - - internal object[] ValidateActionArgs(string actionType, Type[] expected, object[] received) - { - if (expected.Length == 0) - { - // target action expects no arguments, so it effectively doesn't matter what arguments we received - we can still invoke the action - return new object[0]; - } - - var @throw = false; - var receivedTypes = received.Select(x => x == null ? null : x.GetType()); - - if (received.Length != expected.Length) - { - @throw = true; - } - else - { - @throw = !expected.SequenceEqual(receivedTypes, ActionTypeComparer.Instance); - } - - if (@throw) - { - var receivedText = this.ConvertTypesToString(receivedTypes); - var expectedText = this.ConvertTypesToString(expected); - var message = string.Format(CultureInfo.InvariantCulture, "Could not execute the {0} action associated with this mocked member due to a parameter mismatch. Expected: {1} Received: {2}", actionType, expectedText, receivedText); - throw new InvalidOperationException(message); - } - - return received; - } - - internal string GetSelectorString() - { - var visitor = new SelectorStringVisitor(); - visitor.Visit(this.selector); - return visitor.ToString(); - } - - /// - /// Assigns a specified value to an out or ref parameter, so that invocations against the member being specified will result in - /// the corresponding out or ref parameter being set to the specified value. - /// - /// - /// The zero-based index of the parameter. - /// - /// - /// The value to assign to the out or ref parameter. - /// - protected void AssignOutOrRefParameter(int parameterIndex, object value) - { - this.outAndRefAssignments[parameterIndex] = value; - } - - private string ConvertTypesToString(IEnumerable types) - { - return types - .Aggregate( - new StringBuilder(), - (sb, type) => - { - if (sb.Length > 0) - { - sb.Append(", "); - } - - sb.Append(type == null ? "" : type.FullName); - - return sb; - }, - sb => sb.Insert(0, "(").Append(")")) - .ToString(); - } - - private sealed class ActionTypeComparer : IEqualityComparer - { - public static readonly ActionTypeComparer Instance = new ActionTypeComparer(); - - private ActionTypeComparer() - { - } - - public bool Equals(Type expectedType, Type receivedType) - { - Debug.Assert(expectedType != null); - - if (receivedType == null) - { - // one of the arguments provided to the action must have been null, so we can't know the type and just have to assume it's OK - return true; - } - - return expectedType.GetTypeInfo().IsAssignableFrom(receivedType.GetTypeInfo()); - } - - public int GetHashCode(Type obj) - { - return obj == null ? 0 : obj.GetHashCode(); - } - } - } - - /// - /// Facilitates the expression of specifications for what a should do when a given member is invoked. - /// - /// - /// The type of the object being mocked. - /// - public class WhenContinuation : WhenContinuation - { - private Exception exception; - private Delegate doAction; - - internal WhenContinuation(Expression selector, IEnumerable filters) - : base(selector, filters) - { - } - - /// - /// Requests that an exception be thrown if the member is accessed. - /// - /// - /// This overload simply throws an . - /// - public void Throw() - { - this.Throw(new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Mock has been configured to throw when accessing {0}.", this.GetSelectorString()))); - } - - /// - /// Requests that an exception be thrown if the member is accessed. - /// - /// - /// The exception to be thrown. - /// - public void Throw(Exception exception) - { - this.exception = exception; - } - - /// - public new WhenContinuation AssignOutOrRefParameter(int parameterIndex, object value) - { - base.AssignOutOrRefParameter(parameterIndex, value); - return this; - } - - /// - /// Requests that an action be invoked if the member is accessed. - /// - /// - /// The action to be invoked. - /// - /// - /// A continuation object so that the specification can be resumed. - /// - public WhenContinuation Do(Action doAction) - { - this.SetDoAction(doAction); - return this; - } - - /// - /// Requests that an action be invoked if the member is accessed. - /// - /// - /// The action to be invoked. - /// - /// - /// A continuation object so that the specification can be resumed. - /// - public WhenContinuation Do(Action doAction) - { - this.SetDoAction(doAction); - return this; - } - - /// - /// Requests that an action be invoked if the member is accessed. - /// - /// - /// The action to be invoked. - /// - /// - /// A continuation object so that the specification can be resumed. - /// - public WhenContinuation Do(Action doAction) - { - this.SetDoAction(doAction); - return this; - } - - /// - /// Requests that an action be invoked if the member is accessed. - /// - /// - /// The action to be invoked. - /// - /// - /// A continuation object so that the specification can be resumed. - /// - public WhenContinuation Do(Action doAction) - { - this.SetDoAction(doAction); - return this; - } - - /// - /// Requests that an action be invoked if the member is accessed. - /// - /// - /// The action to be invoked. - /// - /// - /// A continuation object so that the specification can be resumed. - /// - public WhenContinuation Do(Action doAction) - { - this.SetDoAction(doAction); - return this; - } - - /// - /// Requests that an action be invoked if the member is accessed. - /// - /// - /// The action to be invoked. - /// - /// - /// A continuation object so that the specification can be resumed. - /// - public WhenContinuation Do(Action doAction) - { - this.SetDoAction(doAction); - return this; - } - - internal override object Apply(object mockedObject, params object[] args) - { - Debug.Assert(args != null); - - if (this.exception != null) - { - throw this.exception; - } - - if (this.doAction != null) - { - args = this.ValidateActionArgs("Do", this.doAction.GetMethodInfo().GetParameters().Select(x => x.ParameterType).ToArray(), args); - this.doAction.DynamicInvoke(args); - } - - return null; - } - - private void SetDoAction(Delegate doAction) - { - if (this.doAction != null) - { - throw new InvalidOperationException("Do can only be specified once per mocked invocation."); - } - - this.doAction = doAction; - } - } - - /// - /// Facilitates the expression of specifications for what a should do when a given member is invoked. - /// - /// - /// The type of the object being mocked. - /// - /// - /// The type being returned by the member being specified. - /// - public sealed class WhenContinuation : WhenContinuation - { - private TMember returnValue; - private Delegate returnAction; - - internal WhenContinuation(Expression selector, IEnumerable filters) - : base(selector, filters) - { - } - - /// - public new WhenContinuation AssignOutOrRefParameter(int parameterIndex, object value) - { - base.AssignOutOrRefParameter(parameterIndex, value); - return this; - } - - /// - public new WhenContinuation Do(Action doAction) - { - base.Do(doAction); - return this; - } - - /// - public new WhenContinuation Do(Action doAction) - { - base.Do(doAction); - return this; - } - - /// - public new WhenContinuation Do(Action doAction) - { - base.Do(doAction); - return this; - } - - /// - public new WhenContinuation Do(Action doAction) - { - base.Do(doAction); - return this; - } - - /// - public new WhenContinuation Do(Action doAction) - { - base.Do(doAction); - return this; - } - - /// - public new WhenContinuation Do(Action doAction) - { - base.Do(doAction); - return this; - } - - /// - /// Requests that a specified value be returned if the member is accessed. - /// - /// - /// The value to return. - /// - public void Return(TMember value) - { - this.returnValue = value; - } - - /// - /// Requests that a Func be invoked to obtain a return value if the member is accessed. - /// - /// - /// The Func that will be invoked to obtain the return value. - /// - public void Return(Func returnAction) - { - this.returnAction = returnAction; - } - - /// - /// Requests that a Func be invoked to obtain a return value if the member is accessed. - /// - /// - /// The Func that will be invoked to obtain the return value. - /// - public void Return(Func returnAction) - { - this.returnAction = returnAction; - } - - /// - /// Requests that a Func be invoked to obtain a return value if the member is accessed. - /// - /// - /// The Func that will be invoked to obtain the return value. - /// - public void Return(Func returnAction) - { - this.returnAction = returnAction; - } - - /// - /// Requests that a Func be invoked to obtain a return value if the member is accessed. - /// - /// - /// The Func that will be invoked to obtain the return value. - /// - public void Return(Func returnAction) - { - this.returnAction = returnAction; - } - - /// - /// Requests that a Func be invoked to obtain a return value if the member is accessed. - /// - /// - /// The Func that will be invoked to obtain the return value. - /// - public void Return(Func returnAction) - { - this.returnAction = returnAction; - } - - /// - /// Requests that a Func be invoked to obtain a return value if the member is accessed. - /// - /// - /// The Func that will be invoked to obtain the return value. - /// - public void Return(Func returnAction) - { - this.returnAction = returnAction; - } - - internal override object Apply(object mockedObject, params object[] args) - { - base.Apply(mockedObject, args); - - if (this.returnAction != null) - { - args = this.ValidateActionArgs("Return", this.returnAction.GetMethodInfo().GetParameters().Select(x => x.ParameterType).ToArray(), args); - return this.returnAction.DynamicInvoke(args); - } - - return this.returnValue; - } - } -} \ No newline at end of file diff --git a/Src/Rebracer.xml b/Src/Rebracer.xml deleted file mode 100644 index 27dd7c4..0000000 --- a/Src/Rebracer.xml +++ /dev/null @@ -1,511 +0,0 @@ - - - - - - - - - - - - - HACK:2 - TODO:2 - UNDONE:2 - UnresolvedMergeConflict:3 - - false - false - false - - - - - 0 - 0 - 1 - 1 - 0 - 0 - 0 - 1 - 0 - 0 - 1 - 1 - 1 - 1 - 1 - 1 - 0 - 1 - 1 - 0 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 2 - 1 - 1 - 0 - 1 - 0 - 0 - 0 - 1 - 1 - 1 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 1 - 0 - 0 - 0 - 0 - 0 - 0 - <NamingPreferencesInfo SerializationVersion="4"> - <SymbolSpecifications> - <SymbolSpecification ID="5c545a62-b14d-460a-88d8-e936c0a39316" Name="Class"> - <ApplicableSymbolKindList> - <TypeKind>Class</TypeKind> - </ApplicableSymbolKindList> - <ApplicableAccessibilityList> - <AccessibilityKind>Public</AccessibilityKind> - <AccessibilityKind>Internal</AccessibilityKind> - <AccessibilityKind>Private</AccessibilityKind> - <AccessibilityKind>Protected</AccessibilityKind> - <AccessibilityKind>ProtectedOrInternal</AccessibilityKind> - </ApplicableAccessibilityList> - <RequiredModifierList /> - </SymbolSpecification> - <SymbolSpecification ID="23d856b4-5089-4405-83ce-749aada99153" Name="Interface"> - <ApplicableSymbolKindList> - <TypeKind>Interface</TypeKind> - </ApplicableSymbolKindList> - <ApplicableAccessibilityList> - <AccessibilityKind>Public</AccessibilityKind> - <AccessibilityKind>Internal</AccessibilityKind> - <AccessibilityKind>Private</AccessibilityKind> - <AccessibilityKind>Protected</AccessibilityKind> - <AccessibilityKind>ProtectedOrInternal</AccessibilityKind> - </ApplicableAccessibilityList> - <RequiredModifierList /> - </SymbolSpecification> - <SymbolSpecification ID="d1796e78-ff66-463f-8576-eb46416060c0" Name="Struct"> - <ApplicableSymbolKindList> - <TypeKind>Struct</TypeKind> - </ApplicableSymbolKindList> - <ApplicableAccessibilityList> - <AccessibilityKind>Public</AccessibilityKind> - <AccessibilityKind>Internal</AccessibilityKind> - <AccessibilityKind>Private</AccessibilityKind> - <AccessibilityKind>Protected</AccessibilityKind> - <AccessibilityKind>ProtectedOrInternal</AccessibilityKind> - </ApplicableAccessibilityList> - <RequiredModifierList /> - </SymbolSpecification> - <SymbolSpecification ID="d8af8dc6-1ade-441d-9947-8946922e198a" Name="Enum"> - <ApplicableSymbolKindList> - <TypeKind>Enum</TypeKind> - </ApplicableSymbolKindList> - <ApplicableAccessibilityList> - <AccessibilityKind>Public</AccessibilityKind> - <AccessibilityKind>Internal</AccessibilityKind> - <AccessibilityKind>Private</AccessibilityKind> - <AccessibilityKind>Protected</AccessibilityKind> - <AccessibilityKind>ProtectedOrInternal</AccessibilityKind> - </ApplicableAccessibilityList> - <RequiredModifierList /> - </SymbolSpecification> - <SymbolSpecification ID="408a3347-b908-4b54-a954-1355e64c1de3" Name="Delegate"> - <ApplicableSymbolKindList> - <TypeKind>Delegate</TypeKind> - </ApplicableSymbolKindList> - <ApplicableAccessibilityList> - <AccessibilityKind>Public</AccessibilityKind> - <AccessibilityKind>Internal</AccessibilityKind> - <AccessibilityKind>Private</AccessibilityKind> - <AccessibilityKind>Protected</AccessibilityKind> - <AccessibilityKind>ProtectedOrInternal</AccessibilityKind> - </ApplicableAccessibilityList> - <RequiredModifierList /> - </SymbolSpecification> - <SymbolSpecification ID="830657f6-e7e5-4830-b328-f109d3b6c165" Name="Event"> - <ApplicableSymbolKindList> - <SymbolKind>Event</SymbolKind> - </ApplicableSymbolKindList> - <ApplicableAccessibilityList> - <AccessibilityKind>Public</AccessibilityKind> - <AccessibilityKind>Internal</AccessibilityKind> - <AccessibilityKind>Private</AccessibilityKind> - <AccessibilityKind>Protected</AccessibilityKind> - <AccessibilityKind>ProtectedOrInternal</AccessibilityKind> - </ApplicableAccessibilityList> - <RequiredModifierList /> - </SymbolSpecification> - <SymbolSpecification ID="390caed4-f0a9-42bb-adbb-b44c4a302a22" Name="Method"> - <ApplicableSymbolKindList> - <SymbolKind>Method</SymbolKind> - </ApplicableSymbolKindList> - <ApplicableAccessibilityList> - <AccessibilityKind>Public</AccessibilityKind> - </ApplicableAccessibilityList> - <RequiredModifierList /> - </SymbolSpecification> - <SymbolSpecification ID="af410767-f189-47c6-b140-aeccf1ff242e" Name="Private Method"> - <ApplicableSymbolKindList> - <SymbolKind>Method</SymbolKind> - </ApplicableSymbolKindList> - <ApplicableAccessibilityList> - <AccessibilityKind>Private</AccessibilityKind> - </ApplicableAccessibilityList> - <RequiredModifierList /> - </SymbolSpecification> - <SymbolSpecification ID="8076757e-6a4a-47f1-9b4b-ae8a3284e987" Name="Abstract Method"> - <ApplicableSymbolKindList> - <SymbolKind>Method</SymbolKind> - </ApplicableSymbolKindList> - <ApplicableAccessibilityList> - <AccessibilityKind>Public</AccessibilityKind> - <AccessibilityKind>Internal</AccessibilityKind> - <AccessibilityKind>Private</AccessibilityKind> - <AccessibilityKind>Protected</AccessibilityKind> - <AccessibilityKind>ProtectedOrInternal</AccessibilityKind> - </ApplicableAccessibilityList> - <RequiredModifierList> - <ModifierKind>IsAbstract</ModifierKind> - </RequiredModifierList> - </SymbolSpecification> - <SymbolSpecification ID="16133061-a8e7-4392-92c3-1d93cd54c218" Name="Static Method"> - <ApplicableSymbolKindList> - <SymbolKind>Method</SymbolKind> - </ApplicableSymbolKindList> - <ApplicableAccessibilityList> - <AccessibilityKind>Public</AccessibilityKind> - <AccessibilityKind>Internal</AccessibilityKind> - <AccessibilityKind>Private</AccessibilityKind> - <AccessibilityKind>Protected</AccessibilityKind> - <AccessibilityKind>ProtectedOrInternal</AccessibilityKind> - </ApplicableAccessibilityList> - <RequiredModifierList> - <ModifierKind>IsStatic</ModifierKind> - </RequiredModifierList> - </SymbolSpecification> - <SymbolSpecification ID="da6a2919-5aa6-4ad1-a24d-576776ed3974" Name="Property"> - <ApplicableSymbolKindList> - <SymbolKind>Property</SymbolKind> - </ApplicableSymbolKindList> - <ApplicableAccessibilityList> - <AccessibilityKind>Public</AccessibilityKind> - <AccessibilityKind>Internal</AccessibilityKind> - <AccessibilityKind>Private</AccessibilityKind> - <AccessibilityKind>Protected</AccessibilityKind> - <AccessibilityKind>ProtectedOrInternal</AccessibilityKind> - </ApplicableAccessibilityList> - <RequiredModifierList /> - </SymbolSpecification> - <SymbolSpecification ID="b24a91ce-3501-4799-b6df-baf044156c83" Name="Public or Protected Field"> - <ApplicableSymbolKindList> - <SymbolKind>Field</SymbolKind> - </ApplicableSymbolKindList> - <ApplicableAccessibilityList> - <AccessibilityKind>Public</AccessibilityKind> - <AccessibilityKind>Protected</AccessibilityKind> - </ApplicableAccessibilityList> - <RequiredModifierList /> - </SymbolSpecification> - <SymbolSpecification ID="70af42cb-1741-4027-969c-9edc4877d965" Name="Static Field"> - <ApplicableSymbolKindList> - <SymbolKind>Field</SymbolKind> - </ApplicableSymbolKindList> - <ApplicableAccessibilityList> - <AccessibilityKind>Public</AccessibilityKind> - <AccessibilityKind>Internal</AccessibilityKind> - <AccessibilityKind>Private</AccessibilityKind> - <AccessibilityKind>Protected</AccessibilityKind> - <AccessibilityKind>ProtectedOrInternal</AccessibilityKind> - </ApplicableAccessibilityList> - <RequiredModifierList> - <ModifierKind>IsStatic</ModifierKind> - </RequiredModifierList> - </SymbolSpecification> - <SymbolSpecification ID="10790aa6-0a0b-432d-a52d-d252ca92302b" Name="Private or Internal Field"> - <ApplicableSymbolKindList> - <SymbolKind>Field</SymbolKind> - </ApplicableSymbolKindList> - <ApplicableAccessibilityList> - <AccessibilityKind>Internal</AccessibilityKind> - <AccessibilityKind>Private</AccessibilityKind> - </ApplicableAccessibilityList> - <RequiredModifierList /> - </SymbolSpecification> - <SymbolSpecification ID="ac995be4-88de-4771-9dcc-a456a7c02d89" Name="Private or Internal Static Field"> - <ApplicableSymbolKindList> - <SymbolKind>Field</SymbolKind> - </ApplicableSymbolKindList> - <ApplicableAccessibilityList> - <AccessibilityKind>Internal</AccessibilityKind> - <AccessibilityKind>Private</AccessibilityKind> - </ApplicableAccessibilityList> - <RequiredModifierList> - <ModifierKind>IsStatic</ModifierKind> - </RequiredModifierList> - </SymbolSpecification> - <SymbolSpecification ID="2c07f5bf-bc81-4c2b-82b4-ae9b3ffd0ba4" Name="Types"> - <ApplicableSymbolKindList> - <TypeKind>Class</TypeKind> - <TypeKind>Struct</TypeKind> - <TypeKind>Interface</TypeKind> - <TypeKind>Enum</TypeKind> - </ApplicableSymbolKindList> - <ApplicableAccessibilityList> - <AccessibilityKind>Public</AccessibilityKind> - <AccessibilityKind>Internal</AccessibilityKind> - <AccessibilityKind>Private</AccessibilityKind> - <AccessibilityKind>Protected</AccessibilityKind> - <AccessibilityKind>ProtectedOrInternal</AccessibilityKind> - </ApplicableAccessibilityList> - <RequiredModifierList /> - </SymbolSpecification> - <SymbolSpecification ID="5f3ddba1-279f-486c-801e-5c097c36dd85" Name="Non-Field Members"> - <ApplicableSymbolKindList> - <SymbolKind>Property</SymbolKind> - <SymbolKind>Method</SymbolKind> - <SymbolKind>Event</SymbolKind> - </ApplicableSymbolKindList> - <ApplicableAccessibilityList> - <AccessibilityKind>Public</AccessibilityKind> - <AccessibilityKind>Internal</AccessibilityKind> - <AccessibilityKind>Private</AccessibilityKind> - <AccessibilityKind>Protected</AccessibilityKind> - <AccessibilityKind>ProtectedOrInternal</AccessibilityKind> - </ApplicableAccessibilityList> - <RequiredModifierList /> - </SymbolSpecification> - </SymbolSpecifications> - <NamingStyles> - <NamingStyle ID="87e7c501-9948-4b53-b1eb-a6cbe918feee" Name="Pascal Case" Prefix="" Suffix="" WordSeparator="" CapitalizationScheme="PascalCase" /> - <NamingStyle ID="1ecc5eb6-b5fc-49a5-a9f1-a980f3e48c92" Name="Begins with I" Prefix="I" Suffix="" WordSeparator="" CapitalizationScheme="PascalCase" /> - </NamingStyles> - <NamingRules> - <SerializableNamingRule SymbolSpecificationID="23d856b4-5089-4405-83ce-749aada99153" NamingStyleID="1ecc5eb6-b5fc-49a5-a9f1-a980f3e48c92" EnforcementLevel="Info" /> - <SerializableNamingRule SymbolSpecificationID="2c07f5bf-bc81-4c2b-82b4-ae9b3ffd0ba4" NamingStyleID="87e7c501-9948-4b53-b1eb-a6cbe918feee" EnforcementLevel="Info" /> - <SerializableNamingRule SymbolSpecificationID="5f3ddba1-279f-486c-801e-5c097c36dd85" NamingStyleID="87e7c501-9948-4b53-b1eb-a6cbe918feee" EnforcementLevel="Info" /> - </NamingRules> -</NamingPreferencesInfo> - 1 - <CodeStyleOption SerializationVersion="1" Type="Boolean" Value="true" DiagnosticSeverity="Hidden" /> - 1 - <CodeStyleOption SerializationVersion="1" Type="Boolean" Value="true" DiagnosticSeverity="Hidden" /> - <CodeStyleOption SerializationVersion="1" Type="Boolean" Value="false" DiagnosticSeverity="Hidden" /> - <CodeStyleOption SerializationVersion="1" Type="Boolean" Value="false" DiagnosticSeverity="Hidden" /> - 1 - <CodeStyleOption SerializationVersion="1" Type="Boolean" Value="false" DiagnosticSeverity="Hidden" /> - <CodeStyleOption SerializationVersion="1" Type="Boolean" Value="false" DiagnosticSeverity="Hidden" /> - <CodeStyleOption SerializationVersion="1" Type="Boolean" Value="false" DiagnosticSeverity="Hidden" /> - <CodeStyleOption SerializationVersion="1" Type="Boolean" Value="false" DiagnosticSeverity="Hidden" /> - <CodeStyleOption SerializationVersion="1" Type="Boolean" Value="false" DiagnosticSeverity="Hidden" /> - 1 - 0 - 0 - 0 - 1 - 1 - - - false - true - true - true - true - Implicit (Windows)|$(VSInstallDir)\JavaScript\References\libhelp.js|$(VSInstallDir)\JavaScript\References\domWindows.js|$(VSInstallDir)\JavaScript\References\underscorefilter.js|$(VSInstallDir)\JavaScript\References\showPlainComments.js;Implicit (Windows 8.1)|$(VSInstallDir)\JavaScript\References\libhelp.js|$(VSInstallDir)\JavaScript\References\sitetypesWindows.js|$(VSInstallDir)\JavaScript\References\domWindows_8.1.js|$(VSInstallDir)\JavaScript\References\underscorefilter.js|$(VSInstallDir)\JavaScript\References\showPlainComments.js;Implicit (Windows Phone 8.1)|$(VSInstallDir)\JavaScript\References\libhelp.js|$(VSInstallDir)\JavaScript\References\sitetypesWindows.js|$(VSInstallDir)\JavaScript\References\domWindowsPhone_8.1.js|$(VSInstallDir)\JavaScript\References\underscorefilter.js|$(VSInstallDir)\JavaScript\References\showPlainComments.js;Implicit (Web)|$(VSInstallDir)\JavaScript\References\libhelp.js|$(VSInstallDir)\JavaScript\References\sitetypesWeb.js|$(VSInstallDir)\JavaScript\References\domWeb.js|$(VSInstallDir)\JavaScript\References\underscorefilter.js|$(VSInstallDir)\JavaScript\References\showPlainComments.js;Dedicated Worker|$(VSInstallDir)\JavaScript\References\libhelp.js|$(VSInstallDir)\JavaScript\References\dedicatedworker.js|$(VSInstallDir)\JavaScript\References\underscorefilter.js|$(VSInstallDir)\JavaScript\References\showPlainComments.js;Generic|$(VSInstallDir)\JavaScript\References\libhelp.js|$(VSInstallDir)\JavaScript\References\underscorefilter.js|$(VSInstallDir)\JavaScript\References\showPlainComments.js; - true - true - true - false - true - true - false - false - true - true - - - true - false - false - true - true - true - 1 - true - false - 5120 - true - false - true - false - false - true - false - false - false - false - false - true - true - true - false - true - true - true - true - false - true - false - false - true - false - 1 - true - 2 - 2 - false - true - false - false - 0 - true - true - 0 - 0 - true - true - false - 0 - 0 - false - 0 - 1 - false - true - false - 2 - true - false - true - true - true - true - true - false - false - false - false - true - true - false - false - false - false - true - true - 2 - 2 - 2 - true - false - false - true - true - false - false - 1 - true - false - false - false - false - false - false - false - false - false - false - false - true - false - false - true - true - - - false - {}[]().,:;+-*/%&|^!~=<>? - false - true - false - true - true - true - true - true - true - true - false - true - true - true - false - false - true - true - true - true - false - false - false - false - false - false - false - true - false - - - true - false - true - true - true - true - true - true - true - true - - - - \ No newline at end of file diff --git a/build.bat b/build.bat deleted file mode 100644 index 33f3b83..0000000 --- a/build.bat +++ /dev/null @@ -1,4 +0,0 @@ -@echo off -cls -".nuget\NuGet.exe" "Install" "FAKE" "-OutputDirectory" "Src\packages" "-ExcludeVersion" -"Src\packages\FAKE\tools\Fake.exe" build.fsx %* \ No newline at end of file diff --git a/build.cake b/build.cake new file mode 100644 index 0000000..af13eba --- /dev/null +++ b/build.cake @@ -0,0 +1,90 @@ +using System; + +// Parameters. +var projectName = "PCLMock"; +var versionMajorMinorPatch = "5.1.2"; +var versionSuffix = "-alpha"; +var semanticVersion = versionMajorMinorPatch + versionSuffix; +var version = versionMajorMinorPatch + ".0" + versionSuffix; +var configuration = EnvironmentVariable("CONFIGURATION") ?? "Release"; +var nugetSource = "https://www.nuget.org/api/v2/package"; + +// To push to NuGet, run with: & {$env:NUGET_API_KEY="$KEY"; ./build.ps1} +var nugetApiKey = EnvironmentVariable("NUGET_API_KEY"); + +// Paths. +var srcDir = Directory("Src"); +var solution = srcDir + File(projectName + ".sln"); + +Setup(context => Information("Building {0} version {1}.", projectName, version)); + +Teardown(context => Information("Build {0} finished.", version)); + +Task("Clean") + .Does(() => DotNetCoreClean(solution)); + +Task("Pre-Build") + .Does( + () => + { + }); + +Task("Build") + .IsDependentOn("Pre-Build") + .Does( + () => + { + var msBuildSettings = new DotNetCoreMSBuildSettings(); + msBuildSettings.Properties["Version"] = new string[] + { + version + }; + + var settings = new DotNetCoreBuildSettings + { + Configuration = configuration, + MSBuildSettings = msBuildSettings, + }; + + DotNetCoreBuild(solution, settings); + }); + +Task("Test") + .IsDependentOn("Build") + .Does( + () => + { + var testProject = srcDir + Directory("PCLMock.UnitTests") + File("PCLMock.UnitTests.csproj"); + DotNetCoreTest(testProject); + }); + +Task("Push") + .IsDependentOn("Test") + .WithCriteria(nugetApiKey != null) + .Does( + () => + { + var settings = new DotNetCoreNuGetPushSettings + { + ApiKey = nugetApiKey, + Source = nugetSource, + }; + + var nuGetPackages = new [] + { + srcDir + Directory("PCLMock/bin") + Directory(configuration) + File("PCLMock." + semanticVersion + ".nupkg"), + srcDir + Directory("PCLMock.CodeGeneration/bin") + Directory(configuration) + File("PCLMock.CodeGeneration." + semanticVersion + ".nupkg"), + srcDir + Directory("PCLMock.CodeGeneration.Console/bin") + Directory(configuration) + File("PCLMock.CodeGeneration.Console." + semanticVersion + ".nupkg"), + srcDir + Directory("PCLMock.CodeGeneration.SourceGenerator/bin") + Directory(configuration) + File("PCLMock.CodeGeneration.SourceGenerator." + semanticVersion + ".nupkg"), + }; + + foreach (var nuGetPackage in nuGetPackages) + { + DotNetCoreNuGetPush(nuGetPackage, settings); + } + }); + +Task("Default") + .IsDependentOn("Push"); + +RunTarget(Argument("target", "Default")); \ No newline at end of file diff --git a/build.fsx b/build.fsx deleted file mode 100644 index 131594b..0000000 --- a/build.fsx +++ /dev/null @@ -1,241 +0,0 @@ -#I "Src/packages/FAKE/tools" -#r "FakeLib.dll" - -open Fake -open Fake.AssemblyInfoFile -open Fake.EnvironmentHelper -open Fake.MSBuildHelper -open Fake.NuGetHelper -open Fake.Testing.XUnit2 - -// properties -let semanticVersion = "5.0.4-alpha" -let version = (>=>) @"(?\d*)\.(?\d*)\.(?\d*).*?" "${major}.${minor}.${build}.0" semanticVersion -let configuration = getBuildParamOrDefault "configuration" "Release" -// can be set by passing: -ev deployToNuGet true -let deployToNuGet = getBuildParamOrDefault "deployToNuGet" "false" -let genDir = "Gen/" -let docDir = "Doc/" -let srcDir = "Src/" -let packagesDir = "Src/packages/" -let testDir = genDir @@ "Test" -let nugetDir = genDir @@ "NuGet" -let nugetSource = "https://www.nuget.org/api/v2/package" - -Target "Clean" (fun _ -> - CleanDirs[genDir; testDir; nugetDir] - - build (fun p -> - { p with - Verbosity = Some(Quiet) - Targets = ["Clean"] - Properties = ["Configuration", configuration] - }) - (srcDir @@ "PCLMock.sln") -) - -// would prefer to use the built-in RestorePackages function, but it restores packages in the root dir (not in Src), which causes build problems -Target "RestorePackages" (fun _ -> - !! "./**/packages.config" - |> Seq.iter ( - RestorePackage (fun p -> - { p with - OutputPath = (srcDir @@ "packages") - }) - ) -) - -Target "Build" (fun _ -> - // generate the shared assembly info - CreateCSharpAssemblyInfoWithConfig (srcDir @@ "AssemblyInfoCommon.cs") - [ - Attribute.Version version - Attribute.FileVersion version - Attribute.Configuration configuration - Attribute.Company "Kent Boogaart" - Attribute.Product "PCLMock" - Attribute.Copyright "© Copyright. Kent Boogaart." - Attribute.Trademark "" - Attribute.Culture "" - Attribute.StringAttribute("NeutralResourcesLanguage", "en-US", "System.Resources") - Attribute.StringAttribute("AssemblyInformationalVersion", semanticVersion, "System.Reflection") - ] - (AssemblyInfoFileConfig(false)) - - build (fun p -> - { p with - Verbosity = Some(Quiet) - Targets = ["Build"] - Properties = - [ - "Optimize", "True" - "DebugSymbols", "True" - "Configuration", configuration - ] - }) - (srcDir @@ "PCLMock.sln") -) - -Target "ExecuteUnitTests" (fun _ -> - xUnit2 (fun p -> - { p with - ShadowCopy = false; -// HtmlOutputPath = Some testDir; -// XmlOutputPath = Some testDir; - }) - [srcDir @@ "PCLMock.UnitTests/bin" @@ configuration @@ "PCLMock.UnitTests.dll"] -) - -Target "CreateArchives" (fun _ -> - // source archive - !! "**/*.*" - -- ".git/**" - -- (genDir @@ "**") - -- (srcDir @@ "**/.vs/**") - -- (srcDir @@ "packages/**/*") - -- (srcDir @@ "**/*.suo") - -- (srcDir @@ "**/*.csproj.user") - -- (srcDir @@ "**/*.gpState") - -- (srcDir @@ "**/bin/**") - -- (srcDir @@ "**/obj/**") - |> Zip "." (genDir @@ "PCLMock-" + semanticVersion + "-src.zip") - - // binary archive - let workingDir = srcDir @@ "PCLMock/bin" @@ configuration - - !! (workingDir @@ "PCLMock.*") - |> Zip workingDir (genDir @@ "PCLMock-" + semanticVersion + "-bin.zip") -) - -Target "CreateNuGetPackages" (fun _ -> - // copy files required in the various NuGets - !! (srcDir @@ "PCLMock/bin" @@ configuration @@ "PCLMock.*") - |> CopyFiles (nugetDir @@ "PCLMock/lib/portable-net45+win8+wp8+wpa81") - - !! (srcDir @@ "PCLMock.CodeGeneration/bin" @@ configuration @@ "PCLMock.CodeGeneration.*") - |> CopyFiles (nugetDir @@ "PCLMock.CodeGeneration/lib/net45") - - !! (srcDir @@ "PCLMock.CodeGeneration.T4/bin" @@ configuration @@ "Mocks.*") - |> CopyFiles (nugetDir @@ "PCLMock.CodeGeneration.T4/content") - !! (srcDir @@ "PCLMock.CodeGeneration.T4/bin" @@ configuration @@ "*.*") - -- ("**/*.xml") - |> CopyFiles (nugetDir @@ "PCLMock.CodeGeneration.T4/tools") - - !! (srcDir @@ "PCLMock.CodeGeneration.Console/bin" @@ configuration @@ "*.*") - -- ("**/*.xml") - |> CopyFiles (nugetDir @@ "PCLMock.CodeGeneration.Console/tools") - - // copy source - let sourceFiles = - [!! (srcDir @@ "**/*.*") - -- ".git/**" - -- (srcDir @@ "**/.vs/**") - -- (srcDir @@ "packages/**/*") - -- (srcDir @@ "**/*.suo") - -- (srcDir @@ "**/*.csproj.user") - -- (srcDir @@ "**/*.gpState") - -- (srcDir @@ "**/bin/**") - -- (srcDir @@ "**/obj/**") - -- (srcDir @@ "PCLMock.CodeGeneration.*/**") - -- (srcDir @@ "PCLMock.UnitTests/**")] - sourceFiles - |> CopyWithSubfoldersTo (nugetDir @@ "PCLMock") - sourceFiles - |> CopyWithSubfoldersTo (nugetDir @@ "PCLMock.CodeGeneration") - - // create the NuGets - NuGet (fun p -> - {p with - Project = "PCLMock" - Version = semanticVersion - OutputPath = nugetDir - WorkingDir = nugetDir @@ "PCLMock" - SymbolPackage = NugetSymbolPackage.Nuspec - Publish = System.Convert.ToBoolean(deployToNuGet) - PublishUrl = nugetSource - }) - (srcDir @@ "PCLMock.nuspec") - - NuGet (fun p -> - {p with - Project = "PCLMock.CodeGeneration" - Version = semanticVersion - OutputPath = nugetDir - WorkingDir = nugetDir @@ "PCLMock.CodeGeneration" - SymbolPackage = NugetSymbolPackage.Nuspec - Dependencies = - [ - "Microsoft.CodeAnalysis", GetPackageVersion packagesDir "Microsoft.CodeAnalysis" - "Microsoft.CodeAnalysis.Analyzers", GetPackageVersion packagesDir "Microsoft.CodeAnalysis.Analyzers" - "Microsoft.CodeAnalysis.Common", GetPackageVersion packagesDir "Microsoft.CodeAnalysis.Common" - "Microsoft.CodeAnalysis.CSharp", GetPackageVersion packagesDir "Microsoft.CodeAnalysis.CSharp" - "Microsoft.CodeAnalysis.CSharp.Workspaces", GetPackageVersion packagesDir "Microsoft.CodeAnalysis.CSharp.Workspaces" - "Microsoft.CodeAnalysis.VisualBasic", GetPackageVersion packagesDir "Microsoft.CodeAnalysis.VisualBasic" - "Microsoft.CodeAnalysis.VisualBasic.Workspaces", GetPackageVersion packagesDir "Microsoft.CodeAnalysis.VisualBasic.Workspaces" - "Microsoft.CodeAnalysis.Workspaces.Common", GetPackageVersion packagesDir "Microsoft.CodeAnalysis.Workspaces.Common" - "Microsoft.Composition", GetPackageVersion packagesDir "Microsoft.Composition" - "Rx-Main", GetPackageVersion packagesDir "Rx-Main" - "System.Collections", GetPackageVersion packagesDir "System.Collections" - "System.Collections.Immutable", GetPackageVersion packagesDir "System.Collections.Immutable" - "System.Diagnostics.Debug", GetPackageVersion packagesDir "System.Diagnostics.Debug" - "System.Globalization", GetPackageVersion packagesDir "System.Globalization" - "System.IO", GetPackageVersion packagesDir "System.IO" - "System.Linq", GetPackageVersion packagesDir "System.Linq" - "System.Reflection", GetPackageVersion packagesDir "System.Reflection" - "System.Reflection.Extensions", GetPackageVersion packagesDir "System.Reflection.Extensions" - "System.Reflection.Metadata", GetPackageVersion packagesDir "System.Reflection.Metadata" - "System.Reflection.Primitives", GetPackageVersion packagesDir "System.Reflection.Primitives" - "System.Resources.ResourceManager", GetPackageVersion packagesDir "System.Resources.ResourceManager" - "System.Runtime", GetPackageVersion packagesDir "System.Runtime" - "System.Runtime.Extensions", GetPackageVersion packagesDir "System.Runtime.Extensions" - "System.Runtime.InteropServices", GetPackageVersion packagesDir "System.Runtime.InteropServices" - "System.Text.Encoding", GetPackageVersion packagesDir "System.Text.Encoding" - "System.Text.Encoding.Extensions", GetPackageVersion packagesDir "System.Text.Encoding.Extensions" - "System.Threading", GetPackageVersion packagesDir "System.Threading" - "PCLMock", semanticVersion - ] - Publish = System.Convert.ToBoolean(deployToNuGet) - PublishUrl = nugetSource - }) - (srcDir @@ "PCLMock.CodeGeneration.nuspec") - - NuGet (fun p -> - {p with - Project = "PCLMock.CodeGeneration.T4" - Version = semanticVersion - OutputPath = nugetDir - WorkingDir = nugetDir @@ "PCLMock.CodeGeneration.T4" - SymbolPackage = NugetSymbolPackage.None - Dependencies = - [ - "PCLMock", semanticVersion - ] - Publish = System.Convert.ToBoolean(deployToNuGet) - PublishUrl = nugetSource - TimeOut = System.TimeSpan.FromMinutes(15.0) - }) - (srcDir @@ "PCLMock.CodeGeneration.T4.nuspec") - - NuGet (fun p -> - {p with - Project = "PCLMock.CodeGeneration.Console" - Version = semanticVersion - OutputPath = nugetDir - WorkingDir = nugetDir @@ "PCLMock.CodeGeneration.Console" - SymbolPackage = NugetSymbolPackage.None - Publish = System.Convert.ToBoolean(deployToNuGet) - PublishUrl = nugetSource - TimeOut = System.TimeSpan.FromMinutes(15.0) - }) - (srcDir @@ "PCLMock.CodeGeneration.Console.nuspec") -) - -// build order -"Clean" - ==> "RestorePackages" - ==> "Build" - ==> "ExecuteUnitTests" - ==> "CreateArchives" - ==> "CreateNuGetPackages" - -RunTargetOrDefault "CreateNuGetPackages" \ No newline at end of file diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..f311388 --- /dev/null +++ b/build.ps1 @@ -0,0 +1,43 @@ +$CakeVersion = "0.37.0" + +# Make sure tools folder exists +$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent +$ToolPath = Join-Path $PSScriptRoot "tools" +if (!(Test-Path $ToolPath)) { + Write-Verbose "Creating tools directory..." + New-Item -Path $ToolPath -Type directory | out-null +} + +########################################################################### +# INSTALL CAKE +########################################################################### + +Add-Type -AssemblyName System.IO.Compression.FileSystem +Function Unzip +{ + param([string]$zipfile, [string]$outpath) + + [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath) +} + + +# Make sure Cake has been installed. +$CakePath = Join-Path $ToolPath "Cake.CoreCLR.$CakeVersion" +$CakeDllPath = Join-Path $CakePath "Cake.dll" +$CakeZipPath = Join-Path $ToolPath "Cake.zip" +if (!(Test-Path $CakeDllPath)) { + Write-Host "Installing Cake $CakeVersion..." + (New-Object System.Net.WebClient).DownloadFile("https://www.nuget.org/api/v2/package/Cake.CoreCLR/$CakeVersion", $CakeZipPath) + Unzip $CakeZipPath $CakePath + Remove-Item $CakeZipPath +} + +########################################################################### +# RUN BUILD SCRIPT +########################################################################### +& dotnet "$CakeDllPath" ./build.cake --bootstrap +if ($LASTEXITCODE -eq 0) +{ + & dotnet "$CakeDllPath" ./build.cake $args +} +exit $LASTEXITCODE \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..3144b6e --- /dev/null +++ b/build.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +# Define varibles +CAKE_VERSION=0.37.0 +DOTNET_SDK_VERSION=2.1.4 +SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +TOOLS_DIR=$SCRIPT_DIR/tools +CAKE_DLL=$TOOLS_DIR/Cake.CoreCLR.$CAKE_VERSION/Cake.dll + +# Make sure the tools folder exist. +if [ ! -d "$TOOLS_DIR" ]; then + mkdir "$TOOLS_DIR" +fi + +########################################################################### +# INSTALL CAKE +########################################################################### + +if [ ! -f "$CAKE_DLL" ]; then + echo "Installing Cake $CAKE_VERSION..." + curl -Lsfo Cake.zip "https://www.nuget.org/api/v2/package/Cake.CoreCLR/$CAKE_VERSION" && unzip -q Cake.zip -d "$TOOLS_DIR/Cake.CoreCLR.$CAKE_VERSION" && rm -f Cake.zip + if [ $? -ne 0 ]; then + echo "An error occured while installing Cake." + exit 1 + fi +fi + +# Make sure that Cake has been installed. +if [ ! -f "$CAKE_DLL" ]; then + echo "Could not find Cake.exe at '$CAKE_DLL'." + exit 1 +fi + +########################################################################### +# RUN BUILD SCRIPT +########################################################################### + +# Start Cake +(exec dotnet "$CAKE_DLL" build.cake --bootstrap) && (exec dotnet "$CAKE_DLL" build.cake "$@") diff --git a/tools/packages.config b/tools/packages.config new file mode 100644 index 0000000..666cc01 --- /dev/null +++ b/tools/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file