├── release-notes.txt ├── src ├── LightMock.Generator │ ├── LightMock.Generator.props │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── AnalyzerReleases.Unshipped.md │ ├── RefReturnVisitor.cs │ ├── SymbolDisplayPartExtensions.cs │ ├── AnalyzerReleases.Shipped.md │ ├── LightMock.Generator.targets │ ├── CompilationContext.cs │ ├── LightMock.Generator.Roslyn40.csproj │ ├── CodeGenerationContext.cs │ ├── ExceptionMessages.cs │ ├── GlobalOptionsNames.cs │ ├── VariableNames.cs │ ├── Suffix.cs │ └── PropertyDefinitionVisitor.cs ├── LightMock.Generator.Tests │ ├── AbstractClass │ │ ├── AbstractClassNotGenerated.cs │ │ ├── CantProcessSealedClass.cs │ │ ├── Indexer.cs │ │ ├── DontOverrideSupport.AssemblyInfo.test.cs │ │ ├── MethodWithInParameter.cs │ │ ├── MethodWithOutParameter.cs │ │ ├── MethodWithRefParameter.cs │ │ ├── RefReturn.cs │ │ ├── NestedClass.cs │ │ ├── ArrangeSetter_When.cs │ │ ├── AbstractClassThrowsExceptionOnRefStruct.cs │ │ ├── ArrangeSetter_WhenAny.cs │ │ ├── ObsoleteSupport.cs │ │ ├── AbstractClassWithConstructors.cs │ │ ├── ArrangeAddRemove_When.cs │ │ ├── ArrangeAddRemove_WhenAny.cs │ │ ├── Indexer.test.cs │ │ ├── ReservedSymbols.test.cs │ │ ├── InheritSpecialized.cs │ │ ├── CantProcessSealedClass.test.cs │ │ ├── InheritSpecialized.test.cs │ │ ├── ArrangeSetter_When.test.cs │ │ ├── AssertSet.cs │ │ ├── ArrangeSetter.cs │ │ ├── AssertSet_WhenAny.cs │ │ ├── ObsoleteSupport.test.cs │ │ ├── MethodWithInParameter.test.cs │ │ ├── NestedClass.test.cs │ │ ├── MethodWithRefParameter.test.cs │ │ ├── NestedGenericClass.cs │ │ ├── InheritAbstractClass.test.cs │ │ ├── DontOverrideSupport.test.cs │ │ ├── AbstractClassWithEnumerableResult.cs │ │ ├── ArrangeSetter_WhenAny.test.cs │ │ ├── MethodWithOutParameter.test.cs │ │ ├── AbstractClassWithTaskMethod.test.cs │ │ ├── GenericAbstractClassWithGenericEvent.cs │ │ ├── AbstractClassWithEventSource.test.cs │ │ ├── AbstractClassWithGenericMethod.test.cs │ │ ├── DontOverrideSupport.cs │ │ ├── TypeCachingWithAbstractClass.cs │ │ ├── AbstractClassThrowsExceptionOnRefStruct.test.cs │ │ ├── GenerateForInternalClass.test.cs │ │ ├── GenericAbstractClassWithGenericEvent.test.cs │ │ ├── AbstractClassWithEventSourceAndMultipleNamespaces.cs │ │ ├── AbstractClassWithEnumerableResult.test.cs │ │ ├── GenericMockAndGenericAbstractClass.test.cs │ │ ├── AbstractClassWithConstructors.test.cs │ │ ├── AbstractClassWithEventSource.cs │ │ ├── NestedGenericClass.test.cs │ │ ├── InheritAbstractClass.cs │ │ ├── TypeCachingWithAbstractClass.test.cs │ │ ├── AbstractClassNotGenerated.test.cs │ │ ├── ArrangeAddRemove_WhenAny.test.cs │ │ ├── AbstractClassWithEventSourceAndMultipleNamespaces.test.cs │ │ ├── AssertSet.test.cs │ │ ├── AssertSet_WhenAny.test.cs │ │ ├── TypeCachingWithGenericAbstractClass.test.cs │ │ ├── TypeCachingWithGenericAbstractClass.cs │ │ ├── GenericMockAndGenericAbstractClass.cs │ │ ├── AbstractClassWithBasicMethods.cs │ │ ├── GenericAbstractClass.cs │ │ ├── RefReturn.test.cs │ │ ├── AbstractClassWithMultipleNamespaces.cs │ │ ├── AssertNoOtherCalls.test.cs │ │ ├── AbstractClassWithBasicProperty.cs │ │ ├── GenericAbstractClass.test.cs │ │ ├── AssertNoOtherCalls_Throws.test.cs │ │ ├── AbstractClassWithBasicMethods.test.cs │ │ ├── AssertNoOtherCalls.cs │ │ ├── AssertNoOtherCalls_Throws.cs │ │ ├── ArrangeSetter.test.cs │ │ ├── ArrangeAddRemove_When.test.cs │ │ ├── AbstractClassWithTaskMethod.cs │ │ ├── AbstractClassWithBasicProperty.test.cs │ │ ├── AbstractClassWithMultipleNamespaces.test.cs │ │ └── AbstractClassWithGenericMethod.cs │ ├── Interface │ │ ├── InterfaceNotGenerated.cs │ │ ├── Indexer.cs │ │ ├── MethodWithOutParameter.cs │ │ ├── ArrangeAddRemove_When.cs │ │ ├── MethodWithRefParameter.cs │ │ ├── ArrangeAddRemove_WhenAny.cs │ │ ├── RefReturn.cs │ │ ├── GenericInterfaceWithVariance.cs │ │ ├── AssertSet.cs │ │ ├── AssertSet_WhenAny.cs │ │ ├── InterfaceWithBasicProperty.cs │ │ ├── NestedInterface.cs │ │ ├── ArrangeSetter_When.cs │ │ ├── InterfaceWithBasicMethods.cs │ │ ├── TypeCachingWithGenericInterface.cs │ │ ├── TypeCachingWithInterface.cs │ │ ├── MethodWithInParameter.cs │ │ ├── ArrangeSetter.cs │ │ ├── GenericInterface.cs │ │ ├── InterfaceWithEventSource.cs │ │ ├── ArrangeSetter_WhenAny.cs │ │ ├── InterfaceWithTaskMethod.cs │ │ ├── InterfaceThrowsExceptionOnRefStruct.cs │ │ ├── AssertNoOtherCalls.cs │ │ ├── GenericInterfaceWithGenericEvent.cs │ │ ├── AssertNoOtherCalls_Throws.cs │ │ ├── GenericMockAndGenericInterface.cs │ │ ├── InterfaceWithEventSourceAndMultipleNamespaces.cs │ │ ├── Indexer.test.cs │ │ ├── ReservedSymbols.test.cs │ │ ├── InterfaceWithMultipleNamespaces.cs │ │ ├── AssertSet_WhenAny.test.cs │ │ ├── ArrangeSetter_When.test.cs │ │ ├── AssertNoOtherCalls.test.cs │ │ ├── InheritSpecialized.test.cs │ │ ├── InherittedInterface.test.cs │ │ ├── InterfaceWithEnumerableResult.cs │ │ ├── ArrangeAddRemove_When.test.cs │ │ ├── NestedGenericInterface.cs │ │ ├── ArrangeSetter_WhenAny.test.cs │ │ ├── MethodWithInParameter.test.cs │ │ ├── ArrangeAddRemove_WhenAny.test.cs │ │ ├── AssertNoOtherCalls_Throws.test.cs │ │ ├── GenericInterface.test.cs │ │ ├── MethodWithRefParameter.test.cs │ │ ├── InheritSpecialized.cs │ │ ├── NestedInterface.test.cs │ │ ├── InterfaceWithEventSource.test.cs │ │ ├── InterfaceWithBasicProperty.test.cs │ │ ├── InterfaceWithGenericMethod.test.cs │ │ ├── MethodWithOutParameter.test.cs │ │ ├── InterfaceWithTaskMethod.test.cs │ │ ├── InterfaceWithBasicMethods.test.cs │ │ ├── GenericInterfaceWithGenericEvent.test.cs │ │ ├── AssertSet.test.cs │ │ ├── GenericInterfaceWithVariance.test.cs │ │ ├── InterfaceThrowsExceptionOnRefStruct.test.cs │ │ ├── InterfaceWithGenericMethod.cs │ │ ├── InterfaceWithMultipleNamespaces.test.cs │ │ ├── InterfaceWithEnumerableResult.test.cs │ │ ├── GenericMockAndGenericInterface.test.cs │ │ ├── TypeCachingWithInterface.test.cs │ │ ├── InterfaceWithEventSourceAndMultipleNamespaces.test.cs │ │ ├── InterfaceNotGenerated.test.cs │ │ ├── NestedGenericInterface.test.cs │ │ ├── TypeCachingWithGenericInterface.test.cs │ │ ├── InherittedInterface.cs │ │ ├── ArrangeSetter.test.cs │ │ └── RefReturn.test.cs │ ├── Attributes │ │ ├── DisableCodeGeneration.cs │ │ ├── EnableCodeGeneration.test.cs │ │ └── DisableCodeGeneration.test.cs │ ├── Friends │ │ ├── IFoo.cs │ │ ├── FriendAssembly.test.cs │ │ └── SameAssembly.test.cs │ ├── Issues │ │ ├── HintNames.cs │ │ ├── TypeOrNamespaceCouldNotBeFound.test.cs │ │ ├── EnsureExceptionWhenMockIsMissing.cs │ │ ├── NamespacesIssue.cs │ │ ├── TypeKeyAttributeRemoved.cs │ │ ├── EnsureExceptionWhenMockIsMissing.test.cs │ │ ├── TypeKeyAttributeRemoved.test.cs │ │ ├── NamespacesIssue.test.cs │ │ └── HintNames.test.cs │ ├── TestAbstractions │ │ ├── ITestScript.cs │ │ ├── CompilationResult.cs │ │ ├── TestableSourceText.cs │ │ └── ValidProgramException.cs │ ├── Delegate │ │ ├── NestedDelegate.cs │ │ ├── GenericDelegate.cs │ │ ├── NestedDelegateWithGenerics.cs │ │ ├── BasicDelegate.test.cs │ │ ├── NestedDelegate.test.cs │ │ ├── GenericDelegate.test.cs │ │ ├── DelegateNotGenerated.test.cs │ │ └── NestedDelegateWithGenerics.test.cs │ ├── AnalyzerOptions │ │ ├── DisableCodeGeneration.cs │ │ └── DisableCodeGeneration.test.cs │ ├── BaseTests │ │ ├── IBaz.cs │ │ ├── IQuux.cs │ │ ├── BarMock.cs │ │ ├── TheTests.cs │ │ ├── PropMock.cs │ │ ├── ArgumentHelper_Tests.cs │ │ └── IFoo.cs │ ├── ExpressionReflect │ │ ├── Model │ │ │ ├── CustomStruct.cs │ │ │ ├── NameIndex.cs │ │ │ ├── CustomerExtensions.cs │ │ │ └── TestExtensionMethods.cs │ │ ├── ActionExtensions.cs │ │ ├── FuncExtensions.cs │ │ ├── ActionExecutionTests.cs │ │ ├── ConditionalTests.cs │ │ └── LICENSE │ ├── Mocks │ │ ├── MockAnalyzerConfigOptions.cs │ │ └── MockAnalyzerConfigOptionsProvider.cs │ ├── LightMock.Generator.Tests.csproj │ ├── Attributes_Test.cs │ └── LightMock.Generator.Tests.Roslyn40.csproj ├── LightMock.Generator.Common │ ├── CodeAnalysis │ │ ├── AllowNullAttribute.cs │ │ └── MayBeNullAttribute.cs │ ├── Preferences │ │ └── AssemblyInfo.cs │ ├── Generator │ │ ├── IRefReturnContext.cs │ │ ├── ILambdaToken.cs │ │ ├── TypeKeyAttribute.cs │ │ ├── Mock{T}.cs │ │ ├── OriginalNameAttribute.cs │ │ ├── TypeExtensions.cs │ │ ├── LambdaRequest.cs │ │ ├── Tags │ │ │ └── Tags.cs │ │ ├── IProtectedContext.cs │ │ ├── IDelegateProvider.cs │ │ ├── ILambdaRequest.cs │ │ └── AbstractMockNameofProvider.cs │ ├── ArgumentHelper.cs │ ├── PropertyArrangement.cs │ ├── ILockedCollection.cs │ ├── ExpressionReflect │ │ ├── ExpressionExtensions.cs │ │ └── ExpressionExecutionException.cs │ ├── IMatchInfo.cs │ └── LightMock.Generator.Common.csproj ├── Directory.Build.props ├── CodeCoverage.runsettings └── common.props └── LICENSE /release-notes.txt: -------------------------------------------------------------------------------- 1 | * fix: In version 1.2.3 .net 9 compatibility with ignore "allow net struct" on delegates -------------------------------------------------------------------------------- /src/LightMock.Generator/LightMock.Generator.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AbstractClassNotGenerated.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.AbstractClass 4 | { 5 | public abstract class AAbstractClassNotGenerated { } 6 | } 7 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/InterfaceNotGenerated.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.Interface 4 | { 5 | public interface IInterfaceNotGenerated 6 | { } 7 | 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/LightMock.Generator/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | 3 | [assembly: InternalsVisibleTo("LightMock.Generator.Tests")] 4 | [assembly: InternalsVisibleTo("LightMock.Generator.Tests.Roslyn40")] 5 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Attributes/DisableCodeGeneration.cs: -------------------------------------------------------------------------------- 1 | namespace LightMock.Generator.Tests.Attributes 2 | { 3 | public interface IDisableCodeGeneration 4 | { 5 | public string SomeProperty { get; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/Indexer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.Interface 4 | { 5 | public interface IIndexer 6 | { 7 | T this[int index] { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Friends/IFoo.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Friends 5 | { 6 | public interface IFoo 7 | { 8 | } 9 | } 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/MethodWithOutParameter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.Interface 4 | { 5 | public interface IMethodWithOutParameter 6 | { 7 | int Foo(out int bar); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/CantProcessSealedClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.AbstractClass 4 | { 5 | public sealed class SomeSealedClass 6 | { 7 | public void Foo() { } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/ArrangeAddRemove_When.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.Interface 4 | { 5 | public interface IArrangeAddRemove_When 6 | { 7 | event EventHandler EventHandler; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/MethodWithRefParameter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.Interface 4 | { 5 | public interface IMethodWithRefParameter 6 | { 7 | string Foo(ref string bar); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/Indexer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.AbstractClass 4 | { 5 | public abstract class AIndexer 6 | { 7 | public abstract T this[int index] { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/ArrangeAddRemove_WhenAny.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.Interface 4 | { 5 | public interface IArrangeAddRemove_WhenAny 6 | { 7 | event EventHandler EventHandler; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/RefReturn.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.Interface 4 | { 5 | public interface IRefReturn 6 | { 7 | ref string Foo(); 8 | ref readonly DateTime Bar(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/DontOverrideSupport.AssemblyInfo.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator; 2 | using LightMock.Generator.Tests.AbstractClass; 3 | 4 | [assembly: DontOverrideAttribute(typeof(SkipThisClass))] 5 | [assembly: DontOverrideAttribute(typeof(SkipThisClass))] -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/GenericInterfaceWithVariance.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.Interface 4 | { 5 | 6 | public interface IGenericInterfaceWithVariance 7 | { 8 | void Foo(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/MethodWithInParameter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.AbstractClass 4 | { 5 | public abstract class AMethodWithInParameter 6 | { 7 | public abstract string Foo(in string bar); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/MethodWithOutParameter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.AbstractClass 4 | { 5 | public abstract class AMethodWithOutParameter 6 | { 7 | public abstract int Foo(out int bar); 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/MethodWithRefParameter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.AbstractClass 4 | { 5 | public abstract class AMethodWithRefParameter 6 | { 7 | public abstract string Foo(ref string bar); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/AssertSet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.Interface 4 | { 5 | public interface IAssertSet 6 | { 7 | public string GetAndSet { get; set; } 8 | public string SetOnly { set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Common/CodeAnalysis/AllowNullAttribute.cs: -------------------------------------------------------------------------------- 1 | namespace System.Diagnostics.CodeAnalysis 2 | { 3 | [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)] 4 | internal sealed class AllowNullAttribute : Attribute { } 5 | } 6 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/AssertSet_WhenAny.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.Interface 4 | { 5 | public interface IAssertSet_WhenAny 6 | { 7 | public string GetAndSet { get; set; } 8 | public string SetOnly { set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/InterfaceWithBasicProperty.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.Interface 4 | { 5 | public interface IInterfaceWithBasicProperty 6 | { 7 | int OnlyGet { get; } 8 | int GetAndSet { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/NestedInterface.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.Interface 4 | { 5 | public interface INestedInterface 6 | { 7 | public interface ITest 8 | { 9 | void Foo(); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/ArrangeSetter_When.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.Interface 4 | { 5 | public interface IArrangeSetter_When 6 | { 7 | public string GetAndSet { get; set; } 8 | public string SetOnly { set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/InterfaceWithBasicMethods.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.Interface 4 | { 5 | public interface IInterfaceWithBasicMethods 6 | { 7 | void DoSomething(int someParam); 8 | int ReturnSomething(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/TypeCachingWithGenericInterface.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.Interface 4 | { 5 | public interface ITypeCachingWithGenericInterface 6 | { 7 | T GetSomething(); 8 | void DoSomething(T p); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/TypeCachingWithInterface.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.Interface 4 | { 5 | public interface ITypeCachingWithInterface 6 | { 7 | void DoSomething(int someParam); 8 | int ReturnSomething(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Issues/HintNames.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.Issues 4 | { 5 | public interface IHintNames { } 6 | public interface IHintNames { } 7 | public abstract class AHintNames { } 8 | public abstract class AHintNames { } 9 | } 10 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/RefReturn.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.AbstractClass 4 | { 5 | public abstract class ARefReturn 6 | { 7 | public abstract ref string Foo(); 8 | public abstract ref readonly DateTime Bar(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/MethodWithInParameter.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public interface IMethodWithInParameter 7 | { 8 | string Foo(in string bar); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/LightMock.Generator/AnalyzerReleases.Unshipped.md: -------------------------------------------------------------------------------- 1 | ; Unshipped analyzer release 2 | ; https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md 3 | ### New Rules 4 | Rule ID | Category | Severity | Notes 5 | --------|----------|----------|------- 6 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/NestedClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.AbstractClass 4 | { 5 | public class XNestedClass 6 | { 7 | public abstract class ATest 8 | { 9 | public abstract void Foo(); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/TestAbstractions/ITestScript.cs: -------------------------------------------------------------------------------- 1 | namespace LightMock.Generator.Tests.TestAbstractions 2 | { 3 | public interface ITestScript 4 | where T : class 5 | { 6 | IMock Context { get; } 7 | T MockObject { get; } 8 | 9 | int DoRun(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Delegate/NestedDelegate.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Delegate 5 | { 6 | public class XNestedDelegate 7 | { 8 | public delegate void SomeDelegate(object sender, int args); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AnalyzerOptions/DisableCodeGeneration.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.AnalyzerOptions 5 | { 6 | public interface IDisableCodeGeneration 7 | { 8 | public string SomeProperty { get; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/BaseTests/IBaz.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.BaseTests 4 | { 5 | interface IBaz 6 | { 7 | void Method(); 8 | void Method(int a); 9 | int Func(); 10 | int Func(int a); 11 | int Property { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/BaseTests/IQuux.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.BaseTests 4 | { 5 | interface IQuux 6 | { 7 | void Method(); 8 | void Method(int a); 9 | int Func(); 10 | int Func(int a); 11 | int Property { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/ArrangeSetter.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public interface IArrangeSetter 7 | { 8 | string GetAndSet { get; set; } 9 | string Set { set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/TestAbstractions/CompilationResult.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis; 2 | using System; 3 | using System.Collections.Immutable; 4 | 5 | namespace LightMock.Generator.Tests.TestAbstractions 6 | { 7 | public record class CompilationResult(ImmutableArray diagnostics, bool success, byte[] assembly); 8 | } 9 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Common/Preferences/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | 3 | [assembly:InternalsVisibleTo("LightMock.Generator")] 4 | [assembly:InternalsVisibleTo("LightMock.Generator.v40")] 5 | [assembly:InternalsVisibleTo("LightMock.Generator.Tests")] 6 | [assembly:InternalsVisibleTo("LightMock.Generator.Tests.Roslyn40")] -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/GenericInterface.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.Interface 4 | { 5 | public interface IGenericInterface 6 | { 7 | T OnlyGet { get; } 8 | T GetAndSet { get; set; } 9 | T GetSomething(); 10 | void DoSomething(T p); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/InterfaceWithEventSource.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.Interface 4 | { 5 | public delegate void EventHandler(object source, T data); 6 | 7 | public interface IInterfaceWithEventSource 8 | { 9 | event EventHandler OnEvent; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/ArrangeSetter_WhenAny.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public interface IArrangeSetter_WhenAny 7 | { 8 | string GetAndSet { get; set; } 9 | string SetOnly { set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Issues/TypeOrNamespaceCouldNotBeFound.test.cs: -------------------------------------------------------------------------------- 1 | namespace LightMock.Generator.Tests.Issues 2 | { 3 | public class TypeOrNamespaceCouldNotBeFound 4 | { 5 | public void Foo() 6 | { 7 | var mock = new Mock(); 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/TestAbstractions/TestableSourceText.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace LightMock.Generator.Tests.TestAbstractions 8 | { 9 | public record TestableSourceText(string sourceCode, string hint); 10 | } 11 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/InterfaceWithTaskMethod.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public interface IInterfaceWithTaskMethod 7 | { 8 | Task FooAsync(); 9 | Task BarAsync(); 10 | Task BazAsync(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Delegate/GenericDelegate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.Delegate 4 | { 5 | public delegate TResult SomeGenericDelegate(T1 a1, T2 a2, T3 a3) 6 | where T1 : class 7 | where T2 : struct, IEquatable 8 | where T3 : IEquatable; 9 | } 10 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/ExpressionReflect/Model/CustomStruct.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.ExpressionReflect.Model 4 | { 5 | struct CustomStruct 6 | { 7 | private readonly int value; 8 | 9 | public CustomStruct(int value) => this.value = value; 10 | 11 | public int Value => this.value; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/InterfaceThrowsExceptionOnRefStruct.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | 7 | public interface IInterfaceThrowsExceptionOnRefStruct 8 | { 9 | void Foo(Span span); 10 | void Bar(Span span); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Common/CodeAnalysis/MayBeNullAttribute.cs: -------------------------------------------------------------------------------- 1 | namespace System.Diagnostics.CodeAnalysis 2 | { 3 | [AttributeUsage(AttributeTargets.Field 4 | | AttributeTargets.Parameter 5 | | AttributeTargets.Property 6 | | AttributeTargets.ReturnValue, 7 | Inherited = false)] 8 | internal sealed class MaybeNullAttribute : Attribute 9 | { } 10 | } -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Issues/EnsureExceptionWhenMockIsMissing.cs: -------------------------------------------------------------------------------- 1 | namespace LightMock.Generator.Tests.Issues 2 | { 3 | public interface IEnsureExceptionWhenMockIsMissingBase 4 | { 5 | void Foo(); 6 | } 7 | 8 | public interface IEnsureExceptionWhenMockIsMissing : IEnsureExceptionWhenMockIsMissingBase 9 | { 10 | void Bar(); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/ArrangeSetter_When.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.AbstractClass 4 | { 5 | public abstract class AArrangeSetter_When 6 | { 7 | protected AArrangeSetter_When(object a1, int a2) { } 8 | 9 | public abstract string GetAndSet { get; set; } 10 | public abstract string SetOnly { set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AbstractClassThrowsExceptionOnRefStruct.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public abstract class AAbstractClassThrowsExceptionOnRefStruct 7 | { 8 | public abstract void Foo(Span span); 9 | public abstract void Bar(Span span); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Delegate/NestedDelegateWithGenerics.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.Delegate 4 | { 5 | public interface XNestedInterface 6 | where T1: struct, IEquatable 7 | { 8 | public interface XContainer 9 | { 10 | public delegate void SomeDelegate(T1 a1, T2 a2, T3 a3) 11 | where T3 : class; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/ExpressionReflect/Model/NameIndex.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.ExpressionReflect.Model 4 | { 5 | sealed class NameIndex 6 | { 7 | private readonly string[] names; 8 | 9 | public NameIndex(params string[] names) 10 | { 11 | this.names = names; 12 | } 13 | 14 | public int this[string name] 15 | { 16 | get { return name.IndexOf(name); } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/ArrangeSetter_WhenAny.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public abstract class AArrangeSetter_WhenAny 7 | { 8 | protected AArrangeSetter_WhenAny(object a1, int a2, IEnumerable a3) { } 9 | 10 | public abstract string GetAndSet { get; set; } 11 | public abstract string SetOnly { set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/AssertNoOtherCalls.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.Interface 4 | { 5 | public interface IAssertNoOtherCalls 6 | { 7 | string GetOnly { get; } 8 | string SetOnly { set; } 9 | string GetAndSet { get; set; } 10 | string Function(string a); 11 | void Method(string a); 12 | string this[string index] { get; set; } 13 | event EventHandler EventHandler; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Issues/NamespacesIssue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Playground 4 | { 5 | public interface IFoo 6 | { 7 | void Bar(); 8 | } 9 | 10 | public interface IFoo 11 | { 12 | void Bar(); 13 | } 14 | 15 | public abstract class AFoo 16 | { 17 | public abstract void Bar(); 18 | } 19 | 20 | public abstract class AFoo 21 | { 22 | public abstract void Bar(); 23 | } 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/ObsoleteSupport.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.AbstractClass 4 | { 5 | public abstract class AObsoleteSupport 6 | { 7 | [Obsolete] 8 | public virtual void Foo() { } 9 | [Obsolete] 10 | public virtual int Bar { get; set; } 11 | [Obsolete] 12 | protected virtual void Baz() { } 13 | [Obsolete] 14 | protected virtual int Quux { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/GenericInterfaceWithGenericEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace LightMock.Generator.Tests.Interface 8 | { 9 | public delegate void EventHandlerGenericClass(object source, T data); 10 | 11 | public interface IGenericInterfaceWithGenericEvent 12 | { 13 | event EventHandlerGenericClass OnEvent; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/AssertNoOtherCalls_Throws.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.Interface 4 | { 5 | public interface IAssertNoOtherCalls_Throws 6 | { 7 | string GetOnly { get; } 8 | string SetOnly { set; } 9 | string GetAndSet { get; set; } 10 | string Function(string a); 11 | void Method(string a); 12 | string this[string index] { get; set; } 13 | event EventHandler EventHandler; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/GenericMockAndGenericInterface.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public interface IGenericMockAndGenericInterface 7 | where T : struct, IComparable 8 | { 9 | T OnlyGet { get; } 10 | T GetAndSet { get; set; } 11 | T GetSomething(); 12 | void DoSomething(T p); 13 | Task FooAsync() where TResult : class; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/InterfaceWithEventSourceAndMultipleNamespaces.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.Interface.EventNamespace1 4 | { 5 | public delegate void EventHandler(object source, T data); 6 | } 7 | 8 | 9 | namespace LightMock.Generator.Tests.Interface.EventNamespace2 10 | { 11 | using EventNamespace1; 12 | 13 | public interface IInterfaceWithEventSourceAndMultipleNamespaces 14 | { 15 | event EventHandler OnEvent; 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AbstractClassWithConstructors.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading.Tasks; 4 | 5 | namespace LightMock.Generator.Tests.AbstractClass 6 | { 7 | public abstract class AAbstractClassWithConstructors 8 | { 9 | public AAbstractClassWithConstructors(int param1, IEnumerable param2) 10 | { } 11 | 12 | protected AAbstractClassWithConstructors(Task param1) 13 | { } 14 | 15 | 16 | public abstract void DoSomething(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Friends/FriendAssembly.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Friends 5 | { 6 | public class FriendAssembly : ITestScript 7 | { 8 | public IMock Context => throw new NotImplementedException(); 9 | 10 | public IFoo MockObject => throw new NotImplementedException(); 11 | 12 | public int DoRun() 13 | { 14 | var mock = new Mock(); 15 | return 42; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/ArrangeAddRemove_When.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.AbstractClass 4 | { 5 | public abstract class AArrangeAddRemove_When 6 | { 7 | public abstract event EventHandler EventHandler; 8 | protected abstract event EventHandler ProtectedEventHandler; 9 | 10 | public event EventHandler InvokeProtectedEventHandler 11 | { 12 | add => ProtectedEventHandler += value; 13 | remove => ProtectedEventHandler -= value; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/ArrangeAddRemove_WhenAny.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.AbstractClass 4 | { 5 | public abstract class AArrangeAddRemove_WhenAny 6 | { 7 | public abstract event EventHandler EventHandler; 8 | protected abstract event EventHandler ProtectedEventHandler; 9 | 10 | public event EventHandler InvokeProtectedEventHandler 11 | { 12 | add => ProtectedEventHandler += value; 13 | remove => ProtectedEventHandler -= value; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/Indexer.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public class Indexer : ITestScript> 7 | { 8 | private readonly Mock> mock; 9 | 10 | public Indexer() => mock = new Mock>(); 11 | 12 | public IMock> Context => mock; 13 | 14 | public IIndexer MockObject => mock.Object; 15 | 16 | public int DoRun() => 42; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | obj/$(MSBuildProjectName) 5 | $(DefaultItemExcludes);obj/** 6 | bin/$(Configuration)/$(TargetFramework)/$(MSBuildProjectName) 7 | 8 | NU5127,NU5128 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/Indexer.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public class Indexer : ITestScript> 7 | { 8 | private readonly Mock> mock; 9 | 10 | public Indexer() => mock = new Mock>(); 11 | 12 | public IMock> Context => mock; 13 | 14 | public AIndexer MockObject => mock.Object; 15 | 16 | public int DoRun() => 42; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Issues/TypeKeyAttributeRemoved.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.Issues 4 | { 5 | public abstract class ATypeKeyAttributeRemoved 6 | { 7 | public abstract void Foo(); 8 | } 9 | 10 | public abstract class ATypeKeyAttributeRemoved 11 | { 12 | public abstract void Foo(T bar); 13 | } 14 | 15 | public interface ITypeKeyAttributeRemoved 16 | { 17 | void Foo(); 18 | } 19 | 20 | public interface ITypeKeyAttributeRemoved 21 | { 22 | void Foo(T bar); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/ReservedSymbols.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public class ReservedSymbols : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public ReservedSymbols() => mock = new Mock(); 11 | 12 | public IMock Context => mock; 13 | 14 | public IReservedSymbols MockObject => mock.Object; 15 | 16 | public int DoRun() => 42; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/InterfaceWithMultipleNamespaces.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.Interface.Namespace1 4 | { 5 | public class MultipleNamespacesArgument 6 | { } 7 | } 8 | 9 | 10 | namespace LightMock.Generator.Tests.Interface.Namespace2 11 | { 12 | using Namespace1; 13 | 14 | public interface IInterfaceWithMultipleNamespaces 15 | { 16 | void DoSomething(MultipleNamespacesArgument someClass); 17 | MultipleNamespacesArgument GetSomething(); 18 | MultipleNamespacesArgument SomeProperty { get; set; } 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/ReservedSymbols.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public class ReservedSymbols : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public ReservedSymbols() => mock = new Mock(); 11 | 12 | public IMock Context => mock; 13 | 14 | public AReservedSymbols MockObject => mock.Object; 15 | 16 | public int DoRun() => 42; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/BaseTests/BarMock.cs: -------------------------------------------------------------------------------- 1 | namespace LightMock.Generator.Tests.BaseTests 2 | { 3 | public class BarMock : IBar 4 | { 5 | private readonly IInvocationContext context; 6 | 7 | public BarMock(IInvocationContext context) 8 | { 9 | this.context = context; 10 | } 11 | 12 | public void Execute(string value) 13 | { 14 | context.Invoke(f => f.Execute(value)); 15 | } 16 | 17 | public string? Execute() 18 | { 19 | return context.Invoke(f => f.Execute()); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/ExpressionReflect/Model/CustomerExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace LightMock.Generator.Tests.ExpressionReflect.Model 8 | { 9 | static class CustomerExtensions 10 | { 11 | public static int GetDefaultAgeEx(this Customer customer, int value) 12 | { 13 | return Customer.AgeConstant + value; 14 | } 15 | 16 | public static int GetDefaultAgeEx(this Customer customer) 17 | { 18 | return customer.Age + Customer.AgeConstant; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/AssertSet_WhenAny.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public class AssertSet_WhenAny : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public AssertSet_WhenAny() => mock = new Mock(); 11 | 12 | public IMock Context => mock; 13 | 14 | public IAssertSet_WhenAny MockObject => mock.Object; 15 | 16 | public int DoRun() => 42; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/InheritSpecialized.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.AbstractClass 4 | { 5 | public sealed class SpecializationTag { } 6 | 7 | public abstract class AInheritSpecialized 8 | { 9 | public abstract T Function(); 10 | public abstract void Action(T a); 11 | public abstract T Property { get; set; } 12 | } 13 | 14 | public abstract class AInheritSpecialized : AInheritSpecialized 15 | { 16 | public abstract string Foo(); 17 | public abstract void Bar(string a); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/ExpressionReflect/ActionExtensions.cs: -------------------------------------------------------------------------------- 1 | #nullable disable 2 | using System; 3 | using System.Linq.Expressions; 4 | using global::ExpressionReflect; 5 | 6 | namespace LightMock.Generator.Tests.ExpressionReflect 7 | { 8 | static class ActionExtensions 9 | { 10 | public static Action Reflect(this Expression target) 11 | { 12 | Action action = () => target.Execute(); 13 | return action; 14 | } 15 | 16 | public static Action Reflect(this Expression> target) 17 | { 18 | Action action = a => target.Execute(a); 19 | return action; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/ArrangeSetter_When.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public class ArrangeSetter_When : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public ArrangeSetter_When() => mock = new Mock(); 11 | 12 | public IMock Context => mock; 13 | 14 | public IArrangeSetter_When MockObject => mock.Object; 15 | 16 | public int DoRun() => 42; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/AssertNoOtherCalls.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public class AssertNoOtherCalls : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public AssertNoOtherCalls() => mock = new Mock(); 11 | 12 | public IMock Context => mock; 13 | 14 | public IAssertNoOtherCalls MockObject => mock.Object; 15 | 16 | public int DoRun() => 42; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/InheritSpecialized.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public sealed class InheritSpecialized : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public InheritSpecialized() => mock = new Mock(); 11 | 12 | public IMock Context => mock; 13 | 14 | public IInheritSpecialized MockObject => mock.Object; 15 | 16 | public int DoRun() => 42; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/InherittedInterface.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using LightMock.Generator.Tests.TestAbstractions; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public class InherittedInterface : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public InherittedInterface() => mock = new Mock(); 11 | 12 | public IMock Context => mock; 13 | 14 | public IInherittedInterface MockObject => mock.Object; 15 | 16 | public int DoRun() => 42; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/InterfaceWithEnumerableResult.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Threading.Tasks; 5 | 6 | namespace LightMock.Generator.Tests.Interface 7 | { 8 | public interface IInterfaceWithEnumerableResult 9 | { 10 | IEnumerable CollectionProperty { get; } 11 | IEnumerable GetCollection(); 12 | IEnumerable GetGenericCollection(); 13 | Task> GetCollectionAsync(); 14 | Task> GetGenericCollectionAsync(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Common/Generator/IRefReturnContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Text; 5 | 6 | namespace LightMock.Generator 7 | { 8 | /// 9 | /// For internal usage 10 | /// 11 | [EditorBrowsable(EditorBrowsableState.Never)] 12 | public interface IRefReturnContext 13 | where T : class 14 | { 15 | /// 16 | /// For internal usage 17 | /// 18 | [EditorBrowsable(EditorBrowsableState.Never)] 19 | object RefReturnContext { get; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/CantProcessSealedClass.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using LightMock.Generator.Tests.TestAbstractions; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public class CantProcessSealedClass : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public CantProcessSealedClass() 11 | => mock = new Mock(); 12 | 13 | public IMock Context => mock; 14 | 15 | public SomeSealedClass MockObject => mock.Object; 16 | 17 | public int DoRun() => 42; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/InheritSpecialized.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public sealed class InheritSpecialized : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public InheritSpecialized() => mock = new Mock(); 11 | 12 | public IMock Context => mock; 13 | 14 | public AInheritSpecialized MockObject => mock.Object; 15 | 16 | public int DoRun() => 42; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Delegate/BasicDelegate.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using LightMock.Generator.Tests.TestAbstractions; 3 | 4 | namespace LightMock.Generator.Tests.Delegate 5 | { 6 | public class BasicDelegate : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public BasicDelegate() 11 | => mock = new Mock(); 12 | 13 | public IMock Context => mock; 14 | 15 | public EventHandler MockObject => mock.Object; 16 | 17 | public int DoRun() 18 | { 19 | return 42; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/ArrangeAddRemove_When.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public class ArrangeAddRemove_When : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public ArrangeAddRemove_When() => mock = new Mock(); 11 | public IMock Context => mock; 12 | 13 | public IArrangeAddRemove_When MockObject => mock.Object; 14 | 15 | public int DoRun() => 42; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/NestedGenericInterface.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.Interface 4 | { 5 | public interface INestedGenericInterface 6 | where T1 : struct, IEquatable 7 | { 8 | public interface IContainingInterface 9 | { 10 | public interface ITest 11 | where T3 : class, IFoo 12 | { 13 | T1 Foo(T2? p); 14 | T1 Bar(T2? p) 15 | where T4 : IEquatable; 16 | 17 | T2 Baz(T3? p); 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Common/Generator/ILambdaToken.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Linq.Expressions; 4 | 5 | namespace LightMock.Generator 6 | { 7 | /// 8 | /// For internal usage 9 | /// 10 | [EditorBrowsable(EditorBrowsableState.Never)] 11 | public interface ILambdaToken 12 | { 13 | /// 14 | /// For internal usage 15 | /// 16 | public string Key { get; } 17 | /// 18 | /// For internal usage 19 | /// 20 | public LambdaExpression Value { get; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/ArrangeSetter_When.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public class ArrangeSetter_When : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public ArrangeSetter_When() => mock = new Mock(new object(), 1234); 11 | 12 | public IMock Context => mock; 13 | 14 | public AArrangeSetter_When MockObject => mock.Object; 15 | 16 | public int DoRun() => 42; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/ArrangeSetter_WhenAny.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public class ArrangeSetter_WhenAny : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public ArrangeSetter_WhenAny() => mock = new Mock(); 11 | 12 | public IMock Context => mock; 13 | 14 | public IArrangeSetter_WhenAny MockObject => mock.Object; 15 | 16 | public int DoRun() => 42; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AssertSet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.AbstractClass 4 | { 5 | public abstract class AAssertSet 6 | { 7 | public abstract string GetAndSet { get; set; } 8 | public abstract string SetOnly { set; } 9 | 10 | protected abstract string ProtectedGetAndSet { get; set; } 11 | protected abstract string ProtectedSetOnly { set; } 12 | 13 | public string InvokeProtectedGetAndSet { get => ProtectedGetAndSet; set => ProtectedGetAndSet = value; } 14 | public string InvokeProtectedSetOnly { set => ProtectedSetOnly = value; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Attributes/EnableCodeGeneration.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Attributes 5 | { 6 | public class DisableCodeGeneration : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public DisableCodeGeneration() => mock = new Mock(); 11 | 12 | public IMock Context => mock; 13 | 14 | public IDisableCodeGeneration MockObject => mock.Object; 15 | 16 | public int DoRun() => 42; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AnalyzerOptions/DisableCodeGeneration.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.AnalyzerOptions 5 | { 6 | public class DisableCodeGeneration : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public DisableCodeGeneration() => mock = new Mock(); 11 | 12 | public IMock Context => mock; 13 | 14 | public IDisableCodeGeneration MockObject => mock.Object; 15 | 16 | public int DoRun() => 42; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/MethodWithInParameter.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public class MethodWithInParameter : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public MethodWithInParameter() 11 | => mock = new Mock(); 12 | 13 | public IMock Context => mock; 14 | 15 | public IMethodWithInParameter MockObject => mock.Object; 16 | 17 | public int DoRun() => 42; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/ArrangeSetter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.AbstractClass 4 | { 5 | public abstract class AArrangeSetter 6 | { 7 | public abstract string GetAndSet { get; set; } 8 | public abstract string SetOnly { set; } 9 | 10 | protected abstract string ProtectedGetAndSet { get; set; } 11 | protected abstract string ProtectedSetOnly { set; } 12 | 13 | public string InvokeProtectedGetAndSet { get => ProtectedGetAndSet; set => ProtectedGetAndSet = value; } 14 | public string InvokeProtectedSetOnly { set => ProtectedSetOnly = value; } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AssertSet_WhenAny.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.AbstractClass 4 | { 5 | public abstract class AAssertSet_WhenAny 6 | { 7 | public abstract string GetAndSet { get; set; } 8 | public abstract string SetOnly { set; } 9 | 10 | protected abstract string ProtectedGetAndSet { get; set; } 11 | protected abstract string ProtectedSetOnly { set; } 12 | 13 | public string InvokeProtectedGetAndSet { get => ProtectedGetAndSet; set => ProtectedGetAndSet = value; } 14 | public string InvokeProtectedSetOnly { set => ProtectedSetOnly = value; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/ObsoleteSupport.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | class ObsoleteSupport : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public ObsoleteSupport() 11 | => mock = new Mock(); 12 | 13 | public IMock Context => mock; 14 | 15 | public AObsoleteSupport MockObject => mock.Object; 16 | 17 | public int DoRun() 18 | { 19 | return 42; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/ArrangeAddRemove_WhenAny.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public class ArrangeAddRemove_WhenAny : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public ArrangeAddRemove_WhenAny() => mock = new Mock(); 11 | 12 | public IMock Context => mock; 13 | 14 | public IArrangeAddRemove_WhenAny MockObject => mock.Object; 15 | 16 | public int DoRun() => 42; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/MethodWithInParameter.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public class MethodWithInParameter : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public MethodWithInParameter() 11 | => mock = new Mock(); 12 | 13 | public IMock Context => mock; 14 | 15 | public AMethodWithInParameter MockObject => mock.Object; 16 | 17 | public int DoRun() => 42; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/NestedClass.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public class NestedClass : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public NestedClass() 11 | => mock = new Mock(); 12 | 13 | public IMock Context => mock; 14 | 15 | public XNestedClass.ATest MockObject => mock.Object; 16 | 17 | public int DoRun() 18 | { 19 | return 42; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/AssertNoOtherCalls_Throws.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public class AssertNoOtherCalls_Throws : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public AssertNoOtherCalls_Throws() => mock = new Mock(); 11 | public IMock Context => mock; 12 | 13 | public IAssertNoOtherCalls_Throws MockObject => mock.Object; 14 | 15 | public int DoRun() => 42; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/GenericInterface.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using LightMock.Generator.Tests.TestAbstractions; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public class GenericInterface : ITestScript> 7 | { 8 | private readonly Mock> mock; 9 | 10 | public GenericInterface() 11 | { 12 | mock = new Mock>(); 13 | } 14 | 15 | public IMock> Context => mock; 16 | 17 | public IGenericInterface MockObject => mock.Object; 18 | 19 | public int DoRun() => 42; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/MethodWithRefParameter.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public class MethodWithRefParameter : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public MethodWithRefParameter() 11 | => mock = new Mock(); 12 | 13 | public IMock Context => mock; 14 | 15 | public IMethodWithRefParameter MockObject => mock.Object; 16 | 17 | public int DoRun() => 42; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/LightMock.Generator/RefReturnVisitor.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace LightMock.Generator 7 | { 8 | sealed class RefReturnVisitor : SymbolVisitor 9 | { 10 | public override string? VisitMethod(IMethodSymbol symbol) 11 | { 12 | if (symbol.ReturnsByRef || symbol.ReturnsByRefReadonly) 13 | { 14 | var result = symbol.ToDisplayString(SymbolDisplayFormats.KRefReturnInterfaceDeclaration) + ";"; 15 | return result; 16 | } 17 | return ""; 18 | } 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/MethodWithRefParameter.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public class MethodWithRefParameter : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public MethodWithRefParameter() 11 | => mock = new Mock(); 12 | 13 | public IMock Context => mock; 14 | 15 | public AMethodWithRefParameter MockObject => mock.Object; 16 | 17 | public int DoRun() => 42; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/NestedGenericClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.AbstractClass 4 | { 5 | public abstract class ANestedGenericClass 6 | where T1 : struct, IEquatable 7 | { 8 | public abstract class AContainingClass 9 | { 10 | public abstract class ATest 11 | where T3 : class 12 | { 13 | public abstract T1 Foo(T2? p); 14 | public abstract T1 Bar(T2? p) 15 | where T4 : IEquatable; 16 | 17 | public abstract T2 Baz(T3? p); 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/ExpressionReflect/FuncExtensions.cs: -------------------------------------------------------------------------------- 1 | #nullable disable 2 | using System; 3 | using System.Linq.Expressions; 4 | using global::ExpressionReflect; 5 | 6 | namespace LightMock.Generator.Tests.ExpressionReflect 7 | { 8 | static class FuncExtensions 9 | { 10 | public static Func Reflect(this Expression> target) 11 | { 12 | Func func = () => (TResult)target.Execute()!; 13 | return func; 14 | } 15 | 16 | public static Func Reflect(this Expression> target) 17 | { 18 | Func func = a => (TResult)target.Execute(a); 19 | return func; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/InheritSpecialized.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public sealed class SpecializationTag { } 7 | 8 | public interface IInheritSpecialized2 : ICollection, IEnumerable 9 | { 10 | T Function(); 11 | void Action(T a); 12 | T Property { get; set; } 13 | } 14 | 15 | public interface IInheritSpecialized : IInheritSpecialized2, ICollection, IEnumerable 16 | { 17 | string Foo(); 18 | void Bar(string a); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/InheritAbstractClass.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using LightMock.Generator.Tests.TestAbstractions; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public class InheritAbstractClass : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public InheritAbstractClass() => mock = new Mock(); 11 | 12 | public IMock Context => mock; 13 | 14 | public AInheritAbstractClass MockObject => mock.Object; 15 | 16 | public int DoRun() 17 | { 18 | return 42; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/NestedInterface.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public class NestedInterface : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public NestedInterface() 11 | => mock = new Mock(); 12 | 13 | public IMock Context => mock; 14 | 15 | public INestedInterface.ITest MockObject => mock.Object; 16 | 17 | public int DoRun() 18 | { 19 | return 42; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Common/Generator/TypeKeyAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LightMock.Generator 6 | { 7 | /// 8 | /// For internal usage 9 | /// 10 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] 11 | public class TypeKeyAttribute : Attribute 12 | { 13 | /// 14 | /// For internal usage 15 | /// 16 | public TypeKeyAttribute(Type key) => Key = key; 17 | 18 | /// 19 | /// For internal usage 20 | /// 21 | public Type Key { get; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/DontOverrideSupport.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public class DontOverrideSupport : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public DontOverrideSupport() 11 | => mock = new Mock(); 12 | 13 | public IMock Context => mock; 14 | 15 | public ADontOverrideSupport MockObject => mock.Object; 16 | 17 | public int DoRun() 18 | { 19 | return 42; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Issues/EnsureExceptionWhenMockIsMissing.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | 3 | namespace LightMock.Generator.Tests.Issues 4 | { 5 | public class EnsureExceptionWhenMockIsMissing : ITestScript 6 | { 7 | private readonly Mock mock; 8 | 9 | public EnsureExceptionWhenMockIsMissing() => mock = new Mock(); 10 | 11 | public IMock Context => mock; 12 | 13 | public IEnsureExceptionWhenMockIsMissing MockObject => mock.Object; 14 | 15 | public int DoRun() => 42; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/InterfaceWithEventSource.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using LightMock.Generator.Tests.TestAbstractions; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public class InterfaceWithEventSource : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public InterfaceWithEventSource() 11 | { 12 | mock = new Mock(); 13 | } 14 | 15 | public IMock Context => mock; 16 | 17 | public IInterfaceWithEventSource MockObject => mock.Object; 18 | 19 | public int DoRun() => 42; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/CodeCoverage.runsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | cobertura 9 | [xunit.*]*,[*Tests]* 10 | Obsolete,GeneratedCodeAttribute,CompilerGeneratedAttribute 11 | false 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Delegate/NestedDelegate.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Delegate 5 | { 6 | public class NestedDelegate : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public NestedDelegate() 11 | => mock = new Mock(); 12 | 13 | public IMock Context => mock; 14 | 15 | public XNestedDelegate.SomeDelegate MockObject => mock.Object; 16 | 17 | public int DoRun() 18 | { 19 | return 42; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AbstractClassWithEnumerableResult.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Threading.Tasks; 5 | 6 | namespace LightMock.Generator.Tests.AbstractClass 7 | { 8 | public abstract class AAbstractClassWithEnumerableResult 9 | { 10 | public abstract IEnumerable CollectionProperty { get; } 11 | public abstract IEnumerable GetCollection(); 12 | public abstract IEnumerable GetGenericCollection(); 13 | public abstract Task> GetCollectionAsync(); 14 | public abstract Task> GetGenericCollectionAsync(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/InterfaceWithBasicProperty.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using LightMock.Generator.Tests.TestAbstractions; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public class InterfaceWithBasicProperty : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public InterfaceWithBasicProperty() 11 | { 12 | mock = new Mock(); 13 | } 14 | 15 | public IMock Context => mock; 16 | 17 | public IInterfaceWithBasicProperty MockObject => mock.Object; 18 | 19 | public int DoRun() => 42; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/InterfaceWithGenericMethod.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using LightMock.Generator.Tests.TestAbstractions; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public class InterfaceWithGenericMethod : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public InterfaceWithGenericMethod() 11 | { 12 | mock = new Mock(); 13 | } 14 | 15 | public IMock Context => mock; 16 | 17 | public IInterfaceWithGenericMethod MockObject => mock.Object; 18 | 19 | public int DoRun() => 42; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Attributes/DisableCodeGeneration.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using LightMock.Generator; 3 | using System; 4 | 5 | [assembly: DisableCodeGeneration] 6 | 7 | namespace LightMock.Generator.Tests.Attributes 8 | { 9 | public class DisableCodeGeneration : ITestScript 10 | { 11 | private readonly Mock mock; 12 | 13 | public DisableCodeGeneration() => mock = new Mock(); 14 | 15 | public IMock Context => mock; 16 | 17 | public IDisableCodeGeneration MockObject => mock.Object; 18 | 19 | public int DoRun() => 42; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/ArrangeSetter_WhenAny.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace LightMock.Generator.Tests.AbstractClass 6 | { 7 | public class ArrangeSetter_WhenAny : ITestScript 8 | { 9 | private readonly Mock mock; 10 | 11 | public ArrangeSetter_WhenAny() => mock = new Mock(new object(), 1234, (IEnumerable)null!); 12 | 13 | public IMock Context => mock; 14 | 15 | public AArrangeSetter_WhenAny MockObject => mock.Object; 16 | 17 | public int DoRun() => 42; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/MethodWithOutParameter.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public sealed class MethodWithOutParameter : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public MethodWithOutParameter() 11 | => mock = new Mock(); 12 | 13 | public IMock Context => mock; 14 | 15 | public AMethodWithOutParameter MockObject => mock.Object; 16 | 17 | public int DoRun() 18 | { 19 | return 42; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Delegate/GenericDelegate.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using LightMock.Generator.Tests.TestAbstractions; 3 | 4 | namespace LightMock.Generator.Tests.Delegate 5 | { 6 | public class GenericDelegate : ITestScript> 7 | { 8 | private readonly Mock> mock; 9 | 10 | public GenericDelegate() 11 | => mock = new Mock>(); 12 | 13 | public IMock> Context => mock; 14 | 15 | public SomeGenericDelegate MockObject => mock.Object; 16 | 17 | public int DoRun() => 42; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/MethodWithOutParameter.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using LightMock.Generator.Tests.TestAbstractions; 4 | 5 | namespace LightMock.Generator.Tests.Interface 6 | { 7 | public class MethodWithOutParameter : ITestScript 8 | { 9 | private readonly Mock mock; 10 | 11 | public MethodWithOutParameter() 12 | => mock = new Mock(); 13 | 14 | public IMock Context => mock; 15 | 16 | public IMethodWithOutParameter MockObject => mock.Object; 17 | 18 | public int DoRun() 19 | { 20 | return 42; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/TestAbstractions/ValidProgramException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace LightMock.Generator.Tests.TestAbstractions 5 | { 6 | public sealed class ValidProgramException : Exception 7 | { 8 | public ValidProgramException() 9 | { 10 | } 11 | 12 | public ValidProgramException(string? message) : base(message) 13 | { 14 | } 15 | 16 | public ValidProgramException(SerializationInfo info, StreamingContext context) : base(info, context) 17 | { 18 | } 19 | 20 | public ValidProgramException(string? message, Exception? innerException) : base(message, innerException) 21 | { 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/InterfaceWithTaskMethod.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using LightMock.Generator.Tests.TestAbstractions; 4 | 5 | namespace LightMock.Generator.Tests.Interface 6 | { 7 | public class InterfaceWithTaskMethod : ITestScript 8 | { 9 | private readonly Mock mock; 10 | 11 | public InterfaceWithTaskMethod() 12 | => mock = new Mock(); 13 | 14 | public IMock Context => mock; 15 | 16 | public IInterfaceWithTaskMethod MockObject => mock.Object; 17 | 18 | public int DoRun() 19 | { 20 | return 42; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AbstractClassWithTaskMethod.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using LightMock.Generator.Tests.TestAbstractions; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public class AbstractClassWithTaskMethod : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public AbstractClassWithTaskMethod() 11 | => mock = new Mock(); 12 | 13 | public IMock Context => mock; 14 | 15 | public AAbstractClassWithTaskMethod MockObject => mock.Object; 16 | 17 | public int DoRun() 18 | { 19 | return 42; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/InterfaceWithBasicMethods.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using LightMock.Generator; 3 | using Xunit; 4 | using LightMock.Generator.Tests.TestAbstractions; 5 | 6 | namespace LightMock.Generator.Tests.Interface 7 | { 8 | public class InterfaceWithBasicMethods : ITestScript 9 | { 10 | private readonly Mock mock; 11 | 12 | public InterfaceWithBasicMethods() 13 | { 14 | mock = new Mock(); 15 | } 16 | 17 | public IMock Context => mock; 18 | public IInterfaceWithBasicMethods MockObject => mock.Object; 19 | 20 | public int DoRun() => 42; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/GenericAbstractClassWithGenericEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.AbstractClass 4 | { 5 | public delegate void EventHandlerGenericClass(object source, T data); 6 | 7 | public abstract class AGenericAbstractClassWithGenericEvent 8 | { 9 | public abstract event EventHandlerGenericClass OnAbstractEvent; 10 | protected abstract event EventHandlerGenericClass OnProtectedAbstractEvent; 11 | #pragma warning disable CS0067 // never used 12 | public virtual event EventHandlerGenericClass? OnVirtualEvent; 13 | protected virtual event EventHandlerGenericClass? OnProtectedVirtualEvent; 14 | #pragma warning restore CS0067 // never used 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AbstractClassWithEventSource.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using LightMock.Generator.Tests.TestAbstractions; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public class AbstractClassWithEventSource : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public AbstractClassWithEventSource() 11 | => mock = new Mock(); 12 | 13 | public IMock Context => mock; 14 | 15 | public AAbstractClassWithEventSource MockObject => mock.Object; 16 | 17 | public int DoRun() 18 | { 19 | return 42; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Friends/SameAssembly.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Friends.FriendAssembly.test.cs")] 5 | 6 | namespace LightMock.Generator.Tests.Friends 7 | { 8 | abstract class Bar 9 | { 10 | protected internal abstract void Foo(); 11 | } 12 | 13 | public class SameAssembly : ITestScript 14 | { 15 | public IMock Context => throw new NotImplementedException(); 16 | 17 | public IFoo MockObject => throw new NotImplementedException(); 18 | 19 | public int DoRun() 20 | { 21 | var mock = new Mock(); 22 | return 42; 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/GenericInterfaceWithGenericEvent.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using LightMock.Generator.Tests.TestAbstractions; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public class GenericInterfaceWithGenericEvent : ITestScript> 7 | { 8 | private readonly Mock> mock; 9 | 10 | public GenericInterfaceWithGenericEvent() 11 | => mock = new Mock>(); 12 | 13 | public IMock> Context => mock; 14 | 15 | public IGenericInterfaceWithGenericEvent MockObject => mock.Object; 16 | 17 | public int DoRun() => 42; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AbstractClassWithGenericMethod.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using LightMock.Generator.Tests.TestAbstractions; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public class AbstractClassWithGenericMethod : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public AbstractClassWithGenericMethod() 11 | => mock = new Mock(); 12 | 13 | public IMock Context => mock; 14 | 15 | public AAbstractClassWithGenericMethod MockObject => mock.Object; 16 | 17 | public int DoRun() 18 | { 19 | return 42; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/AssertSet.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public class AssertSet : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public AssertSet() => mock = new Mock(); 11 | 12 | public IMock Context => mock; 13 | 14 | public IAssertSet MockObject => mock.Object; 15 | 16 | public int DoRun() 17 | { 18 | mock.AssertSet(f => f.GetAndSet = The.Is(s => s.Length > 5), Invoked.Once); 19 | mock.AssertSet(f => f.SetOnly = The.Is(s => s.StartsWith("hello"))); 20 | return 42; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/ExpressionReflect/ActionExecutionTests.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.ExpressionReflect.Model; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq.Expressions; 5 | using Xunit; 6 | 7 | namespace LightMock.Generator.Tests.ExpressionReflect 8 | { 9 | public class ActionExecutionTests 10 | { 11 | [Fact] 12 | public void ShouldCreateSimpleAction_NestedAction() 13 | { 14 | IList list = new List(); 15 | list.Add("Hallo"); 16 | list.Add("Welt"); 17 | 18 | Expression>> expression = x => x.ForEach(() => Console.WriteLine("Write")); 19 | Console.WriteLine(expression); 20 | 21 | Action> reflect = expression.Reflect(); 22 | reflect.Invoke(list); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/GenericInterfaceWithVariance.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using LightMock.Generator.Tests.TestAbstractions; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public class GenericInterfaceWithVariance : ITestScript> 7 | { 8 | private readonly Mock> mock; 9 | 10 | public GenericInterfaceWithVariance() 11 | => mock = new Mock>(); 12 | 13 | public IMock> Context => mock; 14 | 15 | public IGenericInterfaceWithVariance MockObject => mock.Object; 16 | 17 | public int DoRun() 18 | { 19 | return 42; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/InterfaceThrowsExceptionOnRefStruct.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public class InterfaceThrowsExceptionOnRefStruct : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public InterfaceThrowsExceptionOnRefStruct() 11 | => mock = new Mock(); 12 | 13 | public IMock Context => mock; 14 | 15 | public IInterfaceThrowsExceptionOnRefStruct MockObject => mock.Object; 16 | 17 | public int DoRun() 18 | { 19 | return 42; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/InterfaceWithGenericMethod.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public interface IInterfaceWithGenericMethod 7 | { 8 | T GenericReturn(); 9 | Task GenericReturnAsync() where T : class; 10 | void GenericParam(T p); 11 | void GenericWithClassConstraint(T? p) where T : class; 12 | void GenericWithStructConstraint(T p) where T : struct; 13 | void GenericWithConstraint(T p) where T : IEquatable, new(); 14 | void GenericWithManyConstraints(T1? p1, T2 p2, T3 p3) 15 | where T1 : class, new() 16 | where T2 : struct, IEquatable 17 | where T3 : IEquatable, new(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/DontOverrideSupport.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.AbstractClass 4 | { 5 | public abstract class SomeBaseClass 6 | { 7 | public virtual void Quux() { } 8 | public abstract void Quuux(); 9 | } 10 | 11 | public abstract class SkipThisClass : SomeBaseClass 12 | { 13 | public virtual void Foo() => throw new InvalidProgramException(nameof(SkipThisClass) + " called"); 14 | public virtual int Bar() => throw new InvalidProgramException(nameof(SkipThisClass) + " called"); 15 | public abstract void Baz(); 16 | } 17 | 18 | public abstract class ADontOverrideSupport : SkipThisClass 19 | { 20 | public virtual void Quuuux() { } 21 | public abstract void Quuuuux(); 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/InterfaceWithMultipleNamespaces.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using LightMock.Generator.Tests.TestAbstractions; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | using LightMock; 7 | using Namespace2; 8 | 9 | public sealed class InterfaceWithMultipleNamespaces : ITestScript 10 | { 11 | private readonly Mock mock; 12 | 13 | public InterfaceWithMultipleNamespaces() 14 | { 15 | mock = new Mock(); 16 | } 17 | 18 | public IMock Context => mock; 19 | 20 | public IInterfaceWithMultipleNamespaces MockObject => mock.Object; 21 | 22 | public int DoRun() => 42; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/TypeCachingWithAbstractClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.AbstractClass 4 | { 5 | public abstract class ATypeCachingWithAbstractClass 6 | { 7 | public abstract void DoSomething(int p); 8 | public abstract int GetSomething(); 9 | 10 | public void NonAbstractNonVirtualMethod() => throw new NotImplementedException(); 11 | 12 | protected abstract void ProtectedDoSomething(int p); 13 | protected abstract int ProtectedGetSomething(); 14 | 15 | public void InvokeProtectedDoSomething(int p) => ProtectedDoSomething(p); 16 | public int InvokeProtectedGetSomething() => ProtectedGetSomething(); 17 | 18 | protected void ProtectedNonAbstractNonVirtualMethod() => throw new NotImplementedException(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/InterfaceWithEnumerableResult.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Threading.Tasks; 5 | 6 | namespace LightMock.Generator.Tests.Interface 7 | { 8 | public class InterfaceWithEnumerableResult : ITestScript 9 | { 10 | private readonly Mock mock; 11 | 12 | public InterfaceWithEnumerableResult() 13 | => mock = new Mock(); 14 | 15 | public IMock Context => mock; 16 | 17 | public IInterfaceWithEnumerableResult MockObject => mock.Object; 18 | 19 | public int DoRun() 20 | { 21 | return 42; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/GenericMockAndGenericInterface.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using LightMock.Generator.Tests.TestAbstractions; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public class GenericMockAndGenericInterface : ITestScript> 7 | where T : struct, System.IComparable 8 | { 9 | private readonly Mock> mock; 10 | 11 | public GenericMockAndGenericInterface() 12 | => this.mock = new Mock>(); 13 | 14 | public IMock> Context => mock; 15 | 16 | public IGenericMockAndGenericInterface MockObject => mock.Object; 17 | 18 | public int DoRun() 19 | { 20 | return 42; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AbstractClassThrowsExceptionOnRefStruct.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public class AbstractClassThrowsExceptionOnRefStruct : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public AbstractClassThrowsExceptionOnRefStruct() 11 | => mock = new Mock(); 12 | 13 | public IMock Context => mock; 14 | 15 | public AAbstractClassThrowsExceptionOnRefStruct MockObject => mock.Object; 16 | 17 | public int DoRun() 18 | { 19 | return 42; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/GenerateForInternalClass.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | internal abstract class AGenerateForInternalClass 7 | { 8 | } 9 | 10 | internal sealed class GenerateForInternalClass : ITestScript 11 | { 12 | private readonly Mock mock; 13 | 14 | public GenerateForInternalClass() 15 | { 16 | mock = new Mock(); 17 | } 18 | 19 | public IMock Context => mock; 20 | 21 | public AGenerateForInternalClass MockObject => mock.Object; 22 | 23 | public int DoRun() 24 | { 25 | return 42; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/GenericAbstractClassWithGenericEvent.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using LightMock.Generator.Tests.TestAbstractions; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public class GenericAbstractClassWithGenericEvent : ITestScript> 7 | { 8 | private readonly Mock> mock; 9 | 10 | public GenericAbstractClassWithGenericEvent() 11 | => mock = new Mock>(); 12 | 13 | public IMock> Context => mock; 14 | 15 | public AGenericAbstractClassWithGenericEvent MockObject => mock.Object; 16 | 17 | public int DoRun() 18 | { 19 | return 42; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Common/Generator/Mock{T}.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator 4 | { 5 | /// 6 | /// Class for mocks and mocked objects 7 | /// 8 | /// 9 | public sealed class Mock : AbstractMock 10 | where T : class 11 | { 12 | /// 13 | /// Create mock and mocked object without paramters 14 | /// 15 | public Mock() 16 | : base(Array.Empty()) 17 | { } 18 | 19 | /// 20 | /// Create mock and mocked object with parameters 21 | /// 22 | /// Parameters that passed into constructor of mocked object 23 | public Mock(params object[] prms) 24 | : base(prms) 25 | { } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Mocks/MockAnalyzerConfigOptions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis.Diagnostics; 2 | using System.Collections.Immutable; 3 | using System.Diagnostics.CodeAnalysis; 4 | 5 | namespace LightMock.Generator.Tests.Mocks 6 | { 7 | sealed class MockAnalyzerConfigOptions : AnalyzerConfigOptions 8 | { 9 | public static MockAnalyzerConfigOptions Empty { get; } 10 | = new MockAnalyzerConfigOptions(ImmutableDictionary.Empty); 11 | 12 | private readonly ImmutableDictionary backing; 13 | 14 | public MockAnalyzerConfigOptions(ImmutableDictionary backing) 15 | => this.backing = backing; 16 | 17 | public override bool TryGetValue(string key, [NotNullWhen(true)] out string? value) 18 | => backing.TryGetValue(key, out value); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Delegate/DelegateNotGenerated.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Delegate 5 | { 6 | public class DelegateNotGenerated : ITestScript 7 | { 8 | private readonly Lazy> lazyMock; 9 | 10 | public DelegateNotGenerated() 11 | => lazyMock = new Lazy>(() => GetMock()); 12 | 13 | public IMock Context => lazyMock.Value; 14 | 15 | public EventHandler MockObject => lazyMock.Value.Object; 16 | 17 | public int DoRun() 18 | { 19 | return 42; 20 | } 21 | 22 | static Mock GetMock() 23 | where T : class 24 | { 25 | return new Mock(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AbstractClassWithEventSourceAndMultipleNamespaces.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.AbstractClass.EventNamespace1 4 | { 5 | public delegate void EventHandler(object source, T data); 6 | } 7 | 8 | namespace LightMock.Generator.Tests.AbstractClass.EventNamespace2 9 | { 10 | using EventNamespace1; 11 | 12 | public abstract class AAbstractClassWithEventSourceAndMultipleNamespaces 13 | { 14 | #pragma warning disable CS0067 // never used 15 | public virtual event EventHandler? OnVirtualEvent; 16 | protected virtual event EventHandler? OnProtectedVirtualEvent; 17 | #pragma warning restore CS0067 // never used 18 | public abstract event EventHandler? OnAbstractEvent; 19 | protected abstract event EventHandler? OnProtectedAbstractEvent; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AbstractClassWithEnumerableResult.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Threading.Tasks; 5 | 6 | namespace LightMock.Generator.Tests.AbstractClass 7 | { 8 | public class AbstractClassWithEnumerableResult : ITestScript 9 | { 10 | private readonly Mock mock; 11 | 12 | public AbstractClassWithEnumerableResult() 13 | => mock = new Mock(); 14 | 15 | public IMock Context => mock; 16 | 17 | public AAbstractClassWithEnumerableResult MockObject => mock.Object; 18 | 19 | public int DoRun() 20 | { 21 | return 42; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/GenericMockAndGenericAbstractClass.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using LightMock.Generator.Tests.TestAbstractions; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public class GenericMockAndGenericAbstractClass : ITestScript> 7 | where T : struct, IComparable 8 | { 9 | private readonly Mock> mock; 10 | 11 | public GenericMockAndGenericAbstractClass() 12 | => this.mock = new Mock>(); 13 | 14 | public IMock> Context => mock; 15 | 16 | public AGenericMockAndGenericAbstractClass MockObject => mock.Object; 17 | 18 | public int DoRun() 19 | { 20 | return 42; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AbstractClassWithConstructors.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading.Tasks; 4 | using LightMock.Generator.Tests.TestAbstractions; 5 | 6 | namespace LightMock.Generator.Tests.AbstractClass 7 | { 8 | public class AbstractClassWithConstructors : ITestScript 9 | { 10 | private readonly Mock mock; 11 | 12 | public AbstractClassWithConstructors() 13 | => mock = new Mock((int)1234, (IEnumerable)null); 14 | 15 | public IMock Context => mock; 16 | 17 | public AAbstractClassWithConstructors MockObject => mock.Object; 18 | 19 | public int DoRun() 20 | { 21 | return 42; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/ExpressionReflect/Model/TestExtensionMethods.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace LightMock.Generator.Tests.ExpressionReflect.Model 5 | { 6 | public static class TestExtensionMethods 7 | { 8 | public static TSource FirstOrDefaultCustom(this IEnumerable source, 9 | Func predicate) 10 | { 11 | foreach (TSource obj in source) 12 | { 13 | if (predicate(obj, 50)) 14 | { 15 | return obj; 16 | } 17 | } 18 | return default!; 19 | } 20 | 21 | public static void ForEach(this IEnumerable source, Action action) 22 | { 23 | if (source == null) throw new ArgumentNullException("source"); 24 | if (action == null) throw new ArgumentNullException("action"); 25 | 26 | foreach (T item in source) 27 | { 28 | action(); 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AbstractClassWithEventSource.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.AbstractClass 4 | { 5 | public delegate void EventHandler(object source, T data); 6 | 7 | public abstract class AAbstractClassWithEventSource 8 | { 9 | #pragma warning disable CS0067 // never used 10 | public virtual event EventHandler? OnVirtualEvent; 11 | protected virtual event EventHandler? OnProtectedVirtualEvent; 12 | protected internal virtual event EventHandler? OnProtectedInternalVirtualEvent; 13 | #pragma warning restore CS0067 // never used 14 | public abstract event EventHandler? OnAbstractEvent; 15 | protected abstract event EventHandler? OnProtectedAbstractEvent; 16 | protected internal abstract event EventHandler? OnProtectedInternalAbstractEvent; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/TypeCachingWithInterface.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Xunit; 3 | using LightMock.Generator.Tests.TestAbstractions; 4 | 5 | namespace LightMock.Generator.Tests.Interface 6 | { 7 | public class TypeCachingWithInterface : ITestScript 8 | { 9 | private readonly Mock mock; 10 | 11 | public TypeCachingWithInterface() 12 | => mock = new Mock(); 13 | 14 | public IMock Context => mock; 15 | 16 | public ITypeCachingWithInterface MockObject => mock.Object; 17 | 18 | public int DoRun() 19 | { 20 | var another = new Mock(); 21 | var o = another.Object; 22 | Assert.NotNull(o); 23 | 24 | return 42; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Delegate/NestedDelegateWithGenerics.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Delegate 5 | { 6 | public class NestedDelegateWithGenerics : ITestScript.XContainer.SomeDelegate> 7 | { 8 | private readonly Mock.XContainer.SomeDelegate> mock; 9 | 10 | public NestedDelegateWithGenerics() 11 | => mock = new Mock.XContainer.SomeDelegate>(); 12 | 13 | public IMock.XContainer.SomeDelegate> Context => mock; 14 | 15 | public XNestedInterface.XContainer.SomeDelegate MockObject => mock.Object; 16 | 17 | public int DoRun() 18 | { 19 | return 42; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/InterfaceWithEventSourceAndMultipleNamespaces.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using LightMock.Generator.Tests.TestAbstractions; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | using EventNamespace2; 7 | using LightMock; 8 | 9 | public class InterfaceWithEventSourceAndMultipleNamespaces : ITestScript 10 | { 11 | private readonly Mock mock; 12 | 13 | public InterfaceWithEventSourceAndMultipleNamespaces() 14 | => mock = new Mock(); 15 | 16 | public IMock Context => mock; 17 | 18 | public IInterfaceWithEventSourceAndMultipleNamespaces MockObject => mock.Object; 19 | 20 | public int DoRun() => 42; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/NestedGenericClass.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public class NestedGenericClass : ITestScript.AContainingClass.ATest> 7 | { 8 | private readonly Mock.AContainingClass.ATest> mock; 9 | 10 | public NestedGenericClass() 11 | => mock = new Mock.AContainingClass.ATest>(); 12 | 13 | public IMock.AContainingClass.ATest> Context => mock; 14 | 15 | public ANestedGenericClass.AContainingClass.ATest MockObject => mock.Object; 16 | 17 | public int DoRun() 18 | { 19 | throw new NotImplementedException(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/InheritAbstractClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.AbstractClass 4 | { 5 | public abstract class AFoo 6 | { 7 | public abstract void Foo(); 8 | protected abstract void ProtectedFoo(); 9 | public void InvokeProtectedFoo() => ProtectedFoo(); 10 | } 11 | 12 | public abstract class ABar : AFoo 13 | { 14 | public abstract void Bar(); 15 | protected abstract void ProtectedBar(); 16 | public void InvokeProtectedBar() => ProtectedBar(); 17 | } 18 | 19 | public abstract class AInheritAbstractClass : ABar 20 | { 21 | public override void Foo() { } 22 | protected override void ProtectedFoo() { } 23 | 24 | public abstract void Baz(); 25 | protected abstract void ProtectedBaz(); 26 | public void InvokeProtectedBaz() => ProtectedBaz(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Issues/TypeKeyAttributeRemoved.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Issues 5 | { 6 | public class TypeKeyAttributeRemoved : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public TypeKeyAttributeRemoved() => mock = new Mock(); 11 | 12 | public IMock Context => mock; 13 | 14 | public ITypeKeyAttributeRemoved MockObject => mock.Object; 15 | 16 | public int DoRun() 17 | { 18 | new Mock(); 19 | new Mock>(); 20 | new Mock(); 21 | new Mock>(); 22 | return 42; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/InterfaceNotGenerated.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public class InterfaceNotGenerated : ITestScript 7 | { 8 | 9 | private readonly Lazy> lazyMock; 10 | 11 | public InterfaceNotGenerated() 12 | => lazyMock = new Lazy>(() => GetMock()); 13 | 14 | public IMock Context => lazyMock.Value; 15 | 16 | public IInterfaceNotGenerated MockObject => lazyMock.Value.Object; 17 | 18 | public int DoRun() 19 | { 20 | return 42; 21 | } 22 | 23 | static Mock GetMock() 24 | where T : class 25 | { 26 | return new Mock(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/TypeCachingWithAbstractClass.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Xunit; 3 | using LightMock.Generator.Tests.TestAbstractions; 4 | 5 | namespace LightMock.Generator.Tests.AbstractClass 6 | { 7 | public class TypeCachingWithAbstractClass : ITestScript 8 | { 9 | private readonly Mock mock; 10 | 11 | public TypeCachingWithAbstractClass() 12 | => mock = new Mock(); 13 | 14 | public IMock Context => mock; 15 | 16 | public ATypeCachingWithAbstractClass MockObject => mock.Object; 17 | 18 | public int DoRun() 19 | { 20 | var another = new Mock(); 21 | var o = another.Object; 22 | Assert.NotNull(o); 23 | 24 | return 42; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Common/Generator/OriginalNameAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LightMock.Generator 6 | { 7 | /// 8 | /// For internal usage 9 | /// 10 | public sealed class OriginalNameAttribute : Attribute 11 | { 12 | /// 13 | /// For internal usage 14 | /// 15 | public OriginalNameAttribute(int parametersCount, string originalNameFormat) 16 | { 17 | ParametersCount = parametersCount; 18 | OriginalNameFormat = originalNameFormat; 19 | } 20 | 21 | /// 22 | /// For internal usage 23 | /// 24 | public int ParametersCount { get; } 25 | 26 | /// 27 | /// For internal usage 28 | /// 29 | public string OriginalNameFormat { get; } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/NestedGenericInterface.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public class NestedGenericInterface : ITestScript.IContainingInterface.ITest> 7 | { 8 | private readonly Mock.IContainingInterface.ITest> mock; 9 | 10 | public NestedGenericInterface() 11 | => mock = new Mock.IContainingInterface.ITest>(); 12 | 13 | 14 | public IMock.IContainingInterface.ITest> Context => mock; 15 | 16 | public INestedGenericInterface.IContainingInterface.ITest MockObject => mock.Object; 17 | 18 | public int DoRun() 19 | { 20 | return 42; 21 | } 22 | } 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/BaseTests/TheTests.cs: -------------------------------------------------------------------------------- 1 | using Xunit; 2 | 3 | namespace LightMock.Generator.Tests.BaseTests 4 | { 5 | public class TheTests 6 | { 7 | [Fact] 8 | public void IsAnyValue_ReturnsDefaultValue() 9 | { 10 | Assert.Equal(default(string), The.IsAnyValue); 11 | } 12 | 13 | [Fact] 14 | public void Reference_IsAny_ReturnsDefaultValue() 15 | { 16 | Assert.Equal(default(string), The.Reference.IsAny.Value); 17 | } 18 | 19 | [Fact] 20 | public void Reference_Is_AnyPredicate_ReturnsDefaultValue() 21 | { 22 | Assert.Equal(default(string), The.Reference.Is(s => true).Value); 23 | } 24 | 25 | [Fact] 26 | public void Is_AnyPredicate_ReturnsDefaultValue() 27 | { 28 | Assert.Equal(default(string), The.Is(s => true)); 29 | } 30 | 31 | } 32 | } -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AbstractClassNotGenerated.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public class AbstractClassNotGenerated : ITestScript 7 | { 8 | private Lazy> lazyMock; 9 | 10 | public AbstractClassNotGenerated() 11 | => lazyMock = new Lazy>(() => GetMock()); 12 | 13 | public IMock Context => lazyMock.Value; 14 | 15 | public AAbstractClassNotGenerated MockObject => lazyMock.Value.Object; 16 | 17 | public int DoRun() 18 | { 19 | return 42; 20 | } 21 | 22 | static Mock GetMock() 23 | where T : class 24 | { 25 | return new Mock(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/ArrangeAddRemove_WhenAny.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public class ArrangeAddRemove_WhenAny : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public ArrangeAddRemove_WhenAny() => mock = new Mock(); 11 | 12 | public IMock Context => mock; 13 | 14 | public AArrangeAddRemove_WhenAny MockObject => mock.Object; 15 | 16 | public int DoRun() 17 | { 18 | mock.Protected().ArrangeAdd_WhenAny(f => f.ProtectedEventHandler += null).Throws(); 19 | mock.Protected().ArrangeRemove_WhenAny(f => f.ProtectedEventHandler -= null).Throws(); 20 | return 42; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AbstractClassWithEventSourceAndMultipleNamespaces.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using LightMock.Generator.Tests.TestAbstractions; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | using EventNamespace2; 7 | 8 | public class AbstractClassWithEventSourceAndMultipleNamespaces : ITestScript 9 | { 10 | private readonly Mock mock; 11 | 12 | public AbstractClassWithEventSourceAndMultipleNamespaces() 13 | => mock = new Mock(); 14 | 15 | public IMock Context => mock; 16 | 17 | public AAbstractClassWithEventSourceAndMultipleNamespaces MockObject => mock.Object; 18 | 19 | public int DoRun() 20 | { 21 | return 42; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/LightMock.Generator/SymbolDisplayPartExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Runtime.CompilerServices; 6 | 7 | namespace LightMock.Generator 8 | { 9 | static class SymbolDisplayPartExtensions 10 | { 11 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 12 | public static bool IsInternal(this SymbolDisplayPart sdp) 13 | => sdp.Kind == SymbolDisplayPartKind.Keyword && sdp.ToString() == "internal"; 14 | 15 | public static IEnumerable FilterInternalKeywordFromNonFriendDeclarations( 16 | this IEnumerable parts, 17 | ISymbol symbol, Compilation compilation) 18 | { 19 | return symbol.ContainingAssembly.GivesAccessTo(compilation.Assembly) 20 | ? parts 21 | : parts.Where(k => k.IsInternal() == false); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/TypeCachingWithGenericInterface.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Xunit; 3 | using LightMock.Generator.Tests.TestAbstractions; 4 | 5 | namespace LightMock.Generator.Tests.Interface 6 | { 7 | public class TypeCachingWithGenericInterface : ITestScript> 8 | { 9 | private readonly Mock> mock; 10 | 11 | public TypeCachingWithGenericInterface() 12 | => mock = new Mock>(); 13 | 14 | public IMock> Context => mock; 15 | 16 | public ITypeCachingWithGenericInterface MockObject => mock.Object; 17 | 18 | public int DoRun() 19 | { 20 | var another = new Mock>(); 21 | var o = another.Object; 22 | Assert.NotNull(o); 23 | 24 | return 42; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/InherittedInterface.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.Interface 4 | { 5 | public interface IFooResult { } 6 | 7 | public interface IFoo 8 | { 9 | void Foo(); 10 | IFooResult GetResult(); 11 | IFooResult Result { get; } 12 | } 13 | 14 | public interface IBarResult { } 15 | 16 | public interface IBar : IFoo 17 | { 18 | void Bar(); 19 | new IBarResult GetResult(); 20 | new IBarResult Result { get; } 21 | } 22 | 23 | public interface IBazResult { } 24 | 25 | public interface IBaz 26 | { 27 | void Baz(); 28 | IBazResult GetResult(); 29 | IBazResult Result { get; } 30 | } 31 | 32 | public interface IQuuxResult { } 33 | 34 | public interface IInherittedInterface : IBar, IBaz 35 | { 36 | void Quux(); 37 | new IQuuxResult GetResult(); 38 | new IQuuxResult Result { get; } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AssertSet.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public class AssertSet : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public AssertSet() => mock = new Mock(); 11 | 12 | public IMock Context => mock; 13 | 14 | public AAssertSet MockObject => mock.Object; 15 | 16 | public int DoRun() 17 | { 18 | mock.Protected().AssertSet(f => f.ProtectedGetAndSet = The.Is(s => s.Length > 5), Invoked.Once); 19 | mock.Protected().AssertSet(f => f.ProtectedSetOnly = The.Is(s => s.StartsWith("hello"))); 20 | mock.AssertSet(f => f.GetAndSet = The.Is(s => s.Length > 5), Invoked.Once); 21 | mock.AssertSet(f => f.SetOnly = The.Is(s => s.StartsWith("hello"))); 22 | return 42; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AssertSet_WhenAny.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public class AssertSet_WhenAny : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public AssertSet_WhenAny() => mock = new Mock(); 11 | 12 | public IMock Context => mock; 13 | 14 | public AAssertSet_WhenAny MockObject => mock.Object; 15 | 16 | public int DoRun() 17 | { 18 | mock.Protected().AssertSet_WhenAny(f => f.ProtectedGetAndSet = ""); 19 | mock.Protected().AssertSet_WhenAny(f => f.ProtectedGetAndSet = "", Invoked.Once); 20 | mock.Protected().AssertSet_WhenAny(f => f.ProtectedSetOnly = ""); 21 | mock.Protected().AssertSet_WhenAny(f => f.ProtectedSetOnly = "", Invoked.Once); 22 | 23 | return 42; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/TypeCachingWithGenericAbstractClass.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Xunit; 3 | using LightMock.Generator.Tests.TestAbstractions; 4 | 5 | namespace LightMock.Generator.Tests.AbstractClass 6 | { 7 | public class TypeCachingWithGenericAbstractClass : ITestScript> 8 | { 9 | private readonly Mock> mock; 10 | 11 | public TypeCachingWithGenericAbstractClass() 12 | => mock = new Mock>(); 13 | 14 | public IMock> Context => mock; 15 | 16 | public ATypeCachingWithGenericAbstractClass MockObject => mock.Object; 17 | 18 | public int DoRun() 19 | { 20 | var another = new Mock>(); 21 | var o = another.Object; 22 | Assert.NotNull(o); 23 | 24 | return 42; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/BaseTests/PropMock.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace LightMock.Generator.Tests.BaseTests 3 | { 4 | public interface IProp 5 | { 6 | string? ReadOnlyProperty { get; } 7 | string? TwoWayProperty { get; set; } 8 | } 9 | 10 | public class PropMock : IProp 11 | { 12 | private readonly IInvocationContext _context; 13 | 14 | public PropMock(IInvocationContext context) 15 | { 16 | _context = context; 17 | } 18 | 19 | public string? ReadOnlyProperty 20 | { 21 | get 22 | { 23 | return _context.Invoke(x => x.ReadOnlyProperty); 24 | } 25 | } 26 | 27 | public string? TwoWayProperty 28 | { 29 | get 30 | { 31 | return _context.Invoke(x => x.TwoWayProperty); 32 | } 33 | set 34 | { 35 | _context.InvokeSetter(x => x.TwoWayProperty, value); 36 | } 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /src/LightMock.Generator.Common/ArgumentHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Runtime.CompilerServices; 5 | 6 | namespace LightMock 7 | { 8 | /// 9 | /// For internal usage. 10 | /// 11 | [EditorBrowsable(EditorBrowsableState.Never)] 12 | public static class ArgumentHelper 13 | { 14 | /// 15 | /// For internal usage. 16 | /// 17 | [EditorBrowsable(EditorBrowsableState.Never)] 18 | public static T Unpack(IDictionary arguments, string name, T @default) 19 | => arguments.TryGetValue(name, out var value) ? (T)value : @default; 20 | 21 | /// 22 | /// For internal usage. 23 | /// 24 | [EditorBrowsable(EditorBrowsableState.Never), MethodImpl(MethodImplOptions.AggressiveInlining)] 25 | public static T Unpack(IDictionary arguments, string name) 26 | => Unpack(arguments, name, default(T)!); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/TypeCachingWithGenericAbstractClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Xunit; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public abstract class ATypeCachingWithGenericAbstractClass 7 | { 8 | public abstract T OnlyGet { get; } 9 | public abstract T GetAndSet { get; set; } 10 | public abstract T GetSomething(); 11 | public abstract void DoSomething(T p); 12 | 13 | protected abstract T ProtectedOnlyGet { get; } 14 | protected abstract T ProtectedGetAndSet { get; set; } 15 | protected abstract T ProtectedGetSomething(); 16 | protected abstract void ProtectedDoSomething(T p); 17 | 18 | 19 | public T InvokeProtectedOnlyGet => ProtectedOnlyGet; 20 | public T InvokeProtectedGetAndSet 21 | { 22 | get => ProtectedGetAndSet; 23 | set => ProtectedGetAndSet = value; 24 | } 25 | 26 | public T InvokeProtectedGetSomething() => ProtectedGetSomething(); 27 | public void InvokeProtectedDoSomething(T p) => ProtectedDoSomething(p); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/ArrangeSetter.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.Interface 5 | { 6 | public class ArrangeSetter : ITestScript 7 | { 8 | private readonly IMock mock; 9 | 10 | public ArrangeSetter() => mock = new Mock(); 11 | 12 | public IMock Context => mock; 13 | 14 | public IArrangeSetter MockObject => mock.Object; 15 | 16 | public int DoRun() 17 | { 18 | mock // check for 19 | .ArrangeSetter( // strange invocation 20 | f => f.GetAndSet = The.Is(s => s == "1234")) 21 | .Throws(() => new ValidProgramException(nameof(IArrangeSetter.GetAndSet))); 22 | mock.ArrangeSetter(uidPart2: 982712, uidPart1: "c:\\some\\path\\to\\file", expression: f => f.Set = The.Is(s => s == "4567")) 23 | .Throws(() => new ValidProgramException(nameof(IArrangeSetter.Set))); 24 | return 42; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Anton Yashin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/common.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | $(AssemblyName) ($(TargetFramework)) 4 | 1.2.0.0 5 | 1.2.0.0 6 | 1.2.3 7 | 8 | $(Version)$(VersionSuffix) 9 | Anton Yashin 10 | en 11 | Copyright © Anton Yashin 2021 12 | https://github.com/anton-yashin/LightMock.Generator 13 | LICENSE 14 | false 15 | https://github.com/anton-yashin/LightMock.Generator 16 | preview 17 | enable 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/GenericMockAndGenericAbstractClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.AbstractClass 4 | { 5 | public abstract class AGenericMockAndGenericAbstractClass 6 | where T : struct, IComparable 7 | { 8 | public abstract T OnlyGet { get; } 9 | public abstract T GetAndSet { get; set; } 10 | public abstract T GetSomething(); 11 | public abstract void DoSomething(T p); 12 | 13 | protected abstract T ProtectedOnlyGet { get; } 14 | protected abstract T ProtectedGetAndSet { get; set; } 15 | protected abstract T ProtectedGetSomething(); 16 | protected abstract void ProtectedDoSomething(T p); 17 | 18 | 19 | public T InvokeProtectedOnlyGet => ProtectedOnlyGet; 20 | public T InvokeProtectedGetAndSet 21 | { 22 | get => ProtectedGetAndSet; 23 | set => ProtectedGetAndSet = value; 24 | } 25 | 26 | public T InvokeProtectedGetSomething() => ProtectedGetSomething(); 27 | public void InvokeProtectedDoSomething(T p) => ProtectedDoSomething(p); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/ExpressionReflect/ConditionalTests.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.ExpressionReflect.Model; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Linq.Expressions; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using Xunit; 9 | 10 | namespace LightMock.Generator.Tests.ExpressionReflect 11 | { 12 | public class ConditionalTests 13 | { 14 | [Fact] 15 | public void ShouldExecuteConditional() 16 | { 17 | // Arrange 18 | Customer customer = new Customer("John", "Doe") { IsPremium = true }; 19 | Expression> expression = x => x.IsPremium ? 500 : 300; 20 | Console.WriteLine(expression.ToString()); 21 | 22 | // Act 23 | Func emit = expression.Compile(); 24 | Func reflection = expression.Reflect(); 25 | 26 | int emitResult = emit.Invoke(customer); 27 | int reflectionResult = reflection.Invoke(customer); 28 | 29 | // Assert 30 | Assert.Equal(expected: 500, emitResult); 31 | Assert.Equal(expected: 500, reflectionResult); 32 | Assert.Equal(emitResult, reflectionResult); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/LightMock.Generator/AnalyzerReleases.Shipped.md: -------------------------------------------------------------------------------- 1 | ; Shipped analyzer releases 2 | ; https://github.com/dotnet/roslyn-analyzers/blob/master/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md 3 | 4 | ## Release 0.90 5 | 6 | ### New Rules 7 | Rule ID | Category | Severity | Notes 8 | --------|----------|----------|------- 9 | SPG001 | Usage | Error | DiagnosticsDescriptors 10 | SPG002 | Usage | Error | DiagnosticsDescriptors 11 | SPG003 | Usage | Error | DiagnosticsDescriptors 12 | SPG004 | Usage | Warning | DiagnosticsDescriptors 13 | SPG005 | Usage | Error | DiagnosticsDescriptors 14 | 15 | ## Release 0.903 16 | 17 | ### Removed Rules 18 | Rule ID | Category | Severity | Notes 19 | --------|----------|----------|------- 20 | SPG001 | Usage | Error | DiagnosticsDescriptors 21 | SPG002 | Usage | Error | DiagnosticsDescriptors 22 | SPG003 | Usage | Error | DiagnosticsDescriptors 23 | SPG004 | Usage | Warning | DiagnosticsDescriptors 24 | 25 | 26 | ## Release 0.906 27 | ### New Rules 28 | Rule ID | Category | Severity | Notes 29 | --------|----------|----------|------- 30 | SPG006 | Usage | Error | DiagnosticsDescriptors 31 | SPG007 | Usage | Error | DiagnosticsDescriptors 32 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/ExpressionReflect/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Matthias Gernand 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AbstractClassWithBasicMethods.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.AbstractClass 4 | { 5 | public abstract class AAbstractClassWithBasicMethods 6 | { 7 | public abstract void DoSomething(int p); 8 | public abstract int GetSomething(); 9 | 10 | public void NonAbstractNonVirtualMethod() => throw new NotImplementedException(); 11 | 12 | protected abstract void ProtectedDoSomething(int p); 13 | protected abstract int ProtectedGetSomething(); 14 | 15 | protected internal abstract void ProtectedInternalDoSomething(int p); 16 | protected internal abstract int ProtectedInternalGetSomething(); 17 | 18 | public void InvokeProtectedDoSomething(int p) => ProtectedDoSomething(p); 19 | public int InvokeProtectedGetSomething() => ProtectedGetSomething(); 20 | 21 | public void InvokeProtectedInternalDoSomething(int p) => ProtectedInternalDoSomething(p); 22 | public int InvokeProtectedInternalGetSomething() => ProtectedInternalGetSomething(); 23 | 24 | protected void ProtectedNonAbstractNonVirtualMethod() => throw new NotImplementedException(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Issues/NamespacesIssue.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock; 2 | using LightMock.Generator; 3 | using LightMock.Generator.Tests; 4 | using System; 5 | using Xunit; 6 | using LightMock.Generator.Tests.TestAbstractions; 7 | 8 | namespace Playground 9 | { 10 | public class NamespacesIssue : ITestScript 11 | { 12 | private readonly Mock mock; 13 | 14 | public NamespacesIssue() => mock = new Mock(); 15 | 16 | public IMock Context => mock; 17 | 18 | public IFoo MockObject => mock.Object; 19 | 20 | public int DoRun() 21 | { 22 | var mock1 = new Mock>(); 23 | var o1 = mock1.Object; 24 | Assert.NotNull(o1); 25 | 26 | var mock2 = new Mock(); 27 | var o2 = mock2.Object; 28 | Assert.NotNull(o2); 29 | 30 | var mock3 = new Mock>(); 31 | var o3 = mock3.Object; 32 | Assert.NotNull(o3); 33 | 34 | return 42; 35 | } 36 | } 37 | } 38 | 39 | namespace LightMock.Generator.Playground 40 | { 41 | public static class Foo 42 | { 43 | public static void Bar() { } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/LightMock.Generator/LightMock.Generator.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | <_LmgAnalyzer Include="@(Analyzer)" Condition="'%(Analyzer.NuGetPackageId)' == 'LightMock.Generator'" /> 6 | 7 | 8 | 9 | 13 | 14 | 15 | 16 | 18 | 19 | 20 | 21 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/GenericAbstractClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public abstract class AGenericAbstractClass 7 | { 8 | public abstract T OnlyGet { get; } 9 | public abstract T GetAndSet { get; set; } 10 | public abstract T GetSomething(); 11 | public abstract void DoSomething(T p); 12 | public abstract Task FooAsync() where TResult : class; 13 | 14 | protected abstract T ProtectedOnlyGet { get; } 15 | protected abstract T ProtectedGetAndSet { get; set; } 16 | protected abstract T ProtectedGetSomething(); 17 | protected abstract void ProtectedDoSomething(T p); 18 | public abstract Task ProtectedFooAsync() where TResult : class; 19 | 20 | 21 | public T InvokeProtectedOnlyGet => ProtectedOnlyGet; 22 | public T InvokeProtectedGetAndSet 23 | { 24 | get => ProtectedGetAndSet; 25 | set => ProtectedGetAndSet = value; 26 | } 27 | 28 | public T InvokeProtectedGetSomething() => ProtectedGetSomething(); 29 | public void InvokeProtectedDoSomething(T p) => ProtectedDoSomething(p); 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/RefReturn.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | using Xunit; 4 | 5 | namespace LightMock.Generator.Tests.AbstractClass 6 | { 7 | public class RefReturn : ITestScript 8 | { 9 | private readonly Mock mock; 10 | 11 | public RefReturn() => mock = new Mock(); 12 | 13 | public IMock Context => mock; 14 | 15 | public ARefReturn MockObject => mock.Object; 16 | 17 | public int DoRun() 18 | { 19 | const string EXPECTED_STRING = nameof(EXPECTED_STRING); 20 | var expectedDateTime = DateTime.UtcNow; 21 | mock.RefReturn().Arrange(f => f.Foo()).Returns(() => EXPECTED_STRING); 22 | mock.RefReturn().Arrange(f => f.Bar()).Returns(() => expectedDateTime); 23 | 24 | mock.RefReturn().Assert(f => f.Foo(), Invoked.Never); 25 | mock.RefReturn().Assert(f => f.Bar(), Invoked.Never); 26 | 27 | Assert.Equal(EXPECTED_STRING, MockObject.Foo()); 28 | Assert.Equal(expectedDateTime, MockObject.Bar()); 29 | 30 | mock.RefReturn().Assert(f => f.Foo()); 31 | mock.RefReturn().Assert(f => f.Bar()); 32 | return 42; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Interface/RefReturn.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | using Xunit; 4 | 5 | namespace LightMock.Generator.Tests.Interface 6 | { 7 | public class RefReturn : ITestScript 8 | { 9 | private readonly Mock mock; 10 | 11 | public RefReturn() 12 | => mock = new Mock(); 13 | 14 | public IMock Context => mock; 15 | 16 | public IRefReturn MockObject => mock.Object; 17 | 18 | public int DoRun() 19 | { 20 | const string EXPECTED_STRING = nameof(EXPECTED_STRING); 21 | var expectedDateTime = DateTime.UtcNow; 22 | mock.RefReturn().Arrange(f => f.Foo()).Returns(() => EXPECTED_STRING); 23 | mock.RefReturn().Arrange(f => f.Bar()).Returns(() => expectedDateTime); 24 | 25 | mock.RefReturn().Assert(f => f.Foo(), Invoked.Never); 26 | mock.RefReturn().Assert(f => f.Bar(), Invoked.Never); 27 | 28 | Assert.Equal(EXPECTED_STRING, MockObject.Foo()); 29 | Assert.Equal(expectedDateTime, MockObject.Bar()); 30 | 31 | mock.RefReturn().Assert(f => f.Foo()); 32 | mock.RefReturn().Assert(f => f.Bar()); 33 | 34 | return 42; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AbstractClassWithMultipleNamespaces.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.AbstractClass.Namespace1 4 | { 5 | public class MultipleNamespacesArgument 6 | { } 7 | } 8 | 9 | namespace LightMock.Generator.Tests.AbstractClass.Namespace2 10 | { 11 | using Namespace1; 12 | 13 | public abstract class AAbstractClassWithMultipleNamespaces 14 | { 15 | public abstract void DoSomething(MultipleNamespacesArgument someClass); 16 | public abstract MultipleNamespacesArgument GetSomething(); 17 | public abstract MultipleNamespacesArgument SomeProperty { get; set; } 18 | 19 | protected abstract void ProtectedDoSomething(MultipleNamespacesArgument someClass); 20 | protected abstract MultipleNamespacesArgument ProtectedGetSomething(); 21 | protected abstract MultipleNamespacesArgument ProtectedSomeProperty { get; set; } 22 | 23 | public void InvokeProtectedDoSomething(MultipleNamespacesArgument someClass) => ProtectedDoSomething(someClass); 24 | public MultipleNamespacesArgument InvokeProtectedGetSomething() => ProtectedGetSomething(); 25 | public MultipleNamespacesArgument InvokeProtectedSomeProperty 26 | { 27 | get => ProtectedSomeProperty; 28 | set => ProtectedSomeProperty = value; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/LightMock.Generator/CompilationContext.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis; 2 | using Microsoft.CodeAnalysis.CSharp; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Collections.Immutable; 6 | 7 | namespace LightMock.Generator 8 | { 9 | sealed class CompilationContext 10 | { 11 | private readonly HashSet tags; 12 | private readonly List syntaxTrees; 13 | 14 | public CompilationContext() 15 | { 16 | tags = new HashSet(); 17 | syntaxTrees = new List(); 18 | } 19 | 20 | public void AddSyntaxTree(SyntaxTree tree) 21 | { 22 | lock (syntaxTrees) 23 | syntaxTrees.Add(tree); 24 | } 25 | 26 | public CSharpCompilation Update(CSharpCompilation compilation) 27 | { 28 | ImmutableArray trees; 29 | lock (syntaxTrees) 30 | trees = syntaxTrees.ToImmutableArray(); 31 | return compilation.AddSyntaxTrees(trees); 32 | } 33 | 34 | public void AddTag(string tag) 35 | { 36 | lock(tags) 37 | tags.Add(tag); 38 | } 39 | 40 | public bool IsTagExits(string tag) 41 | { 42 | lock (tags) 43 | return tags.Contains(tag); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AssertNoOtherCalls.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public sealed class AssertNoOtherCalls : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public AssertNoOtherCalls() => mock = new Mock(); 11 | 12 | public IMock Context => mock; 13 | 14 | public AAssertNoOtherCalls MockObject => mock.Object; 15 | 16 | public int DoRun() 17 | { 18 | mock.Protected().AssertSet_When(f => f.ProtectedGetAndSet = nameof(AAssertNoOtherCalls.GetAndSet)); 19 | mock.Protected().AssertSet_When(f => f.ProtectedSetOnly = nameof(AAssertNoOtherCalls.SetOnly)); 20 | mock.Protected().AssertSet_When(f => f["123"] = "indexer_set"); 21 | mock.Protected().AssertGet(f => f.ProtectedGetAndSet); 22 | mock.Protected().AssertGet(f => f.ProtectedGetOnly); 23 | mock.Protected().AssertGet(f => f["456"]); 24 | mock.Protected().Assert(f => f.ProtectedFunction(nameof(AAssertNoOtherCalls.Function))); 25 | mock.Protected().Assert(f => f.ProtectedMethod(nameof(AAssertNoOtherCalls.Method))); 26 | 27 | return 42; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AbstractClassWithBasicProperty.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.AbstractClass 4 | { 5 | public abstract class AAbstractClassWithBasicProperty 6 | { 7 | public abstract int OnlyGet { get; } 8 | public abstract int GetAndSet { get; set; } 9 | 10 | public string NonAbstractNonVirtualProperty 11 | => throw new System.NotImplementedException(); 12 | 13 | protected abstract int ProtectedOnlyGet { get; } 14 | protected abstract int ProtectedGetAndSet { get; set; } 15 | 16 | protected internal abstract int ProtectedInternalOnlyGet { get; } 17 | protected internal abstract int ProtectedInternalGetAndSet { get; set; } 18 | 19 | protected string ProtectedNonAbstractNonVirtualProperty 20 | => throw new System.NotImplementedException(); 21 | 22 | public int InvokeProtectedOnlyGet => ProtectedOnlyGet; 23 | public int InvokeProtectedGetAndSet 24 | { 25 | get => ProtectedGetAndSet; 26 | set => ProtectedGetAndSet = value; 27 | } 28 | 29 | public int InvokeProtectedInternalOnlyGet => ProtectedInternalOnlyGet; 30 | public int InvokeProtectedInternalGetAndSet 31 | { 32 | get => ProtectedInternalGetAndSet; 33 | set => ProtectedInternalGetAndSet = value; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/GenericAbstractClass.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Xunit; 3 | using LightMock.Generator.Tests.TestAbstractions; 4 | 5 | namespace LightMock.Generator.Tests.AbstractClass 6 | { 7 | public class GenericAbstractClass : ITestScript> 8 | { 9 | private readonly Mock> mock; 10 | 11 | public GenericAbstractClass() 12 | => mock = new Mock>(); 13 | 14 | public IMock> Context => mock; 15 | 16 | public AGenericAbstractClass MockObject => mock.Object; 17 | 18 | public int DoRun() 19 | { 20 | mock.Object.InvokeProtectedDoSomething(1234); 21 | mock.Protected().Assert(f => f.ProtectedDoSomething(1234)); 22 | 23 | mock.Protected().Arrange(f => f.ProtectedGetSomething()).Returns(5678); 24 | Assert.Equal(5678, mock.Object.InvokeProtectedGetSomething()); 25 | 26 | mock.Protected().Arrange(f => f.ProtectedOnlyGet).Returns(9012); 27 | Assert.Equal(9012, mock.Object.InvokeProtectedOnlyGet); 28 | 29 | mock.Protected().ArrangeProperty(f => f.ProtectedGetAndSet); 30 | mock.Object.InvokeProtectedGetAndSet = 3456; 31 | Assert.Equal(3456, mock.Object.InvokeProtectedGetAndSet); 32 | 33 | return 42; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AssertNoOtherCalls_Throws.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public class AssertNoOtherCalls_Throws : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public AssertNoOtherCalls_Throws() => mock = new Mock(); 11 | 12 | public IMock Context => mock; 13 | 14 | public AAssertNoOtherCalls_Throws MockObject => mock.Object; 15 | 16 | public int DoRun() 17 | { 18 | mock.Protected().AssertSet_When(f => f.ProtectedGetAndSet = nameof(AAssertNoOtherCalls.GetAndSet)); 19 | mock.Protected().AssertSet_When(f => f.ProtectedSetOnly = nameof(AAssertNoOtherCalls.SetOnly)); 20 | mock.Protected().AssertSet_When(f => f["123"] = "indexer_set"); 21 | mock.Protected().AssertGet(f => f.ProtectedGetAndSet); 22 | mock.Protected().AssertGet(f => f.ProtectedGetOnly); 23 | mock.Protected().AssertGet(f => f["456"]); 24 | mock.Protected().Assert(f => f.ProtectedFunction(nameof(AAssertNoOtherCalls.Function))); 25 | mock.Protected().Assert(f => f.ProtectedMethod(nameof(AAssertNoOtherCalls.Method))); 26 | 27 | return 42; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/LightMock.Generator/LightMock.Generator.Roslyn40.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | netstandard2.0 4 | false 5 | 6 | LightMock.Generator 7 | LightMock.Generator 8 | $(DefineConstants);ROSLYN_4 9 | false 10 | portable 11 | Debug;Release 12 | false 13 | 14 | 15 | 16 | 17 | 18 | true 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/BaseTests/ArgumentHelper_Tests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Xunit; 4 | 5 | namespace LightMock.Generator.Tests.BaseTests 6 | { 7 | public class ArgumentHelper_Tests 8 | { 9 | [Fact] 10 | public void Unpack_UsePacked() 11 | { 12 | const string ARG_NAME = nameof(ARG_NAME); 13 | var expected = new object(); 14 | var args = new Dictionary() 15 | { 16 | {ARG_NAME, expected}, 17 | }; 18 | 19 | var result = ArgumentHelper.Unpack(args, ARG_NAME); 20 | Assert.Same(expected, result); 21 | } 22 | 23 | [Fact] 24 | public void Unpack_UseDefault() 25 | { 26 | const string ARG_NAME = nameof(ARG_NAME); 27 | var args = new Dictionary(); 28 | 29 | var result = ArgumentHelper.Unpack(args, ARG_NAME); 30 | Assert.Null(result); 31 | } 32 | 33 | [Fact] 34 | public void Unpack_UseExplicitDefault() 35 | { 36 | const string ARG_NAME = nameof(ARG_NAME); 37 | object expected = new object(); 38 | var args = new Dictionary(); 39 | 40 | var result = ArgumentHelper.Unpack(args, ARG_NAME, expected); 41 | Assert.Same(expected, result); 42 | } 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AbstractClassWithBasicMethods.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Xunit; 3 | using LightMock.Generator.Tests.TestAbstractions; 4 | 5 | namespace LightMock.Generator.Tests.AbstractClass 6 | { 7 | public class AbstractClassWithBasicMethods : ITestScript 8 | { 9 | private readonly Mock mock; 10 | 11 | public AbstractClassWithBasicMethods() 12 | => mock = new Mock(); 13 | 14 | public IMock Context => mock; 15 | 16 | public AAbstractClassWithBasicMethods MockObject => mock.Object; 17 | 18 | public int DoRun() 19 | { 20 | mock.Protected().Arrange(f => f.ProtectedGetSomething()).Returns(1234); 21 | Assert.Equal(expected: 1234, mock.Object.InvokeProtectedGetSomething()); 22 | 23 | mock.Object.InvokeProtectedDoSomething(5678); 24 | mock.Protected().Assert(f => f.ProtectedDoSomething(5678)); 25 | 26 | mock.Protected().Arrange(f => f.ProtectedInternalGetSomething()).Returns(1234); 27 | Assert.Equal(expected: 1234, mock.Object.InvokeProtectedInternalGetSomething()); 28 | 29 | mock.Object.InvokeProtectedInternalDoSomething(5678); 30 | mock.Protected().Assert(f => f.ProtectedInternalDoSomething(5678)); 31 | 32 | return 42; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AssertNoOtherCalls.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.AbstractClass 4 | { 5 | public abstract class AAssertNoOtherCalls 6 | { 7 | public abstract string GetOnly { get; } 8 | public abstract string SetOnly { set; } 9 | public abstract string GetAndSet { get; set; } 10 | public abstract string Function(string a); 11 | public abstract void Method(string a); 12 | 13 | protected abstract string ProtectedGetOnly { get; } 14 | protected abstract string ProtectedSetOnly { set; } 15 | protected abstract string ProtectedGetAndSet { get; set; } 16 | protected abstract string this[string index] { get; set; } 17 | protected abstract string ProtectedFunction(string a); 18 | protected abstract void ProtectedMethod(string a); 19 | 20 | public string InvokeProtectedGetOnly => ProtectedGetOnly; 21 | public string InvokeProtectedSetOnly { set { ProtectedSetOnly = value; } } 22 | public string InvokeProtectedGetAndSet { get => ProtectedGetAndSet; set { ProtectedGetAndSet = value; } } 23 | public string InvokeIndexerGet(string index) => this[index]; 24 | public string InvokeIndexerSet(string index, string value) => this[index] = value; 25 | public string InvokeProtectedFunction(string a) => ProtectedFunction(a); 26 | public void InvokeProtectedMethod(string a) => ProtectedMethod(a); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AssertNoOtherCalls_Throws.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LightMock.Generator.Tests.AbstractClass 4 | { 5 | public abstract class AAssertNoOtherCalls_Throws 6 | { 7 | public abstract string GetOnly { get; } 8 | public abstract string SetOnly { set; } 9 | public abstract string GetAndSet { get; set; } 10 | public abstract string Function(string a); 11 | public abstract void Method(string a); 12 | 13 | protected abstract string ProtectedGetOnly { get; } 14 | protected abstract string ProtectedSetOnly { set; } 15 | protected abstract string ProtectedGetAndSet { get; set; } 16 | protected abstract string this[string index] { get; set; } 17 | protected abstract string ProtectedFunction(string a); 18 | protected abstract void ProtectedMethod(string a); 19 | 20 | public string InvokeProtectedGetOnly => ProtectedGetOnly; 21 | public string InvokeProtectedSetOnly { set { ProtectedSetOnly = value; } } 22 | public string InvokeProtectedGetAndSet { get => ProtectedGetAndSet; set { ProtectedGetAndSet = value; } } 23 | public string InvokeIndexerGet(string index) => this[index]; 24 | public string InvokeIndexerSet(string index, string value) => this[index] = value; 25 | public string InvokeProtectedFunction(string a) => ProtectedFunction(a); 26 | public void InvokeProtectedMethod(string a) => ProtectedMethod(a); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Common/PropertyArrangement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Linq.Expressions; 5 | 6 | namespace LightMock 7 | { 8 | /// 9 | /// A class that represents an arrangement of a mocked property that 10 | /// returns a value of type . 11 | /// 12 | /// The type of the return value of the mocked property. 13 | sealed class PropertyArrangement : Arrangement, 14 | IPropertyArrangementInvocation, 15 | IArrangementInvocation 16 | { 17 | [AllowNull] 18 | private TResult result; 19 | 20 | /// 21 | /// Initializes a new instance of the class. 22 | /// 23 | /// The that specifies 24 | /// where to apply this . 25 | public PropertyArrangement(LambdaExpression expression) 26 | : base(expression) 27 | { 28 | result = default; 29 | } 30 | 31 | [return: MaybeNull] 32 | TResult IArrangementInvocation.Invoke(IInvocationInfo invocation, IDictionary? refValues) => result; 33 | 34 | void IPropertyArrangementInvocation.Invoke(TResult value) => result = value; 35 | 36 | } 37 | } -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/BaseTests/IFoo.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace LightMock.Generator.Tests.BaseTests 4 | { 5 | public interface IFoo 6 | { 7 | void Execute(int first); 8 | void Execute(int first, int second); 9 | void Execute(int first, int second, int third); 10 | void Execute(int first, int second, int third, int fourth); 11 | void Execute(int first, int second, int third, int fourth, int fifth); 12 | void Execute(int first, int second, int third, int fourth, int fifth, int sixth); 13 | 14 | string? Execute(); 15 | string? Execute(string value); 16 | string? Execute(string first, string second); 17 | string? Execute(string first, string second, string third); 18 | string? Execute(string first, string second, string third, string fourth); 19 | 20 | Task ExecuteAsync(); 21 | Task ExecuteAsync(string value); 22 | Task ExecuteAsync(string first, string second); 23 | Task ExecuteAsync(string first, string second, string third); 24 | Task ExecuteAsync(string first, string second, string third, string fourth); 25 | 26 | byte[]? Execute(byte[] array); 27 | 28 | string OutMethod(out string @string, out int @int); 29 | int RefMethod(ref string @string, ref int @int); 30 | } 31 | 32 | public interface IBar 33 | { 34 | void Execute(string value); 35 | string? Execute(); 36 | } 37 | } -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/ArrangeSetter.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public class ArrangeSetter : ITestScript 7 | { 8 | private readonly Mock mock; 9 | 10 | public ArrangeSetter() 11 | => mock = new Mock(); 12 | 13 | public IMock Context => mock; 14 | 15 | public AArrangeSetter MockObject => mock.Object; 16 | 17 | public int DoRun() 18 | { 19 | mock.ArrangeSetter(f => f.GetAndSet = The.Is(s => s == "1234")) 20 | .Throws(() => new ValidProgramException(nameof(AArrangeSetter.GetAndSet))); 21 | mock.ArrangeSetter(uidPart2: 271289, uidPart1: "c:\\some\\path\\to\\file", expression: f => f.SetOnly = The.Is(s => s == "4567")) 22 | .Throws(() => new ValidProgramException(nameof(AArrangeSetter.SetOnly))); 23 | mock.Protected().ArrangeSetter(f => f.ProtectedGetAndSet = The.Is(s => s == "8901")) 24 | .Throws(() => new ValidProgramException("ProtectedGetAndSet")); 25 | mock.Protected().ArrangeSetter(uidPart1: "c:\\some\\path\\to\\file", uidPart2: 819273, expression: f => f.ProtectedSetOnly = The.Is(s => s == "2345")) 26 | .Throws(() => new ValidProgramException("ProtectedSetOnly")); 27 | return 42; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/ArrangeAddRemove_When.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | using Xunit; 4 | 5 | namespace LightMock.Generator.Tests.AbstractClass 6 | { 7 | public class ArrangeAddRemove_When : ITestScript 8 | { 9 | private readonly Mock mock; 10 | 11 | public ArrangeAddRemove_When() => mock = new Mock(); 12 | 13 | public IMock Context => mock; 14 | 15 | public AArrangeAddRemove_When MockObject => mock.Object; 16 | 17 | public int DoRun() 18 | { 19 | mock.Protected().ArrangeAdd_When(f => f.ProtectedEventHandler += SomeEventHandler).Throws(); 20 | mock.Protected().ArrangeRemove_When(f => f.ProtectedEventHandler -= SomeEventHandler).Throws(); 21 | 22 | Assert.Throws(() => MockObject.InvokeProtectedEventHandler += SomeEventHandler); 23 | Assert.Throws(() => MockObject.InvokeProtectedEventHandler -= SomeEventHandler); 24 | 25 | MockObject.InvokeProtectedEventHandler += AnotherEventHandler; 26 | MockObject.InvokeProtectedEventHandler -= AnotherEventHandler; 27 | 28 | return 42; 29 | 30 | void SomeEventHandler(object o, EventArgs a) { } 31 | void AnotherEventHandler(object o, EventArgs a) { } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AbstractClassWithTaskMethod.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public abstract class AAbstractClassWithTaskMethod 7 | { 8 | public abstract Task FooAsync(); 9 | public abstract Task BarAsync(); 10 | public abstract Task BazAsync(); 11 | 12 | public virtual Task VirtualFooAsync() => null!; 13 | public virtual Task VirtualBarAsync() => null!; 14 | public virtual Task VirtualBazAsync() => null!; 15 | 16 | protected abstract Task ProtectedFooAsync(); 17 | protected abstract Task ProtectedBarAsync(); 18 | protected abstract Task ProtectedBazAsync(); 19 | 20 | protected virtual Task ProtectedVirtualFooAsync() => null!; 21 | protected virtual Task ProtectedVirtualBarAsync() => null!; 22 | protected virtual Task ProtectedVirtualBazAsync() => null!; 23 | 24 | public Task InvokeProtectedFooAsync() => ProtectedFooAsync(); 25 | public Task InvokeProtectedBarAsync() => ProtectedBarAsync(); 26 | public Task InvokeProtectedBazAsync()=> ProtectedBazAsync(); 27 | 28 | public Task InvokeProtectedVirtualFooAsync() => ProtectedVirtualFooAsync(); 29 | public Task InvokeProtectedVirtualBarAsync() => ProtectedVirtualBarAsync(); 30 | public Task InvokeProtectedVirtualBazAsync() => ProtectedVirtualBazAsync(); 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AbstractClassWithBasicProperty.test.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Xunit; 3 | using LightMock.Generator.Tests.TestAbstractions; 4 | 5 | namespace LightMock.Generator.Tests.AbstractClass 6 | { 7 | public class AbstractClassWithBasicProperty : ITestScript 8 | { 9 | private readonly Mock mock; 10 | 11 | public AbstractClassWithBasicProperty() 12 | => mock = new Mock(); 13 | 14 | public IMock Context => mock; 15 | 16 | public AAbstractClassWithBasicProperty MockObject => mock.Object; 17 | 18 | public int DoRun() 19 | { 20 | mock.Protected().Arrange(f => f.ProtectedOnlyGet).Returns(1234); 21 | Assert.Equal(1234, mock.Object.InvokeProtectedOnlyGet); 22 | 23 | mock.Protected().ArrangeProperty(f => f.ProtectedGetAndSet); 24 | mock.Object.InvokeProtectedGetAndSet = 5678; 25 | Assert.Equal(5678, mock.Object.InvokeProtectedGetAndSet); 26 | 27 | mock.Protected().Arrange(f => f.ProtectedInternalOnlyGet).Returns(1234); 28 | Assert.Equal(1234, mock.Object.InvokeProtectedInternalOnlyGet); 29 | 30 | mock.Protected().ArrangeProperty(f => f.ProtectedInternalGetAndSet); 31 | mock.Object.InvokeProtectedInternalGetAndSet = 5678; 32 | Assert.Equal(5678, mock.Object.InvokeProtectedInternalGetAndSet); 33 | 34 | return 42; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Issues/HintNames.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using System; 3 | using System.Threading.Tasks; 4 | using static LightMock.Generator.Tests.Issues.HintNames; 5 | 6 | namespace LightMock.Generator.Tests.Issues 7 | { 8 | public class HintNames : ITestScript 9 | { 10 | public interface I1 { } 11 | 12 | public delegate TResult SomeDelegate(T1 a1, T2 a2) 13 | where T1 : allows ref struct 14 | where T2 : I1, allows ref struct 15 | where TResult : new(), allows ref struct; 16 | 17 | 18 | private readonly Mock mock; 19 | 20 | public HintNames() 21 | => mock = new Mock(); 22 | 23 | public IMock Context => mock; 24 | 25 | public IHintNames MockObject => mock.Object; 26 | 27 | public int DoRun() 28 | { 29 | new Mock(); 30 | new Mock>(); 31 | new Mock>(); 32 | new Mock>(); 33 | new Mock>(); 34 | new Mock>>(); 35 | new Mock>(); 36 | new Mock>(); 37 | new Mock>>(); 38 | new Mock(); 39 | new Mock>(); 40 | new Mock>(); 41 | new Mock>>(); 42 | return 42; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AbstractClassWithMultipleNamespaces.test.cs: -------------------------------------------------------------------------------- 1 | using LightMock; 2 | using System; 3 | using Xunit; 4 | using LightMock.Generator.Tests.TestAbstractions; 5 | 6 | namespace LightMock.Generator.Tests.AbstractClass 7 | { 8 | using Namespace1; 9 | using Namespace2; 10 | 11 | public class AbstractClassWithMultipleNamespaces : ITestScript 12 | { 13 | private readonly Mock mock; 14 | 15 | public AbstractClassWithMultipleNamespaces() 16 | => mock = new Mock(); 17 | 18 | public IMock Context => mock; 19 | 20 | public AAbstractClassWithMultipleNamespaces MockObject => mock.Object; 21 | 22 | public int DoRun() 23 | { 24 | var arg1 = new MultipleNamespacesArgument(); 25 | mock.Object.InvokeProtectedDoSomething(arg1); 26 | mock.Protected().Assert(f => f.ProtectedDoSomething(arg1)); 27 | 28 | var arg2 = new MultipleNamespacesArgument(); 29 | mock.Protected().Arrange(f => f.ProtectedGetSomething()).Returns(arg2); 30 | Assert.Same(expected: arg2, mock.Object.InvokeProtectedGetSomething()); 31 | 32 | var arg3 = new MultipleNamespacesArgument(); 33 | mock.Protected().ArrangeProperty(f => f.ProtectedSomeProperty); 34 | mock.Object.InvokeProtectedSomeProperty = arg3; 35 | Assert.Same(expected: arg3, mock.Object.InvokeProtectedSomeProperty); 36 | 37 | return 42; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/LightMock.Generator/CodeGenerationContext.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis; 2 | using Microsoft.CodeAnalysis.CSharp; 3 | using Microsoft.CodeAnalysis.Text; 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | namespace LightMock.Generator 8 | { 9 | record struct CodeGenerationContext( 10 | #if ROSLYN_4 11 | SourceProductionContext Context, 12 | #else 13 | GeneratorExecutionContext Context, 14 | #endif 15 | CSharpCompilation Compilation, 16 | CSharpParseOptions ParseOptions, 17 | CompilationContext CompilationContext) 18 | { 19 | public void ReportDiagnostic(Diagnostic diagnostic) 20 | => Context.ReportDiagnostic(diagnostic); 21 | 22 | public void AddSource(string hint, SourceText text) 23 | => Context.AddSource(hint, text); 24 | 25 | public CodeGenerationContext Update(CSharpCompilation compilation) 26 | => new CodeGenerationContext(Context, compilation, ParseOptions, CompilationContext); 27 | 28 | public bool EmitDiagnostics(IEnumerable diagnostics) 29 | { 30 | bool haveIssues = false; 31 | foreach (var d in diagnostics) 32 | { 33 | haveIssues = true; 34 | ReportDiagnostic(d); 35 | } 36 | return haveIssues; 37 | } 38 | 39 | public CodeGenerationContext AddSyntaxTrees(params SyntaxTree[] trees) 40 | { 41 | return Update(Compilation.AddSyntaxTrees(trees)); 42 | } 43 | 44 | public CodeGenerationContext UpdateFromCompilationContext() 45 | => Update(CompilationContext.Update(Compilation)); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/AbstractClass/AbstractClassWithGenericMethod.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace LightMock.Generator.Tests.AbstractClass 5 | { 6 | public abstract class AAbstractClassWithGenericMethod 7 | { 8 | public abstract T GenericReturn(); 9 | public abstract Task GenericReturnAsync() where T : class; 10 | public abstract void GenericParam(T p); 11 | public abstract void GenericWithClassConstraint(T? p) where T : class; 12 | public abstract void GenericWithStructConstraint(T p) where T : struct; 13 | public abstract void GenericWithConstraint(T p) where T : IEquatable, new(); 14 | public abstract void GenericWithManyConstraints(T1? p1, T2 p2, T3 p3) 15 | where T1 : class, new() 16 | where T2 : struct, IEquatable 17 | where T3 : IEquatable, new(); 18 | 19 | protected abstract T ProtectedGenericReturn(); 20 | protected abstract Task ProtectedGenericReturnAsync() where T : class; 21 | protected abstract void ProtectedGenericParam(T p); 22 | protected abstract void ProtectedGenericWithClassConstraint(T? p) where T : class; 23 | protected abstract void ProtectedGenericWithStructConstraint(T p) where T : struct; 24 | protected abstract void ProtectedGenericWithConstraint(T p) where T : IEquatable, new(); 25 | protected abstract void ProtectedGenericWithManyConstraints(T1? p1, T2 p2, T3 p3) 26 | where T1 : class, new() 27 | where T2 : struct, IEquatable 28 | where T3 : IEquatable, new(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Mocks/MockAnalyzerConfigOptionsProvider.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.CodeAnalysis; 2 | using Microsoft.CodeAnalysis.Diagnostics; 3 | using System; 4 | using System.Collections.Immutable; 5 | 6 | namespace LightMock.Generator.Tests.Mocks 7 | { 8 | sealed class MockAnalyzerConfigOptionsProvider : AnalyzerConfigOptionsProvider 9 | { 10 | private readonly ImmutableDictionary otherOptions; 11 | 12 | public MockAnalyzerConfigOptionsProvider(AnalyzerConfigOptions globalOptions) 13 | : this(globalOptions, ImmutableDictionary.Empty) 14 | { } 15 | 16 | public MockAnalyzerConfigOptionsProvider(AnalyzerConfigOptions globalOptions, 17 | ImmutableDictionary otherOptions) 18 | { 19 | GlobalOptions = globalOptions; 20 | this.otherOptions = otherOptions; 21 | } 22 | 23 | public static MockAnalyzerConfigOptionsProvider Empty { get; } 24 | = new MockAnalyzerConfigOptionsProvider( 25 | MockAnalyzerConfigOptions.Empty, 26 | ImmutableDictionary.Empty); 27 | 28 | public override AnalyzerConfigOptions GlobalOptions { get; } 29 | 30 | public override AnalyzerConfigOptions GetOptions(SyntaxTree tree) 31 | => GetOptionsPrivate(tree); 32 | 33 | public override AnalyzerConfigOptions GetOptions(AdditionalText textFile) 34 | => GetOptionsPrivate(textFile); 35 | 36 | AnalyzerConfigOptions GetOptionsPrivate(object o) 37 | => otherOptions.TryGetValue(o, out var options) ? options : MockAnalyzerConfigOptions.Empty; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/LightMock.Generator/ExceptionMessages.cs: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | MIT License 3 | 4 | Copyright (c) 2021 Anton Yashin 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | ******************************************************************************* 25 | https://github.com/anton-yashin/ 26 | *******************************************************************************/ 27 | using System; 28 | using System.Collections.Generic; 29 | using System.Text; 30 | 31 | namespace LightMock.Generator 32 | { 33 | static class ExceptionMessages 34 | { 35 | public const string OnRefStructMethod = "Can't implement methods with ref-struct params"; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Common/Generator/TypeExtensions.cs: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | MIT License 3 | 4 | Copyright (c) 2021 Anton Yashin 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | ******************************************************************************* 25 | https://github.com/anton-yashin/ 26 | *******************************************************************************/ 27 | using System; 28 | 29 | namespace LightMock.Generator 30 | { 31 | static class TypeExtensions 32 | { 33 | readonly static Type DelegateType = typeof(Delegate); 34 | 35 | public static bool IsDelegate(this Type @this) 36 | => @this.IsSubclassOf(DelegateType); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/LightMock.Generator/GlobalOptionsNames.cs: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | MIT License 3 | 4 | Copyright (c) 2021 Anton Yashin 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | ******************************************************************************* 25 | https://github.com/anton-yashin/ 26 | *******************************************************************************/ 27 | using System; 28 | using System.Collections.Generic; 29 | using System.Text; 30 | 31 | namespace LightMock.Generator 32 | { 33 | internal static class GlobalOptionsNames 34 | { 35 | const string Prefix = "build_property.LightMockGenerator_"; 36 | public const string Enable = Prefix + "Enable"; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Common/Generator/LambdaRequest.cs: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | MIT License 3 | 4 | Copyright (c) 2021 Anton Yashin 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | ******************************************************************************* 25 | https://github.com/anton-yashin/ 26 | *******************************************************************************/ 27 | 28 | using System; 29 | using System.Linq.Expressions; 30 | 31 | namespace LightMock.Generator 32 | { 33 | sealed class LambdaRequest : ILambdaRequest 34 | { 35 | public LambdaExpression? Result { get; private set; } 36 | 37 | public void SetResult(LambdaExpression result) => Result = result; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/LightMock.Generator.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net9.0 5 | 6 | false 7 | preview 8 | enable 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | runtime; build; native; contentfiles; analyzers; buildtransitive 18 | all 19 | 20 | 21 | runtime; build; native; contentfiles; analyzers; buildtransitive 22 | all 23 | 24 | 25 | 26 | runtime; build; native; contentfiles; analyzers; buildtransitive 27 | all 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Common/ILockedCollection.cs: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | MIT License 3 | 4 | Copyright (c) 2021 Anton Yashin 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | ******************************************************************************* 25 | https://github.com/anton-yashin/ 26 | *******************************************************************************/ 27 | using System; 28 | using System.Collections.Generic; 29 | 30 | namespace LightMock 31 | { 32 | internal interface ILockedCollection : ICollection 33 | { 34 | void InvokeLocked(Action> action); 35 | TResult InvokeLocked(Func, TResult> func); 36 | T[] ToArray(); 37 | void AddRange(IEnumerable range); 38 | } 39 | } -------------------------------------------------------------------------------- /src/LightMock.Generator.Common/Generator/Tags/Tags.cs: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | MIT License 3 | 4 | Copyright (c) 2021 Anton Yashin 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | ******************************************************************************* 25 | https://github.com/anton-yashin/ 26 | *******************************************************************************/ 27 | 28 | namespace LightMock.Generator.Tags 29 | { 30 | sealed class MockInstanceTag { } 31 | sealed class ProtectedContextTag { } 32 | sealed class PropertiesContextTag { } 33 | sealed class RefReturnContextTag { } 34 | sealed class AssertWhenTag { } 35 | sealed class AssertWhenAnyTag { } 36 | sealed class ArrangeWhenTag { } 37 | sealed class ArrangeWhenAnyTag { } 38 | } 39 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/Attributes_Test.cs: -------------------------------------------------------------------------------- 1 | using LightMock.Generator.Tests.TestAbstractions; 2 | using Microsoft.CodeAnalysis; 3 | using Microsoft.CodeAnalysis.CSharp; 4 | using System; 5 | using System.Collections.Immutable; 6 | using System.IO; 7 | using System.Linq; 8 | using System.Runtime.Loader; 9 | using Xunit; 10 | using Xunit.Abstractions; 11 | 12 | namespace LightMock.Generator.Tests 13 | { 14 | public class Attributes_Test : GeneratorTestsBase 15 | { 16 | const int KExpected = 42; 17 | 18 | public Attributes_Test(ITestOutputHelper testOutputHelper) 19 | : base(testOutputHelper) 20 | { } 21 | 22 | [Theory, InlineData(false), InlineData(true)] 23 | public void DisableCodeGeneration(bool enable) 24 | { 25 | var name = nameof(DisableCodeGeneration); 26 | if (enable) 27 | name = name.Replace("Disable", "Enable"); 28 | var compilation = CreateCompilation(Utils.LoadResource( 29 | GetFullResourceName(name)), name + Suffix.CSharpFile); 30 | var driver = CreateGenerationDriver(compilation); 31 | driver.RunGeneratorsAndUpdateCompilation(compilation, out var updatedCompilation, out var diagnostics); 32 | var ms = new MemoryStream(); 33 | var result = updatedCompilation.Emit(ms); 34 | Assert.True(result.Success); 35 | ms.Position = 0; 36 | var alc = new AssemblyLoadContext(nameof(DisableCodeGeneration)); 37 | var loadedAssembly = alc.LoadFromStream(ms); 38 | var mockIsGenerated = loadedAssembly.ExportedTypes.Where(t => t.Name == "Property_IDisableCodeGeneration").Any(); 39 | Assert.Equal(expected: enable, actual: mockIsGenerated); 40 | } 41 | 42 | protected override string GetFullResourceName(string resourceName) 43 | => "Attributes." + resourceName + ".test.cs"; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Common/ExpressionReflect/ExpressionExtensions.cs: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2013 Matthias Gernand 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | ****************************************************************************** 23 | https://github.com/mgernand 24 | ******************************************************************************/ 25 | using System.Linq.Expressions; 26 | 27 | namespace ExpressionReflect 28 | { 29 | static class ExpressionExtensions 30 | { 31 | public static object? Execute(this Expression expression, params object[] values) 32 | { 33 | ExpressionReflectionExecutor visitor = new ExpressionReflectionExecutor(expression); 34 | object? result = visitor.Execute(values); 35 | return result; 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /src/LightMock.Generator.Common/IMatchInfo.cs: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | MIT License 3 | 4 | Copyright (c) 2021 Anton Yashin 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | ******************************************************************************* 25 | https://github.com/anton-yashin/ 26 | *******************************************************************************/ 27 | using System; 28 | using System.Collections.Generic; 29 | using System.Text; 30 | 31 | namespace LightMock 32 | { 33 | internal interface IMatchInfo : IEquatable 34 | { 35 | bool Matches(IInvocationInfo? invocationInfo); 36 | } 37 | 38 | internal interface IMatchInfo : IMatchInfo 39 | where T : IInvocationInfo 40 | { 41 | bool Matches(T? invocationInfo); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Common/LightMock.Generator.Common.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | LightMock 6 | 7 | LightMock.Generator.Common 8 | This package is dependency for LightMock.Generator 9 | This package is dependency for LightMock.Generator 10 | 11 | preview 12 | enable 13 | 14 | bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml 15 | true 16 | 17 | true 18 | true 19 | true 20 | snupkg 21 | 22 | 23 | 24 | 25 | 26 | 27 | all 28 | runtime; build; native; contentfiles; analyzers; buildtransitive 29 | 30 | 31 | all 32 | runtime; build; native; contentfiles; analyzers; buildtransitive 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/LightMock.Generator/VariableNames.cs: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | MIT License 3 | 4 | Copyright (c) 2021 Anton Yashin 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | ******************************************************************************* 25 | https://github.com/anton-yashin/ 26 | *******************************************************************************/ 27 | namespace LightMock.Generator 28 | { 29 | static class VariableNames 30 | { 31 | public const string Context = "context"; 32 | public const string ProtectedContext = "protectedContext"; 33 | public const string PropertiesContext = "propertiesContext"; 34 | public const string Invoked = "invoked"; 35 | public const string Request = "request"; 36 | public const string RefReturnContext = "refReturnContext"; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Tests/LightMock.Generator.Tests.Roslyn40.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net9.0 5 | 6 | false 7 | preview 8 | enable 9 | $(DefineConstants);ROSLYN_4 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | runtime; build; native; contentfiles; analyzers; buildtransitive 19 | all 20 | 21 | 22 | runtime; build; native; contentfiles; analyzers; buildtransitive 23 | all 24 | 25 | 26 | 27 | runtime; build; native; contentfiles; analyzers; buildtransitive 28 | all 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Common/ExpressionReflect/ExpressionExecutionException.cs: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2013 Matthias Gernand 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | ****************************************************************************** 23 | https://github.com/mgernand 24 | ******************************************************************************/ 25 | using System; 26 | using System.Diagnostics.CodeAnalysis; 27 | 28 | namespace ExpressionReflect 29 | { 30 | [ExcludeFromCodeCoverage] 31 | class ExpressionExecutionException : Exception 32 | { 33 | public ExpressionExecutionException() 34 | { 35 | } 36 | 37 | public ExpressionExecutionException(string message) 38 | : base(message) 39 | { 40 | } 41 | 42 | public ExpressionExecutionException(string message, Exception inner) 43 | : base(message, inner) 44 | { 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /src/LightMock.Generator/Suffix.cs: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | MIT License 3 | 4 | Copyright (c) 2021 Anton Yashin 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | ******************************************************************************* 25 | https://github.com/anton-yashin/ 26 | *******************************************************************************/ 27 | namespace LightMock.Generator 28 | { 29 | static class Suffix 30 | { 31 | public const string FileName = ".spg.g.cs"; 32 | public const string CSharpFile = ".cs"; 33 | public const string ImplFile = "_Impl"; 34 | public const string Getter = "_GETTER"; 35 | public const string Setter = "_SETTER"; 36 | public const string Indexer = "_INDEXER"; 37 | public const string Add = "_ADD"; 38 | public const string Remove = "_REMOVE"; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Common/Generator/IProtectedContext.cs: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | MIT License 3 | 4 | Copyright (c) 2021 Anton Yashin 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | ******************************************************************************* 25 | https://github.com/anton-yashin/ 26 | *******************************************************************************/ 27 | using System.ComponentModel; 28 | 29 | namespace LightMock.Generator 30 | { 31 | /// 32 | /// For internal usage 33 | /// 34 | [EditorBrowsable(EditorBrowsableState.Never)] 35 | public interface IProtectedContext where T : class 36 | { 37 | /// 38 | /// For internal usage 39 | /// 40 | [EditorBrowsable(EditorBrowsableState.Never)] 41 | object ProtectedContext { get; } 42 | } 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Common/Generator/IDelegateProvider.cs: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | MIT License 3 | 4 | Copyright (c) 2021 Anton Yashin 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | ******************************************************************************* 25 | https://github.com/anton-yashin/ 26 | *******************************************************************************/ 27 | using System; 28 | using System.ComponentModel; 29 | 30 | namespace LightMock.Generator 31 | { 32 | 33 | /// 34 | /// For internal usage 35 | /// 36 | [EditorBrowsable(EditorBrowsableState.Never)] 37 | public interface IDelegateProvider 38 | { 39 | /// 40 | /// For internal usage 41 | /// 42 | /// 43 | [EditorBrowsable(EditorBrowsableState.Never)] 44 | Delegate GetDelegate(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Common/Generator/ILambdaRequest.cs: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | MIT License 3 | 4 | Copyright (c) 2021 Anton Yashin 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | ******************************************************************************* 25 | https://github.com/anton-yashin/ 26 | *******************************************************************************/ 27 | using System; 28 | using System.ComponentModel; 29 | using System.Linq.Expressions; 30 | 31 | namespace LightMock.Generator 32 | { 33 | /// 34 | /// For internal usage 35 | /// 36 | [EditorBrowsable(EditorBrowsableState.Never)] 37 | 38 | public interface ILambdaRequest 39 | { 40 | /// 41 | /// For internal usage 42 | /// 43 | [EditorBrowsable(EditorBrowsableState.Never)] 44 | void SetResult(LambdaExpression result); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/LightMock.Generator.Common/Generator/AbstractMockNameofProvider.cs: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | MIT License 3 | 4 | Copyright (c) 2021 Anton Yashin 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | ******************************************************************************* 25 | https://github.com/anton-yashin/ 26 | *******************************************************************************/ 27 | using System; 28 | using System.Collections.Generic; 29 | using System.Diagnostics.CodeAnalysis; 30 | using System.Linq.Expressions; 31 | 32 | namespace LightMock.Generator 33 | { 34 | /// 35 | /// Use this class with nameof operator 36 | /// 37 | [ExcludeFromCodeCoverage] 38 | internal sealed class AbstractMockNameofProvider : AbstractMock 39 | { 40 | public AbstractMockNameofProvider(object[] prms) : base(prms) 41 | { 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/LightMock.Generator/PropertyDefinitionVisitor.cs: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | MIT License 3 | 4 | Copyright (c) 2021 Anton Yashin 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | ******************************************************************************* 25 | https://github.com/anton-yashin/ 26 | *******************************************************************************/ 27 | using Microsoft.CodeAnalysis; 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Text; 31 | 32 | namespace LightMock.Generator 33 | { 34 | sealed class PropertyDefinitionVisitor : SymbolVisitor 35 | { 36 | public override string? VisitProperty(IPropertySymbol symbol) 37 | => new StringBuilder().AppendPropertyDefinition(symbol).ToString(); 38 | 39 | public override string? VisitEvent(IEventSymbol symbol) 40 | => new StringBuilder().AppendEventDefinition(symbol).ToString(); 41 | } 42 | } 43 | --------------------------------------------------------------------------------