diff --git a/Lib/Castle/ASL - Apache Software Foundation License.txt b/Lib/Castle/ASL - Apache Software Foundation License.txt index 9e90f827b..e259b5841 100644 --- a/Lib/Castle/ASL - Apache Software Foundation License.txt +++ b/Lib/Castle/ASL - Apache Software Foundation License.txt @@ -1,57 +1,57 @@ -Apache License, Version 2.0 - -Apache License -Version 2.0, January 2004 -http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - -"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. - -"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. - -"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. - -"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. - -"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. - -"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. - -"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). - -"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. - -"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." - -"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: - - 1. You must give any other recipients of the Work or Derivative Works a copy of this License; and - - 2. You must cause any modified files to carry prominent notices stating that You changed the files; and - - 3. You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and - - 4. If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. - -You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS +Apache License, Version 2.0 + +Apache License +Version 2.0, January 2004 +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. + +"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: + + 1. You must give any other recipients of the Work or Derivative Works a copy of this License; and + + 2. You must cause any modified files to carry prominent notices stating that You changed the files; and + + 3. You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and + + 4. If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. + +You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS diff --git a/Lib/xUnit/HTML.xslt b/Lib/xUnit/HTML.xslt index 50e593c47..181edb4a3 100644 --- a/Lib/xUnit/HTML.xslt +++ b/Lib/xUnit/HTML.xslt @@ -1,117 +1,117 @@ - - - - - - - - - ]]> - - - xUnit.net Test Results - <xsl:value-of select="@name"/> - - - - - -

Results for

-
- Tests run:   - Failures: , - Skipped: , - Run time: s -
- -
-

Failed tests

- -
- -
-

Failed fixtures

- -
- -
-

Skipped tests

- -
-
-

All tests

-
Click test class name to expand/collapse test details
- -
Results generated at
- - -
- - -
- altrow - s - Skipped - - -   - : -
- -
-
-
-
- - - :
- Stack Trace:
-
-
- - -

- s - - ToggleClass('class') - ToggleClass('class') - - -   -  ( tests) - -
-

-
- display: none; - class - -
-
- + + + + + + + + + ]]> + + + xUnit.net Test Results - <xsl:value-of select="@name"/> + + + + + +

Results for

+
+ Tests run:   + Failures: , + Skipped: , + Run time: s +
+ +
+

Failed tests

+ +
+ +
+

Failed fixtures

+ +
+ +
+

Skipped tests

+ +
+
+

All tests

+
Click test class name to expand/collapse test details
+ +
Results generated at
+ + +
+ + +
+ altrow + s + Skipped + + +   + : +
+ +
+
+
+
+ + + :
+ Stack Trace:
+
+
+ + +

+ s + + ToggleClass('class') + ToggleClass('class') + + +   +  ( tests) + +
+

+
+ display: none; + class + +
+
+
\ No newline at end of file diff --git a/Lib/xUnit/NUnitXml.xslt b/Lib/xUnit/NUnitXml.xslt index a6cad560a..4d82799f5 100644 --- a/Lib/xUnit/NUnitXml.xslt +++ b/Lib/xUnit/NUnitXml.xslt @@ -1,121 +1,121 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - False - True - - - - - - - - - - - - - - - - - - False - True - - - - - - - - - - - - - - - - - - - - - - - - - False - True - - - - False - True - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + False + True + + + + + + + + + + + + + + + + + + False + True + + + + + + + + + + + + + + + + + + + + + + + + + False + True + + + + False + True + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Readme.txt b/Lib/xUnit/XunitLight.Silverlight/Readme.txt index 51c1664d6..95de9c565 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Readme.txt +++ b/Lib/xUnit/XunitLight.Silverlight/Readme.txt @@ -1,3 +1,3 @@ -XunitLight.Silverlight.dll provides a minimalist port of xUnit APIs on running on top of the Microsoft Silverlight testing framework (see .\..\Microsoft folder) - +XunitLight.Silverlight.dll provides a minimalist port of xUnit APIs on running on top of the Microsoft Silverlight testing framework (see .\..\Microsoft folder) + Thanks Jason Jarrett! http://staxmanade.blogspot.com/ \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/Properties/AssemblyInfo.cs b/Lib/xUnit/XunitLight.Silverlight/Source/Properties/AssemblyInfo.cs index fa57b5692..9619d992c 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/Properties/AssemblyInfo.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/Properties/AssemblyInfo.cs @@ -1,35 +1,35 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("xUnitLight.Silverlight")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("xUnitLight.Silverlight")] -[assembly: AssemblyCopyright("Copyright © 2009")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("819b25cd-9089-4683-9c95-f38adee3b4a0")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Revision and Build Numbers -// by using the '*' as shown below: -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("xUnitLight.Silverlight")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("xUnitLight.Silverlight")] +[assembly: AssemblyCopyright("Copyright © 2009")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("819b25cd-9089-4683-9c95-f38adee3b4a0")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/TestClass.cs b/Lib/xUnit/XunitLight.Silverlight/Source/TestClass.cs index 68f0d9306..269d1a304 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/TestClass.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/TestClass.cs @@ -1,205 +1,205 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Reflection; -using Microsoft.Silverlight.Testing.Harness; - -namespace Microsoft.Silverlight.Testing.UnitTesting.Metadata.XunitLight -{ - /// - /// Test class wrapper. - /// - public class TestClass : ITestClass - { - /// - /// Construct a new test class metadata interface. - /// - /// Assembly metadata interface object. - private TestClass(IAssembly assembly) - { - _tests = new List(); - - //_m = new Dictionary(4); - //_m[Methods.ClassCleanup] = null; - //_m[Methods.ClassInitialize] = null; - //_m[Methods.TestCleanup] = null; - //_m[Methods.TestInitialize] = null; - - Assembly = assembly; - } - - /// - /// Creates a new test class wrapper. - /// - /// Assembly metadata object. - /// Type of the class. - public TestClass(IAssembly assembly, Type testClassType) - : this(assembly) - { - _type = testClassType; - - if (_type == null) - { - throw new ArgumentNullException("testClassType"); - } - - //_m[Methods.ClassCleanup] = new LazyMethodInfo(_type, ProviderAttributes.ClassCleanup); - //_m[Methods.ClassInitialize] = new LazyMethodInfo(_type, ProviderAttributes.ClassInitialize); - //_m[Methods.TestCleanup] = new LazyMethodInfo(_type, ProviderAttributes.TestCleanup); - //_m[Methods.TestInitialize] = new LazyMethodInfo(_type, ProviderAttributes.TestInitialize); - } - - /// - /// Methods enum. - /// - internal enum Methods - { - /// - /// Initialize method. - /// - ClassInitialize, - - /// - /// Cleanup method. - /// - ClassCleanup, - - /// - /// Test init method. - /// - TestInitialize, - - /// - /// Test cleanup method. - /// - TestCleanup, - } - - /// - /// Test Type. - /// - private Type _type; - - /// - /// Collection of test method interface objects. - /// - private ICollection _tests; - - /// - /// A value indicating whether tests are loaded. - /// - private bool _testsLoaded; - - /// - /// A dictionary of method types and method interface objects. - /// - private IDictionary _m; - - /// - /// Gets the test assembly metadata. - /// - public IAssembly Assembly - { - get; - protected set; - } - - /// - /// Gets the underlying Type of the test class. - /// - public Type Type - { - get { return _type; } - } - - /// - /// Gets the name of the test class. - /// - public string Name - { - get { return _type.Name; } - } - - /// - /// Gets a collection of test method wrapper instances. - /// - /// A collection of test method interface objects. - public ICollection GetTestMethods() - { - if (!_testsLoaded) - { - ICollection methods = - ReflectionUtility.GetMethodsWithAttribute( - _type, typeof(Xunit.FactAttribute)); - _tests = new List(methods.Count); - foreach (MethodInfo method in methods) - { - _tests.Add(new TestMethod(method)); - } - _testsLoaded = true; - } - return _tests; - } - - /// - /// Gets a value indicating whether an Ignore attribute present - /// on the class. - /// - public bool Ignore - { - get - { - return false; - //return ReflectionUtility.HasAttribute(_type, ProviderAttributes.IgnoreAttribute); - } - } - - /// - /// Gets any test initialize method. - /// - public MethodInfo TestInitializeMethod - { - get - { - return null; - //return _m[Methods.TestInitialize] == null ? null : _m[Methods.TestInitialize].GetMethodInfo(); - } - } - - /// - /// Gets any test cleanup method. - /// - public MethodInfo TestCleanupMethod - { - get - { - return null; - //return _m[Methods.TestCleanup] == null ? null : _m[Methods.TestCleanup].GetMethodInfo(); - } - } - - /// - /// Gets any class initialize method. - /// - public MethodInfo ClassInitializeMethod - { - get - { - return null; - //return _m[Methods.ClassInitialize] == null ? null : _m[Methods.ClassInitialize].GetMethodInfo(); - } - } - - /// - /// Gets any class cleanup method. - /// - public MethodInfo ClassCleanupMethod - { - get - { - return null; - //return _m[Methods.ClassCleanup] == null ? null : _m[Methods.ClassCleanup].GetMethodInfo(); - } - } - } +using System; +using System.Collections; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.Silverlight.Testing.Harness; + +namespace Microsoft.Silverlight.Testing.UnitTesting.Metadata.XunitLight +{ + /// + /// Test class wrapper. + /// + public class TestClass : ITestClass + { + /// + /// Construct a new test class metadata interface. + /// + /// Assembly metadata interface object. + private TestClass(IAssembly assembly) + { + _tests = new List(); + + //_m = new Dictionary(4); + //_m[Methods.ClassCleanup] = null; + //_m[Methods.ClassInitialize] = null; + //_m[Methods.TestCleanup] = null; + //_m[Methods.TestInitialize] = null; + + Assembly = assembly; + } + + /// + /// Creates a new test class wrapper. + /// + /// Assembly metadata object. + /// Type of the class. + public TestClass(IAssembly assembly, Type testClassType) + : this(assembly) + { + _type = testClassType; + + if (_type == null) + { + throw new ArgumentNullException("testClassType"); + } + + //_m[Methods.ClassCleanup] = new LazyMethodInfo(_type, ProviderAttributes.ClassCleanup); + //_m[Methods.ClassInitialize] = new LazyMethodInfo(_type, ProviderAttributes.ClassInitialize); + //_m[Methods.TestCleanup] = new LazyMethodInfo(_type, ProviderAttributes.TestCleanup); + //_m[Methods.TestInitialize] = new LazyMethodInfo(_type, ProviderAttributes.TestInitialize); + } + + /// + /// Methods enum. + /// + internal enum Methods + { + /// + /// Initialize method. + /// + ClassInitialize, + + /// + /// Cleanup method. + /// + ClassCleanup, + + /// + /// Test init method. + /// + TestInitialize, + + /// + /// Test cleanup method. + /// + TestCleanup, + } + + /// + /// Test Type. + /// + private Type _type; + + /// + /// Collection of test method interface objects. + /// + private ICollection _tests; + + /// + /// A value indicating whether tests are loaded. + /// + private bool _testsLoaded; + + /// + /// A dictionary of method types and method interface objects. + /// + private IDictionary _m; + + /// + /// Gets the test assembly metadata. + /// + public IAssembly Assembly + { + get; + protected set; + } + + /// + /// Gets the underlying Type of the test class. + /// + public Type Type + { + get { return _type; } + } + + /// + /// Gets the name of the test class. + /// + public string Name + { + get { return _type.Name; } + } + + /// + /// Gets a collection of test method wrapper instances. + /// + /// A collection of test method interface objects. + public ICollection GetTestMethods() + { + if (!_testsLoaded) + { + ICollection methods = + ReflectionUtility.GetMethodsWithAttribute( + _type, typeof(Xunit.FactAttribute)); + _tests = new List(methods.Count); + foreach (MethodInfo method in methods) + { + _tests.Add(new TestMethod(method)); + } + _testsLoaded = true; + } + return _tests; + } + + /// + /// Gets a value indicating whether an Ignore attribute present + /// on the class. + /// + public bool Ignore + { + get + { + return false; + //return ReflectionUtility.HasAttribute(_type, ProviderAttributes.IgnoreAttribute); + } + } + + /// + /// Gets any test initialize method. + /// + public MethodInfo TestInitializeMethod + { + get + { + return null; + //return _m[Methods.TestInitialize] == null ? null : _m[Methods.TestInitialize].GetMethodInfo(); + } + } + + /// + /// Gets any test cleanup method. + /// + public MethodInfo TestCleanupMethod + { + get + { + return null; + //return _m[Methods.TestCleanup] == null ? null : _m[Methods.TestCleanup].GetMethodInfo(); + } + } + + /// + /// Gets any class initialize method. + /// + public MethodInfo ClassInitializeMethod + { + get + { + return null; + //return _m[Methods.ClassInitialize] == null ? null : _m[Methods.ClassInitialize].GetMethodInfo(); + } + } + + /// + /// Gets any class cleanup method. + /// + public MethodInfo ClassCleanupMethod + { + get + { + return null; + //return _m[Methods.ClassCleanup] == null ? null : _m[Methods.ClassCleanup].GetMethodInfo(); + } + } + } } \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/TestMethod.cs b/Lib/xUnit/XunitLight.Silverlight/Source/TestMethod.cs index e8d931c54..cc6b7676b 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/TestMethod.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/TestMethod.cs @@ -1,215 +1,215 @@ -using System; -using System.Collections.Generic; -using System.Reflection; -using Microsoft.Silverlight.Testing.Harness; - -namespace Microsoft.Silverlight.Testing.UnitTesting.Metadata.XunitLight -{ - /// - /// A provider wrapper for a test method. - /// - public class TestMethod : ITestMethod - { - /// - /// Default value for methods when no priority attribute is defined. - /// - private const int DefaultPriority = 3; - - /// - /// An empty object array. - /// - private static readonly object[] None = { }; - - /// - /// Method reflection object. - /// - private MethodInfo _methodInfo; - - /// - /// Private constructor, the constructor requires the method reflection object. - /// - private TestMethod() { } - - /// - /// Creates a new test method wrapper object. - /// - /// The reflected method. - public TestMethod(MethodInfo methodInfo) - : this() - { - _methodInfo = methodInfo; - } - - /// - /// Allows the test to perform a string WriteLine. - /// - public event EventHandler WriteLine; - - /// - /// Call the WriteLine method. - /// - /// String to WriteLine. - internal void OnWriteLine(string s) - { - StringEventArgs sea = new StringEventArgs(s); - if (WriteLine != null) - { - WriteLine(this, sea); - } - } - - /// - /// Decorates a test class instance with the unit test framework's - /// specific test context capability, if supported. - /// - /// Instance to decorate. - public void DecorateInstance(object instance) - { - } - - /// - /// Gets the underlying reflected method. - /// - public MethodInfo Method - { - get { return _methodInfo; } - } - - /// - /// Gets a value indicating whether there is an Ignore attribute. - /// - public bool Ignore - { - get - { - var fact = ReflectionUtility.GetAttribute(this, typeof(Xunit.FactAttribute)) as Xunit.FactAttribute; - if (string.IsNullOrEmpty(fact.Skip)) - return false; - else - return true; - } - } - - /// - /// Gets any description marked on the test method. - /// - public string Description - { - get - { - var fact = GetFactAttribute(); - - if (fact != null) - return fact.Name; - - return null; - } - } - - private Xunit.FactAttribute GetFactAttribute() - { - return ReflectionUtility.GetAttribute(this, typeof(Xunit.FactAttribute), true) as Xunit.FactAttribute; - - } - - /// - /// Gets the name of the method. - /// - public virtual string Name - { - get { return _methodInfo.Name; } - } - - /// - /// Gets the Category. - /// - public string Category - { - get { return null; } - } - - /// - /// Gets the owner name of the test. - /// - public string Owner - { - get - { - return string.Empty; - } - } - - /// - /// Gets any expected exception attribute information for the test method. - /// - public IExpectedException ExpectedException - { - get - { - //Xunit has it's own exception handling assertion mechanism... - return null; - } - } - - /// - /// Gets any timeout. A Nullable property. - /// - public int? Timeout - { - get - { - var fact = GetFactAttribute(); - if (fact != null && fact.Timeout > 0) - return fact.Timeout; - return null; - } - } - - /// - /// Gets a Collection of test properties. - /// - public ICollection Properties - { - get { return null; } - } - - /// - /// Gets a collection of test work items. - /// - public ICollection WorkItems - { - get { return null; } - } - - /// - /// Gets Priority information. - /// - public IPriority Priority - { - get - { - return null; - } - } - - /// - /// Get any attribute on the test method that are provided dynamically. - /// - /// - /// Dynamically provided attributes on the test method. - /// - public virtual IEnumerable GetDynamicAttributes() - { - return new Attribute[] { }; - } - - /// - /// Invoke the test method. - /// - /// Instance of the test class. - public virtual void Invoke(object instance) - { - _methodInfo.Invoke(instance, None); - } - } +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.Silverlight.Testing.Harness; + +namespace Microsoft.Silverlight.Testing.UnitTesting.Metadata.XunitLight +{ + /// + /// A provider wrapper for a test method. + /// + public class TestMethod : ITestMethod + { + /// + /// Default value for methods when no priority attribute is defined. + /// + private const int DefaultPriority = 3; + + /// + /// An empty object array. + /// + private static readonly object[] None = { }; + + /// + /// Method reflection object. + /// + private MethodInfo _methodInfo; + + /// + /// Private constructor, the constructor requires the method reflection object. + /// + private TestMethod() { } + + /// + /// Creates a new test method wrapper object. + /// + /// The reflected method. + public TestMethod(MethodInfo methodInfo) + : this() + { + _methodInfo = methodInfo; + } + + /// + /// Allows the test to perform a string WriteLine. + /// + public event EventHandler WriteLine; + + /// + /// Call the WriteLine method. + /// + /// String to WriteLine. + internal void OnWriteLine(string s) + { + StringEventArgs sea = new StringEventArgs(s); + if (WriteLine != null) + { + WriteLine(this, sea); + } + } + + /// + /// Decorates a test class instance with the unit test framework's + /// specific test context capability, if supported. + /// + /// Instance to decorate. + public void DecorateInstance(object instance) + { + } + + /// + /// Gets the underlying reflected method. + /// + public MethodInfo Method + { + get { return _methodInfo; } + } + + /// + /// Gets a value indicating whether there is an Ignore attribute. + /// + public bool Ignore + { + get + { + var fact = ReflectionUtility.GetAttribute(this, typeof(Xunit.FactAttribute)) as Xunit.FactAttribute; + if (string.IsNullOrEmpty(fact.Skip)) + return false; + else + return true; + } + } + + /// + /// Gets any description marked on the test method. + /// + public string Description + { + get + { + var fact = GetFactAttribute(); + + if (fact != null) + return fact.Name; + + return null; + } + } + + private Xunit.FactAttribute GetFactAttribute() + { + return ReflectionUtility.GetAttribute(this, typeof(Xunit.FactAttribute), true) as Xunit.FactAttribute; + + } + + /// + /// Gets the name of the method. + /// + public virtual string Name + { + get { return _methodInfo.Name; } + } + + /// + /// Gets the Category. + /// + public string Category + { + get { return null; } + } + + /// + /// Gets the owner name of the test. + /// + public string Owner + { + get + { + return string.Empty; + } + } + + /// + /// Gets any expected exception attribute information for the test method. + /// + public IExpectedException ExpectedException + { + get + { + //Xunit has it's own exception handling assertion mechanism... + return null; + } + } + + /// + /// Gets any timeout. A Nullable property. + /// + public int? Timeout + { + get + { + var fact = GetFactAttribute(); + if (fact != null && fact.Timeout > 0) + return fact.Timeout; + return null; + } + } + + /// + /// Gets a Collection of test properties. + /// + public ICollection Properties + { + get { return null; } + } + + /// + /// Gets a collection of test work items. + /// + public ICollection WorkItems + { + get { return null; } + } + + /// + /// Gets Priority information. + /// + public IPriority Priority + { + get + { + return null; + } + } + + /// + /// Get any attribute on the test method that are provided dynamically. + /// + /// + /// Dynamically provided attributes on the test method. + /// + public virtual IEnumerable GetDynamicAttributes() + { + return new Attribute[] { }; + } + + /// + /// Invoke the test method. + /// + /// Instance of the test class. + public virtual void Invoke(object instance) + { + _methodInfo.Invoke(instance, None); + } + } } \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/UnitTestFrameworkAssembly.cs b/Lib/xUnit/XunitLight.Silverlight/Source/UnitTestFrameworkAssembly.cs index 1460d1e91..3a8e0a806 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/UnitTestFrameworkAssembly.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/UnitTestFrameworkAssembly.cs @@ -1,131 +1,131 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using Microsoft.Silverlight.Testing.Harness; - -namespace Microsoft.Silverlight.Testing.UnitTesting.Metadata.XunitLight -{ - /// - /// Assembly metadata for the Visual Studio Team Test unit test framework. - /// - public class UnitTestFrameworkAssembly : IAssembly - { - /// - /// Assembly reflection object. - /// - private Assembly _assembly; - - /// - /// Unit test provider used for the assembly. - /// - private IUnitTestProvider _provider; - - /// - /// The unit test harness. - /// - private UnitTestHarness _harness; - - /// - /// Creates a new unit test assembly wrapper. - /// - /// Unit test metadata provider. - /// A reference to the unit test harness. - /// Assembly reflection object. - public UnitTestFrameworkAssembly(IUnitTestProvider provider, UnitTestHarness unitTestHarness, Assembly assembly) - { - _provider = provider; - _harness = unitTestHarness; - _assembly = assembly; - } - - /// - /// Gets the name of the test assembly. - /// - public string Name - { - get - { - string n = _assembly.ToString(); - return (n.Contains(", ") ? n.Substring(0, n.IndexOf(",", StringComparison.Ordinal)) : n); - } - } - - /// - /// Gets the unit test provider instance. - /// - public IUnitTestProvider Provider - { - get { return _provider; } - } - - /// - /// Gets any assembly initialize method. - /// - public MethodInfo AssemblyInitializeMethod - { - get { return null; } - } - - /// - /// Gets any assembly cleanup method. - /// - public MethodInfo AssemblyCleanupMethod - { - get { return null; } - } - - /// - /// Gets the test harness used to initialize the assembly. - /// - public UnitTestHarness TestHarness - { - get { return _harness; } - } - - /// - /// Gets the test harness as a unit test harness. - /// - public UnitTestHarness UnitTestHarness - { - get { return _harness as UnitTestHarness; } - } - - /// - /// Reflect and retrieve the test class metadata wrappers for - /// the test assembly. - /// - /// Returns a collection of test class metadata - /// interface objects. - public ICollection GetTestClasses() - { - ICollection classes = _assembly.GetTypes().Where(t => ContainsAMethodWithAFactAttribute(t)).ToList(); - - List tests = new List(classes.Count); - foreach (Type type in classes) - { - tests.Add(new TestClass(this, type)); - } - return tests; - } - - private bool ContainsAMethodWithAFactAttribute(Type type) - { - if (type.IsPublic || type.IsNestedPublic) - { - if ((ReflectionUtility.GetMethodsWithAttribute(type, typeof(Xunit.FactAttribute)).Count > 0)) - return true; - - foreach (Type t in type.GetNestedTypes(BindingFlags.Public)) - { - if (ContainsAMethodWithAFactAttribute(t)) - return true; - } - } - - return false; - } - } - +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using Microsoft.Silverlight.Testing.Harness; + +namespace Microsoft.Silverlight.Testing.UnitTesting.Metadata.XunitLight +{ + /// + /// Assembly metadata for the Visual Studio Team Test unit test framework. + /// + public class UnitTestFrameworkAssembly : IAssembly + { + /// + /// Assembly reflection object. + /// + private Assembly _assembly; + + /// + /// Unit test provider used for the assembly. + /// + private IUnitTestProvider _provider; + + /// + /// The unit test harness. + /// + private UnitTestHarness _harness; + + /// + /// Creates a new unit test assembly wrapper. + /// + /// Unit test metadata provider. + /// A reference to the unit test harness. + /// Assembly reflection object. + public UnitTestFrameworkAssembly(IUnitTestProvider provider, UnitTestHarness unitTestHarness, Assembly assembly) + { + _provider = provider; + _harness = unitTestHarness; + _assembly = assembly; + } + + /// + /// Gets the name of the test assembly. + /// + public string Name + { + get + { + string n = _assembly.ToString(); + return (n.Contains(", ") ? n.Substring(0, n.IndexOf(",", StringComparison.Ordinal)) : n); + } + } + + /// + /// Gets the unit test provider instance. + /// + public IUnitTestProvider Provider + { + get { return _provider; } + } + + /// + /// Gets any assembly initialize method. + /// + public MethodInfo AssemblyInitializeMethod + { + get { return null; } + } + + /// + /// Gets any assembly cleanup method. + /// + public MethodInfo AssemblyCleanupMethod + { + get { return null; } + } + + /// + /// Gets the test harness used to initialize the assembly. + /// + public UnitTestHarness TestHarness + { + get { return _harness; } + } + + /// + /// Gets the test harness as a unit test harness. + /// + public UnitTestHarness UnitTestHarness + { + get { return _harness as UnitTestHarness; } + } + + /// + /// Reflect and retrieve the test class metadata wrappers for + /// the test assembly. + /// + /// Returns a collection of test class metadata + /// interface objects. + public ICollection GetTestClasses() + { + ICollection classes = _assembly.GetTypes().Where(t => ContainsAMethodWithAFactAttribute(t)).ToList(); + + List tests = new List(classes.Count); + foreach (Type type in classes) + { + tests.Add(new TestClass(this, type)); + } + return tests; + } + + private bool ContainsAMethodWithAFactAttribute(Type type) + { + if (type.IsPublic || type.IsNestedPublic) + { + if ((ReflectionUtility.GetMethodsWithAttribute(type, typeof(Xunit.FactAttribute)).Count > 0)) + return true; + + foreach (Type t in type.GetNestedTypes(BindingFlags.Public)) + { + if (ContainsAMethodWithAFactAttribute(t)) + return true; + } + } + + return false; + } + } + } \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/XUnitTestProvider.cs b/Lib/xUnit/XunitLight.Silverlight/Source/XUnitTestProvider.cs index d565b71f4..c6c16a53b 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/XUnitTestProvider.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/XUnitTestProvider.cs @@ -1,99 +1,99 @@ -using System; -using System.Collections.Generic; -using System.Reflection; -using Microsoft.Silverlight.Testing.Harness; - -namespace Microsoft.Silverlight.Testing.UnitTesting.Metadata.XunitLight -{ - /// - /// Provider xUnit metadata. - /// - public class XUnitTestProvider : IUnitTestProvider - { - /// - /// Name of this provider. - /// - private const string ProviderName = "xUnitLite"; - - /// - /// The capabilities of the xUnit provider. - /// - private const UnitTestProviderCapabilities MyCapabilities = - UnitTestProviderCapabilities.MethodCanIgnore; - - /// - /// Whether the capability is supported by this provider. - /// - /// Capability type. - /// A value indicating whether the capability is available. - public bool HasCapability(UnitTestProviderCapabilities capability) - { - return ((capability & MyCapabilities) == capability); - } - - /// - /// Create a new Visual Studio Team Test unit test framework provider - /// instance. - /// - public XUnitTestProvider() - { - _assemblyCache = new Dictionary(2); - } - - /// - /// Cache of assemblies and assembly unit test interface objects. - /// - private Dictionary _assemblyCache; - - /// - /// VSTT unit test provider constructor; takes an assembly reference to - /// perform reflection on to retrieve all test class types. In this - /// implementation of an engine for the VSTT metadata, only a single - /// test Assembly can be utilized at a time for simplicity. - /// - /// The unit test harness. - /// Assembly reflection object. - /// Returns the assembly metadata interface. - public IAssembly GetUnitTestAssembly(UnitTestHarness testHarness, Assembly assemblyReference) - { - if (_assemblyCache.ContainsKey(assemblyReference)) - { - return _assemblyCache[assemblyReference]; - } - else - { - _assemblyCache[assemblyReference] = new UnitTestFrameworkAssembly(this, testHarness, assemblyReference); - return _assemblyCache[assemblyReference]; - } - } - - /// - /// Check if the Exception is actually a failed assertion. - /// - /// Exception object to check. - /// True if the exception is actually an assert failure. - public bool IsFailedAssert(Exception exception) - { - throw new NotImplementedException(); - //Type et = exception.GetType(); - //Type nuAsserts = typeof(NU.AssertionException); - //return (et == nuAsserts || et.IsSubclassOf(nuAsserts)); - } - - /// - /// Gets the name of the provider. - /// - public string Name - { - get { return ProviderName; } - } - - /// - /// Gets the specialized capability descriptor. - /// - public UnitTestProviderCapabilities Capabilities - { - get { return MyCapabilities; } - } - } +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.Silverlight.Testing.Harness; + +namespace Microsoft.Silverlight.Testing.UnitTesting.Metadata.XunitLight +{ + /// + /// Provider xUnit metadata. + /// + public class XUnitTestProvider : IUnitTestProvider + { + /// + /// Name of this provider. + /// + private const string ProviderName = "xUnitLite"; + + /// + /// The capabilities of the xUnit provider. + /// + private const UnitTestProviderCapabilities MyCapabilities = + UnitTestProviderCapabilities.MethodCanIgnore; + + /// + /// Whether the capability is supported by this provider. + /// + /// Capability type. + /// A value indicating whether the capability is available. + public bool HasCapability(UnitTestProviderCapabilities capability) + { + return ((capability & MyCapabilities) == capability); + } + + /// + /// Create a new Visual Studio Team Test unit test framework provider + /// instance. + /// + public XUnitTestProvider() + { + _assemblyCache = new Dictionary(2); + } + + /// + /// Cache of assemblies and assembly unit test interface objects. + /// + private Dictionary _assemblyCache; + + /// + /// VSTT unit test provider constructor; takes an assembly reference to + /// perform reflection on to retrieve all test class types. In this + /// implementation of an engine for the VSTT metadata, only a single + /// test Assembly can be utilized at a time for simplicity. + /// + /// The unit test harness. + /// Assembly reflection object. + /// Returns the assembly metadata interface. + public IAssembly GetUnitTestAssembly(UnitTestHarness testHarness, Assembly assemblyReference) + { + if (_assemblyCache.ContainsKey(assemblyReference)) + { + return _assemblyCache[assemblyReference]; + } + else + { + _assemblyCache[assemblyReference] = new UnitTestFrameworkAssembly(this, testHarness, assemblyReference); + return _assemblyCache[assemblyReference]; + } + } + + /// + /// Check if the Exception is actually a failed assertion. + /// + /// Exception object to check. + /// True if the exception is actually an assert failure. + public bool IsFailedAssert(Exception exception) + { + throw new NotImplementedException(); + //Type et = exception.GetType(); + //Type nuAsserts = typeof(NU.AssertionException); + //return (et == nuAsserts || et.IsSubclassOf(nuAsserts)); + } + + /// + /// Gets the name of the provider. + /// + public string Name + { + get { return ProviderName; } + } + + /// + /// Gets the specialized capability descriptor. + /// + public UnitTestProviderCapabilities Capabilities + { + get { return MyCapabilities; } + } + } } \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Assert.cs b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Assert.cs index 1a6ffa98c..057633568 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Assert.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Assert.cs @@ -1,619 +1,619 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using Xunit.Sdk; - -namespace Xunit -{ - /// - /// Contains various static methods that are used to verify that conditions are met during the - /// process of running tests. - /// - public class Assert - { - /// - /// Used by the Throws and DoesNotThrow methods. - /// - public delegate void ThrowsDelegate(); - - /// - /// Initializes a new instance of the class. - /// - protected Assert() { } - - /// - /// Verifies that a collection contains a given object. - /// - /// The type of the object to be verified - /// The object expected to be in the collection - /// The collection to be inspected - /// Thrown when the object is not present in the collection - public static void Contains(T expected, - IEnumerable collection) - { - Contains(expected, collection, GetComparer()); - } - - /// - /// Verifies that a collection contains a given object, using a comparer. - /// - /// The type of the object to be verified - /// The object expected to be in the collection - /// The collection to be inspected - /// The comparer used to equate objects in the collection with the expected object - /// Thrown when the object is not present in the collection - public static void Contains(T expected, - IEnumerable collection, - IComparer comparer) - { - foreach (T item in collection) - if (comparer.Compare(expected, item) == 0) - return; - - throw new ContainsException(expected); - } - - /// - /// Verifies that a string contains a given sub-string, using the current culture. - /// - /// The sub-string expected to be in the string - /// The string to be inspected - /// Thrown when the sub-string is not present inside the string - public static void Contains(string expectedSubString, - string actualString) - { - Contains(expectedSubString, actualString, StringComparison.CurrentCulture); - } - - /// - /// Verifies that a string contains a given sub-string, using the given comparison type. - /// - /// The sub-string expected to be in the string - /// The string to be inspected - /// The type of string comparison to perform - /// Thrown when the sub-string is not present inside the string - public static void Contains(string expectedSubString, - string actualString, - StringComparison comparisonType) - { - if (actualString.IndexOf(expectedSubString, comparisonType) < 0) - throw new ContainsException(expectedSubString); - } - - /// - /// Verifies that a collection does not contain a given object. - /// - /// The type of the object to be compared - /// The object that is expected not to be in the collection - /// The collection to be inspected - /// Thrown when the object is present inside the container - public static void DoesNotContain(T expected, - IEnumerable collection) - { - DoesNotContain(expected, collection, GetComparer()); - } - - /// - /// Verifies that a collection does not contain a given object, using a comparer. - /// - /// The type of the object to be compared - /// The object that is expected not to be in the collection - /// The collection to be inspected - /// The comparer used to equate objects in the collection with the expected object - /// Thrown when the object is present inside the container - public static void DoesNotContain(T expected, - IEnumerable collection, - IComparer comparer) - { - foreach (T item in collection) - if (comparer.Compare(expected, item) == 0) - throw new DoesNotContainException(expected); - } - - /// - /// Verifies that a string does not contain a given sub-string, using the current culture. - /// - /// The sub-string which is expected not to be in the string - /// The string to be inspected - /// Thrown when the sub-string is present inside the string - public static void DoesNotContain(string expectedSubString, - string actualString) - { - DoesNotContain(expectedSubString, actualString, StringComparison.CurrentCulture); - } - - /// - /// Verifies that a string does not contain a given sub-string, using the current culture. - /// - /// The sub-string which is expected not to be in the string - /// The string to be inspected - /// The type of string comparison to perform - /// Thrown when the sub-string is present inside the given string - public static void DoesNotContain(string expectedSubString, - string actualString, - StringComparison comparisonType) - { - if (actualString.IndexOf(expectedSubString, comparisonType) >= 0) - throw new DoesNotContainException(expectedSubString); - } - - /// - /// Verifies that a block of code does not throw any exceptions. - /// - /// A delegate to the code to be tested - public static void DoesNotThrow(ThrowsDelegate testCode) - { - Exception ex = Record.Exception(testCode); - - if (ex != null) - throw new DoesNotThrowException(ex); - } - - /// - /// Verifies that a collection is empty. - /// - /// The collection to be inspected - /// Thrown when the collection is null - /// Thrown when the collection is not empty - public static void Empty(IEnumerable collection) - { - if (collection == null) throw new ArgumentNullException("collection", "cannot be null"); - -#pragma warning disable 168 - foreach (object @object in collection) - throw new EmptyException(); -#pragma warning restore 168 - } - - /// - /// Verifies that two objects are equal, using a default comparer. - /// - /// The type of the objects to be compared - /// The expected value - /// The value to be compared against - /// Thrown when the objects are not equal - public static void Equal(T expected, - T actual) - { - Equal(expected, actual, GetComparer()); - } - - /// - /// Verifies that two objects are equal, using a custom comparer. - /// - /// The type of the objects to be compared - /// The expected value - /// The value to be compared against - /// The comparer used to compare the two objects - /// Thrown when the objects are not equal - public static void Equal(T expected, - T actual, - IComparer comparer) - { - if (comparer.Compare(expected, actual) != 0) - throw new EqualException(expected, actual); - } - - /// Do not call this method. - [Obsolete("This is an override of Object.Equals(). Call Assert.Equal() instead.", true)] - public new static bool Equals(object a, - object b) - { - throw new InvalidOperationException("Assert.Equals should not be used"); - } - - /// - /// Verifies that the condition is false. - /// - /// The condition to be tested - /// Thrown if the condition is not false - public static void False(bool condition) - { - False(condition, null); - } - - /// - /// Verifies that the condition is false. - /// - /// The condition to be tested - /// The message to show when the condition is not false - /// Thrown if the condition is not false - public static void False(bool condition, - string userMessage) - { - if (condition) - throw new FalseException(userMessage); - } - - static IComparer GetComparer() - { - return new AssertComparer(); - } - - /// - /// Verifies that a value is within a given range. - /// - /// The type of the value to be compared - /// The actual value to be evaluated - /// The (inclusive) low value of the range - /// The (inclusive) high value of the range - /// Thrown when the value is not in the given range - public static void InRange(T actual, - T low, - T high) - { - InRange(actual, low, high, GetComparer()); - } - - /// - /// Verifies that a value is within a given range, using a comparer. - /// - /// The type of the value to be compared - /// The actual value to be evaluated - /// The (inclusive) low value of the range - /// The (inclusive) high value of the range - /// The comparer used to evaluate the value's range - /// Thrown when the value is not in the given range - public static void InRange(T actual, - T low, - T high, - IComparer comparer) - { - if (comparer.Compare(low, actual) > 0 || comparer.Compare(actual, high) > 0) - throw new InRangeException(actual, low, high); - } - - /// - /// Verifies that an object is of the given type or a derived type. - /// - /// The type the object should be - /// The object to be evaluated - /// The object, casted to type T when successful - /// Thrown when the object is not the given type - public static T IsAssignableFrom(object @object) - { - IsAssignableFrom(typeof(T), @object); - return (T)@object; - } - - /// - /// Verifies that an object is of the given type or a derived type. - /// - /// The type the object should be - /// The object to be evaluated - /// Thrown when the object is not the given type - public static void IsAssignableFrom(Type expectedType, - object @object) - { - if (@object == null || !expectedType.IsAssignableFrom(@object.GetType())) - throw new IsAssignableFromException(expectedType, @object); - } - - /// - /// Verifies that an object is not exactly the given type. - /// - /// The type the object should not be - /// The object to be evaluated - /// Thrown when the object is the given type - public static void IsNotType(object @object) - { - IsNotType(typeof(T), @object); - } - - /// - /// Verifies that an object is not exactly the given type. - /// - /// The type the object should not be - /// The object to be evaluated - /// Thrown when the object is the given type - public static void IsNotType(Type expectedType, - object @object) - { - if (expectedType.Equals(@object.GetType())) - throw new IsNotTypeException(expectedType, @object); - } - - /// - /// Verifies that an object is exactly the given type (and not a derived type). - /// - /// The type the object should be - /// The object to be evaluated - /// The object, casted to type T when successful - /// Thrown when the object is not the given type - public static T IsType(object @object) - { - IsType(typeof(T), @object); - return (T)@object; - } - - /// - /// Verifies that an object is exactly the given type (and not a derived type). - /// - /// The type the object should be - /// The object to be evaluated - /// Thrown when the object is not the given type - public static void IsType(Type expectedType, - object @object) - { - if (@object == null || !expectedType.Equals(@object.GetType())) - throw new IsTypeException(expectedType, @object); - } - - /// - /// Verifies that a collection is not empty. - /// - /// The collection to be inspected - /// Thrown when a null collection is passed - /// Thrown when the collection is empty - public static void NotEmpty(IEnumerable collection) - { - if (collection == null) throw new ArgumentNullException("collection", "cannot be null"); - -#pragma warning disable 168 - foreach (object @object in collection) - return; -#pragma warning restore 168 - - throw new NotEmptyException(); - } - - /// - /// Verifies that two objects are not equal, using a default comparer. - /// - /// The type of the objects to be compared - /// The expected object - /// The actual object - /// Thrown when the objects are equal - public static void NotEqual(T expected, - T actual) - { - NotEqual(expected, actual, GetComparer()); - } - - /// - /// Verifies that two objects are not equal, using a custom comparer. - /// - /// The type of the objects to be compared - /// The expected object - /// The actual object - /// The comparer used to examine the objects - /// Thrown when the objects are equal - public static void NotEqual(T expected, - T actual, - IComparer comparer) - { - if (comparer.Compare(expected, actual) == 0) - throw new NotEqualException(); - } - - /// - /// Verifies that a value is not within a given range, using the default comparer. - /// - /// The type of the value to be compared - /// The actual value to be evaluated - /// The (inclusive) low value of the range - /// The (inclusive) high value of the range - /// Thrown when the value is in the given range - public static void NotInRange(T actual, - T low, - T high) - { - NotInRange(actual, low, high, GetComparer()); - } - - /// - /// Verifies that a value is not within a given range, using a comparer. - /// - /// The type of the value to be compared - /// The actual value to be evaluated - /// The (inclusive) low value of the range - /// The (inclusive) high value of the range - /// The comparer used to evaluate the value's range - /// Thrown when the value is in the given range - public static void NotInRange(T actual, - T low, - T high, - IComparer comparer) - { - if (comparer.Compare(low, actual) <= 0 && comparer.Compare(actual, high) <= 0) - throw new NotInRangeException(actual, low, high); - } - - /// - /// Verifies that an object reference is not null. - /// - /// The object to be validated - /// Thrown when the object is not null - public static void NotNull(object @object) - { - if (@object == null) - throw new NotNullException(); - } - - /// - /// Verifies that two objects are not the same instance. - /// - /// The expected object instance - /// The actual object instance - /// Thrown when the objects are the same instance - public static void NotSame(object expected, - object actual) - { - if (object.ReferenceEquals(expected, actual)) - throw new NotSameException(); - } - - /// - /// Verifies that an object reference is null. - /// - /// The object to be inspected - /// Thrown when the object reference is not null - public static void Null(object @object) - { - if (@object != null) - throw new NullException(@object); - } - - /// - /// Verifies that two objects are the same instance. - /// - /// The expected object instance - /// The actual object instance - /// Thrown when the objects are not the same instance - public static void Same(object expected, - object actual) - { - if (!object.ReferenceEquals(expected, actual)) - throw new SameException(expected, actual); - } - - /// - /// Verifies that the exact exception is thrown (and not a derived exception type). - /// - /// The type of the exception expected to be thrown - /// A delegate to the code to be tested - /// The exception that was thrown, when successful - /// Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown - public static T Throws(ThrowsDelegate testCode) - where T : Exception - { - return (T)Throws(typeof(T), testCode); - } - - /// - /// Verifies that the exact exception is thrown (and not a derived exception type). - /// - /// The type of the exception expected to be thrown - /// The message to be shown if the test fails - /// A delegate to the code to be tested - /// The exception that was thrown, when successful - /// Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown - public static T Throws(string userMessage, - ThrowsDelegate testCode) - where T : Exception - { - return (T)Throws(typeof(T), testCode); - } - - /// - /// Verifies that the exact exception is thrown (and not a derived exception type). - /// - /// The type of the exception expected to be thrown - /// A delegate to the code to be tested - /// The exception that was thrown, when successful - /// Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown - public static Exception Throws(Type exceptionType, - ThrowsDelegate testCode) - { - Exception exception = Record.Exception(testCode); - - if (exception == null) - throw new ThrowsException(exceptionType); - - if (!exceptionType.Equals(exception.GetType())) - throw new ThrowsException(exceptionType, exception); - - return exception; - } - - /// - /// Verifies that an expression is true. - /// - /// The condition to be inspected - /// Thrown when the condition is false - public static void True(bool condition) - { - True(condition, null); - } - - /// - /// Verifies that an expression is true. - /// - /// The condition to be inspected - /// The message to be shown when the condition is false - /// Thrown when the condition is false - public static void True(bool condition, - string userMessage) - { - if (!condition) - throw new TrueException(userMessage); - } - - class AssertComparer : IComparer - { - public int Compare(T x, - T y) - { - Type type = typeof(T); - - // Null? - - if (!type.IsValueType || (type.IsGenericType && type.GetGenericTypeDefinition().IsAssignableFrom(typeof(Nullable<>)))) - { - if (Equals(x, default(T))) - { - if (Equals(y, default(T))) - return 0; - return -1; - } - - if (Equals(y, default(T))) - return -1; - } - - // Same type? - - if (x.GetType() != y.GetType()) - return -1; - - // Arrays? - - if (x.GetType().IsArray) - { - Array xArray = x as Array; - Array yArray = y as Array; - - if (xArray != null && yArray != null) - { - if (xArray.Rank != 1) - throw new ArgumentException("Multi-dimension array comparison is not supported"); - - if (xArray.Length != yArray.Length) - return -1; - - for (int index = 0; index < xArray.Length; index++) - if (!Equals(xArray.GetValue(index), yArray.GetValue(index))) - return -1; - - return 0; - } - } - - // Implements IComparable? - - IComparable comparable1 = x as IComparable; - - if (comparable1 != null) - return comparable1.CompareTo(y); - - // Implements IComparable? - - IComparable comparable2 = x as IComparable; - - if (comparable2 != null) - return comparable2.CompareTo(y); - - // Implements IEquatable? - - IEquatable equatable = x as IEquatable; - - if (equatable != null) - return equatable.Equals(y) ? 0 : -1; - - // Last case, rely on Object.Equals - - return Equals(x, y) ? 0 : -1; - } - } - } -} +using System; +using System.Collections; +using System.Collections.Generic; +using Xunit.Sdk; + +namespace Xunit +{ + /// + /// Contains various static methods that are used to verify that conditions are met during the + /// process of running tests. + /// + public class Assert + { + /// + /// Used by the Throws and DoesNotThrow methods. + /// + public delegate void ThrowsDelegate(); + + /// + /// Initializes a new instance of the class. + /// + protected Assert() { } + + /// + /// Verifies that a collection contains a given object. + /// + /// The type of the object to be verified + /// The object expected to be in the collection + /// The collection to be inspected + /// Thrown when the object is not present in the collection + public static void Contains(T expected, + IEnumerable collection) + { + Contains(expected, collection, GetComparer()); + } + + /// + /// Verifies that a collection contains a given object, using a comparer. + /// + /// The type of the object to be verified + /// The object expected to be in the collection + /// The collection to be inspected + /// The comparer used to equate objects in the collection with the expected object + /// Thrown when the object is not present in the collection + public static void Contains(T expected, + IEnumerable collection, + IComparer comparer) + { + foreach (T item in collection) + if (comparer.Compare(expected, item) == 0) + return; + + throw new ContainsException(expected); + } + + /// + /// Verifies that a string contains a given sub-string, using the current culture. + /// + /// The sub-string expected to be in the string + /// The string to be inspected + /// Thrown when the sub-string is not present inside the string + public static void Contains(string expectedSubString, + string actualString) + { + Contains(expectedSubString, actualString, StringComparison.CurrentCulture); + } + + /// + /// Verifies that a string contains a given sub-string, using the given comparison type. + /// + /// The sub-string expected to be in the string + /// The string to be inspected + /// The type of string comparison to perform + /// Thrown when the sub-string is not present inside the string + public static void Contains(string expectedSubString, + string actualString, + StringComparison comparisonType) + { + if (actualString.IndexOf(expectedSubString, comparisonType) < 0) + throw new ContainsException(expectedSubString); + } + + /// + /// Verifies that a collection does not contain a given object. + /// + /// The type of the object to be compared + /// The object that is expected not to be in the collection + /// The collection to be inspected + /// Thrown when the object is present inside the container + public static void DoesNotContain(T expected, + IEnumerable collection) + { + DoesNotContain(expected, collection, GetComparer()); + } + + /// + /// Verifies that a collection does not contain a given object, using a comparer. + /// + /// The type of the object to be compared + /// The object that is expected not to be in the collection + /// The collection to be inspected + /// The comparer used to equate objects in the collection with the expected object + /// Thrown when the object is present inside the container + public static void DoesNotContain(T expected, + IEnumerable collection, + IComparer comparer) + { + foreach (T item in collection) + if (comparer.Compare(expected, item) == 0) + throw new DoesNotContainException(expected); + } + + /// + /// Verifies that a string does not contain a given sub-string, using the current culture. + /// + /// The sub-string which is expected not to be in the string + /// The string to be inspected + /// Thrown when the sub-string is present inside the string + public static void DoesNotContain(string expectedSubString, + string actualString) + { + DoesNotContain(expectedSubString, actualString, StringComparison.CurrentCulture); + } + + /// + /// Verifies that a string does not contain a given sub-string, using the current culture. + /// + /// The sub-string which is expected not to be in the string + /// The string to be inspected + /// The type of string comparison to perform + /// Thrown when the sub-string is present inside the given string + public static void DoesNotContain(string expectedSubString, + string actualString, + StringComparison comparisonType) + { + if (actualString.IndexOf(expectedSubString, comparisonType) >= 0) + throw new DoesNotContainException(expectedSubString); + } + + /// + /// Verifies that a block of code does not throw any exceptions. + /// + /// A delegate to the code to be tested + public static void DoesNotThrow(ThrowsDelegate testCode) + { + Exception ex = Record.Exception(testCode); + + if (ex != null) + throw new DoesNotThrowException(ex); + } + + /// + /// Verifies that a collection is empty. + /// + /// The collection to be inspected + /// Thrown when the collection is null + /// Thrown when the collection is not empty + public static void Empty(IEnumerable collection) + { + if (collection == null) throw new ArgumentNullException("collection", "cannot be null"); + +#pragma warning disable 168 + foreach (object @object in collection) + throw new EmptyException(); +#pragma warning restore 168 + } + + /// + /// Verifies that two objects are equal, using a default comparer. + /// + /// The type of the objects to be compared + /// The expected value + /// The value to be compared against + /// Thrown when the objects are not equal + public static void Equal(T expected, + T actual) + { + Equal(expected, actual, GetComparer()); + } + + /// + /// Verifies that two objects are equal, using a custom comparer. + /// + /// The type of the objects to be compared + /// The expected value + /// The value to be compared against + /// The comparer used to compare the two objects + /// Thrown when the objects are not equal + public static void Equal(T expected, + T actual, + IComparer comparer) + { + if (comparer.Compare(expected, actual) != 0) + throw new EqualException(expected, actual); + } + + /// Do not call this method. + [Obsolete("This is an override of Object.Equals(). Call Assert.Equal() instead.", true)] + public new static bool Equals(object a, + object b) + { + throw new InvalidOperationException("Assert.Equals should not be used"); + } + + /// + /// Verifies that the condition is false. + /// + /// The condition to be tested + /// Thrown if the condition is not false + public static void False(bool condition) + { + False(condition, null); + } + + /// + /// Verifies that the condition is false. + /// + /// The condition to be tested + /// The message to show when the condition is not false + /// Thrown if the condition is not false + public static void False(bool condition, + string userMessage) + { + if (condition) + throw new FalseException(userMessage); + } + + static IComparer GetComparer() + { + return new AssertComparer(); + } + + /// + /// Verifies that a value is within a given range. + /// + /// The type of the value to be compared + /// The actual value to be evaluated + /// The (inclusive) low value of the range + /// The (inclusive) high value of the range + /// Thrown when the value is not in the given range + public static void InRange(T actual, + T low, + T high) + { + InRange(actual, low, high, GetComparer()); + } + + /// + /// Verifies that a value is within a given range, using a comparer. + /// + /// The type of the value to be compared + /// The actual value to be evaluated + /// The (inclusive) low value of the range + /// The (inclusive) high value of the range + /// The comparer used to evaluate the value's range + /// Thrown when the value is not in the given range + public static void InRange(T actual, + T low, + T high, + IComparer comparer) + { + if (comparer.Compare(low, actual) > 0 || comparer.Compare(actual, high) > 0) + throw new InRangeException(actual, low, high); + } + + /// + /// Verifies that an object is of the given type or a derived type. + /// + /// The type the object should be + /// The object to be evaluated + /// The object, casted to type T when successful + /// Thrown when the object is not the given type + public static T IsAssignableFrom(object @object) + { + IsAssignableFrom(typeof(T), @object); + return (T)@object; + } + + /// + /// Verifies that an object is of the given type or a derived type. + /// + /// The type the object should be + /// The object to be evaluated + /// Thrown when the object is not the given type + public static void IsAssignableFrom(Type expectedType, + object @object) + { + if (@object == null || !expectedType.IsAssignableFrom(@object.GetType())) + throw new IsAssignableFromException(expectedType, @object); + } + + /// + /// Verifies that an object is not exactly the given type. + /// + /// The type the object should not be + /// The object to be evaluated + /// Thrown when the object is the given type + public static void IsNotType(object @object) + { + IsNotType(typeof(T), @object); + } + + /// + /// Verifies that an object is not exactly the given type. + /// + /// The type the object should not be + /// The object to be evaluated + /// Thrown when the object is the given type + public static void IsNotType(Type expectedType, + object @object) + { + if (expectedType.Equals(@object.GetType())) + throw new IsNotTypeException(expectedType, @object); + } + + /// + /// Verifies that an object is exactly the given type (and not a derived type). + /// + /// The type the object should be + /// The object to be evaluated + /// The object, casted to type T when successful + /// Thrown when the object is not the given type + public static T IsType(object @object) + { + IsType(typeof(T), @object); + return (T)@object; + } + + /// + /// Verifies that an object is exactly the given type (and not a derived type). + /// + /// The type the object should be + /// The object to be evaluated + /// Thrown when the object is not the given type + public static void IsType(Type expectedType, + object @object) + { + if (@object == null || !expectedType.Equals(@object.GetType())) + throw new IsTypeException(expectedType, @object); + } + + /// + /// Verifies that a collection is not empty. + /// + /// The collection to be inspected + /// Thrown when a null collection is passed + /// Thrown when the collection is empty + public static void NotEmpty(IEnumerable collection) + { + if (collection == null) throw new ArgumentNullException("collection", "cannot be null"); + +#pragma warning disable 168 + foreach (object @object in collection) + return; +#pragma warning restore 168 + + throw new NotEmptyException(); + } + + /// + /// Verifies that two objects are not equal, using a default comparer. + /// + /// The type of the objects to be compared + /// The expected object + /// The actual object + /// Thrown when the objects are equal + public static void NotEqual(T expected, + T actual) + { + NotEqual(expected, actual, GetComparer()); + } + + /// + /// Verifies that two objects are not equal, using a custom comparer. + /// + /// The type of the objects to be compared + /// The expected object + /// The actual object + /// The comparer used to examine the objects + /// Thrown when the objects are equal + public static void NotEqual(T expected, + T actual, + IComparer comparer) + { + if (comparer.Compare(expected, actual) == 0) + throw new NotEqualException(); + } + + /// + /// Verifies that a value is not within a given range, using the default comparer. + /// + /// The type of the value to be compared + /// The actual value to be evaluated + /// The (inclusive) low value of the range + /// The (inclusive) high value of the range + /// Thrown when the value is in the given range + public static void NotInRange(T actual, + T low, + T high) + { + NotInRange(actual, low, high, GetComparer()); + } + + /// + /// Verifies that a value is not within a given range, using a comparer. + /// + /// The type of the value to be compared + /// The actual value to be evaluated + /// The (inclusive) low value of the range + /// The (inclusive) high value of the range + /// The comparer used to evaluate the value's range + /// Thrown when the value is in the given range + public static void NotInRange(T actual, + T low, + T high, + IComparer comparer) + { + if (comparer.Compare(low, actual) <= 0 && comparer.Compare(actual, high) <= 0) + throw new NotInRangeException(actual, low, high); + } + + /// + /// Verifies that an object reference is not null. + /// + /// The object to be validated + /// Thrown when the object is not null + public static void NotNull(object @object) + { + if (@object == null) + throw new NotNullException(); + } + + /// + /// Verifies that two objects are not the same instance. + /// + /// The expected object instance + /// The actual object instance + /// Thrown when the objects are the same instance + public static void NotSame(object expected, + object actual) + { + if (object.ReferenceEquals(expected, actual)) + throw new NotSameException(); + } + + /// + /// Verifies that an object reference is null. + /// + /// The object to be inspected + /// Thrown when the object reference is not null + public static void Null(object @object) + { + if (@object != null) + throw new NullException(@object); + } + + /// + /// Verifies that two objects are the same instance. + /// + /// The expected object instance + /// The actual object instance + /// Thrown when the objects are not the same instance + public static void Same(object expected, + object actual) + { + if (!object.ReferenceEquals(expected, actual)) + throw new SameException(expected, actual); + } + + /// + /// Verifies that the exact exception is thrown (and not a derived exception type). + /// + /// The type of the exception expected to be thrown + /// A delegate to the code to be tested + /// The exception that was thrown, when successful + /// Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown + public static T Throws(ThrowsDelegate testCode) + where T : Exception + { + return (T)Throws(typeof(T), testCode); + } + + /// + /// Verifies that the exact exception is thrown (and not a derived exception type). + /// + /// The type of the exception expected to be thrown + /// The message to be shown if the test fails + /// A delegate to the code to be tested + /// The exception that was thrown, when successful + /// Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown + public static T Throws(string userMessage, + ThrowsDelegate testCode) + where T : Exception + { + return (T)Throws(typeof(T), testCode); + } + + /// + /// Verifies that the exact exception is thrown (and not a derived exception type). + /// + /// The type of the exception expected to be thrown + /// A delegate to the code to be tested + /// The exception that was thrown, when successful + /// Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown + public static Exception Throws(Type exceptionType, + ThrowsDelegate testCode) + { + Exception exception = Record.Exception(testCode); + + if (exception == null) + throw new ThrowsException(exceptionType); + + if (!exceptionType.Equals(exception.GetType())) + throw new ThrowsException(exceptionType, exception); + + return exception; + } + + /// + /// Verifies that an expression is true. + /// + /// The condition to be inspected + /// Thrown when the condition is false + public static void True(bool condition) + { + True(condition, null); + } + + /// + /// Verifies that an expression is true. + /// + /// The condition to be inspected + /// The message to be shown when the condition is false + /// Thrown when the condition is false + public static void True(bool condition, + string userMessage) + { + if (!condition) + throw new TrueException(userMessage); + } + + class AssertComparer : IComparer + { + public int Compare(T x, + T y) + { + Type type = typeof(T); + + // Null? + + if (!type.IsValueType || (type.IsGenericType && type.GetGenericTypeDefinition().IsAssignableFrom(typeof(Nullable<>)))) + { + if (Equals(x, default(T))) + { + if (Equals(y, default(T))) + return 0; + return -1; + } + + if (Equals(y, default(T))) + return -1; + } + + // Same type? + + if (x.GetType() != y.GetType()) + return -1; + + // Arrays? + + if (x.GetType().IsArray) + { + Array xArray = x as Array; + Array yArray = y as Array; + + if (xArray != null && yArray != null) + { + if (xArray.Rank != 1) + throw new ArgumentException("Multi-dimension array comparison is not supported"); + + if (xArray.Length != yArray.Length) + return -1; + + for (int index = 0; index < xArray.Length; index++) + if (!Equals(xArray.GetValue(index), yArray.GetValue(index))) + return -1; + + return 0; + } + } + + // Implements IComparable? + + IComparable comparable1 = x as IComparable; + + if (comparable1 != null) + return comparable1.CompareTo(y); + + // Implements IComparable? + + IComparable comparable2 = x as IComparable; + + if (comparable2 != null) + return comparable2.CompareTo(y); + + // Implements IEquatable? + + IEquatable equatable = x as IEquatable; + + if (equatable != null) + return equatable.Equals(y) ? 0 : -1; + + // Last case, rely on Object.Equals + + return Equals(x, y) ? 0 : -1; + } + } + } +} diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/FactAttribute.cs b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/FactAttribute.cs index 31f6967d3..9a421e9e2 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/FactAttribute.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/FactAttribute.cs @@ -1,15 +1,15 @@ -using System; -namespace Xunit -{ - [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] - public class FactAttribute : Attribute - { - public FactAttribute() - { - } - - public string Name { get; protected set; } - public string Skip { get; set; } - public int Timeout { get; set; } - } -} +using System; +namespace Xunit +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] + public class FactAttribute : Attribute + { + public FactAttribute() + { + } + + public string Name { get; protected set; } + public string Skip { get; set; } + public int Timeout { get; set; } + } +} diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Record.cs b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Record.cs index ee3a551cb..3bcc926b6 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Record.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Record.cs @@ -1,26 +1,26 @@ -namespace Xunit -{ - using Xunit.Sdk; - using System; - - public class Record - { - /// - /// Records any exception which is thrown by the given code. - /// - /// The code which may thrown an exception. - /// Returns the exception that was thrown by the code; null, otherwise. - public static Exception Exception(Assert.ThrowsDelegate code) - { - try - { - code(); - return null; - } - catch (Exception ex) - { - return ex; - } - } - } -} +namespace Xunit +{ + using Xunit.Sdk; + using System; + + public class Record + { + /// + /// Records any exception which is thrown by the given code. + /// + /// The code which may thrown an exception. + /// Returns the exception that was thrown by the code; null, otherwise. + public static Exception Exception(Assert.ThrowsDelegate code) + { + try + { + code(); + return null; + } + catch (Exception ex) + { + return ex; + } + } + } +} diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/AssertActualExpectedException.cs b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/AssertActualExpectedException.cs index fd5668e70..69393ca72 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/AssertActualExpectedException.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/AssertActualExpectedException.cs @@ -1,126 +1,126 @@ -using System; -using System.Collections; -using System.Collections.Generic; - -namespace Xunit.Sdk -{ - /// - /// Base class for exceptions that have actual and expected values - /// - public class AssertActualExpectedException : AssertException - { - readonly string actual; - readonly string differencePosition = ""; - readonly string expected; - - /// - /// Creates a new instance of the class. - /// - /// The expected value - /// The actual value - /// The user message to be shown - public AssertActualExpectedException(object expected, - object actual, - string userMessage) - : this(expected, actual, userMessage, false) {} - - /// - /// Creates a new instance of the class. - /// - /// The expected value - /// The actual value - /// The user message to be shown - /// Set to true to skip the check for difference position - public AssertActualExpectedException(object expected, - object actual, - string userMessage, - bool skipPositionCheck) - : base(userMessage) - { - if (!skipPositionCheck) - { - IEnumerable enumerableActual = actual as IEnumerable; - IEnumerable enumerableExpected = expected as IEnumerable; - - if (enumerableActual != null && enumerableExpected != null) - { - IEnumerator enumeratorActual = enumerableActual.GetEnumerator(); - IEnumerator enumeratorExpected = enumerableExpected.GetEnumerator(); - int position = 0; - - while (true) - { - bool actualHasNext = enumeratorActual.MoveNext(); - bool expectedHasNext = enumeratorExpected.MoveNext(); - - if (!actualHasNext || !expectedHasNext) - break; - - if (!Equals(enumeratorActual.Current, enumeratorExpected.Current)) - break; - - position++; - } - - differencePosition = "Position: First difference is at position " + position + Environment.NewLine; - } - } - - this.actual = actual == null ? null : ConvertToString(actual); - this.expected = expected == null ? null : ConvertToString(expected); - } - - /// - /// Gets the actual value. - /// - public string Actual - { - get { return actual; } - } - - /// - /// Gets the expected value. - /// - public string Expected - { - get { return expected; } - } - - /// - /// Gets a message that describes the current exception. Includes the expected and actual values. - /// - /// The error message that explains the reason for the exception, or an empty string(""). - /// 1 - public override string Message - { - get - { - return string.Format("{0}{4}{1}Expected: {2}{4}Actual: {3}", - base.Message, - differencePosition, - FormatMultiLine(Expected ?? "(null)"), - FormatMultiLine(Actual ?? "(null)"), - Environment.NewLine); - } - } - - static string ConvertToString(object value) - { - Array valueArray = value as Array; - if (valueArray == null) - return value.ToString(); - - List valueStrings = new List(); - - foreach (object valueObject in valueArray) - valueStrings.Add(valueObject.ToString()); - - return value.GetType().FullName + " { " + String.Join(", ", valueStrings.ToArray()) + " }"; - } - - static string FormatMultiLine(string value) - { - return value.Replace(Environment.NewLine, Environment.NewLine + " "); - } - } +using System; +using System.Collections; +using System.Collections.Generic; + +namespace Xunit.Sdk +{ + /// + /// Base class for exceptions that have actual and expected values + /// + public class AssertActualExpectedException : AssertException + { + readonly string actual; + readonly string differencePosition = ""; + readonly string expected; + + /// + /// Creates a new instance of the class. + /// + /// The expected value + /// The actual value + /// The user message to be shown + public AssertActualExpectedException(object expected, + object actual, + string userMessage) + : this(expected, actual, userMessage, false) {} + + /// + /// Creates a new instance of the class. + /// + /// The expected value + /// The actual value + /// The user message to be shown + /// Set to true to skip the check for difference position + public AssertActualExpectedException(object expected, + object actual, + string userMessage, + bool skipPositionCheck) + : base(userMessage) + { + if (!skipPositionCheck) + { + IEnumerable enumerableActual = actual as IEnumerable; + IEnumerable enumerableExpected = expected as IEnumerable; + + if (enumerableActual != null && enumerableExpected != null) + { + IEnumerator enumeratorActual = enumerableActual.GetEnumerator(); + IEnumerator enumeratorExpected = enumerableExpected.GetEnumerator(); + int position = 0; + + while (true) + { + bool actualHasNext = enumeratorActual.MoveNext(); + bool expectedHasNext = enumeratorExpected.MoveNext(); + + if (!actualHasNext || !expectedHasNext) + break; + + if (!Equals(enumeratorActual.Current, enumeratorExpected.Current)) + break; + + position++; + } + + differencePosition = "Position: First difference is at position " + position + Environment.NewLine; + } + } + + this.actual = actual == null ? null : ConvertToString(actual); + this.expected = expected == null ? null : ConvertToString(expected); + } + + /// + /// Gets the actual value. + /// + public string Actual + { + get { return actual; } + } + + /// + /// Gets the expected value. + /// + public string Expected + { + get { return expected; } + } + + /// + /// Gets a message that describes the current exception. Includes the expected and actual values. + /// + /// The error message that explains the reason for the exception, or an empty string(""). + /// 1 + public override string Message + { + get + { + return string.Format("{0}{4}{1}Expected: {2}{4}Actual: {3}", + base.Message, + differencePosition, + FormatMultiLine(Expected ?? "(null)"), + FormatMultiLine(Actual ?? "(null)"), + Environment.NewLine); + } + } + + static string ConvertToString(object value) + { + Array valueArray = value as Array; + if (valueArray == null) + return value.ToString(); + + List valueStrings = new List(); + + foreach (object valueObject in valueArray) + valueStrings.Add(valueObject.ToString()); + + return value.GetType().FullName + " { " + String.Join(", ", valueStrings.ToArray()) + " }"; + } + + static string FormatMultiLine(string value) + { + return value.Replace(Environment.NewLine, Environment.NewLine + " "); + } + } } \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/AssertException.cs b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/AssertException.cs index 218884aa9..a367ef901 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/AssertException.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/AssertException.cs @@ -1,101 +1,101 @@ -using System; -using System.Collections.Generic; - -namespace Xunit.Sdk -{ - /// - /// The base assert exception class - /// - public class AssertException : Exception - { - readonly string stackTrace; - - /// - /// Initializes a new instance of the class. - /// - public AssertException() {} - - /// - /// Initializes a new instance of the class. - /// - /// The user message to be displayed - public AssertException(string userMessage) - : base(userMessage) - { - this.UserMessage = userMessage; - } - - /// - /// Initializes a new instance of the class. - /// - /// The user message to be displayed - /// The inner exception - protected AssertException(string userMessage, Exception innerException) - : base(userMessage, innerException) {} - - /// - /// Initializes a new instance of the class. - /// - /// The user message to be displayed - /// The stack trace to be displayed - protected AssertException(string userMessage, string stackTrace) - : base(userMessage) - { - this.stackTrace = stackTrace; - } - - /// - /// Gets a string representation of the frames on the call stack at the time the current exception was thrown. - /// - /// A string that describes the contents of the call stack, with the most recent method call appearing first. - public override string StackTrace - { - get { return FilterStackTrace(stackTrace ?? base.StackTrace); } - } - - /// - /// Gets the user message - /// - public string UserMessage { get; protected set; } - - /// - /// Filters the stack trace to remove all lines that occur within the testing framework. - /// - /// The original stack trace - /// The filtered stack trace - protected static string FilterStackTrace(string stackTrace) - { - if (stackTrace == null) - return null; - - List results = new List(); - - foreach (string line in SplitLines(stackTrace)) - { - string trimmedLine = line.TrimStart(); - if (!trimmedLine.StartsWith("at Xunit.Assert.") && !trimmedLine.StartsWith("at Xunit.Sdk.")) - results.Add(line); - } - - return string.Join(Environment.NewLine, results.ToArray()); - } - - // Our own custom String.Split because Silverlight/CoreCLR doesn't support the version we were using - static IEnumerable SplitLines(string input) - { - while (true) - { - int idx = input.IndexOf(Environment.NewLine); - - if (idx < 0) - { - yield return input; - break; - } - - yield return input.Substring(0, idx); - input = input.Substring(idx + Environment.NewLine.Length); - } - } - } +using System; +using System.Collections.Generic; + +namespace Xunit.Sdk +{ + /// + /// The base assert exception class + /// + public class AssertException : Exception + { + readonly string stackTrace; + + /// + /// Initializes a new instance of the class. + /// + public AssertException() {} + + /// + /// Initializes a new instance of the class. + /// + /// The user message to be displayed + public AssertException(string userMessage) + : base(userMessage) + { + this.UserMessage = userMessage; + } + + /// + /// Initializes a new instance of the class. + /// + /// The user message to be displayed + /// The inner exception + protected AssertException(string userMessage, Exception innerException) + : base(userMessage, innerException) {} + + /// + /// Initializes a new instance of the class. + /// + /// The user message to be displayed + /// The stack trace to be displayed + protected AssertException(string userMessage, string stackTrace) + : base(userMessage) + { + this.stackTrace = stackTrace; + } + + /// + /// Gets a string representation of the frames on the call stack at the time the current exception was thrown. + /// + /// A string that describes the contents of the call stack, with the most recent method call appearing first. + public override string StackTrace + { + get { return FilterStackTrace(stackTrace ?? base.StackTrace); } + } + + /// + /// Gets the user message + /// + public string UserMessage { get; protected set; } + + /// + /// Filters the stack trace to remove all lines that occur within the testing framework. + /// + /// The original stack trace + /// The filtered stack trace + protected static string FilterStackTrace(string stackTrace) + { + if (stackTrace == null) + return null; + + List results = new List(); + + foreach (string line in SplitLines(stackTrace)) + { + string trimmedLine = line.TrimStart(); + if (!trimmedLine.StartsWith("at Xunit.Assert.") && !trimmedLine.StartsWith("at Xunit.Sdk.")) + results.Add(line); + } + + return string.Join(Environment.NewLine, results.ToArray()); + } + + // Our own custom String.Split because Silverlight/CoreCLR doesn't support the version we were using + static IEnumerable SplitLines(string input) + { + while (true) + { + int idx = input.IndexOf(Environment.NewLine); + + if (idx < 0) + { + yield return input; + break; + } + + yield return input.Substring(0, idx); + input = input.Substring(idx + Environment.NewLine.Length); + } + } + } } \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/ContainsException.cs b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/ContainsException.cs index 235c0692b..d6dac3442 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/ContainsException.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/ContainsException.cs @@ -1,15 +1,15 @@ -namespace Xunit.Sdk -{ - /// - /// Exception thrown when a collection unexpectedly does not contain the expected value. - /// - public class ContainsException : AssertException - { - /// - /// Creates a new instance of the class. - /// - /// The expected object value - public ContainsException(object expected) - : base(string.Format("Assert.Contains() failure: Not found: {0}", expected)) {} - } +namespace Xunit.Sdk +{ + /// + /// Exception thrown when a collection unexpectedly does not contain the expected value. + /// + public class ContainsException : AssertException + { + /// + /// Creates a new instance of the class. + /// + /// The expected object value + public ContainsException(object expected) + : base(string.Format("Assert.Contains() failure: Not found: {0}", expected)) {} + } } \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/DoesNotContainException.cs b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/DoesNotContainException.cs index 6084b1072..e713efd9e 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/DoesNotContainException.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/DoesNotContainException.cs @@ -1,15 +1,15 @@ -namespace Xunit.Sdk -{ - /// - /// Exception thrown when a collection unexpectedly contains the expected value. - /// - public class DoesNotContainException : AssertException - { - /// - /// Creates a new instance of the class. - /// - /// The expected object value - public DoesNotContainException(object expected) - : base(string.Format("Assert.DoesNotContain() failure: Found: {0}", expected)) {} - } +namespace Xunit.Sdk +{ + /// + /// Exception thrown when a collection unexpectedly contains the expected value. + /// + public class DoesNotContainException : AssertException + { + /// + /// Creates a new instance of the class. + /// + /// The expected object value + public DoesNotContainException(object expected) + : base(string.Format("Assert.DoesNotContain() failure: Found: {0}", expected)) {} + } } \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/DoesNotThrowException.cs b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/DoesNotThrowException.cs index 8c7962e79..9264ef1b4 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/DoesNotThrowException.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/DoesNotThrowException.cs @@ -1,34 +1,34 @@ -using System; - -namespace Xunit.Sdk -{ - /// - /// Exception thrown when code unexpectedly throws an exception. - /// - public class DoesNotThrowException : AssertActualExpectedException - { - readonly string stackTrace; - - /// - /// Creates a new instance of the class. - /// - /// Actual exception - public DoesNotThrowException(Exception actual) - : base("(No exception)", - actual.GetType().FullName + (actual.Message == null ? "" : ": " + actual.Message), - "Assert.DoesNotThrow() failure", - true) - { - stackTrace = actual.StackTrace; - } - - /// - /// Gets a string representation of the frames on the call stack at the time the current exception was thrown. - /// - /// A string that describes the contents of the call stack, with the most recent method call appearing first. - public override string StackTrace - { - get { return FilterStackTrace(stackTrace ?? base.StackTrace); } - } - } +using System; + +namespace Xunit.Sdk +{ + /// + /// Exception thrown when code unexpectedly throws an exception. + /// + public class DoesNotThrowException : AssertActualExpectedException + { + readonly string stackTrace; + + /// + /// Creates a new instance of the class. + /// + /// Actual exception + public DoesNotThrowException(Exception actual) + : base("(No exception)", + actual.GetType().FullName + (actual.Message == null ? "" : ": " + actual.Message), + "Assert.DoesNotThrow() failure", + true) + { + stackTrace = actual.StackTrace; + } + + /// + /// Gets a string representation of the frames on the call stack at the time the current exception was thrown. + /// + /// A string that describes the contents of the call stack, with the most recent method call appearing first. + public override string StackTrace + { + get { return FilterStackTrace(stackTrace ?? base.StackTrace); } + } + } } \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/EmptyException.cs b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/EmptyException.cs index 6f570f161..e19a749b9 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/EmptyException.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/EmptyException.cs @@ -1,14 +1,14 @@ -namespace Xunit.Sdk -{ - /// - /// Exception thrown when a collection is unexpectedly not empty. - /// - public class EmptyException : AssertException - { - /// - /// Creates a new instance of the class. - /// - public EmptyException() - : base("Assert.Empty() failure") {} - } +namespace Xunit.Sdk +{ + /// + /// Exception thrown when a collection is unexpectedly not empty. + /// + public class EmptyException : AssertException + { + /// + /// Creates a new instance of the class. + /// + public EmptyException() + : base("Assert.Empty() failure") {} + } } \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/EqualException.cs b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/EqualException.cs index 01c83c3b6..4aded87a8 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/EqualException.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/EqualException.cs @@ -1,17 +1,17 @@ -namespace Xunit.Sdk -{ - /// - /// Exception thrown when two values are unexpectedly not equal. - /// - public class EqualException : AssertActualExpectedException - { - /// - /// Creates a new instance of the class. - /// - /// The expected object value - /// The actual object value - public EqualException(object expected, - object actual) - : base(expected, actual, "Assert.Equal() Failure") {} - } +namespace Xunit.Sdk +{ + /// + /// Exception thrown when two values are unexpectedly not equal. + /// + public class EqualException : AssertActualExpectedException + { + /// + /// Creates a new instance of the class. + /// + /// The expected object value + /// The actual object value + public EqualException(object expected, + object actual) + : base(expected, actual, "Assert.Equal() Failure") {} + } } \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/FalseException.cs b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/FalseException.cs index 83ce0fc09..a419108f0 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/FalseException.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/FalseException.cs @@ -1,15 +1,15 @@ -namespace Xunit.Sdk -{ - /// - /// Exception thrown when a value is unexpectedly true. - /// - public class FalseException : AssertException - { - /// - /// Creates a new instance of the class. - /// - /// The user message to be display, or null for the default message - public FalseException(string userMessage) - : base(userMessage ?? "Assert.False() Failure") {} - } +namespace Xunit.Sdk +{ + /// + /// Exception thrown when a value is unexpectedly true. + /// + public class FalseException : AssertException + { + /// + /// Creates a new instance of the class. + /// + /// The user message to be display, or null for the default message + public FalseException(string userMessage) + : base(userMessage ?? "Assert.False() Failure") {} + } } \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/InRangeException.cs b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/InRangeException.cs index 9496b9ab9..70488d2ac 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/InRangeException.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/InRangeException.cs @@ -1,65 +1,65 @@ -namespace Xunit.Sdk -{ - /// - /// Exception thrown when a value is unexpectedly not in the given range. - /// - public class InRangeException : AssertException - { - readonly string actual; - readonly string high; - readonly string low; - - /// - /// Creates a new instance of the class. - /// - /// The actual object value - /// The low value of the range - /// The high value of the range - public InRangeException(object actual, - object low, - object high) - : base("Assert.InRange() Failure") - { - this.low = low == null ? null : low.ToString(); - this.high = high == null ? null : high.ToString(); - this.actual = actual == null ? null : actual.ToString(); - } - - /// - /// Gets the actual object value - /// - public string Actual - { - get { return actual; } - } - - /// - /// Gets the high value of the range - /// - public string High - { - get { return high; } - } - - /// - /// Gets the low value of the range - /// - public string Low - { - get { return low; } - } - - /// - /// Gets a message that describes the current exception. - /// - /// The error message that explains the reason for the exception, or an empty string(""). - public override string Message - { - get - { - return string.Format("{0}\r\nRange: ({1} - {2})\r\nActual: {3}", - base.Message, Low, High, Actual ?? "(null)"); - } - } - } +namespace Xunit.Sdk +{ + /// + /// Exception thrown when a value is unexpectedly not in the given range. + /// + public class InRangeException : AssertException + { + readonly string actual; + readonly string high; + readonly string low; + + /// + /// Creates a new instance of the class. + /// + /// The actual object value + /// The low value of the range + /// The high value of the range + public InRangeException(object actual, + object low, + object high) + : base("Assert.InRange() Failure") + { + this.low = low == null ? null : low.ToString(); + this.high = high == null ? null : high.ToString(); + this.actual = actual == null ? null : actual.ToString(); + } + + /// + /// Gets the actual object value + /// + public string Actual + { + get { return actual; } + } + + /// + /// Gets the high value of the range + /// + public string High + { + get { return high; } + } + + /// + /// Gets the low value of the range + /// + public string Low + { + get { return low; } + } + + /// + /// Gets a message that describes the current exception. + /// + /// The error message that explains the reason for the exception, or an empty string(""). + public override string Message + { + get + { + return string.Format("{0}\r\nRange: ({1} - {2})\r\nActual: {3}", + base.Message, Low, High, Actual ?? "(null)"); + } + } + } } \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/IsAssignableFromException.cs b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/IsAssignableFromException.cs index 386d514b0..3f93ea3f4 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/IsAssignableFromException.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/IsAssignableFromException.cs @@ -1,19 +1,19 @@ -using System; - -namespace Xunit.Sdk -{ - /// - /// Exception thrown when the value is unexpectedly not of the given type or a derived type. - /// - public class IsAssignableFromException : AssertActualExpectedException - { - /// - /// Creates a new instance of the class. - /// - /// The expected type - /// The actual object value - public IsAssignableFromException(Type expected, - object actual) - : base(expected, actual == null ? null : actual.GetType(), "Assert.IsAssignableFrom() Failure") { } - } +using System; + +namespace Xunit.Sdk +{ + /// + /// Exception thrown when the value is unexpectedly not of the given type or a derived type. + /// + public class IsAssignableFromException : AssertActualExpectedException + { + /// + /// Creates a new instance of the class. + /// + /// The expected type + /// The actual object value + public IsAssignableFromException(Type expected, + object actual) + : base(expected, actual == null ? null : actual.GetType(), "Assert.IsAssignableFrom() Failure") { } + } } \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/IsNotTypeException.cs b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/IsNotTypeException.cs index 285904e89..0c170a992 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/IsNotTypeException.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/IsNotTypeException.cs @@ -1,19 +1,19 @@ -using System; - -namespace Xunit.Sdk -{ - /// - /// Exception thrown when the value is unexpectedly of the exact given type. - /// - public class IsNotTypeException : AssertActualExpectedException - { - /// - /// Creates a new instance of the class. - /// - /// The expected type - /// The actual object value - public IsNotTypeException(Type expected, - object actual) - : base(expected, actual == null ? null : actual.GetType(), "Assert.IsNotType() Failure") {} - } +using System; + +namespace Xunit.Sdk +{ + /// + /// Exception thrown when the value is unexpectedly of the exact given type. + /// + public class IsNotTypeException : AssertActualExpectedException + { + /// + /// Creates a new instance of the class. + /// + /// The expected type + /// The actual object value + public IsNotTypeException(Type expected, + object actual) + : base(expected, actual == null ? null : actual.GetType(), "Assert.IsNotType() Failure") {} + } } \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/IsTypeException.cs b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/IsTypeException.cs index 5934e20ab..a87b8fe6f 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/IsTypeException.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/IsTypeException.cs @@ -1,19 +1,19 @@ -using System; - -namespace Xunit.Sdk -{ - /// - /// Exception thrown when the value is unexpectedly not of the exact given type. - /// - public class IsTypeException : AssertActualExpectedException - { - /// - /// Creates a new instance of the class. - /// - /// The expected type - /// The actual object value - public IsTypeException(Type expected, - object actual) - : base(expected, actual == null ? null : actual.GetType(), "Assert.IsType() Failure") {} - } +using System; + +namespace Xunit.Sdk +{ + /// + /// Exception thrown when the value is unexpectedly not of the exact given type. + /// + public class IsTypeException : AssertActualExpectedException + { + /// + /// Creates a new instance of the class. + /// + /// The expected type + /// The actual object value + public IsTypeException(Type expected, + object actual) + : base(expected, actual == null ? null : actual.GetType(), "Assert.IsType() Failure") {} + } } \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/NotEmptyException.cs b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/NotEmptyException.cs index 922a22103..0863084c2 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/NotEmptyException.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/NotEmptyException.cs @@ -1,14 +1,14 @@ -namespace Xunit.Sdk -{ - /// - /// Exception thrown when a collection is unexpectedly empty. - /// - public class NotEmptyException : AssertException - { - /// - /// Creates a new instance of the class. - /// - public NotEmptyException() - : base("Assert.NotEmpty() failure") {} - } +namespace Xunit.Sdk +{ + /// + /// Exception thrown when a collection is unexpectedly empty. + /// + public class NotEmptyException : AssertException + { + /// + /// Creates a new instance of the class. + /// + public NotEmptyException() + : base("Assert.NotEmpty() failure") {} + } } \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/NotEqualException.cs b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/NotEqualException.cs index edcccb1f2..596030ffe 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/NotEqualException.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/NotEqualException.cs @@ -1,14 +1,14 @@ -namespace Xunit.Sdk -{ - /// - /// Exception thrown when two values are unexpectedly equal. - /// - public class NotEqualException : AssertException - { - /// - /// Creates a new instance of the class. - /// - public NotEqualException() - : base("Assert.NotEqual() Failure") {} - } +namespace Xunit.Sdk +{ + /// + /// Exception thrown when two values are unexpectedly equal. + /// + public class NotEqualException : AssertException + { + /// + /// Creates a new instance of the class. + /// + public NotEqualException() + : base("Assert.NotEqual() Failure") {} + } } \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/NotInRangeException.cs b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/NotInRangeException.cs index 7ff1d561a..707e69c9b 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/NotInRangeException.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/NotInRangeException.cs @@ -1,65 +1,65 @@ -namespace Xunit.Sdk -{ - /// - /// Exception thrown when a value is unexpectedly in the given range. - /// - public class NotInRangeException : AssertException - { - readonly string actual; - readonly string high; - readonly string low; - - /// - /// Creates a new instance of the class. - /// - /// The actual object value - /// The low value of the range - /// The high value of the range - public NotInRangeException(object actual, - object low, - object high) - : base("Assert.NotInRange() Failure") - { - this.low = low == null ? null : low.ToString(); - this.high = high == null ? null : high.ToString(); - this.actual = actual == null ? null : actual.ToString(); - } - - /// - /// Gets the actual object value - /// - public string Actual - { - get { return actual; } - } - - /// - /// Gets the high value of the range - /// - public string High - { - get { return high; } - } - - /// - /// Gets the low value of the range - /// - public string Low - { - get { return low; } - } - - /// - /// Gets a message that describes the current exception. - /// - /// The error message that explains the reason for the exception, or an empty string(""). - public override string Message - { - get - { - return string.Format("{0}\r\nRange: ({1} - {2})\r\nActual: {3}", - base.Message, Low, High, Actual ?? "(null)"); - } - } - } +namespace Xunit.Sdk +{ + /// + /// Exception thrown when a value is unexpectedly in the given range. + /// + public class NotInRangeException : AssertException + { + readonly string actual; + readonly string high; + readonly string low; + + /// + /// Creates a new instance of the class. + /// + /// The actual object value + /// The low value of the range + /// The high value of the range + public NotInRangeException(object actual, + object low, + object high) + : base("Assert.NotInRange() Failure") + { + this.low = low == null ? null : low.ToString(); + this.high = high == null ? null : high.ToString(); + this.actual = actual == null ? null : actual.ToString(); + } + + /// + /// Gets the actual object value + /// + public string Actual + { + get { return actual; } + } + + /// + /// Gets the high value of the range + /// + public string High + { + get { return high; } + } + + /// + /// Gets the low value of the range + /// + public string Low + { + get { return low; } + } + + /// + /// Gets a message that describes the current exception. + /// + /// The error message that explains the reason for the exception, or an empty string(""). + public override string Message + { + get + { + return string.Format("{0}\r\nRange: ({1} - {2})\r\nActual: {3}", + base.Message, Low, High, Actual ?? "(null)"); + } + } + } } \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/NotNullException.cs b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/NotNullException.cs index 4be7da824..df178a20c 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/NotNullException.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/NotNullException.cs @@ -1,14 +1,14 @@ -namespace Xunit.Sdk -{ - /// - /// Exception thrown when an object is unexpectedly null. - /// - public class NotNullException : AssertException - { - /// - /// Creates a new instance of the class. - /// - public NotNullException() - : base("Assert.NotNull() Failure") {} - } +namespace Xunit.Sdk +{ + /// + /// Exception thrown when an object is unexpectedly null. + /// + public class NotNullException : AssertException + { + /// + /// Creates a new instance of the class. + /// + public NotNullException() + : base("Assert.NotNull() Failure") {} + } } \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/NotSameException.cs b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/NotSameException.cs index 5b8bb8db1..249afb770 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/NotSameException.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/NotSameException.cs @@ -1,14 +1,14 @@ -namespace Xunit.Sdk -{ - /// - /// Exception thrown when two values are unexpected the same instance. - /// - public class NotSameException : AssertException - { - /// - /// Creates a new instance of the class. - /// - public NotSameException() - : base("Assert.NotSame() Failure") {} - } +namespace Xunit.Sdk +{ + /// + /// Exception thrown when two values are unexpected the same instance. + /// + public class NotSameException : AssertException + { + /// + /// Creates a new instance of the class. + /// + public NotSameException() + : base("Assert.NotSame() Failure") {} + } } \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/NullException.cs b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/NullException.cs index 9feb739fa..4313c86d1 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/NullException.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/NullException.cs @@ -1,15 +1,15 @@ -namespace Xunit.Sdk -{ - /// - /// Exception thrown when an object reference is unexpectedly not null. - /// - public class NullException : AssertActualExpectedException - { - /// - /// Creates a new instance of the class. - /// - /// - public NullException(object actual) - : base(null, actual, "Assert.Null() Failure") {} - } +namespace Xunit.Sdk +{ + /// + /// Exception thrown when an object reference is unexpectedly not null. + /// + public class NullException : AssertActualExpectedException + { + /// + /// Creates a new instance of the class. + /// + /// + public NullException(object actual) + : base(null, actual, "Assert.Null() Failure") {} + } } \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/SameException.cs b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/SameException.cs index c68af91e2..5781bbafc 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/SameException.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/SameException.cs @@ -1,17 +1,17 @@ -namespace Xunit.Sdk -{ - /// - /// Exception thrown when two object references are unexpectedly not the same instance. - /// - public class SameException : AssertActualExpectedException - { - /// - /// Creates a new instance of the class. - /// - /// The expected object reference - /// The actual object reference - public SameException(object expected, - object actual) - : base(expected, actual, "Assert.Same() Failure") {} - } +namespace Xunit.Sdk +{ + /// + /// Exception thrown when two object references are unexpectedly not the same instance. + /// + public class SameException : AssertActualExpectedException + { + /// + /// Creates a new instance of the class. + /// + /// The expected object reference + /// The actual object reference + public SameException(object expected, + object actual) + : base(expected, actual, "Assert.Same() Failure") {} + } } \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/ThrowsException.cs b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/ThrowsException.cs index 05acee8c2..a752f7376 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/ThrowsException.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/ThrowsException.cs @@ -1,50 +1,50 @@ -using System; - -namespace Xunit.Sdk -{ - /// - /// Exception thrown when code unexpectedly fails to throw an exception. - /// - public class ThrowsException : AssertActualExpectedException - { - readonly string stackTrace = null; - - /// - /// Creates a new instance of the class. Call this constructor - /// when no exception was thrown. - /// - /// The type of the exception that was expected - public ThrowsException(Type expectedType) - : this(expectedType, "(No exception was thrown)", null, null) {} - - /// - /// Creates a new instance of the class. Call this constructor - /// when an exception of the wrong type was thrown. - /// - /// The type of the exception that was expected - /// The actual exception that was thrown - public ThrowsException(Type expectedType, - Exception actual) - : this(expectedType, actual.GetType().FullName, actual.Message, actual.StackTrace) {} - - ThrowsException(Type expected, - string actual, - string actualMessage, - string stackTrace) - : base(expected, - actual + (actualMessage == null ? "" : ": " + actualMessage), - "Assert.Throws() Failure") - { - this.stackTrace = stackTrace; - } - - /// - /// Gets a string representation of the frames on the call stack at the time the current exception was thrown. - /// - /// A string that describes the contents of the call stack, with the most recent method call appearing first. - public override string StackTrace - { - get { return FilterStackTrace(stackTrace ?? base.StackTrace); } - } - } +using System; + +namespace Xunit.Sdk +{ + /// + /// Exception thrown when code unexpectedly fails to throw an exception. + /// + public class ThrowsException : AssertActualExpectedException + { + readonly string stackTrace = null; + + /// + /// Creates a new instance of the class. Call this constructor + /// when no exception was thrown. + /// + /// The type of the exception that was expected + public ThrowsException(Type expectedType) + : this(expectedType, "(No exception was thrown)", null, null) {} + + /// + /// Creates a new instance of the class. Call this constructor + /// when an exception of the wrong type was thrown. + /// + /// The type of the exception that was expected + /// The actual exception that was thrown + public ThrowsException(Type expectedType, + Exception actual) + : this(expectedType, actual.GetType().FullName, actual.Message, actual.StackTrace) {} + + ThrowsException(Type expected, + string actual, + string actualMessage, + string stackTrace) + : base(expected, + actual + (actualMessage == null ? "" : ": " + actualMessage), + "Assert.Throws() Failure") + { + this.stackTrace = stackTrace; + } + + /// + /// Gets a string representation of the frames on the call stack at the time the current exception was thrown. + /// + /// A string that describes the contents of the call stack, with the most recent method call appearing first. + public override string StackTrace + { + get { return FilterStackTrace(stackTrace ?? base.StackTrace); } + } + } } \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/TimeoutException.cs b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/TimeoutException.cs index 0f9380799..1110545cc 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/TimeoutException.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/TimeoutException.cs @@ -1,15 +1,15 @@ -namespace Xunit.Sdk -{ - /// - /// Exception thrown when a test method exceeds the given timeout value - /// - public class TimeoutException : AssertException - { - /// - /// Creates a new instance of the class. - /// - /// The timeout value, in milliseconds - public TimeoutException(long timeout) - : base(string.Format("Test execution time exceeded: {0}ms", timeout)) {} - } +namespace Xunit.Sdk +{ + /// + /// Exception thrown when a test method exceeds the given timeout value + /// + public class TimeoutException : AssertException + { + /// + /// Creates a new instance of the class. + /// + /// The timeout value, in milliseconds + public TimeoutException(long timeout) + : base(string.Format("Test execution time exceeded: {0}ms", timeout)) {} + } } \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/TraceAssertException.cs b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/TraceAssertException.cs index 81f8e7ff1..0e6a00a0e 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/TraceAssertException.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/TraceAssertException.cs @@ -1,69 +1,69 @@ -using System; - -namespace Xunit.Sdk -{ - /// - /// Exception that is thrown when a call to Debug.Assert() fails. - /// - public class TraceAssertException : AssertException - { - readonly string assertDetailedMessage; - readonly string assertMessage; - - /// - /// Creates a new instance of the class. - /// - /// The original assert message - public TraceAssertException(string assertMessage) - : this(assertMessage, "") {} - - /// - /// Creates a new instance of the class. - /// - /// The original assert message - /// The original assert detailed message - public TraceAssertException(string assertMessage, - string assertDetailedMessage) - { - this.assertMessage = assertMessage ?? ""; - this.assertDetailedMessage = assertDetailedMessage ?? ""; - } - - /// - /// Gets the original assert detailed message. - /// - public string AssertDetailedMessage - { - get { return assertDetailedMessage; } - } - - /// - /// Gets the original assert message. - /// - public string AssertMessage - { - get { return assertMessage; } - } - - /// - /// Gets a message that describes the current exception. - /// - public override string Message - { - get - { - string result = "Debug.Assert() Failure"; - - if (AssertMessage != "") - { - result += " : " + AssertMessage; - - if (AssertDetailedMessage != "") - result += Environment.NewLine + "Detailed Message:" + Environment.NewLine + AssertDetailedMessage; - } - - return result; - } - } - } +using System; + +namespace Xunit.Sdk +{ + /// + /// Exception that is thrown when a call to Debug.Assert() fails. + /// + public class TraceAssertException : AssertException + { + readonly string assertDetailedMessage; + readonly string assertMessage; + + /// + /// Creates a new instance of the class. + /// + /// The original assert message + public TraceAssertException(string assertMessage) + : this(assertMessage, "") {} + + /// + /// Creates a new instance of the class. + /// + /// The original assert message + /// The original assert detailed message + public TraceAssertException(string assertMessage, + string assertDetailedMessage) + { + this.assertMessage = assertMessage ?? ""; + this.assertDetailedMessage = assertDetailedMessage ?? ""; + } + + /// + /// Gets the original assert detailed message. + /// + public string AssertDetailedMessage + { + get { return assertDetailedMessage; } + } + + /// + /// Gets the original assert message. + /// + public string AssertMessage + { + get { return assertMessage; } + } + + /// + /// Gets a message that describes the current exception. + /// + public override string Message + { + get + { + string result = "Debug.Assert() Failure"; + + if (AssertMessage != "") + { + result += " : " + AssertMessage; + + if (AssertDetailedMessage != "") + result += Environment.NewLine + "Detailed Message:" + Environment.NewLine + AssertDetailedMessage; + } + + return result; + } + } + } } \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/TrueException.cs b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/TrueException.cs index 25621fd24..76bf71913 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/TrueException.cs +++ b/Lib/xUnit/XunitLight.Silverlight/Source/Xunit/Sdk/Exceptions/TrueException.cs @@ -1,15 +1,15 @@ -namespace Xunit.Sdk -{ - /// - /// Exception thrown when a value is unexpectedly false. - /// - public class TrueException : AssertException - { - /// - /// Creates a new instance of the class. - /// - /// The user message to be displayed, or null for the default message - public TrueException(string userMessage) - : base(userMessage ?? "Assert.True() Failure") {} - } +namespace Xunit.Sdk +{ + /// + /// Exception thrown when a value is unexpectedly false. + /// + public class TrueException : AssertException + { + /// + /// Creates a new instance of the class. + /// + /// The user message to be displayed, or null for the default message + public TrueException(string userMessage) + : base(userMessage ?? "Assert.True() Failure") {} + } } \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/XunitLight.Silverlight.csproj b/Lib/xUnit/XunitLight.Silverlight/Source/XunitLight.Silverlight.csproj index 3beda3cd0..5956534f2 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/XunitLight.Silverlight.csproj +++ b/Lib/xUnit/XunitLight.Silverlight/Source/XunitLight.Silverlight.csproj @@ -1,131 +1,131 @@ - - - - v3.5 - - - Debug - AnyCPU - 9.0.30729 - 2.0 - {9D2235D5-17C0-49F8-A3F8-FE3FBFA06564} - {A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} - Library - Properties - Microsoft.Silverlight.Testing.UnitTesting.Metadata.XunitLight - XunitLight.Silverlight - v3.0 - false - true - false - true - XunitLight.snk - Silverlight - $(TargetFrameworkVersion) - - - 3.5 - - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - - false - - - true - full - false - Bin\Debug - DEBUG;TRACE;SILVERLIGHT - true - true - prompt - 4 - - - pdbonly - true - Bin\Release - TRACE;SILVERLIGHT - true - true - prompt - 4 - - - - ..\..\..\Microsoft\Microsoft.Silverlight.Testing.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + v3.5 + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {9D2235D5-17C0-49F8-A3F8-FE3FBFA06564} + {A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + Microsoft.Silverlight.Testing.UnitTesting.Metadata.XunitLight + XunitLight.Silverlight + v3.0 + false + true + false + true + XunitLight.snk + Silverlight + $(TargetFrameworkVersion) + + + 3.5 + + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + false + + + true + full + false + Bin\Debug + DEBUG;TRACE;SILVERLIGHT + true + true + prompt + 4 + + + pdbonly + true + Bin\Release + TRACE;SILVERLIGHT + true + true + prompt + 4 + + + + ..\..\..\Microsoft\Microsoft.Silverlight.Testing.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Lib/xUnit/XunitLight.Silverlight/Source/XunitLight.Silverlight.sln b/Lib/xUnit/XunitLight.Silverlight/Source/XunitLight.Silverlight.sln index e6a649266..301ca224d 100644 --- a/Lib/xUnit/XunitLight.Silverlight/Source/XunitLight.Silverlight.sln +++ b/Lib/xUnit/XunitLight.Silverlight/Source/XunitLight.Silverlight.sln @@ -1,20 +1,20 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XunitLight.Silverlight", "XunitLight.Silverlight.csproj", "{9D2235D5-17C0-49F8-A3F8-FE3FBFA06564}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {9D2235D5-17C0-49F8-A3F8-FE3FBFA06564}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9D2235D5-17C0-49F8-A3F8-FE3FBFA06564}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9D2235D5-17C0-49F8-A3F8-FE3FBFA06564}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9D2235D5-17C0-49F8-A3F8-FE3FBFA06564}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XunitLight.Silverlight", "XunitLight.Silverlight.csproj", "{9D2235D5-17C0-49F8-A3F8-FE3FBFA06564}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9D2235D5-17C0-49F8-A3F8-FE3FBFA06564}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9D2235D5-17C0-49F8-A3F8-FE3FBFA06564}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9D2235D5-17C0-49F8-A3F8-FE3FBFA06564}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9D2235D5-17C0-49F8-A3F8-FE3FBFA06564}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Lib/xUnit/xunit.console.exe.config b/Lib/xUnit/xunit.console.exe.config index e73fc9d2a..a253b460d 100644 --- a/Lib/xUnit/xunit.console.exe.config +++ b/Lib/xUnit/xunit.console.exe.config @@ -1,21 +1,21 @@ - - - - -
- - - - - - - - - + + + + +
+ + + + + + + + + \ No newline at end of file diff --git a/Lib/xUnit/xunit.console.x86.exe.config b/Lib/xUnit/xunit.console.x86.exe.config index 10222232d..89e63fa2e 100644 --- a/Lib/xUnit/xunit.console.x86.exe.config +++ b/Lib/xUnit/xunit.console.x86.exe.config @@ -1,21 +1,21 @@ - - - - -
- - - - - - - - - + + + + +
+ + + + + + + + + \ No newline at end of file diff --git a/Lib/xUnit/xunit.dll.tdnet b/Lib/xUnit/xunit.dll.tdnet index acfd8cb9b..535d5e23a 100644 --- a/Lib/xUnit/xunit.dll.tdnet +++ b/Lib/xUnit/xunit.dll.tdnet @@ -1,5 +1,5 @@ - - xUnit.net {0}.{1} build {3} - xunit.runner.tdnet.dll - Xunit.Runner.TdNet.TdNetRunner + + xUnit.net {0}.{1} build {3} + xunit.runner.tdnet.dll + Xunit.Runner.TdNet.TdNetRunner \ No newline at end of file diff --git a/Lib/xUnit/xunit.extensions.xml b/Lib/xUnit/xunit.extensions.xml index 62cb5e2a3..9dbfec9b5 100644 --- a/Lib/xUnit/xunit.extensions.xml +++ b/Lib/xUnit/xunit.extensions.xml @@ -1,706 +1,706 @@ - - - - xunit.extensions - - - - - A wrapper for Assert which is used by . - - - - - Verifies that a collection contains a given object. - - The type of the object to be verified - The object expected to be in the collection - The collection to be inspected - Thrown when the object is not present in the collection - - - - Verifies that a collection contains a given object, using a comparer. - - The type of the object to be verified - The object expected to be in the collection - The collection to be inspected - The comparer used to equate objects in the collection with the expected object - Thrown when the object is not present in the collection - - - - Verifies that a string contains a given sub-string, using the current culture. - - The sub-string expected to be in the string - The string to be inspected - Thrown when the sub-string is not present inside the string - - - - Verifies that a string contains a given sub-string, using the given comparison type. - - The sub-string expected to be in the string - The string to be inspected - The type of string comparison to perform - Thrown when the sub-string is not present inside the string - - - - Verifies that a collection does not contain a given object. - - The type of the object to be compared - The object that is expected not to be in the collection - The collection to be inspected - Thrown when the object is present inside the container - - - - Verifies that a collection does not contain a given object, using a comparer. - - The type of the object to be compared - The object that is expected not to be in the collection - The collection to be inspected - The comparer used to equate objects in the collection with the expected object - Thrown when the object is present inside the container - - - - Verifies that a string does not contain a given sub-string, using the current culture. - - The sub-string which is expected not to be in the string - The string to be inspected - Thrown when the sub-string is present inside the string - - - - Verifies that a string does not contain a given sub-string, using the current culture. - - The sub-string which is expected not to be in the string - The string to be inspected - The type of string comparison to perform - Thrown when the sub-string is present inside the given string - - - - Verifies that a block of code does not throw any exceptions. - - A delegate to the code to be tested - - - - Verifies that a collection is empty. - - The collection to be inspected - Thrown when the collection is null - Thrown when the collection is not empty - - - - Verifies that two objects are equal, using a default comparer. - - The type of the objects to be compared - The expected value - The value to be compared against - Thrown when the objects are not equal - - - - Verifies that two objects are equal, using a custom comparer. - - The type of the objects to be compared - The expected value - The value to be compared against - The comparer used to compare the two objects - Thrown when the objects are not equal - - - Do not call this method. Call Assert.Equal() instead. - - - - Verifies that the condition is false. - - The condition to be tested - Thrown if the condition is not false - - - - Verifies that the condition is false. - - The condition to be tested - The message to show when the condition is not false - Thrown if the condition is not false - - - - Serves as a hash function for a particular type. - - A hash code for the current . - - - - Verifies that a value is within a given range. - - The type of the value to be compared - The actual value to be evaluated - The (inclusive) low value of the range - The (inclusive) high value of the range - Thrown when the value is not in the given range - - - - Verifies that a value is within a given range, using a comparer. - - The type of the value to be compared - The actual value to be evaluated - The (inclusive) low value of the range - The (inclusive) high value of the range - The comparer used to evaluate the value's range - Thrown when the value is not in the given range - - - - Verifies that an object is not exactly the given type. - - The type the object should not be - The object to be evaluated - Thrown when the object is the given type - - - - Verifies that an object is not exactly the given type. - - The type the object should not be - The object to be evaluated - Thrown when the object is the given type - - - - Verifies that an object is exactly the given type (and not a derived type). - - The type the object should be - The object to be evaluated - The object, casted to type T when successful - Thrown when the object is not the given type - - - - Verifies that an object is exactly the given type (and not a derived type). - - The type the object should be - The object to be evaluated - Thrown when the object is not the given type - - - - Verifies that a collection is not empty. - - The collection to be inspected - Thrown when a null collection is passed - Thrown when the collection is empty - - - - Verifies that two objects are not equal, using a default comparer. - - The type of the objects to be compared - The expected object - The actual object - Thrown when the objects are equal - - - - Verifies that two objects are not equal, using a custom comparer. - - The type of the objects to be compared - The expected object - The actual object - The comparer used to examine the objects - Thrown when the objects are equal - - - - Verifies that a value is not within a given range, using the default comparer. - - The type of the value to be compared - The actual value to be evaluated - The (inclusive) low value of the range - The (inclusive) high value of the range - Thrown when the value is in the given range - - - - Verifies that a value is not within a given range, using a comparer. - - The type of the value to be compared - The actual value to be evaluated - The (inclusive) low value of the range - The (inclusive) high value of the range - The comparer used to evaluate the value's range - Thrown when the value is in the given range - - - - Verifies that an object reference is not null. - - The object to be validated - Thrown when the object is not null - - - - Verifies that two objects are not the same instance. - - The expected object instance - The actual object instance - Thrown when the objects are the same instance - - - - Verifies that an object reference is null. - - The object to be inspected - Thrown when the object reference is not null - - - - Verifies that two objects are the same instance. - - The expected object instance - The actual object instance - Thrown when the objects are not the same instance - - - - Verifies that the exact exception is thrown (and not a derived exception type). - - The type of the exception expected to be thrown - A delegate to the code to be tested - The exception that was thrown, when successful - Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown - - - - Verifies that the exact exception is thrown (and not a derived exception type). - - The type of the exception expected to be thrown - The message to be shown if the test fails - A delegate to the code to be tested - The exception that was thrown, when successful - Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown - - - - Verifies that the exact exception is thrown (and not a derived exception type). - - The type of the exception expected to be thrown - A delegate to the code to be tested - The exception that was thrown, when successful - Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown - - - - Verifies that an expression is true. - - The condition to be inspected - Thrown when the condition is false - - - - Verifies that an expression is true. - - The condition to be inspected - The message to be shown when the condition is false - Thrown when the condition is false - - - - A class which can be derived from for test classes, which bring an overridable version - of Assert (using the class. - - - - - Gets a class which provides assertions. - - - - - Apply this attribute to your test method to replace the - with another role. - - - - - Replaces the identity of the current thread with . - - The role's name - - - - Restores the original . - - The method under test - - - - Stores the current and replaces it with - a new role identified in constructor. - - The method under test - - - - Apply this attribute to your test method to automatically create a - that is rolled back when the test is - finished. - - - - - Rolls back the transaction. - - - - - Creates the transaction. - - - - - Gets or sets the isolation level of the transaction. - Default value is .Unspecified. - - - - - Gets or sets the scope option for the transaction. - Default value is .Required. - - - - - Gets or sets the timeout of the transaction, in milliseconds. - By default, the transaction will not timeout. - - - - - Provides a data source for a data theory, with the data coming from a class - which must implement IEnumerable<object[]>. - - - - - Abstract attribute which represents a data source for a data theory. - Data source providers derive from this attribute and implement GetData - to return the data for the theory. - - - - - Returns the data to be used to test the theory. - - - The parameter is provided so that the - test data can be converted to the destination parameter type when necessary. - Generally, data should NOT be automatically converted, UNLESS the source data - format does not have rich types (for example, all numbers in Excel spreadsheets - are returned as even if they are integers). Derivers of - this class should NOT throw exceptions for mismatched types or mismatched number - of parameters; the test framework will throw these exceptions at the correct - time. - - The method that is being tested - The types of the parameters for the test method - The theory data - - - - Initializes a new instance of the class. - - The class that provides the data. - - - - - - - Represents an implementation of which uses an - instance of to get the data for a - decorated test method. - - - - - - - - Converts a parameter to its destination parameter type, if necessary. - - The parameter value - The destination parameter type (null if not known) - The converted parameter value - - - - Gets the data adapter to be used to retrieve the test data. - - - - - Provides a data source for a data theory, with the data coming from inline values. - - - - - Initializes a new instance of the class. - - The data values to pass to the theory - - - - Returns the data to be used to test the theory. - - The method that is being tested - The types of the parameters for the test method - The theory data, in table form - - - - Provides a data source for a data theory, with the data coming from an OLEDB connection. - - - - - Creates a new instance of . - - The OLEDB connection string to the data - The SELECT statement used to return the data for the theory - - - - - - - Provides a data source for a data theory, with the data coming from a public static property on the test class. - The property must return IEnumerable<object[]> with the test data. - - - - - Creates a new instance of / - - The name of the public static property on the test class that will provide the test data - - - - Returns the data to be used to test the theory. - - The method that is being tested - The types of the parameters for the test method - The theory data, in table form - - - - Provides a data source for a data theory, with the data coming a Microsoft SQL Server. - - - - - Creates a new instance of , using a trusted connection. - - The server name of the Microsoft SQL Server - The database name - The SQL SELECT statement to return the data for the data theory - - - - Creates a new instance of , using the provided username and password. - - The server name of the Microsoft SQL Server - The database name - The username for the server - The password for the server - The SQL SELECT statement to return the data for the data theory - - - - Provides a data source for a data theory, with the data coming a Microsoft Excel (.xls) spreadsheet. - - - - - Creates a new instance of . - - The filename of the XLS spreadsheet file; if the filename provided - is relative, then it is relative to the location of xunit.extensions.dll. - The SELECT statement that returns the data for the theory - - - - - - - A wrapper around the static operations on which allows time - to be frozen using the . The clock begins in the - thawed state; that is, calls to , , and - return current (non-frozen) values. - - - - - Freezes the clock with the current time. - Until is called, all calls to , , and - will return the exact same values. - - - - - Freezes the clock with the given date and time, considered to be local time. - Until is called, all calls to , , and - will return the exact same values. - - The local date and time to freeze to - - - - Freezes the clock with the given date and time, considered to be Coordinated Universal Time (UTC). - Until is called, all calls to , , and - will return the exact same values. - - The UTC date and time to freeze to - - - - Thaws the clock so that , , and - return normal values. - - - - - Gets a object that is set to the current date and time on this computer, - expressed as the local time. - - - - - Gets the current date. - - - - - Gets a object that is set to the current date and time on this computer, - expressed as the Coordinated Universal Time (UTC). - - - - - Apply this attribute to your test method to freeze the time represented by the - class. - - - - - Freeze the clock with the current date and time. - - - - - Freeze the clock with the given date, considered to be local time. - - The frozen year - The frozen month - The frozen day - - - - Freeze the clock with the given date and time, considered to be in local time. - - The frozen year - The frozen month - The frozen day - The frozen hour - The frozen minute - The frozen second - - - - Freeze the clock with the given date and time, with the given kind of time. - - The frozen year - The frozen month - The frozen day - The frozen hour - The frozen minute - The frozen second - The frozen time kind - - - - Thaws the clock. - - The method under test - - - - Freezes the clock. - - The method under test - - - - Marks a test method as being a data theory. Data theories are tests which are fed - various bits of data from a data source, mapping to parameters on the test method. - If the data source contains multiple rows, then the test method is executed - multiple times (once with each data row). - - - - - Creates instances of which represent individual intended - invocations of the test method, one per data row in the data source. - - The method under test - An enumerator through the desired test method invocations - - - - Represents a single invocation of a data theory test method. - - - - - Creates a new instance of . - - The method under test - The display name of the method under test - The parameters to be passed to the test method - - - - - - - Gets the parameter values that are passed to the test method. - - - - - Apply to a test method to trace the method begin and end. - - - - - This method is called before the test method is executed. - - The method under test - - - - This method is called after the test method is executed. - - The method under test - - - + + + + xunit.extensions + + + + + A wrapper for Assert which is used by . + + + + + Verifies that a collection contains a given object. + + The type of the object to be verified + The object expected to be in the collection + The collection to be inspected + Thrown when the object is not present in the collection + + + + Verifies that a collection contains a given object, using a comparer. + + The type of the object to be verified + The object expected to be in the collection + The collection to be inspected + The comparer used to equate objects in the collection with the expected object + Thrown when the object is not present in the collection + + + + Verifies that a string contains a given sub-string, using the current culture. + + The sub-string expected to be in the string + The string to be inspected + Thrown when the sub-string is not present inside the string + + + + Verifies that a string contains a given sub-string, using the given comparison type. + + The sub-string expected to be in the string + The string to be inspected + The type of string comparison to perform + Thrown when the sub-string is not present inside the string + + + + Verifies that a collection does not contain a given object. + + The type of the object to be compared + The object that is expected not to be in the collection + The collection to be inspected + Thrown when the object is present inside the container + + + + Verifies that a collection does not contain a given object, using a comparer. + + The type of the object to be compared + The object that is expected not to be in the collection + The collection to be inspected + The comparer used to equate objects in the collection with the expected object + Thrown when the object is present inside the container + + + + Verifies that a string does not contain a given sub-string, using the current culture. + + The sub-string which is expected not to be in the string + The string to be inspected + Thrown when the sub-string is present inside the string + + + + Verifies that a string does not contain a given sub-string, using the current culture. + + The sub-string which is expected not to be in the string + The string to be inspected + The type of string comparison to perform + Thrown when the sub-string is present inside the given string + + + + Verifies that a block of code does not throw any exceptions. + + A delegate to the code to be tested + + + + Verifies that a collection is empty. + + The collection to be inspected + Thrown when the collection is null + Thrown when the collection is not empty + + + + Verifies that two objects are equal, using a default comparer. + + The type of the objects to be compared + The expected value + The value to be compared against + Thrown when the objects are not equal + + + + Verifies that two objects are equal, using a custom comparer. + + The type of the objects to be compared + The expected value + The value to be compared against + The comparer used to compare the two objects + Thrown when the objects are not equal + + + Do not call this method. Call Assert.Equal() instead. + + + + Verifies that the condition is false. + + The condition to be tested + Thrown if the condition is not false + + + + Verifies that the condition is false. + + The condition to be tested + The message to show when the condition is not false + Thrown if the condition is not false + + + + Serves as a hash function for a particular type. + + A hash code for the current . + + + + Verifies that a value is within a given range. + + The type of the value to be compared + The actual value to be evaluated + The (inclusive) low value of the range + The (inclusive) high value of the range + Thrown when the value is not in the given range + + + + Verifies that a value is within a given range, using a comparer. + + The type of the value to be compared + The actual value to be evaluated + The (inclusive) low value of the range + The (inclusive) high value of the range + The comparer used to evaluate the value's range + Thrown when the value is not in the given range + + + + Verifies that an object is not exactly the given type. + + The type the object should not be + The object to be evaluated + Thrown when the object is the given type + + + + Verifies that an object is not exactly the given type. + + The type the object should not be + The object to be evaluated + Thrown when the object is the given type + + + + Verifies that an object is exactly the given type (and not a derived type). + + The type the object should be + The object to be evaluated + The object, casted to type T when successful + Thrown when the object is not the given type + + + + Verifies that an object is exactly the given type (and not a derived type). + + The type the object should be + The object to be evaluated + Thrown when the object is not the given type + + + + Verifies that a collection is not empty. + + The collection to be inspected + Thrown when a null collection is passed + Thrown when the collection is empty + + + + Verifies that two objects are not equal, using a default comparer. + + The type of the objects to be compared + The expected object + The actual object + Thrown when the objects are equal + + + + Verifies that two objects are not equal, using a custom comparer. + + The type of the objects to be compared + The expected object + The actual object + The comparer used to examine the objects + Thrown when the objects are equal + + + + Verifies that a value is not within a given range, using the default comparer. + + The type of the value to be compared + The actual value to be evaluated + The (inclusive) low value of the range + The (inclusive) high value of the range + Thrown when the value is in the given range + + + + Verifies that a value is not within a given range, using a comparer. + + The type of the value to be compared + The actual value to be evaluated + The (inclusive) low value of the range + The (inclusive) high value of the range + The comparer used to evaluate the value's range + Thrown when the value is in the given range + + + + Verifies that an object reference is not null. + + The object to be validated + Thrown when the object is not null + + + + Verifies that two objects are not the same instance. + + The expected object instance + The actual object instance + Thrown when the objects are the same instance + + + + Verifies that an object reference is null. + + The object to be inspected + Thrown when the object reference is not null + + + + Verifies that two objects are the same instance. + + The expected object instance + The actual object instance + Thrown when the objects are not the same instance + + + + Verifies that the exact exception is thrown (and not a derived exception type). + + The type of the exception expected to be thrown + A delegate to the code to be tested + The exception that was thrown, when successful + Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown + + + + Verifies that the exact exception is thrown (and not a derived exception type). + + The type of the exception expected to be thrown + The message to be shown if the test fails + A delegate to the code to be tested + The exception that was thrown, when successful + Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown + + + + Verifies that the exact exception is thrown (and not a derived exception type). + + The type of the exception expected to be thrown + A delegate to the code to be tested + The exception that was thrown, when successful + Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown + + + + Verifies that an expression is true. + + The condition to be inspected + Thrown when the condition is false + + + + Verifies that an expression is true. + + The condition to be inspected + The message to be shown when the condition is false + Thrown when the condition is false + + + + A class which can be derived from for test classes, which bring an overridable version + of Assert (using the class. + + + + + Gets a class which provides assertions. + + + + + Apply this attribute to your test method to replace the + with another role. + + + + + Replaces the identity of the current thread with . + + The role's name + + + + Restores the original . + + The method under test + + + + Stores the current and replaces it with + a new role identified in constructor. + + The method under test + + + + Apply this attribute to your test method to automatically create a + that is rolled back when the test is + finished. + + + + + Rolls back the transaction. + + + + + Creates the transaction. + + + + + Gets or sets the isolation level of the transaction. + Default value is .Unspecified. + + + + + Gets or sets the scope option for the transaction. + Default value is .Required. + + + + + Gets or sets the timeout of the transaction, in milliseconds. + By default, the transaction will not timeout. + + + + + Provides a data source for a data theory, with the data coming from a class + which must implement IEnumerable<object[]>. + + + + + Abstract attribute which represents a data source for a data theory. + Data source providers derive from this attribute and implement GetData + to return the data for the theory. + + + + + Returns the data to be used to test the theory. + + + The parameter is provided so that the + test data can be converted to the destination parameter type when necessary. + Generally, data should NOT be automatically converted, UNLESS the source data + format does not have rich types (for example, all numbers in Excel spreadsheets + are returned as even if they are integers). Derivers of + this class should NOT throw exceptions for mismatched types or mismatched number + of parameters; the test framework will throw these exceptions at the correct + time. + + The method that is being tested + The types of the parameters for the test method + The theory data + + + + Initializes a new instance of the class. + + The class that provides the data. + + + + + + + Represents an implementation of which uses an + instance of to get the data for a + decorated test method. + + + + + + + + Converts a parameter to its destination parameter type, if necessary. + + The parameter value + The destination parameter type (null if not known) + The converted parameter value + + + + Gets the data adapter to be used to retrieve the test data. + + + + + Provides a data source for a data theory, with the data coming from inline values. + + + + + Initializes a new instance of the class. + + The data values to pass to the theory + + + + Returns the data to be used to test the theory. + + The method that is being tested + The types of the parameters for the test method + The theory data, in table form + + + + Provides a data source for a data theory, with the data coming from an OLEDB connection. + + + + + Creates a new instance of . + + The OLEDB connection string to the data + The SELECT statement used to return the data for the theory + + + + + + + Provides a data source for a data theory, with the data coming from a public static property on the test class. + The property must return IEnumerable<object[]> with the test data. + + + + + Creates a new instance of / + + The name of the public static property on the test class that will provide the test data + + + + Returns the data to be used to test the theory. + + The method that is being tested + The types of the parameters for the test method + The theory data, in table form + + + + Provides a data source for a data theory, with the data coming a Microsoft SQL Server. + + + + + Creates a new instance of , using a trusted connection. + + The server name of the Microsoft SQL Server + The database name + The SQL SELECT statement to return the data for the data theory + + + + Creates a new instance of , using the provided username and password. + + The server name of the Microsoft SQL Server + The database name + The username for the server + The password for the server + The SQL SELECT statement to return the data for the data theory + + + + Provides a data source for a data theory, with the data coming a Microsoft Excel (.xls) spreadsheet. + + + + + Creates a new instance of . + + The filename of the XLS spreadsheet file; if the filename provided + is relative, then it is relative to the location of xunit.extensions.dll. + The SELECT statement that returns the data for the theory + + + + + + + A wrapper around the static operations on which allows time + to be frozen using the . The clock begins in the + thawed state; that is, calls to , , and + return current (non-frozen) values. + + + + + Freezes the clock with the current time. + Until is called, all calls to , , and + will return the exact same values. + + + + + Freezes the clock with the given date and time, considered to be local time. + Until is called, all calls to , , and + will return the exact same values. + + The local date and time to freeze to + + + + Freezes the clock with the given date and time, considered to be Coordinated Universal Time (UTC). + Until is called, all calls to , , and + will return the exact same values. + + The UTC date and time to freeze to + + + + Thaws the clock so that , , and + return normal values. + + + + + Gets a object that is set to the current date and time on this computer, + expressed as the local time. + + + + + Gets the current date. + + + + + Gets a object that is set to the current date and time on this computer, + expressed as the Coordinated Universal Time (UTC). + + + + + Apply this attribute to your test method to freeze the time represented by the + class. + + + + + Freeze the clock with the current date and time. + + + + + Freeze the clock with the given date, considered to be local time. + + The frozen year + The frozen month + The frozen day + + + + Freeze the clock with the given date and time, considered to be in local time. + + The frozen year + The frozen month + The frozen day + The frozen hour + The frozen minute + The frozen second + + + + Freeze the clock with the given date and time, with the given kind of time. + + The frozen year + The frozen month + The frozen day + The frozen hour + The frozen minute + The frozen second + The frozen time kind + + + + Thaws the clock. + + The method under test + + + + Freezes the clock. + + The method under test + + + + Marks a test method as being a data theory. Data theories are tests which are fed + various bits of data from a data source, mapping to parameters on the test method. + If the data source contains multiple rows, then the test method is executed + multiple times (once with each data row). + + + + + Creates instances of which represent individual intended + invocations of the test method, one per data row in the data source. + + The method under test + An enumerator through the desired test method invocations + + + + Represents a single invocation of a data theory test method. + + + + + Creates a new instance of . + + The method under test + The display name of the method under test + The parameters to be passed to the test method + + + + + + + Gets the parameter values that are passed to the test method. + + + + + Apply to a test method to trace the method begin and end. + + + + + This method is called before the test method is executed. + + The method under test + + + + This method is called after the test method is executed. + + The method under test + + + diff --git a/Lib/xUnit/xunit.gui.exe.Config b/Lib/xUnit/xunit.gui.exe.Config index 65a18b03b..11f3fdcb9 100644 --- a/Lib/xUnit/xunit.gui.exe.Config +++ b/Lib/xUnit/xunit.gui.exe.Config @@ -1,6 +1,6 @@ - - - - - + + + + + \ No newline at end of file diff --git a/Lib/xUnit/xunit.runner.utility.xml b/Lib/xUnit/xunit.runner.utility.xml index 666f34c7b..95924f162 100644 --- a/Lib/xUnit/xunit.runner.utility.xml +++ b/Lib/xUnit/xunit.runner.utility.xml @@ -1,1048 +1,1048 @@ - - - - xunit.runner.utility - - - - - Guard class, used for guard clauses and argument validation - - - - - - - - - - - - - - Wraps calls to the Executor. Used by runners to perform version-resilient test - enumeration and execution. - - - - - Wraps calls to the Executor. Used by runners to perform version-resilient test - enumeration and execution. - - - - - Enumerates the tests in an assembly. - - The fully-formed assembly node of the XML - - - - Gets a count of the tests in the assembly. - - Returns the number of tests, if known; returns -1 if not known. May not represent - an exact count, but should be a best effort guess by the framework. - - - - Runs all the tests in an assembly. - - The callback which is called as each test/class/assembly is - finished, providing XML nodes that are part of the xUnit.net XML output format. - Test runs can be cancelled by returning false to the callback. If null, there are - no status callbacks (and cancellation isn't possible). - Returns the fully-formed assembly node for the assembly that was just run. - - - - Runs all the tests in the given class. - - The type. - The callback which is called as each test/class is - finished, providing XML nodes that are part of the xUnit.net XML output format. - Test runs can be cancelled by returning false to the callback. If null, there are - no status callbacks (and cancellation isn't possible). - Returns the fully-formed class node for the class that was just run. - - - - Runs a single test in a class. - - The type to run. - The method to run. - The callback which is called as each test/class is - finished, providing XML nodes that are part of the xUnit.net XML output format. - Test runs can be cancelled by returning false to the callback. If null, there are - no status callbacks (and cancellation isn't possible). - Returns the fully-formed class node for the class of the test that was just run. - - - - Runs several tests in a single class. - - The type. - The methods to run. - The callback which is called as each test/class is - finished, providing XML nodes that are part of the xUnit.net XML output format. - Test runs can be cancelled by returning false to the callback. If null, there are - no status callbacks (and cancellation isn't possible). - Returns the fully-formed class node for the class of the tests that were just run. - - - - Gets the full pathname to the assembly under test. - - - - - Gets the full pathname to the configuration file. - - - - - Gets the version of xunit.dll used by the test assembly. - - - - - Initializes a new instance of the class. - - The assembly filename. - The config filename. If null, the default config filename will be used. - Set to true to enable shadow copying; false, otherwise. - - - - Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - The callback object which receives real-time status notifications from the - test runner. - - - - - Called when the assembly has finished running. - - The test assembly. - The total number of tests run. - The number of failed tests. - The number of skipped tests. - The time taken to run, in seconds. - - - - Called when the assembly has started running. - - The test assembly. - - - - Called when a class failure is encountered (i.e., when a fixture from - IUseFixture throws an exception during construction or . - - The test class. - The full type name of the exception. - The exception message. - The exception stack trace. - - - - - Called when an exception is thrown (i.e., a catastrophic failure of the testing system). - - The test assembly. - The exception that was thrown. - - - - Called when a test has finished running, regardless of what the result was. - - The test method. - Return true to continue running tests; return false to stop the test run. - - - - Called when a test has started running. - - The test method. - Return true to continue running tests; return false to stop the test run. - - - - Represents the ability to run one or more test methods. - - - - - Runs the specified test methods. - - The test methods to run. - The run status information callback. - - - - Represents the ability to load and unload test assemblies, as well as enumerate - the test assemblies, the test methods, and run tests. - - - - - Represents the ability to enumerate and filter test methods. - - - - - Enumerates all test methods. - - - - - Enumerates test methods which pass the given filter. - - The test method filter. - - - - The test assemblies loaded into the environment. - - - - - Enumerates the test assemblies in the environment. - - - - - - - - - - - Enumerates the traits across all the loaded assemblies. - - - - - Loads the specified assembly, using the default configuration file. - - The assembly filename. - The which represents the newly - loaded test assembly. - - - - Loads the specified assembly using the specified configuration file. - - The assembly filename. - The config filename. - The which represents the newly - loaded test assembly. - - - - Loads the specified assembly using the specified configuration file. - - The assembly filename. - The config filename. - Whether the DLLs should be shadow copied. - The which represents the newly - loaded test assembly. - - - - Adds the assembly loaded into the given - into the environment. - - The executor wrapper. - The which represents the newly - loaded test assembly. - - - - - - - Unloads the specified assembly. - - The assembly to unload. - - - - Represents a failed test run in the object model. - - - - - Base class for all test results in the object model. - - - - - Initializes a new instance of the class. - - The duration the test took to run. For skipped tests, should be 0.0. - The display name of the test result. - - - - Gets the display name of the test result. - - - - - Gets the duration the test took to run. - - - - - Initializes a new instance of the class. - - The duration the test took to run. - The display name of the test result. - The output that was captured during the test run. - Type of the exception. - The exception message. - The exception stack trace. - - - - Gets the output that was captured during the test run. - - - - - Gets the type of the exception. - - - - - Gets the exception message. - - - - - Gets the exception stack trace. - - - - - Represents a skipped test run in the object model. - - - - - Initializes a new instance of the class. - - The display name of the test result. - The skip reason. - - - - Gets the skip reason. - - - - - Acts as an and adapts the callback messages - into calls to an instance of . - - - - - Represents a logger used by and . - - - - - Called when the assembly has finished running. - - The assembly filename. - The total number of tests run. - The number of failed tests. - The number of skipped tests. - The time taken to run, in seconds. - - - - Called when the assembly has started running. - - The assembly filename. - The configuration filename, if given; null, otherwise. - The version of xunit.dll. - - - - Called when a class failure is encountered (i.e., when a fixture from - IUseFixture throws an exception during construction or . - - The full type name of the class. - The full type name of the exception. - The exception message. - The exception stack trace. - - - - - Called when an exception is thrown (i.e., a catastrophic failure of the testing system). - - The assembly filename. - The exception that was thrown. - - - - Called when a test fails. - - The description name of the test. - The full type name of the test class. - The name of the method. - The time spent running the test, in seconds. - The output of the test during its run. - The full type name of the exception. - The exception message. - The exception stack trace. - - - - Called when a test has finished running, regardless of what the result was. - - The description name of the test. - The full type name of the test class. - The name of the method. - Return true to continue running tests; return false to stop the test run. - - - - Called when a test has passed. - - The description name of the test. - The full type name of the test class. - The name of the method. - The time spent running the test, in seconds. - The output of the test during its run. - - - - Called when a test was finished. - - The description name of the test. - The full type name of the test class. - The name of the method. - The skip reason. - - - - Called when a test has started running. - - The description name of the test. - The full type name of the test class. - The name of the method. - Return true to continue running tests; return false to stop the test run. - - - - Initializes a new instance of the class. - - The test class. - The run status information callback. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Represents a passed test run in the object model. - - - - - Initializes a new instance of the class. - - The duration the test took to run. - The display name of the test result. - The output that was captured during the test run. - - - - Gets the output that was captured during the test run. - - - - - Indicates the composite test method status - - - - - The method has not been run - - - - - All test results for the last run passed - - - - - At least one test result for the last run failed - - - - - At least one test result for the last run was skipped, and none failed - - - - - Represents an xUnit Test Project file (.xunit file) - - - - - Initializes a new instance of the class. - - - - - Loads an xUnit.net Test Project file from disk. - - The test project filename - - - - Saves the xUnit.net Test Project file to disk. - - The test project filename - - - - Gets or sets the assemblies in the project. - - - - - Represents an assembly in an . - - - - - Initializes a new instance of the class. - - - - - Gets or sets the assembly filename. - - - - - Gets or sets the config filename. - - - - - Gets or sets a value indicating whether to shadow copy the assembly - when running the tests. - - - The xUnit.net GUI runner does not support this field. - - - - - Gets or sets the output filenames. The dictionary key is the type - of the file to be output; the dictionary value is the filename to - write the output to. - - - The xUnit.net GUI runner does not support this field. The MSBuild - runner only supports output of type 'xml', 'html', and 'nunit'. - - - - - Interface which represents a high level test runner. - - - - - Executes the tests in the assembly. - - Returns true if there were no failures; return false otherwise. - - - - Executes the tests in the assembly, and then executes the transforms with the - resulting assembly XML. - - The transforms to execute. - Returns true if there were no failures; return false otherwise. - - - - Runs the class. - - The type. - - - - - Runs a single test in a test class. - - The full name of the class. - The name of the method. - - - - Runs the list of tests in a test class. - - The full name of the class. - The names of the methods to run. - - - - Represents a single test assembly with test classes. - - - - - Initializes a new instance of the class. - - The executor wrapper. - The test classes. - - - - - - - Enumerates the test classes in the assembly. - - - - - - - - - - - - - - Gets the assembly filename. - - - - - Gets the config filename. - - - - - Gets the executor wrapper. - - - - - Gets the version of xunit.dll that the tests are linked against. - - - - - Represents a single class with test methods. - - - - - Initializes a new instance of the class. - - The namespace-qualified type name that - this class represents. - The test methods inside this test class. - - - - - - - - - - Gets the test runner used to run tests. Exists as an overload primarily - for the purposes of unit testing. - - The run status information callback. - - - - - - - Gets the test assembly that this class belongs to. - - - - - Gets the namespace-qualified type name of this class. - - - - - Represents a single test method. - - - - - Initializes a new instance of the class. - - The method name. - The method's display name. - The method's traits. - - - - Gets the method's display name. - - - - - Gets the method's name. - - - - - Gets the run results for the last run. - - - - - Gets the composite run status for all the results of the last run. - - - - - Gets the test class this test method belongs to. - - - - - Gets the method's traits. - - - - - The result of a test run via . - - - - - All tests passed, with no class-level failures - - - - - At least one test failed, or there was a class-level failure - - - - - There were no tests to run - - - - - Represents a transformation of the resulting assembly XML into some output format. - - - - - Transforms the given assembly XML into the destination format. - - The assembly XML. - - - - Gets the output filename, if known; returns null if the output isn't done to file. - - - - - Gets the type of the output. - - - - - Runs tests in an assembly, and transforms the XML results into calls to - the provided . - - - - - Initializes a new instance of the class. - - The executor wrapper. - The logger. - - - - - - - - - - - - - - - - - - - An implementation of which writes the - XML to a file without any transformation applied. - - - - - Initializes a new instance of the class. - - The output filename. - - - - - - - - - - - - - An implementation of which writes the - XML to a file after applying the XSL stylesheet in the given stream. - - - - - Initializes a new instance of the class. - - The stream with the XSL stylesheet. - The output filename. - The output type. - - - - - - - - - - - - - A dictionary which contains multiple unique values for each key. - - The type of the key. - The type of the value. - - - - Adds the value for the given key. If the key does not exist in the - dictionary yet, it will add it. - - The key. - The value. - - - - Removes all keys and values from the dictionary. - - - - - Determines whether the dictionary contains to specified key and value. - - The key. - The value. - - - - Calls the delegate once for each key/value pair in the dictionary. - - - - - Removes the given key and all of its values. - - - - - Removes the given value from the given key. If this was the - last value for the key, then the key is removed as well. - - The key. - The value. - - - - Gets the values for the given key. - - - - - Gets the count of the keys in the dictionary. - - - - - Gets the keys. - - - - - - - - Transforms stack frames and stack traces into compiler-like output - so they can be double-clicked in Visual Studio. - - - - - - - - - - - Responsible for building instances. Uses an instance - of to interrogate the list of available tests - and create the entire object model tree. - - - - - Creates a which is a complete object model over - the tests inside of instance of . - - The executor wrapper - The fully populated object model - - - - Parses the XML nodes from the version resilient runner facility and converts - them into calls against the provided . - - - - - Logs a result XML node. Maybe be any kind of XML node. - - The node to be logged. - The logger. - Returns true if the user wishes to continue running tests; returns false otherwise. - - - - Logs the assembly node by calling . - - The assembly node. - The logger. - - - - Logs the class node by calling (if the class failed). - The exception type was added in xUnit.net 1.1, so when the test assembly is linked against - xUnit.net versions prior to 1.1, the exception type will be null. - - The class node. - The logger. - Returns true if the user wishes to continue running tests; returns false otherwise. - - - - Logs the start node by calling . The start node was added - in xUnit.net 1.1, so it will only be present when the test assembly is linked against xunit.dll - version 1.1 or later. - - The start node. - The logger. - Returns true if the user wishes to continue running tests; returns false otherwise. - - - - Logs the test node by calling . It will also call - , , or - as appropriate. - - The test node. - The logger. - Returns true if the user wishes to continue running tests; returns false otherwise. - - - + + + + xunit.runner.utility + + + + + Guard class, used for guard clauses and argument validation + + + + + + + + + + + + + + Wraps calls to the Executor. Used by runners to perform version-resilient test + enumeration and execution. + + + + + Wraps calls to the Executor. Used by runners to perform version-resilient test + enumeration and execution. + + + + + Enumerates the tests in an assembly. + + The fully-formed assembly node of the XML + + + + Gets a count of the tests in the assembly. + + Returns the number of tests, if known; returns -1 if not known. May not represent + an exact count, but should be a best effort guess by the framework. + + + + Runs all the tests in an assembly. + + The callback which is called as each test/class/assembly is + finished, providing XML nodes that are part of the xUnit.net XML output format. + Test runs can be cancelled by returning false to the callback. If null, there are + no status callbacks (and cancellation isn't possible). + Returns the fully-formed assembly node for the assembly that was just run. + + + + Runs all the tests in the given class. + + The type. + The callback which is called as each test/class is + finished, providing XML nodes that are part of the xUnit.net XML output format. + Test runs can be cancelled by returning false to the callback. If null, there are + no status callbacks (and cancellation isn't possible). + Returns the fully-formed class node for the class that was just run. + + + + Runs a single test in a class. + + The type to run. + The method to run. + The callback which is called as each test/class is + finished, providing XML nodes that are part of the xUnit.net XML output format. + Test runs can be cancelled by returning false to the callback. If null, there are + no status callbacks (and cancellation isn't possible). + Returns the fully-formed class node for the class of the test that was just run. + + + + Runs several tests in a single class. + + The type. + The methods to run. + The callback which is called as each test/class is + finished, providing XML nodes that are part of the xUnit.net XML output format. + Test runs can be cancelled by returning false to the callback. If null, there are + no status callbacks (and cancellation isn't possible). + Returns the fully-formed class node for the class of the tests that were just run. + + + + Gets the full pathname to the assembly under test. + + + + + Gets the full pathname to the configuration file. + + + + + Gets the version of xunit.dll used by the test assembly. + + + + + Initializes a new instance of the class. + + The assembly filename. + The config filename. If null, the default config filename will be used. + Set to true to enable shadow copying; false, otherwise. + + + + Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + The callback object which receives real-time status notifications from the + test runner. + + + + + Called when the assembly has finished running. + + The test assembly. + The total number of tests run. + The number of failed tests. + The number of skipped tests. + The time taken to run, in seconds. + + + + Called when the assembly has started running. + + The test assembly. + + + + Called when a class failure is encountered (i.e., when a fixture from + IUseFixture throws an exception during construction or . + + The test class. + The full type name of the exception. + The exception message. + The exception stack trace. + + + + + Called when an exception is thrown (i.e., a catastrophic failure of the testing system). + + The test assembly. + The exception that was thrown. + + + + Called when a test has finished running, regardless of what the result was. + + The test method. + Return true to continue running tests; return false to stop the test run. + + + + Called when a test has started running. + + The test method. + Return true to continue running tests; return false to stop the test run. + + + + Represents the ability to run one or more test methods. + + + + + Runs the specified test methods. + + The test methods to run. + The run status information callback. + + + + Represents the ability to load and unload test assemblies, as well as enumerate + the test assemblies, the test methods, and run tests. + + + + + Represents the ability to enumerate and filter test methods. + + + + + Enumerates all test methods. + + + + + Enumerates test methods which pass the given filter. + + The test method filter. + + + + The test assemblies loaded into the environment. + + + + + Enumerates the test assemblies in the environment. + + + + + + + + + + + Enumerates the traits across all the loaded assemblies. + + + + + Loads the specified assembly, using the default configuration file. + + The assembly filename. + The which represents the newly + loaded test assembly. + + + + Loads the specified assembly using the specified configuration file. + + The assembly filename. + The config filename. + The which represents the newly + loaded test assembly. + + + + Loads the specified assembly using the specified configuration file. + + The assembly filename. + The config filename. + Whether the DLLs should be shadow copied. + The which represents the newly + loaded test assembly. + + + + Adds the assembly loaded into the given + into the environment. + + The executor wrapper. + The which represents the newly + loaded test assembly. + + + + + + + Unloads the specified assembly. + + The assembly to unload. + + + + Represents a failed test run in the object model. + + + + + Base class for all test results in the object model. + + + + + Initializes a new instance of the class. + + The duration the test took to run. For skipped tests, should be 0.0. + The display name of the test result. + + + + Gets the display name of the test result. + + + + + Gets the duration the test took to run. + + + + + Initializes a new instance of the class. + + The duration the test took to run. + The display name of the test result. + The output that was captured during the test run. + Type of the exception. + The exception message. + The exception stack trace. + + + + Gets the output that was captured during the test run. + + + + + Gets the type of the exception. + + + + + Gets the exception message. + + + + + Gets the exception stack trace. + + + + + Represents a skipped test run in the object model. + + + + + Initializes a new instance of the class. + + The display name of the test result. + The skip reason. + + + + Gets the skip reason. + + + + + Acts as an and adapts the callback messages + into calls to an instance of . + + + + + Represents a logger used by and . + + + + + Called when the assembly has finished running. + + The assembly filename. + The total number of tests run. + The number of failed tests. + The number of skipped tests. + The time taken to run, in seconds. + + + + Called when the assembly has started running. + + The assembly filename. + The configuration filename, if given; null, otherwise. + The version of xunit.dll. + + + + Called when a class failure is encountered (i.e., when a fixture from + IUseFixture throws an exception during construction or . + + The full type name of the class. + The full type name of the exception. + The exception message. + The exception stack trace. + + + + + Called when an exception is thrown (i.e., a catastrophic failure of the testing system). + + The assembly filename. + The exception that was thrown. + + + + Called when a test fails. + + The description name of the test. + The full type name of the test class. + The name of the method. + The time spent running the test, in seconds. + The output of the test during its run. + The full type name of the exception. + The exception message. + The exception stack trace. + + + + Called when a test has finished running, regardless of what the result was. + + The description name of the test. + The full type name of the test class. + The name of the method. + Return true to continue running tests; return false to stop the test run. + + + + Called when a test has passed. + + The description name of the test. + The full type name of the test class. + The name of the method. + The time spent running the test, in seconds. + The output of the test during its run. + + + + Called when a test was finished. + + The description name of the test. + The full type name of the test class. + The name of the method. + The skip reason. + + + + Called when a test has started running. + + The description name of the test. + The full type name of the test class. + The name of the method. + Return true to continue running tests; return false to stop the test run. + + + + Initializes a new instance of the class. + + The test class. + The run status information callback. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Represents a passed test run in the object model. + + + + + Initializes a new instance of the class. + + The duration the test took to run. + The display name of the test result. + The output that was captured during the test run. + + + + Gets the output that was captured during the test run. + + + + + Indicates the composite test method status + + + + + The method has not been run + + + + + All test results for the last run passed + + + + + At least one test result for the last run failed + + + + + At least one test result for the last run was skipped, and none failed + + + + + Represents an xUnit Test Project file (.xunit file) + + + + + Initializes a new instance of the class. + + + + + Loads an xUnit.net Test Project file from disk. + + The test project filename + + + + Saves the xUnit.net Test Project file to disk. + + The test project filename + + + + Gets or sets the assemblies in the project. + + + + + Represents an assembly in an . + + + + + Initializes a new instance of the class. + + + + + Gets or sets the assembly filename. + + + + + Gets or sets the config filename. + + + + + Gets or sets a value indicating whether to shadow copy the assembly + when running the tests. + + + The xUnit.net GUI runner does not support this field. + + + + + Gets or sets the output filenames. The dictionary key is the type + of the file to be output; the dictionary value is the filename to + write the output to. + + + The xUnit.net GUI runner does not support this field. The MSBuild + runner only supports output of type 'xml', 'html', and 'nunit'. + + + + + Interface which represents a high level test runner. + + + + + Executes the tests in the assembly. + + Returns true if there were no failures; return false otherwise. + + + + Executes the tests in the assembly, and then executes the transforms with the + resulting assembly XML. + + The transforms to execute. + Returns true if there were no failures; return false otherwise. + + + + Runs the class. + + The type. + + + + + Runs a single test in a test class. + + The full name of the class. + The name of the method. + + + + Runs the list of tests in a test class. + + The full name of the class. + The names of the methods to run. + + + + Represents a single test assembly with test classes. + + + + + Initializes a new instance of the class. + + The executor wrapper. + The test classes. + + + + + + + Enumerates the test classes in the assembly. + + + + + + + + + + + + + + Gets the assembly filename. + + + + + Gets the config filename. + + + + + Gets the executor wrapper. + + + + + Gets the version of xunit.dll that the tests are linked against. + + + + + Represents a single class with test methods. + + + + + Initializes a new instance of the class. + + The namespace-qualified type name that + this class represents. + The test methods inside this test class. + + + + + + + + + + Gets the test runner used to run tests. Exists as an overload primarily + for the purposes of unit testing. + + The run status information callback. + + + + + + + Gets the test assembly that this class belongs to. + + + + + Gets the namespace-qualified type name of this class. + + + + + Represents a single test method. + + + + + Initializes a new instance of the class. + + The method name. + The method's display name. + The method's traits. + + + + Gets the method's display name. + + + + + Gets the method's name. + + + + + Gets the run results for the last run. + + + + + Gets the composite run status for all the results of the last run. + + + + + Gets the test class this test method belongs to. + + + + + Gets the method's traits. + + + + + The result of a test run via . + + + + + All tests passed, with no class-level failures + + + + + At least one test failed, or there was a class-level failure + + + + + There were no tests to run + + + + + Represents a transformation of the resulting assembly XML into some output format. + + + + + Transforms the given assembly XML into the destination format. + + The assembly XML. + + + + Gets the output filename, if known; returns null if the output isn't done to file. + + + + + Gets the type of the output. + + + + + Runs tests in an assembly, and transforms the XML results into calls to + the provided . + + + + + Initializes a new instance of the class. + + The executor wrapper. + The logger. + + + + + + + + + + + + + + + + + + + An implementation of which writes the + XML to a file without any transformation applied. + + + + + Initializes a new instance of the class. + + The output filename. + + + + + + + + + + + + + An implementation of which writes the + XML to a file after applying the XSL stylesheet in the given stream. + + + + + Initializes a new instance of the class. + + The stream with the XSL stylesheet. + The output filename. + The output type. + + + + + + + + + + + + + A dictionary which contains multiple unique values for each key. + + The type of the key. + The type of the value. + + + + Adds the value for the given key. If the key does not exist in the + dictionary yet, it will add it. + + The key. + The value. + + + + Removes all keys and values from the dictionary. + + + + + Determines whether the dictionary contains to specified key and value. + + The key. + The value. + + + + Calls the delegate once for each key/value pair in the dictionary. + + + + + Removes the given key and all of its values. + + + + + Removes the given value from the given key. If this was the + last value for the key, then the key is removed as well. + + The key. + The value. + + + + Gets the values for the given key. + + + + + Gets the count of the keys in the dictionary. + + + + + Gets the keys. + + + + + + + + Transforms stack frames and stack traces into compiler-like output + so they can be double-clicked in Visual Studio. + + + + + + + + + + + Responsible for building instances. Uses an instance + of to interrogate the list of available tests + and create the entire object model tree. + + + + + Creates a which is a complete object model over + the tests inside of instance of . + + The executor wrapper + The fully populated object model + + + + Parses the XML nodes from the version resilient runner facility and converts + them into calls against the provided . + + + + + Logs a result XML node. Maybe be any kind of XML node. + + The node to be logged. + The logger. + Returns true if the user wishes to continue running tests; returns false otherwise. + + + + Logs the assembly node by calling . + + The assembly node. + The logger. + + + + Logs the class node by calling (if the class failed). + The exception type was added in xUnit.net 1.1, so when the test assembly is linked against + xUnit.net versions prior to 1.1, the exception type will be null. + + The class node. + The logger. + Returns true if the user wishes to continue running tests; returns false otherwise. + + + + Logs the start node by calling . The start node was added + in xUnit.net 1.1, so it will only be present when the test assembly is linked against xunit.dll + version 1.1 or later. + + The start node. + The logger. + Returns true if the user wishes to continue running tests; returns false otherwise. + + + + Logs the test node by calling . It will also call + , , or + as appropriate. + + The test node. + The logger. + Returns true if the user wishes to continue running tests; returns false otherwise. + + + diff --git a/Lib/xUnit/xunit.xml b/Lib/xUnit/xunit.xml index 50312f463..9a895c862 100644 --- a/Lib/xUnit/xunit.xml +++ b/Lib/xUnit/xunit.xml @@ -1,2306 +1,2306 @@ - - - - xunit - - - - - Contains various static methods that are used to verify that conditions are met during the - process of running tests. - - - - - Initializes a new instance of the class. - - - - - Verifies that a collection contains a given object. - - The type of the object to be verified - The object expected to be in the collection - The collection to be inspected - Thrown when the object is not present in the collection - - - - Verifies that a collection contains a given object, using a comparer. - - The type of the object to be verified - The object expected to be in the collection - The collection to be inspected - The comparer used to equate objects in the collection with the expected object - Thrown when the object is not present in the collection - - - - Verifies that a string contains a given sub-string, using the current culture. - - The sub-string expected to be in the string - The string to be inspected - Thrown when the sub-string is not present inside the string - - - - Verifies that a string contains a given sub-string, using the given comparison type. - - The sub-string expected to be in the string - The string to be inspected - The type of string comparison to perform - Thrown when the sub-string is not present inside the string - - - - Verifies that a collection does not contain a given object. - - The type of the object to be compared - The object that is expected not to be in the collection - The collection to be inspected - Thrown when the object is present inside the container - - - - Verifies that a collection does not contain a given object, using a comparer. - - The type of the object to be compared - The object that is expected not to be in the collection - The collection to be inspected - The comparer used to equate objects in the collection with the expected object - Thrown when the object is present inside the container - - - - Verifies that a string does not contain a given sub-string, using the current culture. - - The sub-string which is expected not to be in the string - The string to be inspected - Thrown when the sub-string is present inside the string - - - - Verifies that a string does not contain a given sub-string, using the current culture. - - The sub-string which is expected not to be in the string - The string to be inspected - The type of string comparison to perform - Thrown when the sub-string is present inside the given string - - - - Verifies that a block of code does not throw any exceptions. - - A delegate to the code to be tested - - - - Verifies that a collection is empty. - - The collection to be inspected - Thrown when the collection is null - Thrown when the collection is not empty - - - - Verifies that two objects are equal, using a default comparer. - - The type of the objects to be compared - The expected value - The value to be compared against - Thrown when the objects are not equal - - - - Verifies that two objects are equal, using a custom comparer. - - The type of the objects to be compared - The expected value - The value to be compared against - The comparer used to compare the two objects - Thrown when the objects are not equal - - - Do not call this method. - - - - Verifies that the condition is false. - - The condition to be tested - Thrown if the condition is not false - - - - Verifies that the condition is false. - - The condition to be tested - The message to show when the condition is not false - Thrown if the condition is not false - - - - Verifies that a value is within a given range. - - The type of the value to be compared - The actual value to be evaluated - The (inclusive) low value of the range - The (inclusive) high value of the range - Thrown when the value is not in the given range - - - - Verifies that a value is within a given range, using a comparer. - - The type of the value to be compared - The actual value to be evaluated - The (inclusive) low value of the range - The (inclusive) high value of the range - The comparer used to evaluate the value's range - Thrown when the value is not in the given range - - - - Verifies that an object is of the given type or a derived type. - - The type the object should be - The object to be evaluated - The object, casted to type T when successful - Thrown when the object is not the given type - - - - Verifies that an object is of the given type or a derived type. - - The type the object should be - The object to be evaluated - Thrown when the object is not the given type - - - - Verifies that an object is not exactly the given type. - - The type the object should not be - The object to be evaluated - Thrown when the object is the given type - - - - Verifies that an object is not exactly the given type. - - The type the object should not be - The object to be evaluated - Thrown when the object is the given type - - - - Verifies that an object is exactly the given type (and not a derived type). - - The type the object should be - The object to be evaluated - The object, casted to type T when successful - Thrown when the object is not the given type - - - - Verifies that an object is exactly the given type (and not a derived type). - - The type the object should be - The object to be evaluated - Thrown when the object is not the given type - - - - Verifies that a collection is not empty. - - The collection to be inspected - Thrown when a null collection is passed - Thrown when the collection is empty - - - - Verifies that two objects are not equal, using a default comparer. - - The type of the objects to be compared - The expected object - The actual object - Thrown when the objects are equal - - - - Verifies that two objects are not equal, using a custom comparer. - - The type of the objects to be compared - The expected object - The actual object - The comparer used to examine the objects - Thrown when the objects are equal - - - - Verifies that a value is not within a given range, using the default comparer. - - The type of the value to be compared - The actual value to be evaluated - The (inclusive) low value of the range - The (inclusive) high value of the range - Thrown when the value is in the given range - - - - Verifies that a value is not within a given range, using a comparer. - - The type of the value to be compared - The actual value to be evaluated - The (inclusive) low value of the range - The (inclusive) high value of the range - The comparer used to evaluate the value's range - Thrown when the value is in the given range - - - - Verifies that an object reference is not null. - - The object to be validated - Thrown when the object is not null - - - - Verifies that two objects are not the same instance. - - The expected object instance - The actual object instance - Thrown when the objects are the same instance - - - - Verifies that an object reference is null. - - The object to be inspected - Thrown when the object reference is not null - - - - Verifies that two objects are the same instance. - - The expected object instance - The actual object instance - Thrown when the objects are not the same instance - - - - Verifies that the exact exception is thrown (and not a derived exception type). - - The type of the exception expected to be thrown - A delegate to the code to be tested - The exception that was thrown, when successful - Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown - - - - Verifies that the exact exception is thrown (and not a derived exception type). - - The type of the exception expected to be thrown - The message to be shown if the test fails - A delegate to the code to be tested - The exception that was thrown, when successful - Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown - - - - Verifies that the exact exception is thrown (and not a derived exception type). - Generally used to test property accessors. - - The type of the exception expected to be thrown - A delegate to the code to be tested - The exception that was thrown, when successful - Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown - - - - Verifies that the exact exception is thrown (and not a derived exception type). - Generally used to test property accessors. - - The type of the exception expected to be thrown - The message to be shown if the test fails - A delegate to the code to be tested - The exception that was thrown, when successful - Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown - - - - Verifies that the exact exception is thrown (and not a derived exception type). - - The type of the exception expected to be thrown - A delegate to the code to be tested - The exception that was thrown, when successful - Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown - - - - Verifies that the exact exception is thrown (and not a derived exception type). - Generally used to test property accessors. - - The type of the exception expected to be thrown - A delegate to the code to be tested - The exception that was thrown, when successful - Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown - - - - Verifies that an expression is true. - - The condition to be inspected - Thrown when the condition is false - - - - Verifies that an expression is true. - - The condition to be inspected - The message to be shown when the condition is false - Thrown when the condition is false - - - - Used by the Throws and DoesNotThrow methods. - - - - - Used by the Throws and DoesNotThrow methods. - - - - - Captures standard output and standard error, and inserts the values into the - as it traverses the chain. - - - - - Base class used by commands which delegate to inner commands. - - - - - Interface which represents the ability to invoke of a test method. - - - - - Executes the test method. - - The instance of the test class - Returns information about the test run - - - - Creates the start XML to be sent to the callback when the test is about to start - running. - - Return the of the start node, or null if the test - is known that it will not be running. - - - - Gets the display name of the test method. - - - - - Determines if the test runner infrastructure should create a new instance of the - test class before running the test. - - - - - Creates a new instance of the class. - - The inner command to delegate to. - - - - - - - - - - - - - - - - - - - Initializes a new instance of the class. - - The inner command - - - - - - - Base class for exceptions that have actual and expected values - - - - - The base assert exception class - - - - - Initializes a new instance of the class. - - - - - Initializes a new instance of the class. - - The user message to be displayed - - - - Initializes a new instance of the class. - - The user message to be displayed - The inner exception - - - - Initializes a new instance of the class. - - The user message to be displayed - The stack trace to be displayed - - - - Filters the stack trace to remove all lines that occur within the testing framework. - - The original stack trace - The filtered stack trace - - - - Gets a string representation of the frames on the call stack at the time the current exception was thrown. - - A string that describes the contents of the call stack, with the most recent method call appearing first. - - - - Gets the user message - - - - - Creates a new instance of the class. - - The expected value - The actual value - The user message to be shown - - - - Creates a new instance of the class. - - The expected value - The actual value - The user message to be shown - Set to true to skip the check for difference position - - - - Gets the actual value. - - - - - Gets the expected value. - - - - - Gets a message that describes the current exception. Includes the expected and actual values. - - The error message that explains the reason for the exception, or an empty string(""). - 1 - - - - Exception thrown when a collection unexpectedly does not contain the expected value. - - - - - Creates a new instance of the class. - - The expected object value - - - - Exception to be thrown from when the number of - parameter values does not the test method signature. - - - - - - - - - - - Internal class used for version-resilient test runners. DO NOT CALL DIRECTLY. - Version-resilient runners should link against xunit.runner.utility.dll and use - ExecutorWrapper instead. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Exception thrown when the value is unexpectedly not of the given type or a derived type. - - - - - Creates a new instance of the class. - - The expected type - The actual object value - - - - Allows the user to record actions for a test. - - - - - Records any exception which is thrown by the given code. - - The code which may thrown an exception. - Returns the exception that was thrown by the code; null, otherwise. - - - - Records any exception which is thrown by the given code that has - a return value. Generally used for testing property accessors. - - The code which may thrown an exception. - Returns the exception that was thrown by the code; null, otherwise. - - - - Exception that is thrown when one or more exceptions are thrown from - the After method of a . - - - - - Initializes a new instance of the class. - - The exceptions. - - - - Initializes a new instance of the class. - - The exceptions. - - - - Gets the list of exceptions thrown in the After method. - - - - - Gets a message that describes the current exception. - - - - - Gets a string representation of the frames on the call stack at the time the current exception was thrown. - - - - - Implementation of which executes the - instances attached to a test method. - - - - - Initializes a new instance of the class. - - The inner command. - The method. - - - - Executes the test method. - - The instance of the test class - Returns information about the test run - - - - Wraps any exceptions thrown by the command execution. - - - - - Initializes a new instance of the class. - - The inner command. - The method. - - - - Executes the test method. - - The instance of the test class - Returns information about the test run - - - - Guard class, used for guard clauses and argument validation - - - - - - - - - - - - - - Base class which contains XML manipulation helper methods - - - - - Interface that represents a single test result. - - - - - Converts the test result into XML that is consumed by the test runners. - - The parent node. - The newly created XML node. - - - - The amount of time spent in execution - - - - - Adds the test execution time to the XML node. - - The XML node. - - - - - - - - - - Utility methods for dealing with exceptions. - - - - - Gets the message for the exception, including any inner exception messages. - - The exception - The formatted message - - - - Gets the stack trace for the exception, including any inner exceptions. - - The exception - The formatted stack trace - - - - Rethrows an exception object without losing the existing stack trace information - - The exception to re-throw. - - For more information on this technique, see - http://www.dotnetjunkies.com/WebLog/chris.taylor/archive/2004/03/03/8353.aspx - - - - - A dictionary which contains multiple unique values for each key. - - The type of the key. - The type of the value. - - - - Adds the value for the given key. If the key does not exist in the - dictionary yet, it will add it. - - The key. - The value. - - - - Removes all keys and values from the dictionary. - - - - - Determines whether the dictionary contains to specified key and value. - - The key. - The value. - - - - Calls the delegate once for each key/value pair in the dictionary. - - - - - Removes the given key and all of its values. - - - - - Removes the given value from the given key. If this was the - last value for the key, then the key is removed as well. - - The key. - The value. - - - - Gets the values for the given key. - - - - - Gets the count of the keys in the dictionary. - - - - - Gets the keys. - - - - - - - - XML utility methods - - - - - Adds an attribute to an XML node. - - The XML node. - The attribute name. - The attribute value. - - - - Adds a child element to an XML node. - - The parent XML node. - The child element name. - The new child XML element. - - - - Exception that is thrown when a call to Debug.Assert() fails. - - - - - Creates a new instance of the class. - - The original assert message - - - - Creates a new instance of the class. - - The original assert message - The original assert detailed message - - - - Gets the original assert detailed message. - - - - - Gets the original assert message. - - - - - Gets a message that describes the current exception. - - - - - Exception thrown when a collection unexpectedly contains the expected value. - - - - - Creates a new instance of the class. - - The expected object value - - - - Exception thrown when code unexpectedly throws an exception. - - - - - Creates a new instance of the class. - - Actual exception - - - - Gets a string representation of the frames on the call stack at the time the current exception was thrown. - - A string that describes the contents of the call stack, with the most recent method call appearing first. - - - - Exception thrown when a collection is unexpectedly not empty. - - - - - Creates a new instance of the class. - - - - - Exception thrown when two values are unexpectedly not equal. - - - - - Creates a new instance of the class. - - The expected object value - The actual object value - - - - Exception thrown when a value is unexpectedly true. - - - - - Creates a new instance of the class. - - The user message to be display, or null for the default message - - - - Exception thrown when a value is unexpectedly not in the given range. - - - - - Creates a new instance of the class. - - The actual object value - The low value of the range - The high value of the range - - - - Gets the actual object value - - - - - Gets the high value of the range - - - - - Gets the low value of the range - - - - - Gets a message that describes the current exception. - - The error message that explains the reason for the exception, or an empty string(""). - - - - Exception thrown when the value is unexpectedly of the exact given type. - - - - - Creates a new instance of the class. - - The expected type - The actual object value - - - - Exception thrown when the value is unexpectedly not of the exact given type. - - - - - Creates a new instance of the class. - - The expected type - The actual object value - - - - Used to decorate xUnit.net test classes that utilize fixture classes. - An instance of the fixture data is initialized just before the first - test in the class is run, and if it implements IDisposable, is disposed - after the last test in the class is run. - - The type of the fixture - - - - Called on the test class just before each test method is run, - passing the fixture data so that it can be used for the test. - All test runs share the same instance of fixture data. - - The fixture data - - - - Exception thrown when a value is unexpectedly in the given range. - - - - - Creates a new instance of the class. - - The actual object value - The low value of the range - The high value of the range - - - - Gets the actual object value - - - - - Gets the high value of the range - - - - - Gets the low value of the range - - - - - Gets a message that describes the current exception. - - The error message that explains the reason for the exception, or an empty string(""). - - - - Base attribute which indicates a test method interception (allows code to be run before and - after the test is run). - - - - - This method is called after the test method is executed. - - The method under test - - - - This method is called before the test method is executed. - - The method under test - - - - Exception thrown when a collection is unexpectedly empty. - - - - - Creates a new instance of the class. - - - - - Exception thrown when two values are unexpectedly equal. - - - - - Creates a new instance of the class. - - - - - Exception thrown when an object is unexpectedly null. - - - - - Creates a new instance of the class. - - - - - Exception thrown when two values are unexpected the same instance. - - - - - Creates a new instance of the class. - - - - - Exception thrown when an object reference is unexpectedly not null. - - - - - Creates a new instance of the class. - - - - - - Command that automatically creates the instance of the test class - and disposes it (if it implements ). - - - - - Creates a new instance of the object. - - The command that is bring wrapped - The method under test - - - - Executes the test method. Creates a new instance of the class - under tests and passes it to the inner command. Also catches - any exceptions and converts them into s. - - The instance of the test class - Returns information about the test run - - - - A command wrapper which catches Trace.Assert and Debug.Assert failures and turns - them into assertion exceptions. - - - - - Creates a new instance of the class. - - The command that will be wrapped. - - - - Executes the test method. - - The instance of the test class - Returns information about the test run - - - - Command used to wrap a which has associated - fixture data. - - - - - Creates a new instance of the class. - - The inner command - The fixtures to be set on the test class - - - - Sets the fixtures on the test class by calling SetFixture, then - calls the inner command. - - The instance of the test class - Returns information about the test run - - - - A timer class used to figure out how long tests take to run. On most .NET implementations - this will use the class because it's a high - resolution timer; however, on Silverlight/CoreCLR, it will use - (which will provide lower resolution results). - - - - - Creates a new instance of the class. - - - - - Starts timing. - - - - - Stops timing. - - - - - Gets how long the timer ran, in milliseconds. In order for this to be valid, - both and must have been called. - - - - - Attribute used to decorate a test method with arbitrary name/value pairs ("traits"). - - - - - Creates a new instance of the class. - - The trait name - The trait value - - - - Gets the trait name. - - - - - Gets the trait value. - - - - - Runner that executes an synchronously. - - - - - Execute the . - - The test class command to execute - The methods to execute; if null or empty, all methods will be executed - The start run callback - The end run result callback - A with the results of the test run - - - - Factory for objects, based on the type under test. - - - - - Creates the test class command, which implements , for a given type. - - The type under test - The test class command, if the class is a test class; null, otherwise - - - - Creates the test class command, which implements , for a given type. - - The type under test - The test class command, if the class is a test class; null, otherwise - - - - Represents an xUnit.net test class - - - - - Interface which describes the ability to executes all the tests in a test class. - - - - - Allows the test class command to choose the next test to be run from the list of - tests that have not yet been run, thereby allowing it to choose the run order. - - The tests remaining to be run - The index of the test that should be run - - - - Execute actions to be run after all the test methods of this test class are run. - - Returns the thrown during execution, if any; null, otherwise - - - - Execute actions to be run before any of the test methods of this test class are run. - - Returns the thrown during execution, if any; null, otherwise - - - - Enumerates the test commands for a given test method in this test class. - - The method under test - The test commands for the given test method - - - - Enumerates the methods which are test methods in this test class. - - The test methods - - - - Determines if a given refers to a test method. - - The test method to validate - True if the method is a test method; false, otherwise - - - - Gets the object instance that is under test. May return null if you wish - the test framework to create a new object instance for each test method. - - - - - Gets or sets the type that is being tested - - - - - Creates a new instance of the class. - - - - - Creates a new instance of the class. - - The type under test - - - - Creates a new instance of the class. - - The type under test - - - - Chooses the next test to run, randomly, using the . - - The tests remaining to be run - The index of the test that should be run - - - - Execute actions to be run after all the test methods of this test class are run. - - Returns the thrown during execution, if any; null, otherwise - - - - Execute actions to be run before any of the test methods of this test class are run. - - Returns the thrown during execution, if any; null, otherwise - - - - Enumerates the test commands for a given test method in this test class. - - The method under test - The test commands for the given test method - - - - Enumerates the methods which are test methods in this test class. - - The test methods - - - - Determines if a given refers to a test method. - - The test method to validate - True if the method is a test method; false, otherwise - - - - Gets the object instance that is under test. May return null if you wish - the test framework to create a new object instance for each test method. - - - - - Gets or sets the randomizer used to determine the order in which tests are run. - - - - - Sets the type that is being tested - - - - - Implementation of that represents a skipped test. - - - - - Represents an xUnit.net test command. - - - - - The method under test. - - - - - Initializes a new instance of the class. - - The method under test. - - - - Initializes a new instance of the class. - - The method under test. - The display name of the test. - - - - - - - - - - - - - Gets the name of the method under test. - - - - - Gets the name of the type under test. - - - - - - - - Creates a new instance of the class. - - The method that is being skipped - The display name for the test. If null, the fully qualified - type name is used. - The reason the test was skipped. - - - - - - - - - - Gets the skip reason. - - - - - - - - Factory for creating objects. - - - - - Make instances of objects for the given class and method. - - The class command - The method under test - The set of objects - - - - A command wrapper which times the running of a command. - - - - - Creates a new instance of the class. - - The command that will be timed. - - - - Executes the inner test method, gathering the amount of time it takes to run. - - Returns information about the test run - - - - Wraps a command which should fail if it runs longer than the given timeout value. - - - - - Creates a new instance of the class. - - The command to be run - The timout, in milliseconds - The method under test - - - - Executes the test method, failing if it takes too long. - - Returns information about the test run - - - - Gets the timeout value, in milliseconds. - - - - - Attributes used to decorate a test fixture that is run with an alternate test runner. - The test runner must implement the interface. - - - - - Creates a new instance of the class. - - The class which implements ITestClassCommand and acts as the runner - for the test fixture. - - - - Gets the test class command. - - - - - Exception thrown when two object references are unexpectedly not the same instance. - - - - - Creates a new instance of the class. - - The expected object reference - The actual object reference - - - - Contains the test results from an assembly. - - - - - Contains multiple test results, representing them as a composite test result. - - - - - Adds a test result to the composite test result list. - - - - - - Gets the test results. - - - - - Creates a new instance of the class. - - The filename of the assembly - - - - Creates a new instance of the class. - - The filename of the assembly - The configuration filename - - - - Converts the test result into XML that is consumed by the test runners. - - The parent node. - The newly created XML node. - - - - Gets the fully qualified filename of the configuration file. - - - - - Gets the directory where the assembly resides. - - - - - Gets the number of failed results. - - - - - Gets the fully qualified filename of the assembly. - - - - - Gets the number of passed results. - - - - - Gets the number of skipped results. - - - - - Contains the test results from a test class. - - - - - Creates a new instance of the class. - - The type under test - - - - Creates a new instance of the class. - - The simple name of the type under test - The fully qualified name of the type under test - The namespace of the type under test - - - - Sets the exception thrown by the test fixture. - - The thrown exception - - - - Converts the test result into XML that is consumed by the test runners. - - The parent node. - The newly created XML node. - - - - Gets the fully qualified test fixture exception type, when an exception has occurred. - - - - - Gets the number of tests which failed. - - - - - Gets the fully qualified name of the type under test. - - - - - Gets the test fixture exception message, when an exception has occurred. - - - - - Gets the simple name of the type under test. - - - - - Gets the namespace of the type under test. - - - - - Gets the number of tests which passed. - - - - - Gets the number of tests which were skipped. - - - - - Gets the test fixture exception stack trace, when an exception has occurred. - - - - - Represents a failed test result. - - - - - Represents the results from running a test method - - - - - Initializes a new instance of the class. The traits for - the test method are discovered using reflection. - - The method under test. - The display name for the test. If null, the fully qualified - type name is used. - - - - Initializes a new instance of the class. - - The name of the method under test. - The type of the method under test. - The display name for the test. If null, the fully qualified - type name is used. - The traits. - - - - Converts the test result into XML that is consumed by the test runners. - - The parent node. - The newly created XML node. - - - - Gets or sets the display name of the method under test. This is the value that's shown - during failures and in the resulting output XML. - - - - - Gets the name of the method under test. - - - - - Gets or sets the standard output/standard error from the test that was captured - while the test was running. - - - - - Gets the traits attached to the test method. - - - - - Gets the name of the type under test. - - - - - Creates a new instance of the class. - - The method under test - The exception throw by the test - The display name for the test. If null, the fully qualified - type name is used. - - - - Creates a new instance of the class. - - The name of the method under test - The name of the type under test - The display name of the test - The custom properties attached to the test method - The full type name of the exception throw - The exception message - The exception stack trace - - - - Converts the test result into XML that is consumed by the test runners. - - The parent node. - The newly created XML node. - - - - Gets the exception type thrown by the test method. - - - - - Gets the exception message thrown by the test method. - - - - - Gets the stack trace of the exception thrown by the test method. - - - - - Represents a passing test result. - - - - - Create a new instance of the class. - - The method under test - The display name for the test. If null, the fully qualified - type name is used. - - - - Create a new instance of the class. - - The name of the method under test - The name of the type under test - The display name for the test. If null, the fully qualified - type name is used. - The custom properties attached to the test method - - - - Converts the test result into XML that is consumed by the test runners. - - The parent node. - The newly created XML node. - - - - Represents a skipped test result. - - - - - Creates a new instance of the class. Uses reflection to discover - the skip reason. - - The method under test - The display name for the test. If null, the fully qualified - type name is used. - The reason the test was skipped. - - - - Creates a new instance of the class. - - The name of the method under test - The name of the type under test - The display name for the test. If null, the fully qualified - type name is used. - The traits attached to the method under test - The skip reason - - - - Converts the test result into XML that is consumed by the test runners. - - The parent node. - The newly created XML node. - - - - Gets the skip reason. - - - - - Represents information about an attribute. - - - - - Gets the instance of the attribute, if available. - - The type of the attribute - The instance of the attribute, if available. - - - - Gets an initialized property value of the attribute. - - The type of the property - The name of the property - The property value - - - - Represents information about a method. - - - - - Creates an instance of the type where this test method was found. If using - reflection, this should be the ReflectedType. - - A new instance of the type. - - - - Gets all the custom attributes for the method that are of the given type. - - The type of the attribute - The matching attributes that decorate the method - - - - Determines if the method has at least one instance of the given attribute type. - - The type of the attribute - True if the method has at least one instance of the given attribute type; false, otherwise - - - - Invokes the test on the given class, with the given parameters. - - The instance of the test class (may be null if - the test method is static). - The parameters to be passed to the test method. - - - - Gets a value indicating whether the method is abstract. - - - - - Gets a value indicating whether the method is static. - - - - - Gets the underlying for the method, if available. - - - - - Gets the name of the method. - - - - - Gets the fully qualified type name of the return type. - - - - - Gets the fully qualified type name of the type that this method belongs to. If - using reflection, this should be the ReflectedType. - - - - - Represents information about a type. - - - - - Gets all the custom attributes for the type that are of the given attribute type. - - The type of the attribute - The matching attributes that decorate the type - - - - Gets a test method by name. - - The name of the method - The method, if it exists; null, otherwise. - - - - Gets all the methods - - - - - - Determines if the type has at least one instance of the given attribute type. - - The type of the attribute - True if the type has at least one instance of the given attribute type; false, otherwise - - - - Determines if the type implements the given interface. - - The type of the interface - True if the type implements the given interface; false, otherwise - - - - Gets a value indicating whether the type is abstract. - - - - - Gets a value indicating whether the type is sealed. - - - - - Gets the underlying object, if available. - - - - - Utility class which inspects methods for test information - - - - - Gets the skip reason from a test method. - - The method to be inspected - The skip reason - - - - Gets the test commands for a test method. - - The method to be inspected - The objects for the test method - - - - Gets the timeout value for a test method. - - The method to be inspected - The timeout, in milliseconds - - - - Gets the traits on a test method. - - The method to be inspected - A dictionary of the traits - - - - Determines whether a test method has a timeout. - - The method to be inspected - True if the method has a timeout; false, otherwise - - - - Determines whether a test method has traits. - - The method to be inspected - True if the method has traits; false, otherwise - - - - Determines whether a test method should be skipped. - - The method to be inspected - True if the method should be skipped; false, otherwise - - - - Determines whether a method is a test method. A test method must be decorated - with the (or derived class) and must not be abstract. - - The method to be inspected - True if the method is a test method; false, otherwise - - - - Wrapper to implement and using reflection. - - - - - Converts an into an using reflection. - - - - - - - Converts a into an using reflection. - - The method to wrap - The wrapper - - - - Converts a into an using reflection. - - The type to wrap - The wrapper - - - - Utility class which inspects types for test information - - - - - Determines if a type contains any test methods - - The type to be inspected - True if the class contains any test methods; false, otherwise - - - - Retrieves the type to run the test class with from the , if present. - - The type to be inspected - The type of the test class runner, if present; null, otherwise - - - - Retrieves a list of the test methods from the test class. - - The type to be inspected - The test methods - - - - Determines if the test class has a applied to it. - - The type to be inspected - True if the test class has a run with attribute; false, otherwise - - - - Determines if the type implements . - - The type to be inspected - True if the type implements ; false, otherwise - - - - Determines whether the specified type is abstract. - - The type. - - true if the specified type is abstract; otherwise, false. - - - - - Determines whether the specified type is static. - - The type. - - true if the specified type is static; otherwise, false. - - - - - Determines if a class is a test class. - - The type to be inspected - True if the type is a test class; false, otherwise - - - - Attribute that is applied to a method to indicate that it is a fact that should be run - by the test runner. It can also be extended to support a customized definition of a - test method. - - - - - Creates instances of which represent individual intended - invocations of the test method. - - The method under test - An enumerator through the desired test method invocations - - - - Enumerates the test commands represented by this test method. Derived classes should - override this method to return instances of , one per execution - of a test method. - - The test method - The test commands which will execute the test runs for the given method - - - - Gets the name of the test to be used when the test is skipped. Defaults to - null, which will cause the fully qualified test name to be used. - - - - - Obsolete. Please use the property instead. - - - - - Marks the test so that it will not be run, and gets or sets the skip reason - - - - - Marks the test as failing if it does not finish running within the given time - period, in milliseconds; set to 0 or less to indicate the method has no timeout - - - - - Exception thrown when code unexpectedly fails to throw an exception. - - - - - Creates a new instance of the class. Call this constructor - when no exception was thrown. - - The type of the exception that was expected - - - - Creates a new instance of the class. Call this constructor - when an exception of the wrong type was thrown. - - The type of the exception that was expected - The actual exception that was thrown - - - - Gets a string representation of the frames on the call stack at the time the current exception was thrown. - - A string that describes the contents of the call stack, with the most recent method call appearing first. - - - - Exception thrown when a test method exceeds the given timeout value - - - - - Creates a new instance of the class. - - The timeout value, in milliseconds - - - - Exception thrown when a value is unexpectedly false. - - - - - Creates a new instance of the class. - - The user message to be displayed, or null for the default message - - - + + + + xunit + + + + + Contains various static methods that are used to verify that conditions are met during the + process of running tests. + + + + + Initializes a new instance of the class. + + + + + Verifies that a collection contains a given object. + + The type of the object to be verified + The object expected to be in the collection + The collection to be inspected + Thrown when the object is not present in the collection + + + + Verifies that a collection contains a given object, using a comparer. + + The type of the object to be verified + The object expected to be in the collection + The collection to be inspected + The comparer used to equate objects in the collection with the expected object + Thrown when the object is not present in the collection + + + + Verifies that a string contains a given sub-string, using the current culture. + + The sub-string expected to be in the string + The string to be inspected + Thrown when the sub-string is not present inside the string + + + + Verifies that a string contains a given sub-string, using the given comparison type. + + The sub-string expected to be in the string + The string to be inspected + The type of string comparison to perform + Thrown when the sub-string is not present inside the string + + + + Verifies that a collection does not contain a given object. + + The type of the object to be compared + The object that is expected not to be in the collection + The collection to be inspected + Thrown when the object is present inside the container + + + + Verifies that a collection does not contain a given object, using a comparer. + + The type of the object to be compared + The object that is expected not to be in the collection + The collection to be inspected + The comparer used to equate objects in the collection with the expected object + Thrown when the object is present inside the container + + + + Verifies that a string does not contain a given sub-string, using the current culture. + + The sub-string which is expected not to be in the string + The string to be inspected + Thrown when the sub-string is present inside the string + + + + Verifies that a string does not contain a given sub-string, using the current culture. + + The sub-string which is expected not to be in the string + The string to be inspected + The type of string comparison to perform + Thrown when the sub-string is present inside the given string + + + + Verifies that a block of code does not throw any exceptions. + + A delegate to the code to be tested + + + + Verifies that a collection is empty. + + The collection to be inspected + Thrown when the collection is null + Thrown when the collection is not empty + + + + Verifies that two objects are equal, using a default comparer. + + The type of the objects to be compared + The expected value + The value to be compared against + Thrown when the objects are not equal + + + + Verifies that two objects are equal, using a custom comparer. + + The type of the objects to be compared + The expected value + The value to be compared against + The comparer used to compare the two objects + Thrown when the objects are not equal + + + Do not call this method. + + + + Verifies that the condition is false. + + The condition to be tested + Thrown if the condition is not false + + + + Verifies that the condition is false. + + The condition to be tested + The message to show when the condition is not false + Thrown if the condition is not false + + + + Verifies that a value is within a given range. + + The type of the value to be compared + The actual value to be evaluated + The (inclusive) low value of the range + The (inclusive) high value of the range + Thrown when the value is not in the given range + + + + Verifies that a value is within a given range, using a comparer. + + The type of the value to be compared + The actual value to be evaluated + The (inclusive) low value of the range + The (inclusive) high value of the range + The comparer used to evaluate the value's range + Thrown when the value is not in the given range + + + + Verifies that an object is of the given type or a derived type. + + The type the object should be + The object to be evaluated + The object, casted to type T when successful + Thrown when the object is not the given type + + + + Verifies that an object is of the given type or a derived type. + + The type the object should be + The object to be evaluated + Thrown when the object is not the given type + + + + Verifies that an object is not exactly the given type. + + The type the object should not be + The object to be evaluated + Thrown when the object is the given type + + + + Verifies that an object is not exactly the given type. + + The type the object should not be + The object to be evaluated + Thrown when the object is the given type + + + + Verifies that an object is exactly the given type (and not a derived type). + + The type the object should be + The object to be evaluated + The object, casted to type T when successful + Thrown when the object is not the given type + + + + Verifies that an object is exactly the given type (and not a derived type). + + The type the object should be + The object to be evaluated + Thrown when the object is not the given type + + + + Verifies that a collection is not empty. + + The collection to be inspected + Thrown when a null collection is passed + Thrown when the collection is empty + + + + Verifies that two objects are not equal, using a default comparer. + + The type of the objects to be compared + The expected object + The actual object + Thrown when the objects are equal + + + + Verifies that two objects are not equal, using a custom comparer. + + The type of the objects to be compared + The expected object + The actual object + The comparer used to examine the objects + Thrown when the objects are equal + + + + Verifies that a value is not within a given range, using the default comparer. + + The type of the value to be compared + The actual value to be evaluated + The (inclusive) low value of the range + The (inclusive) high value of the range + Thrown when the value is in the given range + + + + Verifies that a value is not within a given range, using a comparer. + + The type of the value to be compared + The actual value to be evaluated + The (inclusive) low value of the range + The (inclusive) high value of the range + The comparer used to evaluate the value's range + Thrown when the value is in the given range + + + + Verifies that an object reference is not null. + + The object to be validated + Thrown when the object is not null + + + + Verifies that two objects are not the same instance. + + The expected object instance + The actual object instance + Thrown when the objects are the same instance + + + + Verifies that an object reference is null. + + The object to be inspected + Thrown when the object reference is not null + + + + Verifies that two objects are the same instance. + + The expected object instance + The actual object instance + Thrown when the objects are not the same instance + + + + Verifies that the exact exception is thrown (and not a derived exception type). + + The type of the exception expected to be thrown + A delegate to the code to be tested + The exception that was thrown, when successful + Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown + + + + Verifies that the exact exception is thrown (and not a derived exception type). + + The type of the exception expected to be thrown + The message to be shown if the test fails + A delegate to the code to be tested + The exception that was thrown, when successful + Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown + + + + Verifies that the exact exception is thrown (and not a derived exception type). + Generally used to test property accessors. + + The type of the exception expected to be thrown + A delegate to the code to be tested + The exception that was thrown, when successful + Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown + + + + Verifies that the exact exception is thrown (and not a derived exception type). + Generally used to test property accessors. + + The type of the exception expected to be thrown + The message to be shown if the test fails + A delegate to the code to be tested + The exception that was thrown, when successful + Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown + + + + Verifies that the exact exception is thrown (and not a derived exception type). + + The type of the exception expected to be thrown + A delegate to the code to be tested + The exception that was thrown, when successful + Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown + + + + Verifies that the exact exception is thrown (and not a derived exception type). + Generally used to test property accessors. + + The type of the exception expected to be thrown + A delegate to the code to be tested + The exception that was thrown, when successful + Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown + + + + Verifies that an expression is true. + + The condition to be inspected + Thrown when the condition is false + + + + Verifies that an expression is true. + + The condition to be inspected + The message to be shown when the condition is false + Thrown when the condition is false + + + + Used by the Throws and DoesNotThrow methods. + + + + + Used by the Throws and DoesNotThrow methods. + + + + + Captures standard output and standard error, and inserts the values into the + as it traverses the chain. + + + + + Base class used by commands which delegate to inner commands. + + + + + Interface which represents the ability to invoke of a test method. + + + + + Executes the test method. + + The instance of the test class + Returns information about the test run + + + + Creates the start XML to be sent to the callback when the test is about to start + running. + + Return the of the start node, or null if the test + is known that it will not be running. + + + + Gets the display name of the test method. + + + + + Determines if the test runner infrastructure should create a new instance of the + test class before running the test. + + + + + Creates a new instance of the class. + + The inner command to delegate to. + + + + + + + + + + + + + + + + + + + Initializes a new instance of the class. + + The inner command + + + + + + + Base class for exceptions that have actual and expected values + + + + + The base assert exception class + + + + + Initializes a new instance of the class. + + + + + Initializes a new instance of the class. + + The user message to be displayed + + + + Initializes a new instance of the class. + + The user message to be displayed + The inner exception + + + + Initializes a new instance of the class. + + The user message to be displayed + The stack trace to be displayed + + + + Filters the stack trace to remove all lines that occur within the testing framework. + + The original stack trace + The filtered stack trace + + + + Gets a string representation of the frames on the call stack at the time the current exception was thrown. + + A string that describes the contents of the call stack, with the most recent method call appearing first. + + + + Gets the user message + + + + + Creates a new instance of the class. + + The expected value + The actual value + The user message to be shown + + + + Creates a new instance of the class. + + The expected value + The actual value + The user message to be shown + Set to true to skip the check for difference position + + + + Gets the actual value. + + + + + Gets the expected value. + + + + + Gets a message that describes the current exception. Includes the expected and actual values. + + The error message that explains the reason for the exception, or an empty string(""). + 1 + + + + Exception thrown when a collection unexpectedly does not contain the expected value. + + + + + Creates a new instance of the class. + + The expected object value + + + + Exception to be thrown from when the number of + parameter values does not the test method signature. + + + + + + + + + + + Internal class used for version-resilient test runners. DO NOT CALL DIRECTLY. + Version-resilient runners should link against xunit.runner.utility.dll and use + ExecutorWrapper instead. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Exception thrown when the value is unexpectedly not of the given type or a derived type. + + + + + Creates a new instance of the class. + + The expected type + The actual object value + + + + Allows the user to record actions for a test. + + + + + Records any exception which is thrown by the given code. + + The code which may thrown an exception. + Returns the exception that was thrown by the code; null, otherwise. + + + + Records any exception which is thrown by the given code that has + a return value. Generally used for testing property accessors. + + The code which may thrown an exception. + Returns the exception that was thrown by the code; null, otherwise. + + + + Exception that is thrown when one or more exceptions are thrown from + the After method of a . + + + + + Initializes a new instance of the class. + + The exceptions. + + + + Initializes a new instance of the class. + + The exceptions. + + + + Gets the list of exceptions thrown in the After method. + + + + + Gets a message that describes the current exception. + + + + + Gets a string representation of the frames on the call stack at the time the current exception was thrown. + + + + + Implementation of which executes the + instances attached to a test method. + + + + + Initializes a new instance of the class. + + The inner command. + The method. + + + + Executes the test method. + + The instance of the test class + Returns information about the test run + + + + Wraps any exceptions thrown by the command execution. + + + + + Initializes a new instance of the class. + + The inner command. + The method. + + + + Executes the test method. + + The instance of the test class + Returns information about the test run + + + + Guard class, used for guard clauses and argument validation + + + + + + + + + + + + + + Base class which contains XML manipulation helper methods + + + + + Interface that represents a single test result. + + + + + Converts the test result into XML that is consumed by the test runners. + + The parent node. + The newly created XML node. + + + + The amount of time spent in execution + + + + + Adds the test execution time to the XML node. + + The XML node. + + + + + + + + + + Utility methods for dealing with exceptions. + + + + + Gets the message for the exception, including any inner exception messages. + + The exception + The formatted message + + + + Gets the stack trace for the exception, including any inner exceptions. + + The exception + The formatted stack trace + + + + Rethrows an exception object without losing the existing stack trace information + + The exception to re-throw. + + For more information on this technique, see + http://www.dotnetjunkies.com/WebLog/chris.taylor/archive/2004/03/03/8353.aspx + + + + + A dictionary which contains multiple unique values for each key. + + The type of the key. + The type of the value. + + + + Adds the value for the given key. If the key does not exist in the + dictionary yet, it will add it. + + The key. + The value. + + + + Removes all keys and values from the dictionary. + + + + + Determines whether the dictionary contains to specified key and value. + + The key. + The value. + + + + Calls the delegate once for each key/value pair in the dictionary. + + + + + Removes the given key and all of its values. + + + + + Removes the given value from the given key. If this was the + last value for the key, then the key is removed as well. + + The key. + The value. + + + + Gets the values for the given key. + + + + + Gets the count of the keys in the dictionary. + + + + + Gets the keys. + + + + + + + + XML utility methods + + + + + Adds an attribute to an XML node. + + The XML node. + The attribute name. + The attribute value. + + + + Adds a child element to an XML node. + + The parent XML node. + The child element name. + The new child XML element. + + + + Exception that is thrown when a call to Debug.Assert() fails. + + + + + Creates a new instance of the class. + + The original assert message + + + + Creates a new instance of the class. + + The original assert message + The original assert detailed message + + + + Gets the original assert detailed message. + + + + + Gets the original assert message. + + + + + Gets a message that describes the current exception. + + + + + Exception thrown when a collection unexpectedly contains the expected value. + + + + + Creates a new instance of the class. + + The expected object value + + + + Exception thrown when code unexpectedly throws an exception. + + + + + Creates a new instance of the class. + + Actual exception + + + + Gets a string representation of the frames on the call stack at the time the current exception was thrown. + + A string that describes the contents of the call stack, with the most recent method call appearing first. + + + + Exception thrown when a collection is unexpectedly not empty. + + + + + Creates a new instance of the class. + + + + + Exception thrown when two values are unexpectedly not equal. + + + + + Creates a new instance of the class. + + The expected object value + The actual object value + + + + Exception thrown when a value is unexpectedly true. + + + + + Creates a new instance of the class. + + The user message to be display, or null for the default message + + + + Exception thrown when a value is unexpectedly not in the given range. + + + + + Creates a new instance of the class. + + The actual object value + The low value of the range + The high value of the range + + + + Gets the actual object value + + + + + Gets the high value of the range + + + + + Gets the low value of the range + + + + + Gets a message that describes the current exception. + + The error message that explains the reason for the exception, or an empty string(""). + + + + Exception thrown when the value is unexpectedly of the exact given type. + + + + + Creates a new instance of the class. + + The expected type + The actual object value + + + + Exception thrown when the value is unexpectedly not of the exact given type. + + + + + Creates a new instance of the class. + + The expected type + The actual object value + + + + Used to decorate xUnit.net test classes that utilize fixture classes. + An instance of the fixture data is initialized just before the first + test in the class is run, and if it implements IDisposable, is disposed + after the last test in the class is run. + + The type of the fixture + + + + Called on the test class just before each test method is run, + passing the fixture data so that it can be used for the test. + All test runs share the same instance of fixture data. + + The fixture data + + + + Exception thrown when a value is unexpectedly in the given range. + + + + + Creates a new instance of the class. + + The actual object value + The low value of the range + The high value of the range + + + + Gets the actual object value + + + + + Gets the high value of the range + + + + + Gets the low value of the range + + + + + Gets a message that describes the current exception. + + The error message that explains the reason for the exception, or an empty string(""). + + + + Base attribute which indicates a test method interception (allows code to be run before and + after the test is run). + + + + + This method is called after the test method is executed. + + The method under test + + + + This method is called before the test method is executed. + + The method under test + + + + Exception thrown when a collection is unexpectedly empty. + + + + + Creates a new instance of the class. + + + + + Exception thrown when two values are unexpectedly equal. + + + + + Creates a new instance of the class. + + + + + Exception thrown when an object is unexpectedly null. + + + + + Creates a new instance of the class. + + + + + Exception thrown when two values are unexpected the same instance. + + + + + Creates a new instance of the class. + + + + + Exception thrown when an object reference is unexpectedly not null. + + + + + Creates a new instance of the class. + + + + + + Command that automatically creates the instance of the test class + and disposes it (if it implements ). + + + + + Creates a new instance of the object. + + The command that is bring wrapped + The method under test + + + + Executes the test method. Creates a new instance of the class + under tests and passes it to the inner command. Also catches + any exceptions and converts them into s. + + The instance of the test class + Returns information about the test run + + + + A command wrapper which catches Trace.Assert and Debug.Assert failures and turns + them into assertion exceptions. + + + + + Creates a new instance of the class. + + The command that will be wrapped. + + + + Executes the test method. + + The instance of the test class + Returns information about the test run + + + + Command used to wrap a which has associated + fixture data. + + + + + Creates a new instance of the class. + + The inner command + The fixtures to be set on the test class + + + + Sets the fixtures on the test class by calling SetFixture, then + calls the inner command. + + The instance of the test class + Returns information about the test run + + + + A timer class used to figure out how long tests take to run. On most .NET implementations + this will use the class because it's a high + resolution timer; however, on Silverlight/CoreCLR, it will use + (which will provide lower resolution results). + + + + + Creates a new instance of the class. + + + + + Starts timing. + + + + + Stops timing. + + + + + Gets how long the timer ran, in milliseconds. In order for this to be valid, + both and must have been called. + + + + + Attribute used to decorate a test method with arbitrary name/value pairs ("traits"). + + + + + Creates a new instance of the class. + + The trait name + The trait value + + + + Gets the trait name. + + + + + Gets the trait value. + + + + + Runner that executes an synchronously. + + + + + Execute the . + + The test class command to execute + The methods to execute; if null or empty, all methods will be executed + The start run callback + The end run result callback + A with the results of the test run + + + + Factory for objects, based on the type under test. + + + + + Creates the test class command, which implements , for a given type. + + The type under test + The test class command, if the class is a test class; null, otherwise + + + + Creates the test class command, which implements , for a given type. + + The type under test + The test class command, if the class is a test class; null, otherwise + + + + Represents an xUnit.net test class + + + + + Interface which describes the ability to executes all the tests in a test class. + + + + + Allows the test class command to choose the next test to be run from the list of + tests that have not yet been run, thereby allowing it to choose the run order. + + The tests remaining to be run + The index of the test that should be run + + + + Execute actions to be run after all the test methods of this test class are run. + + Returns the thrown during execution, if any; null, otherwise + + + + Execute actions to be run before any of the test methods of this test class are run. + + Returns the thrown during execution, if any; null, otherwise + + + + Enumerates the test commands for a given test method in this test class. + + The method under test + The test commands for the given test method + + + + Enumerates the methods which are test methods in this test class. + + The test methods + + + + Determines if a given refers to a test method. + + The test method to validate + True if the method is a test method; false, otherwise + + + + Gets the object instance that is under test. May return null if you wish + the test framework to create a new object instance for each test method. + + + + + Gets or sets the type that is being tested + + + + + Creates a new instance of the class. + + + + + Creates a new instance of the class. + + The type under test + + + + Creates a new instance of the class. + + The type under test + + + + Chooses the next test to run, randomly, using the . + + The tests remaining to be run + The index of the test that should be run + + + + Execute actions to be run after all the test methods of this test class are run. + + Returns the thrown during execution, if any; null, otherwise + + + + Execute actions to be run before any of the test methods of this test class are run. + + Returns the thrown during execution, if any; null, otherwise + + + + Enumerates the test commands for a given test method in this test class. + + The method under test + The test commands for the given test method + + + + Enumerates the methods which are test methods in this test class. + + The test methods + + + + Determines if a given refers to a test method. + + The test method to validate + True if the method is a test method; false, otherwise + + + + Gets the object instance that is under test. May return null if you wish + the test framework to create a new object instance for each test method. + + + + + Gets or sets the randomizer used to determine the order in which tests are run. + + + + + Sets the type that is being tested + + + + + Implementation of that represents a skipped test. + + + + + Represents an xUnit.net test command. + + + + + The method under test. + + + + + Initializes a new instance of the class. + + The method under test. + + + + Initializes a new instance of the class. + + The method under test. + The display name of the test. + + + + + + + + + + + + + Gets the name of the method under test. + + + + + Gets the name of the type under test. + + + + + + + + Creates a new instance of the class. + + The method that is being skipped + The display name for the test. If null, the fully qualified + type name is used. + The reason the test was skipped. + + + + + + + + + + Gets the skip reason. + + + + + + + + Factory for creating objects. + + + + + Make instances of objects for the given class and method. + + The class command + The method under test + The set of objects + + + + A command wrapper which times the running of a command. + + + + + Creates a new instance of the class. + + The command that will be timed. + + + + Executes the inner test method, gathering the amount of time it takes to run. + + Returns information about the test run + + + + Wraps a command which should fail if it runs longer than the given timeout value. + + + + + Creates a new instance of the class. + + The command to be run + The timout, in milliseconds + The method under test + + + + Executes the test method, failing if it takes too long. + + Returns information about the test run + + + + Gets the timeout value, in milliseconds. + + + + + Attributes used to decorate a test fixture that is run with an alternate test runner. + The test runner must implement the interface. + + + + + Creates a new instance of the class. + + The class which implements ITestClassCommand and acts as the runner + for the test fixture. + + + + Gets the test class command. + + + + + Exception thrown when two object references are unexpectedly not the same instance. + + + + + Creates a new instance of the class. + + The expected object reference + The actual object reference + + + + Contains the test results from an assembly. + + + + + Contains multiple test results, representing them as a composite test result. + + + + + Adds a test result to the composite test result list. + + + + + + Gets the test results. + + + + + Creates a new instance of the class. + + The filename of the assembly + + + + Creates a new instance of the class. + + The filename of the assembly + The configuration filename + + + + Converts the test result into XML that is consumed by the test runners. + + The parent node. + The newly created XML node. + + + + Gets the fully qualified filename of the configuration file. + + + + + Gets the directory where the assembly resides. + + + + + Gets the number of failed results. + + + + + Gets the fully qualified filename of the assembly. + + + + + Gets the number of passed results. + + + + + Gets the number of skipped results. + + + + + Contains the test results from a test class. + + + + + Creates a new instance of the class. + + The type under test + + + + Creates a new instance of the class. + + The simple name of the type under test + The fully qualified name of the type under test + The namespace of the type under test + + + + Sets the exception thrown by the test fixture. + + The thrown exception + + + + Converts the test result into XML that is consumed by the test runners. + + The parent node. + The newly created XML node. + + + + Gets the fully qualified test fixture exception type, when an exception has occurred. + + + + + Gets the number of tests which failed. + + + + + Gets the fully qualified name of the type under test. + + + + + Gets the test fixture exception message, when an exception has occurred. + + + + + Gets the simple name of the type under test. + + + + + Gets the namespace of the type under test. + + + + + Gets the number of tests which passed. + + + + + Gets the number of tests which were skipped. + + + + + Gets the test fixture exception stack trace, when an exception has occurred. + + + + + Represents a failed test result. + + + + + Represents the results from running a test method + + + + + Initializes a new instance of the class. The traits for + the test method are discovered using reflection. + + The method under test. + The display name for the test. If null, the fully qualified + type name is used. + + + + Initializes a new instance of the class. + + The name of the method under test. + The type of the method under test. + The display name for the test. If null, the fully qualified + type name is used. + The traits. + + + + Converts the test result into XML that is consumed by the test runners. + + The parent node. + The newly created XML node. + + + + Gets or sets the display name of the method under test. This is the value that's shown + during failures and in the resulting output XML. + + + + + Gets the name of the method under test. + + + + + Gets or sets the standard output/standard error from the test that was captured + while the test was running. + + + + + Gets the traits attached to the test method. + + + + + Gets the name of the type under test. + + + + + Creates a new instance of the class. + + The method under test + The exception throw by the test + The display name for the test. If null, the fully qualified + type name is used. + + + + Creates a new instance of the class. + + The name of the method under test + The name of the type under test + The display name of the test + The custom properties attached to the test method + The full type name of the exception throw + The exception message + The exception stack trace + + + + Converts the test result into XML that is consumed by the test runners. + + The parent node. + The newly created XML node. + + + + Gets the exception type thrown by the test method. + + + + + Gets the exception message thrown by the test method. + + + + + Gets the stack trace of the exception thrown by the test method. + + + + + Represents a passing test result. + + + + + Create a new instance of the class. + + The method under test + The display name for the test. If null, the fully qualified + type name is used. + + + + Create a new instance of the class. + + The name of the method under test + The name of the type under test + The display name for the test. If null, the fully qualified + type name is used. + The custom properties attached to the test method + + + + Converts the test result into XML that is consumed by the test runners. + + The parent node. + The newly created XML node. + + + + Represents a skipped test result. + + + + + Creates a new instance of the class. Uses reflection to discover + the skip reason. + + The method under test + The display name for the test. If null, the fully qualified + type name is used. + The reason the test was skipped. + + + + Creates a new instance of the class. + + The name of the method under test + The name of the type under test + The display name for the test. If null, the fully qualified + type name is used. + The traits attached to the method under test + The skip reason + + + + Converts the test result into XML that is consumed by the test runners. + + The parent node. + The newly created XML node. + + + + Gets the skip reason. + + + + + Represents information about an attribute. + + + + + Gets the instance of the attribute, if available. + + The type of the attribute + The instance of the attribute, if available. + + + + Gets an initialized property value of the attribute. + + The type of the property + The name of the property + The property value + + + + Represents information about a method. + + + + + Creates an instance of the type where this test method was found. If using + reflection, this should be the ReflectedType. + + A new instance of the type. + + + + Gets all the custom attributes for the method that are of the given type. + + The type of the attribute + The matching attributes that decorate the method + + + + Determines if the method has at least one instance of the given attribute type. + + The type of the attribute + True if the method has at least one instance of the given attribute type; false, otherwise + + + + Invokes the test on the given class, with the given parameters. + + The instance of the test class (may be null if + the test method is static). + The parameters to be passed to the test method. + + + + Gets a value indicating whether the method is abstract. + + + + + Gets a value indicating whether the method is static. + + + + + Gets the underlying for the method, if available. + + + + + Gets the name of the method. + + + + + Gets the fully qualified type name of the return type. + + + + + Gets the fully qualified type name of the type that this method belongs to. If + using reflection, this should be the ReflectedType. + + + + + Represents information about a type. + + + + + Gets all the custom attributes for the type that are of the given attribute type. + + The type of the attribute + The matching attributes that decorate the type + + + + Gets a test method by name. + + The name of the method + The method, if it exists; null, otherwise. + + + + Gets all the methods + + + + + + Determines if the type has at least one instance of the given attribute type. + + The type of the attribute + True if the type has at least one instance of the given attribute type; false, otherwise + + + + Determines if the type implements the given interface. + + The type of the interface + True if the type implements the given interface; false, otherwise + + + + Gets a value indicating whether the type is abstract. + + + + + Gets a value indicating whether the type is sealed. + + + + + Gets the underlying object, if available. + + + + + Utility class which inspects methods for test information + + + + + Gets the skip reason from a test method. + + The method to be inspected + The skip reason + + + + Gets the test commands for a test method. + + The method to be inspected + The objects for the test method + + + + Gets the timeout value for a test method. + + The method to be inspected + The timeout, in milliseconds + + + + Gets the traits on a test method. + + The method to be inspected + A dictionary of the traits + + + + Determines whether a test method has a timeout. + + The method to be inspected + True if the method has a timeout; false, otherwise + + + + Determines whether a test method has traits. + + The method to be inspected + True if the method has traits; false, otherwise + + + + Determines whether a test method should be skipped. + + The method to be inspected + True if the method should be skipped; false, otherwise + + + + Determines whether a method is a test method. A test method must be decorated + with the (or derived class) and must not be abstract. + + The method to be inspected + True if the method is a test method; false, otherwise + + + + Wrapper to implement and using reflection. + + + + + Converts an into an using reflection. + + + + + + + Converts a into an using reflection. + + The method to wrap + The wrapper + + + + Converts a into an using reflection. + + The type to wrap + The wrapper + + + + Utility class which inspects types for test information + + + + + Determines if a type contains any test methods + + The type to be inspected + True if the class contains any test methods; false, otherwise + + + + Retrieves the type to run the test class with from the , if present. + + The type to be inspected + The type of the test class runner, if present; null, otherwise + + + + Retrieves a list of the test methods from the test class. + + The type to be inspected + The test methods + + + + Determines if the test class has a applied to it. + + The type to be inspected + True if the test class has a run with attribute; false, otherwise + + + + Determines if the type implements . + + The type to be inspected + True if the type implements ; false, otherwise + + + + Determines whether the specified type is abstract. + + The type. + + true if the specified type is abstract; otherwise, false. + + + + + Determines whether the specified type is static. + + The type. + + true if the specified type is static; otherwise, false. + + + + + Determines if a class is a test class. + + The type to be inspected + True if the type is a test class; false, otherwise + + + + Attribute that is applied to a method to indicate that it is a fact that should be run + by the test runner. It can also be extended to support a customized definition of a + test method. + + + + + Creates instances of which represent individual intended + invocations of the test method. + + The method under test + An enumerator through the desired test method invocations + + + + Enumerates the test commands represented by this test method. Derived classes should + override this method to return instances of , one per execution + of a test method. + + The test method + The test commands which will execute the test runs for the given method + + + + Gets the name of the test to be used when the test is skipped. Defaults to + null, which will cause the fully qualified test name to be used. + + + + + Obsolete. Please use the property instead. + + + + + Marks the test so that it will not be run, and gets or sets the skip reason + + + + + Marks the test as failing if it does not finish running within the given time + period, in milliseconds; set to 0 or less to indicate the method has no timeout + + + + + Exception thrown when code unexpectedly fails to throw an exception. + + + + + Creates a new instance of the class. Call this constructor + when no exception was thrown. + + The type of the exception that was expected + + + + Creates a new instance of the class. Call this constructor + when an exception of the wrong type was thrown. + + The type of the exception that was expected + The actual exception that was thrown + + + + Gets a string representation of the frames on the call stack at the time the current exception was thrown. + + A string that describes the contents of the call stack, with the most recent method call appearing first. + + + + Exception thrown when a test method exceeds the given timeout value + + + + + Creates a new instance of the class. + + The timeout value, in milliseconds + + + + Exception thrown when a value is unexpectedly false. + + + + + Creates a new instance of the class. + + The user message to be displayed, or null for the default message + + + diff --git a/License.txt b/License.txt index 8b6bcf878..fb36f9263 100644 --- a/License.txt +++ b/License.txt @@ -1,39 +1,39 @@ -Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -http://code.google.com/p/moq/ -All rights reserved. - -Redistribution and use in source and binary forms, -with or without modification, are permitted provided -that the following conditions are met: - - * Redistributions of source code must retain the - above copyright notice, this list of conditions and - the following disclaimer. - - * Redistributions in binary form must reproduce - the above copyright notice, this list of conditions - and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the - names of its contributors may be used to endorse - or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -SUCH DAMAGE. - -[This is the BSD license, see +Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +http://code.google.com/p/moq/ +All rights reserved. + +Redistribution and use in source and binary forms, +with or without modification, are permitted provided +that the following conditions are met: + + * Redistributions of source code must retain the + above copyright notice, this list of conditions and + the following disclaimer. + + * Redistributions in binary form must reproduce + the above copyright notice, this list of conditions + and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the + names of its contributors may be used to endorse + or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. + +[This is the BSD license, see http://www.opensource.org/licenses/bsd-license.php] \ No newline at end of file diff --git a/Moq.Help.scproj b/Moq.Help.scproj index 3e9c071b4..99e72706d 100644 --- a/Moq.Help.scproj +++ b/Moq.Help.scproj @@ -1,180 +1,180 @@ - - - - Moq - vs2005 - 1033 - Help - $(BuildDir)\dll - $(DllDir)\dependency - $(BuildDir)\comments - $(BuildDir)\$(TopicStyle) - $(TopicStyleDir)\output - $(DxRoot)\ProductionTools - $(DxRoot)\ProductionTransforms - $(DXROOT)\Examples\Generic - false - - - - - - - - - - - - $(ProgramFiles(x86)) - - - - - $(ProgramFiles) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + Moq + vs2005 + 1033 + Help + $(BuildDir)\dll + $(DllDir)\dependency + $(BuildDir)\comments + $(BuildDir)\$(TopicStyle) + $(TopicStyleDir)\output + $(DxRoot)\ProductionTools + $(DxRoot)\ProductionTransforms + $(DXROOT)\Examples\Generic + false + + + + + + + + + + + + $(ProgramFiles(x86)) + + + + + $(ProgramFiles) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Moq.shfb b/Moq.shfb index 33d93e27e..7004dae5c 100644 --- a/Moq.shfb +++ b/Moq.shfb @@ -1,119 +1,119 @@ - - - - - - - - - - - - - - - - - - - - Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET and Silverlight developed from scratch to take full advantage of .NET 3.5 (i.e. Linq expression trees) and C# 3.0 features (i.e. lambda expressions) that make it the most productive, simple and refactoring-friendly mocking library available. -<p> -See the <a href="http://code.google.com/p/moq/wiki/QuickStart">online quickstarts</a> for more examples than those available in this code documentation. -</p> -<p>The Mock&lt;T&gt; class is the core of the library, so it's a good place to start.</p> -You can also read <a href="http://blogsearch.google.com/blogsearch?q=moq+mock">blog entries</a> from around the world about Moq. - This namespace defines the interfaces that contain the methods available in Moq fluent API, such as Setup, Callback, Returns, Throws, etc. -<p> -Review the documentation of the available methods on these interfaces for code examples. The way these interfaces are composed, grouped and made visible at different stages during an expectation (i.e. Verifiable is the last "verb" and can't be specified before the Returns) is internal but the API will naturally lead you to the proper way of using it, so don't worry too much about who (and where) exposes these language interfaces. They will show up in Intellisense when it's appropriate. -</p><p> -Do use their documentation to learn about options (especially when there are several overloads available) that may be a better fit for a particular scenario.</p> - - Provides pre-built mocks for testing ASP.NET MVC applications. - - Importing this namespace will enable the Protected() method on mocks, enabling expectations on protected members by specifying the member name as a string. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Summary, Parameter, AutoDocumentCtors, Namespace - InheritedMembers, Protected, SealedProtected - - - ..\build\Help\ - - - True - True - - Help1xAndWebsite - False - 4.0.30319 - False - False - False - - Moq - Moq - en-US - - - moqdisc@googlegroups.com - - - - Local - Msdn - Blank - vs2005 - HashedMemberName - CSharp - False - True - False - Hierarchical - True - ms.vsipcc+, ms.vsexpresscc+ - 1.0.0.0 - AboveNamespaces + + + + + + + + + + + + + + + + + + + + Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET and Silverlight developed from scratch to take full advantage of .NET 3.5 (i.e. Linq expression trees) and C# 3.0 features (i.e. lambda expressions) that make it the most productive, simple and refactoring-friendly mocking library available. +<p> +See the <a href="http://code.google.com/p/moq/wiki/QuickStart">online quickstarts</a> for more examples than those available in this code documentation. +</p> +<p>The Mock&lt;T&gt; class is the core of the library, so it's a good place to start.</p> +You can also read <a href="http://blogsearch.google.com/blogsearch?q=moq+mock">blog entries</a> from around the world about Moq. + This namespace defines the interfaces that contain the methods available in Moq fluent API, such as Setup, Callback, Returns, Throws, etc. +<p> +Review the documentation of the available methods on these interfaces for code examples. The way these interfaces are composed, grouped and made visible at different stages during an expectation (i.e. Verifiable is the last "verb" and can't be specified before the Returns) is internal but the API will naturally lead you to the proper way of using it, so don't worry too much about who (and where) exposes these language interfaces. They will show up in Intellisense when it's appropriate. +</p><p> +Do use their documentation to learn about options (especially when there are several overloads available) that may be a better fit for a particular scenario.</p> + + Provides pre-built mocks for testing ASP.NET MVC applications. + + Importing this namespace will enable the Protected() method on mocks, enabling expectations on protected members by specifying the member name as a string. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Summary, Parameter, AutoDocumentCtors, Namespace + InheritedMembers, Protected, SealedProtected + + + ..\build\Help\ + + + True + True + + Help1xAndWebsite + False + 4.0.30319 + False + False + False + + Moq + Moq + en-US + + + moqdisc@googlegroups.com + + + + Local + Msdn + Blank + vs2005 + HashedMemberName + CSharp + False + True + False + Hierarchical + True + ms.vsipcc+, ms.vsexpresscc+ + 1.0.0.0 + AboveNamespaces \ No newline at end of file diff --git a/Moq.shfbproj b/Moq.shfbproj index 072ccd409..dc4666eaa 100644 --- a/Moq.shfbproj +++ b/Moq.shfbproj @@ -1,155 +1,155 @@ - - - - Debug - AnyCPU - 2.0 - {625556c0-8f59-4f6e-a1cb-531db1cc0935} - 1.9.0.0 - - Documentation - Documentation - Documentation - - ..\build\Help\ - Moq - en-US - - - - - - - - - - - - - - - - - - - - - - - - - Summary, AutoDocumentCtors, Namespace - InheritedMembers, Protected, SealedProtected - ..\build\HTML Help Workshop\ - - - ..\build\Sandcastle\ - - - - - HtmlHelp1, Website - 4.0.30319 - Moq - moqdisc%40googlegroups.com - vs2005 - HashedMemberName - CSharp - - - - - - - - - - - -{@HelpFormatOutputPaths} - -{@CachedFrameworkCommentList} -{@CommentFileList} - - - - - - - - - - - - - - - - - - - - - - Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET and Silverlight developed from scratch to take full advantage of .NET 3.5 (i.e. Linq expression trees) and C# 3.0 features (i.e. lambda expressions) that make it the most productive, simple and refactoring-friendly mocking library available. -<p> -See the <a href="http://code.google.com/p/moq/wiki/QuickStart">online quickstarts</a> for more examples than those available in this code documentation. -</p> -<p>The Mock&lt;T&gt; class is the core of the library, so it's a good place to start.</p> -You can also read <a href="http://blogsearch.google.com/blogsearch?q=moq+mock">blog entries</a> from around the world about Moq. - This namespace defines the interfaces that contain the methods available in Moq fluent API, such as Setup, Callback, Returns, Throws, etc. -<p> -Review the documentation of the available methods on these interfaces for code examples. The way these interfaces are composed, grouped and made visible at different stages during an expectation (i.e. Verifiable is the last "verb" and can't be specified before the Returns) is internal but the API will naturally lead you to the proper way of using it, so don't worry too much about who (and where) exposes these language interfaces. They will show up in Intellisense when it's appropriate. -</p><p> -Do use their documentation to learn about options (especially when there are several overloads available) that may be a better fit for a particular scenario.</p> - - Provides pre-built mocks for testing ASP.NET MVC applications. - - Importing this namespace will enable the Protected() method on mocks, enabling expectations on protected members by specifying the member name as a string. - - - - - - - - - - - - - - - - - - - - - - + + + + Debug + AnyCPU + 2.0 + {625556c0-8f59-4f6e-a1cb-531db1cc0935} + 1.9.0.0 + + Documentation + Documentation + Documentation + + ..\build\Help\ + Moq + en-US + + + + + + + + + + + + + + + + + + + + + + + + + Summary, AutoDocumentCtors, Namespace + InheritedMembers, Protected, SealedProtected + ..\build\HTML Help Workshop\ + + + ..\build\Sandcastle\ + + + + + HtmlHelp1, Website + 4.0.30319 + Moq + moqdisc%40googlegroups.com + vs2005 + HashedMemberName + CSharp + + + + + + + + + + + +{@HelpFormatOutputPaths} + +{@CachedFrameworkCommentList} +{@CommentFileList} + + + + + + + + + + + + + + + + + + + + + + Root namespace of Moq (pronounced "Mock-you" or just "Mock"), the only mocking library for .NET and Silverlight developed from scratch to take full advantage of .NET 3.5 (i.e. Linq expression trees) and C# 3.0 features (i.e. lambda expressions) that make it the most productive, simple and refactoring-friendly mocking library available. +<p> +See the <a href="http://code.google.com/p/moq/wiki/QuickStart">online quickstarts</a> for more examples than those available in this code documentation. +</p> +<p>The Mock&lt;T&gt; class is the core of the library, so it's a good place to start.</p> +You can also read <a href="http://blogsearch.google.com/blogsearch?q=moq+mock">blog entries</a> from around the world about Moq. + This namespace defines the interfaces that contain the methods available in Moq fluent API, such as Setup, Callback, Returns, Throws, etc. +<p> +Review the documentation of the available methods on these interfaces for code examples. The way these interfaces are composed, grouped and made visible at different stages during an expectation (i.e. Verifiable is the last "verb" and can't be specified before the Returns) is internal but the API will naturally lead you to the proper way of using it, so don't worry too much about who (and where) exposes these language interfaces. They will show up in Intellisense when it's appropriate. +</p><p> +Do use their documentation to learn about options (especially when there are several overloads available) that may be a better fit for a particular scenario.</p> + + Provides pre-built mocks for testing ASP.NET MVC applications. + + Importing this namespace will enable the Protected() method on mocks, enabling expectations on protected members by specifying the member name as a string. + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Samples/Lib/Moq.xml b/Samples/Lib/Moq.xml index 39c6dbf5b..f0592f204 100644 --- a/Samples/Lib/Moq.xml +++ b/Samples/Lib/Moq.xml @@ -1,3450 +1,3450 @@ - - - - Moq - - - - - Interface to be implemented by classes that determine the - default value of non-expected invocations. - - - - - Provides a value for the given member and arguments. - - The member to provide a default - value for. - Optional arguments passed in - to the call that requires a default value. - - - - Provides a typed for a - specific type of . - - The type of event arguments required by the event. - - The mocked event can either be a or custom - event handler which follows .NET practice of providing object sender, EventArgs args - kind of signature. - - - - - Represents a generic event that has been mocked and can - be rised. - - - - - Provided solely to allow the interceptor to determine when the attached - handler is coming from this mocked event so we can assign the - corresponding EventInfo for it. - - - - - Raises the associated event with the given - event argument data. - - - - - Provides support for attaching a to - a generic event. - - Event to convert. - - - - Event raised whenever the mocked event is rised. - - - - - Raises the associated event with the given - event argument data. - - Data to pass to the event. - - - - Provides support for attaching a to - a generic event. - - Event to convert. - - - - Provided solely to allow the interceptor to determine when the attached - handler is coming from this mocked event so we can assign the - corresponding EventInfo for it. - - - - - Utility factory class to use to construct multiple - mocks when consistent verification is - desired for all of them. - - - If multiple mocks will be created during a test, passing - the desired (if different than the - or the one - passed to the factory constructor) and later verifying each - mock can become repetitive and tedious. - - This factory class helps in that scenario by providing a - simplified creation of multiple mocks with a default - (unless overriden by calling - ) and posterior verification. - - - - The following is a straightforward example on how to - create and automatically verify strict mocks using a : - - var factory = new MockFactory(MockBehavior.Strict); - - var foo = factory.Create<IFoo>(); - var bar = factory.Create<IBar>(); - - // no need to call Verifiable() on the setup - // as we'll be validating all of them anyway. - foo.Setup(f => f.Do()); - bar.Setup(b => b.Redo()); - - // exercise the mocks here - - factory.VerifyAll(); - // At this point all setups are already checked - // and an optional MockException might be thrown. - // Note also that because the mocks are strict, any invocation - // that doesn't have a matching setup will also throw a MockException. - - The following examples shows how to setup the factory - to create loose mocks and later verify only verifiable setups: - - var factory = new MockFactory(MockBehavior.Loose); - - var foo = factory.Create<IFoo>(); - var bar = factory.Create<IBar>(); - - // this setup will be verified when we verify the factory - foo.Setup(f => f.Do()).Verifiable(); - - // this setup will NOT be verified - foo.Setup(f => f.Calculate()); - - // this setup will be verified when we verify the factory - bar.Setup(b => b.Redo()).Verifiable(); - - // exercise the mocks here - // note that because the mocks are Loose, members - // called in the interfaces for which no matching - // setups exist will NOT throw exceptions, - // and will rather return default values. - - factory.Verify(); - // At this point verifiable setups are already checked - // and an optional MockException might be thrown. - - The following examples shows how to setup the factory with a - default strict behavior, overriding that default for a - specific mock: - - var factory = new MockFactory(MockBehavior.Strict); - - // this particular one we want loose - var foo = factory.Create<IFoo>(MockBehavior.Loose); - var bar = factory.Create<IBar>(); - - // specify setups - - // exercise the mocks here - - factory.Verify(); - - - - - - - Initializes the factory with the given - for newly created mocks from the factory. - - The behavior to use for mocks created - using the factory method if not overriden - by using the overload. - - - - Creates a new mock with the default - specified at factory construction time. - - Type to mock. - A new . - - - var factory = new MockFactory(MockBehavior.Strict); - - var foo = factory.Create<IFoo>(); - // use mock on tests - - factory.VerifyAll(); - - - - - - Creates a new mock with the default - specified at factory construction time and with the - the given constructor arguments for the class. - - - The mock will try to find the best match constructor given the - constructor arguments, and invoke that to initialize the instance. - This applies only to classes, not interfaces. - - Type to mock. - Constructor arguments for mocked classes. - A new . - - - var factory = new MockFactory(MockBehavior.Default); - - var mock = factory.Create<MyBase>("Foo", 25, true); - // use mock on tests - - factory.Verify(); - - - - - - Creates a new mock with the given . - - Type to mock. - Behavior to use for the mock, which overrides - the default behavior specified at factory construction time. - A new . - - The following example shows how to create a mock with a different - behavior to that specified as the default for the factory: - - var factory = new MockFactory(MockBehavior.Strict); - - var foo = factory.Create<IFoo>(MockBehavior.Loose); - - - - - - Creates a new mock with the given - and with the the given constructor arguments for the class. - - - The mock will try to find the best match constructor given the - constructor arguments, and invoke that to initialize the instance. - This applies only to classes, not interfaces. - - Type to mock. - Behavior to use for the mock, which overrides - the default behavior specified at factory construction time. - Constructor arguments for mocked classes. - A new . - - The following example shows how to create a mock with a different - behavior to that specified as the default for the factory, passing - constructor arguments: - - var factory = new MockFactory(MockBehavior.Default); - - var mock = factory.Create<MyBase>(MockBehavior.Strict, "Foo", 25, true); - - - - - - Implements creation of a new mock within the factory. - - Type to mock. - The behavior for the new mock. - Optional arguments for the construction of the mock. - - - - Verifies all verifiable expectations on all mocks created - by this factory. - - - One or more mocks had expectations that were not satisfied. - - - - Verifies all verifiable expectations on all mocks created - by this factory. - - - One or more mocks had expectations that were not satisfied. - - - - Invokes for each mock - in , and accumulates the resulting - that might be - thrown from the action. - - The action to execute against - each mock. - - - - Whether the base member virtual implementation will be called - for mocked classes if no setup is matched. Defaults to . - - - - - Specifies the behavior to use when returning default values for - unexpected invocations on loose mocks. - - - - - Gets the mocks that have been created by this factory and - that will get verified together. - - - - - Defines the Throws verb. - - - - - Helper interface used to hide the base - members from the fluent API to make it much cleaner - in Visual Studio intellisense. - - - - - - - - - - - - - - - - - Specifies the exception to throw when the method is invoked. - - Exception instance to throw. - - This example shows how to throw an exception when the method is - invoked with an empty string argument: - - mock.Setup(x => x.Execute("")) - .Throws(new ArgumentException()); - - - - - - Specifies the type of exception to throw when the method is invoked. - - Type of exception to instantiate and throw when the setup is matched. - - This example shows how to throw an exception when the method is - invoked with an empty string argument: - - mock.Setup(x => x.Execute("")) - .Throws<ArgumentException>(); - - - - - - Allows the specification of a matching condition for an - argument in a method invocation, rather than a specific - argument value. "It" refers to the argument being matched. - - - This class allows the setup to match a method invocation - with an arbitrary value, with a value in a specified range, or - even one that matches a given predicate. - - - - - Matches any value of the given type. - - - Typically used when the actual argument value for a method - call is not relevant. - - - - // Throws an exception for a call to Remove with any string value. - mock.Setup(x => x.Remove(It.IsAny<string>())).Throws(new InvalidOperationException()); - - - Type of the value. - - - - Matches any value that satisfies the given predicate. - - Type of the argument to check. - The predicate used to match the method argument. - - Allows the specification of a predicate to perform matching - of method call arguments. - - - This example shows how to return the value 1 whenever the argument to the - Do method is an even number. - - mock.Setup(x => x.Do(It.Is<int>(i => i % 2 == 0))) - .Returns(1); - - This example shows how to throw an exception if the argument to the - method is a negative number: - - mock.Setup(x => x.GetUser(It.Is<int>(i => i < 0))) - .Throws(new ArgumentException()); - - - - - - Matches any value that is in the range specified. - - Type of the argument to check. - The lower bound of the range. - The upper bound of the range. - The kind of range. See . - - The following example shows how to expect a method call - with an integer argument within the 0..100 range. - - mock.Setup(x => x.HasInventory( - It.IsAny<string>(), - It.IsInRange(0, 100, Range.Inclusive))) - .Returns(false); - - - - - - Matches a string argument if it matches the given regular expression pattern. - - The pattern to use to match the string argument value. - - The following example shows how to expect a call to a method where the - string argument matches the given regular expression: - - mock.Setup(x => x.Check(It.IsRegex("[a-z]+"))).Returns(1); - - - - - - Matches a string argument if it matches the given regular expression pattern. - - The pattern to use to match the string argument value. - The options used to interpret the pattern. - - The following example shows how to expect a call to a method where the - string argument matches the given regular expression, in a case insensitive way: - - mock.Setup(x => x.Check(It.IsRegex("[a-z]+", RegexOptions.IgnoreCase))).Returns(1); - - - - - - Defines the Returns verb. - - Mocked type. - Type of the return value from the expression. - - - - Specifies the value to return. - - The value to return, or . - - Return a true value from the method call: - - mock.Setup(x => x.Execute("ping")) - .Returns(true); - - - - - - Specifies a function that will calculate the value to return from the method. - - The function that will calculate the return value. - - Return a calculated value when the method is called: - - mock.Setup(x => x.Execute("ping")) - .Returns(() => returnValues[0]); - - The lambda expression to retrieve the return value is lazy-executed, - meaning that its value may change depending on the moment the method - is executed and the value the returnValues array has at - that moment. - - - - - Specifies a function that will calculate the value to return from the method, - retrieving the arguments for the invocation. - - Type of the argument of the invoked method. - The function that will calculate the return value. - - Return a calculated value which is evaluated lazily at the time of the invocation. - - The lookup list can change between invocations and the setup - will return different values accordingly. Also, notice how the specific - string argument is retrieved by simply declaring it as part of the lambda - expression: - - - mock.Setup(x => x.Execute(It.IsAny<string>())) - .Returns((string command) => returnValues[command]); - - - - - - Specifies a function that will calculate the value to return from the method, - retrieving the arguments for the invocation. - - Type of the first argument of the invoked method. - Type of the second argument of the invoked method. - The function that will calculate the return value. - - Return a calculated value which is evaluated lazily at the time of the invocation. - - The return value is calculated from the value of the actual method invocation arguments. - Notice how the arguments are retrieved by simply declaring them as part of the lambda - expression: - - - mock.Setup(x => x.Execute( - It.IsAny<string>(), - It.IsAny<string>())) - .Returns((string arg1, string arg2) => arg1 + arg2); - - - - - - Specifies a function that will calculate the value to return from the method, - retrieving the arguments for the invocation. - - Type of the first argument of the invoked method. - Type of the second argument of the invoked method. - Type of the third argument of the invoked method. - The function that will calculate the return value. - - Return a calculated value which is evaluated lazily at the time of the invocation. - - The return value is calculated from the value of the actual method invocation arguments. - Notice how the arguments are retrieved by simply declaring them as part of the lambda - expression: - - - mock.Setup(x => x.Execute( - It.IsAny<string>(), - It.IsAny<string>(), - It.IsAny<int>())) - .Returns((string arg1, string arg2, int arg3) => arg1 + arg2 + arg3); - - - - - - Specifies a function that will calculate the value to return from the method, - retrieving the arguments for the invocation. - - Type of the first argument of the invoked method. - Type of the second argument of the invoked method. - Type of the third argument of the invoked method. - Type of the fourth argument of the invoked method. - The function that will calculate the return value. - - Return a calculated value which is evaluated lazily at the time of the invocation. - - The return value is calculated from the value of the actual method invocation arguments. - Notice how the arguments are retrieved by simply declaring them as part of the lambda - expression: - - - mock.Setup(x => x.Execute( - It.IsAny<string>(), - It.IsAny<string>(), - It.IsAny<int>(), - It.IsAny<bool>())) - .Returns((string arg1, string arg2, int arg3, bool arg4) => arg1 + arg2 + arg3 + arg4); - - - - - - Implemented by all generated mock object instances. - - - - - Implemented by all generated mock object instances. - - - - - Reference the Mock that contains this as the mock.Object value. - - - - - Reference the Mock that contains this as the mock.Object value. - - - - - Defines the Raises verb. - - - - - Specifies the event that will be raised - when the setup is met. - - An expression that represents an event attach or detach action. - The event arguments to pass for the raised event. - - The following example shows how to raise an event when - the setup is met: - - var mock = new Mock<IContainer>(); - - mock.Setup(add => add.Add(It.IsAny<string>(), It.IsAny<object>())) - .Raises(add => add.Added += null, EventArgs.Empty); - - - - - - Specifies the event that will be raised - when the setup is matched. - - An expression that represents an event attach or detach action. - A function that will build the - to pass when raising the event. - - - - - Specifies the event that will be raised - when the setup is matched. - - An expression that represents an event attach or detach action. - A function that will build the - to pass when raising the event. - Type of the argument received by the expected invocation. - - - - - Specifies the event that will be raised - when the setup is matched. - - An expression that represents an event attach or detach action. - A function that will build the - to pass when raising the event. - Type of the first argument received by the expected invocation. - Type of the second argument received by the expected invocation. - - - - - Specifies the event that will be raised - when the setup is matched. - - An expression that represents an event attach or detach action. - A function that will build the - to pass when raising the event. - Type of the first argument received by the expected invocation. - Type of the second argument received by the expected invocation. - Type of the third argument received by the expected invocation. - - - - - Specifies the event that will be raised - when the setup is matched. - - An expression that represents an event attach or detach action. - A function that will build the - to pass when raising the event. - Type of the first argument received by the expected invocation. - Type of the second argument received by the expected invocation. - Type of the third argument received by the expected invocation. - Type of the fourth argument received by the expected invocation. - - - - - Implements the fluent API. - - - - - Defines the Callback verb and overloads. - - - - - Specifies a callback to invoke when the method is called. - - Callback method to invoke. - - The following example specifies a callback to set a boolean - value that can be used later: - - bool called = false; - mock.Setup(x => x.Execute()) - .Callback(() => called = true); - - - - - - Specifies a callback to invoke when the method is called that receives the original - arguments. - - Argument type of the invoked method. - Callback method to invoke. - - Invokes the given callback with the concrete invocation argument value. - - Notice how the specific string argument is retrieved by simply declaring - it as part of the lambda expression for the callback: - - - mock.Setup(x => x.Execute(It.IsAny<string>())) - .Callback((string command) => Console.WriteLine(command)); - - - - - - Specifies a callback to invoke when the method is called that receives the original - arguments. - - Type of the first argument of the invoked method. - Type of the second argument of the invoked method. - Callback method to invoke. - - Invokes the given callback with the concrete invocation arguments values. - - Notice how the specific arguments are retrieved by simply declaring - them as part of the lambda expression for the callback: - - - mock.Setup(x => x.Execute( - It.IsAny<string>(), - It.IsAny<string>())) - .Callback((string arg1, string arg2) => Console.WriteLine(arg1 + arg2)); - - - - - - Specifies a callback to invoke when the method is called that receives the original - arguments. - - Type of the first argument of the invoked method. - Type of the second argument of the invoked method. - Type of the third argument of the invoked method. - Callback method to invoke. - - Invokes the given callback with the concrete invocation arguments values. - - Notice how the specific arguments are retrieved by simply declaring - them as part of the lambda expression for the callback: - - - mock.Setup(x => x.Execute( - It.IsAny<string>(), - It.IsAny<string>(), - It.IsAny<int>())) - .Callback((string arg1, string arg2, int arg3) => Console.WriteLine(arg1 + arg2 + arg3)); - - - - - - Specifies a callback to invoke when the method is called that receives the original - arguments. - - Type of the first argument of the invoked method. - Type of the second argument of the invoked method. - Type of the third argument of the invoked method. - Type of the fourth argument of the invoked method. - Callback method to invoke. - - Invokes the given callback with the concrete invocation arguments values. - - Notice how the specific arguments are retrieved by simply declaring - them as part of the lambda expression for the callback: - - - mock.Setup(x => x.Execute( - It.IsAny<string>(), - It.IsAny<string>(), - It.IsAny<int>(), - It.IsAny<bool>())) - .Callback((string arg1, string arg2, int arg3, bool arg4) => Console.WriteLine(arg1 + arg2 + arg3 + arg4)); - - - - - - Defines occurrence members to constraint setups. - - - - - The expected invocation can happen at most once. - - - - var mock = new Mock<ICommand>(); - mock.Setup(foo => foo.Execute("ping")) - .AtMostOnce(); - - - - - - The expected invocation can happen at most specified number of times. - - - - var mock = new Mock<ICommand>(); - mock.Setup(foo => foo.Execute("ping")) - .AtMost( 5 ); - - - - - - Defines the Raises verb. - - - - - Specifies the mocked event that will be raised - when the setup is met. - - The mocked event, retrieved from - or . - - The event args to pass when raising the event. - - The following example shows how to raise an event when - the setup is met: - - var mock = new Mock<IContainer>(); - // create handler to associate with the event to raise - var handler = mock.CreateEventHandler(); - // associate the handler with the event to raise - mock.Object.Added += handler; - // setup the invocation and the handler to raise - mock.Setup(add => add.Add(It.IsAny<string>(), It.IsAny<object>())) - .Raises(handler, EventArgs.Empty); - - - - - - Specifies the mocked event that will be raised - when the setup is matched. - - The mocked event, retrieved from - or . - - A function that will build the - to pass when raising the event. - - - - - Specifies the mocked event that will be raised - when the setup is matched. - - The mocked event, retrieved from - or . - - A function that will build the - to pass when raising the event. - Type of the argument received by the expected invocation. - - - - - Specifies the mocked event that will be raised - when the setup is matched. - - The mocked event, retrieved from - or . - - A function that will build the - to pass when raising the event. - Type of the first argument received by the expected invocation. - Type of the second argument received by the expected invocation. - - - - - Specifies the mocked event that will be raised - when the setup is matched. - - The mocked event, retrieved from - or . - - A function that will build the - to pass when raising the event. - Type of the first argument received by the expected invocation. - Type of the second argument received by the expected invocation. - Type of the third argument received by the expected invocation. - - - - - Specifies the mocked event that will be raised - when the setup is matched. - - The mocked event, retrieved from - or . - - A function that will build the - to pass when raising the event. - Type of the first argument received by the expected invocation. - Type of the second argument received by the expected invocation. - Type of the third argument received by the expected invocation. - Type of the fourth argument received by the expected invocation. - - - - - Defines the Verifiable verb. - - - - - Marks the expectation as verifiable, meaning that a call - to will check if this particular - expectation was met. - - - The following example marks the expectation as verifiable: - - mock.Expect(x => x.Execute("ping")) - .Returns(true) - .Verifiable(); - - - - - - Marks the expectation as verifiable, meaning that a call - to will check if this particular - expectation was met, and specifies a message for failures. - - - The following example marks the expectation as verifiable: - - mock.Expect(x => x.Execute("ping")) - .Returns(true) - .Verifiable("Ping should be executed always!"); - - - - - Type to mock, which can be an interface or a class. - - Provides a mock implementation of . - - - Only abstract and virtual members of classes can be mocked. - - The behavior of the mock with regards to the setups and the actual calls is determined - by the optional that can be passed to the - constructor. - - - - The following example shows establishing setups with specific values - for method invocations: - - //setup - data - var order = new Order(TALISKER, 50); - var mock = new Mock<IWarehouse>(); - - //setup - mock.Setup(x => x.HasInventory(TALISKER, 50)).Returns(true); - - //exercise - order.Fill(mock.Object); - - //verify - Assert.True(order.IsFilled); - - The following example shows how to use the class - to specify conditions for arguments instead of specific values: - - //setup - data - var order = new Order(TALISKER, 50); - var mock = new Mock<IWarehouse>(); - - //setup - //shows how to expect a value within a range - mock.Setup(x => x.HasInventory( - It.IsAny<string>(), - It.IsInRange(0, 100, Range.Inclusive))) - .Returns(false); - - //shows how to throw for unexpected calls. - mock.Setup(x => x.Remove( - It.IsAny<string>(), - It.IsAny<int>())) - .Throws(new InvalidOperationException()); - - //exercise - order.Fill(mock.Object); - - //verify - Assert.False(order.IsFilled); - - - - - - Base class for mocks and static helper class with methods that - apply to mocked objects, such as to - retrieve a from an object instance. - - - - - Retrieves the mock object for the given object instance. - - Type of the mock to retrieve. Can be omitted as it's inferred - from the object instance passed in as the instance. - The instance of the mocked object. - The mock associated with the mocked object. - The received instance - was not created by Moq. - - The following example shows how to add a new setup to an object - instance which is not the original but rather - the object associated with it: - - // Typed instance, not the mock, is retrieved from some test API. - HttpContextBase context = GetMockContext(); - - // context.Request is the typed object from the "real" API - // so in order to add a setup to it, we need to get - // the mock that "owns" it - Mock<HttpRequestBase> request = Mock.Get(context.Request); - mock.Setup(req => req.AppRelativeCurrentExecutionFilePath) - .Returns(tempUrl); - - - - - - Returns the mocked object value. - - - - - Verifies that all verifiable expectations have been met. - - - This example sets up an expectation and marks it as verifiable. After - the mock is used, a Verify() call is issued on the mock - to ensure the method in the setup was invoked: - - var mock = new Mock<IWarehouse>(); - this.Setup(x => x.HasInventory(TALISKER, 50)).Verifiable().Returns(true); - ... - // other test code - ... - // Will throw if the test code has didn't call HasInventory. - this.Verify(); - - - Not all verifiable expectations were met. - - - - Verifies all expectations regardless of whether they have - been flagged as verifiable. - - - This example sets up an expectation without marking it as verifiable. After - the mock is used, a call is issued on the mock - to ensure that all expectations are met: - - var mock = new Mock<IWarehouse>(); - this.Setup(x => x.HasInventory(TALISKER, 50)).Returns(true); - ... - // other test code - ... - // Will throw if the test code has didn't call HasInventory, even - // that expectation was not marked as verifiable. - this.VerifyAll(); - - - At least one expectation was not met. - - - - Gets the interceptor target for the given expression and root mock, - building the intermediate hierarchy of mock objects if necessary. - - - - - Creates a handler that can be associated to an event receiving - the given and can be used - to raise the event. - - Type of - data passed in to the event. - - This example shows how to invoke an event with a custom event arguments - class in a view that will cause its corresponding presenter to - react by changing its state: - - var mockView = new Mock<IOrdersView>(); - var mockedEvent = mockView.CreateEventHandler<OrderEventArgs>(); - - var presenter = new OrdersPresenter(mockView.Object); - - // Check that the presenter has no selection by default - Assert.Null(presenter.SelectedOrder); - - // Create a mock event handler of the appropriate type - var handler = mockView.CreateEventHandler<OrderEventArgs>(); - // Associate it with the event we want to raise - mockView.Object.Cancel += handler; - // Finally raise the event with a specific arguments data - handler.Raise(new OrderEventArgs { Order = new Order("moq", 500) }); - - // Now the presenter reacted to the event, and we have a selected order - Assert.NotNull(presenter.SelectedOrder); - Assert.Equal("moq", presenter.SelectedOrder.ProductName); - - - - - - Creates a handler that can be associated to an event receiving - a generic and can be used - to raise the event. - - - This example shows how to invoke a generic event in a view that will - cause its corresponding presenter to react by changing its state: - - var mockView = new Mock<IOrdersView>(); - var mockedEvent = mockView.CreateEventHandler(); - - var presenter = new OrdersPresenter(mockView.Object); - - // Check that the presenter is not in the "Canceled" state - Assert.False(presenter.IsCanceled); - - // Create a mock event handler of the appropriate type - var handler = mockView.CreateEventHandler(); - // Associate it with the event we want to raise - mockView.Object.Cancel += handler; - // Finally raise the event - handler.Raise(EventArgs.Empty); - - // Now the presenter reacted to the event, and changed its state - Assert.True(presenter.IsCanceled); - - - - - - Exposes the list of extra interfaces implemented by the mock. - - - - - Behavior of the mock, according to the value set in the constructor. - - - - - Whether the base member virtual implementation will be called - for mocked classes if no setup is matched. Defaults to . - - - - - Specifies the behavior to use when returning default values for - unexpected invocations on loose mocks. - - - - - Specifies the class that will determine the default - value to return when invocations are made that - have no setups and need to return a default - value (for loose mocks). - - - - - Gets the mocked object instance. - - - - - Retrieves the type of the mocked object, its generic type argument. - This is used in the auto-mocking of hierarchy access. - - - - - Base class for visitors of expression trees. - - - Provides the functionality of the internal visitor base class that - comes with Linq. - Matt's comments on the implementation: - - In this variant there is only one visitor class that dispatches calls to the general - Visit function out to specific VisitXXX methods corresponding to different node types. - Note not every node type gets it own method, for example all binary operators are - treated in one VisitBinary method. The nodes themselves do not directly participate - in the visitation process. They are treated as just data. - The reason for this is that the quantity of visitors is actually open ended. - You can write your own. Therefore no semantics of visiting is coupled into the node classes. - It’s all in the visitors. The default visit behavior for node XXX is baked into the base - class’s version of VisitXXX. - - - Another variant is that all VisitXXX methods return a node. - The Expression tree nodes are immutable. In order to change the tree you must construct - a new one. The default VisitXXX methods will construct a new node if any of its sub-trees change. - If no changes are made then the same node is returned. That way if you make a change - to a node (by making a new node) deep down in a tree, the rest of the tree is rebuilt - automatically for you. - - See: http://blogs.msdn.com/mattwar/archive/2007/07/31/linq-building-an-iqueryable-provider-part-ii.aspx. - - Matt Warren: http://blogs.msdn.com/mattwar - Documented by InSTEDD: http://www.instedd.org - - - - Default constructor used by derived visitors. - - - - - Visits the , determining which - of the concrete Visit methods to call. - - - - - Visits the generic , determining and - calling the appropriate Visit method according to the - , which will result - in calls to , - or . - - - - - - - Visits the initializer by - calling the for the - . - - - - - Visits the expression by - calling with the expression. - - - - - Visits the by calling - with the , - and - expressions. - - - - - Visits the by calling - with the - expression. - - - - - Visits the , by default returning the - same without further behavior. - - - - - Visits the by calling - with the , - and - expressions. - - - - - Visits the returning it - by default without further behavior. - - - - - Visits the by calling - with the - expression. - - - - - Visits the by calling - with the expression, - and then with the . - - - - - - - Visits the by iterating - the list and visiting each in it. - - - - - - - Visits the by calling - with the expression. - - - - - - - Visits the by calling - with the . - - - - - - - Visits the by calling - with the - . - - - - - - - Visits the by - calling for each in the - collection. - - - - - - - Visits the by - calling for each - in the collection. - - - - - - - Visits the by calling - with the expression. - - - - - - - Visits the by calling - with the - expressions. - - - - - - - Visits the by calling - with the - expression, then with the - . - - - - - Visits the by calling - with the - expression, and then with the - . - - - - - - - Visits the by calling - with the - expressions. - - - - - - - Visits the by calling - with the - expressions. - - - - - - - Sets an expectation on the mocked type for a call to - to a void method. - - - If more than one expectation is set for the same method or property, - the latest one wins and is the one that will be executed. - - Lambda expression that specifies the expected method invocation. - - - var mock = new Mock<IProcessor>(); - this.Setup(x => x.Execute("ping")); - - - - - - Sets an expectation on the mocked type for a call to - to a value returning method. - - Type of the return value. Typically omitted as it can be inferred from the expression. - - If more than one expectation is set for the same method or property, - the latest one wins and is the one that will be executed. - - Lambda expression that specifies the expected method invocation. - - - this.Setup(x => x.HasInventory("Talisker", 50)).Returns(true); - - - - - - Sets an expectation on the mocked type for a call to - to a property getter. - - - If more than one expectation is set for the same property getter, - the latest one wins and is the one that will be executed. - - Type of the property. Typically omitted as it can be inferred from the expression. - Lambda expression that specifies the expected property getter. - - - this.SetupGet(x => x.Suspended) - .Returns(true); - - - - - - Sets an expectation on the mocked type for a call to - to a property setter. - - - If more than one expectation is set for the same property setter, - the latest one wins and is the one that will be executed. - - Type of the property. Typically omitted as it can be inferred from the expression. - Lambda expression that specifies the expected property setter. - - - this.SetupSet(x => x.Suspended); - - - - - - Sets an expectation on the mocked type for a call to - to a property setter with a specific value. - - - More than one expectation can be set for the setter with - different values. - - Type of the property. Typically omitted as it can be inferred from the expression. - Lambda expression that specifies the expected property setter. - The value expected to be set for the property. - - - this.SetupSet(x => x.Suspended, true); - - - - - - Ctor invoked by AsTInterface exclusively. - - - - - Initializes an instance of the mock with default behavior and with - the given constructor arguments for the class. (Only valid when is a class) - - - The mock will try to find the best match constructor given the constructor arguments, and invoke that - to initialize the instance. This applies only for classes, not interfaces. - - - var mock = new Mock<MyProvider>(someArgument, 25); - - Optional constructor arguments if the mocked type is a class. - - - - Initializes an instance of the mock with default behavior. - - - var mock = new Mock<IFormatProvider>(); - - - - - Initializes an instance of the mock with the specified behavior. - - - var mock = new Mock<IFormatProvider>(MockBehavior.Relaxed); - - Behavior of the mock. - - - - Initializes an instance of the mock with a specific behavior with - the given constructor arguments for the class. - - - The mock will try to find the best match constructor given the constructor arguments, and invoke that - to initialize the instance. This applies only to classes, not interfaces. - - - var mock = new Mock<MyProvider>(someArgument, 25); - - Behavior of the mock. - Optional constructor arguments if the mocked type is a class. - - - - Returns the mocked object value. - - - - - Specifies a setup on the mocked type for a call to - to a void method. - - - If more than one setup is specified for the same method or property, - the latest one wins and is the one that will be executed. - - Lambda expression that specifies the expected method invocation. - - - var mock = new Mock<IProcessor>(); - mock.Setup(x => x.Execute("ping")); - - - - - - Specifies a setup on the mocked type for a call to - to a value returning method. - - Type of the return value. Typically omitted as it can be inferred from the expression. - - If more than one setup is specified for the same method or property, - the latest one wins and is the one that will be executed. - - Lambda expression that specifies the method invocation. - - - mock.Setup(x => x.HasInventory("Talisker", 50)).Returns(true); - - - - - - Specifies a setup on the mocked type for a call to - to a property getter. - - - If more than one setup is set for the same property getter, - the latest one wins and is the one that will be executed. - - Type of the property. Typically omitted as it can be inferred from the expression. - Lambda expression that specifies the property getter. - - - mock.SetupGet(x => x.Suspended) - .Returns(true); - - - - - - Specifies a setup on the mocked type for a call to - to a property setter. - - - If more than one setup is set for the same property setter, - the latest one wins and is the one that will be executed. - - This overloads allows the use of a callback already - typed for the property type. - - - Type of the property. Typically omitted as it can be inferred from the expression. - Lambda expression that sets a property to a value. - - - mock.SetupSet(x => x.Suspended = true); - - - - - - Specifies a setup on the mocked type for a call to - to a property setter. - - - If more than one setup is set for the same property setter, - the latest one wins and is the one that will be executed. - - Lambda expression that sets a property to a value. - - - mock.SetupSet(x => x.Suspended = true); - - - - - - Specifies that the given property should have "property behavior", - meaning that setting its value will cause it to be saved and - later returned when the property is requested. (this is also - known as "stubbing"). - - Type of the property, inferred from the property - expression (does not need to be specified). - Property expression to stub. - - If you have an interface with an int property Value, you might - stub it using the following straightforward call: - - var mock = new Mock<IHaveValue>(); - mock.Stub(v => v.Value); - - After the Stub call has been issued, setting and - retrieving the object value will behave as expected: - - IHaveValue v = mock.Object; - - v.Value = 5; - Assert.Equal(5, v.Value); - - - - - - Specifies that the given property should have "property behavior", - meaning that setting its value will cause it to be saved and - later returned when the property is requested. This overload - allows setting the initial value for the property. (this is also - known as "stubbing"). - - Type of the property, inferred from the property - expression (does not need to be specified). - Property expression to stub. - Initial value for the property. - - If you have an interface with an int property Value, you might - stub it using the following straightforward call: - - var mock = new Mock<IHaveValue>(); - mock.SetupProperty(v => v.Value, 5); - - After the SetupProperty call has been issued, setting and - retrieving the object value will behave as expected: - - IHaveValue v = mock.Object; - // Initial value was stored - Assert.Equal(5, v.Value); - - // New value set which changes the initial value - v.Value = 6; - Assert.Equal(6, v.Value); - - - - - - Specifies that the all properties on the mock should have "property behavior", - meaning that setting its value will cause it to be saved and - later returned when the property is requested. (this is also - known as "stubbing"). The default value for each property will be the - one generated as specified by the property for the mock. - - - If the mock is set to , - the mocked default values will also get all properties setup recursively. - - - - - Verifies that a specific invocation matching the given expression was performed on the mock. Use - in conjuntion with the default . - - - This example assumes that the mock has been used, and later we want to verify that a given - invocation with specific parameters was performed: - - var mock = new Mock<IProcessor>(); - // exercise mock - //... - // Will throw if the test code didn't call Execute with a "ping" string argument. - mock.Verify(proc => proc.Execute("ping")); - - - The invocation was not performed on the mock. - Expression to verify. - - - - Verifies that a specific invocation matching the given expression was performed on the mock. Use - in conjuntion with the default . - - The invocation was not call the times specified by - . - Expression to verify. - The times a method is allowed to be called. - - - - Verifies that a specific invocation matching the given expression was performed on the mock, - specifying a failure error message. Use in conjuntion with the default - . - - - This example assumes that the mock has been used, and later we want to verify that a given - invocation with specific parameters was performed: - - var mock = new Mock<IProcessor>(); - // exercise mock - //... - // Will throw if the test code didn't call Execute with a "ping" string argument. - mock.Verify(proc => proc.Execute("ping")); - - - The invocation was not performed on the mock. - Expression to verify. - Message to show if verification fails. - - - - Verifies that a specific invocation matching the given expression was performed on the mock, - specifying a failure error message. Use in conjuntion with the default - . - - The invocation was not call the times specified by - . - Expression to verify. - The times a method is allowed to be called. - Message to show if verification fails. - - - - Verifies that a specific invocation matching the given expression was performed on the mock. Use - in conjuntion with the default . - - - This example assumes that the mock has been used, and later we want to verify that a given - invocation with specific parameters was performed: - - var mock = new Mock<IWarehouse>(); - // exercise mock - //... - // Will throw if the test code didn't call HasInventory. - mock.Verify(warehouse => warehouse.HasInventory(TALISKER, 50)); - - - The invocation was not performed on the mock. - Expression to verify. - Type of return value from the expression. - - - - Verifies that a specific invocation matching the given - expression was performed on the mock. Use in conjuntion - with the default . - - The invocation was not call the times specified by - . - Expression to verify. - The times a method is allowed to be called. - Type of return value from the expression. - - - - Verifies that a specific invocation matching the given - expression was performed on the mock, specifying a failure - error message. - Use in conjuntion with the default . - - - This example assumes that the mock has been used, - and later we want to verify that a given invocation - with specific parameters was performed: - - var mock = new Mock<IWarehouse>(); - // exercise mock - //... - // Will throw if the test code didn't call HasInventory. - mock.Verify(warehouse => warehouse.HasInventory(TALISKER, 50), "When filling orders, inventory has to be checked"); - - - The invocation was not performed on the mock. - Expression to verify. - Message to show if verification fails. - Type of return value from the expression. - - - - Verifies that a specific invocation matching the given - expression was performed on the mock, specifying a failure - error message. - Use in conjuntion with the default . - - The invocation was not call the times specified by - . - Expression to verify. - The times a method is allowed to be called. - Message to show if verification fails. - Type of return value from the expression. - - - - Verifies that a property was read on the mock. - Use in conjuntion with the default . - - - This example assumes that the mock has been used, - and later we want to verify that a given property - was retrieved from it: - - var mock = new Mock<IWarehouse>(); - // exercise mock - //... - // Will throw if the test code didn't retrieve the IsClosed property. - mock.VerifyGet(warehouse => warehouse.IsClosed); - - - The invocation was not performed on the mock. - Expression to verify. - Type of the property to verify. Typically omitted as it can - be inferred from the expression's return type. - - - - Verifies that a property was read on the mock. - Use in conjuntion with the default . - - The invocation was not call the times specified by - . - The times a method is allowed to be called. - Expression to verify. - Type of the property to verify. Typically omitted as it can - be inferred from the expression's return type. - - - - Verifies that a property was read on the mock, specifying a failure - error message. - Use in conjuntion with the default . - - - This example assumes that the mock has been used, - and later we want to verify that a given property - was retrieved from it: - - var mock = new Mock<IWarehouse>(); - // exercise mock - //... - // Will throw if the test code didn't retrieve the IsClosed property. - mock.VerifyGet(warehouse => warehouse.IsClosed); - - - The invocation was not performed on the mock. - Expression to verify. - Message to show if verification fails. - Type of the property to verify. Typically omitted as it can - be inferred from the expression's return type. - - - - Verifies that a property was read on the mock, specifying a failure - error message. - Use in conjuntion with the default . - - The invocation was not call the times specified by - . - The times a method is allowed to be called. - Expression to verify. - Message to show if verification fails. - Type of the property to verify. Typically omitted as it can - be inferred from the expression's return type. - - - - Verifies that a property was set on the mock. - Use in conjuntion with the default . - - - This example assumes that the mock has been used, - and later we want to verify that a given property - was set on it: - - var mock = new Mock<IWarehouse>(); - // exercise mock - //... - // Will throw if the test code didn't set the IsClosed property. - mock.VerifySet(warehouse => warehouse.IsClosed = true); - - - The invocation was not performed on the mock. - Expression to verify. - - - - Verifies that a property was set on the mock. - Use in conjuntion with the default . - - The invocation was not call the times specified by - . - The times a method is allowed to be called. - Expression to verify. - - - - Verifies that a property was set on the mock, specifying - a failure message. - Use in conjuntion with the default . - - - This example assumes that the mock has been used, - and later we want to verify that a given property - was set on it: - - var mock = new Mock<IWarehouse>(); - // exercise mock - //... - // Will throw if the test code didn't set the IsClosed property. - mock.VerifySet(warehouse => warehouse.IsClosed = true, "Warehouse should always be closed after the action"); - - - The invocation was not performed on the mock. - Expression to verify. - Message to show if verification fails. - - - - Verifies that a property was set on the mock, specifying - a failure message. - Use in conjuntion with the default . - - The invocation was not call the times specified by - . - The times a method is allowed to be called. - Expression to verify. - Message to show if verification fails. - - - - Adds an interface implementation to the mock, - allowing setups to be specified for it. - - - This method can only be called before the first use - of the mock property, at which - point the runtime type has already been generated - and no more interfaces can be added to it. - - Also, must be an - interface and not a class, which must be specified - when creating the mock instead. - - - The mock type - has already been generated by accessing the property. - The specified - is not an interface. - - The following example creates a mock for the main interface - and later adds to it to verify - it's called by the consumer code: - - var mock = new Mock<IProcessor>(); - mock.Setup(x => x.Execute("ping")); - - // add IDisposable interface - var disposable = mock.As<IDisposable>(); - disposable.Setup(d => d.Dispose()).Verifiable(); - - - Type of interface to cast the mock to. - - - - Raises the event referenced in using - the given and arguments. - - The arguments are - invalid for the target event invocation, or the is - not an event attach or detach expression. - - The following example shows how to raise a event: - - var mock = new Mock<IViewModel>(); - - mock.Raise(x => x.PropertyChanged -= null, new PropertyChangedEventArgs("Name")); - - - - This example shows how to invoke an event with a custom event arguments - class in a view that will cause its corresponding presenter to - react by changing its state: - - var mockView = new Mock<IOrdersView>(); - var presenter = new OrdersPresenter(mockView.Object); - - // Check that the presenter has no selection by default - Assert.Null(presenter.SelectedOrder); - - // Raise the event with a specific arguments data - mockView.Raise(v => v.SelectionChanged += null, new OrderEventArgs { Order = new Order("moq", 500) }); - - // Now the presenter reacted to the event, and we have a selected order - Assert.NotNull(presenter.SelectedOrder); - Assert.Equal("moq", presenter.SelectedOrder.ProductName); - - - - - - Exposes the mocked object instance. - - - - - Holds extensions that would cause conflicts with new APIs if available - in the core Moq namespace (even if hidden), such as the SetupSet legacy - members. - - - - - Specifies a setup on the mocked type for a call to - to a property setter. - - - If more than one setup is set for the same property setter, - the latest one wins and is the one that will be executed. - - Type of the property. Typically omitted as it can be inferred from the expression. - Type of the mock. - The target mock for the setup. - Lambda expression that specifies the property setter. - - - mock.SetupSet(x => x.Suspended); - - - - - - Specifies a setup on the mocked type for a call to - to a property setter with a specific value. - - - More than one setup can be set for the setter with - different values. - - Type of the property. Typically omitted as it can be inferred from the expression. - Type of the mock. - The target mock for the setup. - Lambda expression that specifies the property setter. - The value to be set for the property. - - - mock.SetupSet(x => x.Suspended, true); - - - - - - Verifies that a property has been set on the mock. - Use in conjuntion with the default . - - - This example assumes that the mock has been used, - and later we want to verify that a given invocation - with specific parameters was performed: - - var mock = new Mock<IWarehouse>(); - // exercise mock - //... - // Will throw if the test code didn't set the IsClosed property. - mock.VerifySet(warehouse => warehouse.IsClosed); - - - The invocation was not performed on the mock. - Expression to verify. - The mock instance. - Mocked type. - Type of the property to verify. Typically omitted as it can - be inferred from the expression's return type. - - - - Verifies that a property has been set on the mock to the given value. - Use in conjuntion with the default . - - - This example assumes that the mock has been used, - and later we want to verify that a given invocation - with specific parameters was performed: - - var mock = new Mock<IWarehouse>(); - // exercise mock - //... - // Will throw if the test code didn't set the IsClosed property to true - mock.VerifySet(warehouse => warehouse.IsClosed, true); - - - The invocation was not performed on the mock. - Expression to verify. - The value that should have been set on the property. - The mock instance. - Mocked type. - Type of the property to verify. Typically omitted as it can - be inferred from the expression's return type. - - - - Verifies that a property has been set on the mock, specifying a failure - error message. - Use in conjuntion with the default . - - - This example assumes that the mock has been used, - and later we want to verify that a given invocation - with specific parameters was performed: - - var mock = new Mock<IWarehouse>(); - // exercise mock - //... - // Will throw if the test code didn't set the IsClosed property. - mock.VerifySet(warehouse => warehouse.IsClosed); - - - The invocation was not performed on the mock. - Expression to verify. - Message to show if verification fails. - The mock instance. - Mocked type. - Type of the property to verify. Typically omitted as it can - be inferred from the expression's return type. - - - - Verifies that a property has been set on the mock to the given value, specifying a failure - error message. - Use in conjuntion with the default . - - - This example assumes that the mock has been used, - and later we want to verify that a given invocation - with specific parameters was performed: - - var mock = new Mock<IWarehouse>(); - // exercise mock - //... - // Will throw if the test code didn't set the IsClosed property to true - mock.VerifySet(warehouse => warehouse.IsClosed, true); - - - The invocation was not performed on the mock. - Expression to verify. - The value that should have been set on the property. - Message to show if verification fails. - The mock instance. - Mocked type. - Type of the property to verify. Typically omitted as it can - be inferred from the expression's return type. - - - - Provides partial evaluation of subtrees, whenever they can be evaluated locally. - - Matt Warren: http://blogs.msdn.com/mattwar - Documented by InSTEDD: http://www.instedd.org - - - - Performs evaluation and replacement of independent sub-trees - - The root of the expression tree. - A function that decides whether a given expression - node can be part of the local function. - A new tree with sub-trees evaluated and replaced. - - - - Performs evaluation and replacement of independent sub-trees - - The root of the expression tree. - A new tree with sub-trees evaluated and replaced. - - - - Evaluates and replaces sub-trees when first candidate is reached (top-down) - - - - - Performs bottom-up analysis to determine which nodes can possibly - be part of an evaluated sub-tree. - - - - - Marks a method as a matcher, which allows complete replacement - of the built-in class with your own argument - matching rules. - - - The argument matching is used to determine whether a concrete - invocation in the mock matches a given setup. This - matching mechanism is fully extensible. - - There are two parts of a matcher: the compiler matcher - and the runtime matcher. - - - Compiler matcher - Used to satisfy the compiler requirements for the - argument. Needs to be a method optionally receiving any arguments - you might need for the matching, but with a return type that - matches that of the argument. - - Let's say I want to match a lists of orders that contains - a particular one. I might create a compiler matcher like the following: - - - public static class Orders - { - [Matcher] - public static IEnumerable<Order> Contains(Order order) - { - return null; - } - } - - Now we can invoke this static method instead of an argument in an - invocation: - - var order = new Order { ... }; - var mock = new Mock<IRepository<Order>>(); - - mock.Setup(x => x.Save(Orders.Contains(order))) - .Throws<ArgumentException>(); - - Note that the return value from the compiler matcher is irrelevant. - This method will never be called, and is just used to satisfy the - compiler and to signal Moq that this is not a method that we want - to be invoked at runtime. - - - - Runtime matcher - - The runtime matcher is the one that will actually perform evaluation - when the test is run, and is defined by convention to have the - same signature as the compiler matcher, but where the return - value is the first argument to the call, which contains the - object received by the actual invocation at runtime: - - public static bool Contains(IEnumerable<Order> orders, Order order) - { - return orders.Contains(order); - } - - At runtime, the mocked method will be invoked with a specific - list of orders. This value will be passed to this runtime - matcher as the first argument, while the second argument is the - one specified in the setup (x.Save(Orders.Contains(order))). - - The boolean returned determines whether the given argument has been - matched. If all arguments to the expected method are matched, then - the setup matches and is evaluated. - - - - - - Using this extensible infrastructure, you can easily replace the entire - set of matchers with your own. You can also avoid the - typical (and annoying) lengthy expressions that result when you have - multiple arguments that use generics. - - - The following is the complete example explained above: - - public static class Orders - { - [Matcher] - public static IEnumerable<Order> Contains(Order order) - { - return null; - } - - public static bool Contains(IEnumerable<Order> orders, Order order) - { - return orders.Contains(order); - } - } - - And the concrete test using this matcher: - - var order = new Order { ... }; - var mock = new Mock<IRepository<Order>>(); - - mock.Setup(x => x.Save(Orders.Contains(order))) - .Throws<ArgumentException>(); - - // use mock, invoke Save, and have the matcher filter. - - - - - - Defines the Callback verb for property getter setups. - - - Mocked type. - Type of the property. - - - - Specifies a callback to invoke when the property is retrieved. - - Callback method to invoke. - - Invokes the given callback with the property value being set. - - mock.SetupGet(x => x.Suspended) - .Callback(() => called = true) - .Returns(true); - - - - - - Matcher to treat static functions as matchers. - - mock.Setup(x => x.StringMethod(A.MagicString())); - - pbulic static class A - { - [Matcher] - public static string MagicString() { return null; } - public static bool MagicString(string arg) - { - return arg == "magic"; - } - } - - Will success if: mock.Object.StringMethod("magic"); - and fail with any other call. - - - - - We need this non-generics base class so that - we can use from - generic code. - - - - - Implements the fluent API. - - - - - Implements the fluent API. - - - - - Implements the fluent API. - - - - - Defines the Callback verb and overloads for callbacks on - setups that return a value. - - Mocked type. - Type of the return value of the setup. - - - - Specifies a callback to invoke when the method is called. - - Callback method to invoke. - - The following example specifies a callback to set a boolean - value that can be used later: - - bool called = false; - mock.Setup(x => x.Execute()) - .Callback(() => called = true) - .Returns(true); - - Note that in the case of value-returning methods, after the Callback - call you can still specify the return value. - - - - - Specifies a callback to invoke when the method is called that receives the original - arguments. - - Type of the argument of the invoked method. - Callback method to invoke. - - Invokes the given callback with the concrete invocation argument value. - - Notice how the specific string argument is retrieved by simply declaring - it as part of the lambda expression for the callback: - - - mock.Setup(x => x.Execute(It.IsAny<string>())) - .Callback((string command) => Console.WriteLine(command)) - .Returns(true); - - - - - - Specifies a callback to invoke when the method is called that receives the original - arguments. - - Type of the first argument of the invoked method. - Type of the second argument of the invoked method. - Callback method to invoke. - - Invokes the given callback with the concrete invocation arguments values. - - Notice how the specific arguments are retrieved by simply declaring - them as part of the lambda expression for the callback: - - - mock.Setup(x => x.Execute( - It.IsAny<string>(), - It.IsAny<string>())) - .Callback((string arg1, string arg2) => Console.WriteLine(arg1 + arg2)) - .Returns(true); - - - - - - Specifies a callback to invoke when the method is called that receives the original - arguments. - - Type of the first argument of the invoked method. - Type of the second argument of the invoked method. - Type of the third argument of the invoked method. - Callback method to invoke. - - Invokes the given callback with the concrete invocation arguments values. - - Notice how the specific arguments are retrieved by simply declaring - them as part of the lambda expression for the callback: - - - mock.Setup(x => x.Execute( - It.IsAny<string>(), - It.IsAny<string>(), - It.IsAny<int>())) - .Callback((string arg1, string arg2, int arg3) => Console.WriteLine(arg1 + arg2 + arg3)) - .Returns(true); - - - - - - Specifies a callback to invoke when the method is called that receives the original - arguments. - - Type of the first argument of the invoked method. - Type of the second argument of the invoked method. - Type of the third argument of the invoked method. - Type of the fourth argument of the invoked method. - Callback method to invoke. - - Invokes the given callback with the concrete invocation arguments values. - - Notice how the specific arguments are retrieved by simply declaring - them as part of the lambda expression for the callback: - - - mock.Setup(x => x.Execute( - It.IsAny<string>(), - It.IsAny<string>(), - It.IsAny<int>(), - It.IsAny<bool>())) - .Callback((string arg1, string arg2, int arg3, bool arg4) => Console.WriteLine(arg1 + arg2 + arg3 + arg4)) - .Returns(true); - - - - - - Implements the fluent API. - - - - - Defines the Never verb. - - - - - The expected invocation is never expected to happen. - - - - var mock = new Mock<ICommand>(); - mock.Setup(foo => foo.Execute("ping")) - .Never(); - - - - is always verified inmediately as - the invocations are performed, like strict mocks do - with unexpected invocations. - - - - - Implements the fluent API. - - - - - Implements the fluent API. - - - - - Defines the Returns verb for property get setups. - - Mocked type. - Type of the property. - - - - Specifies the value to return. - - The value to return, or . - - Return a true value from the property getter call: - - mock.SetupGet(x => x.Suspended) - .Returns(true); - - - - - - Specifies a function that will calculate the value to return for the property. - - The function that will calculate the return value. - - Return a calculated value when the property is retrieved: - - mock.SetupGet(x => x.Suspended) - .Returns(() => returnValues[0]); - - The lambda expression to retrieve the return value is lazy-executed, - meaning that its value may change depending on the moment the property - is retrieved and the value the returnValues array has at - that moment. - - - - - A that returns an empty default value - for non-mockeable types, and mocks for all other types (interfaces and - non-sealed classes) that can be mocked. - - - - - A that returns an empty default value - for invocations that do not have setups or return values, with loose mocks. - This is the default behavior for a mock. - - - - - Kind of range to use in a filter specified through - . - - - - - The range includes the to and - from values. - - - - - The range does not include the to and - from values. - - - - - Exception thrown by mocks when setups are not matched, - the mock is not properly setup, etc. - - - A distinct exception type is provided so that exceptions - thrown by the mock can be differentiated in tests that - expect other exceptions to be thrown (i.e. ArgumentException). - - Richer exception hierarchy/types are not provided as - tests typically should not catch or expect exceptions - from the mocks. These are typically the result of changes - in the tested class or its collaborators implementation, and - result in fixes in the mock setup so that they dissapear and - allow the test to pass. - - - - - - Supports the serialization infrastructure. - - Serialization information. - Streaming context. - - - - Supports the serialization infrastructure. - - Serialization information. - Streaming context. - - - - Made internal as it's of no use for - consumers, but it's important for - our own tests. - - - - - Used by the mock factory to accumulate verification - failures. - - - - - Supports the serialization infrastructure. - - - - - Options to customize the behavior of the mock. - - - - - Causes the mock to always throw - an exception for invocations that don't have a - corresponding setup. - - - - - Will never throw exceptions, returning default - values when necessary (null for reference types, - zero for value types or empty enumerables and arrays). - - - - - Default mock behavior, which equals . - - - - - Implements the fluent API. - - - - - A strongly-typed resource class, for looking up localized strings, etc. - - - - - Returns the cached ResourceManager instance used by this class. - - - - - Overrides the current thread's CurrentUICulture property for all - resource lookups using this strongly typed resource class. - - - - - Looks up a localized string similar to Mock type has already been initialized by accessing its Object property. Adding interfaces must be done before that.. - - - - - Looks up a localized string similar to Value cannot be an empty string.. - - - - - Looks up a localized string similar to Can only add interfaces to the mock.. - - - - - Looks up a localized string similar to Can't set return value for void method {0}.. - - - - - Looks up a localized string similar to Constructor arguments cannot be passed for interface mocks.. - - - - - Looks up a localized string similar to A matching constructor for the given arguments was not found on the mocked type.. - - - - - Looks up a localized string similar to Expression {0} involves a field access, which is not supported. Use properties instead.. - - - - - Looks up a localized string similar to Type to mock must be an interface or an abstract or non-sealed class. . - - - - - Looks up a localized string similar to Cannot retrieve a mock with the given object type {0} as it's not the main type of the mock or any of its additional interfaces. - Please cast the argument to one of the supported types: {1}. - Remember that there's no generics covariance in the CLR, so your object must be one of these types in order for the call to succeed.. - - - - - Looks up a localized string similar to Member {0}.{1} does not exist.. - - - - - Looks up a localized string similar to Method {0}.{1} is public. Use strong-typed Expect overload instead: - mock.Setup(x => x.{1}()); - . - - - - - Looks up a localized string similar to {0} invocation failed with mock behavior {1}. - {2}. - - - - - Looks up a localized string similar to Expected only {0} calls to {1}.. - - - - - Looks up a localized string similar to Expected only one call to {0}.. - - - - - Looks up a localized string similar to {0} - Invocation was performed on the mock less than {2} times: {1}. - - - - - Looks up a localized string similar to {0} - Invocation was not performed on the mock: {1}. - - - - - Looks up a localized string similar to {0} - Invocation was performed on the mock more than {3} times: {1}. - - - - - Looks up a localized string similar to {0} - Invocation was performed on the mock more than a time: {1}. - - - - - Looks up a localized string similar to {0} - Invocation was performed on the mock less or equal than {2} times or more or equal than {3} times: {1}. - - - - - Looks up a localized string similar to {0} - Invocation was performed on the mock less than {2} times or more than {3} times: {1}. - - - - - Looks up a localized string similar to {0} - Invocation was not performed on the mock {2} times: {1}. - - - - - Looks up a localized string similar to {0} - Invocation was performed on the mock: {1}. - - - - - Looks up a localized string similar to All invocations on the mock must have a corresponding setup.. - - - - - Looks up a localized string similar to Object instance was not created by Moq.. - - - - - Looks up a localized string similar to Property {0}.{1} does not exist.. - - - - - Looks up a localized string similar to Property {0}.{1} is write-only.. - - - - - Looks up a localized string similar to Property {0}.{1} is read-only.. - - - - - Looks up a localized string similar to Cannot raise a mocked event unless it has been associated (attached) to a concrete event in a mocked object.. - - - - - Looks up a localized string similar to Invocation needs to return a value and therefore must have a corresponding setup that provides it.. - - - - - Looks up a localized string similar to A lambda expression is expected as the argument to It.Is<T>.. - - - - - Looks up a localized string similar to Invocation {0} should not have been made.. - - - - - Looks up a localized string similar to Expression is not a method invocation: {0}. - - - - - Looks up a localized string similar to Expression is not a property access: {0}. - - - - - Looks up a localized string similar to Expression is not a property setter invocation.. - - - - - Looks up a localized string similar to Invalid setup on a non-overridable member: - {0}. - - - - - Looks up a localized string similar to Type {0} does not implement required interface {1}. - - - - - Looks up a localized string similar to Type {0} does not from required type {1}. - - - - - Looks up a localized string similar to To specify a setup for public property {0}.{1}, use the typed overloads, such as: - mock.Setup(x => x.{1}).Returns(value); - mock.SetupGet(x => x.{1}).Returns(value); //equivalent to previous one - mock.SetupSet(x => x.{1}).Callback(callbackDelegate); - . - - - - - Looks up a localized string similar to Expression {0} is not supported.. - - - - - Looks up a localized string similar to Only property accesses are supported in intermediate invocations on a setup. Unsupported expression {0}.. - - - - - Looks up a localized string similar to Expression contains intermediate property access {0}.{1} which is of type {2} and cannot be mocked. Unsupported expression {3}.. - - - - - Looks up a localized string similar to Setter expression cannot use argument matchers that receive parameters.. - - - - - Looks up a localized string similar to Member {0} is not supported for protected mocking.. - - - - - Looks up a localized string similar to Setter expression can only use static custom matchers.. - - - - - Looks up a localized string similar to To specify a setup for protected property {0}.{1}, use: - mock.Setup<{2}>(x => x.{1}).Returns(value); - mock.SetupGet(x => x.{1}).Returns(value); //equivalent to previous one - mock.SetupSet(x => x.{1}).Callback(callbackDelegate);. - - - - - Looks up a localized string similar to The following setups were not matched: - {0}. - - - - - Defines the number of invocations allowed by a mocked method. - - - - - Specifies that a mocked method should be invoked times as minimum. - - The minimun number of times. - An object defining the allowed number of invocations. - - - - Specifies that a mocked method should be invoked one time as minimum. - - An object defining the allowed number of invocations. - - - - Specifies that a mocked method should be invoked time as maximun. - - The maximun number of times. - An object defining the allowed number of invocations. - - - - Specifies that a mocked method should be invoked one time as maximun. - - An object defining the allowed number of invocations. - - - - Specifies that a mocked method should be invoked between and - times. - - The minimun number of times. - The maximun number of times. - The kind of range. See . - An object defining the allowed number of invocations. - - - - Specifies that a mocked method should be invoked exactly times. - - The times that a method or property can be called. - An object defining the allowed number of invocations. - - - - Specifies that a mocked method should not be invoked. - - An object defining the allowed number of invocations. - - - - Determines the way default values are generated - calculated for loose mocks. - - - - - Default behavior, which generates empty values for - value types (i.e. default(int)), empty array and - enumerables, and nulls for all other reference types. - - - - - Whenever the default value generated by - is null, replaces this value with a mock (if the type - can be mocked). - - - For sealed classes, a null value will be generated. - - - - - Allows setups to be specified for protected members by using their - name as a string, rather than strong-typing them which is not possible - due to their visibility. - - - - - Specifies a setup for a void method invocation with the given - , optionally specifying - arguments for the method call. - - Name of the void method to be invoke. - Optional arguments for the invocation. If argument matchers are used, - remember to use rather than . - - - - Specifies a setup for an invocation on a property or a non void method with the given - , optionally specifying - arguments for the method call. - - Name of the method or property to be invoke. - Optional arguments for the invocation. If argument matchers are used, - remember to use rather than . - Return type of the method or property. - - - - Specifies a setup for an invocation on a property getter with the given - . - - Name of the property. - Type of the property. - - - - Specifies a setup for an invocation on a property setter with the given - . - - Name of the property. - Type of the property. - - - - Implements the actual interception and method invocation for - all mocks. - - - - - Get an eventInfo for a given event name. Search type ancestors depth first if necessary. - - Name of the event, with the set_ or get_ prefix already removed - - - - Given a type return all of its ancestors, both types and interfaces. - - The type to find immediate ancestors of - - - - Casts the expression to a lambda expression, removing - a cast if there's any. - - - - - Casts the body of the lambda expression to a . - - If the body is not a method call. - - - - Converts the body of the lambda expression into the referenced by it. - - - - - Checks whether the body of the lambda expression is a property access. - - - - - Checks whether the expression is a property access. - - - - - Checks whether the body of the lambda expression is a property indexer, which is true - when the expression is an whose - has - equal to . - - - - - Checks whether the expression is a property indexer, which is true - when the expression is an whose - has - equal to . - - - - - Creates an expression that casts the given expression to the - type. - - - - - TODO: remove this code when https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=331583 - is fixed. - - - - - Implements the fluent API. - - - - - Defines the Callback verb for property setter setups. - - Type of the property. - - - - Specifies a callback to invoke when the property is set that receives the - property value being set. - - Callback method to invoke. - - Invokes the given callback with the property value being set. - - mock.SetupSet(x => x.Suspended) - .Callback((bool state) => Console.WriteLine(state)); - - - - - - Tracks the current mock and interception context. - - - - - - - - - - - - - Enables the Protected() method on , - allowing setups to be set for protected members by using their - name as a string, rather than strong-typing them which is not possible - due to their visibility. - - - - - Enable protected setups for the mock. - - Mocked object type. Typically omitted as it can be inferred from the mock instance. - The mock to set the protected setups on. - - - - Allows the specification of a matching condition for an - argument in a protected member setup, rather than a specific - argument value. "ItExpr" refers to the argument being matched. - - - Use this variant of argument matching instead of - for protected setups. - This class allows the setup to match a method invocation - with an arbitrary value, with a value in a specified range, or - even one that matches a given predicate, or null. - - - - - Matches a null value of the given type. - - - Required for protected mocks as the null value cannot be used - directly as it prevents proper method overload selection. - - - - // Throws an exception for a call to Remove with a null string value. - mock.Protected() - .Setup("Remove", ItExpr.IsNull<string>()) - .Throws(new InvalidOperationException()); - - - Type of the value. - - - - Matches any value of the given type. - - - Typically used when the actual argument value for a method - call is not relevant. - - - - // Throws an exception for a call to Remove with any string value. - mock.Protected() - .Setup("Remove", ItExpr.IsAny<string>()) - .Throws(new InvalidOperationException()); - - - Type of the value. - - - - Matches any value that satisfies the given predicate. - - Type of the argument to check. - The predicate used to match the method argument. - - Allows the specification of a predicate to perform matching - of method call arguments. - - - This example shows how to return the value 1 whenever the argument to the - Do method is an even number. - - mock.Protected() - .Setup("Do", ItExpr.Is<int>(i => i % 2 == 0)) - .Returns(1); - - This example shows how to throw an exception if the argument to the - method is a negative number: - - mock.Protected() - .Setup("GetUser", ItExpr.Is<int>(i => i < 0)) - .Throws(new ArgumentException()); - - - - - - Matches any value that is in the range specified. - - Type of the argument to check. - The lower bound of the range. - The upper bound of the range. - The kind of range. See . - - The following example shows how to expect a method call - with an integer argument within the 0..100 range. - - mock.Protected() - .Setup("HasInventory", - ItExpr.IsAny<string>(), - ItExpr.IsInRange(0, 100, Range.Inclusive)) - .Returns(false); - - - - - - Matches a string argument if it matches the given regular expression pattern. - - The pattern to use to match the string argument value. - - The following example shows how to expect a call to a method where the - string argument matches the given regular expression: - - mock.Protected() - .Setup("Check", ItExpr.IsRegex("[a-z]+")) - .Returns(1); - - - - - - Matches a string argument if it matches the given regular expression pattern. - - The pattern to use to match the string argument value. - The options used to interpret the pattern. - - The following example shows how to expect a call to a method where the - string argument matches the given regular expression, in a case insensitive way: - - mock.Protected() - .Setup("Check", ItExpr.IsRegex("[a-z]+", RegexOptions.IgnoreCase)) - .Returns(1); - - - - - - Checks an argument to ensure it isn't null. - - The argument value to check. - The name of the argument. - - - - Checks a string argument to ensure it isn't null or empty. - - The argument value to check. - The name of the argument. - - - - Checks an argument to ensure it is in the specified range including the edges. - - Type of the argument to check, it must be an type. - - The argument value to check. - The minimun allowed value for the argument. - The maximun allowed value for the argument. - The name of the argument. - - - - Checks an argument to ensure it is in the specified range excluding the edges. - - Type of the argument to check, it must be an type. - - The argument value to check. - The minimun allowed value for the argument. - The maximun allowed value for the argument. - The name of the argument. - - - + + + + Moq + + + + + Interface to be implemented by classes that determine the + default value of non-expected invocations. + + + + + Provides a value for the given member and arguments. + + The member to provide a default + value for. + Optional arguments passed in + to the call that requires a default value. + + + + Provides a typed for a + specific type of . + + The type of event arguments required by the event. + + The mocked event can either be a or custom + event handler which follows .NET practice of providing object sender, EventArgs args + kind of signature. + + + + + Represents a generic event that has been mocked and can + be rised. + + + + + Provided solely to allow the interceptor to determine when the attached + handler is coming from this mocked event so we can assign the + corresponding EventInfo for it. + + + + + Raises the associated event with the given + event argument data. + + + + + Provides support for attaching a to + a generic event. + + Event to convert. + + + + Event raised whenever the mocked event is rised. + + + + + Raises the associated event with the given + event argument data. + + Data to pass to the event. + + + + Provides support for attaching a to + a generic event. + + Event to convert. + + + + Provided solely to allow the interceptor to determine when the attached + handler is coming from this mocked event so we can assign the + corresponding EventInfo for it. + + + + + Utility factory class to use to construct multiple + mocks when consistent verification is + desired for all of them. + + + If multiple mocks will be created during a test, passing + the desired (if different than the + or the one + passed to the factory constructor) and later verifying each + mock can become repetitive and tedious. + + This factory class helps in that scenario by providing a + simplified creation of multiple mocks with a default + (unless overriden by calling + ) and posterior verification. + + + + The following is a straightforward example on how to + create and automatically verify strict mocks using a : + + var factory = new MockFactory(MockBehavior.Strict); + + var foo = factory.Create<IFoo>(); + var bar = factory.Create<IBar>(); + + // no need to call Verifiable() on the setup + // as we'll be validating all of them anyway. + foo.Setup(f => f.Do()); + bar.Setup(b => b.Redo()); + + // exercise the mocks here + + factory.VerifyAll(); + // At this point all setups are already checked + // and an optional MockException might be thrown. + // Note also that because the mocks are strict, any invocation + // that doesn't have a matching setup will also throw a MockException. + + The following examples shows how to setup the factory + to create loose mocks and later verify only verifiable setups: + + var factory = new MockFactory(MockBehavior.Loose); + + var foo = factory.Create<IFoo>(); + var bar = factory.Create<IBar>(); + + // this setup will be verified when we verify the factory + foo.Setup(f => f.Do()).Verifiable(); + + // this setup will NOT be verified + foo.Setup(f => f.Calculate()); + + // this setup will be verified when we verify the factory + bar.Setup(b => b.Redo()).Verifiable(); + + // exercise the mocks here + // note that because the mocks are Loose, members + // called in the interfaces for which no matching + // setups exist will NOT throw exceptions, + // and will rather return default values. + + factory.Verify(); + // At this point verifiable setups are already checked + // and an optional MockException might be thrown. + + The following examples shows how to setup the factory with a + default strict behavior, overriding that default for a + specific mock: + + var factory = new MockFactory(MockBehavior.Strict); + + // this particular one we want loose + var foo = factory.Create<IFoo>(MockBehavior.Loose); + var bar = factory.Create<IBar>(); + + // specify setups + + // exercise the mocks here + + factory.Verify(); + + + + + + + Initializes the factory with the given + for newly created mocks from the factory. + + The behavior to use for mocks created + using the factory method if not overriden + by using the overload. + + + + Creates a new mock with the default + specified at factory construction time. + + Type to mock. + A new . + + + var factory = new MockFactory(MockBehavior.Strict); + + var foo = factory.Create<IFoo>(); + // use mock on tests + + factory.VerifyAll(); + + + + + + Creates a new mock with the default + specified at factory construction time and with the + the given constructor arguments for the class. + + + The mock will try to find the best match constructor given the + constructor arguments, and invoke that to initialize the instance. + This applies only to classes, not interfaces. + + Type to mock. + Constructor arguments for mocked classes. + A new . + + + var factory = new MockFactory(MockBehavior.Default); + + var mock = factory.Create<MyBase>("Foo", 25, true); + // use mock on tests + + factory.Verify(); + + + + + + Creates a new mock with the given . + + Type to mock. + Behavior to use for the mock, which overrides + the default behavior specified at factory construction time. + A new . + + The following example shows how to create a mock with a different + behavior to that specified as the default for the factory: + + var factory = new MockFactory(MockBehavior.Strict); + + var foo = factory.Create<IFoo>(MockBehavior.Loose); + + + + + + Creates a new mock with the given + and with the the given constructor arguments for the class. + + + The mock will try to find the best match constructor given the + constructor arguments, and invoke that to initialize the instance. + This applies only to classes, not interfaces. + + Type to mock. + Behavior to use for the mock, which overrides + the default behavior specified at factory construction time. + Constructor arguments for mocked classes. + A new . + + The following example shows how to create a mock with a different + behavior to that specified as the default for the factory, passing + constructor arguments: + + var factory = new MockFactory(MockBehavior.Default); + + var mock = factory.Create<MyBase>(MockBehavior.Strict, "Foo", 25, true); + + + + + + Implements creation of a new mock within the factory. + + Type to mock. + The behavior for the new mock. + Optional arguments for the construction of the mock. + + + + Verifies all verifiable expectations on all mocks created + by this factory. + + + One or more mocks had expectations that were not satisfied. + + + + Verifies all verifiable expectations on all mocks created + by this factory. + + + One or more mocks had expectations that were not satisfied. + + + + Invokes for each mock + in , and accumulates the resulting + that might be + thrown from the action. + + The action to execute against + each mock. + + + + Whether the base member virtual implementation will be called + for mocked classes if no setup is matched. Defaults to . + + + + + Specifies the behavior to use when returning default values for + unexpected invocations on loose mocks. + + + + + Gets the mocks that have been created by this factory and + that will get verified together. + + + + + Defines the Throws verb. + + + + + Helper interface used to hide the base + members from the fluent API to make it much cleaner + in Visual Studio intellisense. + + + + + + + + + + + + + + + + + Specifies the exception to throw when the method is invoked. + + Exception instance to throw. + + This example shows how to throw an exception when the method is + invoked with an empty string argument: + + mock.Setup(x => x.Execute("")) + .Throws(new ArgumentException()); + + + + + + Specifies the type of exception to throw when the method is invoked. + + Type of exception to instantiate and throw when the setup is matched. + + This example shows how to throw an exception when the method is + invoked with an empty string argument: + + mock.Setup(x => x.Execute("")) + .Throws<ArgumentException>(); + + + + + + Allows the specification of a matching condition for an + argument in a method invocation, rather than a specific + argument value. "It" refers to the argument being matched. + + + This class allows the setup to match a method invocation + with an arbitrary value, with a value in a specified range, or + even one that matches a given predicate. + + + + + Matches any value of the given type. + + + Typically used when the actual argument value for a method + call is not relevant. + + + + // Throws an exception for a call to Remove with any string value. + mock.Setup(x => x.Remove(It.IsAny<string>())).Throws(new InvalidOperationException()); + + + Type of the value. + + + + Matches any value that satisfies the given predicate. + + Type of the argument to check. + The predicate used to match the method argument. + + Allows the specification of a predicate to perform matching + of method call arguments. + + + This example shows how to return the value 1 whenever the argument to the + Do method is an even number. + + mock.Setup(x => x.Do(It.Is<int>(i => i % 2 == 0))) + .Returns(1); + + This example shows how to throw an exception if the argument to the + method is a negative number: + + mock.Setup(x => x.GetUser(It.Is<int>(i => i < 0))) + .Throws(new ArgumentException()); + + + + + + Matches any value that is in the range specified. + + Type of the argument to check. + The lower bound of the range. + The upper bound of the range. + The kind of range. See . + + The following example shows how to expect a method call + with an integer argument within the 0..100 range. + + mock.Setup(x => x.HasInventory( + It.IsAny<string>(), + It.IsInRange(0, 100, Range.Inclusive))) + .Returns(false); + + + + + + Matches a string argument if it matches the given regular expression pattern. + + The pattern to use to match the string argument value. + + The following example shows how to expect a call to a method where the + string argument matches the given regular expression: + + mock.Setup(x => x.Check(It.IsRegex("[a-z]+"))).Returns(1); + + + + + + Matches a string argument if it matches the given regular expression pattern. + + The pattern to use to match the string argument value. + The options used to interpret the pattern. + + The following example shows how to expect a call to a method where the + string argument matches the given regular expression, in a case insensitive way: + + mock.Setup(x => x.Check(It.IsRegex("[a-z]+", RegexOptions.IgnoreCase))).Returns(1); + + + + + + Defines the Returns verb. + + Mocked type. + Type of the return value from the expression. + + + + Specifies the value to return. + + The value to return, or . + + Return a true value from the method call: + + mock.Setup(x => x.Execute("ping")) + .Returns(true); + + + + + + Specifies a function that will calculate the value to return from the method. + + The function that will calculate the return value. + + Return a calculated value when the method is called: + + mock.Setup(x => x.Execute("ping")) + .Returns(() => returnValues[0]); + + The lambda expression to retrieve the return value is lazy-executed, + meaning that its value may change depending on the moment the method + is executed and the value the returnValues array has at + that moment. + + + + + Specifies a function that will calculate the value to return from the method, + retrieving the arguments for the invocation. + + Type of the argument of the invoked method. + The function that will calculate the return value. + + Return a calculated value which is evaluated lazily at the time of the invocation. + + The lookup list can change between invocations and the setup + will return different values accordingly. Also, notice how the specific + string argument is retrieved by simply declaring it as part of the lambda + expression: + + + mock.Setup(x => x.Execute(It.IsAny<string>())) + .Returns((string command) => returnValues[command]); + + + + + + Specifies a function that will calculate the value to return from the method, + retrieving the arguments for the invocation. + + Type of the first argument of the invoked method. + Type of the second argument of the invoked method. + The function that will calculate the return value. + + Return a calculated value which is evaluated lazily at the time of the invocation. + + The return value is calculated from the value of the actual method invocation arguments. + Notice how the arguments are retrieved by simply declaring them as part of the lambda + expression: + + + mock.Setup(x => x.Execute( + It.IsAny<string>(), + It.IsAny<string>())) + .Returns((string arg1, string arg2) => arg1 + arg2); + + + + + + Specifies a function that will calculate the value to return from the method, + retrieving the arguments for the invocation. + + Type of the first argument of the invoked method. + Type of the second argument of the invoked method. + Type of the third argument of the invoked method. + The function that will calculate the return value. + + Return a calculated value which is evaluated lazily at the time of the invocation. + + The return value is calculated from the value of the actual method invocation arguments. + Notice how the arguments are retrieved by simply declaring them as part of the lambda + expression: + + + mock.Setup(x => x.Execute( + It.IsAny<string>(), + It.IsAny<string>(), + It.IsAny<int>())) + .Returns((string arg1, string arg2, int arg3) => arg1 + arg2 + arg3); + + + + + + Specifies a function that will calculate the value to return from the method, + retrieving the arguments for the invocation. + + Type of the first argument of the invoked method. + Type of the second argument of the invoked method. + Type of the third argument of the invoked method. + Type of the fourth argument of the invoked method. + The function that will calculate the return value. + + Return a calculated value which is evaluated lazily at the time of the invocation. + + The return value is calculated from the value of the actual method invocation arguments. + Notice how the arguments are retrieved by simply declaring them as part of the lambda + expression: + + + mock.Setup(x => x.Execute( + It.IsAny<string>(), + It.IsAny<string>(), + It.IsAny<int>(), + It.IsAny<bool>())) + .Returns((string arg1, string arg2, int arg3, bool arg4) => arg1 + arg2 + arg3 + arg4); + + + + + + Implemented by all generated mock object instances. + + + + + Implemented by all generated mock object instances. + + + + + Reference the Mock that contains this as the mock.Object value. + + + + + Reference the Mock that contains this as the mock.Object value. + + + + + Defines the Raises verb. + + + + + Specifies the event that will be raised + when the setup is met. + + An expression that represents an event attach or detach action. + The event arguments to pass for the raised event. + + The following example shows how to raise an event when + the setup is met: + + var mock = new Mock<IContainer>(); + + mock.Setup(add => add.Add(It.IsAny<string>(), It.IsAny<object>())) + .Raises(add => add.Added += null, EventArgs.Empty); + + + + + + Specifies the event that will be raised + when the setup is matched. + + An expression that represents an event attach or detach action. + A function that will build the + to pass when raising the event. + + + + + Specifies the event that will be raised + when the setup is matched. + + An expression that represents an event attach or detach action. + A function that will build the + to pass when raising the event. + Type of the argument received by the expected invocation. + + + + + Specifies the event that will be raised + when the setup is matched. + + An expression that represents an event attach or detach action. + A function that will build the + to pass when raising the event. + Type of the first argument received by the expected invocation. + Type of the second argument received by the expected invocation. + + + + + Specifies the event that will be raised + when the setup is matched. + + An expression that represents an event attach or detach action. + A function that will build the + to pass when raising the event. + Type of the first argument received by the expected invocation. + Type of the second argument received by the expected invocation. + Type of the third argument received by the expected invocation. + + + + + Specifies the event that will be raised + when the setup is matched. + + An expression that represents an event attach or detach action. + A function that will build the + to pass when raising the event. + Type of the first argument received by the expected invocation. + Type of the second argument received by the expected invocation. + Type of the third argument received by the expected invocation. + Type of the fourth argument received by the expected invocation. + + + + + Implements the fluent API. + + + + + Defines the Callback verb and overloads. + + + + + Specifies a callback to invoke when the method is called. + + Callback method to invoke. + + The following example specifies a callback to set a boolean + value that can be used later: + + bool called = false; + mock.Setup(x => x.Execute()) + .Callback(() => called = true); + + + + + + Specifies a callback to invoke when the method is called that receives the original + arguments. + + Argument type of the invoked method. + Callback method to invoke. + + Invokes the given callback with the concrete invocation argument value. + + Notice how the specific string argument is retrieved by simply declaring + it as part of the lambda expression for the callback: + + + mock.Setup(x => x.Execute(It.IsAny<string>())) + .Callback((string command) => Console.WriteLine(command)); + + + + + + Specifies a callback to invoke when the method is called that receives the original + arguments. + + Type of the first argument of the invoked method. + Type of the second argument of the invoked method. + Callback method to invoke. + + Invokes the given callback with the concrete invocation arguments values. + + Notice how the specific arguments are retrieved by simply declaring + them as part of the lambda expression for the callback: + + + mock.Setup(x => x.Execute( + It.IsAny<string>(), + It.IsAny<string>())) + .Callback((string arg1, string arg2) => Console.WriteLine(arg1 + arg2)); + + + + + + Specifies a callback to invoke when the method is called that receives the original + arguments. + + Type of the first argument of the invoked method. + Type of the second argument of the invoked method. + Type of the third argument of the invoked method. + Callback method to invoke. + + Invokes the given callback with the concrete invocation arguments values. + + Notice how the specific arguments are retrieved by simply declaring + them as part of the lambda expression for the callback: + + + mock.Setup(x => x.Execute( + It.IsAny<string>(), + It.IsAny<string>(), + It.IsAny<int>())) + .Callback((string arg1, string arg2, int arg3) => Console.WriteLine(arg1 + arg2 + arg3)); + + + + + + Specifies a callback to invoke when the method is called that receives the original + arguments. + + Type of the first argument of the invoked method. + Type of the second argument of the invoked method. + Type of the third argument of the invoked method. + Type of the fourth argument of the invoked method. + Callback method to invoke. + + Invokes the given callback with the concrete invocation arguments values. + + Notice how the specific arguments are retrieved by simply declaring + them as part of the lambda expression for the callback: + + + mock.Setup(x => x.Execute( + It.IsAny<string>(), + It.IsAny<string>(), + It.IsAny<int>(), + It.IsAny<bool>())) + .Callback((string arg1, string arg2, int arg3, bool arg4) => Console.WriteLine(arg1 + arg2 + arg3 + arg4)); + + + + + + Defines occurrence members to constraint setups. + + + + + The expected invocation can happen at most once. + + + + var mock = new Mock<ICommand>(); + mock.Setup(foo => foo.Execute("ping")) + .AtMostOnce(); + + + + + + The expected invocation can happen at most specified number of times. + + + + var mock = new Mock<ICommand>(); + mock.Setup(foo => foo.Execute("ping")) + .AtMost( 5 ); + + + + + + Defines the Raises verb. + + + + + Specifies the mocked event that will be raised + when the setup is met. + + The mocked event, retrieved from + or . + + The event args to pass when raising the event. + + The following example shows how to raise an event when + the setup is met: + + var mock = new Mock<IContainer>(); + // create handler to associate with the event to raise + var handler = mock.CreateEventHandler(); + // associate the handler with the event to raise + mock.Object.Added += handler; + // setup the invocation and the handler to raise + mock.Setup(add => add.Add(It.IsAny<string>(), It.IsAny<object>())) + .Raises(handler, EventArgs.Empty); + + + + + + Specifies the mocked event that will be raised + when the setup is matched. + + The mocked event, retrieved from + or . + + A function that will build the + to pass when raising the event. + + + + + Specifies the mocked event that will be raised + when the setup is matched. + + The mocked event, retrieved from + or . + + A function that will build the + to pass when raising the event. + Type of the argument received by the expected invocation. + + + + + Specifies the mocked event that will be raised + when the setup is matched. + + The mocked event, retrieved from + or . + + A function that will build the + to pass when raising the event. + Type of the first argument received by the expected invocation. + Type of the second argument received by the expected invocation. + + + + + Specifies the mocked event that will be raised + when the setup is matched. + + The mocked event, retrieved from + or . + + A function that will build the + to pass when raising the event. + Type of the first argument received by the expected invocation. + Type of the second argument received by the expected invocation. + Type of the third argument received by the expected invocation. + + + + + Specifies the mocked event that will be raised + when the setup is matched. + + The mocked event, retrieved from + or . + + A function that will build the + to pass when raising the event. + Type of the first argument received by the expected invocation. + Type of the second argument received by the expected invocation. + Type of the third argument received by the expected invocation. + Type of the fourth argument received by the expected invocation. + + + + + Defines the Verifiable verb. + + + + + Marks the expectation as verifiable, meaning that a call + to will check if this particular + expectation was met. + + + The following example marks the expectation as verifiable: + + mock.Expect(x => x.Execute("ping")) + .Returns(true) + .Verifiable(); + + + + + + Marks the expectation as verifiable, meaning that a call + to will check if this particular + expectation was met, and specifies a message for failures. + + + The following example marks the expectation as verifiable: + + mock.Expect(x => x.Execute("ping")) + .Returns(true) + .Verifiable("Ping should be executed always!"); + + + + + Type to mock, which can be an interface or a class. + + Provides a mock implementation of . + + + Only abstract and virtual members of classes can be mocked. + + The behavior of the mock with regards to the setups and the actual calls is determined + by the optional that can be passed to the + constructor. + + + + The following example shows establishing setups with specific values + for method invocations: + + //setup - data + var order = new Order(TALISKER, 50); + var mock = new Mock<IWarehouse>(); + + //setup + mock.Setup(x => x.HasInventory(TALISKER, 50)).Returns(true); + + //exercise + order.Fill(mock.Object); + + //verify + Assert.True(order.IsFilled); + + The following example shows how to use the class + to specify conditions for arguments instead of specific values: + + //setup - data + var order = new Order(TALISKER, 50); + var mock = new Mock<IWarehouse>(); + + //setup + //shows how to expect a value within a range + mock.Setup(x => x.HasInventory( + It.IsAny<string>(), + It.IsInRange(0, 100, Range.Inclusive))) + .Returns(false); + + //shows how to throw for unexpected calls. + mock.Setup(x => x.Remove( + It.IsAny<string>(), + It.IsAny<int>())) + .Throws(new InvalidOperationException()); + + //exercise + order.Fill(mock.Object); + + //verify + Assert.False(order.IsFilled); + + + + + + Base class for mocks and static helper class with methods that + apply to mocked objects, such as to + retrieve a from an object instance. + + + + + Retrieves the mock object for the given object instance. + + Type of the mock to retrieve. Can be omitted as it's inferred + from the object instance passed in as the instance. + The instance of the mocked object. + The mock associated with the mocked object. + The received instance + was not created by Moq. + + The following example shows how to add a new setup to an object + instance which is not the original but rather + the object associated with it: + + // Typed instance, not the mock, is retrieved from some test API. + HttpContextBase context = GetMockContext(); + + // context.Request is the typed object from the "real" API + // so in order to add a setup to it, we need to get + // the mock that "owns" it + Mock<HttpRequestBase> request = Mock.Get(context.Request); + mock.Setup(req => req.AppRelativeCurrentExecutionFilePath) + .Returns(tempUrl); + + + + + + Returns the mocked object value. + + + + + Verifies that all verifiable expectations have been met. + + + This example sets up an expectation and marks it as verifiable. After + the mock is used, a Verify() call is issued on the mock + to ensure the method in the setup was invoked: + + var mock = new Mock<IWarehouse>(); + this.Setup(x => x.HasInventory(TALISKER, 50)).Verifiable().Returns(true); + ... + // other test code + ... + // Will throw if the test code has didn't call HasInventory. + this.Verify(); + + + Not all verifiable expectations were met. + + + + Verifies all expectations regardless of whether they have + been flagged as verifiable. + + + This example sets up an expectation without marking it as verifiable. After + the mock is used, a call is issued on the mock + to ensure that all expectations are met: + + var mock = new Mock<IWarehouse>(); + this.Setup(x => x.HasInventory(TALISKER, 50)).Returns(true); + ... + // other test code + ... + // Will throw if the test code has didn't call HasInventory, even + // that expectation was not marked as verifiable. + this.VerifyAll(); + + + At least one expectation was not met. + + + + Gets the interceptor target for the given expression and root mock, + building the intermediate hierarchy of mock objects if necessary. + + + + + Creates a handler that can be associated to an event receiving + the given and can be used + to raise the event. + + Type of + data passed in to the event. + + This example shows how to invoke an event with a custom event arguments + class in a view that will cause its corresponding presenter to + react by changing its state: + + var mockView = new Mock<IOrdersView>(); + var mockedEvent = mockView.CreateEventHandler<OrderEventArgs>(); + + var presenter = new OrdersPresenter(mockView.Object); + + // Check that the presenter has no selection by default + Assert.Null(presenter.SelectedOrder); + + // Create a mock event handler of the appropriate type + var handler = mockView.CreateEventHandler<OrderEventArgs>(); + // Associate it with the event we want to raise + mockView.Object.Cancel += handler; + // Finally raise the event with a specific arguments data + handler.Raise(new OrderEventArgs { Order = new Order("moq", 500) }); + + // Now the presenter reacted to the event, and we have a selected order + Assert.NotNull(presenter.SelectedOrder); + Assert.Equal("moq", presenter.SelectedOrder.ProductName); + + + + + + Creates a handler that can be associated to an event receiving + a generic and can be used + to raise the event. + + + This example shows how to invoke a generic event in a view that will + cause its corresponding presenter to react by changing its state: + + var mockView = new Mock<IOrdersView>(); + var mockedEvent = mockView.CreateEventHandler(); + + var presenter = new OrdersPresenter(mockView.Object); + + // Check that the presenter is not in the "Canceled" state + Assert.False(presenter.IsCanceled); + + // Create a mock event handler of the appropriate type + var handler = mockView.CreateEventHandler(); + // Associate it with the event we want to raise + mockView.Object.Cancel += handler; + // Finally raise the event + handler.Raise(EventArgs.Empty); + + // Now the presenter reacted to the event, and changed its state + Assert.True(presenter.IsCanceled); + + + + + + Exposes the list of extra interfaces implemented by the mock. + + + + + Behavior of the mock, according to the value set in the constructor. + + + + + Whether the base member virtual implementation will be called + for mocked classes if no setup is matched. Defaults to . + + + + + Specifies the behavior to use when returning default values for + unexpected invocations on loose mocks. + + + + + Specifies the class that will determine the default + value to return when invocations are made that + have no setups and need to return a default + value (for loose mocks). + + + + + Gets the mocked object instance. + + + + + Retrieves the type of the mocked object, its generic type argument. + This is used in the auto-mocking of hierarchy access. + + + + + Base class for visitors of expression trees. + + + Provides the functionality of the internal visitor base class that + comes with Linq. + Matt's comments on the implementation: + + In this variant there is only one visitor class that dispatches calls to the general + Visit function out to specific VisitXXX methods corresponding to different node types. + Note not every node type gets it own method, for example all binary operators are + treated in one VisitBinary method. The nodes themselves do not directly participate + in the visitation process. They are treated as just data. + The reason for this is that the quantity of visitors is actually open ended. + You can write your own. Therefore no semantics of visiting is coupled into the node classes. + It’s all in the visitors. The default visit behavior for node XXX is baked into the base + class’s version of VisitXXX. + + + Another variant is that all VisitXXX methods return a node. + The Expression tree nodes are immutable. In order to change the tree you must construct + a new one. The default VisitXXX methods will construct a new node if any of its sub-trees change. + If no changes are made then the same node is returned. That way if you make a change + to a node (by making a new node) deep down in a tree, the rest of the tree is rebuilt + automatically for you. + + See: http://blogs.msdn.com/mattwar/archive/2007/07/31/linq-building-an-iqueryable-provider-part-ii.aspx. + + Matt Warren: http://blogs.msdn.com/mattwar + Documented by InSTEDD: http://www.instedd.org + + + + Default constructor used by derived visitors. + + + + + Visits the , determining which + of the concrete Visit methods to call. + + + + + Visits the generic , determining and + calling the appropriate Visit method according to the + , which will result + in calls to , + or . + + + + + + + Visits the initializer by + calling the for the + . + + + + + Visits the expression by + calling with the expression. + + + + + Visits the by calling + with the , + and + expressions. + + + + + Visits the by calling + with the + expression. + + + + + Visits the , by default returning the + same without further behavior. + + + + + Visits the by calling + with the , + and + expressions. + + + + + Visits the returning it + by default without further behavior. + + + + + Visits the by calling + with the + expression. + + + + + Visits the by calling + with the expression, + and then with the . + + + + + + + Visits the by iterating + the list and visiting each in it. + + + + + + + Visits the by calling + with the expression. + + + + + + + Visits the by calling + with the . + + + + + + + Visits the by calling + with the + . + + + + + + + Visits the by + calling for each in the + collection. + + + + + + + Visits the by + calling for each + in the collection. + + + + + + + Visits the by calling + with the expression. + + + + + + + Visits the by calling + with the + expressions. + + + + + + + Visits the by calling + with the + expression, then with the + . + + + + + Visits the by calling + with the + expression, and then with the + . + + + + + + + Visits the by calling + with the + expressions. + + + + + + + Visits the by calling + with the + expressions. + + + + + + + Sets an expectation on the mocked type for a call to + to a void method. + + + If more than one expectation is set for the same method or property, + the latest one wins and is the one that will be executed. + + Lambda expression that specifies the expected method invocation. + + + var mock = new Mock<IProcessor>(); + this.Setup(x => x.Execute("ping")); + + + + + + Sets an expectation on the mocked type for a call to + to a value returning method. + + Type of the return value. Typically omitted as it can be inferred from the expression. + + If more than one expectation is set for the same method or property, + the latest one wins and is the one that will be executed. + + Lambda expression that specifies the expected method invocation. + + + this.Setup(x => x.HasInventory("Talisker", 50)).Returns(true); + + + + + + Sets an expectation on the mocked type for a call to + to a property getter. + + + If more than one expectation is set for the same property getter, + the latest one wins and is the one that will be executed. + + Type of the property. Typically omitted as it can be inferred from the expression. + Lambda expression that specifies the expected property getter. + + + this.SetupGet(x => x.Suspended) + .Returns(true); + + + + + + Sets an expectation on the mocked type for a call to + to a property setter. + + + If more than one expectation is set for the same property setter, + the latest one wins and is the one that will be executed. + + Type of the property. Typically omitted as it can be inferred from the expression. + Lambda expression that specifies the expected property setter. + + + this.SetupSet(x => x.Suspended); + + + + + + Sets an expectation on the mocked type for a call to + to a property setter with a specific value. + + + More than one expectation can be set for the setter with + different values. + + Type of the property. Typically omitted as it can be inferred from the expression. + Lambda expression that specifies the expected property setter. + The value expected to be set for the property. + + + this.SetupSet(x => x.Suspended, true); + + + + + + Ctor invoked by AsTInterface exclusively. + + + + + Initializes an instance of the mock with default behavior and with + the given constructor arguments for the class. (Only valid when is a class) + + + The mock will try to find the best match constructor given the constructor arguments, and invoke that + to initialize the instance. This applies only for classes, not interfaces. + + + var mock = new Mock<MyProvider>(someArgument, 25); + + Optional constructor arguments if the mocked type is a class. + + + + Initializes an instance of the mock with default behavior. + + + var mock = new Mock<IFormatProvider>(); + + + + + Initializes an instance of the mock with the specified behavior. + + + var mock = new Mock<IFormatProvider>(MockBehavior.Relaxed); + + Behavior of the mock. + + + + Initializes an instance of the mock with a specific behavior with + the given constructor arguments for the class. + + + The mock will try to find the best match constructor given the constructor arguments, and invoke that + to initialize the instance. This applies only to classes, not interfaces. + + + var mock = new Mock<MyProvider>(someArgument, 25); + + Behavior of the mock. + Optional constructor arguments if the mocked type is a class. + + + + Returns the mocked object value. + + + + + Specifies a setup on the mocked type for a call to + to a void method. + + + If more than one setup is specified for the same method or property, + the latest one wins and is the one that will be executed. + + Lambda expression that specifies the expected method invocation. + + + var mock = new Mock<IProcessor>(); + mock.Setup(x => x.Execute("ping")); + + + + + + Specifies a setup on the mocked type for a call to + to a value returning method. + + Type of the return value. Typically omitted as it can be inferred from the expression. + + If more than one setup is specified for the same method or property, + the latest one wins and is the one that will be executed. + + Lambda expression that specifies the method invocation. + + + mock.Setup(x => x.HasInventory("Talisker", 50)).Returns(true); + + + + + + Specifies a setup on the mocked type for a call to + to a property getter. + + + If more than one setup is set for the same property getter, + the latest one wins and is the one that will be executed. + + Type of the property. Typically omitted as it can be inferred from the expression. + Lambda expression that specifies the property getter. + + + mock.SetupGet(x => x.Suspended) + .Returns(true); + + + + + + Specifies a setup on the mocked type for a call to + to a property setter. + + + If more than one setup is set for the same property setter, + the latest one wins and is the one that will be executed. + + This overloads allows the use of a callback already + typed for the property type. + + + Type of the property. Typically omitted as it can be inferred from the expression. + Lambda expression that sets a property to a value. + + + mock.SetupSet(x => x.Suspended = true); + + + + + + Specifies a setup on the mocked type for a call to + to a property setter. + + + If more than one setup is set for the same property setter, + the latest one wins and is the one that will be executed. + + Lambda expression that sets a property to a value. + + + mock.SetupSet(x => x.Suspended = true); + + + + + + Specifies that the given property should have "property behavior", + meaning that setting its value will cause it to be saved and + later returned when the property is requested. (this is also + known as "stubbing"). + + Type of the property, inferred from the property + expression (does not need to be specified). + Property expression to stub. + + If you have an interface with an int property Value, you might + stub it using the following straightforward call: + + var mock = new Mock<IHaveValue>(); + mock.Stub(v => v.Value); + + After the Stub call has been issued, setting and + retrieving the object value will behave as expected: + + IHaveValue v = mock.Object; + + v.Value = 5; + Assert.Equal(5, v.Value); + + + + + + Specifies that the given property should have "property behavior", + meaning that setting its value will cause it to be saved and + later returned when the property is requested. This overload + allows setting the initial value for the property. (this is also + known as "stubbing"). + + Type of the property, inferred from the property + expression (does not need to be specified). + Property expression to stub. + Initial value for the property. + + If you have an interface with an int property Value, you might + stub it using the following straightforward call: + + var mock = new Mock<IHaveValue>(); + mock.SetupProperty(v => v.Value, 5); + + After the SetupProperty call has been issued, setting and + retrieving the object value will behave as expected: + + IHaveValue v = mock.Object; + // Initial value was stored + Assert.Equal(5, v.Value); + + // New value set which changes the initial value + v.Value = 6; + Assert.Equal(6, v.Value); + + + + + + Specifies that the all properties on the mock should have "property behavior", + meaning that setting its value will cause it to be saved and + later returned when the property is requested. (this is also + known as "stubbing"). The default value for each property will be the + one generated as specified by the property for the mock. + + + If the mock is set to , + the mocked default values will also get all properties setup recursively. + + + + + Verifies that a specific invocation matching the given expression was performed on the mock. Use + in conjuntion with the default . + + + This example assumes that the mock has been used, and later we want to verify that a given + invocation with specific parameters was performed: + + var mock = new Mock<IProcessor>(); + // exercise mock + //... + // Will throw if the test code didn't call Execute with a "ping" string argument. + mock.Verify(proc => proc.Execute("ping")); + + + The invocation was not performed on the mock. + Expression to verify. + + + + Verifies that a specific invocation matching the given expression was performed on the mock. Use + in conjuntion with the default . + + The invocation was not call the times specified by + . + Expression to verify. + The times a method is allowed to be called. + + + + Verifies that a specific invocation matching the given expression was performed on the mock, + specifying a failure error message. Use in conjuntion with the default + . + + + This example assumes that the mock has been used, and later we want to verify that a given + invocation with specific parameters was performed: + + var mock = new Mock<IProcessor>(); + // exercise mock + //... + // Will throw if the test code didn't call Execute with a "ping" string argument. + mock.Verify(proc => proc.Execute("ping")); + + + The invocation was not performed on the mock. + Expression to verify. + Message to show if verification fails. + + + + Verifies that a specific invocation matching the given expression was performed on the mock, + specifying a failure error message. Use in conjuntion with the default + . + + The invocation was not call the times specified by + . + Expression to verify. + The times a method is allowed to be called. + Message to show if verification fails. + + + + Verifies that a specific invocation matching the given expression was performed on the mock. Use + in conjuntion with the default . + + + This example assumes that the mock has been used, and later we want to verify that a given + invocation with specific parameters was performed: + + var mock = new Mock<IWarehouse>(); + // exercise mock + //... + // Will throw if the test code didn't call HasInventory. + mock.Verify(warehouse => warehouse.HasInventory(TALISKER, 50)); + + + The invocation was not performed on the mock. + Expression to verify. + Type of return value from the expression. + + + + Verifies that a specific invocation matching the given + expression was performed on the mock. Use in conjuntion + with the default . + + The invocation was not call the times specified by + . + Expression to verify. + The times a method is allowed to be called. + Type of return value from the expression. + + + + Verifies that a specific invocation matching the given + expression was performed on the mock, specifying a failure + error message. + Use in conjuntion with the default . + + + This example assumes that the mock has been used, + and later we want to verify that a given invocation + with specific parameters was performed: + + var mock = new Mock<IWarehouse>(); + // exercise mock + //... + // Will throw if the test code didn't call HasInventory. + mock.Verify(warehouse => warehouse.HasInventory(TALISKER, 50), "When filling orders, inventory has to be checked"); + + + The invocation was not performed on the mock. + Expression to verify. + Message to show if verification fails. + Type of return value from the expression. + + + + Verifies that a specific invocation matching the given + expression was performed on the mock, specifying a failure + error message. + Use in conjuntion with the default . + + The invocation was not call the times specified by + . + Expression to verify. + The times a method is allowed to be called. + Message to show if verification fails. + Type of return value from the expression. + + + + Verifies that a property was read on the mock. + Use in conjuntion with the default . + + + This example assumes that the mock has been used, + and later we want to verify that a given property + was retrieved from it: + + var mock = new Mock<IWarehouse>(); + // exercise mock + //... + // Will throw if the test code didn't retrieve the IsClosed property. + mock.VerifyGet(warehouse => warehouse.IsClosed); + + + The invocation was not performed on the mock. + Expression to verify. + Type of the property to verify. Typically omitted as it can + be inferred from the expression's return type. + + + + Verifies that a property was read on the mock. + Use in conjuntion with the default . + + The invocation was not call the times specified by + . + The times a method is allowed to be called. + Expression to verify. + Type of the property to verify. Typically omitted as it can + be inferred from the expression's return type. + + + + Verifies that a property was read on the mock, specifying a failure + error message. + Use in conjuntion with the default . + + + This example assumes that the mock has been used, + and later we want to verify that a given property + was retrieved from it: + + var mock = new Mock<IWarehouse>(); + // exercise mock + //... + // Will throw if the test code didn't retrieve the IsClosed property. + mock.VerifyGet(warehouse => warehouse.IsClosed); + + + The invocation was not performed on the mock. + Expression to verify. + Message to show if verification fails. + Type of the property to verify. Typically omitted as it can + be inferred from the expression's return type. + + + + Verifies that a property was read on the mock, specifying a failure + error message. + Use in conjuntion with the default . + + The invocation was not call the times specified by + . + The times a method is allowed to be called. + Expression to verify. + Message to show if verification fails. + Type of the property to verify. Typically omitted as it can + be inferred from the expression's return type. + + + + Verifies that a property was set on the mock. + Use in conjuntion with the default . + + + This example assumes that the mock has been used, + and later we want to verify that a given property + was set on it: + + var mock = new Mock<IWarehouse>(); + // exercise mock + //... + // Will throw if the test code didn't set the IsClosed property. + mock.VerifySet(warehouse => warehouse.IsClosed = true); + + + The invocation was not performed on the mock. + Expression to verify. + + + + Verifies that a property was set on the mock. + Use in conjuntion with the default . + + The invocation was not call the times specified by + . + The times a method is allowed to be called. + Expression to verify. + + + + Verifies that a property was set on the mock, specifying + a failure message. + Use in conjuntion with the default . + + + This example assumes that the mock has been used, + and later we want to verify that a given property + was set on it: + + var mock = new Mock<IWarehouse>(); + // exercise mock + //... + // Will throw if the test code didn't set the IsClosed property. + mock.VerifySet(warehouse => warehouse.IsClosed = true, "Warehouse should always be closed after the action"); + + + The invocation was not performed on the mock. + Expression to verify. + Message to show if verification fails. + + + + Verifies that a property was set on the mock, specifying + a failure message. + Use in conjuntion with the default . + + The invocation was not call the times specified by + . + The times a method is allowed to be called. + Expression to verify. + Message to show if verification fails. + + + + Adds an interface implementation to the mock, + allowing setups to be specified for it. + + + This method can only be called before the first use + of the mock property, at which + point the runtime type has already been generated + and no more interfaces can be added to it. + + Also, must be an + interface and not a class, which must be specified + when creating the mock instead. + + + The mock type + has already been generated by accessing the property. + The specified + is not an interface. + + The following example creates a mock for the main interface + and later adds to it to verify + it's called by the consumer code: + + var mock = new Mock<IProcessor>(); + mock.Setup(x => x.Execute("ping")); + + // add IDisposable interface + var disposable = mock.As<IDisposable>(); + disposable.Setup(d => d.Dispose()).Verifiable(); + + + Type of interface to cast the mock to. + + + + Raises the event referenced in using + the given and arguments. + + The arguments are + invalid for the target event invocation, or the is + not an event attach or detach expression. + + The following example shows how to raise a event: + + var mock = new Mock<IViewModel>(); + + mock.Raise(x => x.PropertyChanged -= null, new PropertyChangedEventArgs("Name")); + + + + This example shows how to invoke an event with a custom event arguments + class in a view that will cause its corresponding presenter to + react by changing its state: + + var mockView = new Mock<IOrdersView>(); + var presenter = new OrdersPresenter(mockView.Object); + + // Check that the presenter has no selection by default + Assert.Null(presenter.SelectedOrder); + + // Raise the event with a specific arguments data + mockView.Raise(v => v.SelectionChanged += null, new OrderEventArgs { Order = new Order("moq", 500) }); + + // Now the presenter reacted to the event, and we have a selected order + Assert.NotNull(presenter.SelectedOrder); + Assert.Equal("moq", presenter.SelectedOrder.ProductName); + + + + + + Exposes the mocked object instance. + + + + + Holds extensions that would cause conflicts with new APIs if available + in the core Moq namespace (even if hidden), such as the SetupSet legacy + members. + + + + + Specifies a setup on the mocked type for a call to + to a property setter. + + + If more than one setup is set for the same property setter, + the latest one wins and is the one that will be executed. + + Type of the property. Typically omitted as it can be inferred from the expression. + Type of the mock. + The target mock for the setup. + Lambda expression that specifies the property setter. + + + mock.SetupSet(x => x.Suspended); + + + + + + Specifies a setup on the mocked type for a call to + to a property setter with a specific value. + + + More than one setup can be set for the setter with + different values. + + Type of the property. Typically omitted as it can be inferred from the expression. + Type of the mock. + The target mock for the setup. + Lambda expression that specifies the property setter. + The value to be set for the property. + + + mock.SetupSet(x => x.Suspended, true); + + + + + + Verifies that a property has been set on the mock. + Use in conjuntion with the default . + + + This example assumes that the mock has been used, + and later we want to verify that a given invocation + with specific parameters was performed: + + var mock = new Mock<IWarehouse>(); + // exercise mock + //... + // Will throw if the test code didn't set the IsClosed property. + mock.VerifySet(warehouse => warehouse.IsClosed); + + + The invocation was not performed on the mock. + Expression to verify. + The mock instance. + Mocked type. + Type of the property to verify. Typically omitted as it can + be inferred from the expression's return type. + + + + Verifies that a property has been set on the mock to the given value. + Use in conjuntion with the default . + + + This example assumes that the mock has been used, + and later we want to verify that a given invocation + with specific parameters was performed: + + var mock = new Mock<IWarehouse>(); + // exercise mock + //... + // Will throw if the test code didn't set the IsClosed property to true + mock.VerifySet(warehouse => warehouse.IsClosed, true); + + + The invocation was not performed on the mock. + Expression to verify. + The value that should have been set on the property. + The mock instance. + Mocked type. + Type of the property to verify. Typically omitted as it can + be inferred from the expression's return type. + + + + Verifies that a property has been set on the mock, specifying a failure + error message. + Use in conjuntion with the default . + + + This example assumes that the mock has been used, + and later we want to verify that a given invocation + with specific parameters was performed: + + var mock = new Mock<IWarehouse>(); + // exercise mock + //... + // Will throw if the test code didn't set the IsClosed property. + mock.VerifySet(warehouse => warehouse.IsClosed); + + + The invocation was not performed on the mock. + Expression to verify. + Message to show if verification fails. + The mock instance. + Mocked type. + Type of the property to verify. Typically omitted as it can + be inferred from the expression's return type. + + + + Verifies that a property has been set on the mock to the given value, specifying a failure + error message. + Use in conjuntion with the default . + + + This example assumes that the mock has been used, + and later we want to verify that a given invocation + with specific parameters was performed: + + var mock = new Mock<IWarehouse>(); + // exercise mock + //... + // Will throw if the test code didn't set the IsClosed property to true + mock.VerifySet(warehouse => warehouse.IsClosed, true); + + + The invocation was not performed on the mock. + Expression to verify. + The value that should have been set on the property. + Message to show if verification fails. + The mock instance. + Mocked type. + Type of the property to verify. Typically omitted as it can + be inferred from the expression's return type. + + + + Provides partial evaluation of subtrees, whenever they can be evaluated locally. + + Matt Warren: http://blogs.msdn.com/mattwar + Documented by InSTEDD: http://www.instedd.org + + + + Performs evaluation and replacement of independent sub-trees + + The root of the expression tree. + A function that decides whether a given expression + node can be part of the local function. + A new tree with sub-trees evaluated and replaced. + + + + Performs evaluation and replacement of independent sub-trees + + The root of the expression tree. + A new tree with sub-trees evaluated and replaced. + + + + Evaluates and replaces sub-trees when first candidate is reached (top-down) + + + + + Performs bottom-up analysis to determine which nodes can possibly + be part of an evaluated sub-tree. + + + + + Marks a method as a matcher, which allows complete replacement + of the built-in class with your own argument + matching rules. + + + The argument matching is used to determine whether a concrete + invocation in the mock matches a given setup. This + matching mechanism is fully extensible. + + There are two parts of a matcher: the compiler matcher + and the runtime matcher. + + + Compiler matcher + Used to satisfy the compiler requirements for the + argument. Needs to be a method optionally receiving any arguments + you might need for the matching, but with a return type that + matches that of the argument. + + Let's say I want to match a lists of orders that contains + a particular one. I might create a compiler matcher like the following: + + + public static class Orders + { + [Matcher] + public static IEnumerable<Order> Contains(Order order) + { + return null; + } + } + + Now we can invoke this static method instead of an argument in an + invocation: + + var order = new Order { ... }; + var mock = new Mock<IRepository<Order>>(); + + mock.Setup(x => x.Save(Orders.Contains(order))) + .Throws<ArgumentException>(); + + Note that the return value from the compiler matcher is irrelevant. + This method will never be called, and is just used to satisfy the + compiler and to signal Moq that this is not a method that we want + to be invoked at runtime. + + + + Runtime matcher + + The runtime matcher is the one that will actually perform evaluation + when the test is run, and is defined by convention to have the + same signature as the compiler matcher, but where the return + value is the first argument to the call, which contains the + object received by the actual invocation at runtime: + + public static bool Contains(IEnumerable<Order> orders, Order order) + { + return orders.Contains(order); + } + + At runtime, the mocked method will be invoked with a specific + list of orders. This value will be passed to this runtime + matcher as the first argument, while the second argument is the + one specified in the setup (x.Save(Orders.Contains(order))). + + The boolean returned determines whether the given argument has been + matched. If all arguments to the expected method are matched, then + the setup matches and is evaluated. + + + + + + Using this extensible infrastructure, you can easily replace the entire + set of matchers with your own. You can also avoid the + typical (and annoying) lengthy expressions that result when you have + multiple arguments that use generics. + + + The following is the complete example explained above: + + public static class Orders + { + [Matcher] + public static IEnumerable<Order> Contains(Order order) + { + return null; + } + + public static bool Contains(IEnumerable<Order> orders, Order order) + { + return orders.Contains(order); + } + } + + And the concrete test using this matcher: + + var order = new Order { ... }; + var mock = new Mock<IRepository<Order>>(); + + mock.Setup(x => x.Save(Orders.Contains(order))) + .Throws<ArgumentException>(); + + // use mock, invoke Save, and have the matcher filter. + + + + + + Defines the Callback verb for property getter setups. + + + Mocked type. + Type of the property. + + + + Specifies a callback to invoke when the property is retrieved. + + Callback method to invoke. + + Invokes the given callback with the property value being set. + + mock.SetupGet(x => x.Suspended) + .Callback(() => called = true) + .Returns(true); + + + + + + Matcher to treat static functions as matchers. + + mock.Setup(x => x.StringMethod(A.MagicString())); + + pbulic static class A + { + [Matcher] + public static string MagicString() { return null; } + public static bool MagicString(string arg) + { + return arg == "magic"; + } + } + + Will success if: mock.Object.StringMethod("magic"); + and fail with any other call. + + + + + We need this non-generics base class so that + we can use from + generic code. + + + + + Implements the fluent API. + + + + + Implements the fluent API. + + + + + Implements the fluent API. + + + + + Defines the Callback verb and overloads for callbacks on + setups that return a value. + + Mocked type. + Type of the return value of the setup. + + + + Specifies a callback to invoke when the method is called. + + Callback method to invoke. + + The following example specifies a callback to set a boolean + value that can be used later: + + bool called = false; + mock.Setup(x => x.Execute()) + .Callback(() => called = true) + .Returns(true); + + Note that in the case of value-returning methods, after the Callback + call you can still specify the return value. + + + + + Specifies a callback to invoke when the method is called that receives the original + arguments. + + Type of the argument of the invoked method. + Callback method to invoke. + + Invokes the given callback with the concrete invocation argument value. + + Notice how the specific string argument is retrieved by simply declaring + it as part of the lambda expression for the callback: + + + mock.Setup(x => x.Execute(It.IsAny<string>())) + .Callback((string command) => Console.WriteLine(command)) + .Returns(true); + + + + + + Specifies a callback to invoke when the method is called that receives the original + arguments. + + Type of the first argument of the invoked method. + Type of the second argument of the invoked method. + Callback method to invoke. + + Invokes the given callback with the concrete invocation arguments values. + + Notice how the specific arguments are retrieved by simply declaring + them as part of the lambda expression for the callback: + + + mock.Setup(x => x.Execute( + It.IsAny<string>(), + It.IsAny<string>())) + .Callback((string arg1, string arg2) => Console.WriteLine(arg1 + arg2)) + .Returns(true); + + + + + + Specifies a callback to invoke when the method is called that receives the original + arguments. + + Type of the first argument of the invoked method. + Type of the second argument of the invoked method. + Type of the third argument of the invoked method. + Callback method to invoke. + + Invokes the given callback with the concrete invocation arguments values. + + Notice how the specific arguments are retrieved by simply declaring + them as part of the lambda expression for the callback: + + + mock.Setup(x => x.Execute( + It.IsAny<string>(), + It.IsAny<string>(), + It.IsAny<int>())) + .Callback((string arg1, string arg2, int arg3) => Console.WriteLine(arg1 + arg2 + arg3)) + .Returns(true); + + + + + + Specifies a callback to invoke when the method is called that receives the original + arguments. + + Type of the first argument of the invoked method. + Type of the second argument of the invoked method. + Type of the third argument of the invoked method. + Type of the fourth argument of the invoked method. + Callback method to invoke. + + Invokes the given callback with the concrete invocation arguments values. + + Notice how the specific arguments are retrieved by simply declaring + them as part of the lambda expression for the callback: + + + mock.Setup(x => x.Execute( + It.IsAny<string>(), + It.IsAny<string>(), + It.IsAny<int>(), + It.IsAny<bool>())) + .Callback((string arg1, string arg2, int arg3, bool arg4) => Console.WriteLine(arg1 + arg2 + arg3 + arg4)) + .Returns(true); + + + + + + Implements the fluent API. + + + + + Defines the Never verb. + + + + + The expected invocation is never expected to happen. + + + + var mock = new Mock<ICommand>(); + mock.Setup(foo => foo.Execute("ping")) + .Never(); + + + + is always verified inmediately as + the invocations are performed, like strict mocks do + with unexpected invocations. + + + + + Implements the fluent API. + + + + + Implements the fluent API. + + + + + Defines the Returns verb for property get setups. + + Mocked type. + Type of the property. + + + + Specifies the value to return. + + The value to return, or . + + Return a true value from the property getter call: + + mock.SetupGet(x => x.Suspended) + .Returns(true); + + + + + + Specifies a function that will calculate the value to return for the property. + + The function that will calculate the return value. + + Return a calculated value when the property is retrieved: + + mock.SetupGet(x => x.Suspended) + .Returns(() => returnValues[0]); + + The lambda expression to retrieve the return value is lazy-executed, + meaning that its value may change depending on the moment the property + is retrieved and the value the returnValues array has at + that moment. + + + + + A that returns an empty default value + for non-mockeable types, and mocks for all other types (interfaces and + non-sealed classes) that can be mocked. + + + + + A that returns an empty default value + for invocations that do not have setups or return values, with loose mocks. + This is the default behavior for a mock. + + + + + Kind of range to use in a filter specified through + . + + + + + The range includes the to and + from values. + + + + + The range does not include the to and + from values. + + + + + Exception thrown by mocks when setups are not matched, + the mock is not properly setup, etc. + + + A distinct exception type is provided so that exceptions + thrown by the mock can be differentiated in tests that + expect other exceptions to be thrown (i.e. ArgumentException). + + Richer exception hierarchy/types are not provided as + tests typically should not catch or expect exceptions + from the mocks. These are typically the result of changes + in the tested class or its collaborators implementation, and + result in fixes in the mock setup so that they dissapear and + allow the test to pass. + + + + + + Supports the serialization infrastructure. + + Serialization information. + Streaming context. + + + + Supports the serialization infrastructure. + + Serialization information. + Streaming context. + + + + Made internal as it's of no use for + consumers, but it's important for + our own tests. + + + + + Used by the mock factory to accumulate verification + failures. + + + + + Supports the serialization infrastructure. + + + + + Options to customize the behavior of the mock. + + + + + Causes the mock to always throw + an exception for invocations that don't have a + corresponding setup. + + + + + Will never throw exceptions, returning default + values when necessary (null for reference types, + zero for value types or empty enumerables and arrays). + + + + + Default mock behavior, which equals . + + + + + Implements the fluent API. + + + + + A strongly-typed resource class, for looking up localized strings, etc. + + + + + Returns the cached ResourceManager instance used by this class. + + + + + Overrides the current thread's CurrentUICulture property for all + resource lookups using this strongly typed resource class. + + + + + Looks up a localized string similar to Mock type has already been initialized by accessing its Object property. Adding interfaces must be done before that.. + + + + + Looks up a localized string similar to Value cannot be an empty string.. + + + + + Looks up a localized string similar to Can only add interfaces to the mock.. + + + + + Looks up a localized string similar to Can't set return value for void method {0}.. + + + + + Looks up a localized string similar to Constructor arguments cannot be passed for interface mocks.. + + + + + Looks up a localized string similar to A matching constructor for the given arguments was not found on the mocked type.. + + + + + Looks up a localized string similar to Expression {0} involves a field access, which is not supported. Use properties instead.. + + + + + Looks up a localized string similar to Type to mock must be an interface or an abstract or non-sealed class. . + + + + + Looks up a localized string similar to Cannot retrieve a mock with the given object type {0} as it's not the main type of the mock or any of its additional interfaces. + Please cast the argument to one of the supported types: {1}. + Remember that there's no generics covariance in the CLR, so your object must be one of these types in order for the call to succeed.. + + + + + Looks up a localized string similar to Member {0}.{1} does not exist.. + + + + + Looks up a localized string similar to Method {0}.{1} is public. Use strong-typed Expect overload instead: + mock.Setup(x => x.{1}()); + . + + + + + Looks up a localized string similar to {0} invocation failed with mock behavior {1}. + {2}. + + + + + Looks up a localized string similar to Expected only {0} calls to {1}.. + + + + + Looks up a localized string similar to Expected only one call to {0}.. + + + + + Looks up a localized string similar to {0} + Invocation was performed on the mock less than {2} times: {1}. + + + + + Looks up a localized string similar to {0} + Invocation was not performed on the mock: {1}. + + + + + Looks up a localized string similar to {0} + Invocation was performed on the mock more than {3} times: {1}. + + + + + Looks up a localized string similar to {0} + Invocation was performed on the mock more than a time: {1}. + + + + + Looks up a localized string similar to {0} + Invocation was performed on the mock less or equal than {2} times or more or equal than {3} times: {1}. + + + + + Looks up a localized string similar to {0} + Invocation was performed on the mock less than {2} times or more than {3} times: {1}. + + + + + Looks up a localized string similar to {0} + Invocation was not performed on the mock {2} times: {1}. + + + + + Looks up a localized string similar to {0} + Invocation was performed on the mock: {1}. + + + + + Looks up a localized string similar to All invocations on the mock must have a corresponding setup.. + + + + + Looks up a localized string similar to Object instance was not created by Moq.. + + + + + Looks up a localized string similar to Property {0}.{1} does not exist.. + + + + + Looks up a localized string similar to Property {0}.{1} is write-only.. + + + + + Looks up a localized string similar to Property {0}.{1} is read-only.. + + + + + Looks up a localized string similar to Cannot raise a mocked event unless it has been associated (attached) to a concrete event in a mocked object.. + + + + + Looks up a localized string similar to Invocation needs to return a value and therefore must have a corresponding setup that provides it.. + + + + + Looks up a localized string similar to A lambda expression is expected as the argument to It.Is<T>.. + + + + + Looks up a localized string similar to Invocation {0} should not have been made.. + + + + + Looks up a localized string similar to Expression is not a method invocation: {0}. + + + + + Looks up a localized string similar to Expression is not a property access: {0}. + + + + + Looks up a localized string similar to Expression is not a property setter invocation.. + + + + + Looks up a localized string similar to Invalid setup on a non-overridable member: + {0}. + + + + + Looks up a localized string similar to Type {0} does not implement required interface {1}. + + + + + Looks up a localized string similar to Type {0} does not from required type {1}. + + + + + Looks up a localized string similar to To specify a setup for public property {0}.{1}, use the typed overloads, such as: + mock.Setup(x => x.{1}).Returns(value); + mock.SetupGet(x => x.{1}).Returns(value); //equivalent to previous one + mock.SetupSet(x => x.{1}).Callback(callbackDelegate); + . + + + + + Looks up a localized string similar to Expression {0} is not supported.. + + + + + Looks up a localized string similar to Only property accesses are supported in intermediate invocations on a setup. Unsupported expression {0}.. + + + + + Looks up a localized string similar to Expression contains intermediate property access {0}.{1} which is of type {2} and cannot be mocked. Unsupported expression {3}.. + + + + + Looks up a localized string similar to Setter expression cannot use argument matchers that receive parameters.. + + + + + Looks up a localized string similar to Member {0} is not supported for protected mocking.. + + + + + Looks up a localized string similar to Setter expression can only use static custom matchers.. + + + + + Looks up a localized string similar to To specify a setup for protected property {0}.{1}, use: + mock.Setup<{2}>(x => x.{1}).Returns(value); + mock.SetupGet(x => x.{1}).Returns(value); //equivalent to previous one + mock.SetupSet(x => x.{1}).Callback(callbackDelegate);. + + + + + Looks up a localized string similar to The following setups were not matched: + {0}. + + + + + Defines the number of invocations allowed by a mocked method. + + + + + Specifies that a mocked method should be invoked times as minimum. + + The minimun number of times. + An object defining the allowed number of invocations. + + + + Specifies that a mocked method should be invoked one time as minimum. + + An object defining the allowed number of invocations. + + + + Specifies that a mocked method should be invoked time as maximun. + + The maximun number of times. + An object defining the allowed number of invocations. + + + + Specifies that a mocked method should be invoked one time as maximun. + + An object defining the allowed number of invocations. + + + + Specifies that a mocked method should be invoked between and + times. + + The minimun number of times. + The maximun number of times. + The kind of range. See . + An object defining the allowed number of invocations. + + + + Specifies that a mocked method should be invoked exactly times. + + The times that a method or property can be called. + An object defining the allowed number of invocations. + + + + Specifies that a mocked method should not be invoked. + + An object defining the allowed number of invocations. + + + + Determines the way default values are generated + calculated for loose mocks. + + + + + Default behavior, which generates empty values for + value types (i.e. default(int)), empty array and + enumerables, and nulls for all other reference types. + + + + + Whenever the default value generated by + is null, replaces this value with a mock (if the type + can be mocked). + + + For sealed classes, a null value will be generated. + + + + + Allows setups to be specified for protected members by using their + name as a string, rather than strong-typing them which is not possible + due to their visibility. + + + + + Specifies a setup for a void method invocation with the given + , optionally specifying + arguments for the method call. + + Name of the void method to be invoke. + Optional arguments for the invocation. If argument matchers are used, + remember to use rather than . + + + + Specifies a setup for an invocation on a property or a non void method with the given + , optionally specifying + arguments for the method call. + + Name of the method or property to be invoke. + Optional arguments for the invocation. If argument matchers are used, + remember to use rather than . + Return type of the method or property. + + + + Specifies a setup for an invocation on a property getter with the given + . + + Name of the property. + Type of the property. + + + + Specifies a setup for an invocation on a property setter with the given + . + + Name of the property. + Type of the property. + + + + Implements the actual interception and method invocation for + all mocks. + + + + + Get an eventInfo for a given event name. Search type ancestors depth first if necessary. + + Name of the event, with the set_ or get_ prefix already removed + + + + Given a type return all of its ancestors, both types and interfaces. + + The type to find immediate ancestors of + + + + Casts the expression to a lambda expression, removing + a cast if there's any. + + + + + Casts the body of the lambda expression to a . + + If the body is not a method call. + + + + Converts the body of the lambda expression into the referenced by it. + + + + + Checks whether the body of the lambda expression is a property access. + + + + + Checks whether the expression is a property access. + + + + + Checks whether the body of the lambda expression is a property indexer, which is true + when the expression is an whose + has + equal to . + + + + + Checks whether the expression is a property indexer, which is true + when the expression is an whose + has + equal to . + + + + + Creates an expression that casts the given expression to the + type. + + + + + TODO: remove this code when https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=331583 + is fixed. + + + + + Implements the fluent API. + + + + + Defines the Callback verb for property setter setups. + + Type of the property. + + + + Specifies a callback to invoke when the property is set that receives the + property value being set. + + Callback method to invoke. + + Invokes the given callback with the property value being set. + + mock.SetupSet(x => x.Suspended) + .Callback((bool state) => Console.WriteLine(state)); + + + + + + Tracks the current mock and interception context. + + + + + + + + + + + + + Enables the Protected() method on , + allowing setups to be set for protected members by using their + name as a string, rather than strong-typing them which is not possible + due to their visibility. + + + + + Enable protected setups for the mock. + + Mocked object type. Typically omitted as it can be inferred from the mock instance. + The mock to set the protected setups on. + + + + Allows the specification of a matching condition for an + argument in a protected member setup, rather than a specific + argument value. "ItExpr" refers to the argument being matched. + + + Use this variant of argument matching instead of + for protected setups. + This class allows the setup to match a method invocation + with an arbitrary value, with a value in a specified range, or + even one that matches a given predicate, or null. + + + + + Matches a null value of the given type. + + + Required for protected mocks as the null value cannot be used + directly as it prevents proper method overload selection. + + + + // Throws an exception for a call to Remove with a null string value. + mock.Protected() + .Setup("Remove", ItExpr.IsNull<string>()) + .Throws(new InvalidOperationException()); + + + Type of the value. + + + + Matches any value of the given type. + + + Typically used when the actual argument value for a method + call is not relevant. + + + + // Throws an exception for a call to Remove with any string value. + mock.Protected() + .Setup("Remove", ItExpr.IsAny<string>()) + .Throws(new InvalidOperationException()); + + + Type of the value. + + + + Matches any value that satisfies the given predicate. + + Type of the argument to check. + The predicate used to match the method argument. + + Allows the specification of a predicate to perform matching + of method call arguments. + + + This example shows how to return the value 1 whenever the argument to the + Do method is an even number. + + mock.Protected() + .Setup("Do", ItExpr.Is<int>(i => i % 2 == 0)) + .Returns(1); + + This example shows how to throw an exception if the argument to the + method is a negative number: + + mock.Protected() + .Setup("GetUser", ItExpr.Is<int>(i => i < 0)) + .Throws(new ArgumentException()); + + + + + + Matches any value that is in the range specified. + + Type of the argument to check. + The lower bound of the range. + The upper bound of the range. + The kind of range. See . + + The following example shows how to expect a method call + with an integer argument within the 0..100 range. + + mock.Protected() + .Setup("HasInventory", + ItExpr.IsAny<string>(), + ItExpr.IsInRange(0, 100, Range.Inclusive)) + .Returns(false); + + + + + + Matches a string argument if it matches the given regular expression pattern. + + The pattern to use to match the string argument value. + + The following example shows how to expect a call to a method where the + string argument matches the given regular expression: + + mock.Protected() + .Setup("Check", ItExpr.IsRegex("[a-z]+")) + .Returns(1); + + + + + + Matches a string argument if it matches the given regular expression pattern. + + The pattern to use to match the string argument value. + The options used to interpret the pattern. + + The following example shows how to expect a call to a method where the + string argument matches the given regular expression, in a case insensitive way: + + mock.Protected() + .Setup("Check", ItExpr.IsRegex("[a-z]+", RegexOptions.IgnoreCase)) + .Returns(1); + + + + + + Checks an argument to ensure it isn't null. + + The argument value to check. + The name of the argument. + + + + Checks a string argument to ensure it isn't null or empty. + + The argument value to check. + The name of the argument. + + + + Checks an argument to ensure it is in the specified range including the edges. + + Type of the argument to check, it must be an type. + + The argument value to check. + The minimun allowed value for the argument. + The maximun allowed value for the argument. + The name of the argument. + + + + Checks an argument to ensure it is in the specified range excluding the edges. + + Type of the argument to check, it must be an type. + + The argument value to check. + The minimun allowed value for the argument. + The maximun allowed value for the argument. + The name of the argument. + + + diff --git a/Samples/Lib/System.Web.Mvc.xml b/Samples/Lib/System.Web.Mvc.xml index 863971596..a5885c243 100644 --- a/Samples/Lib/System.Web.Mvc.xml +++ b/Samples/Lib/System.Web.Mvc.xml @@ -1,3136 +1,3136 @@ - - - - System.Web.Mvc - - - - - Class used to render a view using an returned by a . - - - - - Base class used to supply the model to the view and then render the view to the response. - - - - - Encapsulates the result of an action method and is used to perform a - framework level operation on the action method's behalf. - - - - - Enables processing of the result of an action method by a custom type that inherits from . - - - - - - When called by the action invoker, renders the view to the response. - - - - - - When overridden, returns the used to render the view. - - - - - - - Gets or sets the for this result. - - - - - Gets or sets the that is rendered to the response. - - - - - Gets or sets the view data for this result. - - - - - Gets or sets the view engines () associated with this result. - - - - - The name of the view to be rendered. - - - - - Searches the registered view engines and returns the used to render the view. - - - - - - - The name of the master view (such as a master page or template) to use when rendering the view. - - - - - Defines the contract for an action invoker, used to invoke an action in response to an http request. - - - - - Invokes the specified action. - - - The name of the action. - True if the action was found, otherwise false. - - - - Renders the specified partial view. - - - The name of the partial view - - - - Renders the specified partial view replacing its ViewData property with the - supplied ViewDataDictionary. - - - The name of the partial view - - - - Renders the specified partial view passing in a copy of the current - ViewDataDictionary, but - with the Model property set to the specified model. - - - The name of the partial view - - - - Renders the specified partial view, replacing the partial view's ViewData property with the - supplied ViewDataDictionary. The Model - property of the view data is set to the specified model. - - - The name of the partial view - The model for the partial view - The view data for the partial view - - - - Sends binary content to the response via a . - - - - - Base class used to send binary content to the response - - - - - The content type to use for the response. - - - - - If specified, sets the content-disposition header so that a file download dialog appears in the browesr with the specified file name. - - - - - Initializes a new instance of - - The stream to send to the response - The content type to use for the response - - - - Gets the stream which will be sent to the response. - - - - - Returns an anchor tag containing the url to the specified action such that when the action link is clicked, - the action is invoked asynchronously via javascript. - - The inner text of the anchor tag - The name of the action - - An object providing options for the asynchronous request - An anchor tag - - - - Returns an anchor tag containing the url to the specified action such that when the action link is clicked, - the action is invoked asynchronously via javascript. - - The inner text of the anchor tag - The name of the action - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - - An object providing options for the asynchronous request - An anchor tag - - - - Returns an anchor tag containing the url to the specified action such that when the action link is clicked, - the action is invoked asynchronously via javascript. - - The inner text of the anchor tag - The name of the action - The name of the controller - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - The protocol for the URL such as "http" or "https" - The url fragment name (also known as anchor name) - The host name for the URL - - An object providing options for the asynchronous request - An anchor tag - - - - Returns an anchor tag containing the url to the specified action such that when the action link is clicked, - the action is invoked asynchronously via javascript. - - The inner text of the anchor tag - The name of the action - An object containing the parameters for a route. - - An object providing options for the asynchronous request - An anchor tag - - - - Returns an anchor tag containing the url to the specified action such that when the action link is clicked, - the action is invoked asynchronously via javascript. - - The inner text of the anchor tag - The name of the action - An object containing the parameters for a route. - An object containing the html attributes for the element. - - An object providing options for the asynchronous request - An anchor tag - - - - Returns an anchor tag containing the url to the specified action such that when the action link is clicked, - the action is invoked asynchronously via javascript. - - The inner text of the anchor tag - The name of the action - The name of the controller - - An object providing options for the asynchronous request - An anchor tag - - - - Returns an anchor tag containing the url to the specified action such that when the action link is clicked, - the action is invoked asynchronously via javascript. - - The inner text of the anchor tag - The name of the action - The name of the controller - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - - An object providing options for the asynchronous request - An anchor tag - - - - Returns an anchor tag containing the url to the specified action such that when the action link is clicked, - the action is invoked asynchronously via javascript. - - The inner text of the anchor tag - The name of the action - The name of the controller - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - - An object providing options for the asynchronous request - An anchor tag - - - - Returns an anchor tag containing the url to the specified action such that when the action link is clicked, - the action is invoked asynchronously via javascript. - - The inner text of the anchor tag - The name of the action - The name of the controller - An object containing the parameters for a route.. - - An object providing options for the asynchronous request - An anchor tag - - - - Returns an anchor tag containing the url to the specified action such that when the action link is clicked, - the action is invoked asynchronously via javascript. - - The inner text of the anchor tag - The name of the action - The name of the controller - An object containing the parameters for a route. - An object containing the html attributes for the element. - - An object providing options for the asynchronous request - An anchor tag - - - - Returns an anchor tag containing the url to the specified action such that when the action link is clicked, - the action is invoked asynchronously via javascript. - - The inner text of the anchor tag - The name of the action - The name of the controller - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - The protocol for the URL such as "http" or "https" - The url fragment name (also known as anchor name) - The host name for the URL - - An object providing options for the asynchronous request - An anchor tag - - - - Returns an anchor tag containing the url to the specified action such that when the action link is clicked, - the action is invoked asynchronously via javascript. - - The inner text of the anchor tag - The name of the action - The name of the controller - An object containing the parameters for a route. - An object containing the html attributes for the element. - The protocol for the URL such as "http" or "https" - The url fragment name (also known as anchor name) - The host name for the URL - - An object providing options for the asynchronous request - An anchor tag - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. The form is submitted asynchronously using javascript. - - - An object providing options for the asynchronous request - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. The form is submitted asynchronously using javascript. - - - The name of the action - An object providing options for the asynchronous request - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. The form is submitted asynchronously using javascript. - - - The name of the action - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - An object providing options for the asynchronous request - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. The form is submitted asynchronously using javascript. - - - The name of the action - The name of the controller - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - An object containing the html attributes for the element. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - An object providing options for the asynchronous request - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. The form is submitted asynchronously using javascript. - - - The name of the action - The name of the controller - An object containing the parameters for a route. - An object providing options for the asynchronous request - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. The form is submitted asynchronously using javascript. - - - The name of the action - An object containing the parameters for a route. - An object containing the html attributes for the element. - An object providing options for the asynchronous request - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. The form is submitted asynchronously using javascript. - - - The name of the action - The name of the controller - An object providing options for the asynchronous request - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. The form is submitted asynchronously using javascript. - - - The name of the action - The name of the controller - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - An object providing options for the asynchronous request - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. The form is submitted asynchronously using javascript. - - - The name of the action - The name of the controller - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - An object containing the html attributes for the element. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - An object providing options for the asynchronous request - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. The form is submitted asynchronously using javascript. - - - The name of the action - The name of the controller - An object containing the parameters for a route - An object providing options for the asynchronous request - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. The form is submitted asynchronously using javascript. - - - The name of the action - The name of the controller - An object containing the parameters for a route - An object containing the html attributes for the element - An object providing options for the asynchronous request - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. The form is submitted asynchronously using javascript. - - - The name of the route to used to obtain the form post url. - An object providing options for the asynchronous request - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. The form is submitted asynchronously using javascript. - - - The name of the route to used to obtain the form post url. - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - An object providing options for the asynchronous request - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. The form is submitted asynchronously using javascript. - - - The name of the route to used to obtain the form post url. - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - An object containing the html attributes for the element. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - An object providing options for the asynchronous request - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. The form is submitted asynchronously using javascript. - - - The name of the route to used to obtain the form post url. - An object containing the parameters for a route. - An object providing options for the asynchronous request - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. The form is submitted asynchronously using javascript. - - - The name of the route to used to obtain the form post url. - An object containing the parameters for a route. - An object containing the html attributes for the element. - An object providing options for the asynchronous request - An instance. - - - - Returns an anchor tag containing the virtual path for the specified route values such that when the link is clicked, - a request is made to the virtual path asynchronously via javascript. - - - The inner text of the anchor tag - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - An object providing options for the asynchronous request - An anchor tag - - - - Returns an anchor tag containing the virtual path for the specified route values such that when the link is clicked, - a request is made to the virtual path asynchronously via javascript. - - - The inner text of the anchor tag - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - An object providing options for the asynchronous request - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - An anchor tag - - - - Returns an anchor tag containing the virtual path for the specified route values such that when the link is clicked, - a request is made to the virtual path asynchronously via javascript. - - - The inner text of the anchor tag - An object containing the parameters for a route. - An object providing options for the asynchronous request - An anchor tag - - - - Returns an anchor tag containing the virtual path for the specified route values such that when the link is clicked, - a request is made to the virtual path asynchronously via javascript. - - - The inner text of the anchor tag - An object containing the parameters for a route. - An object providing options for the asynchronous request - An object containing the html attributes for the element - An anchor tag - - - - Returns an anchor tag containing the virtual path for the specified route values such that when the link is clicked, - a request is made to the virtual path asynchronously via javascript. - - - The inner text of the anchor tag - The name of the route to used to obtain the form post url. - An object providing options for the asynchronous request - An anchor tag - - - - Returns an anchor tag containing the virtual path for the specified route values such that when the link is clicked, - a request is made to the virtual path asynchronously via javascript. - - - The inner text of the anchor tag - The name of the route to used to obtain the form post url. - An object providing options for the asynchronous request - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - An anchor tag - - - - Returns an anchor tag containing the virtual path for the specified route values such that when the link is clicked, - a request is made to the virtual path asynchronously via javascript. - - - The inner text of the anchor tag - The name of the route to used to obtain the form post url. - An object providing options for the asynchronous request - An object containing the html attributes for the element - An anchor tag - - - - Returns an anchor tag containing the virtual path for the specified route values such that when the link is clicked, - a request is made to the virtual path asynchronously via javascript. - - - The inner text of the anchor tag - The name of the route to used to obtain the form post url. - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - An object providing options for the asynchronous request - An anchor tag - - - - Returns an anchor tag containing the virtual path for the specified route values such that when the link is clicked, - a request is made to the virtual path asynchronously via javascript. - - - The inner text of the anchor tag - The name of the route to used to obtain the form post url. - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - An object providing options for the asynchronous request - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - An anchor tag - - - - Returns an anchor tag containing the virtual path for the specified route values such that when the link is clicked, - a request is made to the virtual path asynchronously via javascript. - - - The inner text of the anchor tag - The name of the route to used to obtain the form post url. - An object containing the parameters for a route. - An object providing options for the asynchronous request - An anchor tag - - - - Returns an anchor tag containing the virtual path for the specified route values such that when the link is clicked, - a request is made to the virtual path asynchronously via javascript. - - - The inner text of the anchor tag - The name of the route to used to obtain the form post url. - An object containing the parameters for a route. - An object providing options for the asynchronous request - An object containing the html attributes for the element - An anchor tag - - - - Returns an anchor tag containing the virtual path for the specified route values such that when the link is clicked, - a request is made to the virtual path asynchronously via javascript. - - - The inner text of the anchor tag - The name of the route to used to obtain the form post url. - The protocol for the URL such as "http" or "https" - The host name for the URL - The url fragment name (also known as anchor name) - An object containing the parameters for a route. - An object providing options for the asynchronous request - An object containing the html attributes for the element - An anchor tag - - - - A strongly-typed resource class, for looking up localized strings, etc. - - - - - Returns the cached ResourceManager instance used by this class. - - - - - Overrides the current thread's CurrentUICulture property for all - resource lookups using this strongly typed resource class. - - - - - Looks up a localized string similar to The current request for action '{0}' on controller type '{1}' is ambiguous between the following action methods:{2}. - - - - - Looks up a localized string similar to {0} on type {1}. - - - - - Looks up a localized string similar to No route in the route table matches the supplied values.. - - - - - Looks up a localized string similar to A required anti-forgery token was not supplied or was invalid.. - - - - - Looks up a localized string similar to The value '{0}' is outside the valid range of the enumeration type '{1}'.. - - - - - Looks up a localized string similar to Value cannot be null or empty.. - - - - - Looks up a localized string similar to The partial view '{0}' could not be found. The following locations were searched:{1}. - - - - - Looks up a localized string similar to The property '{0}' cannot be null or empty.. - - - - - Looks up a localized string similar to The value '{0}' is invalid.. - - - - - Looks up a localized string similar to The view '{0}' or its master could not be found. The following locations were searched:{1}. - - - - - Looks up a localized string similar to A public action method '{0}' could not be found on controller '{1}'.. - - - - - Looks up a localized string similar to The model of type '{0}' was not successfully updated.. - - - - - Looks up a localized string similar to There was an error creating the IControllerFactory '{0}'. Check that it has a public parameterless constructor.. - - - - - Looks up a localized string similar to The IControllerFactory '{0}' did not return a controller for a controller named '{1}'.. - - - - - Looks up a localized string similar to The controller factory type '{0}' must implement the IControllerFactory interface.. - - - - - Looks up a localized string similar to The controller name '{0}' is ambiguous between the following types:{1}. - - - - - Looks up a localized string similar to An error occurred while creating a controller of type '{0}'. If the controller doesn't have a controller factory, ensure that it has a parameterless public constructor.. - - - - - Looks up a localized string similar to The controller for path '{0}' could not be found or it does not implement IController.. - - - - - Looks up a localized string similar to The controller type '{0}' must implement IController.. - - - - - Looks up a localized string similar to A value is required.. - - - - - Looks up a localized string similar to The total number of ticks for the TimeSpan must be greater than 0.. - - - - - Looks up a localized string similar to The type '{0}' does not inherit from Exception.. - - - - - Looks up a localized string similar to Order must be greater than or equal to -1.. - - - - - Looks up a localized string similar to There is no ViewData item with the key '{0}' of type '{1}'.. - - - - - Looks up a localized string similar to The value must be greater than or equal to zero.. - - - - - Looks up a localized string similar to The ViewData item with the key '{0}' is of type '{1}' but needs to be of type '{2}'.. - - - - - Looks up a localized string similar to There was an error creating the IModelBinder '{0}'. Check that it has a public parameterless constructor.. - - - - - Looks up a localized string similar to The type '{0}' does not implement the IModelBinder interface.. - - - - - Looks up a localized string similar to The type '{0}' contains multiple attributes inheriting from CustomModelBinderAttribute.. - - - - - Looks up a localized string similar to Cannot create a descriptor for instance method '{0}' on type '{1}' since the type does not subclass ControllerBase.. - - - - - Looks up a localized string similar to Cannot call action method '{0}' on controller '{1}' since the parameter '{2}' is passed by reference.. - - - - - Looks up a localized string similar to Cannot call action method '{0}' on controller '{1}' since it is a generic method.. - - - - - Looks up a localized string similar to The parameters dictionary contains a null entry for parameter '{0}' of non-nullable type '{1}' for method '{2}' in '{3}'. To make a parameter optional its type should be either a reference type or a Nullable type.. - - - - - Looks up a localized string similar to The parameters dictionary does not contain an entry for parameter '{0}' of type '{1}' for method '{2}' in '{3}'. The dictionary must contain an entry for each parameter, even parameters with null values.. - - - - - Looks up a localized string similar to The parameters dictionary contains an invalid entry for parameter '{0}' for method '{1}' in '{2}'. The dictionary contains a value of type '{3}', but the parameter requires a value of type '{4}'.. - - - - - Looks up a localized string similar to The parameter '{0}' on method '{1}' contains multiple attributes inheriting from CustomModelBinderAttribute.. - - - - - Looks up a localized string similar to The SessionStateTempDataProvider requires SessionState to be enabled.. - - - - - Looks up a localized string similar to The parameter conversion from type '{0}' to type '{1}' failed. See the inner exception for more information.. - - - - - Looks up a localized string similar to The parameter conversion from type '{0}' to type '{1}' failed because no TypeConverter can convert between these types.. - - - - - Looks up a localized string similar to The model item passed into the dictionary is of type '{0}' but this dictionary requires a model item of type '{1}'.. - - - - - Looks up a localized string similar to A ViewMasterPage can only be used with content pages that derive from ViewPage or ViewPage<TViewItem>.. - - - - - Looks up a localized string similar to The ViewUserControl '{0}' cannot find an IViewDataContainer. The ViewUserControl must be inside a ViewPage, ViewMasterPage, or another ViewUserControl.. - - - - - Looks up a localized string similar to A ViewUserControl can only be used inside pages that derive from ViewPage or ViewPage<TViewItem>.. - - - - - Looks up a localized string similar to A master name cannot be specified when the view is a ViewUserControl.. - - - - - Looks up a localized string similar to The view found at '{0}' could not be created.. - - - - - Looks up a localized string similar to The view at '{0}' must derive from ViewPage, ViewPage<TViewData>, ViewUserControl, or ViewUserControl<TViewData>.. - - - - - Instantiates and initializes the Ajax, Html, and Url properties. - - - - - Renders the view page to the response. - - - - - - Returns an containing methods useful for AJAX scenarios. - - - - - Returns an containing methods useful for rendering HTML elements. - - - - - Convenience property used to access the Model property of the - - - - - Returns a which renders the supplied content to the response. - - The content to write to the response - - - - - Returns a which renders the supplied content to the response. - - The content to write to the response - The content type - - - - - Returns a which renders the supplied content to the response. - - The content to write to the response - The content type - The content encoding - - - - - Returns a which writes the fileContents to the Response. - - The binary content to send to the response. - The content type. - - - - - Returns a which writes the fileContents to the Response. - - The binary content to send to the response. - The content type. - If specified, sets the content-disposition header so that a file download dialog appears in the browesr with the specified file name - - - - - Returns a which writes the fileStream to the Response. - - The stream to send to the response. - The content type - - - - - Returns a which writes the fileStream to the Response. - - The stream to send to the response. - The content type - If specified, sets the content-disposition header so that a file download dialog appears in the browesr with the specified file name - - - - - Returns a which writes the file to the Response. - - The path to the file to send to the response. - The content type - - - - - Returns a which writes the file to the Response. - - The path to the file to send to the response. - The content type - If specified, sets the content-disposition header so that a file download dialog appears in the browesr with the specified file name - - - - - Method called whenever a request matches this controller, but not an action of this controller. - - The name of the attempted action - - - - Returns a which writes a script to the response - which is then executed on the client. - - The JavaScript code to run on the client - - - - - Returns a which serializes the specified object to - JSON and writes the JSON to the response. - - The JavaScript code to run on the client - - - - - Returns a which serializes the specified object to - JSON and writes the JSON to the response. - - The JavaScript code to run on the client - The content type - - - - - Returns a which serializes the specified object to - JSON and writes the JSON to the response. - - The JavaScript code to run on the client - The content type - The content encoding - - - - - Method called before the action method is invoked. - - Contains information about the current request and action - - - - Method called after the action method is invoked. - - Contains information about the current request and action - - - - Method called when authorization occurs. - - Contains information about the current request and action - - - - Method called when an unhandled exception occurs in the action. - - Contains information about the current request and action - - - - Method called after the action result returned by an action method is executed. - - Contains information about the current request and action result - - - - Method called before the action result returned by an action method is executed. - - Contains information about the current request and action result - - - - Returns a which renders a partial view to the response. - - - - - - Returns a which renders a partial view to the response. - - The model rendered by the partial view - - - - Returns a which renders a partial view to the response. - - The name of the partial view - - - - Returns a which renders a partial view to the response. - - The name of the partial view - The model rendered by the partial view - - - - Returns a which redirects to the specified URL - - The URL to redirect to. - - - - - Returns a which redirects to the specified action - - The name of the action. - - - - - Returns a which redirects to the specified action - - The name of the action. - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - - - - - Returns a which redirects to the specified action - - The name of the action. - An object containing the parameters for a route. - - - - - Returns a which redirects to the specified action - - The name of the action. - The name of the controller - - - - - Returns a which redirects to the specified action - - The name of the action. - The name of the controller - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - - - - - Returns a which redirects to the specified action - - The name of the action. - The name of the controller - An object containing the parameters for a route. - - - - - Returns a which redirects to the specified route - - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - - - - - Returns a which redirects to the specified route - - An object containing the parameters for a route. - - - - - Returns a which redirects to the specified route - - The name of the route - - - - - Returns a which redirects to the specified route - - The name of the route - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - - - - - Returns a which redirects to the specified route - - The name of the route - An object containing the parameters for a route. - - - - - Updates the specified model instance using values from the Controller's current ValueProvider. - Returns true if successful. - - The type of the model object - The model instance to update. - - - - Updates the specified model instance using values from the Controller's current ValueProvider. - Returns true if successful. - - The type of the model object - The model instance to update. - Prefix to use when looking up values in the value provider - - - - Updates the specified model instance using values from the Controller's current ValueProvider. - Returns true if successful. - - The type of the model object - The model instance to update. - List of properties of the model to update - - - - Updates the specified model instance using values from the Controller's current ValueProvider. - Returns true if successful. - - The type of the model object - The model instance to update. - List of properties of the model to update - Prefix to use when looking up values in the value provider - - - - Updates the specified model instance using values from the Controller's current ValueProvider. - Returns true if successful. - - The type of the model object - The model instance to update. - Prefix to use when looking up values in the value provider - List of properties of the model to update - List of properties to explicitly exclude from update. These are excluded even if they are listed in the includeProperties list - - - - Updates the specified model instance using values from the Controller's current ValueProvider. - Returns true if successful. - - The type of the model object - The model instance to update. - A dictionary of values used to update the model - - - - Updates the specified model instance using values from the Controller's current ValueProvider. - Returns true if successful. - - The type of the model object - The model instance to update. - Prefix to use when looking up values in the value provider - A dictionary of values used to update the model - - - - Updates the specified model instance using values from the Controller's current ValueProvider. - Returns true if successful. - - The type of the model object - The model instance to update. - List of properties of the model to update - A dictionary of values used to update the model - - - - Updates the specified model instance using values from the Controller's current ValueProvider. - Returns true if successful. - - The type of the model object - The model instance to update. - Prefix to use when looking up values in the value provider - List of properties of the model to update - A dictionary of values used to update the model - - - - Updates the specified model instance using values from the Controller's current ValueProvider. - Returns true if successful. - - The type of the model object - The model instance to update. - Prefix to use when looking up values in the value provider - List of properties of the model to update - List of properties to explicitly exclude from update. These are excluded even if they are listed in the includeProperties list - A dictionary of values used to update the model - - - - Updates the specified model instance using values from the Controller's current ValueProvider. - - The type of the model object - The model instance to update. - - - - Updates the specified model instance using values from the Controller's current ValueProvider. - - The type of the model object - The model instance to update. - Prefix to use when looking up values in the value provider - - - - Updates the specified model instance using values from the Controller's current ValueProvider. - - The type of the model object - The model instance to update. - List of properties of the model to update - - - - Updates the specified model instance using values from the Controller's current ValueProvider. - - The type of the model object - The model instance to update. - Prefix to use when looking up values in the value provider - List of properties of the model to update - - - - Updates the specified model instance using values from the Controller's current ValueProvider. - - The type of the model object - The model instance to update. - Prefix to use when looking up values in the value provider - List of properties of the model to update - List of properties to explicitly exclude from update. These are excluded even if they are listed in the includeProperties list - - - - Updates the specified model instance using values from the Controller's current ValueProvider. - - The type of the model object - The model instance to update. - A dictionary of values used to update the model - - - - Updates the specified model instance using values from the Controller's current ValueProvider. - - The type of the model object - The model instance to update. - Prefix to use when looking up values in the value provider - A dictionary of values used to update the model - - - - Updates the specified model instance using values from the Controller's current ValueProvider. - - The type of the model object - The model instance to update. - List of properties of the model to update - A dictionary of values used to update the model - - - - Updates the specified model instance using values from the Controller's current ValueProvider. - - The type of the model object - The model instance to update. - Prefix to use when looking up values in the value provider - List of properties of the model to update - A dictionary of values used to update the model - - - - Updates the specified model instance using values from the Controller's current ValueProvider. - - The type of the model object - The model instance to update. - Prefix to use when looking up values in the value provider - List of properties of the model to update - List of properties to explicitly exclude from update. These are excluded even if they are listed in the includeProperties list - A dictionary of values used to update the model - - - - Returns a which renders a view to the response. - - - - - - Returns a which renders a view to the response. - - The model rendered by the view - - - - - Returns a which renders a view to the response. - - The name of the partial view - - - - - Returns a which renders a view to the response. - - The name of the view - The name of the master view - - - - - Returns a which renders a view to the response. - - The name of the view - The model rendered by the view - - - - - Returns a which renders a view to the response. - - The name of the view - The name of the master view - The model rendered by the view - - - - - Returns a which renders the specified to the response. - - The view rendered to the response - - - - - Returns a which renders the specified to the response. - - The view rendered to the response - The model rendered by the view - - - - - Gets the for the controller. - - - - - Encapsulates all HTTP-specific information about an individual HTTP request. - - - - - Gets the object containing the - state of the model and model binding validation. - - - - - Gets the object for the current HTTP request. - - - - - Gets the object for the current HTTP request. - - - - - Returns the for the current request. - - - - - Gets the object that provides methods used in processing Web requests. - - - - - Gets the object for the current HTTP request. - - - - - Gets the object used to store data for the next request. - - - - - Gets the object used to generate URLs using Routing. - - - - - Gets the security information for the current HTTP request. - - - - - Class containing convenience methods for use in rendering HTML for use in Ajax scenarios within a view. - - - - - Gets the collection of routes. - - - - - Gets the current . - - - - - Gets the current . - - - - - Gets the current . - - - - - Encapsulates information related to rendering a view. - - - - - Encapsulates information about an HTTP request that matches a defined Route and Controller. - - - - - Gets data associated with this request which only lives for one request. - - - - - Gets the to render. - - - - - Gets the view data supplied to the view. - - - - - Returns an anchor tag containing the virtual path to the specified action. - - The inner text of the anchor tag - The name of the action - An anchor tag - - - - Returns an anchor tag containing the virtual path to the specified action. - - The inner text of the anchor tag - The name of the action - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - An anchor tag - - - - Returns an anchor tag containing the virtual path to the specified action. - - The inner text of the anchor tag - The name of the action - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - An anchor tag - - - - Returns an anchor tag containing the virtual path to the specified action. - - The inner text of the anchor tag - The name of the action - An object containing the parameters for a route - An anchor tag - - - - Returns an anchor tag containing the virtual path to the specified action. - - The inner text of the anchor tag - The name of the action - An object containing the parameters for a route - An object containing the html attributes for the element - An anchor tag - - - - Returns an anchor tag containing the virtual path to the specified action. - - The inner text of the anchor tag - The name of the action - The name of the controller - An anchor tag - - - - Returns an anchor tag containing the virtual path to the specified action. - - The inner text of the anchor tag - The name of the action - The name of the controller - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - An anchor tag - - - - Returns an anchor tag containing the virtual path to the specified action. - - The inner text of the anchor tag - The name of the action - The name of the controller - An object containing the parameters for a route - An object containing the html attributes for the element - An anchor tag - - - - Returns an anchor tag containing the url to the specified action. - - The inner text of the anchor tag - The name of the action - The name of the controller - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - The protocol for the URL such as "http" or "https" - The url fragment name (also known as anchor name) - The host name for the URL - An anchor tag - - - - Returns an anchor tag containing the url to the specified action. - - The inner text of the anchor tag - The name of the action - The name of the controller - An object containing the parameters for a route - An object containing the html attributes for the element - The protocol for the URL such as "http" or "https" - The url fragment name (also known as anchor name) - The host name for the URL - An anchor tag - - - - Returns an anchor tag containing the virtual path for the specified route values. - - The inner text of the anchor tag - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - An anchor tag - - - - Returns an anchor tag containing the virtual path for the specified route values. - - The inner text of the anchor tag - An object containing the parameters for a route - An anchor tag - - - - Returns an anchor tag containing the virtual path for the specified route values. - - The inner text of the anchor tag - The name of the route used to return a virtual path. - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - An anchor tag - - - - Returns an anchor tag containing the virtual path for the specified route values. - - The inner text of the anchor tag - The name of the route used to return a virtual path. - An object containing the parameters for a route - An anchor tag - - - - Returns an anchor tag containing the virtual path for the specified route values. - - The inner text of the anchor tag - The name of the route used to return a virtual path. - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - An anchor tag - - - - Returns an anchor tag containing the virtual path for the specified route values. - - The inner text of the anchor tag - The name of the route used to return a virtual path. - An object containing the parameters for a route - An object containing the html attributes for the element - An anchor tag - - - - Returns an anchor tag containing the virtual path for the specified route values. - - The inner text of the anchor tag - The name of the route used to return a virtual path. - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - An anchor tag - - - - Returns an anchor tag containing the virtual path for the specified route values. - - The inner text of the anchor tag - The name of the route used to return a virtual path. - An object containing the parameters for a route - An object containing the html attributes for the element - An anchor tag - - - - Returns an anchor tag containing the url for the specified route values. - - The inner text of the anchor tag - The name of the route used to return a virtual path. - The host name for the URL - The protocol for the URL such as "http" or "https" - The url fragment name (also known as anchor name) - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - An anchor tag - - - - Returns an anchor tag containing the url for the specified route values. - - The inner text of the anchor tag - The name of the route used to return a virtual path. - The host name for the URL - The protocol for the URL such as "http" or "https" - The url fragment name (also known as anchor name) - An object containing the parameters for a route - An object containing the html attributes for the element - An anchor tag - - - - Represents the state of an attempt to bind a posted form to an action method including validation information. - - - - - Initializes a new instance of the class - - - - - Initializes a new instance of the class with the values copied - from the the specified ModelStateDictionary. - - - - - Adds the specified to the errors collection for the - associated with the specified key. - - - - - - - Adds the specified error message to the errors collection for the - associated with the specified key. - - - - - - - Returns true if there are any associated or prefixed with the specified key. - - - - - - - Copies the values from the specified into this - dictionary, overwriting existing values in cases where the keys are the same. - - - - - - Sets the value for the specified key using the specified - - - - - - - Gets the number of key/value pairs that are in the collection. - - - - - Returns true if there are no errors, otherwise false. - - - - - Gets a collection that contains the keys in the dictionary. - - - - - Gets or sets the value that is associated with the specified key. - - - - - - - Gets a collection that contains the values in the dictionary. - - - - - Initializes a new instance of the class. - - An object that contains information about the current request and the defined route it matched. - - - - Initializes a new instance of the class. - - An object that contains information about the current request and the defined route it matched. - A collection of Route instances. - - - - Returns a virtual path for the specified route values. - - The name of the action - The virtual path to the action - - - - Returns a virtual path URL for the specified route values. - - The name of the action - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - The virtual path to the action - - - - Returns a virtual path for the specified route values. - - The name of the action - An object containing the parameters for a route. - The virtual path to the action - - - - Returns a virtual path for the specified route values. - - The name of the action - The name of the controller - The virtual path to the action - - - - Returns a virtual path for the specified route values. - - The name of the action - The name of the controller - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - The virtual path to the action - - - - Returns a virtual path for the specified route values. - - The name of the action - The name of the controller - An object containing the parameters for a route. - The protocol for the URL such as "http" or "https" - The virtual path to the action - - - - Returns a fully qualified URL for the specified route values. - - The name of the action - The name of the controller - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - The protocol for the URL such as "http" or "https" - The URL to the action - - - - Returns a fully qualified URL for the specified route values. - - The name of the action - The name of the controller - An object containing the parameters for a route - The protocol for the URL such as "http" or "https" - The host name for the URL - The URL to the action - - - - Converts a virtual path to an application absolute path. - - - If the specified does not start with the tilde [~] character, - then this method returns the specified unchanged. - - The virtual path to the content. - - - - - Encodes a URL string - - The text to encode - An encoded string - - - - Returns a virtual path for the specified route values. - - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - A virtual path - - - - Returns a virtual path for the specified route values. - - An object containing the parameters for a route. - A virtual path - - - - Returns a virtual path for the specified route values. - - The name of the route used to return a virtual path. - A virtual path - - - - Returns a virtual path for the specified route values. - - The name of the route used to return a virtual path. - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - A virtual path - - - - Returns a virtual path for the specified route values. - - The name of the route used to return a virtual path. - An object containing the parameters for a route. - A virtual path - - - - Returns a fully qualified URL for the specified route values. - - The name of the route used to return a virtual path. - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - The protocol for the URL such as "http" or "https" - A virtual path - - - - Returns a fully qualified URL for the specified route values. - - The name of the route used to generate the virtual path - The name of the controller - An object containing the parameters for a route - The protocol for the URL such as "http" or "https" - The host name for the URL - The virtual path to the action - - - - Encapsulates information about an HTTP request that matches a defined route. - - - - - A collection containing the routes registered for the application. - - - - - Class containing convenience methods for use in rendering HTML in a view. - - - - - Returns the string for a hidden input containing a token used to prevent CSRF attacks. - - - - - - Returns the string for a hidden input containing a token used to prevent CSRF attacks. - - A salt to use when generating the token - - - - - Method used to encode HTML attribute values. - - The string to encode - - - - - Method used to encode HTML attribute values. - - The object to encode - - - - - Method used to encode HTML. - - The string to encode - - - - - Method used to encode HTML. - - The object to encode - - - - - Convenience method used to generate a link using Routing to determine the virtual path. - - The current - The collection of routes. - The text displayed in the link - The name of the route, if any. - The name of the action. - The name of the controller. - The route values - The html attributes - - - - - Convenience method used to generate a link using Routing to determine the URL. - - The current - The collection of routes. - The text displayed in the link - The name of the route, if any. - The name of the action. - The name of the controller. - The route values - The html attributes - The protocol to use, such as http or https. - The hostname for the URL - The fragment to append to the end of the URL - - - - - Convenience method which converts the value into a string. - - - - - - - Convenience method for converting the value to a string - - - - - - - Gets or sets the string which replaces the dot character in the ID of html elements generated by HTML helpers. - - - - - Gets the collection of routes. - - - - - Gets the current . - - - - - Gets the current . - - - - - Gets the current . - - - - - A collection of instances. - - - - - Adds an to the - - - - - - Adds an error message to the - - - - - - When applied to an action method, specifies which HTTP verbs the method will respond to. - - - - - Gets the list of HTTP verbs the action method will respond to. - - - - - Represents an error that occured while attempting to bind a request to the arguments of an action method. - - - - - Initializes a new instance of the class with the specified exception. - - - For security reasons, the exception's ErrorMessage property is not set to the - Exception's Message property by default. - - - - - - Initializes a new instance of the class with the specified exception and error message. - - - - - - - Initializes a new instance of the class with the specified error message. - - - - - - The , if any, that occurred while binding to the model. - - - - - - - - - - Represents the result of an attempt to bind a supplied value (from a form post, query string, etc...) to - a property of an argument to an action method or to the argument itself. - - - - - Initializes a new instance of the class with the specified - raw value, attempted value, and . - - - - - - - - Converts the value encapsulated by this result to the specified type. - - The target type - - - - - Converts the value encapsulated by this result to the specified type. - - The target type - The culture to use in the conversion. - - - - - The RawValue converted to a string for display purposes. - - - - - The raw value supplied by the value provider. - - - - - Sends binary content to the response. - - - - - Initializes a new instance of with the specified file contents and content type. - - The byte array to send to the response - The content type to use for the response - - - - The binary content to send to the response. - - - - - Class used by the Html helpers to build HTML tags. - - - - - Encapsulates the state of model binding to a property of an argument, or the argument itself, of an action method. - - - - - Returns a which encapsulates the value which was attempted to be bound by model binding. - - - - - Returns a containing any errors that occurred during model binding. - - - - - Returns a textarea tag suitable for entering multiline input. - - - The form field name and ViewData key used to lookup the value. - An textarea tag - - - - Returns a textarea tag suitable for entering multiline input. - - - The form field name and ViewData key used to lookup the value. - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - An textarea tag - - - - Returns a textarea tag suitable for entering multiline input. - - - The form field name and ViewData key used to lookup the value. - An object containing the html attributes for the element - An textarea tag - - - - Returns a textarea tag suitable for entering multiline input. - - - The form field name and ViewData key used to lookup the value. - The value of the input. If null, looks at the ViewData and then ModelStatefor the value. - An textarea tag - - - - Returns a textarea tag suitable for entering multiline input. - - - The form field name and ViewData key used to lookup the value. - The value of the input. If null, looks at the ViewData and then ModelStatefor the value. - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - An textarea tag - - - - Returns a textarea tag suitable for entering multiline input. - - - The form field name and ViewData key used to lookup the value. - The value of the input. If null, looks at the ViewData and then ModelStatefor the value. - An object containing the html attributes for the element - An textarea tag - - - - Returns a textarea tag suitable for entering multiline input. - - - The form field name and ViewData key used to lookup the value. - The value of the input. If null, looks at the ViewData and then ModelStatefor the value. - The number of columns - The number of rows - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - An textarea tag - - - - Returns a textarea tag suitable for entering multiline input. - - - The form field name and ViewData key used to lookup the value. - The value of the input. If null, looks at the ViewData and then ModelStatefor the value. - The number of columns - The number of rows - An object containing the html attributes for the element - An textarea tag - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. - - - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. - - - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. - - - An object containing the parameters for a route - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. - - - The name of the action - The name of the controller - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. - - - The name of the action - The name of the controller - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. - - - The name of the action - The name of the controller - An object containing the parameters for a route - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. - - - The name of the action - The name of the controller - The HTTP method for the form post, either Get or Post - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. - - - The name of the action - The name of the controller - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - The HTTP method for the form post, either Get or Post - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. - - - The name of the action - The name of the controller - An object containing the parameters for a route - The HTTP method for the form post, either Get or Post - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. - - - The name of the action - The name of the controller - The HTTP method for the form post, either Get or Post - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. - - - The name of the action - The name of the controller - The HTTP method for the form post, either Get or Post - An object containing the html attributes for the element - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. - - - The name of the action - The name of the controller - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - The HTTP method for the form post, either Get or Post - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. - - - The name of the action - The name of the controller - An object containing the parameters for a route - The HTTP method for the form post, either Get or Post - An object containing the html attributes for the element - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. - - - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. - - - An object containing the parameters for a route - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. - - - The name of the route to used to obtain the form post url. - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. - - - The name of the route to used to obtain the form post url. - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. - - - The name of the route to used to obtain the form post url. - An object containing the parameters for a route - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. - - - The name of the route to used to obtain the form post url. - The HTTP method for the form post, either Get or Post - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. - - - The name of the route to used to obtain the form post url. - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - The HTTP method for the form post, either Get or Post - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. - - - The name of the route to used to obtain the form post url. - An object containing the parameters for a route - The HTTP method for the form post, either Get or Post - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. - - - The name of the route to used to obtain the form post url. - The HTTP method for the form post, either Get or Post - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. - - - The name of the route to used to obtain the form post url. - The HTTP method for the form post, either Get or Post - An object containing the html attributes for the element - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. - - - The name of the route to used to obtain the form post url. - An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. - The HTTP method for the form post, either Get or Post - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - An instance. - - - - Writes a begin form tag to the response while returning an - instance. Can be used in a using block in which case it renders the end form tag at the end of the - using block. - - - The name of the route to used to obtain the form post url. - An object containing the parameters for a route - The HTTP method for the form post, either Get or Post - An object containing the html attributes for the element - An instance. - - - - Renders the end form tag to the response. This provides an alternative way to end the form - to using a using block with and . - - - - - - Sends the contents of a file to the response. - - - - - Initializes an instance of with the specified file name and content type. - - The name of the file to send to the response. - The content type of the response. - - - - The path to the file which is sent to the response. - - - - - Represents a result that doesn't do anything, like a controller action returning null. - - - This follows a pattern known as the Null Object pattern - - - - - Defines the contract for temp data providers which store data viewed on the next request. - - - - - Displays a validation message if the specified field contains an error in the ModelState. - - - The name of the property or model object being validated - An empty string if valid, otherwise a span with an error message - - - - Displays a validation message if the specified field contains an error in the ModelState. - - - The name of the property or model object being validated - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - An empty string if valid, otherwise a span with an error message - - - - Displays a validation message if the specified field contains an error in the ModelState. - - - The name of the property or model object being validated - The message to display if the specified field is in error - An empty string if valid, otherwise a span with an error message - - - - Displays a validation message if the specified field contains an error in the ModelState. - - - The name of the property or model object being validated - The message to display if the specified field is in error - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - An empty string if valid, otherwise a span with an error message - - - - Displays a validation message if the specified field contains an error in the ModelState. - - - The name of the property or model object being validated - An object containing the html attributes for the element - An empty string if valid, otherwise a span with an error message - - - - Displays a validation message if the specified field contains an error in the ModelState. - - - The name of the property or model object being validated - The message to display if the specified field is in error - An object containing the html attributes for the element - An empty string if valid, otherwise a span with an error message - - - - Returns an unordered list [ul] of validation messages within the ModelState. - - - - - - - Returns an unordered list [ul] of validation messages within the ModelState. - - - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - - - - - Returns an unordered list [ul] of validation messages within the ModelState. - - - An object containing the html attributes for the element - - - - - Returns a select tag used to select a single option from a set of possible choices. - - - The name of the form field and used as a key to lookup possible options. If ViewData[name] implements IEnumerable of . - Provides the text for a default empty valued option, if it is not null. - - - - - Returns a select tag used to select a single option from a set of possible choices. - - - The name of the form field and used as a key to lookup possible options. If ViewData[name] implements IEnumerable of . - The enumeration of SelectListItem instances used to populate the drop down. - Provides the text for a default empty valued option, if it is not null. - - - - - Returns a select tag used to select a single option from a set of possible choices. - - - The name of the form field and used as a key to lookup possible options. If ViewData[name] implements IEnumerable of . - The enumeration of SelectListItem instances used to populate the drop down. - Provides the text for a default empty valued option, if it is not null. - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - - - - - Returns a select tag used to select a single option from a set of possible choices. - - - The name of the form field and used as a key to lookup possible options. If ViewData[name] implements IEnumerable of . - - - - - Returns a select tag used to select a single option from a set of possible choices. - - - The name of the form field and used as a key to lookup possible options. If ViewData[name] implements IEnumerable of . - The enumeration of SelectListItem instances used to populate the drop down. - - - - - Returns a select tag used to select a single option from a set of possible choices. - - - The name of the form field and used as a key to lookup possible options. If ViewData[name] implements IEnumerable of . - The enumeration of SelectListItem instances used to populate the drop down. - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - - - - - Returns a select tag used to select a single option from a set of possible choices. - - - The name of the form field and used as a key to lookup possible options. If ViewData[name] implements IEnumerable of . - The enumeration of SelectListItem instances used to populate the drop down. - An object containing the html attributes for the element. - - - - - Returns a select tag used to select a single option from a set of possible choices. - - - The name of the form field and used as a key to lookup possible options. If ViewData[name] implements IEnumerable of . - The enumeration of SelectListItem instances used to populate the drop down. - Provides the text for a default empty valued option, if it is not null. - An object containing the html attributes for the element. - - - - - Returns a select tag used to select a multiple options from a set of possible choices. - - - The name of the form field and used as a key to lookup possible options. If ViewData[name] implements IEnumerable of . - - - - - Returns a select tag used to select a multiple options from a set of possible choices. - - - The name of the form field and used as a key to lookup possible options. If ViewData[name] implements IEnumerable of . - The enumeration of SelectListItem instances used to populate the drop down. - - - - - Returns a select tag used to select a multiple options from a set of possible choices. - - - The name of the form field and used as a key to lookup possible options. If ViewData[name] implements IEnumerable of . - The enumeration of SelectListItem instances used to populate the drop down. - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - - - - - Returns a select tag used to select a multiple options from a set of possible choices. - - - The name of the form field and used as a key to lookup possible options. If ViewData[name] implements IEnumerable of . - The enumeration of SelectListItem instances used to populate the drop down. - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - - - - - Returns the input tag for a checkbox. - - - The form field name - An input tag with the type set to "checkbox" - - - - Returns the input tag for a checkbox. - - - The form field name - A boolean indicating whether or not the checkbox is checked - An input tag with the type set to "checkbox" - - - - Returns the input tag for a checkbox. - - - The form field name - A boolean indicating whether or not the checkbox is checked - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - An input tag with the type set to "checkbox" - - - - Returns the input tag for a checkbox. - - - The form field name - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - An input tag with the type set to "checkbox" - - - - Returns the input tag for a checkbox. - - - The form field name - An object containing the html attributes for the element - An input tag with the type set to "checkbox" - - - - Returns the input tag for a checkbox. - - - The form field name - A boolean indicating whether or not the checkbox is checked - An object containing the html attributes for the element - An input tag with the type set to "checkbox" - - - - Returns a hidden input tag. - - - The form field name and ViewData key used to lookup the value. - An input tag with the type set to "hidden" - - - - Returns a hidden input tag. - - - The form field name and ViewData key used to lookup the value. - The value of the hidden input. If null, looks at the ViewData and then ModelStatefor the value. - An input tag with the type set to "hidden" - - - - Returns a hidden input tag. - - - The form field name and ViewData key used to lookup the value. - The value of the hidden input. If null, looks at the ViewData and then ModelStatefor the value. - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - An input tag with the type set to "hidden" - - - - Returns a hidden input tag. - - - The form field name and ViewData key used to lookup the value. - The value of the hidden input. If null, looks at the ViewData and then ModelStatefor the value. - An object containing the html attributes for the element - An input tag with the type set to "hidden" - - - - Returns a password tag. - - - The form field name and ViewData key used to lookup the value. - An input tag with the type set to "password" - - - - Returns a password tag. - - - The form field name and ViewData key used to lookup the value. - The value of the input. If null, looks at the ViewData and then ModelStatefor the value. - An input tag with the type set to "password" - - - - Returns a password tag. - - - The form field name and ViewData key used to lookup the value. - The value of the input. If null, looks at the ViewData and then ModelStatefor the value. - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - An input tag with the type set to "password" - - - - Returns a password tag. - - - The form field name and ViewData key used to lookup the value. - The value of the input. If null, looks at the ViewData and then ModelStatefor the value. - An object containing the html attributes for the element - An input tag with the type set to "password" - - - - Returns a radio button tag used to present one possible value, out of a range, for a form field specified by the name. - - - The form field name and ViewData key used to lookup the current value. - If checked, the value of the radio button submitted when the form is posted. If the value in ViewData or ModelState matches this value, the radio button is checked. - An input tag with the type set to "radio" - - - - Returns a radio button tag used to present one possible value, out of a range, for a form field specified by the name. - - - The form field name and ViewData key used to lookup the current value. - If checked, the value of the radio button submitted when the form is posted. If the value in ViewData or ModelState matches this value, the radio button is checked. - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - An input tag with the type set to "radio" - - - - Returns a radio button tag used to present one possible value, out of a range, for a form field specified by the name. - - - The form field name and ViewData key used to lookup the current value. - If checked, the value of the radio button submitted when the form is posted. If the value in ViewData or ModelState matches this value, the radio button is checked. - An object containing the html attributes for the element - An input tag with the type set to "radio" - - - - Returns a radio button tag used to present one possible value, out of a range, for a form field specified by the name. - - - The form field name and ViewData key used to lookup the current value. - If checked, the value of the radio button submitted when the form is posted. If the value in ViewData or ModelState matches this value, the radio button is checked. - Whether or not the radio button is checked - An input tag with the type set to "radio" - - - - Returns a radio button tag used to present one possible value, out of a range, for a form field specified by the name. - - - The form field name and ViewData key used to lookup the current value. - If checked, the value of the radio button submitted when the form is posted. If the value in ViewData or ModelState matches this value, the radio button is checked. - Whether or not the radio button is checked - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - An input tag with the type set to "radio" - - - - Returns a radio button tag used to present one possible value, out of a range, for a form field specified by the name. - - - The form field name and ViewData key used to lookup the current value. - If checked, the value of the radio button submitted when the form is posted. If the value in ViewData or ModelState matches this value, the radio button is checked. - Whether or not the radio button is checked - An object containing the html attributes for the element - An input tag with the type set to "radio" - - - - Returns a text input tag. - - - The form field name and ViewData key used to lookup the value. - An input tag with the type set to "text" - - - - Returns a text input tag. - - - The form field name and ViewData key used to lookup the value. - The value of the input. If null, looks at the ViewData and then ModelStatefor the value. - An input tag with the type set to "text" - - - - Returns a text input tag. - - - The form field name and ViewData key used to lookup the value. - The value of the input. If null, looks at the ViewData and then ModelStatefor the value. - An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax - An input tag with the type set to "text" - - - - Returns a text input tag. - - - The form field name and ViewData key used to lookup the value. - The value of the input. If null, looks at the ViewData and then ModelStatefor the value. - An object containing the html attributes for the element - An input tag with the type set to "text" - - - - Initializes a new instance of the - with the specified . - - - - - - Attribute used to provide details on how model binding to a parameter should occur. - - - - - A comma delimited black list of property names for which binding is not allowed. - - - - - A comma delimited white list of property names for which binding is allowed. - - - - - Gets or sets the prefix to use when binding to an action argument or model property. - - - - + + + + System.Web.Mvc + + + + + Class used to render a view using an returned by a . + + + + + Base class used to supply the model to the view and then render the view to the response. + + + + + Encapsulates the result of an action method and is used to perform a + framework level operation on the action method's behalf. + + + + + Enables processing of the result of an action method by a custom type that inherits from . + + + + + + When called by the action invoker, renders the view to the response. + + + + + + When overridden, returns the used to render the view. + + + + + + + Gets or sets the for this result. + + + + + Gets or sets the that is rendered to the response. + + + + + Gets or sets the view data for this result. + + + + + Gets or sets the view engines () associated with this result. + + + + + The name of the view to be rendered. + + + + + Searches the registered view engines and returns the used to render the view. + + + + + + + The name of the master view (such as a master page or template) to use when rendering the view. + + + + + Defines the contract for an action invoker, used to invoke an action in response to an http request. + + + + + Invokes the specified action. + + + The name of the action. + True if the action was found, otherwise false. + + + + Renders the specified partial view. + + + The name of the partial view + + + + Renders the specified partial view replacing its ViewData property with the + supplied ViewDataDictionary. + + + The name of the partial view + + + + Renders the specified partial view passing in a copy of the current + ViewDataDictionary, but + with the Model property set to the specified model. + + + The name of the partial view + + + + Renders the specified partial view, replacing the partial view's ViewData property with the + supplied ViewDataDictionary. The Model + property of the view data is set to the specified model. + + + The name of the partial view + The model for the partial view + The view data for the partial view + + + + Sends binary content to the response via a . + + + + + Base class used to send binary content to the response + + + + + The content type to use for the response. + + + + + If specified, sets the content-disposition header so that a file download dialog appears in the browesr with the specified file name. + + + + + Initializes a new instance of + + The stream to send to the response + The content type to use for the response + + + + Gets the stream which will be sent to the response. + + + + + Returns an anchor tag containing the url to the specified action such that when the action link is clicked, + the action is invoked asynchronously via javascript. + + The inner text of the anchor tag + The name of the action + + An object providing options for the asynchronous request + An anchor tag + + + + Returns an anchor tag containing the url to the specified action such that when the action link is clicked, + the action is invoked asynchronously via javascript. + + The inner text of the anchor tag + The name of the action + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + + An object providing options for the asynchronous request + An anchor tag + + + + Returns an anchor tag containing the url to the specified action such that when the action link is clicked, + the action is invoked asynchronously via javascript. + + The inner text of the anchor tag + The name of the action + The name of the controller + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + The protocol for the URL such as "http" or "https" + The url fragment name (also known as anchor name) + The host name for the URL + + An object providing options for the asynchronous request + An anchor tag + + + + Returns an anchor tag containing the url to the specified action such that when the action link is clicked, + the action is invoked asynchronously via javascript. + + The inner text of the anchor tag + The name of the action + An object containing the parameters for a route. + + An object providing options for the asynchronous request + An anchor tag + + + + Returns an anchor tag containing the url to the specified action such that when the action link is clicked, + the action is invoked asynchronously via javascript. + + The inner text of the anchor tag + The name of the action + An object containing the parameters for a route. + An object containing the html attributes for the element. + + An object providing options for the asynchronous request + An anchor tag + + + + Returns an anchor tag containing the url to the specified action such that when the action link is clicked, + the action is invoked asynchronously via javascript. + + The inner text of the anchor tag + The name of the action + The name of the controller + + An object providing options for the asynchronous request + An anchor tag + + + + Returns an anchor tag containing the url to the specified action such that when the action link is clicked, + the action is invoked asynchronously via javascript. + + The inner text of the anchor tag + The name of the action + The name of the controller + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + + An object providing options for the asynchronous request + An anchor tag + + + + Returns an anchor tag containing the url to the specified action such that when the action link is clicked, + the action is invoked asynchronously via javascript. + + The inner text of the anchor tag + The name of the action + The name of the controller + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + + An object providing options for the asynchronous request + An anchor tag + + + + Returns an anchor tag containing the url to the specified action such that when the action link is clicked, + the action is invoked asynchronously via javascript. + + The inner text of the anchor tag + The name of the action + The name of the controller + An object containing the parameters for a route.. + + An object providing options for the asynchronous request + An anchor tag + + + + Returns an anchor tag containing the url to the specified action such that when the action link is clicked, + the action is invoked asynchronously via javascript. + + The inner text of the anchor tag + The name of the action + The name of the controller + An object containing the parameters for a route. + An object containing the html attributes for the element. + + An object providing options for the asynchronous request + An anchor tag + + + + Returns an anchor tag containing the url to the specified action such that when the action link is clicked, + the action is invoked asynchronously via javascript. + + The inner text of the anchor tag + The name of the action + The name of the controller + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + The protocol for the URL such as "http" or "https" + The url fragment name (also known as anchor name) + The host name for the URL + + An object providing options for the asynchronous request + An anchor tag + + + + Returns an anchor tag containing the url to the specified action such that when the action link is clicked, + the action is invoked asynchronously via javascript. + + The inner text of the anchor tag + The name of the action + The name of the controller + An object containing the parameters for a route. + An object containing the html attributes for the element. + The protocol for the URL such as "http" or "https" + The url fragment name (also known as anchor name) + The host name for the URL + + An object providing options for the asynchronous request + An anchor tag + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. The form is submitted asynchronously using javascript. + + + An object providing options for the asynchronous request + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. The form is submitted asynchronously using javascript. + + + The name of the action + An object providing options for the asynchronous request + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. The form is submitted asynchronously using javascript. + + + The name of the action + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + An object providing options for the asynchronous request + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. The form is submitted asynchronously using javascript. + + + The name of the action + The name of the controller + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + An object containing the html attributes for the element. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + An object providing options for the asynchronous request + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. The form is submitted asynchronously using javascript. + + + The name of the action + The name of the controller + An object containing the parameters for a route. + An object providing options for the asynchronous request + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. The form is submitted asynchronously using javascript. + + + The name of the action + An object containing the parameters for a route. + An object containing the html attributes for the element. + An object providing options for the asynchronous request + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. The form is submitted asynchronously using javascript. + + + The name of the action + The name of the controller + An object providing options for the asynchronous request + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. The form is submitted asynchronously using javascript. + + + The name of the action + The name of the controller + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + An object providing options for the asynchronous request + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. The form is submitted asynchronously using javascript. + + + The name of the action + The name of the controller + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + An object containing the html attributes for the element. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + An object providing options for the asynchronous request + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. The form is submitted asynchronously using javascript. + + + The name of the action + The name of the controller + An object containing the parameters for a route + An object providing options for the asynchronous request + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. The form is submitted asynchronously using javascript. + + + The name of the action + The name of the controller + An object containing the parameters for a route + An object containing the html attributes for the element + An object providing options for the asynchronous request + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. The form is submitted asynchronously using javascript. + + + The name of the route to used to obtain the form post url. + An object providing options for the asynchronous request + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. The form is submitted asynchronously using javascript. + + + The name of the route to used to obtain the form post url. + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + An object providing options for the asynchronous request + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. The form is submitted asynchronously using javascript. + + + The name of the route to used to obtain the form post url. + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + An object containing the html attributes for the element. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + An object providing options for the asynchronous request + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. The form is submitted asynchronously using javascript. + + + The name of the route to used to obtain the form post url. + An object containing the parameters for a route. + An object providing options for the asynchronous request + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. The form is submitted asynchronously using javascript. + + + The name of the route to used to obtain the form post url. + An object containing the parameters for a route. + An object containing the html attributes for the element. + An object providing options for the asynchronous request + An instance. + + + + Returns an anchor tag containing the virtual path for the specified route values such that when the link is clicked, + a request is made to the virtual path asynchronously via javascript. + + + The inner text of the anchor tag + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + An object providing options for the asynchronous request + An anchor tag + + + + Returns an anchor tag containing the virtual path for the specified route values such that when the link is clicked, + a request is made to the virtual path asynchronously via javascript. + + + The inner text of the anchor tag + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + An object providing options for the asynchronous request + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + An anchor tag + + + + Returns an anchor tag containing the virtual path for the specified route values such that when the link is clicked, + a request is made to the virtual path asynchronously via javascript. + + + The inner text of the anchor tag + An object containing the parameters for a route. + An object providing options for the asynchronous request + An anchor tag + + + + Returns an anchor tag containing the virtual path for the specified route values such that when the link is clicked, + a request is made to the virtual path asynchronously via javascript. + + + The inner text of the anchor tag + An object containing the parameters for a route. + An object providing options for the asynchronous request + An object containing the html attributes for the element + An anchor tag + + + + Returns an anchor tag containing the virtual path for the specified route values such that when the link is clicked, + a request is made to the virtual path asynchronously via javascript. + + + The inner text of the anchor tag + The name of the route to used to obtain the form post url. + An object providing options for the asynchronous request + An anchor tag + + + + Returns an anchor tag containing the virtual path for the specified route values such that when the link is clicked, + a request is made to the virtual path asynchronously via javascript. + + + The inner text of the anchor tag + The name of the route to used to obtain the form post url. + An object providing options for the asynchronous request + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + An anchor tag + + + + Returns an anchor tag containing the virtual path for the specified route values such that when the link is clicked, + a request is made to the virtual path asynchronously via javascript. + + + The inner text of the anchor tag + The name of the route to used to obtain the form post url. + An object providing options for the asynchronous request + An object containing the html attributes for the element + An anchor tag + + + + Returns an anchor tag containing the virtual path for the specified route values such that when the link is clicked, + a request is made to the virtual path asynchronously via javascript. + + + The inner text of the anchor tag + The name of the route to used to obtain the form post url. + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + An object providing options for the asynchronous request + An anchor tag + + + + Returns an anchor tag containing the virtual path for the specified route values such that when the link is clicked, + a request is made to the virtual path asynchronously via javascript. + + + The inner text of the anchor tag + The name of the route to used to obtain the form post url. + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + An object providing options for the asynchronous request + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + An anchor tag + + + + Returns an anchor tag containing the virtual path for the specified route values such that when the link is clicked, + a request is made to the virtual path asynchronously via javascript. + + + The inner text of the anchor tag + The name of the route to used to obtain the form post url. + An object containing the parameters for a route. + An object providing options for the asynchronous request + An anchor tag + + + + Returns an anchor tag containing the virtual path for the specified route values such that when the link is clicked, + a request is made to the virtual path asynchronously via javascript. + + + The inner text of the anchor tag + The name of the route to used to obtain the form post url. + An object containing the parameters for a route. + An object providing options for the asynchronous request + An object containing the html attributes for the element + An anchor tag + + + + Returns an anchor tag containing the virtual path for the specified route values such that when the link is clicked, + a request is made to the virtual path asynchronously via javascript. + + + The inner text of the anchor tag + The name of the route to used to obtain the form post url. + The protocol for the URL such as "http" or "https" + The host name for the URL + The url fragment name (also known as anchor name) + An object containing the parameters for a route. + An object providing options for the asynchronous request + An object containing the html attributes for the element + An anchor tag + + + + A strongly-typed resource class, for looking up localized strings, etc. + + + + + Returns the cached ResourceManager instance used by this class. + + + + + Overrides the current thread's CurrentUICulture property for all + resource lookups using this strongly typed resource class. + + + + + Looks up a localized string similar to The current request for action '{0}' on controller type '{1}' is ambiguous between the following action methods:{2}. + + + + + Looks up a localized string similar to {0} on type {1}. + + + + + Looks up a localized string similar to No route in the route table matches the supplied values.. + + + + + Looks up a localized string similar to A required anti-forgery token was not supplied or was invalid.. + + + + + Looks up a localized string similar to The value '{0}' is outside the valid range of the enumeration type '{1}'.. + + + + + Looks up a localized string similar to Value cannot be null or empty.. + + + + + Looks up a localized string similar to The partial view '{0}' could not be found. The following locations were searched:{1}. + + + + + Looks up a localized string similar to The property '{0}' cannot be null or empty.. + + + + + Looks up a localized string similar to The value '{0}' is invalid.. + + + + + Looks up a localized string similar to The view '{0}' or its master could not be found. The following locations were searched:{1}. + + + + + Looks up a localized string similar to A public action method '{0}' could not be found on controller '{1}'.. + + + + + Looks up a localized string similar to The model of type '{0}' was not successfully updated.. + + + + + Looks up a localized string similar to There was an error creating the IControllerFactory '{0}'. Check that it has a public parameterless constructor.. + + + + + Looks up a localized string similar to The IControllerFactory '{0}' did not return a controller for a controller named '{1}'.. + + + + + Looks up a localized string similar to The controller factory type '{0}' must implement the IControllerFactory interface.. + + + + + Looks up a localized string similar to The controller name '{0}' is ambiguous between the following types:{1}. + + + + + Looks up a localized string similar to An error occurred while creating a controller of type '{0}'. If the controller doesn't have a controller factory, ensure that it has a parameterless public constructor.. + + + + + Looks up a localized string similar to The controller for path '{0}' could not be found or it does not implement IController.. + + + + + Looks up a localized string similar to The controller type '{0}' must implement IController.. + + + + + Looks up a localized string similar to A value is required.. + + + + + Looks up a localized string similar to The total number of ticks for the TimeSpan must be greater than 0.. + + + + + Looks up a localized string similar to The type '{0}' does not inherit from Exception.. + + + + + Looks up a localized string similar to Order must be greater than or equal to -1.. + + + + + Looks up a localized string similar to There is no ViewData item with the key '{0}' of type '{1}'.. + + + + + Looks up a localized string similar to The value must be greater than or equal to zero.. + + + + + Looks up a localized string similar to The ViewData item with the key '{0}' is of type '{1}' but needs to be of type '{2}'.. + + + + + Looks up a localized string similar to There was an error creating the IModelBinder '{0}'. Check that it has a public parameterless constructor.. + + + + + Looks up a localized string similar to The type '{0}' does not implement the IModelBinder interface.. + + + + + Looks up a localized string similar to The type '{0}' contains multiple attributes inheriting from CustomModelBinderAttribute.. + + + + + Looks up a localized string similar to Cannot create a descriptor for instance method '{0}' on type '{1}' since the type does not subclass ControllerBase.. + + + + + Looks up a localized string similar to Cannot call action method '{0}' on controller '{1}' since the parameter '{2}' is passed by reference.. + + + + + Looks up a localized string similar to Cannot call action method '{0}' on controller '{1}' since it is a generic method.. + + + + + Looks up a localized string similar to The parameters dictionary contains a null entry for parameter '{0}' of non-nullable type '{1}' for method '{2}' in '{3}'. To make a parameter optional its type should be either a reference type or a Nullable type.. + + + + + Looks up a localized string similar to The parameters dictionary does not contain an entry for parameter '{0}' of type '{1}' for method '{2}' in '{3}'. The dictionary must contain an entry for each parameter, even parameters with null values.. + + + + + Looks up a localized string similar to The parameters dictionary contains an invalid entry for parameter '{0}' for method '{1}' in '{2}'. The dictionary contains a value of type '{3}', but the parameter requires a value of type '{4}'.. + + + + + Looks up a localized string similar to The parameter '{0}' on method '{1}' contains multiple attributes inheriting from CustomModelBinderAttribute.. + + + + + Looks up a localized string similar to The SessionStateTempDataProvider requires SessionState to be enabled.. + + + + + Looks up a localized string similar to The parameter conversion from type '{0}' to type '{1}' failed. See the inner exception for more information.. + + + + + Looks up a localized string similar to The parameter conversion from type '{0}' to type '{1}' failed because no TypeConverter can convert between these types.. + + + + + Looks up a localized string similar to The model item passed into the dictionary is of type '{0}' but this dictionary requires a model item of type '{1}'.. + + + + + Looks up a localized string similar to A ViewMasterPage can only be used with content pages that derive from ViewPage or ViewPage<TViewItem>.. + + + + + Looks up a localized string similar to The ViewUserControl '{0}' cannot find an IViewDataContainer. The ViewUserControl must be inside a ViewPage, ViewMasterPage, or another ViewUserControl.. + + + + + Looks up a localized string similar to A ViewUserControl can only be used inside pages that derive from ViewPage or ViewPage<TViewItem>.. + + + + + Looks up a localized string similar to A master name cannot be specified when the view is a ViewUserControl.. + + + + + Looks up a localized string similar to The view found at '{0}' could not be created.. + + + + + Looks up a localized string similar to The view at '{0}' must derive from ViewPage, ViewPage<TViewData>, ViewUserControl, or ViewUserControl<TViewData>.. + + + + + Instantiates and initializes the Ajax, Html, and Url properties. + + + + + Renders the view page to the response. + + + + + + Returns an containing methods useful for AJAX scenarios. + + + + + Returns an containing methods useful for rendering HTML elements. + + + + + Convenience property used to access the Model property of the + + + + + Returns a which renders the supplied content to the response. + + The content to write to the response + + + + + Returns a which renders the supplied content to the response. + + The content to write to the response + The content type + + + + + Returns a which renders the supplied content to the response. + + The content to write to the response + The content type + The content encoding + + + + + Returns a which writes the fileContents to the Response. + + The binary content to send to the response. + The content type. + + + + + Returns a which writes the fileContents to the Response. + + The binary content to send to the response. + The content type. + If specified, sets the content-disposition header so that a file download dialog appears in the browesr with the specified file name + + + + + Returns a which writes the fileStream to the Response. + + The stream to send to the response. + The content type + + + + + Returns a which writes the fileStream to the Response. + + The stream to send to the response. + The content type + If specified, sets the content-disposition header so that a file download dialog appears in the browesr with the specified file name + + + + + Returns a which writes the file to the Response. + + The path to the file to send to the response. + The content type + + + + + Returns a which writes the file to the Response. + + The path to the file to send to the response. + The content type + If specified, sets the content-disposition header so that a file download dialog appears in the browesr with the specified file name + + + + + Method called whenever a request matches this controller, but not an action of this controller. + + The name of the attempted action + + + + Returns a which writes a script to the response + which is then executed on the client. + + The JavaScript code to run on the client + + + + + Returns a which serializes the specified object to + JSON and writes the JSON to the response. + + The JavaScript code to run on the client + + + + + Returns a which serializes the specified object to + JSON and writes the JSON to the response. + + The JavaScript code to run on the client + The content type + + + + + Returns a which serializes the specified object to + JSON and writes the JSON to the response. + + The JavaScript code to run on the client + The content type + The content encoding + + + + + Method called before the action method is invoked. + + Contains information about the current request and action + + + + Method called after the action method is invoked. + + Contains information about the current request and action + + + + Method called when authorization occurs. + + Contains information about the current request and action + + + + Method called when an unhandled exception occurs in the action. + + Contains information about the current request and action + + + + Method called after the action result returned by an action method is executed. + + Contains information about the current request and action result + + + + Method called before the action result returned by an action method is executed. + + Contains information about the current request and action result + + + + Returns a which renders a partial view to the response. + + + + + + Returns a which renders a partial view to the response. + + The model rendered by the partial view + + + + Returns a which renders a partial view to the response. + + The name of the partial view + + + + Returns a which renders a partial view to the response. + + The name of the partial view + The model rendered by the partial view + + + + Returns a which redirects to the specified URL + + The URL to redirect to. + + + + + Returns a which redirects to the specified action + + The name of the action. + + + + + Returns a which redirects to the specified action + + The name of the action. + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + + + + + Returns a which redirects to the specified action + + The name of the action. + An object containing the parameters for a route. + + + + + Returns a which redirects to the specified action + + The name of the action. + The name of the controller + + + + + Returns a which redirects to the specified action + + The name of the action. + The name of the controller + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + + + + + Returns a which redirects to the specified action + + The name of the action. + The name of the controller + An object containing the parameters for a route. + + + + + Returns a which redirects to the specified route + + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + + + + + Returns a which redirects to the specified route + + An object containing the parameters for a route. + + + + + Returns a which redirects to the specified route + + The name of the route + + + + + Returns a which redirects to the specified route + + The name of the route + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + + + + + Returns a which redirects to the specified route + + The name of the route + An object containing the parameters for a route. + + + + + Updates the specified model instance using values from the Controller's current ValueProvider. + Returns true if successful. + + The type of the model object + The model instance to update. + + + + Updates the specified model instance using values from the Controller's current ValueProvider. + Returns true if successful. + + The type of the model object + The model instance to update. + Prefix to use when looking up values in the value provider + + + + Updates the specified model instance using values from the Controller's current ValueProvider. + Returns true if successful. + + The type of the model object + The model instance to update. + List of properties of the model to update + + + + Updates the specified model instance using values from the Controller's current ValueProvider. + Returns true if successful. + + The type of the model object + The model instance to update. + List of properties of the model to update + Prefix to use when looking up values in the value provider + + + + Updates the specified model instance using values from the Controller's current ValueProvider. + Returns true if successful. + + The type of the model object + The model instance to update. + Prefix to use when looking up values in the value provider + List of properties of the model to update + List of properties to explicitly exclude from update. These are excluded even if they are listed in the includeProperties list + + + + Updates the specified model instance using values from the Controller's current ValueProvider. + Returns true if successful. + + The type of the model object + The model instance to update. + A dictionary of values used to update the model + + + + Updates the specified model instance using values from the Controller's current ValueProvider. + Returns true if successful. + + The type of the model object + The model instance to update. + Prefix to use when looking up values in the value provider + A dictionary of values used to update the model + + + + Updates the specified model instance using values from the Controller's current ValueProvider. + Returns true if successful. + + The type of the model object + The model instance to update. + List of properties of the model to update + A dictionary of values used to update the model + + + + Updates the specified model instance using values from the Controller's current ValueProvider. + Returns true if successful. + + The type of the model object + The model instance to update. + Prefix to use when looking up values in the value provider + List of properties of the model to update + A dictionary of values used to update the model + + + + Updates the specified model instance using values from the Controller's current ValueProvider. + Returns true if successful. + + The type of the model object + The model instance to update. + Prefix to use when looking up values in the value provider + List of properties of the model to update + List of properties to explicitly exclude from update. These are excluded even if they are listed in the includeProperties list + A dictionary of values used to update the model + + + + Updates the specified model instance using values from the Controller's current ValueProvider. + + The type of the model object + The model instance to update. + + + + Updates the specified model instance using values from the Controller's current ValueProvider. + + The type of the model object + The model instance to update. + Prefix to use when looking up values in the value provider + + + + Updates the specified model instance using values from the Controller's current ValueProvider. + + The type of the model object + The model instance to update. + List of properties of the model to update + + + + Updates the specified model instance using values from the Controller's current ValueProvider. + + The type of the model object + The model instance to update. + Prefix to use when looking up values in the value provider + List of properties of the model to update + + + + Updates the specified model instance using values from the Controller's current ValueProvider. + + The type of the model object + The model instance to update. + Prefix to use when looking up values in the value provider + List of properties of the model to update + List of properties to explicitly exclude from update. These are excluded even if they are listed in the includeProperties list + + + + Updates the specified model instance using values from the Controller's current ValueProvider. + + The type of the model object + The model instance to update. + A dictionary of values used to update the model + + + + Updates the specified model instance using values from the Controller's current ValueProvider. + + The type of the model object + The model instance to update. + Prefix to use when looking up values in the value provider + A dictionary of values used to update the model + + + + Updates the specified model instance using values from the Controller's current ValueProvider. + + The type of the model object + The model instance to update. + List of properties of the model to update + A dictionary of values used to update the model + + + + Updates the specified model instance using values from the Controller's current ValueProvider. + + The type of the model object + The model instance to update. + Prefix to use when looking up values in the value provider + List of properties of the model to update + A dictionary of values used to update the model + + + + Updates the specified model instance using values from the Controller's current ValueProvider. + + The type of the model object + The model instance to update. + Prefix to use when looking up values in the value provider + List of properties of the model to update + List of properties to explicitly exclude from update. These are excluded even if they are listed in the includeProperties list + A dictionary of values used to update the model + + + + Returns a which renders a view to the response. + + + + + + Returns a which renders a view to the response. + + The model rendered by the view + + + + + Returns a which renders a view to the response. + + The name of the partial view + + + + + Returns a which renders a view to the response. + + The name of the view + The name of the master view + + + + + Returns a which renders a view to the response. + + The name of the view + The model rendered by the view + + + + + Returns a which renders a view to the response. + + The name of the view + The name of the master view + The model rendered by the view + + + + + Returns a which renders the specified to the response. + + The view rendered to the response + + + + + Returns a which renders the specified to the response. + + The view rendered to the response + The model rendered by the view + + + + + Gets the for the controller. + + + + + Encapsulates all HTTP-specific information about an individual HTTP request. + + + + + Gets the object containing the + state of the model and model binding validation. + + + + + Gets the object for the current HTTP request. + + + + + Gets the object for the current HTTP request. + + + + + Returns the for the current request. + + + + + Gets the object that provides methods used in processing Web requests. + + + + + Gets the object for the current HTTP request. + + + + + Gets the object used to store data for the next request. + + + + + Gets the object used to generate URLs using Routing. + + + + + Gets the security information for the current HTTP request. + + + + + Class containing convenience methods for use in rendering HTML for use in Ajax scenarios within a view. + + + + + Gets the collection of routes. + + + + + Gets the current . + + + + + Gets the current . + + + + + Gets the current . + + + + + Encapsulates information related to rendering a view. + + + + + Encapsulates information about an HTTP request that matches a defined Route and Controller. + + + + + Gets data associated with this request which only lives for one request. + + + + + Gets the to render. + + + + + Gets the view data supplied to the view. + + + + + Returns an anchor tag containing the virtual path to the specified action. + + The inner text of the anchor tag + The name of the action + An anchor tag + + + + Returns an anchor tag containing the virtual path to the specified action. + + The inner text of the anchor tag + The name of the action + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + An anchor tag + + + + Returns an anchor tag containing the virtual path to the specified action. + + The inner text of the anchor tag + The name of the action + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + An anchor tag + + + + Returns an anchor tag containing the virtual path to the specified action. + + The inner text of the anchor tag + The name of the action + An object containing the parameters for a route + An anchor tag + + + + Returns an anchor tag containing the virtual path to the specified action. + + The inner text of the anchor tag + The name of the action + An object containing the parameters for a route + An object containing the html attributes for the element + An anchor tag + + + + Returns an anchor tag containing the virtual path to the specified action. + + The inner text of the anchor tag + The name of the action + The name of the controller + An anchor tag + + + + Returns an anchor tag containing the virtual path to the specified action. + + The inner text of the anchor tag + The name of the action + The name of the controller + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + An anchor tag + + + + Returns an anchor tag containing the virtual path to the specified action. + + The inner text of the anchor tag + The name of the action + The name of the controller + An object containing the parameters for a route + An object containing the html attributes for the element + An anchor tag + + + + Returns an anchor tag containing the url to the specified action. + + The inner text of the anchor tag + The name of the action + The name of the controller + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + The protocol for the URL such as "http" or "https" + The url fragment name (also known as anchor name) + The host name for the URL + An anchor tag + + + + Returns an anchor tag containing the url to the specified action. + + The inner text of the anchor tag + The name of the action + The name of the controller + An object containing the parameters for a route + An object containing the html attributes for the element + The protocol for the URL such as "http" or "https" + The url fragment name (also known as anchor name) + The host name for the URL + An anchor tag + + + + Returns an anchor tag containing the virtual path for the specified route values. + + The inner text of the anchor tag + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + An anchor tag + + + + Returns an anchor tag containing the virtual path for the specified route values. + + The inner text of the anchor tag + An object containing the parameters for a route + An anchor tag + + + + Returns an anchor tag containing the virtual path for the specified route values. + + The inner text of the anchor tag + The name of the route used to return a virtual path. + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + An anchor tag + + + + Returns an anchor tag containing the virtual path for the specified route values. + + The inner text of the anchor tag + The name of the route used to return a virtual path. + An object containing the parameters for a route + An anchor tag + + + + Returns an anchor tag containing the virtual path for the specified route values. + + The inner text of the anchor tag + The name of the route used to return a virtual path. + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + An anchor tag + + + + Returns an anchor tag containing the virtual path for the specified route values. + + The inner text of the anchor tag + The name of the route used to return a virtual path. + An object containing the parameters for a route + An object containing the html attributes for the element + An anchor tag + + + + Returns an anchor tag containing the virtual path for the specified route values. + + The inner text of the anchor tag + The name of the route used to return a virtual path. + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + An anchor tag + + + + Returns an anchor tag containing the virtual path for the specified route values. + + The inner text of the anchor tag + The name of the route used to return a virtual path. + An object containing the parameters for a route + An object containing the html attributes for the element + An anchor tag + + + + Returns an anchor tag containing the url for the specified route values. + + The inner text of the anchor tag + The name of the route used to return a virtual path. + The host name for the URL + The protocol for the URL such as "http" or "https" + The url fragment name (also known as anchor name) + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + An anchor tag + + + + Returns an anchor tag containing the url for the specified route values. + + The inner text of the anchor tag + The name of the route used to return a virtual path. + The host name for the URL + The protocol for the URL such as "http" or "https" + The url fragment name (also known as anchor name) + An object containing the parameters for a route + An object containing the html attributes for the element + An anchor tag + + + + Represents the state of an attempt to bind a posted form to an action method including validation information. + + + + + Initializes a new instance of the class + + + + + Initializes a new instance of the class with the values copied + from the the specified ModelStateDictionary. + + + + + Adds the specified to the errors collection for the + associated with the specified key. + + + + + + + Adds the specified error message to the errors collection for the + associated with the specified key. + + + + + + + Returns true if there are any associated or prefixed with the specified key. + + + + + + + Copies the values from the specified into this + dictionary, overwriting existing values in cases where the keys are the same. + + + + + + Sets the value for the specified key using the specified + + + + + + + Gets the number of key/value pairs that are in the collection. + + + + + Returns true if there are no errors, otherwise false. + + + + + Gets a collection that contains the keys in the dictionary. + + + + + Gets or sets the value that is associated with the specified key. + + + + + + + Gets a collection that contains the values in the dictionary. + + + + + Initializes a new instance of the class. + + An object that contains information about the current request and the defined route it matched. + + + + Initializes a new instance of the class. + + An object that contains information about the current request and the defined route it matched. + A collection of Route instances. + + + + Returns a virtual path for the specified route values. + + The name of the action + The virtual path to the action + + + + Returns a virtual path URL for the specified route values. + + The name of the action + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + The virtual path to the action + + + + Returns a virtual path for the specified route values. + + The name of the action + An object containing the parameters for a route. + The virtual path to the action + + + + Returns a virtual path for the specified route values. + + The name of the action + The name of the controller + The virtual path to the action + + + + Returns a virtual path for the specified route values. + + The name of the action + The name of the controller + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + The virtual path to the action + + + + Returns a virtual path for the specified route values. + + The name of the action + The name of the controller + An object containing the parameters for a route. + The protocol for the URL such as "http" or "https" + The virtual path to the action + + + + Returns a fully qualified URL for the specified route values. + + The name of the action + The name of the controller + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + The protocol for the URL such as "http" or "https" + The URL to the action + + + + Returns a fully qualified URL for the specified route values. + + The name of the action + The name of the controller + An object containing the parameters for a route + The protocol for the URL such as "http" or "https" + The host name for the URL + The URL to the action + + + + Converts a virtual path to an application absolute path. + + + If the specified does not start with the tilde [~] character, + then this method returns the specified unchanged. + + The virtual path to the content. + + + + + Encodes a URL string + + The text to encode + An encoded string + + + + Returns a virtual path for the specified route values. + + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + A virtual path + + + + Returns a virtual path for the specified route values. + + An object containing the parameters for a route. + A virtual path + + + + Returns a virtual path for the specified route values. + + The name of the route used to return a virtual path. + A virtual path + + + + Returns a virtual path for the specified route values. + + The name of the route used to return a virtual path. + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + A virtual path + + + + Returns a virtual path for the specified route values. + + The name of the route used to return a virtual path. + An object containing the parameters for a route. + A virtual path + + + + Returns a fully qualified URL for the specified route values. + + The name of the route used to return a virtual path. + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + The protocol for the URL such as "http" or "https" + A virtual path + + + + Returns a fully qualified URL for the specified route values. + + The name of the route used to generate the virtual path + The name of the controller + An object containing the parameters for a route + The protocol for the URL such as "http" or "https" + The host name for the URL + The virtual path to the action + + + + Encapsulates information about an HTTP request that matches a defined route. + + + + + A collection containing the routes registered for the application. + + + + + Class containing convenience methods for use in rendering HTML in a view. + + + + + Returns the string for a hidden input containing a token used to prevent CSRF attacks. + + + + + + Returns the string for a hidden input containing a token used to prevent CSRF attacks. + + A salt to use when generating the token + + + + + Method used to encode HTML attribute values. + + The string to encode + + + + + Method used to encode HTML attribute values. + + The object to encode + + + + + Method used to encode HTML. + + The string to encode + + + + + Method used to encode HTML. + + The object to encode + + + + + Convenience method used to generate a link using Routing to determine the virtual path. + + The current + The collection of routes. + The text displayed in the link + The name of the route, if any. + The name of the action. + The name of the controller. + The route values + The html attributes + + + + + Convenience method used to generate a link using Routing to determine the URL. + + The current + The collection of routes. + The text displayed in the link + The name of the route, if any. + The name of the action. + The name of the controller. + The route values + The html attributes + The protocol to use, such as http or https. + The hostname for the URL + The fragment to append to the end of the URL + + + + + Convenience method which converts the value into a string. + + + + + + + Convenience method for converting the value to a string + + + + + + + Gets or sets the string which replaces the dot character in the ID of html elements generated by HTML helpers. + + + + + Gets the collection of routes. + + + + + Gets the current . + + + + + Gets the current . + + + + + Gets the current . + + + + + A collection of instances. + + + + + Adds an to the + + + + + + Adds an error message to the + + + + + + When applied to an action method, specifies which HTTP verbs the method will respond to. + + + + + Gets the list of HTTP verbs the action method will respond to. + + + + + Represents an error that occured while attempting to bind a request to the arguments of an action method. + + + + + Initializes a new instance of the class with the specified exception. + + + For security reasons, the exception's ErrorMessage property is not set to the + Exception's Message property by default. + + + + + + Initializes a new instance of the class with the specified exception and error message. + + + + + + + Initializes a new instance of the class with the specified error message. + + + + + + The , if any, that occurred while binding to the model. + + + + + + + + + + Represents the result of an attempt to bind a supplied value (from a form post, query string, etc...) to + a property of an argument to an action method or to the argument itself. + + + + + Initializes a new instance of the class with the specified + raw value, attempted value, and . + + + + + + + + Converts the value encapsulated by this result to the specified type. + + The target type + + + + + Converts the value encapsulated by this result to the specified type. + + The target type + The culture to use in the conversion. + + + + + The RawValue converted to a string for display purposes. + + + + + The raw value supplied by the value provider. + + + + + Sends binary content to the response. + + + + + Initializes a new instance of with the specified file contents and content type. + + The byte array to send to the response + The content type to use for the response + + + + The binary content to send to the response. + + + + + Class used by the Html helpers to build HTML tags. + + + + + Encapsulates the state of model binding to a property of an argument, or the argument itself, of an action method. + + + + + Returns a which encapsulates the value which was attempted to be bound by model binding. + + + + + Returns a containing any errors that occurred during model binding. + + + + + Returns a textarea tag suitable for entering multiline input. + + + The form field name and ViewData key used to lookup the value. + An textarea tag + + + + Returns a textarea tag suitable for entering multiline input. + + + The form field name and ViewData key used to lookup the value. + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + An textarea tag + + + + Returns a textarea tag suitable for entering multiline input. + + + The form field name and ViewData key used to lookup the value. + An object containing the html attributes for the element + An textarea tag + + + + Returns a textarea tag suitable for entering multiline input. + + + The form field name and ViewData key used to lookup the value. + The value of the input. If null, looks at the ViewData and then ModelStatefor the value. + An textarea tag + + + + Returns a textarea tag suitable for entering multiline input. + + + The form field name and ViewData key used to lookup the value. + The value of the input. If null, looks at the ViewData and then ModelStatefor the value. + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + An textarea tag + + + + Returns a textarea tag suitable for entering multiline input. + + + The form field name and ViewData key used to lookup the value. + The value of the input. If null, looks at the ViewData and then ModelStatefor the value. + An object containing the html attributes for the element + An textarea tag + + + + Returns a textarea tag suitable for entering multiline input. + + + The form field name and ViewData key used to lookup the value. + The value of the input. If null, looks at the ViewData and then ModelStatefor the value. + The number of columns + The number of rows + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + An textarea tag + + + + Returns a textarea tag suitable for entering multiline input. + + + The form field name and ViewData key used to lookup the value. + The value of the input. If null, looks at the ViewData and then ModelStatefor the value. + The number of columns + The number of rows + An object containing the html attributes for the element + An textarea tag + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. + + + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. + + + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. + + + An object containing the parameters for a route + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. + + + The name of the action + The name of the controller + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. + + + The name of the action + The name of the controller + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. + + + The name of the action + The name of the controller + An object containing the parameters for a route + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. + + + The name of the action + The name of the controller + The HTTP method for the form post, either Get or Post + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. + + + The name of the action + The name of the controller + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + The HTTP method for the form post, either Get or Post + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. + + + The name of the action + The name of the controller + An object containing the parameters for a route + The HTTP method for the form post, either Get or Post + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. + + + The name of the action + The name of the controller + The HTTP method for the form post, either Get or Post + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. + + + The name of the action + The name of the controller + The HTTP method for the form post, either Get or Post + An object containing the html attributes for the element + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. + + + The name of the action + The name of the controller + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + The HTTP method for the form post, either Get or Post + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. + + + The name of the action + The name of the controller + An object containing the parameters for a route + The HTTP method for the form post, either Get or Post + An object containing the html attributes for the element + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. + + + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. + + + An object containing the parameters for a route + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. + + + The name of the route to used to obtain the form post url. + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. + + + The name of the route to used to obtain the form post url. + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. + + + The name of the route to used to obtain the form post url. + An object containing the parameters for a route + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. + + + The name of the route to used to obtain the form post url. + The HTTP method for the form post, either Get or Post + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. + + + The name of the route to used to obtain the form post url. + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + The HTTP method for the form post, either Get or Post + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. + + + The name of the route to used to obtain the form post url. + An object containing the parameters for a route + The HTTP method for the form post, either Get or Post + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. + + + The name of the route to used to obtain the form post url. + The HTTP method for the form post, either Get or Post + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. + + + The name of the route to used to obtain the form post url. + The HTTP method for the form post, either Get or Post + An object containing the html attributes for the element + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. + + + The name of the route to used to obtain the form post url. + An object containing the parameters for a route. The parameters are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax. + The HTTP method for the form post, either Get or Post + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + An instance. + + + + Writes a begin form tag to the response while returning an + instance. Can be used in a using block in which case it renders the end form tag at the end of the + using block. + + + The name of the route to used to obtain the form post url. + An object containing the parameters for a route + The HTTP method for the form post, either Get or Post + An object containing the html attributes for the element + An instance. + + + + Renders the end form tag to the response. This provides an alternative way to end the form + to using a using block with and . + + + + + + Sends the contents of a file to the response. + + + + + Initializes an instance of with the specified file name and content type. + + The name of the file to send to the response. + The content type of the response. + + + + The path to the file which is sent to the response. + + + + + Represents a result that doesn't do anything, like a controller action returning null. + + + This follows a pattern known as the Null Object pattern + + + + + Defines the contract for temp data providers which store data viewed on the next request. + + + + + Displays a validation message if the specified field contains an error in the ModelState. + + + The name of the property or model object being validated + An empty string if valid, otherwise a span with an error message + + + + Displays a validation message if the specified field contains an error in the ModelState. + + + The name of the property or model object being validated + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + An empty string if valid, otherwise a span with an error message + + + + Displays a validation message if the specified field contains an error in the ModelState. + + + The name of the property or model object being validated + The message to display if the specified field is in error + An empty string if valid, otherwise a span with an error message + + + + Displays a validation message if the specified field contains an error in the ModelState. + + + The name of the property or model object being validated + The message to display if the specified field is in error + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + An empty string if valid, otherwise a span with an error message + + + + Displays a validation message if the specified field contains an error in the ModelState. + + + The name of the property or model object being validated + An object containing the html attributes for the element + An empty string if valid, otherwise a span with an error message + + + + Displays a validation message if the specified field contains an error in the ModelState. + + + The name of the property or model object being validated + The message to display if the specified field is in error + An object containing the html attributes for the element + An empty string if valid, otherwise a span with an error message + + + + Returns an unordered list [ul] of validation messages within the ModelState. + + + + + + + Returns an unordered list [ul] of validation messages within the ModelState. + + + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + + + + + Returns an unordered list [ul] of validation messages within the ModelState. + + + An object containing the html attributes for the element + + + + + Returns a select tag used to select a single option from a set of possible choices. + + + The name of the form field and used as a key to lookup possible options. If ViewData[name] implements IEnumerable of . + Provides the text for a default empty valued option, if it is not null. + + + + + Returns a select tag used to select a single option from a set of possible choices. + + + The name of the form field and used as a key to lookup possible options. If ViewData[name] implements IEnumerable of . + The enumeration of SelectListItem instances used to populate the drop down. + Provides the text for a default empty valued option, if it is not null. + + + + + Returns a select tag used to select a single option from a set of possible choices. + + + The name of the form field and used as a key to lookup possible options. If ViewData[name] implements IEnumerable of . + The enumeration of SelectListItem instances used to populate the drop down. + Provides the text for a default empty valued option, if it is not null. + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + + + + + Returns a select tag used to select a single option from a set of possible choices. + + + The name of the form field and used as a key to lookup possible options. If ViewData[name] implements IEnumerable of . + + + + + Returns a select tag used to select a single option from a set of possible choices. + + + The name of the form field and used as a key to lookup possible options. If ViewData[name] implements IEnumerable of . + The enumeration of SelectListItem instances used to populate the drop down. + + + + + Returns a select tag used to select a single option from a set of possible choices. + + + The name of the form field and used as a key to lookup possible options. If ViewData[name] implements IEnumerable of . + The enumeration of SelectListItem instances used to populate the drop down. + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + + + + + Returns a select tag used to select a single option from a set of possible choices. + + + The name of the form field and used as a key to lookup possible options. If ViewData[name] implements IEnumerable of . + The enumeration of SelectListItem instances used to populate the drop down. + An object containing the html attributes for the element. + + + + + Returns a select tag used to select a single option from a set of possible choices. + + + The name of the form field and used as a key to lookup possible options. If ViewData[name] implements IEnumerable of . + The enumeration of SelectListItem instances used to populate the drop down. + Provides the text for a default empty valued option, if it is not null. + An object containing the html attributes for the element. + + + + + Returns a select tag used to select a multiple options from a set of possible choices. + + + The name of the form field and used as a key to lookup possible options. If ViewData[name] implements IEnumerable of . + + + + + Returns a select tag used to select a multiple options from a set of possible choices. + + + The name of the form field and used as a key to lookup possible options. If ViewData[name] implements IEnumerable of . + The enumeration of SelectListItem instances used to populate the drop down. + + + + + Returns a select tag used to select a multiple options from a set of possible choices. + + + The name of the form field and used as a key to lookup possible options. If ViewData[name] implements IEnumerable of . + The enumeration of SelectListItem instances used to populate the drop down. + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + + + + + Returns a select tag used to select a multiple options from a set of possible choices. + + + The name of the form field and used as a key to lookup possible options. If ViewData[name] implements IEnumerable of . + The enumeration of SelectListItem instances used to populate the drop down. + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + + + + + Returns the input tag for a checkbox. + + + The form field name + An input tag with the type set to "checkbox" + + + + Returns the input tag for a checkbox. + + + The form field name + A boolean indicating whether or not the checkbox is checked + An input tag with the type set to "checkbox" + + + + Returns the input tag for a checkbox. + + + The form field name + A boolean indicating whether or not the checkbox is checked + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + An input tag with the type set to "checkbox" + + + + Returns the input tag for a checkbox. + + + The form field name + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + An input tag with the type set to "checkbox" + + + + Returns the input tag for a checkbox. + + + The form field name + An object containing the html attributes for the element + An input tag with the type set to "checkbox" + + + + Returns the input tag for a checkbox. + + + The form field name + A boolean indicating whether or not the checkbox is checked + An object containing the html attributes for the element + An input tag with the type set to "checkbox" + + + + Returns a hidden input tag. + + + The form field name and ViewData key used to lookup the value. + An input tag with the type set to "hidden" + + + + Returns a hidden input tag. + + + The form field name and ViewData key used to lookup the value. + The value of the hidden input. If null, looks at the ViewData and then ModelStatefor the value. + An input tag with the type set to "hidden" + + + + Returns a hidden input tag. + + + The form field name and ViewData key used to lookup the value. + The value of the hidden input. If null, looks at the ViewData and then ModelStatefor the value. + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + An input tag with the type set to "hidden" + + + + Returns a hidden input tag. + + + The form field name and ViewData key used to lookup the value. + The value of the hidden input. If null, looks at the ViewData and then ModelStatefor the value. + An object containing the html attributes for the element + An input tag with the type set to "hidden" + + + + Returns a password tag. + + + The form field name and ViewData key used to lookup the value. + An input tag with the type set to "password" + + + + Returns a password tag. + + + The form field name and ViewData key used to lookup the value. + The value of the input. If null, looks at the ViewData and then ModelStatefor the value. + An input tag with the type set to "password" + + + + Returns a password tag. + + + The form field name and ViewData key used to lookup the value. + The value of the input. If null, looks at the ViewData and then ModelStatefor the value. + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + An input tag with the type set to "password" + + + + Returns a password tag. + + + The form field name and ViewData key used to lookup the value. + The value of the input. If null, looks at the ViewData and then ModelStatefor the value. + An object containing the html attributes for the element + An input tag with the type set to "password" + + + + Returns a radio button tag used to present one possible value, out of a range, for a form field specified by the name. + + + The form field name and ViewData key used to lookup the current value. + If checked, the value of the radio button submitted when the form is posted. If the value in ViewData or ModelState matches this value, the radio button is checked. + An input tag with the type set to "radio" + + + + Returns a radio button tag used to present one possible value, out of a range, for a form field specified by the name. + + + The form field name and ViewData key used to lookup the current value. + If checked, the value of the radio button submitted when the form is posted. If the value in ViewData or ModelState matches this value, the radio button is checked. + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + An input tag with the type set to "radio" + + + + Returns a radio button tag used to present one possible value, out of a range, for a form field specified by the name. + + + The form field name and ViewData key used to lookup the current value. + If checked, the value of the radio button submitted when the form is posted. If the value in ViewData or ModelState matches this value, the radio button is checked. + An object containing the html attributes for the element + An input tag with the type set to "radio" + + + + Returns a radio button tag used to present one possible value, out of a range, for a form field specified by the name. + + + The form field name and ViewData key used to lookup the current value. + If checked, the value of the radio button submitted when the form is posted. If the value in ViewData or ModelState matches this value, the radio button is checked. + Whether or not the radio button is checked + An input tag with the type set to "radio" + + + + Returns a radio button tag used to present one possible value, out of a range, for a form field specified by the name. + + + The form field name and ViewData key used to lookup the current value. + If checked, the value of the radio button submitted when the form is posted. If the value in ViewData or ModelState matches this value, the radio button is checked. + Whether or not the radio button is checked + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + An input tag with the type set to "radio" + + + + Returns a radio button tag used to present one possible value, out of a range, for a form field specified by the name. + + + The form field name and ViewData key used to lookup the current value. + If checked, the value of the radio button submitted when the form is posted. If the value in ViewData or ModelState matches this value, the radio button is checked. + Whether or not the radio button is checked + An object containing the html attributes for the element + An input tag with the type set to "radio" + + + + Returns a text input tag. + + + The form field name and ViewData key used to lookup the value. + An input tag with the type set to "text" + + + + Returns a text input tag. + + + The form field name and ViewData key used to lookup the value. + The value of the input. If null, looks at the ViewData and then ModelStatefor the value. + An input tag with the type set to "text" + + + + Returns a text input tag. + + + The form field name and ViewData key used to lookup the value. + The value of the input. If null, looks at the ViewData and then ModelStatefor the value. + An object containing the html attributes for the element. The attributes are retrieved via reflection by examining the properties of the object. Typically created using object initializer syntax + An input tag with the type set to "text" + + + + Returns a text input tag. + + + The form field name and ViewData key used to lookup the value. + The value of the input. If null, looks at the ViewData and then ModelStatefor the value. + An object containing the html attributes for the element + An input tag with the type set to "text" + + + + Initializes a new instance of the + with the specified . + + + + + + Attribute used to provide details on how model binding to a parameter should occur. + + + + + A comma delimited black list of property names for which binding is not allowed. + + + + + A comma delimited white list of property names for which binding is allowed. + + + + + Gets or sets the prefix to use when binding to an action argument or model property. + + + + diff --git a/Samples/ProductsMvcSample/ProductsMvcSample.sln b/Samples/ProductsMvcSample/ProductsMvcSample.sln index 1ad3258d6..dbed5c301 100644 --- a/Samples/ProductsMvcSample/ProductsMvcSample.sln +++ b/Samples/ProductsMvcSample/ProductsMvcSample.sln @@ -1,34 +1,34 @@ - -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source", "Source", "{6F1F9F8E-B88A-426E-9408-CB39D2052BFA}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "UnitTests", "UnitTests", "{6CA54C7A-DAB8-42E4-8A20-C1329194FF36}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProductsMvcSample", "Source\ProductsMvcSample\ProductsMvcSample.csproj", "{766F76DC-B97D-41FE-A6D8-F039EAB8533D}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProductsMvcSample.Tests", "UnitTests\ProductsMvcSample.Tests\ProductsMvcSample.Tests.csproj", "{0BB61A7C-2791-45EC-A7A5-E2F525CAFA72}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {766F76DC-B97D-41FE-A6D8-F039EAB8533D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {766F76DC-B97D-41FE-A6D8-F039EAB8533D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {766F76DC-B97D-41FE-A6D8-F039EAB8533D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {766F76DC-B97D-41FE-A6D8-F039EAB8533D}.Release|Any CPU.Build.0 = Release|Any CPU - {0BB61A7C-2791-45EC-A7A5-E2F525CAFA72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0BB61A7C-2791-45EC-A7A5-E2F525CAFA72}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0BB61A7C-2791-45EC-A7A5-E2F525CAFA72}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0BB61A7C-2791-45EC-A7A5-E2F525CAFA72}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {766F76DC-B97D-41FE-A6D8-F039EAB8533D} = {6F1F9F8E-B88A-426E-9408-CB39D2052BFA} - {0BB61A7C-2791-45EC-A7A5-E2F525CAFA72} = {6CA54C7A-DAB8-42E4-8A20-C1329194FF36} - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source", "Source", "{6F1F9F8E-B88A-426E-9408-CB39D2052BFA}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "UnitTests", "UnitTests", "{6CA54C7A-DAB8-42E4-8A20-C1329194FF36}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProductsMvcSample", "Source\ProductsMvcSample\ProductsMvcSample.csproj", "{766F76DC-B97D-41FE-A6D8-F039EAB8533D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProductsMvcSample.Tests", "UnitTests\ProductsMvcSample.Tests\ProductsMvcSample.Tests.csproj", "{0BB61A7C-2791-45EC-A7A5-E2F525CAFA72}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {766F76DC-B97D-41FE-A6D8-F039EAB8533D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {766F76DC-B97D-41FE-A6D8-F039EAB8533D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {766F76DC-B97D-41FE-A6D8-F039EAB8533D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {766F76DC-B97D-41FE-A6D8-F039EAB8533D}.Release|Any CPU.Build.0 = Release|Any CPU + {0BB61A7C-2791-45EC-A7A5-E2F525CAFA72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0BB61A7C-2791-45EC-A7A5-E2F525CAFA72}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0BB61A7C-2791-45EC-A7A5-E2F525CAFA72}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0BB61A7C-2791-45EC-A7A5-E2F525CAFA72}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {766F76DC-B97D-41FE-A6D8-F039EAB8533D} = {6F1F9F8E-B88A-426E-9408-CB39D2052BFA} + {0BB61A7C-2791-45EC-A7A5-E2F525CAFA72} = {6CA54C7A-DAB8-42E4-8A20-C1329194FF36} + EndGlobalSection +EndGlobal diff --git a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Controllers/HomeController.cs b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Controllers/HomeController.cs index 4ac5674a2..88025b6ee 100644 --- a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Controllers/HomeController.cs +++ b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Controllers/HomeController.cs @@ -1,12 +1,12 @@ -using System.Web.Mvc; - -namespace ProductsMvcSample.Controllers -{ - public class HomeController : Controller - { - public ViewResult Index() - { - return View("Welcome"); - } - } -} +using System.Web.Mvc; + +namespace ProductsMvcSample.Controllers +{ + public class HomeController : Controller + { + public ViewResult Index() + { + return View("Welcome"); + } + } +} diff --git a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Controllers/ProductsController.cs b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Controllers/ProductsController.cs index 8f92c38c9..1e2c0d56c 100644 --- a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Controllers/ProductsController.cs +++ b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Controllers/ProductsController.cs @@ -1,36 +1,36 @@ -using System.Web.Mvc; -using ProductsMvcSample.Models; -using ProductsMvcSample.Services; - -namespace ProductsMvcSample.Controllers -{ - public class ProductsController : Controller - { - IProductsCatalogService catalogService; - - public ProductsController() - : this(new ProductsCatalogService()) - { - - } - - public ProductsController(IProductsCatalogService catalogService) - { - this.catalogService = catalogService; - } - - public ActionResult Index() - { - return View(); - } - - public ActionResult Category(int id) - { - var model = new ProductsListViewData(); - model.CategoryId = id; - model.CategoryName = catalogService.GetCategoryName(id); - model.Products.AddRange(catalogService.GetProducts(id) ?? new Product[0]); - return View("ProductsList", model); - } - } -} +using System.Web.Mvc; +using ProductsMvcSample.Models; +using ProductsMvcSample.Services; + +namespace ProductsMvcSample.Controllers +{ + public class ProductsController : Controller + { + IProductsCatalogService catalogService; + + public ProductsController() + : this(new ProductsCatalogService()) + { + + } + + public ProductsController(IProductsCatalogService catalogService) + { + this.catalogService = catalogService; + } + + public ActionResult Index() + { + return View(); + } + + public ActionResult Category(int id) + { + var model = new ProductsListViewData(); + model.CategoryId = id; + model.CategoryName = catalogService.GetCategoryName(id); + model.Products.AddRange(catalogService.GetProducts(id) ?? new Product[0]); + return View("ProductsList", model); + } + } +} diff --git a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Default.aspx b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Default.aspx index 6a36d3a0a..65b715e11 100644 --- a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Default.aspx +++ b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Default.aspx @@ -1,3 +1,3 @@ -<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ProductsMvcSample.Default" %> - -<%-- Please do not delete this file. It is used to ensure that ASP.NET MVC is activated by IIS when a user makes a "/" request to the server. --%> +<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ProductsMvcSample.Default" %> + +<%-- Please do not delete this file. It is used to ensure that ASP.NET MVC is activated by IIS when a user makes a "/" request to the server. --%> diff --git a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Default.aspx.cs b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Default.aspx.cs index 07892ee99..8c90403af 100644 --- a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Default.aspx.cs +++ b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Default.aspx.cs @@ -1,17 +1,17 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; -using System.Web.UI; -using System.Web.UI.WebControls; - -namespace ProductsMvcSample -{ - public partial class Default : System.Web.UI.Page - { - protected void Page_Load(object sender, EventArgs e) - { - Response.Redirect("~/Home"); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; + +namespace ProductsMvcSample +{ + public partial class Default : System.Web.UI.Page + { + protected void Page_Load(object sender, EventArgs e) + { + Response.Redirect("~/Home"); + } + } +} diff --git a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Global.asax b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Global.asax index 1279a6f1b..9ed5fbca5 100644 --- a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Global.asax +++ b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Global.asax @@ -1 +1 @@ -<%@ Application Codebehind="Global.asax.cs" Inherits="ProductsMvcSample.Global" Language="C#" %> +<%@ Application Codebehind="Global.asax.cs" Inherits="ProductsMvcSample.Global" Language="C#" %> diff --git a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Global.asax.cs b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Global.asax.cs index 739aae40c..3c9744975 100644 --- a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Global.asax.cs +++ b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Global.asax.cs @@ -1,33 +1,33 @@ -using System; -using System.Web.Mvc; -using System.Web.Routing; - -namespace ProductsMvcSample -{ - public class Global : System.Web.HttpApplication - { - - protected void Application_Start(object sender, EventArgs e) - { - // Note: Change Url= to Url="[controller].mvc/[action]/[id]" to enable - // automatic support on IIS6 - RegisterRoutes(RouteTable.Routes); - } - - public static void RegisterRoutes(RouteCollection routes) - { - routes.MapRoute( - "Default", // Route name - "{controller}/{action}/{id}", // URL with parameters - new { controller = "Home", action = "Index", id = "" }, // Parameter defaults - new { controller = @"[^\.]*" } // Parameter constraints - ); - - routes.MapRoute( - "Root", // Route name - "Default.aspx", // URL with parameters - new { controller = "Home", action = "Index", id = "" } // Parameter defaults - ); - } - } +using System; +using System.Web.Mvc; +using System.Web.Routing; + +namespace ProductsMvcSample +{ + public class Global : System.Web.HttpApplication + { + + protected void Application_Start(object sender, EventArgs e) + { + // Note: Change Url= to Url="[controller].mvc/[action]/[id]" to enable + // automatic support on IIS6 + RegisterRoutes(RouteTable.Routes); + } + + public static void RegisterRoutes(RouteCollection routes) + { + routes.MapRoute( + "Default", // Route name + "{controller}/{action}/{id}", // URL with parameters + new { controller = "Home", action = "Index", id = "" }, // Parameter defaults + new { controller = @"[^\.]*" } // Parameter constraints + ); + + routes.MapRoute( + "Root", // Route name + "Default.aspx", // URL with parameters + new { controller = "Home", action = "Index", id = "" } // Parameter defaults + ); + } + } } \ No newline at end of file diff --git a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Models/Product.cs b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Models/Product.cs index db6d39033..cb0ccc8a7 100644 --- a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Models/Product.cs +++ b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Models/Product.cs @@ -1,10 +1,10 @@ -using System; - -namespace ProductsMvcSample.Models -{ - public class Product - { - public int Id { get; set; } - public string Name { get; set; } - } -} +using System; + +namespace ProductsMvcSample.Models +{ + public class Product + { + public int Id { get; set; } + public string Name { get; set; } + } +} diff --git a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Models/ProductsListViewData.cs b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Models/ProductsListViewData.cs index c0c56c569..d99369e1e 100644 --- a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Models/ProductsListViewData.cs +++ b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Models/ProductsListViewData.cs @@ -1,16 +1,16 @@ -using System.Collections.Generic; - -namespace ProductsMvcSample.Models -{ - public class ProductsListViewData - { - public ProductsListViewData () - { - Products = new List(); - } - - public int CategoryId { get; set; } - public string CategoryName { get; set; } - public List Products { get; private set; } - } -} +using System.Collections.Generic; + +namespace ProductsMvcSample.Models +{ + public class ProductsListViewData + { + public ProductsListViewData () + { + Products = new List(); + } + + public int CategoryId { get; set; } + public string CategoryName { get; set; } + public List Products { get; private set; } + } +} diff --git a/Samples/ProductsMvcSample/Source/ProductsMvcSample/ProductsMvcSample.csproj b/Samples/ProductsMvcSample/Source/ProductsMvcSample/ProductsMvcSample.csproj index 5024a9f05..7beae3166 100644 --- a/Samples/ProductsMvcSample/Source/ProductsMvcSample/ProductsMvcSample.csproj +++ b/Samples/ProductsMvcSample/Source/ProductsMvcSample/ProductsMvcSample.csproj @@ -1,144 +1,144 @@ - - - Debug - AnyCPU - 9.0.30729 - 2.0 - {766F76DC-B97D-41FE-A6D8-F039EAB8533D} - {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} - Library - Properties - ProductsMvcSample - ProductsMvcSample - v3.5 - - - true - full - false - bin\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\ - TRACE - prompt - 4 - - - - False - ..\..\..\Lib\Microsoft.Web.Mvc.dll - - - False - ..\..\..\Lib\Moq.dll - - - - - 3.5 - - - False - ..\..\..\Lib\System.Web.Abstractions.dll - 3.5 - - - False - - - False - ..\..\..\Lib\System.Web.Mvc.dll - - - False - ..\..\..\Lib\System.Web.Routing.dll - 3.5 - - - 3.5 - - - - - - - - - - - - - - - - - - Default.aspx - ASPXCodeBehind - - - Global.asax - - - - - - - - Welcome.aspx - ASPXCodeBehind - - - ProductsList.aspx - ASPXCodeBehind - - - Site.Master - ASPXCodeBehind - - - - - - - - - - - - - - - - - - - - False - True - 64701 - / - - - False - False - - - False - - - - + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {766F76DC-B97D-41FE-A6D8-F039EAB8533D} + {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + ProductsMvcSample + ProductsMvcSample + v3.5 + + + true + full + false + bin\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\ + TRACE + prompt + 4 + + + + False + ..\..\..\Lib\Microsoft.Web.Mvc.dll + + + False + ..\..\..\Lib\Moq.dll + + + + + 3.5 + + + False + ..\..\..\Lib\System.Web.Abstractions.dll + 3.5 + + + False + + + False + ..\..\..\Lib\System.Web.Mvc.dll + + + False + ..\..\..\Lib\System.Web.Routing.dll + 3.5 + + + 3.5 + + + + + + + + + + + + + + + + + + Default.aspx + ASPXCodeBehind + + + Global.asax + + + + + + + + Welcome.aspx + ASPXCodeBehind + + + ProductsList.aspx + ASPXCodeBehind + + + Site.Master + ASPXCodeBehind + + + + + + + + + + + + + + + + + + + + False + True + 64701 + / + + + False + False + + + False + + + + \ No newline at end of file diff --git a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Properties/AssemblyInfo.cs b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Properties/AssemblyInfo.cs index 63f2aa795..ab77be42f 100644 --- a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Properties/AssemblyInfo.cs +++ b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Properties/AssemblyInfo.cs @@ -1,34 +1,34 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("ProductsMvcSample")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("MSIT")] -[assembly: AssemblyProduct("ProductsMvcSample")] -[assembly: AssemblyCopyright("Copyright © MSIT 2007")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("3d5900ae-111a-45be-96b3-d9e4606ca793")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Revision and Build Numbers -// by using the '*' as shown below: -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ProductsMvcSample")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("MSIT")] +[assembly: AssemblyProduct("ProductsMvcSample")] +[assembly: AssemblyCopyright("Copyright © MSIT 2007")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("3d5900ae-111a-45be-96b3-d9e4606ca793")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Services/IProductsCatalogService.cs b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Services/IProductsCatalogService.cs index 41f35c976..798a130e0 100644 --- a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Services/IProductsCatalogService.cs +++ b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Services/IProductsCatalogService.cs @@ -1,11 +1,11 @@ -using System.Collections.Generic; -using ProductsMvcSample.Models; - -namespace ProductsMvcSample.Services -{ - public interface IProductsCatalogService - { - string GetCategoryName(int categoryId); - IEnumerable GetProducts(int categoryId); - } -} +using System.Collections.Generic; +using ProductsMvcSample.Models; + +namespace ProductsMvcSample.Services +{ + public interface IProductsCatalogService + { + string GetCategoryName(int categoryId); + IEnumerable GetProducts(int categoryId); + } +} diff --git a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Services/ProductsCatalogService.cs b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Services/ProductsCatalogService.cs index 72d1f957e..e622f3734 100644 --- a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Services/ProductsCatalogService.cs +++ b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Services/ProductsCatalogService.cs @@ -1,38 +1,38 @@ -using System.Collections.Generic; -using ProductsMvcSample.Models; - -namespace ProductsMvcSample.Services -{ - public class ProductsCatalogService : IProductsCatalogService - { - public string GetCategoryName(int categoryId) - { - if (categoryId == 1) - return "Beverage"; - if (categoryId == 2) - return "Condiments"; - return null; - } - - public IEnumerable GetProducts(int categoryId) - { - if (categoryId == 1) - { - yield return new Product { Id = 1, Name = "Merlot" }; - yield return new Product { Id = 2, Name = "Spirits" }; - yield return new Product { Id = 3, Name = "Beer" }; - yield return new Product { Id = 4, Name = "Cabernet" }; - yield return new Product { Id = 5, Name = "Chardonnay" }; - } - if (categoryId == 2) - { - yield return new Product { Id = 10, Name = "Aniseed Syrup" }; - yield return new Product { Id = 11, Name = "Chef Anton's Cajun Seasoning" }; - yield return new Product { Id = 12, Name = "Chef Anton's Gumbo Mix" }; - yield return new Product { Id = 13, Name = "Gula Malacca" }; - yield return new Product { Id = 14, Name = "Vegie-spread" }; - } - yield break; - } - } -} +using System.Collections.Generic; +using ProductsMvcSample.Models; + +namespace ProductsMvcSample.Services +{ + public class ProductsCatalogService : IProductsCatalogService + { + public string GetCategoryName(int categoryId) + { + if (categoryId == 1) + return "Beverage"; + if (categoryId == 2) + return "Condiments"; + return null; + } + + public IEnumerable GetProducts(int categoryId) + { + if (categoryId == 1) + { + yield return new Product { Id = 1, Name = "Merlot" }; + yield return new Product { Id = 2, Name = "Spirits" }; + yield return new Product { Id = 3, Name = "Beer" }; + yield return new Product { Id = 4, Name = "Cabernet" }; + yield return new Product { Id = 5, Name = "Chardonnay" }; + } + if (categoryId == 2) + { + yield return new Product { Id = 10, Name = "Aniseed Syrup" }; + yield return new Product { Id = 11, Name = "Chef Anton's Cajun Seasoning" }; + yield return new Product { Id = 12, Name = "Chef Anton's Gumbo Mix" }; + yield return new Product { Id = 13, Name = "Gula Malacca" }; + yield return new Product { Id = 14, Name = "Vegie-spread" }; + } + yield break; + } + } +} diff --git a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Views/Home/Welcome.aspx b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Views/Home/Welcome.aspx index d7611c6bd..567a4aacf 100644 --- a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Views/Home/Welcome.aspx +++ b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Views/Home/Welcome.aspx @@ -1,11 +1,11 @@ -<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="Welcome.aspx.cs" Inherits="ProductsMvcSample.Views.Home.Welcome" Title="Untitled Page" %> -<%@ Import Namespace="ProductsMvcSample.Controllers" %> - - - - -
    -
  • <%= Html.ActionLink(c => c.Category(1), "View Category 1") %>
  • -
  • <%= Html.ActionLink(c => c.Category(2), "View Category 2") %>
  • -
-
+<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="Welcome.aspx.cs" Inherits="ProductsMvcSample.Views.Home.Welcome" Title="Untitled Page" %> +<%@ Import Namespace="ProductsMvcSample.Controllers" %> + + + + +
    +
  • <%= Html.ActionLink(c => c.Category(1), "View Category 1") %>
  • +
  • <%= Html.ActionLink(c => c.Category(2), "View Category 2") %>
  • +
+
diff --git a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Views/Home/Welcome.aspx.cs b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Views/Home/Welcome.aspx.cs index 3ee5ea981..7c2cd3419 100644 --- a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Views/Home/Welcome.aspx.cs +++ b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Views/Home/Welcome.aspx.cs @@ -1,8 +1,8 @@ -using System.Web.Mvc; - -namespace ProductsMvcSample.Views.Home -{ - public partial class Welcome : ViewPage - { - } -} +using System.Web.Mvc; + +namespace ProductsMvcSample.Views.Home +{ + public partial class Welcome : ViewPage + { + } +} diff --git a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Views/Products/ProductsList.aspx b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Views/Products/ProductsList.aspx index 431a3128c..208f825c6 100644 --- a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Views/Products/ProductsList.aspx +++ b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Views/Products/ProductsList.aspx @@ -1,15 +1,15 @@ -<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="ProductsList.aspx.cs" Inherits="ProductsMvcSample.Views.Products.ProductsList" Title="Untitled Page" %> - - - - -

<%= ViewData.Model.CategoryName %>

- -
    -<% foreach (var product in ViewData.Model.Products) - { %> -
  • <%= product.Name %>
  • -<% } %> -
- -
+<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="ProductsList.aspx.cs" Inherits="ProductsMvcSample.Views.Products.ProductsList" Title="Untitled Page" %> + + + + +

<%= ViewData.Model.CategoryName %>

+ +
    +<% foreach (var product in ViewData.Model.Products) + { %> +
  • <%= product.Name %>
  • +<% } %> +
+ +
diff --git a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Views/Products/ProductsList.aspx.cs b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Views/Products/ProductsList.aspx.cs index 3c812690c..c685655e9 100644 --- a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Views/Products/ProductsList.aspx.cs +++ b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Views/Products/ProductsList.aspx.cs @@ -1,15 +1,15 @@ -using System; -using System.Web.Mvc; -using ProductsMvcSample.Models; - -namespace ProductsMvcSample.Views.Products -{ - public partial class ProductsList : ViewPage - { - protected override void OnLoad(EventArgs e) - { - base.OnLoad(e); - Title = "Products of " + ViewData.Model.CategoryName; - } - } -} +using System; +using System.Web.Mvc; +using ProductsMvcSample.Models; + +namespace ProductsMvcSample.Views.Products +{ + public partial class ProductsList : ViewPage + { + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); + Title = "Products of " + ViewData.Model.CategoryName; + } + } +} diff --git a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Views/Shared/Site.Master b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Views/Shared/Site.Master index 8faf57175..52558f292 100644 --- a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Views/Shared/Site.Master +++ b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Views/Shared/Site.Master @@ -1,19 +1,19 @@ -<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="ProductsMvcSample.Views.Shared.Site" %> - - - - - - Untitled Page - - - - -
Products Catalog Sample (Tested by MoQ).
-
- - - -
- - +<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="ProductsMvcSample.Views.Shared.Site" %> + + + + + + Untitled Page + + + + +
Products Catalog Sample (Tested by MoQ).
+
+ + + +
+ + diff --git a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Views/Shared/Site.Master.cs b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Views/Shared/Site.Master.cs index 0e6079538..fb23e9f60 100644 --- a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Views/Shared/Site.Master.cs +++ b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Views/Shared/Site.Master.cs @@ -1,8 +1,8 @@ -using System.Web.Mvc; - -namespace ProductsMvcSample.Views.Shared -{ - public partial class Site : ViewMasterPage - { - } -} +using System.Web.Mvc; + +namespace ProductsMvcSample.Views.Shared +{ + public partial class Site : ViewMasterPage + { + } +} diff --git a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Web.config b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Web.config index e4b2e2b31..c20bc50ba 100644 --- a/Samples/ProductsMvcSample/Source/ProductsMvcSample/Web.config +++ b/Samples/ProductsMvcSample/Source/ProductsMvcSample/Web.config @@ -1,148 +1,148 @@ - - - - - - - -
- -
-
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + +
+ +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Samples/ProductsMvcSample/UnitTests/ProductsMvcSample.Tests/Controllers/ProductsControllerFixture.cs b/Samples/ProductsMvcSample/UnitTests/ProductsMvcSample.Tests/Controllers/ProductsControllerFixture.cs index b1e45d7a3..954dcf539 100644 --- a/Samples/ProductsMvcSample/UnitTests/ProductsMvcSample.Tests/Controllers/ProductsControllerFixture.cs +++ b/Samples/ProductsMvcSample/UnitTests/ProductsMvcSample.Tests/Controllers/ProductsControllerFixture.cs @@ -1,90 +1,90 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using NUnit.Framework; -using System.Web.Mvc; -using Moq; -using ProductsMvcSample.Models; -using ProductsMvcSample.Controllers; -using ProductsMvcSample.Services; - -namespace ProductsMvcSample.Tests.Controllers -{ - [TestFixture] - public class ProductsControllerFixture - { - [Test] - public void CategoryRendersProductsListWithProductsListViewData() - { - // Arrange mocks - var catalogService = new Mock(); - - // Target object - var controller = new ProductsController(catalogService.Object); - - // Act - var result = controller.Category(2); - - // Assert - Assert.IsNotNull(result); - Assert.IsTrue(result is ViewResult); - var viewResult = (ViewResult)result; - Assert.IsNotNull(viewResult.ViewData.Model); - Assert.That(viewResult.ViewData.Model is ProductsListViewData); - } - - [Test] - public void CategoryRendersRendersViewDataWithCategoryInfo() - { - // Arrange mocks - var catalogService = new Mock(); - catalogService - .Setup(c => c.GetCategoryName(2)) - .Returns("FooCategory"); - - // Target object - var controller = new ProductsController(catalogService.Object); - - // Act - var result = controller.Category(2); - - // Assert - // We don't repeat the assertions from the previous test here - var viewData = ((ViewResult)result).ViewData.Model as ProductsListViewData; - Assert.IsNotNull(viewData); - Assert.AreEqual(2, viewData.CategoryId); - Assert.AreEqual("FooCategory", viewData.CategoryName); - } - - [Test] - public void CategoryRendersRendersViewDataWithProdcutsListing() - { - // Arrange mocks - var catalogService = new Mock(); - catalogService - .Setup(c => c.GetCategoryName(2)) - .Returns("FooCategory"); - catalogService.Setup(c => c - .GetProducts(2)) - .Returns(new List - { - new Product { Id = 4 , Name = "Foo"}, - new Product { Id = 7 , Name = "Bar"} - }); - - // Target object - var controller = new ProductsController(catalogService.Object); - - // Act - var result = controller.Category(2); - - // Assert - var viewData = ((ViewResult)result).ViewData.Model as ProductsListViewData; - Assert.IsNotNull(viewData); - Assert.AreEqual(2, viewData.Products.Count); - Assert.AreEqual(4, viewData.Products[0].Id); - Assert.AreEqual("Bar", viewData.Products[1].Name); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using NUnit.Framework; +using System.Web.Mvc; +using Moq; +using ProductsMvcSample.Models; +using ProductsMvcSample.Controllers; +using ProductsMvcSample.Services; + +namespace ProductsMvcSample.Tests.Controllers +{ + [TestFixture] + public class ProductsControllerFixture + { + [Test] + public void CategoryRendersProductsListWithProductsListViewData() + { + // Arrange mocks + var catalogService = new Mock(); + + // Target object + var controller = new ProductsController(catalogService.Object); + + // Act + var result = controller.Category(2); + + // Assert + Assert.IsNotNull(result); + Assert.IsTrue(result is ViewResult); + var viewResult = (ViewResult)result; + Assert.IsNotNull(viewResult.ViewData.Model); + Assert.That(viewResult.ViewData.Model is ProductsListViewData); + } + + [Test] + public void CategoryRendersRendersViewDataWithCategoryInfo() + { + // Arrange mocks + var catalogService = new Mock(); + catalogService + .Setup(c => c.GetCategoryName(2)) + .Returns("FooCategory"); + + // Target object + var controller = new ProductsController(catalogService.Object); + + // Act + var result = controller.Category(2); + + // Assert + // We don't repeat the assertions from the previous test here + var viewData = ((ViewResult)result).ViewData.Model as ProductsListViewData; + Assert.IsNotNull(viewData); + Assert.AreEqual(2, viewData.CategoryId); + Assert.AreEqual("FooCategory", viewData.CategoryName); + } + + [Test] + public void CategoryRendersRendersViewDataWithProdcutsListing() + { + // Arrange mocks + var catalogService = new Mock(); + catalogService + .Setup(c => c.GetCategoryName(2)) + .Returns("FooCategory"); + catalogService.Setup(c => c + .GetProducts(2)) + .Returns(new List + { + new Product { Id = 4 , Name = "Foo"}, + new Product { Id = 7 , Name = "Bar"} + }); + + // Target object + var controller = new ProductsController(catalogService.Object); + + // Act + var result = controller.Category(2); + + // Assert + var viewData = ((ViewResult)result).ViewData.Model as ProductsListViewData; + Assert.IsNotNull(viewData); + Assert.AreEqual(2, viewData.Products.Count); + Assert.AreEqual(4, viewData.Products[0].Id); + Assert.AreEqual("Bar", viewData.Products[1].Name); + } + } +} diff --git a/Samples/ProductsMvcSample/UnitTests/ProductsMvcSample.Tests/MvcTestHelper.cs b/Samples/ProductsMvcSample/UnitTests/ProductsMvcSample.Tests/MvcTestHelper.cs index 6bc3eac0e..ac6e25478 100644 --- a/Samples/ProductsMvcSample/UnitTests/ProductsMvcSample.Tests/MvcTestHelper.cs +++ b/Samples/ProductsMvcSample/UnitTests/ProductsMvcSample.Tests/MvcTestHelper.cs @@ -1,47 +1,47 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Web.Mvc; -using System.Web; -using Moq; -using System.Linq.Expressions; -using NUnit.Framework; -using System.ComponentModel; -using System.Web.Routing; - -namespace ProductsMvcSample.Tests -{ - public static class MvcTestHelper - { - public static void VerifyCallsTo(this RouteData route, Expression> action) - where T : IController - { - Assert.IsNotNull(route); - - Assert.IsTrue(route.Values.ContainsKey("controller"), "Controller's name doesn't exists."); - Assert.AreEqual(typeof(T).Name, route.Values["controller"].ToString() + "Controller", "Controller's name."); - - var methodCall = action.Body as MethodCallExpression; - if (methodCall == null) - throw new NotSupportedException("Action body must be a MethodCallExpression."); - - Assert.IsTrue(route.Values.ContainsKey("action"), "Action's name doesn't exists."); - Assert.AreEqual(methodCall.Method.Name, route.Values["action"], "Action's name."); - - foreach (var parameter in methodCall.Method.GetParameters()) - { - Assert.IsTrue(route.Values.ContainsKey(parameter.Name), String.Format("Argument for '{0}' doesn't exists.", parameter.Name)); - - object expectedValue; - var argumentExpr = methodCall.Arguments[parameter.Position] as ConstantExpression; - if (argumentExpr != null) - expectedValue = argumentExpr.Value; - else - throw new NotSupportedException("Arguments must be ConstantExpression."); - object actualValue = TypeDescriptor.GetConverter(expectedValue.GetType()).ConvertFromString(route.Values[parameter.Name].ToString()); - Assert.AreEqual(expectedValue, actualValue, String.Format("Argument for '{0}'.", parameter.Name)); - } - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Web.Mvc; +using System.Web; +using Moq; +using System.Linq.Expressions; +using NUnit.Framework; +using System.ComponentModel; +using System.Web.Routing; + +namespace ProductsMvcSample.Tests +{ + public static class MvcTestHelper + { + public static void VerifyCallsTo(this RouteData route, Expression> action) + where T : IController + { + Assert.IsNotNull(route); + + Assert.IsTrue(route.Values.ContainsKey("controller"), "Controller's name doesn't exists."); + Assert.AreEqual(typeof(T).Name, route.Values["controller"].ToString() + "Controller", "Controller's name."); + + var methodCall = action.Body as MethodCallExpression; + if (methodCall == null) + throw new NotSupportedException("Action body must be a MethodCallExpression."); + + Assert.IsTrue(route.Values.ContainsKey("action"), "Action's name doesn't exists."); + Assert.AreEqual(methodCall.Method.Name, route.Values["action"], "Action's name."); + + foreach (var parameter in methodCall.Method.GetParameters()) + { + Assert.IsTrue(route.Values.ContainsKey(parameter.Name), String.Format("Argument for '{0}' doesn't exists.", parameter.Name)); + + object expectedValue; + var argumentExpr = methodCall.Arguments[parameter.Position] as ConstantExpression; + if (argumentExpr != null) + expectedValue = argumentExpr.Value; + else + throw new NotSupportedException("Arguments must be ConstantExpression."); + object actualValue = TypeDescriptor.GetConverter(expectedValue.GetType()).ConvertFromString(route.Values[parameter.Name].ToString()); + Assert.AreEqual(expectedValue, actualValue, String.Format("Argument for '{0}'.", parameter.Name)); + } + } + } +} diff --git a/Samples/ProductsMvcSample/UnitTests/ProductsMvcSample.Tests/ProductsMvcSample.Tests.csproj b/Samples/ProductsMvcSample/UnitTests/ProductsMvcSample.Tests/ProductsMvcSample.Tests.csproj index ba294275d..be8f8b402 100644 --- a/Samples/ProductsMvcSample/UnitTests/ProductsMvcSample.Tests/ProductsMvcSample.Tests.csproj +++ b/Samples/ProductsMvcSample/UnitTests/ProductsMvcSample.Tests/ProductsMvcSample.Tests.csproj @@ -1,94 +1,94 @@ - - - - Debug - AnyCPU - 9.0.30729 - 2.0 - {0BB61A7C-2791-45EC-A7A5-E2F525CAFA72} - Library - Properties - ProductsMvcSample.Tests - ProductsMvcSample.Tests - v3.5 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - False - ..\..\..\Lib\Moq.dll - - - False - ..\..\..\Lib\nunit.framework.dll - - - - 3.5 - - - - False - ..\..\..\Lib\System.Web.Abstractions.dll - 3.5 - - - False - - - False - ..\..\..\Lib\System.Web.Mvc.dll - - - False - ..\..\..\Lib\System.Web.Routing.dll - 3.5 - - - 3.5 - - - - - - - - Code - - - - Code - - - - - {766F76DC-B97D-41FE-A6D8-F039EAB8533D} - ProductsMvcSample - - - - + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {0BB61A7C-2791-45EC-A7A5-E2F525CAFA72} + Library + Properties + ProductsMvcSample.Tests + ProductsMvcSample.Tests + v3.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + ..\..\..\Lib\Moq.dll + + + False + ..\..\..\Lib\nunit.framework.dll + + + + 3.5 + + + + False + ..\..\..\Lib\System.Web.Abstractions.dll + 3.5 + + + False + + + False + ..\..\..\Lib\System.Web.Mvc.dll + + + False + ..\..\..\Lib\System.Web.Routing.dll + 3.5 + + + 3.5 + + + + + + + + Code + + + + Code + + + + + {766F76DC-B97D-41FE-A6D8-F039EAB8533D} + ProductsMvcSample + + + + \ No newline at end of file diff --git a/Samples/ProductsMvcSample/UnitTests/ProductsMvcSample.Tests/Properties/AssemblyInfo.cs b/Samples/ProductsMvcSample/UnitTests/ProductsMvcSample.Tests/Properties/AssemblyInfo.cs index 4f613ca1b..89e71474d 100644 --- a/Samples/ProductsMvcSample/UnitTests/ProductsMvcSample.Tests/Properties/AssemblyInfo.cs +++ b/Samples/ProductsMvcSample/UnitTests/ProductsMvcSample.Tests/Properties/AssemblyInfo.cs @@ -1,36 +1,36 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("ProductsMvcSample.Tests")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("ProductsMvcSample.Tests")] -[assembly: AssemblyCopyright("Copyright © 2008")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("de0092f2-f2f0-49b9-bf7e-cfbcb331cccc")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ProductsMvcSample.Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ProductsMvcSample.Tests")] +[assembly: AssemblyCopyright("Copyright © 2008")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("de0092f2-f2f0-49b9-bf7e-cfbcb331cccc")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Samples/ProductsMvcSample/UnitTests/ProductsMvcSample.Tests/Routes/ProductsRoutesFixture.cs b/Samples/ProductsMvcSample/UnitTests/ProductsMvcSample.Tests/Routes/ProductsRoutesFixture.cs index 15a96329e..834ca39af 100644 --- a/Samples/ProductsMvcSample/UnitTests/ProductsMvcSample.Tests/Routes/ProductsRoutesFixture.cs +++ b/Samples/ProductsMvcSample/UnitTests/ProductsMvcSample.Tests/Routes/ProductsRoutesFixture.cs @@ -1,39 +1,39 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using NUnit.Framework; -using System.Web.Mvc; -using ProductsMvcSample.Controllers; -using System.Web.Routing; -using Moq; -using System.Web; - -namespace ProductsMvcSample.Tests.Routes -{ - [TestFixture] - public class ProductsRoutesFixture - { - [Test] - public void ShouldAccept_Products_Category_CategoryId() - { - // Arrange - var routes = new RouteCollection(); - Global.RegisterRoutes(routes); - var context = new Mock { DefaultValue = DefaultValue.Mock }; - context - .Setup(c => c.Request.AppRelativeCurrentExecutionFilePath) - .Returns("~/Products/Category/2"); - - // Act - var routeData = routes.GetRouteData(context.Object); - - // Assert - Assert.AreEqual("Products", routeData.Values["controller"], "Default controller is HomeController"); - Assert.AreEqual("Category", routeData.Values["action"], "Default action is Index"); - Assert.AreEqual("2", routeData.Values["id"], "Default Id is empty string"); - - routeData.VerifyCallsTo(c => c.Category(2)); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using NUnit.Framework; +using System.Web.Mvc; +using ProductsMvcSample.Controllers; +using System.Web.Routing; +using Moq; +using System.Web; + +namespace ProductsMvcSample.Tests.Routes +{ + [TestFixture] + public class ProductsRoutesFixture + { + [Test] + public void ShouldAccept_Products_Category_CategoryId() + { + // Arrange + var routes = new RouteCollection(); + Global.RegisterRoutes(routes); + var context = new Mock { DefaultValue = DefaultValue.Mock }; + context + .Setup(c => c.Request.AppRelativeCurrentExecutionFilePath) + .Returns("~/Products/Category/2"); + + // Act + var routeData = routes.GetRouteData(context.Object); + + // Assert + Assert.AreEqual("Products", routeData.Values["controller"], "Default controller is HomeController"); + Assert.AreEqual("Category", routeData.Values["action"], "Default action is Index"); + Assert.AreEqual("2", routeData.Values["id"], "Default Id is empty string"); + + routeData.VerifyCallsTo(c => c.Category(2)); + } + } +} diff --git a/Samples/StoreSample/Source/Models/Category.cs b/Samples/StoreSample/Source/Models/Category.cs index 89e171520..0e7f7637c 100644 --- a/Samples/StoreSample/Source/Models/Category.cs +++ b/Samples/StoreSample/Source/Models/Category.cs @@ -1,10 +1,10 @@ -using System; - -namespace Store -{ - public class Category - { - public int Id { get; set; } - public string Name { get; set; } - } -} +using System; + +namespace Store +{ + public class Category + { + public int Id { get; set; } + public string Name { get; set; } + } +} diff --git a/Samples/StoreSample/Source/Models/Order.cs b/Samples/StoreSample/Source/Models/Order.cs index 5f0043856..ea3877b17 100644 --- a/Samples/StoreSample/Source/Models/Order.cs +++ b/Samples/StoreSample/Source/Models/Order.cs @@ -1,11 +1,11 @@ -using System; - -namespace Store -{ - public class Order - { - public Product Product { get; set; } - public int Quantity { get; set; } - public bool Filled { get; set; } - } -} +using System; + +namespace Store +{ + public class Order + { + public Product Product { get; set; } + public int Quantity { get; set; } + public bool Filled { get; set; } + } +} diff --git a/Samples/StoreSample/Source/Models/Product.cs b/Samples/StoreSample/Source/Models/Product.cs index 4e23e587f..36e5a42ef 100644 --- a/Samples/StoreSample/Source/Models/Product.cs +++ b/Samples/StoreSample/Source/Models/Product.cs @@ -1,10 +1,10 @@ -using System; - -namespace Store -{ - public class Product - { - public int Id { get; set; } - public string Name { get; set; } - } -} +using System; + +namespace Store +{ + public class Product + { + public int Id { get; set; } + public string Name { get; set; } + } +} diff --git a/Samples/StoreSample/Source/Presenters/ProductsPresenter.cs b/Samples/StoreSample/Source/Presenters/ProductsPresenter.cs index edd4cf874..93980fe65 100644 --- a/Samples/StoreSample/Source/Presenters/ProductsPresenter.cs +++ b/Samples/StoreSample/Source/Presenters/ProductsPresenter.cs @@ -1,39 +1,39 @@ -using System; - -namespace Store -{ - public class ProductsPresenter - { - ICatalogService catalog; - IProductsView view; - - public ProductsPresenter(ICatalogService catalog, IProductsView view) - { - this.catalog = catalog; - this.view = view; - view.SetCategories(catalog.GetCategories()); - view.CategorySelected += (sender, args) => SelectCategory(args.Category); - } - - void SelectCategory(Category category) - { - view.SetProducts(catalog.GetProducts(category.Id)); - } - - public void PlaceOrder(Order order) - { - if (catalog.HasInventory(order.Product.Id, order.Quantity)) - { - try - { - catalog.Remove(order.Product.Id, order.Quantity); - order.Filled = true; - } - catch (InvalidOperationException) - { - // LOG? - } - } - } - } -} +using System; + +namespace Store +{ + public class ProductsPresenter + { + ICatalogService catalog; + IProductsView view; + + public ProductsPresenter(ICatalogService catalog, IProductsView view) + { + this.catalog = catalog; + this.view = view; + view.SetCategories(catalog.GetCategories()); + view.CategorySelected += (sender, args) => SelectCategory(args.Category); + } + + void SelectCategory(Category category) + { + view.SetProducts(catalog.GetProducts(category.Id)); + } + + public void PlaceOrder(Order order) + { + if (catalog.HasInventory(order.Product.Id, order.Quantity)) + { + try + { + catalog.Remove(order.Product.Id, order.Quantity); + order.Filled = true; + } + catch (InvalidOperationException) + { + // LOG? + } + } + } + } +} diff --git a/Samples/StoreSample/Source/Properties/AssemblyInfo.cs b/Samples/StoreSample/Source/Properties/AssemblyInfo.cs index e14f57abd..f8b7f0031 100644 --- a/Samples/StoreSample/Source/Properties/AssemblyInfo.cs +++ b/Samples/StoreSample/Source/Properties/AssemblyInfo.cs @@ -1,36 +1,36 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Source")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("Source")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2009")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("d42053e4-3f65-401f-ae9f-31d242d3561f")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Source")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("Source")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2009")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("d42053e4-3f65-401f-ae9f-31d242d3561f")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Samples/StoreSample/Source/Services/CatalogService.cs b/Samples/StoreSample/Source/Services/CatalogService.cs index c22d26d02..f0bb4251b 100644 --- a/Samples/StoreSample/Source/Services/CatalogService.cs +++ b/Samples/StoreSample/Source/Services/CatalogService.cs @@ -1,9 +1,9 @@ -using System; - -namespace Store -{ - public class CatalogService - { - - } -} +using System; + +namespace Store +{ + public class CatalogService + { + + } +} diff --git a/Samples/StoreSample/Source/Services/ICatalogService.cs b/Samples/StoreSample/Source/Services/ICatalogService.cs index 3a661e1eb..d8ae34a7c 100644 --- a/Samples/StoreSample/Source/Services/ICatalogService.cs +++ b/Samples/StoreSample/Source/Services/ICatalogService.cs @@ -1,13 +1,13 @@ -using System; -using System.Collections.Generic; - -namespace Store -{ - public interface ICatalogService - { - IEnumerable GetCategories(); - IEnumerable GetProducts(int categoryId); - bool HasInventory(int productId, int quantity); - void Remove(int productId, int quantity); - } -} +using System; +using System.Collections.Generic; + +namespace Store +{ + public interface ICatalogService + { + IEnumerable GetCategories(); + IEnumerable GetProducts(int categoryId); + bool HasInventory(int productId, int quantity); + void Remove(int productId, int quantity); + } +} diff --git a/Samples/StoreSample/Source/Store.csproj b/Samples/StoreSample/Source/Store.csproj index 5ce569a17..05711c6b2 100644 --- a/Samples/StoreSample/Source/Store.csproj +++ b/Samples/StoreSample/Source/Store.csproj @@ -1,58 +1,58 @@ - - - - Debug - AnyCPU - 9.0.30729 - 2.0 - {BDF061BD-AD85-4BE6-9661-C24504896633} - Library - Properties - Store - Store - v3.5 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - 3.5 - - - - - - - - - - - - - - - + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {BDF061BD-AD85-4BE6-9661-C24504896633} + Library + Properties + Store + Store + v3.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + 3.5 + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Samples/StoreSample/Source/Views/CategoryEventArgs.cs b/Samples/StoreSample/Source/Views/CategoryEventArgs.cs index 216a13f81..e57ca22f4 100644 --- a/Samples/StoreSample/Source/Views/CategoryEventArgs.cs +++ b/Samples/StoreSample/Source/Views/CategoryEventArgs.cs @@ -1,14 +1,14 @@ -using System; - -namespace Store -{ - public class CategoryEventArgs : EventArgs - { - public CategoryEventArgs(Category category) - { - this.Category = category; - } - - public Category Category { get; private set; } - } -} +using System; + +namespace Store +{ + public class CategoryEventArgs : EventArgs + { + public CategoryEventArgs(Category category) + { + this.Category = category; + } + + public Category Category { get; private set; } + } +} diff --git a/Samples/StoreSample/Source/Views/IProductsView.cs b/Samples/StoreSample/Source/Views/IProductsView.cs index aa62675f3..1c464ab5b 100644 --- a/Samples/StoreSample/Source/Views/IProductsView.cs +++ b/Samples/StoreSample/Source/Views/IProductsView.cs @@ -1,12 +1,12 @@ -using System; -using System.Collections.Generic; - -namespace Store -{ - public interface IProductsView - { - event EventHandler CategorySelected; - void SetCategories(IEnumerable categories); - void SetProducts(IEnumerable products); - } -} +using System; +using System.Collections.Generic; + +namespace Store +{ + public interface IProductsView + { + event EventHandler CategorySelected; + void SetCategories(IEnumerable categories); + void SetProducts(IEnumerable products); + } +} diff --git a/Samples/StoreSample/StoreSample.sln b/Samples/StoreSample/StoreSample.sln index f8f3a2519..021f439e9 100644 --- a/Samples/StoreSample/StoreSample.sln +++ b/Samples/StoreSample/StoreSample.sln @@ -1,31 +1,31 @@ - -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Store", "Source\Store.csproj", "{BDF061BD-AD85-4BE6-9661-C24504896633}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Store.Tests", "UnitTests\Store.Tests.csproj", "{ACA76E67-0611-4415-927D-64FFB9C462A5}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{EAB21A99-0B6F-431E-B2D2-2D98FA1ECDDD}" - ProjectSection(SolutionItems) = preProject - Stories.txt = Stories.txt - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {BDF061BD-AD85-4BE6-9661-C24504896633}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {BDF061BD-AD85-4BE6-9661-C24504896633}.Debug|Any CPU.Build.0 = Debug|Any CPU - {BDF061BD-AD85-4BE6-9661-C24504896633}.Release|Any CPU.ActiveCfg = Release|Any CPU - {BDF061BD-AD85-4BE6-9661-C24504896633}.Release|Any CPU.Build.0 = Release|Any CPU - {ACA76E67-0611-4415-927D-64FFB9C462A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {ACA76E67-0611-4415-927D-64FFB9C462A5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {ACA76E67-0611-4415-927D-64FFB9C462A5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {ACA76E67-0611-4415-927D-64FFB9C462A5}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Store", "Source\Store.csproj", "{BDF061BD-AD85-4BE6-9661-C24504896633}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Store.Tests", "UnitTests\Store.Tests.csproj", "{ACA76E67-0611-4415-927D-64FFB9C462A5}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{EAB21A99-0B6F-431E-B2D2-2D98FA1ECDDD}" + ProjectSection(SolutionItems) = preProject + Stories.txt = Stories.txt + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BDF061BD-AD85-4BE6-9661-C24504896633}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BDF061BD-AD85-4BE6-9661-C24504896633}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BDF061BD-AD85-4BE6-9661-C24504896633}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BDF061BD-AD85-4BE6-9661-C24504896633}.Release|Any CPU.Build.0 = Release|Any CPU + {ACA76E67-0611-4415-927D-64FFB9C462A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ACA76E67-0611-4415-927D-64FFB9C462A5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ACA76E67-0611-4415-927D-64FFB9C462A5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ACA76E67-0611-4415-927D-64FFB9C462A5}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Samples/StoreSample/Stories.txt b/Samples/StoreSample/Stories.txt index 21aa45649..1ff2b4359 100644 --- a/Samples/StoreSample/Stories.txt +++ b/Samples/StoreSample/Stories.txt @@ -1,10 +1,10 @@ -Products - -1 - User sees a list of all available categories -2 - Upon selection of a category, a list of corresponding products is shown -3 - Upon selection of a product, the user can place an order by specifying the quantity. - a) Order will only be filled if there's enough inventory in stock. - b) If there's enough stock, the corresponding quantity of the product - will be removed from the stock. - c) If stock throws while removing the products, no error is raised and the +Products + +1 - User sees a list of all available categories +2 - Upon selection of a category, a list of corresponding products is shown +3 - Upon selection of a product, the user can place an order by specifying the quantity. + a) Order will only be filled if there's enough inventory in stock. + b) If there's enough stock, the corresponding quantity of the product + will be removed from the stock. + c) If stock throws while removing the products, no error is raised and the order remains unfilled so that the user can retry the operation. \ No newline at end of file diff --git a/Samples/StoreSample/UnitTests/ProductsPresenterFixturecs.cs b/Samples/StoreSample/UnitTests/ProductsPresenterFixturecs.cs index b415bac48..54deff40b 100644 --- a/Samples/StoreSample/UnitTests/ProductsPresenterFixturecs.cs +++ b/Samples/StoreSample/UnitTests/ProductsPresenterFixturecs.cs @@ -1,122 +1,122 @@ -using System.Collections.Generic; -using Moq; -using NUnit.Framework; -using System; - -namespace Store.Tests -{ - [TestFixture] - public class ProductsPresenterFixturecs - { - [Test] - public void ShouldSetViewCategories() - { - // Arrange - var catalog = new Mock(); - var view = new Mock(); - - // Act - var presenter = new ProductsPresenter(catalog.Object, view.Object); - - // Assert - view.Verify(v => v.SetCategories(It.IsAny>())); - } - - - [Test] - public void ShouldCategorySelectionSetProducts() - { - // Arrange - var catalog = new Mock(); - var view = new Mock(); - var presenter = new ProductsPresenter(catalog.Object, view.Object); - - // Act - view.Raise( - v => v.CategorySelected += null, - new CategoryEventArgs(new Category { Id = 1 })); - - // Assert - view.Verify(v => v.SetProducts(It.IsAny>())); - } - - [Test] - public void ShouldPlaceOrderIfEnoughInventory() - { - // Arrange - var catalog = new Mock(); - var view = new Mock(); - var presenter = new ProductsPresenter(catalog.Object, view.Object); - var order = new Order - { - Product = new Product { Id = 1 }, - Quantity = 5 - }; - - catalog - .Setup(c => c.HasInventory(1, 5)) - .Returns(true); - - // Act - presenter.PlaceOrder(order); - - // Assert - Assert.IsTrue(order.Filled); - catalog.Verify(c => c.HasInventory(1, 5)); - } - - [Test] - public void ShouldNotPlaceOrderIfNotEnoughInventory() - { - // Arrange - var catalog = new Mock(); - var view = new Mock(); - var presenter = new ProductsPresenter(catalog.Object, view.Object); - var order = new Order - { - Product = new Product { Id = 1 }, - Quantity = 5 - }; - - catalog - .Setup(c => c.HasInventory(1, 5)) - .Returns(false); - - // Act - presenter.PlaceOrder(order); - - // Assert - Assert.IsFalse(order.Filled); - catalog.Verify(c => c.HasInventory(1, 5)); - } - - [Test] - public void ShouldNotPlaceOrderIfFailsToRemove() - { - // Arrange - var catalog = new Mock(); - var view = new Mock(); - var presenter = new ProductsPresenter(catalog.Object, view.Object); - var order = new Order - { - Product = new Product { Id = 1 }, - Quantity = 5 - }; - - catalog - .Setup(c => c.HasInventory(1, 5)) - .Returns(true); - catalog - .Setup(c => c.Remove(1, 5)) - .Throws(); - - // Act - presenter.PlaceOrder(order); - - // Assert - Assert.IsFalse(order.Filled); - catalog.Verify(c => c.HasInventory(1, 5)); - catalog.Verify(c => c.Remove(1, 5)); - } - } -} +using System.Collections.Generic; +using Moq; +using NUnit.Framework; +using System; + +namespace Store.Tests +{ + [TestFixture] + public class ProductsPresenterFixturecs + { + [Test] + public void ShouldSetViewCategories() + { + // Arrange + var catalog = new Mock(); + var view = new Mock(); + + // Act + var presenter = new ProductsPresenter(catalog.Object, view.Object); + + // Assert + view.Verify(v => v.SetCategories(It.IsAny>())); + } + + + [Test] + public void ShouldCategorySelectionSetProducts() + { + // Arrange + var catalog = new Mock(); + var view = new Mock(); + var presenter = new ProductsPresenter(catalog.Object, view.Object); + + // Act + view.Raise( + v => v.CategorySelected += null, + new CategoryEventArgs(new Category { Id = 1 })); + + // Assert + view.Verify(v => v.SetProducts(It.IsAny>())); + } + + [Test] + public void ShouldPlaceOrderIfEnoughInventory() + { + // Arrange + var catalog = new Mock(); + var view = new Mock(); + var presenter = new ProductsPresenter(catalog.Object, view.Object); + var order = new Order + { + Product = new Product { Id = 1 }, + Quantity = 5 + }; + + catalog + .Setup(c => c.HasInventory(1, 5)) + .Returns(true); + + // Act + presenter.PlaceOrder(order); + + // Assert + Assert.IsTrue(order.Filled); + catalog.Verify(c => c.HasInventory(1, 5)); + } + + [Test] + public void ShouldNotPlaceOrderIfNotEnoughInventory() + { + // Arrange + var catalog = new Mock(); + var view = new Mock(); + var presenter = new ProductsPresenter(catalog.Object, view.Object); + var order = new Order + { + Product = new Product { Id = 1 }, + Quantity = 5 + }; + + catalog + .Setup(c => c.HasInventory(1, 5)) + .Returns(false); + + // Act + presenter.PlaceOrder(order); + + // Assert + Assert.IsFalse(order.Filled); + catalog.Verify(c => c.HasInventory(1, 5)); + } + + [Test] + public void ShouldNotPlaceOrderIfFailsToRemove() + { + // Arrange + var catalog = new Mock(); + var view = new Mock(); + var presenter = new ProductsPresenter(catalog.Object, view.Object); + var order = new Order + { + Product = new Product { Id = 1 }, + Quantity = 5 + }; + + catalog + .Setup(c => c.HasInventory(1, 5)) + .Returns(true); + catalog + .Setup(c => c.Remove(1, 5)) + .Throws(); + + // Act + presenter.PlaceOrder(order); + + // Assert + Assert.IsFalse(order.Filled); + catalog.Verify(c => c.HasInventory(1, 5)); + catalog.Verify(c => c.Remove(1, 5)); + } + } +} diff --git a/Samples/StoreSample/UnitTests/Properties/AssemblyInfo.cs b/Samples/StoreSample/UnitTests/Properties/AssemblyInfo.cs index d28c43980..b3fedb0df 100644 --- a/Samples/StoreSample/UnitTests/Properties/AssemblyInfo.cs +++ b/Samples/StoreSample/UnitTests/Properties/AssemblyInfo.cs @@ -1,36 +1,36 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("UnitTests")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("UnitTests")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2009")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("ad32ee97-abac-45b0-94b0-6a987e8e22a6")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("UnitTests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("UnitTests")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2009")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("ad32ee97-abac-45b0-94b0-6a987e8e22a6")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Samples/StoreSample/UnitTests/Store.Tests.csproj b/Samples/StoreSample/UnitTests/Store.Tests.csproj index 57e432263..7c7f62c2f 100644 --- a/Samples/StoreSample/UnitTests/Store.Tests.csproj +++ b/Samples/StoreSample/UnitTests/Store.Tests.csproj @@ -1,65 +1,65 @@ - - - - Debug - AnyCPU - 9.0.30729 - 2.0 - {ACA76E67-0611-4415-927D-64FFB9C462A5} - Library - Properties - Store.Tests - Store.Tests - v3.5 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - False - ..\..\Lib\Moq.dll - - - False - ..\..\Lib\nunit.framework.dll - - - - 3.5 - - - - - - - - - {BDF061BD-AD85-4BE6-9661-C24504896633} - Store - - - - + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {ACA76E67-0611-4415-927D-64FFB9C462A5} + Library + Properties + Store.Tests + Store.Tests + v3.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + ..\..\Lib\Moq.dll + + + False + ..\..\Lib\nunit.framework.dll + + + + 3.5 + + + + + + + + + {BDF061BD-AD85-4BE6-9661-C24504896633} + Store + + + + \ No newline at end of file diff --git a/Source/AdvancedMatcherAttribute.cs b/Source/AdvancedMatcherAttribute.cs index d5de663bc..d2fcb8ebc 100644 --- a/Source/AdvancedMatcherAttribute.cs +++ b/Source/AdvancedMatcherAttribute.cs @@ -1,71 +1,71 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Reflection; - -namespace Moq -{ - [AttributeUsage(AttributeTargets.Method, Inherited = true)] - internal sealed class AdvancedMatcherAttribute : Attribute - { - public AdvancedMatcherAttribute(Type matcherType) - { - Guard.NotNull(() => matcherType, matcherType); - Guard.CanBeAssigned(() => matcherType, matcherType, typeof(IMatcher)); - - this.MatcherType = matcherType; - } - - public Type MatcherType { get; private set; } - - public IMatcher CreateMatcher() - { - try - { - return (IMatcher)Activator.CreateInstance(MatcherType); - } - catch (TargetInvocationException e) - { - throw e.InnerException; - } - } - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Reflection; + +namespace Moq +{ + [AttributeUsage(AttributeTargets.Method, Inherited = true)] + internal sealed class AdvancedMatcherAttribute : Attribute + { + public AdvancedMatcherAttribute(Type matcherType) + { + Guard.NotNull(() => matcherType, matcherType); + Guard.CanBeAssigned(() => matcherType, matcherType, typeof(IMatcher)); + + this.MatcherType = matcherType; + } + + public Type MatcherType { get; private set; } + + public IMatcher CreateMatcher() + { + try + { + return (IMatcher)Activator.CreateInstance(MatcherType); + } + catch (TargetInvocationException e) + { + throw e.InnerException; + } + } + } } \ No newline at end of file diff --git a/Source/AsInterface.cs b/Source/AsInterface.cs index 51885331c..e2dfb6c9f 100644 --- a/Source/AsInterface.cs +++ b/Source/AsInterface.cs @@ -1,102 +1,102 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Collections.Generic; -using System.Reflection; - -namespace Moq -{ - internal class AsInterface : Mock - where TInterface : class - { - private Mock owner; - - public AsInterface(Mock owner) - : base(true) - { - this.owner = owner; - } - - internal override Dictionary InnerMocks - { - get { return this.owner.InnerMocks; } - } - - internal override Interceptor Interceptor - { - get { return this.owner.Interceptor; } - set { this.owner.Interceptor = value; } - } - - internal override Type MockedType - { - get { return typeof(TInterface); } - } - - public override MockBehavior Behavior - { - get { return this.owner.Behavior; } - internal set { this.owner.Behavior = value; } - } - - public override bool CallBase - { - get { return this.owner.CallBase; } - set { this.owner.CallBase = value; } - } - - public override DefaultValue DefaultValue - { - get { return this.owner.DefaultValue; } - set { this.owner.DefaultValue = value; } - } - - public override TInterface Object - { - get { return this.owner.Object as TInterface; } - } - - public override Mock As() - { - return this.owner.As(); - } - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Collections.Generic; +using System.Reflection; + +namespace Moq +{ + internal class AsInterface : Mock + where TInterface : class + { + private Mock owner; + + public AsInterface(Mock owner) + : base(true) + { + this.owner = owner; + } + + internal override Dictionary InnerMocks + { + get { return this.owner.InnerMocks; } + } + + internal override Interceptor Interceptor + { + get { return this.owner.Interceptor; } + set { this.owner.Interceptor = value; } + } + + internal override Type MockedType + { + get { return typeof(TInterface); } + } + + public override MockBehavior Behavior + { + get { return this.owner.Behavior; } + internal set { this.owner.Behavior = value; } + } + + public override bool CallBase + { + get { return this.owner.CallBase; } + set { this.owner.CallBase = value; } + } + + public override DefaultValue DefaultValue + { + get { return this.owner.DefaultValue; } + set { this.owner.DefaultValue = value; } + } + + public override TInterface Object + { + get { return this.owner.Object as TInterface; } + } + + public override Mock As() + { + return this.owner.As(); + } + } } \ No newline at end of file diff --git a/Source/ConditionalContext.cs b/Source/ConditionalContext.cs index b2dce7132..4245e762f 100644 --- a/Source/ConditionalContext.cs +++ b/Source/ConditionalContext.cs @@ -1,85 +1,85 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Linq.Expressions; -using Moq.Language; -using Moq.Language.Flow; - -namespace Moq -{ - internal class ConditionalContext : ISetupConditionResult - where T : class - { - private Mock mock; - private Func condition; - - public ConditionalContext(Mock mock, Func condition) - { - this.mock = mock; - this.condition = condition; - } - - public ISetup Setup(Expression> expression) - { - return Mock.Setup(mock, expression, this.condition); - } - - public ISetup Setup(Expression> expression) - { - return Mock.Setup(mock, expression, this.condition); - } - - public ISetupGetter SetupGet(Expression> expression) - { - return Mock.SetupGet(mock, expression, this.condition); - } - - public ISetupSetter SetupSet(Action setterExpression) - { - return Mock.SetupSet(mock, setterExpression, this.condition); - } - - public ISetup SetupSet(Action setterExpression) - { - return Mock.SetupSet(mock, setterExpression, this.condition); - } - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Linq.Expressions; +using Moq.Language; +using Moq.Language.Flow; + +namespace Moq +{ + internal class ConditionalContext : ISetupConditionResult + where T : class + { + private Mock mock; + private Func condition; + + public ConditionalContext(Mock mock, Func condition) + { + this.mock = mock; + this.condition = condition; + } + + public ISetup Setup(Expression> expression) + { + return Mock.Setup(mock, expression, this.condition); + } + + public ISetup Setup(Expression> expression) + { + return Mock.Setup(mock, expression, this.condition); + } + + public ISetupGetter SetupGet(Expression> expression) + { + return Mock.SetupGet(mock, expression, this.condition); + } + + public ISetupSetter SetupSet(Action setterExpression) + { + return Mock.SetupSet(mock, setterExpression, this.condition); + } + + public ISetup SetupSet(Action setterExpression) + { + return Mock.SetupSet(mock, setterExpression, this.condition); + } + } } \ No newline at end of file diff --git a/Source/DefaultValue.cs b/Source/DefaultValue.cs index 4d47223aa..244473afa 100644 --- a/Source/DefaultValue.cs +++ b/Source/DefaultValue.cs @@ -1,66 +1,66 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -namespace Moq -{ - /// - /// Determines the way default values are generated - /// calculated for loose mocks. - /// - public enum DefaultValue - { - /// - /// Default behavior, which generates empty values for - /// value types (i.e. default(int)), empty array and - /// enumerables, and nulls for all other reference types. - /// - Empty, - - /// - /// Whenever the default value generated by - /// is null, replaces this value with a mock (if the type - /// can be mocked). - /// - /// - /// For sealed classes, a null value will be generated. - /// - Mock - } -} +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +namespace Moq +{ + /// + /// Determines the way default values are generated + /// calculated for loose mocks. + /// + public enum DefaultValue + { + /// + /// Default behavior, which generates empty values for + /// value types (i.e. default(int)), empty array and + /// enumerables, and nulls for all other reference types. + /// + Empty, + + /// + /// Whenever the default value generated by + /// is null, replaces this value with a mock (if the type + /// can be mocked). + /// + /// + /// For sealed classes, a null value will be generated. + /// + Mock + } +} diff --git a/Source/EmptyDefaultValueProvider.cs b/Source/EmptyDefaultValueProvider.cs index c0c38eb3e..c47930867 100644 --- a/Source/EmptyDefaultValueProvider.cs +++ b/Source/EmptyDefaultValueProvider.cs @@ -1,119 +1,119 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; - -namespace Moq -{ - /// - /// A that returns an empty default value - /// for invocations that do not have setups or return values, with loose mocks. - /// This is the default behavior for a mock. - /// - internal class EmptyDefaultValueProvider : IDefaultValueProvider - { - private Dictionary defaultValues = new Dictionary(); - - public virtual void DefineDefault(T value) - { - this.defaultValues[typeof(T)] = value; - } - - public virtual object ProvideDefault(MethodInfo member) - { - var valueType = member.ReturnType; - - if (this.defaultValues.ContainsKey(valueType)) - { - return this.defaultValues[valueType]; - } - - return valueType.IsValueType ? GetValueTypeDefault(valueType) : GetReferenceTypeDefault(valueType); - } - - private static object GetReferenceTypeDefault(Type valueType) - { - if (valueType.IsArray) - { - return Activator.CreateInstance(valueType, 0); - } - else if (valueType == typeof(IEnumerable)) - { - return new object[0]; - } - else if (valueType == typeof(IQueryable)) - { - return new object[0].AsQueryable(); - } - else if (valueType.IsGenericType && valueType.GetGenericTypeDefinition() == typeof(IEnumerable<>)) - { - var genericListType = typeof(List<>).MakeGenericType(valueType.GetGenericArguments()[0]); - return Activator.CreateInstance(genericListType); - } - else if (valueType.IsGenericType && valueType.GetGenericTypeDefinition() == typeof(IQueryable<>)) - { - var genericType = valueType.GetGenericArguments()[0]; - var genericListType = typeof(List<>).MakeGenericType(genericType); - - return typeof(Queryable).GetMethods() - .Single(x => x.Name == "AsQueryable" && x.IsGenericMethod) - .MakeGenericMethod(genericType) - .Invoke(null, new[] { Activator.CreateInstance(genericListType) }); - } - - return null; - } - - private static object GetValueTypeDefault(Type valueType) - { - // For nullable value types, return null. - if (valueType.IsGenericType && valueType.GetGenericTypeDefinition() == typeof(Nullable<>)) - { - return null; - } - - return Activator.CreateInstance(valueType); - } - } -} +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +namespace Moq +{ + /// + /// A that returns an empty default value + /// for invocations that do not have setups or return values, with loose mocks. + /// This is the default behavior for a mock. + /// + internal class EmptyDefaultValueProvider : IDefaultValueProvider + { + private Dictionary defaultValues = new Dictionary(); + + public virtual void DefineDefault(T value) + { + this.defaultValues[typeof(T)] = value; + } + + public virtual object ProvideDefault(MethodInfo member) + { + var valueType = member.ReturnType; + + if (this.defaultValues.ContainsKey(valueType)) + { + return this.defaultValues[valueType]; + } + + return valueType.IsValueType ? GetValueTypeDefault(valueType) : GetReferenceTypeDefault(valueType); + } + + private static object GetReferenceTypeDefault(Type valueType) + { + if (valueType.IsArray) + { + return Activator.CreateInstance(valueType, 0); + } + else if (valueType == typeof(IEnumerable)) + { + return new object[0]; + } + else if (valueType == typeof(IQueryable)) + { + return new object[0].AsQueryable(); + } + else if (valueType.IsGenericType && valueType.GetGenericTypeDefinition() == typeof(IEnumerable<>)) + { + var genericListType = typeof(List<>).MakeGenericType(valueType.GetGenericArguments()[0]); + return Activator.CreateInstance(genericListType); + } + else if (valueType.IsGenericType && valueType.GetGenericTypeDefinition() == typeof(IQueryable<>)) + { + var genericType = valueType.GetGenericArguments()[0]; + var genericListType = typeof(List<>).MakeGenericType(genericType); + + return typeof(Queryable).GetMethods() + .Single(x => x.Name == "AsQueryable" && x.IsGenericMethod) + .MakeGenericMethod(genericType) + .Invoke(null, new[] { Activator.CreateInstance(genericListType) }); + } + + return null; + } + + private static object GetValueTypeDefault(Type valueType) + { + // For nullable value types, return null. + if (valueType.IsGenericType && valueType.GetGenericTypeDefinition() == typeof(Nullable<>)) + { + return null; + } + + return Activator.CreateInstance(valueType); + } + } +} diff --git a/Source/Evaluator.cs b/Source/Evaluator.cs index 84c6d4b63..cb51b1854 100644 --- a/Source/Evaluator.cs +++ b/Source/Evaluator.cs @@ -1,166 +1,166 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Collections.Generic; -using System.Linq.Expressions; - -namespace Moq -{ - /// - /// Provides partial evaluation of subtrees, whenever they can be evaluated locally. - /// - /// Matt Warren: http://blogs.msdn.com/mattwar - /// Documented by InSTEDD: http://www.instedd.org - internal static class Evaluator - { - /// - /// Performs evaluation and replacement of independent sub-trees - /// - /// The root of the expression tree. - /// A function that decides whether a given expression - /// node can be part of the local function. - /// A new tree with sub-trees evaluated and replaced. - public static Expression PartialEval(Expression expression, Func fnCanBeEvaluated) - { - return new SubtreeEvaluator(new Nominator(fnCanBeEvaluated).Nominate(expression)).Eval(expression); - } - - /// - /// Performs evaluation and replacement of independent sub-trees - /// - /// The root of the expression tree. - /// A new tree with sub-trees evaluated and replaced. - public static Expression PartialEval(Expression expression) - { - return PartialEval(expression, e => e.NodeType != ExpressionType.Parameter); - } - - /// - /// Evaluates and replaces sub-trees when first candidate is reached (top-down) - /// - private class SubtreeEvaluator : ExpressionVisitor - { - private HashSet candidates; - - internal SubtreeEvaluator(HashSet candidates) - { - this.candidates = candidates; - } - - internal Expression Eval(Expression exp) - { - return this.Visit(exp); - } - - public override Expression Visit(Expression exp) - { - if (exp == null) - { - return null; - } - if (this.candidates.Contains(exp)) - { - return Evaluate(exp); - } - return base.Visit(exp); - } - - private static Expression Evaluate(Expression e) - { - if (e.NodeType == ExpressionType.Constant) - { - return e; - } - LambdaExpression lambda = Expression.Lambda(e); - Delegate fn = lambda.Compile(); - return Expression.Constant(fn.DynamicInvoke(null), e.Type); - } - } - - /// - /// Performs bottom-up analysis to determine which nodes can possibly - /// be part of an evaluated sub-tree. - /// - private class Nominator : ExpressionVisitor - { - private Func fnCanBeEvaluated; - private HashSet candidates; - private bool cannotBeEvaluated; - - internal Nominator(Func fnCanBeEvaluated) - { - this.fnCanBeEvaluated = fnCanBeEvaluated; - } - - internal HashSet Nominate(Expression expression) - { - this.candidates = new HashSet(); - this.Visit(expression); - return this.candidates; - } - - public override Expression Visit(Expression expression) - { - if (expression != null) - { - bool saveCannotBeEvaluated = this.cannotBeEvaluated; - this.cannotBeEvaluated = false; - base.Visit(expression); - if (!this.cannotBeEvaluated) - { - if (this.fnCanBeEvaluated(expression)) - { - this.candidates.Add(expression); - } - else - { - this.cannotBeEvaluated = true; - } - } - - this.cannotBeEvaluated |= saveCannotBeEvaluated; - } - - return expression; - } - } - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Collections.Generic; +using System.Linq.Expressions; + +namespace Moq +{ + /// + /// Provides partial evaluation of subtrees, whenever they can be evaluated locally. + /// + /// Matt Warren: http://blogs.msdn.com/mattwar + /// Documented by InSTEDD: http://www.instedd.org + internal static class Evaluator + { + /// + /// Performs evaluation and replacement of independent sub-trees + /// + /// The root of the expression tree. + /// A function that decides whether a given expression + /// node can be part of the local function. + /// A new tree with sub-trees evaluated and replaced. + public static Expression PartialEval(Expression expression, Func fnCanBeEvaluated) + { + return new SubtreeEvaluator(new Nominator(fnCanBeEvaluated).Nominate(expression)).Eval(expression); + } + + /// + /// Performs evaluation and replacement of independent sub-trees + /// + /// The root of the expression tree. + /// A new tree with sub-trees evaluated and replaced. + public static Expression PartialEval(Expression expression) + { + return PartialEval(expression, e => e.NodeType != ExpressionType.Parameter); + } + + /// + /// Evaluates and replaces sub-trees when first candidate is reached (top-down) + /// + private class SubtreeEvaluator : ExpressionVisitor + { + private HashSet candidates; + + internal SubtreeEvaluator(HashSet candidates) + { + this.candidates = candidates; + } + + internal Expression Eval(Expression exp) + { + return this.Visit(exp); + } + + public override Expression Visit(Expression exp) + { + if (exp == null) + { + return null; + } + if (this.candidates.Contains(exp)) + { + return Evaluate(exp); + } + return base.Visit(exp); + } + + private static Expression Evaluate(Expression e) + { + if (e.NodeType == ExpressionType.Constant) + { + return e; + } + LambdaExpression lambda = Expression.Lambda(e); + Delegate fn = lambda.Compile(); + return Expression.Constant(fn.DynamicInvoke(null), e.Type); + } + } + + /// + /// Performs bottom-up analysis to determine which nodes can possibly + /// be part of an evaluated sub-tree. + /// + private class Nominator : ExpressionVisitor + { + private Func fnCanBeEvaluated; + private HashSet candidates; + private bool cannotBeEvaluated; + + internal Nominator(Func fnCanBeEvaluated) + { + this.fnCanBeEvaluated = fnCanBeEvaluated; + } + + internal HashSet Nominate(Expression expression) + { + this.candidates = new HashSet(); + this.Visit(expression); + return this.candidates; + } + + public override Expression Visit(Expression expression) + { + if (expression != null) + { + bool saveCannotBeEvaluated = this.cannotBeEvaluated; + this.cannotBeEvaluated = false; + base.Visit(expression); + if (!this.cannotBeEvaluated) + { + if (this.fnCanBeEvaluated(expression)) + { + this.candidates.Add(expression); + } + else + { + this.cannotBeEvaluated = true; + } + } + + this.cannotBeEvaluated |= saveCannotBeEvaluated; + } + + return expression; + } + } + } } \ No newline at end of file diff --git a/Source/ExpressionStringBuilder.cs b/Source/ExpressionStringBuilder.cs index a005f1a85..288f50d2b 100644 --- a/Source/ExpressionStringBuilder.cs +++ b/Source/ExpressionStringBuilder.cs @@ -1,1125 +1,1125 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Linq.Expressions; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Text; -using System.Collections.ObjectModel; - -namespace Moq -{ - /// - /// The intention of is to create a more readable - /// string representation for the failure message. - /// - internal class ExpressionStringBuilder - { - private readonly Expression expression; - private StringBuilder builder; - private Func getTypeName; - - internal static string GetString(Expression expression) - { - return GetString(expression, type => type.Name); - } - - internal static string GetString(Expression expression, Func getTypeName) - { - var builder = new ExpressionStringBuilder(getTypeName, expression); - return builder.ToString(); - } - - public ExpressionStringBuilder(Func getTypeName, Expression expression) - { - this.getTypeName = getTypeName; - this.expression = expression; - } - - public override string ToString() - { - builder = new StringBuilder(); - ToString(expression); - return builder.ToString(); - } - - public void ToString(Expression exp) - { - if (exp == null) - { - builder.Append("null"); - return; - } - switch (exp.NodeType) - { - case ExpressionType.Negate: - case ExpressionType.NegateChecked: - case ExpressionType.Not: - case ExpressionType.Convert: - case ExpressionType.ConvertChecked: - case ExpressionType.ArrayLength: - case ExpressionType.Quote: - case ExpressionType.TypeAs: - ToStringUnary((UnaryExpression)exp); - return; - case ExpressionType.Add: - case ExpressionType.AddChecked: - case ExpressionType.Subtract: - case ExpressionType.SubtractChecked: - case ExpressionType.Multiply: - case ExpressionType.MultiplyChecked: - case ExpressionType.Divide: - case ExpressionType.Modulo: - case ExpressionType.And: - case ExpressionType.AndAlso: - case ExpressionType.Or: - case ExpressionType.OrElse: - case ExpressionType.LessThan: - case ExpressionType.LessThanOrEqual: - case ExpressionType.GreaterThan: - case ExpressionType.GreaterThanOrEqual: - case ExpressionType.Equal: - case ExpressionType.NotEqual: - case ExpressionType.Coalesce: - case ExpressionType.ArrayIndex: - case ExpressionType.RightShift: - case ExpressionType.LeftShift: - case ExpressionType.ExclusiveOr: - ToStringBinary((BinaryExpression)exp); - return; - case ExpressionType.TypeIs: - ToStringTypeIs((TypeBinaryExpression)exp); - return; - case ExpressionType.Conditional: - ToStringConditional((ConditionalExpression)exp); - return; - case ExpressionType.Constant: - ToStringConstant((ConstantExpression)exp); - return; - case ExpressionType.Parameter: - ToStringParameter((ParameterExpression)exp); - return; - case ExpressionType.MemberAccess: - ToStringMemberAccess((MemberExpression)exp); - return; - case ExpressionType.Call: - ToStringMethodCall((MethodCallExpression)exp); - return; - case ExpressionType.Lambda: - ToStringLambda((LambdaExpression)exp); - return; - case ExpressionType.New: - ToStringNew((NewExpression)exp); - return; - case ExpressionType.NewArrayInit: - case ExpressionType.NewArrayBounds: - ToStringNewArray((NewArrayExpression)exp); - return; - case ExpressionType.Invoke: - ToStringInvocation((InvocationExpression)exp); - return; - case ExpressionType.MemberInit: - ToStringMemberInit((MemberInitExpression)exp); - return; - case ExpressionType.ListInit: - ToStringListInit((ListInitExpression)exp); - return; - default: - throw new Exception(string.Format("Unhandled expression type: '{0}'", exp.NodeType)); - } - } - - private void ToStringBinding(MemberBinding binding) - { - switch (binding.BindingType) - { - case MemberBindingType.Assignment: - ToStringMemberAssignment((MemberAssignment)binding); - return; - case MemberBindingType.MemberBinding: - ToStringMemberMemberBinding((MemberMemberBinding)binding); - return; - case MemberBindingType.ListBinding: - ToStringMemberListBinding((MemberListBinding)binding); - return; - default: - throw new Exception(string.Format("Unhandled binding type '{0}'", binding.BindingType)); - } - } - - private void ToStringElementInitializer(ElementInit initializer) - { - builder.Append("{ "); - ToStringExpressionList(initializer.Arguments); - builder.Append(" }"); - return; - } - - private void ToStringUnary(UnaryExpression u) - { - switch (u.NodeType) - { - case ExpressionType.Convert: - case ExpressionType.ConvertChecked: - builder.Append("(").Append(this.getTypeName(u.Type)).Append(")"); - ToString(u.Operand); - //builder.Append(")"); - return; - - case ExpressionType.ArrayLength: - ToString(u.Operand); - builder.Append(".Length"); - return; - - case ExpressionType.Negate: - case ExpressionType.NegateChecked: - builder.Append("-"); - ToString(u.Operand); - return; - - case ExpressionType.Not: - builder.Append("!("); - ToString(u.Operand); - builder.Append(")"); - return; - - case ExpressionType.Quote: - ToString(u.Operand); - return; - - case ExpressionType.TypeAs: - builder.Append("("); - ToString(u.Operand); - builder.Append(" as "); - builder.Append(u.Type.DisplayName(this.getTypeName)); - builder.Append(")"); - return; - } - return; - } - - private void ToStringBinary(BinaryExpression b) - { - if (b.NodeType == ExpressionType.ArrayIndex) - { - ToString(b.Left); - builder.Append("["); - ToString(b.Right); - builder.Append("]"); - } - else - { - string @operator = ToStringOperator(b.NodeType); - if (NeedEncloseInParen(b.Left)) - { - builder.Append("("); - ToString(b.Left); - builder.Append(")"); - } - else - { - ToString(b.Left); - } - builder.Append(" "); - builder.Append(@operator); - builder.Append(" "); - if (NeedEncloseInParen(b.Right)) - { - builder.Append("("); - ToString(b.Right); - builder.Append(")"); - } - else - { - ToString(b.Right); - } - } - } - - private static bool NeedEncloseInParen(Expression operand) - { - return operand.NodeType == ExpressionType.AndAlso || operand.NodeType == ExpressionType.OrElse; - } - - private void ToStringTypeIs(TypeBinaryExpression b) - { - ToString(b.Expression); - return; - } - - private void ToStringConstant(ConstantExpression c) - { - var value = c.Value; - if (value != null) - { - if (value is string) - { - builder.Append("\"").Append(value).Append("\""); - } - else if (value.ToString() == value.GetType().ToString()) - { - // Perhaps is better without nothing (at least for local variables) - //builder.Append(""); - } - else if (c.Type.IsEnum) - { - builder.Append(c.Type.DisplayName(this.getTypeName)).Append(".").Append(value); - } - else - { - builder.Append(value); - } - } - else - { - builder.Append("null"); - } - } - - private void ToStringConditional(ConditionalExpression c) - { - ToString(c.Test); - ToString(c.IfTrue); - ToString(c.IfFalse); - return; - } - - private void ToStringParameter(ParameterExpression p) - { - if (p.Name != null) - { - builder.Append(p.Name); - } - else - { - builder.Append(""); - } - } - - private void ToStringMemberAccess(MemberExpression m) - { - if (m.Expression != null) - { - ToString(m.Expression); - } - else - { - builder.Append(m.Member.DeclaringType.DisplayName(this.getTypeName)); - } - builder.Append("."); - builder.Append(m.Member.Name); - return; - } - - private void ToStringMethodCall(MethodCallExpression node) - { - if (node != null) - { - var paramFrom = 0; - var expression = node.Object; - - if (Attribute.GetCustomAttribute(node.Method, typeof(ExtensionAttribute)) != null) - { - paramFrom = 1; - expression = node.Arguments[0]; - } - - if (expression != null) - { - ToString(expression); - } - else // Method is static - { - this.builder.Append(this.getTypeName(node.Method.DeclaringType)); - } - - if (node.Method.IsPropertyIndexerGetter()) - { - this.builder.Append("["); - AsCommaSeparatedValues(node.Arguments.Skip(paramFrom), ToString); - this.builder.Append("]"); - } - else if (node.Method.IsPropertyIndexerSetter()) - { - this.builder.Append("["); - AsCommaSeparatedValues(node.Arguments - .Skip(paramFrom) - .Take(node.Arguments.Count - paramFrom), ToString); - this.builder.Append("] = "); - ToString(node.Arguments.Last()); - } - else if (node.Method.IsPropertyGetter()) - { - this.builder.Append(".").Append(node.Method.Name.Substring(4)); - } - else if (node.Method.IsPropertySetter()) - { - this.builder.Append(".").Append(node.Method.Name.Substring(4)).Append(" = "); - ToString(node.Arguments.Last()); - } - else if (node.Method.IsGenericMethod) - { - this.builder - .Append(".") - .Append(node.Method.Name) - .Append("<") - .Append(string.Join(",", node.Method.GetGenericArguments().Select(s => this.getTypeName(s)).ToArray())) - .Append(">("); - AsCommaSeparatedValues(node.Arguments.Skip(paramFrom), ToString); - this.builder.Append(")"); - } - else - { - this.builder - .Append(".") - .Append(node.Method.Name) - .Append("("); - AsCommaSeparatedValues(node.Arguments.Skip(paramFrom), ToString); - this.builder.Append(")"); - } - } - } - - private void ToStringExpressionList(ReadOnlyCollection original) - { - AsCommaSeparatedValues(original, ToString); - return; - } - - private void ToStringMemberAssignment(MemberAssignment assignment) - { - builder.Append(assignment.Member.Name); - builder.Append("= "); - ToString(assignment.Expression); - return; - } - - private void ToStringMemberMemberBinding(MemberMemberBinding binding) - { - ToStringBindingList(binding.Bindings); - return; - } - - private void ToStringMemberListBinding(MemberListBinding binding) - { - ToStringElementInitializerList(binding.Initializers); - return; - } - - private void ToStringBindingList(IEnumerable original) - { - bool appendComma = false; - foreach (var exp in original) - { - if (appendComma) - { - builder.Append(", "); - } - ToStringBinding(exp); - appendComma = true; - } - return; - } - - private void ToStringElementInitializerList(ReadOnlyCollection original) - { - for (int i = 0, n = original.Count; i < n; i++) - { - ToStringElementInitializer(original[i]); - } - return; - } - - private void ToStringLambda(LambdaExpression lambda) - { - if (lambda.Parameters.Count == 1) - { - ToStringParameter(lambda.Parameters[0]); - } - else - { - builder.Append("("); - AsCommaSeparatedValues(lambda.Parameters, ToStringParameter); - builder.Append(")"); - } - builder.Append(" => "); - ToString(lambda.Body); - return; - } - - private void ToStringNew(NewExpression nex) - { - Type type = (nex.Constructor == null) ? nex.Type : nex.Constructor.DeclaringType; - builder.Append("new "); - builder.Append(type.DisplayName(this.getTypeName)); - builder.Append("("); - AsCommaSeparatedValues(nex.Arguments, ToString); - builder.Append(")"); - return; - } - - private void ToStringMemberInit(MemberInitExpression init) - { - ToStringNew(init.NewExpression); - builder.Append(" { "); - ToStringBindingList(init.Bindings); - builder.Append(" }"); - return; - } - - private void ToStringListInit(ListInitExpression init) - { - ToStringNew(init.NewExpression); - builder.Append(" { "); - bool appendComma = false; - foreach (var initializer in init.Initializers) - { - if (appendComma) - { - builder.Append(", "); - } - ToStringElementInitializer(initializer); - appendComma = true; - } - builder.Append(" }"); - return; - } - - private void ToStringNewArray(NewArrayExpression na) - { - switch (na.NodeType) - { - case ExpressionType.NewArrayInit: - builder.Append("new[] { "); - AsCommaSeparatedValues(na.Expressions, ToString); - builder.Append(" }"); - return; - case ExpressionType.NewArrayBounds: - builder.Append("new "); - builder.Append(na.Type.GetElementType().DisplayName(this.getTypeName)); - builder.Append("["); - AsCommaSeparatedValues(na.Expressions, ToString); - builder.Append("]"); - return; - } - } - - private void AsCommaSeparatedValues(IEnumerable source, Action toStringAction) where T : Expression - { - bool appendComma = false; - foreach (var exp in source) - { - if (appendComma) - { - builder.Append(", "); - } - toStringAction(exp); - appendComma = true; - } - } - - private void ToStringInvocation(InvocationExpression iv) - { - ToStringExpressionList(iv.Arguments); - return; - } - - internal static string ToStringOperator(ExpressionType nodeType) - { - switch (nodeType) - { - case ExpressionType.Add: - case ExpressionType.AddChecked: - return "+"; - - case ExpressionType.And: - return "&"; - - case ExpressionType.AndAlso: - return "&&"; - - case ExpressionType.Coalesce: - return "??"; - - case ExpressionType.Divide: - return "/"; - - case ExpressionType.Equal: - return "=="; - - case ExpressionType.ExclusiveOr: - return "^"; - - case ExpressionType.GreaterThan: - return ">"; - - case ExpressionType.GreaterThanOrEqual: - return ">="; - - case ExpressionType.LeftShift: - return "<<"; - - case ExpressionType.LessThan: - return "<"; - - case ExpressionType.LessThanOrEqual: - return "<="; - - case ExpressionType.Modulo: - return "%"; - - case ExpressionType.Multiply: - case ExpressionType.MultiplyChecked: - return "*"; - - case ExpressionType.NotEqual: - return "!="; - - case ExpressionType.Or: - return "|"; - - case ExpressionType.OrElse: - return "||"; - - case ExpressionType.Power: - return "^"; - - case ExpressionType.RightShift: - return ">>"; - - case ExpressionType.Subtract: - case ExpressionType.SubtractChecked: - return "-"; - } - return nodeType.ToString(); - } - } - - internal static class StringExtensions - { - public static string[] Lines(this string source) - { - return source.Split(new[] { Environment.NewLine }, StringSplitOptions.None); - } - - public static string AsCommaSeparatedValues(this IEnumerable source) - { - if (source == null) - { - return string.Empty; - } - var result = new StringBuilder(100); - bool appendComma = false; - foreach (var value in source) - { - if (appendComma) - { - result.Append(", "); - } - result.Append(value); - appendComma = true; - } - return result.ToString(); - } - } - - internal static class TypeExtensions - { - public static string DisplayName(this Type source, Func getName) - { - if (source == null) - { - throw new ArgumentNullException("source"); - } - var builder = new StringBuilder(100); - builder.Append(getName(source).Split('`').First()); - if (source.IsGenericType) - { - builder.Append("<"); - builder.Append(source.GetGenericArguments().Select(t => getName(t)).AsCommaSeparatedValues()); - builder.Append(">"); - } - return builder.ToString(); - } - } - - // internal class ExpressionStringBuilder : ExpressionVisitor - // { - // private StringBuilder output = new StringBuilder(); - // private Func getMethodName; - - // private ExpressionStringBuilder(Func getMethodName) - // { - // this.getMethodName = getMethodName; - // } - - // internal static string GetString(Expression expression) - // { - // return GetString(expression, method => method.GetName()); - // } - - // internal static string GetString(Expression expression, Func getMethodName) - // { - // var builder = new ExpressionStringBuilder(getMethodName); - // builder.Visit(expression); - // return builder.output.ToString(); - // } - - // protected override Expression VisitBinary(BinaryExpression node) - // { - // if (node != null) - // { - // if (node.NodeType == ExpressionType.ArrayIndex) - // { - // this.Visit(node.Left); - // this.output.Append("["); - // this.Visit(node.Right); - // this.output.Append("]"); - // } - // else - // { - // var @operator = GetStringOperator(node.NodeType); - // if (IsParentEnclosed(node.Left)) - // { - // this.output.Append("("); - // this.Visit(node.Left); - // this.output.Append(")"); - // } - // else - // { - // this.Visit(node.Left); - // } - - // output.Append(" ").Append(@operator).Append(" "); - // if (IsParentEnclosed(node.Right)) - // { - // this.output.Append("("); - // this.Visit(node.Right); - // this.output.Append(")"); - // } - // else - // { - // this.Visit(node.Right); - // } - // } - // } - - // return node; - // } - - // protected override Expression VisitConditional(ConditionalExpression node) - // { - // if (node != null) - // { - // this.Visit(node.Test); - // this.Visit(node.IfTrue); - // this.Visit(node.IfFalse); - // } - - // return node; - // } - - // protected override Expression VisitConstant(ConstantExpression node) - // { - // if (node != null) - // { - // var value = node.Value; - // if (value != null) - // { - // if (value is string) - // { - // this.output.Append('"').Append(value).Append('"'); - // } - // else if (node.Type.IsEnum) - // { - // this.output.Append(node.Type.Name).Append(".").Append(value); - // } - // else if (value.ToString() != value.GetType().ToString()) - // { - // this.output.Append(value); - // } - // } - // else - // { - // this.output.Append("null"); - // } - // } - - // return node; - // } - - // protected override ElementInit VisitElementInit(ElementInit node) - // { - // if (node != null) - // { - // this.Visit(node.Arguments); - // } - - // return node; - // } - - // protected override Expression VisitInvocation(InvocationExpression node) - // { - // if (node != null) - // { - // this.Visit(node.Arguments); - // } - - // return node; - // } - - //#if NET3x - // protected override Expression VisitLambda(LambdaExpression node) - //#else - // protected override Expression VisitLambda(Expression node) - //#endif - // { - // if (node != null) - // { - // if (node.Parameters.Count == 1) - // { - // this.VisitParameter(node.Parameters[0]); - // } - // else - // { - // this.output.Append("("); - // this.Visit(node.Parameters, n => this.VisitParameter(n), 0, node.Parameters.Count); - // this.output.Append(")"); - // } - - // output.Append(" => "); - // this.Visit(node.Body); - // } - - // return node; - // } - - // protected override Expression VisitListInit(ListInitExpression node) - // { - // if (node != null) - // { - // this.VisitNew(node.NewExpression); - // Visit(node.Initializers, n => this.VisitElementInit(n)); - // } - - // return node; - // } - - // protected override Expression VisitMember(MemberExpression node) - // { - // if (node != null) - // { - // if (node.Expression != null) - // { - // this.Visit(node.Expression); - // } - // else - // { - // this.output.Append(node.Member.DeclaringType.Name); - // } - - // this.output.Append(".").Append(node.Member.Name); - // } - - // return node; - // } - - // protected override Expression VisitMemberInit(MemberInitExpression node) - // { - // if (node != null) - // { - // this.VisitNew(node.NewExpression); - // Visit(node.Bindings, n => this.VisitMemberBinding(n)); - // } - - // return node; - // } - - // protected override MemberListBinding VisitMemberListBinding(MemberListBinding node) - // { - // if (node != null) - // { - // Visit(node.Initializers, n => this.VisitElementInit(n)); - // } - - // return node; - // } - - // protected override MemberAssignment VisitMemberAssignment(MemberAssignment node) - // { - // if (node != null) - // { - // this.Visit(node.Expression); - // } - - // return node; - // } - - // protected override MemberBinding VisitMemberBinding(MemberBinding node) - // { - // if (node != null) - // { - // switch (node.BindingType) - // { - // case MemberBindingType.Assignment: - // this.VisitMemberAssignment((MemberAssignment)node); - // break; - - // case MemberBindingType.MemberBinding: - // this.VisitMemberMemberBinding((MemberMemberBinding)node); - // break; - - // case MemberBindingType.ListBinding: - // this.VisitMemberListBinding((MemberListBinding)node); - // break; - - // default: - // throw new InvalidOperationException(string.Format( - // CultureInfo.CurrentCulture, - // "Unhandled binding type '{0}'", - // node.BindingType)); - // } - // } - - // return node; - // } - - // protected override MemberMemberBinding VisitMemberMemberBinding(MemberMemberBinding node) - // { - // if (node != null) - // { - // Visit(node.Bindings, n => this.VisitMemberBinding(n)); - // } - - // return node; - // } - - // protected override Expression VisitMethodCall(MethodCallExpression node) - // { - // if (node != null) - // { - // var paramFrom = 0; - // var expression = node.Object; - - // if (Attribute.GetCustomAttribute(node.Method, typeof(ExtensionAttribute)) != null) - // { - // paramFrom = 1; - // expression = node.Arguments[0]; - // } - - // if (expression != null) - // { - // this.Visit(expression); - // } - // else // Method is static - // { - // this.output.Append(node.Method.DeclaringType.Name); - // } - - // if (node.Method.IsPropertyIndexerGetter()) - // { - // this.output.Append("["); - // this.Visit(node.Arguments, n => this.Visit(n), paramFrom, node.Arguments.Count); - // this.output.Append("]"); - // } - // else if (node.Method.IsPropertyIndexerSetter()) - // { - // this.output.Append("["); - // this.Visit(node.Arguments, n => this.Visit(n), paramFrom, node.Arguments.Count - 1); - // this.output.Append("] = "); - // this.Visit(node.Arguments.Last()); - // } - // else if (node.Method.IsPropertyGetter()) - // { - // this.output.Append(".").Append(node.Method.Name.Substring(4)); - // } - // else if (node.Method.IsPropertySetter()) - // { - // this.output.Append(".").Append(node.Method.Name.Substring(4)).Append(" = "); - // this.Visit(node.Arguments.Last()); - // } - // else if (node.Method.IsGenericMethod) - // { - // this.output - // .Append(".") - // .Append(this.getMethodName(node.Method)) - // .Append("<") - // .Append(string.Join(",", node.Method.GetGenericArguments().Select(s => s.Name))) - // .Append(">("); - // this.Visit(node.Arguments, n => this.Visit(n), paramFrom, node.Arguments.Count); - // output.Append(")"); - // } - // else - // { - // this.output.Append(".").Append(this.getMethodName(node.Method)).Append("("); - // this.Visit(node.Arguments, n => this.Visit(n), paramFrom, node.Arguments.Count); - // output.Append(")"); - // } - // } - - // return node; - // } - - // protected override Expression VisitNew(NewExpression node) - // { - // if (node != null) - // { - // this.Visit(node.Arguments); - // } - - // return node; - // } - - // protected override Expression VisitNewArray(NewArrayExpression node) - // { - // if (node != null) - // { - // this.output.Append("new[] { "); - // this.Visit(node.Expressions); - // this.output.Append(" }"); - // } - - // return node; - // } - - // protected override Expression VisitParameter(ParameterExpression node) - // { - // if (node != null) - // { - // this.output.Append(node.Name != null ? node.Name : ""); - // } - - // return node; - // } - - // protected override Expression VisitTypeBinary(TypeBinaryExpression node) - // { - // return node != null ? this.Visit(node.Expression) : node; - // } - - // protected override Expression VisitUnary(UnaryExpression node) - // { - // if (node != null) - // { - // switch (node.NodeType) - // { - // case ExpressionType.Negate: - // case ExpressionType.NegateChecked: - // this.output.Append("-"); - // this.Visit(node.Operand); - // break; - - // case ExpressionType.Not: - // this.output.Append("!("); - // this.Visit(node.Operand); - // this.output.Append(")"); - // break; - - // case ExpressionType.Quote: - // this.Visit(node.Operand); - // break; - - // case ExpressionType.TypeAs: - // this.output.Append("("); - // this.Visit(node.Operand); - // this.output.Append(" as ").Append(node.Type.Name).Append(")"); - // break; - // } - // } - - // return node; - // } - - // private static string GetStringOperator(ExpressionType nodeType) - // { - // switch (nodeType) - // { - // case ExpressionType.Add: - // case ExpressionType.AddChecked: - // return "+"; - - // case ExpressionType.And: - // return "&"; - - // case ExpressionType.AndAlso: - // return "&&"; - - // case ExpressionType.Coalesce: - // return "??"; - - // case ExpressionType.Divide: - // return "/"; - - // case ExpressionType.Equal: - // return "=="; - - // case ExpressionType.ExclusiveOr: - // return "^"; - - // case ExpressionType.GreaterThan: - // return ">"; - - // case ExpressionType.GreaterThanOrEqual: - // return ">="; - - // case ExpressionType.LeftShift: - // return "<<"; - - // case ExpressionType.LessThan: - // return "<"; - - // case ExpressionType.LessThanOrEqual: - // return "<="; - - // case ExpressionType.Modulo: - // return "%"; - - // case ExpressionType.Multiply: - // case ExpressionType.MultiplyChecked: - // return "*"; - - // case ExpressionType.NotEqual: - // return "!="; - - // case ExpressionType.Or: - // return "|"; - - // case ExpressionType.OrElse: - // return "||"; - - // case ExpressionType.Power: - // return "^"; - - // case ExpressionType.RightShift: - // return ">>"; - - // case ExpressionType.Subtract: - // case ExpressionType.SubtractChecked: - // return "-"; - // } - - // return nodeType.ToString(); - // } - - // private static bool IsParentEnclosed(Expression node) - // { - // return node.NodeType == ExpressionType.AndAlso || node.NodeType == ExpressionType.OrElse; - // } - - // private void Visit(IList arguments, Func elementVisitor, int paramFrom, int paramTo) - // { - // var appendComma = false; - // for (var index = paramFrom; index < paramTo; index++) - // { - // if (appendComma) - // { - // this.output.Append(", "); - // } - - // elementVisitor(arguments[index]); - // appendComma = true; - // } - // } - // } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Text; +using System.Collections.ObjectModel; + +namespace Moq +{ + /// + /// The intention of is to create a more readable + /// string representation for the failure message. + /// + internal class ExpressionStringBuilder + { + private readonly Expression expression; + private StringBuilder builder; + private Func getTypeName; + + internal static string GetString(Expression expression) + { + return GetString(expression, type => type.Name); + } + + internal static string GetString(Expression expression, Func getTypeName) + { + var builder = new ExpressionStringBuilder(getTypeName, expression); + return builder.ToString(); + } + + public ExpressionStringBuilder(Func getTypeName, Expression expression) + { + this.getTypeName = getTypeName; + this.expression = expression; + } + + public override string ToString() + { + builder = new StringBuilder(); + ToString(expression); + return builder.ToString(); + } + + public void ToString(Expression exp) + { + if (exp == null) + { + builder.Append("null"); + return; + } + switch (exp.NodeType) + { + case ExpressionType.Negate: + case ExpressionType.NegateChecked: + case ExpressionType.Not: + case ExpressionType.Convert: + case ExpressionType.ConvertChecked: + case ExpressionType.ArrayLength: + case ExpressionType.Quote: + case ExpressionType.TypeAs: + ToStringUnary((UnaryExpression)exp); + return; + case ExpressionType.Add: + case ExpressionType.AddChecked: + case ExpressionType.Subtract: + case ExpressionType.SubtractChecked: + case ExpressionType.Multiply: + case ExpressionType.MultiplyChecked: + case ExpressionType.Divide: + case ExpressionType.Modulo: + case ExpressionType.And: + case ExpressionType.AndAlso: + case ExpressionType.Or: + case ExpressionType.OrElse: + case ExpressionType.LessThan: + case ExpressionType.LessThanOrEqual: + case ExpressionType.GreaterThan: + case ExpressionType.GreaterThanOrEqual: + case ExpressionType.Equal: + case ExpressionType.NotEqual: + case ExpressionType.Coalesce: + case ExpressionType.ArrayIndex: + case ExpressionType.RightShift: + case ExpressionType.LeftShift: + case ExpressionType.ExclusiveOr: + ToStringBinary((BinaryExpression)exp); + return; + case ExpressionType.TypeIs: + ToStringTypeIs((TypeBinaryExpression)exp); + return; + case ExpressionType.Conditional: + ToStringConditional((ConditionalExpression)exp); + return; + case ExpressionType.Constant: + ToStringConstant((ConstantExpression)exp); + return; + case ExpressionType.Parameter: + ToStringParameter((ParameterExpression)exp); + return; + case ExpressionType.MemberAccess: + ToStringMemberAccess((MemberExpression)exp); + return; + case ExpressionType.Call: + ToStringMethodCall((MethodCallExpression)exp); + return; + case ExpressionType.Lambda: + ToStringLambda((LambdaExpression)exp); + return; + case ExpressionType.New: + ToStringNew((NewExpression)exp); + return; + case ExpressionType.NewArrayInit: + case ExpressionType.NewArrayBounds: + ToStringNewArray((NewArrayExpression)exp); + return; + case ExpressionType.Invoke: + ToStringInvocation((InvocationExpression)exp); + return; + case ExpressionType.MemberInit: + ToStringMemberInit((MemberInitExpression)exp); + return; + case ExpressionType.ListInit: + ToStringListInit((ListInitExpression)exp); + return; + default: + throw new Exception(string.Format("Unhandled expression type: '{0}'", exp.NodeType)); + } + } + + private void ToStringBinding(MemberBinding binding) + { + switch (binding.BindingType) + { + case MemberBindingType.Assignment: + ToStringMemberAssignment((MemberAssignment)binding); + return; + case MemberBindingType.MemberBinding: + ToStringMemberMemberBinding((MemberMemberBinding)binding); + return; + case MemberBindingType.ListBinding: + ToStringMemberListBinding((MemberListBinding)binding); + return; + default: + throw new Exception(string.Format("Unhandled binding type '{0}'", binding.BindingType)); + } + } + + private void ToStringElementInitializer(ElementInit initializer) + { + builder.Append("{ "); + ToStringExpressionList(initializer.Arguments); + builder.Append(" }"); + return; + } + + private void ToStringUnary(UnaryExpression u) + { + switch (u.NodeType) + { + case ExpressionType.Convert: + case ExpressionType.ConvertChecked: + builder.Append("(").Append(this.getTypeName(u.Type)).Append(")"); + ToString(u.Operand); + //builder.Append(")"); + return; + + case ExpressionType.ArrayLength: + ToString(u.Operand); + builder.Append(".Length"); + return; + + case ExpressionType.Negate: + case ExpressionType.NegateChecked: + builder.Append("-"); + ToString(u.Operand); + return; + + case ExpressionType.Not: + builder.Append("!("); + ToString(u.Operand); + builder.Append(")"); + return; + + case ExpressionType.Quote: + ToString(u.Operand); + return; + + case ExpressionType.TypeAs: + builder.Append("("); + ToString(u.Operand); + builder.Append(" as "); + builder.Append(u.Type.DisplayName(this.getTypeName)); + builder.Append(")"); + return; + } + return; + } + + private void ToStringBinary(BinaryExpression b) + { + if (b.NodeType == ExpressionType.ArrayIndex) + { + ToString(b.Left); + builder.Append("["); + ToString(b.Right); + builder.Append("]"); + } + else + { + string @operator = ToStringOperator(b.NodeType); + if (NeedEncloseInParen(b.Left)) + { + builder.Append("("); + ToString(b.Left); + builder.Append(")"); + } + else + { + ToString(b.Left); + } + builder.Append(" "); + builder.Append(@operator); + builder.Append(" "); + if (NeedEncloseInParen(b.Right)) + { + builder.Append("("); + ToString(b.Right); + builder.Append(")"); + } + else + { + ToString(b.Right); + } + } + } + + private static bool NeedEncloseInParen(Expression operand) + { + return operand.NodeType == ExpressionType.AndAlso || operand.NodeType == ExpressionType.OrElse; + } + + private void ToStringTypeIs(TypeBinaryExpression b) + { + ToString(b.Expression); + return; + } + + private void ToStringConstant(ConstantExpression c) + { + var value = c.Value; + if (value != null) + { + if (value is string) + { + builder.Append("\"").Append(value).Append("\""); + } + else if (value.ToString() == value.GetType().ToString()) + { + // Perhaps is better without nothing (at least for local variables) + //builder.Append(""); + } + else if (c.Type.IsEnum) + { + builder.Append(c.Type.DisplayName(this.getTypeName)).Append(".").Append(value); + } + else + { + builder.Append(value); + } + } + else + { + builder.Append("null"); + } + } + + private void ToStringConditional(ConditionalExpression c) + { + ToString(c.Test); + ToString(c.IfTrue); + ToString(c.IfFalse); + return; + } + + private void ToStringParameter(ParameterExpression p) + { + if (p.Name != null) + { + builder.Append(p.Name); + } + else + { + builder.Append(""); + } + } + + private void ToStringMemberAccess(MemberExpression m) + { + if (m.Expression != null) + { + ToString(m.Expression); + } + else + { + builder.Append(m.Member.DeclaringType.DisplayName(this.getTypeName)); + } + builder.Append("."); + builder.Append(m.Member.Name); + return; + } + + private void ToStringMethodCall(MethodCallExpression node) + { + if (node != null) + { + var paramFrom = 0; + var expression = node.Object; + + if (Attribute.GetCustomAttribute(node.Method, typeof(ExtensionAttribute)) != null) + { + paramFrom = 1; + expression = node.Arguments[0]; + } + + if (expression != null) + { + ToString(expression); + } + else // Method is static + { + this.builder.Append(this.getTypeName(node.Method.DeclaringType)); + } + + if (node.Method.IsPropertyIndexerGetter()) + { + this.builder.Append("["); + AsCommaSeparatedValues(node.Arguments.Skip(paramFrom), ToString); + this.builder.Append("]"); + } + else if (node.Method.IsPropertyIndexerSetter()) + { + this.builder.Append("["); + AsCommaSeparatedValues(node.Arguments + .Skip(paramFrom) + .Take(node.Arguments.Count - paramFrom), ToString); + this.builder.Append("] = "); + ToString(node.Arguments.Last()); + } + else if (node.Method.IsPropertyGetter()) + { + this.builder.Append(".").Append(node.Method.Name.Substring(4)); + } + else if (node.Method.IsPropertySetter()) + { + this.builder.Append(".").Append(node.Method.Name.Substring(4)).Append(" = "); + ToString(node.Arguments.Last()); + } + else if (node.Method.IsGenericMethod) + { + this.builder + .Append(".") + .Append(node.Method.Name) + .Append("<") + .Append(string.Join(",", node.Method.GetGenericArguments().Select(s => this.getTypeName(s)).ToArray())) + .Append(">("); + AsCommaSeparatedValues(node.Arguments.Skip(paramFrom), ToString); + this.builder.Append(")"); + } + else + { + this.builder + .Append(".") + .Append(node.Method.Name) + .Append("("); + AsCommaSeparatedValues(node.Arguments.Skip(paramFrom), ToString); + this.builder.Append(")"); + } + } + } + + private void ToStringExpressionList(ReadOnlyCollection original) + { + AsCommaSeparatedValues(original, ToString); + return; + } + + private void ToStringMemberAssignment(MemberAssignment assignment) + { + builder.Append(assignment.Member.Name); + builder.Append("= "); + ToString(assignment.Expression); + return; + } + + private void ToStringMemberMemberBinding(MemberMemberBinding binding) + { + ToStringBindingList(binding.Bindings); + return; + } + + private void ToStringMemberListBinding(MemberListBinding binding) + { + ToStringElementInitializerList(binding.Initializers); + return; + } + + private void ToStringBindingList(IEnumerable original) + { + bool appendComma = false; + foreach (var exp in original) + { + if (appendComma) + { + builder.Append(", "); + } + ToStringBinding(exp); + appendComma = true; + } + return; + } + + private void ToStringElementInitializerList(ReadOnlyCollection original) + { + for (int i = 0, n = original.Count; i < n; i++) + { + ToStringElementInitializer(original[i]); + } + return; + } + + private void ToStringLambda(LambdaExpression lambda) + { + if (lambda.Parameters.Count == 1) + { + ToStringParameter(lambda.Parameters[0]); + } + else + { + builder.Append("("); + AsCommaSeparatedValues(lambda.Parameters, ToStringParameter); + builder.Append(")"); + } + builder.Append(" => "); + ToString(lambda.Body); + return; + } + + private void ToStringNew(NewExpression nex) + { + Type type = (nex.Constructor == null) ? nex.Type : nex.Constructor.DeclaringType; + builder.Append("new "); + builder.Append(type.DisplayName(this.getTypeName)); + builder.Append("("); + AsCommaSeparatedValues(nex.Arguments, ToString); + builder.Append(")"); + return; + } + + private void ToStringMemberInit(MemberInitExpression init) + { + ToStringNew(init.NewExpression); + builder.Append(" { "); + ToStringBindingList(init.Bindings); + builder.Append(" }"); + return; + } + + private void ToStringListInit(ListInitExpression init) + { + ToStringNew(init.NewExpression); + builder.Append(" { "); + bool appendComma = false; + foreach (var initializer in init.Initializers) + { + if (appendComma) + { + builder.Append(", "); + } + ToStringElementInitializer(initializer); + appendComma = true; + } + builder.Append(" }"); + return; + } + + private void ToStringNewArray(NewArrayExpression na) + { + switch (na.NodeType) + { + case ExpressionType.NewArrayInit: + builder.Append("new[] { "); + AsCommaSeparatedValues(na.Expressions, ToString); + builder.Append(" }"); + return; + case ExpressionType.NewArrayBounds: + builder.Append("new "); + builder.Append(na.Type.GetElementType().DisplayName(this.getTypeName)); + builder.Append("["); + AsCommaSeparatedValues(na.Expressions, ToString); + builder.Append("]"); + return; + } + } + + private void AsCommaSeparatedValues(IEnumerable source, Action toStringAction) where T : Expression + { + bool appendComma = false; + foreach (var exp in source) + { + if (appendComma) + { + builder.Append(", "); + } + toStringAction(exp); + appendComma = true; + } + } + + private void ToStringInvocation(InvocationExpression iv) + { + ToStringExpressionList(iv.Arguments); + return; + } + + internal static string ToStringOperator(ExpressionType nodeType) + { + switch (nodeType) + { + case ExpressionType.Add: + case ExpressionType.AddChecked: + return "+"; + + case ExpressionType.And: + return "&"; + + case ExpressionType.AndAlso: + return "&&"; + + case ExpressionType.Coalesce: + return "??"; + + case ExpressionType.Divide: + return "/"; + + case ExpressionType.Equal: + return "=="; + + case ExpressionType.ExclusiveOr: + return "^"; + + case ExpressionType.GreaterThan: + return ">"; + + case ExpressionType.GreaterThanOrEqual: + return ">="; + + case ExpressionType.LeftShift: + return "<<"; + + case ExpressionType.LessThan: + return "<"; + + case ExpressionType.LessThanOrEqual: + return "<="; + + case ExpressionType.Modulo: + return "%"; + + case ExpressionType.Multiply: + case ExpressionType.MultiplyChecked: + return "*"; + + case ExpressionType.NotEqual: + return "!="; + + case ExpressionType.Or: + return "|"; + + case ExpressionType.OrElse: + return "||"; + + case ExpressionType.Power: + return "^"; + + case ExpressionType.RightShift: + return ">>"; + + case ExpressionType.Subtract: + case ExpressionType.SubtractChecked: + return "-"; + } + return nodeType.ToString(); + } + } + + internal static class StringExtensions + { + public static string[] Lines(this string source) + { + return source.Split(new[] { Environment.NewLine }, StringSplitOptions.None); + } + + public static string AsCommaSeparatedValues(this IEnumerable source) + { + if (source == null) + { + return string.Empty; + } + var result = new StringBuilder(100); + bool appendComma = false; + foreach (var value in source) + { + if (appendComma) + { + result.Append(", "); + } + result.Append(value); + appendComma = true; + } + return result.ToString(); + } + } + + internal static class TypeExtensions + { + public static string DisplayName(this Type source, Func getName) + { + if (source == null) + { + throw new ArgumentNullException("source"); + } + var builder = new StringBuilder(100); + builder.Append(getName(source).Split('`').First()); + if (source.IsGenericType) + { + builder.Append("<"); + builder.Append(source.GetGenericArguments().Select(t => getName(t)).AsCommaSeparatedValues()); + builder.Append(">"); + } + return builder.ToString(); + } + } + + // internal class ExpressionStringBuilder : ExpressionVisitor + // { + // private StringBuilder output = new StringBuilder(); + // private Func getMethodName; + + // private ExpressionStringBuilder(Func getMethodName) + // { + // this.getMethodName = getMethodName; + // } + + // internal static string GetString(Expression expression) + // { + // return GetString(expression, method => method.GetName()); + // } + + // internal static string GetString(Expression expression, Func getMethodName) + // { + // var builder = new ExpressionStringBuilder(getMethodName); + // builder.Visit(expression); + // return builder.output.ToString(); + // } + + // protected override Expression VisitBinary(BinaryExpression node) + // { + // if (node != null) + // { + // if (node.NodeType == ExpressionType.ArrayIndex) + // { + // this.Visit(node.Left); + // this.output.Append("["); + // this.Visit(node.Right); + // this.output.Append("]"); + // } + // else + // { + // var @operator = GetStringOperator(node.NodeType); + // if (IsParentEnclosed(node.Left)) + // { + // this.output.Append("("); + // this.Visit(node.Left); + // this.output.Append(")"); + // } + // else + // { + // this.Visit(node.Left); + // } + + // output.Append(" ").Append(@operator).Append(" "); + // if (IsParentEnclosed(node.Right)) + // { + // this.output.Append("("); + // this.Visit(node.Right); + // this.output.Append(")"); + // } + // else + // { + // this.Visit(node.Right); + // } + // } + // } + + // return node; + // } + + // protected override Expression VisitConditional(ConditionalExpression node) + // { + // if (node != null) + // { + // this.Visit(node.Test); + // this.Visit(node.IfTrue); + // this.Visit(node.IfFalse); + // } + + // return node; + // } + + // protected override Expression VisitConstant(ConstantExpression node) + // { + // if (node != null) + // { + // var value = node.Value; + // if (value != null) + // { + // if (value is string) + // { + // this.output.Append('"').Append(value).Append('"'); + // } + // else if (node.Type.IsEnum) + // { + // this.output.Append(node.Type.Name).Append(".").Append(value); + // } + // else if (value.ToString() != value.GetType().ToString()) + // { + // this.output.Append(value); + // } + // } + // else + // { + // this.output.Append("null"); + // } + // } + + // return node; + // } + + // protected override ElementInit VisitElementInit(ElementInit node) + // { + // if (node != null) + // { + // this.Visit(node.Arguments); + // } + + // return node; + // } + + // protected override Expression VisitInvocation(InvocationExpression node) + // { + // if (node != null) + // { + // this.Visit(node.Arguments); + // } + + // return node; + // } + + //#if NET3x + // protected override Expression VisitLambda(LambdaExpression node) + //#else + // protected override Expression VisitLambda(Expression node) + //#endif + // { + // if (node != null) + // { + // if (node.Parameters.Count == 1) + // { + // this.VisitParameter(node.Parameters[0]); + // } + // else + // { + // this.output.Append("("); + // this.Visit(node.Parameters, n => this.VisitParameter(n), 0, node.Parameters.Count); + // this.output.Append(")"); + // } + + // output.Append(" => "); + // this.Visit(node.Body); + // } + + // return node; + // } + + // protected override Expression VisitListInit(ListInitExpression node) + // { + // if (node != null) + // { + // this.VisitNew(node.NewExpression); + // Visit(node.Initializers, n => this.VisitElementInit(n)); + // } + + // return node; + // } + + // protected override Expression VisitMember(MemberExpression node) + // { + // if (node != null) + // { + // if (node.Expression != null) + // { + // this.Visit(node.Expression); + // } + // else + // { + // this.output.Append(node.Member.DeclaringType.Name); + // } + + // this.output.Append(".").Append(node.Member.Name); + // } + + // return node; + // } + + // protected override Expression VisitMemberInit(MemberInitExpression node) + // { + // if (node != null) + // { + // this.VisitNew(node.NewExpression); + // Visit(node.Bindings, n => this.VisitMemberBinding(n)); + // } + + // return node; + // } + + // protected override MemberListBinding VisitMemberListBinding(MemberListBinding node) + // { + // if (node != null) + // { + // Visit(node.Initializers, n => this.VisitElementInit(n)); + // } + + // return node; + // } + + // protected override MemberAssignment VisitMemberAssignment(MemberAssignment node) + // { + // if (node != null) + // { + // this.Visit(node.Expression); + // } + + // return node; + // } + + // protected override MemberBinding VisitMemberBinding(MemberBinding node) + // { + // if (node != null) + // { + // switch (node.BindingType) + // { + // case MemberBindingType.Assignment: + // this.VisitMemberAssignment((MemberAssignment)node); + // break; + + // case MemberBindingType.MemberBinding: + // this.VisitMemberMemberBinding((MemberMemberBinding)node); + // break; + + // case MemberBindingType.ListBinding: + // this.VisitMemberListBinding((MemberListBinding)node); + // break; + + // default: + // throw new InvalidOperationException(string.Format( + // CultureInfo.CurrentCulture, + // "Unhandled binding type '{0}'", + // node.BindingType)); + // } + // } + + // return node; + // } + + // protected override MemberMemberBinding VisitMemberMemberBinding(MemberMemberBinding node) + // { + // if (node != null) + // { + // Visit(node.Bindings, n => this.VisitMemberBinding(n)); + // } + + // return node; + // } + + // protected override Expression VisitMethodCall(MethodCallExpression node) + // { + // if (node != null) + // { + // var paramFrom = 0; + // var expression = node.Object; + + // if (Attribute.GetCustomAttribute(node.Method, typeof(ExtensionAttribute)) != null) + // { + // paramFrom = 1; + // expression = node.Arguments[0]; + // } + + // if (expression != null) + // { + // this.Visit(expression); + // } + // else // Method is static + // { + // this.output.Append(node.Method.DeclaringType.Name); + // } + + // if (node.Method.IsPropertyIndexerGetter()) + // { + // this.output.Append("["); + // this.Visit(node.Arguments, n => this.Visit(n), paramFrom, node.Arguments.Count); + // this.output.Append("]"); + // } + // else if (node.Method.IsPropertyIndexerSetter()) + // { + // this.output.Append("["); + // this.Visit(node.Arguments, n => this.Visit(n), paramFrom, node.Arguments.Count - 1); + // this.output.Append("] = "); + // this.Visit(node.Arguments.Last()); + // } + // else if (node.Method.IsPropertyGetter()) + // { + // this.output.Append(".").Append(node.Method.Name.Substring(4)); + // } + // else if (node.Method.IsPropertySetter()) + // { + // this.output.Append(".").Append(node.Method.Name.Substring(4)).Append(" = "); + // this.Visit(node.Arguments.Last()); + // } + // else if (node.Method.IsGenericMethod) + // { + // this.output + // .Append(".") + // .Append(this.getMethodName(node.Method)) + // .Append("<") + // .Append(string.Join(",", node.Method.GetGenericArguments().Select(s => s.Name))) + // .Append(">("); + // this.Visit(node.Arguments, n => this.Visit(n), paramFrom, node.Arguments.Count); + // output.Append(")"); + // } + // else + // { + // this.output.Append(".").Append(this.getMethodName(node.Method)).Append("("); + // this.Visit(node.Arguments, n => this.Visit(n), paramFrom, node.Arguments.Count); + // output.Append(")"); + // } + // } + + // return node; + // } + + // protected override Expression VisitNew(NewExpression node) + // { + // if (node != null) + // { + // this.Visit(node.Arguments); + // } + + // return node; + // } + + // protected override Expression VisitNewArray(NewArrayExpression node) + // { + // if (node != null) + // { + // this.output.Append("new[] { "); + // this.Visit(node.Expressions); + // this.output.Append(" }"); + // } + + // return node; + // } + + // protected override Expression VisitParameter(ParameterExpression node) + // { + // if (node != null) + // { + // this.output.Append(node.Name != null ? node.Name : ""); + // } + + // return node; + // } + + // protected override Expression VisitTypeBinary(TypeBinaryExpression node) + // { + // return node != null ? this.Visit(node.Expression) : node; + // } + + // protected override Expression VisitUnary(UnaryExpression node) + // { + // if (node != null) + // { + // switch (node.NodeType) + // { + // case ExpressionType.Negate: + // case ExpressionType.NegateChecked: + // this.output.Append("-"); + // this.Visit(node.Operand); + // break; + + // case ExpressionType.Not: + // this.output.Append("!("); + // this.Visit(node.Operand); + // this.output.Append(")"); + // break; + + // case ExpressionType.Quote: + // this.Visit(node.Operand); + // break; + + // case ExpressionType.TypeAs: + // this.output.Append("("); + // this.Visit(node.Operand); + // this.output.Append(" as ").Append(node.Type.Name).Append(")"); + // break; + // } + // } + + // return node; + // } + + // private static string GetStringOperator(ExpressionType nodeType) + // { + // switch (nodeType) + // { + // case ExpressionType.Add: + // case ExpressionType.AddChecked: + // return "+"; + + // case ExpressionType.And: + // return "&"; + + // case ExpressionType.AndAlso: + // return "&&"; + + // case ExpressionType.Coalesce: + // return "??"; + + // case ExpressionType.Divide: + // return "/"; + + // case ExpressionType.Equal: + // return "=="; + + // case ExpressionType.ExclusiveOr: + // return "^"; + + // case ExpressionType.GreaterThan: + // return ">"; + + // case ExpressionType.GreaterThanOrEqual: + // return ">="; + + // case ExpressionType.LeftShift: + // return "<<"; + + // case ExpressionType.LessThan: + // return "<"; + + // case ExpressionType.LessThanOrEqual: + // return "<="; + + // case ExpressionType.Modulo: + // return "%"; + + // case ExpressionType.Multiply: + // case ExpressionType.MultiplyChecked: + // return "*"; + + // case ExpressionType.NotEqual: + // return "!="; + + // case ExpressionType.Or: + // return "|"; + + // case ExpressionType.OrElse: + // return "||"; + + // case ExpressionType.Power: + // return "^"; + + // case ExpressionType.RightShift: + // return ">>"; + + // case ExpressionType.Subtract: + // case ExpressionType.SubtractChecked: + // return "-"; + // } + + // return nodeType.ToString(); + // } + + // private static bool IsParentEnclosed(Expression node) + // { + // return node.NodeType == ExpressionType.AndAlso || node.NodeType == ExpressionType.OrElse; + // } + + // private void Visit(IList arguments, Func elementVisitor, int paramFrom, int paramTo) + // { + // var appendComma = false; + // for (var index = paramFrom; index < paramTo; index++) + // { + // if (appendComma) + // { + // this.output.Append(", "); + // } + + // elementVisitor(arguments[index]); + // appendComma = true; + // } + // } + // } } \ No newline at end of file diff --git a/Source/FluentMockContext.cs b/Source/FluentMockContext.cs index 04a58b3f1..c58fad9f8 100644 --- a/Source/FluentMockContext.cs +++ b/Source/FluentMockContext.cs @@ -1,127 +1,127 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Collections.Generic; -using System.Linq; -using Moq.Proxy; - -namespace Moq -{ - /// - /// Tracks the current mock and interception context. - /// - internal class FluentMockContext : IDisposable - { - [ThreadStatic] - private static FluentMockContext current; - - private List invocations = new List(); - - public static FluentMockContext Current - { - get { return current; } - } - - /// - /// Having an active fluent mock context means that the invocation - /// is being performed in "trial" mode, just to gather the - /// target method and arguments that need to be matched later - /// when the actual invocation is made. - /// - public static bool IsActive - { - get { return current != null; } - } - - public FluentMockContext() - { - current = this; - } - - public void Add(Mock mock, ICallContext invocation) - { - invocations.Add(new MockInvocation(mock, invocation, LastMatch)); - } - - public MockInvocation LastInvocation - { - get { return invocations.LastOrDefault(); } - } - - public Match LastMatch { get; set; } - - public void Dispose() - { - foreach (var invocation in invocations) - { - invocation.Dispose(); - } - - current = null; - } - - internal class MockInvocation : IDisposable - { - private DefaultValue defaultValue; - - public MockInvocation(Mock mock, ICallContext invocation, Match matcher) - { - this.Mock = mock; - this.Invocation = invocation; - this.Match = matcher; - defaultValue = mock.DefaultValue; - // Temporarily set mock default value to Mock so that recursion works. - mock.DefaultValue = DefaultValue.Mock; - } - - public Mock Mock { get; private set; } - - public ICallContext Invocation { get; private set; } - - public Match Match { get; private set; } - - public void Dispose() - { - Mock.DefaultValue = defaultValue; - } - } - } -} +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Collections.Generic; +using System.Linq; +using Moq.Proxy; + +namespace Moq +{ + /// + /// Tracks the current mock and interception context. + /// + internal class FluentMockContext : IDisposable + { + [ThreadStatic] + private static FluentMockContext current; + + private List invocations = new List(); + + public static FluentMockContext Current + { + get { return current; } + } + + /// + /// Having an active fluent mock context means that the invocation + /// is being performed in "trial" mode, just to gather the + /// target method and arguments that need to be matched later + /// when the actual invocation is made. + /// + public static bool IsActive + { + get { return current != null; } + } + + public FluentMockContext() + { + current = this; + } + + public void Add(Mock mock, ICallContext invocation) + { + invocations.Add(new MockInvocation(mock, invocation, LastMatch)); + } + + public MockInvocation LastInvocation + { + get { return invocations.LastOrDefault(); } + } + + public Match LastMatch { get; set; } + + public void Dispose() + { + foreach (var invocation in invocations) + { + invocation.Dispose(); + } + + current = null; + } + + internal class MockInvocation : IDisposable + { + private DefaultValue defaultValue; + + public MockInvocation(Mock mock, ICallContext invocation, Match matcher) + { + this.Mock = mock; + this.Invocation = invocation; + this.Match = matcher; + defaultValue = mock.DefaultValue; + // Temporarily set mock default value to Mock so that recursion works. + mock.DefaultValue = DefaultValue.Mock; + } + + public Mock Mock { get; private set; } + + public ICallContext Invocation { get; private set; } + + public Match Match { get; private set; } + + public void Dispose() + { + Mock.DefaultValue = defaultValue; + } + } + } +} diff --git a/Source/GlobalSuppressions.cs b/Source/GlobalSuppressions.cs index f784cf9a4..d227fc948 100644 --- a/Source/GlobalSuppressions.cs +++ b/Source/GlobalSuppressions.cs @@ -1,21 +1,21 @@ -// This file is used by Code Analysis to maintain SuppressMessage -// attributes that are applied to this project. -// Project-level suppressions either have no target or are given -// a specific target and scoped to a namespace, type, member, etc. -// -// To add a suppression to this file, right-click the message in the -// Error List, point to "Suppress Message(s)", and click -// "In Project Suppression File". -// You do not need to add suppressions to this file manually. - -using System.Diagnostics.CodeAnalysis; - -[assembly: SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "Moq.Protected")] - -[assembly: SuppressMessage("Microsoft.Naming", "CA1703:ResourceStringsShouldBeSpelledCorrectly", MessageId = "Moq", Scope = "resource", Target = "Moq.Properties.Resources.resources")] -[assembly: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Moq")] -[assembly: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Moq", Scope = "namespace", Target = "Moq")] -[assembly: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Moq", Scope = "namespace", Target = "Moq.Language")] -[assembly: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Moq", Scope = "namespace", Target = "Moq.Language.Flow")] -[assembly: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Moq", Scope = "namespace", Target = "Moq.Protected")] +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. +// +// To add a suppression to this file, right-click the message in the +// Error List, point to "Suppress Message(s)", and click +// "In Project Suppression File". +// You do not need to add suppressions to this file manually. + +using System.Diagnostics.CodeAnalysis; + +[assembly: SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "Moq.Protected")] + +[assembly: SuppressMessage("Microsoft.Naming", "CA1703:ResourceStringsShouldBeSpelledCorrectly", MessageId = "Moq", Scope = "resource", Target = "Moq.Properties.Resources.resources")] +[assembly: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Moq")] +[assembly: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Moq", Scope = "namespace", Target = "Moq")] +[assembly: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Moq", Scope = "namespace", Target = "Moq.Language")] +[assembly: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Moq", Scope = "namespace", Target = "Moq.Language.Flow")] +[assembly: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Moq", Scope = "namespace", Target = "Moq.Protected")] [assembly: SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Protected", Scope = "namespace", Target = "Moq.Protected")] \ No newline at end of file diff --git a/Source/Guard.cs b/Source/Guard.cs index 5e204fbee..e04e31838 100644 --- a/Source/Guard.cs +++ b/Source/Guard.cs @@ -1,141 +1,141 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Diagnostics; -using System.Globalization; -using System.Linq.Expressions; -using Moq.Properties; - -namespace Moq -{ - [DebuggerStepThrough] - internal static class Guard - { - /// - /// Ensures the given is not null. - /// Throws otherwise. - /// - public static void NotNull(Expression> reference, T value) - { - if (value == null) - { - throw new ArgumentNullException(GetParameterName(reference)); - } - } - - /// - /// Ensures the given string is not null or empty. - /// Throws in the first case, or - /// in the latter. - /// - public static void NotNullOrEmpty(Expression> reference, string value) - { - NotNull(reference, value); - if (value.Length == 0) - { - throw new ArgumentException(Resources.ArgumentCannotBeEmpty, GetParameterName(reference)); - } - } - - /// - /// Checks an argument to ensure it is in the specified range including the edges. - /// - /// Type of the argument to check, it must be an type. - /// - /// The expression containing the name of the argument. - /// The argument value to check. - /// The minimun allowed value for the argument. - /// The maximun allowed value for the argument. - public static void NotOutOfRangeInclusive(Expression> reference, T value, T from, T to) - where T : IComparable - { - if (value != null && (value.CompareTo(from) < 0 || value.CompareTo(to) > 0)) - { - throw new ArgumentOutOfRangeException(GetParameterName(reference)); - } - } - - /// - /// Checks an argument to ensure it is in the specified range excluding the edges. - /// - /// Type of the argument to check, it must be an type. - /// - /// The expression containing the name of the argument. - /// The argument value to check. - /// The minimun allowed value for the argument. - /// The maximun allowed value for the argument. - public static void NotOutOfRangeExclusive(Expression> reference, T value, T from, T to) - where T : IComparable - { - if (value != null && (value.CompareTo(from) <= 0 || value.CompareTo(to) >= 0)) - { - throw new ArgumentOutOfRangeException(GetParameterName(reference)); - } - } - - public static void CanBeAssigned(Expression> reference, Type typeToAssign, Type targetType) - { - if (!targetType.IsAssignableFrom(typeToAssign)) - { - if (targetType.IsInterface) - { - throw new ArgumentException(string.Format( - CultureInfo.CurrentCulture, - Resources.TypeNotImplementInterface, - typeToAssign, - targetType), GetParameterName(reference)); - } - - throw new ArgumentException(string.Format( - CultureInfo.CurrentCulture, - Resources.TypeNotInheritFromType, - typeToAssign, - targetType), GetParameterName(reference)); - } - } - - private static string GetParameterName(LambdaExpression reference) - { - var member = (MemberExpression)reference.Body; - return member.Member.Name; - } - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Diagnostics; +using System.Globalization; +using System.Linq.Expressions; +using Moq.Properties; + +namespace Moq +{ + [DebuggerStepThrough] + internal static class Guard + { + /// + /// Ensures the given is not null. + /// Throws otherwise. + /// + public static void NotNull(Expression> reference, T value) + { + if (value == null) + { + throw new ArgumentNullException(GetParameterName(reference)); + } + } + + /// + /// Ensures the given string is not null or empty. + /// Throws in the first case, or + /// in the latter. + /// + public static void NotNullOrEmpty(Expression> reference, string value) + { + NotNull(reference, value); + if (value.Length == 0) + { + throw new ArgumentException(Resources.ArgumentCannotBeEmpty, GetParameterName(reference)); + } + } + + /// + /// Checks an argument to ensure it is in the specified range including the edges. + /// + /// Type of the argument to check, it must be an type. + /// + /// The expression containing the name of the argument. + /// The argument value to check. + /// The minimun allowed value for the argument. + /// The maximun allowed value for the argument. + public static void NotOutOfRangeInclusive(Expression> reference, T value, T from, T to) + where T : IComparable + { + if (value != null && (value.CompareTo(from) < 0 || value.CompareTo(to) > 0)) + { + throw new ArgumentOutOfRangeException(GetParameterName(reference)); + } + } + + /// + /// Checks an argument to ensure it is in the specified range excluding the edges. + /// + /// Type of the argument to check, it must be an type. + /// + /// The expression containing the name of the argument. + /// The argument value to check. + /// The minimun allowed value for the argument. + /// The maximun allowed value for the argument. + public static void NotOutOfRangeExclusive(Expression> reference, T value, T from, T to) + where T : IComparable + { + if (value != null && (value.CompareTo(from) <= 0 || value.CompareTo(to) >= 0)) + { + throw new ArgumentOutOfRangeException(GetParameterName(reference)); + } + } + + public static void CanBeAssigned(Expression> reference, Type typeToAssign, Type targetType) + { + if (!targetType.IsAssignableFrom(typeToAssign)) + { + if (targetType.IsInterface) + { + throw new ArgumentException(string.Format( + CultureInfo.CurrentCulture, + Resources.TypeNotImplementInterface, + typeToAssign, + targetType), GetParameterName(reference)); + } + + throw new ArgumentException(string.Format( + CultureInfo.CurrentCulture, + Resources.TypeNotInheritFromType, + typeToAssign, + targetType), GetParameterName(reference)); + } + } + + private static string GetParameterName(LambdaExpression reference) + { + var member = (MemberExpression)reference.Body; + return member.Member.Name; + } + } } \ No newline at end of file diff --git a/Source/IDefaultValueProvider.cs b/Source/IDefaultValueProvider.cs index 866b06ed8..9e37245aa 100644 --- a/Source/IDefaultValueProvider.cs +++ b/Source/IDefaultValueProvider.cs @@ -1,56 +1,56 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System.ComponentModel; -using System.Reflection; - -namespace Moq -{ - /// - [EditorBrowsable(EditorBrowsableState.Advanced)] - internal interface IDefaultValueProvider - { - /// - void DefineDefault(T value); - - /// - object ProvideDefault(MethodInfo member); - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System.ComponentModel; +using System.Reflection; + +namespace Moq +{ + /// + [EditorBrowsable(EditorBrowsableState.Advanced)] + internal interface IDefaultValueProvider + { + /// + void DefineDefault(T value); + + /// + object ProvideDefault(MethodInfo member); + } } \ No newline at end of file diff --git a/Source/IDefaultValueProvider.xdoc b/Source/IDefaultValueProvider.xdoc index fe74ce9b4..7a2d1ee1e 100644 --- a/Source/IDefaultValueProvider.xdoc +++ b/Source/IDefaultValueProvider.xdoc @@ -1,24 +1,24 @@ - - - - - Interface to be implemented by classes that determine the - default value of non-expected invocations. - - - - - Defines the default value to return in all the methods returning . - - The type of the return value. - The value to set as default. - - - - Provides a value for the given member and arguments. - - - The member to provide a default value for. - - + + + + + Interface to be implemented by classes that determine the + default value of non-expected invocations. + + + + + Defines the default value to return in all the methods returning . + + The type of the return value. + The value to set as default. + + + + Provides a value for the given member and arguments. + + + The member to provide a default value for. + + \ No newline at end of file diff --git a/Source/IHideObjectMembers.cs b/Source/IHideObjectMembers.cs index 940117983..7e62129eb 100644 --- a/Source/IHideObjectMembers.cs +++ b/Source/IHideObjectMembers.cs @@ -1,73 +1,73 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; - -namespace Moq -{ - /// - /// Helper interface used to hide the base - /// members from the fluent API to make it much cleaner - /// in Visual Studio intellisense. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IHideObjectMembers - { - /// - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "We're hiding Object.GetType")] - [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "GetType", Justification = "We're hiding Object.GetType")] - [EditorBrowsable(EditorBrowsableState.Never)] - Type GetType(); - - /// - [EditorBrowsable(EditorBrowsableState.Never)] - int GetHashCode(); - - /// - [EditorBrowsable(EditorBrowsableState.Never)] - string ToString(); - - /// - [EditorBrowsable(EditorBrowsableState.Never)] - bool Equals(object other); - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; + +namespace Moq +{ + /// + /// Helper interface used to hide the base + /// members from the fluent API to make it much cleaner + /// in Visual Studio intellisense. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public interface IHideObjectMembers + { + /// + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "We're hiding Object.GetType")] + [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "GetType", Justification = "We're hiding Object.GetType")] + [EditorBrowsable(EditorBrowsableState.Never)] + Type GetType(); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + int GetHashCode(); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + string ToString(); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + bool Equals(object other); + } } \ No newline at end of file diff --git a/Source/IMatcher.cs b/Source/IMatcher.cs index 357e74861..18945aa16 100644 --- a/Source/IMatcher.cs +++ b/Source/IMatcher.cs @@ -1,50 +1,50 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System.Linq.Expressions; - -namespace Moq -{ - internal interface IMatcher - { - void Initialize(Expression matcherExpression); - bool Matches(object value); - } -} +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System.Linq.Expressions; + +namespace Moq +{ + internal interface IMatcher + { + void Initialize(Expression matcherExpression); + bool Matches(object value); + } +} diff --git a/Source/IMocked.cs b/Source/IMocked.cs index 64b2a8aed..3445d60e2 100644 --- a/Source/IMocked.cs +++ b/Source/IMocked.cs @@ -1,69 +1,69 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System.ComponentModel; - -namespace Moq -{ - /// - /// Implemented by all generated mock object instances. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IMocked : IMocked - where T : class - { - /// - /// Reference the Mock that contains this as the mock.Object value. - /// - new Mock Mock { get; } - } - - /// - /// Implemented by all generated mock object instances. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IMocked - { - /// - /// Reference the Mock that contains this as the mock.Object value. - /// - Mock Mock { get; } - } -} +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System.ComponentModel; + +namespace Moq +{ + /// + /// Implemented by all generated mock object instances. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public interface IMocked : IMocked + where T : class + { + /// + /// Reference the Mock that contains this as the mock.Object value. + /// + new Mock Mock { get; } + } + + /// + /// Implemented by all generated mock object instances. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public interface IMocked + { + /// + /// Reference the Mock that contains this as the mock.Object value. + /// + Mock Mock { get; } + } +} diff --git a/Source/IProxyCall.cs b/Source/IProxyCall.cs index 57e8a1f39..50297dc65 100644 --- a/Source/IProxyCall.cs +++ b/Source/IProxyCall.cs @@ -1,66 +1,66 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System.Linq.Expressions; -using System.Reflection; -using Moq.Proxy; - -namespace Moq -{ - internal interface IProxyCall - { - int CallCount { get; } - bool IsConditional { get; } - string FailMessage { get; set; } - bool Invoked { get; set; } - bool IsVerifiable { get; set; } - Expression SetupExpression { get; } - MethodInfo Method { get; } - - bool Matches(ICallContext call); - void Execute(ICallContext call); - void SetOutParameters(ICallContext call); - - // Where the setup was performed. - string FileName { get; } - int FileLine { get; } - MethodBase TestMethod { get; } - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System.Linq.Expressions; +using System.Reflection; +using Moq.Proxy; + +namespace Moq +{ + internal interface IProxyCall + { + int CallCount { get; } + bool IsConditional { get; } + string FailMessage { get; set; } + bool Invoked { get; set; } + bool IsVerifiable { get; set; } + Expression SetupExpression { get; } + MethodInfo Method { get; } + + bool Matches(ICallContext call); + void Execute(ICallContext call); + void SetOutParameters(ICallContext call); + + // Where the setup was performed. + string FileName { get; } + int FileLine { get; } + MethodBase TestMethod { get; } + } } \ No newline at end of file diff --git a/Source/Includes/GenericTypeParameters.tt b/Source/Includes/GenericTypeParameters.tt index dd25400aa..bad900029 100644 --- a/Source/Includes/GenericTypeParameters.tt +++ b/Source/Includes/GenericTypeParameters.tt @@ -1,25 +1,25 @@ -<#+ -private const int GenericTypeMax = 16; -private const int GenericTypeMin = 5; - -private const string GenericTypeFormat = "T{0}"; -private const string GenericArgumentFormat = "T{0} arg{0}"; - -private static readonly string[] ordinalNumbers = new[] { "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "nineth", "tenth", "eleventh", "twelfth", "thirteenth", "fourteenth", "fifteenth", "sixteenth" }; -private static readonly string[] wordNumbers = new[] { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen" }; - -public static string ConvertToWord(int number) -{ - return wordNumbers[number - 1]; -} - -public static string ConvertToOrdinal(int number) -{ - return ordinalNumbers[number - 1]; -} - -private static string GetGenericList(int typeCount, string format, string separator = ", ") -{ - return string.Join(separator, Enumerable.Range(1, typeCount).Select(n => string.Format(format, n)).ToArray()); -} +<#+ +private const int GenericTypeMax = 16; +private const int GenericTypeMin = 5; + +private const string GenericTypeFormat = "T{0}"; +private const string GenericArgumentFormat = "T{0} arg{0}"; + +private static readonly string[] ordinalNumbers = new[] { "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "nineth", "tenth", "eleventh", "twelfth", "thirteenth", "fourteenth", "fifteenth", "sixteenth" }; +private static readonly string[] wordNumbers = new[] { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen" }; + +public static string ConvertToWord(int number) +{ + return wordNumbers[number - 1]; +} + +public static string ConvertToOrdinal(int number) +{ + return ordinalNumbers[number - 1]; +} + +private static string GetGenericList(int typeCount, string format, string separator = ", ") +{ + return string.Join(separator, Enumerable.Range(1, typeCount).Select(n => string.Format(format, n)).ToArray()); +} #> \ No newline at end of file diff --git a/Source/Language/Flow/ICallbackResult.cs b/Source/Language/Flow/ICallbackResult.cs index 06d18d882..b22f979b6 100644 --- a/Source/Language/Flow/ICallbackResult.cs +++ b/Source/Language/Flow/ICallbackResult.cs @@ -1,52 +1,52 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System.ComponentModel; - -namespace Moq.Language.Flow -{ - /// - /// Implements the fluent API. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public interface ICallbackResult : IThrows, IThrowsResult, IHideObjectMembers - { - } -} +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System.ComponentModel; + +namespace Moq.Language.Flow +{ + /// + /// Implements the fluent API. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public interface ICallbackResult : IThrows, IThrowsResult, IHideObjectMembers + { + } +} diff --git a/Source/Language/Flow/IReturnsResult.cs b/Source/Language/Flow/IReturnsResult.cs index 86f2f0649..48043f3e0 100644 --- a/Source/Language/Flow/IReturnsResult.cs +++ b/Source/Language/Flow/IReturnsResult.cs @@ -1,52 +1,52 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System.ComponentModel; - -namespace Moq.Language.Flow -{ - /// - /// Implements the fluent API. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IReturnsResult : ICallback, IOccurrence, IRaise, IVerifies, IHideObjectMembers - { - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System.ComponentModel; + +namespace Moq.Language.Flow +{ + /// + /// Implements the fluent API. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public interface IReturnsResult : ICallback, IOccurrence, IRaise, IVerifies, IHideObjectMembers + { + } } \ No newline at end of file diff --git a/Source/Language/Flow/IReturnsThrows.cs b/Source/Language/Flow/IReturnsThrows.cs index 8107d69f7..11f009e61 100644 --- a/Source/Language/Flow/IReturnsThrows.cs +++ b/Source/Language/Flow/IReturnsThrows.cs @@ -1,62 +1,62 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System.ComponentModel; - -namespace Moq.Language.Flow -{ - /// - /// Implements the fluent API. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IReturnsThrows : IReturns, IThrows, IHideObjectMembers - where TMock : class - { - } - - /// - /// Implements the fluent API. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IReturnsThrowsGetter : IReturnsGetter, IThrows, IHideObjectMembers - where TMock : class - { - } -} +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System.ComponentModel; + +namespace Moq.Language.Flow +{ + /// + /// Implements the fluent API. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public interface IReturnsThrows : IReturns, IThrows, IHideObjectMembers + where TMock : class + { + } + + /// + /// Implements the fluent API. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public interface IReturnsThrowsGetter : IReturnsGetter, IThrows, IHideObjectMembers + where TMock : class + { + } +} diff --git a/Source/Language/Flow/ISetup.cs b/Source/Language/Flow/ISetup.cs index 08f342334..d96ee38fd 100644 --- a/Source/Language/Flow/ISetup.cs +++ b/Source/Language/Flow/ISetup.cs @@ -1,80 +1,80 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System.ComponentModel; - -namespace Moq.Language.Flow -{ - /// - /// Implements the fluent API. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public interface ISetup : ICallback, ICallbackResult, IRaise, IVerifies, IHideObjectMembers - where TMock : class - { - } - - /// - /// Implements the fluent API. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public interface ISetup : ICallback, IReturnsThrows, IVerifies, IHideObjectMembers - where TMock : class - { - } - - /// - /// Implements the fluent API. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public interface ISetupGetter : ICallbackGetter, IReturnsThrowsGetter, IVerifies, IHideObjectMembers - where TMock : class - { - } - - /// - /// Implements the fluent API. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public interface ISetupSetter : ICallbackSetter, ICallbackResult, IRaise, IVerifies, IHideObjectMembers - where TMock : class - { - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System.ComponentModel; + +namespace Moq.Language.Flow +{ + /// + /// Implements the fluent API. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public interface ISetup : ICallback, ICallbackResult, IRaise, IVerifies, IHideObjectMembers + where TMock : class + { + } + + /// + /// Implements the fluent API. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public interface ISetup : ICallback, IReturnsThrows, IVerifies, IHideObjectMembers + where TMock : class + { + } + + /// + /// Implements the fluent API. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public interface ISetupGetter : ICallbackGetter, IReturnsThrowsGetter, IVerifies, IHideObjectMembers + where TMock : class + { + } + + /// + /// Implements the fluent API. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public interface ISetupSetter : ICallbackSetter, ICallbackResult, IRaise, IVerifies, IHideObjectMembers + where TMock : class + { + } } \ No newline at end of file diff --git a/Source/Language/Flow/IThrowsResult.cs b/Source/Language/Flow/IThrowsResult.cs index dbd16eec7..e15b5be1e 100644 --- a/Source/Language/Flow/IThrowsResult.cs +++ b/Source/Language/Flow/IThrowsResult.cs @@ -1,52 +1,52 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System.ComponentModel; - -namespace Moq.Language.Flow -{ - /// - /// Implements the fluent API. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IThrowsResult : IOccurrence, IVerifies, IHideObjectMembers - { - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System.ComponentModel; + +namespace Moq.Language.Flow +{ + /// + /// Implements the fluent API. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public interface IThrowsResult : IOccurrence, IVerifies, IHideObjectMembers + { + } } \ No newline at end of file diff --git a/Source/Language/ICallback.Generated.cs b/Source/Language/ICallback.Generated.cs index 770f150c8..67fbf5c20 100644 --- a/Source/Language/ICallback.Generated.cs +++ b/Source/Language/ICallback.Generated.cs @@ -1,1149 +1,1149 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.ComponentModel; -using Moq.Language.Flow; - -namespace Moq.Language -{ - partial interface ICallback - { - /// - /// Specifies a callback to invoke when the method is called that receives the original arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((string arg1, string arg2) => Console.WriteLine(arg1 + arg2)); - /// - /// - ICallbackResult Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((string arg1, string arg2, string arg3) => Console.WriteLine(arg1 + arg2 + arg3)); - /// - /// - ICallbackResult Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((string arg1, string arg2, string arg3, string arg4) => Console.WriteLine(arg1 + arg2 + arg3 + arg4)); - /// - /// - ICallbackResult Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((string arg1, string arg2, string arg3, string arg4, string arg5) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5)); - /// - /// - ICallbackResult Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6)); - /// - /// - ICallbackResult Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7)); - /// - /// - ICallbackResult Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The type of the eighth argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8)); - /// - /// - ICallbackResult Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The type of the eighth argument of the invoked method. - /// The type of the nineth argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9)); - /// - /// - ICallbackResult Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The type of the eighth argument of the invoked method. - /// The type of the nineth argument of the invoked method. - /// The type of the tenth argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10)); - /// - /// - ICallbackResult Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The type of the eighth argument of the invoked method. - /// The type of the nineth argument of the invoked method. - /// The type of the tenth argument of the invoked method. - /// The type of the eleventh argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11)); - /// - /// - ICallbackResult Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The type of the eighth argument of the invoked method. - /// The type of the nineth argument of the invoked method. - /// The type of the tenth argument of the invoked method. - /// The type of the eleventh argument of the invoked method. - /// The type of the twelfth argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12)); - /// - /// - ICallbackResult Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The type of the eighth argument of the invoked method. - /// The type of the nineth argument of the invoked method. - /// The type of the tenth argument of the invoked method. - /// The type of the eleventh argument of the invoked method. - /// The type of the twelfth argument of the invoked method. - /// The type of the thirteenth argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12, string arg13) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13)); - /// - /// - ICallbackResult Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The type of the eighth argument of the invoked method. - /// The type of the nineth argument of the invoked method. - /// The type of the tenth argument of the invoked method. - /// The type of the eleventh argument of the invoked method. - /// The type of the twelfth argument of the invoked method. - /// The type of the thirteenth argument of the invoked method. - /// The type of the fourteenth argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12, string arg13, string arg14) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14)); - /// - /// - ICallbackResult Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The type of the eighth argument of the invoked method. - /// The type of the nineth argument of the invoked method. - /// The type of the tenth argument of the invoked method. - /// The type of the eleventh argument of the invoked method. - /// The type of the twelfth argument of the invoked method. - /// The type of the thirteenth argument of the invoked method. - /// The type of the fourteenth argument of the invoked method. - /// The type of the fifteenth argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12, string arg13, string arg14, string arg15) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14 + arg15)); - /// - /// - ICallbackResult Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The type of the eighth argument of the invoked method. - /// The type of the nineth argument of the invoked method. - /// The type of the tenth argument of the invoked method. - /// The type of the eleventh argument of the invoked method. - /// The type of the twelfth argument of the invoked method. - /// The type of the thirteenth argument of the invoked method. - /// The type of the fourteenth argument of the invoked method. - /// The type of the fifteenth argument of the invoked method. - /// The type of the sixteenth argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12, string arg13, string arg14, string arg15, string arg16) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14 + arg15 + arg16)); - /// - /// - ICallbackResult Callback(Action action); - } - - partial interface ICallback - where TMock : class - { - - /// - /// Specifies a callback to invoke when the method is called that receives the original - /// arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((arg1, arg2) => Console.WriteLine(arg1 + arg2)); - /// - /// - IReturnsThrows Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original - /// arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((arg1, arg2, arg3) => Console.WriteLine(arg1 + arg2 + arg3)); - /// - /// - IReturnsThrows Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original - /// arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((arg1, arg2, arg3, arg4) => Console.WriteLine(arg1 + arg2 + arg3 + arg4)); - /// - /// - IReturnsThrows Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original - /// arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((arg1, arg2, arg3, arg4, arg5) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5)); - /// - /// - IReturnsThrows Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original - /// arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((arg1, arg2, arg3, arg4, arg5, arg6) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6)); - /// - /// - IReturnsThrows Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original - /// arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7)); - /// - /// - IReturnsThrows Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original - /// arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The type of the eighth argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8)); - /// - /// - IReturnsThrows Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original - /// arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The type of the eighth argument of the invoked method. - /// The type of the nineth argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9)); - /// - /// - IReturnsThrows Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original - /// arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The type of the eighth argument of the invoked method. - /// The type of the nineth argument of the invoked method. - /// The type of the tenth argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10)); - /// - /// - IReturnsThrows Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original - /// arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The type of the eighth argument of the invoked method. - /// The type of the nineth argument of the invoked method. - /// The type of the tenth argument of the invoked method. - /// The type of the eleventh argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11)); - /// - /// - IReturnsThrows Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original - /// arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The type of the eighth argument of the invoked method. - /// The type of the nineth argument of the invoked method. - /// The type of the tenth argument of the invoked method. - /// The type of the eleventh argument of the invoked method. - /// The type of the twelfth argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12)); - /// - /// - IReturnsThrows Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original - /// arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The type of the eighth argument of the invoked method. - /// The type of the nineth argument of the invoked method. - /// The type of the tenth argument of the invoked method. - /// The type of the eleventh argument of the invoked method. - /// The type of the twelfth argument of the invoked method. - /// The type of the thirteenth argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13)); - /// - /// - IReturnsThrows Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original - /// arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The type of the eighth argument of the invoked method. - /// The type of the nineth argument of the invoked method. - /// The type of the tenth argument of the invoked method. - /// The type of the eleventh argument of the invoked method. - /// The type of the twelfth argument of the invoked method. - /// The type of the thirteenth argument of the invoked method. - /// The type of the fourteenth argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14)); - /// - /// - IReturnsThrows Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original - /// arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The type of the eighth argument of the invoked method. - /// The type of the nineth argument of the invoked method. - /// The type of the tenth argument of the invoked method. - /// The type of the eleventh argument of the invoked method. - /// The type of the twelfth argument of the invoked method. - /// The type of the thirteenth argument of the invoked method. - /// The type of the fourteenth argument of the invoked method. - /// The type of the fifteenth argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14 + arg15)); - /// - /// - IReturnsThrows Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original - /// arguments. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The type of the eighth argument of the invoked method. - /// The type of the nineth argument of the invoked method. - /// The type of the tenth argument of the invoked method. - /// The type of the eleventh argument of the invoked method. - /// The type of the twelfth argument of the invoked method. - /// The type of the thirteenth argument of the invoked method. - /// The type of the fourteenth argument of the invoked method. - /// The type of the fifteenth argument of the invoked method. - /// The type of the sixteenth argument of the invoked method. - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>(), - /// It.IsAny<string>())) - /// .Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14 + arg15 + arg16)); - /// - /// - IReturnsThrows Callback(Action action); - } -} +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.ComponentModel; +using Moq.Language.Flow; + +namespace Moq.Language +{ + partial interface ICallback + { + /// + /// Specifies a callback to invoke when the method is called that receives the original arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((string arg1, string arg2) => Console.WriteLine(arg1 + arg2)); + /// + /// + ICallbackResult Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((string arg1, string arg2, string arg3) => Console.WriteLine(arg1 + arg2 + arg3)); + /// + /// + ICallbackResult Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((string arg1, string arg2, string arg3, string arg4) => Console.WriteLine(arg1 + arg2 + arg3 + arg4)); + /// + /// + ICallbackResult Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((string arg1, string arg2, string arg3, string arg4, string arg5) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5)); + /// + /// + ICallbackResult Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6)); + /// + /// + ICallbackResult Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7)); + /// + /// + ICallbackResult Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The type of the eighth argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8)); + /// + /// + ICallbackResult Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The type of the eighth argument of the invoked method. + /// The type of the nineth argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9)); + /// + /// + ICallbackResult Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The type of the eighth argument of the invoked method. + /// The type of the nineth argument of the invoked method. + /// The type of the tenth argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10)); + /// + /// + ICallbackResult Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The type of the eighth argument of the invoked method. + /// The type of the nineth argument of the invoked method. + /// The type of the tenth argument of the invoked method. + /// The type of the eleventh argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11)); + /// + /// + ICallbackResult Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The type of the eighth argument of the invoked method. + /// The type of the nineth argument of the invoked method. + /// The type of the tenth argument of the invoked method. + /// The type of the eleventh argument of the invoked method. + /// The type of the twelfth argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12)); + /// + /// + ICallbackResult Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The type of the eighth argument of the invoked method. + /// The type of the nineth argument of the invoked method. + /// The type of the tenth argument of the invoked method. + /// The type of the eleventh argument of the invoked method. + /// The type of the twelfth argument of the invoked method. + /// The type of the thirteenth argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12, string arg13) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13)); + /// + /// + ICallbackResult Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The type of the eighth argument of the invoked method. + /// The type of the nineth argument of the invoked method. + /// The type of the tenth argument of the invoked method. + /// The type of the eleventh argument of the invoked method. + /// The type of the twelfth argument of the invoked method. + /// The type of the thirteenth argument of the invoked method. + /// The type of the fourteenth argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12, string arg13, string arg14) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14)); + /// + /// + ICallbackResult Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The type of the eighth argument of the invoked method. + /// The type of the nineth argument of the invoked method. + /// The type of the tenth argument of the invoked method. + /// The type of the eleventh argument of the invoked method. + /// The type of the twelfth argument of the invoked method. + /// The type of the thirteenth argument of the invoked method. + /// The type of the fourteenth argument of the invoked method. + /// The type of the fifteenth argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12, string arg13, string arg14, string arg15) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14 + arg15)); + /// + /// + ICallbackResult Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The type of the eighth argument of the invoked method. + /// The type of the nineth argument of the invoked method. + /// The type of the tenth argument of the invoked method. + /// The type of the eleventh argument of the invoked method. + /// The type of the twelfth argument of the invoked method. + /// The type of the thirteenth argument of the invoked method. + /// The type of the fourteenth argument of the invoked method. + /// The type of the fifteenth argument of the invoked method. + /// The type of the sixteenth argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12, string arg13, string arg14, string arg15, string arg16) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14 + arg15 + arg16)); + /// + /// + ICallbackResult Callback(Action action); + } + + partial interface ICallback + where TMock : class + { + + /// + /// Specifies a callback to invoke when the method is called that receives the original + /// arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((arg1, arg2) => Console.WriteLine(arg1 + arg2)); + /// + /// + IReturnsThrows Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original + /// arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((arg1, arg2, arg3) => Console.WriteLine(arg1 + arg2 + arg3)); + /// + /// + IReturnsThrows Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original + /// arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((arg1, arg2, arg3, arg4) => Console.WriteLine(arg1 + arg2 + arg3 + arg4)); + /// + /// + IReturnsThrows Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original + /// arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((arg1, arg2, arg3, arg4, arg5) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5)); + /// + /// + IReturnsThrows Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original + /// arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((arg1, arg2, arg3, arg4, arg5, arg6) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6)); + /// + /// + IReturnsThrows Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original + /// arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7)); + /// + /// + IReturnsThrows Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original + /// arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The type of the eighth argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8)); + /// + /// + IReturnsThrows Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original + /// arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The type of the eighth argument of the invoked method. + /// The type of the nineth argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9)); + /// + /// + IReturnsThrows Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original + /// arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The type of the eighth argument of the invoked method. + /// The type of the nineth argument of the invoked method. + /// The type of the tenth argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10)); + /// + /// + IReturnsThrows Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original + /// arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The type of the eighth argument of the invoked method. + /// The type of the nineth argument of the invoked method. + /// The type of the tenth argument of the invoked method. + /// The type of the eleventh argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11)); + /// + /// + IReturnsThrows Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original + /// arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The type of the eighth argument of the invoked method. + /// The type of the nineth argument of the invoked method. + /// The type of the tenth argument of the invoked method. + /// The type of the eleventh argument of the invoked method. + /// The type of the twelfth argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12)); + /// + /// + IReturnsThrows Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original + /// arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The type of the eighth argument of the invoked method. + /// The type of the nineth argument of the invoked method. + /// The type of the tenth argument of the invoked method. + /// The type of the eleventh argument of the invoked method. + /// The type of the twelfth argument of the invoked method. + /// The type of the thirteenth argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13)); + /// + /// + IReturnsThrows Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original + /// arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The type of the eighth argument of the invoked method. + /// The type of the nineth argument of the invoked method. + /// The type of the tenth argument of the invoked method. + /// The type of the eleventh argument of the invoked method. + /// The type of the twelfth argument of the invoked method. + /// The type of the thirteenth argument of the invoked method. + /// The type of the fourteenth argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14)); + /// + /// + IReturnsThrows Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original + /// arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The type of the eighth argument of the invoked method. + /// The type of the nineth argument of the invoked method. + /// The type of the tenth argument of the invoked method. + /// The type of the eleventh argument of the invoked method. + /// The type of the twelfth argument of the invoked method. + /// The type of the thirteenth argument of the invoked method. + /// The type of the fourteenth argument of the invoked method. + /// The type of the fifteenth argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14 + arg15)); + /// + /// + IReturnsThrows Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original + /// arguments. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The type of the eighth argument of the invoked method. + /// The type of the nineth argument of the invoked method. + /// The type of the tenth argument of the invoked method. + /// The type of the eleventh argument of the invoked method. + /// The type of the twelfth argument of the invoked method. + /// The type of the thirteenth argument of the invoked method. + /// The type of the fourteenth argument of the invoked method. + /// The type of the fifteenth argument of the invoked method. + /// The type of the sixteenth argument of the invoked method. + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>(), + /// It.IsAny<string>())) + /// .Callback((arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16) => Console.WriteLine(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14 + arg15 + arg16)); + /// + /// + IReturnsThrows Callback(Action action); + } +} diff --git a/Source/Language/ICallback.cs b/Source/Language/ICallback.cs index 40a3531e6..4867fa79f 100644 --- a/Source/Language/ICallback.cs +++ b/Source/Language/ICallback.cs @@ -1,132 +1,132 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.ComponentModel; -using Moq.Language.Flow; - -namespace Moq.Language -{ - /// - /// Defines the Callback verb and overloads. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public partial interface ICallback : IHideObjectMembers - { - /// - /// Specifies a callback to invoke when the method is called. - /// - /// The callback method to invoke. - /// - /// The following example specifies a callback to set a boolean - /// value that can be used later: - /// - /// var called = false; - /// mock.Setup(x => x.Execute()) - /// .Callback(() => called = true); - /// - /// - ICallbackResult Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original arguments. - /// - /// The argument type of the invoked method. - /// The callback method to invoke. - /// - /// Invokes the given callback with the concrete invocation argument value. - /// - /// Notice how the specific string argument is retrieved by simply declaring - /// it as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute(It.IsAny<string>())) - /// .Callback((string command) => Console.WriteLine(command)); - /// - /// - ICallbackResult Callback(Action action); - } - - /// - /// Defines the Callback verb and overloads for callbacks on - /// setups that return a value. - /// - /// Mocked type. - /// Type of the return value of the setup. - public partial interface ICallback : IHideObjectMembers - where TMock : class - { - /// - /// Specifies a callback to invoke when the method is called. - /// - /// The callback method to invoke. - /// - /// The following example specifies a callback to set a boolean value that can be used later: - /// - /// var called = false; - /// mock.Setup(x => x.Execute()) - /// .Callback(() => called = true) - /// .Returns(true); - /// - /// Note that in the case of value-returning methods, after the Callback - /// call you can still specify the return value. - /// - IReturnsThrows Callback(Action action); - - /// - /// Specifies a callback to invoke when the method is called that receives the original arguments. - /// - /// The type of the argument of the invoked method. - /// Callback method to invoke. - /// - /// Invokes the given callback with the concrete invocation argument value. - /// - /// Notice how the specific string argument is retrieved by simply declaring - /// it as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute(It.IsAny<string>())) - /// .Callback(command => Console.WriteLine(command)) - /// .Returns(true); - /// - /// - IReturnsThrows Callback(Action action); - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.ComponentModel; +using Moq.Language.Flow; + +namespace Moq.Language +{ + /// + /// Defines the Callback verb and overloads. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public partial interface ICallback : IHideObjectMembers + { + /// + /// Specifies a callback to invoke when the method is called. + /// + /// The callback method to invoke. + /// + /// The following example specifies a callback to set a boolean + /// value that can be used later: + /// + /// var called = false; + /// mock.Setup(x => x.Execute()) + /// .Callback(() => called = true); + /// + /// + ICallbackResult Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original arguments. + /// + /// The argument type of the invoked method. + /// The callback method to invoke. + /// + /// Invokes the given callback with the concrete invocation argument value. + /// + /// Notice how the specific string argument is retrieved by simply declaring + /// it as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute(It.IsAny<string>())) + /// .Callback((string command) => Console.WriteLine(command)); + /// + /// + ICallbackResult Callback(Action action); + } + + /// + /// Defines the Callback verb and overloads for callbacks on + /// setups that return a value. + /// + /// Mocked type. + /// Type of the return value of the setup. + public partial interface ICallback : IHideObjectMembers + where TMock : class + { + /// + /// Specifies a callback to invoke when the method is called. + /// + /// The callback method to invoke. + /// + /// The following example specifies a callback to set a boolean value that can be used later: + /// + /// var called = false; + /// mock.Setup(x => x.Execute()) + /// .Callback(() => called = true) + /// .Returns(true); + /// + /// Note that in the case of value-returning methods, after the Callback + /// call you can still specify the return value. + /// + IReturnsThrows Callback(Action action); + + /// + /// Specifies a callback to invoke when the method is called that receives the original arguments. + /// + /// The type of the argument of the invoked method. + /// Callback method to invoke. + /// + /// Invokes the given callback with the concrete invocation argument value. + /// + /// Notice how the specific string argument is retrieved by simply declaring + /// it as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute(It.IsAny<string>())) + /// .Callback(command => Console.WriteLine(command)) + /// .Returns(true); + /// + /// + IReturnsThrows Callback(Action action); + } } \ No newline at end of file diff --git a/Source/Language/ICallback.tt b/Source/Language/ICallback.tt index 66f27d677..0a894fad6 100644 --- a/Source/Language/ICallback.tt +++ b/Source/Language/ICallback.tt @@ -1,146 +1,146 @@ -<#@ template debug="false" hostspecific="false" language="C#" #> -<#@ output extension=".Generated.cs" #> -<#@ Assembly Name="System.Core" #> -<#@ Import Namespace="System.Linq" #> -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.ComponentModel; -using Moq.Language.Flow; - -namespace Moq.Language -{ - partial interface ICallback - { <# -for (var typeCount = 2; typeCount <= GenericTypeMax; typeCount++) -{ - var typeList = GetGenericList(typeCount, GenericTypeFormat); -#> - - /// - /// Specifies a callback to invoke when the method is called that receives the original arguments. - /// -<# - for (var typeIndex = 1; typeIndex <= typeCount; typeIndex++) - { -#> - /// The type of the <#= ConvertToOrdinal(typeIndex) #> argument of the invoked method. -<# - } -#> - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( -<# - for (var typeIndex = 1; typeIndex < typeCount; typeIndex++) - { -#> - /// It.IsAny<string>(), -<# - } -#> - /// It.IsAny<string>())) - /// .Callback((<#= GetGenericList(typeCount, "string arg{0}") #>) => Console.WriteLine(<#= GetGenericList(typeCount, "arg{0}", " + ") #>)); - /// - /// - ICallbackResult Callback<<#= typeList #>>(Action<<#= typeList #>> action); -<# -} -#> - } - - partial interface ICallback - where TMock : class - { -<# -for (var typeCount = 2; typeCount <= GenericTypeMax; typeCount++) -{ - var typeList = GetGenericList(typeCount, GenericTypeFormat); -#> - - /// - /// Specifies a callback to invoke when the method is called that receives the original - /// arguments. - /// -<# - for (var typeIndex = 1; typeIndex <= typeCount; typeIndex++) - { -#> - /// The type of the <#= ConvertToOrdinal(typeIndex) #> argument of the invoked method. -<# - } -#> - /// The callback method to invoke. - /// A reference to interface. - /// - /// Invokes the given callback with the concrete invocation arguments values. - /// - /// Notice how the specific arguments are retrieved by simply declaring - /// them as part of the lambda expression for the callback: - /// - /// - /// mock.Setup(x => x.Execute( -<# - for (var typeIndex = 1; typeIndex < typeCount; typeIndex++) - { -#> - /// It.IsAny<string>(), -<# - } -#> - /// It.IsAny<string>())) - /// .Callback((<#= GetGenericList(typeCount, "arg{0}") #>) => Console.WriteLine(<#= GetGenericList(typeCount, "arg{0}", " + ") #>)); - /// - /// - IReturnsThrows Callback<<#= typeList #>>(Action<<#= typeList #>> action); -<# -} -#> - } -} +<#@ template debug="false" hostspecific="false" language="C#" #> +<#@ output extension=".Generated.cs" #> +<#@ Assembly Name="System.Core" #> +<#@ Import Namespace="System.Linq" #> +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.ComponentModel; +using Moq.Language.Flow; + +namespace Moq.Language +{ + partial interface ICallback + { <# +for (var typeCount = 2; typeCount <= GenericTypeMax; typeCount++) +{ + var typeList = GetGenericList(typeCount, GenericTypeFormat); +#> + + /// + /// Specifies a callback to invoke when the method is called that receives the original arguments. + /// +<# + for (var typeIndex = 1; typeIndex <= typeCount; typeIndex++) + { +#> + /// The type of the <#= ConvertToOrdinal(typeIndex) #> argument of the invoked method. +<# + } +#> + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( +<# + for (var typeIndex = 1; typeIndex < typeCount; typeIndex++) + { +#> + /// It.IsAny<string>(), +<# + } +#> + /// It.IsAny<string>())) + /// .Callback((<#= GetGenericList(typeCount, "string arg{0}") #>) => Console.WriteLine(<#= GetGenericList(typeCount, "arg{0}", " + ") #>)); + /// + /// + ICallbackResult Callback<<#= typeList #>>(Action<<#= typeList #>> action); +<# +} +#> + } + + partial interface ICallback + where TMock : class + { +<# +for (var typeCount = 2; typeCount <= GenericTypeMax; typeCount++) +{ + var typeList = GetGenericList(typeCount, GenericTypeFormat); +#> + + /// + /// Specifies a callback to invoke when the method is called that receives the original + /// arguments. + /// +<# + for (var typeIndex = 1; typeIndex <= typeCount; typeIndex++) + { +#> + /// The type of the <#= ConvertToOrdinal(typeIndex) #> argument of the invoked method. +<# + } +#> + /// The callback method to invoke. + /// A reference to interface. + /// + /// Invokes the given callback with the concrete invocation arguments values. + /// + /// Notice how the specific arguments are retrieved by simply declaring + /// them as part of the lambda expression for the callback: + /// + /// + /// mock.Setup(x => x.Execute( +<# + for (var typeIndex = 1; typeIndex < typeCount; typeIndex++) + { +#> + /// It.IsAny<string>(), +<# + } +#> + /// It.IsAny<string>())) + /// .Callback((<#= GetGenericList(typeCount, "arg{0}") #>) => Console.WriteLine(<#= GetGenericList(typeCount, "arg{0}", " + ") #>)); + /// + /// + IReturnsThrows Callback<<#= typeList #>>(Action<<#= typeList #>> action); +<# +} +#> + } +} <#@ Include File="..\Includes\GenericTypeParameters.tt" #> \ No newline at end of file diff --git a/Source/Language/ICallbackGetter.cs b/Source/Language/ICallbackGetter.cs index 77520ff0a..cfd4d6e7d 100644 --- a/Source/Language/ICallbackGetter.cs +++ b/Source/Language/ICallbackGetter.cs @@ -1,71 +1,71 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.ComponentModel; -using Moq.Language.Flow; - -namespace Moq.Language -{ - /// - /// Defines the Callback verb for property getter setups. - /// - /// - /// Mocked type. - /// Type of the property. - [EditorBrowsable(EditorBrowsableState.Never)] - public interface ICallbackGetter : IHideObjectMembers - where TMock : class - { - /// - /// Specifies a callback to invoke when the property is retrieved. - /// - /// Callback method to invoke. - /// - /// Invokes the given callback with the property value being set. - /// - /// mock.SetupGet(x => x.Suspended) - /// .Callback(() => called = true) - /// .Returns(true); - /// - /// - IReturnsThrowsGetter Callback(Action action); - } -} +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.ComponentModel; +using Moq.Language.Flow; + +namespace Moq.Language +{ + /// + /// Defines the Callback verb for property getter setups. + /// + /// + /// Mocked type. + /// Type of the property. + [EditorBrowsable(EditorBrowsableState.Never)] + public interface ICallbackGetter : IHideObjectMembers + where TMock : class + { + /// + /// Specifies a callback to invoke when the property is retrieved. + /// + /// Callback method to invoke. + /// + /// Invokes the given callback with the property value being set. + /// + /// mock.SetupGet(x => x.Suspended) + /// .Callback(() => called = true) + /// .Returns(true); + /// + /// + IReturnsThrowsGetter Callback(Action action); + } +} diff --git a/Source/Language/ICallbackSetter.cs b/Source/Language/ICallbackSetter.cs index d2ea967da..03682b199 100644 --- a/Source/Language/ICallbackSetter.cs +++ b/Source/Language/ICallbackSetter.cs @@ -1,68 +1,68 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.ComponentModel; -using Moq.Language.Flow; - -namespace Moq.Language -{ - /// - /// Defines the Callback verb for property setter setups. - /// - /// Type of the property. - [EditorBrowsable(EditorBrowsableState.Never)] - public interface ICallbackSetter : IHideObjectMembers - { - /// - /// Specifies a callback to invoke when the property is set that receives the - /// property value being set. - /// - /// Callback method to invoke. - /// - /// Invokes the given callback with the property value being set. - /// - /// mock.SetupSet(x => x.Suspended) - /// .Callback((bool state) => Console.WriteLine(state)); - /// - /// - ICallbackResult Callback(Action action); - } -} +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.ComponentModel; +using Moq.Language.Flow; + +namespace Moq.Language +{ + /// + /// Defines the Callback verb for property setter setups. + /// + /// Type of the property. + [EditorBrowsable(EditorBrowsableState.Never)] + public interface ICallbackSetter : IHideObjectMembers + { + /// + /// Specifies a callback to invoke when the property is set that receives the + /// property value being set. + /// + /// Callback method to invoke. + /// + /// Invokes the given callback with the property value being set. + /// + /// mock.SetupSet(x => x.Suspended) + /// .Callback((bool state) => Console.WriteLine(state)); + /// + /// + ICallbackResult Callback(Action action); + } +} diff --git a/Source/Language/IRaise.Generated.cs b/Source/Language/IRaise.Generated.cs index 1d19f0e48..10e2e102e 100644 --- a/Source/Language/IRaise.Generated.cs +++ b/Source/Language/IRaise.Generated.cs @@ -1,327 +1,327 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] -using System; -using System.ComponentModel; - -namespace Moq.Language -{ - partial interface IRaise - { - /// - /// Specifies the event that will be raised when the setup is matched. - /// - /// The expression that represents an event attach or detach action. - /// The function that will build the - /// to pass when raising the event. - /// The type of the first argument received by the expected invocation. - /// - IVerifies Raises(Action eventExpression, Func func); - - /// - /// Specifies the event that will be raised when the setup is matched. - /// - /// The expression that represents an event attach or detach action. - /// The function that will build the - /// to pass when raising the event. - /// The type of the first argument received by the expected invocation. - /// The type of the second argument received by the expected invocation. - /// - IVerifies Raises(Action eventExpression, Func func); - - /// - /// Specifies the event that will be raised when the setup is matched. - /// - /// The expression that represents an event attach or detach action. - /// The function that will build the - /// to pass when raising the event. - /// The type of the first argument received by the expected invocation. - /// The type of the second argument received by the expected invocation. - /// The type of the third argument received by the expected invocation. - /// - IVerifies Raises(Action eventExpression, Func func); - - /// - /// Specifies the event that will be raised when the setup is matched. - /// - /// The expression that represents an event attach or detach action. - /// The function that will build the - /// to pass when raising the event. - /// The type of the first argument received by the expected invocation. - /// The type of the second argument received by the expected invocation. - /// The type of the third argument received by the expected invocation. - /// The type of the fourth argument received by the expected invocation. - /// - IVerifies Raises(Action eventExpression, Func func); - - /// - /// Specifies the event that will be raised when the setup is matched. - /// - /// The expression that represents an event attach or detach action. - /// The function that will build the - /// to pass when raising the event. - /// The type of the first argument received by the expected invocation. - /// The type of the second argument received by the expected invocation. - /// The type of the third argument received by the expected invocation. - /// The type of the fourth argument received by the expected invocation. - /// The type of the fifth argument received by the expected invocation. - /// - IVerifies Raises(Action eventExpression, Func func); - - /// - /// Specifies the event that will be raised when the setup is matched. - /// - /// The expression that represents an event attach or detach action. - /// The function that will build the - /// to pass when raising the event. - /// The type of the first argument received by the expected invocation. - /// The type of the second argument received by the expected invocation. - /// The type of the third argument received by the expected invocation. - /// The type of the fourth argument received by the expected invocation. - /// The type of the fifth argument received by the expected invocation. - /// The type of the sixth argument received by the expected invocation. - /// - IVerifies Raises(Action eventExpression, Func func); - - /// - /// Specifies the event that will be raised when the setup is matched. - /// - /// The expression that represents an event attach or detach action. - /// The function that will build the - /// to pass when raising the event. - /// The type of the first argument received by the expected invocation. - /// The type of the second argument received by the expected invocation. - /// The type of the third argument received by the expected invocation. - /// The type of the fourth argument received by the expected invocation. - /// The type of the fifth argument received by the expected invocation. - /// The type of the sixth argument received by the expected invocation. - /// The type of the seventh argument received by the expected invocation. - /// - IVerifies Raises(Action eventExpression, Func func); - - /// - /// Specifies the event that will be raised when the setup is matched. - /// - /// The expression that represents an event attach or detach action. - /// The function that will build the - /// to pass when raising the event. - /// The type of the first argument received by the expected invocation. - /// The type of the second argument received by the expected invocation. - /// The type of the third argument received by the expected invocation. - /// The type of the fourth argument received by the expected invocation. - /// The type of the fifth argument received by the expected invocation. - /// The type of the sixth argument received by the expected invocation. - /// The type of the seventh argument received by the expected invocation. - /// The type of the eighth argument received by the expected invocation. - /// - IVerifies Raises(Action eventExpression, Func func); - - /// - /// Specifies the event that will be raised when the setup is matched. - /// - /// The expression that represents an event attach or detach action. - /// The function that will build the - /// to pass when raising the event. - /// The type of the first argument received by the expected invocation. - /// The type of the second argument received by the expected invocation. - /// The type of the third argument received by the expected invocation. - /// The type of the fourth argument received by the expected invocation. - /// The type of the fifth argument received by the expected invocation. - /// The type of the sixth argument received by the expected invocation. - /// The type of the seventh argument received by the expected invocation. - /// The type of the eighth argument received by the expected invocation. - /// The type of the nineth argument received by the expected invocation. - /// - IVerifies Raises(Action eventExpression, Func func); - - /// - /// Specifies the event that will be raised when the setup is matched. - /// - /// The expression that represents an event attach or detach action. - /// The function that will build the - /// to pass when raising the event. - /// The type of the first argument received by the expected invocation. - /// The type of the second argument received by the expected invocation. - /// The type of the third argument received by the expected invocation. - /// The type of the fourth argument received by the expected invocation. - /// The type of the fifth argument received by the expected invocation. - /// The type of the sixth argument received by the expected invocation. - /// The type of the seventh argument received by the expected invocation. - /// The type of the eighth argument received by the expected invocation. - /// The type of the nineth argument received by the expected invocation. - /// The type of the tenth argument received by the expected invocation. - /// - IVerifies Raises(Action eventExpression, Func func); - - /// - /// Specifies the event that will be raised when the setup is matched. - /// - /// The expression that represents an event attach or detach action. - /// The function that will build the - /// to pass when raising the event. - /// The type of the first argument received by the expected invocation. - /// The type of the second argument received by the expected invocation. - /// The type of the third argument received by the expected invocation. - /// The type of the fourth argument received by the expected invocation. - /// The type of the fifth argument received by the expected invocation. - /// The type of the sixth argument received by the expected invocation. - /// The type of the seventh argument received by the expected invocation. - /// The type of the eighth argument received by the expected invocation. - /// The type of the nineth argument received by the expected invocation. - /// The type of the tenth argument received by the expected invocation. - /// The type of the eleventh argument received by the expected invocation. - /// - IVerifies Raises(Action eventExpression, Func func); - - /// - /// Specifies the event that will be raised when the setup is matched. - /// - /// The expression that represents an event attach or detach action. - /// The function that will build the - /// to pass when raising the event. - /// The type of the first argument received by the expected invocation. - /// The type of the second argument received by the expected invocation. - /// The type of the third argument received by the expected invocation. - /// The type of the fourth argument received by the expected invocation. - /// The type of the fifth argument received by the expected invocation. - /// The type of the sixth argument received by the expected invocation. - /// The type of the seventh argument received by the expected invocation. - /// The type of the eighth argument received by the expected invocation. - /// The type of the nineth argument received by the expected invocation. - /// The type of the tenth argument received by the expected invocation. - /// The type of the eleventh argument received by the expected invocation. - /// The type of the twelfth argument received by the expected invocation. - /// - IVerifies Raises(Action eventExpression, Func func); - - /// - /// Specifies the event that will be raised when the setup is matched. - /// - /// The expression that represents an event attach or detach action. - /// The function that will build the - /// to pass when raising the event. - /// The type of the first argument received by the expected invocation. - /// The type of the second argument received by the expected invocation. - /// The type of the third argument received by the expected invocation. - /// The type of the fourth argument received by the expected invocation. - /// The type of the fifth argument received by the expected invocation. - /// The type of the sixth argument received by the expected invocation. - /// The type of the seventh argument received by the expected invocation. - /// The type of the eighth argument received by the expected invocation. - /// The type of the nineth argument received by the expected invocation. - /// The type of the tenth argument received by the expected invocation. - /// The type of the eleventh argument received by the expected invocation. - /// The type of the twelfth argument received by the expected invocation. - /// The type of the thirteenth argument received by the expected invocation. - /// - IVerifies Raises(Action eventExpression, Func func); - - /// - /// Specifies the event that will be raised when the setup is matched. - /// - /// The expression that represents an event attach or detach action. - /// The function that will build the - /// to pass when raising the event. - /// The type of the first argument received by the expected invocation. - /// The type of the second argument received by the expected invocation. - /// The type of the third argument received by the expected invocation. - /// The type of the fourth argument received by the expected invocation. - /// The type of the fifth argument received by the expected invocation. - /// The type of the sixth argument received by the expected invocation. - /// The type of the seventh argument received by the expected invocation. - /// The type of the eighth argument received by the expected invocation. - /// The type of the nineth argument received by the expected invocation. - /// The type of the tenth argument received by the expected invocation. - /// The type of the eleventh argument received by the expected invocation. - /// The type of the twelfth argument received by the expected invocation. - /// The type of the thirteenth argument received by the expected invocation. - /// The type of the fourteenth argument received by the expected invocation. - /// - IVerifies Raises(Action eventExpression, Func func); - - /// - /// Specifies the event that will be raised when the setup is matched. - /// - /// The expression that represents an event attach or detach action. - /// The function that will build the - /// to pass when raising the event. - /// The type of the first argument received by the expected invocation. - /// The type of the second argument received by the expected invocation. - /// The type of the third argument received by the expected invocation. - /// The type of the fourth argument received by the expected invocation. - /// The type of the fifth argument received by the expected invocation. - /// The type of the sixth argument received by the expected invocation. - /// The type of the seventh argument received by the expected invocation. - /// The type of the eighth argument received by the expected invocation. - /// The type of the nineth argument received by the expected invocation. - /// The type of the tenth argument received by the expected invocation. - /// The type of the eleventh argument received by the expected invocation. - /// The type of the twelfth argument received by the expected invocation. - /// The type of the thirteenth argument received by the expected invocation. - /// The type of the fourteenth argument received by the expected invocation. - /// The type of the fifteenth argument received by the expected invocation. - /// - IVerifies Raises(Action eventExpression, Func func); - - /// - /// Specifies the event that will be raised when the setup is matched. - /// - /// The expression that represents an event attach or detach action. - /// The function that will build the - /// to pass when raising the event. - /// The type of the first argument received by the expected invocation. - /// The type of the second argument received by the expected invocation. - /// The type of the third argument received by the expected invocation. - /// The type of the fourth argument received by the expected invocation. - /// The type of the fifth argument received by the expected invocation. - /// The type of the sixth argument received by the expected invocation. - /// The type of the seventh argument received by the expected invocation. - /// The type of the eighth argument received by the expected invocation. - /// The type of the nineth argument received by the expected invocation. - /// The type of the tenth argument received by the expected invocation. - /// The type of the eleventh argument received by the expected invocation. - /// The type of the twelfth argument received by the expected invocation. - /// The type of the thirteenth argument received by the expected invocation. - /// The type of the fourteenth argument received by the expected invocation. - /// The type of the fifteenth argument received by the expected invocation. - /// The type of the sixteenth argument received by the expected invocation. - /// - IVerifies Raises(Action eventExpression, Func func); - } -} +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] +using System; +using System.ComponentModel; + +namespace Moq.Language +{ + partial interface IRaise + { + /// + /// Specifies the event that will be raised when the setup is matched. + /// + /// The expression that represents an event attach or detach action. + /// The function that will build the + /// to pass when raising the event. + /// The type of the first argument received by the expected invocation. + /// + IVerifies Raises(Action eventExpression, Func func); + + /// + /// Specifies the event that will be raised when the setup is matched. + /// + /// The expression that represents an event attach or detach action. + /// The function that will build the + /// to pass when raising the event. + /// The type of the first argument received by the expected invocation. + /// The type of the second argument received by the expected invocation. + /// + IVerifies Raises(Action eventExpression, Func func); + + /// + /// Specifies the event that will be raised when the setup is matched. + /// + /// The expression that represents an event attach or detach action. + /// The function that will build the + /// to pass when raising the event. + /// The type of the first argument received by the expected invocation. + /// The type of the second argument received by the expected invocation. + /// The type of the third argument received by the expected invocation. + /// + IVerifies Raises(Action eventExpression, Func func); + + /// + /// Specifies the event that will be raised when the setup is matched. + /// + /// The expression that represents an event attach or detach action. + /// The function that will build the + /// to pass when raising the event. + /// The type of the first argument received by the expected invocation. + /// The type of the second argument received by the expected invocation. + /// The type of the third argument received by the expected invocation. + /// The type of the fourth argument received by the expected invocation. + /// + IVerifies Raises(Action eventExpression, Func func); + + /// + /// Specifies the event that will be raised when the setup is matched. + /// + /// The expression that represents an event attach or detach action. + /// The function that will build the + /// to pass when raising the event. + /// The type of the first argument received by the expected invocation. + /// The type of the second argument received by the expected invocation. + /// The type of the third argument received by the expected invocation. + /// The type of the fourth argument received by the expected invocation. + /// The type of the fifth argument received by the expected invocation. + /// + IVerifies Raises(Action eventExpression, Func func); + + /// + /// Specifies the event that will be raised when the setup is matched. + /// + /// The expression that represents an event attach or detach action. + /// The function that will build the + /// to pass when raising the event. + /// The type of the first argument received by the expected invocation. + /// The type of the second argument received by the expected invocation. + /// The type of the third argument received by the expected invocation. + /// The type of the fourth argument received by the expected invocation. + /// The type of the fifth argument received by the expected invocation. + /// The type of the sixth argument received by the expected invocation. + /// + IVerifies Raises(Action eventExpression, Func func); + + /// + /// Specifies the event that will be raised when the setup is matched. + /// + /// The expression that represents an event attach or detach action. + /// The function that will build the + /// to pass when raising the event. + /// The type of the first argument received by the expected invocation. + /// The type of the second argument received by the expected invocation. + /// The type of the third argument received by the expected invocation. + /// The type of the fourth argument received by the expected invocation. + /// The type of the fifth argument received by the expected invocation. + /// The type of the sixth argument received by the expected invocation. + /// The type of the seventh argument received by the expected invocation. + /// + IVerifies Raises(Action eventExpression, Func func); + + /// + /// Specifies the event that will be raised when the setup is matched. + /// + /// The expression that represents an event attach or detach action. + /// The function that will build the + /// to pass when raising the event. + /// The type of the first argument received by the expected invocation. + /// The type of the second argument received by the expected invocation. + /// The type of the third argument received by the expected invocation. + /// The type of the fourth argument received by the expected invocation. + /// The type of the fifth argument received by the expected invocation. + /// The type of the sixth argument received by the expected invocation. + /// The type of the seventh argument received by the expected invocation. + /// The type of the eighth argument received by the expected invocation. + /// + IVerifies Raises(Action eventExpression, Func func); + + /// + /// Specifies the event that will be raised when the setup is matched. + /// + /// The expression that represents an event attach or detach action. + /// The function that will build the + /// to pass when raising the event. + /// The type of the first argument received by the expected invocation. + /// The type of the second argument received by the expected invocation. + /// The type of the third argument received by the expected invocation. + /// The type of the fourth argument received by the expected invocation. + /// The type of the fifth argument received by the expected invocation. + /// The type of the sixth argument received by the expected invocation. + /// The type of the seventh argument received by the expected invocation. + /// The type of the eighth argument received by the expected invocation. + /// The type of the nineth argument received by the expected invocation. + /// + IVerifies Raises(Action eventExpression, Func func); + + /// + /// Specifies the event that will be raised when the setup is matched. + /// + /// The expression that represents an event attach or detach action. + /// The function that will build the + /// to pass when raising the event. + /// The type of the first argument received by the expected invocation. + /// The type of the second argument received by the expected invocation. + /// The type of the third argument received by the expected invocation. + /// The type of the fourth argument received by the expected invocation. + /// The type of the fifth argument received by the expected invocation. + /// The type of the sixth argument received by the expected invocation. + /// The type of the seventh argument received by the expected invocation. + /// The type of the eighth argument received by the expected invocation. + /// The type of the nineth argument received by the expected invocation. + /// The type of the tenth argument received by the expected invocation. + /// + IVerifies Raises(Action eventExpression, Func func); + + /// + /// Specifies the event that will be raised when the setup is matched. + /// + /// The expression that represents an event attach or detach action. + /// The function that will build the + /// to pass when raising the event. + /// The type of the first argument received by the expected invocation. + /// The type of the second argument received by the expected invocation. + /// The type of the third argument received by the expected invocation. + /// The type of the fourth argument received by the expected invocation. + /// The type of the fifth argument received by the expected invocation. + /// The type of the sixth argument received by the expected invocation. + /// The type of the seventh argument received by the expected invocation. + /// The type of the eighth argument received by the expected invocation. + /// The type of the nineth argument received by the expected invocation. + /// The type of the tenth argument received by the expected invocation. + /// The type of the eleventh argument received by the expected invocation. + /// + IVerifies Raises(Action eventExpression, Func func); + + /// + /// Specifies the event that will be raised when the setup is matched. + /// + /// The expression that represents an event attach or detach action. + /// The function that will build the + /// to pass when raising the event. + /// The type of the first argument received by the expected invocation. + /// The type of the second argument received by the expected invocation. + /// The type of the third argument received by the expected invocation. + /// The type of the fourth argument received by the expected invocation. + /// The type of the fifth argument received by the expected invocation. + /// The type of the sixth argument received by the expected invocation. + /// The type of the seventh argument received by the expected invocation. + /// The type of the eighth argument received by the expected invocation. + /// The type of the nineth argument received by the expected invocation. + /// The type of the tenth argument received by the expected invocation. + /// The type of the eleventh argument received by the expected invocation. + /// The type of the twelfth argument received by the expected invocation. + /// + IVerifies Raises(Action eventExpression, Func func); + + /// + /// Specifies the event that will be raised when the setup is matched. + /// + /// The expression that represents an event attach or detach action. + /// The function that will build the + /// to pass when raising the event. + /// The type of the first argument received by the expected invocation. + /// The type of the second argument received by the expected invocation. + /// The type of the third argument received by the expected invocation. + /// The type of the fourth argument received by the expected invocation. + /// The type of the fifth argument received by the expected invocation. + /// The type of the sixth argument received by the expected invocation. + /// The type of the seventh argument received by the expected invocation. + /// The type of the eighth argument received by the expected invocation. + /// The type of the nineth argument received by the expected invocation. + /// The type of the tenth argument received by the expected invocation. + /// The type of the eleventh argument received by the expected invocation. + /// The type of the twelfth argument received by the expected invocation. + /// The type of the thirteenth argument received by the expected invocation. + /// + IVerifies Raises(Action eventExpression, Func func); + + /// + /// Specifies the event that will be raised when the setup is matched. + /// + /// The expression that represents an event attach or detach action. + /// The function that will build the + /// to pass when raising the event. + /// The type of the first argument received by the expected invocation. + /// The type of the second argument received by the expected invocation. + /// The type of the third argument received by the expected invocation. + /// The type of the fourth argument received by the expected invocation. + /// The type of the fifth argument received by the expected invocation. + /// The type of the sixth argument received by the expected invocation. + /// The type of the seventh argument received by the expected invocation. + /// The type of the eighth argument received by the expected invocation. + /// The type of the nineth argument received by the expected invocation. + /// The type of the tenth argument received by the expected invocation. + /// The type of the eleventh argument received by the expected invocation. + /// The type of the twelfth argument received by the expected invocation. + /// The type of the thirteenth argument received by the expected invocation. + /// The type of the fourteenth argument received by the expected invocation. + /// + IVerifies Raises(Action eventExpression, Func func); + + /// + /// Specifies the event that will be raised when the setup is matched. + /// + /// The expression that represents an event attach or detach action. + /// The function that will build the + /// to pass when raising the event. + /// The type of the first argument received by the expected invocation. + /// The type of the second argument received by the expected invocation. + /// The type of the third argument received by the expected invocation. + /// The type of the fourth argument received by the expected invocation. + /// The type of the fifth argument received by the expected invocation. + /// The type of the sixth argument received by the expected invocation. + /// The type of the seventh argument received by the expected invocation. + /// The type of the eighth argument received by the expected invocation. + /// The type of the nineth argument received by the expected invocation. + /// The type of the tenth argument received by the expected invocation. + /// The type of the eleventh argument received by the expected invocation. + /// The type of the twelfth argument received by the expected invocation. + /// The type of the thirteenth argument received by the expected invocation. + /// The type of the fourteenth argument received by the expected invocation. + /// The type of the fifteenth argument received by the expected invocation. + /// + IVerifies Raises(Action eventExpression, Func func); + + /// + /// Specifies the event that will be raised when the setup is matched. + /// + /// The expression that represents an event attach or detach action. + /// The function that will build the + /// to pass when raising the event. + /// The type of the first argument received by the expected invocation. + /// The type of the second argument received by the expected invocation. + /// The type of the third argument received by the expected invocation. + /// The type of the fourth argument received by the expected invocation. + /// The type of the fifth argument received by the expected invocation. + /// The type of the sixth argument received by the expected invocation. + /// The type of the seventh argument received by the expected invocation. + /// The type of the eighth argument received by the expected invocation. + /// The type of the nineth argument received by the expected invocation. + /// The type of the tenth argument received by the expected invocation. + /// The type of the eleventh argument received by the expected invocation. + /// The type of the twelfth argument received by the expected invocation. + /// The type of the thirteenth argument received by the expected invocation. + /// The type of the fourteenth argument received by the expected invocation. + /// The type of the fifteenth argument received by the expected invocation. + /// The type of the sixteenth argument received by the expected invocation. + /// + IVerifies Raises(Action eventExpression, Func func); + } +} diff --git a/Source/Language/IRaise.cs b/Source/Language/IRaise.cs index ec24964ca..ae53e07d8 100644 --- a/Source/Language/IRaise.cs +++ b/Source/Language/IRaise.cs @@ -1,87 +1,87 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] -using System; -using System.ComponentModel; - -namespace Moq.Language -{ - /// - /// Defines the Raises verb. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public partial interface IRaise : IHideObjectMembers - { - /// - /// Specifies the event that will be raised - /// when the setup is met. - /// - /// An expression that represents an event attach or detach action. - /// The event arguments to pass for the raised event. - /// - /// The following example shows how to raise an event when - /// the setup is met: - /// - /// var mock = new Mock<IContainer>(); - /// - /// mock.Setup(add => add.Add(It.IsAny<string>(), It.IsAny<object>())) - /// .Raises(add => add.Added += null, EventArgs.Empty); - /// - /// - IVerifies Raises(Action eventExpression, EventArgs args); - - /// - /// Specifies the event that will be raised - /// when the setup is matched. - /// - /// An expression that represents an event attach or detach action. - /// A function that will build the - /// to pass when raising the event. - /// - IVerifies Raises(Action eventExpression, Func func); - - /// - /// Specifies the custom event that will be raised - /// when the setup is matched. - /// - /// An expression that represents an event attach or detach action. - /// The arguments to pass to the custom delegate (non EventHandler-compatible). - IVerifies Raises(Action eventExpression, params object[] args); - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] +using System; +using System.ComponentModel; + +namespace Moq.Language +{ + /// + /// Defines the Raises verb. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public partial interface IRaise : IHideObjectMembers + { + /// + /// Specifies the event that will be raised + /// when the setup is met. + /// + /// An expression that represents an event attach or detach action. + /// The event arguments to pass for the raised event. + /// + /// The following example shows how to raise an event when + /// the setup is met: + /// + /// var mock = new Mock<IContainer>(); + /// + /// mock.Setup(add => add.Add(It.IsAny<string>(), It.IsAny<object>())) + /// .Raises(add => add.Added += null, EventArgs.Empty); + /// + /// + IVerifies Raises(Action eventExpression, EventArgs args); + + /// + /// Specifies the event that will be raised + /// when the setup is matched. + /// + /// An expression that represents an event attach or detach action. + /// A function that will build the + /// to pass when raising the event. + /// + IVerifies Raises(Action eventExpression, Func func); + + /// + /// Specifies the custom event that will be raised + /// when the setup is matched. + /// + /// An expression that represents an event attach or detach action. + /// The arguments to pass to the custom delegate (non EventHandler-compatible). + IVerifies Raises(Action eventExpression, params object[] args); + } } \ No newline at end of file diff --git a/Source/Language/IRaise.tt b/Source/Language/IRaise.tt index bdb7627b5..c089401e6 100644 --- a/Source/Language/IRaise.tt +++ b/Source/Language/IRaise.tt @@ -1,77 +1,77 @@ -<#@ template debug="false" hostspecific="false" language="C#" #> -<#@ output extension=".Generated.cs" #> -<#@ Assembly Name="System.Core" #> -<#@ Import Namespace="System.Linq" #> -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] -using System; -using System.ComponentModel; - -namespace Moq.Language -{ - partial interface IRaise - { <# -for (var typeCount = 1; typeCount <= GenericTypeMax; typeCount++) -{ - var typeList = GetGenericList(typeCount, GenericTypeFormat); -#> - - /// - /// Specifies the event that will be raised when the setup is matched. - /// - /// The expression that represents an event attach or detach action. - /// The function that will build the - /// to pass when raising the event. -<# - for (var typeIndex = 1; typeIndex <= typeCount; typeIndex++) - { -#> - /// The type of the <#= ConvertToOrdinal(typeIndex) #> argument received by the expected invocation. -<# - } -#> - /// - IVerifies Raises<<#= typeList #>>(Action eventExpression, Func<<#= typeList #>, EventArgs> func); -<# -} -#> - } -} +<#@ template debug="false" hostspecific="false" language="C#" #> +<#@ output extension=".Generated.cs" #> +<#@ Assembly Name="System.Core" #> +<#@ Import Namespace="System.Linq" #> +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] +using System; +using System.ComponentModel; + +namespace Moq.Language +{ + partial interface IRaise + { <# +for (var typeCount = 1; typeCount <= GenericTypeMax; typeCount++) +{ + var typeList = GetGenericList(typeCount, GenericTypeFormat); +#> + + /// + /// Specifies the event that will be raised when the setup is matched. + /// + /// The expression that represents an event attach or detach action. + /// The function that will build the + /// to pass when raising the event. +<# + for (var typeIndex = 1; typeIndex <= typeCount; typeIndex++) + { +#> + /// The type of the <#= ConvertToOrdinal(typeIndex) #> argument received by the expected invocation. +<# + } +#> + /// + IVerifies Raises<<#= typeList #>>(Action eventExpression, Func<<#= typeList #>, EventArgs> func); +<# +} +#> + } +} <#@ Include File="..\Includes\GenericTypeParameters.tt" #> \ No newline at end of file diff --git a/Source/Language/IReturns.Generated.cs b/Source/Language/IReturns.Generated.cs index c5ba7aa8a..cbd2a5094 100644 --- a/Source/Language/IReturns.Generated.cs +++ b/Source/Language/IReturns.Generated.cs @@ -1,604 +1,604 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.ComponentModel; -using Moq.Language.Flow; - -namespace Moq.Language -{ - partial interface IReturns - { - /// - /// Specifies a function that will calculate the value to return from the method, - /// retrieving the arguments for the invocation. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The function that will calculate the return value. - /// Returns a calculated value which is evaluated lazily at the time of the invocation. - /// - /// - /// The return value is calculated from the value of the actual method invocation arguments. - /// Notice how the arguments are retrieved by simply declaring them as part of the lambda - /// expression: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<int>(), - /// It.IsAny<int>())) - /// .Returns((string arg1, string arg2) => arg1 + arg2); - /// - /// - IReturnsResult Returns(Func valueFunction); - - /// - /// Specifies a function that will calculate the value to return from the method, - /// retrieving the arguments for the invocation. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The function that will calculate the return value. - /// Returns a calculated value which is evaluated lazily at the time of the invocation. - /// - /// - /// The return value is calculated from the value of the actual method invocation arguments. - /// Notice how the arguments are retrieved by simply declaring them as part of the lambda - /// expression: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>())) - /// .Returns((string arg1, string arg2, string arg3) => arg1 + arg2 + arg3); - /// - /// - IReturnsResult Returns(Func valueFunction); - - /// - /// Specifies a function that will calculate the value to return from the method, - /// retrieving the arguments for the invocation. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The function that will calculate the return value. - /// Returns a calculated value which is evaluated lazily at the time of the invocation. - /// - /// - /// The return value is calculated from the value of the actual method invocation arguments. - /// Notice how the arguments are retrieved by simply declaring them as part of the lambda - /// expression: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>())) - /// .Returns((string arg1, string arg2, string arg3, string arg4) => arg1 + arg2 + arg3 + arg4); - /// - /// - IReturnsResult Returns(Func valueFunction); - - /// - /// Specifies a function that will calculate the value to return from the method, - /// retrieving the arguments for the invocation. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The function that will calculate the return value. - /// Returns a calculated value which is evaluated lazily at the time of the invocation. - /// - /// - /// The return value is calculated from the value of the actual method invocation arguments. - /// Notice how the arguments are retrieved by simply declaring them as part of the lambda - /// expression: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>())) - /// .Returns((string arg1, string arg2, string arg3, string arg4, string arg5) => arg1 + arg2 + arg3 + arg4 + arg5); - /// - /// - IReturnsResult Returns(Func valueFunction); - - /// - /// Specifies a function that will calculate the value to return from the method, - /// retrieving the arguments for the invocation. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The function that will calculate the return value. - /// Returns a calculated value which is evaluated lazily at the time of the invocation. - /// - /// - /// The return value is calculated from the value of the actual method invocation arguments. - /// Notice how the arguments are retrieved by simply declaring them as part of the lambda - /// expression: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>())) - /// .Returns((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6); - /// - /// - IReturnsResult Returns(Func valueFunction); - - /// - /// Specifies a function that will calculate the value to return from the method, - /// retrieving the arguments for the invocation. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The function that will calculate the return value. - /// Returns a calculated value which is evaluated lazily at the time of the invocation. - /// - /// - /// The return value is calculated from the value of the actual method invocation arguments. - /// Notice how the arguments are retrieved by simply declaring them as part of the lambda - /// expression: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>())) - /// .Returns((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7); - /// - /// - IReturnsResult Returns(Func valueFunction); - - /// - /// Specifies a function that will calculate the value to return from the method, - /// retrieving the arguments for the invocation. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The type of the eighth argument of the invoked method. - /// The function that will calculate the return value. - /// Returns a calculated value which is evaluated lazily at the time of the invocation. - /// - /// - /// The return value is calculated from the value of the actual method invocation arguments. - /// Notice how the arguments are retrieved by simply declaring them as part of the lambda - /// expression: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>())) - /// .Returns((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8); - /// - /// - IReturnsResult Returns(Func valueFunction); - - /// - /// Specifies a function that will calculate the value to return from the method, - /// retrieving the arguments for the invocation. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The type of the eighth argument of the invoked method. - /// The type of the nineth argument of the invoked method. - /// The function that will calculate the return value. - /// Returns a calculated value which is evaluated lazily at the time of the invocation. - /// - /// - /// The return value is calculated from the value of the actual method invocation arguments. - /// Notice how the arguments are retrieved by simply declaring them as part of the lambda - /// expression: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>())) - /// .Returns((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9); - /// - /// - IReturnsResult Returns(Func valueFunction); - - /// - /// Specifies a function that will calculate the value to return from the method, - /// retrieving the arguments for the invocation. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The type of the eighth argument of the invoked method. - /// The type of the nineth argument of the invoked method. - /// The type of the tenth argument of the invoked method. - /// The function that will calculate the return value. - /// Returns a calculated value which is evaluated lazily at the time of the invocation. - /// - /// - /// The return value is calculated from the value of the actual method invocation arguments. - /// Notice how the arguments are retrieved by simply declaring them as part of the lambda - /// expression: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>())) - /// .Returns((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10); - /// - /// - IReturnsResult Returns(Func valueFunction); - - /// - /// Specifies a function that will calculate the value to return from the method, - /// retrieving the arguments for the invocation. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The type of the eighth argument of the invoked method. - /// The type of the nineth argument of the invoked method. - /// The type of the tenth argument of the invoked method. - /// The type of the eleventh argument of the invoked method. - /// The function that will calculate the return value. - /// Returns a calculated value which is evaluated lazily at the time of the invocation. - /// - /// - /// The return value is calculated from the value of the actual method invocation arguments. - /// Notice how the arguments are retrieved by simply declaring them as part of the lambda - /// expression: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>())) - /// .Returns((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11); - /// - /// - IReturnsResult Returns(Func valueFunction); - - /// - /// Specifies a function that will calculate the value to return from the method, - /// retrieving the arguments for the invocation. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The type of the eighth argument of the invoked method. - /// The type of the nineth argument of the invoked method. - /// The type of the tenth argument of the invoked method. - /// The type of the eleventh argument of the invoked method. - /// The type of the twelfth argument of the invoked method. - /// The function that will calculate the return value. - /// Returns a calculated value which is evaluated lazily at the time of the invocation. - /// - /// - /// The return value is calculated from the value of the actual method invocation arguments. - /// Notice how the arguments are retrieved by simply declaring them as part of the lambda - /// expression: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>())) - /// .Returns((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12); - /// - /// - IReturnsResult Returns(Func valueFunction); - - /// - /// Specifies a function that will calculate the value to return from the method, - /// retrieving the arguments for the invocation. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The type of the eighth argument of the invoked method. - /// The type of the nineth argument of the invoked method. - /// The type of the tenth argument of the invoked method. - /// The type of the eleventh argument of the invoked method. - /// The type of the twelfth argument of the invoked method. - /// The type of the thirteenth argument of the invoked method. - /// The function that will calculate the return value. - /// Returns a calculated value which is evaluated lazily at the time of the invocation. - /// - /// - /// The return value is calculated from the value of the actual method invocation arguments. - /// Notice how the arguments are retrieved by simply declaring them as part of the lambda - /// expression: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>())) - /// .Returns((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12, string arg13) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13); - /// - /// - IReturnsResult Returns(Func valueFunction); - - /// - /// Specifies a function that will calculate the value to return from the method, - /// retrieving the arguments for the invocation. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The type of the eighth argument of the invoked method. - /// The type of the nineth argument of the invoked method. - /// The type of the tenth argument of the invoked method. - /// The type of the eleventh argument of the invoked method. - /// The type of the twelfth argument of the invoked method. - /// The type of the thirteenth argument of the invoked method. - /// The type of the fourteenth argument of the invoked method. - /// The function that will calculate the return value. - /// Returns a calculated value which is evaluated lazily at the time of the invocation. - /// - /// - /// The return value is calculated from the value of the actual method invocation arguments. - /// Notice how the arguments are retrieved by simply declaring them as part of the lambda - /// expression: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>())) - /// .Returns((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12, string arg13, string arg14) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14); - /// - /// - IReturnsResult Returns(Func valueFunction); - - /// - /// Specifies a function that will calculate the value to return from the method, - /// retrieving the arguments for the invocation. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The type of the eighth argument of the invoked method. - /// The type of the nineth argument of the invoked method. - /// The type of the tenth argument of the invoked method. - /// The type of the eleventh argument of the invoked method. - /// The type of the twelfth argument of the invoked method. - /// The type of the thirteenth argument of the invoked method. - /// The type of the fourteenth argument of the invoked method. - /// The type of the fifteenth argument of the invoked method. - /// The function that will calculate the return value. - /// Returns a calculated value which is evaluated lazily at the time of the invocation. - /// - /// - /// The return value is calculated from the value of the actual method invocation arguments. - /// Notice how the arguments are retrieved by simply declaring them as part of the lambda - /// expression: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>())) - /// .Returns((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12, string arg13, string arg14, string arg15) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14 + arg15); - /// - /// - IReturnsResult Returns(Func valueFunction); - - /// - /// Specifies a function that will calculate the value to return from the method, - /// retrieving the arguments for the invocation. - /// - /// The type of the first argument of the invoked method. - /// The type of the second argument of the invoked method. - /// The type of the third argument of the invoked method. - /// The type of the fourth argument of the invoked method. - /// The type of the fifth argument of the invoked method. - /// The type of the sixth argument of the invoked method. - /// The type of the seventh argument of the invoked method. - /// The type of the eighth argument of the invoked method. - /// The type of the nineth argument of the invoked method. - /// The type of the tenth argument of the invoked method. - /// The type of the eleventh argument of the invoked method. - /// The type of the twelfth argument of the invoked method. - /// The type of the thirteenth argument of the invoked method. - /// The type of the fourteenth argument of the invoked method. - /// The type of the fifteenth argument of the invoked method. - /// The type of the sixteenth argument of the invoked method. - /// The function that will calculate the return value. - /// Returns a calculated value which is evaluated lazily at the time of the invocation. - /// - /// - /// The return value is calculated from the value of the actual method invocation arguments. - /// Notice how the arguments are retrieved by simply declaring them as part of the lambda - /// expression: - /// - /// - /// mock.Setup(x => x.Execute( - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>(), - /// It.IsAny<int>())) - /// .Returns((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12, string arg13, string arg14, string arg15, string arg16) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14 + arg15 + arg16); - /// - /// - IReturnsResult Returns(Func valueFunction); - } -} +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.ComponentModel; +using Moq.Language.Flow; + +namespace Moq.Language +{ + partial interface IReturns + { + /// + /// Specifies a function that will calculate the value to return from the method, + /// retrieving the arguments for the invocation. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The function that will calculate the return value. + /// Returns a calculated value which is evaluated lazily at the time of the invocation. + /// + /// + /// The return value is calculated from the value of the actual method invocation arguments. + /// Notice how the arguments are retrieved by simply declaring them as part of the lambda + /// expression: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<int>(), + /// It.IsAny<int>())) + /// .Returns((string arg1, string arg2) => arg1 + arg2); + /// + /// + IReturnsResult Returns(Func valueFunction); + + /// + /// Specifies a function that will calculate the value to return from the method, + /// retrieving the arguments for the invocation. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The function that will calculate the return value. + /// Returns a calculated value which is evaluated lazily at the time of the invocation. + /// + /// + /// The return value is calculated from the value of the actual method invocation arguments. + /// Notice how the arguments are retrieved by simply declaring them as part of the lambda + /// expression: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>())) + /// .Returns((string arg1, string arg2, string arg3) => arg1 + arg2 + arg3); + /// + /// + IReturnsResult Returns(Func valueFunction); + + /// + /// Specifies a function that will calculate the value to return from the method, + /// retrieving the arguments for the invocation. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The function that will calculate the return value. + /// Returns a calculated value which is evaluated lazily at the time of the invocation. + /// + /// + /// The return value is calculated from the value of the actual method invocation arguments. + /// Notice how the arguments are retrieved by simply declaring them as part of the lambda + /// expression: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>())) + /// .Returns((string arg1, string arg2, string arg3, string arg4) => arg1 + arg2 + arg3 + arg4); + /// + /// + IReturnsResult Returns(Func valueFunction); + + /// + /// Specifies a function that will calculate the value to return from the method, + /// retrieving the arguments for the invocation. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The function that will calculate the return value. + /// Returns a calculated value which is evaluated lazily at the time of the invocation. + /// + /// + /// The return value is calculated from the value of the actual method invocation arguments. + /// Notice how the arguments are retrieved by simply declaring them as part of the lambda + /// expression: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>())) + /// .Returns((string arg1, string arg2, string arg3, string arg4, string arg5) => arg1 + arg2 + arg3 + arg4 + arg5); + /// + /// + IReturnsResult Returns(Func valueFunction); + + /// + /// Specifies a function that will calculate the value to return from the method, + /// retrieving the arguments for the invocation. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The function that will calculate the return value. + /// Returns a calculated value which is evaluated lazily at the time of the invocation. + /// + /// + /// The return value is calculated from the value of the actual method invocation arguments. + /// Notice how the arguments are retrieved by simply declaring them as part of the lambda + /// expression: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>())) + /// .Returns((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6); + /// + /// + IReturnsResult Returns(Func valueFunction); + + /// + /// Specifies a function that will calculate the value to return from the method, + /// retrieving the arguments for the invocation. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The function that will calculate the return value. + /// Returns a calculated value which is evaluated lazily at the time of the invocation. + /// + /// + /// The return value is calculated from the value of the actual method invocation arguments. + /// Notice how the arguments are retrieved by simply declaring them as part of the lambda + /// expression: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>())) + /// .Returns((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7); + /// + /// + IReturnsResult Returns(Func valueFunction); + + /// + /// Specifies a function that will calculate the value to return from the method, + /// retrieving the arguments for the invocation. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The type of the eighth argument of the invoked method. + /// The function that will calculate the return value. + /// Returns a calculated value which is evaluated lazily at the time of the invocation. + /// + /// + /// The return value is calculated from the value of the actual method invocation arguments. + /// Notice how the arguments are retrieved by simply declaring them as part of the lambda + /// expression: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>())) + /// .Returns((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8); + /// + /// + IReturnsResult Returns(Func valueFunction); + + /// + /// Specifies a function that will calculate the value to return from the method, + /// retrieving the arguments for the invocation. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The type of the eighth argument of the invoked method. + /// The type of the nineth argument of the invoked method. + /// The function that will calculate the return value. + /// Returns a calculated value which is evaluated lazily at the time of the invocation. + /// + /// + /// The return value is calculated from the value of the actual method invocation arguments. + /// Notice how the arguments are retrieved by simply declaring them as part of the lambda + /// expression: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>())) + /// .Returns((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9); + /// + /// + IReturnsResult Returns(Func valueFunction); + + /// + /// Specifies a function that will calculate the value to return from the method, + /// retrieving the arguments for the invocation. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The type of the eighth argument of the invoked method. + /// The type of the nineth argument of the invoked method. + /// The type of the tenth argument of the invoked method. + /// The function that will calculate the return value. + /// Returns a calculated value which is evaluated lazily at the time of the invocation. + /// + /// + /// The return value is calculated from the value of the actual method invocation arguments. + /// Notice how the arguments are retrieved by simply declaring them as part of the lambda + /// expression: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>())) + /// .Returns((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10); + /// + /// + IReturnsResult Returns(Func valueFunction); + + /// + /// Specifies a function that will calculate the value to return from the method, + /// retrieving the arguments for the invocation. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The type of the eighth argument of the invoked method. + /// The type of the nineth argument of the invoked method. + /// The type of the tenth argument of the invoked method. + /// The type of the eleventh argument of the invoked method. + /// The function that will calculate the return value. + /// Returns a calculated value which is evaluated lazily at the time of the invocation. + /// + /// + /// The return value is calculated from the value of the actual method invocation arguments. + /// Notice how the arguments are retrieved by simply declaring them as part of the lambda + /// expression: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>())) + /// .Returns((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11); + /// + /// + IReturnsResult Returns(Func valueFunction); + + /// + /// Specifies a function that will calculate the value to return from the method, + /// retrieving the arguments for the invocation. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The type of the eighth argument of the invoked method. + /// The type of the nineth argument of the invoked method. + /// The type of the tenth argument of the invoked method. + /// The type of the eleventh argument of the invoked method. + /// The type of the twelfth argument of the invoked method. + /// The function that will calculate the return value. + /// Returns a calculated value which is evaluated lazily at the time of the invocation. + /// + /// + /// The return value is calculated from the value of the actual method invocation arguments. + /// Notice how the arguments are retrieved by simply declaring them as part of the lambda + /// expression: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>())) + /// .Returns((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12); + /// + /// + IReturnsResult Returns(Func valueFunction); + + /// + /// Specifies a function that will calculate the value to return from the method, + /// retrieving the arguments for the invocation. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The type of the eighth argument of the invoked method. + /// The type of the nineth argument of the invoked method. + /// The type of the tenth argument of the invoked method. + /// The type of the eleventh argument of the invoked method. + /// The type of the twelfth argument of the invoked method. + /// The type of the thirteenth argument of the invoked method. + /// The function that will calculate the return value. + /// Returns a calculated value which is evaluated lazily at the time of the invocation. + /// + /// + /// The return value is calculated from the value of the actual method invocation arguments. + /// Notice how the arguments are retrieved by simply declaring them as part of the lambda + /// expression: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>())) + /// .Returns((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12, string arg13) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13); + /// + /// + IReturnsResult Returns(Func valueFunction); + + /// + /// Specifies a function that will calculate the value to return from the method, + /// retrieving the arguments for the invocation. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The type of the eighth argument of the invoked method. + /// The type of the nineth argument of the invoked method. + /// The type of the tenth argument of the invoked method. + /// The type of the eleventh argument of the invoked method. + /// The type of the twelfth argument of the invoked method. + /// The type of the thirteenth argument of the invoked method. + /// The type of the fourteenth argument of the invoked method. + /// The function that will calculate the return value. + /// Returns a calculated value which is evaluated lazily at the time of the invocation. + /// + /// + /// The return value is calculated from the value of the actual method invocation arguments. + /// Notice how the arguments are retrieved by simply declaring them as part of the lambda + /// expression: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>())) + /// .Returns((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12, string arg13, string arg14) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14); + /// + /// + IReturnsResult Returns(Func valueFunction); + + /// + /// Specifies a function that will calculate the value to return from the method, + /// retrieving the arguments for the invocation. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The type of the eighth argument of the invoked method. + /// The type of the nineth argument of the invoked method. + /// The type of the tenth argument of the invoked method. + /// The type of the eleventh argument of the invoked method. + /// The type of the twelfth argument of the invoked method. + /// The type of the thirteenth argument of the invoked method. + /// The type of the fourteenth argument of the invoked method. + /// The type of the fifteenth argument of the invoked method. + /// The function that will calculate the return value. + /// Returns a calculated value which is evaluated lazily at the time of the invocation. + /// + /// + /// The return value is calculated from the value of the actual method invocation arguments. + /// Notice how the arguments are retrieved by simply declaring them as part of the lambda + /// expression: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>())) + /// .Returns((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12, string arg13, string arg14, string arg15) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14 + arg15); + /// + /// + IReturnsResult Returns(Func valueFunction); + + /// + /// Specifies a function that will calculate the value to return from the method, + /// retrieving the arguments for the invocation. + /// + /// The type of the first argument of the invoked method. + /// The type of the second argument of the invoked method. + /// The type of the third argument of the invoked method. + /// The type of the fourth argument of the invoked method. + /// The type of the fifth argument of the invoked method. + /// The type of the sixth argument of the invoked method. + /// The type of the seventh argument of the invoked method. + /// The type of the eighth argument of the invoked method. + /// The type of the nineth argument of the invoked method. + /// The type of the tenth argument of the invoked method. + /// The type of the eleventh argument of the invoked method. + /// The type of the twelfth argument of the invoked method. + /// The type of the thirteenth argument of the invoked method. + /// The type of the fourteenth argument of the invoked method. + /// The type of the fifteenth argument of the invoked method. + /// The type of the sixteenth argument of the invoked method. + /// The function that will calculate the return value. + /// Returns a calculated value which is evaluated lazily at the time of the invocation. + /// + /// + /// The return value is calculated from the value of the actual method invocation arguments. + /// Notice how the arguments are retrieved by simply declaring them as part of the lambda + /// expression: + /// + /// + /// mock.Setup(x => x.Execute( + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>(), + /// It.IsAny<int>())) + /// .Returns((string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8, string arg9, string arg10, string arg11, string arg12, string arg13, string arg14, string arg15, string arg16) => arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9 + arg10 + arg11 + arg12 + arg13 + arg14 + arg15 + arg16); + /// + /// + IReturnsResult Returns(Func valueFunction); + } +} diff --git a/Source/Language/IReturns.tt b/Source/Language/IReturns.tt index 40d9b4a0e..6ad941905 100644 --- a/Source/Language/IReturns.tt +++ b/Source/Language/IReturns.tt @@ -1,98 +1,98 @@ -<#@ template debug="false" hostspecific="false" language="C#" #> -<#@ output extension=".Generated.cs" #> -<#@ Assembly Name="System.Core" #> -<#@ Import Namespace="System.Linq" #> -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.ComponentModel; -using Moq.Language.Flow; - -namespace Moq.Language -{ - partial interface IReturns - { <# -for (var typeCount = 2; typeCount <= GenericTypeMax; typeCount++) -{ - var typeList = GetGenericList(typeCount, GenericTypeFormat); -#> - - /// - /// Specifies a function that will calculate the value to return from the method, - /// retrieving the arguments for the invocation. - /// -<# - for (var typeIndex = 1; typeIndex <= typeCount; typeIndex++) - { -#> - /// The type of the <#= ConvertToOrdinal(typeIndex) #> argument of the invoked method. -<# - } -#> - /// The function that will calculate the return value. - /// Returns a calculated value which is evaluated lazily at the time of the invocation. - /// - /// - /// The return value is calculated from the value of the actual method invocation arguments. - /// Notice how the arguments are retrieved by simply declaring them as part of the lambda - /// expression: - /// - /// - /// mock.Setup(x => x.Execute( -<# - for (var typeIndex = 1; typeIndex < typeCount; typeIndex++) - { -#> - /// It.IsAny<int>(), -<# - } -#> - /// It.IsAny<int>())) - /// .Returns((<#= GetGenericList(typeCount, "string arg{0}") #>) => <#= GetGenericList(typeCount, "arg{0}", " + ") #>); - /// - /// - IReturnsResult Returns<<#= typeList #>>(Func<<#= typeList #>, TResult> valueFunction); -<# -} -#> - } -} +<#@ template debug="false" hostspecific="false" language="C#" #> +<#@ output extension=".Generated.cs" #> +<#@ Assembly Name="System.Core" #> +<#@ Import Namespace="System.Linq" #> +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.ComponentModel; +using Moq.Language.Flow; + +namespace Moq.Language +{ + partial interface IReturns + { <# +for (var typeCount = 2; typeCount <= GenericTypeMax; typeCount++) +{ + var typeList = GetGenericList(typeCount, GenericTypeFormat); +#> + + /// + /// Specifies a function that will calculate the value to return from the method, + /// retrieving the arguments for the invocation. + /// +<# + for (var typeIndex = 1; typeIndex <= typeCount; typeIndex++) + { +#> + /// The type of the <#= ConvertToOrdinal(typeIndex) #> argument of the invoked method. +<# + } +#> + /// The function that will calculate the return value. + /// Returns a calculated value which is evaluated lazily at the time of the invocation. + /// + /// + /// The return value is calculated from the value of the actual method invocation arguments. + /// Notice how the arguments are retrieved by simply declaring them as part of the lambda + /// expression: + /// + /// + /// mock.Setup(x => x.Execute( +<# + for (var typeIndex = 1; typeIndex < typeCount; typeIndex++) + { +#> + /// It.IsAny<int>(), +<# + } +#> + /// It.IsAny<int>())) + /// .Returns((<#= GetGenericList(typeCount, "string arg{0}") #>) => <#= GetGenericList(typeCount, "arg{0}", " + ") #>); + /// + /// + IReturnsResult Returns<<#= typeList #>>(Func<<#= typeList #>, TResult> valueFunction); +<# +} +#> + } +} <#@ Include File="..\Includes\GenericTypeParameters.tt" #> \ No newline at end of file diff --git a/Source/Language/ISetupConditionResult.cs b/Source/Language/ISetupConditionResult.cs index 23bf38b64..c3f7c33de 100644 --- a/Source/Language/ISetupConditionResult.cs +++ b/Source/Language/ISetupConditionResult.cs @@ -1,56 +1,56 @@ -using System; -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; -using System.Linq.Expressions; -using Moq.Language.Flow; - -namespace Moq.Language -{ - /// - /// Implements the fluent API. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public interface ISetupConditionResult where T : class - { - /// - /// The expectation will be considered only in the former condition. - /// - /// - /// - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "By design")] - ISetup Setup(Expression> expression); - - /// - /// The expectation will be considered only in the former condition. - /// - /// - /// - /// - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "By design")] - ISetup Setup(Expression> expression); - - /// - /// Setups the get. - /// - /// The type of the property. - /// The expression. - /// - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "By design")] - ISetupGetter SetupGet(Expression> expression); - - /// - /// Setups the set. - /// - /// The type of the property. - /// The setter expression. - /// - ISetupSetter SetupSet(Action setterExpression); - - /// - /// Setups the set. - /// - /// The setter expression. - /// - ISetup SetupSet(Action setterExpression); - } +using System; +using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; +using System.Linq.Expressions; +using Moq.Language.Flow; + +namespace Moq.Language +{ + /// + /// Implements the fluent API. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public interface ISetupConditionResult where T : class + { + /// + /// The expectation will be considered only in the former condition. + /// + /// + /// + [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "By design")] + ISetup Setup(Expression> expression); + + /// + /// The expectation will be considered only in the former condition. + /// + /// + /// + /// + [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "By design")] + ISetup Setup(Expression> expression); + + /// + /// Setups the get. + /// + /// The type of the property. + /// The expression. + /// + [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "By design")] + ISetupGetter SetupGet(Expression> expression); + + /// + /// Setups the set. + /// + /// The type of the property. + /// The setter expression. + /// + ISetupSetter SetupSet(Action setterExpression); + + /// + /// Setups the set. + /// + /// The setter expression. + /// + ISetup SetupSet(Action setterExpression); + } } \ No newline at end of file diff --git a/Source/Language/IThrows.cs b/Source/Language/IThrows.cs index 340241928..6897b3c15 100644 --- a/Source/Language/IThrows.cs +++ b/Source/Language/IThrows.cs @@ -1,83 +1,83 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; -using Moq.Language.Flow; - -namespace Moq.Language -{ - /// - /// Defines the Throws verb. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IThrows : IHideObjectMembers - { - /// - /// Specifies the exception to throw when the method is invoked. - /// - /// Exception instance to throw. - /// - /// This example shows how to throw an exception when the method is - /// invoked with an empty string argument: - /// - /// mock.Setup(x => x.Execute("")) - /// .Throws(new ArgumentException()); - /// - /// - IThrowsResult Throws(Exception exception); - - /// - /// Specifies the type of exception to throw when the method is invoked. - /// - /// Type of exception to instantiate and throw when the setup is matched. - /// - /// This example shows how to throw an exception when the method is - /// invoked with an empty string argument: - /// - /// mock.Setup(x => x.Execute("")) - /// .Throws<ArgumentException>(); - /// - /// - [SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")] - IThrowsResult Throws() where TException : Exception, new(); - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; +using Moq.Language.Flow; + +namespace Moq.Language +{ + /// + /// Defines the Throws verb. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public interface IThrows : IHideObjectMembers + { + /// + /// Specifies the exception to throw when the method is invoked. + /// + /// Exception instance to throw. + /// + /// This example shows how to throw an exception when the method is + /// invoked with an empty string argument: + /// + /// mock.Setup(x => x.Execute("")) + /// .Throws(new ArgumentException()); + /// + /// + IThrowsResult Throws(Exception exception); + + /// + /// Specifies the type of exception to throw when the method is invoked. + /// + /// Type of exception to instantiate and throw when the setup is matched. + /// + /// This example shows how to throw an exception when the method is + /// invoked with an empty string argument: + /// + /// mock.Setup(x => x.Execute("")) + /// .Throws<ArgumentException>(); + /// + /// + [SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")] + IThrowsResult Throws() where TException : Exception, new(); + } } \ No newline at end of file diff --git a/Source/Language/IVerifies.cs b/Source/Language/IVerifies.cs index 81ffddc44..cd3b110f9 100644 --- a/Source/Language/IVerifies.cs +++ b/Source/Language/IVerifies.cs @@ -1,81 +1,81 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System.ComponentModel; - -namespace Moq.Language -{ - /// - /// Defines the Verifiable verb. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IVerifies : IHideObjectMembers - { - /// - /// Marks the expectation as verifiable, meaning that a call - /// to will check if this particular - /// expectation was met. - /// - /// - /// The following example marks the expectation as verifiable: - /// - /// mock.Expect(x => x.Execute("ping")) - /// .Returns(true) - /// .Verifiable(); - /// - /// - void Verifiable(); - - /// - /// Marks the expectation as verifiable, meaning that a call - /// to will check if this particular - /// expectation was met, and specifies a message for failures. - /// - /// - /// The following example marks the expectation as verifiable: - /// - /// mock.Expect(x => x.Execute("ping")) - /// .Returns(true) - /// .Verifiable("Ping should be executed always!"); - /// - /// - void Verifiable(string failMessage); - } -} +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System.ComponentModel; + +namespace Moq.Language +{ + /// + /// Defines the Verifiable verb. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public interface IVerifies : IHideObjectMembers + { + /// + /// Marks the expectation as verifiable, meaning that a call + /// to will check if this particular + /// expectation was met. + /// + /// + /// The following example marks the expectation as verifiable: + /// + /// mock.Expect(x => x.Execute("ping")) + /// .Returns(true) + /// .Verifiable(); + /// + /// + void Verifiable(); + + /// + /// Marks the expectation as verifiable, meaning that a call + /// to will check if this particular + /// expectation was met, and specifies a message for failures. + /// + /// + /// The following example marks the expectation as verifiable: + /// + /// mock.Expect(x => x.Execute("ping")) + /// .Returns(true) + /// .Verifiable("Ping should be executed always!"); + /// + /// + void Verifiable(string failMessage); + } +} diff --git a/Source/Linq/FluentMockVisitor.cs b/Source/Linq/FluentMockVisitor.cs index 8661a9eb5..5863f8881 100644 --- a/Source/Linq/FluentMockVisitor.cs +++ b/Source/Linq/FluentMockVisitor.cs @@ -1,199 +1,199 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Reflection; -using System.Linq.Expressions; -using System.Runtime.CompilerServices; -using System.Diagnostics.CodeAnalysis; - -namespace Moq.Linq -{ - internal class FluentMockVisitor : ExpressionVisitor - { - private static readonly MethodInfo fluentMockGenericMethod = ((Func, Expression>, Mock>) - QueryableMockExtensions.FluentMock).Method.GetGenericMethodDefinition(); - - private static readonly MethodInfo mockGetGenericMethod = ((Func>)Mock.Get) - .Method.GetGenericMethodDefinition(); - - private Expression expression; - - /// - /// The first method call or member access will be the - /// last segment of the expression (depth-first traversal), - /// which is the one we have to Setup rather than FluentMock. - /// And the last one is the one we have to Mock.Get rather - /// than FluentMock. - /// - private bool isFirst = true; - - public FluentMockVisitor(Expression expression) - { - this.expression = expression; - } - - public static Expression Accept(Expression expression) - { - return new FluentMockVisitor(expression).Accept(); - } - - public Expression Accept() - { - return this.Visit(expression); - } - - protected override Expression VisitParameter(ParameterExpression node) - { - if (node == null) - { - return null; - } - - // the actual first object being used in a fluent expression. - return Expression.Call(null, mockGetGenericMethod.MakeGenericMethod(node.Type), node); - } - - protected override Expression VisitMethodCall(MethodCallExpression node) - { - if (node == null) - { - return null; - } - - var lambdaParam = Expression.Parameter(node.Object.Type, "mock"); - var lambdaBody = Expression.Call(lambdaParam, node.Method, node.Arguments); - var targetMethod = GetTargetMethod(node.Object.Type, node.Method.ReturnType); - if (isFirst) - { - isFirst = false; - } - - return TranslateFluent(node.Object.Type, node.Method.ReturnType, targetMethod, Visit(node.Object), lambdaParam, lambdaBody); - } - - protected override Expression VisitMember(MemberExpression node) - { - if (node == null) - { - return null; - } - - // If member is not mock-able, actually, including being a sealed class, etc.? - if (node.Member is FieldInfo) - { - throw new NotSupportedException(); - } - - // Translate differently member accesses over transparent - // compiler-generated types as they are typically the - // anonymous types generated to build up the query expressions. - if (node.Expression.NodeType == ExpressionType.Parameter && - node.Expression.Type.GetCustomAttribute(false) != null) - { - var memberType = ((PropertyInfo)node.Member).PropertyType; - - // Generate a Mock.Get over the entire member access rather. - // .foo => Mock.Get(.foo) - return Expression.Call(null, mockGetGenericMethod.MakeGenericMethod(memberType), node); - } - - var lambdaParam = Expression.Parameter(node.Expression.Type, "mock"); - Expression lambdaBody = Expression.MakeMemberAccess(lambdaParam, node.Member); - var targetMethod = GetTargetMethod(node.Expression.Type, ((PropertyInfo)node.Member).PropertyType); - if (isFirst) - { - isFirst = false; - } - - return TranslateFluent(node.Expression.Type, ((PropertyInfo)node.Member).PropertyType, targetMethod, Visit(node.Expression), lambdaParam, lambdaBody); - } - - // Args like: string IFoo (mock => mock.Value) - private static Expression TranslateFluent( - Type objectType, - Type returnType, - MethodInfo targetMethod, - Expression instance, - ParameterExpression lambdaParam, - Expression lambdaBody) - { - var funcType = typeof(Func<,>).MakeGenericType(objectType, returnType); - - // This is the fluent extension method one, so pass the instance as one more arg. - if (targetMethod.IsStatic) - { - return Expression.Call(targetMethod, instance, Expression.Lambda(funcType, lambdaBody, lambdaParam)); - } - - return Expression.Call(instance, targetMethod, Expression.Lambda(funcType, lambdaBody, lambdaParam)); - } - - private MethodInfo GetTargetMethod(Type objectType, Type returnType) - { - MethodInfo targetMethod; - // dte.Solution => - if (isFirst) - { - //.Setup(mock => mock.Solution) - targetMethod = GetSetupMethod(objectType, returnType); - } - else - { - //.FluentMock(mock => mock.Solution) - targetMethod = fluentMockGenericMethod.MakeGenericMethod(objectType, returnType); - } - - return targetMethod; - } - - private static MethodInfo GetSetupMethod(Type objectType, Type returnType) - { - return typeof(Mock<>) - .MakeGenericType(objectType) - .GetMethods() - .First(mi => mi.Name == "Setup" && mi.IsGenericMethod) - .MakeGenericMethod(returnType); - } - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; +using System.Linq.Expressions; +using System.Runtime.CompilerServices; +using System.Diagnostics.CodeAnalysis; + +namespace Moq.Linq +{ + internal class FluentMockVisitor : ExpressionVisitor + { + private static readonly MethodInfo fluentMockGenericMethod = ((Func, Expression>, Mock>) + QueryableMockExtensions.FluentMock).Method.GetGenericMethodDefinition(); + + private static readonly MethodInfo mockGetGenericMethod = ((Func>)Mock.Get) + .Method.GetGenericMethodDefinition(); + + private Expression expression; + + /// + /// The first method call or member access will be the + /// last segment of the expression (depth-first traversal), + /// which is the one we have to Setup rather than FluentMock. + /// And the last one is the one we have to Mock.Get rather + /// than FluentMock. + /// + private bool isFirst = true; + + public FluentMockVisitor(Expression expression) + { + this.expression = expression; + } + + public static Expression Accept(Expression expression) + { + return new FluentMockVisitor(expression).Accept(); + } + + public Expression Accept() + { + return this.Visit(expression); + } + + protected override Expression VisitParameter(ParameterExpression node) + { + if (node == null) + { + return null; + } + + // the actual first object being used in a fluent expression. + return Expression.Call(null, mockGetGenericMethod.MakeGenericMethod(node.Type), node); + } + + protected override Expression VisitMethodCall(MethodCallExpression node) + { + if (node == null) + { + return null; + } + + var lambdaParam = Expression.Parameter(node.Object.Type, "mock"); + var lambdaBody = Expression.Call(lambdaParam, node.Method, node.Arguments); + var targetMethod = GetTargetMethod(node.Object.Type, node.Method.ReturnType); + if (isFirst) + { + isFirst = false; + } + + return TranslateFluent(node.Object.Type, node.Method.ReturnType, targetMethod, Visit(node.Object), lambdaParam, lambdaBody); + } + + protected override Expression VisitMember(MemberExpression node) + { + if (node == null) + { + return null; + } + + // If member is not mock-able, actually, including being a sealed class, etc.? + if (node.Member is FieldInfo) + { + throw new NotSupportedException(); + } + + // Translate differently member accesses over transparent + // compiler-generated types as they are typically the + // anonymous types generated to build up the query expressions. + if (node.Expression.NodeType == ExpressionType.Parameter && + node.Expression.Type.GetCustomAttribute(false) != null) + { + var memberType = ((PropertyInfo)node.Member).PropertyType; + + // Generate a Mock.Get over the entire member access rather. + // .foo => Mock.Get(.foo) + return Expression.Call(null, mockGetGenericMethod.MakeGenericMethod(memberType), node); + } + + var lambdaParam = Expression.Parameter(node.Expression.Type, "mock"); + Expression lambdaBody = Expression.MakeMemberAccess(lambdaParam, node.Member); + var targetMethod = GetTargetMethod(node.Expression.Type, ((PropertyInfo)node.Member).PropertyType); + if (isFirst) + { + isFirst = false; + } + + return TranslateFluent(node.Expression.Type, ((PropertyInfo)node.Member).PropertyType, targetMethod, Visit(node.Expression), lambdaParam, lambdaBody); + } + + // Args like: string IFoo (mock => mock.Value) + private static Expression TranslateFluent( + Type objectType, + Type returnType, + MethodInfo targetMethod, + Expression instance, + ParameterExpression lambdaParam, + Expression lambdaBody) + { + var funcType = typeof(Func<,>).MakeGenericType(objectType, returnType); + + // This is the fluent extension method one, so pass the instance as one more arg. + if (targetMethod.IsStatic) + { + return Expression.Call(targetMethod, instance, Expression.Lambda(funcType, lambdaBody, lambdaParam)); + } + + return Expression.Call(instance, targetMethod, Expression.Lambda(funcType, lambdaBody, lambdaParam)); + } + + private MethodInfo GetTargetMethod(Type objectType, Type returnType) + { + MethodInfo targetMethod; + // dte.Solution => + if (isFirst) + { + //.Setup(mock => mock.Solution) + targetMethod = GetSetupMethod(objectType, returnType); + } + else + { + //.FluentMock(mock => mock.Solution) + targetMethod = fluentMockGenericMethod.MakeGenericMethod(objectType, returnType); + } + + return targetMethod; + } + + private static MethodInfo GetSetupMethod(Type objectType, Type returnType) + { + return typeof(Mock<>) + .MakeGenericType(objectType) + .GetMethods() + .First(mi => mi.Name == "Setup" && mi.IsGenericMethod) + .MakeGenericMethod(returnType); + } + } } \ No newline at end of file diff --git a/Source/Linq/Mock.cs b/Source/Linq/Mock.cs index 8a5f95f63..1d3586b14 100644 --- a/Source/Linq/Mock.cs +++ b/Source/Linq/Mock.cs @@ -1,75 +1,75 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Linq.Expressions; -using System.Diagnostics.CodeAnalysis; -using Moq.Linq; - -namespace Moq -{ - public partial class Mock - { - /// - /// Creates an mock object of the indicated type. - /// - /// The type of the mocked object. - /// The mocked object created. - public static T Of() where T : class - { - return Mocks.CreateMockQuery().First(); - } - - /// - /// Creates an mock object of the indicated type. - /// - /// The predicate with the specification of how the mocked object should behave. - /// The type of the mocked object. - /// The mocked object created. - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "By Design")] - public static T Of(Expression> predicate) where T : class - { - return Mocks.CreateMockQuery().First(predicate); - } - } -} +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Linq.Expressions; +using System.Diagnostics.CodeAnalysis; +using Moq.Linq; + +namespace Moq +{ + public partial class Mock + { + /// + /// Creates an mock object of the indicated type. + /// + /// The type of the mocked object. + /// The mocked object created. + public static T Of() where T : class + { + return Mocks.CreateMockQuery().First(); + } + + /// + /// Creates an mock object of the indicated type. + /// + /// The predicate with the specification of how the mocked object should behave. + /// The type of the mocked object. + /// The mocked object created. + [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "By Design")] + public static T Of(Expression> predicate) where T : class + { + return Mocks.CreateMockQuery().First(predicate); + } + } +} diff --git a/Source/Linq/MockQuery.cs b/Source/Linq/MockQuery.cs index dee9dc06d..7638c484d 100644 --- a/Source/Linq/MockQuery.cs +++ b/Source/Linq/MockQuery.cs @@ -1,135 +1,135 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using System.Reflection; - -namespace Moq.Linq -{ - /// - /// A default implementation of IQueryable for use with QueryProvider - /// - internal class MockQueryable : IQueryable, IQueryProvider - { - private MethodCallExpression underlyingCreateMocks; - - /// - /// The is a - /// static method that returns an IQueryable of Mocks of T which is used to - /// apply the linq specification to. - /// - public MockQueryable(MethodCallExpression underlyingCreateMocks) - { - Guard.NotNull(() => underlyingCreateMocks, underlyingCreateMocks); - - this.Expression = Expression.Constant(this); - this.underlyingCreateMocks = underlyingCreateMocks; - } - - public MockQueryable(MethodCallExpression underlyingCreateMocks, Expression expression) - { - Guard.NotNull(() => underlyingCreateMocks, underlyingCreateMocks); - Guard.NotNull(() => expression, expression); - Guard.CanBeAssigned(() => expression, expression.Type, typeof(IQueryable)); - - this.underlyingCreateMocks = underlyingCreateMocks; - this.Expression = expression; - } - - public Type ElementType - { - get { return typeof(T); } - } - - public Expression Expression { get; private set; } - - public IQueryProvider Provider - { - get { return this; } - } - - public IQueryable CreateQuery(Expression expression) - { - return this.CreateQuery(expression); - } - - public IQueryable CreateQuery(Expression expression) - { - return new MockQueryable(this.underlyingCreateMocks, expression); - } - - public object Execute(Expression expression) - { - return this.Execute>(expression); - } - - public TResult Execute(Expression expression) - { - var replaced = new MockSetupsBuilder(this.underlyingCreateMocks).Visit(expression); - - var lambda = Expression.Lambda>(replaced); - return lambda.Compile().Invoke(); - } - - public IEnumerator GetEnumerator() - { - return this.Provider.Execute>(this.Expression).GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return this.GetEnumerator(); - } - - public override string ToString() - { - if (this.Expression.NodeType == ExpressionType.Constant && ((ConstantExpression)this.Expression).Value == this) - { - return "Query(" + typeof(T) + ")"; - } - - return this.Expression.ToString(); - } - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; + +namespace Moq.Linq +{ + /// + /// A default implementation of IQueryable for use with QueryProvider + /// + internal class MockQueryable : IQueryable, IQueryProvider + { + private MethodCallExpression underlyingCreateMocks; + + /// + /// The is a + /// static method that returns an IQueryable of Mocks of T which is used to + /// apply the linq specification to. + /// + public MockQueryable(MethodCallExpression underlyingCreateMocks) + { + Guard.NotNull(() => underlyingCreateMocks, underlyingCreateMocks); + + this.Expression = Expression.Constant(this); + this.underlyingCreateMocks = underlyingCreateMocks; + } + + public MockQueryable(MethodCallExpression underlyingCreateMocks, Expression expression) + { + Guard.NotNull(() => underlyingCreateMocks, underlyingCreateMocks); + Guard.NotNull(() => expression, expression); + Guard.CanBeAssigned(() => expression, expression.Type, typeof(IQueryable)); + + this.underlyingCreateMocks = underlyingCreateMocks; + this.Expression = expression; + } + + public Type ElementType + { + get { return typeof(T); } + } + + public Expression Expression { get; private set; } + + public IQueryProvider Provider + { + get { return this; } + } + + public IQueryable CreateQuery(Expression expression) + { + return this.CreateQuery(expression); + } + + public IQueryable CreateQuery(Expression expression) + { + return new MockQueryable(this.underlyingCreateMocks, expression); + } + + public object Execute(Expression expression) + { + return this.Execute>(expression); + } + + public TResult Execute(Expression expression) + { + var replaced = new MockSetupsBuilder(this.underlyingCreateMocks).Visit(expression); + + var lambda = Expression.Lambda>(replaced); + return lambda.Compile().Invoke(); + } + + public IEnumerator GetEnumerator() + { + return this.Provider.Execute>(this.Expression).GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return this.GetEnumerator(); + } + + public override string ToString() + { + if (this.Expression.NodeType == ExpressionType.Constant && ((ConstantExpression)this.Expression).Value == this) + { + return "Query(" + typeof(T) + ")"; + } + + return this.Expression.ToString(); + } + } } \ No newline at end of file diff --git a/Source/Linq/MockRepository.cs b/Source/Linq/MockRepository.cs index ce5ce08e9..2155c7d09 100644 --- a/Source/Linq/MockRepository.cs +++ b/Source/Linq/MockRepository.cs @@ -1,99 +1,99 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Diagnostics.CodeAnalysis; -using System.ComponentModel; -using System.Linq.Expressions; -using Moq.Linq; -using System.Reflection; - -namespace Moq -{ -#pragma warning disable 618 - public partial class MockRepository - { -#pragma warning restore 618 - - /// - /// Access the universe of mocks of the given type, to retrieve those - /// that behave according to the LINQ query specification. - /// - /// The type of the mocked object to query. - public IQueryable Of() where T : class - { - return CreateMockQuery(); - } - - /// - /// Access the universe of mocks of the given type, to retrieve those - /// that behave according to the LINQ query specification. - /// - /// The predicate with the setup expressions. - /// The type of the mocked object to query. - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "By design")] - public IQueryable Of(Expression> specification) where T : class - { - return CreateMockQuery().Where(specification); - } - - /// - /// Creates an mock object of the indicated type. - /// - /// The type of the mocked object. - /// The mocked object created. - [EditorBrowsable(EditorBrowsableState.Never)] - public T OneOf() where T : class - { - return CreateMockQuery().First(); - } - - /// - /// Creates an mock object of the indicated type. - /// - /// The predicate with the setup expressions. - /// The type of the mocked object. - /// The mocked object created. - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "By Design")] - [EditorBrowsable(EditorBrowsableState.Never)] - public T OneOf(Expression> specification) where T : class - { - return CreateMockQuery().First(specification); - } - - /// - /// Creates the mock query with the underlying queriable implementation. - /// - internal IQueryable CreateMockQuery() where T : class - { - return new MockQueryable(Expression.Call( - Expression.Constant(this), - ((Func>)CreateQueryable).Method)); - } - - /// - /// Wraps the enumerator inside a queryable. - /// - internal IQueryable CreateQueryable() where T : class - { - return CreateMocks().AsQueryable(); - } - - /// - /// Method that is turned into the actual call from .Query{T}, to - /// transform the queryable query into a normal enumerable query. - /// This method is never used directly by consumers. - /// - private IEnumerable CreateMocks() where T : class - { - do - { - var mock = this.Create(); - mock.SetupAllProperties(); - - yield return mock.Object; - } - while (true); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Diagnostics.CodeAnalysis; +using System.ComponentModel; +using System.Linq.Expressions; +using Moq.Linq; +using System.Reflection; + +namespace Moq +{ +#pragma warning disable 618 + public partial class MockRepository + { +#pragma warning restore 618 + + /// + /// Access the universe of mocks of the given type, to retrieve those + /// that behave according to the LINQ query specification. + /// + /// The type of the mocked object to query. + public IQueryable Of() where T : class + { + return CreateMockQuery(); + } + + /// + /// Access the universe of mocks of the given type, to retrieve those + /// that behave according to the LINQ query specification. + /// + /// The predicate with the setup expressions. + /// The type of the mocked object to query. + [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "By design")] + public IQueryable Of(Expression> specification) where T : class + { + return CreateMockQuery().Where(specification); + } + + /// + /// Creates an mock object of the indicated type. + /// + /// The type of the mocked object. + /// The mocked object created. + [EditorBrowsable(EditorBrowsableState.Never)] + public T OneOf() where T : class + { + return CreateMockQuery().First(); + } + + /// + /// Creates an mock object of the indicated type. + /// + /// The predicate with the setup expressions. + /// The type of the mocked object. + /// The mocked object created. + [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "By Design")] + [EditorBrowsable(EditorBrowsableState.Never)] + public T OneOf(Expression> specification) where T : class + { + return CreateMockQuery().First(specification); + } + + /// + /// Creates the mock query with the underlying queriable implementation. + /// + internal IQueryable CreateMockQuery() where T : class + { + return new MockQueryable(Expression.Call( + Expression.Constant(this), + ((Func>)CreateQueryable).Method)); + } + + /// + /// Wraps the enumerator inside a queryable. + /// + internal IQueryable CreateQueryable() where T : class + { + return CreateMocks().AsQueryable(); + } + + /// + /// Method that is turned into the actual call from .Query{T}, to + /// transform the queryable query into a normal enumerable query. + /// This method is never used directly by consumers. + /// + private IEnumerable CreateMocks() where T : class + { + do + { + var mock = this.Create(); + mock.SetupAllProperties(); + + yield return mock.Object; + } + while (true); + } + } +} diff --git a/Source/Linq/Mocks.cs b/Source/Linq/Mocks.cs index c91a55c83..9fd6bc4ab 100644 --- a/Source/Linq/Mocks.cs +++ b/Source/Linq/Mocks.cs @@ -1,215 +1,215 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; -using System.Globalization; -using System.Linq; -using System.Linq.Expressions; -using System.Reflection; -using Moq.Linq; -using Moq.Properties; - -namespace Moq -{ - /// - /// Allows querying the universe of mocks for those that behave - /// according to the LINQ query specification. - /// - /// - /// This entry-point into Linq to Mocks is the only one in the root Moq - /// namespace to ease discovery. But to get all the mocking extension - /// methods on Object, a using of Moq.Linq must be done, so that the - /// polluting of the intellisense for all objects is an explicit opt-in. - /// - public static class Mocks - { - /// - /// Access the universe of mocks of the given type, to retrieve those - /// that behave according to the LINQ query specification. - /// - /// The type of the mocked object to query. - public static IQueryable Of() where T : class - { - return CreateMockQuery(); - } - - /// - /// Access the universe of mocks of the given type, to retrieve those - /// that behave according to the LINQ query specification. - /// - /// The predicate with the setup expressions. - /// The type of the mocked object to query. - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "By design")] - public static IQueryable Of(Expression> specification) where T : class - { - return CreateMockQuery().Where(specification); - } - - /// - /// Creates an mock object of the indicated type. - /// - /// The type of the mocked object. - /// The mocked object created. - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("Moved to Mock.Of, as it's a single one, so no reason to be on Mocks.", true)] - public static T OneOf() where T : class - { - return CreateMockQuery().First(); - } - - /// - /// Creates an mock object of the indicated type. - /// - /// The predicate with the setup expressions. - /// The type of the mocked object. - /// The mocked object created. - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "By Design")] - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("Moved to Mock.Of, as it's a single one, so no reason to be on Mocks.", true)] - public static T OneOf(Expression> specification) where T : class - { - return CreateMockQuery().First(specification); - } - - /// - /// Creates the mock query with the underlying queriable implementation. - /// - internal static IQueryable CreateMockQuery() where T : class - { - return new MockQueryable(Expression.Call(null, - ((Func>)CreateQueryable).Method)); - } - - /// - /// Wraps the enumerator inside a queryable. - /// - internal static IQueryable CreateQueryable() where T : class - { - return CreateMocks().AsQueryable(); - } - - /// - /// Method that is turned into the actual call from .Query{T}, to - /// transform the queryable query into a normal enumerable query. - /// This method is never used directly by consumers. - /// - private static IEnumerable CreateMocks() where T : class - { - do - { - var mock = new Mock(); - mock.SetupAllProperties(); - - yield return mock.Object; - } - while (true); - } - - /// - /// Extension method used to support Linq-like setup properties that are not virtual but do have - /// a getter and a setter, thereby allowing the use of Linq to Mocks to quickly initialize Dtos too :) - /// - internal static bool SetPropery(Mock target, Expression> propertyReference, TResult value) - where T : class - { - var memberExpr = (MemberExpression)propertyReference.Body; - var member = (PropertyInfo)memberExpr.Member; - - member.SetValue(target.Object, value, null); - - return true; - } - } - - /// - /// Helper extensions that are used by the query translator. - /// - internal static class QueryableMockExtensions - { - /// - /// Retrieves a fluent mock from the given setup expression. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] - public static Mock FluentMock(this Mock mock, Expression> setup) - where T : class - where TResult : class - { - Guard.NotNull(() => mock, mock); - Guard.NotNull(() => setup, setup); - typeof(TResult).ThrowIfNotMockeable(); - - MethodInfo info; - if (setup.Body.NodeType == ExpressionType.MemberAccess) - { - var memberExpr = ((MemberExpression)setup.Body); - memberExpr.ThrowIfNotMockeable(); - - info = ((PropertyInfo)memberExpr.Member).GetGetMethod(); - } - else if (setup.Body.NodeType == ExpressionType.Call) - { - info = ((MethodCallExpression)setup.Body).Method; - } - else - { - throw new NotSupportedException("Unsupported expression: " + setup.ToStringFixed()); - } - - info.ReturnType.ThrowIfNotMockeable(); - - Mock fluentMock; - if (!mock.InnerMocks.TryGetValue(info, out fluentMock)) - { - fluentMock = ((IMocked)new MockDefaultValueProvider(mock).ProvideDefault(info)).Mock; - Mock.SetupAllProperties(fluentMock); - } - - var result = (TResult)fluentMock.Object; - - mock.Setup(setup).Returns(result); - - return (Mock)fluentMock; - } - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using Moq.Linq; +using Moq.Properties; + +namespace Moq +{ + /// + /// Allows querying the universe of mocks for those that behave + /// according to the LINQ query specification. + /// + /// + /// This entry-point into Linq to Mocks is the only one in the root Moq + /// namespace to ease discovery. But to get all the mocking extension + /// methods on Object, a using of Moq.Linq must be done, so that the + /// polluting of the intellisense for all objects is an explicit opt-in. + /// + public static class Mocks + { + /// + /// Access the universe of mocks of the given type, to retrieve those + /// that behave according to the LINQ query specification. + /// + /// The type of the mocked object to query. + public static IQueryable Of() where T : class + { + return CreateMockQuery(); + } + + /// + /// Access the universe of mocks of the given type, to retrieve those + /// that behave according to the LINQ query specification. + /// + /// The predicate with the setup expressions. + /// The type of the mocked object to query. + [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "By design")] + public static IQueryable Of(Expression> specification) where T : class + { + return CreateMockQuery().Where(specification); + } + + /// + /// Creates an mock object of the indicated type. + /// + /// The type of the mocked object. + /// The mocked object created. + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("Moved to Mock.Of, as it's a single one, so no reason to be on Mocks.", true)] + public static T OneOf() where T : class + { + return CreateMockQuery().First(); + } + + /// + /// Creates an mock object of the indicated type. + /// + /// The predicate with the setup expressions. + /// The type of the mocked object. + /// The mocked object created. + [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "By Design")] + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("Moved to Mock.Of, as it's a single one, so no reason to be on Mocks.", true)] + public static T OneOf(Expression> specification) where T : class + { + return CreateMockQuery().First(specification); + } + + /// + /// Creates the mock query with the underlying queriable implementation. + /// + internal static IQueryable CreateMockQuery() where T : class + { + return new MockQueryable(Expression.Call(null, + ((Func>)CreateQueryable).Method)); + } + + /// + /// Wraps the enumerator inside a queryable. + /// + internal static IQueryable CreateQueryable() where T : class + { + return CreateMocks().AsQueryable(); + } + + /// + /// Method that is turned into the actual call from .Query{T}, to + /// transform the queryable query into a normal enumerable query. + /// This method is never used directly by consumers. + /// + private static IEnumerable CreateMocks() where T : class + { + do + { + var mock = new Mock(); + mock.SetupAllProperties(); + + yield return mock.Object; + } + while (true); + } + + /// + /// Extension method used to support Linq-like setup properties that are not virtual but do have + /// a getter and a setter, thereby allowing the use of Linq to Mocks to quickly initialize Dtos too :) + /// + internal static bool SetPropery(Mock target, Expression> propertyReference, TResult value) + where T : class + { + var memberExpr = (MemberExpression)propertyReference.Body; + var member = (PropertyInfo)memberExpr.Member; + + member.SetValue(target.Object, value, null); + + return true; + } + } + + /// + /// Helper extensions that are used by the query translator. + /// + internal static class QueryableMockExtensions + { + /// + /// Retrieves a fluent mock from the given setup expression. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] + public static Mock FluentMock(this Mock mock, Expression> setup) + where T : class + where TResult : class + { + Guard.NotNull(() => mock, mock); + Guard.NotNull(() => setup, setup); + typeof(TResult).ThrowIfNotMockeable(); + + MethodInfo info; + if (setup.Body.NodeType == ExpressionType.MemberAccess) + { + var memberExpr = ((MemberExpression)setup.Body); + memberExpr.ThrowIfNotMockeable(); + + info = ((PropertyInfo)memberExpr.Member).GetGetMethod(); + } + else if (setup.Body.NodeType == ExpressionType.Call) + { + info = ((MethodCallExpression)setup.Body).Method; + } + else + { + throw new NotSupportedException("Unsupported expression: " + setup.ToStringFixed()); + } + + info.ReturnType.ThrowIfNotMockeable(); + + Mock fluentMock; + if (!mock.InnerMocks.TryGetValue(info, out fluentMock)) + { + fluentMock = ((IMocked)new MockDefaultValueProvider(mock).ProvideDefault(info)).Mock; + Mock.SetupAllProperties(fluentMock); + } + + var result = (TResult)fluentMock.Object; + + mock.Setup(setup).Returns(result); + + return (Mock)fluentMock; + } + } } \ No newline at end of file diff --git a/Source/Match.cs b/Source/Match.cs index ca673baaf..c7567c4e2 100644 --- a/Source/Match.cs +++ b/Source/Match.cs @@ -1,135 +1,135 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; -using System.Linq.Expressions; -using System.Reflection; - -namespace Moq -{ - /// - public abstract class Match - { - /// - /// Provided for the sole purpose of rendering the delegate passed to the - /// matcher constructor if no friendly render lambda is provided. - /// - internal static TValue Matcher() - { - return default(TValue); - } - - internal abstract bool Matches(object value); - - internal Expression RenderExpression { get; set; } - - /// - public static T Create(Predicate condition) - { - SetLastMatch(new Match(condition)); - return default(T); - } - - /// - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] - public static T Create(Predicate condition, Expression> renderExpression) - { - SetLastMatch(new Match(condition, renderExpression)); - return default(T); - } - - /// - /// This method is used to set an expression as the last matcher invoked, - /// which is used in the SetupSet to allow matchers in the prop = value - /// delegate expression. This delegate is executed in "fluent" mode in - /// order to capture the value being set, and construct the corresponding - /// methodcall. - /// This is also used in the MatcherFactory for each argument expression. - /// This method ensures that when we execute the delegate, we - /// also track the matcher that was invoked, so that when we create the - /// methodcall we build the expression using it, rather than the null/default - /// value returned from the actual invocation. - /// - private static Match SetLastMatch(Match match) - { - if (FluentMockContext.IsActive) - { - FluentMockContext.Current.LastMatch = match; - } - - return match; - } - } - - /// - public class Match : Match - { - private static readonly Expression> defaultRender = Expression.Lambda>( - Expression.Call( - typeof(Match) - .GetMethod("Matcher", BindingFlags.Static | BindingFlags.NonPublic) - .MakeGenericMethod(typeof(T)))); - - internal Predicate Condition { get; set; } - - internal Match(Predicate condition, Expression> renderExpression) - { - this.Condition = condition; - this.RenderExpression = renderExpression.Body; - } - - internal Match(Predicate condition) - : this(condition, defaultRender) - { - } - - internal override bool Matches(object value) - { - if (value != null && !(value is T)) - { - return false; - } - - return this.Condition((T)value); - } - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; +using System.Linq.Expressions; +using System.Reflection; + +namespace Moq +{ + /// + public abstract class Match + { + /// + /// Provided for the sole purpose of rendering the delegate passed to the + /// matcher constructor if no friendly render lambda is provided. + /// + internal static TValue Matcher() + { + return default(TValue); + } + + internal abstract bool Matches(object value); + + internal Expression RenderExpression { get; set; } + + /// + public static T Create(Predicate condition) + { + SetLastMatch(new Match(condition)); + return default(T); + } + + /// + [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] + public static T Create(Predicate condition, Expression> renderExpression) + { + SetLastMatch(new Match(condition, renderExpression)); + return default(T); + } + + /// + /// This method is used to set an expression as the last matcher invoked, + /// which is used in the SetupSet to allow matchers in the prop = value + /// delegate expression. This delegate is executed in "fluent" mode in + /// order to capture the value being set, and construct the corresponding + /// methodcall. + /// This is also used in the MatcherFactory for each argument expression. + /// This method ensures that when we execute the delegate, we + /// also track the matcher that was invoked, so that when we create the + /// methodcall we build the expression using it, rather than the null/default + /// value returned from the actual invocation. + /// + private static Match SetLastMatch(Match match) + { + if (FluentMockContext.IsActive) + { + FluentMockContext.Current.LastMatch = match; + } + + return match; + } + } + + /// + public class Match : Match + { + private static readonly Expression> defaultRender = Expression.Lambda>( + Expression.Call( + typeof(Match) + .GetMethod("Matcher", BindingFlags.Static | BindingFlags.NonPublic) + .MakeGenericMethod(typeof(T)))); + + internal Predicate Condition { get; set; } + + internal Match(Predicate condition, Expression> renderExpression) + { + this.Condition = condition; + this.RenderExpression = renderExpression.Body; + } + + internal Match(Predicate condition) + : this(condition, defaultRender) + { + } + + internal override bool Matches(object value) + { + if (value != null && !(value is T)) + { + return false; + } + + return this.Condition((T)value); + } + } } \ No newline at end of file diff --git a/Source/Match.xdoc b/Source/Match.xdoc index 7e75b7469..698d1f859 100644 --- a/Source/Match.xdoc +++ b/Source/Match.xdoc @@ -1,94 +1,94 @@ - - - - - Allows creation custom value matchers that can be used on setups and verification, - completely replacing the built-in class with your own argument - matching rules. - - - See also . - - - - - Allows creation custom value matchers that can be used on setups and verification, - completely replacing the built-in class with your own argument - matching rules. - - Type of the value to match. - - The argument matching is used to determine whether a concrete - invocation in the mock matches a given setup. This - matching mechanism is fully extensible. - - - Creating a custom matcher is straightforward. You just need to create a method - that returns a value from a call to with - your matching condition and optional friendly render expression: - - [Matcher] - public Order IsBigOrder() - { - return Match<Order>.Create( - o => o.GrandTotal >= 5000, - /* a friendly expression to render on failures */ - () => IsBigOrder()); - } - - This method can be used in any mock setup invocation: - - mock.Setup(m => m.Submit(IsBigOrder()).Throws<UnauthorizedAccessException>(); - - At runtime, Moq knows that the return value was a matcher (note that the method MUST be - annotated with the [Matcher] attribute in order to determine this) and - evaluates your predicate with the actual value passed into your predicate. - - Another example might be a case where you want to match a lists of orders - that contains a particular one. You might create matcher like the following: - - - public static class Orders - { - [Matcher] - public static IEnumerable<Order> Contains(Order order) - { - return Match<IEnumerable<Order>>.Create(orders => orders.Contains(order)); - } - } - - Now we can invoke this static method instead of an argument in an - invocation: - - var order = new Order { ... }; - var mock = new Mock<IRepository<Order>>(); - - mock.Setup(x => x.Save(Orders.Contains(order))) - .Throws<ArgumentException>(); - - - - - - Initializes the match with the condition that - will be checked in order to match invocation - values. - - The condition to match against actual values. - - - - - - - Initializes the match with the condition that - will be checked in order to match invocation - values. - - The condition to match against actual values. - A lambda representation of the matcher, to be used - when rendering error messages, such as () => It.IsAny<string<(). - - - + + + + + Allows creation custom value matchers that can be used on setups and verification, + completely replacing the built-in class with your own argument + matching rules. + + + See also . + + + + + Allows creation custom value matchers that can be used on setups and verification, + completely replacing the built-in class with your own argument + matching rules. + + Type of the value to match. + + The argument matching is used to determine whether a concrete + invocation in the mock matches a given setup. This + matching mechanism is fully extensible. + + + Creating a custom matcher is straightforward. You just need to create a method + that returns a value from a call to with + your matching condition and optional friendly render expression: + + [Matcher] + public Order IsBigOrder() + { + return Match<Order>.Create( + o => o.GrandTotal >= 5000, + /* a friendly expression to render on failures */ + () => IsBigOrder()); + } + + This method can be used in any mock setup invocation: + + mock.Setup(m => m.Submit(IsBigOrder()).Throws<UnauthorizedAccessException>(); + + At runtime, Moq knows that the return value was a matcher (note that the method MUST be + annotated with the [Matcher] attribute in order to determine this) and + evaluates your predicate with the actual value passed into your predicate. + + Another example might be a case where you want to match a lists of orders + that contains a particular one. You might create matcher like the following: + + + public static class Orders + { + [Matcher] + public static IEnumerable<Order> Contains(Order order) + { + return Match<IEnumerable<Order>>.Create(orders => orders.Contains(order)); + } + } + + Now we can invoke this static method instead of an argument in an + invocation: + + var order = new Order { ... }; + var mock = new Mock<IRepository<Order>>(); + + mock.Setup(x => x.Save(Orders.Contains(order))) + .Throws<ArgumentException>(); + + + + + + Initializes the match with the condition that + will be checked in order to match invocation + values. + + The condition to match against actual values. + + + + + + + Initializes the match with the condition that + will be checked in order to match invocation + values. + + The condition to match against actual values. + A lambda representation of the matcher, to be used + when rendering error messages, such as () => It.IsAny<string<(). + + + \ No newline at end of file diff --git a/Source/MatchExpression.cs b/Source/MatchExpression.cs index 7db9b26c5..feecfe022 100644 --- a/Source/MatchExpression.cs +++ b/Source/MatchExpression.cs @@ -1,70 +1,70 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Linq.Expressions; - -namespace Moq -{ - internal class MatchExpression : Expression - { - public MatchExpression(Match match) -#if NET3x - : base(ExpressionType.Call, typeof(Match)) -#endif - { - this.Match = match; - } - -#if !NET3x - public override ExpressionType NodeType - { - get { return ExpressionType.Call; } - } - - public override Type Type - { - get { return typeof(Match); } - } -#endif - - public Match Match { get; private set; } - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Linq.Expressions; + +namespace Moq +{ + internal class MatchExpression : Expression + { + public MatchExpression(Match match) +#if NET3x + : base(ExpressionType.Call, typeof(Match)) +#endif + { + this.Match = match; + } + +#if !NET3x + public override ExpressionType NodeType + { + get { return ExpressionType.Call; } + } + + public override Type Type + { + get { return typeof(Match); } + } +#endif + + public Match Match { get; private set; } + } } \ No newline at end of file diff --git a/Source/MatcherAttribute.cs b/Source/MatcherAttribute.cs index 5d6684f15..2fdbe22d5 100644 --- a/Source/MatcherAttribute.cs +++ b/Source/MatcherAttribute.cs @@ -1,163 +1,163 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.ComponentModel; - -namespace Moq -{ - /// - /// Marks a method as a matcher, which allows complete replacement - /// of the built-in class with your own argument - /// matching rules. - /// - /// - /// This feature has been deprecated in favor of the new - /// and simpler . - /// - /// - /// The argument matching is used to determine whether a concrete - /// invocation in the mock matches a given setup. This - /// matching mechanism is fully extensible. - /// - /// - /// There are two parts of a matcher: the compiler matcher - /// and the runtime matcher. - /// - /// - /// Compiler matcher - /// Used to satisfy the compiler requirements for the - /// argument. Needs to be a method optionally receiving any arguments - /// you might need for the matching, but with a return type that - /// matches that of the argument. - /// - /// Let's say I want to match a lists of orders that contains - /// a particular one. I might create a compiler matcher like the following: - /// - /// - /// public static class Orders - /// { - /// [Matcher] - /// public static IEnumerable<Order> Contains(Order order) - /// { - /// return null; - /// } - /// } - /// - /// Now we can invoke this static method instead of an argument in an - /// invocation: - /// - /// var order = new Order { ... }; - /// var mock = new Mock<IRepository<Order>>(); - /// - /// mock.Setup(x => x.Save(Orders.Contains(order))) - /// .Throws<ArgumentException>(); - /// - /// Note that the return value from the compiler matcher is irrelevant. - /// This method will never be called, and is just used to satisfy the - /// compiler and to signal Moq that this is not a method that we want - /// to be invoked at runtime. - /// - /// - /// - /// Runtime matcher - /// - /// The runtime matcher is the one that will actually perform evaluation - /// when the test is run, and is defined by convention to have the - /// same signature as the compiler matcher, but where the return - /// value is the first argument to the call, which contains the - /// object received by the actual invocation at runtime: - /// - /// public static bool Contains(IEnumerable<Order> orders, Order order) - /// { - /// return orders.Contains(order); - /// } - /// - /// At runtime, the mocked method will be invoked with a specific - /// list of orders. This value will be passed to this runtime - /// matcher as the first argument, while the second argument is the - /// one specified in the setup (x.Save(Orders.Contains(order))). - /// - /// The boolean returned determines whether the given argument has been - /// matched. If all arguments to the expected method are matched, then - /// the setup matches and is evaluated. - /// - /// - /// - /// - /// - /// Using this extensible infrastructure, you can easily replace the entire - /// set of matchers with your own. You can also avoid the - /// typical (and annoying) lengthy expressions that result when you have - /// multiple arguments that use generics. - /// - /// - /// The following is the complete example explained above: - /// - /// public static class Orders - /// { - /// [Matcher] - /// public static IEnumerable<Order> Contains(Order order) - /// { - /// return null; - /// } - /// - /// public static bool Contains(IEnumerable<Order> orders, Order order) - /// { - /// return orders.Contains(order); - /// } - /// } - /// - /// And the concrete test using this matcher: - /// - /// var order = new Order { ... }; - /// var mock = new Mock<IRepository<Order>>(); - /// - /// mock.Setup(x => x.Save(Orders.Contains(order))) - /// .Throws<ArgumentException>(); - /// - /// // use mock, invoke Save, and have the matcher filter. - /// - /// - [AttributeUsage(AttributeTargets.Method, Inherited = true)] - public sealed class MatcherAttribute : Attribute - { - } -} +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.ComponentModel; + +namespace Moq +{ + /// + /// Marks a method as a matcher, which allows complete replacement + /// of the built-in class with your own argument + /// matching rules. + /// + /// + /// This feature has been deprecated in favor of the new + /// and simpler . + /// + /// + /// The argument matching is used to determine whether a concrete + /// invocation in the mock matches a given setup. This + /// matching mechanism is fully extensible. + /// + /// + /// There are two parts of a matcher: the compiler matcher + /// and the runtime matcher. + /// + /// + /// Compiler matcher + /// Used to satisfy the compiler requirements for the + /// argument. Needs to be a method optionally receiving any arguments + /// you might need for the matching, but with a return type that + /// matches that of the argument. + /// + /// Let's say I want to match a lists of orders that contains + /// a particular one. I might create a compiler matcher like the following: + /// + /// + /// public static class Orders + /// { + /// [Matcher] + /// public static IEnumerable<Order> Contains(Order order) + /// { + /// return null; + /// } + /// } + /// + /// Now we can invoke this static method instead of an argument in an + /// invocation: + /// + /// var order = new Order { ... }; + /// var mock = new Mock<IRepository<Order>>(); + /// + /// mock.Setup(x => x.Save(Orders.Contains(order))) + /// .Throws<ArgumentException>(); + /// + /// Note that the return value from the compiler matcher is irrelevant. + /// This method will never be called, and is just used to satisfy the + /// compiler and to signal Moq that this is not a method that we want + /// to be invoked at runtime. + /// + /// + /// + /// Runtime matcher + /// + /// The runtime matcher is the one that will actually perform evaluation + /// when the test is run, and is defined by convention to have the + /// same signature as the compiler matcher, but where the return + /// value is the first argument to the call, which contains the + /// object received by the actual invocation at runtime: + /// + /// public static bool Contains(IEnumerable<Order> orders, Order order) + /// { + /// return orders.Contains(order); + /// } + /// + /// At runtime, the mocked method will be invoked with a specific + /// list of orders. This value will be passed to this runtime + /// matcher as the first argument, while the second argument is the + /// one specified in the setup (x.Save(Orders.Contains(order))). + /// + /// The boolean returned determines whether the given argument has been + /// matched. If all arguments to the expected method are matched, then + /// the setup matches and is evaluated. + /// + /// + /// + /// + /// + /// Using this extensible infrastructure, you can easily replace the entire + /// set of matchers with your own. You can also avoid the + /// typical (and annoying) lengthy expressions that result when you have + /// multiple arguments that use generics. + /// + /// + /// The following is the complete example explained above: + /// + /// public static class Orders + /// { + /// [Matcher] + /// public static IEnumerable<Order> Contains(Order order) + /// { + /// return null; + /// } + /// + /// public static bool Contains(IEnumerable<Order> orders, Order order) + /// { + /// return orders.Contains(order); + /// } + /// } + /// + /// And the concrete test using this matcher: + /// + /// var order = new Order { ... }; + /// var mock = new Mock<IRepository<Order>>(); + /// + /// mock.Setup(x => x.Save(Orders.Contains(order))) + /// .Throws<ArgumentException>(); + /// + /// // use mock, invoke Save, and have the matcher filter. + /// + /// + [AttributeUsage(AttributeTargets.Method, Inherited = true)] + public sealed class MatcherAttribute : Attribute + { + } +} diff --git a/Source/MatcherFactory.cs b/Source/MatcherFactory.cs index 2ae048921..7bb05d4ce 100644 --- a/Source/MatcherFactory.cs +++ b/Source/MatcherFactory.cs @@ -1,147 +1,147 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Globalization; -using System.Linq.Expressions; -using Moq.Properties; -using Moq.Matchers; - -namespace Moq -{ - internal static class MatcherFactory - { - public static IMatcher CreateMatcher(Expression expression, bool isParams) - { - // Type inference on the call might - // do automatic conversion to the desired - // method argument type, and a Convert expression type - // might be the topmost instead. - // i.e.: It.IsInRange(0, 100, Range.Inclusive) - // the values are ints, but if the method to call - // expects, say, a double, a Convert node will be on - // the expression. - if (isParams && (expression.NodeType == ExpressionType.NewArrayInit || !expression.Type.IsArray)) - { - return new ParamArrayMatcher((NewArrayExpression)expression); - } - - var originalExpression = expression; - if (expression.NodeType == ExpressionType.Convert) - { - expression = ((UnaryExpression)expression).Operand; - } - - // SetupSet passes a custom expression. - var matchExpression = expression as MatchExpression; - if (matchExpression != null) - { - return new Matcher(matchExpression.Match); - } - - if (expression.NodeType == ExpressionType.Call) - { - var call = (MethodCallExpression)expression; - - // Try to determine if invocation is to a matcher. - using (var context = new FluentMockContext()) - { - Expression.Lambda(call).Compile().Invoke(); - - if (context.LastMatch != null) - { - return new Matcher(context.LastMatch); - } - } - - var attr = call.Method.GetCustomAttribute(true); -#pragma warning disable 618 - var staticMatcherMethodAttr = call.Method.GetCustomAttribute(true); -#pragma warning restore 618 - - if (attr != null) - { - var matcher = attr.CreateMatcher(); - matcher.Initialize(originalExpression); - return matcher; - } - else if (staticMatcherMethodAttr != null) - { - var matcher = new MatcherAttributeMatcher(); - matcher.Initialize(originalExpression); - return matcher; - } - else - { - var matcher = new LazyEvalMatcher(); - matcher.Initialize(originalExpression); - return matcher; - } - } - else if (expression.NodeType == ExpressionType.MemberAccess) - { - // Try to determine if invocation is to a matcher. - using (var context = new FluentMockContext()) - { - Expression.Lambda((MemberExpression)expression).Compile().Invoke(); - if (context.LastMatch != null) - { - return new Matcher(context.LastMatch); - } - } - } - - // Try reducing locals to get a constant. - var reduced = originalExpression.PartialEval(); - if (reduced.NodeType == ExpressionType.Constant) - { - return new ConstantMatcher(((ConstantExpression)reduced).Value); - } - - if (reduced.NodeType == ExpressionType.Quote) - { - return new ExpressionMatcher(((UnaryExpression)expression).Operand); - } - - throw new NotSupportedException( - string.Format(CultureInfo.CurrentCulture, Resources.UnsupportedExpression, expression)); - } - } -} +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Globalization; +using System.Linq.Expressions; +using Moq.Properties; +using Moq.Matchers; + +namespace Moq +{ + internal static class MatcherFactory + { + public static IMatcher CreateMatcher(Expression expression, bool isParams) + { + // Type inference on the call might + // do automatic conversion to the desired + // method argument type, and a Convert expression type + // might be the topmost instead. + // i.e.: It.IsInRange(0, 100, Range.Inclusive) + // the values are ints, but if the method to call + // expects, say, a double, a Convert node will be on + // the expression. + if (isParams && (expression.NodeType == ExpressionType.NewArrayInit || !expression.Type.IsArray)) + { + return new ParamArrayMatcher((NewArrayExpression)expression); + } + + var originalExpression = expression; + if (expression.NodeType == ExpressionType.Convert) + { + expression = ((UnaryExpression)expression).Operand; + } + + // SetupSet passes a custom expression. + var matchExpression = expression as MatchExpression; + if (matchExpression != null) + { + return new Matcher(matchExpression.Match); + } + + if (expression.NodeType == ExpressionType.Call) + { + var call = (MethodCallExpression)expression; + + // Try to determine if invocation is to a matcher. + using (var context = new FluentMockContext()) + { + Expression.Lambda(call).Compile().Invoke(); + + if (context.LastMatch != null) + { + return new Matcher(context.LastMatch); + } + } + + var attr = call.Method.GetCustomAttribute(true); +#pragma warning disable 618 + var staticMatcherMethodAttr = call.Method.GetCustomAttribute(true); +#pragma warning restore 618 + + if (attr != null) + { + var matcher = attr.CreateMatcher(); + matcher.Initialize(originalExpression); + return matcher; + } + else if (staticMatcherMethodAttr != null) + { + var matcher = new MatcherAttributeMatcher(); + matcher.Initialize(originalExpression); + return matcher; + } + else + { + var matcher = new LazyEvalMatcher(); + matcher.Initialize(originalExpression); + return matcher; + } + } + else if (expression.NodeType == ExpressionType.MemberAccess) + { + // Try to determine if invocation is to a matcher. + using (var context = new FluentMockContext()) + { + Expression.Lambda((MemberExpression)expression).Compile().Invoke(); + if (context.LastMatch != null) + { + return new Matcher(context.LastMatch); + } + } + } + + // Try reducing locals to get a constant. + var reduced = originalExpression.PartialEval(); + if (reduced.NodeType == ExpressionType.Constant) + { + return new ConstantMatcher(((ConstantExpression)reduced).Value); + } + + if (reduced.NodeType == ExpressionType.Quote) + { + return new ExpressionMatcher(((UnaryExpression)expression).Operand); + } + + throw new NotSupportedException( + string.Format(CultureInfo.CurrentCulture, Resources.UnsupportedExpression, expression)); + } + } +} diff --git a/Source/Matchers/ConstantMatcher.cs b/Source/Matchers/ConstantMatcher.cs index a73fce147..d59da5c01 100644 --- a/Source/Matchers/ConstantMatcher.cs +++ b/Source/Matchers/ConstantMatcher.cs @@ -1,86 +1,86 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Collections; -using System.Linq.Expressions; -using System.Globalization; -using System.Linq; -using System.Collections.Generic; - -namespace Moq.Matchers -{ - internal class ConstantMatcher : IMatcher - { - private object constantValue; - - public ConstantMatcher(object constantValue) - { - this.constantValue = constantValue; - } - - public void Initialize(Expression matcherExpression) - { - this.constantValue = ((ConstantExpression)matcherExpression).Value; - } - - public bool Matches(object value) - { - if (object.Equals(constantValue, value)) - { - return true; - } - - if (this.constantValue is IEnumerable && value is IEnumerable) - { - return this.MatchesEnumerable(value); - } - - return false; - } - - private bool MatchesEnumerable(object value) - { - var constValues = (IEnumerable)constantValue; - var values = (IEnumerable)value; - return constValues.Cast().SequenceEqual(values.Cast()); - } - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Collections; +using System.Linq.Expressions; +using System.Globalization; +using System.Linq; +using System.Collections.Generic; + +namespace Moq.Matchers +{ + internal class ConstantMatcher : IMatcher + { + private object constantValue; + + public ConstantMatcher(object constantValue) + { + this.constantValue = constantValue; + } + + public void Initialize(Expression matcherExpression) + { + this.constantValue = ((ConstantExpression)matcherExpression).Value; + } + + public bool Matches(object value) + { + if (object.Equals(constantValue, value)) + { + return true; + } + + if (this.constantValue is IEnumerable && value is IEnumerable) + { + return this.MatchesEnumerable(value); + } + + return false; + } + + private bool MatchesEnumerable(object value) + { + var constValues = (IEnumerable)constantValue; + var values = (IEnumerable)value; + return constValues.Cast().SequenceEqual(values.Cast()); + } + } } \ No newline at end of file diff --git a/Source/Matchers/ExpressionComparer.cs b/Source/Matchers/ExpressionComparer.cs index d6775c264..b9a17e354 100644 --- a/Source/Matchers/ExpressionComparer.cs +++ b/Source/Matchers/ExpressionComparer.cs @@ -1,276 +1,276 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Collections.Generic; -using System.Linq.Expressions; -using System.Collections.ObjectModel; -using System.Reflection; -using System.Linq; - -namespace Moq.Matchers -{ - internal class ExpressionComparer : IEqualityComparer - { - public static readonly ExpressionComparer Default = new ExpressionComparer(); - - private ExpressionComparer() - { - } - - public bool Equals(Expression x, Expression y) - { - if (x == null && y == null) - { - return true; - } - - if (x == null || y == null) - { - return false; - } - - if (x.NodeType == y.NodeType) - { - switch (x.NodeType) - { - case ExpressionType.Negate: - case ExpressionType.NegateChecked: - case ExpressionType.Not: - case ExpressionType.Convert: - case ExpressionType.ConvertChecked: - case ExpressionType.ArrayLength: - case ExpressionType.Quote: - case ExpressionType.TypeAs: - case ExpressionType.UnaryPlus: - return this.EqualsUnary((UnaryExpression)x, (UnaryExpression)y); - case ExpressionType.Add: - case ExpressionType.AddChecked: - case ExpressionType.Subtract: - case ExpressionType.SubtractChecked: - case ExpressionType.Multiply: - case ExpressionType.MultiplyChecked: - case ExpressionType.Divide: - case ExpressionType.Modulo: - case ExpressionType.And: - case ExpressionType.AndAlso: - case ExpressionType.Or: - case ExpressionType.OrElse: - case ExpressionType.LessThan: - case ExpressionType.LessThanOrEqual: - case ExpressionType.GreaterThan: - case ExpressionType.GreaterThanOrEqual: - case ExpressionType.Equal: - case ExpressionType.NotEqual: - case ExpressionType.Coalesce: - case ExpressionType.ArrayIndex: - case ExpressionType.RightShift: - case ExpressionType.LeftShift: - case ExpressionType.ExclusiveOr: - case ExpressionType.Power: - return this.EqualsBinary((BinaryExpression)x, (BinaryExpression)y); - case ExpressionType.TypeIs: - return this.EqualsTypeBinary((TypeBinaryExpression)x, (TypeBinaryExpression)y); - case ExpressionType.Conditional: - return this.EqualsConditional((ConditionalExpression)x, (ConditionalExpression)y); - case ExpressionType.Constant: - return EqualsConstant((ConstantExpression)x, (ConstantExpression)y); - case ExpressionType.Parameter: - return this.EqualsParameter((ParameterExpression)x, (ParameterExpression)y); - case ExpressionType.MemberAccess: - return this.EqualsMember((MemberExpression)x, (MemberExpression)y); - case ExpressionType.Call: - return this.EqualsMethodCall((MethodCallExpression)x, (MethodCallExpression)y); - case ExpressionType.Lambda: - return this.EqualsLambda((LambdaExpression)x, (LambdaExpression)y); - case ExpressionType.New: - return this.EqualsNew((NewExpression)x, (NewExpression)y); - case ExpressionType.NewArrayInit: - case ExpressionType.NewArrayBounds: - return this.EqualsNewArray((NewArrayExpression)x, (NewArrayExpression)y); - case ExpressionType.Invoke: - return this.EqualsInvocation((InvocationExpression)x, (InvocationExpression)y); - case ExpressionType.MemberInit: - return this.EqualsMemberInit((MemberInitExpression)x, (MemberInitExpression)y); - case ExpressionType.ListInit: - return this.EqualsListInit((ListInitExpression)x, (ListInitExpression)y); - } - } - - return false; - } - - public int GetHashCode(Expression obj) - { - return obj == null ? 0 : obj.GetHashCode(); - } - - private static bool Equals(ReadOnlyCollection x, ReadOnlyCollection y, Func comparer) - { - if (x.Count != y.Count) - { - return false; - } - - for (var index = 0; index < x.Count; index++) - { - if (!comparer(x[index], y[index])) - { - return false; - } - } - - return true; - } - - private bool EqualsBinary(BinaryExpression x, BinaryExpression y) - { - return x.Method == x.Method && this.Equals(x.Left, y.Left) && this.Equals(x.Right, y.Right) && - this.Equals(x.Conversion, y.Conversion); - } - - private bool EqualsConditional(ConditionalExpression x, ConditionalExpression y) - { - return this.Equals(x.Test, y.Test) && this.Equals(x.IfTrue, y.IfTrue) && this.Equals(x.IfFalse, y.IfFalse); - } - - private static bool EqualsConstant(ConstantExpression x, ConstantExpression y) - { - return object.Equals(x.Value, y.Value); - } - - private bool EqualsElementInit(ElementInit x, ElementInit y) - { - return x.AddMethod == y.AddMethod && Equals(x.Arguments, y.Arguments, this.Equals); - } - - private bool EqualsInvocation(InvocationExpression x, InvocationExpression y) - { - return this.Equals(x.Expression, y.Expression) && Equals(x.Arguments, y.Arguments, this.Equals); - } - - private bool EqualsLambda(LambdaExpression x, LambdaExpression y) - { - return x.GetType() == y.GetType() && this.Equals(x.Body, y.Body) && - Equals(x.Parameters, y.Parameters, this.EqualsParameter); - } - - private bool EqualsListInit(ListInitExpression x, ListInitExpression y) - { - return this.EqualsNew(x.NewExpression, y.NewExpression) && - Equals(x.Initializers, y.Initializers, this.EqualsElementInit); - } - - private bool EqualsMemberAssignment(MemberAssignment x, MemberAssignment y) - { - return this.Equals(x.Expression, y.Expression); - } - - private bool EqualsMemberBinding(MemberBinding x, MemberBinding y) - { - if (x.BindingType == y.BindingType && x.Member == y.Member) - { - switch (x.BindingType) - { - case MemberBindingType.Assignment: - return this.EqualsMemberAssignment((MemberAssignment)x, (MemberAssignment)y); - case MemberBindingType.MemberBinding: - return this.EqualsMemberMemberBinding((MemberMemberBinding)x, (MemberMemberBinding)y); - case MemberBindingType.ListBinding: - return this.EqualsMemberListBinding((MemberListBinding)x, (MemberListBinding)y); - } - } - - return false; - } - - private bool EqualsMember(MemberExpression x, MemberExpression y) - { - return x.Member == y.Member && this.Equals(x.Expression, y.Expression); - } - - private bool EqualsMemberInit(MemberInitExpression x, MemberInitExpression y) - { - return this.EqualsNew(x.NewExpression, y.NewExpression) && - Equals(x.Bindings, y.Bindings, this.EqualsMemberBinding); - } - - private bool EqualsMemberListBinding(MemberListBinding x, MemberListBinding y) - { - return Equals(x.Initializers, y.Initializers, this.EqualsElementInit); - } - - private bool EqualsMemberMemberBinding(MemberMemberBinding x, MemberMemberBinding y) - { - return Equals(x.Bindings, y.Bindings, this.EqualsMemberBinding); - } - - private bool EqualsMethodCall(MethodCallExpression x, MethodCallExpression y) - { - return x.Method == y.Method && this.Equals(x.Object, y.Object) && - Equals(x.Arguments, y.Arguments, this.Equals); - } - - private bool EqualsNewArray(NewArrayExpression x, NewArrayExpression y) - { - return x.Type == y.Type && Equals(x.Expressions, y.Expressions, this.Equals); - } - - private bool EqualsNew(NewExpression x, NewExpression y) - { - return x.Constructor == y.Constructor && Equals(x.Arguments, y.Arguments, this.Equals); - } - - private bool EqualsParameter(ParameterExpression x, ParameterExpression y) - { - return x.Type == y.Type; - } - - private bool EqualsTypeBinary(TypeBinaryExpression x, TypeBinaryExpression y) - { - return x.TypeOperand == y.TypeOperand && this.Equals(x.Expression, y.Expression); - } - - private bool EqualsUnary(UnaryExpression x, UnaryExpression y) - { - return x.Method == y.Method && this.Equals(x.Operand, y.Operand); - } - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Collections.ObjectModel; +using System.Reflection; +using System.Linq; + +namespace Moq.Matchers +{ + internal class ExpressionComparer : IEqualityComparer + { + public static readonly ExpressionComparer Default = new ExpressionComparer(); + + private ExpressionComparer() + { + } + + public bool Equals(Expression x, Expression y) + { + if (x == null && y == null) + { + return true; + } + + if (x == null || y == null) + { + return false; + } + + if (x.NodeType == y.NodeType) + { + switch (x.NodeType) + { + case ExpressionType.Negate: + case ExpressionType.NegateChecked: + case ExpressionType.Not: + case ExpressionType.Convert: + case ExpressionType.ConvertChecked: + case ExpressionType.ArrayLength: + case ExpressionType.Quote: + case ExpressionType.TypeAs: + case ExpressionType.UnaryPlus: + return this.EqualsUnary((UnaryExpression)x, (UnaryExpression)y); + case ExpressionType.Add: + case ExpressionType.AddChecked: + case ExpressionType.Subtract: + case ExpressionType.SubtractChecked: + case ExpressionType.Multiply: + case ExpressionType.MultiplyChecked: + case ExpressionType.Divide: + case ExpressionType.Modulo: + case ExpressionType.And: + case ExpressionType.AndAlso: + case ExpressionType.Or: + case ExpressionType.OrElse: + case ExpressionType.LessThan: + case ExpressionType.LessThanOrEqual: + case ExpressionType.GreaterThan: + case ExpressionType.GreaterThanOrEqual: + case ExpressionType.Equal: + case ExpressionType.NotEqual: + case ExpressionType.Coalesce: + case ExpressionType.ArrayIndex: + case ExpressionType.RightShift: + case ExpressionType.LeftShift: + case ExpressionType.ExclusiveOr: + case ExpressionType.Power: + return this.EqualsBinary((BinaryExpression)x, (BinaryExpression)y); + case ExpressionType.TypeIs: + return this.EqualsTypeBinary((TypeBinaryExpression)x, (TypeBinaryExpression)y); + case ExpressionType.Conditional: + return this.EqualsConditional((ConditionalExpression)x, (ConditionalExpression)y); + case ExpressionType.Constant: + return EqualsConstant((ConstantExpression)x, (ConstantExpression)y); + case ExpressionType.Parameter: + return this.EqualsParameter((ParameterExpression)x, (ParameterExpression)y); + case ExpressionType.MemberAccess: + return this.EqualsMember((MemberExpression)x, (MemberExpression)y); + case ExpressionType.Call: + return this.EqualsMethodCall((MethodCallExpression)x, (MethodCallExpression)y); + case ExpressionType.Lambda: + return this.EqualsLambda((LambdaExpression)x, (LambdaExpression)y); + case ExpressionType.New: + return this.EqualsNew((NewExpression)x, (NewExpression)y); + case ExpressionType.NewArrayInit: + case ExpressionType.NewArrayBounds: + return this.EqualsNewArray((NewArrayExpression)x, (NewArrayExpression)y); + case ExpressionType.Invoke: + return this.EqualsInvocation((InvocationExpression)x, (InvocationExpression)y); + case ExpressionType.MemberInit: + return this.EqualsMemberInit((MemberInitExpression)x, (MemberInitExpression)y); + case ExpressionType.ListInit: + return this.EqualsListInit((ListInitExpression)x, (ListInitExpression)y); + } + } + + return false; + } + + public int GetHashCode(Expression obj) + { + return obj == null ? 0 : obj.GetHashCode(); + } + + private static bool Equals(ReadOnlyCollection x, ReadOnlyCollection y, Func comparer) + { + if (x.Count != y.Count) + { + return false; + } + + for (var index = 0; index < x.Count; index++) + { + if (!comparer(x[index], y[index])) + { + return false; + } + } + + return true; + } + + private bool EqualsBinary(BinaryExpression x, BinaryExpression y) + { + return x.Method == x.Method && this.Equals(x.Left, y.Left) && this.Equals(x.Right, y.Right) && + this.Equals(x.Conversion, y.Conversion); + } + + private bool EqualsConditional(ConditionalExpression x, ConditionalExpression y) + { + return this.Equals(x.Test, y.Test) && this.Equals(x.IfTrue, y.IfTrue) && this.Equals(x.IfFalse, y.IfFalse); + } + + private static bool EqualsConstant(ConstantExpression x, ConstantExpression y) + { + return object.Equals(x.Value, y.Value); + } + + private bool EqualsElementInit(ElementInit x, ElementInit y) + { + return x.AddMethod == y.AddMethod && Equals(x.Arguments, y.Arguments, this.Equals); + } + + private bool EqualsInvocation(InvocationExpression x, InvocationExpression y) + { + return this.Equals(x.Expression, y.Expression) && Equals(x.Arguments, y.Arguments, this.Equals); + } + + private bool EqualsLambda(LambdaExpression x, LambdaExpression y) + { + return x.GetType() == y.GetType() && this.Equals(x.Body, y.Body) && + Equals(x.Parameters, y.Parameters, this.EqualsParameter); + } + + private bool EqualsListInit(ListInitExpression x, ListInitExpression y) + { + return this.EqualsNew(x.NewExpression, y.NewExpression) && + Equals(x.Initializers, y.Initializers, this.EqualsElementInit); + } + + private bool EqualsMemberAssignment(MemberAssignment x, MemberAssignment y) + { + return this.Equals(x.Expression, y.Expression); + } + + private bool EqualsMemberBinding(MemberBinding x, MemberBinding y) + { + if (x.BindingType == y.BindingType && x.Member == y.Member) + { + switch (x.BindingType) + { + case MemberBindingType.Assignment: + return this.EqualsMemberAssignment((MemberAssignment)x, (MemberAssignment)y); + case MemberBindingType.MemberBinding: + return this.EqualsMemberMemberBinding((MemberMemberBinding)x, (MemberMemberBinding)y); + case MemberBindingType.ListBinding: + return this.EqualsMemberListBinding((MemberListBinding)x, (MemberListBinding)y); + } + } + + return false; + } + + private bool EqualsMember(MemberExpression x, MemberExpression y) + { + return x.Member == y.Member && this.Equals(x.Expression, y.Expression); + } + + private bool EqualsMemberInit(MemberInitExpression x, MemberInitExpression y) + { + return this.EqualsNew(x.NewExpression, y.NewExpression) && + Equals(x.Bindings, y.Bindings, this.EqualsMemberBinding); + } + + private bool EqualsMemberListBinding(MemberListBinding x, MemberListBinding y) + { + return Equals(x.Initializers, y.Initializers, this.EqualsElementInit); + } + + private bool EqualsMemberMemberBinding(MemberMemberBinding x, MemberMemberBinding y) + { + return Equals(x.Bindings, y.Bindings, this.EqualsMemberBinding); + } + + private bool EqualsMethodCall(MethodCallExpression x, MethodCallExpression y) + { + return x.Method == y.Method && this.Equals(x.Object, y.Object) && + Equals(x.Arguments, y.Arguments, this.Equals); + } + + private bool EqualsNewArray(NewArrayExpression x, NewArrayExpression y) + { + return x.Type == y.Type && Equals(x.Expressions, y.Expressions, this.Equals); + } + + private bool EqualsNew(NewExpression x, NewExpression y) + { + return x.Constructor == y.Constructor && Equals(x.Arguments, y.Arguments, this.Equals); + } + + private bool EqualsParameter(ParameterExpression x, ParameterExpression y) + { + return x.Type == y.Type; + } + + private bool EqualsTypeBinary(TypeBinaryExpression x, TypeBinaryExpression y) + { + return x.TypeOperand == y.TypeOperand && this.Equals(x.Expression, y.Expression); + } + + private bool EqualsUnary(UnaryExpression x, UnaryExpression y) + { + return x.Method == y.Method && this.Equals(x.Operand, y.Operand); + } + } } \ No newline at end of file diff --git a/Source/Matchers/ExpressionMatcher.cs b/Source/Matchers/ExpressionMatcher.cs index d1320bf64..3c63e6de2 100644 --- a/Source/Matchers/ExpressionMatcher.cs +++ b/Source/Matchers/ExpressionMatcher.cs @@ -1,70 +1,70 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Linq.Expressions; - -namespace Moq.Matchers -{ - internal class ExpressionMatcher : IMatcher - { - private Expression expression; - - public ExpressionMatcher(Expression matcherExpression) - { - this.expression = matcherExpression; - } - - void IMatcher.Initialize(Expression matcherExpression) - { - } - - public bool Matches(object value) - { - var valueExpression = value as Expression; - if (value == null) - { - return false; - } - - return ExpressionComparer.Default.Equals(this.expression, valueExpression); - } - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Linq.Expressions; + +namespace Moq.Matchers +{ + internal class ExpressionMatcher : IMatcher + { + private Expression expression; + + public ExpressionMatcher(Expression matcherExpression) + { + this.expression = matcherExpression; + } + + void IMatcher.Initialize(Expression matcherExpression) + { + } + + public bool Matches(object value) + { + var valueExpression = value as Expression; + if (value == null) + { + return false; + } + + return ExpressionComparer.Default.Equals(this.expression, valueExpression); + } + } } \ No newline at end of file diff --git a/Source/Matchers/LazyEvalMatcher.cs b/Source/Matchers/LazyEvalMatcher.cs index 57d1e75d8..b819e7f01 100644 --- a/Source/Matchers/LazyEvalMatcher.cs +++ b/Source/Matchers/LazyEvalMatcher.cs @@ -1,66 +1,66 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Linq.Expressions; - -namespace Moq.Matchers -{ - internal class LazyEvalMatcher : IMatcher - { - private Expression expression; - - public void Initialize(Expression matcherExpression) - { - this.expression = matcherExpression; - } - - public bool Matches(object value) - { - var eval = Evaluator.PartialEval(this.expression); - if (eval.NodeType == ExpressionType.Constant) - { - return object.Equals(((ConstantExpression)eval).Value, value); - } - - return false; - } - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Linq.Expressions; + +namespace Moq.Matchers +{ + internal class LazyEvalMatcher : IMatcher + { + private Expression expression; + + public void Initialize(Expression matcherExpression) + { + this.expression = matcherExpression; + } + + public bool Matches(object value) + { + var eval = Evaluator.PartialEval(this.expression); + if (eval.NodeType == ExpressionType.Constant) + { + return object.Equals(((ConstantExpression)eval).Value, value); + } + + return false; + } + } } \ No newline at end of file diff --git a/Source/Matchers/Matcher.cs b/Source/Matchers/Matcher.cs index e1da7e667..1709c528a 100644 --- a/Source/Matchers/Matcher.cs +++ b/Source/Matchers/Matcher.cs @@ -1,63 +1,63 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System.Linq.Expressions; - -namespace Moq.Matchers -{ - internal class Matcher : IMatcher - { - private Match match; - - public Matcher(Match match) - { - this.match = match; - } - - public void Initialize(Expression matcherExpression) - { - } - - public bool Matches(object value) - { - return match.Matches(value); - } - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System.Linq.Expressions; + +namespace Moq.Matchers +{ + internal class Matcher : IMatcher + { + private Match match; + + public Matcher(Match match) + { + this.match = match; + } + + public void Initialize(Expression matcherExpression) + { + } + + public bool Matches(object value) + { + return match.Matches(value); + } + } } \ No newline at end of file diff --git a/Source/Matchers/MatcherAttributeMatcher.cs b/Source/Matchers/MatcherAttributeMatcher.cs index dd67a2f10..8e608de04 100644 --- a/Source/Matchers/MatcherAttributeMatcher.cs +++ b/Source/Matchers/MatcherAttributeMatcher.cs @@ -1,132 +1,132 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Linq.Expressions; -using System.Reflection; - -namespace Moq.Matchers -{ - /// - /// Matcher to treat static functions as matchers. - /// - /// mock.Setup(x => x.StringMethod(A.MagicString())); - /// - /// public static class A - /// { - /// [Matcher] - /// public static string MagicString() { return null; } - /// public static bool MagicString(string arg) - /// { - /// return arg == "magic"; - /// } - /// } - /// - /// Will succeed if: mock.Object.StringMethod("magic"); - /// and fail with any other call. - /// - internal class MatcherAttributeMatcher : IMatcher - { - private MethodInfo validatorMethod; - private Expression matcherExpression; - - public void Initialize(Expression matchExpression) - { - this.validatorMethod = ResolveValidatorMethod(matchExpression); - this.matcherExpression = matchExpression; - } - - private static MethodInfo ResolveValidatorMethod(Expression expression) - { - var call = (MethodCallExpression)expression; - var expectedParametersTypes = new[] { call.Method.ReturnType }.Concat(call.Method.GetParameters().Select(p => p.ParameterType)).ToArray(); - - MethodInfo method = null; - - if (call.Method.IsGenericMethod) - { - // This is the "hard" way in .NET 3.5 as GetMethod does not support - // passing generic type arguments for the query. - var genericArgs = call.Method.GetGenericArguments(); - - method = call.Method.DeclaringType.GetMethods() - .Where(m => - m.Name == call.Method.Name && - m.IsGenericMethodDefinition && - m.GetGenericArguments().Length == - call.Method.GetGenericMethodDefinition().GetGenericArguments().Length && - expectedParametersTypes.SequenceEqual( - m.MakeGenericMethod(genericArgs).GetParameters().Select(p => p.ParameterType))) - .Select(m => m.MakeGenericMethod(genericArgs)) - .FirstOrDefault(); - } - else - { - method = call.Method.DeclaringType.GetMethod(call.Method.Name, expectedParametersTypes); - } - - // throw if validatorMethod doesn't exists - if (method == null) - { - throw new MissingMethodException(string.Format(CultureInfo.CurrentCulture, - "public {0}bool {1}({2}) in class {3}.", - call.Method.IsStatic ? "static " : String.Empty, - call.Method.Name, - String.Join(", ", expectedParametersTypes.Select(x => x.Name).ToArray()), - call.Method.DeclaringType.ToString())); - } - return method; - } - - public bool Matches(object value) - { - // use matcher Expression to get extra arguments - MethodCallExpression call = (MethodCallExpression)matcherExpression; - var extraArgs = call.Arguments.Select(ae => ((ConstantExpression)ae.PartialEval()).Value); - var args = new[] { value }.Concat(extraArgs).ToArray(); - // for static and non-static method - var instance = call.Object == null ? null : (call.Object.PartialEval() as ConstantExpression).Value; - return (bool)validatorMethod.Invoke(instance, args); - } - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; + +namespace Moq.Matchers +{ + /// + /// Matcher to treat static functions as matchers. + /// + /// mock.Setup(x => x.StringMethod(A.MagicString())); + /// + /// public static class A + /// { + /// [Matcher] + /// public static string MagicString() { return null; } + /// public static bool MagicString(string arg) + /// { + /// return arg == "magic"; + /// } + /// } + /// + /// Will succeed if: mock.Object.StringMethod("magic"); + /// and fail with any other call. + /// + internal class MatcherAttributeMatcher : IMatcher + { + private MethodInfo validatorMethod; + private Expression matcherExpression; + + public void Initialize(Expression matchExpression) + { + this.validatorMethod = ResolveValidatorMethod(matchExpression); + this.matcherExpression = matchExpression; + } + + private static MethodInfo ResolveValidatorMethod(Expression expression) + { + var call = (MethodCallExpression)expression; + var expectedParametersTypes = new[] { call.Method.ReturnType }.Concat(call.Method.GetParameters().Select(p => p.ParameterType)).ToArray(); + + MethodInfo method = null; + + if (call.Method.IsGenericMethod) + { + // This is the "hard" way in .NET 3.5 as GetMethod does not support + // passing generic type arguments for the query. + var genericArgs = call.Method.GetGenericArguments(); + + method = call.Method.DeclaringType.GetMethods() + .Where(m => + m.Name == call.Method.Name && + m.IsGenericMethodDefinition && + m.GetGenericArguments().Length == + call.Method.GetGenericMethodDefinition().GetGenericArguments().Length && + expectedParametersTypes.SequenceEqual( + m.MakeGenericMethod(genericArgs).GetParameters().Select(p => p.ParameterType))) + .Select(m => m.MakeGenericMethod(genericArgs)) + .FirstOrDefault(); + } + else + { + method = call.Method.DeclaringType.GetMethod(call.Method.Name, expectedParametersTypes); + } + + // throw if validatorMethod doesn't exists + if (method == null) + { + throw new MissingMethodException(string.Format(CultureInfo.CurrentCulture, + "public {0}bool {1}({2}) in class {3}.", + call.Method.IsStatic ? "static " : String.Empty, + call.Method.Name, + String.Join(", ", expectedParametersTypes.Select(x => x.Name).ToArray()), + call.Method.DeclaringType.ToString())); + } + return method; + } + + public bool Matches(object value) + { + // use matcher Expression to get extra arguments + MethodCallExpression call = (MethodCallExpression)matcherExpression; + var extraArgs = call.Arguments.Select(ae => ((ConstantExpression)ae.PartialEval()).Value); + var args = new[] { value }.Concat(extraArgs).ToArray(); + // for static and non-static method + var instance = call.Object == null ? null : (call.Object.PartialEval() as ConstantExpression).Value; + return (bool)validatorMethod.Invoke(instance, args); + } + } } \ No newline at end of file diff --git a/Source/Matchers/ParamArrayMatcher.cs b/Source/Matchers/ParamArrayMatcher.cs index 0f7a7e462..3923a84ea 100644 --- a/Source/Matchers/ParamArrayMatcher.cs +++ b/Source/Matchers/ParamArrayMatcher.cs @@ -1,96 +1,96 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Linq; -using System.Linq.Expressions; - -namespace Moq.Matchers -{ - internal class ParamArrayMatcher : IMatcher - { - private NewArrayExpression arrayInitExpression; - private IMatcher[] matchers; - - internal ParamArrayMatcher(NewArrayExpression matcherExpression) - { - this.arrayInitExpression = matcherExpression; - this.Initialize(); - } - - public bool Matches(object value) - { - Array values = value as Array; - if (values == null || this.matchers.Length != values.Length) - { - return false; - } - - for (int index = 0; index < values.Length; index++) - { - if (!this.matchers[index].Matches(values.GetValue(index))) - { - return false; - } - } - - return true; - } - - void IMatcher.Initialize(Expression matcherExpression) - { - this.arrayInitExpression = matcherExpression as NewArrayExpression; - this.Initialize(); - } - - private void Initialize() - { - if (this.arrayInitExpression != null) - { - this.matchers = this.arrayInitExpression.Expressions - .Select(e => MatcherFactory.CreateMatcher(e, false)).ToArray(); - } - else - { - this.matchers = new IMatcher[0]; - } - } - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Linq; +using System.Linq.Expressions; + +namespace Moq.Matchers +{ + internal class ParamArrayMatcher : IMatcher + { + private NewArrayExpression arrayInitExpression; + private IMatcher[] matchers; + + internal ParamArrayMatcher(NewArrayExpression matcherExpression) + { + this.arrayInitExpression = matcherExpression; + this.Initialize(); + } + + public bool Matches(object value) + { + Array values = value as Array; + if (values == null || this.matchers.Length != values.Length) + { + return false; + } + + for (int index = 0; index < values.Length; index++) + { + if (!this.matchers[index].Matches(values.GetValue(index))) + { + return false; + } + } + + return true; + } + + void IMatcher.Initialize(Expression matcherExpression) + { + this.arrayInitExpression = matcherExpression as NewArrayExpression; + this.Initialize(); + } + + private void Initialize() + { + if (this.arrayInitExpression != null) + { + this.matchers = this.arrayInitExpression.Expressions + .Select(e => MatcherFactory.CreateMatcher(e, false)).ToArray(); + } + else + { + this.matchers = new IMatcher[0]; + } + } + } } \ No newline at end of file diff --git a/Source/Matchers/PredicateMatcher.cs b/Source/Matchers/PredicateMatcher.cs index 4920de90b..8ba48f79e 100644 --- a/Source/Matchers/PredicateMatcher.cs +++ b/Source/Matchers/PredicateMatcher.cs @@ -1,74 +1,74 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Linq.Expressions; - -namespace Moq.Matchers -{ - internal class PredicateMatcher : IMatcher - { - private Delegate predicate; - private Type matcherType; - - public void Initialize(Expression matcherExpression) - { - // TODO: validate argument or trust the compiler? - var call = matcherExpression as MethodCallExpression; - var lambda = call.Arguments[0].StripQuotes() as LambdaExpression; - matcherType = call.Type; - - if (lambda == null) - throw new ArgumentException(Properties.Resources.SetupLambda); - - predicate = lambda.Compile(); - } - - public bool Matches(object value) - { - if (value != null && !matcherType.IsAssignableFrom(value.GetType())) - { - return false; - } - - return (bool)predicate.InvokePreserveStack(value); - } - } -} +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Linq.Expressions; + +namespace Moq.Matchers +{ + internal class PredicateMatcher : IMatcher + { + private Delegate predicate; + private Type matcherType; + + public void Initialize(Expression matcherExpression) + { + // TODO: validate argument or trust the compiler? + var call = matcherExpression as MethodCallExpression; + var lambda = call.Arguments[0].StripQuotes() as LambdaExpression; + matcherType = call.Type; + + if (lambda == null) + throw new ArgumentException(Properties.Resources.SetupLambda); + + predicate = lambda.Compile(); + } + + public bool Matches(object value) + { + if (value != null && !matcherType.IsAssignableFrom(value.GetType())) + { + return false; + } + + return (bool)predicate.InvokePreserveStack(value); + } + } +} diff --git a/Source/Matchers/RefMatcher.cs b/Source/Matchers/RefMatcher.cs index d8526b7d8..5622df276 100644 --- a/Source/Matchers/RefMatcher.cs +++ b/Source/Matchers/RefMatcher.cs @@ -1,71 +1,71 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Linq.Expressions; - -namespace Moq.Matchers -{ - internal class RefMatcher : IMatcher - { - private Func equals; - - public RefMatcher(object reference) - { - if (reference != null && reference.GetType().IsValueType) - { - equals = value => object.Equals(reference, value); - } - else - { - equals = value => object.ReferenceEquals(reference, value); - } - } - - public bool Matches(object value) - { - return equals(value); - } - - public void Initialize(Expression matcherExpression) - { - } - } -} +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Linq.Expressions; + +namespace Moq.Matchers +{ + internal class RefMatcher : IMatcher + { + private Func equals; + + public RefMatcher(object reference) + { + if (reference != null && reference.GetType().IsValueType) + { + equals = value => object.Equals(reference, value); + } + else + { + equals = value => object.ReferenceEquals(reference, value); + } + } + + public bool Matches(object value) + { + return equals(value); + } + + public void Initialize(Expression matcherExpression) + { + } + } +} diff --git a/Source/MemberInfoExtensions.cs b/Source/MemberInfoExtensions.cs index eaa48f92e..88ec7e96b 100644 --- a/Source/MemberInfoExtensions.cs +++ b/Source/MemberInfoExtensions.cs @@ -1,109 +1,109 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; - -namespace Moq -{ - internal static class MemberInfoExtensions - { - public static string GetFullName(this MethodBase method) - { - if (method.IsGenericMethod) - { - return method.Name + GetGenericArguments(method.GetGenericArguments(), t => GetFullName(t)); - } - - return method.Name; - } - - public static string GetFullName(this Type type) - { - if (type.IsGenericType) - { - return type.FullName.Substring(0, type.FullName.IndexOf('`')) + - GetGenericArguments(type.GetGenericArguments(), t => GetFullName(t)); - } - - return type.FullName; - } - - public static string GetName(this MethodBase method) - { - if (method.IsGenericMethod) - { - return method.Name + GetGenericArguments(method.GetGenericArguments(), t => GetName(t)); - } - - return method.Name; - } - - public static string GetName(this Type type) - { - if (type.IsGenericType) - { - return type.Name.Substring(0, type.Name.IndexOf('`')) + - GetGenericArguments(type.GetGenericArguments(), t => GetName(t)); - } - - return type.Name; - } - - public static IEnumerable GetParameterTypes(this MethodBase method) - { - return method.GetParameters().Select(parameter => parameter.ParameterType); - } - - public static bool IsDestructor(this MethodInfo method) - { - return method.Name == "Finalize" && !method.IsGenericMethod && - method.ReturnType == typeof(void) && method.GetParameters().Length == 0; - } - - - public static bool IsEventAttach(this MethodBase method) - { - return method.Name.StartsWith("add_", StringComparison.Ordinal); - } - - public static bool IsEventDetach(this MethodBase method) - { - return method.Name.StartsWith("remove_", StringComparison.Ordinal); - } - - public static bool IsPropertyGetter(this MethodBase method) - { - return method.Name.StartsWith("get_", StringComparison.Ordinal); - } - - public static bool IsPropertyIndexerGetter(this MethodBase method) - { - return method.Name.StartsWith("get_Item", StringComparison.Ordinal); - } - - public static bool IsPropertyIndexerSetter(this MethodBase method) - { - return method.Name.StartsWith("set_Item", StringComparison.Ordinal); - } - - public static bool IsPropertySetter(this MethodBase method) - { - return method.Name.StartsWith("set_", StringComparison.Ordinal); - } - - public static bool IsRefArgument(this ParameterInfo parameter) - { - return parameter.ParameterType.IsByRef && (parameter.Attributes & ParameterAttributes.Out) == ParameterAttributes.None; - } - - public static bool IsOutArgument(this ParameterInfo parameter) - { - return parameter.ParameterType.IsByRef && (parameter.Attributes & ParameterAttributes.Out) == ParameterAttributes.Out; - } - - private static string GetGenericArguments(IEnumerable types, Func typeGetter) - { - return "<" + string.Join(",", types.Select(typeGetter).ToArray()) + ">"; - } - } +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +namespace Moq +{ + internal static class MemberInfoExtensions + { + public static string GetFullName(this MethodBase method) + { + if (method.IsGenericMethod) + { + return method.Name + GetGenericArguments(method.GetGenericArguments(), t => GetFullName(t)); + } + + return method.Name; + } + + public static string GetFullName(this Type type) + { + if (type.IsGenericType) + { + return type.FullName.Substring(0, type.FullName.IndexOf('`')) + + GetGenericArguments(type.GetGenericArguments(), t => GetFullName(t)); + } + + return type.FullName; + } + + public static string GetName(this MethodBase method) + { + if (method.IsGenericMethod) + { + return method.Name + GetGenericArguments(method.GetGenericArguments(), t => GetName(t)); + } + + return method.Name; + } + + public static string GetName(this Type type) + { + if (type.IsGenericType) + { + return type.Name.Substring(0, type.Name.IndexOf('`')) + + GetGenericArguments(type.GetGenericArguments(), t => GetName(t)); + } + + return type.Name; + } + + public static IEnumerable GetParameterTypes(this MethodBase method) + { + return method.GetParameters().Select(parameter => parameter.ParameterType); + } + + public static bool IsDestructor(this MethodInfo method) + { + return method.Name == "Finalize" && !method.IsGenericMethod && + method.ReturnType == typeof(void) && method.GetParameters().Length == 0; + } + + + public static bool IsEventAttach(this MethodBase method) + { + return method.Name.StartsWith("add_", StringComparison.Ordinal); + } + + public static bool IsEventDetach(this MethodBase method) + { + return method.Name.StartsWith("remove_", StringComparison.Ordinal); + } + + public static bool IsPropertyGetter(this MethodBase method) + { + return method.Name.StartsWith("get_", StringComparison.Ordinal); + } + + public static bool IsPropertyIndexerGetter(this MethodBase method) + { + return method.Name.StartsWith("get_Item", StringComparison.Ordinal); + } + + public static bool IsPropertyIndexerSetter(this MethodBase method) + { + return method.Name.StartsWith("set_Item", StringComparison.Ordinal); + } + + public static bool IsPropertySetter(this MethodBase method) + { + return method.Name.StartsWith("set_", StringComparison.Ordinal); + } + + public static bool IsRefArgument(this ParameterInfo parameter) + { + return parameter.ParameterType.IsByRef && (parameter.Attributes & ParameterAttributes.Out) == ParameterAttributes.None; + } + + public static bool IsOutArgument(this ParameterInfo parameter) + { + return parameter.ParameterType.IsByRef && (parameter.Attributes & ParameterAttributes.Out) == ParameterAttributes.Out; + } + + private static string GetGenericArguments(IEnumerable types, Func typeGetter) + { + return "<" + string.Join(",", types.Select(typeGetter).ToArray()) + ">"; + } + } } \ No newline at end of file diff --git a/Source/MethodCall.Generated.cs b/Source/MethodCall.Generated.cs index e85969cc2..3aa7aad55 100644 --- a/Source/MethodCall.Generated.cs +++ b/Source/MethodCall.Generated.cs @@ -1,205 +1,205 @@ -using System; -using System.Diagnostics.CodeAnalysis; -using Moq.Language; -using Moq.Language.Flow; - -namespace Moq -{ - internal partial class MethodCall - { - public IVerifies Raises(Action eventExpression, Func func) - { - return RaisesImpl(eventExpression, func); - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return RaisesImpl(eventExpression, func); - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return RaisesImpl(eventExpression, func); - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return RaisesImpl(eventExpression, func); - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return RaisesImpl(eventExpression, func); - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return RaisesImpl(eventExpression, func); - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return RaisesImpl(eventExpression, func); - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return RaisesImpl(eventExpression, func); - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return RaisesImpl(eventExpression, func); - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return RaisesImpl(eventExpression, func); - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return RaisesImpl(eventExpression, func); - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return RaisesImpl(eventExpression, func); - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return RaisesImpl(eventExpression, func); - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return RaisesImpl(eventExpression, func); - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return RaisesImpl(eventExpression, func); - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return RaisesImpl(eventExpression, func); - } - } - - internal partial class MethodCall - { - [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] - public ICallbackResult Callback(Action callback) - { - this.SetCallbackWithArguments(callback); - return this; - } - - [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] - public ICallbackResult Callback(Action callback) - { - this.SetCallbackWithArguments(callback); - return this; - } - - [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] - public ICallbackResult Callback(Action callback) - { - this.SetCallbackWithArguments(callback); - return this; - } - - [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] - public ICallbackResult Callback(Action callback) - { - this.SetCallbackWithArguments(callback); - return this; - } - - [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] - public ICallbackResult Callback(Action callback) - { - this.SetCallbackWithArguments(callback); - return this; - } - - [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] - public ICallbackResult Callback(Action callback) - { - this.SetCallbackWithArguments(callback); - return this; - } - - [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] - public ICallbackResult Callback(Action callback) - { - this.SetCallbackWithArguments(callback); - return this; - } - - [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] - public ICallbackResult Callback(Action callback) - { - this.SetCallbackWithArguments(callback); - return this; - } - - [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] - public ICallbackResult Callback(Action callback) - { - this.SetCallbackWithArguments(callback); - return this; - } - - [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] - public ICallbackResult Callback(Action callback) - { - this.SetCallbackWithArguments(callback); - return this; - } - - [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] - public ICallbackResult Callback(Action callback) - { - this.SetCallbackWithArguments(callback); - return this; - } - - [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] - public ICallbackResult Callback(Action callback) - { - this.SetCallbackWithArguments(callback); - return this; - } - - [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] - public ICallbackResult Callback(Action callback) - { - this.SetCallbackWithArguments(callback); - return this; - } - - [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] - public ICallbackResult Callback(Action callback) - { - this.SetCallbackWithArguments(callback); - return this; - } - - [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] - public ICallbackResult Callback(Action callback) - { - this.SetCallbackWithArguments(callback); - return this; - } - - [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] - public ICallbackResult Callback(Action callback) - { - this.SetCallbackWithArguments(callback); - return this; - } - } -} +using System; +using System.Diagnostics.CodeAnalysis; +using Moq.Language; +using Moq.Language.Flow; + +namespace Moq +{ + internal partial class MethodCall + { + public IVerifies Raises(Action eventExpression, Func func) + { + return RaisesImpl(eventExpression, func); + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return RaisesImpl(eventExpression, func); + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return RaisesImpl(eventExpression, func); + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return RaisesImpl(eventExpression, func); + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return RaisesImpl(eventExpression, func); + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return RaisesImpl(eventExpression, func); + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return RaisesImpl(eventExpression, func); + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return RaisesImpl(eventExpression, func); + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return RaisesImpl(eventExpression, func); + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return RaisesImpl(eventExpression, func); + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return RaisesImpl(eventExpression, func); + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return RaisesImpl(eventExpression, func); + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return RaisesImpl(eventExpression, func); + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return RaisesImpl(eventExpression, func); + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return RaisesImpl(eventExpression, func); + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return RaisesImpl(eventExpression, func); + } + } + + internal partial class MethodCall + { + [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] + public ICallbackResult Callback(Action callback) + { + this.SetCallbackWithArguments(callback); + return this; + } + + [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] + public ICallbackResult Callback(Action callback) + { + this.SetCallbackWithArguments(callback); + return this; + } + + [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] + public ICallbackResult Callback(Action callback) + { + this.SetCallbackWithArguments(callback); + return this; + } + + [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] + public ICallbackResult Callback(Action callback) + { + this.SetCallbackWithArguments(callback); + return this; + } + + [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] + public ICallbackResult Callback(Action callback) + { + this.SetCallbackWithArguments(callback); + return this; + } + + [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] + public ICallbackResult Callback(Action callback) + { + this.SetCallbackWithArguments(callback); + return this; + } + + [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] + public ICallbackResult Callback(Action callback) + { + this.SetCallbackWithArguments(callback); + return this; + } + + [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] + public ICallbackResult Callback(Action callback) + { + this.SetCallbackWithArguments(callback); + return this; + } + + [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] + public ICallbackResult Callback(Action callback) + { + this.SetCallbackWithArguments(callback); + return this; + } + + [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] + public ICallbackResult Callback(Action callback) + { + this.SetCallbackWithArguments(callback); + return this; + } + + [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] + public ICallbackResult Callback(Action callback) + { + this.SetCallbackWithArguments(callback); + return this; + } + + [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] + public ICallbackResult Callback(Action callback) + { + this.SetCallbackWithArguments(callback); + return this; + } + + [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] + public ICallbackResult Callback(Action callback) + { + this.SetCallbackWithArguments(callback); + return this; + } + + [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] + public ICallbackResult Callback(Action callback) + { + this.SetCallbackWithArguments(callback); + return this; + } + + [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] + public ICallbackResult Callback(Action callback) + { + this.SetCallbackWithArguments(callback); + return this; + } + + [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] + public ICallbackResult Callback(Action callback) + { + this.SetCallbackWithArguments(callback); + return this; + } + } +} diff --git a/Source/MethodCall.tt b/Source/MethodCall.tt index 4156ec930..8bb06986d 100644 --- a/Source/MethodCall.tt +++ b/Source/MethodCall.tt @@ -1,58 +1,58 @@ -<#@ template debug="false" hostspecific="false" language="C#" #> -<#@ output extension=".Generated.cs" #> -<#@ Assembly Name="System.Core" #> -<#@ Import Namespace="System.Linq" #> -using System; -using System.Diagnostics.CodeAnalysis; -using Moq.Language; -using Moq.Language.Flow; - -namespace Moq -{ - internal partial class MethodCall - { - public IVerifies Raises(Action eventExpression, Func func) - { - return RaisesImpl(eventExpression, func); - } -<# -for (var typeCount = 2; typeCount <= GenericTypeMax; typeCount++) -{ - var typeList = GetGenericList(typeCount, GenericTypeFormat); -#> - - public IVerifies Raises<<#= typeList #>>(Action eventExpression, Func<<#= typeList #>, EventArgs> func) - { - return RaisesImpl(eventExpression, func); - } -<# -} -#> - } - - internal partial class MethodCall - { - [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] - public ICallbackResult Callback(Action callback) - { - this.SetCallbackWithArguments(callback); - return this; - } -<# -for (var typeCount = 2; typeCount <= GenericTypeMax; typeCount++) -{ - var typeList = GetGenericList(typeCount, GenericTypeFormat); -#> - - [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] - public ICallbackResult Callback<<#= typeList #>>(Action<<#= typeList #>> callback) - { - this.SetCallbackWithArguments(callback); - return this; - } -<# -} -#> - } -} +<#@ template debug="false" hostspecific="false" language="C#" #> +<#@ output extension=".Generated.cs" #> +<#@ Assembly Name="System.Core" #> +<#@ Import Namespace="System.Linq" #> +using System; +using System.Diagnostics.CodeAnalysis; +using Moq.Language; +using Moq.Language.Flow; + +namespace Moq +{ + internal partial class MethodCall + { + public IVerifies Raises(Action eventExpression, Func func) + { + return RaisesImpl(eventExpression, func); + } +<# +for (var typeCount = 2; typeCount <= GenericTypeMax; typeCount++) +{ + var typeList = GetGenericList(typeCount, GenericTypeFormat); +#> + + public IVerifies Raises<<#= typeList #>>(Action eventExpression, Func<<#= typeList #>, EventArgs> func) + { + return RaisesImpl(eventExpression, func); + } +<# +} +#> + } + + internal partial class MethodCall + { + [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] + public ICallbackResult Callback(Action callback) + { + this.SetCallbackWithArguments(callback); + return this; + } +<# +for (var typeCount = 2; typeCount <= GenericTypeMax; typeCount++) +{ + var typeList = GetGenericList(typeCount, GenericTypeFormat); +#> + + [SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "callback")] + public ICallbackResult Callback<<#= typeList #>>(Action<<#= typeList #>> callback) + { + this.SetCallbackWithArguments(callback); + return this; + } +<# +} +#> + } +} <#@ Include File="Includes\GenericTypeParameters.tt" #> \ No newline at end of file diff --git a/Source/MethodCallReturn.Generated.cs b/Source/MethodCallReturn.Generated.cs index 404eefdbb..133797226 100644 --- a/Source/MethodCallReturn.Generated.cs +++ b/Source/MethodCallReturn.Generated.cs @@ -1,298 +1,298 @@ -using System; -using System.Diagnostics.CodeAnalysis; -using Moq.Language; -using Moq.Language.Flow; - -namespace Moq -{ - internal sealed partial class MethodCallReturn - { - public IVerifies Raises(Action eventExpression, Func func) - { - return this.RaisesImpl(eventExpression, func); - } - - public IReturnsResult Returns(Func valueExpression) - { - this.SetReturnDelegate(valueExpression); - return this; - } - - [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] - public new IReturnsThrows Callback(Action callback) - { - base.Callback(callback); - return this; - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return this.RaisesImpl(eventExpression, func); - } - - public IReturnsResult Returns(Func valueExpression) - { - this.SetReturnDelegate(valueExpression); - return this; - } - - [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] - public new IReturnsThrows Callback(Action callback) - { - base.Callback(callback); - return this; - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return this.RaisesImpl(eventExpression, func); - } - - public IReturnsResult Returns(Func valueExpression) - { - this.SetReturnDelegate(valueExpression); - return this; - } - - [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] - public new IReturnsThrows Callback(Action callback) - { - base.Callback(callback); - return this; - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return this.RaisesImpl(eventExpression, func); - } - - public IReturnsResult Returns(Func valueExpression) - { - this.SetReturnDelegate(valueExpression); - return this; - } - - [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] - public new IReturnsThrows Callback(Action callback) - { - base.Callback(callback); - return this; - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return this.RaisesImpl(eventExpression, func); - } - - public IReturnsResult Returns(Func valueExpression) - { - this.SetReturnDelegate(valueExpression); - return this; - } - - [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] - public new IReturnsThrows Callback(Action callback) - { - base.Callback(callback); - return this; - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return this.RaisesImpl(eventExpression, func); - } - - public IReturnsResult Returns(Func valueExpression) - { - this.SetReturnDelegate(valueExpression); - return this; - } - - [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] - public new IReturnsThrows Callback(Action callback) - { - base.Callback(callback); - return this; - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return this.RaisesImpl(eventExpression, func); - } - - public IReturnsResult Returns(Func valueExpression) - { - this.SetReturnDelegate(valueExpression); - return this; - } - - [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] - public new IReturnsThrows Callback(Action callback) - { - base.Callback(callback); - return this; - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return this.RaisesImpl(eventExpression, func); - } - - public IReturnsResult Returns(Func valueExpression) - { - this.SetReturnDelegate(valueExpression); - return this; - } - - [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] - public new IReturnsThrows Callback(Action callback) - { - base.Callback(callback); - return this; - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return this.RaisesImpl(eventExpression, func); - } - - public IReturnsResult Returns(Func valueExpression) - { - this.SetReturnDelegate(valueExpression); - return this; - } - - [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] - public new IReturnsThrows Callback(Action callback) - { - base.Callback(callback); - return this; - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return this.RaisesImpl(eventExpression, func); - } - - public IReturnsResult Returns(Func valueExpression) - { - this.SetReturnDelegate(valueExpression); - return this; - } - - [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] - public new IReturnsThrows Callback(Action callback) - { - base.Callback(callback); - return this; - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return this.RaisesImpl(eventExpression, func); - } - - public IReturnsResult Returns(Func valueExpression) - { - this.SetReturnDelegate(valueExpression); - return this; - } - - [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] - public new IReturnsThrows Callback(Action callback) - { - base.Callback(callback); - return this; - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return this.RaisesImpl(eventExpression, func); - } - - public IReturnsResult Returns(Func valueExpression) - { - this.SetReturnDelegate(valueExpression); - return this; - } - - [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] - public new IReturnsThrows Callback(Action callback) - { - base.Callback(callback); - return this; - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return this.RaisesImpl(eventExpression, func); - } - - public IReturnsResult Returns(Func valueExpression) - { - this.SetReturnDelegate(valueExpression); - return this; - } - - [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] - public new IReturnsThrows Callback(Action callback) - { - base.Callback(callback); - return this; - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return this.RaisesImpl(eventExpression, func); - } - - public IReturnsResult Returns(Func valueExpression) - { - this.SetReturnDelegate(valueExpression); - return this; - } - - [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] - public new IReturnsThrows Callback(Action callback) - { - base.Callback(callback); - return this; - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return this.RaisesImpl(eventExpression, func); - } - - public IReturnsResult Returns(Func valueExpression) - { - this.SetReturnDelegate(valueExpression); - return this; - } - - [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] - public new IReturnsThrows Callback(Action callback) - { - base.Callback(callback); - return this; - } - - public IVerifies Raises(Action eventExpression, Func func) - { - return this.RaisesImpl(eventExpression, func); - } - - public IReturnsResult Returns(Func valueExpression) - { - this.SetReturnDelegate(valueExpression); - return this; - } - - [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] - public new IReturnsThrows Callback(Action callback) - { - base.Callback(callback); - return this; - } - } -} +using System; +using System.Diagnostics.CodeAnalysis; +using Moq.Language; +using Moq.Language.Flow; + +namespace Moq +{ + internal sealed partial class MethodCallReturn + { + public IVerifies Raises(Action eventExpression, Func func) + { + return this.RaisesImpl(eventExpression, func); + } + + public IReturnsResult Returns(Func valueExpression) + { + this.SetReturnDelegate(valueExpression); + return this; + } + + [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] + public new IReturnsThrows Callback(Action callback) + { + base.Callback(callback); + return this; + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return this.RaisesImpl(eventExpression, func); + } + + public IReturnsResult Returns(Func valueExpression) + { + this.SetReturnDelegate(valueExpression); + return this; + } + + [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] + public new IReturnsThrows Callback(Action callback) + { + base.Callback(callback); + return this; + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return this.RaisesImpl(eventExpression, func); + } + + public IReturnsResult Returns(Func valueExpression) + { + this.SetReturnDelegate(valueExpression); + return this; + } + + [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] + public new IReturnsThrows Callback(Action callback) + { + base.Callback(callback); + return this; + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return this.RaisesImpl(eventExpression, func); + } + + public IReturnsResult Returns(Func valueExpression) + { + this.SetReturnDelegate(valueExpression); + return this; + } + + [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] + public new IReturnsThrows Callback(Action callback) + { + base.Callback(callback); + return this; + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return this.RaisesImpl(eventExpression, func); + } + + public IReturnsResult Returns(Func valueExpression) + { + this.SetReturnDelegate(valueExpression); + return this; + } + + [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] + public new IReturnsThrows Callback(Action callback) + { + base.Callback(callback); + return this; + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return this.RaisesImpl(eventExpression, func); + } + + public IReturnsResult Returns(Func valueExpression) + { + this.SetReturnDelegate(valueExpression); + return this; + } + + [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] + public new IReturnsThrows Callback(Action callback) + { + base.Callback(callback); + return this; + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return this.RaisesImpl(eventExpression, func); + } + + public IReturnsResult Returns(Func valueExpression) + { + this.SetReturnDelegate(valueExpression); + return this; + } + + [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] + public new IReturnsThrows Callback(Action callback) + { + base.Callback(callback); + return this; + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return this.RaisesImpl(eventExpression, func); + } + + public IReturnsResult Returns(Func valueExpression) + { + this.SetReturnDelegate(valueExpression); + return this; + } + + [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] + public new IReturnsThrows Callback(Action callback) + { + base.Callback(callback); + return this; + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return this.RaisesImpl(eventExpression, func); + } + + public IReturnsResult Returns(Func valueExpression) + { + this.SetReturnDelegate(valueExpression); + return this; + } + + [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] + public new IReturnsThrows Callback(Action callback) + { + base.Callback(callback); + return this; + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return this.RaisesImpl(eventExpression, func); + } + + public IReturnsResult Returns(Func valueExpression) + { + this.SetReturnDelegate(valueExpression); + return this; + } + + [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] + public new IReturnsThrows Callback(Action callback) + { + base.Callback(callback); + return this; + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return this.RaisesImpl(eventExpression, func); + } + + public IReturnsResult Returns(Func valueExpression) + { + this.SetReturnDelegate(valueExpression); + return this; + } + + [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] + public new IReturnsThrows Callback(Action callback) + { + base.Callback(callback); + return this; + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return this.RaisesImpl(eventExpression, func); + } + + public IReturnsResult Returns(Func valueExpression) + { + this.SetReturnDelegate(valueExpression); + return this; + } + + [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] + public new IReturnsThrows Callback(Action callback) + { + base.Callback(callback); + return this; + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return this.RaisesImpl(eventExpression, func); + } + + public IReturnsResult Returns(Func valueExpression) + { + this.SetReturnDelegate(valueExpression); + return this; + } + + [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] + public new IReturnsThrows Callback(Action callback) + { + base.Callback(callback); + return this; + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return this.RaisesImpl(eventExpression, func); + } + + public IReturnsResult Returns(Func valueExpression) + { + this.SetReturnDelegate(valueExpression); + return this; + } + + [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] + public new IReturnsThrows Callback(Action callback) + { + base.Callback(callback); + return this; + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return this.RaisesImpl(eventExpression, func); + } + + public IReturnsResult Returns(Func valueExpression) + { + this.SetReturnDelegate(valueExpression); + return this; + } + + [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] + public new IReturnsThrows Callback(Action callback) + { + base.Callback(callback); + return this; + } + + public IVerifies Raises(Action eventExpression, Func func) + { + return this.RaisesImpl(eventExpression, func); + } + + public IReturnsResult Returns(Func valueExpression) + { + this.SetReturnDelegate(valueExpression); + return this; + } + + [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] + public new IReturnsThrows Callback(Action callback) + { + base.Callback(callback); + return this; + } + } +} diff --git a/Source/MethodCallReturn.tt b/Source/MethodCallReturn.tt index 58aa4a4df..6662c5208 100644 --- a/Source/MethodCallReturn.tt +++ b/Source/MethodCallReturn.tt @@ -1,59 +1,59 @@ -<#@ template debug="false" hostspecific="false" language="C#" #> -<#@ output extension=".Generated.cs" #> -<#@ Assembly Name="System.Core" #> -<#@ Import Namespace="System.Linq" #> -using System; -using System.Diagnostics.CodeAnalysis; -using Moq.Language; -using Moq.Language.Flow; - -namespace Moq -{ - internal sealed partial class MethodCallReturn - { - public IVerifies Raises(Action eventExpression, Func func) - { - return this.RaisesImpl(eventExpression, func); - } - - public IReturnsResult Returns(Func valueExpression) - { - this.SetReturnDelegate(valueExpression); - return this; - } - - [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] - public new IReturnsThrows Callback(Action callback) - { - base.Callback(callback); - return this; - } -<# -for (var typeCount = 2; typeCount <= GenericTypeMax; typeCount++) -{ - var typeList = GetGenericList(typeCount, GenericTypeFormat); -#> - - public IVerifies Raises<<#= typeList #>>(Action eventExpression, Func<<#= typeList #>, EventArgs> func) - { - return this.RaisesImpl(eventExpression, func); - } - - public IReturnsResult Returns<<#= typeList #>>(Func<<#= typeList #>, TResult> valueExpression) - { - this.SetReturnDelegate(valueExpression); - return this; - } - - [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] - public new IReturnsThrows Callback<<#= typeList #>>(Action<<#= typeList #>> callback) - { - base.Callback(callback); - return this; - } -<# -} -#> - } -} +<#@ template debug="false" hostspecific="false" language="C#" #> +<#@ output extension=".Generated.cs" #> +<#@ Assembly Name="System.Core" #> +<#@ Import Namespace="System.Linq" #> +using System; +using System.Diagnostics.CodeAnalysis; +using Moq.Language; +using Moq.Language.Flow; + +namespace Moq +{ + internal sealed partial class MethodCallReturn + { + public IVerifies Raises(Action eventExpression, Func func) + { + return this.RaisesImpl(eventExpression, func); + } + + public IReturnsResult Returns(Func valueExpression) + { + this.SetReturnDelegate(valueExpression); + return this; + } + + [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] + public new IReturnsThrows Callback(Action callback) + { + base.Callback(callback); + return this; + } +<# +for (var typeCount = 2; typeCount <= GenericTypeMax; typeCount++) +{ + var typeList = GetGenericList(typeCount, GenericTypeFormat); +#> + + public IVerifies Raises<<#= typeList #>>(Action eventExpression, Func<<#= typeList #>, EventArgs> func) + { + return this.RaisesImpl(eventExpression, func); + } + + public IReturnsResult Returns<<#= typeList #>>(Func<<#= typeList #>, TResult> valueExpression) + { + this.SetReturnDelegate(valueExpression); + return this; + } + + [SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Justification = "This class provides typed members for the method-returning interfaces. It's never used through the base class type.")] + public new IReturnsThrows Callback<<#= typeList #>>(Action<<#= typeList #>> callback) + { + base.Callback(callback); + return this; + } +<# +} +#> + } +} <#@ Include File="Includes\GenericTypeParameters.tt" #> \ No newline at end of file diff --git a/Source/Microsoft/Delegates.cs b/Source/Microsoft/Delegates.cs index 1f0fb7f6b..0c09003cf 100644 --- a/Source/Microsoft/Delegates.cs +++ b/Source/Microsoft/Delegates.cs @@ -1,679 +1,679 @@ -#if NET3x -using System.Diagnostics.CodeAnalysis; - -namespace System -{ - /// - /// Encapsulates a method that has five parameters and does not return a value. - /// - /// The type of the first parameter of the method that this delegate encapsulates. - /// The type of the second parameter of the method that this delegate encapsulates. - /// The type of the third parameter of the method that this delegate encapsulates. - /// The type of the fourth parameter of the method that this delegate encapsulates. - /// The type of the fifth parameter of the method that this delegate encapsulates. - /// The first parameter of the method that this delegate encapsulates. - /// The second parameter of the method that this delegate encapsulates. - /// The third parameter of the method that this delegate encapsulates. - /// The fourth parameter of the method that this delegate encapsulates. - /// The fifth parameter of the method that this delegate encapsulates. - [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] - public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5); - - /// - /// Encapsulates a method that has five parameters and returns a value of the type specified by the parameter. - /// - /// The type of the first parameter of the method that this delegate encapsulates. - /// The type of the second parameter of the method that this delegate encapsulates. - /// The type of the third parameter of the method that this delegate encapsulates. - /// The type of the fourth parameter of the method that this delegate encapsulates. - /// The type of the fifth parameter of the method that this delegate encapsulates. - /// The type of the return value of the method that this delegate encapsulates. - /// The first parameter of the method that this delegate encapsulates. - /// The second parameter of the method that this delegate encapsulates. - /// The third parameter of the method that this delegate encapsulates. - /// The fourth parameter of the method that this delegate encapsulates. - /// The fifth parameter of the method that this delegate encapsulates. - /// The return value of the method that this delegate encapsulates. - [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] - public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5); - - /// - /// Encapsulates a method that has six parameters and does not return a value. - /// - /// The type of the first parameter of the method that this delegate encapsulates. - /// The type of the second parameter of the method that this delegate encapsulates. - /// The type of the third parameter of the method that this delegate encapsulates. - /// The type of the fourth parameter of the method that this delegate encapsulates. - /// The type of the fifth parameter of the method that this delegate encapsulates. - /// The type of the sixth parameter of the method that this delegate encapsulates. - /// The first parameter of the method that this delegate encapsulates. - /// The second parameter of the method that this delegate encapsulates. - /// The third parameter of the method that this delegate encapsulates. - /// The fourth parameter of the method that this delegate encapsulates. - /// The fifth parameter of the method that this delegate encapsulates. - /// The sixth parameter of the method that this delegate encapsulates. - [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] - public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6); - - /// - /// Encapsulates a method that has six parameters and returns a value of the type specified by the parameter. - /// - /// The type of the first parameter of the method that this delegate encapsulates. - /// The type of the second parameter of the method that this delegate encapsulates. - /// The type of the third parameter of the method that this delegate encapsulates. - /// The type of the fourth parameter of the method that this delegate encapsulates. - /// The type of the fifth parameter of the method that this delegate encapsulates. - /// The type of the sixth parameter of the method that this delegate encapsulates. - /// The type of the return value of the method that this delegate encapsulates. - /// The first parameter of the method that this delegate encapsulates. - /// The second parameter of the method that this delegate encapsulates. - /// The third parameter of the method that this delegate encapsulates. - /// The fourth parameter of the method that this delegate encapsulates. - /// The fifth parameter of the method that this delegate encapsulates. - /// The sixth parameter of the method that this delegate encapsulates. - /// The return value of the method that this delegate encapsulates. - [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] - public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6); - - /// - /// Encapsulates a method that has seven parameters and does not return a value. - /// - /// The type of the first parameter of the method that this delegate encapsulates. - /// The type of the second parameter of the method that this delegate encapsulates. - /// The type of the third parameter of the method that this delegate encapsulates. - /// The type of the fourth parameter of the method that this delegate encapsulates. - /// The type of the fifth parameter of the method that this delegate encapsulates. - /// The type of the sixth parameter of the method that this delegate encapsulates. - /// The type of the seventh parameter of the method that this delegate encapsulates. - /// The first parameter of the method that this delegate encapsulates. - /// The second parameter of the method that this delegate encapsulates. - /// The third parameter of the method that this delegate encapsulates. - /// The fourth parameter of the method that this delegate encapsulates. - /// The fifth parameter of the method that this delegate encapsulates. - /// The sixth parameter of the method that this delegate encapsulates. - /// The seventh parameter of the method that this delegate encapsulates. - [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] - public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7); - - /// - /// Encapsulates a method that has seven parameters and returns a value of the type specified by the parameter. - /// - /// The type of the first parameter of the method that this delegate encapsulates. - /// The type of the second parameter of the method that this delegate encapsulates. - /// The type of the third parameter of the method that this delegate encapsulates. - /// The type of the fourth parameter of the method that this delegate encapsulates. - /// The type of the fifth parameter of the method that this delegate encapsulates. - /// The type of the sixth parameter of the method that this delegate encapsulates. - /// The type of the seventh parameter of the method that this delegate encapsulates. - /// The type of the return value of the method that this delegate encapsulates. - /// The first parameter of the method that this delegate encapsulates. - /// The second parameter of the method that this delegate encapsulates. - /// The third parameter of the method that this delegate encapsulates. - /// The fourth parameter of the method that this delegate encapsulates. - /// The fifth parameter of the method that this delegate encapsulates. - /// The sixth parameter of the method that this delegate encapsulates. - /// The seventh parameter of the method that this delegate encapsulates. - /// The return value of the method that this delegate encapsulates. - [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] - public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7); - - /// - /// Encapsulates a method that has eight parameters and does not return a value. - /// - /// The type of the first parameter of the method that this delegate encapsulates. - /// The type of the second parameter of the method that this delegate encapsulates. - /// The type of the third parameter of the method that this delegate encapsulates. - /// The type of the fourth parameter of the method that this delegate encapsulates. - /// The type of the fifth parameter of the method that this delegate encapsulates. - /// The type of the sixth parameter of the method that this delegate encapsulates. - /// The type of the seventh parameter of the method that this delegate encapsulates. - /// The type of the eighth parameter of the method that this delegate encapsulates. - /// The first parameter of the method that this delegate encapsulates. - /// The second parameter of the method that this delegate encapsulates. - /// The third parameter of the method that this delegate encapsulates. - /// The fourth parameter of the method that this delegate encapsulates. - /// The fifth parameter of the method that this delegate encapsulates. - /// The sixth parameter of the method that this delegate encapsulates. - /// The seventh parameter of the method that this delegate encapsulates. - /// The eighth parameter of the method that this delegate encapsulates. - [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] - public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8); - - /// - /// Encapsulates a method that has eight parameters and returns a value of the type specified by the parameter. - /// - /// The type of the first parameter of the method that this delegate encapsulates. - /// The type of the second parameter of the method that this delegate encapsulates. - /// The type of the third parameter of the method that this delegate encapsulates. - /// The type of the fourth parameter of the method that this delegate encapsulates. - /// The type of the fifth parameter of the method that this delegate encapsulates. - /// The type of the sixth parameter of the method that this delegate encapsulates. - /// The type of the seventh parameter of the method that this delegate encapsulates. - /// The type of the eighth parameter of the method that this delegate encapsulates. - /// The type of the return value of the method that this delegate encapsulates. - /// The first parameter of the method that this delegate encapsulates. - /// The second parameter of the method that this delegate encapsulates. - /// The third parameter of the method that this delegate encapsulates. - /// The fourth parameter of the method that this delegate encapsulates. - /// The fifth parameter of the method that this delegate encapsulates. - /// The sixth parameter of the method that this delegate encapsulates. - /// The seventh parameter of the method that this delegate encapsulates. - /// The eighth parameter of the method that this delegate encapsulates. - /// The return value of the method that this delegate encapsulates. - [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] - public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8); - - /// - /// Encapsulates a method that has nine parameters and does not return a value. - /// - /// The type of the first parameter of the method that this delegate encapsulates. - /// The type of the second parameter of the method that this delegate encapsulates. - /// The type of the third parameter of the method that this delegate encapsulates. - /// The type of the fourth parameter of the method that this delegate encapsulates. - /// The type of the fifth parameter of the method that this delegate encapsulates. - /// The type of the sixth parameter of the method that this delegate encapsulates. - /// The type of the seventh parameter of the method that this delegate encapsulates. - /// The type of the eighth parameter of the method that this delegate encapsulates. - /// The type of the nineth parameter of the method that this delegate encapsulates. - /// The first parameter of the method that this delegate encapsulates. - /// The second parameter of the method that this delegate encapsulates. - /// The third parameter of the method that this delegate encapsulates. - /// The fourth parameter of the method that this delegate encapsulates. - /// The fifth parameter of the method that this delegate encapsulates. - /// The sixth parameter of the method that this delegate encapsulates. - /// The seventh parameter of the method that this delegate encapsulates. - /// The eighth parameter of the method that this delegate encapsulates. - /// The nineth parameter of the method that this delegate encapsulates. - [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] - public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9); - - /// - /// Encapsulates a method that has nine parameters and returns a value of the type specified by the parameter. - /// - /// The type of the first parameter of the method that this delegate encapsulates. - /// The type of the second parameter of the method that this delegate encapsulates. - /// The type of the third parameter of the method that this delegate encapsulates. - /// The type of the fourth parameter of the method that this delegate encapsulates. - /// The type of the fifth parameter of the method that this delegate encapsulates. - /// The type of the sixth parameter of the method that this delegate encapsulates. - /// The type of the seventh parameter of the method that this delegate encapsulates. - /// The type of the eighth parameter of the method that this delegate encapsulates. - /// The type of the nineth parameter of the method that this delegate encapsulates. - /// The type of the return value of the method that this delegate encapsulates. - /// The first parameter of the method that this delegate encapsulates. - /// The second parameter of the method that this delegate encapsulates. - /// The third parameter of the method that this delegate encapsulates. - /// The fourth parameter of the method that this delegate encapsulates. - /// The fifth parameter of the method that this delegate encapsulates. - /// The sixth parameter of the method that this delegate encapsulates. - /// The seventh parameter of the method that this delegate encapsulates. - /// The eighth parameter of the method that this delegate encapsulates. - /// The nineth parameter of the method that this delegate encapsulates. - /// The return value of the method that this delegate encapsulates. - [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] - public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9); - - /// - /// Encapsulates a method that has ten parameters and does not return a value. - /// - /// The type of the first parameter of the method that this delegate encapsulates. - /// The type of the second parameter of the method that this delegate encapsulates. - /// The type of the third parameter of the method that this delegate encapsulates. - /// The type of the fourth parameter of the method that this delegate encapsulates. - /// The type of the fifth parameter of the method that this delegate encapsulates. - /// The type of the sixth parameter of the method that this delegate encapsulates. - /// The type of the seventh parameter of the method that this delegate encapsulates. - /// The type of the eighth parameter of the method that this delegate encapsulates. - /// The type of the nineth parameter of the method that this delegate encapsulates. - /// The type of the tenth parameter of the method that this delegate encapsulates. - /// The first parameter of the method that this delegate encapsulates. - /// The second parameter of the method that this delegate encapsulates. - /// The third parameter of the method that this delegate encapsulates. - /// The fourth parameter of the method that this delegate encapsulates. - /// The fifth parameter of the method that this delegate encapsulates. - /// The sixth parameter of the method that this delegate encapsulates. - /// The seventh parameter of the method that this delegate encapsulates. - /// The eighth parameter of the method that this delegate encapsulates. - /// The nineth parameter of the method that this delegate encapsulates. - /// The tenth parameter of the method that this delegate encapsulates. - [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] - public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10); - - /// - /// Encapsulates a method that has ten parameters and returns a value of the type specified by the parameter. - /// - /// The type of the first parameter of the method that this delegate encapsulates. - /// The type of the second parameter of the method that this delegate encapsulates. - /// The type of the third parameter of the method that this delegate encapsulates. - /// The type of the fourth parameter of the method that this delegate encapsulates. - /// The type of the fifth parameter of the method that this delegate encapsulates. - /// The type of the sixth parameter of the method that this delegate encapsulates. - /// The type of the seventh parameter of the method that this delegate encapsulates. - /// The type of the eighth parameter of the method that this delegate encapsulates. - /// The type of the nineth parameter of the method that this delegate encapsulates. - /// The type of the tenth parameter of the method that this delegate encapsulates. - /// The type of the return value of the method that this delegate encapsulates. - /// The first parameter of the method that this delegate encapsulates. - /// The second parameter of the method that this delegate encapsulates. - /// The third parameter of the method that this delegate encapsulates. - /// The fourth parameter of the method that this delegate encapsulates. - /// The fifth parameter of the method that this delegate encapsulates. - /// The sixth parameter of the method that this delegate encapsulates. - /// The seventh parameter of the method that this delegate encapsulates. - /// The eighth parameter of the method that this delegate encapsulates. - /// The nineth parameter of the method that this delegate encapsulates. - /// The tenth parameter of the method that this delegate encapsulates. - /// The return value of the method that this delegate encapsulates. - [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] - public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10); - - /// - /// Encapsulates a method that has eleven parameters and does not return a value. - /// - /// The type of the first parameter of the method that this delegate encapsulates. - /// The type of the second parameter of the method that this delegate encapsulates. - /// The type of the third parameter of the method that this delegate encapsulates. - /// The type of the fourth parameter of the method that this delegate encapsulates. - /// The type of the fifth parameter of the method that this delegate encapsulates. - /// The type of the sixth parameter of the method that this delegate encapsulates. - /// The type of the seventh parameter of the method that this delegate encapsulates. - /// The type of the eighth parameter of the method that this delegate encapsulates. - /// The type of the nineth parameter of the method that this delegate encapsulates. - /// The type of the tenth parameter of the method that this delegate encapsulates. - /// The type of the eleventh parameter of the method that this delegate encapsulates. - /// The first parameter of the method that this delegate encapsulates. - /// The second parameter of the method that this delegate encapsulates. - /// The third parameter of the method that this delegate encapsulates. - /// The fourth parameter of the method that this delegate encapsulates. - /// The fifth parameter of the method that this delegate encapsulates. - /// The sixth parameter of the method that this delegate encapsulates. - /// The seventh parameter of the method that this delegate encapsulates. - /// The eighth parameter of the method that this delegate encapsulates. - /// The nineth parameter of the method that this delegate encapsulates. - /// The tenth parameter of the method that this delegate encapsulates. - /// The eleventh parameter of the method that this delegate encapsulates. - [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] - public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11); - - /// - /// Encapsulates a method that has eleven parameters and returns a value of the type specified by the parameter. - /// - /// The type of the first parameter of the method that this delegate encapsulates. - /// The type of the second parameter of the method that this delegate encapsulates. - /// The type of the third parameter of the method that this delegate encapsulates. - /// The type of the fourth parameter of the method that this delegate encapsulates. - /// The type of the fifth parameter of the method that this delegate encapsulates. - /// The type of the sixth parameter of the method that this delegate encapsulates. - /// The type of the seventh parameter of the method that this delegate encapsulates. - /// The type of the eighth parameter of the method that this delegate encapsulates. - /// The type of the nineth parameter of the method that this delegate encapsulates. - /// The type of the tenth parameter of the method that this delegate encapsulates. - /// The type of the eleventh parameter of the method that this delegate encapsulates. - /// The type of the return value of the method that this delegate encapsulates. - /// The first parameter of the method that this delegate encapsulates. - /// The second parameter of the method that this delegate encapsulates. - /// The third parameter of the method that this delegate encapsulates. - /// The fourth parameter of the method that this delegate encapsulates. - /// The fifth parameter of the method that this delegate encapsulates. - /// The sixth parameter of the method that this delegate encapsulates. - /// The seventh parameter of the method that this delegate encapsulates. - /// The eighth parameter of the method that this delegate encapsulates. - /// The nineth parameter of the method that this delegate encapsulates. - /// The tenth parameter of the method that this delegate encapsulates. - /// The eleventh parameter of the method that this delegate encapsulates. - /// The return value of the method that this delegate encapsulates. - [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] - public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11); - - /// - /// Encapsulates a method that has twelve parameters and does not return a value. - /// - /// The type of the first parameter of the method that this delegate encapsulates. - /// The type of the second parameter of the method that this delegate encapsulates. - /// The type of the third parameter of the method that this delegate encapsulates. - /// The type of the fourth parameter of the method that this delegate encapsulates. - /// The type of the fifth parameter of the method that this delegate encapsulates. - /// The type of the sixth parameter of the method that this delegate encapsulates. - /// The type of the seventh parameter of the method that this delegate encapsulates. - /// The type of the eighth parameter of the method that this delegate encapsulates. - /// The type of the nineth parameter of the method that this delegate encapsulates. - /// The type of the tenth parameter of the method that this delegate encapsulates. - /// The type of the eleventh parameter of the method that this delegate encapsulates. - /// The type of the twelfth parameter of the method that this delegate encapsulates. - /// The first parameter of the method that this delegate encapsulates. - /// The second parameter of the method that this delegate encapsulates. - /// The third parameter of the method that this delegate encapsulates. - /// The fourth parameter of the method that this delegate encapsulates. - /// The fifth parameter of the method that this delegate encapsulates. - /// The sixth parameter of the method that this delegate encapsulates. - /// The seventh parameter of the method that this delegate encapsulates. - /// The eighth parameter of the method that this delegate encapsulates. - /// The nineth parameter of the method that this delegate encapsulates. - /// The tenth parameter of the method that this delegate encapsulates. - /// The eleventh parameter of the method that this delegate encapsulates. - /// The twelfth parameter of the method that this delegate encapsulates. - [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] - public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12); - - /// - /// Encapsulates a method that has twelve parameters and returns a value of the type specified by the parameter. - /// - /// The type of the first parameter of the method that this delegate encapsulates. - /// The type of the second parameter of the method that this delegate encapsulates. - /// The type of the third parameter of the method that this delegate encapsulates. - /// The type of the fourth parameter of the method that this delegate encapsulates. - /// The type of the fifth parameter of the method that this delegate encapsulates. - /// The type of the sixth parameter of the method that this delegate encapsulates. - /// The type of the seventh parameter of the method that this delegate encapsulates. - /// The type of the eighth parameter of the method that this delegate encapsulates. - /// The type of the nineth parameter of the method that this delegate encapsulates. - /// The type of the tenth parameter of the method that this delegate encapsulates. - /// The type of the eleventh parameter of the method that this delegate encapsulates. - /// The type of the twelfth parameter of the method that this delegate encapsulates. - /// The type of the return value of the method that this delegate encapsulates. - /// The first parameter of the method that this delegate encapsulates. - /// The second parameter of the method that this delegate encapsulates. - /// The third parameter of the method that this delegate encapsulates. - /// The fourth parameter of the method that this delegate encapsulates. - /// The fifth parameter of the method that this delegate encapsulates. - /// The sixth parameter of the method that this delegate encapsulates. - /// The seventh parameter of the method that this delegate encapsulates. - /// The eighth parameter of the method that this delegate encapsulates. - /// The nineth parameter of the method that this delegate encapsulates. - /// The tenth parameter of the method that this delegate encapsulates. - /// The eleventh parameter of the method that this delegate encapsulates. - /// The twelfth parameter of the method that this delegate encapsulates. - /// The return value of the method that this delegate encapsulates. - [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] - public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12); - - /// - /// Encapsulates a method that has thirteen parameters and does not return a value. - /// - /// The type of the first parameter of the method that this delegate encapsulates. - /// The type of the second parameter of the method that this delegate encapsulates. - /// The type of the third parameter of the method that this delegate encapsulates. - /// The type of the fourth parameter of the method that this delegate encapsulates. - /// The type of the fifth parameter of the method that this delegate encapsulates. - /// The type of the sixth parameter of the method that this delegate encapsulates. - /// The type of the seventh parameter of the method that this delegate encapsulates. - /// The type of the eighth parameter of the method that this delegate encapsulates. - /// The type of the nineth parameter of the method that this delegate encapsulates. - /// The type of the tenth parameter of the method that this delegate encapsulates. - /// The type of the eleventh parameter of the method that this delegate encapsulates. - /// The type of the twelfth parameter of the method that this delegate encapsulates. - /// The type of the thirteenth parameter of the method that this delegate encapsulates. - /// The first parameter of the method that this delegate encapsulates. - /// The second parameter of the method that this delegate encapsulates. - /// The third parameter of the method that this delegate encapsulates. - /// The fourth parameter of the method that this delegate encapsulates. - /// The fifth parameter of the method that this delegate encapsulates. - /// The sixth parameter of the method that this delegate encapsulates. - /// The seventh parameter of the method that this delegate encapsulates. - /// The eighth parameter of the method that this delegate encapsulates. - /// The nineth parameter of the method that this delegate encapsulates. - /// The tenth parameter of the method that this delegate encapsulates. - /// The eleventh parameter of the method that this delegate encapsulates. - /// The twelfth parameter of the method that this delegate encapsulates. - /// The thirteenth parameter of the method that this delegate encapsulates. - [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] - public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13); - - /// - /// Encapsulates a method that has thirteen parameters and returns a value of the type specified by the parameter. - /// - /// The type of the first parameter of the method that this delegate encapsulates. - /// The type of the second parameter of the method that this delegate encapsulates. - /// The type of the third parameter of the method that this delegate encapsulates. - /// The type of the fourth parameter of the method that this delegate encapsulates. - /// The type of the fifth parameter of the method that this delegate encapsulates. - /// The type of the sixth parameter of the method that this delegate encapsulates. - /// The type of the seventh parameter of the method that this delegate encapsulates. - /// The type of the eighth parameter of the method that this delegate encapsulates. - /// The type of the nineth parameter of the method that this delegate encapsulates. - /// The type of the tenth parameter of the method that this delegate encapsulates. - /// The type of the eleventh parameter of the method that this delegate encapsulates. - /// The type of the twelfth parameter of the method that this delegate encapsulates. - /// The type of the thirteenth parameter of the method that this delegate encapsulates. - /// The type of the return value of the method that this delegate encapsulates. - /// The first parameter of the method that this delegate encapsulates. - /// The second parameter of the method that this delegate encapsulates. - /// The third parameter of the method that this delegate encapsulates. - /// The fourth parameter of the method that this delegate encapsulates. - /// The fifth parameter of the method that this delegate encapsulates. - /// The sixth parameter of the method that this delegate encapsulates. - /// The seventh parameter of the method that this delegate encapsulates. - /// The eighth parameter of the method that this delegate encapsulates. - /// The nineth parameter of the method that this delegate encapsulates. - /// The tenth parameter of the method that this delegate encapsulates. - /// The eleventh parameter of the method that this delegate encapsulates. - /// The twelfth parameter of the method that this delegate encapsulates. - /// The thirteenth parameter of the method that this delegate encapsulates. - /// The return value of the method that this delegate encapsulates. - [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] - public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13); - - /// - /// Encapsulates a method that has fourteen parameters and does not return a value. - /// - /// The type of the first parameter of the method that this delegate encapsulates. - /// The type of the second parameter of the method that this delegate encapsulates. - /// The type of the third parameter of the method that this delegate encapsulates. - /// The type of the fourth parameter of the method that this delegate encapsulates. - /// The type of the fifth parameter of the method that this delegate encapsulates. - /// The type of the sixth parameter of the method that this delegate encapsulates. - /// The type of the seventh parameter of the method that this delegate encapsulates. - /// The type of the eighth parameter of the method that this delegate encapsulates. - /// The type of the nineth parameter of the method that this delegate encapsulates. - /// The type of the tenth parameter of the method that this delegate encapsulates. - /// The type of the eleventh parameter of the method that this delegate encapsulates. - /// The type of the twelfth parameter of the method that this delegate encapsulates. - /// The type of the thirteenth parameter of the method that this delegate encapsulates. - /// The type of the fourteenth parameter of the method that this delegate encapsulates. - /// The first parameter of the method that this delegate encapsulates. - /// The second parameter of the method that this delegate encapsulates. - /// The third parameter of the method that this delegate encapsulates. - /// The fourth parameter of the method that this delegate encapsulates. - /// The fifth parameter of the method that this delegate encapsulates. - /// The sixth parameter of the method that this delegate encapsulates. - /// The seventh parameter of the method that this delegate encapsulates. - /// The eighth parameter of the method that this delegate encapsulates. - /// The nineth parameter of the method that this delegate encapsulates. - /// The tenth parameter of the method that this delegate encapsulates. - /// The eleventh parameter of the method that this delegate encapsulates. - /// The twelfth parameter of the method that this delegate encapsulates. - /// The thirteenth parameter of the method that this delegate encapsulates. - /// The fourteenth parameter of the method that this delegate encapsulates. - [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] - public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14); - - /// - /// Encapsulates a method that has fourteen parameters and returns a value of the type specified by the parameter. - /// - /// The type of the first parameter of the method that this delegate encapsulates. - /// The type of the second parameter of the method that this delegate encapsulates. - /// The type of the third parameter of the method that this delegate encapsulates. - /// The type of the fourth parameter of the method that this delegate encapsulates. - /// The type of the fifth parameter of the method that this delegate encapsulates. - /// The type of the sixth parameter of the method that this delegate encapsulates. - /// The type of the seventh parameter of the method that this delegate encapsulates. - /// The type of the eighth parameter of the method that this delegate encapsulates. - /// The type of the nineth parameter of the method that this delegate encapsulates. - /// The type of the tenth parameter of the method that this delegate encapsulates. - /// The type of the eleventh parameter of the method that this delegate encapsulates. - /// The type of the twelfth parameter of the method that this delegate encapsulates. - /// The type of the thirteenth parameter of the method that this delegate encapsulates. - /// The type of the fourteenth parameter of the method that this delegate encapsulates. - /// The type of the return value of the method that this delegate encapsulates. - /// The first parameter of the method that this delegate encapsulates. - /// The second parameter of the method that this delegate encapsulates. - /// The third parameter of the method that this delegate encapsulates. - /// The fourth parameter of the method that this delegate encapsulates. - /// The fifth parameter of the method that this delegate encapsulates. - /// The sixth parameter of the method that this delegate encapsulates. - /// The seventh parameter of the method that this delegate encapsulates. - /// The eighth parameter of the method that this delegate encapsulates. - /// The nineth parameter of the method that this delegate encapsulates. - /// The tenth parameter of the method that this delegate encapsulates. - /// The eleventh parameter of the method that this delegate encapsulates. - /// The twelfth parameter of the method that this delegate encapsulates. - /// The thirteenth parameter of the method that this delegate encapsulates. - /// The fourteenth parameter of the method that this delegate encapsulates. - /// The return value of the method that this delegate encapsulates. - [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] - public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14); - - /// - /// Encapsulates a method that has fifteen parameters and does not return a value. - /// - /// The type of the first parameter of the method that this delegate encapsulates. - /// The type of the second parameter of the method that this delegate encapsulates. - /// The type of the third parameter of the method that this delegate encapsulates. - /// The type of the fourth parameter of the method that this delegate encapsulates. - /// The type of the fifth parameter of the method that this delegate encapsulates. - /// The type of the sixth parameter of the method that this delegate encapsulates. - /// The type of the seventh parameter of the method that this delegate encapsulates. - /// The type of the eighth parameter of the method that this delegate encapsulates. - /// The type of the nineth parameter of the method that this delegate encapsulates. - /// The type of the tenth parameter of the method that this delegate encapsulates. - /// The type of the eleventh parameter of the method that this delegate encapsulates. - /// The type of the twelfth parameter of the method that this delegate encapsulates. - /// The type of the thirteenth parameter of the method that this delegate encapsulates. - /// The type of the fourteenth parameter of the method that this delegate encapsulates. - /// The type of the fifteenth parameter of the method that this delegate encapsulates. - /// The first parameter of the method that this delegate encapsulates. - /// The second parameter of the method that this delegate encapsulates. - /// The third parameter of the method that this delegate encapsulates. - /// The fourth parameter of the method that this delegate encapsulates. - /// The fifth parameter of the method that this delegate encapsulates. - /// The sixth parameter of the method that this delegate encapsulates. - /// The seventh parameter of the method that this delegate encapsulates. - /// The eighth parameter of the method that this delegate encapsulates. - /// The nineth parameter of the method that this delegate encapsulates. - /// The tenth parameter of the method that this delegate encapsulates. - /// The eleventh parameter of the method that this delegate encapsulates. - /// The twelfth parameter of the method that this delegate encapsulates. - /// The thirteenth parameter of the method that this delegate encapsulates. - /// The fourteenth parameter of the method that this delegate encapsulates. - /// The fifteenth parameter of the method that this delegate encapsulates. - [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] - public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15); - - /// - /// Encapsulates a method that has fifteen parameters and returns a value of the type specified by the parameter. - /// - /// The type of the first parameter of the method that this delegate encapsulates. - /// The type of the second parameter of the method that this delegate encapsulates. - /// The type of the third parameter of the method that this delegate encapsulates. - /// The type of the fourth parameter of the method that this delegate encapsulates. - /// The type of the fifth parameter of the method that this delegate encapsulates. - /// The type of the sixth parameter of the method that this delegate encapsulates. - /// The type of the seventh parameter of the method that this delegate encapsulates. - /// The type of the eighth parameter of the method that this delegate encapsulates. - /// The type of the nineth parameter of the method that this delegate encapsulates. - /// The type of the tenth parameter of the method that this delegate encapsulates. - /// The type of the eleventh parameter of the method that this delegate encapsulates. - /// The type of the twelfth parameter of the method that this delegate encapsulates. - /// The type of the thirteenth parameter of the method that this delegate encapsulates. - /// The type of the fourteenth parameter of the method that this delegate encapsulates. - /// The type of the fifteenth parameter of the method that this delegate encapsulates. - /// The type of the return value of the method that this delegate encapsulates. - /// The first parameter of the method that this delegate encapsulates. - /// The second parameter of the method that this delegate encapsulates. - /// The third parameter of the method that this delegate encapsulates. - /// The fourth parameter of the method that this delegate encapsulates. - /// The fifth parameter of the method that this delegate encapsulates. - /// The sixth parameter of the method that this delegate encapsulates. - /// The seventh parameter of the method that this delegate encapsulates. - /// The eighth parameter of the method that this delegate encapsulates. - /// The nineth parameter of the method that this delegate encapsulates. - /// The tenth parameter of the method that this delegate encapsulates. - /// The eleventh parameter of the method that this delegate encapsulates. - /// The twelfth parameter of the method that this delegate encapsulates. - /// The thirteenth parameter of the method that this delegate encapsulates. - /// The fourteenth parameter of the method that this delegate encapsulates. - /// The fifteenth parameter of the method that this delegate encapsulates. - /// The return value of the method that this delegate encapsulates. - [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] - public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15); - - /// - /// Encapsulates a method that has sixteen parameters and does not return a value. - /// - /// The type of the first parameter of the method that this delegate encapsulates. - /// The type of the second parameter of the method that this delegate encapsulates. - /// The type of the third parameter of the method that this delegate encapsulates. - /// The type of the fourth parameter of the method that this delegate encapsulates. - /// The type of the fifth parameter of the method that this delegate encapsulates. - /// The type of the sixth parameter of the method that this delegate encapsulates. - /// The type of the seventh parameter of the method that this delegate encapsulates. - /// The type of the eighth parameter of the method that this delegate encapsulates. - /// The type of the nineth parameter of the method that this delegate encapsulates. - /// The type of the tenth parameter of the method that this delegate encapsulates. - /// The type of the eleventh parameter of the method that this delegate encapsulates. - /// The type of the twelfth parameter of the method that this delegate encapsulates. - /// The type of the thirteenth parameter of the method that this delegate encapsulates. - /// The type of the fourteenth parameter of the method that this delegate encapsulates. - /// The type of the fifteenth parameter of the method that this delegate encapsulates. - /// The type of the sixteenth parameter of the method that this delegate encapsulates. - /// The first parameter of the method that this delegate encapsulates. - /// The second parameter of the method that this delegate encapsulates. - /// The third parameter of the method that this delegate encapsulates. - /// The fourth parameter of the method that this delegate encapsulates. - /// The fifth parameter of the method that this delegate encapsulates. - /// The sixth parameter of the method that this delegate encapsulates. - /// The seventh parameter of the method that this delegate encapsulates. - /// The eighth parameter of the method that this delegate encapsulates. - /// The nineth parameter of the method that this delegate encapsulates. - /// The tenth parameter of the method that this delegate encapsulates. - /// The eleventh parameter of the method that this delegate encapsulates. - /// The twelfth parameter of the method that this delegate encapsulates. - /// The thirteenth parameter of the method that this delegate encapsulates. - /// The fourteenth parameter of the method that this delegate encapsulates. - /// The fifteenth parameter of the method that this delegate encapsulates. - /// The sixteenth parameter of the method that this delegate encapsulates. - [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] - public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16); - - /// - /// Encapsulates a method that has sixteen parameters and returns a value of the type specified by the parameter. - /// - /// The type of the first parameter of the method that this delegate encapsulates. - /// The type of the second parameter of the method that this delegate encapsulates. - /// The type of the third parameter of the method that this delegate encapsulates. - /// The type of the fourth parameter of the method that this delegate encapsulates. - /// The type of the fifth parameter of the method that this delegate encapsulates. - /// The type of the sixth parameter of the method that this delegate encapsulates. - /// The type of the seventh parameter of the method that this delegate encapsulates. - /// The type of the eighth parameter of the method that this delegate encapsulates. - /// The type of the nineth parameter of the method that this delegate encapsulates. - /// The type of the tenth parameter of the method that this delegate encapsulates. - /// The type of the eleventh parameter of the method that this delegate encapsulates. - /// The type of the twelfth parameter of the method that this delegate encapsulates. - /// The type of the thirteenth parameter of the method that this delegate encapsulates. - /// The type of the fourteenth parameter of the method that this delegate encapsulates. - /// The type of the fifteenth parameter of the method that this delegate encapsulates. - /// The type of the sixteenth parameter of the method that this delegate encapsulates. - /// The type of the return value of the method that this delegate encapsulates. - /// The first parameter of the method that this delegate encapsulates. - /// The second parameter of the method that this delegate encapsulates. - /// The third parameter of the method that this delegate encapsulates. - /// The fourth parameter of the method that this delegate encapsulates. - /// The fifth parameter of the method that this delegate encapsulates. - /// The sixth parameter of the method that this delegate encapsulates. - /// The seventh parameter of the method that this delegate encapsulates. - /// The eighth parameter of the method that this delegate encapsulates. - /// The nineth parameter of the method that this delegate encapsulates. - /// The tenth parameter of the method that this delegate encapsulates. - /// The eleventh parameter of the method that this delegate encapsulates. - /// The twelfth parameter of the method that this delegate encapsulates. - /// The thirteenth parameter of the method that this delegate encapsulates. - /// The fourteenth parameter of the method that this delegate encapsulates. - /// The fifteenth parameter of the method that this delegate encapsulates. - /// The sixteenth parameter of the method that this delegate encapsulates. - /// The return value of the method that this delegate encapsulates. - [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] - public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16); - -} -#endif +#if NET3x +using System.Diagnostics.CodeAnalysis; + +namespace System +{ + /// + /// Encapsulates a method that has five parameters and does not return a value. + /// + /// The type of the first parameter of the method that this delegate encapsulates. + /// The type of the second parameter of the method that this delegate encapsulates. + /// The type of the third parameter of the method that this delegate encapsulates. + /// The type of the fourth parameter of the method that this delegate encapsulates. + /// The type of the fifth parameter of the method that this delegate encapsulates. + /// The first parameter of the method that this delegate encapsulates. + /// The second parameter of the method that this delegate encapsulates. + /// The third parameter of the method that this delegate encapsulates. + /// The fourth parameter of the method that this delegate encapsulates. + /// The fifth parameter of the method that this delegate encapsulates. + [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] + public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5); + + /// + /// Encapsulates a method that has five parameters and returns a value of the type specified by the parameter. + /// + /// The type of the first parameter of the method that this delegate encapsulates. + /// The type of the second parameter of the method that this delegate encapsulates. + /// The type of the third parameter of the method that this delegate encapsulates. + /// The type of the fourth parameter of the method that this delegate encapsulates. + /// The type of the fifth parameter of the method that this delegate encapsulates. + /// The type of the return value of the method that this delegate encapsulates. + /// The first parameter of the method that this delegate encapsulates. + /// The second parameter of the method that this delegate encapsulates. + /// The third parameter of the method that this delegate encapsulates. + /// The fourth parameter of the method that this delegate encapsulates. + /// The fifth parameter of the method that this delegate encapsulates. + /// The return value of the method that this delegate encapsulates. + [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] + public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5); + + /// + /// Encapsulates a method that has six parameters and does not return a value. + /// + /// The type of the first parameter of the method that this delegate encapsulates. + /// The type of the second parameter of the method that this delegate encapsulates. + /// The type of the third parameter of the method that this delegate encapsulates. + /// The type of the fourth parameter of the method that this delegate encapsulates. + /// The type of the fifth parameter of the method that this delegate encapsulates. + /// The type of the sixth parameter of the method that this delegate encapsulates. + /// The first parameter of the method that this delegate encapsulates. + /// The second parameter of the method that this delegate encapsulates. + /// The third parameter of the method that this delegate encapsulates. + /// The fourth parameter of the method that this delegate encapsulates. + /// The fifth parameter of the method that this delegate encapsulates. + /// The sixth parameter of the method that this delegate encapsulates. + [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] + public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6); + + /// + /// Encapsulates a method that has six parameters and returns a value of the type specified by the parameter. + /// + /// The type of the first parameter of the method that this delegate encapsulates. + /// The type of the second parameter of the method that this delegate encapsulates. + /// The type of the third parameter of the method that this delegate encapsulates. + /// The type of the fourth parameter of the method that this delegate encapsulates. + /// The type of the fifth parameter of the method that this delegate encapsulates. + /// The type of the sixth parameter of the method that this delegate encapsulates. + /// The type of the return value of the method that this delegate encapsulates. + /// The first parameter of the method that this delegate encapsulates. + /// The second parameter of the method that this delegate encapsulates. + /// The third parameter of the method that this delegate encapsulates. + /// The fourth parameter of the method that this delegate encapsulates. + /// The fifth parameter of the method that this delegate encapsulates. + /// The sixth parameter of the method that this delegate encapsulates. + /// The return value of the method that this delegate encapsulates. + [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] + public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6); + + /// + /// Encapsulates a method that has seven parameters and does not return a value. + /// + /// The type of the first parameter of the method that this delegate encapsulates. + /// The type of the second parameter of the method that this delegate encapsulates. + /// The type of the third parameter of the method that this delegate encapsulates. + /// The type of the fourth parameter of the method that this delegate encapsulates. + /// The type of the fifth parameter of the method that this delegate encapsulates. + /// The type of the sixth parameter of the method that this delegate encapsulates. + /// The type of the seventh parameter of the method that this delegate encapsulates. + /// The first parameter of the method that this delegate encapsulates. + /// The second parameter of the method that this delegate encapsulates. + /// The third parameter of the method that this delegate encapsulates. + /// The fourth parameter of the method that this delegate encapsulates. + /// The fifth parameter of the method that this delegate encapsulates. + /// The sixth parameter of the method that this delegate encapsulates. + /// The seventh parameter of the method that this delegate encapsulates. + [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] + public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7); + + /// + /// Encapsulates a method that has seven parameters and returns a value of the type specified by the parameter. + /// + /// The type of the first parameter of the method that this delegate encapsulates. + /// The type of the second parameter of the method that this delegate encapsulates. + /// The type of the third parameter of the method that this delegate encapsulates. + /// The type of the fourth parameter of the method that this delegate encapsulates. + /// The type of the fifth parameter of the method that this delegate encapsulates. + /// The type of the sixth parameter of the method that this delegate encapsulates. + /// The type of the seventh parameter of the method that this delegate encapsulates. + /// The type of the return value of the method that this delegate encapsulates. + /// The first parameter of the method that this delegate encapsulates. + /// The second parameter of the method that this delegate encapsulates. + /// The third parameter of the method that this delegate encapsulates. + /// The fourth parameter of the method that this delegate encapsulates. + /// The fifth parameter of the method that this delegate encapsulates. + /// The sixth parameter of the method that this delegate encapsulates. + /// The seventh parameter of the method that this delegate encapsulates. + /// The return value of the method that this delegate encapsulates. + [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] + public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7); + + /// + /// Encapsulates a method that has eight parameters and does not return a value. + /// + /// The type of the first parameter of the method that this delegate encapsulates. + /// The type of the second parameter of the method that this delegate encapsulates. + /// The type of the third parameter of the method that this delegate encapsulates. + /// The type of the fourth parameter of the method that this delegate encapsulates. + /// The type of the fifth parameter of the method that this delegate encapsulates. + /// The type of the sixth parameter of the method that this delegate encapsulates. + /// The type of the seventh parameter of the method that this delegate encapsulates. + /// The type of the eighth parameter of the method that this delegate encapsulates. + /// The first parameter of the method that this delegate encapsulates. + /// The second parameter of the method that this delegate encapsulates. + /// The third parameter of the method that this delegate encapsulates. + /// The fourth parameter of the method that this delegate encapsulates. + /// The fifth parameter of the method that this delegate encapsulates. + /// The sixth parameter of the method that this delegate encapsulates. + /// The seventh parameter of the method that this delegate encapsulates. + /// The eighth parameter of the method that this delegate encapsulates. + [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] + public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8); + + /// + /// Encapsulates a method that has eight parameters and returns a value of the type specified by the parameter. + /// + /// The type of the first parameter of the method that this delegate encapsulates. + /// The type of the second parameter of the method that this delegate encapsulates. + /// The type of the third parameter of the method that this delegate encapsulates. + /// The type of the fourth parameter of the method that this delegate encapsulates. + /// The type of the fifth parameter of the method that this delegate encapsulates. + /// The type of the sixth parameter of the method that this delegate encapsulates. + /// The type of the seventh parameter of the method that this delegate encapsulates. + /// The type of the eighth parameter of the method that this delegate encapsulates. + /// The type of the return value of the method that this delegate encapsulates. + /// The first parameter of the method that this delegate encapsulates. + /// The second parameter of the method that this delegate encapsulates. + /// The third parameter of the method that this delegate encapsulates. + /// The fourth parameter of the method that this delegate encapsulates. + /// The fifth parameter of the method that this delegate encapsulates. + /// The sixth parameter of the method that this delegate encapsulates. + /// The seventh parameter of the method that this delegate encapsulates. + /// The eighth parameter of the method that this delegate encapsulates. + /// The return value of the method that this delegate encapsulates. + [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] + public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8); + + /// + /// Encapsulates a method that has nine parameters and does not return a value. + /// + /// The type of the first parameter of the method that this delegate encapsulates. + /// The type of the second parameter of the method that this delegate encapsulates. + /// The type of the third parameter of the method that this delegate encapsulates. + /// The type of the fourth parameter of the method that this delegate encapsulates. + /// The type of the fifth parameter of the method that this delegate encapsulates. + /// The type of the sixth parameter of the method that this delegate encapsulates. + /// The type of the seventh parameter of the method that this delegate encapsulates. + /// The type of the eighth parameter of the method that this delegate encapsulates. + /// The type of the nineth parameter of the method that this delegate encapsulates. + /// The first parameter of the method that this delegate encapsulates. + /// The second parameter of the method that this delegate encapsulates. + /// The third parameter of the method that this delegate encapsulates. + /// The fourth parameter of the method that this delegate encapsulates. + /// The fifth parameter of the method that this delegate encapsulates. + /// The sixth parameter of the method that this delegate encapsulates. + /// The seventh parameter of the method that this delegate encapsulates. + /// The eighth parameter of the method that this delegate encapsulates. + /// The nineth parameter of the method that this delegate encapsulates. + [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] + public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9); + + /// + /// Encapsulates a method that has nine parameters and returns a value of the type specified by the parameter. + /// + /// The type of the first parameter of the method that this delegate encapsulates. + /// The type of the second parameter of the method that this delegate encapsulates. + /// The type of the third parameter of the method that this delegate encapsulates. + /// The type of the fourth parameter of the method that this delegate encapsulates. + /// The type of the fifth parameter of the method that this delegate encapsulates. + /// The type of the sixth parameter of the method that this delegate encapsulates. + /// The type of the seventh parameter of the method that this delegate encapsulates. + /// The type of the eighth parameter of the method that this delegate encapsulates. + /// The type of the nineth parameter of the method that this delegate encapsulates. + /// The type of the return value of the method that this delegate encapsulates. + /// The first parameter of the method that this delegate encapsulates. + /// The second parameter of the method that this delegate encapsulates. + /// The third parameter of the method that this delegate encapsulates. + /// The fourth parameter of the method that this delegate encapsulates. + /// The fifth parameter of the method that this delegate encapsulates. + /// The sixth parameter of the method that this delegate encapsulates. + /// The seventh parameter of the method that this delegate encapsulates. + /// The eighth parameter of the method that this delegate encapsulates. + /// The nineth parameter of the method that this delegate encapsulates. + /// The return value of the method that this delegate encapsulates. + [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] + public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9); + + /// + /// Encapsulates a method that has ten parameters and does not return a value. + /// + /// The type of the first parameter of the method that this delegate encapsulates. + /// The type of the second parameter of the method that this delegate encapsulates. + /// The type of the third parameter of the method that this delegate encapsulates. + /// The type of the fourth parameter of the method that this delegate encapsulates. + /// The type of the fifth parameter of the method that this delegate encapsulates. + /// The type of the sixth parameter of the method that this delegate encapsulates. + /// The type of the seventh parameter of the method that this delegate encapsulates. + /// The type of the eighth parameter of the method that this delegate encapsulates. + /// The type of the nineth parameter of the method that this delegate encapsulates. + /// The type of the tenth parameter of the method that this delegate encapsulates. + /// The first parameter of the method that this delegate encapsulates. + /// The second parameter of the method that this delegate encapsulates. + /// The third parameter of the method that this delegate encapsulates. + /// The fourth parameter of the method that this delegate encapsulates. + /// The fifth parameter of the method that this delegate encapsulates. + /// The sixth parameter of the method that this delegate encapsulates. + /// The seventh parameter of the method that this delegate encapsulates. + /// The eighth parameter of the method that this delegate encapsulates. + /// The nineth parameter of the method that this delegate encapsulates. + /// The tenth parameter of the method that this delegate encapsulates. + [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] + public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10); + + /// + /// Encapsulates a method that has ten parameters and returns a value of the type specified by the parameter. + /// + /// The type of the first parameter of the method that this delegate encapsulates. + /// The type of the second parameter of the method that this delegate encapsulates. + /// The type of the third parameter of the method that this delegate encapsulates. + /// The type of the fourth parameter of the method that this delegate encapsulates. + /// The type of the fifth parameter of the method that this delegate encapsulates. + /// The type of the sixth parameter of the method that this delegate encapsulates. + /// The type of the seventh parameter of the method that this delegate encapsulates. + /// The type of the eighth parameter of the method that this delegate encapsulates. + /// The type of the nineth parameter of the method that this delegate encapsulates. + /// The type of the tenth parameter of the method that this delegate encapsulates. + /// The type of the return value of the method that this delegate encapsulates. + /// The first parameter of the method that this delegate encapsulates. + /// The second parameter of the method that this delegate encapsulates. + /// The third parameter of the method that this delegate encapsulates. + /// The fourth parameter of the method that this delegate encapsulates. + /// The fifth parameter of the method that this delegate encapsulates. + /// The sixth parameter of the method that this delegate encapsulates. + /// The seventh parameter of the method that this delegate encapsulates. + /// The eighth parameter of the method that this delegate encapsulates. + /// The nineth parameter of the method that this delegate encapsulates. + /// The tenth parameter of the method that this delegate encapsulates. + /// The return value of the method that this delegate encapsulates. + [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] + public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10); + + /// + /// Encapsulates a method that has eleven parameters and does not return a value. + /// + /// The type of the first parameter of the method that this delegate encapsulates. + /// The type of the second parameter of the method that this delegate encapsulates. + /// The type of the third parameter of the method that this delegate encapsulates. + /// The type of the fourth parameter of the method that this delegate encapsulates. + /// The type of the fifth parameter of the method that this delegate encapsulates. + /// The type of the sixth parameter of the method that this delegate encapsulates. + /// The type of the seventh parameter of the method that this delegate encapsulates. + /// The type of the eighth parameter of the method that this delegate encapsulates. + /// The type of the nineth parameter of the method that this delegate encapsulates. + /// The type of the tenth parameter of the method that this delegate encapsulates. + /// The type of the eleventh parameter of the method that this delegate encapsulates. + /// The first parameter of the method that this delegate encapsulates. + /// The second parameter of the method that this delegate encapsulates. + /// The third parameter of the method that this delegate encapsulates. + /// The fourth parameter of the method that this delegate encapsulates. + /// The fifth parameter of the method that this delegate encapsulates. + /// The sixth parameter of the method that this delegate encapsulates. + /// The seventh parameter of the method that this delegate encapsulates. + /// The eighth parameter of the method that this delegate encapsulates. + /// The nineth parameter of the method that this delegate encapsulates. + /// The tenth parameter of the method that this delegate encapsulates. + /// The eleventh parameter of the method that this delegate encapsulates. + [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] + public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11); + + /// + /// Encapsulates a method that has eleven parameters and returns a value of the type specified by the parameter. + /// + /// The type of the first parameter of the method that this delegate encapsulates. + /// The type of the second parameter of the method that this delegate encapsulates. + /// The type of the third parameter of the method that this delegate encapsulates. + /// The type of the fourth parameter of the method that this delegate encapsulates. + /// The type of the fifth parameter of the method that this delegate encapsulates. + /// The type of the sixth parameter of the method that this delegate encapsulates. + /// The type of the seventh parameter of the method that this delegate encapsulates. + /// The type of the eighth parameter of the method that this delegate encapsulates. + /// The type of the nineth parameter of the method that this delegate encapsulates. + /// The type of the tenth parameter of the method that this delegate encapsulates. + /// The type of the eleventh parameter of the method that this delegate encapsulates. + /// The type of the return value of the method that this delegate encapsulates. + /// The first parameter of the method that this delegate encapsulates. + /// The second parameter of the method that this delegate encapsulates. + /// The third parameter of the method that this delegate encapsulates. + /// The fourth parameter of the method that this delegate encapsulates. + /// The fifth parameter of the method that this delegate encapsulates. + /// The sixth parameter of the method that this delegate encapsulates. + /// The seventh parameter of the method that this delegate encapsulates. + /// The eighth parameter of the method that this delegate encapsulates. + /// The nineth parameter of the method that this delegate encapsulates. + /// The tenth parameter of the method that this delegate encapsulates. + /// The eleventh parameter of the method that this delegate encapsulates. + /// The return value of the method that this delegate encapsulates. + [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] + public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11); + + /// + /// Encapsulates a method that has twelve parameters and does not return a value. + /// + /// The type of the first parameter of the method that this delegate encapsulates. + /// The type of the second parameter of the method that this delegate encapsulates. + /// The type of the third parameter of the method that this delegate encapsulates. + /// The type of the fourth parameter of the method that this delegate encapsulates. + /// The type of the fifth parameter of the method that this delegate encapsulates. + /// The type of the sixth parameter of the method that this delegate encapsulates. + /// The type of the seventh parameter of the method that this delegate encapsulates. + /// The type of the eighth parameter of the method that this delegate encapsulates. + /// The type of the nineth parameter of the method that this delegate encapsulates. + /// The type of the tenth parameter of the method that this delegate encapsulates. + /// The type of the eleventh parameter of the method that this delegate encapsulates. + /// The type of the twelfth parameter of the method that this delegate encapsulates. + /// The first parameter of the method that this delegate encapsulates. + /// The second parameter of the method that this delegate encapsulates. + /// The third parameter of the method that this delegate encapsulates. + /// The fourth parameter of the method that this delegate encapsulates. + /// The fifth parameter of the method that this delegate encapsulates. + /// The sixth parameter of the method that this delegate encapsulates. + /// The seventh parameter of the method that this delegate encapsulates. + /// The eighth parameter of the method that this delegate encapsulates. + /// The nineth parameter of the method that this delegate encapsulates. + /// The tenth parameter of the method that this delegate encapsulates. + /// The eleventh parameter of the method that this delegate encapsulates. + /// The twelfth parameter of the method that this delegate encapsulates. + [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] + public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12); + + /// + /// Encapsulates a method that has twelve parameters and returns a value of the type specified by the parameter. + /// + /// The type of the first parameter of the method that this delegate encapsulates. + /// The type of the second parameter of the method that this delegate encapsulates. + /// The type of the third parameter of the method that this delegate encapsulates. + /// The type of the fourth parameter of the method that this delegate encapsulates. + /// The type of the fifth parameter of the method that this delegate encapsulates. + /// The type of the sixth parameter of the method that this delegate encapsulates. + /// The type of the seventh parameter of the method that this delegate encapsulates. + /// The type of the eighth parameter of the method that this delegate encapsulates. + /// The type of the nineth parameter of the method that this delegate encapsulates. + /// The type of the tenth parameter of the method that this delegate encapsulates. + /// The type of the eleventh parameter of the method that this delegate encapsulates. + /// The type of the twelfth parameter of the method that this delegate encapsulates. + /// The type of the return value of the method that this delegate encapsulates. + /// The first parameter of the method that this delegate encapsulates. + /// The second parameter of the method that this delegate encapsulates. + /// The third parameter of the method that this delegate encapsulates. + /// The fourth parameter of the method that this delegate encapsulates. + /// The fifth parameter of the method that this delegate encapsulates. + /// The sixth parameter of the method that this delegate encapsulates. + /// The seventh parameter of the method that this delegate encapsulates. + /// The eighth parameter of the method that this delegate encapsulates. + /// The nineth parameter of the method that this delegate encapsulates. + /// The tenth parameter of the method that this delegate encapsulates. + /// The eleventh parameter of the method that this delegate encapsulates. + /// The twelfth parameter of the method that this delegate encapsulates. + /// The return value of the method that this delegate encapsulates. + [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] + public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12); + + /// + /// Encapsulates a method that has thirteen parameters and does not return a value. + /// + /// The type of the first parameter of the method that this delegate encapsulates. + /// The type of the second parameter of the method that this delegate encapsulates. + /// The type of the third parameter of the method that this delegate encapsulates. + /// The type of the fourth parameter of the method that this delegate encapsulates. + /// The type of the fifth parameter of the method that this delegate encapsulates. + /// The type of the sixth parameter of the method that this delegate encapsulates. + /// The type of the seventh parameter of the method that this delegate encapsulates. + /// The type of the eighth parameter of the method that this delegate encapsulates. + /// The type of the nineth parameter of the method that this delegate encapsulates. + /// The type of the tenth parameter of the method that this delegate encapsulates. + /// The type of the eleventh parameter of the method that this delegate encapsulates. + /// The type of the twelfth parameter of the method that this delegate encapsulates. + /// The type of the thirteenth parameter of the method that this delegate encapsulates. + /// The first parameter of the method that this delegate encapsulates. + /// The second parameter of the method that this delegate encapsulates. + /// The third parameter of the method that this delegate encapsulates. + /// The fourth parameter of the method that this delegate encapsulates. + /// The fifth parameter of the method that this delegate encapsulates. + /// The sixth parameter of the method that this delegate encapsulates. + /// The seventh parameter of the method that this delegate encapsulates. + /// The eighth parameter of the method that this delegate encapsulates. + /// The nineth parameter of the method that this delegate encapsulates. + /// The tenth parameter of the method that this delegate encapsulates. + /// The eleventh parameter of the method that this delegate encapsulates. + /// The twelfth parameter of the method that this delegate encapsulates. + /// The thirteenth parameter of the method that this delegate encapsulates. + [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] + public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13); + + /// + /// Encapsulates a method that has thirteen parameters and returns a value of the type specified by the parameter. + /// + /// The type of the first parameter of the method that this delegate encapsulates. + /// The type of the second parameter of the method that this delegate encapsulates. + /// The type of the third parameter of the method that this delegate encapsulates. + /// The type of the fourth parameter of the method that this delegate encapsulates. + /// The type of the fifth parameter of the method that this delegate encapsulates. + /// The type of the sixth parameter of the method that this delegate encapsulates. + /// The type of the seventh parameter of the method that this delegate encapsulates. + /// The type of the eighth parameter of the method that this delegate encapsulates. + /// The type of the nineth parameter of the method that this delegate encapsulates. + /// The type of the tenth parameter of the method that this delegate encapsulates. + /// The type of the eleventh parameter of the method that this delegate encapsulates. + /// The type of the twelfth parameter of the method that this delegate encapsulates. + /// The type of the thirteenth parameter of the method that this delegate encapsulates. + /// The type of the return value of the method that this delegate encapsulates. + /// The first parameter of the method that this delegate encapsulates. + /// The second parameter of the method that this delegate encapsulates. + /// The third parameter of the method that this delegate encapsulates. + /// The fourth parameter of the method that this delegate encapsulates. + /// The fifth parameter of the method that this delegate encapsulates. + /// The sixth parameter of the method that this delegate encapsulates. + /// The seventh parameter of the method that this delegate encapsulates. + /// The eighth parameter of the method that this delegate encapsulates. + /// The nineth parameter of the method that this delegate encapsulates. + /// The tenth parameter of the method that this delegate encapsulates. + /// The eleventh parameter of the method that this delegate encapsulates. + /// The twelfth parameter of the method that this delegate encapsulates. + /// The thirteenth parameter of the method that this delegate encapsulates. + /// The return value of the method that this delegate encapsulates. + [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] + public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13); + + /// + /// Encapsulates a method that has fourteen parameters and does not return a value. + /// + /// The type of the first parameter of the method that this delegate encapsulates. + /// The type of the second parameter of the method that this delegate encapsulates. + /// The type of the third parameter of the method that this delegate encapsulates. + /// The type of the fourth parameter of the method that this delegate encapsulates. + /// The type of the fifth parameter of the method that this delegate encapsulates. + /// The type of the sixth parameter of the method that this delegate encapsulates. + /// The type of the seventh parameter of the method that this delegate encapsulates. + /// The type of the eighth parameter of the method that this delegate encapsulates. + /// The type of the nineth parameter of the method that this delegate encapsulates. + /// The type of the tenth parameter of the method that this delegate encapsulates. + /// The type of the eleventh parameter of the method that this delegate encapsulates. + /// The type of the twelfth parameter of the method that this delegate encapsulates. + /// The type of the thirteenth parameter of the method that this delegate encapsulates. + /// The type of the fourteenth parameter of the method that this delegate encapsulates. + /// The first parameter of the method that this delegate encapsulates. + /// The second parameter of the method that this delegate encapsulates. + /// The third parameter of the method that this delegate encapsulates. + /// The fourth parameter of the method that this delegate encapsulates. + /// The fifth parameter of the method that this delegate encapsulates. + /// The sixth parameter of the method that this delegate encapsulates. + /// The seventh parameter of the method that this delegate encapsulates. + /// The eighth parameter of the method that this delegate encapsulates. + /// The nineth parameter of the method that this delegate encapsulates. + /// The tenth parameter of the method that this delegate encapsulates. + /// The eleventh parameter of the method that this delegate encapsulates. + /// The twelfth parameter of the method that this delegate encapsulates. + /// The thirteenth parameter of the method that this delegate encapsulates. + /// The fourteenth parameter of the method that this delegate encapsulates. + [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] + public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14); + + /// + /// Encapsulates a method that has fourteen parameters and returns a value of the type specified by the parameter. + /// + /// The type of the first parameter of the method that this delegate encapsulates. + /// The type of the second parameter of the method that this delegate encapsulates. + /// The type of the third parameter of the method that this delegate encapsulates. + /// The type of the fourth parameter of the method that this delegate encapsulates. + /// The type of the fifth parameter of the method that this delegate encapsulates. + /// The type of the sixth parameter of the method that this delegate encapsulates. + /// The type of the seventh parameter of the method that this delegate encapsulates. + /// The type of the eighth parameter of the method that this delegate encapsulates. + /// The type of the nineth parameter of the method that this delegate encapsulates. + /// The type of the tenth parameter of the method that this delegate encapsulates. + /// The type of the eleventh parameter of the method that this delegate encapsulates. + /// The type of the twelfth parameter of the method that this delegate encapsulates. + /// The type of the thirteenth parameter of the method that this delegate encapsulates. + /// The type of the fourteenth parameter of the method that this delegate encapsulates. + /// The type of the return value of the method that this delegate encapsulates. + /// The first parameter of the method that this delegate encapsulates. + /// The second parameter of the method that this delegate encapsulates. + /// The third parameter of the method that this delegate encapsulates. + /// The fourth parameter of the method that this delegate encapsulates. + /// The fifth parameter of the method that this delegate encapsulates. + /// The sixth parameter of the method that this delegate encapsulates. + /// The seventh parameter of the method that this delegate encapsulates. + /// The eighth parameter of the method that this delegate encapsulates. + /// The nineth parameter of the method that this delegate encapsulates. + /// The tenth parameter of the method that this delegate encapsulates. + /// The eleventh parameter of the method that this delegate encapsulates. + /// The twelfth parameter of the method that this delegate encapsulates. + /// The thirteenth parameter of the method that this delegate encapsulates. + /// The fourteenth parameter of the method that this delegate encapsulates. + /// The return value of the method that this delegate encapsulates. + [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] + public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14); + + /// + /// Encapsulates a method that has fifteen parameters and does not return a value. + /// + /// The type of the first parameter of the method that this delegate encapsulates. + /// The type of the second parameter of the method that this delegate encapsulates. + /// The type of the third parameter of the method that this delegate encapsulates. + /// The type of the fourth parameter of the method that this delegate encapsulates. + /// The type of the fifth parameter of the method that this delegate encapsulates. + /// The type of the sixth parameter of the method that this delegate encapsulates. + /// The type of the seventh parameter of the method that this delegate encapsulates. + /// The type of the eighth parameter of the method that this delegate encapsulates. + /// The type of the nineth parameter of the method that this delegate encapsulates. + /// The type of the tenth parameter of the method that this delegate encapsulates. + /// The type of the eleventh parameter of the method that this delegate encapsulates. + /// The type of the twelfth parameter of the method that this delegate encapsulates. + /// The type of the thirteenth parameter of the method that this delegate encapsulates. + /// The type of the fourteenth parameter of the method that this delegate encapsulates. + /// The type of the fifteenth parameter of the method that this delegate encapsulates. + /// The first parameter of the method that this delegate encapsulates. + /// The second parameter of the method that this delegate encapsulates. + /// The third parameter of the method that this delegate encapsulates. + /// The fourth parameter of the method that this delegate encapsulates. + /// The fifth parameter of the method that this delegate encapsulates. + /// The sixth parameter of the method that this delegate encapsulates. + /// The seventh parameter of the method that this delegate encapsulates. + /// The eighth parameter of the method that this delegate encapsulates. + /// The nineth parameter of the method that this delegate encapsulates. + /// The tenth parameter of the method that this delegate encapsulates. + /// The eleventh parameter of the method that this delegate encapsulates. + /// The twelfth parameter of the method that this delegate encapsulates. + /// The thirteenth parameter of the method that this delegate encapsulates. + /// The fourteenth parameter of the method that this delegate encapsulates. + /// The fifteenth parameter of the method that this delegate encapsulates. + [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] + public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15); + + /// + /// Encapsulates a method that has fifteen parameters and returns a value of the type specified by the parameter. + /// + /// The type of the first parameter of the method that this delegate encapsulates. + /// The type of the second parameter of the method that this delegate encapsulates. + /// The type of the third parameter of the method that this delegate encapsulates. + /// The type of the fourth parameter of the method that this delegate encapsulates. + /// The type of the fifth parameter of the method that this delegate encapsulates. + /// The type of the sixth parameter of the method that this delegate encapsulates. + /// The type of the seventh parameter of the method that this delegate encapsulates. + /// The type of the eighth parameter of the method that this delegate encapsulates. + /// The type of the nineth parameter of the method that this delegate encapsulates. + /// The type of the tenth parameter of the method that this delegate encapsulates. + /// The type of the eleventh parameter of the method that this delegate encapsulates. + /// The type of the twelfth parameter of the method that this delegate encapsulates. + /// The type of the thirteenth parameter of the method that this delegate encapsulates. + /// The type of the fourteenth parameter of the method that this delegate encapsulates. + /// The type of the fifteenth parameter of the method that this delegate encapsulates. + /// The type of the return value of the method that this delegate encapsulates. + /// The first parameter of the method that this delegate encapsulates. + /// The second parameter of the method that this delegate encapsulates. + /// The third parameter of the method that this delegate encapsulates. + /// The fourth parameter of the method that this delegate encapsulates. + /// The fifth parameter of the method that this delegate encapsulates. + /// The sixth parameter of the method that this delegate encapsulates. + /// The seventh parameter of the method that this delegate encapsulates. + /// The eighth parameter of the method that this delegate encapsulates. + /// The nineth parameter of the method that this delegate encapsulates. + /// The tenth parameter of the method that this delegate encapsulates. + /// The eleventh parameter of the method that this delegate encapsulates. + /// The twelfth parameter of the method that this delegate encapsulates. + /// The thirteenth parameter of the method that this delegate encapsulates. + /// The fourteenth parameter of the method that this delegate encapsulates. + /// The fifteenth parameter of the method that this delegate encapsulates. + /// The return value of the method that this delegate encapsulates. + [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] + public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15); + + /// + /// Encapsulates a method that has sixteen parameters and does not return a value. + /// + /// The type of the first parameter of the method that this delegate encapsulates. + /// The type of the second parameter of the method that this delegate encapsulates. + /// The type of the third parameter of the method that this delegate encapsulates. + /// The type of the fourth parameter of the method that this delegate encapsulates. + /// The type of the fifth parameter of the method that this delegate encapsulates. + /// The type of the sixth parameter of the method that this delegate encapsulates. + /// The type of the seventh parameter of the method that this delegate encapsulates. + /// The type of the eighth parameter of the method that this delegate encapsulates. + /// The type of the nineth parameter of the method that this delegate encapsulates. + /// The type of the tenth parameter of the method that this delegate encapsulates. + /// The type of the eleventh parameter of the method that this delegate encapsulates. + /// The type of the twelfth parameter of the method that this delegate encapsulates. + /// The type of the thirteenth parameter of the method that this delegate encapsulates. + /// The type of the fourteenth parameter of the method that this delegate encapsulates. + /// The type of the fifteenth parameter of the method that this delegate encapsulates. + /// The type of the sixteenth parameter of the method that this delegate encapsulates. + /// The first parameter of the method that this delegate encapsulates. + /// The second parameter of the method that this delegate encapsulates. + /// The third parameter of the method that this delegate encapsulates. + /// The fourth parameter of the method that this delegate encapsulates. + /// The fifth parameter of the method that this delegate encapsulates. + /// The sixth parameter of the method that this delegate encapsulates. + /// The seventh parameter of the method that this delegate encapsulates. + /// The eighth parameter of the method that this delegate encapsulates. + /// The nineth parameter of the method that this delegate encapsulates. + /// The tenth parameter of the method that this delegate encapsulates. + /// The eleventh parameter of the method that this delegate encapsulates. + /// The twelfth parameter of the method that this delegate encapsulates. + /// The thirteenth parameter of the method that this delegate encapsulates. + /// The fourteenth parameter of the method that this delegate encapsulates. + /// The fifteenth parameter of the method that this delegate encapsulates. + /// The sixteenth parameter of the method that this delegate encapsulates. + [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] + public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16); + + /// + /// Encapsulates a method that has sixteen parameters and returns a value of the type specified by the parameter. + /// + /// The type of the first parameter of the method that this delegate encapsulates. + /// The type of the second parameter of the method that this delegate encapsulates. + /// The type of the third parameter of the method that this delegate encapsulates. + /// The type of the fourth parameter of the method that this delegate encapsulates. + /// The type of the fifth parameter of the method that this delegate encapsulates. + /// The type of the sixth parameter of the method that this delegate encapsulates. + /// The type of the seventh parameter of the method that this delegate encapsulates. + /// The type of the eighth parameter of the method that this delegate encapsulates. + /// The type of the nineth parameter of the method that this delegate encapsulates. + /// The type of the tenth parameter of the method that this delegate encapsulates. + /// The type of the eleventh parameter of the method that this delegate encapsulates. + /// The type of the twelfth parameter of the method that this delegate encapsulates. + /// The type of the thirteenth parameter of the method that this delegate encapsulates. + /// The type of the fourteenth parameter of the method that this delegate encapsulates. + /// The type of the fifteenth parameter of the method that this delegate encapsulates. + /// The type of the sixteenth parameter of the method that this delegate encapsulates. + /// The type of the return value of the method that this delegate encapsulates. + /// The first parameter of the method that this delegate encapsulates. + /// The second parameter of the method that this delegate encapsulates. + /// The third parameter of the method that this delegate encapsulates. + /// The fourth parameter of the method that this delegate encapsulates. + /// The fifth parameter of the method that this delegate encapsulates. + /// The sixth parameter of the method that this delegate encapsulates. + /// The seventh parameter of the method that this delegate encapsulates. + /// The eighth parameter of the method that this delegate encapsulates. + /// The nineth parameter of the method that this delegate encapsulates. + /// The tenth parameter of the method that this delegate encapsulates. + /// The eleventh parameter of the method that this delegate encapsulates. + /// The twelfth parameter of the method that this delegate encapsulates. + /// The thirteenth parameter of the method that this delegate encapsulates. + /// The fourteenth parameter of the method that this delegate encapsulates. + /// The fifteenth parameter of the method that this delegate encapsulates. + /// The sixteenth parameter of the method that this delegate encapsulates. + /// The return value of the method that this delegate encapsulates. + [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] + public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16); + +} +#endif diff --git a/Source/Microsoft/Delegates.tt b/Source/Microsoft/Delegates.tt index 09cda5ce5..08a810a23 100644 --- a/Source/Microsoft/Delegates.tt +++ b/Source/Microsoft/Delegates.tt @@ -1,66 +1,66 @@ -<#@ template debug="false" hostspecific="false" language="C#" #> -<#@ output extension=".cs" #> -<#@ Assembly Name="System.Core" #> -<#@ Import Namespace="System.Linq" #> -#if NET3x -using System.Diagnostics.CodeAnalysis; - -namespace System -{ -<# -for (var typeCount = GenericTypeMin; typeCount <= GenericTypeMax; typeCount++) -{ - var typeList = GetGenericList(typeCount, GenericTypeFormat); - var argumentList = GetGenericList(typeCount, GenericArgumentFormat); -#> - /// - /// Encapsulates a method that has <#= ConvertToWord(typeCount) #> parameters and does not return a value. - /// -<# - for (var typeIndex = 1; typeIndex <= typeCount; typeIndex++) - { -#> - /// The type of the <#= ConvertToOrdinal(typeIndex) #> parameter of the method that this delegate encapsulates. -<# - } - - for (var typeIndex = 1; typeIndex <= typeCount; typeIndex++) - { -#> - /// The <#= ConvertToOrdinal(typeIndex) #> parameter of the method that this delegate encapsulates. -<# - } -#> - [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] - public delegate void Action<<#= typeList #>>(<#= argumentList #>); - - /// - /// Encapsulates a method that has <#= ConvertToWord(typeCount) #> parameters and returns a value of the type specified by the parameter. - /// -<# - for (var typeIndex = 1; typeIndex <= typeCount; typeIndex++) - { -#> - /// The type of the <#= ConvertToOrdinal(typeIndex) #> parameter of the method that this delegate encapsulates. -<# - } -#> - /// The type of the return value of the method that this delegate encapsulates. -<# - for (var typeIndex = 1; typeIndex <= typeCount; typeIndex++) - { -#> - /// The <#= ConvertToOrdinal(typeIndex) #> parameter of the method that this delegate encapsulates. -<# - } -#> - /// The return value of the method that this delegate encapsulates. - [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] - public delegate TResult Func<<#= typeList #>, TResult>(<#= argumentList #>); - -<# -} -#> -} -#endif +<#@ template debug="false" hostspecific="false" language="C#" #> +<#@ output extension=".cs" #> +<#@ Assembly Name="System.Core" #> +<#@ Import Namespace="System.Linq" #> +#if NET3x +using System.Diagnostics.CodeAnalysis; + +namespace System +{ +<# +for (var typeCount = GenericTypeMin; typeCount <= GenericTypeMax; typeCount++) +{ + var typeList = GetGenericList(typeCount, GenericTypeFormat); + var argumentList = GetGenericList(typeCount, GenericArgumentFormat); +#> + /// + /// Encapsulates a method that has <#= ConvertToWord(typeCount) #> parameters and does not return a value. + /// +<# + for (var typeIndex = 1; typeIndex <= typeCount; typeIndex++) + { +#> + /// The type of the <#= ConvertToOrdinal(typeIndex) #> parameter of the method that this delegate encapsulates. +<# + } + + for (var typeIndex = 1; typeIndex <= typeCount; typeIndex++) + { +#> + /// The <#= ConvertToOrdinal(typeIndex) #> parameter of the method that this delegate encapsulates. +<# + } +#> + [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] + public delegate void Action<<#= typeList #>>(<#= argumentList #>); + + /// + /// Encapsulates a method that has <#= ConvertToWord(typeCount) #> parameters and returns a value of the type specified by the parameter. + /// +<# + for (var typeIndex = 1; typeIndex <= typeCount; typeIndex++) + { +#> + /// The type of the <#= ConvertToOrdinal(typeIndex) #> parameter of the method that this delegate encapsulates. +<# + } +#> + /// The type of the return value of the method that this delegate encapsulates. +<# + for (var typeIndex = 1; typeIndex <= typeCount; typeIndex++) + { +#> + /// The <#= ConvertToOrdinal(typeIndex) #> parameter of the method that this delegate encapsulates. +<# + } +#> + /// The return value of the method that this delegate encapsulates. + [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "The number of type parameters is necessary to provide the desired behavior.")] + public delegate TResult Func<<#= typeList #>, TResult>(<#= argumentList #>); + +<# +} +#> +} +#endif <#@ Include File="..\Includes\GenericTypeParameters.tt" #> \ No newline at end of file diff --git a/Source/Microsoft/ExpressionVisitor.cs b/Source/Microsoft/ExpressionVisitor.cs index b4e871e36..56d100fbd 100644 --- a/Source/Microsoft/ExpressionVisitor.cs +++ b/Source/Microsoft/ExpressionVisitor.cs @@ -1,503 +1,503 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// This source code is made available under the terms of the Microsoft Public License (MS-PL) -#if NET3x -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Diagnostics; -using System.Globalization; -using System.Reflection; - -namespace System.Linq.Expressions -{ - [DebuggerStepThrough] - internal abstract class ExpressionVisitor - { - protected ExpressionVisitor() - { - } - - public static ReadOnlyCollection Visit(ReadOnlyCollection nodes, Func elementVisitor) - { - List list = null; - for (var index = 0; index < nodes.Count; index++) - { - var expression = elementVisitor(nodes[index]); - if (list != null) - { - list.Add(expression); - } - else if (!object.ReferenceEquals(expression, nodes[index])) - { - list = new List(nodes.Count); - for (var j = 0; j < index; j++) - { - list.Add(nodes[j]); - } - - list.Add(expression); - } - } - - return list != null ? list.AsReadOnly() : nodes; - } - - public virtual Expression Visit(Expression node) - { - if (node == null) - { - return node; - } - - switch (node.NodeType) - { - case ExpressionType.Negate: - case ExpressionType.NegateChecked: - case ExpressionType.Not: - case ExpressionType.Convert: - case ExpressionType.ConvertChecked: - case ExpressionType.ArrayLength: - case ExpressionType.Quote: - case ExpressionType.TypeAs: - case ExpressionType.UnaryPlus: - return this.VisitUnary((UnaryExpression)node); - case ExpressionType.Add: - case ExpressionType.AddChecked: - case ExpressionType.Subtract: - case ExpressionType.SubtractChecked: - case ExpressionType.Multiply: - case ExpressionType.MultiplyChecked: - case ExpressionType.Divide: - case ExpressionType.Modulo: - case ExpressionType.And: - case ExpressionType.AndAlso: - case ExpressionType.Or: - case ExpressionType.OrElse: - case ExpressionType.LessThan: - case ExpressionType.LessThanOrEqual: - case ExpressionType.GreaterThan: - case ExpressionType.GreaterThanOrEqual: - case ExpressionType.Equal: - case ExpressionType.NotEqual: - case ExpressionType.Coalesce: - case ExpressionType.ArrayIndex: - case ExpressionType.RightShift: - case ExpressionType.LeftShift: - case ExpressionType.ExclusiveOr: - case ExpressionType.Power: - return this.VisitBinary((BinaryExpression)node); - case ExpressionType.TypeIs: - return this.VisitTypeBinary((TypeBinaryExpression)node); - case ExpressionType.Conditional: - return this.VisitConditional((ConditionalExpression)node); - case ExpressionType.Constant: - return this.VisitConstant((ConstantExpression)node); - case ExpressionType.Parameter: - return this.VisitParameter((ParameterExpression)node); - case ExpressionType.MemberAccess: - return this.VisitMember((MemberExpression)node); - case ExpressionType.Call: - return this.VisitMethodCall((MethodCallExpression)node); - case ExpressionType.Lambda: - return this.VisitLambda((LambdaExpression)node); - case ExpressionType.New: - return this.VisitNew((NewExpression)node); - case ExpressionType.NewArrayInit: - case ExpressionType.NewArrayBounds: - return this.VisitNewArray((NewArrayExpression)node); - case ExpressionType.Invoke: - return this.VisitInvocation((InvocationExpression)node); - case ExpressionType.MemberInit: - return this.VisitMemberInit((MemberInitExpression)node); - case ExpressionType.ListInit: - return this.VisitListInit((ListInitExpression)node); - } - - return VisitUnknown(node); - } - - public ReadOnlyCollection Visit(ReadOnlyCollection nodes) - { - if (nodes != null) - { - List list = null; - for (var index = 0; index < nodes.Count; index++) - { - var node = this.Visit(nodes[index]); - if (list != null) - { - list.Add(node); - } - else if (node != nodes[index]) - { - list = new List(nodes.Count); - for (int j = 0; j < index; j++) - { - list.Add(nodes[j]); - } - - list.Add(node); - } - } - - if (list != null) - { - return list.AsReadOnly(); - } - } - - return nodes; - } - - protected virtual Expression VisitBinary(BinaryExpression node) - { - Expression left = this.Visit(node.Left); - Expression right = this.Visit(node.Right); - Expression conversion = this.Visit(node.Conversion); - return UpdateBinary(node, left, right, conversion, node.IsLiftedToNull, node.Method); - } - - protected virtual Expression VisitConditional(ConditionalExpression node) - { - var test = this.Visit(node.Test); - var ifTrue = this.Visit(node.IfTrue); - var ifFalse = this.Visit(node.IfFalse); - return UpdateConditional(node, test, ifTrue, ifFalse); - } - - protected virtual Expression VisitConstant(ConstantExpression node) - { - return node; - } - - protected virtual ElementInit VisitElementInit(ElementInit node) - { - var arguments = this.Visit(node.Arguments); - if (arguments != node.Arguments) - { - return Expression.ElementInit(node.AddMethod, arguments); - } - - return node; - } - - protected virtual Expression VisitInvocation(InvocationExpression node) - { - var args = this.Visit(node.Arguments); - var expression = this.Visit(node.Expression); - return UpdateInvocation(node, expression, args); - } - - protected virtual Expression VisitLambda(LambdaExpression node) - { - var body = this.Visit(node.Body); - return UpdateLambda(node, node.Type, body, node.Parameters); - } - - protected virtual Expression VisitListInit(ListInitExpression node) - { - var newExpression = (NewExpression)this.VisitNew(node.NewExpression); - var initializers = Visit(node.Initializers, n => this.VisitElementInit(n)); - return UpdateListInit(node, newExpression, initializers); - } - - protected virtual Expression VisitMember(MemberExpression node) - { - var expression = this.Visit(node.Expression); - return UpdateMember(node, expression, node.Member); - } - - protected virtual MemberAssignment VisitMemberAssignment(MemberAssignment node) - { - var expression = this.Visit(node.Expression); - return UpdateMemberAssignment(node, node.Member, expression); - } - - protected virtual MemberBinding VisitMemberBinding(MemberBinding node) - { - switch (node.BindingType) - { - case MemberBindingType.Assignment: - return this.VisitMemberAssignment((MemberAssignment)node); - case MemberBindingType.MemberBinding: - return this.VisitMemberMemberBinding((MemberMemberBinding)node); - case MemberBindingType.ListBinding: - return this.VisitMemberListBinding((MemberListBinding)node); - } - - throw new InvalidOperationException(string.Format( - CultureInfo.CurrentCulture, - "Unhandled binding type '{0}'", - node.BindingType)); - } - - protected virtual Expression VisitMemberInit(MemberInitExpression node) - { - var newExpression = (NewExpression)this.VisitNew(node.NewExpression); - var bindings = Visit(node.Bindings, n => this.VisitMemberBinding(n)); - return UpdateMemberInit(node, newExpression, bindings); - } - - protected virtual MemberListBinding VisitMemberListBinding(MemberListBinding node) - { - var initializers = Visit(node.Initializers, n => this.VisitElementInit(n)); - return UpdateMemberListBinding(node, node.Member, initializers); - } - - protected virtual MemberMemberBinding VisitMemberMemberBinding(MemberMemberBinding node) - { - var bindings = Visit(node.Bindings, n => this.VisitMemberBinding(n)); - return UpdateMemberMemberBinding(node, node.Member, bindings); - } - - protected virtual Expression VisitMethodCall(MethodCallExpression node) - { - var obj = this.Visit(node.Object); - var args = this.Visit(node.Arguments); - return UpdateMethodCall(node, obj, node.Method, args); - } - - protected virtual Expression VisitNew(NewExpression node) - { - var args = this.Visit(node.Arguments); - return UpdateNew(node, node.Constructor, args, node.Members); - } - - protected virtual Expression VisitNewArray(NewArrayExpression node) - { - var expressions = this.Visit(node.Expressions); - return UpdateNewArray(node, node.Type, expressions); - } - - protected virtual Expression VisitParameter(ParameterExpression node) - { - return node; - } - - protected virtual Expression VisitTypeBinary(TypeBinaryExpression node) - { - var expression = this.Visit(node.Expression); - return UpdateTypeBinary(node, expression, node.TypeOperand); - } - - protected virtual Expression VisitUnary(UnaryExpression node) - { - var operand = this.Visit(node.Operand); - return UpdateUnary(node, operand, node.Type, node.Method); - } - - private static BinaryExpression UpdateBinary( - BinaryExpression node, - Expression left, - Expression right, - Expression conversion, - bool isLiftedToNull, - MethodInfo method) - { - if (left != node.Left || right != node.Right || conversion != node.Conversion || - method != node.Method || isLiftedToNull != node.IsLiftedToNull) - { - if (node.NodeType == ExpressionType.Coalesce && node.Conversion != null) - { - return Expression.Coalesce(left, right, conversion as LambdaExpression); - } - - return Expression.MakeBinary(node.NodeType, left, right, isLiftedToNull, method); - } - - return node; - } - - private static ConditionalExpression UpdateConditional( - ConditionalExpression node, - Expression test, - Expression ifTrue, - Expression ifFalse) - { - if (test != node.Test || ifTrue != node.IfTrue || ifFalse != node.IfFalse) - { - return Expression.Condition(test, ifTrue, ifFalse); - } - - return node; - } - - private static InvocationExpression UpdateInvocation( - InvocationExpression node, - Expression expression, - IEnumerable args) - { - if (args != node.Arguments || expression != node.Expression) - { - return Expression.Invoke(expression, args); - } - - return node; - } - - private static LambdaExpression UpdateLambda( - LambdaExpression node, - Type delegateType, - Expression body, - IEnumerable parameters) - { - if (body != node.Body || parameters != node.Parameters || delegateType != node.Type) - { - return Expression.Lambda(delegateType, body, parameters); - } - - return node; - } - - private static ListInitExpression UpdateListInit( - ListInitExpression node, - NewExpression newExpression, - IEnumerable initializers) - { - if (newExpression != node.NewExpression || initializers != node.Initializers) - { - return Expression.ListInit(newExpression, initializers); - } - - return node; - } - - private static MemberExpression UpdateMember(MemberExpression node, Expression expression, MemberInfo member) - { - if (expression != node.Expression || member != node.Member) - { - return Expression.MakeMemberAccess(expression, member); - } - - return node; - } - - private static MemberAssignment UpdateMemberAssignment(MemberAssignment node, MemberInfo member, Expression expression) - { - if (expression != node.Expression || member != node.Member) - { - return Expression.Bind(member, expression); - } - - return node; - } - - private static MemberInitExpression UpdateMemberInit( - MemberInitExpression node, - NewExpression newExpression, - IEnumerable bindings) - { - if (newExpression != node.NewExpression || bindings != node.Bindings) - { - return Expression.MemberInit(newExpression, bindings); - } - - return node; - } - - private static MemberListBinding UpdateMemberListBinding( - MemberListBinding node, - MemberInfo member, - IEnumerable initializers) - { - if (initializers != node.Initializers || member != node.Member) - { - return Expression.ListBind(member, initializers); - } - - return node; - } - - private static MemberMemberBinding UpdateMemberMemberBinding( - MemberMemberBinding node, - MemberInfo member, - IEnumerable bindings) - { - if (bindings != node.Bindings || member != node.Member) - { - return Expression.MemberBind(member, bindings); - } - - return node; - } - - private static MethodCallExpression UpdateMethodCall( - MethodCallExpression node, - Expression obj, - MethodInfo method, - IEnumerable args) - { - if (obj != node.Object || method != node.Method || args != node.Arguments) - { - return Expression.Call(obj, method, args); - } - - return node; - } - - private static NewExpression UpdateNew( - NewExpression node, - ConstructorInfo constructor, - IEnumerable args, - IEnumerable members) - { - if (args != node.Arguments || constructor != node.Constructor || members != node.Members) - { - if (node.Members != null) - { - return Expression.New(constructor, args, members); - } - - return Expression.New(constructor, args); - } - - return node; - } - - private static NewArrayExpression UpdateNewArray( - NewArrayExpression node, - Type arrayType, - IEnumerable expressions) - { - if (expressions != node.Expressions || node.Type != arrayType) - { - if (node.NodeType == ExpressionType.NewArrayInit) - { - return Expression.NewArrayInit(arrayType.GetElementType(), expressions); - } - - return Expression.NewArrayBounds(arrayType.GetElementType(), expressions); - } - - return node; - } - - private static TypeBinaryExpression UpdateTypeBinary(TypeBinaryExpression node, Expression expression, Type typeOperand) - { - if (expression != node.Expression || typeOperand != node.TypeOperand) - { - return Expression.TypeIs(expression, typeOperand); - } - - return node; - } - - private static UnaryExpression UpdateUnary(UnaryExpression node, Expression operand, Type resultType, MethodInfo method) - { - if (node.Operand != operand || node.Type != resultType || node.Method != method) - { - return Expression.MakeUnary(node.NodeType, operand, resultType, method); - } - - return node; - } - - private static Expression VisitUnknown(Expression node) - { - throw new InvalidOperationException(string.Format( - CultureInfo.CurrentCulture, - "Unhandled expression type: '{0}'", - node.NodeType)); - } - } -} +// Copyright (c) Microsoft Corporation. All rights reserved. +// This source code is made available under the terms of the Microsoft Public License (MS-PL) +#if NET3x +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.Globalization; +using System.Reflection; + +namespace System.Linq.Expressions +{ + [DebuggerStepThrough] + internal abstract class ExpressionVisitor + { + protected ExpressionVisitor() + { + } + + public static ReadOnlyCollection Visit(ReadOnlyCollection nodes, Func elementVisitor) + { + List list = null; + for (var index = 0; index < nodes.Count; index++) + { + var expression = elementVisitor(nodes[index]); + if (list != null) + { + list.Add(expression); + } + else if (!object.ReferenceEquals(expression, nodes[index])) + { + list = new List(nodes.Count); + for (var j = 0; j < index; j++) + { + list.Add(nodes[j]); + } + + list.Add(expression); + } + } + + return list != null ? list.AsReadOnly() : nodes; + } + + public virtual Expression Visit(Expression node) + { + if (node == null) + { + return node; + } + + switch (node.NodeType) + { + case ExpressionType.Negate: + case ExpressionType.NegateChecked: + case ExpressionType.Not: + case ExpressionType.Convert: + case ExpressionType.ConvertChecked: + case ExpressionType.ArrayLength: + case ExpressionType.Quote: + case ExpressionType.TypeAs: + case ExpressionType.UnaryPlus: + return this.VisitUnary((UnaryExpression)node); + case ExpressionType.Add: + case ExpressionType.AddChecked: + case ExpressionType.Subtract: + case ExpressionType.SubtractChecked: + case ExpressionType.Multiply: + case ExpressionType.MultiplyChecked: + case ExpressionType.Divide: + case ExpressionType.Modulo: + case ExpressionType.And: + case ExpressionType.AndAlso: + case ExpressionType.Or: + case ExpressionType.OrElse: + case ExpressionType.LessThan: + case ExpressionType.LessThanOrEqual: + case ExpressionType.GreaterThan: + case ExpressionType.GreaterThanOrEqual: + case ExpressionType.Equal: + case ExpressionType.NotEqual: + case ExpressionType.Coalesce: + case ExpressionType.ArrayIndex: + case ExpressionType.RightShift: + case ExpressionType.LeftShift: + case ExpressionType.ExclusiveOr: + case ExpressionType.Power: + return this.VisitBinary((BinaryExpression)node); + case ExpressionType.TypeIs: + return this.VisitTypeBinary((TypeBinaryExpression)node); + case ExpressionType.Conditional: + return this.VisitConditional((ConditionalExpression)node); + case ExpressionType.Constant: + return this.VisitConstant((ConstantExpression)node); + case ExpressionType.Parameter: + return this.VisitParameter((ParameterExpression)node); + case ExpressionType.MemberAccess: + return this.VisitMember((MemberExpression)node); + case ExpressionType.Call: + return this.VisitMethodCall((MethodCallExpression)node); + case ExpressionType.Lambda: + return this.VisitLambda((LambdaExpression)node); + case ExpressionType.New: + return this.VisitNew((NewExpression)node); + case ExpressionType.NewArrayInit: + case ExpressionType.NewArrayBounds: + return this.VisitNewArray((NewArrayExpression)node); + case ExpressionType.Invoke: + return this.VisitInvocation((InvocationExpression)node); + case ExpressionType.MemberInit: + return this.VisitMemberInit((MemberInitExpression)node); + case ExpressionType.ListInit: + return this.VisitListInit((ListInitExpression)node); + } + + return VisitUnknown(node); + } + + public ReadOnlyCollection Visit(ReadOnlyCollection nodes) + { + if (nodes != null) + { + List list = null; + for (var index = 0; index < nodes.Count; index++) + { + var node = this.Visit(nodes[index]); + if (list != null) + { + list.Add(node); + } + else if (node != nodes[index]) + { + list = new List(nodes.Count); + for (int j = 0; j < index; j++) + { + list.Add(nodes[j]); + } + + list.Add(node); + } + } + + if (list != null) + { + return list.AsReadOnly(); + } + } + + return nodes; + } + + protected virtual Expression VisitBinary(BinaryExpression node) + { + Expression left = this.Visit(node.Left); + Expression right = this.Visit(node.Right); + Expression conversion = this.Visit(node.Conversion); + return UpdateBinary(node, left, right, conversion, node.IsLiftedToNull, node.Method); + } + + protected virtual Expression VisitConditional(ConditionalExpression node) + { + var test = this.Visit(node.Test); + var ifTrue = this.Visit(node.IfTrue); + var ifFalse = this.Visit(node.IfFalse); + return UpdateConditional(node, test, ifTrue, ifFalse); + } + + protected virtual Expression VisitConstant(ConstantExpression node) + { + return node; + } + + protected virtual ElementInit VisitElementInit(ElementInit node) + { + var arguments = this.Visit(node.Arguments); + if (arguments != node.Arguments) + { + return Expression.ElementInit(node.AddMethod, arguments); + } + + return node; + } + + protected virtual Expression VisitInvocation(InvocationExpression node) + { + var args = this.Visit(node.Arguments); + var expression = this.Visit(node.Expression); + return UpdateInvocation(node, expression, args); + } + + protected virtual Expression VisitLambda(LambdaExpression node) + { + var body = this.Visit(node.Body); + return UpdateLambda(node, node.Type, body, node.Parameters); + } + + protected virtual Expression VisitListInit(ListInitExpression node) + { + var newExpression = (NewExpression)this.VisitNew(node.NewExpression); + var initializers = Visit(node.Initializers, n => this.VisitElementInit(n)); + return UpdateListInit(node, newExpression, initializers); + } + + protected virtual Expression VisitMember(MemberExpression node) + { + var expression = this.Visit(node.Expression); + return UpdateMember(node, expression, node.Member); + } + + protected virtual MemberAssignment VisitMemberAssignment(MemberAssignment node) + { + var expression = this.Visit(node.Expression); + return UpdateMemberAssignment(node, node.Member, expression); + } + + protected virtual MemberBinding VisitMemberBinding(MemberBinding node) + { + switch (node.BindingType) + { + case MemberBindingType.Assignment: + return this.VisitMemberAssignment((MemberAssignment)node); + case MemberBindingType.MemberBinding: + return this.VisitMemberMemberBinding((MemberMemberBinding)node); + case MemberBindingType.ListBinding: + return this.VisitMemberListBinding((MemberListBinding)node); + } + + throw new InvalidOperationException(string.Format( + CultureInfo.CurrentCulture, + "Unhandled binding type '{0}'", + node.BindingType)); + } + + protected virtual Expression VisitMemberInit(MemberInitExpression node) + { + var newExpression = (NewExpression)this.VisitNew(node.NewExpression); + var bindings = Visit(node.Bindings, n => this.VisitMemberBinding(n)); + return UpdateMemberInit(node, newExpression, bindings); + } + + protected virtual MemberListBinding VisitMemberListBinding(MemberListBinding node) + { + var initializers = Visit(node.Initializers, n => this.VisitElementInit(n)); + return UpdateMemberListBinding(node, node.Member, initializers); + } + + protected virtual MemberMemberBinding VisitMemberMemberBinding(MemberMemberBinding node) + { + var bindings = Visit(node.Bindings, n => this.VisitMemberBinding(n)); + return UpdateMemberMemberBinding(node, node.Member, bindings); + } + + protected virtual Expression VisitMethodCall(MethodCallExpression node) + { + var obj = this.Visit(node.Object); + var args = this.Visit(node.Arguments); + return UpdateMethodCall(node, obj, node.Method, args); + } + + protected virtual Expression VisitNew(NewExpression node) + { + var args = this.Visit(node.Arguments); + return UpdateNew(node, node.Constructor, args, node.Members); + } + + protected virtual Expression VisitNewArray(NewArrayExpression node) + { + var expressions = this.Visit(node.Expressions); + return UpdateNewArray(node, node.Type, expressions); + } + + protected virtual Expression VisitParameter(ParameterExpression node) + { + return node; + } + + protected virtual Expression VisitTypeBinary(TypeBinaryExpression node) + { + var expression = this.Visit(node.Expression); + return UpdateTypeBinary(node, expression, node.TypeOperand); + } + + protected virtual Expression VisitUnary(UnaryExpression node) + { + var operand = this.Visit(node.Operand); + return UpdateUnary(node, operand, node.Type, node.Method); + } + + private static BinaryExpression UpdateBinary( + BinaryExpression node, + Expression left, + Expression right, + Expression conversion, + bool isLiftedToNull, + MethodInfo method) + { + if (left != node.Left || right != node.Right || conversion != node.Conversion || + method != node.Method || isLiftedToNull != node.IsLiftedToNull) + { + if (node.NodeType == ExpressionType.Coalesce && node.Conversion != null) + { + return Expression.Coalesce(left, right, conversion as LambdaExpression); + } + + return Expression.MakeBinary(node.NodeType, left, right, isLiftedToNull, method); + } + + return node; + } + + private static ConditionalExpression UpdateConditional( + ConditionalExpression node, + Expression test, + Expression ifTrue, + Expression ifFalse) + { + if (test != node.Test || ifTrue != node.IfTrue || ifFalse != node.IfFalse) + { + return Expression.Condition(test, ifTrue, ifFalse); + } + + return node; + } + + private static InvocationExpression UpdateInvocation( + InvocationExpression node, + Expression expression, + IEnumerable args) + { + if (args != node.Arguments || expression != node.Expression) + { + return Expression.Invoke(expression, args); + } + + return node; + } + + private static LambdaExpression UpdateLambda( + LambdaExpression node, + Type delegateType, + Expression body, + IEnumerable parameters) + { + if (body != node.Body || parameters != node.Parameters || delegateType != node.Type) + { + return Expression.Lambda(delegateType, body, parameters); + } + + return node; + } + + private static ListInitExpression UpdateListInit( + ListInitExpression node, + NewExpression newExpression, + IEnumerable initializers) + { + if (newExpression != node.NewExpression || initializers != node.Initializers) + { + return Expression.ListInit(newExpression, initializers); + } + + return node; + } + + private static MemberExpression UpdateMember(MemberExpression node, Expression expression, MemberInfo member) + { + if (expression != node.Expression || member != node.Member) + { + return Expression.MakeMemberAccess(expression, member); + } + + return node; + } + + private static MemberAssignment UpdateMemberAssignment(MemberAssignment node, MemberInfo member, Expression expression) + { + if (expression != node.Expression || member != node.Member) + { + return Expression.Bind(member, expression); + } + + return node; + } + + private static MemberInitExpression UpdateMemberInit( + MemberInitExpression node, + NewExpression newExpression, + IEnumerable bindings) + { + if (newExpression != node.NewExpression || bindings != node.Bindings) + { + return Expression.MemberInit(newExpression, bindings); + } + + return node; + } + + private static MemberListBinding UpdateMemberListBinding( + MemberListBinding node, + MemberInfo member, + IEnumerable initializers) + { + if (initializers != node.Initializers || member != node.Member) + { + return Expression.ListBind(member, initializers); + } + + return node; + } + + private static MemberMemberBinding UpdateMemberMemberBinding( + MemberMemberBinding node, + MemberInfo member, + IEnumerable bindings) + { + if (bindings != node.Bindings || member != node.Member) + { + return Expression.MemberBind(member, bindings); + } + + return node; + } + + private static MethodCallExpression UpdateMethodCall( + MethodCallExpression node, + Expression obj, + MethodInfo method, + IEnumerable args) + { + if (obj != node.Object || method != node.Method || args != node.Arguments) + { + return Expression.Call(obj, method, args); + } + + return node; + } + + private static NewExpression UpdateNew( + NewExpression node, + ConstructorInfo constructor, + IEnumerable args, + IEnumerable members) + { + if (args != node.Arguments || constructor != node.Constructor || members != node.Members) + { + if (node.Members != null) + { + return Expression.New(constructor, args, members); + } + + return Expression.New(constructor, args); + } + + return node; + } + + private static NewArrayExpression UpdateNewArray( + NewArrayExpression node, + Type arrayType, + IEnumerable expressions) + { + if (expressions != node.Expressions || node.Type != arrayType) + { + if (node.NodeType == ExpressionType.NewArrayInit) + { + return Expression.NewArrayInit(arrayType.GetElementType(), expressions); + } + + return Expression.NewArrayBounds(arrayType.GetElementType(), expressions); + } + + return node; + } + + private static TypeBinaryExpression UpdateTypeBinary(TypeBinaryExpression node, Expression expression, Type typeOperand) + { + if (expression != node.Expression || typeOperand != node.TypeOperand) + { + return Expression.TypeIs(expression, typeOperand); + } + + return node; + } + + private static UnaryExpression UpdateUnary(UnaryExpression node, Expression operand, Type resultType, MethodInfo method) + { + if (node.Operand != operand || node.Type != resultType || node.Method != method) + { + return Expression.MakeUnary(node.NodeType, operand, resultType, method); + } + + return node; + } + + private static Expression VisitUnknown(Expression node) + { + throw new InvalidOperationException(string.Format( + CultureInfo.CurrentCulture, + "Unhandled expression type: '{0}'", + node.NodeType)); + } + } +} #endif \ No newline at end of file diff --git a/Source/Mock.Generic.xdoc b/Source/Mock.Generic.xdoc index 12a68d48d..2a4a8a793 100644 --- a/Source/Mock.Generic.xdoc +++ b/Source/Mock.Generic.xdoc @@ -1,615 +1,615 @@ - - - - - Provides a mock implementation of . - - - Any interface type can be used for mocking, but for classes, only abstract and virtual members can be mocked. - - The behavior of the mock with regards to the setups and the actual calls is determined - by the optional that can be passed to the - constructor. - - - Type to mock, which can be an interface or a class. - - The following example shows establishing setups with specific values - for method invocations: - - // Arrange - var order = new Order(TALISKER, 50); - var mock = new Mock<IWarehouse>(); - - mock.Setup(x => x.HasInventory(TALISKER, 50)).Returns(true); - - // Act - order.Fill(mock.Object); - - // Assert - Assert.True(order.IsFilled); - - The following example shows how to use the class - to specify conditions for arguments instead of specific values: - - // Arrange - var order = new Order(TALISKER, 50); - var mock = new Mock<IWarehouse>(); - - // shows how to expect a value within a range - mock.Setup(x => x.HasInventory( - It.IsAny<string>(), - It.IsInRange(0, 100, Range.Inclusive))) - .Returns(false); - - // shows how to throw for unexpected calls. - mock.Setup(x => x.Remove( - It.IsAny<string>(), - It.IsAny<int>())) - .Throws(new InvalidOperationException()); - - // Act - order.Fill(mock.Object); - - // Assert - Assert.False(order.IsFilled); - - - - - - Initializes an instance of the mock with default behavior. - - - var mock = new Mock<IFormatProvider>(); - - - - - Initializes an instance of the mock with default behavior and with - the given constructor arguments for the class. (Only valid when is a class) - - - The mock will try to find the best match constructor given the constructor arguments, and invoke that - to initialize the instance. This applies only for classes, not interfaces. - - - var mock = new Mock<MyProvider>(someArgument, 25); - - Optional constructor arguments if the mocked type is a class. - - - - Initializes an instance of the mock with the specified behavior. - - - var mock = new Mock<IFormatProvider>(MockBehavior.Relaxed); - - Behavior of the mock. - - - - Initializes an instance of the mock with a specific behavior with - the given constructor arguments for the class. - - - The mock will try to find the best match constructor given the constructor arguments, and invoke that - to initialize the instance. This applies only to classes, not interfaces. - - - var mock = new Mock<MyProvider>(someArgument, 25); - - Behavior of the mock. - Optional constructor arguments if the mocked type is a class. - - - - Exposes the mocked object instance. - - - - - Specifies a setup on the mocked type for a call to - to a void method. - - - If more than one setup is specified for the same method or property, - the latest one wins and is the one that will be executed. - - Lambda expression that specifies the expected method invocation. - - - var mock = new Mock<IProcessor>(); - mock.Setup(x => x.Execute("ping")); - - - - - - Specifies a setup on the mocked type for a call to - to a value returning method. - - Type of the return value. Typically omitted as it can be inferred from the expression. - - If more than one setup is specified for the same method or property, - the latest one wins and is the one that will be executed. - - Lambda expression that specifies the method invocation. - - - mock.Setup(x => x.HasInventory("Talisker", 50)).Returns(true); - - - - - - Specifies a setup on the mocked type for a call to - to a property getter. - - - If more than one setup is set for the same property getter, - the latest one wins and is the one that will be executed. - - Type of the property. Typically omitted as it can be inferred from the expression. - Lambda expression that specifies the property getter. - - - mock.SetupGet(x => x.Suspended) - .Returns(true); - - - - - - Specifies a setup on the mocked type for a call to - to a property setter. - - - If more than one setup is set for the same property setter, - the latest one wins and is the one that will be executed. - - This overloads allows the use of a callback already - typed for the property type. - - - Type of the property. Typically omitted as it can be inferred from the expression. - The Lambda expression that sets a property to a value. - - - mock.SetupSet(x => x.Suspended = true); - - - - - - Specifies a setup on the mocked type for a call to - to a property setter. - - - If more than one setup is set for the same property setter, - the latest one wins and is the one that will be executed. - - Lambda expression that sets a property to a value. - - - mock.SetupSet(x => x.Suspended = true); - - - - - - Specifies that the given property should have "property behavior", - meaning that setting its value will cause it to be saved and - later returned when the property is requested. (this is also - known as "stubbing"). - - - Type of the property, inferred from the property - expression (does not need to be specified). - - Property expression to stub. - - If you have an interface with an int property Value, you might - stub it using the following straightforward call: - - var mock = new Mock<IHaveValue>(); - mock.Stub(v => v.Value); - - After the Stub call has been issued, setting and - retrieving the object value will behave as expected: - - IHaveValue v = mock.Object; - - v.Value = 5; - Assert.Equal(5, v.Value); - - - - - - Specifies that the given property should have "property behavior", - meaning that setting its value will cause it to be saved and - later returned when the property is requested. This overload - allows setting the initial value for the property. (this is also - known as "stubbing"). - - - Type of the property, inferred from the property - expression (does not need to be specified). - - Property expression to stub. - Initial value for the property. - - If you have an interface with an int property Value, you might - stub it using the following straightforward call: - - var mock = new Mock<IHaveValue>(); - mock.SetupProperty(v => v.Value, 5); - - After the SetupProperty call has been issued, setting and - retrieving the object value will behave as expected: - - IHaveValue v = mock.Object; - // Initial value was stored - Assert.Equal(5, v.Value); - - // New value set which changes the initial value - v.Value = 6; - Assert.Equal(6, v.Value); - - - - - - Specifies that the all properties on the mock should have "property behavior", - meaning that setting its value will cause it to be saved and - later returned when the property is requested. (this is also - known as "stubbing"). The default value for each property will be the - one generated as specified by the property for the mock. - - - If the mock is set to , - the mocked default values will also get all properties setup recursively. - - - - - Verifies that a specific invocation matching the given expression was performed on the mock. Use - in conjuntion with the default . - - - This example assumes that the mock has been used, and later we want to verify that a given - invocation with specific parameters was performed: - - var mock = new Mock<IProcessor>(); - // exercise mock - //... - // Will throw if the test code didn't call Execute with a "ping" string argument. - mock.Verify(proc => proc.Execute("ping")); - - - The invocation was not performed on the mock. - Expression to verify. - - - - Verifies that a specific invocation matching the given expression was performed on the mock. Use - in conjuntion with the default . - - - The invocation was not call the times specified by - . - - Expression to verify. - The number of times a method is allowed to be called. - - - - Verifies that a specific invocation matching the given expression was performed on the mock, - specifying a failure error message. Use in conjuntion with the default - . - - - This example assumes that the mock has been used, and later we want to verify that a given - invocation with specific parameters was performed: - - var mock = new Mock<IProcessor>(); - // exercise mock - //... - // Will throw if the test code didn't call Execute with a "ping" string argument. - mock.Verify(proc => proc.Execute("ping")); - - - The invocation was not performed on the mock. - Expression to verify. - Message to show if verification fails. - - - - Verifies that a specific invocation matching the given expression was performed on the mock, - specifying a failure error message. Use in conjuntion with the default - . - - - The invocation was not call the times specified by - . - - Expression to verify. - The number of times a method is allowed to be called. - Message to show if verification fails. - - - - Verifies that a specific invocation matching the given expression was performed on the mock. Use - in conjuntion with the default . - - - This example assumes that the mock has been used, and later we want to verify that a given - invocation with specific parameters was performed: - - var mock = new Mock<IWarehouse>(); - // exercise mock - //... - // Will throw if the test code didn't call HasInventory. - mock.Verify(warehouse => warehouse.HasInventory(TALISKER, 50)); - - - The invocation was not performed on the mock. - Expression to verify. - Type of return value from the expression. - - - - Verifies that a specific invocation matching the given - expression was performed on the mock. Use in conjuntion - with the default . - - - The invocation was not call the times specified by - . - - Expression to verify. - The number of times a method is allowed to be called. - Type of return value from the expression. - - - - Verifies that a specific invocation matching the given - expression was performed on the mock, specifying a failure - error message. - - - This example assumes that the mock has been used, - and later we want to verify that a given invocation - with specific parameters was performed: - - var mock = new Mock<IWarehouse>(); - // exercise mock - //... - // Will throw if the test code didn't call HasInventory. - mock.Verify(warehouse => warehouse.HasInventory(TALISKER, 50), "When filling orders, inventory has to be checked"); - - - The invocation was not performed on the mock. - Expression to verify. - Message to show if verification fails. - Type of return value from the expression. - - - - Verifies that a specific invocation matching the given - expression was performed on the mock, specifying a failure - error message. - - - The invocation was not call the times specified by - . - - Expression to verify. - The number of times a method is allowed to be called. - Message to show if verification fails. - Type of return value from the expression. - - - - Verifies that a property was read on the mock. - - - This example assumes that the mock has been used, - and later we want to verify that a given property - was retrieved from it: - - var mock = new Mock<IWarehouse>(); - // exercise mock - //... - // Will throw if the test code didn't retrieve the IsClosed property. - mock.VerifyGet(warehouse => warehouse.IsClosed); - - - The invocation was not performed on the mock. - Expression to verify. - - Type of the property to verify. Typically omitted as it can - be inferred from the expression's return type. - - - - - Verifies that a property was read on the mock. - - - The invocation was not call the times specified by - . - - The number of times a method is allowed to be called. - Expression to verify. - - Type of the property to verify. Typically omitted as it can - be inferred from the expression's return type. - - - - - Verifies that a property was read on the mock, specifying a failure - error message. - - - This example assumes that the mock has been used, - and later we want to verify that a given property - was retrieved from it: - - var mock = new Mock<IWarehouse>(); - // exercise mock - //... - // Will throw if the test code didn't retrieve the IsClosed property. - mock.VerifyGet(warehouse => warehouse.IsClosed); - - - The invocation was not performed on the mock. - Expression to verify. - Message to show if verification fails. - - Type of the property to verify. Typically omitted as it can - be inferred from the expression's return type. - - - - - Verifies that a property was read on the mock, specifying a failure - error message. - - - The invocation was not call the times specified by - . - - The number of times a method is allowed to be called. - Expression to verify. - Message to show if verification fails. - - Type of the property to verify. Typically omitted as it can - be inferred from the expression's return type. - - - - - Verifies that a property was set on the mock. - - - This example assumes that the mock has been used, - and later we want to verify that a given property - was set on it: - - var mock = new Mock<IWarehouse>(); - // exercise mock - //... - // Will throw if the test code didn't set the IsClosed property. - mock.VerifySet(warehouse => warehouse.IsClosed = true); - - - The invocation was not performed on the mock. - Expression to verify. - - - - Verifies that a property was set on the mock. - - - The invocation was not call the times specified by - . - - The number of times a method is allowed to be called. - Expression to verify. - - - - Verifies that a property was set on the mock, specifying - a failure message. - - - This example assumes that the mock has been used, - and later we want to verify that a given property - was set on it: - - var mock = new Mock<IWarehouse>(); - // exercise mock - //... - // Will throw if the test code didn't set the IsClosed property. - mock.VerifySet(warehouse => warehouse.IsClosed = true, "Warehouse should always be closed after the action"); - - - The invocation was not performed on the mock. - Expression to verify. - Message to show if verification fails. - - - - Verifies that a property was set on the mock, specifying - a failure message. - - - The invocation was not call the times specified by - . - - The number of times a method is allowed to be called. - Expression to verify. - Message to show if verification fails. - - - - Raises the event referenced in using - the given argument. - - - The argument is - invalid for the target event invocation, or the is - not an event attach or detach expression. - - - The following example shows how to raise a event: - - var mock = new Mock<IViewModel>(); - - mock.Raise(x => x.PropertyChanged -= null, new PropertyChangedEventArgs("Name")); - - - - This example shows how to invoke an event with a custom event arguments - class in a view that will cause its corresponding presenter to - react by changing its state: - - var mockView = new Mock<IOrdersView>(); - var presenter = new OrdersPresenter(mockView.Object); - - // Check that the presenter has no selection by default - Assert.Null(presenter.SelectedOrder); - - // Raise the event with a specific arguments data - mockView.Raise(v => v.SelectionChanged += null, new OrderEventArgs { Order = new Order("moq", 500) }); - - // Now the presenter reacted to the event, and we have a selected order - Assert.NotNull(presenter.SelectedOrder); - Assert.Equal("moq", presenter.SelectedOrder.ProductName); - - - - - - Raises the event referenced in using - the given argument for a non-EventHandler typed event. - - - The arguments are - invalid for the target event invocation, or the is - not an event attach or detach expression. - - - The following example shows how to raise a custom event that does not adhere to - the standard EventHandler: - - var mock = new Mock<IViewModel>(); - - mock.Raise(x => x.MyEvent -= null, "Name", bool, 25); - - - + + + + + Provides a mock implementation of . + + + Any interface type can be used for mocking, but for classes, only abstract and virtual members can be mocked. + + The behavior of the mock with regards to the setups and the actual calls is determined + by the optional that can be passed to the + constructor. + + + Type to mock, which can be an interface or a class. + + The following example shows establishing setups with specific values + for method invocations: + + // Arrange + var order = new Order(TALISKER, 50); + var mock = new Mock<IWarehouse>(); + + mock.Setup(x => x.HasInventory(TALISKER, 50)).Returns(true); + + // Act + order.Fill(mock.Object); + + // Assert + Assert.True(order.IsFilled); + + The following example shows how to use the class + to specify conditions for arguments instead of specific values: + + // Arrange + var order = new Order(TALISKER, 50); + var mock = new Mock<IWarehouse>(); + + // shows how to expect a value within a range + mock.Setup(x => x.HasInventory( + It.IsAny<string>(), + It.IsInRange(0, 100, Range.Inclusive))) + .Returns(false); + + // shows how to throw for unexpected calls. + mock.Setup(x => x.Remove( + It.IsAny<string>(), + It.IsAny<int>())) + .Throws(new InvalidOperationException()); + + // Act + order.Fill(mock.Object); + + // Assert + Assert.False(order.IsFilled); + + + + + + Initializes an instance of the mock with default behavior. + + + var mock = new Mock<IFormatProvider>(); + + + + + Initializes an instance of the mock with default behavior and with + the given constructor arguments for the class. (Only valid when is a class) + + + The mock will try to find the best match constructor given the constructor arguments, and invoke that + to initialize the instance. This applies only for classes, not interfaces. + + + var mock = new Mock<MyProvider>(someArgument, 25); + + Optional constructor arguments if the mocked type is a class. + + + + Initializes an instance of the mock with the specified behavior. + + + var mock = new Mock<IFormatProvider>(MockBehavior.Relaxed); + + Behavior of the mock. + + + + Initializes an instance of the mock with a specific behavior with + the given constructor arguments for the class. + + + The mock will try to find the best match constructor given the constructor arguments, and invoke that + to initialize the instance. This applies only to classes, not interfaces. + + + var mock = new Mock<MyProvider>(someArgument, 25); + + Behavior of the mock. + Optional constructor arguments if the mocked type is a class. + + + + Exposes the mocked object instance. + + + + + Specifies a setup on the mocked type for a call to + to a void method. + + + If more than one setup is specified for the same method or property, + the latest one wins and is the one that will be executed. + + Lambda expression that specifies the expected method invocation. + + + var mock = new Mock<IProcessor>(); + mock.Setup(x => x.Execute("ping")); + + + + + + Specifies a setup on the mocked type for a call to + to a value returning method. + + Type of the return value. Typically omitted as it can be inferred from the expression. + + If more than one setup is specified for the same method or property, + the latest one wins and is the one that will be executed. + + Lambda expression that specifies the method invocation. + + + mock.Setup(x => x.HasInventory("Talisker", 50)).Returns(true); + + + + + + Specifies a setup on the mocked type for a call to + to a property getter. + + + If more than one setup is set for the same property getter, + the latest one wins and is the one that will be executed. + + Type of the property. Typically omitted as it can be inferred from the expression. + Lambda expression that specifies the property getter. + + + mock.SetupGet(x => x.Suspended) + .Returns(true); + + + + + + Specifies a setup on the mocked type for a call to + to a property setter. + + + If more than one setup is set for the same property setter, + the latest one wins and is the one that will be executed. + + This overloads allows the use of a callback already + typed for the property type. + + + Type of the property. Typically omitted as it can be inferred from the expression. + The Lambda expression that sets a property to a value. + + + mock.SetupSet(x => x.Suspended = true); + + + + + + Specifies a setup on the mocked type for a call to + to a property setter. + + + If more than one setup is set for the same property setter, + the latest one wins and is the one that will be executed. + + Lambda expression that sets a property to a value. + + + mock.SetupSet(x => x.Suspended = true); + + + + + + Specifies that the given property should have "property behavior", + meaning that setting its value will cause it to be saved and + later returned when the property is requested. (this is also + known as "stubbing"). + + + Type of the property, inferred from the property + expression (does not need to be specified). + + Property expression to stub. + + If you have an interface with an int property Value, you might + stub it using the following straightforward call: + + var mock = new Mock<IHaveValue>(); + mock.Stub(v => v.Value); + + After the Stub call has been issued, setting and + retrieving the object value will behave as expected: + + IHaveValue v = mock.Object; + + v.Value = 5; + Assert.Equal(5, v.Value); + + + + + + Specifies that the given property should have "property behavior", + meaning that setting its value will cause it to be saved and + later returned when the property is requested. This overload + allows setting the initial value for the property. (this is also + known as "stubbing"). + + + Type of the property, inferred from the property + expression (does not need to be specified). + + Property expression to stub. + Initial value for the property. + + If you have an interface with an int property Value, you might + stub it using the following straightforward call: + + var mock = new Mock<IHaveValue>(); + mock.SetupProperty(v => v.Value, 5); + + After the SetupProperty call has been issued, setting and + retrieving the object value will behave as expected: + + IHaveValue v = mock.Object; + // Initial value was stored + Assert.Equal(5, v.Value); + + // New value set which changes the initial value + v.Value = 6; + Assert.Equal(6, v.Value); + + + + + + Specifies that the all properties on the mock should have "property behavior", + meaning that setting its value will cause it to be saved and + later returned when the property is requested. (this is also + known as "stubbing"). The default value for each property will be the + one generated as specified by the property for the mock. + + + If the mock is set to , + the mocked default values will also get all properties setup recursively. + + + + + Verifies that a specific invocation matching the given expression was performed on the mock. Use + in conjuntion with the default . + + + This example assumes that the mock has been used, and later we want to verify that a given + invocation with specific parameters was performed: + + var mock = new Mock<IProcessor>(); + // exercise mock + //... + // Will throw if the test code didn't call Execute with a "ping" string argument. + mock.Verify(proc => proc.Execute("ping")); + + + The invocation was not performed on the mock. + Expression to verify. + + + + Verifies that a specific invocation matching the given expression was performed on the mock. Use + in conjuntion with the default . + + + The invocation was not call the times specified by + . + + Expression to verify. + The number of times a method is allowed to be called. + + + + Verifies that a specific invocation matching the given expression was performed on the mock, + specifying a failure error message. Use in conjuntion with the default + . + + + This example assumes that the mock has been used, and later we want to verify that a given + invocation with specific parameters was performed: + + var mock = new Mock<IProcessor>(); + // exercise mock + //... + // Will throw if the test code didn't call Execute with a "ping" string argument. + mock.Verify(proc => proc.Execute("ping")); + + + The invocation was not performed on the mock. + Expression to verify. + Message to show if verification fails. + + + + Verifies that a specific invocation matching the given expression was performed on the mock, + specifying a failure error message. Use in conjuntion with the default + . + + + The invocation was not call the times specified by + . + + Expression to verify. + The number of times a method is allowed to be called. + Message to show if verification fails. + + + + Verifies that a specific invocation matching the given expression was performed on the mock. Use + in conjuntion with the default . + + + This example assumes that the mock has been used, and later we want to verify that a given + invocation with specific parameters was performed: + + var mock = new Mock<IWarehouse>(); + // exercise mock + //... + // Will throw if the test code didn't call HasInventory. + mock.Verify(warehouse => warehouse.HasInventory(TALISKER, 50)); + + + The invocation was not performed on the mock. + Expression to verify. + Type of return value from the expression. + + + + Verifies that a specific invocation matching the given + expression was performed on the mock. Use in conjuntion + with the default . + + + The invocation was not call the times specified by + . + + Expression to verify. + The number of times a method is allowed to be called. + Type of return value from the expression. + + + + Verifies that a specific invocation matching the given + expression was performed on the mock, specifying a failure + error message. + + + This example assumes that the mock has been used, + and later we want to verify that a given invocation + with specific parameters was performed: + + var mock = new Mock<IWarehouse>(); + // exercise mock + //... + // Will throw if the test code didn't call HasInventory. + mock.Verify(warehouse => warehouse.HasInventory(TALISKER, 50), "When filling orders, inventory has to be checked"); + + + The invocation was not performed on the mock. + Expression to verify. + Message to show if verification fails. + Type of return value from the expression. + + + + Verifies that a specific invocation matching the given + expression was performed on the mock, specifying a failure + error message. + + + The invocation was not call the times specified by + . + + Expression to verify. + The number of times a method is allowed to be called. + Message to show if verification fails. + Type of return value from the expression. + + + + Verifies that a property was read on the mock. + + + This example assumes that the mock has been used, + and later we want to verify that a given property + was retrieved from it: + + var mock = new Mock<IWarehouse>(); + // exercise mock + //... + // Will throw if the test code didn't retrieve the IsClosed property. + mock.VerifyGet(warehouse => warehouse.IsClosed); + + + The invocation was not performed on the mock. + Expression to verify. + + Type of the property to verify. Typically omitted as it can + be inferred from the expression's return type. + + + + + Verifies that a property was read on the mock. + + + The invocation was not call the times specified by + . + + The number of times a method is allowed to be called. + Expression to verify. + + Type of the property to verify. Typically omitted as it can + be inferred from the expression's return type. + + + + + Verifies that a property was read on the mock, specifying a failure + error message. + + + This example assumes that the mock has been used, + and later we want to verify that a given property + was retrieved from it: + + var mock = new Mock<IWarehouse>(); + // exercise mock + //... + // Will throw if the test code didn't retrieve the IsClosed property. + mock.VerifyGet(warehouse => warehouse.IsClosed); + + + The invocation was not performed on the mock. + Expression to verify. + Message to show if verification fails. + + Type of the property to verify. Typically omitted as it can + be inferred from the expression's return type. + + + + + Verifies that a property was read on the mock, specifying a failure + error message. + + + The invocation was not call the times specified by + . + + The number of times a method is allowed to be called. + Expression to verify. + Message to show if verification fails. + + Type of the property to verify. Typically omitted as it can + be inferred from the expression's return type. + + + + + Verifies that a property was set on the mock. + + + This example assumes that the mock has been used, + and later we want to verify that a given property + was set on it: + + var mock = new Mock<IWarehouse>(); + // exercise mock + //... + // Will throw if the test code didn't set the IsClosed property. + mock.VerifySet(warehouse => warehouse.IsClosed = true); + + + The invocation was not performed on the mock. + Expression to verify. + + + + Verifies that a property was set on the mock. + + + The invocation was not call the times specified by + . + + The number of times a method is allowed to be called. + Expression to verify. + + + + Verifies that a property was set on the mock, specifying + a failure message. + + + This example assumes that the mock has been used, + and later we want to verify that a given property + was set on it: + + var mock = new Mock<IWarehouse>(); + // exercise mock + //... + // Will throw if the test code didn't set the IsClosed property. + mock.VerifySet(warehouse => warehouse.IsClosed = true, "Warehouse should always be closed after the action"); + + + The invocation was not performed on the mock. + Expression to verify. + Message to show if verification fails. + + + + Verifies that a property was set on the mock, specifying + a failure message. + + + The invocation was not call the times specified by + . + + The number of times a method is allowed to be called. + Expression to verify. + Message to show if verification fails. + + + + Raises the event referenced in using + the given argument. + + + The argument is + invalid for the target event invocation, or the is + not an event attach or detach expression. + + + The following example shows how to raise a event: + + var mock = new Mock<IViewModel>(); + + mock.Raise(x => x.PropertyChanged -= null, new PropertyChangedEventArgs("Name")); + + + + This example shows how to invoke an event with a custom event arguments + class in a view that will cause its corresponding presenter to + react by changing its state: + + var mockView = new Mock<IOrdersView>(); + var presenter = new OrdersPresenter(mockView.Object); + + // Check that the presenter has no selection by default + Assert.Null(presenter.SelectedOrder); + + // Raise the event with a specific arguments data + mockView.Raise(v => v.SelectionChanged += null, new OrderEventArgs { Order = new Order("moq", 500) }); + + // Now the presenter reacted to the event, and we have a selected order + Assert.NotNull(presenter.SelectedOrder); + Assert.Equal("moq", presenter.SelectedOrder.ProductName); + + + + + + Raises the event referenced in using + the given argument for a non-EventHandler typed event. + + + The arguments are + invalid for the target event invocation, or the is + not an event attach or detach expression. + + + The following example shows how to raise a custom event that does not adhere to + the standard EventHandler: + + var mock = new Mock<IViewModel>(); + + mock.Raise(x => x.MyEvent -= null, "Name", bool, 25); + + + \ No newline at end of file diff --git a/Source/Mock.xdoc b/Source/Mock.xdoc index 90205a2d3..29697f3bf 100644 --- a/Source/Mock.xdoc +++ b/Source/Mock.xdoc @@ -1,161 +1,161 @@ - - - - - Base class for mocks and static helper class with methods that - apply to mocked objects, such as to - retrieve a from an object instance. - - - - - Initializes a new instance of the class. - - - - - Retrieves the mock object for the given object instance. - - - Type of the mock to retrieve. Can be omitted as it's inferred - from the object instance passed in as the instance. - - The instance of the mocked object. - The mock associated with the mocked object. - - The received instance - was not created by Moq. - - - The following example shows how to add a new setup to an object - instance which is not the original but rather - the object associated with it: - - // Typed instance, not the mock, is retrieved from some test API. - HttpContextBase context = GetMockContext(); - - // context.Request is the typed object from the "real" API - // so in order to add a setup to it, we need to get - // the mock that "owns" it - Mock<HttpRequestBase> request = Mock.Get(context.Request); - mock.Setup(req => req.AppRelativeCurrentExecutionFilePath) - .Returns(tempUrl); - - - - - - Behavior of the mock, according to the value set in the constructor. - - - - - Whether the base member virtual implementation will be called - for mocked classes if no setup is matched. Defaults to . - - - - - Specifies the behavior to use when returning default values for - unexpected invocations on loose mocks. - - - - - Gets the mocked object instance. - - - - - Returns the mocked object value. - - - - - Verifies that all verifiable expectations have been met. - - - This example sets up an expectation and marks it as verifiable. After - the mock is used, a Verify() call is issued on the mock - to ensure the method in the setup was invoked: - - var mock = new Mock<IWarehouse>(); - this.Setup(x => x.HasInventory(TALISKER, 50)).Verifiable().Returns(true); - ... - // other test code - ... - // Will throw if the test code has didn't call HasInventory. - this.Verify(); - - - Not all verifiable expectations were met. - - - - Verifies all expectations regardless of whether they have - been flagged as verifiable. - - - This example sets up an expectation without marking it as verifiable. After - the mock is used, a call is issued on the mock - to ensure that all expectations are met: - - var mock = new Mock<IWarehouse>(); - this.Setup(x => x.HasInventory(TALISKER, 50)).Returns(true); - ... - // other test code - ... - // Will throw if the test code has didn't call HasInventory, even - // that expectation was not marked as verifiable. - this.VerifyAll(); - - - At least one expectation was not met. - - - - Adds an interface implementation to the mock, - allowing setups to be specified for it. - - - This method can only be called before the first use - of the mock property, at which - point the runtime type has already been generated - and no more interfaces can be added to it. - - Also, must be an - interface and not a class, which must be specified - when creating the mock instead. - - - - The mock type - has already been generated by accessing the property. - - - The specified - is not an interface. - - - The following example creates a mock for the main interface - and later adds to it to verify - it's called by the consumer code: - - var mock = new Mock<IProcessor>(); - mock.Setup(x => x.Execute("ping")); - - // add IDisposable interface - var disposable = mock.As<IDisposable>(); - disposable.Setup(d => d.Dispose()).Verifiable(); - - - Type of interface to cast the mock to. - - - - Defines the default value to return in all mocked methods or properties returning . - - The type to define the default. - The default value. - + + + + + Base class for mocks and static helper class with methods that + apply to mocked objects, such as to + retrieve a from an object instance. + + + + + Initializes a new instance of the class. + + + + + Retrieves the mock object for the given object instance. + + + Type of the mock to retrieve. Can be omitted as it's inferred + from the object instance passed in as the instance. + + The instance of the mocked object. + The mock associated with the mocked object. + + The received instance + was not created by Moq. + + + The following example shows how to add a new setup to an object + instance which is not the original but rather + the object associated with it: + + // Typed instance, not the mock, is retrieved from some test API. + HttpContextBase context = GetMockContext(); + + // context.Request is the typed object from the "real" API + // so in order to add a setup to it, we need to get + // the mock that "owns" it + Mock<HttpRequestBase> request = Mock.Get(context.Request); + mock.Setup(req => req.AppRelativeCurrentExecutionFilePath) + .Returns(tempUrl); + + + + + + Behavior of the mock, according to the value set in the constructor. + + + + + Whether the base member virtual implementation will be called + for mocked classes if no setup is matched. Defaults to . + + + + + Specifies the behavior to use when returning default values for + unexpected invocations on loose mocks. + + + + + Gets the mocked object instance. + + + + + Returns the mocked object value. + + + + + Verifies that all verifiable expectations have been met. + + + This example sets up an expectation and marks it as verifiable. After + the mock is used, a Verify() call is issued on the mock + to ensure the method in the setup was invoked: + + var mock = new Mock<IWarehouse>(); + this.Setup(x => x.HasInventory(TALISKER, 50)).Verifiable().Returns(true); + ... + // other test code + ... + // Will throw if the test code has didn't call HasInventory. + this.Verify(); + + + Not all verifiable expectations were met. + + + + Verifies all expectations regardless of whether they have + been flagged as verifiable. + + + This example sets up an expectation without marking it as verifiable. After + the mock is used, a call is issued on the mock + to ensure that all expectations are met: + + var mock = new Mock<IWarehouse>(); + this.Setup(x => x.HasInventory(TALISKER, 50)).Returns(true); + ... + // other test code + ... + // Will throw if the test code has didn't call HasInventory, even + // that expectation was not marked as verifiable. + this.VerifyAll(); + + + At least one expectation was not met. + + + + Adds an interface implementation to the mock, + allowing setups to be specified for it. + + + This method can only be called before the first use + of the mock property, at which + point the runtime type has already been generated + and no more interfaces can be added to it. + + Also, must be an + interface and not a class, which must be specified + when creating the mock instead. + + + + The mock type + has already been generated by accessing the property. + + + The specified + is not an interface. + + + The following example creates a mock for the main interface + and later adds to it to verify + it's called by the consumer code: + + var mock = new Mock<IProcessor>(); + mock.Setup(x => x.Execute("ping")); + + // add IDisposable interface + var disposable = mock.As<IDisposable>(); + disposable.Setup(d => d.Dispose()).Verifiable(); + + + Type of interface to cast the mock to. + + + + Defines the default value to return in all mocked methods or properties returning . + + The type to define the default. + The default value. + \ No newline at end of file diff --git a/Source/MockBehavior.cs b/Source/MockBehavior.cs index 82bbfa4f1..c72bd4785 100644 --- a/Source/MockBehavior.cs +++ b/Source/MockBehavior.cs @@ -1,66 +1,66 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - - -namespace Moq -{ - /// - /// Options to customize the behavior of the mock. - /// - public enum MockBehavior - { - /// - /// Causes the mock to always throw - /// an exception for invocations that don't have a - /// corresponding setup. - /// - Strict, - /// - /// Will never throw exceptions, returning default - /// values when necessary (null for reference types, - /// zero for value types or empty enumerables and arrays). - /// - Loose, - /// - /// Default mock behavior, which equals . - /// - Default = Loose, - } -} +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + + +namespace Moq +{ + /// + /// Options to customize the behavior of the mock. + /// + public enum MockBehavior + { + /// + /// Causes the mock to always throw + /// an exception for invocations that don't have a + /// corresponding setup. + /// + Strict, + /// + /// Will never throw exceptions, returning default + /// values when necessary (null for reference types, + /// zero for value types or empty enumerables and arrays). + /// + Loose, + /// + /// Default mock behavior, which equals . + /// + Default = Loose, + } +} diff --git a/Source/MockDefaultValueProvider.cs b/Source/MockDefaultValueProvider.cs index bb2d0f200..b727a6577 100644 --- a/Source/MockDefaultValueProvider.cs +++ b/Source/MockDefaultValueProvider.cs @@ -1,77 +1,77 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Reflection; - -namespace Moq -{ - /// - /// A that returns an empty default value - /// for non-mockeable types, and mocks for all other types (interfaces and - /// non-sealed classes) that can be mocked. - /// - internal class MockDefaultValueProvider : EmptyDefaultValueProvider - { - private Mock owner; - - public MockDefaultValueProvider(Mock owner) - { - this.owner = owner; - } - - public override object ProvideDefault(MethodInfo member) - { - var value = base.ProvideDefault(member); - - Mock mock = null; - if (value == null && member.ReturnType.IsMockeable() && !owner.InnerMocks.TryGetValue(member, out mock)) - { - var mockType = typeof(Mock<>).MakeGenericType(member.ReturnType); - mock = (Mock)Activator.CreateInstance(mockType, owner.Behavior); - mock.DefaultValue = owner.DefaultValue; - mock.CallBase = owner.CallBase; - owner.InnerMocks.Add(member, mock); - } - - return mock != null ? mock.Object : value; - } - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Reflection; + +namespace Moq +{ + /// + /// A that returns an empty default value + /// for non-mockeable types, and mocks for all other types (interfaces and + /// non-sealed classes) that can be mocked. + /// + internal class MockDefaultValueProvider : EmptyDefaultValueProvider + { + private Mock owner; + + public MockDefaultValueProvider(Mock owner) + { + this.owner = owner; + } + + public override object ProvideDefault(MethodInfo member) + { + var value = base.ProvideDefault(member); + + Mock mock = null; + if (value == null && member.ReturnType.IsMockeable() && !owner.InnerMocks.TryGetValue(member, out mock)) + { + var mockType = typeof(Mock<>).MakeGenericType(member.ReturnType); + mock = (Mock)Activator.CreateInstance(mockType, owner.Behavior); + mock.DefaultValue = owner.DefaultValue; + mock.CallBase = owner.CallBase; + owner.InnerMocks.Add(member, mock); + } + + return mock != null ? mock.Object : value; + } + } } \ No newline at end of file diff --git a/Source/MockRepository.cs b/Source/MockRepository.cs index 4b3c13f0c..52fa47ef4 100644 --- a/Source/MockRepository.cs +++ b/Source/MockRepository.cs @@ -1,151 +1,151 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Moq.Properties; - -namespace Moq -{ - /// - /// Utility repository class to use to construct multiple - /// mocks when consistent verification is - /// desired for all of them. - /// - /// - /// If multiple mocks will be created during a test, passing - /// the desired (if different than the - /// or the one - /// passed to the repository constructor) and later verifying each - /// mock can become repetitive and tedious. - /// - /// This repository class helps in that scenario by providing a - /// simplified creation of multiple mocks with a default - /// (unless overriden by calling - /// ) and posterior verification. - /// - /// - /// - /// The following is a straightforward example on how to - /// create and automatically verify strict mocks using a : - /// - /// var repository = new MockRepository(MockBehavior.Strict); - /// - /// var foo = repository.Create<IFoo>(); - /// var bar = repository.Create<IBar>(); - /// - /// // no need to call Verifiable() on the setup - /// // as we'll be validating all of them anyway. - /// foo.Setup(f => f.Do()); - /// bar.Setup(b => b.Redo()); - /// - /// // exercise the mocks here - /// - /// repository.VerifyAll(); - /// // At this point all setups are already checked - /// // and an optional MockException might be thrown. - /// // Note also that because the mocks are strict, any invocation - /// // that doesn't have a matching setup will also throw a MockException. - /// - /// The following examples shows how to setup the repository - /// to create loose mocks and later verify only verifiable setups: - /// - /// var repository = new MockRepository(MockBehavior.Loose); - /// - /// var foo = repository.Create<IFoo>(); - /// var bar = repository.Create<IBar>(); - /// - /// // this setup will be verified when we verify the repository - /// foo.Setup(f => f.Do()).Verifiable(); - /// - /// // this setup will NOT be verified - /// foo.Setup(f => f.Calculate()); - /// - /// // this setup will be verified when we verify the repository - /// bar.Setup(b => b.Redo()).Verifiable(); - /// - /// // exercise the mocks here - /// // note that because the mocks are Loose, members - /// // called in the interfaces for which no matching - /// // setups exist will NOT throw exceptions, - /// // and will rather return default values. - /// - /// repository.Verify(); - /// // At this point verifiable setups are already checked - /// // and an optional MockException might be thrown. - /// - /// The following examples shows how to setup the repository with a - /// default strict behavior, overriding that default for a - /// specific mock: - /// - /// var repository = new MockRepository(MockBehavior.Strict); - /// - /// // this particular one we want loose - /// var foo = repository.Create<IFoo>(MockBehavior.Loose); - /// var bar = repository.Create<IBar>(); - /// - /// // specify setups - /// - /// // exercise the mocks here - /// - /// repository.Verify(); - /// - /// - /// -#pragma warning disable 618 - public partial class MockRepository : MockFactory - { - /// - /// Initializes the repository with the given - /// for newly created mocks from the repository. - /// - /// The behavior to use for mocks created - /// using the repository method if not overriden - /// by using the overload. - public MockRepository(MockBehavior defaultBehavior) - : base(defaultBehavior) - { - } -#pragma warning restore 618 - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Moq.Properties; + +namespace Moq +{ + /// + /// Utility repository class to use to construct multiple + /// mocks when consistent verification is + /// desired for all of them. + /// + /// + /// If multiple mocks will be created during a test, passing + /// the desired (if different than the + /// or the one + /// passed to the repository constructor) and later verifying each + /// mock can become repetitive and tedious. + /// + /// This repository class helps in that scenario by providing a + /// simplified creation of multiple mocks with a default + /// (unless overriden by calling + /// ) and posterior verification. + /// + /// + /// + /// The following is a straightforward example on how to + /// create and automatically verify strict mocks using a : + /// + /// var repository = new MockRepository(MockBehavior.Strict); + /// + /// var foo = repository.Create<IFoo>(); + /// var bar = repository.Create<IBar>(); + /// + /// // no need to call Verifiable() on the setup + /// // as we'll be validating all of them anyway. + /// foo.Setup(f => f.Do()); + /// bar.Setup(b => b.Redo()); + /// + /// // exercise the mocks here + /// + /// repository.VerifyAll(); + /// // At this point all setups are already checked + /// // and an optional MockException might be thrown. + /// // Note also that because the mocks are strict, any invocation + /// // that doesn't have a matching setup will also throw a MockException. + /// + /// The following examples shows how to setup the repository + /// to create loose mocks and later verify only verifiable setups: + /// + /// var repository = new MockRepository(MockBehavior.Loose); + /// + /// var foo = repository.Create<IFoo>(); + /// var bar = repository.Create<IBar>(); + /// + /// // this setup will be verified when we verify the repository + /// foo.Setup(f => f.Do()).Verifiable(); + /// + /// // this setup will NOT be verified + /// foo.Setup(f => f.Calculate()); + /// + /// // this setup will be verified when we verify the repository + /// bar.Setup(b => b.Redo()).Verifiable(); + /// + /// // exercise the mocks here + /// // note that because the mocks are Loose, members + /// // called in the interfaces for which no matching + /// // setups exist will NOT throw exceptions, + /// // and will rather return default values. + /// + /// repository.Verify(); + /// // At this point verifiable setups are already checked + /// // and an optional MockException might be thrown. + /// + /// The following examples shows how to setup the repository with a + /// default strict behavior, overriding that default for a + /// specific mock: + /// + /// var repository = new MockRepository(MockBehavior.Strict); + /// + /// // this particular one we want loose + /// var foo = repository.Create<IFoo>(MockBehavior.Loose); + /// var bar = repository.Create<IBar>(); + /// + /// // specify setups + /// + /// // exercise the mocks here + /// + /// repository.Verify(); + /// + /// + /// +#pragma warning disable 618 + public partial class MockRepository : MockFactory + { + /// + /// Initializes the repository with the given + /// for newly created mocks from the repository. + /// + /// The behavior to use for mocks created + /// using the repository method if not overriden + /// by using the overload. + public MockRepository(MockBehavior defaultBehavior) + : base(defaultBehavior) + { + } +#pragma warning restore 618 + } } \ No newline at end of file diff --git a/Source/MockSequence.cs b/Source/MockSequence.cs index 9989381a4..77306dfd2 100644 --- a/Source/MockSequence.cs +++ b/Source/MockSequence.cs @@ -1,76 +1,76 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Moq.Language; - -namespace Moq -{ - /// - /// Helper class to setup a full trace between many mocks - /// - public class MockSequence - { - int sequenceStep; - int sequenceLength; - - /// - /// Initialize a trace setup - /// - public MockSequence() - { - sequenceLength = 0; - sequenceStep = 0; - } - - /// - /// Allow sequence to be repeated - /// - public bool Cyclic { get; set; } - - private void NextStep() - { - sequenceStep++; - if (Cyclic) - sequenceStep = sequenceStep % sequenceLength; - } - - internal ISetupConditionResult For(Mock mock) - where TMock : class - { - var expectationPosition = sequenceLength++; - - // HACK assume condition is only - // evaluated once. issues to attach callback lately. - return mock.When(() => - { - var c = expectationPosition == sequenceStep; - if (c) - { - this.NextStep(); - } - - return c; - }); - } - } - - /// - /// define nice api - /// - public static class MockSequenceHelper - { - /// - /// Perform an expectation in the trace. - /// - public static ISetupConditionResult InSequence( - this Mock mock, - MockSequence sequence) - where TMock : class - { - Guard.NotNull(() => sequence, sequence); - - return sequence.For(mock); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Moq.Language; + +namespace Moq +{ + /// + /// Helper class to setup a full trace between many mocks + /// + public class MockSequence + { + int sequenceStep; + int sequenceLength; + + /// + /// Initialize a trace setup + /// + public MockSequence() + { + sequenceLength = 0; + sequenceStep = 0; + } + + /// + /// Allow sequence to be repeated + /// + public bool Cyclic { get; set; } + + private void NextStep() + { + sequenceStep++; + if (Cyclic) + sequenceStep = sequenceStep % sequenceLength; + } + + internal ISetupConditionResult For(Mock mock) + where TMock : class + { + var expectationPosition = sequenceLength++; + + // HACK assume condition is only + // evaluated once. issues to attach callback lately. + return mock.When(() => + { + var c = expectationPosition == sequenceStep; + if (c) + { + this.NextStep(); + } + + return c; + }); + } + } + + /// + /// define nice api + /// + public static class MockSequenceHelper + { + /// + /// Perform an expectation in the trace. + /// + public static ISetupConditionResult InSequence( + this Mock mock, + MockSequence sequence) + where TMock : class + { + Guard.NotNull(() => sequence, sequence); + + return sequence.For(mock); + } + } +} diff --git a/Source/Obsolete/IOccurrence.cs b/Source/Obsolete/IOccurrence.cs index 51b719795..234f18d76 100644 --- a/Source/Obsolete/IOccurrence.cs +++ b/Source/Obsolete/IOccurrence.cs @@ -1,80 +1,80 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System.ComponentModel; -using System; - -namespace Moq.Language -{ - /// - /// Defines occurrence members to constraint setups. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IOccurrence : IHideObjectMembers - { - /// - /// The expected invocation can happen at most once. - /// - /// - /// - /// var mock = new Mock<ICommand>(); - /// mock.Setup(foo => foo.Execute("ping")) - /// .AtMostOnce(); - /// - /// - [Obsolete("To verify this condition, use the overload to Verify that receives Times.AtMostOnce().")] - [EditorBrowsable(EditorBrowsableState.Never)] - IVerifies AtMostOnce(); - /// - /// The expected invocation can happen at most specified number of times. - /// - /// The number of times to accept calls. - /// - /// - /// var mock = new Mock<ICommand>(); - /// mock.Setup(foo => foo.Execute("ping")) - /// .AtMost( 5 ); - /// - /// - [Obsolete("To verify this condition, use the overload to Verify that receives Times.AtMost(callCount).")] - [EditorBrowsable(EditorBrowsableState.Never)] - IVerifies AtMost(int callCount); - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System.ComponentModel; +using System; + +namespace Moq.Language +{ + /// + /// Defines occurrence members to constraint setups. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public interface IOccurrence : IHideObjectMembers + { + /// + /// The expected invocation can happen at most once. + /// + /// + /// + /// var mock = new Mock<ICommand>(); + /// mock.Setup(foo => foo.Execute("ping")) + /// .AtMostOnce(); + /// + /// + [Obsolete("To verify this condition, use the overload to Verify that receives Times.AtMostOnce().")] + [EditorBrowsable(EditorBrowsableState.Never)] + IVerifies AtMostOnce(); + /// + /// The expected invocation can happen at most specified number of times. + /// + /// The number of times to accept calls. + /// + /// + /// var mock = new Mock<ICommand>(); + /// mock.Setup(foo => foo.Execute("ping")) + /// .AtMost( 5 ); + /// + /// + [Obsolete("To verify this condition, use the overload to Verify that receives Times.AtMost(callCount).")] + [EditorBrowsable(EditorBrowsableState.Never)] + IVerifies AtMost(int callCount); + } } \ No newline at end of file diff --git a/Source/Obsolete/Mock.Generic.Legacy.cs b/Source/Obsolete/Mock.Generic.Legacy.cs index bd29ba4b4..5ee83a2b8 100644 --- a/Source/Obsolete/Mock.Generic.Legacy.cs +++ b/Source/Obsolete/Mock.Generic.Legacy.cs @@ -1,147 +1,147 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.ComponentModel; -using System.Linq.Expressions; -using Moq.Language.Flow; - -namespace Moq -{ - // Keeps legacy members that are hidden and are provided - // for backwards compatibility (so that existing projects - // still compile, but people don't see them). - // A bug in EditorBrowsable actually prevents us from moving these members - // completely to extension methods, as the attribute is not honored and - // therefore the members are always visible. - public partial class Mock - { - /// - /// Obsolete. - /// - [Obsolete("Expect has been renamed to Setup.", false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public ISetup Expect(Expression> expression) - { - return Setup(expression); - } - - /// - /// Obsolete. - /// - [Obsolete("Expect has been renamed to Setup.", false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public ISetup Expect(Expression> expression) - { - return Setup(expression); - } - - /// - /// Obsolete. - /// - [Obsolete("ExpectGet has been renamed to SetupGet.", false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public ISetupGetter ExpectGet(Expression> expression) - { - return SetupGet(expression); - } - - /// - /// Obsolete. - /// - [Obsolete("ExpectSet has been renamed to SetupSet.", false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public ISetupSetter ExpectSet(Expression> expression) - { - return Mock.SetupSet(this, expression); - } - - /// - /// Obsolete. - /// - [Obsolete("ExpectSet has been renamed to SetupSet, and the new syntax allows you to pass the value in the expression itself, like f => f.Value = 25.", true)] - [EditorBrowsable(EditorBrowsableState.Never)] - public ISetupSetter ExpectSet(Expression> expression, TProperty value) - { - return Mock.SetupSet(this, expression, value); - } - } - - /// - /// Provides legacy API members as extensions so that - /// existing code continues to compile, but new code - /// doesn't see then. - /// - public static class MockLegacyExtensions - { - /// - /// Obsolete. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("The new syntax allows you to pass the value in the expression itself, like f => f.Value = 25.", true)] - public static ISetupSetter SetupSet(this Mock mock, Expression> expression, TProperty value) - where T : class - { - return Mock.SetupSet(mock, expression, value); - } - - /// - /// Obsolete. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("Use the new syntax, which allows you to pass the value in the expression itself, mock.VerifySet(m => m.Value = 25);", true)] - public static void VerifySet(this Mock mock, Expression> expression, TProperty value) - where T : class - { - Mock.VerifySet(mock, expression, value, Times.AtLeastOnce(), null); - } - - /// - /// Obsolete. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("Use the new syntax, which allows you to pass the value in the expression itself, mock.VerifySet(m => m.Value = 25, failMessage);", true)] - public static void VerifySet(this Mock mock, Expression> expression, TProperty value, string failMessage) - where T : class - { - Mock.VerifySet(mock, expression, value, Times.AtLeastOnce(), failMessage); - } - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.ComponentModel; +using System.Linq.Expressions; +using Moq.Language.Flow; + +namespace Moq +{ + // Keeps legacy members that are hidden and are provided + // for backwards compatibility (so that existing projects + // still compile, but people don't see them). + // A bug in EditorBrowsable actually prevents us from moving these members + // completely to extension methods, as the attribute is not honored and + // therefore the members are always visible. + public partial class Mock + { + /// + /// Obsolete. + /// + [Obsolete("Expect has been renamed to Setup.", false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public ISetup Expect(Expression> expression) + { + return Setup(expression); + } + + /// + /// Obsolete. + /// + [Obsolete("Expect has been renamed to Setup.", false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public ISetup Expect(Expression> expression) + { + return Setup(expression); + } + + /// + /// Obsolete. + /// + [Obsolete("ExpectGet has been renamed to SetupGet.", false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public ISetupGetter ExpectGet(Expression> expression) + { + return SetupGet(expression); + } + + /// + /// Obsolete. + /// + [Obsolete("ExpectSet has been renamed to SetupSet.", false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public ISetupSetter ExpectSet(Expression> expression) + { + return Mock.SetupSet(this, expression); + } + + /// + /// Obsolete. + /// + [Obsolete("ExpectSet has been renamed to SetupSet, and the new syntax allows you to pass the value in the expression itself, like f => f.Value = 25.", true)] + [EditorBrowsable(EditorBrowsableState.Never)] + public ISetupSetter ExpectSet(Expression> expression, TProperty value) + { + return Mock.SetupSet(this, expression, value); + } + } + + /// + /// Provides legacy API members as extensions so that + /// existing code continues to compile, but new code + /// doesn't see then. + /// + public static class MockLegacyExtensions + { + /// + /// Obsolete. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("The new syntax allows you to pass the value in the expression itself, like f => f.Value = 25.", true)] + public static ISetupSetter SetupSet(this Mock mock, Expression> expression, TProperty value) + where T : class + { + return Mock.SetupSet(mock, expression, value); + } + + /// + /// Obsolete. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("Use the new syntax, which allows you to pass the value in the expression itself, mock.VerifySet(m => m.Value = 25);", true)] + public static void VerifySet(this Mock mock, Expression> expression, TProperty value) + where T : class + { + Mock.VerifySet(mock, expression, value, Times.AtLeastOnce(), null); + } + + /// + /// Obsolete. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("Use the new syntax, which allows you to pass the value in the expression itself, mock.VerifySet(m => m.Value = 25, failMessage);", true)] + public static void VerifySet(this Mock mock, Expression> expression, TProperty value, string failMessage) + where T : class + { + Mock.VerifySet(mock, expression, value, Times.AtLeastOnce(), failMessage); + } + } } \ No newline at end of file diff --git a/Source/Obsolete/Mock.Legacy.cs b/Source/Obsolete/Mock.Legacy.cs index a9b08b718..b7dac3979 100644 --- a/Source/Obsolete/Mock.Legacy.cs +++ b/Source/Obsolete/Mock.Legacy.cs @@ -1,106 +1,106 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Linq.Expressions; - -namespace Moq -{ - // Keeps legacy implementations. - public partial class Mock - { - [Obsolete] - internal static SetterMethodCall SetupSet( - Mock mock, - Expression> expression, TProperty value) - where T : class - { - var prop = expression.ToPropertyInfo(); - ThrowIfPropertyNotWritable(prop); - - var setter = prop.GetSetMethod(); - ThrowIfCantOverride(expression, setter); - - var call = new SetterMethodCall(mock, expression, setter, value); - var targetInterceptor = GetInterceptor(((MemberExpression)expression.Body).Expression, mock); - - targetInterceptor.AddCall(call, SetupKind.PropertySet); - - return call; - } - - [Obsolete] - internal static void VerifySet( - Mock mock, - Expression> expression, - Times times, - string failMessage) - where T : class - { - var method = expression.ToPropertyInfo().GetSetMethod(); - ThrowIfVerifyNonVirtual(expression, method); - - var expected = new SetterMethodCall(mock, expression, method) - { - FailMessage = failMessage - }; - VerifyCalls(GetInterceptor(((MemberExpression)expression.Body).Expression, mock), expected, expression, times); - } - - [Obsolete] - internal static void VerifySet( - Mock mock, - Expression> expression, - TProperty value, - Times times, - string failMessage) - where T : class - { - var method = expression.ToPropertyInfo().GetSetMethod(); - ThrowIfVerifyNonVirtual(expression, method); - - var expected = new SetterMethodCall(mock, expression, method, value) - { - FailMessage = failMessage - }; - VerifyCalls(GetInterceptor(((MemberExpression)expression.Body).Expression, mock), expected, expression, times); - } - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Linq.Expressions; + +namespace Moq +{ + // Keeps legacy implementations. + public partial class Mock + { + [Obsolete] + internal static SetterMethodCall SetupSet( + Mock mock, + Expression> expression, TProperty value) + where T : class + { + var prop = expression.ToPropertyInfo(); + ThrowIfPropertyNotWritable(prop); + + var setter = prop.GetSetMethod(); + ThrowIfCantOverride(expression, setter); + + var call = new SetterMethodCall(mock, expression, setter, value); + var targetInterceptor = GetInterceptor(((MemberExpression)expression.Body).Expression, mock); + + targetInterceptor.AddCall(call, SetupKind.PropertySet); + + return call; + } + + [Obsolete] + internal static void VerifySet( + Mock mock, + Expression> expression, + Times times, + string failMessage) + where T : class + { + var method = expression.ToPropertyInfo().GetSetMethod(); + ThrowIfVerifyNonVirtual(expression, method); + + var expected = new SetterMethodCall(mock, expression, method) + { + FailMessage = failMessage + }; + VerifyCalls(GetInterceptor(((MemberExpression)expression.Body).Expression, mock), expected, expression, times); + } + + [Obsolete] + internal static void VerifySet( + Mock mock, + Expression> expression, + TProperty value, + Times times, + string failMessage) + where T : class + { + var method = expression.ToPropertyInfo().GetSetMethod(); + ThrowIfVerifyNonVirtual(expression, method); + + var expected = new SetterMethodCall(mock, expression, method, value) + { + FailMessage = failMessage + }; + VerifyCalls(GetInterceptor(((MemberExpression)expression.Body).Expression, mock), expected, expression, times); + } + } } \ No newline at end of file diff --git a/Source/Obsolete/MockFactory.cs b/Source/Obsolete/MockFactory.cs index 2fad668a3..fee8a6242 100644 --- a/Source/Obsolete/MockFactory.cs +++ b/Source/Obsolete/MockFactory.cs @@ -1,355 +1,355 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Moq.Properties; - -namespace Moq -{ - /// - /// Utility factory class to use to construct multiple - /// mocks when consistent verification is - /// desired for all of them. - /// - /// - /// If multiple mocks will be created during a test, passing - /// the desired (if different than the - /// or the one - /// passed to the factory constructor) and later verifying each - /// mock can become repetitive and tedious. - /// - /// This factory class helps in that scenario by providing a - /// simplified creation of multiple mocks with a default - /// (unless overriden by calling - /// ) and posterior verification. - /// - /// - /// - /// The following is a straightforward example on how to - /// create and automatically verify strict mocks using a : - /// - /// var factory = new MockFactory(MockBehavior.Strict); - /// - /// var foo = factory.Create<IFoo>(); - /// var bar = factory.Create<IBar>(); - /// - /// // no need to call Verifiable() on the setup - /// // as we'll be validating all of them anyway. - /// foo.Setup(f => f.Do()); - /// bar.Setup(b => b.Redo()); - /// - /// // exercise the mocks here - /// - /// factory.VerifyAll(); - /// // At this point all setups are already checked - /// // and an optional MockException might be thrown. - /// // Note also that because the mocks are strict, any invocation - /// // that doesn't have a matching setup will also throw a MockException. - /// - /// The following examples shows how to setup the factory - /// to create loose mocks and later verify only verifiable setups: - /// - /// var factory = new MockFactory(MockBehavior.Loose); - /// - /// var foo = factory.Create<IFoo>(); - /// var bar = factory.Create<IBar>(); - /// - /// // this setup will be verified when we verify the factory - /// foo.Setup(f => f.Do()).Verifiable(); - /// - /// // this setup will NOT be verified - /// foo.Setup(f => f.Calculate()); - /// - /// // this setup will be verified when we verify the factory - /// bar.Setup(b => b.Redo()).Verifiable(); - /// - /// // exercise the mocks here - /// // note that because the mocks are Loose, members - /// // called in the interfaces for which no matching - /// // setups exist will NOT throw exceptions, - /// // and will rather return default values. - /// - /// factory.Verify(); - /// // At this point verifiable setups are already checked - /// // and an optional MockException might be thrown. - /// - /// The following examples shows how to setup the factory with a - /// default strict behavior, overriding that default for a - /// specific mock: - /// - /// var factory = new MockFactory(MockBehavior.Strict); - /// - /// // this particular one we want loose - /// var foo = factory.Create<IFoo>(MockBehavior.Loose); - /// var bar = factory.Create<IBar>(); - /// - /// // specify setups - /// - /// // exercise the mocks here - /// - /// factory.Verify(); - /// - /// - /// - [Obsolete("This class has been renamed to MockRepository. MockFactory will be retired in v5.", false)] - public partial class MockFactory - { - List mocks = new List(); - MockBehavior defaultBehavior; - - /// - /// Initializes the factory with the given - /// for newly created mocks from the factory. - /// - /// The behavior to use for mocks created - /// using the factory method if not overriden - /// by using the overload. - public MockFactory(MockBehavior defaultBehavior) - { - this.defaultBehavior = defaultBehavior; - } - - /// - /// Whether the base member virtual implementation will be called - /// for mocked classes if no setup is matched. Defaults to . - /// - public bool CallBase { get; set; } - - /// - /// Specifies the behavior to use when returning default values for - /// unexpected invocations on loose mocks. - /// - public DefaultValue DefaultValue { get; set; } - - /// - /// Gets the mocks that have been created by this factory and - /// that will get verified together. - /// - protected internal IEnumerable Mocks { get { return mocks; } } - - /// - /// Creates a new mock with the default - /// specified at factory construction time. - /// - /// Type to mock. - /// A new . - /// - /// - /// var factory = new MockFactory(MockBehavior.Strict); - /// - /// var foo = factory.Create<IFoo>(); - /// // use mock on tests - /// - /// factory.VerifyAll(); - /// - /// - public Mock Create() - where T : class - { - return CreateMock(defaultBehavior, new object[0]); - } - - /// - /// Creates a new mock with the default - /// specified at factory construction time and with the - /// the given constructor arguments for the class. - /// - /// - /// The mock will try to find the best match constructor given the - /// constructor arguments, and invoke that to initialize the instance. - /// This applies only to classes, not interfaces. - /// - /// Type to mock. - /// Constructor arguments for mocked classes. - /// A new . - /// - /// - /// var factory = new MockFactory(MockBehavior.Default); - /// - /// var mock = factory.Create<MyBase>("Foo", 25, true); - /// // use mock on tests - /// - /// factory.Verify(); - /// - /// - public Mock Create(params object[] args) - where T : class - { - // "fix" compiler picking this overload instead of - // the one receiving the mock behavior. - if (args != null && args.Length > 0 && args[0] is MockBehavior) - { - return CreateMock((MockBehavior)args[0], args.Skip(1).ToArray()); - } - - return CreateMock(defaultBehavior, args); - } - - /// - /// Creates a new mock with the given . - /// - /// Type to mock. - /// Behavior to use for the mock, which overrides - /// the default behavior specified at factory construction time. - /// A new . - /// - /// The following example shows how to create a mock with a different - /// behavior to that specified as the default for the factory: - /// - /// var factory = new MockFactory(MockBehavior.Strict); - /// - /// var foo = factory.Create<IFoo>(MockBehavior.Loose); - /// - /// - public Mock Create(MockBehavior behavior) - where T : class - { - return CreateMock(behavior, new object[0]); - } - - /// - /// Creates a new mock with the given - /// and with the the given constructor arguments for the class. - /// - /// - /// The mock will try to find the best match constructor given the - /// constructor arguments, and invoke that to initialize the instance. - /// This applies only to classes, not interfaces. - /// - /// Type to mock. - /// Behavior to use for the mock, which overrides - /// the default behavior specified at factory construction time. - /// Constructor arguments for mocked classes. - /// A new . - /// - /// The following example shows how to create a mock with a different - /// behavior to that specified as the default for the factory, passing - /// constructor arguments: - /// - /// var factory = new MockFactory(MockBehavior.Default); - /// - /// var mock = factory.Create<MyBase>(MockBehavior.Strict, "Foo", 25, true); - /// - /// - public Mock Create(MockBehavior behavior, params object[] args) - where T : class - { - return CreateMock(behavior, args); - } - - /// - /// Implements creation of a new mock within the factory. - /// - /// Type to mock. - /// The behavior for the new mock. - /// Optional arguments for the construction of the mock. - protected virtual Mock CreateMock(MockBehavior behavior, object[] args) - where T : class - { - var mock = new Mock(behavior, args); - mocks.Add(mock); - - mock.CallBase = this.CallBase; - mock.DefaultValue = this.DefaultValue; - - return mock; - } - - /// - /// Verifies all verifiable expectations on all mocks created - /// by this factory. - /// - /// - /// One or more mocks had expectations that were not satisfied. - public virtual void Verify() - { - VerifyMocks(verifiable => verifiable.Verify()); - } - - /// - /// Verifies all verifiable expectations on all mocks created - /// by this factory. - /// - /// - /// One or more mocks had expectations that were not satisfied. - public virtual void VerifyAll() - { - VerifyMocks(verifiable => verifiable.VerifyAll()); - } - - /// - /// Invokes for each mock - /// in , and accumulates the resulting - /// that might be - /// thrown from the action. - /// - /// The action to execute against - /// each mock. - protected virtual void VerifyMocks(Action verifyAction) - { - Guard.NotNull(() => verifyAction, verifyAction); - - var message = new StringBuilder(); - - foreach (var mock in mocks) - { - try - { - verifyAction(mock); - } - catch (MockVerificationException mve) - { - message.AppendLine(mve.GetRawSetups()); - } - } - - if (message.ToString().Length > 0) - { - throw new MockException( - MockException.ExceptionReason.VerificationFailed, - string.Format(CultureInfo.CurrentCulture, Resources.VerficationFailed, message)); - } - } - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Moq.Properties; + +namespace Moq +{ + /// + /// Utility factory class to use to construct multiple + /// mocks when consistent verification is + /// desired for all of them. + /// + /// + /// If multiple mocks will be created during a test, passing + /// the desired (if different than the + /// or the one + /// passed to the factory constructor) and later verifying each + /// mock can become repetitive and tedious. + /// + /// This factory class helps in that scenario by providing a + /// simplified creation of multiple mocks with a default + /// (unless overriden by calling + /// ) and posterior verification. + /// + /// + /// + /// The following is a straightforward example on how to + /// create and automatically verify strict mocks using a : + /// + /// var factory = new MockFactory(MockBehavior.Strict); + /// + /// var foo = factory.Create<IFoo>(); + /// var bar = factory.Create<IBar>(); + /// + /// // no need to call Verifiable() on the setup + /// // as we'll be validating all of them anyway. + /// foo.Setup(f => f.Do()); + /// bar.Setup(b => b.Redo()); + /// + /// // exercise the mocks here + /// + /// factory.VerifyAll(); + /// // At this point all setups are already checked + /// // and an optional MockException might be thrown. + /// // Note also that because the mocks are strict, any invocation + /// // that doesn't have a matching setup will also throw a MockException. + /// + /// The following examples shows how to setup the factory + /// to create loose mocks and later verify only verifiable setups: + /// + /// var factory = new MockFactory(MockBehavior.Loose); + /// + /// var foo = factory.Create<IFoo>(); + /// var bar = factory.Create<IBar>(); + /// + /// // this setup will be verified when we verify the factory + /// foo.Setup(f => f.Do()).Verifiable(); + /// + /// // this setup will NOT be verified + /// foo.Setup(f => f.Calculate()); + /// + /// // this setup will be verified when we verify the factory + /// bar.Setup(b => b.Redo()).Verifiable(); + /// + /// // exercise the mocks here + /// // note that because the mocks are Loose, members + /// // called in the interfaces for which no matching + /// // setups exist will NOT throw exceptions, + /// // and will rather return default values. + /// + /// factory.Verify(); + /// // At this point verifiable setups are already checked + /// // and an optional MockException might be thrown. + /// + /// The following examples shows how to setup the factory with a + /// default strict behavior, overriding that default for a + /// specific mock: + /// + /// var factory = new MockFactory(MockBehavior.Strict); + /// + /// // this particular one we want loose + /// var foo = factory.Create<IFoo>(MockBehavior.Loose); + /// var bar = factory.Create<IBar>(); + /// + /// // specify setups + /// + /// // exercise the mocks here + /// + /// factory.Verify(); + /// + /// + /// + [Obsolete("This class has been renamed to MockRepository. MockFactory will be retired in v5.", false)] + public partial class MockFactory + { + List mocks = new List(); + MockBehavior defaultBehavior; + + /// + /// Initializes the factory with the given + /// for newly created mocks from the factory. + /// + /// The behavior to use for mocks created + /// using the factory method if not overriden + /// by using the overload. + public MockFactory(MockBehavior defaultBehavior) + { + this.defaultBehavior = defaultBehavior; + } + + /// + /// Whether the base member virtual implementation will be called + /// for mocked classes if no setup is matched. Defaults to . + /// + public bool CallBase { get; set; } + + /// + /// Specifies the behavior to use when returning default values for + /// unexpected invocations on loose mocks. + /// + public DefaultValue DefaultValue { get; set; } + + /// + /// Gets the mocks that have been created by this factory and + /// that will get verified together. + /// + protected internal IEnumerable Mocks { get { return mocks; } } + + /// + /// Creates a new mock with the default + /// specified at factory construction time. + /// + /// Type to mock. + /// A new . + /// + /// + /// var factory = new MockFactory(MockBehavior.Strict); + /// + /// var foo = factory.Create<IFoo>(); + /// // use mock on tests + /// + /// factory.VerifyAll(); + /// + /// + public Mock Create() + where T : class + { + return CreateMock(defaultBehavior, new object[0]); + } + + /// + /// Creates a new mock with the default + /// specified at factory construction time and with the + /// the given constructor arguments for the class. + /// + /// + /// The mock will try to find the best match constructor given the + /// constructor arguments, and invoke that to initialize the instance. + /// This applies only to classes, not interfaces. + /// + /// Type to mock. + /// Constructor arguments for mocked classes. + /// A new . + /// + /// + /// var factory = new MockFactory(MockBehavior.Default); + /// + /// var mock = factory.Create<MyBase>("Foo", 25, true); + /// // use mock on tests + /// + /// factory.Verify(); + /// + /// + public Mock Create(params object[] args) + where T : class + { + // "fix" compiler picking this overload instead of + // the one receiving the mock behavior. + if (args != null && args.Length > 0 && args[0] is MockBehavior) + { + return CreateMock((MockBehavior)args[0], args.Skip(1).ToArray()); + } + + return CreateMock(defaultBehavior, args); + } + + /// + /// Creates a new mock with the given . + /// + /// Type to mock. + /// Behavior to use for the mock, which overrides + /// the default behavior specified at factory construction time. + /// A new . + /// + /// The following example shows how to create a mock with a different + /// behavior to that specified as the default for the factory: + /// + /// var factory = new MockFactory(MockBehavior.Strict); + /// + /// var foo = factory.Create<IFoo>(MockBehavior.Loose); + /// + /// + public Mock Create(MockBehavior behavior) + where T : class + { + return CreateMock(behavior, new object[0]); + } + + /// + /// Creates a new mock with the given + /// and with the the given constructor arguments for the class. + /// + /// + /// The mock will try to find the best match constructor given the + /// constructor arguments, and invoke that to initialize the instance. + /// This applies only to classes, not interfaces. + /// + /// Type to mock. + /// Behavior to use for the mock, which overrides + /// the default behavior specified at factory construction time. + /// Constructor arguments for mocked classes. + /// A new . + /// + /// The following example shows how to create a mock with a different + /// behavior to that specified as the default for the factory, passing + /// constructor arguments: + /// + /// var factory = new MockFactory(MockBehavior.Default); + /// + /// var mock = factory.Create<MyBase>(MockBehavior.Strict, "Foo", 25, true); + /// + /// + public Mock Create(MockBehavior behavior, params object[] args) + where T : class + { + return CreateMock(behavior, args); + } + + /// + /// Implements creation of a new mock within the factory. + /// + /// Type to mock. + /// The behavior for the new mock. + /// Optional arguments for the construction of the mock. + protected virtual Mock CreateMock(MockBehavior behavior, object[] args) + where T : class + { + var mock = new Mock(behavior, args); + mocks.Add(mock); + + mock.CallBase = this.CallBase; + mock.DefaultValue = this.DefaultValue; + + return mock; + } + + /// + /// Verifies all verifiable expectations on all mocks created + /// by this factory. + /// + /// + /// One or more mocks had expectations that were not satisfied. + public virtual void Verify() + { + VerifyMocks(verifiable => verifiable.Verify()); + } + + /// + /// Verifies all verifiable expectations on all mocks created + /// by this factory. + /// + /// + /// One or more mocks had expectations that were not satisfied. + public virtual void VerifyAll() + { + VerifyMocks(verifiable => verifiable.VerifyAll()); + } + + /// + /// Invokes for each mock + /// in , and accumulates the resulting + /// that might be + /// thrown from the action. + /// + /// The action to execute against + /// each mock. + protected virtual void VerifyMocks(Action verifyAction) + { + Guard.NotNull(() => verifyAction, verifyAction); + + var message = new StringBuilder(); + + foreach (var mock in mocks) + { + try + { + verifyAction(mock); + } + catch (MockVerificationException mve) + { + message.AppendLine(mve.GetRawSetups()); + } + } + + if (message.ToString().Length > 0) + { + throw new MockException( + MockException.ExceptionReason.VerificationFailed, + string.Format(CultureInfo.CurrentCulture, Resources.VerficationFailed, message)); + } + } + } } \ No newline at end of file diff --git a/Source/PexProtector.cs b/Source/PexProtector.cs index 2ab53436b..cc2414918 100644 --- a/Source/PexProtector.cs +++ b/Source/PexProtector.cs @@ -1,64 +1,64 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Diagnostics; - -internal sealed class __ProtectAttribute : Attribute -{ -} - -namespace Moq -{ - [__Protect] - [DebuggerStepThrough] - internal static class PexProtector - { - public static void Invoke(Action action) - { - action(); - } - - public static T Invoke(Func function) - { - return function(); - } - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Diagnostics; + +internal sealed class __ProtectAttribute : Attribute +{ +} + +namespace Moq +{ + [__Protect] + [DebuggerStepThrough] + internal static class PexProtector + { + public static void Invoke(Action action) + { + action(); + } + + public static T Invoke(Func function) + { + return function(); + } + } } \ No newline at end of file diff --git a/Source/Protected/IProtectedMock.cs b/Source/Protected/IProtectedMock.cs index 428547926..6449435f4 100644 --- a/Source/Protected/IProtectedMock.cs +++ b/Source/Protected/IProtectedMock.cs @@ -1,154 +1,154 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System.Diagnostics.CodeAnalysis; -using Moq.Language.Flow; - -namespace Moq.Protected -{ - /// - /// Allows setups to be specified for protected members by using their - /// name as a string, rather than strong-typing them which is not possible - /// due to their visibility. - /// - public interface IProtectedMock : IHideObjectMembers - where TMock : class - { - #region Setup - - /// - /// Specifies a setup for a void method invocation with the given - /// , optionally specifying arguments for the method call. - /// - /// The name of the void method to be invoked. - /// The optional arguments for the invocation. If argument matchers are used, - /// remember to use rather than . - ISetup Setup(string voidMethodName, params object[] args); - - /// - /// Specifies a setup for an invocation on a property or a non void method with the given - /// , optionally specifying arguments for the method call. - /// - /// The name of the method or property to be invoked. - /// The optional arguments for the invocation. If argument matchers are used, - /// remember to use rather than . - /// The return type of the method or property. - ISetup Setup(string methodOrPropertyName, params object[] args); - - /// - /// Specifies a setup for an invocation on a property getter with the given - /// . - /// - /// The name of the property. - /// The type of the property. - ISetupGetter SetupGet(string propertyName); - - /// - /// Specifies a setup for an invocation on a property setter with the given - /// . - /// - /// The name of the property. - /// The property value. If argument matchers are used, - /// remember to use rather than . - /// The type of the property. - ISetupSetter SetupSet(string propertyName, object value); - - #endregion - - #region Verify - - /// - /// Specifies a verify for a void method with the given , - /// optionally specifying arguments for the method call. Use in conjuntion with the default - /// . - /// - /// The invocation was not call the times specified by - /// . - /// The name of the void method to be verified. - /// The number of times a method is allowed to be called. - /// The optional arguments for the invocation. If argument matchers are used, - /// remember to use rather than . - void Verify(string methodName, Times times, params object[] args); - - /// - /// Specifies a verify for an invocation on a property or a non void method with the given - /// , optionally specifying arguments for the method call. - /// - /// The invocation was not call the times specified by - /// . - /// The name of the method or property to be invoked. - /// The optional arguments for the invocation. If argument matchers are used, - /// remember to use rather than . - /// The number of times a method is allowed to be called. - /// The type of return value from the expression. - [SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")] - void Verify(string methodName, Times times, params object[] args); - - /// - /// Specifies a verify for an invocation on a property getter with the given - /// . - /// The invocation was not call the times specified by - /// . - /// - /// The name of the property. - /// The number of times a method is allowed to be called. - /// The type of the property. - // TODO should receive args to support indexers - [SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")] - void VerifyGet(string propertyName, Times times); - - /// - /// Specifies a setup for an invocation on a property setter with the given - /// . - /// - /// The invocation was not call the times specified by - /// . - /// The name of the property. - /// The number of times a method is allowed to be called. - /// The property value. - /// The type of the property. If argument matchers are used, - /// remember to use rather than . - // TODO should receive args to support indexers - [SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")] - void VerifySet(string propertyName, Times times, object value); - - #endregion - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System.Diagnostics.CodeAnalysis; +using Moq.Language.Flow; + +namespace Moq.Protected +{ + /// + /// Allows setups to be specified for protected members by using their + /// name as a string, rather than strong-typing them which is not possible + /// due to their visibility. + /// + public interface IProtectedMock : IHideObjectMembers + where TMock : class + { + #region Setup + + /// + /// Specifies a setup for a void method invocation with the given + /// , optionally specifying arguments for the method call. + /// + /// The name of the void method to be invoked. + /// The optional arguments for the invocation. If argument matchers are used, + /// remember to use rather than . + ISetup Setup(string voidMethodName, params object[] args); + + /// + /// Specifies a setup for an invocation on a property or a non void method with the given + /// , optionally specifying arguments for the method call. + /// + /// The name of the method or property to be invoked. + /// The optional arguments for the invocation. If argument matchers are used, + /// remember to use rather than . + /// The return type of the method or property. + ISetup Setup(string methodOrPropertyName, params object[] args); + + /// + /// Specifies a setup for an invocation on a property getter with the given + /// . + /// + /// The name of the property. + /// The type of the property. + ISetupGetter SetupGet(string propertyName); + + /// + /// Specifies a setup for an invocation on a property setter with the given + /// . + /// + /// The name of the property. + /// The property value. If argument matchers are used, + /// remember to use rather than . + /// The type of the property. + ISetupSetter SetupSet(string propertyName, object value); + + #endregion + + #region Verify + + /// + /// Specifies a verify for a void method with the given , + /// optionally specifying arguments for the method call. Use in conjuntion with the default + /// . + /// + /// The invocation was not call the times specified by + /// . + /// The name of the void method to be verified. + /// The number of times a method is allowed to be called. + /// The optional arguments for the invocation. If argument matchers are used, + /// remember to use rather than . + void Verify(string methodName, Times times, params object[] args); + + /// + /// Specifies a verify for an invocation on a property or a non void method with the given + /// , optionally specifying arguments for the method call. + /// + /// The invocation was not call the times specified by + /// . + /// The name of the method or property to be invoked. + /// The optional arguments for the invocation. If argument matchers are used, + /// remember to use rather than . + /// The number of times a method is allowed to be called. + /// The type of return value from the expression. + [SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")] + void Verify(string methodName, Times times, params object[] args); + + /// + /// Specifies a verify for an invocation on a property getter with the given + /// . + /// The invocation was not call the times specified by + /// . + /// + /// The name of the property. + /// The number of times a method is allowed to be called. + /// The type of the property. + // TODO should receive args to support indexers + [SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")] + void VerifyGet(string propertyName, Times times); + + /// + /// Specifies a setup for an invocation on a property setter with the given + /// . + /// + /// The invocation was not call the times specified by + /// . + /// The name of the property. + /// The number of times a method is allowed to be called. + /// The property value. + /// The type of the property. If argument matchers are used, + /// remember to use rather than . + // TODO should receive args to support indexers + [SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")] + void VerifySet(string propertyName, Times times, object value); + + #endregion + } } \ No newline at end of file diff --git a/Source/Protected/ItExpr.cs b/Source/Protected/ItExpr.cs index 4eb612be9..fc844c50a 100644 --- a/Source/Protected/ItExpr.cs +++ b/Source/Protected/ItExpr.cs @@ -1,214 +1,214 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Diagnostics.CodeAnalysis; -using System.Linq.Expressions; -using System.Text.RegularExpressions; -using Moq.Matchers; - -namespace Moq.Protected -{ - /// - /// Allows the specification of a matching condition for an - /// argument in a protected member setup, rather than a specific - /// argument value. "ItExpr" refers to the argument being matched. - /// - /// - /// Use this variant of argument matching instead of - /// for protected setups. - /// This class allows the setup to match a method invocation - /// with an arbitrary value, with a value in a specified range, or - /// even one that matches a given predicate, or null. - /// - [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Expr")] - public static class ItExpr - { - /// - /// Matches a null value of the given type. - /// - /// - /// Required for protected mocks as the null value cannot be used - /// directly as it prevents proper method overload selection. - /// - /// - /// - /// // Throws an exception for a call to Remove with a null string value. - /// mock.Protected() - /// .Setup("Remove", ItExpr.IsNull<string>()) - /// .Throws(new InvalidOperationException()); - /// - /// - /// Type of the value. - [SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")] - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] - public static Expression IsNull() - { - Expression> expr = () => It.Is(v => Object.Equals(v, default(TValue))); - - return expr.Body; - } - - /// - /// Matches any value of the given type. - /// - /// - /// Typically used when the actual argument value for a method - /// call is not relevant. - /// - /// - /// - /// // Throws an exception for a call to Remove with any string value. - /// mock.Protected() - /// .Setup("Remove", ItExpr.IsAny<string>()) - /// .Throws(new InvalidOperationException()); - /// - /// - /// Type of the value. - [SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")] - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] - public static Expression IsAny() - { - Expression> expr = () => It.IsAny(); - return expr.Body; - } - - /// - /// Matches any value that satisfies the given predicate. - /// - /// Type of the argument to check. - /// The predicate used to match the method argument. - /// - /// Allows the specification of a predicate to perform matching - /// of method call arguments. - /// - /// - /// This example shows how to return the value 1 whenever the argument to the - /// Do method is an even number. - /// - /// mock.Protected() - /// .Setup("Do", ItExpr.Is<int>(i => i % 2 == 0)) - /// .Returns(1); - /// - /// This example shows how to throw an exception if the argument to the - /// method is a negative number: - /// - /// mock.Protected() - /// .Setup("GetUser", ItExpr.Is<int>(i => i < 0)) - /// .Throws(new ArgumentException()); - /// - /// - [AdvancedMatcher(typeof(PredicateMatcher))] - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] - public static Expression Is(Expression> match) - { - return Expression.Call(null, - typeof(It).GetMethod("Is").MakeGenericMethod(typeof(TValue)), - match); - } - - /// - /// Matches any value that is in the range specified. - /// - /// Type of the argument to check. - /// The lower bound of the range. - /// The upper bound of the range. - /// The kind of range. See . - /// - /// The following example shows how to expect a method call - /// with an integer argument within the 0..100 range. - /// - /// mock.Protected() - /// .Setup("HasInventory", - /// ItExpr.IsAny<string>(), - /// ItExpr.IsInRange(0, 100, Range.Inclusive)) - /// .Returns(false); - /// - /// - public static Expression IsInRange(TValue from, TValue to, Range rangeKind) - where TValue : IComparable - { - Expression> expr = () => It.IsInRange(from, to, rangeKind); - - return expr.Body; - } - - /// - /// Matches a string argument if it matches the given regular expression pattern. - /// - /// The pattern to use to match the string argument value. - /// - /// The following example shows how to expect a call to a method where the - /// string argument matches the given regular expression: - /// - /// mock.Protected() - /// .Setup("Check", ItExpr.IsRegex("[a-z]+")) - /// .Returns(1); - /// - /// - public static Expression IsRegex(string regex) - { - Expression> expr = () => It.IsRegex(regex); - - return expr.Body; - } - - /// - /// Matches a string argument if it matches the given regular expression pattern. - /// - /// The pattern to use to match the string argument value. - /// The options used to interpret the pattern. - /// - /// The following example shows how to expect a call to a method where the - /// string argument matches the given regular expression, in a case insensitive way: - /// - /// mock.Protected() - /// .Setup("Check", ItExpr.IsRegex("[a-z]+", RegexOptions.IgnoreCase)) - /// .Returns(1); - /// - /// - public static Expression IsRegex(string regex, RegexOptions options) - { - Expression> expr = () => It.IsRegex(regex, options); - - return expr.Body; - } - } -} +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Diagnostics.CodeAnalysis; +using System.Linq.Expressions; +using System.Text.RegularExpressions; +using Moq.Matchers; + +namespace Moq.Protected +{ + /// + /// Allows the specification of a matching condition for an + /// argument in a protected member setup, rather than a specific + /// argument value. "ItExpr" refers to the argument being matched. + /// + /// + /// Use this variant of argument matching instead of + /// for protected setups. + /// This class allows the setup to match a method invocation + /// with an arbitrary value, with a value in a specified range, or + /// even one that matches a given predicate, or null. + /// + [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Expr")] + public static class ItExpr + { + /// + /// Matches a null value of the given type. + /// + /// + /// Required for protected mocks as the null value cannot be used + /// directly as it prevents proper method overload selection. + /// + /// + /// + /// // Throws an exception for a call to Remove with a null string value. + /// mock.Protected() + /// .Setup("Remove", ItExpr.IsNull<string>()) + /// .Throws(new InvalidOperationException()); + /// + /// + /// Type of the value. + [SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")] + [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] + public static Expression IsNull() + { + Expression> expr = () => It.Is(v => Object.Equals(v, default(TValue))); + + return expr.Body; + } + + /// + /// Matches any value of the given type. + /// + /// + /// Typically used when the actual argument value for a method + /// call is not relevant. + /// + /// + /// + /// // Throws an exception for a call to Remove with any string value. + /// mock.Protected() + /// .Setup("Remove", ItExpr.IsAny<string>()) + /// .Throws(new InvalidOperationException()); + /// + /// + /// Type of the value. + [SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")] + [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] + public static Expression IsAny() + { + Expression> expr = () => It.IsAny(); + return expr.Body; + } + + /// + /// Matches any value that satisfies the given predicate. + /// + /// Type of the argument to check. + /// The predicate used to match the method argument. + /// + /// Allows the specification of a predicate to perform matching + /// of method call arguments. + /// + /// + /// This example shows how to return the value 1 whenever the argument to the + /// Do method is an even number. + /// + /// mock.Protected() + /// .Setup("Do", ItExpr.Is<int>(i => i % 2 == 0)) + /// .Returns(1); + /// + /// This example shows how to throw an exception if the argument to the + /// method is a negative number: + /// + /// mock.Protected() + /// .Setup("GetUser", ItExpr.Is<int>(i => i < 0)) + /// .Throws(new ArgumentException()); + /// + /// + [AdvancedMatcher(typeof(PredicateMatcher))] + [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] + public static Expression Is(Expression> match) + { + return Expression.Call(null, + typeof(It).GetMethod("Is").MakeGenericMethod(typeof(TValue)), + match); + } + + /// + /// Matches any value that is in the range specified. + /// + /// Type of the argument to check. + /// The lower bound of the range. + /// The upper bound of the range. + /// The kind of range. See . + /// + /// The following example shows how to expect a method call + /// with an integer argument within the 0..100 range. + /// + /// mock.Protected() + /// .Setup("HasInventory", + /// ItExpr.IsAny<string>(), + /// ItExpr.IsInRange(0, 100, Range.Inclusive)) + /// .Returns(false); + /// + /// + public static Expression IsInRange(TValue from, TValue to, Range rangeKind) + where TValue : IComparable + { + Expression> expr = () => It.IsInRange(from, to, rangeKind); + + return expr.Body; + } + + /// + /// Matches a string argument if it matches the given regular expression pattern. + /// + /// The pattern to use to match the string argument value. + /// + /// The following example shows how to expect a call to a method where the + /// string argument matches the given regular expression: + /// + /// mock.Protected() + /// .Setup("Check", ItExpr.IsRegex("[a-z]+")) + /// .Returns(1); + /// + /// + public static Expression IsRegex(string regex) + { + Expression> expr = () => It.IsRegex(regex); + + return expr.Body; + } + + /// + /// Matches a string argument if it matches the given regular expression pattern. + /// + /// The pattern to use to match the string argument value. + /// The options used to interpret the pattern. + /// + /// The following example shows how to expect a call to a method where the + /// string argument matches the given regular expression, in a case insensitive way: + /// + /// mock.Protected() + /// .Setup("Check", ItExpr.IsRegex("[a-z]+", RegexOptions.IgnoreCase)) + /// .Returns(1); + /// + /// + public static Expression IsRegex(string regex, RegexOptions options) + { + Expression> expr = () => It.IsRegex(regex, options); + + return expr.Body; + } + } +} diff --git a/Source/Protected/ProtectedExtension.cs b/Source/Protected/ProtectedExtension.cs index 388d5b55a..69706e7a5 100644 --- a/Source/Protected/ProtectedExtension.cs +++ b/Source/Protected/ProtectedExtension.cs @@ -1,65 +1,65 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - - -namespace Moq.Protected -{ - /// - /// Enables the Protected() method on , - /// allowing setups to be set for protected members by using their - /// name as a string, rather than strong-typing them which is not possible - /// due to their visibility. - /// - public static class ProtectedExtension - { - /// - /// Enable protected setups for the mock. - /// - /// Mocked object type. Typically omitted as it can be inferred from the mock instance. - /// The mock to set the protected setups on. - public static IProtectedMock Protected(this Mock mock) - where T : class - { - Guard.NotNull(() => mock, mock); - - return new ProtectedMock(mock); - } - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + + +namespace Moq.Protected +{ + /// + /// Enables the Protected() method on , + /// allowing setups to be set for protected members by using their + /// name as a string, rather than strong-typing them which is not possible + /// due to their visibility. + /// + public static class ProtectedExtension + { + /// + /// Enable protected setups for the mock. + /// + /// Mocked object type. Typically omitted as it can be inferred from the mock instance. + /// The mock to set the protected setups on. + public static IProtectedMock Protected(this Mock mock) + where T : class + { + Guard.NotNull(() => mock, mock); + + return new ProtectedMock(mock); + } + } } \ No newline at end of file diff --git a/Source/Protected/ProtectedMock.cs b/Source/Protected/ProtectedMock.cs index f1dce50d2..37b4b3fd6 100644 --- a/Source/Protected/ProtectedMock.cs +++ b/Source/Protected/ProtectedMock.cs @@ -1,378 +1,378 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Linq.Expressions; -using System.Reflection; -using Moq.Language.Flow; -using Moq.Properties; - -namespace Moq.Protected -{ - internal class ProtectedMock : IProtectedMock - where T : class - { - private Mock mock; - - public ProtectedMock(Mock mock) - { - this.mock = mock; - } - - #region Setup - - public ISetup Setup(string methodName, params object[] args) - { - Guard.NotNullOrEmpty(() => methodName, methodName); - - var method = GetMethod(methodName, args); - ThrowIfMemberMissing(methodName, method); - ThrowIfPublicMethod(method); - - return Mock.Setup(mock, GetMethodCall(method, args), null); - } - - public ISetup Setup(string methodName, params object[] args) - { - Guard.NotNullOrEmpty(() => methodName, methodName); - - var property = GetProperty(methodName); - if (property != null) - { - ThrowIfPublicGetter(property); - // TODO should consider property indexers - return Mock.SetupGet(mock, GetMemberAccess(property), null); - } - - var method = GetMethod(methodName, args); - ThrowIfMemberMissing(methodName, method); - ThrowIfVoidMethod(method); - ThrowIfPublicMethod(method); - - return Mock.Setup(mock, GetMethodCall(method, args), null); - } - - public ISetupGetter SetupGet(string propertyName) - { - Guard.NotNullOrEmpty(() => propertyName, propertyName); - - var property = GetProperty(propertyName); - ThrowIfMemberMissing(propertyName, property); - ThrowIfPublicGetter(property); - property.ThrowIfNoGetter(); - - return Mock.SetupGet(mock, GetMemberAccess(property), null); - } - - public ISetupSetter SetupSet(string propertyName, object value) - { - Guard.NotNullOrEmpty(() => propertyName, propertyName); - - var property = GetProperty(propertyName); - ThrowIfMemberMissing(propertyName, property); - ThrowIfPublicSetter(property); - property.ThrowIfNoSetter(); - - return Mock.SetupSet(mock, GetSetterExpression(property, ItExpr.IsAny()), null); - } - - #endregion - - #region Verify - - public void Verify(string methodName, Times times, object[] args) - { - Guard.NotNullOrEmpty(() => methodName, methodName); - - var method = GetMethod(methodName, args); - ThrowIfMemberMissing(methodName, method); - ThrowIfPublicMethod(method); - - Mock.Verify(mock, GetMethodCall(method, args), times, null); - } - - public void Verify(string methodName, Times times, object[] args) - { - Guard.NotNullOrEmpty(() => methodName, methodName); - - var property = GetProperty(methodName); - if (property != null) - { - ThrowIfPublicGetter(property); - // TODO should consider property indexers - Mock.VerifyGet(mock, GetMemberAccess(property), times, null); - return; - } - - var method = GetMethod(methodName, args); - ThrowIfMemberMissing(methodName, method); - ThrowIfPublicMethod(method); - - Mock.Verify(mock, GetMethodCall(method, args), times, null); - } - - // TODO should receive args to support indexers - public void VerifyGet(string propertyName, Times times) - { - Guard.NotNullOrEmpty(() => propertyName, propertyName); - - var property = GetProperty(propertyName); - ThrowIfMemberMissing(propertyName, property); - ThrowIfPublicGetter(property); - property.ThrowIfNoGetter(); - - // TODO should consider property indexers - Mock.VerifyGet(mock, GetMemberAccess(property), times, null); - } - - // TODO should receive args to support indexers - public void VerifySet(string propertyName, Times times, object value) - { - Guard.NotNullOrEmpty(() => propertyName, propertyName); - - var property = GetProperty(propertyName); - ThrowIfMemberMissing(propertyName, property); - ThrowIfPublicSetter(property); - property.ThrowIfNoSetter(); - - // TODO should consider property indexers - // TODO should receive the parameter here - Mock.VerifySet(mock, GetSetterExpression(property, ItExpr.IsAny()), times, null); - } - - #endregion - - private static Expression> GetMemberAccess(PropertyInfo property) - { - var param = Expression.Parameter(typeof(T), "mock"); - return Expression.Lambda>(Expression.MakeMemberAccess(param, property), param); - } - - private static MethodInfo GetMethod(string methodName, params object[] args) - { - return typeof(T).GetMethod( - methodName, - BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, - null, - ToArgTypes(args), - null); - } - - private static Expression> GetMethodCall(MethodInfo method, object[] args) - { - var param = Expression.Parameter(typeof(T), "mock"); - return Expression.Lambda>(Expression.Call(param, method, ToExpressionArgs(args)), param); - } - - private static Expression> GetMethodCall(MethodInfo method, object[] args) - { - var param = Expression.Parameter(typeof(T), "mock"); - return Expression.Lambda>(Expression.Call(param, method, ToExpressionArgs(args)), param); - } - - // TODO should support arguments for property indexers - private static PropertyInfo GetProperty(string propertyName) - { - return typeof(T).GetProperty( - propertyName, - BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); - } - - private static Action GetSetterExpression(PropertyInfo property, Expression value) - { - var param = Expression.Parameter(typeof(T), "mock"); - - return Expression.Lambda>( - Expression.Call(param, property.GetSetMethod(true), value), - param).Compile(); - } - - private static void ThrowIfNonVirtual(MethodInfo method) - { - if (method.IsAssembly || method.IsFamilyAndAssembly) - { - throw new ArgumentException(string.Format( - CultureInfo.CurrentCulture, - Resources.VerifyOnNonVirtualMember, - method.ReflectedType.Name + "." + method.Name)); - } - } - - private static void ThrowIfMemberMissing(string memberName, MemberInfo member) - { - if (member == null) - { - throw new ArgumentException(string.Format( - CultureInfo.CurrentCulture, - Resources.MemberMissing, - typeof(T).Name, - memberName)); - } - } - - private static void ThrowIfPublicMethod(MethodInfo method) - { - if (method.IsPublic) - { - throw new ArgumentException(string.Format( - CultureInfo.CurrentCulture, - Resources.MethodIsPublic, - method.ReflectedType.Name, - method.Name)); - } - } - - private static void ThrowIfPublicGetter(PropertyInfo property) - { - if (property.CanRead && property.GetGetMethod() != null) - { - throw new ArgumentException(string.Format( - CultureInfo.CurrentCulture, - Resources.UnexpectedPublicProperty, - property.ReflectedType.Name, - property.Name)); - } - } - - private static void ThrowIfPublicSetter(PropertyInfo property) - { - if (property.CanWrite && property.GetSetMethod() != null) - { - throw new ArgumentException(string.Format( - CultureInfo.CurrentCulture, - Resources.UnexpectedPublicProperty, - property.ReflectedType.Name, - property.Name)); - } - } - - private static void ThrowIfVoidMethod(MethodInfo method) - { - if (method.ReturnType == typeof(void)) - { - throw new ArgumentException(Resources.CantSetReturnValueForVoid); - } - } - - private static Type[] ToArgTypes(object[] args) - { - if (args == null) - { - throw new ArgumentException("Use ItExpr.IsNull rather than a null argument value, as it prevents proper method lookup."); - } - - var types = new Type[args.Length]; - for (int index = 0; index < args.Length; index++) - { - if (args[index] == null) - { - throw new ArgumentException("Use ItExpr.IsNull rather than a null argument value, as it prevents proper method lookup."); - } - - var expr = args[index] as Expression; - if (expr == null) - { - types[index] = args[index].GetType(); - } - else if (expr.NodeType == ExpressionType.Call) - { - types[index] = ((MethodCallExpression)expr).Method.ReturnType; - } - else if (expr.NodeType == ExpressionType.MemberAccess) - { - var member = (MemberExpression)expr; - switch (member.Member.MemberType) - { - case MemberTypes.Field: - types[index] = ((FieldInfo)member.Member).FieldType; - break; - case MemberTypes.Property: - types[index] = ((PropertyInfo)member.Member).PropertyType; - break; - default: - throw new NotSupportedException(string.Format( - Resources.Culture, - Resources.UnsupportedMember, - member.Member.Name)); - } - } - else - { - var evalExpr = expr.PartialEval(); - if (evalExpr.NodeType == ExpressionType.Constant) - { - types[index] = ((ConstantExpression)evalExpr).Type; - } - else - { - types[index] = null; - } - } - } - - return types; - } - - private static Expression ToExpressionArg(object arg) - { - var lambda = arg as LambdaExpression; - if (lambda != null) - { - return lambda.Body; - } - - var expression = arg as Expression; - if (expression != null) - { - return expression; - } - - return Expression.Constant(arg); - } - - private static IEnumerable ToExpressionArgs(object[] args) - { - return args.Select(arg => ToExpressionArg(arg)); - } - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using Moq.Language.Flow; +using Moq.Properties; + +namespace Moq.Protected +{ + internal class ProtectedMock : IProtectedMock + where T : class + { + private Mock mock; + + public ProtectedMock(Mock mock) + { + this.mock = mock; + } + + #region Setup + + public ISetup Setup(string methodName, params object[] args) + { + Guard.NotNullOrEmpty(() => methodName, methodName); + + var method = GetMethod(methodName, args); + ThrowIfMemberMissing(methodName, method); + ThrowIfPublicMethod(method); + + return Mock.Setup(mock, GetMethodCall(method, args), null); + } + + public ISetup Setup(string methodName, params object[] args) + { + Guard.NotNullOrEmpty(() => methodName, methodName); + + var property = GetProperty(methodName); + if (property != null) + { + ThrowIfPublicGetter(property); + // TODO should consider property indexers + return Mock.SetupGet(mock, GetMemberAccess(property), null); + } + + var method = GetMethod(methodName, args); + ThrowIfMemberMissing(methodName, method); + ThrowIfVoidMethod(method); + ThrowIfPublicMethod(method); + + return Mock.Setup(mock, GetMethodCall(method, args), null); + } + + public ISetupGetter SetupGet(string propertyName) + { + Guard.NotNullOrEmpty(() => propertyName, propertyName); + + var property = GetProperty(propertyName); + ThrowIfMemberMissing(propertyName, property); + ThrowIfPublicGetter(property); + property.ThrowIfNoGetter(); + + return Mock.SetupGet(mock, GetMemberAccess(property), null); + } + + public ISetupSetter SetupSet(string propertyName, object value) + { + Guard.NotNullOrEmpty(() => propertyName, propertyName); + + var property = GetProperty(propertyName); + ThrowIfMemberMissing(propertyName, property); + ThrowIfPublicSetter(property); + property.ThrowIfNoSetter(); + + return Mock.SetupSet(mock, GetSetterExpression(property, ItExpr.IsAny()), null); + } + + #endregion + + #region Verify + + public void Verify(string methodName, Times times, object[] args) + { + Guard.NotNullOrEmpty(() => methodName, methodName); + + var method = GetMethod(methodName, args); + ThrowIfMemberMissing(methodName, method); + ThrowIfPublicMethod(method); + + Mock.Verify(mock, GetMethodCall(method, args), times, null); + } + + public void Verify(string methodName, Times times, object[] args) + { + Guard.NotNullOrEmpty(() => methodName, methodName); + + var property = GetProperty(methodName); + if (property != null) + { + ThrowIfPublicGetter(property); + // TODO should consider property indexers + Mock.VerifyGet(mock, GetMemberAccess(property), times, null); + return; + } + + var method = GetMethod(methodName, args); + ThrowIfMemberMissing(methodName, method); + ThrowIfPublicMethod(method); + + Mock.Verify(mock, GetMethodCall(method, args), times, null); + } + + // TODO should receive args to support indexers + public void VerifyGet(string propertyName, Times times) + { + Guard.NotNullOrEmpty(() => propertyName, propertyName); + + var property = GetProperty(propertyName); + ThrowIfMemberMissing(propertyName, property); + ThrowIfPublicGetter(property); + property.ThrowIfNoGetter(); + + // TODO should consider property indexers + Mock.VerifyGet(mock, GetMemberAccess(property), times, null); + } + + // TODO should receive args to support indexers + public void VerifySet(string propertyName, Times times, object value) + { + Guard.NotNullOrEmpty(() => propertyName, propertyName); + + var property = GetProperty(propertyName); + ThrowIfMemberMissing(propertyName, property); + ThrowIfPublicSetter(property); + property.ThrowIfNoSetter(); + + // TODO should consider property indexers + // TODO should receive the parameter here + Mock.VerifySet(mock, GetSetterExpression(property, ItExpr.IsAny()), times, null); + } + + #endregion + + private static Expression> GetMemberAccess(PropertyInfo property) + { + var param = Expression.Parameter(typeof(T), "mock"); + return Expression.Lambda>(Expression.MakeMemberAccess(param, property), param); + } + + private static MethodInfo GetMethod(string methodName, params object[] args) + { + return typeof(T).GetMethod( + methodName, + BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, + null, + ToArgTypes(args), + null); + } + + private static Expression> GetMethodCall(MethodInfo method, object[] args) + { + var param = Expression.Parameter(typeof(T), "mock"); + return Expression.Lambda>(Expression.Call(param, method, ToExpressionArgs(args)), param); + } + + private static Expression> GetMethodCall(MethodInfo method, object[] args) + { + var param = Expression.Parameter(typeof(T), "mock"); + return Expression.Lambda>(Expression.Call(param, method, ToExpressionArgs(args)), param); + } + + // TODO should support arguments for property indexers + private static PropertyInfo GetProperty(string propertyName) + { + return typeof(T).GetProperty( + propertyName, + BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); + } + + private static Action GetSetterExpression(PropertyInfo property, Expression value) + { + var param = Expression.Parameter(typeof(T), "mock"); + + return Expression.Lambda>( + Expression.Call(param, property.GetSetMethod(true), value), + param).Compile(); + } + + private static void ThrowIfNonVirtual(MethodInfo method) + { + if (method.IsAssembly || method.IsFamilyAndAssembly) + { + throw new ArgumentException(string.Format( + CultureInfo.CurrentCulture, + Resources.VerifyOnNonVirtualMember, + method.ReflectedType.Name + "." + method.Name)); + } + } + + private static void ThrowIfMemberMissing(string memberName, MemberInfo member) + { + if (member == null) + { + throw new ArgumentException(string.Format( + CultureInfo.CurrentCulture, + Resources.MemberMissing, + typeof(T).Name, + memberName)); + } + } + + private static void ThrowIfPublicMethod(MethodInfo method) + { + if (method.IsPublic) + { + throw new ArgumentException(string.Format( + CultureInfo.CurrentCulture, + Resources.MethodIsPublic, + method.ReflectedType.Name, + method.Name)); + } + } + + private static void ThrowIfPublicGetter(PropertyInfo property) + { + if (property.CanRead && property.GetGetMethod() != null) + { + throw new ArgumentException(string.Format( + CultureInfo.CurrentCulture, + Resources.UnexpectedPublicProperty, + property.ReflectedType.Name, + property.Name)); + } + } + + private static void ThrowIfPublicSetter(PropertyInfo property) + { + if (property.CanWrite && property.GetSetMethod() != null) + { + throw new ArgumentException(string.Format( + CultureInfo.CurrentCulture, + Resources.UnexpectedPublicProperty, + property.ReflectedType.Name, + property.Name)); + } + } + + private static void ThrowIfVoidMethod(MethodInfo method) + { + if (method.ReturnType == typeof(void)) + { + throw new ArgumentException(Resources.CantSetReturnValueForVoid); + } + } + + private static Type[] ToArgTypes(object[] args) + { + if (args == null) + { + throw new ArgumentException("Use ItExpr.IsNull rather than a null argument value, as it prevents proper method lookup."); + } + + var types = new Type[args.Length]; + for (int index = 0; index < args.Length; index++) + { + if (args[index] == null) + { + throw new ArgumentException("Use ItExpr.IsNull rather than a null argument value, as it prevents proper method lookup."); + } + + var expr = args[index] as Expression; + if (expr == null) + { + types[index] = args[index].GetType(); + } + else if (expr.NodeType == ExpressionType.Call) + { + types[index] = ((MethodCallExpression)expr).Method.ReturnType; + } + else if (expr.NodeType == ExpressionType.MemberAccess) + { + var member = (MemberExpression)expr; + switch (member.Member.MemberType) + { + case MemberTypes.Field: + types[index] = ((FieldInfo)member.Member).FieldType; + break; + case MemberTypes.Property: + types[index] = ((PropertyInfo)member.Member).PropertyType; + break; + default: + throw new NotSupportedException(string.Format( + Resources.Culture, + Resources.UnsupportedMember, + member.Member.Name)); + } + } + else + { + var evalExpr = expr.PartialEval(); + if (evalExpr.NodeType == ExpressionType.Constant) + { + types[index] = ((ConstantExpression)evalExpr).Type; + } + else + { + types[index] = null; + } + } + } + + return types; + } + + private static Expression ToExpressionArg(object arg) + { + var lambda = arg as LambdaExpression; + if (lambda != null) + { + return lambda.Body; + } + + var expression = arg as Expression; + if (expression != null) + { + return expression; + } + + return Expression.Constant(arg); + } + + private static IEnumerable ToExpressionArgs(object[] args) + { + return args.Select(arg => ToExpressionArg(arg)); + } + } } \ No newline at end of file diff --git a/Source/Proxy/ICallContext.cs b/Source/Proxy/ICallContext.cs index fbfbdbf3e..70e5b9a59 100644 --- a/Source/Proxy/ICallContext.cs +++ b/Source/Proxy/ICallContext.cs @@ -1,58 +1,58 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Reflection; - -namespace Moq.Proxy -{ - internal interface ICallContext - { - object[] Arguments { get; } - - MethodInfo Method { get; } - - object ReturnValue { get; set; } - - void InvokeBase(); - - void SetArgumentValue(int index, object value); - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Reflection; + +namespace Moq.Proxy +{ + internal interface ICallContext + { + object[] Arguments { get; } + + MethodInfo Method { get; } + + object ReturnValue { get; set; } + + void InvokeBase(); + + void SetArgumentValue(int index, object value); + } } \ No newline at end of file diff --git a/Source/Proxy/ICallInterceptor.cs b/Source/Proxy/ICallInterceptor.cs index 8d9c1ecd9..eeb17b3f0 100644 --- a/Source/Proxy/ICallInterceptor.cs +++ b/Source/Proxy/ICallInterceptor.cs @@ -1,47 +1,47 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -namespace Moq.Proxy -{ - internal interface ICallInterceptor - { - void Intercept(ICallContext context); - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +namespace Moq.Proxy +{ + internal interface ICallInterceptor + { + void Intercept(ICallContext context); + } } \ No newline at end of file diff --git a/Source/Range.cs b/Source/Range.cs index cc06971a2..1ecdd6fd0 100644 --- a/Source/Range.cs +++ b/Source/Range.cs @@ -1,60 +1,60 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -namespace Moq -{ - /// - /// Kind of range to use in a filter specified through - /// . - /// - public enum Range - { - /// - /// The range includes the to and - /// from values. - /// - Inclusive, - /// - /// The range does not include the to and - /// from values. - /// - Exclusive - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +namespace Moq +{ + /// + /// Kind of range to use in a filter specified through + /// . + /// + public enum Range + { + /// + /// The range includes the to and + /// from values. + /// + Inclusive, + /// + /// The range does not include the to and + /// from values. + /// + Exclusive + } } \ No newline at end of file diff --git a/Source/SequenceExtensions.cs b/Source/SequenceExtensions.cs index 9ee7ef7e9..98f9ed76e 100644 --- a/Source/SequenceExtensions.cs +++ b/Source/SequenceExtensions.cs @@ -1,29 +1,29 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Linq.Expressions; -using Moq.Language.Flow; -using Moq.Language; -using System.Diagnostics.CodeAnalysis; - -namespace Moq -{ - /// - /// Helper for sequencing return values in the same method. - /// - public static class SequenceExtensions - { - /// - /// Return a sequence of values, once per call. - /// - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "By Design")] - public static ISetupSequentialResult SetupSequence( - this Mock mock, - Expression> expression) - where TMock : class - { - return new SetupSequentialContext(mock, expression); - } - } +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Linq.Expressions; +using Moq.Language.Flow; +using Moq.Language; +using System.Diagnostics.CodeAnalysis; + +namespace Moq +{ + /// + /// Helper for sequencing return values in the same method. + /// + public static class SequenceExtensions + { + /// + /// Return a sequence of values, once per call. + /// + [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "By Design")] + public static ISetupSequentialResult SetupSequence( + this Mock mock, + Expression> expression) + where TMock : class + { + return new SetupSequentialContext(mock, expression); + } + } } \ No newline at end of file diff --git a/Source/SetterMethodCall.cs b/Source/SetterMethodCall.cs index bbd5c64e7..29bc0d493 100644 --- a/Source/SetterMethodCall.cs +++ b/Source/SetterMethodCall.cs @@ -1,73 +1,73 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Linq.Expressions; -using System.Reflection; -using Moq.Language.Flow; -using Moq.Protected; - -namespace Moq -{ - internal class SetterMethodCall : MethodCall, ISetupSetter - where TMock : class - { - public SetterMethodCall(Mock mock, Expression originalExpression, MethodInfo method) - : base(mock, null, originalExpression, method, new[] { ItExpr.IsAny() }) - { - } - - public SetterMethodCall(Mock mock, Expression originalExpression, MethodInfo method, TProperty value) - : base(mock, null, originalExpression, method, new[] { ItExpr.Is(arg => Object.Equals(arg, value)) }) - { - } - - public SetterMethodCall(Mock mock, Func condition, Expression originalExpression, MethodInfo method, Expression value) - : base(mock, condition, originalExpression, method, new[] { value }) - { - } - - public ICallbackResult Callback(Action callback) - { - this.SetCallbackWithArguments(callback); - return this; - } - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Linq.Expressions; +using System.Reflection; +using Moq.Language.Flow; +using Moq.Protected; + +namespace Moq +{ + internal class SetterMethodCall : MethodCall, ISetupSetter + where TMock : class + { + public SetterMethodCall(Mock mock, Expression originalExpression, MethodInfo method) + : base(mock, null, originalExpression, method, new[] { ItExpr.IsAny() }) + { + } + + public SetterMethodCall(Mock mock, Expression originalExpression, MethodInfo method, TProperty value) + : base(mock, null, originalExpression, method, new[] { ItExpr.Is(arg => Object.Equals(arg, value)) }) + { + } + + public SetterMethodCall(Mock mock, Func condition, Expression originalExpression, MethodInfo method, Expression value) + : base(mock, condition, originalExpression, method, new[] { value }) + { + } + + public ICallbackResult Callback(Action callback) + { + this.SetCallbackWithArguments(callback); + return this; + } + } } \ No newline at end of file diff --git a/Source/SetupKind.cs b/Source/SetupKind.cs index 959dcbc38..8e66bfe53 100644 --- a/Source/SetupKind.cs +++ b/Source/SetupKind.cs @@ -1,49 +1,49 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - - -namespace Moq -{ - internal enum SetupKind - { - PropertySet, - Other, - } -} +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + + +namespace Moq +{ + internal enum SetupKind + { + PropertySet, + Other, + } +} diff --git a/Source/Times.cs b/Source/Times.cs index 96a51f9da..82358390f 100644 --- a/Source/Times.cs +++ b/Source/Times.cs @@ -1,184 +1,184 @@ -//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD -//http://code.google.com/p/moq/ -//All rights reserved. - -//Redistribution and use in source and binary forms, -//with or without modification, are permitted provided -//that the following conditions are met: - -// * Redistributions of source code must retain the -// above copyright notice, this list of conditions and -// the following disclaimer. - -// * Redistributions in binary form must reproduce -// the above copyright notice, this list of conditions -// and the following disclaimer in the documentation -// and/or other materials provided with the distribution. - -// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the -// names of its contributors may be used to endorse -// or promote products derived from this software -// without specific prior written permission. - -//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -//SUCH DAMAGE. - -//[This is the BSD license, see -// http://www.opensource.org/licenses/bsd-license.php] - -using System; -using System.Globalization; -using Moq.Properties; - -namespace Moq -{ - /// - public struct Times - { - private Func evaluator; - private string messageFormat; - private int from; - private int to; - - private Times(Func evaluator, int from, int to, string messageFormat) - { - this.evaluator = evaluator; - this.from = from; - this.to = to; - this.messageFormat = messageFormat; - } - - /// - public static Times AtLeast(int callCount) - { - Guard.NotOutOfRangeInclusive(() => callCount, callCount, 1, int.MaxValue); - - return new Times(c => c >= callCount, callCount, int.MaxValue, Resources.NoMatchingCallsAtLeast); - } - - /// - public static Times AtLeastOnce() - { - return new Times(c => c >= 1, 1, int.MaxValue, Resources.NoMatchingCallsAtLeastOnce); - } - - /// - public static Times AtMost(int callCount) - { - Guard.NotOutOfRangeInclusive(() => callCount, callCount, 0, int.MaxValue); - - return new Times(c => c >= 0 && c <= callCount, 0, callCount, Resources.NoMatchingCallsAtMost); - } - - /// - public static Times AtMostOnce() - { - return new Times(c => c >= 0 && c <= 1, 0, 1, Resources.NoMatchingCallsAtMostOnce); - } - - /// - public static Times Between(int callCountFrom, int callCountTo, Range rangeKind) - { - if (rangeKind == Range.Exclusive) - { - Guard.NotOutOfRangeExclusive(() => callCountFrom, callCountFrom, 0, callCountTo); - if (callCountTo - callCountFrom == 1) - { - throw new ArgumentOutOfRangeException("callCountTo"); - } - - return new Times( - c => c > callCountFrom && c < callCountTo, - callCountFrom, - callCountTo, - Resources.NoMatchingCallsBetweenExclusive); - } - - Guard.NotOutOfRangeInclusive(() => callCountFrom, callCountFrom, 0, callCountTo); - return new Times( - c => c >= callCountFrom && c <= callCountTo, - callCountFrom, - callCountTo, - Resources.NoMatchingCallsBetweenInclusive); - } - - /// - public static Times Exactly(int callCount) - { - Guard.NotOutOfRangeInclusive(() => callCount, callCount, 0, int.MaxValue); - - return new Times(c => c == callCount, callCount, callCount, Resources.NoMatchingCallsExactly); - } - - /// - public static Times Never() - { - return new Times(c => c == 0, 0, 0, Resources.NoMatchingCallsNever); - } - - /// - public static Times Once() - { - return new Times(c => c == 1, 1, 1, Resources.NoMatchingCallsOnce); - } - - /// - public override bool Equals(object obj) - { - if (obj is Times) - { - var other = (Times)obj; - return this.from == other.from && this.to == other.to; - } - - return false; - } - - /// - public override int GetHashCode() - { - return this.from.GetHashCode() ^ this.to.GetHashCode(); - } - - /// - public static bool operator ==(Times left, Times right) - { - return left.Equals(right); - } - - /// - public static bool operator !=(Times left, Times right) - { - return !left.Equals(right); - } - - internal string GetExceptionMessage(string failMessage, string expression, int callCount) - { - return string.Format( - CultureInfo.CurrentCulture, - this.messageFormat, - failMessage, - expression, - this.from, - this.to, - callCount); - } - - internal bool Verify(int callCount) - { - return this.evaluator(callCount); - } - } +//Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD +//http://code.google.com/p/moq/ +//All rights reserved. + +//Redistribution and use in source and binary forms, +//with or without modification, are permitted provided +//that the following conditions are met: + +// * Redistributions of source code must retain the +// above copyright notice, this list of conditions and +// the following disclaimer. + +// * Redistributions in binary form must reproduce +// the above copyright notice, this list of conditions +// and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the +// names of its contributors may be used to endorse +// or promote products derived from this software +// without specific prior written permission. + +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +//SUCH DAMAGE. + +//[This is the BSD license, see +// http://www.opensource.org/licenses/bsd-license.php] + +using System; +using System.Globalization; +using Moq.Properties; + +namespace Moq +{ + /// + public struct Times + { + private Func evaluator; + private string messageFormat; + private int from; + private int to; + + private Times(Func evaluator, int from, int to, string messageFormat) + { + this.evaluator = evaluator; + this.from = from; + this.to = to; + this.messageFormat = messageFormat; + } + + /// + public static Times AtLeast(int callCount) + { + Guard.NotOutOfRangeInclusive(() => callCount, callCount, 1, int.MaxValue); + + return new Times(c => c >= callCount, callCount, int.MaxValue, Resources.NoMatchingCallsAtLeast); + } + + /// + public static Times AtLeastOnce() + { + return new Times(c => c >= 1, 1, int.MaxValue, Resources.NoMatchingCallsAtLeastOnce); + } + + /// + public static Times AtMost(int callCount) + { + Guard.NotOutOfRangeInclusive(() => callCount, callCount, 0, int.MaxValue); + + return new Times(c => c >= 0 && c <= callCount, 0, callCount, Resources.NoMatchingCallsAtMost); + } + + /// + public static Times AtMostOnce() + { + return new Times(c => c >= 0 && c <= 1, 0, 1, Resources.NoMatchingCallsAtMostOnce); + } + + /// + public static Times Between(int callCountFrom, int callCountTo, Range rangeKind) + { + if (rangeKind == Range.Exclusive) + { + Guard.NotOutOfRangeExclusive(() => callCountFrom, callCountFrom, 0, callCountTo); + if (callCountTo - callCountFrom == 1) + { + throw new ArgumentOutOfRangeException("callCountTo"); + } + + return new Times( + c => c > callCountFrom && c < callCountTo, + callCountFrom, + callCountTo, + Resources.NoMatchingCallsBetweenExclusive); + } + + Guard.NotOutOfRangeInclusive(() => callCountFrom, callCountFrom, 0, callCountTo); + return new Times( + c => c >= callCountFrom && c <= callCountTo, + callCountFrom, + callCountTo, + Resources.NoMatchingCallsBetweenInclusive); + } + + /// + public static Times Exactly(int callCount) + { + Guard.NotOutOfRangeInclusive(() => callCount, callCount, 0, int.MaxValue); + + return new Times(c => c == callCount, callCount, callCount, Resources.NoMatchingCallsExactly); + } + + /// + public static Times Never() + { + return new Times(c => c == 0, 0, 0, Resources.NoMatchingCallsNever); + } + + /// + public static Times Once() + { + return new Times(c => c == 1, 1, 1, Resources.NoMatchingCallsOnce); + } + + /// + public override bool Equals(object obj) + { + if (obj is Times) + { + var other = (Times)obj; + return this.from == other.from && this.to == other.to; + } + + return false; + } + + /// + public override int GetHashCode() + { + return this.from.GetHashCode() ^ this.to.GetHashCode(); + } + + /// + public static bool operator ==(Times left, Times right) + { + return left.Equals(right); + } + + /// + public static bool operator !=(Times left, Times right) + { + return !left.Equals(right); + } + + internal string GetExceptionMessage(string failMessage, string expression, int callCount) + { + return string.Format( + CultureInfo.CurrentCulture, + this.messageFormat, + failMessage, + expression, + this.from, + this.to, + callCount); + } + + internal bool Verify(int callCount) + { + return this.evaluator(callCount); + } + } } \ No newline at end of file diff --git a/Source/Times.xdoc b/Source/Times.xdoc index a81f6da67..b85a1e582 100644 --- a/Source/Times.xdoc +++ b/Source/Times.xdoc @@ -1,112 +1,112 @@ - - - - - Defines the number of invocations allowed by a mocked method. - - - - - Specifies that a mocked method should be invoked times as minimum. - - The minimun number of times. - An object defining the allowed number of invocations. - - - - Specifies that a mocked method should be invoked one time as minimum. - - An object defining the allowed number of invocations. - - - - Specifies that a mocked method should be invoked time as maximun. - - The maximun number of times. - An object defining the allowed number of invocations. - - - - Specifies that a mocked method should be invoked one time as maximun. - - An object defining the allowed number of invocations. - - - - Specifies that a mocked method should be invoked between and - times. - - The minimun number of times. - The maximun number of times. - - The kind of range. See . - - An object defining the allowed number of invocations. - - - - Specifies that a mocked method should be invoked exactly times. - - The times that a method or property can be called. - An object defining the allowed number of invocations. - - - - Specifies that a mocked method should not be invoked. - - An object defining the allowed number of invocations. - - - - Specifies that a mocked method should be invoked exactly one time. - - An object defining the allowed number of invocations. - - - - Determines whether the specified is equal to this instance. - - - The to compare with this instance. - - - true if the specified is equal to this instance; otherwise, false. - - - - - Returns a hash code for this instance. - - - A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. - - - - - Determines whether two specified objects have the same value. - - - The first . - - - The second . - - - true if the value of left is the same as the value of right; otherwise, false. - - - - - Determines whether two specified objects have different values. - - - The first . - - - The second . - - - true if the value of left is different from the value of right; otherwise, false. - - + + + + + Defines the number of invocations allowed by a mocked method. + + + + + Specifies that a mocked method should be invoked times as minimum. + + The minimun number of times. + An object defining the allowed number of invocations. + + + + Specifies that a mocked method should be invoked one time as minimum. + + An object defining the allowed number of invocations. + + + + Specifies that a mocked method should be invoked time as maximun. + + The maximun number of times. + An object defining the allowed number of invocations. + + + + Specifies that a mocked method should be invoked one time as maximun. + + An object defining the allowed number of invocations. + + + + Specifies that a mocked method should be invoked between and + times. + + The minimun number of times. + The maximun number of times. + + The kind of range. See . + + An object defining the allowed number of invocations. + + + + Specifies that a mocked method should be invoked exactly times. + + The times that a method or property can be called. + An object defining the allowed number of invocations. + + + + Specifies that a mocked method should not be invoked. + + An object defining the allowed number of invocations. + + + + Specifies that a mocked method should be invoked exactly one time. + + An object defining the allowed number of invocations. + + + + Determines whether the specified is equal to this instance. + + + The to compare with this instance. + + + true if the specified is equal to this instance; otherwise, false. + + + + + Returns a hash code for this instance. + + + A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + + + + + Determines whether two specified objects have the same value. + + + The first . + + + The second . + + + true if the value of left is the same as the value of right; otherwise, false. + + + + + Determines whether two specified objects have different values. + + + The first . + + + The second . + + + true if the value of left is different from the value of right; otherwise, false. + + \ No newline at end of file diff --git a/Source/ilmerge.exclude b/Source/ilmerge.exclude index 6773dd342..50b546cca 100644 --- a/Source/ilmerge.exclude +++ b/Source/ilmerge.exclude @@ -1,3 +1,3 @@ -Castle.DynamicProxy.IProxyTargetAccessor -Castle.DynamicProxy.AbstractInvocation +Castle.DynamicProxy.IProxyTargetAccessor +Castle.DynamicProxy.AbstractInvocation Castle.DynamicProxy.Generators.AttributesToAvoidReplicating \ No newline at end of file diff --git a/Tools/ILMerge License.rtf b/Tools/ILMerge License.rtf index 41f5b6ada..e8001515e 100644 --- a/Tools/ILMerge License.rtf +++ b/Tools/ILMerge License.rtf @@ -1,104 +1,104 @@ -{\rtf1\ansi\ansicpg1252\uc1\deff0\stshfdbch0\stshfloch0\stshfhich0\stshfbi0\deflang1033\deflangfe1033{\fonttbl{\f0\froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f37\fswiss\fcharset0\fprq2{\*\panose 020b0604030504040204}Tahoma;} -{\f39\froman\fcharset0\fprq2{\*\panose 02040602050305030304}Book Antiqua;}{\f40\fswiss\fcharset0\fprq2{\*\panose 020b0706030402020204}Franklin Gothic Demi Cond;}{\f41\fswiss\fcharset0\fprq2{\*\panose 020b0503020102020204}Franklin Gothic Book;} -{\f42\froman\fcharset238\fprq2 Times New Roman CE;}{\f43\froman\fcharset204\fprq2 Times New Roman Cyr;}{\f45\froman\fcharset161\fprq2 Times New Roman Greek;}{\f46\froman\fcharset162\fprq2 Times New Roman Tur;} -{\f47\froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\f48\froman\fcharset178\fprq2 Times New Roman (Arabic);}{\f49\froman\fcharset186\fprq2 Times New Roman Baltic;}{\f50\froman\fcharset163\fprq2 Times New Roman (Vietnamese);} -{\f412\fswiss\fcharset238\fprq2 Tahoma CE;}{\f413\fswiss\fcharset204\fprq2 Tahoma Cyr;}{\f415\fswiss\fcharset161\fprq2 Tahoma Greek;}{\f416\fswiss\fcharset162\fprq2 Tahoma Tur;}{\f417\fswiss\fcharset177\fprq2 Tahoma (Hebrew);} -{\f418\fswiss\fcharset178\fprq2 Tahoma (Arabic);}{\f419\fswiss\fcharset186\fprq2 Tahoma Baltic;}{\f420\fswiss\fcharset163\fprq2 Tahoma (Vietnamese);}{\f421\fswiss\fcharset222\fprq2 Tahoma (Thai);}{\f432\froman\fcharset238\fprq2 Book Antiqua CE;} -{\f433\froman\fcharset204\fprq2 Book Antiqua Cyr;}{\f435\froman\fcharset161\fprq2 Book Antiqua Greek;}{\f436\froman\fcharset162\fprq2 Book Antiqua Tur;}{\f439\froman\fcharset186\fprq2 Book Antiqua Baltic;} -{\f442\fswiss\fcharset238\fprq2 Franklin Gothic Demi Cond CE;}{\f443\fswiss\fcharset204\fprq2 Franklin Gothic Demi Cond Cyr;}{\f445\fswiss\fcharset161\fprq2 Franklin Gothic Demi Cond Greek;}{\f446\fswiss\fcharset162\fprq2 Franklin Gothic Demi Cond Tur;} -{\f449\fswiss\fcharset186\fprq2 Franklin Gothic Demi Cond Baltic;}{\f452\fswiss\fcharset238\fprq2 Franklin Gothic Book CE;}{\f453\fswiss\fcharset204\fprq2 Franklin Gothic Book Cyr;}{\f455\fswiss\fcharset161\fprq2 Franklin Gothic Book Greek;} -{\f456\fswiss\fcharset162\fprq2 Franklin Gothic Book Tur;}{\f459\fswiss\fcharset186\fprq2 Franklin Gothic Book Baltic;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255; -\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;\red192\green192\blue192;} -{\stylesheet{\ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \snext0 Normal;}{\*\cs10 \additive \ssemihidden Default Paragraph Font;}{\* -\ts11\tsrowd\trftsWidthB3\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\trcbpat1\trcfpat1\tscellwidthfts0\tsvertalt\tsbrdrt\tsbrdrl\tsbrdrb\tsbrdrr\tsbrdrdgl\tsbrdrdgr\tsbrdrh\tsbrdrv -\ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \fs20\lang1024\langfe1024\cgrid\langnp1024\langfenp1024 \snext11 \ssemihidden Normal Table;}{\s15\ql \fi-274\li274\ri0\sb120\sl460\slmult0 -\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin274\itap0 \f40\fs44\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon0 \snext15 \styrsid9786739 1sectionhead;}{\s16\ql \li0\ri0\sb120\sl200\slmult0 -\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \caps\f40\fs16\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon0 \snext16 \styrsid9786739 4laparahead;}{\s17\ql \li0\ri-18\sb120\sl240\slmult0 -\widctlpar\aspalpha\aspnum\faauto\adjustright\rin-18\lin0\itap0 \f40\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon0 \snext17 \styrsid9786739 2lasubhead;}{\s18\ql \fi-187\li187\ri0\sb60\sl180\slmult0 -\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin187\itap0 \f41\fs16\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon0 \snext18 \styrsid9786739 3cnumbered;}{\s19\ql \fi-340\li624\ri0\sb60\sl160\slmult0 -\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin624\itap0 \f41\fs14\cf1\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon0 \snext19 \styrsid9786739 3inumbered2ndlevel;}{\s20\ql \li0\ri0\sb240\sl240\slmult0 -\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \f40\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon0 \snext20 \styrsid9786739 2afrenchsubhead;}{\s21\ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 -\cbpat9 \f37\fs20\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon0 \snext21 \ssemihidden \styrsid7154712 Document Map;}}{\*\latentstyles\lsdstimax156\lsdlockeddef0}{\*\pgptbl {\pgp\ipgp2\itap0\li0\ri0\sb0\sa0\brdrt\brdrs\brdrw20 }{\pgp\ipgp0 -\itap0\li0\ri0\sb0\sa0}}{\*\rsidtbl \rsid2099452\rsid4207571\rsid5465292\rsid5510097\rsid5510644\rsid7154712\rsid7241305\rsid7672529\rsid7735936\rsid9179139\rsid9786739\rsid10440675\rsid11303133\rsid13130884\rsid14028235\rsid14100361\rsid14113652 -\rsid15276140\rsid16213514}{\*\generator Microsoft Word 11.0.6359;}{\info{\title ILMerge EULA}{\author Ken Leppert}{\operator mbarnett}{\creatim\yr2005\mo3\dy16\hr15\min43}{\revtim\yr2005\mo3\dy16\hr15\min43}{\printim\yr2004\mo4\dy30\hr13\min9}{\version2} -{\edmins0}{\nofpages3}{\nofwords1188}{\nofchars6775}{\*\company Microsoft Corporation}{\nofcharsws7948}{\vern24703}}\widowctrl\ftnbj\aenddoc\noxlattoyen\expshrtn\noultrlspc\dntblnsbdb\nospaceforul\formshade\horzdoc\dgmargin\dghspace180\dgvspace180 -\dghorigin1800\dgvorigin1440\dghshow1\dgvshow1\jexpand\viewkind1\viewscale68\viewzk2\pgbrdrhead\pgbrdrfoot\splytwnine\ftnlytwnine\htmautsp\nolnhtadjtbl\useltbaln\alntblind\lytcalctblwd\lyttblrtgr\lnbrkrule\nobrkwrptbl\snaptogridincell\allowfieldendsel -\wrppunct\asianbrkrule\rsidroot9786739\newtblstyruls\nogrowautofit \fet0\sectd \linex0\endnhere\sectlinegrid360\sectdefaultcl\sftnbj {\*\pnseclvl1\pnucrm\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl2\pnucltr\pnstart1\pnindent720\pnhang -{\pntxta .}}{\*\pnseclvl3\pndec\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl4\pnlcltr\pnstart1\pnindent720\pnhang {\pntxta )}}{\*\pnseclvl5\pndec\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl6\pnlcltr\pnstart1\pnindent720\pnhang -{\pntxtb (}{\pntxta )}}{\*\pnseclvl7\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl8\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl9\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}\pard\plain -\s15\ql \li0\ri0\sb100\sa100\sbauto1\saauto1\widctlpar\aspalpha\aspnum\faauto\outlinelevel0\adjustright\rin0\lin0\itap0\pararsid7154712 \f40\fs44\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\b\f39\fs28\insrsid9786739 MICROSOFT }{ -\b\f39\fs28\insrsid5465292 ILMerge}{\insrsid9786739 -\par }{\b\f39\fs22\insrsid9786739 END-USER LICENSE AGREEMENT FOR MICROSOFT SOFTWARE}{\insrsid9786739 -\par }\pard\plain \s17\qj \li0\ri-17\sb100\sa100\sbauto1\saauto1\widctlpar\aspalpha\aspnum\faauto\adjustright\rin-17\lin0\itap0\pararsid14100361 \f40\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\b\f39\insrsid9786739 IMPORTANT\emdash -READ CAREFULLY: }{\f39\insrsid9786739 This End-User License Agreement (\'93EULA\'94) is a legal agreement between you (either an individual or a single entity) and Microsoft Corporation (\'93Microsoft\'94) for th -e Microsoft software that accompanies this EULA, which includes computer software and may include associated media, printed materials, \'93online\'94 or electronic documentation, and Internet-based services (\'93Software\'94).\~ - An amendment or addendum to this EULA may accompany the Software.\~ }{\b\f39\insrsid9786739 -YOU AGREE TO BE BOUND BY THE TERMS OF THIS EULA BY INSTALLING, COPYING, OR OTHERWISE USING THE SOFTWARE. IF YOU DO NOT AGREE, DO NOT INSTALL, COPY, OR USE THE SOFTWARE.}{\insrsid9786739 -\par }\pard\plain \qj \li0\ri0\sb100\sa100\sbauto1\saauto1\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid14100361 \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\f39\fs22\insrsid9786739 1.\~\~\~\~\~\~\~\~ }{ -\b\f39\fs22\insrsid9786739 GRANTS OF LICENSE}{\f39\fs22\insrsid9786739 . Microsoft grants you the rights described in this EULA provided that you comply with all terms and conditions of this EULA.\~ }{\insrsid9786739 -\par }\pard\plain \s19\qj \fi720\li0\ri0\sb100\sa100\sbauto1\saauto1\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid14100361 \f41\fs14\cf1\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\f39\fs22\cf0\insrsid9786739 1.1\~\~\~\~\~\~ }{ -\b\i\f39\fs22\cf0\insrsid9786739 License Grant}{\f39\fs22\cf0\insrsid9786739 . Microsoft grants to you a personal, nonexclusive, nontransferable, limited license to }{\f39\fs22\insrsid9786739 install and use a reasonable number of copies of -the Software on computers residing on your premises }{\f39\fs22\cf0\insrsid9786739 for the purposes of designing, developing, and testing, your software product(s), provided that you are the only individual using the Software.\~ }{\insrsid9786739 -\par }\pard\plain \s18\qj \fi720\li0\ri0\sb100\sa100\sbauto1\saauto1\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid14100361 \f41\fs16\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\f39\fs22\insrsid9786739 1.2\~\~\~\~\~\~ }{ -\b\i\f39\fs22\insrsid9786739 Documentation}{\f39\fs22\insrsid9786739 .}{\b\f39\fs22\insrsid9786739 \~ }{\f39\fs22\insrsid9786739 You may make and use a reasonabl -e number of copies of any documentation, provided that such copies shall be used only for your personal purposes and are not to be republished or distributed (either in hard copy or electronic form) beyond your premises.}{\insrsid9786739 -\par }\pard \s18\qj \li0\ri0\sb100\sa100\sbauto1\saauto1\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid14100361 {\f39\fs22\insrsid9786739 2.\~\~\~\~\~\~\~\~ }{\b\f39\fs22\insrsid9786739 RESERVATION OF RIGHTS AND OWNERSHIP.\~ }{ -\f39\fs22\insrsid9786739 The Software is licensed as a single product.\~ Its component parts may not be separated. Microsoft reserves all rights not expressly granted to you in this EULA.\~ - The Software is protected by copyright and other intellectual property laws and treaties}{\f39\fs22\insrsid14028235 , and}{\f39\fs22\insrsid9786739 Microsoft }{\f39\fs22\insrsid14028235 (}{\f39\fs22\insrsid9786739 or its suppliers}{ -\f39\fs22\insrsid14028235 , where applicable)}{\f39\fs22\insrsid9786739 own }{\f39\fs22\insrsid14028235 all right, }{\f39\fs22\insrsid9786739 title, }{\f39\fs22\insrsid14028235 and interest in all }{\f39\fs22\insrsid9786739 -intellectual property rights in the Software.\~ }{\b\f39\fs22\insrsid9786739 The Software is licensed, not sold.}{\insrsid9786739 -\par }\pard\plain \s19\qj \li0\ri0\sb100\sa100\sbauto1\saauto1\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid14100361 \f41\fs14\cf1\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\f39\fs22\cf0\insrsid9786739 3.\~\~\~\~\~\~\~\~ }{ -\b\f39\fs22\cf0\insrsid9786739 LIMITATIONS ON REVERSE ENGINEERING, DECOMPILATION, AND DISASSEMBLY}{\b\i\f39\fs22\cf0\insrsid9786739 .}{\f39\fs22\cf0\insrsid9786739 \~ - You may not reverse engineer, decompile, or disassemble the Software, except and only to the extent that such activity is expressly permitted by applicable law notwithstanding this limitation.}{\insrsid9786739 -\par }\pard\plain \s18\qj \li0\ri0\sb100\sa100\sbauto1\saauto1\sl220\slmult0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid14100361 \f41\fs16\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\f39\fs22\insrsid9786739 4.\~\~\~\~\~\~\~\~ -}{\b\f39\fs22\insrsid9786739 NO RENTAL/COMMERCIAL HOSTING.}{\b\i\f39\fs22\insrsid9786739 }{\f39\fs22\insrsid9786739 You may not rent, lease, lend or provide commercial hosting services with the Software.}{\insrsid9786739 -\par }\pard\plain \s19\qj \li0\ri0\sb100\sa100\sbauto1\saauto1\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid14100361 \f41\fs14\cf1\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\f39\fs22\cf0\insrsid9786739 5.\~\~\~\~\~\~\~\~ }{ -\b\f39\fs22\cf0\insrsid9786739 NO SOFTWARE TRANSFER.\~ }{\f39\fs22\cf0\insrsid9786739 You may not assign or otherwise transfer the SOFTWARE or any of your rights hereunder to any third party.}{\insrsid9786739 -\par }{\f39\fs22\cf0\insrsid9786739 6.\~\~\~\~\~\~\~\~ }{\b\f39\fs22\cf0\insrsid9786739 CONSENT TO USE OF DATA.\~ }{\f39\fs22\cf0\insrsid9786739 You - agree that Microsoft and its affiliates may collect and use technical information gathered as part of the product support services provided to you, if any, related to the Software.\~ - Microsoft may use this information solely to improve our products or to provide customized services or technologies to you and will not disclose this information in a form that personally identifies you.\~\~ }{\insrsid9786739 -\par }{\f39\fs22\cf0\insrsid5510644 7}{\f39\fs22\cf0\insrsid9786739 .\~\~\~\~\~\~\~\~ }{\b\f39\fs22\cf0\insrsid9786739 ADDITIONAL SOFTWARE/SERVICES.\~ }{\f39\fs22\insrsid9786739 Microsoft is not obligated to provide maintenance, technical supplements}{ -\f39\fs22\insrsid14028235 , updates,}{\f39\fs22\insrsid9786739 or other support to you for the Software licensed under this EULA. }{\f39\fs22\insrsid7241305 }{\f39\fs22\insrsid9786739 In the event that Microsoft does provide such supplements or updates} -{\b\f39\fs22\insrsid9786739 , }{\f39\fs22\insrsid9786739 this EULA applies to such updates, supplements, or add-on components of the Software that Microsoft may provide to -you or make available to you after the date you obtain your initial copy of the Software, unless we provide other terms along with the update, supplement, or add-on component}{\f39\fs22\cf0\insrsid9786739 .\~ - Microsoft reserves the right to discontinue any Internet-based services provided to you or made available to you through the use of the Software.\~ }{\insrsid9786739 -\par }\pard\plain \s18\qj \li0\ri0\sb100\sa100\sbauto1\saauto1\sl220\slmult0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid14100361 \f41\fs16\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\f39\fs22\insrsid5510644 8}{ -\f39\fs22\insrsid9786739 .\~\~\~\~\~\~\~\~ }{\b\f39\fs22\insrsid9786739 EXPORT RESTRICTIONS}{\f39\fs22\insrsid9786739 .\~ }{\f39\fs22\cgrid0\insrsid9786739 You acknowledge that the Software is subject to U.S. export jurisdiction.\~ - You agree to comply with all applicable international and national laws that apply to the Software, including the U.S. Export Administration Regulations, as well as end-user, end-use, and destination restrictions issued by U.S. and other governments.\~\~ - For additional information see }{\f39\fs22\ul\cgrid0\insrsid9786739 http://www.microsoft.com/exporting/}{\f39\fs22\cgrid0\insrsid9786739 .}{\insrsid9786739 -\par }\pard\plain \s19\qj \li0\ri0\sb100\sa100\sbauto1\saauto1\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid14100361 \f41\fs14\cf1\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\f39\fs22\cf0\insrsid14113652 9}{ -\f39\fs22\cf0\insrsid9786739 .\~\~\~\~\~\~ }{\b\f39\fs22\cf0\insrsid9786739 TERMINATION.}{\f39\fs22\cf0\insrsid9786739 \~ Without prejudice to any other rights, Microsoft may terminate this EULA if you fail to comply with }{\f39\fs22\cf0\insrsid7241305 -any }{\f39\fs22\cf0\insrsid9786739 term}{\f39\fs22\cf0\insrsid7241305 or}{\f39\fs22\cf0\insrsid9786739 condition of this EULA. }{\f39\fs22\cf0\insrsid7241305 }{\f39\fs22\cf0\insrsid9786739 -In such event, you must destroy all copies of the Software and all of its component parts.}{\insrsid9786739 -\par }\pard\plain \s18\qj \li0\ri0\sb100\sa100\sbauto1\saauto1\sl220\slmult0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid14100361 \f41\fs16\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\f39\fs22\insrsid9786739 1}{ -\f39\fs22\insrsid14113652 0}{\f39\fs22\insrsid9786739 .\~\~\~\~\~\~ }{\b\f39\fs22\ul\insrsid9786739 DISCLAIMER OF WARRANTIES}{\b\f39\fs22\insrsid9786739 .\~ - TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND ITS SUPPLIERS PROVIDE THE SOFTWARE}{\f39\fs22\insrsid9786739 }{\b\f39\fs22\insrsid9786739 AND SUPPORT SERVICES (IF ANY) }{\b\i\f39\fs22\insrsid9786739 AS IS AND WITH ALL FAULTS}{ -\b\f39\fs22\insrsid9786739 , AND HEREBY DISCLAIM ALL OTHER WARRANTIES AND CONDITIONS, WHETHER EXPRESS, IMPLIED - OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY (IF ANY) IMPLIED WARRANTIES, DUTIES OR CONDITIONS OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR PURPOSE, OF RELIABILITY OR AVAILABILITY, OF ACCURACY OR COMPLETENESS OF RESPONSES, OF RESULTS, OF WORKMANLI -K -E EFFORT, OF LACK OF VIRUSES, AND OF LACK OF NEGLIGENCE, ALL WITH REGARD TO THE SOFTWARE, AND THE PROVISION OF OR FAILURE TO PROVIDE SUPPORT OR OTHER SERVICES, INFORMATION, SOFTWARE, AND RELATED CONTENT THROUGH THE SOFTWARE OR OTHERWISE ARISING OUT OF THE - USE OF THE SOFTWARE.\~ ALSO, THERE IS NO WARRANTY OR CONDITION OF TITLE, QUIET ENJOYMENT, QUIET POSSESSION, CORRESPONDENCE TO DESCRIPTION OR NON-INFRINGEMENT WITH REGARD TO THE SOFTWARE.}{\insrsid9786739 -\par }{\f39\fs22\insrsid9786739 1}{\f39\fs22\insrsid14113652 1}{\f39\fs22\insrsid9786739 .}{\b\f39\fs22\insrsid9786739 \~\~\~\~\~\~ }{\b\f39\fs22\ul\insrsid9786739 EXCLUSION OF INCIDENTAL, CONSEQUENTIAL AND CERTAIN OTHER DAMAGES}{\b\f39\fs22\insrsid9786739 .\~ - }{\b\caps\f39\fs22\insrsid9786739 -To the maximum extent permitted by applicable law, in no event shall Microsoft or its suppliers be liable for any special, incidental, punitive, indirect, or consequential damages whatsoever (including, but not limited to, damages for loss of profit -s, LOSS OF DATA, or confidential or other information}{\b\f39\fs22\insrsid9786739 , }{\b\caps\f39\fs22\insrsid9786739 -for business interruption, for personal injury, for loss of privacy, for failure to meet any duty including of good faith or of reasonable care, for negligence, and}{\b\f39\fs22\insrsid9786739 }{\b\caps\f39\fs22\insrsid9786739 -for any other pecuniary or other los -s whatsoever) arising out of or in any way related to the use of or inability to use the SOFTWARE, the provision of or failure to provide Support OR OTHER Services, informatIon, software, and related CONTENT through the software or otherwise arising out o -f - the use of the software, or otherwise under or in connection with any provision of this EULA, even in the event of the fault, tort (including negligence), misrepresentation, strict liability, breach of contract or breach of warranty of Microsoft or any s -upplier, and even if Microsoft or any supplier has been advised of the possibility of such damages. }{\insrsid9786739 -\par }{\f39\fs22\insrsid9786739 1}{\f39\fs22\insrsid14113652 2}{\f39\fs22\insrsid9786739 .}{\b\f39\fs22\insrsid9786739 \~\~\~\~\~\~ }{\b\f39\fs22\ul\insrsid9786739 LIMITATION OF LIABILITY AND REMEDIES}{\b\f39\fs22\insrsid9786739 -. NOTWITHSTANDING ANY DAMAGES THAT YOU MIGHT INCUR FOR ANY REASON WHATSOEVER (INCLUDING, WITHOUT LIMITATION, A -LL DAMAGES REFERENCED HEREIN AND ALL DIRECT OR GENERAL DAMAGES IN CONTRACT OR ANYTHING ELSE), THE ENTIRE LIABILITY OF MICROSOFT AND ANY OF ITS SUPPLIERS UNDER ANY PROVISION OF THIS EULA AND YOUR EXCLUSIVE REMEDY HEREUNDER SHALL BE LIMITED TO THE GREATER O -F THE ACTUAL DAMAGES YOU INCUR IN REASONABLE RELIANCE ON THE SOFTWARE UP TO THE AMOUNT ACTUALLY PAID BY YOU FOR THE SOFTWARE}{\f39\fs22\insrsid9786739 }{\b\f39\fs22\insrsid9786739 OR US$5.00.\~ - THE FOREGOING LIMITATIONS, EXCLUSIONS AND DISCLAIMERS SHALL APPLY TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, EVEN IF ANY REMEDY FAILS ITS ESSENTIAL PURPOSE.}{\insrsid9786739 -\par }{\f39\fs22\insrsid9786739 1}{\f39\fs22\insrsid14113652 3}{\f39\fs22\insrsid9786739 .\~\~\~\~\~\~ }{\b\f39\fs22\insrsid9786739 APPLICABLE LAW.\~ }{\f39\fs22\insrsid7735936 T}{\f39\fs22\insrsid9786739 his EULA }{\f39\fs22\insrsid7735936 -shall be construed under and }{\f39\fs22\insrsid9786739 governed by the laws of the State of Washington}{\f39\fs22\insrsid7735936 , without regard to conflicts of law principles}{\f39\fs22\insrsid9786739 .\~ }{\insrsid9786739 -\par }\pard\plain \s20\qj \li0\ri0\sb100\sa100\sbauto1\saauto1\sl240\slmult0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid14100361 \f40\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\f39\insrsid9786739 1}{\f39\insrsid14113652 -4}{\f39\insrsid9786739 .\~\~\~\~ }{\b\f39\insrsid9786739 ENTIRE AGREEMENT; SEVERABILITY.\~ }{\f39\insrsid9786739 This -EULA (including any addendum or amendment to this EULA which is included with the Software) are the entire agreement between you and Microsoft relating to the Software and the support services (if any) and they supersede all prior or contemporaneous oral -or written communications,\~proposals and representations with respect to the Software or any other subject matter covered by this EULA.\~ - If any provision of this EULA is held to be void, invalid, unenforceable or illegal, the other provisions shall continue in full force and effect}{\insrsid9786739 -\par }\pard\plain \qj \li0\ri0\sb100\sa100\sbauto1\saauto1\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid14100361 \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\insrsid10440675 +{\rtf1\ansi\ansicpg1252\uc1\deff0\stshfdbch0\stshfloch0\stshfhich0\stshfbi0\deflang1033\deflangfe1033{\fonttbl{\f0\froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f37\fswiss\fcharset0\fprq2{\*\panose 020b0604030504040204}Tahoma;} +{\f39\froman\fcharset0\fprq2{\*\panose 02040602050305030304}Book Antiqua;}{\f40\fswiss\fcharset0\fprq2{\*\panose 020b0706030402020204}Franklin Gothic Demi Cond;}{\f41\fswiss\fcharset0\fprq2{\*\panose 020b0503020102020204}Franklin Gothic Book;} +{\f42\froman\fcharset238\fprq2 Times New Roman CE;}{\f43\froman\fcharset204\fprq2 Times New Roman Cyr;}{\f45\froman\fcharset161\fprq2 Times New Roman Greek;}{\f46\froman\fcharset162\fprq2 Times New Roman Tur;} +{\f47\froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\f48\froman\fcharset178\fprq2 Times New Roman (Arabic);}{\f49\froman\fcharset186\fprq2 Times New Roman Baltic;}{\f50\froman\fcharset163\fprq2 Times New Roman (Vietnamese);} +{\f412\fswiss\fcharset238\fprq2 Tahoma CE;}{\f413\fswiss\fcharset204\fprq2 Tahoma Cyr;}{\f415\fswiss\fcharset161\fprq2 Tahoma Greek;}{\f416\fswiss\fcharset162\fprq2 Tahoma Tur;}{\f417\fswiss\fcharset177\fprq2 Tahoma (Hebrew);} +{\f418\fswiss\fcharset178\fprq2 Tahoma (Arabic);}{\f419\fswiss\fcharset186\fprq2 Tahoma Baltic;}{\f420\fswiss\fcharset163\fprq2 Tahoma (Vietnamese);}{\f421\fswiss\fcharset222\fprq2 Tahoma (Thai);}{\f432\froman\fcharset238\fprq2 Book Antiqua CE;} +{\f433\froman\fcharset204\fprq2 Book Antiqua Cyr;}{\f435\froman\fcharset161\fprq2 Book Antiqua Greek;}{\f436\froman\fcharset162\fprq2 Book Antiqua Tur;}{\f439\froman\fcharset186\fprq2 Book Antiqua Baltic;} +{\f442\fswiss\fcharset238\fprq2 Franklin Gothic Demi Cond CE;}{\f443\fswiss\fcharset204\fprq2 Franklin Gothic Demi Cond Cyr;}{\f445\fswiss\fcharset161\fprq2 Franklin Gothic Demi Cond Greek;}{\f446\fswiss\fcharset162\fprq2 Franklin Gothic Demi Cond Tur;} +{\f449\fswiss\fcharset186\fprq2 Franklin Gothic Demi Cond Baltic;}{\f452\fswiss\fcharset238\fprq2 Franklin Gothic Book CE;}{\f453\fswiss\fcharset204\fprq2 Franklin Gothic Book Cyr;}{\f455\fswiss\fcharset161\fprq2 Franklin Gothic Book Greek;} +{\f456\fswiss\fcharset162\fprq2 Franklin Gothic Book Tur;}{\f459\fswiss\fcharset186\fprq2 Franklin Gothic Book Baltic;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255; +\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;\red192\green192\blue192;} +{\stylesheet{\ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \snext0 Normal;}{\*\cs10 \additive \ssemihidden Default Paragraph Font;}{\* +\ts11\tsrowd\trftsWidthB3\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\trcbpat1\trcfpat1\tscellwidthfts0\tsvertalt\tsbrdrt\tsbrdrl\tsbrdrb\tsbrdrr\tsbrdrdgl\tsbrdrdgr\tsbrdrh\tsbrdrv +\ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \fs20\lang1024\langfe1024\cgrid\langnp1024\langfenp1024 \snext11 \ssemihidden Normal Table;}{\s15\ql \fi-274\li274\ri0\sb120\sl460\slmult0 +\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin274\itap0 \f40\fs44\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon0 \snext15 \styrsid9786739 1sectionhead;}{\s16\ql \li0\ri0\sb120\sl200\slmult0 +\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \caps\f40\fs16\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon0 \snext16 \styrsid9786739 4laparahead;}{\s17\ql \li0\ri-18\sb120\sl240\slmult0 +\widctlpar\aspalpha\aspnum\faauto\adjustright\rin-18\lin0\itap0 \f40\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon0 \snext17 \styrsid9786739 2lasubhead;}{\s18\ql \fi-187\li187\ri0\sb60\sl180\slmult0 +\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin187\itap0 \f41\fs16\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon0 \snext18 \styrsid9786739 3cnumbered;}{\s19\ql \fi-340\li624\ri0\sb60\sl160\slmult0 +\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin624\itap0 \f41\fs14\cf1\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon0 \snext19 \styrsid9786739 3inumbered2ndlevel;}{\s20\ql \li0\ri0\sb240\sl240\slmult0 +\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \f40\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon0 \snext20 \styrsid9786739 2afrenchsubhead;}{\s21\ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 +\cbpat9 \f37\fs20\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon0 \snext21 \ssemihidden \styrsid7154712 Document Map;}}{\*\latentstyles\lsdstimax156\lsdlockeddef0}{\*\pgptbl {\pgp\ipgp2\itap0\li0\ri0\sb0\sa0\brdrt\brdrs\brdrw20 }{\pgp\ipgp0 +\itap0\li0\ri0\sb0\sa0}}{\*\rsidtbl \rsid2099452\rsid4207571\rsid5465292\rsid5510097\rsid5510644\rsid7154712\rsid7241305\rsid7672529\rsid7735936\rsid9179139\rsid9786739\rsid10440675\rsid11303133\rsid13130884\rsid14028235\rsid14100361\rsid14113652 +\rsid15276140\rsid16213514}{\*\generator Microsoft Word 11.0.6359;}{\info{\title ILMerge EULA}{\author Ken Leppert}{\operator mbarnett}{\creatim\yr2005\mo3\dy16\hr15\min43}{\revtim\yr2005\mo3\dy16\hr15\min43}{\printim\yr2004\mo4\dy30\hr13\min9}{\version2} +{\edmins0}{\nofpages3}{\nofwords1188}{\nofchars6775}{\*\company Microsoft Corporation}{\nofcharsws7948}{\vern24703}}\widowctrl\ftnbj\aenddoc\noxlattoyen\expshrtn\noultrlspc\dntblnsbdb\nospaceforul\formshade\horzdoc\dgmargin\dghspace180\dgvspace180 +\dghorigin1800\dgvorigin1440\dghshow1\dgvshow1\jexpand\viewkind1\viewscale68\viewzk2\pgbrdrhead\pgbrdrfoot\splytwnine\ftnlytwnine\htmautsp\nolnhtadjtbl\useltbaln\alntblind\lytcalctblwd\lyttblrtgr\lnbrkrule\nobrkwrptbl\snaptogridincell\allowfieldendsel +\wrppunct\asianbrkrule\rsidroot9786739\newtblstyruls\nogrowautofit \fet0\sectd \linex0\endnhere\sectlinegrid360\sectdefaultcl\sftnbj {\*\pnseclvl1\pnucrm\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl2\pnucltr\pnstart1\pnindent720\pnhang +{\pntxta .}}{\*\pnseclvl3\pndec\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl4\pnlcltr\pnstart1\pnindent720\pnhang {\pntxta )}}{\*\pnseclvl5\pndec\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl6\pnlcltr\pnstart1\pnindent720\pnhang +{\pntxtb (}{\pntxta )}}{\*\pnseclvl7\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl8\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl9\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}\pard\plain +\s15\ql \li0\ri0\sb100\sa100\sbauto1\saauto1\widctlpar\aspalpha\aspnum\faauto\outlinelevel0\adjustright\rin0\lin0\itap0\pararsid7154712 \f40\fs44\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\b\f39\fs28\insrsid9786739 MICROSOFT }{ +\b\f39\fs28\insrsid5465292 ILMerge}{\insrsid9786739 +\par }{\b\f39\fs22\insrsid9786739 END-USER LICENSE AGREEMENT FOR MICROSOFT SOFTWARE}{\insrsid9786739 +\par }\pard\plain \s17\qj \li0\ri-17\sb100\sa100\sbauto1\saauto1\widctlpar\aspalpha\aspnum\faauto\adjustright\rin-17\lin0\itap0\pararsid14100361 \f40\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\b\f39\insrsid9786739 IMPORTANT\emdash +READ CAREFULLY: }{\f39\insrsid9786739 This End-User License Agreement (\'93EULA\'94) is a legal agreement between you (either an individual or a single entity) and Microsoft Corporation (\'93Microsoft\'94) for th +e Microsoft software that accompanies this EULA, which includes computer software and may include associated media, printed materials, \'93online\'94 or electronic documentation, and Internet-based services (\'93Software\'94).\~ + An amendment or addendum to this EULA may accompany the Software.\~ }{\b\f39\insrsid9786739 +YOU AGREE TO BE BOUND BY THE TERMS OF THIS EULA BY INSTALLING, COPYING, OR OTHERWISE USING THE SOFTWARE. IF YOU DO NOT AGREE, DO NOT INSTALL, COPY, OR USE THE SOFTWARE.}{\insrsid9786739 +\par }\pard\plain \qj \li0\ri0\sb100\sa100\sbauto1\saauto1\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid14100361 \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\f39\fs22\insrsid9786739 1.\~\~\~\~\~\~\~\~ }{ +\b\f39\fs22\insrsid9786739 GRANTS OF LICENSE}{\f39\fs22\insrsid9786739 . Microsoft grants you the rights described in this EULA provided that you comply with all terms and conditions of this EULA.\~ }{\insrsid9786739 +\par }\pard\plain \s19\qj \fi720\li0\ri0\sb100\sa100\sbauto1\saauto1\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid14100361 \f41\fs14\cf1\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\f39\fs22\cf0\insrsid9786739 1.1\~\~\~\~\~\~ }{ +\b\i\f39\fs22\cf0\insrsid9786739 License Grant}{\f39\fs22\cf0\insrsid9786739 . Microsoft grants to you a personal, nonexclusive, nontransferable, limited license to }{\f39\fs22\insrsid9786739 install and use a reasonable number of copies of +the Software on computers residing on your premises }{\f39\fs22\cf0\insrsid9786739 for the purposes of designing, developing, and testing, your software product(s), provided that you are the only individual using the Software.\~ }{\insrsid9786739 +\par }\pard\plain \s18\qj \fi720\li0\ri0\sb100\sa100\sbauto1\saauto1\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid14100361 \f41\fs16\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\f39\fs22\insrsid9786739 1.2\~\~\~\~\~\~ }{ +\b\i\f39\fs22\insrsid9786739 Documentation}{\f39\fs22\insrsid9786739 .}{\b\f39\fs22\insrsid9786739 \~ }{\f39\fs22\insrsid9786739 You may make and use a reasonabl +e number of copies of any documentation, provided that such copies shall be used only for your personal purposes and are not to be republished or distributed (either in hard copy or electronic form) beyond your premises.}{\insrsid9786739 +\par }\pard \s18\qj \li0\ri0\sb100\sa100\sbauto1\saauto1\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid14100361 {\f39\fs22\insrsid9786739 2.\~\~\~\~\~\~\~\~ }{\b\f39\fs22\insrsid9786739 RESERVATION OF RIGHTS AND OWNERSHIP.\~ }{ +\f39\fs22\insrsid9786739 The Software is licensed as a single product.\~ Its component parts may not be separated. Microsoft reserves all rights not expressly granted to you in this EULA.\~ + The Software is protected by copyright and other intellectual property laws and treaties}{\f39\fs22\insrsid14028235 , and}{\f39\fs22\insrsid9786739 Microsoft }{\f39\fs22\insrsid14028235 (}{\f39\fs22\insrsid9786739 or its suppliers}{ +\f39\fs22\insrsid14028235 , where applicable)}{\f39\fs22\insrsid9786739 own }{\f39\fs22\insrsid14028235 all right, }{\f39\fs22\insrsid9786739 title, }{\f39\fs22\insrsid14028235 and interest in all }{\f39\fs22\insrsid9786739 +intellectual property rights in the Software.\~ }{\b\f39\fs22\insrsid9786739 The Software is licensed, not sold.}{\insrsid9786739 +\par }\pard\plain \s19\qj \li0\ri0\sb100\sa100\sbauto1\saauto1\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid14100361 \f41\fs14\cf1\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\f39\fs22\cf0\insrsid9786739 3.\~\~\~\~\~\~\~\~ }{ +\b\f39\fs22\cf0\insrsid9786739 LIMITATIONS ON REVERSE ENGINEERING, DECOMPILATION, AND DISASSEMBLY}{\b\i\f39\fs22\cf0\insrsid9786739 .}{\f39\fs22\cf0\insrsid9786739 \~ + You may not reverse engineer, decompile, or disassemble the Software, except and only to the extent that such activity is expressly permitted by applicable law notwithstanding this limitation.}{\insrsid9786739 +\par }\pard\plain \s18\qj \li0\ri0\sb100\sa100\sbauto1\saauto1\sl220\slmult0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid14100361 \f41\fs16\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\f39\fs22\insrsid9786739 4.\~\~\~\~\~\~\~\~ +}{\b\f39\fs22\insrsid9786739 NO RENTAL/COMMERCIAL HOSTING.}{\b\i\f39\fs22\insrsid9786739 }{\f39\fs22\insrsid9786739 You may not rent, lease, lend or provide commercial hosting services with the Software.}{\insrsid9786739 +\par }\pard\plain \s19\qj \li0\ri0\sb100\sa100\sbauto1\saauto1\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid14100361 \f41\fs14\cf1\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\f39\fs22\cf0\insrsid9786739 5.\~\~\~\~\~\~\~\~ }{ +\b\f39\fs22\cf0\insrsid9786739 NO SOFTWARE TRANSFER.\~ }{\f39\fs22\cf0\insrsid9786739 You may not assign or otherwise transfer the SOFTWARE or any of your rights hereunder to any third party.}{\insrsid9786739 +\par }{\f39\fs22\cf0\insrsid9786739 6.\~\~\~\~\~\~\~\~ }{\b\f39\fs22\cf0\insrsid9786739 CONSENT TO USE OF DATA.\~ }{\f39\fs22\cf0\insrsid9786739 You + agree that Microsoft and its affiliates may collect and use technical information gathered as part of the product support services provided to you, if any, related to the Software.\~ + Microsoft may use this information solely to improve our products or to provide customized services or technologies to you and will not disclose this information in a form that personally identifies you.\~\~ }{\insrsid9786739 +\par }{\f39\fs22\cf0\insrsid5510644 7}{\f39\fs22\cf0\insrsid9786739 .\~\~\~\~\~\~\~\~ }{\b\f39\fs22\cf0\insrsid9786739 ADDITIONAL SOFTWARE/SERVICES.\~ }{\f39\fs22\insrsid9786739 Microsoft is not obligated to provide maintenance, technical supplements}{ +\f39\fs22\insrsid14028235 , updates,}{\f39\fs22\insrsid9786739 or other support to you for the Software licensed under this EULA. }{\f39\fs22\insrsid7241305 }{\f39\fs22\insrsid9786739 In the event that Microsoft does provide such supplements or updates} +{\b\f39\fs22\insrsid9786739 , }{\f39\fs22\insrsid9786739 this EULA applies to such updates, supplements, or add-on components of the Software that Microsoft may provide to +you or make available to you after the date you obtain your initial copy of the Software, unless we provide other terms along with the update, supplement, or add-on component}{\f39\fs22\cf0\insrsid9786739 .\~ + Microsoft reserves the right to discontinue any Internet-based services provided to you or made available to you through the use of the Software.\~ }{\insrsid9786739 +\par }\pard\plain \s18\qj \li0\ri0\sb100\sa100\sbauto1\saauto1\sl220\slmult0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid14100361 \f41\fs16\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\f39\fs22\insrsid5510644 8}{ +\f39\fs22\insrsid9786739 .\~\~\~\~\~\~\~\~ }{\b\f39\fs22\insrsid9786739 EXPORT RESTRICTIONS}{\f39\fs22\insrsid9786739 .\~ }{\f39\fs22\cgrid0\insrsid9786739 You acknowledge that the Software is subject to U.S. export jurisdiction.\~ + You agree to comply with all applicable international and national laws that apply to the Software, including the U.S. Export Administration Regulations, as well as end-user, end-use, and destination restrictions issued by U.S. and other governments.\~\~ + For additional information see }{\f39\fs22\ul\cgrid0\insrsid9786739 http://www.microsoft.com/exporting/}{\f39\fs22\cgrid0\insrsid9786739 .}{\insrsid9786739 +\par }\pard\plain \s19\qj \li0\ri0\sb100\sa100\sbauto1\saauto1\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid14100361 \f41\fs14\cf1\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\f39\fs22\cf0\insrsid14113652 9}{ +\f39\fs22\cf0\insrsid9786739 .\~\~\~\~\~\~ }{\b\f39\fs22\cf0\insrsid9786739 TERMINATION.}{\f39\fs22\cf0\insrsid9786739 \~ Without prejudice to any other rights, Microsoft may terminate this EULA if you fail to comply with }{\f39\fs22\cf0\insrsid7241305 +any }{\f39\fs22\cf0\insrsid9786739 term}{\f39\fs22\cf0\insrsid7241305 or}{\f39\fs22\cf0\insrsid9786739 condition of this EULA. }{\f39\fs22\cf0\insrsid7241305 }{\f39\fs22\cf0\insrsid9786739 +In such event, you must destroy all copies of the Software and all of its component parts.}{\insrsid9786739 +\par }\pard\plain \s18\qj \li0\ri0\sb100\sa100\sbauto1\saauto1\sl220\slmult0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid14100361 \f41\fs16\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\f39\fs22\insrsid9786739 1}{ +\f39\fs22\insrsid14113652 0}{\f39\fs22\insrsid9786739 .\~\~\~\~\~\~ }{\b\f39\fs22\ul\insrsid9786739 DISCLAIMER OF WARRANTIES}{\b\f39\fs22\insrsid9786739 .\~ + TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND ITS SUPPLIERS PROVIDE THE SOFTWARE}{\f39\fs22\insrsid9786739 }{\b\f39\fs22\insrsid9786739 AND SUPPORT SERVICES (IF ANY) }{\b\i\f39\fs22\insrsid9786739 AS IS AND WITH ALL FAULTS}{ +\b\f39\fs22\insrsid9786739 , AND HEREBY DISCLAIM ALL OTHER WARRANTIES AND CONDITIONS, WHETHER EXPRESS, IMPLIED + OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY (IF ANY) IMPLIED WARRANTIES, DUTIES OR CONDITIONS OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR PURPOSE, OF RELIABILITY OR AVAILABILITY, OF ACCURACY OR COMPLETENESS OF RESPONSES, OF RESULTS, OF WORKMANLI +K +E EFFORT, OF LACK OF VIRUSES, AND OF LACK OF NEGLIGENCE, ALL WITH REGARD TO THE SOFTWARE, AND THE PROVISION OF OR FAILURE TO PROVIDE SUPPORT OR OTHER SERVICES, INFORMATION, SOFTWARE, AND RELATED CONTENT THROUGH THE SOFTWARE OR OTHERWISE ARISING OUT OF THE + USE OF THE SOFTWARE.\~ ALSO, THERE IS NO WARRANTY OR CONDITION OF TITLE, QUIET ENJOYMENT, QUIET POSSESSION, CORRESPONDENCE TO DESCRIPTION OR NON-INFRINGEMENT WITH REGARD TO THE SOFTWARE.}{\insrsid9786739 +\par }{\f39\fs22\insrsid9786739 1}{\f39\fs22\insrsid14113652 1}{\f39\fs22\insrsid9786739 .}{\b\f39\fs22\insrsid9786739 \~\~\~\~\~\~ }{\b\f39\fs22\ul\insrsid9786739 EXCLUSION OF INCIDENTAL, CONSEQUENTIAL AND CERTAIN OTHER DAMAGES}{\b\f39\fs22\insrsid9786739 .\~ + }{\b\caps\f39\fs22\insrsid9786739 +To the maximum extent permitted by applicable law, in no event shall Microsoft or its suppliers be liable for any special, incidental, punitive, indirect, or consequential damages whatsoever (including, but not limited to, damages for loss of profit +s, LOSS OF DATA, or confidential or other information}{\b\f39\fs22\insrsid9786739 , }{\b\caps\f39\fs22\insrsid9786739 +for business interruption, for personal injury, for loss of privacy, for failure to meet any duty including of good faith or of reasonable care, for negligence, and}{\b\f39\fs22\insrsid9786739 }{\b\caps\f39\fs22\insrsid9786739 +for any other pecuniary or other los +s whatsoever) arising out of or in any way related to the use of or inability to use the SOFTWARE, the provision of or failure to provide Support OR OTHER Services, informatIon, software, and related CONTENT through the software or otherwise arising out o +f + the use of the software, or otherwise under or in connection with any provision of this EULA, even in the event of the fault, tort (including negligence), misrepresentation, strict liability, breach of contract or breach of warranty of Microsoft or any s +upplier, and even if Microsoft or any supplier has been advised of the possibility of such damages. }{\insrsid9786739 +\par }{\f39\fs22\insrsid9786739 1}{\f39\fs22\insrsid14113652 2}{\f39\fs22\insrsid9786739 .}{\b\f39\fs22\insrsid9786739 \~\~\~\~\~\~ }{\b\f39\fs22\ul\insrsid9786739 LIMITATION OF LIABILITY AND REMEDIES}{\b\f39\fs22\insrsid9786739 +. NOTWITHSTANDING ANY DAMAGES THAT YOU MIGHT INCUR FOR ANY REASON WHATSOEVER (INCLUDING, WITHOUT LIMITATION, A +LL DAMAGES REFERENCED HEREIN AND ALL DIRECT OR GENERAL DAMAGES IN CONTRACT OR ANYTHING ELSE), THE ENTIRE LIABILITY OF MICROSOFT AND ANY OF ITS SUPPLIERS UNDER ANY PROVISION OF THIS EULA AND YOUR EXCLUSIVE REMEDY HEREUNDER SHALL BE LIMITED TO THE GREATER O +F THE ACTUAL DAMAGES YOU INCUR IN REASONABLE RELIANCE ON THE SOFTWARE UP TO THE AMOUNT ACTUALLY PAID BY YOU FOR THE SOFTWARE}{\f39\fs22\insrsid9786739 }{\b\f39\fs22\insrsid9786739 OR US$5.00.\~ + THE FOREGOING LIMITATIONS, EXCLUSIONS AND DISCLAIMERS SHALL APPLY TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, EVEN IF ANY REMEDY FAILS ITS ESSENTIAL PURPOSE.}{\insrsid9786739 +\par }{\f39\fs22\insrsid9786739 1}{\f39\fs22\insrsid14113652 3}{\f39\fs22\insrsid9786739 .\~\~\~\~\~\~ }{\b\f39\fs22\insrsid9786739 APPLICABLE LAW.\~ }{\f39\fs22\insrsid7735936 T}{\f39\fs22\insrsid9786739 his EULA }{\f39\fs22\insrsid7735936 +shall be construed under and }{\f39\fs22\insrsid9786739 governed by the laws of the State of Washington}{\f39\fs22\insrsid7735936 , without regard to conflicts of law principles}{\f39\fs22\insrsid9786739 .\~ }{\insrsid9786739 +\par }\pard\plain \s20\qj \li0\ri0\sb100\sa100\sbauto1\saauto1\sl240\slmult0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid14100361 \f40\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\f39\insrsid9786739 1}{\f39\insrsid14113652 +4}{\f39\insrsid9786739 .\~\~\~\~ }{\b\f39\insrsid9786739 ENTIRE AGREEMENT; SEVERABILITY.\~ }{\f39\insrsid9786739 This +EULA (including any addendum or amendment to this EULA which is included with the Software) are the entire agreement between you and Microsoft relating to the Software and the support services (if any) and they supersede all prior or contemporaneous oral +or written communications,\~proposals and representations with respect to the Software or any other subject matter covered by this EULA.\~ + If any provision of this EULA is held to be void, invalid, unenforceable or illegal, the other provisions shall continue in full force and effect}{\insrsid9786739 +\par }\pard\plain \qj \li0\ri0\sb100\sa100\sbauto1\saauto1\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid14100361 \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\insrsid10440675 \par }} \ No newline at end of file diff --git a/UnitTests.Silverlight/App.xaml b/UnitTests.Silverlight/App.xaml index ba4b34551..417dc20d1 100644 --- a/UnitTests.Silverlight/App.xaml +++ b/UnitTests.Silverlight/App.xaml @@ -1,4 +1,4 @@ - \ No newline at end of file diff --git a/UnitTests.Silverlight/App.xaml.cs b/UnitTests.Silverlight/App.xaml.cs index 2fde1ffde..22605433e 100644 --- a/UnitTests.Silverlight/App.xaml.cs +++ b/UnitTests.Silverlight/App.xaml.cs @@ -1,69 +1,69 @@ -using System; -using System.Diagnostics; -using System.Windows; -using Microsoft.Silverlight.Testing; -using Microsoft.Silverlight.Testing.UnitTesting.Metadata.XunitLight; -using System.Windows.Browser; - -namespace Moq.Tests.Silverlight -{ - public partial class App : Application - { - public App() - { - this.Startup += this.OnApplicationStartup; - this.Exit += this.OnApplicationExit; - this.UnhandledException += this.OnApplicationUnhandledException; - - this.InitializeComponent(); - } - - private void OnApplicationStartup(object sender, StartupEventArgs e) - { - /* - * Wire the XunitLight test harness provider into the silverlight testing framework - */ - UnitTestSystem.RegisterUnitTestProvider(new XUnitTestProvider()); - - this.RootVisual = UnitTestSystem.CreateTestPage(); - } - - private void OnApplicationExit(object sender, EventArgs e) - { - } - - private void OnApplicationUnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) - { - // If the app is running outside of the debugger then report the exception using - // the browser's exception mechanism. On IE this will display it a yellow alert - // icon in the status bar and Firefox will display a script error. - if (!Debugger.IsAttached) - { - - // NOTE: This will allow the application to continue running after an exception has been thrown - // but not handled. - // For production applications this error handling should be replaced with something that will - // report the error to the website and stop the application. - e.Handled = true; - Deployment.Current.Dispatcher.BeginInvoke( - (Action)this.ReportErrorToDOM, - e); - } - } - - private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e) - { - try - { - var errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace - .Replace('"', '\'') - .Replace("\r\n", @"\n"); - - HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight 2 Application " + errorMsg + "\");"); - } - catch (Exception) - { - } - } - } +using System; +using System.Diagnostics; +using System.Windows; +using Microsoft.Silverlight.Testing; +using Microsoft.Silverlight.Testing.UnitTesting.Metadata.XunitLight; +using System.Windows.Browser; + +namespace Moq.Tests.Silverlight +{ + public partial class App : Application + { + public App() + { + this.Startup += this.OnApplicationStartup; + this.Exit += this.OnApplicationExit; + this.UnhandledException += this.OnApplicationUnhandledException; + + this.InitializeComponent(); + } + + private void OnApplicationStartup(object sender, StartupEventArgs e) + { + /* + * Wire the XunitLight test harness provider into the silverlight testing framework + */ + UnitTestSystem.RegisterUnitTestProvider(new XUnitTestProvider()); + + this.RootVisual = UnitTestSystem.CreateTestPage(); + } + + private void OnApplicationExit(object sender, EventArgs e) + { + } + + private void OnApplicationUnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) + { + // If the app is running outside of the debugger then report the exception using + // the browser's exception mechanism. On IE this will display it a yellow alert + // icon in the status bar and Firefox will display a script error. + if (!Debugger.IsAttached) + { + + // NOTE: This will allow the application to continue running after an exception has been thrown + // but not handled. + // For production applications this error handling should be replaced with something that will + // report the error to the website and stop the application. + e.Handled = true; + Deployment.Current.Dispatcher.BeginInvoke( + (Action)this.ReportErrorToDOM, + e); + } + } + + private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e) + { + try + { + var errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace + .Replace('"', '\'') + .Replace("\r\n", @"\n"); + + HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight 2 Application " + errorMsg + "\");"); + } + catch (Exception) + { + } + } + } } \ No newline at end of file diff --git a/UnitTests.Silverlight/Properties/AppManifest.xml b/UnitTests.Silverlight/Properties/AppManifest.xml index 75b9aa359..6d0aa768a 100644 --- a/UnitTests.Silverlight/Properties/AppManifest.xml +++ b/UnitTests.Silverlight/Properties/AppManifest.xml @@ -1,6 +1,6 @@ - - - - + + + + diff --git a/UnitTests.Silverlight/Properties/AssemblyInfo.cs b/UnitTests.Silverlight/Properties/AssemblyInfo.cs index 69662d5f4..7364d33d1 100644 --- a/UnitTests.Silverlight/Properties/AssemblyInfo.cs +++ b/UnitTests.Silverlight/Properties/AssemblyInfo.cs @@ -1,31 +1,31 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Moq.Tests.Silverlight")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Moq.Tests.Silverlight")] -[assembly: AssemblyCopyright("Copyright © 2008")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Revision and Build Numbers -// by using the '*' as shown below: -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Moq.Tests.Silverlight")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Moq.Tests.Silverlight")] +[assembly: AssemblyCopyright("Copyright © 2008")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/UnitTests.Silverlight/Regressions/DynamicProxyFixture.cs b/UnitTests.Silverlight/Regressions/DynamicProxyFixture.cs index 5e6801d99..15341196e 100644 --- a/UnitTests.Silverlight/Regressions/DynamicProxyFixture.cs +++ b/UnitTests.Silverlight/Regressions/DynamicProxyFixture.cs @@ -1,37 +1,37 @@ -using System; -using System.Net; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Documents; -using System.Windows.Ink; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Animation; -using System.Windows.Shapes; -using Xunit; -using Castle.DynamicProxy; - -namespace Moq.Tests.Regressions -{ - public class DynamicProxyFixture - { - [Fact] - public void CanProxyClassWithProtectedAbstractMethod() - { - new ProxyGenerator().CreateClassProxy(new ProxyGenerationOptions()); - } - - [Fact] - public void CanMockClassWithProtectedAbstractMethods() - { - var mock = new Mock(); - - Assert.NotNull(mock.Object); - } - - public abstract class TestClass - { - protected abstract void Foo(); - } - } +using System; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Ink; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Shapes; +using Xunit; +using Castle.DynamicProxy; + +namespace Moq.Tests.Regressions +{ + public class DynamicProxyFixture + { + [Fact] + public void CanProxyClassWithProtectedAbstractMethod() + { + new ProxyGenerator().CreateClassProxy(new ProxyGenerationOptions()); + } + + [Fact] + public void CanMockClassWithProtectedAbstractMethods() + { + var mock = new Mock(); + + Assert.NotNull(mock.Object); + } + + public abstract class TestClass + { + protected abstract void Foo(); + } + } } \ No newline at end of file diff --git a/UnitTests.Visualizer/MockContextViewModelFixture.cs b/UnitTests.Visualizer/MockContextViewModelFixture.cs index c3c863431..2ab79d2e6 100644 --- a/UnitTests.Visualizer/MockContextViewModelFixture.cs +++ b/UnitTests.Visualizer/MockContextViewModelFixture.cs @@ -1,95 +1,95 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Globalization; -using System.Linq; -using Xunit; - -namespace Moq.Visualizer.Tests -{ - public class MockContextViewModelFixture - { - [Fact] - public void CtorSetsBehavior() - { - var target = new MockContextViewModel(new Mock(MockBehavior.Strict)); - - Assert.Equal(MockBehavior.Strict, target.Behavior); - } - - [Fact] - public void CtorSetsCallBase() - { - var target = new MockContextViewModel(new Mock { CallBase = false }); - - Assert.Equal(false, target.CallBase); - } - - [Fact] - public void CtorSetsDefaultValue() - { - var target = new MockContextViewModel(new Mock { DefaultValue = DefaultValue.Empty }); - - Assert.Equal(DefaultValue.Empty, target.DefaultValue); - } - - [Fact] - public void AddExpandedMockViewModelToMocks() - { - var target = new MockContextViewModel(new Mock()); - - Assert.Equal(1, target.Mocks.Count()); - Assert.NotNull(target.Mocks.ElementAt(0)); - Assert.True(target.Mocks.ElementAt(0).IsExpanded); - } - - [Fact] - public void AddExpandedSetupViewModelToContainers() - { - var mock = new Mock(); - //mock.Setup(c => c.ToString(It.IsAny())); - //mock.Setup(c => c.ToSingle(It.IsAny())); - - var target = new MockContextViewModel(mock); - - var setup = (ContainerViewModel)target.Mocks.ElementAt(0) - .Containers.Single(c => c.Name == "Setups"); - Assert.NotNull(setup); - //Assert.Equal(2, setup.Children.Count()); - Assert.True(setup.IsExpanded); - } - - [Fact] - public void AddExpandedOtherCallsViewModelToMockContainers() - { - var mock = new Mock(); - mock.Setup(c => c.ToString(It.IsAny())); - //mock.Object.ToString(CultureInfo.CurrentCulture); - //mock.Object.ToChar(CultureInfo.CurrentCulture); - //mock.Object.ToDateTime(CultureInfo.CurrentCulture); - - var target = new MockContextViewModel(mock); - - var call = (ContainerViewModel)target.Mocks.ElementAt(0) - .Containers.Single(c => c.Name == "Invocations without setup"); - Assert.NotNull(call); - //Assert.Equal(2, call.Children.Count()); - Assert.True(call.IsExpanded); - } - - [Fact] - public void AddExpandedMockViewModelToInnerMockContainers() - { - var mock = new Mock>(); - //mock.Setup(c => c[0].ToString(It.IsAny(), It.IsAny())); - - var target = new MockContextViewModel(mock); - - var call = (ContainerViewModel)target.Mocks.ElementAt(0) - .Containers.Single(c => c.Name == "Inner Mocks"); - Assert.NotNull(call); - //Assert.Equal(1, call.Children.Count()); - Assert.True(call.IsExpanded); - } - } +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Globalization; +using System.Linq; +using Xunit; + +namespace Moq.Visualizer.Tests +{ + public class MockContextViewModelFixture + { + [Fact] + public void CtorSetsBehavior() + { + var target = new MockContextViewModel(new Mock(MockBehavior.Strict)); + + Assert.Equal(MockBehavior.Strict, target.Behavior); + } + + [Fact] + public void CtorSetsCallBase() + { + var target = new MockContextViewModel(new Mock { CallBase = false }); + + Assert.Equal(false, target.CallBase); + } + + [Fact] + public void CtorSetsDefaultValue() + { + var target = new MockContextViewModel(new Mock { DefaultValue = DefaultValue.Empty }); + + Assert.Equal(DefaultValue.Empty, target.DefaultValue); + } + + [Fact] + public void AddExpandedMockViewModelToMocks() + { + var target = new MockContextViewModel(new Mock()); + + Assert.Equal(1, target.Mocks.Count()); + Assert.NotNull(target.Mocks.ElementAt(0)); + Assert.True(target.Mocks.ElementAt(0).IsExpanded); + } + + [Fact] + public void AddExpandedSetupViewModelToContainers() + { + var mock = new Mock(); + //mock.Setup(c => c.ToString(It.IsAny())); + //mock.Setup(c => c.ToSingle(It.IsAny())); + + var target = new MockContextViewModel(mock); + + var setup = (ContainerViewModel)target.Mocks.ElementAt(0) + .Containers.Single(c => c.Name == "Setups"); + Assert.NotNull(setup); + //Assert.Equal(2, setup.Children.Count()); + Assert.True(setup.IsExpanded); + } + + [Fact] + public void AddExpandedOtherCallsViewModelToMockContainers() + { + var mock = new Mock(); + mock.Setup(c => c.ToString(It.IsAny())); + //mock.Object.ToString(CultureInfo.CurrentCulture); + //mock.Object.ToChar(CultureInfo.CurrentCulture); + //mock.Object.ToDateTime(CultureInfo.CurrentCulture); + + var target = new MockContextViewModel(mock); + + var call = (ContainerViewModel)target.Mocks.ElementAt(0) + .Containers.Single(c => c.Name == "Invocations without setup"); + Assert.NotNull(call); + //Assert.Equal(2, call.Children.Count()); + Assert.True(call.IsExpanded); + } + + [Fact] + public void AddExpandedMockViewModelToInnerMockContainers() + { + var mock = new Mock>(); + //mock.Setup(c => c[0].ToString(It.IsAny(), It.IsAny())); + + var target = new MockContextViewModel(mock); + + var call = (ContainerViewModel)target.Mocks.ElementAt(0) + .Containers.Single(c => c.Name == "Inner Mocks"); + Assert.NotNull(call); + //Assert.Equal(1, call.Children.Count()); + Assert.True(call.IsExpanded); + } + } } \ No newline at end of file diff --git a/UnitTests.Visualizer/Moq.Visualizer.Tests.csproj b/UnitTests.Visualizer/Moq.Visualizer.Tests.csproj index 599dee8ea..89bff8667 100644 --- a/UnitTests.Visualizer/Moq.Visualizer.Tests.csproj +++ b/UnitTests.Visualizer/Moq.Visualizer.Tests.csproj @@ -1,115 +1,115 @@ - - - - Debug - AnyCPU - 9.0.30729 - 2.0 - {A84563A0-8A70-43D9-A1C0-530955413318} - Library - Properties - Moq.Visualizer.Tests - Moq.Visualizer.Tests - v4.0 - 512 - true - ..\Moq.snk - - - 3.5 - - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - AllRules.ruleset - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - AllRules.ruleset - - - - - 3.5 - - - - - False - ..\Lib\xUnit\xunit.dll - - - - - - - - - - {1C91AC30-5977-4BE5-BA67-8EB186C03514} - Moq - - - - - Moq.snk - - - - - False - .NET Framework 3.5 SP1 Client Profile - false - - - False - .NET Framework 3.5 SP1 - true - - - False - Microsoft Visual Basic PowerPacks 10.0 - true - - - False - Windows Installer 3.1 - true - - - - + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {A84563A0-8A70-43D9-A1C0-530955413318} + Library + Properties + Moq.Visualizer.Tests + Moq.Visualizer.Tests + v4.0 + 512 + true + ..\Moq.snk + + + 3.5 + + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + AllRules.ruleset + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + AllRules.ruleset + + + + + 3.5 + + + + + False + ..\Lib\xUnit\xunit.dll + + + + + + + + + + {1C91AC30-5977-4BE5-BA67-8EB186C03514} + Moq + + + + + Moq.snk + + + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + true + + + False + Microsoft Visual Basic PowerPacks 10.0 + true + + + False + Windows Installer 3.1 + true + + + + \ No newline at end of file diff --git a/UnitTests.Visualizer/Properties/AssemblyInfo.cs b/UnitTests.Visualizer/Properties/AssemblyInfo.cs index 244e1f21c..7a8a94c62 100644 --- a/UnitTests.Visualizer/Properties/AssemblyInfo.cs +++ b/UnitTests.Visualizer/Properties/AssemblyInfo.cs @@ -1,36 +1,36 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("UnitTests.Visualizer")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("UnitTests.Visualizer")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2009")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("3a3f0f06-7487-4e50-b9cf-9ff2eb6e62a0")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("UnitTests.Visualizer")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("UnitTests.Visualizer")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2009")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("3a3f0f06-7487-4e50-b9cf-9ff2eb6e62a0")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/UnitTests.Visualizer/SetupViewModelFixture.cs b/UnitTests.Visualizer/SetupViewModelFixture.cs index 8eccdb217..a74b20da1 100644 --- a/UnitTests.Visualizer/SetupViewModelFixture.cs +++ b/UnitTests.Visualizer/SetupViewModelFixture.cs @@ -1,56 +1,56 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Xunit; - -namespace Moq.Visualizer.Tests -{ - public class SetupViewModelFixture - { - [Fact] - public void CtorSetsSetupExpression() - { - var target = new SetupViewModel("foo", false, false); - - Assert.Equal("foo", target.SetupExpression); - } - - [Fact] - public void CtorSetsIsVerifiable() - { - var target = new SetupViewModel("foo", true, false); - - Assert.Equal(true, target.IsVerifiable); - } - - [Fact] - public void CtorSetsIsNever() - { - var target = new SetupViewModel("foo", false, true); - - Assert.Equal(true, target.IsNever); - } - - [Fact] - public void CtorSetContainers() - { - var expectedContainer1 = new ContainerViewModel("bar", new ICloneable[0]); - var expectedContainer2 = new ContainerViewModel("baz", new IFormattable[0]); - - var target = new SetupViewModel("foo", false, false, expectedContainer1, expectedContainer2); - - Assert.Equal(2, target.Containers.Count()); - Assert.Same(expectedContainer1, target.Containers.ElementAt(0)); - Assert.Same(expectedContainer2, target.Containers.ElementAt(1)); - } - - [Fact] - public void CtorSetsIsExpandedAsFalse() - { - var target = new SetupViewModel("foo", false, false); - - Assert.False(target.IsExpanded); - } - } +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Xunit; + +namespace Moq.Visualizer.Tests +{ + public class SetupViewModelFixture + { + [Fact] + public void CtorSetsSetupExpression() + { + var target = new SetupViewModel("foo", false, false); + + Assert.Equal("foo", target.SetupExpression); + } + + [Fact] + public void CtorSetsIsVerifiable() + { + var target = new SetupViewModel("foo", true, false); + + Assert.Equal(true, target.IsVerifiable); + } + + [Fact] + public void CtorSetsIsNever() + { + var target = new SetupViewModel("foo", false, true); + + Assert.Equal(true, target.IsNever); + } + + [Fact] + public void CtorSetContainers() + { + var expectedContainer1 = new ContainerViewModel("bar", new ICloneable[0]); + var expectedContainer2 = new ContainerViewModel("baz", new IFormattable[0]); + + var target = new SetupViewModel("foo", false, false, expectedContainer1, expectedContainer2); + + Assert.Equal(2, target.Containers.Count()); + Assert.Same(expectedContainer1, target.Containers.ElementAt(0)); + Assert.Same(expectedContainer2, target.Containers.ElementAt(1)); + } + + [Fact] + public void CtorSetsIsExpandedAsFalse() + { + var target = new SetupViewModel("foo", false, false); + + Assert.False(target.IsExpanded); + } + } } \ No newline at end of file diff --git a/UnitTests/AdvancedMatcherAttributeFixture.cs b/UnitTests/AdvancedMatcherAttributeFixture.cs index 125a742ea..3a39449d5 100644 --- a/UnitTests/AdvancedMatcherAttributeFixture.cs +++ b/UnitTests/AdvancedMatcherAttributeFixture.cs @@ -1,78 +1,78 @@ -using System; -using System.Linq.Expressions; -using Xunit; - -namespace Moq.Tests -{ - public class AdvancedMatcherAttributeFixture - { - [Fact] - public void ShouldThrowIfNullMatcherType() - { - Assert.Throws(() => new AdvancedMatcherAttribute(null)); - } - - [Fact] - public void ShouldThrowIfMatcherNotIExpressionMatcher() - { - Assert.Throws(() => new AdvancedMatcherAttribute(typeof(object))); - } - - [Fact] - public void ShouldCreateMatcher() - { - var attr = new AdvancedMatcherAttribute(typeof(MockMatcher)); - var matcher = attr.CreateMatcher(); - - Assert.NotNull(matcher); - } - - [Fact] - public void ShouldExposeMatcherType() - { - var attr = new AdvancedMatcherAttribute(typeof(MockMatcher)); - - Assert.Equal(typeof(MockMatcher), attr.MatcherType); - } - - [Fact] - public void ShouldThrowRealException() - { - var attr = new AdvancedMatcherAttribute(typeof(ThrowingMatcher)); - Assert.Throws(() => attr.CreateMatcher()); - } - - public class MockMatcher : IMatcher - { - #region IMatcher Members - - public void Initialize(Expression matcherExpression) - { - } - - public bool Matches(object value) - { - return false; - } - - #endregion - } - - public class ThrowingMatcher : IMatcher - { - public ThrowingMatcher() - { - throw new ArgumentException(); - } - - public void Initialize(Expression matcherExpression) - { - } - - public bool Matches(object value) - { - return false; - } - } - } +using System; +using System.Linq.Expressions; +using Xunit; + +namespace Moq.Tests +{ + public class AdvancedMatcherAttributeFixture + { + [Fact] + public void ShouldThrowIfNullMatcherType() + { + Assert.Throws(() => new AdvancedMatcherAttribute(null)); + } + + [Fact] + public void ShouldThrowIfMatcherNotIExpressionMatcher() + { + Assert.Throws(() => new AdvancedMatcherAttribute(typeof(object))); + } + + [Fact] + public void ShouldCreateMatcher() + { + var attr = new AdvancedMatcherAttribute(typeof(MockMatcher)); + var matcher = attr.CreateMatcher(); + + Assert.NotNull(matcher); + } + + [Fact] + public void ShouldExposeMatcherType() + { + var attr = new AdvancedMatcherAttribute(typeof(MockMatcher)); + + Assert.Equal(typeof(MockMatcher), attr.MatcherType); + } + + [Fact] + public void ShouldThrowRealException() + { + var attr = new AdvancedMatcherAttribute(typeof(ThrowingMatcher)); + Assert.Throws(() => attr.CreateMatcher()); + } + + public class MockMatcher : IMatcher + { + #region IMatcher Members + + public void Initialize(Expression matcherExpression) + { + } + + public bool Matches(object value) + { + return false; + } + + #endregion + } + + public class ThrowingMatcher : IMatcher + { + public ThrowingMatcher() + { + throw new ArgumentException(); + } + + public void Initialize(Expression matcherExpression) + { + } + + public bool Matches(object value) + { + return false; + } + } + } } \ No newline at end of file diff --git a/UnitTests/AsInterfaceFixture.cs b/UnitTests/AsInterfaceFixture.cs index 521233f50..d71fdf4bf 100644 --- a/UnitTests/AsInterfaceFixture.cs +++ b/UnitTests/AsInterfaceFixture.cs @@ -1,172 +1,172 @@ -using System; -using System.Diagnostics; -using Xunit; - -namespace Moq.Tests -{ - public class AsInterfaceFixture - { - [Fact] - public void ShouldThrowIfAsIsInvokedAfterInstanceIsRetrieved() - { - var mock = new Mock(); - - var instance = mock.Object; - - Assert.Throws(() => mock.As()); - } - - [Fact] - public void ShouldThrowIfAsIsInvokedWithANonInterfaceTypeParameter() - { - var mock = new Mock(); - - Assert.Throws(() => mock.As()); - } - - [Fact] - public void ShouldExpectGetOnANewInterface() - { - var mock = new Mock(); - - bool called = false; - - mock.As().SetupGet(x => x.Value) - .Callback(() => called = true) - .Returns(25); - - Assert.Equal(25, ((IFoo)mock.Object).Value); - Assert.True(called); - } - - [Fact] - public void ShouldExpectCallWithArgumentOnNewInterface() - { - var mock = new Mock(); - mock.As().Setup(x => x.Execute("ping")).Returns("ack"); - - Assert.Equal("ack", ((IFoo)mock.Object).Execute("ping")); - } - - [Fact] - public void ShouldExpectPropertySetterOnNewInterface() - { - bool called = false; - int value = 0; - var mock = new Mock(); - mock.As().SetupSet(x => x.Value = 100).Callback(i => { value = i; called = true; }); - - ((IFoo)mock.Object).Value = 100; - - Assert.Equal(100, value); - Assert.True(called); - } - - [Fact] - public void MockAsExistingInterfaceAfterObjectSucceedsIfNotNew() - { - var mock = new Mock(); - - mock.As().SetupGet(x => x.Value).Returns(25); - - Assert.Equal(25, ((IFoo)mock.Object).Value); - - var fm = mock.As(); - - fm.Setup(f => f.Execute()); - } - - [Fact] - public void ThrowsWithTargetTypeName() - { - var bag = new Mock(); - var foo = bag.As(); - - bag.Setup(b => b.Add("foo", "bar")).Verifiable(); - foo.Setup(f => f.Execute()).Verifiable(); - - try - { - bag.Verify(); - } - catch (MockVerificationException me) - { - Assert.Contains(typeof(IFoo).Name, me.Message); - Assert.Contains(typeof(IBag).Name, me.Message); - } - } - - [Fact] - public void GetMockFromAddedInterfaceWorks() - { - var bag = new Mock(); - var foo = bag.As(); - - foo.SetupGet(x => x.Value).Returns(25); - - IFoo f = bag.Object as IFoo; - - var foomock = Mock.Get(f); - - Assert.NotNull(foomock); - } - - [Fact] - public void GetMockFromNonAddedInterfaceThrows() - { - var bag = new Mock(); - bag.As(); - bag.As(); - object b = bag.Object; - - Assert.Throws(() => Mock.Get(b)); - } - - [Fact] - public void VerifiesExpectationOnAddedInterface() - { - var bag = new Mock(); - var foo = bag.As(); - - foo.Setup(f => f.Execute()).Verifiable(); - - Assert.Throws(() => foo.Verify()); - Assert.Throws(() => foo.VerifyAll()); - Assert.Throws(() => foo.Verify(f => f.Execute())); - - foo.Object.Execute(); - - foo.Verify(); - foo.VerifyAll(); - foo.Verify(f => f.Execute()); - } - - [Fact] - public void VerifiesExpectationOnAddedInterfaceCastedDynamically() - { - var bag = new Mock(); - bag.As(); - - ((IFoo)bag.Object).Execute(); - - bag.As().Verify(f => f.Execute()); - } - - public interface IFoo - { - void Execute(); - string Execute(string command); - string Execute(string arg1, string arg2); - string Execute(string arg1, string arg2, string arg3); - string Execute(string arg1, string arg2, string arg3, string arg4); - - int Value { get; set; } - } - - public interface IBag - { - void Add(string key, object o); - object Get(string key); - } - } -} +using System; +using System.Diagnostics; +using Xunit; + +namespace Moq.Tests +{ + public class AsInterfaceFixture + { + [Fact] + public void ShouldThrowIfAsIsInvokedAfterInstanceIsRetrieved() + { + var mock = new Mock(); + + var instance = mock.Object; + + Assert.Throws(() => mock.As()); + } + + [Fact] + public void ShouldThrowIfAsIsInvokedWithANonInterfaceTypeParameter() + { + var mock = new Mock(); + + Assert.Throws(() => mock.As()); + } + + [Fact] + public void ShouldExpectGetOnANewInterface() + { + var mock = new Mock(); + + bool called = false; + + mock.As().SetupGet(x => x.Value) + .Callback(() => called = true) + .Returns(25); + + Assert.Equal(25, ((IFoo)mock.Object).Value); + Assert.True(called); + } + + [Fact] + public void ShouldExpectCallWithArgumentOnNewInterface() + { + var mock = new Mock(); + mock.As().Setup(x => x.Execute("ping")).Returns("ack"); + + Assert.Equal("ack", ((IFoo)mock.Object).Execute("ping")); + } + + [Fact] + public void ShouldExpectPropertySetterOnNewInterface() + { + bool called = false; + int value = 0; + var mock = new Mock(); + mock.As().SetupSet(x => x.Value = 100).Callback(i => { value = i; called = true; }); + + ((IFoo)mock.Object).Value = 100; + + Assert.Equal(100, value); + Assert.True(called); + } + + [Fact] + public void MockAsExistingInterfaceAfterObjectSucceedsIfNotNew() + { + var mock = new Mock(); + + mock.As().SetupGet(x => x.Value).Returns(25); + + Assert.Equal(25, ((IFoo)mock.Object).Value); + + var fm = mock.As(); + + fm.Setup(f => f.Execute()); + } + + [Fact] + public void ThrowsWithTargetTypeName() + { + var bag = new Mock(); + var foo = bag.As(); + + bag.Setup(b => b.Add("foo", "bar")).Verifiable(); + foo.Setup(f => f.Execute()).Verifiable(); + + try + { + bag.Verify(); + } + catch (MockVerificationException me) + { + Assert.Contains(typeof(IFoo).Name, me.Message); + Assert.Contains(typeof(IBag).Name, me.Message); + } + } + + [Fact] + public void GetMockFromAddedInterfaceWorks() + { + var bag = new Mock(); + var foo = bag.As(); + + foo.SetupGet(x => x.Value).Returns(25); + + IFoo f = bag.Object as IFoo; + + var foomock = Mock.Get(f); + + Assert.NotNull(foomock); + } + + [Fact] + public void GetMockFromNonAddedInterfaceThrows() + { + var bag = new Mock(); + bag.As(); + bag.As(); + object b = bag.Object; + + Assert.Throws(() => Mock.Get(b)); + } + + [Fact] + public void VerifiesExpectationOnAddedInterface() + { + var bag = new Mock(); + var foo = bag.As(); + + foo.Setup(f => f.Execute()).Verifiable(); + + Assert.Throws(() => foo.Verify()); + Assert.Throws(() => foo.VerifyAll()); + Assert.Throws(() => foo.Verify(f => f.Execute())); + + foo.Object.Execute(); + + foo.Verify(); + foo.VerifyAll(); + foo.Verify(f => f.Execute()); + } + + [Fact] + public void VerifiesExpectationOnAddedInterfaceCastedDynamically() + { + var bag = new Mock(); + bag.As(); + + ((IFoo)bag.Object).Execute(); + + bag.As().Verify(f => f.Execute()); + } + + public interface IFoo + { + void Execute(); + string Execute(string command); + string Execute(string arg1, string arg2); + string Execute(string arg1, string arg2, string arg3); + string Execute(string arg1, string arg2, string arg3, string arg4); + + int Value { get; set; } + } + + public interface IBag + { + void Add(string key, object o); + object Get(string key); + } + } +} diff --git a/UnitTests/CallbacksFixture.cs b/UnitTests/CallbacksFixture.cs index e2f2edfc2..73af5d782 100644 --- a/UnitTests/CallbacksFixture.cs +++ b/UnitTests/CallbacksFixture.cs @@ -1,446 +1,446 @@ -using System; -using Xunit; - -namespace Moq.Tests -{ - public class CallbacksFixture - { - [Fact] - public void ExecutesCallbackWhenVoidMethodIsCalled() - { - var mock = new Mock(); - bool called = false; - mock.Setup(x => x.Submit()).Callback(() => called = true); - - mock.Object.Submit(); - Assert.True(called); - } - - [Fact] - public void ExecutesCallbackWhenNonVoidMethodIsCalled() - { - var mock = new Mock(); - bool called = false; - mock.Setup(x => x.Execute("ping")).Callback(() => called = true).Returns("ack"); - - Assert.Equal("ack", mock.Object.Execute("ping")); - Assert.True(called); - } - - [Fact] - public void CallbackCalledWithoutArgumentsForMethodCallWithArguments() - { - var mock = new Mock(); - bool called = false; - mock.Setup(x => x.Submit(It.IsAny())).Callback(() => called = true); - - mock.Object.Submit("blah"); - Assert.True(called); - } - - [Fact] - public void FriendlyErrorWhenCallbackArgumentCountNotMatch() - { - var mock = new Mock(); - - Assert.Throws(() => - mock.Setup(x => x.Submit(It.IsAny())) - .Callback((string s1, string s2) => System.Console.WriteLine(s1 + s2))); - } - - [Fact] - public void CallbackCalledWithOneArgument() - { - var mock = new Mock(); - string callbackArg = null; - mock.Setup(x => x.Submit(It.IsAny())).Callback((string s) => callbackArg = s); - - mock.Object.Submit("blah"); - Assert.Equal("blah", callbackArg); - } - - [Fact] - public void CallbackCalledWithTwoArguments() - { - var mock = new Mock(); - string callbackArg1 = null; - string callbackArg2 = null; - mock.Setup(x => x.Submit(It.IsAny(), It.IsAny())) - .Callback((string s1, string s2) => { callbackArg1 = s1; callbackArg2 = s2; }); - - mock.Object.Submit("blah1", "blah2"); - Assert.Equal("blah1", callbackArg1); - Assert.Equal("blah2", callbackArg2); - } - - [Fact] - public void CallbackCalledWithThreeArguments() - { - var mock = new Mock(); - string callbackArg1 = null; - string callbackArg2 = null; - string callbackArg3 = null; - mock.Setup(x => x.Submit(It.IsAny(), It.IsAny(), It.IsAny())) - .Callback((string s1, string s2, string s3) => { callbackArg1 = s1; callbackArg2 = s2; callbackArg3 = s3; }); - - mock.Object.Submit("blah1", "blah2", "blah3"); - Assert.Equal("blah1", callbackArg1); - Assert.Equal("blah2", callbackArg2); - Assert.Equal("blah3", callbackArg3); - } - - [Fact] - public void CallbackCalledWithFourArguments() - { - var mock = new Mock(); - string callbackArg1 = null; - string callbackArg2 = null; - string callbackArg3 = null; - string callbackArg4 = null; - mock.Setup(x => x.Submit(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) - .Callback((string s1, string s2, string s3, string s4) => { callbackArg1 = s1; callbackArg2 = s2; callbackArg3 = s3; callbackArg4 = s4; }); - - mock.Object.Submit("blah1", "blah2", "blah3", "blah4"); - Assert.Equal("blah1", callbackArg1); - Assert.Equal("blah2", callbackArg2); - Assert.Equal("blah3", callbackArg3); - Assert.Equal("blah4", callbackArg4); - } - - [Fact] - public void CallbackCalledWithFiveArguments() - { - var mock = new Mock(); - string callbackArg1 = null; - string callbackArg2 = null; - string callbackArg3 = null; - string callbackArg4 = null; - string callbackArg5 = null; - mock.Setup(x => x.Submit(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) - .Callback((string s1, string s2, string s3, string s4, string s5) => { callbackArg1 = s1; callbackArg2 = s2; callbackArg3 = s3; callbackArg4 = s4; callbackArg5 = s5; }); - - mock.Object.Submit("blah1", "blah2", "blah3", "blah4", "blah5"); - Assert.Equal("blah1", callbackArg1); - Assert.Equal("blah2", callbackArg2); - Assert.Equal("blah3", callbackArg3); - Assert.Equal("blah4", callbackArg4); - Assert.Equal("blah5", callbackArg5); - } - - [Fact] - public void CallbackCalledWithSixArguments() - { - var mock = new Mock(); - string callbackArg1 = null; - string callbackArg2 = null; - string callbackArg3 = null; - string callbackArg4 = null; - string callbackArg5 = null; - string callbackArg6 = null; - mock.Setup(x => x.Submit(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) - .Callback((string s1, string s2, string s3, string s4, string s5, string s6) => { callbackArg1 = s1; callbackArg2 = s2; callbackArg3 = s3; callbackArg4 = s4; callbackArg5 = s5; callbackArg6 = s6; }); - - mock.Object.Submit("blah1", "blah2", "blah3", "blah4", "blah5", "blah6"); - Assert.Equal("blah1", callbackArg1); - Assert.Equal("blah2", callbackArg2); - Assert.Equal("blah3", callbackArg3); - Assert.Equal("blah4", callbackArg4); - Assert.Equal("blah5", callbackArg5); - Assert.Equal("blah6", callbackArg6); - } - - [Fact] - public void CallbackCalledWithSevenArguments() - { - var mock = new Mock(); - string callbackArg1 = null; - string callbackArg2 = null; - string callbackArg3 = null; - string callbackArg4 = null; - string callbackArg5 = null; - string callbackArg6 = null; - string callbackArg7 = null; - mock.Setup(x => x.Submit(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) - .Callback((string s1, string s2, string s3, string s4, string s5, string s6, string s7) => { callbackArg1 = s1; callbackArg2 = s2; callbackArg3 = s3; callbackArg4 = s4; callbackArg5 = s5; callbackArg6 = s6; callbackArg7 = s7; }); - - mock.Object.Submit("blah1", "blah2", "blah3", "blah4", "blah5", "blah6", "blah7"); - Assert.Equal("blah1", callbackArg1); - Assert.Equal("blah2", callbackArg2); - Assert.Equal("blah3", callbackArg3); - Assert.Equal("blah4", callbackArg4); - Assert.Equal("blah5", callbackArg5); - Assert.Equal("blah6", callbackArg6); - Assert.Equal("blah7", callbackArg7); - } - - [Fact] - public void CallbackCalledWithEightArguments() - { - var mock = new Mock(); - string callbackArg1 = null; - string callbackArg2 = null; - string callbackArg3 = null; - string callbackArg4 = null; - string callbackArg5 = null; - string callbackArg6 = null; - string callbackArg7 = null; - string callbackArg8 = null; - mock.Setup(x => x.Submit(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) - .Callback((string s1, string s2, string s3, string s4, string s5, string s6, string s7, string s8) => { callbackArg1 = s1; callbackArg2 = s2; callbackArg3 = s3; callbackArg4 = s4; callbackArg5 = s5; callbackArg6 = s6; callbackArg7 = s7; callbackArg8 = s8; }); - - mock.Object.Submit("blah1", "blah2", "blah3", "blah4", "blah5", "blah6", "blah7", "blah8"); - Assert.Equal("blah1", callbackArg1); - Assert.Equal("blah2", callbackArg2); - Assert.Equal("blah3", callbackArg3); - Assert.Equal("blah4", callbackArg4); - Assert.Equal("blah5", callbackArg5); - Assert.Equal("blah6", callbackArg6); - Assert.Equal("blah7", callbackArg7); - Assert.Equal("blah8", callbackArg8); - } - - [Fact] - public void CallbackCalledWithOneArgumentForNonVoidMethod() - { - var mock = new Mock(); - string callbackArg1 = null; - mock.Setup(x => x.Execute(It.IsAny())) - .Callback((string s1) => callbackArg1 = s1) - .Returns("foo"); - - mock.Object.Execute("blah1"); - Assert.Equal("blah1", callbackArg1); - } - - [Fact] - public void CallbackCalledWithTwoArgumentsForNonVoidMethod() - { - var mock = new Mock(); - string callbackArg1 = null; - string callbackArg2 = null; - mock.Setup(x => x.Execute(It.IsAny(), It.IsAny())) - .Callback((string s1, string s2) => { callbackArg1 = s1; callbackArg2 = s2; }) - .Returns("foo"); - - mock.Object.Execute("blah1", "blah2"); - Assert.Equal("blah1", callbackArg1); - Assert.Equal("blah2", callbackArg2); - } - - [Fact] - public void CallbackCalledWithThreeArgumentsForNonVoidMethod() - { - var mock = new Mock(); - string callbackArg1 = null; - string callbackArg2 = null; - string callbackArg3 = null; - mock.Setup(x => x.Execute(It.IsAny(), It.IsAny(), It.IsAny())) - .Callback((string s1, string s2, string s3) => { callbackArg1 = s1; callbackArg2 = s2; callbackArg3 = s3; }) - .Returns("foo"); - - mock.Object.Execute("blah1", "blah2", "blah3"); - Assert.Equal("blah1", callbackArg1); - Assert.Equal("blah2", callbackArg2); - Assert.Equal("blah3", callbackArg3); - } - - [Fact] - public void CallbackCalledWithFourArgumentsForNonVoidMethod() - { - var mock = new Mock(); - string callbackArg1 = null; - string callbackArg2 = null; - string callbackArg3 = null; - string callbackArg4 = null; - mock.Setup(x => x.Execute(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) - .Callback((string s1, string s2, string s3, string s4) => { callbackArg1 = s1; callbackArg2 = s2; callbackArg3 = s3; callbackArg4 = s4; }) - .Returns("foo"); - - mock.Object.Execute("blah1", "blah2", "blah3", "blah4"); - Assert.Equal("blah1", callbackArg1); - Assert.Equal("blah2", callbackArg2); - Assert.Equal("blah3", callbackArg3); - Assert.Equal("blah4", callbackArg4); - } - - [Fact] - public void CallbackCalledWithFiveArgumentsForNonVoidMethod() - { - var mock = new Mock(); - string callbackArg1 = null; - string callbackArg2 = null; - string callbackArg3 = null; - string callbackArg4 = null; - string callbackArg5 = null; - mock.Setup(x => x.Execute(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) - .Callback((string s1, string s2, string s3, string s4, string s5) => { callbackArg1 = s1; callbackArg2 = s2; callbackArg3 = s3; callbackArg4 = s4; callbackArg5 = s5; }) - .Returns("foo"); - - mock.Object.Execute("blah1", "blah2", "blah3", "blah4", "blah5"); - Assert.Equal("blah1", callbackArg1); - Assert.Equal("blah2", callbackArg2); - Assert.Equal("blah3", callbackArg3); - Assert.Equal("blah4", callbackArg4); - Assert.Equal("blah5", callbackArg5); - } - - [Fact] - public void CallbackCalledWithSixArgumentsForNonVoidMethod() - { - var mock = new Mock(); - string callbackArg1 = null; - string callbackArg2 = null; - string callbackArg3 = null; - string callbackArg4 = null; - string callbackArg5 = null; - string callbackArg6 = null; - mock.Setup(x => x.Execute(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) - .Callback((string s1, string s2, string s3, string s4, string s5, string s6) => { callbackArg1 = s1; callbackArg2 = s2; callbackArg3 = s3; callbackArg4 = s4; callbackArg5 = s5; callbackArg6 = s6; }) - .Returns("foo"); - - mock.Object.Execute("blah1", "blah2", "blah3", "blah4", "blah5", "blah6"); - Assert.Equal("blah1", callbackArg1); - Assert.Equal("blah2", callbackArg2); - Assert.Equal("blah3", callbackArg3); - Assert.Equal("blah4", callbackArg4); - Assert.Equal("blah5", callbackArg5); - Assert.Equal("blah6", callbackArg6); - } - - [Fact] - public void CallbackCalledWithSevenArgumentsForNonVoidMethod() - { - var mock = new Mock(); - string callbackArg1 = null; - string callbackArg2 = null; - string callbackArg3 = null; - string callbackArg4 = null; - string callbackArg5 = null; - string callbackArg6 = null; - string callbackArg7 = null; - mock.Setup(x => x.Execute(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) - .Callback((string s1, string s2, string s3, string s4, string s5, string s6, string s7) => { callbackArg1 = s1; callbackArg2 = s2; callbackArg3 = s3; callbackArg4 = s4; callbackArg5 = s5; callbackArg6 = s6; callbackArg7 = s7; }) - .Returns("foo"); - - mock.Object.Execute("blah1", "blah2", "blah3", "blah4", "blah5", "blah6", "blah7"); - Assert.Equal("blah1", callbackArg1); - Assert.Equal("blah2", callbackArg2); - Assert.Equal("blah3", callbackArg3); - Assert.Equal("blah4", callbackArg4); - Assert.Equal("blah5", callbackArg5); - Assert.Equal("blah6", callbackArg6); - Assert.Equal("blah7", callbackArg7); - } - - [Fact] - public void CallbackCalledWithEightArgumentsForNonVoidMethod() - { - var mock = new Mock(); - string callbackArg1 = null; - string callbackArg2 = null; - string callbackArg3 = null; - string callbackArg4 = null; - string callbackArg5 = null; - string callbackArg6 = null; - string callbackArg7 = null; - string callbackArg8 = null; - mock.Setup(x => x.Execute(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) - .Callback((string s1, string s2, string s3, string s4, string s5, string s6, string s7, string s8) => { callbackArg1 = s1; callbackArg2 = s2; callbackArg3 = s3; callbackArg4 = s4; callbackArg5 = s5; callbackArg6 = s6; callbackArg7 = s7; callbackArg8 = s8; }) - .Returns("foo"); - - mock.Object.Execute("blah1", "blah2", "blah3", "blah4", "blah5", "blah6", "blah7", "blah8"); - Assert.Equal("blah1", callbackArg1); - Assert.Equal("blah2", callbackArg2); - Assert.Equal("blah3", callbackArg3); - Assert.Equal("blah4", callbackArg4); - Assert.Equal("blah5", callbackArg5); - Assert.Equal("blah6", callbackArg6); - Assert.Equal("blah7", callbackArg7); - Assert.Equal("blah8", callbackArg8); - } - - [Fact] - public void CallbackCalledAfterReturnsCall() - { - var mock = new Mock(); - bool returnsCalled = false; - bool beforeCalled = false; - bool afterCalled = false; - - mock.Setup(foo => foo.Execute("ping")) - .Callback(() => { Assert.False(returnsCalled); beforeCalled = true; }) - .Returns(() => { returnsCalled = true; return "ack"; }) - .Callback(() => { Assert.True(returnsCalled); afterCalled = true; }); - - Assert.Equal("ack", mock.Object.Execute("ping")); - - Assert.True(beforeCalled); - Assert.True(afterCalled); - } - - [Fact] - public void CallbackCalledAfterReturnsCallWithArg() - { - var mock = new Mock(); - bool returnsCalled = false; - - mock.Setup(foo => foo.Execute(It.IsAny())) - .Callback(s => Assert.False(returnsCalled)) - .Returns(() => { returnsCalled = true; return "ack"; }) - .Callback(s => Assert.True(returnsCalled)); - - mock.Object.Execute("ping"); - - Assert.True(returnsCalled); - } - - [Fact] - public void CallbackCanReceiveABaseClass() - { - var mock = new Mock(MockBehavior.Strict); - mock.Setup(foo => foo.Method(It.IsAny())).Callback(TraceMe); - - mock.Object.Method(new Derived()); - } - - public interface IInterface - { - void Method(Derived b); - } - - public class Base - { - } - - public class Derived : Base - { - } - - private void TraceMe(Base b) - { - } - - public interface IFoo - { - void Submit(); - void Submit(string command); - string Submit(string arg1, string arg2); - string Submit(string arg1, string arg2, string arg3); - string Submit(string arg1, string arg2, string arg3, string arg4); - void Submit(string arg1, string arg2, string arg3, string arg4, string arg5); - void Submit(string arg1, string arg2, string arg3, string arg4, string arg5, string arg6); - void Submit(string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7); - void Submit(string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8); - string Execute(string command); - string Execute(string arg1, string arg2); - string Execute(string arg1, string arg2, string arg3); - string Execute(string arg1, string arg2, string arg3, string arg4); - string Execute(string arg1, string arg2, string arg3, string arg4, string arg5); - string Execute(string arg1, string arg2, string arg3, string arg4, string arg5, string arg6); - string Execute(string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7); - string Execute(string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8); - - int Value { get; set; } - } - } -} +using System; +using Xunit; + +namespace Moq.Tests +{ + public class CallbacksFixture + { + [Fact] + public void ExecutesCallbackWhenVoidMethodIsCalled() + { + var mock = new Mock(); + bool called = false; + mock.Setup(x => x.Submit()).Callback(() => called = true); + + mock.Object.Submit(); + Assert.True(called); + } + + [Fact] + public void ExecutesCallbackWhenNonVoidMethodIsCalled() + { + var mock = new Mock(); + bool called = false; + mock.Setup(x => x.Execute("ping")).Callback(() => called = true).Returns("ack"); + + Assert.Equal("ack", mock.Object.Execute("ping")); + Assert.True(called); + } + + [Fact] + public void CallbackCalledWithoutArgumentsForMethodCallWithArguments() + { + var mock = new Mock(); + bool called = false; + mock.Setup(x => x.Submit(It.IsAny())).Callback(() => called = true); + + mock.Object.Submit("blah"); + Assert.True(called); + } + + [Fact] + public void FriendlyErrorWhenCallbackArgumentCountNotMatch() + { + var mock = new Mock(); + + Assert.Throws(() => + mock.Setup(x => x.Submit(It.IsAny())) + .Callback((string s1, string s2) => System.Console.WriteLine(s1 + s2))); + } + + [Fact] + public void CallbackCalledWithOneArgument() + { + var mock = new Mock(); + string callbackArg = null; + mock.Setup(x => x.Submit(It.IsAny())).Callback((string s) => callbackArg = s); + + mock.Object.Submit("blah"); + Assert.Equal("blah", callbackArg); + } + + [Fact] + public void CallbackCalledWithTwoArguments() + { + var mock = new Mock(); + string callbackArg1 = null; + string callbackArg2 = null; + mock.Setup(x => x.Submit(It.IsAny(), It.IsAny())) + .Callback((string s1, string s2) => { callbackArg1 = s1; callbackArg2 = s2; }); + + mock.Object.Submit("blah1", "blah2"); + Assert.Equal("blah1", callbackArg1); + Assert.Equal("blah2", callbackArg2); + } + + [Fact] + public void CallbackCalledWithThreeArguments() + { + var mock = new Mock(); + string callbackArg1 = null; + string callbackArg2 = null; + string callbackArg3 = null; + mock.Setup(x => x.Submit(It.IsAny(), It.IsAny(), It.IsAny())) + .Callback((string s1, string s2, string s3) => { callbackArg1 = s1; callbackArg2 = s2; callbackArg3 = s3; }); + + mock.Object.Submit("blah1", "blah2", "blah3"); + Assert.Equal("blah1", callbackArg1); + Assert.Equal("blah2", callbackArg2); + Assert.Equal("blah3", callbackArg3); + } + + [Fact] + public void CallbackCalledWithFourArguments() + { + var mock = new Mock(); + string callbackArg1 = null; + string callbackArg2 = null; + string callbackArg3 = null; + string callbackArg4 = null; + mock.Setup(x => x.Submit(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .Callback((string s1, string s2, string s3, string s4) => { callbackArg1 = s1; callbackArg2 = s2; callbackArg3 = s3; callbackArg4 = s4; }); + + mock.Object.Submit("blah1", "blah2", "blah3", "blah4"); + Assert.Equal("blah1", callbackArg1); + Assert.Equal("blah2", callbackArg2); + Assert.Equal("blah3", callbackArg3); + Assert.Equal("blah4", callbackArg4); + } + + [Fact] + public void CallbackCalledWithFiveArguments() + { + var mock = new Mock(); + string callbackArg1 = null; + string callbackArg2 = null; + string callbackArg3 = null; + string callbackArg4 = null; + string callbackArg5 = null; + mock.Setup(x => x.Submit(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .Callback((string s1, string s2, string s3, string s4, string s5) => { callbackArg1 = s1; callbackArg2 = s2; callbackArg3 = s3; callbackArg4 = s4; callbackArg5 = s5; }); + + mock.Object.Submit("blah1", "blah2", "blah3", "blah4", "blah5"); + Assert.Equal("blah1", callbackArg1); + Assert.Equal("blah2", callbackArg2); + Assert.Equal("blah3", callbackArg3); + Assert.Equal("blah4", callbackArg4); + Assert.Equal("blah5", callbackArg5); + } + + [Fact] + public void CallbackCalledWithSixArguments() + { + var mock = new Mock(); + string callbackArg1 = null; + string callbackArg2 = null; + string callbackArg3 = null; + string callbackArg4 = null; + string callbackArg5 = null; + string callbackArg6 = null; + mock.Setup(x => x.Submit(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .Callback((string s1, string s2, string s3, string s4, string s5, string s6) => { callbackArg1 = s1; callbackArg2 = s2; callbackArg3 = s3; callbackArg4 = s4; callbackArg5 = s5; callbackArg6 = s6; }); + + mock.Object.Submit("blah1", "blah2", "blah3", "blah4", "blah5", "blah6"); + Assert.Equal("blah1", callbackArg1); + Assert.Equal("blah2", callbackArg2); + Assert.Equal("blah3", callbackArg3); + Assert.Equal("blah4", callbackArg4); + Assert.Equal("blah5", callbackArg5); + Assert.Equal("blah6", callbackArg6); + } + + [Fact] + public void CallbackCalledWithSevenArguments() + { + var mock = new Mock(); + string callbackArg1 = null; + string callbackArg2 = null; + string callbackArg3 = null; + string callbackArg4 = null; + string callbackArg5 = null; + string callbackArg6 = null; + string callbackArg7 = null; + mock.Setup(x => x.Submit(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .Callback((string s1, string s2, string s3, string s4, string s5, string s6, string s7) => { callbackArg1 = s1; callbackArg2 = s2; callbackArg3 = s3; callbackArg4 = s4; callbackArg5 = s5; callbackArg6 = s6; callbackArg7 = s7; }); + + mock.Object.Submit("blah1", "blah2", "blah3", "blah4", "blah5", "blah6", "blah7"); + Assert.Equal("blah1", callbackArg1); + Assert.Equal("blah2", callbackArg2); + Assert.Equal("blah3", callbackArg3); + Assert.Equal("blah4", callbackArg4); + Assert.Equal("blah5", callbackArg5); + Assert.Equal("blah6", callbackArg6); + Assert.Equal("blah7", callbackArg7); + } + + [Fact] + public void CallbackCalledWithEightArguments() + { + var mock = new Mock(); + string callbackArg1 = null; + string callbackArg2 = null; + string callbackArg3 = null; + string callbackArg4 = null; + string callbackArg5 = null; + string callbackArg6 = null; + string callbackArg7 = null; + string callbackArg8 = null; + mock.Setup(x => x.Submit(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .Callback((string s1, string s2, string s3, string s4, string s5, string s6, string s7, string s8) => { callbackArg1 = s1; callbackArg2 = s2; callbackArg3 = s3; callbackArg4 = s4; callbackArg5 = s5; callbackArg6 = s6; callbackArg7 = s7; callbackArg8 = s8; }); + + mock.Object.Submit("blah1", "blah2", "blah3", "blah4", "blah5", "blah6", "blah7", "blah8"); + Assert.Equal("blah1", callbackArg1); + Assert.Equal("blah2", callbackArg2); + Assert.Equal("blah3", callbackArg3); + Assert.Equal("blah4", callbackArg4); + Assert.Equal("blah5", callbackArg5); + Assert.Equal("blah6", callbackArg6); + Assert.Equal("blah7", callbackArg7); + Assert.Equal("blah8", callbackArg8); + } + + [Fact] + public void CallbackCalledWithOneArgumentForNonVoidMethod() + { + var mock = new Mock(); + string callbackArg1 = null; + mock.Setup(x => x.Execute(It.IsAny())) + .Callback((string s1) => callbackArg1 = s1) + .Returns("foo"); + + mock.Object.Execute("blah1"); + Assert.Equal("blah1", callbackArg1); + } + + [Fact] + public void CallbackCalledWithTwoArgumentsForNonVoidMethod() + { + var mock = new Mock(); + string callbackArg1 = null; + string callbackArg2 = null; + mock.Setup(x => x.Execute(It.IsAny(), It.IsAny())) + .Callback((string s1, string s2) => { callbackArg1 = s1; callbackArg2 = s2; }) + .Returns("foo"); + + mock.Object.Execute("blah1", "blah2"); + Assert.Equal("blah1", callbackArg1); + Assert.Equal("blah2", callbackArg2); + } + + [Fact] + public void CallbackCalledWithThreeArgumentsForNonVoidMethod() + { + var mock = new Mock(); + string callbackArg1 = null; + string callbackArg2 = null; + string callbackArg3 = null; + mock.Setup(x => x.Execute(It.IsAny(), It.IsAny(), It.IsAny())) + .Callback((string s1, string s2, string s3) => { callbackArg1 = s1; callbackArg2 = s2; callbackArg3 = s3; }) + .Returns("foo"); + + mock.Object.Execute("blah1", "blah2", "blah3"); + Assert.Equal("blah1", callbackArg1); + Assert.Equal("blah2", callbackArg2); + Assert.Equal("blah3", callbackArg3); + } + + [Fact] + public void CallbackCalledWithFourArgumentsForNonVoidMethod() + { + var mock = new Mock(); + string callbackArg1 = null; + string callbackArg2 = null; + string callbackArg3 = null; + string callbackArg4 = null; + mock.Setup(x => x.Execute(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .Callback((string s1, string s2, string s3, string s4) => { callbackArg1 = s1; callbackArg2 = s2; callbackArg3 = s3; callbackArg4 = s4; }) + .Returns("foo"); + + mock.Object.Execute("blah1", "blah2", "blah3", "blah4"); + Assert.Equal("blah1", callbackArg1); + Assert.Equal("blah2", callbackArg2); + Assert.Equal("blah3", callbackArg3); + Assert.Equal("blah4", callbackArg4); + } + + [Fact] + public void CallbackCalledWithFiveArgumentsForNonVoidMethod() + { + var mock = new Mock(); + string callbackArg1 = null; + string callbackArg2 = null; + string callbackArg3 = null; + string callbackArg4 = null; + string callbackArg5 = null; + mock.Setup(x => x.Execute(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .Callback((string s1, string s2, string s3, string s4, string s5) => { callbackArg1 = s1; callbackArg2 = s2; callbackArg3 = s3; callbackArg4 = s4; callbackArg5 = s5; }) + .Returns("foo"); + + mock.Object.Execute("blah1", "blah2", "blah3", "blah4", "blah5"); + Assert.Equal("blah1", callbackArg1); + Assert.Equal("blah2", callbackArg2); + Assert.Equal("blah3", callbackArg3); + Assert.Equal("blah4", callbackArg4); + Assert.Equal("blah5", callbackArg5); + } + + [Fact] + public void CallbackCalledWithSixArgumentsForNonVoidMethod() + { + var mock = new Mock(); + string callbackArg1 = null; + string callbackArg2 = null; + string callbackArg3 = null; + string callbackArg4 = null; + string callbackArg5 = null; + string callbackArg6 = null; + mock.Setup(x => x.Execute(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .Callback((string s1, string s2, string s3, string s4, string s5, string s6) => { callbackArg1 = s1; callbackArg2 = s2; callbackArg3 = s3; callbackArg4 = s4; callbackArg5 = s5; callbackArg6 = s6; }) + .Returns("foo"); + + mock.Object.Execute("blah1", "blah2", "blah3", "blah4", "blah5", "blah6"); + Assert.Equal("blah1", callbackArg1); + Assert.Equal("blah2", callbackArg2); + Assert.Equal("blah3", callbackArg3); + Assert.Equal("blah4", callbackArg4); + Assert.Equal("blah5", callbackArg5); + Assert.Equal("blah6", callbackArg6); + } + + [Fact] + public void CallbackCalledWithSevenArgumentsForNonVoidMethod() + { + var mock = new Mock(); + string callbackArg1 = null; + string callbackArg2 = null; + string callbackArg3 = null; + string callbackArg4 = null; + string callbackArg5 = null; + string callbackArg6 = null; + string callbackArg7 = null; + mock.Setup(x => x.Execute(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .Callback((string s1, string s2, string s3, string s4, string s5, string s6, string s7) => { callbackArg1 = s1; callbackArg2 = s2; callbackArg3 = s3; callbackArg4 = s4; callbackArg5 = s5; callbackArg6 = s6; callbackArg7 = s7; }) + .Returns("foo"); + + mock.Object.Execute("blah1", "blah2", "blah3", "blah4", "blah5", "blah6", "blah7"); + Assert.Equal("blah1", callbackArg1); + Assert.Equal("blah2", callbackArg2); + Assert.Equal("blah3", callbackArg3); + Assert.Equal("blah4", callbackArg4); + Assert.Equal("blah5", callbackArg5); + Assert.Equal("blah6", callbackArg6); + Assert.Equal("blah7", callbackArg7); + } + + [Fact] + public void CallbackCalledWithEightArgumentsForNonVoidMethod() + { + var mock = new Mock(); + string callbackArg1 = null; + string callbackArg2 = null; + string callbackArg3 = null; + string callbackArg4 = null; + string callbackArg5 = null; + string callbackArg6 = null; + string callbackArg7 = null; + string callbackArg8 = null; + mock.Setup(x => x.Execute(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .Callback((string s1, string s2, string s3, string s4, string s5, string s6, string s7, string s8) => { callbackArg1 = s1; callbackArg2 = s2; callbackArg3 = s3; callbackArg4 = s4; callbackArg5 = s5; callbackArg6 = s6; callbackArg7 = s7; callbackArg8 = s8; }) + .Returns("foo"); + + mock.Object.Execute("blah1", "blah2", "blah3", "blah4", "blah5", "blah6", "blah7", "blah8"); + Assert.Equal("blah1", callbackArg1); + Assert.Equal("blah2", callbackArg2); + Assert.Equal("blah3", callbackArg3); + Assert.Equal("blah4", callbackArg4); + Assert.Equal("blah5", callbackArg5); + Assert.Equal("blah6", callbackArg6); + Assert.Equal("blah7", callbackArg7); + Assert.Equal("blah8", callbackArg8); + } + + [Fact] + public void CallbackCalledAfterReturnsCall() + { + var mock = new Mock(); + bool returnsCalled = false; + bool beforeCalled = false; + bool afterCalled = false; + + mock.Setup(foo => foo.Execute("ping")) + .Callback(() => { Assert.False(returnsCalled); beforeCalled = true; }) + .Returns(() => { returnsCalled = true; return "ack"; }) + .Callback(() => { Assert.True(returnsCalled); afterCalled = true; }); + + Assert.Equal("ack", mock.Object.Execute("ping")); + + Assert.True(beforeCalled); + Assert.True(afterCalled); + } + + [Fact] + public void CallbackCalledAfterReturnsCallWithArg() + { + var mock = new Mock(); + bool returnsCalled = false; + + mock.Setup(foo => foo.Execute(It.IsAny())) + .Callback(s => Assert.False(returnsCalled)) + .Returns(() => { returnsCalled = true; return "ack"; }) + .Callback(s => Assert.True(returnsCalled)); + + mock.Object.Execute("ping"); + + Assert.True(returnsCalled); + } + + [Fact] + public void CallbackCanReceiveABaseClass() + { + var mock = new Mock(MockBehavior.Strict); + mock.Setup(foo => foo.Method(It.IsAny())).Callback(TraceMe); + + mock.Object.Method(new Derived()); + } + + public interface IInterface + { + void Method(Derived b); + } + + public class Base + { + } + + public class Derived : Base + { + } + + private void TraceMe(Base b) + { + } + + public interface IFoo + { + void Submit(); + void Submit(string command); + string Submit(string arg1, string arg2); + string Submit(string arg1, string arg2, string arg3); + string Submit(string arg1, string arg2, string arg3, string arg4); + void Submit(string arg1, string arg2, string arg3, string arg4, string arg5); + void Submit(string arg1, string arg2, string arg3, string arg4, string arg5, string arg6); + void Submit(string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7); + void Submit(string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8); + string Execute(string command); + string Execute(string arg1, string arg2); + string Execute(string arg1, string arg2, string arg3); + string Execute(string arg1, string arg2, string arg3, string arg4); + string Execute(string arg1, string arg2, string arg3, string arg4, string arg5); + string Execute(string arg1, string arg2, string arg3, string arg4, string arg5, string arg6); + string Execute(string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7); + string Execute(string arg1, string arg2, string arg3, string arg4, string arg5, string arg6, string arg7, string arg8); + + int Value { get; set; } + } + } +} diff --git a/UnitTests/ConditionalSetupFixture.cs b/UnitTests/ConditionalSetupFixture.cs index 9c4f8e50f..44e0c0e62 100644 --- a/UnitTests/ConditionalSetupFixture.cs +++ b/UnitTests/ConditionalSetupFixture.cs @@ -1,165 +1,165 @@ -using System; -using Xunit; - -namespace Moq.Tests -{ - public class ConditionalSetupFixture - { - [Fact] - public void ChooseAffirmativeExpectationOnMethod() - { - var mock = new Mock(); - - var when = true; - - mock.When(() => when).Setup(x => x.Foo()).Returns("bar"); - mock.When(() => !when).Setup(x => x.Foo()).Returns("no bar"); - - Assert.Equal("bar", mock.Object.Foo()); - - when = false; - Assert.Equal("no bar", mock.Object.Foo()); - - when = true; - Assert.Equal("bar", mock.Object.Foo()); - } - - [Fact] - public void ChooseAffirmativeExpetationOnVoidMethod() - { - var mock = new Mock(); - - var when = true; - var positive = false; - var negative = false; - - mock.When(() => when).Setup(x => x.Bar()).Callback(() => positive = true); - mock.When(() => !when).Setup(x => x.Bar()).Callback(() => negative = true); - - mock.Object.Bar(); - - Assert.True(positive); - Assert.False(negative); - - when = false; - positive = false; - mock.Object.Bar(); - - Assert.False(positive); - Assert.True(negative); - - when = true; - negative = false; - mock.Object.Bar(); - - Assert.True(positive); - Assert.False(negative); - } - - [Fact] - public void ChooseAffirmativeExpectationOnPropertyGetter() - { - var mock = new Mock(); - - var first = true; - - mock.When(() => first).SetupGet(x => x.Value).Returns("bar"); - mock.When(() => !first).SetupGet(x => x.Value).Returns("no bar"); - - Assert.Equal("bar", mock.Object.Value); - first = false; - Assert.Equal("no bar", mock.Object.Value); - first = true; - Assert.Equal("bar", mock.Object.Value); - } - - [Fact] - public void ChooseAffirmativeExpetationOnPropertySetter() - { - var mock = new Mock(); - - var when = true; - var positive = false; - var negative = false; - - mock.When(() => when).SetupSet(x => x.Value = "foo").Callback(() => positive = true); - mock.When(() => !when).SetupSet(x => x.Value = "foo").Callback(() => negative = true); - - mock.Object.Value = "foo"; - - Assert.True(positive); - Assert.False(negative); - - when = false; - positive = false; - mock.Object.Value = "foo"; - - Assert.False(positive); - Assert.True(negative); - - when = true; - negative = false; - mock.Object.Value = "foo"; - - Assert.True(positive); - Assert.False(negative); - } - - [Fact] - public void ChooseAffirmativeExpetationOnTypedPropertySetter() - { - var mock = new Mock(); - - var when = true; - var positive = false; - var negative = false; - - mock.When(() => when).SetupSet(x => x.Value = "foo").Callback(s => positive = true); - mock.When(() => !when).SetupSet(x => x.Value = "foo").Callback(s => negative = true); - - mock.Object.Value = "foo"; - - Assert.True(positive); - Assert.False(negative); - - when = false; - positive = false; - mock.Object.Value = "foo"; - - Assert.False(positive); - Assert.True(negative); - - when = true; - negative = false; - mock.Object.Value = "foo"; - - Assert.True(positive); - Assert.False(negative); - } - - [Fact] - public void ChooseAffirmativeExpectationOnPropertyIndexer() - { - var mock = new Mock(); - - var first = true; - - mock.When(() => first).Setup(x => x[0]).Returns("bar"); - mock.When(() => !first).Setup(x => x[0]).Returns("no bar"); - - Assert.Equal("bar", mock.Object[0]); - first = false; - Assert.Equal("no bar", mock.Object[0]); - first = true; - Assert.Equal("bar", mock.Object[0]); - } - - public interface IFoo - { - string Value { get; set; } - string this[int index] { get; } - void Bar(); - string Foo(); - } - } +using System; +using Xunit; + +namespace Moq.Tests +{ + public class ConditionalSetupFixture + { + [Fact] + public void ChooseAffirmativeExpectationOnMethod() + { + var mock = new Mock(); + + var when = true; + + mock.When(() => when).Setup(x => x.Foo()).Returns("bar"); + mock.When(() => !when).Setup(x => x.Foo()).Returns("no bar"); + + Assert.Equal("bar", mock.Object.Foo()); + + when = false; + Assert.Equal("no bar", mock.Object.Foo()); + + when = true; + Assert.Equal("bar", mock.Object.Foo()); + } + + [Fact] + public void ChooseAffirmativeExpetationOnVoidMethod() + { + var mock = new Mock(); + + var when = true; + var positive = false; + var negative = false; + + mock.When(() => when).Setup(x => x.Bar()).Callback(() => positive = true); + mock.When(() => !when).Setup(x => x.Bar()).Callback(() => negative = true); + + mock.Object.Bar(); + + Assert.True(positive); + Assert.False(negative); + + when = false; + positive = false; + mock.Object.Bar(); + + Assert.False(positive); + Assert.True(negative); + + when = true; + negative = false; + mock.Object.Bar(); + + Assert.True(positive); + Assert.False(negative); + } + + [Fact] + public void ChooseAffirmativeExpectationOnPropertyGetter() + { + var mock = new Mock(); + + var first = true; + + mock.When(() => first).SetupGet(x => x.Value).Returns("bar"); + mock.When(() => !first).SetupGet(x => x.Value).Returns("no bar"); + + Assert.Equal("bar", mock.Object.Value); + first = false; + Assert.Equal("no bar", mock.Object.Value); + first = true; + Assert.Equal("bar", mock.Object.Value); + } + + [Fact] + public void ChooseAffirmativeExpetationOnPropertySetter() + { + var mock = new Mock(); + + var when = true; + var positive = false; + var negative = false; + + mock.When(() => when).SetupSet(x => x.Value = "foo").Callback(() => positive = true); + mock.When(() => !when).SetupSet(x => x.Value = "foo").Callback(() => negative = true); + + mock.Object.Value = "foo"; + + Assert.True(positive); + Assert.False(negative); + + when = false; + positive = false; + mock.Object.Value = "foo"; + + Assert.False(positive); + Assert.True(negative); + + when = true; + negative = false; + mock.Object.Value = "foo"; + + Assert.True(positive); + Assert.False(negative); + } + + [Fact] + public void ChooseAffirmativeExpetationOnTypedPropertySetter() + { + var mock = new Mock(); + + var when = true; + var positive = false; + var negative = false; + + mock.When(() => when).SetupSet(x => x.Value = "foo").Callback(s => positive = true); + mock.When(() => !when).SetupSet(x => x.Value = "foo").Callback(s => negative = true); + + mock.Object.Value = "foo"; + + Assert.True(positive); + Assert.False(negative); + + when = false; + positive = false; + mock.Object.Value = "foo"; + + Assert.False(positive); + Assert.True(negative); + + when = true; + negative = false; + mock.Object.Value = "foo"; + + Assert.True(positive); + Assert.False(negative); + } + + [Fact] + public void ChooseAffirmativeExpectationOnPropertyIndexer() + { + var mock = new Mock(); + + var first = true; + + mock.When(() => first).Setup(x => x[0]).Returns("bar"); + mock.When(() => !first).Setup(x => x[0]).Returns("no bar"); + + Assert.Equal("bar", mock.Object[0]); + first = false; + Assert.Equal("no bar", mock.Object[0]); + first = true; + Assert.Equal("bar", mock.Object[0]); + } + + public interface IFoo + { + string Value { get; set; } + string this[int index] { get; } + void Bar(); + string Foo(); + } + } } \ No newline at end of file diff --git a/UnitTests/CustomMatcherFixture.cs b/UnitTests/CustomMatcherFixture.cs index 73d1c29fa..0d6498b2a 100644 --- a/UnitTests/CustomMatcherFixture.cs +++ b/UnitTests/CustomMatcherFixture.cs @@ -1,64 +1,64 @@ -using System; -using Xunit; - -namespace Moq.Tests -{ - public class CustomMatcherFixture - { - [Fact] - public void UsesCustomMatcher() - { - var mock = new Mock(); - - mock.Setup(m => m.Do(Any())).Returns(true); - - Assert.True(mock.Object.Do("foo")); - } - - [Fact] - public void UsesCustomMatcherWithArgument() - { - var mock = new Mock(); - - mock.Setup(m => m.Do(Between(1, 5, Range.Inclusive))).Returns(true); - - Assert.False(mock.Object.Do(6)); - Assert.True(mock.Object.Do(1)); - Assert.True(mock.Object.Do(5)); - } - - public TValue Any() - { - return Match.Create(v => true); - } - - public TValue Between(TValue from, TValue to, Range rangeKind) - where TValue : IComparable - { - return Match.Create(value => - { - if (value == null) - { - return false; - } - - if (rangeKind == Range.Exclusive) - { - return value.CompareTo(from) > 0 && - value.CompareTo(to) < 0; - } - else - { - return value.CompareTo(from) >= 0 && - value.CompareTo(to) <= 0; - } - }); - } - - public interface IFoo - { - bool Do(string value); - bool Do(int value); - } - } -} +using System; +using Xunit; + +namespace Moq.Tests +{ + public class CustomMatcherFixture + { + [Fact] + public void UsesCustomMatcher() + { + var mock = new Mock(); + + mock.Setup(m => m.Do(Any())).Returns(true); + + Assert.True(mock.Object.Do("foo")); + } + + [Fact] + public void UsesCustomMatcherWithArgument() + { + var mock = new Mock(); + + mock.Setup(m => m.Do(Between(1, 5, Range.Inclusive))).Returns(true); + + Assert.False(mock.Object.Do(6)); + Assert.True(mock.Object.Do(1)); + Assert.True(mock.Object.Do(5)); + } + + public TValue Any() + { + return Match.Create(v => true); + } + + public TValue Between(TValue from, TValue to, Range rangeKind) + where TValue : IComparable + { + return Match.Create(value => + { + if (value == null) + { + return false; + } + + if (rangeKind == Range.Exclusive) + { + return value.CompareTo(from) > 0 && + value.CompareTo(to) < 0; + } + else + { + return value.CompareTo(from) >= 0 && + value.CompareTo(to) <= 0; + } + }); + } + + public interface IFoo + { + bool Do(string value); + bool Do(int value); + } + } +} diff --git a/UnitTests/Demo.cs b/UnitTests/Demo.cs index 86b02b01b..ea15bb7c4 100644 --- a/UnitTests/Demo.cs +++ b/UnitTests/Demo.cs @@ -1,182 +1,182 @@ -using System; -using Xunit; - -namespace Moq.Tests -{ - public class Demo - { - private static string TALISKER = "Talisker"; - - [Fact] - public void FillingRemovesInventoryIfInStock() - { - //setup - data - var order = new Order(TALISKER, 50); - var mock = new Mock(); - - //setup - expectations - mock.Setup(x => x.HasInventory(TALISKER, 50)).Returns(true); - - //exercise - order.Fill(mock.Object); - - //verify state - Assert.True(order.IsFilled); - //verify interaction - mock.VerifyAll(); - } - - public void FillingDoesNotRemoveIfNotEnoughInStock() - { - //setup - data - var order = new Order(TALISKER, 50); - var mock = new Mock(); - - //setup - expectations - mock.Setup(x => x.HasInventory(It.IsAny(), It.IsInRange(0, 100, Range.Inclusive))).Returns(false); - mock.Setup(x => x.Remove(It.IsAny(), It.IsAny())).Throws(new InvalidOperationException()); - - //exercise - order.Fill(mock.Object); - - //verify - Assert.False(order.IsFilled); - } - - public void TestPresenterSelection() - { - var mockView = new Mock(); - var presenter = new OrdersPresenter(mockView.Object); - - // Check that the presenter has no selection by default - Assert.Null(presenter.SelectedOrder); - - // Finally raise the event with a specific arguments data - mockView.Raise(mv => mv.OrderSelected += null, new OrderEventArgs { Order = new Order("moq", 500) }); - - // Now the presenter reacted to the event, and we have a selected order - Assert.NotNull(presenter.SelectedOrder); - Assert.Equal("moq", presenter.SelectedOrder.ProductName); - } - - public class OrderEventArgs : EventArgs - { - public Order Order { get; set; } - } - - public interface IOrdersView - { - event EventHandler OrderSelected; - } - - public class OrdersPresenter - { - public OrdersPresenter(IOrdersView view) - { - view.OrderSelected += (sender, args) => DoOrderSelection(args.Order); - } - - public Order SelectedOrder { get; private set; } - - private void DoOrderSelection(Order selectedOrder) - { - // Do something when the view selects an order. - SelectedOrder = selectedOrder; - } - } - - public interface IWarehouse - { - bool HasInventory(string productName, int quantity); - void Remove(string productName, int quantity); - } - - public class Order - { - public string ProductName { get; private set; } - public int Quantity { get; private set; } - public bool IsFilled { get; private set; } - - public Order(string productName, int quantity) - { - this.ProductName = productName; - this.Quantity = quantity; - } - - public void Fill(IWarehouse warehouse) - { - if (warehouse.HasInventory(ProductName, Quantity)) - { - warehouse.Remove(ProductName, Quantity); - IsFilled = true; - } - } - - } - - [Fact] - [Obsolete] - public void ProjectHomePageDemo() - { - var mock = new Mock(); - - // WOW! No record/reply weirdness?! :) - mock.Setup(framework => framework.ShouldDownload(It.IsAny())) - .Callback((Version version) => - Console.WriteLine("Someone wanted version {0}!!!", version)) - .Returns(true) - .AtMostOnce(); - - // Hand mock.Object as a collaborator and exercise it, - // like calling methods on it... - ILoveThisFramework lovable = mock.Object; - bool download = lovable.ShouldDownload(new Version("2.0.0.0")); - - mock.VerifyAll(); - mock.Verify(framework => framework.ShouldDownload(new Version("2.0.0.0"))); - } - - public interface ILoveThisFramework - { - bool ShouldDownload(Version version); - } - - public void When_user_forgot_password_should_save_user() - { - var userRepository = new Mock(); - var smsSender = new Mock(); - - var theUser = new User { HashedPassword = "this is not hashed password" }; - - userRepository.Setup(x => x.GetUserByName("ayende")).Returns(theUser); - - var controllerUnderTest = new LoginController(userRepository.Object, smsSender.Object); - - controllerUnderTest.ForgotMyPassword("ayende"); - - userRepository.Verify(x => x.Save(theUser)); - } - - public interface ISmsSender { } - public interface IUserRepository - { - void Save(User user); - User GetUserByName(string username); - } - - public class User - { - public string HashedPassword { get; set; } - } - - public class LoginController - { - public LoginController(IUserRepository repo, ISmsSender sender) - { - } - - public void ForgotMyPassword(string username) { } - } - - } -} +using System; +using Xunit; + +namespace Moq.Tests +{ + public class Demo + { + private static string TALISKER = "Talisker"; + + [Fact] + public void FillingRemovesInventoryIfInStock() + { + //setup - data + var order = new Order(TALISKER, 50); + var mock = new Mock(); + + //setup - expectations + mock.Setup(x => x.HasInventory(TALISKER, 50)).Returns(true); + + //exercise + order.Fill(mock.Object); + + //verify state + Assert.True(order.IsFilled); + //verify interaction + mock.VerifyAll(); + } + + public void FillingDoesNotRemoveIfNotEnoughInStock() + { + //setup - data + var order = new Order(TALISKER, 50); + var mock = new Mock(); + + //setup - expectations + mock.Setup(x => x.HasInventory(It.IsAny(), It.IsInRange(0, 100, Range.Inclusive))).Returns(false); + mock.Setup(x => x.Remove(It.IsAny(), It.IsAny())).Throws(new InvalidOperationException()); + + //exercise + order.Fill(mock.Object); + + //verify + Assert.False(order.IsFilled); + } + + public void TestPresenterSelection() + { + var mockView = new Mock(); + var presenter = new OrdersPresenter(mockView.Object); + + // Check that the presenter has no selection by default + Assert.Null(presenter.SelectedOrder); + + // Finally raise the event with a specific arguments data + mockView.Raise(mv => mv.OrderSelected += null, new OrderEventArgs { Order = new Order("moq", 500) }); + + // Now the presenter reacted to the event, and we have a selected order + Assert.NotNull(presenter.SelectedOrder); + Assert.Equal("moq", presenter.SelectedOrder.ProductName); + } + + public class OrderEventArgs : EventArgs + { + public Order Order { get; set; } + } + + public interface IOrdersView + { + event EventHandler OrderSelected; + } + + public class OrdersPresenter + { + public OrdersPresenter(IOrdersView view) + { + view.OrderSelected += (sender, args) => DoOrderSelection(args.Order); + } + + public Order SelectedOrder { get; private set; } + + private void DoOrderSelection(Order selectedOrder) + { + // Do something when the view selects an order. + SelectedOrder = selectedOrder; + } + } + + public interface IWarehouse + { + bool HasInventory(string productName, int quantity); + void Remove(string productName, int quantity); + } + + public class Order + { + public string ProductName { get; private set; } + public int Quantity { get; private set; } + public bool IsFilled { get; private set; } + + public Order(string productName, int quantity) + { + this.ProductName = productName; + this.Quantity = quantity; + } + + public void Fill(IWarehouse warehouse) + { + if (warehouse.HasInventory(ProductName, Quantity)) + { + warehouse.Remove(ProductName, Quantity); + IsFilled = true; + } + } + + } + + [Fact] + [Obsolete] + public void ProjectHomePageDemo() + { + var mock = new Mock(); + + // WOW! No record/reply weirdness?! :) + mock.Setup(framework => framework.ShouldDownload(It.IsAny())) + .Callback((Version version) => + Console.WriteLine("Someone wanted version {0}!!!", version)) + .Returns(true) + .AtMostOnce(); + + // Hand mock.Object as a collaborator and exercise it, + // like calling methods on it... + ILoveThisFramework lovable = mock.Object; + bool download = lovable.ShouldDownload(new Version("2.0.0.0")); + + mock.VerifyAll(); + mock.Verify(framework => framework.ShouldDownload(new Version("2.0.0.0"))); + } + + public interface ILoveThisFramework + { + bool ShouldDownload(Version version); + } + + public void When_user_forgot_password_should_save_user() + { + var userRepository = new Mock(); + var smsSender = new Mock(); + + var theUser = new User { HashedPassword = "this is not hashed password" }; + + userRepository.Setup(x => x.GetUserByName("ayende")).Returns(theUser); + + var controllerUnderTest = new LoginController(userRepository.Object, smsSender.Object); + + controllerUnderTest.ForgotMyPassword("ayende"); + + userRepository.Verify(x => x.Save(theUser)); + } + + public interface ISmsSender { } + public interface IUserRepository + { + void Save(User user); + User GetUserByName(string username); + } + + public class User + { + public string HashedPassword { get; set; } + } + + public class LoginController + { + public LoginController(IUserRepository repo, ISmsSender sender) + { + } + + public void ForgotMyPassword(string username) { } + } + + } +} diff --git a/UnitTests/EmptyDefaultValueProviderFixture.cs b/UnitTests/EmptyDefaultValueProviderFixture.cs index 256ecf70e..a02732444 100644 --- a/UnitTests/EmptyDefaultValueProviderFixture.cs +++ b/UnitTests/EmptyDefaultValueProviderFixture.cs @@ -1,127 +1,127 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace Moq.Tests -{ - public class EmptyDefaultValueProviderFixture - { - [Fact] - public void ProvidesNullString() - { - var provider = new EmptyDefaultValueProvider(); - - var value = provider.ProvideDefault(typeof(IFoo).GetProperty("StringValue").GetGetMethod()); - - Assert.Null(value); - } - - [Fact] - public void ProvidesDefaultInt() - { - var provider = new EmptyDefaultValueProvider(); - - var value = provider.ProvideDefault(typeof(IFoo).GetProperty("IntValue").GetGetMethod()); - - Assert.Equal(default(int), value); - } - - [Fact] - public void ProvidesNullInt() - { - var provider = new EmptyDefaultValueProvider(); - - var value = provider.ProvideDefault(typeof(IFoo).GetProperty("NullableIntValue").GetGetMethod()); - - Assert.Null(value); - } - - [Fact] - public void ProvidesDefaultBool() - { - var provider = new EmptyDefaultValueProvider(); - - var value = provider.ProvideDefault(typeof(IFoo).GetProperty("BoolValue").GetGetMethod()); - - Assert.Equal(default(bool), value); - } - - [Fact] - public void ProvidesDefaultEnum() - { - var provider = new EmptyDefaultValueProvider(); - - var value = provider.ProvideDefault(typeof(IFoo).GetProperty("Platform").GetGetMethod()); - - Assert.Equal(default(PlatformID), value); - } - - [Fact] - public void ProvidesEmptyEnumerable() - { - var provider = new EmptyDefaultValueProvider(); - - var value = provider.ProvideDefault(typeof(IFoo).GetProperty("Indexes").GetGetMethod()); - Assert.True(value is IEnumerable && ((IEnumerable)value).Count() == 0); - } - - [Fact] - public void ProvidesEmptyArray() - { - var provider = new EmptyDefaultValueProvider(); - - var value = provider.ProvideDefault(typeof(IFoo).GetProperty("Bars").GetGetMethod()); - Assert.True(value is IBar[] && ((IBar[])value).Length == 0); - } - - [Fact] - public void ProvidesNullReferenceTypes() - { - var provider = new EmptyDefaultValueProvider(); - - var value1 = provider.ProvideDefault(typeof(IFoo).GetProperty("Bar").GetGetMethod()); - var value2 = provider.ProvideDefault(typeof(IFoo).GetProperty("Object").GetGetMethod()); - - Assert.Null(value1); - Assert.Null(value2); - } - - [Fact] - public void ProvideEmptyQueryable() - { - var provider = new EmptyDefaultValueProvider(); - var value = provider.ProvideDefault(typeof(IFoo).GetProperty("Queryable").GetGetMethod()); - - Assert.IsAssignableFrom>(value); - Assert.Equal(0, ((IQueryable)value).Count()); - } - - [Fact] - public void ProvideEmptyQueryableObjects() - { - var provider = new EmptyDefaultValueProvider(); - var value = provider.ProvideDefault(typeof(IFoo).GetProperty("QueryableObjects").GetGetMethod()); - - Assert.IsAssignableFrom(value); - Assert.Equal(0, ((IQueryable)value).Cast().Count()); - } - - public interface IFoo - { - object Object { get; set; } - IBar Bar { get; set; } - string StringValue { get; set; } - int IntValue { get; set; } - bool BoolValue { get; set; } - int? NullableIntValue { get; set; } - PlatformID Platform { get; set; } - IEnumerable Indexes { get; set; } - IBar[] Bars { get; set; } - IQueryable Queryable { get; } - IQueryable QueryableObjects { get; } - } - - public interface IBar { } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using Xunit; + +namespace Moq.Tests +{ + public class EmptyDefaultValueProviderFixture + { + [Fact] + public void ProvidesNullString() + { + var provider = new EmptyDefaultValueProvider(); + + var value = provider.ProvideDefault(typeof(IFoo).GetProperty("StringValue").GetGetMethod()); + + Assert.Null(value); + } + + [Fact] + public void ProvidesDefaultInt() + { + var provider = new EmptyDefaultValueProvider(); + + var value = provider.ProvideDefault(typeof(IFoo).GetProperty("IntValue").GetGetMethod()); + + Assert.Equal(default(int), value); + } + + [Fact] + public void ProvidesNullInt() + { + var provider = new EmptyDefaultValueProvider(); + + var value = provider.ProvideDefault(typeof(IFoo).GetProperty("NullableIntValue").GetGetMethod()); + + Assert.Null(value); + } + + [Fact] + public void ProvidesDefaultBool() + { + var provider = new EmptyDefaultValueProvider(); + + var value = provider.ProvideDefault(typeof(IFoo).GetProperty("BoolValue").GetGetMethod()); + + Assert.Equal(default(bool), value); + } + + [Fact] + public void ProvidesDefaultEnum() + { + var provider = new EmptyDefaultValueProvider(); + + var value = provider.ProvideDefault(typeof(IFoo).GetProperty("Platform").GetGetMethod()); + + Assert.Equal(default(PlatformID), value); + } + + [Fact] + public void ProvidesEmptyEnumerable() + { + var provider = new EmptyDefaultValueProvider(); + + var value = provider.ProvideDefault(typeof(IFoo).GetProperty("Indexes").GetGetMethod()); + Assert.True(value is IEnumerable && ((IEnumerable)value).Count() == 0); + } + + [Fact] + public void ProvidesEmptyArray() + { + var provider = new EmptyDefaultValueProvider(); + + var value = provider.ProvideDefault(typeof(IFoo).GetProperty("Bars").GetGetMethod()); + Assert.True(value is IBar[] && ((IBar[])value).Length == 0); + } + + [Fact] + public void ProvidesNullReferenceTypes() + { + var provider = new EmptyDefaultValueProvider(); + + var value1 = provider.ProvideDefault(typeof(IFoo).GetProperty("Bar").GetGetMethod()); + var value2 = provider.ProvideDefault(typeof(IFoo).GetProperty("Object").GetGetMethod()); + + Assert.Null(value1); + Assert.Null(value2); + } + + [Fact] + public void ProvideEmptyQueryable() + { + var provider = new EmptyDefaultValueProvider(); + var value = provider.ProvideDefault(typeof(IFoo).GetProperty("Queryable").GetGetMethod()); + + Assert.IsAssignableFrom>(value); + Assert.Equal(0, ((IQueryable)value).Count()); + } + + [Fact] + public void ProvideEmptyQueryableObjects() + { + var provider = new EmptyDefaultValueProvider(); + var value = provider.ProvideDefault(typeof(IFoo).GetProperty("QueryableObjects").GetGetMethod()); + + Assert.IsAssignableFrom(value); + Assert.Equal(0, ((IQueryable)value).Cast().Count()); + } + + public interface IFoo + { + object Object { get; set; } + IBar Bar { get; set; } + string StringValue { get; set; } + int IntValue { get; set; } + bool BoolValue { get; set; } + int? NullableIntValue { get; set; } + PlatformID Platform { get; set; } + IEnumerable Indexes { get; set; } + IBar[] Bars { get; set; } + IQueryable Queryable { get; } + IQueryable QueryableObjects { get; } + } + + public interface IBar { } + } +} diff --git a/UnitTests/ExpressionExtensionsFixture.cs b/UnitTests/ExpressionExtensionsFixture.cs index 10f271820..4f9b819d4 100644 --- a/UnitTests/ExpressionExtensionsFixture.cs +++ b/UnitTests/ExpressionExtensionsFixture.cs @@ -1,149 +1,149 @@ -using System; -using System.Linq.Expressions; -using Xunit; - -namespace Moq.Tests -{ - public class ExpressionExtensionsFixture - { - [Fact] - public void FixesGenericMethodName() - { - Expression> expr1 = f => f.Do(""); - Expression> expr2 = f => f.Do(5); - - Assert.NotEqual(expr1.ToStringFixed(), expr2.ToStringFixed()); - } - - [Fact] - public void PrefixesStaticMethodWithClass() - { - Expression expr = () => DoStatic(5); - - var value = expr.ToStringFixed(); - - Assert.Contains("ExpressionExtensionsFixture.DoStatic(5)", value); - } - - [Fact] - public void PrefixesStaticGenericMethodWithClass() - { - Expression expr = () => DoStaticGeneric(5); - - var value = expr.ToStringFixed(); - - Assert.Contains("ExpressionExtensionsFixture.DoStaticGeneric(5)", value); - } - - [Fact] - public void ToLambdaThrowsIfNullExpression() - { - Assert.Throws(() => ExpressionExtensions.ToLambda(null)); - } - - [Fact] - public void ToLambdaThrowsIfExpressionNotLambda() - { - Assert.Throws(() => Expression.Constant(5).ToLambda()); - } - - [Fact] - public void ToLambdaRemovesConvert() - { - var lambda = ToExpression(() => (object)5); - - var result = lambda.ToLambda(); - - Assert.Equal(typeof(int), result.Compile().Method.ReturnType); - } - - [Fact] - public void IsPropertyLambdaTrue() - { - var expr = ToExpression(f => f.Value).ToLambda(); - - Assert.True(expr.IsProperty()); - } - - [Fact] - public void IsPropertyLambdaFalse() - { - var expr = ToExpression(f => f.Do()).ToLambda(); - - Assert.False(expr.IsProperty()); - } - - [Fact] - public void IsPropertyExpressionTrue() - { - var expr = ToExpression(f => f.Value).ToLambda().Body; - - Assert.True(expr.IsProperty()); - } - - [Fact] - public void IsPropertyExpressionFalse() - { - var expr = ToExpression(f => f.Do()).ToLambda().Body; - - Assert.False(expr.IsProperty()); - } - - [Fact] - public void IsPropertyIndexerExpressionTrue() - { - var expr = ToExpression(f => f[5]).ToLambda().Body; - - Assert.True(expr.IsPropertyIndexer()); - } - - [Fact] - public void ToMethodCallThrowsIfNotMethodCall() - { - var expr = ToExpression(f => f.Value).ToLambda(); - - Assert.Throws(() => expr.ToMethodCall()); - } - - [Fact] - public void ToMethodCallConvertsLambda() - { - var expr = ToExpression(f => f.Do()).ToLambda(); - - Assert.Equal(typeof(IFoo).GetMethod("Do"), expr.ToMethodCall().Method); - } - - [Fact] - public void ToPropertyInfoConvertsExpression() - { - - } - - private Expression ToExpression(Expression> expression) - { - return expression; - } - - private Expression ToExpression(Expression> expression) - { - return expression; - } - - private Expression ToExpression(Expression> expression) - { - return expression; - } - - private void Do(T value) { } - - private static void DoStatic(int value) { } - private static void DoStaticGeneric(T value) { } - - public interface IFoo - { - int Value { get; set; } - void Do(); - object this[int index] { get; set; } - } - } -} +using System; +using System.Linq.Expressions; +using Xunit; + +namespace Moq.Tests +{ + public class ExpressionExtensionsFixture + { + [Fact] + public void FixesGenericMethodName() + { + Expression> expr1 = f => f.Do(""); + Expression> expr2 = f => f.Do(5); + + Assert.NotEqual(expr1.ToStringFixed(), expr2.ToStringFixed()); + } + + [Fact] + public void PrefixesStaticMethodWithClass() + { + Expression expr = () => DoStatic(5); + + var value = expr.ToStringFixed(); + + Assert.Contains("ExpressionExtensionsFixture.DoStatic(5)", value); + } + + [Fact] + public void PrefixesStaticGenericMethodWithClass() + { + Expression expr = () => DoStaticGeneric(5); + + var value = expr.ToStringFixed(); + + Assert.Contains("ExpressionExtensionsFixture.DoStaticGeneric(5)", value); + } + + [Fact] + public void ToLambdaThrowsIfNullExpression() + { + Assert.Throws(() => ExpressionExtensions.ToLambda(null)); + } + + [Fact] + public void ToLambdaThrowsIfExpressionNotLambda() + { + Assert.Throws(() => Expression.Constant(5).ToLambda()); + } + + [Fact] + public void ToLambdaRemovesConvert() + { + var lambda = ToExpression(() => (object)5); + + var result = lambda.ToLambda(); + + Assert.Equal(typeof(int), result.Compile().Method.ReturnType); + } + + [Fact] + public void IsPropertyLambdaTrue() + { + var expr = ToExpression(f => f.Value).ToLambda(); + + Assert.True(expr.IsProperty()); + } + + [Fact] + public void IsPropertyLambdaFalse() + { + var expr = ToExpression(f => f.Do()).ToLambda(); + + Assert.False(expr.IsProperty()); + } + + [Fact] + public void IsPropertyExpressionTrue() + { + var expr = ToExpression(f => f.Value).ToLambda().Body; + + Assert.True(expr.IsProperty()); + } + + [Fact] + public void IsPropertyExpressionFalse() + { + var expr = ToExpression(f => f.Do()).ToLambda().Body; + + Assert.False(expr.IsProperty()); + } + + [Fact] + public void IsPropertyIndexerExpressionTrue() + { + var expr = ToExpression(f => f[5]).ToLambda().Body; + + Assert.True(expr.IsPropertyIndexer()); + } + + [Fact] + public void ToMethodCallThrowsIfNotMethodCall() + { + var expr = ToExpression(f => f.Value).ToLambda(); + + Assert.Throws(() => expr.ToMethodCall()); + } + + [Fact] + public void ToMethodCallConvertsLambda() + { + var expr = ToExpression(f => f.Do()).ToLambda(); + + Assert.Equal(typeof(IFoo).GetMethod("Do"), expr.ToMethodCall().Method); + } + + [Fact] + public void ToPropertyInfoConvertsExpression() + { + + } + + private Expression ToExpression(Expression> expression) + { + return expression; + } + + private Expression ToExpression(Expression> expression) + { + return expression; + } + + private Expression ToExpression(Expression> expression) + { + return expression; + } + + private void Do(T value) { } + + private static void DoStatic(int value) { } + private static void DoStaticGeneric(T value) { } + + public interface IFoo + { + int Value { get; set; } + void Do(); + object this[int index] { get; set; } + } + } +} diff --git a/UnitTests/ExtensibilityFixture.cs b/UnitTests/ExtensibilityFixture.cs index 279101562..76f0d17ac 100644 --- a/UnitTests/ExtensibilityFixture.cs +++ b/UnitTests/ExtensibilityFixture.cs @@ -1,137 +1,137 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace Moq.Tests -{ - public class ExtensibilityFixture - { - [Fact] - public void ShouldExtendMatching() - { - var mock = new Mock(); - mock.Setup(repo => repo.Save(OrderIs.Big())) - .Throws(new InvalidOperationException()); - - try - { - mock.Object.Save(new Order { Amount = 1000 }); - - Assert.True(false, "Should have failed for big order"); - } - catch (InvalidOperationException) - { - } - } - - [Fact] - public void ShouldExtendWithSimpleMatchers() - { - var order = new Order(); - var mock = new Mock(); - - Order repo = Match.Create(r => true); - - mock.Setup(x => x.Save(Orders.Contains(order))) - .Throws(); - - Assert.Throws(() => mock.Object.Save(new[] { order })); - } - - [Fact] - public void ShouldExtendWithPropertyMatchers() - { - var mock = new Mock(); - mock.Setup(repo => repo.Save(Orders.IsSmall)) - .Throws(new InvalidOperationException()); - - try - { - mock.Object.Save(new Order { Amount = 50 }); - - Assert.True(false, "Should have failed for small order"); - } - catch (InvalidOperationException) - { - } - } - - //[Fact] - //public void SetterMatcherRendersNicely() - //{ - // var mock = new Mock(); - - // try - // { - // mock.VerifySet(repo => repo.Value = It.IsAny()); - // } - // catch (MockException me) - // { - // Console.WriteLine(me.Message); - // } - - // mock.Object.Value = 25; - - // mock.VerifySet(repo => repo.Value = It.IsInRange(10, 25, Range.Inclusive)); - //} - } - - public static class Orders - { - public static IEnumerable Contains(Order order) - { - return Match.Create>(orders => orders.Contains(order)); - } - - public static Order IsBig() - { - return Match.Create(o => o.Amount >= 1000); - } - - public static Order IsSmall - { - get - { - return Match.Create(o => o.Amount <= 1000); - } - } - } - - public interface IOrderRepository - { - void Save(Order order); - void Save(IEnumerable orders); - int Value { get; set; } - } - - public static class OrderIs - { - [AdvancedMatcher(typeof(BigOrderMatcher))] - public static Order Big() - { - return null; - } - - public class BigOrderMatcher : IMatcher - { - public void Initialize(System.Linq.Expressions.Expression matcherExpression) - { - } - - public bool Matches(object value) - { - if (value is Order && - ((Order)value).Amount >= 1000) - return true; - - return false; - } - } - } - - public class Order - { - public int Amount { get; set; } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using Xunit; + +namespace Moq.Tests +{ + public class ExtensibilityFixture + { + [Fact] + public void ShouldExtendMatching() + { + var mock = new Mock(); + mock.Setup(repo => repo.Save(OrderIs.Big())) + .Throws(new InvalidOperationException()); + + try + { + mock.Object.Save(new Order { Amount = 1000 }); + + Assert.True(false, "Should have failed for big order"); + } + catch (InvalidOperationException) + { + } + } + + [Fact] + public void ShouldExtendWithSimpleMatchers() + { + var order = new Order(); + var mock = new Mock(); + + Order repo = Match.Create(r => true); + + mock.Setup(x => x.Save(Orders.Contains(order))) + .Throws(); + + Assert.Throws(() => mock.Object.Save(new[] { order })); + } + + [Fact] + public void ShouldExtendWithPropertyMatchers() + { + var mock = new Mock(); + mock.Setup(repo => repo.Save(Orders.IsSmall)) + .Throws(new InvalidOperationException()); + + try + { + mock.Object.Save(new Order { Amount = 50 }); + + Assert.True(false, "Should have failed for small order"); + } + catch (InvalidOperationException) + { + } + } + + //[Fact] + //public void SetterMatcherRendersNicely() + //{ + // var mock = new Mock(); + + // try + // { + // mock.VerifySet(repo => repo.Value = It.IsAny()); + // } + // catch (MockException me) + // { + // Console.WriteLine(me.Message); + // } + + // mock.Object.Value = 25; + + // mock.VerifySet(repo => repo.Value = It.IsInRange(10, 25, Range.Inclusive)); + //} + } + + public static class Orders + { + public static IEnumerable Contains(Order order) + { + return Match.Create>(orders => orders.Contains(order)); + } + + public static Order IsBig() + { + return Match.Create(o => o.Amount >= 1000); + } + + public static Order IsSmall + { + get + { + return Match.Create(o => o.Amount <= 1000); + } + } + } + + public interface IOrderRepository + { + void Save(Order order); + void Save(IEnumerable orders); + int Value { get; set; } + } + + public static class OrderIs + { + [AdvancedMatcher(typeof(BigOrderMatcher))] + public static Order Big() + { + return null; + } + + public class BigOrderMatcher : IMatcher + { + public void Initialize(System.Linq.Expressions.Expression matcherExpression) + { + } + + public bool Matches(object value) + { + if (value is Order && + ((Order)value).Amount >= 1000) + return true; + + return false; + } + } + } + + public class Order + { + public int Amount { get; set; } + } +} diff --git a/UnitTests/Library/ClassLibrary1.Silverlight/ClassLibrary1.Silverlight.csproj b/UnitTests/Library/ClassLibrary1.Silverlight/ClassLibrary1.Silverlight.csproj index 2c0ee7372..f2d99c643 100644 --- a/UnitTests/Library/ClassLibrary1.Silverlight/ClassLibrary1.Silverlight.csproj +++ b/UnitTests/Library/ClassLibrary1.Silverlight/ClassLibrary1.Silverlight.csproj @@ -1,88 +1,88 @@ - - - - Debug - AnyCPU - 8.0.50727 - 2.0 - {48D475B6-CB45-44AD-91B7-964135AB0B5C} - {A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} - Library - Properties - ClassLibrary1.Silverlight - ClassLibrary1.Silverlight - Silverlight - v4.0 - $(TargetFrameworkVersion) - false - true - true - $([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Moq.Tests.csproj))\ - - - - v3.5 - - - true - full - false - DEBUG;TRACE;SILVERLIGHT - true - true - prompt - 4 - - - pdbonly - true - TRACE;SILVERLIGHT - true - true - prompt - 4 - - - true - - - ..\ClassLibrary1\Foo.snk - - - - - - - - - - - - - Foo.cs - - - - - - Foo.snk - - - - - - - - - - - + + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {48D475B6-CB45-44AD-91B7-964135AB0B5C} + {A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + ClassLibrary1.Silverlight + ClassLibrary1.Silverlight + Silverlight + v4.0 + $(TargetFrameworkVersion) + false + true + true + $([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Moq.Tests.csproj))\ + + + + v3.5 + + + true + full + false + DEBUG;TRACE;SILVERLIGHT + true + true + prompt + 4 + + + pdbonly + true + TRACE;SILVERLIGHT + true + true + prompt + 4 + + + true + + + ..\ClassLibrary1\Foo.snk + + + + + + + + + + + + + Foo.cs + + + + + + Foo.snk + + + + + + + + + + + \ No newline at end of file diff --git a/UnitTests/Library/ClassLibrary1.Silverlight/Properties/AssemblyInfo.cs b/UnitTests/Library/ClassLibrary1.Silverlight/Properties/AssemblyInfo.cs index 69c7dc794..7653c5272 100644 --- a/UnitTests/Library/ClassLibrary1.Silverlight/Properties/AssemblyInfo.cs +++ b/UnitTests/Library/ClassLibrary1.Silverlight/Properties/AssemblyInfo.cs @@ -1,35 +1,35 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("ClassLibrary1.Silverlight")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("ClassLibrary1.Silverlight")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2010")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("468a57a4-6daa-4c29-8d94-df06b5f09ac2")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Revision and Build Numbers -// by using the '*' as shown below: -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ClassLibrary1.Silverlight")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("ClassLibrary1.Silverlight")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2010")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("468a57a4-6daa-4c29-8d94-df06b5f09ac2")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/UnitTests/Library/ClassLibrary1.sln b/UnitTests/Library/ClassLibrary1.sln index b5bf17304..d6f323109 100644 --- a/UnitTests/Library/ClassLibrary1.sln +++ b/UnitTests/Library/ClassLibrary1.sln @@ -1,38 +1,38 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrary1", "ClassLibrary1\ClassLibrary1.csproj", "{AD73DEAC-E669-4070-BE05-099F9F313007}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrary2", "ClassLibrary2\ClassLibrary2.csproj", "{F16C2503-9FBB-464D-AFF0-E58E97769B9E}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrary1.Silverlight", "ClassLibrary1.Silverlight\ClassLibrary1.Silverlight.csproj", "{48D475B6-CB45-44AD-91B7-964135AB0B5C}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrary2.Silverlight", "ClassLibrary2.Silverlight\ClassLibrary2.Silverlight.csproj", "{878F099B-AE0E-49C7-B74D-263E80C4545D}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {AD73DEAC-E669-4070-BE05-099F9F313007}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AD73DEAC-E669-4070-BE05-099F9F313007}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AD73DEAC-E669-4070-BE05-099F9F313007}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AD73DEAC-E669-4070-BE05-099F9F313007}.Release|Any CPU.Build.0 = Release|Any CPU - {F16C2503-9FBB-464D-AFF0-E58E97769B9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F16C2503-9FBB-464D-AFF0-E58E97769B9E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F16C2503-9FBB-464D-AFF0-E58E97769B9E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F16C2503-9FBB-464D-AFF0-E58E97769B9E}.Release|Any CPU.Build.0 = Release|Any CPU - {48D475B6-CB45-44AD-91B7-964135AB0B5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {48D475B6-CB45-44AD-91B7-964135AB0B5C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {48D475B6-CB45-44AD-91B7-964135AB0B5C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {48D475B6-CB45-44AD-91B7-964135AB0B5C}.Release|Any CPU.Build.0 = Release|Any CPU - {878F099B-AE0E-49C7-B74D-263E80C4545D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {878F099B-AE0E-49C7-B74D-263E80C4545D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {878F099B-AE0E-49C7-B74D-263E80C4545D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {878F099B-AE0E-49C7-B74D-263E80C4545D}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrary1", "ClassLibrary1\ClassLibrary1.csproj", "{AD73DEAC-E669-4070-BE05-099F9F313007}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrary2", "ClassLibrary2\ClassLibrary2.csproj", "{F16C2503-9FBB-464D-AFF0-E58E97769B9E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrary1.Silverlight", "ClassLibrary1.Silverlight\ClassLibrary1.Silverlight.csproj", "{48D475B6-CB45-44AD-91B7-964135AB0B5C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrary2.Silverlight", "ClassLibrary2.Silverlight\ClassLibrary2.Silverlight.csproj", "{878F099B-AE0E-49C7-B74D-263E80C4545D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AD73DEAC-E669-4070-BE05-099F9F313007}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AD73DEAC-E669-4070-BE05-099F9F313007}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AD73DEAC-E669-4070-BE05-099F9F313007}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AD73DEAC-E669-4070-BE05-099F9F313007}.Release|Any CPU.Build.0 = Release|Any CPU + {F16C2503-9FBB-464D-AFF0-E58E97769B9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F16C2503-9FBB-464D-AFF0-E58E97769B9E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F16C2503-9FBB-464D-AFF0-E58E97769B9E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F16C2503-9FBB-464D-AFF0-E58E97769B9E}.Release|Any CPU.Build.0 = Release|Any CPU + {48D475B6-CB45-44AD-91B7-964135AB0B5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {48D475B6-CB45-44AD-91B7-964135AB0B5C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {48D475B6-CB45-44AD-91B7-964135AB0B5C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {48D475B6-CB45-44AD-91B7-964135AB0B5C}.Release|Any CPU.Build.0 = Release|Any CPU + {878F099B-AE0E-49C7-B74D-263E80C4545D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {878F099B-AE0E-49C7-B74D-263E80C4545D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {878F099B-AE0E-49C7-B74D-263E80C4545D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {878F099B-AE0E-49C7-B74D-263E80C4545D}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/UnitTests/Library/ClassLibrary1/ClassLibrary1.csproj b/UnitTests/Library/ClassLibrary1/ClassLibrary1.csproj index eac00552d..4c918863b 100644 --- a/UnitTests/Library/ClassLibrary1/ClassLibrary1.csproj +++ b/UnitTests/Library/ClassLibrary1/ClassLibrary1.csproj @@ -1,61 +1,61 @@ - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {AD73DEAC-E669-4070-BE05-099F9F313007} - Library - Properties - ClassLibrary1 - ClassLibrary1 - v3.5 - 512 - $([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Moq.Tests.csproj))\ - - - true - full - false - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - TRACE - prompt - 4 - - - true - - - Foo.snk - - - - - - - - - - - - - - - - - - + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {AD73DEAC-E669-4070-BE05-099F9F313007} + Library + Properties + ClassLibrary1 + ClassLibrary1 + v3.5 + 512 + $([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Moq.Tests.csproj))\ + + + true + full + false + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + TRACE + prompt + 4 + + + true + + + Foo.snk + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/UnitTests/Library/ClassLibrary1/Foo.cs b/UnitTests/Library/ClassLibrary1/Foo.cs index 03e100e3a..90da66696 100644 --- a/UnitTests/Library/ClassLibrary1/Foo.cs +++ b/UnitTests/Library/ClassLibrary1/Foo.cs @@ -1,28 +1,28 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Runtime.CompilerServices; - -[assembly: InternalsVisibleTo("Moq.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001009f7a95086500f8f66d892174803850fed9c22225c2ccfff21f39c8af8abfa5415b1664efd0d8e0a6f7f2513b1c11659bd84723dc7900c3d481b833a73a2bcf1ed94c16c4be64d54352c86956c89930444e9ac15124d3693e3f029818e8410f167399d6b995324b635e95353ba97bfab856abbaeb9b40c9b160070c6325e22ddc")] -[assembly: InternalsVisibleTo("Moq.Silverlight.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001009f7a95086500f8f66d892174803850fed9c22225c2ccfff21f39c8af8abfa5415b1664efd0d8e0a6f7f2513b1c11659bd84723dc7900c3d481b833a73a2bcf1ed94c16c4be64d54352c86956c89930444e9ac15124d3693e3f029818e8410f167399d6b995324b635e95353ba97bfab856abbaeb9b40c9b160070c6325e22ddc")] -[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2,PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] - -namespace ClassLibrary1 -{ - internal interface IFooInternal : IFoo - { - DateTime When { get; set; } - } - - public interface IFoo - { - int Id { get; set; } - } - - public class Foo : IFoo - { - public int Id { get; set; } - public string Value { get; set; } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Moq.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001009f7a95086500f8f66d892174803850fed9c22225c2ccfff21f39c8af8abfa5415b1664efd0d8e0a6f7f2513b1c11659bd84723dc7900c3d481b833a73a2bcf1ed94c16c4be64d54352c86956c89930444e9ac15124d3693e3f029818e8410f167399d6b995324b635e95353ba97bfab856abbaeb9b40c9b160070c6325e22ddc")] +[assembly: InternalsVisibleTo("Moq.Silverlight.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001009f7a95086500f8f66d892174803850fed9c22225c2ccfff21f39c8af8abfa5415b1664efd0d8e0a6f7f2513b1c11659bd84723dc7900c3d481b833a73a2bcf1ed94c16c4be64d54352c86956c89930444e9ac15124d3693e3f029818e8410f167399d6b995324b635e95353ba97bfab856abbaeb9b40c9b160070c6325e22ddc")] +[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2,PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] + +namespace ClassLibrary1 +{ + internal interface IFooInternal : IFoo + { + DateTime When { get; set; } + } + + public interface IFoo + { + int Id { get; set; } + } + + public class Foo : IFoo + { + public int Id { get; set; } + public string Value { get; set; } + } +} diff --git a/UnitTests/Library/ClassLibrary1/Properties/AssemblyInfo.cs b/UnitTests/Library/ClassLibrary1/Properties/AssemblyInfo.cs index fe226b0eb..d65e7d133 100644 --- a/UnitTests/Library/ClassLibrary1/Properties/AssemblyInfo.cs +++ b/UnitTests/Library/ClassLibrary1/Properties/AssemblyInfo.cs @@ -1,36 +1,36 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("ClassLibrary1")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("ClassLibrary1")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2010")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("88163159-e1e3-4b4f-a7e5-96c91d3a680a")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ClassLibrary1")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("ClassLibrary1")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2010")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("88163159-e1e3-4b4f-a7e5-96c91d3a680a")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/UnitTests/Library/ClassLibrary2.Silverlight/ClassLibrary2.Silverlight.csproj b/UnitTests/Library/ClassLibrary2.Silverlight/ClassLibrary2.Silverlight.csproj index cdd281007..40f754a44 100644 --- a/UnitTests/Library/ClassLibrary2.Silverlight/ClassLibrary2.Silverlight.csproj +++ b/UnitTests/Library/ClassLibrary2.Silverlight/ClassLibrary2.Silverlight.csproj @@ -1,94 +1,94 @@ - - - - Debug - AnyCPU - 8.0.50727 - 2.0 - {878F099B-AE0E-49C7-B74D-263E80C4545D} - {A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} - Library - Properties - ClassLibrary2.Silverlight - ClassLibrary2.Silverlight - Silverlight - v4.0 - $(TargetFrameworkVersion) - false - true - true - $([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Moq.Tests.csproj))\ - - - - v3.5 - - - true - full - false - DEBUG;TRACE;SILVERLIGHT - true - true - prompt - 4 - - - pdbonly - true - TRACE;SILVERLIGHT - true - true - prompt - 4 - - - true - - - ..\ClassLibrary2\Bar.snk - - - - - - - - - - - - - Bar.cs - - - - - - Bar.snk - - - - - {48D475B6-CB45-44AD-91B7-964135AB0B5C} - ClassLibrary1.Silverlight - - - - - - - - - - - + + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {878F099B-AE0E-49C7-B74D-263E80C4545D} + {A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + ClassLibrary2.Silverlight + ClassLibrary2.Silverlight + Silverlight + v4.0 + $(TargetFrameworkVersion) + false + true + true + $([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Moq.Tests.csproj))\ + + + + v3.5 + + + true + full + false + DEBUG;TRACE;SILVERLIGHT + true + true + prompt + 4 + + + pdbonly + true + TRACE;SILVERLIGHT + true + true + prompt + 4 + + + true + + + ..\ClassLibrary2\Bar.snk + + + + + + + + + + + + + Bar.cs + + + + + + Bar.snk + + + + + {48D475B6-CB45-44AD-91B7-964135AB0B5C} + ClassLibrary1.Silverlight + + + + + + + + + + + \ No newline at end of file diff --git a/UnitTests/Library/ClassLibrary2.Silverlight/Properties/AssemblyInfo.cs b/UnitTests/Library/ClassLibrary2.Silverlight/Properties/AssemblyInfo.cs index cf6722141..77ef37674 100644 --- a/UnitTests/Library/ClassLibrary2.Silverlight/Properties/AssemblyInfo.cs +++ b/UnitTests/Library/ClassLibrary2.Silverlight/Properties/AssemblyInfo.cs @@ -1,35 +1,35 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("ClassLibrary2.Silverlight")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("ClassLibrary2.Silverlight")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2010")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("c87d9f17-909d-4b29-b5c2-7726e0bf7f99")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Revision and Build Numbers -// by using the '*' as shown below: -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ClassLibrary2.Silverlight")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("ClassLibrary2.Silverlight")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2010")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("c87d9f17-909d-4b29-b5c2-7726e0bf7f99")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/UnitTests/Library/ClassLibrary2/Bar.cs b/UnitTests/Library/ClassLibrary2/Bar.cs index 3544d53c7..533d4c5fb 100644 --- a/UnitTests/Library/ClassLibrary2/Bar.cs +++ b/UnitTests/Library/ClassLibrary2/Bar.cs @@ -1,23 +1,23 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using ClassLibrary1; -using System.Runtime.CompilerServices; - -[assembly: InternalsVisibleTo("Moq.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001009f7a95086500f8f66d892174803850fed9c22225c2ccfff21f39c8af8abfa5415b1664efd0d8e0a6f7f2513b1c11659bd84723dc7900c3d481b833a73a2bcf1ed94c16c4be64d54352c86956c89930444e9ac15124d3693e3f029818e8410f167399d6b995324b635e95353ba97bfab856abbaeb9b40c9b160070c6325e22ddc")] -[assembly: InternalsVisibleTo("Moq.Silverlight.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001009f7a95086500f8f66d892174803850fed9c22225c2ccfff21f39c8af8abfa5415b1664efd0d8e0a6f7f2513b1c11659bd84723dc7900c3d481b833a73a2bcf1ed94c16c4be64d54352c86956c89930444e9ac15124d3693e3f029818e8410f167399d6b995324b635e95353ba97bfab856abbaeb9b40c9b160070c6325e22ddc")] -[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2,PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] - -namespace ClassLibrary2 -{ - public interface IBar : IFoo - { - DateTimeOffset When { get; set; } - } - - public class Bar : Foo - { - public DateTimeOffset When { get; set; } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using ClassLibrary1; +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Moq.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001009f7a95086500f8f66d892174803850fed9c22225c2ccfff21f39c8af8abfa5415b1664efd0d8e0a6f7f2513b1c11659bd84723dc7900c3d481b833a73a2bcf1ed94c16c4be64d54352c86956c89930444e9ac15124d3693e3f029818e8410f167399d6b995324b635e95353ba97bfab856abbaeb9b40c9b160070c6325e22ddc")] +[assembly: InternalsVisibleTo("Moq.Silverlight.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001009f7a95086500f8f66d892174803850fed9c22225c2ccfff21f39c8af8abfa5415b1664efd0d8e0a6f7f2513b1c11659bd84723dc7900c3d481b833a73a2bcf1ed94c16c4be64d54352c86956c89930444e9ac15124d3693e3f029818e8410f167399d6b995324b635e95353ba97bfab856abbaeb9b40c9b160070c6325e22ddc")] +[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2,PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] + +namespace ClassLibrary2 +{ + public interface IBar : IFoo + { + DateTimeOffset When { get; set; } + } + + public class Bar : Foo + { + public DateTimeOffset When { get; set; } + } +} diff --git a/UnitTests/Library/ClassLibrary2/ClassLibrary2.csproj b/UnitTests/Library/ClassLibrary2/ClassLibrary2.csproj index 1bfc51794..e086aeaca 100644 --- a/UnitTests/Library/ClassLibrary2/ClassLibrary2.csproj +++ b/UnitTests/Library/ClassLibrary2/ClassLibrary2.csproj @@ -1,67 +1,67 @@ - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {F16C2503-9FBB-464D-AFF0-E58E97769B9E} - Library - Properties - ClassLibrary2 - ClassLibrary2 - v3.5 - 512 - $([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Moq.Tests.csproj))\ - - - true - full - false - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - TRACE - prompt - 4 - - - true - - - Bar.snk - - - - - - - - - - - - - - - - - - - {AD73DEAC-E669-4070-BE05-099F9F313007} - ClassLibrary1 - - - - + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {F16C2503-9FBB-464D-AFF0-E58E97769B9E} + Library + Properties + ClassLibrary2 + ClassLibrary2 + v3.5 + 512 + $([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Moq.Tests.csproj))\ + + + true + full + false + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + TRACE + prompt + 4 + + + true + + + Bar.snk + + + + + + + + + + + + + + + + + + + {AD73DEAC-E669-4070-BE05-099F9F313007} + ClassLibrary1 + + + + \ No newline at end of file diff --git a/UnitTests/Library/ClassLibrary2/Properties/AssemblyInfo.cs b/UnitTests/Library/ClassLibrary2/Properties/AssemblyInfo.cs index 0addee10e..75972f752 100644 --- a/UnitTests/Library/ClassLibrary2/Properties/AssemblyInfo.cs +++ b/UnitTests/Library/ClassLibrary2/Properties/AssemblyInfo.cs @@ -1,36 +1,36 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("ClassLibrary2")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("ClassLibrary2")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2010")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("9ea84dc4-84f9-40b0-966d-5483a6916fca")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ClassLibrary2")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("ClassLibrary2")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2010")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("9ea84dc4-84f9-40b0-966d-5483a6916fca")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/UnitTests/Linq/MockRepositoryQuerying.cs b/UnitTests/Linq/MockRepositoryQuerying.cs index b060535fe..9c25a3fc0 100644 --- a/UnitTests/Linq/MockRepositoryQuerying.cs +++ b/UnitTests/Linq/MockRepositoryQuerying.cs @@ -1,67 +1,67 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Xunit; - -namespace Moq.Tests.Linq -{ - public class MockRepositoryQuerying - { - public class GivenAStrictFactory - { - private MockRepository repository; - - public GivenAStrictFactory() - { - this.repository = new MockRepository(MockBehavior.Strict); - } - - [Fact] - public void WhenQueryingSingle_ThenItIsStrict() - { - var foo = this.repository.OneOf(); - - Assert.Throws(() => foo.Do()); - } - - [Fact] - public void WhenQueryingMultiple_ThenItIsStrict() - { - var foo = this.repository.Of().First(); - - Assert.Throws(() => foo.Do()); - } - - [Fact] - public void WhenQueryingSingleWithProperty_ThenItIsStrict() - { - var foo = this.repository.OneOf(x => x.Id == "1"); - - Assert.Throws(() => foo.Do()); - - Mock.Get(foo).Verify(); - - Assert.Equal("1", foo.Id); - } - - [Fact] - public void WhenQueryingMultipleWithProperty_ThenItIsStrict() - { - var foo = this.repository.Of(x => x.Id == "1").First(); - - Assert.Throws(() => foo.Do()); - - Mock.Get(foo).Verify(); - - Assert.Equal("1", foo.Id); - } - } - - public interface IFoo - { - string Id { get; set; } - bool Do(); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Xunit; + +namespace Moq.Tests.Linq +{ + public class MockRepositoryQuerying + { + public class GivenAStrictFactory + { + private MockRepository repository; + + public GivenAStrictFactory() + { + this.repository = new MockRepository(MockBehavior.Strict); + } + + [Fact] + public void WhenQueryingSingle_ThenItIsStrict() + { + var foo = this.repository.OneOf(); + + Assert.Throws(() => foo.Do()); + } + + [Fact] + public void WhenQueryingMultiple_ThenItIsStrict() + { + var foo = this.repository.Of().First(); + + Assert.Throws(() => foo.Do()); + } + + [Fact] + public void WhenQueryingSingleWithProperty_ThenItIsStrict() + { + var foo = this.repository.OneOf(x => x.Id == "1"); + + Assert.Throws(() => foo.Do()); + + Mock.Get(foo).Verify(); + + Assert.Equal("1", foo.Id); + } + + [Fact] + public void WhenQueryingMultipleWithProperty_ThenItIsStrict() + { + var foo = this.repository.Of(x => x.Id == "1").First(); + + Assert.Throws(() => foo.Do()); + + Mock.Get(foo).Verify(); + + Assert.Equal("1", foo.Id); + } + } + + public interface IFoo + { + string Id { get; set; } + bool Do(); + } + } +} diff --git a/UnitTests/Linq/SupportedQuerying.cs b/UnitTests/Linq/SupportedQuerying.cs index 734865181..ad37cc902 100644 --- a/UnitTests/Linq/SupportedQuerying.cs +++ b/UnitTests/Linq/SupportedQuerying.cs @@ -1,283 +1,283 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Xunit; - -namespace Moq.Tests.Linq -{ - public class SupportedQuerying - { - public class GivenABooleanProperty - { - [Fact] - public void WhenImplicitlyQueryingTrueOneOf_ThenSetsPropertyToTrue() - { - var target = Mock.Of(x => x.IsValid); - - Assert.True(target.IsValid); - } - - [Fact] - public void WhenImplicitlyQueryingTrueWhere_ThenSetsPropertyToTrue() - { - var target = Mocks.Of().Where(x => x.IsValid); - - Assert.True(target.First().IsValid); - } - - [Fact] - public void WhenImplicitlyQueryingTrueFirst_ThenSetsPropertyToTrue() - { - var target = Mocks.Of().First(x => x.IsValid); - - Assert.True(target.IsValid); - } - - [Fact] - public void WhenImplicitlyQueryingTrueFirstOrDefault_ThenSetsPropertyToTrue() - { - var target = Mocks.Of().FirstOrDefault(x => x.IsValid); - - Assert.True(target.IsValid); - } - - [Fact] - public void WhenExplicitlyQueryingTrueOneOf_ThenSetsPropertyToTrue() - { - var target = Mock.Of(x => x.IsValid == true); - - Assert.True(target.IsValid); - } - - [Fact] - public void WhenExplicitlyQueryingTrueWhere_ThenSetsPropertyToTrue() - { - var target = Mocks.Of().Where(x => x.IsValid == true); - - Assert.True(target.First().IsValid); - } - - [Fact] - public void WhenExplicitlyQueryingTrueFirst_ThenSetsPropertyToTrue() - { - var target = Mocks.Of().First(x => x.IsValid == true); - - Assert.True(target.IsValid); - } - - [Fact] - public void WhenExplicitlyQueryingTrueFirstOrDefault_ThenSetsPropertyToTrue() - { - var target = Mocks.Of().FirstOrDefault(x => x.IsValid == true); - - Assert.True(target.IsValid); - } - - [Fact] - public void WhenQueryingOnFluent_ThenSetsPropertyToTrue() - { - var target = Mocks.Of().FirstOrDefault(x => x.Foo.IsValid == true); - - Assert.True(target.Foo.IsValid); - } - - [Fact] - public void WhenQueryingWithFalse_ThenSetsProperty() - { - var target = Mock.Of(x => x.IsValid == false); - - Assert.False(target.IsValid); - } - - [Fact] - public void WhenQueryingTrueEquals_ThenSetsProperty() - { - var target = Mock.Of(x => true == x.IsValid); - - Assert.True(target.IsValid); - } - - [Fact] - public void WhenQueryingFalseEquals_ThenSetsProperty() - { - var target = Mock.Of(x => false == x.IsValid); - - Assert.False(target.IsValid); - } - - [Fact] - public void WhenQueryingNegatedProperty_ThenSetsProperty() - { - var target = Mock.Of(x => !x.IsValid); - - Assert.False(target.IsValid); - } - - [Fact] - public void WhenQueryingWithNoValue_ThenAlwaysHasPropertyStubBehavior() - { - var foo = Mock.Of(); - - foo.IsValid = true; - - Assert.True(foo.IsValid); - - foo.IsValid = false; - - Assert.False(foo.IsValid); - } - - public class FooDefaultIsValid : IFoo - { - public FooDefaultIsValid() - { - this.IsValid = true; - } - - public virtual bool IsValid { get; set; } - } - - public interface IFoo - { - bool IsValid { get; set; } - } - - public interface IFluent - { - IFoo Foo { get; set; } - } - } - - public class GivenAnEnumProperty - { - [Fact] - public void WhenQueryingWithEnumValue_ThenSetsPropertyValue() - { - var target = Mocks.Of().First(f => f.Targets == AttributeTargets.Class); - - Assert.Equal(AttributeTargets.Class, target.Targets); - } - - [Fact(Skip = "Not implemented yet. Need to refactor old matcher stuff to the new one, require the MatcherAttribute on matchers, and verify it.")] - public void WhenQueryingWithItIsAny_ThenThrowsNotSupportedException() - { - var target = Mocks.Of().First(f => f.Targets == It.IsAny()); - - Assert.Equal(AttributeTargets.Class, target.Targets); - } - - public interface IFoo - { - AttributeTargets Targets { get; set; } - } - } - - public class GivenTwoProperties - { - [Fact] - public void WhenCombiningQueryingWithImplicitBoolean_ThenSetsBothProperties() - { - var target = Mock.Of(x => x.IsValid && x.Value == "foo"); - - Assert.True(target.IsValid); - Assert.Equal("foo", target.Value); - } - - [Fact] - public void WhenCombiningQueryingWithExplicitBoolean_ThenSetsBothProperties() - { - var target = Mock.Of(x => x.IsValid == true && x.Value == "foo"); - - Assert.True(target.IsValid); - Assert.Equal("foo", target.Value); - } - - public interface IFoo - { - string Value { get; set; } - bool IsValid { get; set; } - } - } - - public class GivenAMethodWithOneParameter - { - [Fact] - public void WhenUsingSpecificArgumentValue_ThenSetsReturnValue() - { - var foo = Mock.Of(x => x.Do(5) == "foo"); - - Assert.Equal("foo", foo.Do(5)); - } - - [Fact] - public void WhenUsingItIsAnyForArgument_ThenSetsReturnValue() - { - var foo = Mock.Of(x => x.Do(It.IsAny()) == "foo"); - - Assert.Equal("foo", foo.Do(5)); - } - - [Fact] - public void WhenUsingItIsForArgument_ThenSetsReturnValue() - { - var foo = Mock.Of(x => x.Do(It.Is(i => i > 0)) == "foo"); - - Assert.Equal("foo", foo.Do(5)); - Assert.Equal(default(string), foo.Do(-5)); - } - - [Fact] - public void WhenUsingCustomMatcherForArgument_ThenSetsReturnValue() - { - var foo = Mock.Of(x => x.Do(Any()) == "foo"); - - Assert.Equal("foo", foo.Do(5)); - } - - public TValue Any() - { - return Match.Create(v => true); - } - - public interface IFoo - { - string Do(int value); - } - } - - public class GivenAClassWithNonVirtualProperties - { - [Fact] - public void WhenQueryingByProperties_ThenSetsThemDirectly() - { - var foo = Mock.Of(x => x.Id == 1 && x.Value == "hello"); - - Assert.Equal(1, foo.Id); - Assert.Equal("hello", foo.Value); - } - - public class Foo - { - public int Id { get; set; } - public string Value { get; set; } - } - } - - public class GivenAReadonlyProperty - { - [Fact] - public void WhenQueryingByProperties_ThenSetsThemDirectly() - { - var foo = Mock.Of(x => x.Id == 1); - - Assert.Equal(1, foo.Id); - } - - public class Foo - { - public virtual int Id { get { return 0; } } - } - } - } +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Xunit; + +namespace Moq.Tests.Linq +{ + public class SupportedQuerying + { + public class GivenABooleanProperty + { + [Fact] + public void WhenImplicitlyQueryingTrueOneOf_ThenSetsPropertyToTrue() + { + var target = Mock.Of(x => x.IsValid); + + Assert.True(target.IsValid); + } + + [Fact] + public void WhenImplicitlyQueryingTrueWhere_ThenSetsPropertyToTrue() + { + var target = Mocks.Of().Where(x => x.IsValid); + + Assert.True(target.First().IsValid); + } + + [Fact] + public void WhenImplicitlyQueryingTrueFirst_ThenSetsPropertyToTrue() + { + var target = Mocks.Of().First(x => x.IsValid); + + Assert.True(target.IsValid); + } + + [Fact] + public void WhenImplicitlyQueryingTrueFirstOrDefault_ThenSetsPropertyToTrue() + { + var target = Mocks.Of().FirstOrDefault(x => x.IsValid); + + Assert.True(target.IsValid); + } + + [Fact] + public void WhenExplicitlyQueryingTrueOneOf_ThenSetsPropertyToTrue() + { + var target = Mock.Of(x => x.IsValid == true); + + Assert.True(target.IsValid); + } + + [Fact] + public void WhenExplicitlyQueryingTrueWhere_ThenSetsPropertyToTrue() + { + var target = Mocks.Of().Where(x => x.IsValid == true); + + Assert.True(target.First().IsValid); + } + + [Fact] + public void WhenExplicitlyQueryingTrueFirst_ThenSetsPropertyToTrue() + { + var target = Mocks.Of().First(x => x.IsValid == true); + + Assert.True(target.IsValid); + } + + [Fact] + public void WhenExplicitlyQueryingTrueFirstOrDefault_ThenSetsPropertyToTrue() + { + var target = Mocks.Of().FirstOrDefault(x => x.IsValid == true); + + Assert.True(target.IsValid); + } + + [Fact] + public void WhenQueryingOnFluent_ThenSetsPropertyToTrue() + { + var target = Mocks.Of().FirstOrDefault(x => x.Foo.IsValid == true); + + Assert.True(target.Foo.IsValid); + } + + [Fact] + public void WhenQueryingWithFalse_ThenSetsProperty() + { + var target = Mock.Of(x => x.IsValid == false); + + Assert.False(target.IsValid); + } + + [Fact] + public void WhenQueryingTrueEquals_ThenSetsProperty() + { + var target = Mock.Of(x => true == x.IsValid); + + Assert.True(target.IsValid); + } + + [Fact] + public void WhenQueryingFalseEquals_ThenSetsProperty() + { + var target = Mock.Of(x => false == x.IsValid); + + Assert.False(target.IsValid); + } + + [Fact] + public void WhenQueryingNegatedProperty_ThenSetsProperty() + { + var target = Mock.Of(x => !x.IsValid); + + Assert.False(target.IsValid); + } + + [Fact] + public void WhenQueryingWithNoValue_ThenAlwaysHasPropertyStubBehavior() + { + var foo = Mock.Of(); + + foo.IsValid = true; + + Assert.True(foo.IsValid); + + foo.IsValid = false; + + Assert.False(foo.IsValid); + } + + public class FooDefaultIsValid : IFoo + { + public FooDefaultIsValid() + { + this.IsValid = true; + } + + public virtual bool IsValid { get; set; } + } + + public interface IFoo + { + bool IsValid { get; set; } + } + + public interface IFluent + { + IFoo Foo { get; set; } + } + } + + public class GivenAnEnumProperty + { + [Fact] + public void WhenQueryingWithEnumValue_ThenSetsPropertyValue() + { + var target = Mocks.Of().First(f => f.Targets == AttributeTargets.Class); + + Assert.Equal(AttributeTargets.Class, target.Targets); + } + + [Fact(Skip = "Not implemented yet. Need to refactor old matcher stuff to the new one, require the MatcherAttribute on matchers, and verify it.")] + public void WhenQueryingWithItIsAny_ThenThrowsNotSupportedException() + { + var target = Mocks.Of().First(f => f.Targets == It.IsAny()); + + Assert.Equal(AttributeTargets.Class, target.Targets); + } + + public interface IFoo + { + AttributeTargets Targets { get; set; } + } + } + + public class GivenTwoProperties + { + [Fact] + public void WhenCombiningQueryingWithImplicitBoolean_ThenSetsBothProperties() + { + var target = Mock.Of(x => x.IsValid && x.Value == "foo"); + + Assert.True(target.IsValid); + Assert.Equal("foo", target.Value); + } + + [Fact] + public void WhenCombiningQueryingWithExplicitBoolean_ThenSetsBothProperties() + { + var target = Mock.Of(x => x.IsValid == true && x.Value == "foo"); + + Assert.True(target.IsValid); + Assert.Equal("foo", target.Value); + } + + public interface IFoo + { + string Value { get; set; } + bool IsValid { get; set; } + } + } + + public class GivenAMethodWithOneParameter + { + [Fact] + public void WhenUsingSpecificArgumentValue_ThenSetsReturnValue() + { + var foo = Mock.Of(x => x.Do(5) == "foo"); + + Assert.Equal("foo", foo.Do(5)); + } + + [Fact] + public void WhenUsingItIsAnyForArgument_ThenSetsReturnValue() + { + var foo = Mock.Of(x => x.Do(It.IsAny()) == "foo"); + + Assert.Equal("foo", foo.Do(5)); + } + + [Fact] + public void WhenUsingItIsForArgument_ThenSetsReturnValue() + { + var foo = Mock.Of(x => x.Do(It.Is(i => i > 0)) == "foo"); + + Assert.Equal("foo", foo.Do(5)); + Assert.Equal(default(string), foo.Do(-5)); + } + + [Fact] + public void WhenUsingCustomMatcherForArgument_ThenSetsReturnValue() + { + var foo = Mock.Of(x => x.Do(Any()) == "foo"); + + Assert.Equal("foo", foo.Do(5)); + } + + public TValue Any() + { + return Match.Create(v => true); + } + + public interface IFoo + { + string Do(int value); + } + } + + public class GivenAClassWithNonVirtualProperties + { + [Fact] + public void WhenQueryingByProperties_ThenSetsThemDirectly() + { + var foo = Mock.Of(x => x.Id == 1 && x.Value == "hello"); + + Assert.Equal(1, foo.Id); + Assert.Equal("hello", foo.Value); + } + + public class Foo + { + public int Id { get; set; } + public string Value { get; set; } + } + } + + public class GivenAReadonlyProperty + { + [Fact] + public void WhenQueryingByProperties_ThenSetsThemDirectly() + { + var foo = Mock.Of(x => x.Id == 1); + + Assert.Equal(1, foo.Id); + } + + public class Foo + { + public virtual int Id { get { return 0; } } + } + } + } } \ No newline at end of file diff --git a/UnitTests/Linq/UnsupportedQuerying.cs b/UnitTests/Linq/UnsupportedQuerying.cs index 9310c5cc2..ebfbe47a9 100644 --- a/UnitTests/Linq/UnsupportedQuerying.cs +++ b/UnitTests/Linq/UnsupportedQuerying.cs @@ -1,206 +1,206 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Xunit; - -namespace Moq.Tests.Linq -{ - public class UnsupportedQuerying - { - public class GivenAReadonlyNonVirtualProperty - { - [Fact] - public void WhenQueryingDirect_ThenThrowsNotSupportedException() - { - Assert.Throws(() => Mock.Of(x => x.NonVirtualValue == "bar")); - } - - [Fact] - public void WhenQueryingOnFluent_ThenThrowsNotSupportedException() - { - Assert.Throws(() => Mock.Of(x => x.VirtualBar.NonVirtualValue == "bar")); - } - - [Fact] - public void WhenQueryingOnIntermediateFluentReadonly_ThenThrowsNotSupportedException() - { - Assert.Throws(() => Mock.Of(x => x.NonVirtualBar.VirtualValue == "bar")); - } - - public class Bar - { - public string NonVirtualValue { get { return "foo"; } } - public virtual string VirtualValue { get; set; } - } - - public class Foo - { - public virtual Bar VirtualBar { get; set; } - public Bar NonVirtualBar { get; set; } - } - } - - public class GivenAField - { - [Fact] - public void WhenQueryingField_ThenThrowsNotSupportedException() - { - Assert.Throws(() => Mock.Of(x => x.FieldValue == "bar")); - } - - [Fact] - public void WhenQueryingOnFluent_ThenThrowsNotSupportedException() - { - Assert.Throws(() => Mock.Of(x => x.VirtualBar.FieldValue == "bar")); - } - - [Fact] - public void WhenIntermediateFluentReadonly_ThenThrowsNotSupportedException() - { - Assert.Throws(() => Mock.Of(x => x.Bar.VirtualValue == "bar")); - } - - public class Bar - { - public string FieldValue = "foo"; - public virtual string VirtualValue { get; set; } - } - - public class Foo - { - public Bar Bar = new Bar(); - - public virtual Bar VirtualBar { get; set; } - } - } - - public class GivenANonVirtualMethod - { - [Fact] - public void WhenQueryingDirect_ThenThrowsNotSupportedException() - { - Assert.Throws(() => Mock.Of(x => x.NonVirtual() == "foo")); - } - - [Fact] - public void WhenQueryingOnFluent_ThenThrowsNotSupportedException() - { - Assert.Throws(() => Mock.Of(x => x.Virtual().NonVirtual() == "foo")); - } - - [Fact] - public void WhenQueryingOnIntermediateFluentNonVirtual_ThenThrowsNotSupportedException() - { - Assert.Throws(() => Mock.Of(x => x.NonVirtual().Virtual() == "foo")); - } - - public class Bar - { - public string NonVirtual() - { - return string.Empty; - } - - public virtual string Virtual() - { - return string.Empty; - } - } - - public class Foo - { - public Bar NonVirtual() - { - return new Bar(); - } - - public virtual Bar Virtual() - { - return new Bar(); - } - } - } - - public class GivenAnInterface - { - [Fact] - public void WhenQueryingSingle_ThenThrowsNotSupportedException() - { - Assert.Throws(() => Mocks.Of().Single()); - } - - [Fact] - public void WhenQueryingSingleOrDefault_ThenThrowsNotSupportedException() - { - Assert.Throws(() => Mocks.Of().SingleOrDefault()); - } - - [Fact] - public void WhenQueryingAll_ThenThrowsNotSupportedException() - { - Assert.Throws(() => Mocks.Of().All(x => x.Value == "Foo")); - } - - [Fact] - public void WhenQueryingAny_ThenThrowsNotSupportedException() - { - Assert.Throws(() => Mocks.Of().Any()); - } - - [Fact] - public void WhenQueryingLast_ThenThrowsNotSupportedException() - { - Assert.Throws(() => Mocks.Of().Last()); - } - - [Fact] - public void WhenQueryingLastOrDefault_ThenThrowsNotSupportedException() - { - Assert.Throws(() => Mocks.Of().LastOrDefault()); - } - - [Fact] - public void WhenOperatorIsNotEqual_ThenThrowsNotSupportedException() - { - Assert.Throws(() => Mock.Of(x => x.Value != "foo")); - } - - [Fact] - public void WhenOperatorIsGreaterThan_ThenThrowsNotSupportedException() - { - Assert.Throws(() => Mock.Of(x => x.Count > 5)); - } - - [Fact] - public void WhenOperatorIsGreaterThanOrEqual_ThenThrowsNotSupportedException() - { - Assert.Throws(() => Mock.Of(x => x.Count >= 5)); - } - - [Fact] - public void WhenOperatorIsLessThan_ThenThrowsNotSupportedException() - { - Assert.Throws(() => Mock.Of(x => x.Count < 5)); - } - - [Fact] - public void WhenOperatorIsLessThanOrEqual_ThenThrowsNotSupportedException() - { - Assert.Throws(() => Mock.Of(x => x.Count <= 5)); - } - - [Fact] - public void WhenCombiningWithOrRatherThanLogicalAnd_ThenThrowsNotSupportedException() - { - Assert.Throws(() => Mock.Of(x => x.Count == 5 || x.Value == "foo")); - } - - public interface IFoo - { - string Value { get; set; } - int Count { get; set; } - } - } - } +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Xunit; + +namespace Moq.Tests.Linq +{ + public class UnsupportedQuerying + { + public class GivenAReadonlyNonVirtualProperty + { + [Fact] + public void WhenQueryingDirect_ThenThrowsNotSupportedException() + { + Assert.Throws(() => Mock.Of(x => x.NonVirtualValue == "bar")); + } + + [Fact] + public void WhenQueryingOnFluent_ThenThrowsNotSupportedException() + { + Assert.Throws(() => Mock.Of(x => x.VirtualBar.NonVirtualValue == "bar")); + } + + [Fact] + public void WhenQueryingOnIntermediateFluentReadonly_ThenThrowsNotSupportedException() + { + Assert.Throws(() => Mock.Of(x => x.NonVirtualBar.VirtualValue == "bar")); + } + + public class Bar + { + public string NonVirtualValue { get { return "foo"; } } + public virtual string VirtualValue { get; set; } + } + + public class Foo + { + public virtual Bar VirtualBar { get; set; } + public Bar NonVirtualBar { get; set; } + } + } + + public class GivenAField + { + [Fact] + public void WhenQueryingField_ThenThrowsNotSupportedException() + { + Assert.Throws(() => Mock.Of(x => x.FieldValue == "bar")); + } + + [Fact] + public void WhenQueryingOnFluent_ThenThrowsNotSupportedException() + { + Assert.Throws(() => Mock.Of(x => x.VirtualBar.FieldValue == "bar")); + } + + [Fact] + public void WhenIntermediateFluentReadonly_ThenThrowsNotSupportedException() + { + Assert.Throws(() => Mock.Of(x => x.Bar.VirtualValue == "bar")); + } + + public class Bar + { + public string FieldValue = "foo"; + public virtual string VirtualValue { get; set; } + } + + public class Foo + { + public Bar Bar = new Bar(); + + public virtual Bar VirtualBar { get; set; } + } + } + + public class GivenANonVirtualMethod + { + [Fact] + public void WhenQueryingDirect_ThenThrowsNotSupportedException() + { + Assert.Throws(() => Mock.Of(x => x.NonVirtual() == "foo")); + } + + [Fact] + public void WhenQueryingOnFluent_ThenThrowsNotSupportedException() + { + Assert.Throws(() => Mock.Of(x => x.Virtual().NonVirtual() == "foo")); + } + + [Fact] + public void WhenQueryingOnIntermediateFluentNonVirtual_ThenThrowsNotSupportedException() + { + Assert.Throws(() => Mock.Of(x => x.NonVirtual().Virtual() == "foo")); + } + + public class Bar + { + public string NonVirtual() + { + return string.Empty; + } + + public virtual string Virtual() + { + return string.Empty; + } + } + + public class Foo + { + public Bar NonVirtual() + { + return new Bar(); + } + + public virtual Bar Virtual() + { + return new Bar(); + } + } + } + + public class GivenAnInterface + { + [Fact] + public void WhenQueryingSingle_ThenThrowsNotSupportedException() + { + Assert.Throws(() => Mocks.Of().Single()); + } + + [Fact] + public void WhenQueryingSingleOrDefault_ThenThrowsNotSupportedException() + { + Assert.Throws(() => Mocks.Of().SingleOrDefault()); + } + + [Fact] + public void WhenQueryingAll_ThenThrowsNotSupportedException() + { + Assert.Throws(() => Mocks.Of().All(x => x.Value == "Foo")); + } + + [Fact] + public void WhenQueryingAny_ThenThrowsNotSupportedException() + { + Assert.Throws(() => Mocks.Of().Any()); + } + + [Fact] + public void WhenQueryingLast_ThenThrowsNotSupportedException() + { + Assert.Throws(() => Mocks.Of().Last()); + } + + [Fact] + public void WhenQueryingLastOrDefault_ThenThrowsNotSupportedException() + { + Assert.Throws(() => Mocks.Of().LastOrDefault()); + } + + [Fact] + public void WhenOperatorIsNotEqual_ThenThrowsNotSupportedException() + { + Assert.Throws(() => Mock.Of(x => x.Value != "foo")); + } + + [Fact] + public void WhenOperatorIsGreaterThan_ThenThrowsNotSupportedException() + { + Assert.Throws(() => Mock.Of(x => x.Count > 5)); + } + + [Fact] + public void WhenOperatorIsGreaterThanOrEqual_ThenThrowsNotSupportedException() + { + Assert.Throws(() => Mock.Of(x => x.Count >= 5)); + } + + [Fact] + public void WhenOperatorIsLessThan_ThenThrowsNotSupportedException() + { + Assert.Throws(() => Mock.Of(x => x.Count < 5)); + } + + [Fact] + public void WhenOperatorIsLessThanOrEqual_ThenThrowsNotSupportedException() + { + Assert.Throws(() => Mock.Of(x => x.Count <= 5)); + } + + [Fact] + public void WhenCombiningWithOrRatherThanLogicalAnd_ThenThrowsNotSupportedException() + { + Assert.Throws(() => Mock.Of(x => x.Count == 5 || x.Value == "foo")); + } + + public interface IFoo + { + string Value { get; set; } + int Count { get; set; } + } + } + } } \ No newline at end of file diff --git a/UnitTests/Matchers/AnyMatcherFixture.cs b/UnitTests/Matchers/AnyMatcherFixture.cs index 4fc9283e6..de71f7d9c 100644 --- a/UnitTests/Matchers/AnyMatcherFixture.cs +++ b/UnitTests/Matchers/AnyMatcherFixture.cs @@ -1,66 +1,66 @@ -using System; -using System.Linq.Expressions; -using Xunit; - -namespace Moq.Tests.Matchers -{ - public class AnyMatcherFixture - { - [Fact] - public void MatchesNull() - { - var expr = ToExpression(() => It.IsAny()).ToLambda().Body; - - var matcher = MatcherFactory.CreateMatcher(expr, false); - matcher.Initialize(expr); - - Assert.True(matcher.Matches(null)); - } - - [Fact] - public void MatchesIfAssignableType() - { - var expr = ToExpression(() => It.IsAny()).ToLambda().Body; - - var matcher = MatcherFactory.CreateMatcher(expr, false); - matcher.Initialize(expr); - - Assert.True(matcher.Matches("foo")); - } - - [Fact] - public void MatchesIfAssignableInterface() - { - var expr = ToExpression(() => It.IsAny()).ToLambda().Body; - - var matcher = MatcherFactory.CreateMatcher(expr, false); - matcher.Initialize(expr); - - Assert.True(matcher.Matches(new Disposable())); - } - - [Fact] - public void DoesntMatchIfNotAssignableType() - { - var expr = ToExpression(() => It.IsAny()).ToLambda().Body; - - var matcher = MatcherFactory.CreateMatcher(expr, false); - matcher.Initialize(expr); - - Assert.False(matcher.Matches("foo")); - } - - private Expression ToExpression(Expression> expr) - { - return expr; - } - - class Disposable : IDisposable - { - public void Dispose() - { - throw new NotImplementedException(); - } - } - } -} +using System; +using System.Linq.Expressions; +using Xunit; + +namespace Moq.Tests.Matchers +{ + public class AnyMatcherFixture + { + [Fact] + public void MatchesNull() + { + var expr = ToExpression(() => It.IsAny()).ToLambda().Body; + + var matcher = MatcherFactory.CreateMatcher(expr, false); + matcher.Initialize(expr); + + Assert.True(matcher.Matches(null)); + } + + [Fact] + public void MatchesIfAssignableType() + { + var expr = ToExpression(() => It.IsAny()).ToLambda().Body; + + var matcher = MatcherFactory.CreateMatcher(expr, false); + matcher.Initialize(expr); + + Assert.True(matcher.Matches("foo")); + } + + [Fact] + public void MatchesIfAssignableInterface() + { + var expr = ToExpression(() => It.IsAny()).ToLambda().Body; + + var matcher = MatcherFactory.CreateMatcher(expr, false); + matcher.Initialize(expr); + + Assert.True(matcher.Matches(new Disposable())); + } + + [Fact] + public void DoesntMatchIfNotAssignableType() + { + var expr = ToExpression(() => It.IsAny()).ToLambda().Body; + + var matcher = MatcherFactory.CreateMatcher(expr, false); + matcher.Initialize(expr); + + Assert.False(matcher.Matches("foo")); + } + + private Expression ToExpression(Expression> expr) + { + return expr; + } + + class Disposable : IDisposable + { + public void Dispose() + { + throw new NotImplementedException(); + } + } + } +} diff --git a/UnitTests/MockBehaviorFixture.cs b/UnitTests/MockBehaviorFixture.cs index f38f86f5f..17c6a3bf5 100644 --- a/UnitTests/MockBehaviorFixture.cs +++ b/UnitTests/MockBehaviorFixture.cs @@ -1,309 +1,309 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace Moq.Tests -{ - public class MockBehaviorFixture - { - [Fact] - public void ShouldThrowIfStrictNoExpectation() - { - var mock = new Mock(MockBehavior.Strict); - try - { - mock.Object.Do(); - Assert.True(false, "Should have thrown for unexpected call with MockBehavior.Strict"); - } - catch (MockException mex) - { - Assert.Equal(MockException.ExceptionReason.NoSetup, mex.Reason); - } - } - - [Fact] - public void ShouldReturnDefaultForLooseBehaviorOnInterface() - { - var mock = new Mock(MockBehavior.Loose); - - Assert.Equal(0, mock.Object.Get()); - Assert.Null(mock.Object.GetObject()); - } - - [Fact] - public void ShouldReturnDefaultForLooseBehaviorOnAbstract() - { - var mock = new Mock(MockBehavior.Loose); - - Assert.Equal(0, mock.Object.AbstractGet()); - Assert.Null(mock.Object.GetObject()); - } - - [Fact] - public void ShouldReturnEmptyArrayOnLoose() - { - var mock = new Mock(MockBehavior.Loose); - - Assert.NotNull(mock.Object.GetArray()); - Assert.Equal(0, mock.Object.GetArray().Length); - } - - [Fact] - public void ShouldReturnEmptyArrayTwoDimensionsOnLoose() - { - var mock = new Mock(MockBehavior.Loose); - - Assert.NotNull(mock.Object.GetArrayTwoDimensions()); - Assert.Equal(0, mock.Object.GetArrayTwoDimensions().Length); - } - - [Fact] - public void ShouldReturnNullListOnLoose() - { - var mock = new Mock(MockBehavior.Loose); - - Assert.Null(mock.Object.GetList()); - } - - [Fact] - public void ShouldReturnEmptyEnumerableStringOnLoose() - { - var mock = new Mock(MockBehavior.Loose); - - Assert.NotNull(mock.Object.GetEnumerable()); - Assert.Equal(0, mock.Object.GetEnumerable().Count()); - } - - [Fact] - public void ShouldReturnEmptyEnumerableObjectsOnLoose() - { - var mock = new Mock(MockBehavior.Loose); - - Assert.NotNull(mock.Object.GetEnumerableObjects()); - Assert.Equal(0, mock.Object.GetEnumerableObjects().Cast().Count()); - } - - [Fact] - public void ShouldReturnDefaultGuidOnLoose() - { - var mock = new Mock(MockBehavior.Loose); - Assert.Equal(default(Guid), mock.Object.GetGuid()); - } - - [Fact] - public void ShouldReturnNullStringOnLoose() - { - var mock = new Mock(MockBehavior.Loose); - - Assert.Null(mock.Object.DoReturnString()); - } - - [Fact] - public void ShouldReturnNullStringOnLooseWithExpect() - { - var mock = new Mock(MockBehavior.Loose); - - mock.Setup(x => x.DoReturnString()); - - Assert.Null(mock.Object.DoReturnString()); - } - - [Fact] - public void ReturnsMockDefaultValueForLooseBehaviorOnInterface() - { - var mock = new Mock(MockBehavior.Loose) { DefaultValue = DefaultValue.Mock }; - - var value = mock.Object.GetObject(); - - Assert.True(value is IMocked); - } - - [Fact] - public void ReturnsMockDefaultValueForLooseBehaviorOnAbstract() - { - var mock = new Mock(MockBehavior.Loose) { DefaultValue = DefaultValue.Mock }; - - var value = mock.Object.Bar; - - Assert.True(value is IMocked); - - value = mock.Object.GetBar(); - - Assert.True(value is IMocked); - } - - [Fact] - public void ReturnsEmptyArrayOnLooseWithMockDefaultValue() - { - var mock = new Mock(MockBehavior.Loose) { DefaultValue = DefaultValue.Mock }; - - Assert.NotNull(mock.Object.GetArray()); - Assert.Equal(0, mock.Object.GetArray().Length); - } - - [Fact] - public void ReturnsEmptyArrayTwoDimensionsOnLooseWithMockDefaultValue() - { - var mock = new Mock(MockBehavior.Loose) { DefaultValue = DefaultValue.Mock }; - - Assert.NotNull(mock.Object.GetArrayTwoDimensions()); - Assert.Equal(0, mock.Object.GetArrayTwoDimensions().Length); - } - - [Fact] - public void ReturnsMockListOnLooseWithMockDefaultValue() - { - var mock = new Mock(MockBehavior.Loose) { DefaultValue = DefaultValue.Mock }; - - Assert.NotNull(mock.Object.GetList()); - - var list = mock.Object.GetList(); - - list.Add("foo"); - - Assert.Equal("foo", list[0]); - } - - [Fact] - public void ReturnsEmptyEnumerableStringOnLooseWithMockDefaultValue() - { - var mock = new Mock(MockBehavior.Loose) { DefaultValue = DefaultValue.Mock }; - - Assert.NotNull(mock.Object.GetEnumerable()); - Assert.Equal(0, mock.Object.GetEnumerable().Count()); - } - - [Fact] - public void ReturnsEmptyQueryableStringOnLooseWithMockDefaultValue() - { - var mock = new Mock(MockBehavior.Loose) { DefaultValue = DefaultValue.Mock }; - - Assert.NotNull(mock.Object.GetQueryable()); - Assert.Equal(0, mock.Object.GetQueryable().Count()); - } - - [Fact] - public void ReturnsEmptyEnumerableObjectsOnLooseWithMockDefaultValue() - { - var mock = new Mock(MockBehavior.Loose) { DefaultValue = DefaultValue.Mock }; - - Assert.NotNull(mock.Object.GetEnumerableObjects()); - Assert.Equal(0, mock.Object.GetEnumerableObjects().Cast().Count()); - } - - [Fact] - public void ReturnsEmptyQueryableObjectsOnLooseWithMockDefaultValue() - { - var mock = new Mock(MockBehavior.Loose) { DefaultValue = DefaultValue.Mock }; - - Assert.NotNull(mock.Object.GetQueryableObjects()); - Assert.Equal(0, mock.Object.GetQueryableObjects().Cast().Count()); - } - - [Fact] - public void ReturnsDefaultGuidOnLooseWithMockDefaultValueWithMockDefaultValue() - { - var mock = new Mock(MockBehavior.Loose) { DefaultValue = DefaultValue.Mock }; - Assert.Equal(default(Guid), mock.Object.GetGuid()); - } - - [Fact] - public void ReturnsNullStringOnLooseWithMockDefaultValue() - { - var mock = new Mock(MockBehavior.Loose) { DefaultValue = DefaultValue.Mock }; - - Assert.Null(mock.Object.DoReturnString()); - } - - public interface IFoo - { - void Do(); - int Get(); - Guid GetGuid(); - object GetObject(); - string[] GetArray(); - string[][] GetArrayTwoDimensions(); - List GetList(); - IEnumerable GetEnumerable(); - IEnumerable GetEnumerableObjects(); - string DoReturnString(); - IQueryable GetQueryable(); - IQueryable GetQueryableObjects(); - } - - public interface IBar { } - - public abstract class Foo : IFoo - { - public abstract IBar Bar { get; set; } - public abstract IBar GetBar(); - - public abstract void Do(); - public abstract object GetObject(); - public abstract string DoReturnString(); - - public void DoNonVirtual() { } - public virtual void DoVirtual() { } - - public int NonVirtualGet() - { - return 0; - } - - public int VirtualGet() - { - return 0; - } - - public virtual int Get() - { - return AbstractGet(); - } - - public abstract int AbstractGet(); - - public string[] GetArray() - { - return new string[0]; - } - - public string[][] GetArrayTwoDimensions() - { - return new string[0][]; - } - - public List GetList() - { - return null; - } - - public IEnumerable GetEnumerable() - { - return new string[0]; - } - - public IEnumerable GetEnumerableObjects() - { - return new object[0]; - } - - - public Guid GetGuid() - { - return default(Guid); - } - - public IQueryable GetQueryable() - { - return new string[0].AsQueryable(); - } - - public IQueryable GetQueryableObjects() - { - return new object[0].AsQueryable(); - } - } - } -} +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using Xunit; + +namespace Moq.Tests +{ + public class MockBehaviorFixture + { + [Fact] + public void ShouldThrowIfStrictNoExpectation() + { + var mock = new Mock(MockBehavior.Strict); + try + { + mock.Object.Do(); + Assert.True(false, "Should have thrown for unexpected call with MockBehavior.Strict"); + } + catch (MockException mex) + { + Assert.Equal(MockException.ExceptionReason.NoSetup, mex.Reason); + } + } + + [Fact] + public void ShouldReturnDefaultForLooseBehaviorOnInterface() + { + var mock = new Mock(MockBehavior.Loose); + + Assert.Equal(0, mock.Object.Get()); + Assert.Null(mock.Object.GetObject()); + } + + [Fact] + public void ShouldReturnDefaultForLooseBehaviorOnAbstract() + { + var mock = new Mock(MockBehavior.Loose); + + Assert.Equal(0, mock.Object.AbstractGet()); + Assert.Null(mock.Object.GetObject()); + } + + [Fact] + public void ShouldReturnEmptyArrayOnLoose() + { + var mock = new Mock(MockBehavior.Loose); + + Assert.NotNull(mock.Object.GetArray()); + Assert.Equal(0, mock.Object.GetArray().Length); + } + + [Fact] + public void ShouldReturnEmptyArrayTwoDimensionsOnLoose() + { + var mock = new Mock(MockBehavior.Loose); + + Assert.NotNull(mock.Object.GetArrayTwoDimensions()); + Assert.Equal(0, mock.Object.GetArrayTwoDimensions().Length); + } + + [Fact] + public void ShouldReturnNullListOnLoose() + { + var mock = new Mock(MockBehavior.Loose); + + Assert.Null(mock.Object.GetList()); + } + + [Fact] + public void ShouldReturnEmptyEnumerableStringOnLoose() + { + var mock = new Mock(MockBehavior.Loose); + + Assert.NotNull(mock.Object.GetEnumerable()); + Assert.Equal(0, mock.Object.GetEnumerable().Count()); + } + + [Fact] + public void ShouldReturnEmptyEnumerableObjectsOnLoose() + { + var mock = new Mock(MockBehavior.Loose); + + Assert.NotNull(mock.Object.GetEnumerableObjects()); + Assert.Equal(0, mock.Object.GetEnumerableObjects().Cast().Count()); + } + + [Fact] + public void ShouldReturnDefaultGuidOnLoose() + { + var mock = new Mock(MockBehavior.Loose); + Assert.Equal(default(Guid), mock.Object.GetGuid()); + } + + [Fact] + public void ShouldReturnNullStringOnLoose() + { + var mock = new Mock(MockBehavior.Loose); + + Assert.Null(mock.Object.DoReturnString()); + } + + [Fact] + public void ShouldReturnNullStringOnLooseWithExpect() + { + var mock = new Mock(MockBehavior.Loose); + + mock.Setup(x => x.DoReturnString()); + + Assert.Null(mock.Object.DoReturnString()); + } + + [Fact] + public void ReturnsMockDefaultValueForLooseBehaviorOnInterface() + { + var mock = new Mock(MockBehavior.Loose) { DefaultValue = DefaultValue.Mock }; + + var value = mock.Object.GetObject(); + + Assert.True(value is IMocked); + } + + [Fact] + public void ReturnsMockDefaultValueForLooseBehaviorOnAbstract() + { + var mock = new Mock(MockBehavior.Loose) { DefaultValue = DefaultValue.Mock }; + + var value = mock.Object.Bar; + + Assert.True(value is IMocked); + + value = mock.Object.GetBar(); + + Assert.True(value is IMocked); + } + + [Fact] + public void ReturnsEmptyArrayOnLooseWithMockDefaultValue() + { + var mock = new Mock(MockBehavior.Loose) { DefaultValue = DefaultValue.Mock }; + + Assert.NotNull(mock.Object.GetArray()); + Assert.Equal(0, mock.Object.GetArray().Length); + } + + [Fact] + public void ReturnsEmptyArrayTwoDimensionsOnLooseWithMockDefaultValue() + { + var mock = new Mock(MockBehavior.Loose) { DefaultValue = DefaultValue.Mock }; + + Assert.NotNull(mock.Object.GetArrayTwoDimensions()); + Assert.Equal(0, mock.Object.GetArrayTwoDimensions().Length); + } + + [Fact] + public void ReturnsMockListOnLooseWithMockDefaultValue() + { + var mock = new Mock(MockBehavior.Loose) { DefaultValue = DefaultValue.Mock }; + + Assert.NotNull(mock.Object.GetList()); + + var list = mock.Object.GetList(); + + list.Add("foo"); + + Assert.Equal("foo", list[0]); + } + + [Fact] + public void ReturnsEmptyEnumerableStringOnLooseWithMockDefaultValue() + { + var mock = new Mock(MockBehavior.Loose) { DefaultValue = DefaultValue.Mock }; + + Assert.NotNull(mock.Object.GetEnumerable()); + Assert.Equal(0, mock.Object.GetEnumerable().Count()); + } + + [Fact] + public void ReturnsEmptyQueryableStringOnLooseWithMockDefaultValue() + { + var mock = new Mock(MockBehavior.Loose) { DefaultValue = DefaultValue.Mock }; + + Assert.NotNull(mock.Object.GetQueryable()); + Assert.Equal(0, mock.Object.GetQueryable().Count()); + } + + [Fact] + public void ReturnsEmptyEnumerableObjectsOnLooseWithMockDefaultValue() + { + var mock = new Mock(MockBehavior.Loose) { DefaultValue = DefaultValue.Mock }; + + Assert.NotNull(mock.Object.GetEnumerableObjects()); + Assert.Equal(0, mock.Object.GetEnumerableObjects().Cast().Count()); + } + + [Fact] + public void ReturnsEmptyQueryableObjectsOnLooseWithMockDefaultValue() + { + var mock = new Mock(MockBehavior.Loose) { DefaultValue = DefaultValue.Mock }; + + Assert.NotNull(mock.Object.GetQueryableObjects()); + Assert.Equal(0, mock.Object.GetQueryableObjects().Cast().Count()); + } + + [Fact] + public void ReturnsDefaultGuidOnLooseWithMockDefaultValueWithMockDefaultValue() + { + var mock = new Mock(MockBehavior.Loose) { DefaultValue = DefaultValue.Mock }; + Assert.Equal(default(Guid), mock.Object.GetGuid()); + } + + [Fact] + public void ReturnsNullStringOnLooseWithMockDefaultValue() + { + var mock = new Mock(MockBehavior.Loose) { DefaultValue = DefaultValue.Mock }; + + Assert.Null(mock.Object.DoReturnString()); + } + + public interface IFoo + { + void Do(); + int Get(); + Guid GetGuid(); + object GetObject(); + string[] GetArray(); + string[][] GetArrayTwoDimensions(); + List GetList(); + IEnumerable GetEnumerable(); + IEnumerable GetEnumerableObjects(); + string DoReturnString(); + IQueryable GetQueryable(); + IQueryable GetQueryableObjects(); + } + + public interface IBar { } + + public abstract class Foo : IFoo + { + public abstract IBar Bar { get; set; } + public abstract IBar GetBar(); + + public abstract void Do(); + public abstract object GetObject(); + public abstract string DoReturnString(); + + public void DoNonVirtual() { } + public virtual void DoVirtual() { } + + public int NonVirtualGet() + { + return 0; + } + + public int VirtualGet() + { + return 0; + } + + public virtual int Get() + { + return AbstractGet(); + } + + public abstract int AbstractGet(); + + public string[] GetArray() + { + return new string[0]; + } + + public string[][] GetArrayTwoDimensions() + { + return new string[0][]; + } + + public List GetList() + { + return null; + } + + public IEnumerable GetEnumerable() + { + return new string[0]; + } + + public IEnumerable GetEnumerableObjects() + { + return new object[0]; + } + + + public Guid GetGuid() + { + return default(Guid); + } + + public IQueryable GetQueryable() + { + return new string[0].AsQueryable(); + } + + public IQueryable GetQueryableObjects() + { + return new object[0].AsQueryable(); + } + } + } +} diff --git a/UnitTests/MockDefaultValueProviderFixture.cs b/UnitTests/MockDefaultValueProviderFixture.cs index 09b3926eb..02555b421 100644 --- a/UnitTests/MockDefaultValueProviderFixture.cs +++ b/UnitTests/MockDefaultValueProviderFixture.cs @@ -1,103 +1,103 @@ -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace Moq.Tests -{ - public class MockDefaultValueProviderFixture - { - [Fact] - public void ProvidesMockValue() - { - var mock = new Mock(); - var provider = new MockDefaultValueProvider(mock); - - var value = provider.ProvideDefault(typeof(IFoo).GetProperty("Bar").GetGetMethod()); - - Assert.NotNull(value); - Assert.True(value is IMocked); - } - - [Fact] - public void CachesProvidedValue() - { - var mock = new Mock(); - var provider = new MockDefaultValueProvider(mock); - - var value1 = provider.ProvideDefault(typeof(IFoo).GetProperty("Bar").GetGetMethod()); - var value2 = provider.ProvideDefault(typeof(IFoo).GetProperty("Bar").GetGetMethod()); - - Assert.Same(value1, value2); - } - - [Fact] - public void ProvidesEmptyValueIfNotMockeable() - { - var mock = new Mock(); - var provider = new MockDefaultValueProvider(mock); - - var value = provider.ProvideDefault(typeof(IFoo).GetProperty("Value").GetGetMethod()); - Assert.Equal(default(string), value); - - value = provider.ProvideDefault(typeof(IFoo).GetProperty("Value").GetGetMethod()); - Assert.Equal(default(string), value); - - value = provider.ProvideDefault(typeof(IFoo).GetProperty("Indexes").GetGetMethod()); - Assert.True(value is IEnumerable && ((IEnumerable)value).Count() == 0); - - value = provider.ProvideDefault(typeof(IFoo).GetProperty("Bars").GetGetMethod()); - Assert.True(value is IBar[] && ((IBar[])value).Length == 0); - } - - [Fact] - public void NewMocksHaveSameBehaviorAndDefaultValueAsOwner() - { - var mock = new Mock(); - var provider = new MockDefaultValueProvider(mock); - - var value = provider.ProvideDefault(typeof(IFoo).GetProperty("Bar").GetGetMethod()); - - var barMock = Mock.Get((IBar)value); - - Assert.Equal(mock.Behavior, barMock.Behavior); - Assert.Equal(mock.DefaultValue, barMock.DefaultValue); - } - - [Fact] - public void NewMocksHaveSameCallBaseAsOwner() - { - var mock = new Mock { CallBase = true }; - var provider = new MockDefaultValueProvider(mock); - - var value = provider.ProvideDefault(typeof(IFoo).GetProperty("Bar").GetGetMethod()); - - var barMock = Mock.Get((IBar)value); - - Assert.Equal(mock.CallBase, barMock.CallBase); - } - - [Fact] - public void CreatedMockIsVerifiedWithOwner() - { - var mock = new Mock(); - var provider = new MockDefaultValueProvider(mock); - - var value = provider.ProvideDefault(typeof(IFoo).GetProperty("Bar").GetGetMethod()); - - var barMock = Mock.Get((IBar)value); - barMock.Setup(b => b.Do()).Verifiable(); - - Assert.Throws(() => mock.Verify()); - } - - public interface IFoo - { - IBar Bar { get; set; } - string Value { get; set; } - IEnumerable Indexes { get; set; } - IBar[] Bars { get; set; } - } - - public interface IBar { void Do(); } - } -} +using System.Collections.Generic; +using System.Linq; +using Xunit; + +namespace Moq.Tests +{ + public class MockDefaultValueProviderFixture + { + [Fact] + public void ProvidesMockValue() + { + var mock = new Mock(); + var provider = new MockDefaultValueProvider(mock); + + var value = provider.ProvideDefault(typeof(IFoo).GetProperty("Bar").GetGetMethod()); + + Assert.NotNull(value); + Assert.True(value is IMocked); + } + + [Fact] + public void CachesProvidedValue() + { + var mock = new Mock(); + var provider = new MockDefaultValueProvider(mock); + + var value1 = provider.ProvideDefault(typeof(IFoo).GetProperty("Bar").GetGetMethod()); + var value2 = provider.ProvideDefault(typeof(IFoo).GetProperty("Bar").GetGetMethod()); + + Assert.Same(value1, value2); + } + + [Fact] + public void ProvidesEmptyValueIfNotMockeable() + { + var mock = new Mock(); + var provider = new MockDefaultValueProvider(mock); + + var value = provider.ProvideDefault(typeof(IFoo).GetProperty("Value").GetGetMethod()); + Assert.Equal(default(string), value); + + value = provider.ProvideDefault(typeof(IFoo).GetProperty("Value").GetGetMethod()); + Assert.Equal(default(string), value); + + value = provider.ProvideDefault(typeof(IFoo).GetProperty("Indexes").GetGetMethod()); + Assert.True(value is IEnumerable && ((IEnumerable)value).Count() == 0); + + value = provider.ProvideDefault(typeof(IFoo).GetProperty("Bars").GetGetMethod()); + Assert.True(value is IBar[] && ((IBar[])value).Length == 0); + } + + [Fact] + public void NewMocksHaveSameBehaviorAndDefaultValueAsOwner() + { + var mock = new Mock(); + var provider = new MockDefaultValueProvider(mock); + + var value = provider.ProvideDefault(typeof(IFoo).GetProperty("Bar").GetGetMethod()); + + var barMock = Mock.Get((IBar)value); + + Assert.Equal(mock.Behavior, barMock.Behavior); + Assert.Equal(mock.DefaultValue, barMock.DefaultValue); + } + + [Fact] + public void NewMocksHaveSameCallBaseAsOwner() + { + var mock = new Mock { CallBase = true }; + var provider = new MockDefaultValueProvider(mock); + + var value = provider.ProvideDefault(typeof(IFoo).GetProperty("Bar").GetGetMethod()); + + var barMock = Mock.Get((IBar)value); + + Assert.Equal(mock.CallBase, barMock.CallBase); + } + + [Fact] + public void CreatedMockIsVerifiedWithOwner() + { + var mock = new Mock(); + var provider = new MockDefaultValueProvider(mock); + + var value = provider.ProvideDefault(typeof(IFoo).GetProperty("Bar").GetGetMethod()); + + var barMock = Mock.Get((IBar)value); + barMock.Setup(b => b.Do()).Verifiable(); + + Assert.Throws(() => mock.Verify()); + } + + public interface IFoo + { + IBar Bar { get; set; } + string Value { get; set; } + IEnumerable Indexes { get; set; } + IBar[] Bars { get; set; } + } + + public interface IBar { void Do(); } + } +} diff --git a/UnitTests/MockRepositoryFixture.cs b/UnitTests/MockRepositoryFixture.cs index 9bd217e1b..f4557bcce 100644 --- a/UnitTests/MockRepositoryFixture.cs +++ b/UnitTests/MockRepositoryFixture.cs @@ -1,179 +1,179 @@ -using System; -using System.Linq.Expressions; -using Xunit; - -namespace Moq.Tests -{ - public class MockRepositoryFixture - { - [Fact] - public void ShouldCreateFactoryWithMockBehaviorAndVerificationBehavior() - { - var repository = new MockRepository(MockBehavior.Loose); - - Assert.NotNull(repository); - } - - [Fact] - public void ShouldCreateMocksWithFactoryBehavior() - { - var repository = new MockRepository(MockBehavior.Loose); - - var mock = repository.Create(); - - Assert.Equal(MockBehavior.Loose, mock.Behavior); - } - - [Fact] - public void ShouldCreateMockWithConstructorArgs() - { - var repository = new MockRepository(MockBehavior.Loose); - - var mock = repository.Create("foo"); - - Assert.Equal("foo", mock.Object.Value); - } - - [Fact] - public void ShouldVerifyAll() - { - try - { - var repository = new MockRepository(MockBehavior.Default); - var mock = repository.Create(); - - mock.Setup(foo => foo.Do()); - - repository.VerifyAll(); - } - catch (MockException mex) - { - Assert.Equal(MockException.ExceptionReason.VerificationFailed, mex.Reason); - } - } - - [Fact] - public void ShouldVerifyVerifiables() - { - try - { - var repository = new MockRepository(MockBehavior.Default); - var mock = repository.Create(); - - mock.Setup(foo => foo.Do()); - mock.Setup(foo => foo.Undo()).Verifiable(); - - repository.Verify(); - } - catch (MockException mex) - { - Assert.Equal(MockException.ExceptionReason.VerificationFailed, mex.Reason); - Expression> doExpr = foo => foo.Do(); - Assert.False(mex.Message.Contains(doExpr.ToString())); - } - } - - [Fact] - public void ShouldAggregateFailures() - { - try - { - var repository = new MockRepository(MockBehavior.Loose); - var foo = repository.Create(); - var bar = repository.Create(); - - foo.Setup(f => f.Do()); - bar.Setup(b => b.Redo()); - - repository.VerifyAll(); - } - catch (MockException mex) - { - Expression> fooExpect = f => f.Do(); - Assert.True(mex.Message.Contains(fooExpect.ToString())); - - Expression> barExpect = b => b.Redo(); - Assert.True(mex.Message.Contains(barExpect.ToString())); - } - } - - [Fact] - public void ShouldOverrideDefaultBehavior() - { - var repository = new MockRepository(MockBehavior.Loose); - var mock = repository.Create(MockBehavior.Strict); - - Assert.Equal(MockBehavior.Strict, mock.Behavior); - } - - [Fact] - public void ShouldOverrideDefaultBehaviorWithCtorArgs() - { - var repository = new MockRepository(MockBehavior.Loose); - var mock = repository.Create(MockBehavior.Strict, "Foo"); - - Assert.Equal(MockBehavior.Strict, mock.Behavior); - Assert.Equal("Foo", mock.Object.Value); - } - - [Fact] - public void ShouldCreateMocksWithFactoryDefaultValue() - { - var repository = new MockRepository(MockBehavior.Loose) { DefaultValue = DefaultValue.Mock }; - - var mock = repository.Create(); - - Assert.NotNull(mock.Object.Bar()); - } - - [Fact] - public void ShouldCreateMocksWithFactoryCallBase() - { - var repository = new MockRepository(MockBehavior.Loose); - - var mock = repository.Create(); - - mock.Object.BaseMethod(); - - Assert.False(mock.Object.BaseCalled); - - repository.CallBase = true; - - mock = repository.Create(); - - mock.Object.BaseMethod(); - - Assert.True(mock.Object.BaseCalled); - } - - public interface IFoo - { - void Do(); - void Undo(); - IBar Bar(); - } - - public interface IBar { void Redo(); } - - public abstract class BaseClass - { - public bool BaseCalled; - - public BaseClass() - { - } - - public BaseClass(string value) - { - this.Value = value; - } - - public string Value { get; set; } - - public virtual void BaseMethod() - { - BaseCalled = true; - } - } - } -} +using System; +using System.Linq.Expressions; +using Xunit; + +namespace Moq.Tests +{ + public class MockRepositoryFixture + { + [Fact] + public void ShouldCreateFactoryWithMockBehaviorAndVerificationBehavior() + { + var repository = new MockRepository(MockBehavior.Loose); + + Assert.NotNull(repository); + } + + [Fact] + public void ShouldCreateMocksWithFactoryBehavior() + { + var repository = new MockRepository(MockBehavior.Loose); + + var mock = repository.Create(); + + Assert.Equal(MockBehavior.Loose, mock.Behavior); + } + + [Fact] + public void ShouldCreateMockWithConstructorArgs() + { + var repository = new MockRepository(MockBehavior.Loose); + + var mock = repository.Create("foo"); + + Assert.Equal("foo", mock.Object.Value); + } + + [Fact] + public void ShouldVerifyAll() + { + try + { + var repository = new MockRepository(MockBehavior.Default); + var mock = repository.Create(); + + mock.Setup(foo => foo.Do()); + + repository.VerifyAll(); + } + catch (MockException mex) + { + Assert.Equal(MockException.ExceptionReason.VerificationFailed, mex.Reason); + } + } + + [Fact] + public void ShouldVerifyVerifiables() + { + try + { + var repository = new MockRepository(MockBehavior.Default); + var mock = repository.Create(); + + mock.Setup(foo => foo.Do()); + mock.Setup(foo => foo.Undo()).Verifiable(); + + repository.Verify(); + } + catch (MockException mex) + { + Assert.Equal(MockException.ExceptionReason.VerificationFailed, mex.Reason); + Expression> doExpr = foo => foo.Do(); + Assert.False(mex.Message.Contains(doExpr.ToString())); + } + } + + [Fact] + public void ShouldAggregateFailures() + { + try + { + var repository = new MockRepository(MockBehavior.Loose); + var foo = repository.Create(); + var bar = repository.Create(); + + foo.Setup(f => f.Do()); + bar.Setup(b => b.Redo()); + + repository.VerifyAll(); + } + catch (MockException mex) + { + Expression> fooExpect = f => f.Do(); + Assert.True(mex.Message.Contains(fooExpect.ToString())); + + Expression> barExpect = b => b.Redo(); + Assert.True(mex.Message.Contains(barExpect.ToString())); + } + } + + [Fact] + public void ShouldOverrideDefaultBehavior() + { + var repository = new MockRepository(MockBehavior.Loose); + var mock = repository.Create(MockBehavior.Strict); + + Assert.Equal(MockBehavior.Strict, mock.Behavior); + } + + [Fact] + public void ShouldOverrideDefaultBehaviorWithCtorArgs() + { + var repository = new MockRepository(MockBehavior.Loose); + var mock = repository.Create(MockBehavior.Strict, "Foo"); + + Assert.Equal(MockBehavior.Strict, mock.Behavior); + Assert.Equal("Foo", mock.Object.Value); + } + + [Fact] + public void ShouldCreateMocksWithFactoryDefaultValue() + { + var repository = new MockRepository(MockBehavior.Loose) { DefaultValue = DefaultValue.Mock }; + + var mock = repository.Create(); + + Assert.NotNull(mock.Object.Bar()); + } + + [Fact] + public void ShouldCreateMocksWithFactoryCallBase() + { + var repository = new MockRepository(MockBehavior.Loose); + + var mock = repository.Create(); + + mock.Object.BaseMethod(); + + Assert.False(mock.Object.BaseCalled); + + repository.CallBase = true; + + mock = repository.Create(); + + mock.Object.BaseMethod(); + + Assert.True(mock.Object.BaseCalled); + } + + public interface IFoo + { + void Do(); + void Undo(); + IBar Bar(); + } + + public interface IBar { void Redo(); } + + public abstract class BaseClass + { + public bool BaseCalled; + + public BaseClass() + { + } + + public BaseClass(string value) + { + this.Value = value; + } + + public string Value { get; set; } + + public virtual void BaseMethod() + { + BaseCalled = true; + } + } + } +} diff --git a/UnitTests/MockSequenceFixture.cs b/UnitTests/MockSequenceFixture.cs index 8f23f1432..21b044452 100644 --- a/UnitTests/MockSequenceFixture.cs +++ b/UnitTests/MockSequenceFixture.cs @@ -1,76 +1,76 @@ -using Xunit; - -namespace Moq.Tests -{ - public class MockSequenceFixture - { - [Fact] - public void RightSequenceSuccess() - { - var a = new Mock(MockBehavior.Strict); - var b = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - a.InSequence(sequence).Setup(x => x.Do(100)).Returns(101); - b.InSequence(sequence).Setup(x => x.Do(200)).Returns(201); - - a.Object.Do(100); - b.Object.Do(200); - } - - [Fact] - public void InvalidSequenceFail() - { - var a = new Mock(MockBehavior.Strict); - var b = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - a.InSequence(sequence).Setup(x => x.Do(100)).Returns(101); - b.InSequence(sequence).Setup(x => x.Do(200)).Returns(201); - - Assert.Throws(() => b.Object.Do(200)); - } - - [Fact] - public void NoCyclicSequenceFail() - { - var a = new Mock(MockBehavior.Strict); - var b = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - a.InSequence(sequence).Setup(x => x.Do(100)).Returns(101); - b.InSequence(sequence).Setup(x => x.Do(200)).Returns(201); - - Assert.Equal(101, a.Object.Do(100)); - Assert.Equal(201, b.Object.Do(200)); - - Assert.Throws(() => a.Object.Do(100)); - Assert.Throws(() => b.Object.Do(200)); - } - - [Fact] - public void CyclicSequenceSuccesss() - { - var a = new Mock(MockBehavior.Strict); - var b = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence { Cyclic = true }; - a.InSequence(sequence).Setup(x => x.Do(100)).Returns(101); - b.InSequence(sequence).Setup(x => x.Do(200)).Returns(201); - - Assert.Equal(101, a.Object.Do(100)); - Assert.Equal(201, b.Object.Do(200)); - - Assert.Equal(101, a.Object.Do(100)); - Assert.Equal(201, b.Object.Do(200)); - - Assert.Equal(101, a.Object.Do(100)); - Assert.Equal(201, b.Object.Do(200)); - } - - public interface IFoo - { - int Do(int arg); - } - } +using Xunit; + +namespace Moq.Tests +{ + public class MockSequenceFixture + { + [Fact] + public void RightSequenceSuccess() + { + var a = new Mock(MockBehavior.Strict); + var b = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + a.InSequence(sequence).Setup(x => x.Do(100)).Returns(101); + b.InSequence(sequence).Setup(x => x.Do(200)).Returns(201); + + a.Object.Do(100); + b.Object.Do(200); + } + + [Fact] + public void InvalidSequenceFail() + { + var a = new Mock(MockBehavior.Strict); + var b = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + a.InSequence(sequence).Setup(x => x.Do(100)).Returns(101); + b.InSequence(sequence).Setup(x => x.Do(200)).Returns(201); + + Assert.Throws(() => b.Object.Do(200)); + } + + [Fact] + public void NoCyclicSequenceFail() + { + var a = new Mock(MockBehavior.Strict); + var b = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + a.InSequence(sequence).Setup(x => x.Do(100)).Returns(101); + b.InSequence(sequence).Setup(x => x.Do(200)).Returns(201); + + Assert.Equal(101, a.Object.Do(100)); + Assert.Equal(201, b.Object.Do(200)); + + Assert.Throws(() => a.Object.Do(100)); + Assert.Throws(() => b.Object.Do(200)); + } + + [Fact] + public void CyclicSequenceSuccesss() + { + var a = new Mock(MockBehavior.Strict); + var b = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence { Cyclic = true }; + a.InSequence(sequence).Setup(x => x.Do(100)).Returns(101); + b.InSequence(sequence).Setup(x => x.Do(200)).Returns(201); + + Assert.Equal(101, a.Object.Do(100)); + Assert.Equal(201, b.Object.Do(200)); + + Assert.Equal(101, a.Object.Do(100)); + Assert.Equal(201, b.Object.Do(200)); + + Assert.Equal(101, a.Object.Do(100)); + Assert.Equal(201, b.Object.Do(200)); + } + + public interface IFoo + { + int Do(int arg); + } + } } \ No newline at end of file diff --git a/UnitTests/OccurrenceFixture.cs b/UnitTests/OccurrenceFixture.cs index b57e12a52..64f44fce6 100644 --- a/UnitTests/OccurrenceFixture.cs +++ b/UnitTests/OccurrenceFixture.cs @@ -1,56 +1,56 @@ -using System; -using Xunit; - -namespace Moq.Tests -{ - public class OccurrenceFixture - { - [Fact] - [Obsolete] - public void OnceThrowsOnSecondCall() - { - var mock = new Mock(); - mock.Setup(foo => foo.Execute("ping")) - .Returns("ack") - .AtMostOnce(); - - Assert.Equal("ack", mock.Object.Execute("ping")); - MockException mex = Assert.Throws(() => mock.Object.Execute("ping")); - Assert.Equal(MockException.ExceptionReason.MoreThanOneCall, mex.Reason); - } - - [Fact] - [Obsolete] - public void RepeatThrowsOnNPlusOneCall() - { - var repeat = 5; - var mock = new Mock(); - mock.Setup(foo => foo.Execute("ping")) - .Returns("ack") - .AtMost(5); - - var calls = 0; - MockException mex = Assert.Throws(() => - { - while (calls <= repeat + 1) - { - mock.Object.Execute("ping"); - calls++; - } - - Assert.True(false, "should fail on two calls"); - }); - - Assert.Equal(MockException.ExceptionReason.MoreThanNCalls, mex.Reason); - Assert.Equal(calls, repeat); - } - - public interface IFoo - { - int Value { get; set; } - int Echo(int value); - void Submit(); - string Execute(string command); - } - } +using System; +using Xunit; + +namespace Moq.Tests +{ + public class OccurrenceFixture + { + [Fact] + [Obsolete] + public void OnceThrowsOnSecondCall() + { + var mock = new Mock(); + mock.Setup(foo => foo.Execute("ping")) + .Returns("ack") + .AtMostOnce(); + + Assert.Equal("ack", mock.Object.Execute("ping")); + MockException mex = Assert.Throws(() => mock.Object.Execute("ping")); + Assert.Equal(MockException.ExceptionReason.MoreThanOneCall, mex.Reason); + } + + [Fact] + [Obsolete] + public void RepeatThrowsOnNPlusOneCall() + { + var repeat = 5; + var mock = new Mock(); + mock.Setup(foo => foo.Execute("ping")) + .Returns("ack") + .AtMost(5); + + var calls = 0; + MockException mex = Assert.Throws(() => + { + while (calls <= repeat + 1) + { + mock.Object.Execute("ping"); + calls++; + } + + Assert.True(false, "should fail on two calls"); + }); + + Assert.Equal(MockException.ExceptionReason.MoreThanNCalls, mex.Reason); + Assert.Equal(calls, repeat); + } + + public interface IFoo + { + int Value { get; set; } + int Echo(int value); + void Submit(); + string Execute(string command); + } + } } \ No newline at end of file diff --git a/UnitTests/OutRefFixture.cs b/UnitTests/OutRefFixture.cs index 1b7bc694e..fc0ccfa97 100644 --- a/UnitTests/OutRefFixture.cs +++ b/UnitTests/OutRefFixture.cs @@ -1,100 +1,100 @@ -using Xunit; -using System; - -namespace Moq.Tests -{ - public class OutRefFixture - { - [Fact] - public void ExpectsOutArgument() - { - var mock = new Mock(); - var expected = "ack"; - - mock.Setup(m => m.Execute("ping", out expected)).Returns(true); - - string actual; - var ok = mock.Object.Execute("ping", out actual); - - Assert.True(ok); - Assert.Equal(expected, actual); - } - - [Fact] - public void ExpectsOutEagerlyEvaluates() - { - var mock = new Mock(); - string expected = "ack"; - - mock.Setup(m => m.Execute("ping", out expected)).Returns(true); - - expected = "foo"; - - string actual; - bool ok = mock.Object.Execute("ping", out actual); - - Assert.True(ok); - Assert.Equal("ack", actual); - } - - [Fact] - public void ExpectsRefArgument() - { - var mock = new Mock(); - string expected = "ack"; - - mock.Setup(m => m.Echo(ref expected)).Returns(s => s); - - string actual = mock.Object.Echo(ref expected); - - Assert.Equal(expected, actual); - } - - [Fact] - public void RefOnlyMatchesSameInstance() - { - var mock = new Mock(MockBehavior.Strict); - string expected = "ack"; - - mock.Setup(m => m.Echo(ref expected)).Returns(s => s); - - string actual = null; - Assert.Throws(() => mock.Object.Echo(ref actual)); - } - - [Fact] - public void RefTakesGuidParameter() - { - var mock = new Mock(MockBehavior.Strict); - var expected = Guid.NewGuid(); - - mock.Setup(m => m.GuidMethod(ref expected)).Returns(true); - - Assert.Equal(true, mock.Object.GuidMethod(ref expected)); - } - - [Fact] - public void RefWorksWithOtherValueTypes() - { - var mock = new Mock(MockBehavior.Strict); - var expected = 5; - - mock.Setup(m => m.IntMethod(ref expected)).Returns(true); - - Assert.Equal(true, mock.Object.IntMethod(ref expected)); - } - - // ThrowsIfOutIsNotConstant - // ThrowsIfRefIsNotConstant - - public interface IFoo - { - T Echo(ref T value); - bool Execute(string command, out string result); - void Submit(string command, ref string result); - int Value { get; set; } - bool GuidMethod(ref Guid guid); - bool IntMethod(ref int value); - } - } -} +using Xunit; +using System; + +namespace Moq.Tests +{ + public class OutRefFixture + { + [Fact] + public void ExpectsOutArgument() + { + var mock = new Mock(); + var expected = "ack"; + + mock.Setup(m => m.Execute("ping", out expected)).Returns(true); + + string actual; + var ok = mock.Object.Execute("ping", out actual); + + Assert.True(ok); + Assert.Equal(expected, actual); + } + + [Fact] + public void ExpectsOutEagerlyEvaluates() + { + var mock = new Mock(); + string expected = "ack"; + + mock.Setup(m => m.Execute("ping", out expected)).Returns(true); + + expected = "foo"; + + string actual; + bool ok = mock.Object.Execute("ping", out actual); + + Assert.True(ok); + Assert.Equal("ack", actual); + } + + [Fact] + public void ExpectsRefArgument() + { + var mock = new Mock(); + string expected = "ack"; + + mock.Setup(m => m.Echo(ref expected)).Returns(s => s); + + string actual = mock.Object.Echo(ref expected); + + Assert.Equal(expected, actual); + } + + [Fact] + public void RefOnlyMatchesSameInstance() + { + var mock = new Mock(MockBehavior.Strict); + string expected = "ack"; + + mock.Setup(m => m.Echo(ref expected)).Returns(s => s); + + string actual = null; + Assert.Throws(() => mock.Object.Echo(ref actual)); + } + + [Fact] + public void RefTakesGuidParameter() + { + var mock = new Mock(MockBehavior.Strict); + var expected = Guid.NewGuid(); + + mock.Setup(m => m.GuidMethod(ref expected)).Returns(true); + + Assert.Equal(true, mock.Object.GuidMethod(ref expected)); + } + + [Fact] + public void RefWorksWithOtherValueTypes() + { + var mock = new Mock(MockBehavior.Strict); + var expected = 5; + + mock.Setup(m => m.IntMethod(ref expected)).Returns(true); + + Assert.Equal(true, mock.Object.IntMethod(ref expected)); + } + + // ThrowsIfOutIsNotConstant + // ThrowsIfRefIsNotConstant + + public interface IFoo + { + T Echo(ref T value); + bool Execute(string command, out string result); + void Submit(string command, ref string result); + int Value { get; set; } + bool GuidMethod(ref Guid guid); + bool IntMethod(ref int value); + } + } +} diff --git a/UnitTests/Pex/Moq.UnitTests.Pex.csproj b/UnitTests/Pex/Moq.UnitTests.Pex.csproj index 4f04669b7..e31e2a883 100644 --- a/UnitTests/Pex/Moq.UnitTests.Pex.csproj +++ b/UnitTests/Pex/Moq.UnitTests.Pex.csproj @@ -1,68 +1,68 @@ - - - - Debug - AnyCPU - 9.0.30729 - 2.0 - {662DD403-EFFD-4804-A29D-2E1F80D92835} - Library - Properties - Moq.UnitTests.Pex - Moq.UnitTests.Pex - v3.5 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - False - C:\Program Files (x86)\Microsoft Pex\bin\Microsoft.Pex.Framework.dll - - - - - 3.5 - - - - - - - - - - - - {1C91AC30-5977-4BE5-BA67-8EB186C03514} - Moq - - - - - - - + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {662DD403-EFFD-4804-A29D-2E1F80D92835} + Library + Properties + Moq.UnitTests.Pex + Moq.UnitTests.Pex + v3.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + C:\Program Files (x86)\Microsoft Pex\bin\Microsoft.Pex.Framework.dll + + + + + 3.5 + + + + + + + + + + + + {1C91AC30-5977-4BE5-BA67-8EB186C03514} + Moq + + + + + + + \ No newline at end of file diff --git a/UnitTests/Pex/Moq.UnitTests.Pex.sln b/UnitTests/Pex/Moq.UnitTests.Pex.sln index 8201c9d66..50f4d9094 100644 --- a/UnitTests/Pex/Moq.UnitTests.Pex.sln +++ b/UnitTests/Pex/Moq.UnitTests.Pex.sln @@ -1,34 +1,34 @@ - -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moq.UnitTests.Pex", "Moq.UnitTests.Pex.csproj", "{662DD403-EFFD-4804-A29D-2E1F80D92835}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moq", "..\..\Source\Moq.csproj", "{1C91AC30-5977-4BE5-BA67-8EB186C03514}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Debug|x86 = Debug|x86 - Release|Any CPU = Release|Any CPU - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {662DD403-EFFD-4804-A29D-2E1F80D92835}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {662DD403-EFFD-4804-A29D-2E1F80D92835}.Debug|Any CPU.Build.0 = Debug|Any CPU - {662DD403-EFFD-4804-A29D-2E1F80D92835}.Debug|x86.ActiveCfg = Debug|Any CPU - {662DD403-EFFD-4804-A29D-2E1F80D92835}.Release|Any CPU.ActiveCfg = Release|Any CPU - {662DD403-EFFD-4804-A29D-2E1F80D92835}.Release|Any CPU.Build.0 = Release|Any CPU - {662DD403-EFFD-4804-A29D-2E1F80D92835}.Release|x86.ActiveCfg = Release|Any CPU - {1C91AC30-5977-4BE5-BA67-8EB186C03514}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1C91AC30-5977-4BE5-BA67-8EB186C03514}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1C91AC30-5977-4BE5-BA67-8EB186C03514}.Debug|x86.ActiveCfg = Debug|x86 - {1C91AC30-5977-4BE5-BA67-8EB186C03514}.Debug|x86.Build.0 = Debug|x86 - {1C91AC30-5977-4BE5-BA67-8EB186C03514}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1C91AC30-5977-4BE5-BA67-8EB186C03514}.Release|Any CPU.Build.0 = Release|Any CPU - {1C91AC30-5977-4BE5-BA67-8EB186C03514}.Release|x86.ActiveCfg = Release|x86 - {1C91AC30-5977-4BE5-BA67-8EB186C03514}.Release|x86.Build.0 = Release|x86 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moq.UnitTests.Pex", "Moq.UnitTests.Pex.csproj", "{662DD403-EFFD-4804-A29D-2E1F80D92835}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moq", "..\..\Source\Moq.csproj", "{1C91AC30-5977-4BE5-BA67-8EB186C03514}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {662DD403-EFFD-4804-A29D-2E1F80D92835}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {662DD403-EFFD-4804-A29D-2E1F80D92835}.Debug|Any CPU.Build.0 = Debug|Any CPU + {662DD403-EFFD-4804-A29D-2E1F80D92835}.Debug|x86.ActiveCfg = Debug|Any CPU + {662DD403-EFFD-4804-A29D-2E1F80D92835}.Release|Any CPU.ActiveCfg = Release|Any CPU + {662DD403-EFFD-4804-A29D-2E1F80D92835}.Release|Any CPU.Build.0 = Release|Any CPU + {662DD403-EFFD-4804-A29D-2E1F80D92835}.Release|x86.ActiveCfg = Release|Any CPU + {1C91AC30-5977-4BE5-BA67-8EB186C03514}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1C91AC30-5977-4BE5-BA67-8EB186C03514}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1C91AC30-5977-4BE5-BA67-8EB186C03514}.Debug|x86.ActiveCfg = Debug|x86 + {1C91AC30-5977-4BE5-BA67-8EB186C03514}.Debug|x86.Build.0 = Debug|x86 + {1C91AC30-5977-4BE5-BA67-8EB186C03514}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1C91AC30-5977-4BE5-BA67-8EB186C03514}.Release|Any CPU.Build.0 = Release|Any CPU + {1C91AC30-5977-4BE5-BA67-8EB186C03514}.Release|x86.ActiveCfg = Release|x86 + {1C91AC30-5977-4BE5-BA67-8EB186C03514}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/UnitTests/Pex/ShouldExpectCallReturn.cs b/UnitTests/Pex/ShouldExpectCallReturn.cs index 99559494a..0c4098ee2 100644 --- a/UnitTests/Pex/ShouldExpectCallReturn.cs +++ b/UnitTests/Pex/ShouldExpectCallReturn.cs @@ -1,36 +1,36 @@ -// ==++== -// -// Copyright (c) Microsoft Corporation. All rights reserved. -// -// ==--== - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.Pex.Framework; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Microsoft.Pex.Framework.Suppression; -using Microsoft.Pex.Framework.Choices; - -namespace Mock.Tests -{ - [TestClass] - [PexClass(Suite = "checkin")] - public partial class ShouldExpectCallReturn - { - [TestMethod] - [PexMethod(MaxBranches = int.MaxValue)] - public void Moq() - { - // ShouldExpectCallReturn - var mock = new Mock(); - var clone = new object(); - - mock.Setup(x => x.Clone()).Returns(clone); - - Assert.AreSame(clone, mock.Object.Clone()); - } - } -} +// ==++== +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ==--== + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Pex.Framework; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Microsoft.Pex.Framework.Suppression; +using Microsoft.Pex.Framework.Choices; + +namespace Mock.Tests +{ + [TestClass] + [PexClass(Suite = "checkin")] + public partial class ShouldExpectCallReturn + { + [TestMethod] + [PexMethod(MaxBranches = int.MaxValue)] + public void Moq() + { + // ShouldExpectCallReturn + var mock = new Mock(); + var clone = new object(); + + mock.Setup(x => x.Clone()).Returns(clone); + + Assert.AreSame(clone, mock.Object.Clone()); + } + } +} diff --git a/UnitTests/Pex/ShouldExpectCallWithArgument.cs b/UnitTests/Pex/ShouldExpectCallWithArgument.cs index 09b759925..2b82fca1f 100644 --- a/UnitTests/Pex/ShouldExpectCallWithArgument.cs +++ b/UnitTests/Pex/ShouldExpectCallWithArgument.cs @@ -1,84 +1,84 @@ -// ==++== -// -// Copyright (c) Microsoft Corporation. All rights reserved. -// -// ==--== - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.Pex.Framework; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Microsoft.Pex.Framework.Suppression; -using Microsoft.Pex.Framework.Instrumentation; -using System.Diagnostics; -using Microsoft.Pex.Framework.Choices; -using Microsoft.Pex.Framework.Validation; - -[assembly: PexInstrumentAssembly("Moq")] -[assembly: PexInstrumentAssembly("DynamicProxyGenAssembly2")] - -namespace Mock.Tests -{ - [TestClass] - [PexClass(Suite = "checkin")] - public partial class ShouldExpectCallWithArgument - { - public interface IFoo - { - int DoInt(int i); - } - - [TestMethod] - [PexMethod(MaxBranches = int.MaxValue)] - public void Moq() - { - // ShouldExpectCallWithArgument - var mock = new Mock(); - mock.Setup(x => x.DoInt(1)).Returns(11); - mock.Setup(x => x.DoInt(2)).Returns(22); - - Assert.AreEqual(11, mock.Object.DoInt(1)); - Assert.AreEqual(22, mock.Object.DoInt(2)); - } - - [PexMethod(MaxBranches = int.MaxValue)] - [PexExpectedGoals] - public void MoqWithParameterValue(int y) - { - // ShouldExpectCallWithArgument - var mock = new Mock(); - mock.Setup(x => x.DoInt(1)).Returns(y); - - if (mock.Object.DoInt(1) == 4242) - throw new PexGoalException(); - } - - [PexMethod(MaxBranches = int.MaxValue)] - [PexExpectedGoals] - public void MoqWithParameterDelegate(int y) - { - // ShouldExpectCallWithArgument - var mock = new Mock(); - mock.Setup(x => x.DoInt(1)).Returns(() => y); - - if (mock.Object.DoInt(1) == 4242) - throw new PexGoalException(); - } - - [PexMethod(MaxBranches = int.MaxValue)] - [PexExpectedGoals] - [PexIgnore("TODO")] - public void MoqWithSymbolicArgumentParameterValue(int y, int z) - { - // ShouldExpectCallWithArgument - var mock = new Mock(); - mock.Setup(x => x.DoInt(y)).Returns(() => z); - - if (mock.Object.DoInt(2323) == 4242) - throw new PexGoalException(); - } - } +// ==++== +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ==--== + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Pex.Framework; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Microsoft.Pex.Framework.Suppression; +using Microsoft.Pex.Framework.Instrumentation; +using System.Diagnostics; +using Microsoft.Pex.Framework.Choices; +using Microsoft.Pex.Framework.Validation; + +[assembly: PexInstrumentAssembly("Moq")] +[assembly: PexInstrumentAssembly("DynamicProxyGenAssembly2")] + +namespace Mock.Tests +{ + [TestClass] + [PexClass(Suite = "checkin")] + public partial class ShouldExpectCallWithArgument + { + public interface IFoo + { + int DoInt(int i); + } + + [TestMethod] + [PexMethod(MaxBranches = int.MaxValue)] + public void Moq() + { + // ShouldExpectCallWithArgument + var mock = new Mock(); + mock.Setup(x => x.DoInt(1)).Returns(11); + mock.Setup(x => x.DoInt(2)).Returns(22); + + Assert.AreEqual(11, mock.Object.DoInt(1)); + Assert.AreEqual(22, mock.Object.DoInt(2)); + } + + [PexMethod(MaxBranches = int.MaxValue)] + [PexExpectedGoals] + public void MoqWithParameterValue(int y) + { + // ShouldExpectCallWithArgument + var mock = new Mock(); + mock.Setup(x => x.DoInt(1)).Returns(y); + + if (mock.Object.DoInt(1) == 4242) + throw new PexGoalException(); + } + + [PexMethod(MaxBranches = int.MaxValue)] + [PexExpectedGoals] + public void MoqWithParameterDelegate(int y) + { + // ShouldExpectCallWithArgument + var mock = new Mock(); + mock.Setup(x => x.DoInt(1)).Returns(() => y); + + if (mock.Object.DoInt(1) == 4242) + throw new PexGoalException(); + } + + [PexMethod(MaxBranches = int.MaxValue)] + [PexExpectedGoals] + [PexIgnore("TODO")] + public void MoqWithSymbolicArgumentParameterValue(int y, int z) + { + // ShouldExpectCallWithArgument + var mock = new Mock(); + mock.Setup(x => x.DoInt(y)).Returns(() => z); + + if (mock.Object.DoInt(2323) == 4242) + throw new PexGoalException(); + } + } } \ No newline at end of file diff --git a/UnitTests/Pex/ShouldExpectCallWithReferenceLazyEvaluate.cs b/UnitTests/Pex/ShouldExpectCallWithReferenceLazyEvaluate.cs index 45c4fdf17..5ed049a9d 100644 --- a/UnitTests/Pex/ShouldExpectCallWithReferenceLazyEvaluate.cs +++ b/UnitTests/Pex/ShouldExpectCallWithReferenceLazyEvaluate.cs @@ -1,39 +1,39 @@ -// ==++== -// -// Copyright (c) Microsoft Corporation. All rights reserved. -// -// ==--== - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.Pex.Framework; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Microsoft.Pex.Framework.Suppression; -using Microsoft.Pex.Framework.Choices; - -namespace Mock.Tests -{ - [TestClass] - [PexClass(Suite = "checkin")] - public partial class ShouldExpectCallWithReferenceLazyEvaluate - { - public interface IFoo - { - int Parse(string value); - } - - [PexMethod(MaxBranches = int.MaxValue)] - public void Moq() - { - int a = 25; - var mock = new Mock(); - mock.Setup(x => x.Parse(a.ToString())).Returns(() => a); - - a = 10; - Assert.AreEqual(10, mock.Object.Parse("10")); - } - } -} +// ==++== +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ==--== + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Pex.Framework; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Microsoft.Pex.Framework.Suppression; +using Microsoft.Pex.Framework.Choices; + +namespace Mock.Tests +{ + [TestClass] + [PexClass(Suite = "checkin")] + public partial class ShouldExpectCallWithReferenceLazyEvaluate + { + public interface IFoo + { + int Parse(string value); + } + + [PexMethod(MaxBranches = int.MaxValue)] + public void Moq() + { + int a = 25; + var mock = new Mock(); + mock.Setup(x => x.Parse(a.ToString())).Returns(() => a); + + a = 10; + Assert.AreEqual(10, mock.Object.Parse("10")); + } + } +} diff --git a/UnitTests/Pex/ShouldExpectReturnPropertyValue.cs b/UnitTests/Pex/ShouldExpectReturnPropertyValue.cs index 77b10bb53..e1a86a239 100644 --- a/UnitTests/Pex/ShouldExpectReturnPropertyValue.cs +++ b/UnitTests/Pex/ShouldExpectReturnPropertyValue.cs @@ -1,36 +1,36 @@ -// ==++== -// -// Copyright (c) Microsoft Corporation. All rights reserved. -// -// ==--== - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.Pex.Framework; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Microsoft.Pex.Framework.Suppression; -using Microsoft.Pex.Framework.Choices; - -namespace Mock.Tests -{ - [TestClass] - [PexClass(Suite = "checkin")] - public partial class ShouldExpectReturnPropertyValue - { - public interface IFoo - { - int ValueProperty { get; } - } - - [PexMethod(MaxBranches = int.MaxValue)] - public void Moq() - { - var mock = new Mock(); - mock.Setup(x => x.ValueProperty).Returns(25); - Assert.AreEqual(25, mock.Object.ValueProperty); - } - } -} +// ==++== +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ==--== + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Pex.Framework; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Microsoft.Pex.Framework.Suppression; +using Microsoft.Pex.Framework.Choices; + +namespace Mock.Tests +{ + [TestClass] + [PexClass(Suite = "checkin")] + public partial class ShouldExpectReturnPropertyValue + { + public interface IFoo + { + int ValueProperty { get; } + } + + [PexMethod(MaxBranches = int.MaxValue)] + public void Moq() + { + var mock = new Mock(); + mock.Setup(x => x.ValueProperty).Returns(25); + Assert.AreEqual(25, mock.Object.ValueProperty); + } + } +} diff --git a/UnitTests/Pex/ShouldMatchPredicateArgument.cs b/UnitTests/Pex/ShouldMatchPredicateArgument.cs index 899ae34d3..6ccfb118d 100644 --- a/UnitTests/Pex/ShouldMatchPredicateArgument.cs +++ b/UnitTests/Pex/ShouldMatchPredicateArgument.cs @@ -1,40 +1,40 @@ -// ==++== -// -// Copyright (c) Microsoft Corporation. All rights reserved. -// -// ==--== - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.Pex.Framework; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Microsoft.Pex.Framework.Suppression; - -namespace Mock.Tests -{ - [TestClass] - [PexClass(Suite = "checkin")] - public partial class ShouldMatchPredicateArgument - { - public interface IFoo - { - int Duplicate(int i); - } - - [TestMethod] - [PexMethod(MaxBranches = int.MaxValue)] - public void Moq() - { - var mock = new Mock(); - - mock.Setup(x => x.Duplicate(It.Is(value => value < 5 && value > 0))) - .Returns(() => 1); - - Assert.AreEqual(1, mock.Object.Duplicate(3)); - Assert.AreEqual(0, mock.Object.Duplicate(0)); - } - } -} +// ==++== +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// ==--== + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Pex.Framework; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Microsoft.Pex.Framework.Suppression; + +namespace Mock.Tests +{ + [TestClass] + [PexClass(Suite = "checkin")] + public partial class ShouldMatchPredicateArgument + { + public interface IFoo + { + int Duplicate(int i); + } + + [TestMethod] + [PexMethod(MaxBranches = int.MaxValue)] + public void Moq() + { + var mock = new Mock(); + + mock.Setup(x => x.Duplicate(It.Is(value => value < 5 && value > 0))) + .Returns(() => 1); + + Assert.AreEqual(1, mock.Object.Duplicate(3)); + Assert.AreEqual(0, mock.Object.Duplicate(0)); + } + } +} diff --git a/UnitTests/Properties/AssemblyInfo.cs b/UnitTests/Properties/AssemblyInfo.cs index 683ff6a8f..3d2c550eb 100644 --- a/UnitTests/Properties/AssemblyInfo.cs +++ b/UnitTests/Properties/AssemblyInfo.cs @@ -1,35 +1,35 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Moq.Tests")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Clarius Consulting SA")] -[assembly: AssemblyProduct("Moq.Tests")] -[assembly: AssemblyCopyright("Copyright © Clarius Consulting SA 2007")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("32d141f9-9a50-4ce1-8d27-abdb7f320dea")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Moq.Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Clarius Consulting SA")] +[assembly: AssemblyProduct("Moq.Tests")] +[assembly: AssemblyCopyright("Copyright © Clarius Consulting SA 2007")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("32d141f9-9a50-4ce1-8d27-abdb7f320dea")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/UnitTests/PropertiesFixture.cs b/UnitTests/PropertiesFixture.cs index 5a7cd16ef..2ca3b3db8 100644 --- a/UnitTests/PropertiesFixture.cs +++ b/UnitTests/PropertiesFixture.cs @@ -1,95 +1,95 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Xunit; -using System.Linq.Expressions; - -namespace Moq.Tests -{ - public class PropertiesFixture - { - public interface IFoo - { - IIndexedFoo Indexed { get; set; } - } - - public interface IIndexedFoo - { - string this[int key] { get; set; } - string this[int key1, string key2, bool key3, DateTime key4] { get; set; } - - IBar this[int key1, string key2, DateTime key4] { get; set; } - } - - public interface IBar - { - string Value { get; set; } - } - - - [Fact] - public void ShouldSupportMultipleIndexerGettersInFluentMock() - { - var foo = new Mock(); - - foo.SetupGet(x => x.Indexed[It.IsAny(), "foo", It.IsAny()].Value).Returns("bar"); - - var result = foo.Object.Indexed[1, "foo", DateTime.Now].Value; - - Assert.Equal("bar", result); - } - - [Fact] - public void ShouldSupportMultipleIndexerGetters() - { - var foo = new Mock(); - - foo.SetupGet(x => x[It.IsAny(), "foo", true, It.IsAny()]).Returns("bar"); - - var result = foo.Object[1, "foo", true, DateTime.Now]; - - Assert.Equal("bar", result); - } - - [Fact] - public void ShouldSetIndexer() - { - var foo = new Mock(MockBehavior.Strict); - - foo.SetupSet(f => f[0] = "foo"); - - foo.Object[0] = "foo"; - } - - [Fact] - public void ShouldSetIndexerWithValueMatcher() - { - var foo = new Mock(MockBehavior.Strict); - - foo.SetupSet(f => f[0] = It.IsAny()); - - foo.Object[0] = "foo"; - } - - [Fact(Skip = "Not supported for now")] - public void ShouldSetIndexerWithIndexMatcher() - { - var foo = new Mock(MockBehavior.Strict); - - foo.SetupSet(f => f[It.IsAny()] = "foo"); - - foo.Object[18] = "foo"; - } - - [Fact(Skip = "Not supported for now")] - public void ShouldSetIndexerWithBothMatcher() - { - var foo = new Mock(MockBehavior.Strict); - - foo.SetupSet(f => f[It.IsAny()] = It.IsAny()); - - foo.Object[18] = "foo"; - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Xunit; +using System.Linq.Expressions; + +namespace Moq.Tests +{ + public class PropertiesFixture + { + public interface IFoo + { + IIndexedFoo Indexed { get; set; } + } + + public interface IIndexedFoo + { + string this[int key] { get; set; } + string this[int key1, string key2, bool key3, DateTime key4] { get; set; } + + IBar this[int key1, string key2, DateTime key4] { get; set; } + } + + public interface IBar + { + string Value { get; set; } + } + + + [Fact] + public void ShouldSupportMultipleIndexerGettersInFluentMock() + { + var foo = new Mock(); + + foo.SetupGet(x => x.Indexed[It.IsAny(), "foo", It.IsAny()].Value).Returns("bar"); + + var result = foo.Object.Indexed[1, "foo", DateTime.Now].Value; + + Assert.Equal("bar", result); + } + + [Fact] + public void ShouldSupportMultipleIndexerGetters() + { + var foo = new Mock(); + + foo.SetupGet(x => x[It.IsAny(), "foo", true, It.IsAny()]).Returns("bar"); + + var result = foo.Object[1, "foo", true, DateTime.Now]; + + Assert.Equal("bar", result); + } + + [Fact] + public void ShouldSetIndexer() + { + var foo = new Mock(MockBehavior.Strict); + + foo.SetupSet(f => f[0] = "foo"); + + foo.Object[0] = "foo"; + } + + [Fact] + public void ShouldSetIndexerWithValueMatcher() + { + var foo = new Mock(MockBehavior.Strict); + + foo.SetupSet(f => f[0] = It.IsAny()); + + foo.Object[0] = "foo"; + } + + [Fact(Skip = "Not supported for now")] + public void ShouldSetIndexerWithIndexMatcher() + { + var foo = new Mock(MockBehavior.Strict); + + foo.SetupSet(f => f[It.IsAny()] = "foo"); + + foo.Object[18] = "foo"; + } + + [Fact(Skip = "Not supported for now")] + public void ShouldSetIndexerWithBothMatcher() + { + var foo = new Mock(MockBehavior.Strict); + + foo.SetupSet(f => f[It.IsAny()] = It.IsAny()); + + foo.Object[18] = "foo"; + } + } +} diff --git a/UnitTests/ProtectedMockFixture.cs b/UnitTests/ProtectedMockFixture.cs index d1ab39be4..81001e5cb 100644 --- a/UnitTests/ProtectedMockFixture.cs +++ b/UnitTests/ProtectedMockFixture.cs @@ -1,833 +1,833 @@ -using System; -using Moq.Protected; -using Xunit; -using System.Linq.Expressions; - -namespace Moq.Tests -{ - public partial class ProtectedMockFixture - { - [Fact] - public void ThrowsIfNullMock() - { - Assert.Throws(() => ProtectedExtension.Protected((Mock)null)); - } - - [Fact] - public void ThrowsIfSetupNullVoidMethodName() - { - Assert.Throws(() => new Mock().Protected().Setup(null)); - } - - [Fact] - public void ThrowsIfSetupEmptyVoidMethodName() - { - Assert.Throws(() => new Mock().Protected().Setup(string.Empty)); - } - - [Fact] - public void ThrowsIfSetupResultNullMethodName() - { - Assert.Throws(() => new Mock().Protected().Setup(null)); - } - - [Fact] - public void ThrowsIfSetupResultEmptyMethodName() - { - Assert.Throws(() => new Mock().Protected().Setup(string.Empty)); - } - - [Fact] - public void ThrowsIfSetupVoidMethodNotFound() - { - Assert.Throws(() => new Mock().Protected().Setup("Foo")); - } - - [Fact] - public void ThrowsIfSetupResultMethodNotFound() - { - Assert.Throws(() => new Mock().Protected().Setup("Foo")); - } - - [Fact] - public void ThrowsIfSetupPublicVoidMethod() - { - Assert.Throws(() => new Mock().Protected().Setup("Public")); - } - - [Fact] - public void ThrowsIfSetupPublicResultMethod() - { - Assert.Throws(() => new Mock().Protected().Setup("PublicInt")); - } - - [Fact] - public void ThrowsIfSetupNonVirtualVoidMethod() - { - Assert.Throws(() => new Mock().Protected().Setup("NonVirtual")); - } - - [Fact] - public void ThrowsIfSetupNonVirtualResultMethod() - { - Assert.Throws(() => new Mock().Protected().Setup("NonVirtualInt")); - } - - [Fact] - public void SetupAllowsProtectedInternalVoidMethod() - { - var mock = new Mock(); - mock.Protected().Setup("ProtectedInternal"); - mock.Object.ProtectedInternal(); - - mock.VerifyAll(); - } - - [Fact] - public void SetupAllowsProtectedInternalResultMethod() - { - var mock = new Mock(); - mock.Protected() - .Setup("ProtectedInternalInt") - .Returns(5); - - Assert.Equal(5, mock.Object.ProtectedInternalInt()); - } - - [Fact] - public void SetupAllowsProtectedVoidMethod() - { - var mock = new Mock(); - mock.Protected().Setup("Protected"); - mock.Object.DoProtected(); - - mock.VerifyAll(); - } - - [Fact] - public void SetupAllowsProtectedResultMethod() - { - var mock = new Mock(); - mock.Protected() - .Setup("ProtectedInt") - .Returns(5); - - Assert.Equal(5, mock.Object.DoProtectedInt()); - } - - [Fact] - public void ThrowsIfSetupVoidMethodIsProperty() - { - Assert.Throws(() => new Mock().Protected().Setup("ProtectedValue")); - } - - [Fact] - public void SetupResultAllowsProperty() - { - var mock = new Mock(); - mock.Protected() - .Setup("ProtectedValue") - .Returns("foo"); - - Assert.Equal("foo", mock.Object.GetProtectedValue()); - } - - [Fact] - public void ThrowsIfSetupGetNullPropertyName() - { - Assert.Throws(() => new Mock().Protected().SetupGet(null)); - } - - [Fact] - public void ThrowsIfSetupGetEmptyPropertyName() - { - Assert.Throws(() => new Mock().Protected().SetupGet(string.Empty)); - } - - [Fact] - public void ThrowsIfSetupGetPropertyNotFound() - { - Assert.Throws(() => new Mock().Protected().SetupGet("Foo")); - } - - [Fact] - public void ThrowsIfSetupGetPropertyWithoutPropertyGet() - { - Assert.Throws(() => new Mock().Protected().SetupGet("OnlySet")); - } - - [Fact] - public void ThrowsIfSetupGetPublicPropertyGet() - { - Assert.Throws(() => new Mock().Protected().SetupGet("PublicValue")); - } - - [Fact] - public void ThrowsIfSetupGetNonVirtualProperty() - { - Assert.Throws(() => new Mock().Protected().SetupGet("NonVirtualValue")); - } - - [Fact] - public void SetupGetAllowsProtectedInternalPropertyGet() - { - var mock = new Mock(); - mock.Protected() - .SetupGet("ProtectedInternalValue") - .Returns("foo"); - - Assert.Equal("foo", mock.Object.ProtectedInternalValue); - } - - [Fact] - public void SetupGetAllowsProtectedPropertyGet() - { - var mock = new Mock(); - mock.Protected() - .SetupGet("ProtectedValue") - .Returns("foo"); - - Assert.Equal("foo", mock.Object.GetProtectedValue()); - } - - [Fact] - public void ThrowsIfSetupSetNullPropertyName() - { - Assert.Throws( - () => new Mock().Protected().SetupSet(null, ItExpr.IsAny())); - } - - [Fact] - public void ThrowsIfSetupSetEmptyPropertyName() - { - Assert.Throws( - () => new Mock().Protected().SetupSet(string.Empty, ItExpr.IsAny())); - } - - [Fact] - public void ThrowsIfSetupSetPropertyNotFound() - { - Assert.Throws( - () => new Mock().Protected().SetupSet("Foo", ItExpr.IsAny())); - } - - [Fact] - public void ThrowsIfSetupSetPropertyWithoutPropertySet() - { - Assert.Throws( - () => new Mock().Protected().SetupSet("OnlyGet", ItExpr.IsAny())); - } - - [Fact] - public void ThrowsIfSetupSetPublicPropertySet() - { - Assert.Throws( - () => new Mock().Protected().SetupSet("PublicValue", ItExpr.IsAny())); - } - - [Fact] - public void ThrowsIfSetupSetNonVirtualProperty() - { - Assert.Throws( - () => new Mock().Protected().SetupSet("NonVirtualValue", ItExpr.IsAny())); - } - - [Fact] - public void SetupSetAllowsProtectedInternalPropertySet() - { - var mock = new Mock(); - var value = string.Empty; - mock.Protected() - .SetupSet("ProtectedInternalValue", ItExpr.IsAny()) - .Callback(v => value = v); - - mock.Object.ProtectedInternalValue = "foo"; - - Assert.Equal("foo", value); - mock.VerifyAll(); - } - - [Fact] - public void SetupSetAllowsProtectedPropertySet() - { - var mock = new Mock(); - var value = string.Empty; - mock.Protected() - .SetupSet("ProtectedValue", ItExpr.IsAny()) - .Callback(v => value = v); - - mock.Object.SetProtectedValue("foo"); - - Assert.Equal("foo", value); - mock.VerifyAll(); - } - - [Fact] - public void ThrowsIfNullArgs() - { - Assert.Throws(() => new Mock().Protected() - .Setup("StringArg", null) - .Returns("null")); - } - - [Fact] - public void AllowMatchersForArgs() - { - var mock = new Mock(); - - mock.Protected() - .Setup("StringArg", ItExpr.IsNull()) - .Returns("null"); - - Assert.Equal("null", mock.Object.DoStringArg(null)); - - mock.Protected() - .Setup("StringArg", ItExpr.Is(s => s == "bar")) - .Returns("baz"); - - Assert.Equal("baz", mock.Object.DoStringArg("bar")); - - mock = new Mock(); - - mock.Protected() - .Setup("StringArg", ItExpr.Is(s => s.Length >= 2)) - .Returns("long"); - mock.Protected() - .Setup("StringArg", ItExpr.Is(s => s.Length < 2)) - .Returns("short"); - - Assert.Equal("short", mock.Object.DoStringArg("f")); - Assert.Equal("long", mock.Object.DoStringArg("foo")); - - mock = new Mock(); - mock.CallBase = true; - - mock.Protected() - .Setup("TwoArgs", ItExpr.IsAny(), 5) - .Returns("done"); - - Assert.Equal("done", mock.Object.DoTwoArgs("foobar", 5)); - Assert.Equal("echo", mock.Object.DoTwoArgs("echo", 15)); - - mock = new Mock(); - mock.CallBase = true; - - mock.Protected() - .Setup("TwoArgs", ItExpr.IsAny(), ItExpr.IsInRange(1, 3, Range.Inclusive)) - .Returns("inrange"); - - Assert.Equal("inrange", mock.Object.DoTwoArgs("foobar", 2)); - Assert.Equal("echo", mock.Object.DoTwoArgs("echo", 4)); - } - - [Fact] - public void ResolveOverloads() - { - // NOTE: There are two overloads named "Do" and "DoReturn" - var mock = new Mock(); - mock.Protected().Setup("Do", 1, 2).Verifiable(); - mock.Protected().Setup("DoReturn", "1", "2").Returns("3").Verifiable(); - - mock.Object.ExecuteDo(1, 2); - Assert.Equal("3", mock.Object.ExecuteDoReturn("1", "2")); - - mock.Verify(); - } - - [Fact] - public void ThrowsIfSetReturnsForVoidMethod() - { - Assert.Throws( - () => new Mock().Protected().Setup("Do", "1", "2").Returns("3")); - } - - [Fact] - public void SetupResultAllowsProtectedMethodInBaseClass() - { - var mock = new Mock(); - mock.Protected() - .Setup("ProtectedInt") - .Returns(5); - - Assert.Equal(5, mock.Object.DoProtectedInt()); - } - - [Fact] - public void ThrowsIfVerifyNullVoidMethodName() - { - Assert.Throws(() => new Mock().Protected().Verify(null, Times.Once())); - } - - [Fact] - public void ThrowsIfVerifyEmptyVoidMethodName() - { - Assert.Throws(() => new Mock().Protected().Verify(string.Empty, Times.Once())); - } - - [Fact] - public void ThrowsIfVerifyNullResultMethodName() - { - Assert.Throws(() => new Mock().Protected().Verify(null, Times.Once())); - } - - [Fact] - public void ThrowsIfVerifyEmptyResultMethodName() - { - Assert.Throws(() => new Mock().Protected().Verify(string.Empty, Times.Once())); - } - - [Fact] - public void ThrowsIfVerifyVoidMethodNotFound() - { - Assert.Throws(() => new Mock().Protected().Verify("Foo", Times.Once())); - } - - [Fact] - public void ThrowsIfVerifyResultMethodNotFound() - { - Assert.Throws(() => new Mock().Protected().Verify("Foo", Times.Once())); - } - - [Fact] - public void ThrowsIfVerifyPublicVoidMethod() - { - Assert.Throws(() => new Mock().Protected().Verify("Public", Times.Once())); - } - - [Fact] - public void ThrowsIfVerifyPublicResultMethod() - { - Assert.Throws( - () => new Mock().Protected().Verify("PublicInt", Times.Once())); - } - - [Fact] - public void ThrowsIfVerifyNonVirtualVoidMethod() - { - Assert.Throws(() => new Mock().Protected().Verify("NonVirtual", Times.Once())); - } - - [Fact] - public void ThrowsIfVerifyNonVirtualResultMethod() - { - Assert.Throws( - () => new Mock().Protected().Verify("NonVirtualInt", Times.Once())); - } - - [Fact] - public void VerifyAllowsProtectedInternalVoidMethod() - { - var mock = new Mock(); - mock.Object.ProtectedInternal(); - - mock.Protected().Verify("ProtectedInternal", Times.Once()); - } - - [Fact] - public void VerifyAllowsProtectedInternalResultMethod() - { - var mock = new Mock(); - mock.Object.ProtectedInternalInt(); - - mock.Protected().Verify("ProtectedInternalInt", Times.Once()); - } - - [Fact] - public void VerifyAllowsProtectedVoidMethod() - { - var mock = new Mock(); - mock.Object.DoProtected(); - - mock.Protected().Verify("Protected", Times.Once()); - } - - [Fact] - public void VerifyAllowsProtectedResultMethod() - { - var mock = new Mock(); - mock.Object.DoProtectedInt(); - - mock.Protected().Verify("ProtectedInt", Times.Once()); - } - - [Fact] - public void ThrowsIfVerifyVoidMethodIsProperty() - { - Assert.Throws( - () => new Mock().Protected().Verify("ProtectedValue", Times.Once())); - } - - [Fact] - public void VerifyResultAllowsProperty() - { - var mock = new Mock(); - mock.Object.GetProtectedValue(); - - mock.Protected().Verify("ProtectedValue", Times.Once()); - } - - [Fact] - public void ThrowsIfVerifyVoidMethodTimesNotReached() - { - var mock = new Mock(); - mock.Object.DoProtected(); - - Assert.Throws(() => mock.Protected().Verify("Protected", Times.Exactly(2))); - } - - [Fact] - public void ThrowsIfVerifyResultMethodTimesNotReached() - { - var mock = new Mock(); - mock.Object.DoProtectedInt(); - - Assert.Throws(() => mock.Protected().Verify("ProtectedInt", Times.Exactly(2))); - } - - [Fact] - public void DoesNotThrowIfVerifyVoidMethodTimesReached() - { - var mock = new Mock(); - mock.Object.DoProtected(); - mock.Object.DoProtected(); - - mock.Protected().Verify("Protected", Times.Exactly(2)); - } - - [Fact] - public void DoesNotThrowIfVerifyReturnMethodTimesReached() - { - var mock = new Mock(); - mock.Object.DoProtectedInt(); - mock.Object.DoProtectedInt(); - - mock.Protected().Verify("ProtectedInt", Times.Exactly(2)); - } - - [Fact] - public void ThrowsIfVerifyPropertyTimesNotReached() - { - var mock = new Mock(); - mock.Object.GetProtectedValue(); - - Assert.Throws(() => mock.Protected().Verify("ProtectedValue", Times.Exactly(2))); - } - - [Fact] - public void DoesNotThrowIfVerifyPropertyTimesReached() - { - var mock = new Mock(); - mock.Object.GetProtectedValue(); - mock.Object.GetProtectedValue(); - - mock.Protected().Verify("ProtectedValue", Times.Exactly(2)); - } - - [Fact] - public void ThrowsIfVerifyGetNullPropertyName() - { - Assert.Throws(() => new Mock().Protected().VerifyGet(null, Times.Once())); - } - - [Fact] - public void ThrowsIfVerifyGetEmptyPropertyName() - { - Assert.Throws(() => new Mock().Protected().VerifyGet(string.Empty, Times.Once())); - } - - [Fact] - public void ThrowsIfVerifyGetPropertyNotFound() - { - Assert.Throws(() => new Mock().Protected().VerifyGet("Foo", Times.Once())); - } - - [Fact] - public void ThrowsIfVerifyGetPropertyWithoutPropertyGet() - { - Assert.Throws(() => new Mock().Protected().VerifyGet("OnlySet", Times.Once())); - } - - [Fact] - public void ThrowsIfVerifyGetIsPublicPropertyGet() - { - Assert.Throws( - () => new Mock().Protected().VerifyGet("PublicValue", Times.Once())); - } - - [Fact] - public void VerifyGetAllowsProtectedInternalPropertyGet() - { - var mock = new Mock(); - var value = mock.Object.ProtectedInternalValue; - - mock.Protected().VerifyGet("ProtectedInternalValue", Times.Once()); - } - - [Fact] - public void VerifyGetAllowsProtectedPropertyGet() - { - var mock = new Mock(); - mock.Object.GetProtectedValue(); - - mock.Protected().VerifyGet("ProtectedValue", Times.Once()); - } - - [Fact] - public void ThrowsIfVerifyGetNonVirtualPropertyGet() - { - Assert.Throws( - () => new Mock().Protected().VerifyGet("NonVirtualValue", Times.Once())); - } - - [Fact] - public void ThrowsIfVerifyGetTimesNotReached() - { - var mock = new Mock(); - mock.Object.GetProtectedValue(); - - Assert.Throws(() => mock.Protected().VerifyGet("ProtectedValue", Times.Exactly(2))); - } - - [Fact] - public void DoesNotThrowIfVerifyGetPropertyTimesReached() - { - var mock = new Mock(); - mock.Object.GetProtectedValue(); - mock.Object.GetProtectedValue(); - - mock.Protected().VerifyGet("ProtectedValue", Times.Exactly(2)); - } - } - - public partial class ProtectedMockFixture - { - - [Fact] - public void ThrowsIfVerifySetNullPropertyName() - { - Assert.Throws( - () => new Mock().Protected().VerifySet(null, Times.Once(), ItExpr.IsAny())); - } - - [Fact] - public void ThrowsIfVerifySetEmptyPropertyName() - { - Assert.Throws( - () => new Mock().Protected().VerifySet(string.Empty, Times.Once(), ItExpr.IsAny())); - } - - [Fact] - public void ThrowsIfVerifySetPropertyNotFound() - { - Assert.Throws( - () => new Mock().Protected().VerifySet("Foo", Times.Once(), ItExpr.IsAny())); - } - - [Fact] - public void ThrowsIfVerifySetPropertyWithoutPropertySet() - { - Assert.Throws( - () => new Mock().Protected().VerifySet("OnlyGet", Times.Once(), ItExpr.IsAny())); - } - - [Fact] - public void ThrowsIfVerifySetPublicPropertySet() - { - Assert.Throws( - () => new Mock().Protected().VerifySet("PublicValue", Times.Once(), ItExpr.IsAny())); - } - - [Fact] - public void ThrowsIfVerifySetNonVirtualPropertySet() - { - Assert.Throws( - () => new Mock().Protected().VerifySet("NonVirtualValue", Times.Once(), ItExpr.IsAny())); - } - - [Fact] - public void VerifySetAllowsProtectedInternalPropertySet() - { - var mock = new Mock(); - mock.Object.ProtectedInternalValue = "foo"; - - mock.Protected().VerifySet("ProtectedInternalValue", Times.Once(), "bar"); - } - - [Fact] - public void VerifySetAllowsProtectedPropertySet() - { - var mock = new Mock(); - mock.Object.SetProtectedValue("foo"); - - mock.Protected().VerifySet("ProtectedValue", Times.Once(), ItExpr.IsAny()); - } - - [Fact] - public void ThrowsIfVerifySetTimesNotReached() - { - var mock = new Mock(); - mock.Object.SetProtectedValue("Foo"); - - Assert.Throws( - () => mock.Protected().VerifySet("ProtectedValue", Times.Exactly(2), ItExpr.IsAny())); - } - - [Fact] - public void DoesNotThrowIfVerifySetPropertyTimesReached() - { - var mock = new Mock(); - mock.Object.SetProtectedValue("foo"); - mock.Object.SetProtectedValue("foo"); - - mock.Protected().VerifySet("ProtectedValue", Times.Exactly(2), ItExpr.IsAny()); - } - - public class MethodOverloads - { - public void ExecuteDo(int a, int b) - { - this.Do(a, b); - } - - public void ExecuteDo(string a, string b) - { - this.Do(a, b); - } - - public int ExecuteDoReturn(int a, int b) - { - return this.DoReturn(a, b); - } - - protected virtual void Do(int a, int b) - { - } - - protected virtual void Do(string a, string b) - { - } - - protected virtual int DoReturn(int a, int b) - { - return a + b; - } - - public string ExecuteDoReturn(string a, string b) - { - return DoReturn(a, b); - } - - protected virtual string DoReturn(string a, string b) - { - return a + b; - } - } - - public class FooBase - { - public virtual string PublicValue { get; set; } - - protected internal virtual string ProtectedInternalValue { get; set; } - - protected string NonVirtualValue { get; set; } - - protected virtual int OnlyGet - { - get { return 0; } - } - - protected virtual int OnlySet - { - set { } - } - - protected virtual string ProtectedValue { get; set; } - - protected virtual int this[int index] - { - get { return 0; } - set { } - } - - public void DoProtected() - { - this.Protected(); - } - - public int DoProtectedInt() - { - return this.ProtectedInt(); - } - - public string DoStringArg(string arg) - { - return this.StringArg(arg); - } - - public string DoTwoArgs(string arg, int arg1) - { - return this.TwoArgs(arg, arg1); - } - - public string GetProtectedValue() - { - return this.ProtectedValue; - } - - public virtual void Public() - { - } - - public virtual int PublicInt() - { - return 10; - } - - public void SetProtectedValue(string value) - { - this.ProtectedValue = value; - } - - internal protected virtual void ProtectedInternal() - { - } - - internal protected virtual int ProtectedInternalInt() - { - return 0; - } - - protected virtual void Protected() - { - } - - protected virtual int ProtectedInt() - { - return 2; - } - - protected void NonVirtual() - { - } - - protected int NonVirtualInt() - { - return 2; - } - - protected virtual string StringArg(string arg) - { - return arg; - } - - protected virtual string TwoArgs(string arg, int arg1) - { - return arg; - } - } - - public class FooDerived : FooBase - { - } - } +using System; +using Moq.Protected; +using Xunit; +using System.Linq.Expressions; + +namespace Moq.Tests +{ + public partial class ProtectedMockFixture + { + [Fact] + public void ThrowsIfNullMock() + { + Assert.Throws(() => ProtectedExtension.Protected((Mock)null)); + } + + [Fact] + public void ThrowsIfSetupNullVoidMethodName() + { + Assert.Throws(() => new Mock().Protected().Setup(null)); + } + + [Fact] + public void ThrowsIfSetupEmptyVoidMethodName() + { + Assert.Throws(() => new Mock().Protected().Setup(string.Empty)); + } + + [Fact] + public void ThrowsIfSetupResultNullMethodName() + { + Assert.Throws(() => new Mock().Protected().Setup(null)); + } + + [Fact] + public void ThrowsIfSetupResultEmptyMethodName() + { + Assert.Throws(() => new Mock().Protected().Setup(string.Empty)); + } + + [Fact] + public void ThrowsIfSetupVoidMethodNotFound() + { + Assert.Throws(() => new Mock().Protected().Setup("Foo")); + } + + [Fact] + public void ThrowsIfSetupResultMethodNotFound() + { + Assert.Throws(() => new Mock().Protected().Setup("Foo")); + } + + [Fact] + public void ThrowsIfSetupPublicVoidMethod() + { + Assert.Throws(() => new Mock().Protected().Setup("Public")); + } + + [Fact] + public void ThrowsIfSetupPublicResultMethod() + { + Assert.Throws(() => new Mock().Protected().Setup("PublicInt")); + } + + [Fact] + public void ThrowsIfSetupNonVirtualVoidMethod() + { + Assert.Throws(() => new Mock().Protected().Setup("NonVirtual")); + } + + [Fact] + public void ThrowsIfSetupNonVirtualResultMethod() + { + Assert.Throws(() => new Mock().Protected().Setup("NonVirtualInt")); + } + + [Fact] + public void SetupAllowsProtectedInternalVoidMethod() + { + var mock = new Mock(); + mock.Protected().Setup("ProtectedInternal"); + mock.Object.ProtectedInternal(); + + mock.VerifyAll(); + } + + [Fact] + public void SetupAllowsProtectedInternalResultMethod() + { + var mock = new Mock(); + mock.Protected() + .Setup("ProtectedInternalInt") + .Returns(5); + + Assert.Equal(5, mock.Object.ProtectedInternalInt()); + } + + [Fact] + public void SetupAllowsProtectedVoidMethod() + { + var mock = new Mock(); + mock.Protected().Setup("Protected"); + mock.Object.DoProtected(); + + mock.VerifyAll(); + } + + [Fact] + public void SetupAllowsProtectedResultMethod() + { + var mock = new Mock(); + mock.Protected() + .Setup("ProtectedInt") + .Returns(5); + + Assert.Equal(5, mock.Object.DoProtectedInt()); + } + + [Fact] + public void ThrowsIfSetupVoidMethodIsProperty() + { + Assert.Throws(() => new Mock().Protected().Setup("ProtectedValue")); + } + + [Fact] + public void SetupResultAllowsProperty() + { + var mock = new Mock(); + mock.Protected() + .Setup("ProtectedValue") + .Returns("foo"); + + Assert.Equal("foo", mock.Object.GetProtectedValue()); + } + + [Fact] + public void ThrowsIfSetupGetNullPropertyName() + { + Assert.Throws(() => new Mock().Protected().SetupGet(null)); + } + + [Fact] + public void ThrowsIfSetupGetEmptyPropertyName() + { + Assert.Throws(() => new Mock().Protected().SetupGet(string.Empty)); + } + + [Fact] + public void ThrowsIfSetupGetPropertyNotFound() + { + Assert.Throws(() => new Mock().Protected().SetupGet("Foo")); + } + + [Fact] + public void ThrowsIfSetupGetPropertyWithoutPropertyGet() + { + Assert.Throws(() => new Mock().Protected().SetupGet("OnlySet")); + } + + [Fact] + public void ThrowsIfSetupGetPublicPropertyGet() + { + Assert.Throws(() => new Mock().Protected().SetupGet("PublicValue")); + } + + [Fact] + public void ThrowsIfSetupGetNonVirtualProperty() + { + Assert.Throws(() => new Mock().Protected().SetupGet("NonVirtualValue")); + } + + [Fact] + public void SetupGetAllowsProtectedInternalPropertyGet() + { + var mock = new Mock(); + mock.Protected() + .SetupGet("ProtectedInternalValue") + .Returns("foo"); + + Assert.Equal("foo", mock.Object.ProtectedInternalValue); + } + + [Fact] + public void SetupGetAllowsProtectedPropertyGet() + { + var mock = new Mock(); + mock.Protected() + .SetupGet("ProtectedValue") + .Returns("foo"); + + Assert.Equal("foo", mock.Object.GetProtectedValue()); + } + + [Fact] + public void ThrowsIfSetupSetNullPropertyName() + { + Assert.Throws( + () => new Mock().Protected().SetupSet(null, ItExpr.IsAny())); + } + + [Fact] + public void ThrowsIfSetupSetEmptyPropertyName() + { + Assert.Throws( + () => new Mock().Protected().SetupSet(string.Empty, ItExpr.IsAny())); + } + + [Fact] + public void ThrowsIfSetupSetPropertyNotFound() + { + Assert.Throws( + () => new Mock().Protected().SetupSet("Foo", ItExpr.IsAny())); + } + + [Fact] + public void ThrowsIfSetupSetPropertyWithoutPropertySet() + { + Assert.Throws( + () => new Mock().Protected().SetupSet("OnlyGet", ItExpr.IsAny())); + } + + [Fact] + public void ThrowsIfSetupSetPublicPropertySet() + { + Assert.Throws( + () => new Mock().Protected().SetupSet("PublicValue", ItExpr.IsAny())); + } + + [Fact] + public void ThrowsIfSetupSetNonVirtualProperty() + { + Assert.Throws( + () => new Mock().Protected().SetupSet("NonVirtualValue", ItExpr.IsAny())); + } + + [Fact] + public void SetupSetAllowsProtectedInternalPropertySet() + { + var mock = new Mock(); + var value = string.Empty; + mock.Protected() + .SetupSet("ProtectedInternalValue", ItExpr.IsAny()) + .Callback(v => value = v); + + mock.Object.ProtectedInternalValue = "foo"; + + Assert.Equal("foo", value); + mock.VerifyAll(); + } + + [Fact] + public void SetupSetAllowsProtectedPropertySet() + { + var mock = new Mock(); + var value = string.Empty; + mock.Protected() + .SetupSet("ProtectedValue", ItExpr.IsAny()) + .Callback(v => value = v); + + mock.Object.SetProtectedValue("foo"); + + Assert.Equal("foo", value); + mock.VerifyAll(); + } + + [Fact] + public void ThrowsIfNullArgs() + { + Assert.Throws(() => new Mock().Protected() + .Setup("StringArg", null) + .Returns("null")); + } + + [Fact] + public void AllowMatchersForArgs() + { + var mock = new Mock(); + + mock.Protected() + .Setup("StringArg", ItExpr.IsNull()) + .Returns("null"); + + Assert.Equal("null", mock.Object.DoStringArg(null)); + + mock.Protected() + .Setup("StringArg", ItExpr.Is(s => s == "bar")) + .Returns("baz"); + + Assert.Equal("baz", mock.Object.DoStringArg("bar")); + + mock = new Mock(); + + mock.Protected() + .Setup("StringArg", ItExpr.Is(s => s.Length >= 2)) + .Returns("long"); + mock.Protected() + .Setup("StringArg", ItExpr.Is(s => s.Length < 2)) + .Returns("short"); + + Assert.Equal("short", mock.Object.DoStringArg("f")); + Assert.Equal("long", mock.Object.DoStringArg("foo")); + + mock = new Mock(); + mock.CallBase = true; + + mock.Protected() + .Setup("TwoArgs", ItExpr.IsAny(), 5) + .Returns("done"); + + Assert.Equal("done", mock.Object.DoTwoArgs("foobar", 5)); + Assert.Equal("echo", mock.Object.DoTwoArgs("echo", 15)); + + mock = new Mock(); + mock.CallBase = true; + + mock.Protected() + .Setup("TwoArgs", ItExpr.IsAny(), ItExpr.IsInRange(1, 3, Range.Inclusive)) + .Returns("inrange"); + + Assert.Equal("inrange", mock.Object.DoTwoArgs("foobar", 2)); + Assert.Equal("echo", mock.Object.DoTwoArgs("echo", 4)); + } + + [Fact] + public void ResolveOverloads() + { + // NOTE: There are two overloads named "Do" and "DoReturn" + var mock = new Mock(); + mock.Protected().Setup("Do", 1, 2).Verifiable(); + mock.Protected().Setup("DoReturn", "1", "2").Returns("3").Verifiable(); + + mock.Object.ExecuteDo(1, 2); + Assert.Equal("3", mock.Object.ExecuteDoReturn("1", "2")); + + mock.Verify(); + } + + [Fact] + public void ThrowsIfSetReturnsForVoidMethod() + { + Assert.Throws( + () => new Mock().Protected().Setup("Do", "1", "2").Returns("3")); + } + + [Fact] + public void SetupResultAllowsProtectedMethodInBaseClass() + { + var mock = new Mock(); + mock.Protected() + .Setup("ProtectedInt") + .Returns(5); + + Assert.Equal(5, mock.Object.DoProtectedInt()); + } + + [Fact] + public void ThrowsIfVerifyNullVoidMethodName() + { + Assert.Throws(() => new Mock().Protected().Verify(null, Times.Once())); + } + + [Fact] + public void ThrowsIfVerifyEmptyVoidMethodName() + { + Assert.Throws(() => new Mock().Protected().Verify(string.Empty, Times.Once())); + } + + [Fact] + public void ThrowsIfVerifyNullResultMethodName() + { + Assert.Throws(() => new Mock().Protected().Verify(null, Times.Once())); + } + + [Fact] + public void ThrowsIfVerifyEmptyResultMethodName() + { + Assert.Throws(() => new Mock().Protected().Verify(string.Empty, Times.Once())); + } + + [Fact] + public void ThrowsIfVerifyVoidMethodNotFound() + { + Assert.Throws(() => new Mock().Protected().Verify("Foo", Times.Once())); + } + + [Fact] + public void ThrowsIfVerifyResultMethodNotFound() + { + Assert.Throws(() => new Mock().Protected().Verify("Foo", Times.Once())); + } + + [Fact] + public void ThrowsIfVerifyPublicVoidMethod() + { + Assert.Throws(() => new Mock().Protected().Verify("Public", Times.Once())); + } + + [Fact] + public void ThrowsIfVerifyPublicResultMethod() + { + Assert.Throws( + () => new Mock().Protected().Verify("PublicInt", Times.Once())); + } + + [Fact] + public void ThrowsIfVerifyNonVirtualVoidMethod() + { + Assert.Throws(() => new Mock().Protected().Verify("NonVirtual", Times.Once())); + } + + [Fact] + public void ThrowsIfVerifyNonVirtualResultMethod() + { + Assert.Throws( + () => new Mock().Protected().Verify("NonVirtualInt", Times.Once())); + } + + [Fact] + public void VerifyAllowsProtectedInternalVoidMethod() + { + var mock = new Mock(); + mock.Object.ProtectedInternal(); + + mock.Protected().Verify("ProtectedInternal", Times.Once()); + } + + [Fact] + public void VerifyAllowsProtectedInternalResultMethod() + { + var mock = new Mock(); + mock.Object.ProtectedInternalInt(); + + mock.Protected().Verify("ProtectedInternalInt", Times.Once()); + } + + [Fact] + public void VerifyAllowsProtectedVoidMethod() + { + var mock = new Mock(); + mock.Object.DoProtected(); + + mock.Protected().Verify("Protected", Times.Once()); + } + + [Fact] + public void VerifyAllowsProtectedResultMethod() + { + var mock = new Mock(); + mock.Object.DoProtectedInt(); + + mock.Protected().Verify("ProtectedInt", Times.Once()); + } + + [Fact] + public void ThrowsIfVerifyVoidMethodIsProperty() + { + Assert.Throws( + () => new Mock().Protected().Verify("ProtectedValue", Times.Once())); + } + + [Fact] + public void VerifyResultAllowsProperty() + { + var mock = new Mock(); + mock.Object.GetProtectedValue(); + + mock.Protected().Verify("ProtectedValue", Times.Once()); + } + + [Fact] + public void ThrowsIfVerifyVoidMethodTimesNotReached() + { + var mock = new Mock(); + mock.Object.DoProtected(); + + Assert.Throws(() => mock.Protected().Verify("Protected", Times.Exactly(2))); + } + + [Fact] + public void ThrowsIfVerifyResultMethodTimesNotReached() + { + var mock = new Mock(); + mock.Object.DoProtectedInt(); + + Assert.Throws(() => mock.Protected().Verify("ProtectedInt", Times.Exactly(2))); + } + + [Fact] + public void DoesNotThrowIfVerifyVoidMethodTimesReached() + { + var mock = new Mock(); + mock.Object.DoProtected(); + mock.Object.DoProtected(); + + mock.Protected().Verify("Protected", Times.Exactly(2)); + } + + [Fact] + public void DoesNotThrowIfVerifyReturnMethodTimesReached() + { + var mock = new Mock(); + mock.Object.DoProtectedInt(); + mock.Object.DoProtectedInt(); + + mock.Protected().Verify("ProtectedInt", Times.Exactly(2)); + } + + [Fact] + public void ThrowsIfVerifyPropertyTimesNotReached() + { + var mock = new Mock(); + mock.Object.GetProtectedValue(); + + Assert.Throws(() => mock.Protected().Verify("ProtectedValue", Times.Exactly(2))); + } + + [Fact] + public void DoesNotThrowIfVerifyPropertyTimesReached() + { + var mock = new Mock(); + mock.Object.GetProtectedValue(); + mock.Object.GetProtectedValue(); + + mock.Protected().Verify("ProtectedValue", Times.Exactly(2)); + } + + [Fact] + public void ThrowsIfVerifyGetNullPropertyName() + { + Assert.Throws(() => new Mock().Protected().VerifyGet(null, Times.Once())); + } + + [Fact] + public void ThrowsIfVerifyGetEmptyPropertyName() + { + Assert.Throws(() => new Mock().Protected().VerifyGet(string.Empty, Times.Once())); + } + + [Fact] + public void ThrowsIfVerifyGetPropertyNotFound() + { + Assert.Throws(() => new Mock().Protected().VerifyGet("Foo", Times.Once())); + } + + [Fact] + public void ThrowsIfVerifyGetPropertyWithoutPropertyGet() + { + Assert.Throws(() => new Mock().Protected().VerifyGet("OnlySet", Times.Once())); + } + + [Fact] + public void ThrowsIfVerifyGetIsPublicPropertyGet() + { + Assert.Throws( + () => new Mock().Protected().VerifyGet("PublicValue", Times.Once())); + } + + [Fact] + public void VerifyGetAllowsProtectedInternalPropertyGet() + { + var mock = new Mock(); + var value = mock.Object.ProtectedInternalValue; + + mock.Protected().VerifyGet("ProtectedInternalValue", Times.Once()); + } + + [Fact] + public void VerifyGetAllowsProtectedPropertyGet() + { + var mock = new Mock(); + mock.Object.GetProtectedValue(); + + mock.Protected().VerifyGet("ProtectedValue", Times.Once()); + } + + [Fact] + public void ThrowsIfVerifyGetNonVirtualPropertyGet() + { + Assert.Throws( + () => new Mock().Protected().VerifyGet("NonVirtualValue", Times.Once())); + } + + [Fact] + public void ThrowsIfVerifyGetTimesNotReached() + { + var mock = new Mock(); + mock.Object.GetProtectedValue(); + + Assert.Throws(() => mock.Protected().VerifyGet("ProtectedValue", Times.Exactly(2))); + } + + [Fact] + public void DoesNotThrowIfVerifyGetPropertyTimesReached() + { + var mock = new Mock(); + mock.Object.GetProtectedValue(); + mock.Object.GetProtectedValue(); + + mock.Protected().VerifyGet("ProtectedValue", Times.Exactly(2)); + } + } + + public partial class ProtectedMockFixture + { + + [Fact] + public void ThrowsIfVerifySetNullPropertyName() + { + Assert.Throws( + () => new Mock().Protected().VerifySet(null, Times.Once(), ItExpr.IsAny())); + } + + [Fact] + public void ThrowsIfVerifySetEmptyPropertyName() + { + Assert.Throws( + () => new Mock().Protected().VerifySet(string.Empty, Times.Once(), ItExpr.IsAny())); + } + + [Fact] + public void ThrowsIfVerifySetPropertyNotFound() + { + Assert.Throws( + () => new Mock().Protected().VerifySet("Foo", Times.Once(), ItExpr.IsAny())); + } + + [Fact] + public void ThrowsIfVerifySetPropertyWithoutPropertySet() + { + Assert.Throws( + () => new Mock().Protected().VerifySet("OnlyGet", Times.Once(), ItExpr.IsAny())); + } + + [Fact] + public void ThrowsIfVerifySetPublicPropertySet() + { + Assert.Throws( + () => new Mock().Protected().VerifySet("PublicValue", Times.Once(), ItExpr.IsAny())); + } + + [Fact] + public void ThrowsIfVerifySetNonVirtualPropertySet() + { + Assert.Throws( + () => new Mock().Protected().VerifySet("NonVirtualValue", Times.Once(), ItExpr.IsAny())); + } + + [Fact] + public void VerifySetAllowsProtectedInternalPropertySet() + { + var mock = new Mock(); + mock.Object.ProtectedInternalValue = "foo"; + + mock.Protected().VerifySet("ProtectedInternalValue", Times.Once(), "bar"); + } + + [Fact] + public void VerifySetAllowsProtectedPropertySet() + { + var mock = new Mock(); + mock.Object.SetProtectedValue("foo"); + + mock.Protected().VerifySet("ProtectedValue", Times.Once(), ItExpr.IsAny()); + } + + [Fact] + public void ThrowsIfVerifySetTimesNotReached() + { + var mock = new Mock(); + mock.Object.SetProtectedValue("Foo"); + + Assert.Throws( + () => mock.Protected().VerifySet("ProtectedValue", Times.Exactly(2), ItExpr.IsAny())); + } + + [Fact] + public void DoesNotThrowIfVerifySetPropertyTimesReached() + { + var mock = new Mock(); + mock.Object.SetProtectedValue("foo"); + mock.Object.SetProtectedValue("foo"); + + mock.Protected().VerifySet("ProtectedValue", Times.Exactly(2), ItExpr.IsAny()); + } + + public class MethodOverloads + { + public void ExecuteDo(int a, int b) + { + this.Do(a, b); + } + + public void ExecuteDo(string a, string b) + { + this.Do(a, b); + } + + public int ExecuteDoReturn(int a, int b) + { + return this.DoReturn(a, b); + } + + protected virtual void Do(int a, int b) + { + } + + protected virtual void Do(string a, string b) + { + } + + protected virtual int DoReturn(int a, int b) + { + return a + b; + } + + public string ExecuteDoReturn(string a, string b) + { + return DoReturn(a, b); + } + + protected virtual string DoReturn(string a, string b) + { + return a + b; + } + } + + public class FooBase + { + public virtual string PublicValue { get; set; } + + protected internal virtual string ProtectedInternalValue { get; set; } + + protected string NonVirtualValue { get; set; } + + protected virtual int OnlyGet + { + get { return 0; } + } + + protected virtual int OnlySet + { + set { } + } + + protected virtual string ProtectedValue { get; set; } + + protected virtual int this[int index] + { + get { return 0; } + set { } + } + + public void DoProtected() + { + this.Protected(); + } + + public int DoProtectedInt() + { + return this.ProtectedInt(); + } + + public string DoStringArg(string arg) + { + return this.StringArg(arg); + } + + public string DoTwoArgs(string arg, int arg1) + { + return this.TwoArgs(arg, arg1); + } + + public string GetProtectedValue() + { + return this.ProtectedValue; + } + + public virtual void Public() + { + } + + public virtual int PublicInt() + { + return 10; + } + + public void SetProtectedValue(string value) + { + this.ProtectedValue = value; + } + + internal protected virtual void ProtectedInternal() + { + } + + internal protected virtual int ProtectedInternalInt() + { + return 0; + } + + protected virtual void Protected() + { + } + + protected virtual int ProtectedInt() + { + return 2; + } + + protected void NonVirtual() + { + } + + protected int NonVirtualInt() + { + return 2; + } + + protected virtual string StringArg(string arg) + { + return arg; + } + + protected virtual string TwoArgs(string arg, int arg1) + { + return arg; + } + } + + public class FooDerived : FooBase + { + } + } } \ No newline at end of file diff --git a/UnitTests/RecursiveMocksFixture.cs b/UnitTests/RecursiveMocksFixture.cs index 3531a944c..227c4eb1b 100644 --- a/UnitTests/RecursiveMocksFixture.cs +++ b/UnitTests/RecursiveMocksFixture.cs @@ -1,348 +1,348 @@ -using System; -using Xunit; - -namespace Moq.Tests -{ - public class RecursiveMocksFixture - { - [Fact] - public void CreatesMockForAccessedProperty() - { - var mock = new Mock(); - - mock.SetupGet(m => m.Bar.Value).Returns(5); - - Assert.Equal(5, mock.Object.Bar.Value); - } - - [Fact] - public void RetrievesSameMockForProperty() - { - var mock = new Mock { DefaultValue = DefaultValue.Mock }; - - var b1 = mock.Object.Bar; - var b2 = mock.Object.Bar; - - Assert.Same(b1, b2); - } - - [Fact] - public void NewMocksHaveSameBehaviorAndDefaultValueAsOwner() - { - var mock = new Mock(); - - mock.SetupGet(m => m.Bar.Value).Returns(5); - - var barMock = Mock.Get(mock.Object.Bar); - - Assert.Equal(mock.Behavior, barMock.Behavior); - Assert.Equal(mock.DefaultValue, barMock.DefaultValue); - } - - - [Fact] - public void CreatesMockForAccessedPropertyWithMethod() - { - var mock = new Mock(); - - mock.Setup(m => m.Bar.Do("ping")).Returns("ack"); - mock.Setup(m => m.Bar.Baz.Do("ping")).Returns("ack"); - - Assert.Equal("ack", mock.Object.Bar.Do("ping")); - Assert.Equal("ack", mock.Object.Bar.Baz.Do("ping")); - Assert.Equal(default(string), mock.Object.Bar.Do("foo")); - } - - [Fact] - public void CreatesMockForAccessedPropertyWithVoidMethod() - { - var mock = new Mock(); - - mock.Setup(m => m.Bar.Baz.Do()); - - //Assert.Throws(() => mock.VerifyAll()); - - Assert.NotNull(mock.Object.Bar); - Assert.NotNull(mock.Object.Bar.Baz); - - mock.Object.Bar.Baz.Do(); - - mock.Verify(m => m.Bar.Baz.Do()); - } - - [Fact] - public void CreatesMockForAccessedPropertyWithSetterWithValue() - { - var mock = new Mock(); - - mock.SetupSet(m => m.Bar.Value = 5); - - Assert.NotNull(mock.Object.Bar); - Assert.Throws(() => mock.VerifyAll()); - - mock.Object.Bar.Value = 5; - - mock.VerifyAll(); - } - - [Fact] - public void CreatesMockForAccessedPropertyWithSetter() - { - var mock = new Mock(); - - mock.SetupSet(m => m.Bar.Value = It.IsAny()); - - Assert.NotNull(mock.Object.Bar); - Assert.Throws(() => mock.VerifyAll()); - - mock.Object.Bar.Value = 5; - - mock.VerifyAll(); - } - - [Fact] - public void VerifiesAllHierarchy() - { - var mock = new Mock(); - - mock.Setup(m => m.Bar.Do("ping")).Returns("ack"); - mock.Setup(m => m.Do("ping")).Returns("ack"); - - mock.Object.Do("ping"); - var bar = mock.Object.Bar; - - Assert.Throws(() => mock.VerifyAll()); - } - - [Fact] - public void VerifiesHierarchy() - { - var mock = new Mock(); - - mock.Setup(m => m.Bar.Do("ping")).Returns("ack").Verifiable(); - mock.Setup(m => m.Do("ping")).Returns("ack"); - - mock.Object.Do("ping"); - var bar = mock.Object.Bar; - - Assert.Throws(() => mock.Verify()); - } - - [Fact] - public void VerifiesHierarchyMethodWithExpression() - { - var mock = new Mock(); - - Assert.Throws(() => mock.Verify(m => m.Bar.Do("ping"))); - - mock.Object.Bar.Do("ping"); - mock.Verify(m => m.Bar.Do("ping")); - } - - [Fact] - public void VerifiesHierarchyPropertyGetWithExpression() - { - var mock = new Mock(); - - Assert.Throws(() => mock.VerifyGet(m => m.Bar.Value)); - - var value = mock.Object.Bar.Value; - mock.VerifyGet(m => m.Bar.Value); - } - - [Fact] - public void VerifiesHierarchyPropertySetWithExpression() - { - var mock = new Mock(); - - Assert.Throws(() => mock.VerifySet(m => m.Bar.Value = It.IsAny())); - - mock.Object.Bar.Value = 5; - mock.VerifySet(m => m.Bar.Value = It.IsAny()); - } - - [Fact] - public void VerifiesReturnWithExpression() - { - var mock = new Mock(); - - mock.Setup(m => m.Bar.Do("ping")).Returns("ack").Verifiable(); - - Assert.Throws(() => mock.Verify(m => m.Bar.Do("ping"))); - - var result = mock.Object.Bar.Do("ping"); - - Assert.Equal("ack", result); - mock.Verify(m => m.Bar.Do("ping")); - } - - [Fact] - public void VerifiesVoidWithExpression() - { - var mock = new Mock(); - - mock.Setup(m => m.Bar.Baz.Do()); - - Assert.Throws(() => mock.Verify(m => m.Bar.Baz.Do())); - - mock.Object.Bar.Baz.Do(); - - mock.Verify(m => m.Bar.Baz.Do()); - } - - [Fact] - public void VerifiesGetWithExpression() - { - var mock = new Mock(); - - mock.SetupGet(m => m.Bar.Value).Returns(5); - - Assert.Throws(() => mock.VerifyGet(m => m.Bar.Value)); - - var result = mock.Object.Bar.Value; - - Assert.Equal(5, result); - - mock.VerifyGet(m => m.Bar.Value); - } - - [Fact] - public void VerifiesGetWithExpression2() - { - var mock = new Mock(); - - mock.Setup(m => m.Bar.Value).Returns(5); - - Assert.Throws(() => mock.Verify(m => m.Bar.Value)); - - var result = mock.Object.Bar.Value; - - Assert.Equal(5, result); - - mock.Verify(m => m.Bar.Value); - } - - [Fact] - public void VerifiesSetWithExpression() - { - var mock = new Mock(); - - mock.SetupSet(m => m.Bar.Value = It.IsAny()); - - Assert.Throws(() => mock.VerifySet(m => m.Bar.Value = It.IsAny())); - - mock.Object.Bar.Value = 5; - - mock.VerifySet(m => m.Bar.Value = It.IsAny()); - } - - [Fact] - public void VerifiesSetWithExpressionAndValue() - { - var mock = new Mock(); - - mock.SetupSet(m => m.Bar.Value = 5); - - Assert.Throws(() => mock.VerifySet(m => m.Bar.Value = 5)); - - mock.Object.Bar.Value = 5; - - mock.VerifySet(m => m.Bar.Value = 5); - } - - [Fact] - public void FieldAccessNotSupported() - { - var mock = new Mock(); - - Assert.Throws(() => mock.Setup(m => m.BarField.Do("ping"))); - } - - [Fact] - public void NonMockeableTypeThrows() - { - var mock = new Mock(); - - Assert.Throws(() => mock.Setup(m => m.Bar.Value.ToString())); - } - - [Fact] - public void IntermediateIndexerAccessIsSupported() - { - var mock = new Mock(); - - mock.Setup(m => m[0].Do("ping")).Returns("ack"); - - var result = mock.Object[0].Do("ping"); - - Assert.Equal("ack", result); - } - - [Fact] - public void IntermediateMethodInvocationAreSupported() - { - var mock = new Mock(); - - mock.Setup(m => m.GetBar().Do("ping")).Returns("ack"); - - var result = mock.Object.GetBar().Do("ping"); - - Assert.Equal("ack", result); - } - - [Fact] - public void FullMethodInvocationsSupportedInsideFluent() - { - var fooMock = new Mock(MockBehavior.Strict); - fooMock.Setup(f => f.Bar.GetBaz("hey").Value).Returns(5); - - Assert.Equal(5, fooMock.Object.Bar.GetBaz("hey").Value); - } - - [Fact] - public void FullMethodInvocationInsideFluentCanUseMatchers() - { - var fooMock = new Mock(MockBehavior.Strict); - fooMock.Setup(f => f.Bar.GetBaz(It.IsAny()).Value).Returns(5); - - Assert.Equal(5, fooMock.Object.Bar.GetBaz("foo").Value); - } - - public class Foo : IFoo - { - - public IBar BarField; - public IBar Bar { get; set; } - public IBar GetBar() { return null; } - public IBar this[int index] { get { return null; } set { } } - - public string Do(string command) - { - throw new NotImplementedException(); - } - } - - public interface IFoo - { - IBar Bar { get; set; } - IBar this[int index] { get; set; } - string Do(string command); - IBar GetBar(); - } - - public interface IBar - { - int Value { get; set; } - string Do(string command); - IBaz Baz { get; set; } - IBaz GetBaz(string value); - } - - public interface IBaz - { - int Value { get; set; } - string Do(string command); - void Do(); - } - } -} +using System; +using Xunit; + +namespace Moq.Tests +{ + public class RecursiveMocksFixture + { + [Fact] + public void CreatesMockForAccessedProperty() + { + var mock = new Mock(); + + mock.SetupGet(m => m.Bar.Value).Returns(5); + + Assert.Equal(5, mock.Object.Bar.Value); + } + + [Fact] + public void RetrievesSameMockForProperty() + { + var mock = new Mock { DefaultValue = DefaultValue.Mock }; + + var b1 = mock.Object.Bar; + var b2 = mock.Object.Bar; + + Assert.Same(b1, b2); + } + + [Fact] + public void NewMocksHaveSameBehaviorAndDefaultValueAsOwner() + { + var mock = new Mock(); + + mock.SetupGet(m => m.Bar.Value).Returns(5); + + var barMock = Mock.Get(mock.Object.Bar); + + Assert.Equal(mock.Behavior, barMock.Behavior); + Assert.Equal(mock.DefaultValue, barMock.DefaultValue); + } + + + [Fact] + public void CreatesMockForAccessedPropertyWithMethod() + { + var mock = new Mock(); + + mock.Setup(m => m.Bar.Do("ping")).Returns("ack"); + mock.Setup(m => m.Bar.Baz.Do("ping")).Returns("ack"); + + Assert.Equal("ack", mock.Object.Bar.Do("ping")); + Assert.Equal("ack", mock.Object.Bar.Baz.Do("ping")); + Assert.Equal(default(string), mock.Object.Bar.Do("foo")); + } + + [Fact] + public void CreatesMockForAccessedPropertyWithVoidMethod() + { + var mock = new Mock(); + + mock.Setup(m => m.Bar.Baz.Do()); + + //Assert.Throws(() => mock.VerifyAll()); + + Assert.NotNull(mock.Object.Bar); + Assert.NotNull(mock.Object.Bar.Baz); + + mock.Object.Bar.Baz.Do(); + + mock.Verify(m => m.Bar.Baz.Do()); + } + + [Fact] + public void CreatesMockForAccessedPropertyWithSetterWithValue() + { + var mock = new Mock(); + + mock.SetupSet(m => m.Bar.Value = 5); + + Assert.NotNull(mock.Object.Bar); + Assert.Throws(() => mock.VerifyAll()); + + mock.Object.Bar.Value = 5; + + mock.VerifyAll(); + } + + [Fact] + public void CreatesMockForAccessedPropertyWithSetter() + { + var mock = new Mock(); + + mock.SetupSet(m => m.Bar.Value = It.IsAny()); + + Assert.NotNull(mock.Object.Bar); + Assert.Throws(() => mock.VerifyAll()); + + mock.Object.Bar.Value = 5; + + mock.VerifyAll(); + } + + [Fact] + public void VerifiesAllHierarchy() + { + var mock = new Mock(); + + mock.Setup(m => m.Bar.Do("ping")).Returns("ack"); + mock.Setup(m => m.Do("ping")).Returns("ack"); + + mock.Object.Do("ping"); + var bar = mock.Object.Bar; + + Assert.Throws(() => mock.VerifyAll()); + } + + [Fact] + public void VerifiesHierarchy() + { + var mock = new Mock(); + + mock.Setup(m => m.Bar.Do("ping")).Returns("ack").Verifiable(); + mock.Setup(m => m.Do("ping")).Returns("ack"); + + mock.Object.Do("ping"); + var bar = mock.Object.Bar; + + Assert.Throws(() => mock.Verify()); + } + + [Fact] + public void VerifiesHierarchyMethodWithExpression() + { + var mock = new Mock(); + + Assert.Throws(() => mock.Verify(m => m.Bar.Do("ping"))); + + mock.Object.Bar.Do("ping"); + mock.Verify(m => m.Bar.Do("ping")); + } + + [Fact] + public void VerifiesHierarchyPropertyGetWithExpression() + { + var mock = new Mock(); + + Assert.Throws(() => mock.VerifyGet(m => m.Bar.Value)); + + var value = mock.Object.Bar.Value; + mock.VerifyGet(m => m.Bar.Value); + } + + [Fact] + public void VerifiesHierarchyPropertySetWithExpression() + { + var mock = new Mock(); + + Assert.Throws(() => mock.VerifySet(m => m.Bar.Value = It.IsAny())); + + mock.Object.Bar.Value = 5; + mock.VerifySet(m => m.Bar.Value = It.IsAny()); + } + + [Fact] + public void VerifiesReturnWithExpression() + { + var mock = new Mock(); + + mock.Setup(m => m.Bar.Do("ping")).Returns("ack").Verifiable(); + + Assert.Throws(() => mock.Verify(m => m.Bar.Do("ping"))); + + var result = mock.Object.Bar.Do("ping"); + + Assert.Equal("ack", result); + mock.Verify(m => m.Bar.Do("ping")); + } + + [Fact] + public void VerifiesVoidWithExpression() + { + var mock = new Mock(); + + mock.Setup(m => m.Bar.Baz.Do()); + + Assert.Throws(() => mock.Verify(m => m.Bar.Baz.Do())); + + mock.Object.Bar.Baz.Do(); + + mock.Verify(m => m.Bar.Baz.Do()); + } + + [Fact] + public void VerifiesGetWithExpression() + { + var mock = new Mock(); + + mock.SetupGet(m => m.Bar.Value).Returns(5); + + Assert.Throws(() => mock.VerifyGet(m => m.Bar.Value)); + + var result = mock.Object.Bar.Value; + + Assert.Equal(5, result); + + mock.VerifyGet(m => m.Bar.Value); + } + + [Fact] + public void VerifiesGetWithExpression2() + { + var mock = new Mock(); + + mock.Setup(m => m.Bar.Value).Returns(5); + + Assert.Throws(() => mock.Verify(m => m.Bar.Value)); + + var result = mock.Object.Bar.Value; + + Assert.Equal(5, result); + + mock.Verify(m => m.Bar.Value); + } + + [Fact] + public void VerifiesSetWithExpression() + { + var mock = new Mock(); + + mock.SetupSet(m => m.Bar.Value = It.IsAny()); + + Assert.Throws(() => mock.VerifySet(m => m.Bar.Value = It.IsAny())); + + mock.Object.Bar.Value = 5; + + mock.VerifySet(m => m.Bar.Value = It.IsAny()); + } + + [Fact] + public void VerifiesSetWithExpressionAndValue() + { + var mock = new Mock(); + + mock.SetupSet(m => m.Bar.Value = 5); + + Assert.Throws(() => mock.VerifySet(m => m.Bar.Value = 5)); + + mock.Object.Bar.Value = 5; + + mock.VerifySet(m => m.Bar.Value = 5); + } + + [Fact] + public void FieldAccessNotSupported() + { + var mock = new Mock(); + + Assert.Throws(() => mock.Setup(m => m.BarField.Do("ping"))); + } + + [Fact] + public void NonMockeableTypeThrows() + { + var mock = new Mock(); + + Assert.Throws(() => mock.Setup(m => m.Bar.Value.ToString())); + } + + [Fact] + public void IntermediateIndexerAccessIsSupported() + { + var mock = new Mock(); + + mock.Setup(m => m[0].Do("ping")).Returns("ack"); + + var result = mock.Object[0].Do("ping"); + + Assert.Equal("ack", result); + } + + [Fact] + public void IntermediateMethodInvocationAreSupported() + { + var mock = new Mock(); + + mock.Setup(m => m.GetBar().Do("ping")).Returns("ack"); + + var result = mock.Object.GetBar().Do("ping"); + + Assert.Equal("ack", result); + } + + [Fact] + public void FullMethodInvocationsSupportedInsideFluent() + { + var fooMock = new Mock(MockBehavior.Strict); + fooMock.Setup(f => f.Bar.GetBaz("hey").Value).Returns(5); + + Assert.Equal(5, fooMock.Object.Bar.GetBaz("hey").Value); + } + + [Fact] + public void FullMethodInvocationInsideFluentCanUseMatchers() + { + var fooMock = new Mock(MockBehavior.Strict); + fooMock.Setup(f => f.Bar.GetBaz(It.IsAny()).Value).Returns(5); + + Assert.Equal(5, fooMock.Object.Bar.GetBaz("foo").Value); + } + + public class Foo : IFoo + { + + public IBar BarField; + public IBar Bar { get; set; } + public IBar GetBar() { return null; } + public IBar this[int index] { get { return null; } set { } } + + public string Do(string command) + { + throw new NotImplementedException(); + } + } + + public interface IFoo + { + IBar Bar { get; set; } + IBar this[int index] { get; set; } + string Do(string command); + IBar GetBar(); + } + + public interface IBar + { + int Value { get; set; } + string Do(string command); + IBaz Baz { get; set; } + IBaz GetBaz(string value); + } + + public interface IBaz + { + int Value { get; set; } + string Do(string command); + void Do(); + } + } +} diff --git a/UnitTests/Regressions/StreamFixture.cs b/UnitTests/Regressions/StreamFixture.cs index 9d44c5279..e2ed6b1fc 100644 --- a/UnitTests/Regressions/StreamFixture.cs +++ b/UnitTests/Regressions/StreamFixture.cs @@ -1,29 +1,29 @@ -using System.Diagnostics; -using System.IO; -using Xunit; - -namespace Moq.Tests -{ - public class StreamFixture - { - [Fact] - public void ShouldMockStream() - { - var mockStream = new Mock(); - - mockStream.Setup(stream => stream.Seek(0, SeekOrigin.Begin)).Returns(0L); - - var position = mockStream.Object.Seek(0, SeekOrigin.Begin); - - Assert.Equal(0, position); - - mockStream.Setup(stream => stream.Flush()); - mockStream.Setup(stream => stream.SetLength(100)); - - mockStream.Object.Flush(); - mockStream.Object.SetLength(100); - - mockStream.VerifyAll(); - } - } -} +using System.Diagnostics; +using System.IO; +using Xunit; + +namespace Moq.Tests +{ + public class StreamFixture + { + [Fact] + public void ShouldMockStream() + { + var mockStream = new Mock(); + + mockStream.Setup(stream => stream.Seek(0, SeekOrigin.Begin)).Returns(0L); + + var position = mockStream.Object.Seek(0, SeekOrigin.Begin); + + Assert.Equal(0, position); + + mockStream.Setup(stream => stream.Flush()); + mockStream.Setup(stream => stream.SetLength(100)); + + mockStream.Object.Flush(); + mockStream.Object.SetLength(100); + + mockStream.VerifyAll(); + } + } +} diff --git a/UnitTests/StubExtensionsFixture.cs b/UnitTests/StubExtensionsFixture.cs index 561bf2202..58265b1ca 100644 --- a/UnitTests/StubExtensionsFixture.cs +++ b/UnitTests/StubExtensionsFixture.cs @@ -1,124 +1,124 @@ -using System.Diagnostics; -using Xunit; - -namespace Moq.Tests -{ - public class StubExtensionsFixture - { - [Fact] - public void ShouldStubPropertyWithoutInitialValue() - { - var mock = new Mock(); - - mock.SetupProperty(f => f.ValueProperty); - - Assert.Equal(0, mock.Object.ValueProperty); - - mock.Object.ValueProperty = 5; - - Assert.Equal(5, mock.Object.ValueProperty); - } - - [Fact] - public void ShouldStubPropertyWithInitialValue() - { - var mock = new Mock(); - - mock.SetupProperty(f => f.ValueProperty, 5); - - Assert.Equal(5, mock.Object.ValueProperty); - - mock.Object.ValueProperty = 15; - - Assert.Equal(15, mock.Object.ValueProperty); - } - - [Fact] - public void StubsAllProperties() - { - var mock = new Mock(); - - mock.SetupAllProperties(); - - mock.Object.ValueProperty = 5; - Assert.Equal(5, mock.Object.ValueProperty); - - var obj = new object(); - mock.Object.Object = obj; - Assert.Same(obj, mock.Object.Object); - - var bar = new Mock(); - mock.Object.Bar = bar.Object; - Assert.Same(bar.Object, mock.Object.Bar); - } - - [Fact] - public void StubsAllHierarchy() - { - var mock = new Mock() { DefaultValue = DefaultValue.Mock }; - - mock.SetupAllProperties(); - - mock.Object.Bar.Value = 5; - Assert.Equal(5, mock.Object.Bar.Value); - } - - [Fact] - public void StubsInheritedInterfaceProperties() - { - var mock = new Mock(); - - mock.SetupAllProperties(); - - mock.Object.Value = 5; - Assert.Equal(5, mock.Object.Value); - - mock.Object.Name = "foo"; - Assert.Equal("foo", mock.Object.Name); - } - - [Fact] - public void StubsInheritedClassProperties() - { - var mock = new Mock(); - - mock.SetupAllProperties(); - - mock.Object.BaseValue = 5; - Assert.Equal(5, mock.Object.BaseValue); - - mock.Object.Value = 10; - Assert.Equal(10, mock.Object.Value); - } - - private object GetValue() { return new object(); } - - public interface IFoo - { - int ValueProperty { get; set; } - object Object { get; set; } - IBar Bar { get; set; } - } - - public class Derived : Base - { - public string Name { get; set; } - } - - public abstract class Base : IBar - { - public int BaseValue { get; set; } - public int Value { get; set; } - } - - public interface IBar - { - int Value { get; set; } - } - - public interface IBaz : IBar - { - string Name { get; set; } - } - } -} +using System.Diagnostics; +using Xunit; + +namespace Moq.Tests +{ + public class StubExtensionsFixture + { + [Fact] + public void ShouldStubPropertyWithoutInitialValue() + { + var mock = new Mock(); + + mock.SetupProperty(f => f.ValueProperty); + + Assert.Equal(0, mock.Object.ValueProperty); + + mock.Object.ValueProperty = 5; + + Assert.Equal(5, mock.Object.ValueProperty); + } + + [Fact] + public void ShouldStubPropertyWithInitialValue() + { + var mock = new Mock(); + + mock.SetupProperty(f => f.ValueProperty, 5); + + Assert.Equal(5, mock.Object.ValueProperty); + + mock.Object.ValueProperty = 15; + + Assert.Equal(15, mock.Object.ValueProperty); + } + + [Fact] + public void StubsAllProperties() + { + var mock = new Mock(); + + mock.SetupAllProperties(); + + mock.Object.ValueProperty = 5; + Assert.Equal(5, mock.Object.ValueProperty); + + var obj = new object(); + mock.Object.Object = obj; + Assert.Same(obj, mock.Object.Object); + + var bar = new Mock(); + mock.Object.Bar = bar.Object; + Assert.Same(bar.Object, mock.Object.Bar); + } + + [Fact] + public void StubsAllHierarchy() + { + var mock = new Mock() { DefaultValue = DefaultValue.Mock }; + + mock.SetupAllProperties(); + + mock.Object.Bar.Value = 5; + Assert.Equal(5, mock.Object.Bar.Value); + } + + [Fact] + public void StubsInheritedInterfaceProperties() + { + var mock = new Mock(); + + mock.SetupAllProperties(); + + mock.Object.Value = 5; + Assert.Equal(5, mock.Object.Value); + + mock.Object.Name = "foo"; + Assert.Equal("foo", mock.Object.Name); + } + + [Fact] + public void StubsInheritedClassProperties() + { + var mock = new Mock(); + + mock.SetupAllProperties(); + + mock.Object.BaseValue = 5; + Assert.Equal(5, mock.Object.BaseValue); + + mock.Object.Value = 10; + Assert.Equal(10, mock.Object.Value); + } + + private object GetValue() { return new object(); } + + public interface IFoo + { + int ValueProperty { get; set; } + object Object { get; set; } + IBar Bar { get; set; } + } + + public class Derived : Base + { + public string Name { get; set; } + } + + public abstract class Base : IBar + { + public int BaseValue { get; set; } + public int Value { get; set; } + } + + public interface IBar + { + int Value { get; set; } + } + + public interface IBaz : IBar + { + string Name { get; set; } + } + } +} diff --git a/UnitTests/TimesFixture.cs b/UnitTests/TimesFixture.cs index 30812704d..cffa8bedc 100644 --- a/UnitTests/TimesFixture.cs +++ b/UnitTests/TimesFixture.cs @@ -1,171 +1,171 @@ -using System; -using Xunit; - -namespace Moq.Tests -{ - public class TimesFixture - { - [Fact] - public void AtLeastOnceRangesBetweenOneAndMaxValue() - { - var target = Times.AtLeastOnce(); - - Assert.False(target.Verify(-1)); - Assert.False(target.Verify(0)); - Assert.True(target.Verify(1)); - Assert.True(target.Verify(5)); - Assert.True(target.Verify(int.MaxValue)); - } - - [Fact] - public void AtLeastThrowsIfTimesLessThanOne() - { - Assert.Throws(() => Times.AtLeast(0)); - Assert.Throws(() => Times.AtLeast(-1)); - } - - [Fact] - public void AtLeastRangesBetweenTimesAndMaxValue() - { - var target = Times.AtLeast(10); - - Assert.False(target.Verify(-1)); - Assert.False(target.Verify(0)); - Assert.False(target.Verify(9)); - Assert.True(target.Verify(10)); - Assert.True(target.Verify(int.MaxValue)); - } - - [Fact] - public void AtMostOnceRangesBetweenZeroAndOne() - { - var target = Times.AtMostOnce(); - - Assert.False(target.Verify(-1)); - Assert.True(target.Verify(0)); - Assert.True(target.Verify(1)); - Assert.False(target.Verify(5)); - Assert.False(target.Verify(int.MaxValue)); - } - - [Fact] - public void AtMostThrowsIfTimesLessThanZero() - { - Assert.Throws(() => Times.AtMost(-1)); - Assert.Throws(() => Times.AtMost(-2)); - } - - [Fact] - public void AtMostRangesBetweenZeroAndTimes() - { - var target = Times.AtMost(10); - - Assert.False(target.Verify(-1)); - Assert.True(target.Verify(0)); - Assert.True(target.Verify(6)); - Assert.True(target.Verify(10)); - Assert.False(target.Verify(11)); - Assert.False(target.Verify(int.MaxValue)); - } - - [Fact] - public void BetweenInclusiveThrowsIfFromLessThanZero() - { - Assert.Throws(() => Times.Between(-1, 10, Range.Inclusive)); - Assert.Throws(() => Times.Between(-2, 3, Range.Inclusive)); - } - - [Fact] - public void BetweenInclusiveThrowsIfFromGreaterThanTo() - { - Assert.Throws(() => Times.Between(3, 2, Range.Inclusive)); - Assert.Throws(() => Times.Between(-3, -2, Range.Inclusive)); - Assert.Throws(() => Times.Between(0, -2, Range.Inclusive)); - } - - [Fact] - public void BetweenInclusiveRangesBetweenFromAndTo() - { - var target = Times.Between(10, 20, Range.Inclusive); - - Assert.False(target.Verify(0)); - Assert.False(target.Verify(9)); - Assert.True(target.Verify(10)); - Assert.True(target.Verify(14)); - Assert.True(target.Verify(20)); - Assert.False(target.Verify(21)); - Assert.False(target.Verify(int.MaxValue)); - } - - [Fact] - public void BetweenExclusiveThrowsIfFromLessThanZero() - { - Assert.Throws(() => Times.Between(-1, 10, Range.Exclusive)); - Assert.Throws(() => Times.Between(-2, 3, Range.Exclusive)); - } - - [Fact] - public void BetweenExclusiveThrowsIfFromPlusOneGreaterThanToMinusOne() - { - Assert.Throws(() => Times.Between(2, 3, Range.Exclusive)); - Assert.Throws(() => Times.Between(3, 2, Range.Exclusive)); - Assert.Throws(() => Times.Between(0, -2, Range.Exclusive)); - } - - [Fact] - public void BetweenExclusiveRangesBetweenFromPlusOneAndToMinusOne() - { - var target = Times.Between(10, 20, Range.Exclusive); - - Assert.False(target.Verify(0)); - Assert.False(target.Verify(10)); - Assert.True(target.Verify(11)); - Assert.True(target.Verify(14)); - Assert.True(target.Verify(19)); - Assert.False(target.Verify(20)); - Assert.False(target.Verify(int.MaxValue)); - } - - [Fact] - public void ExactlyThrowsIfTimesLessThanZero() - { - Assert.Throws(() => Times.Exactly(-1)); - Assert.Throws(() => Times.Exactly(-2)); - } - - [Fact] - public void ExactlyCheckExactTimes() - { - var target = Times.Exactly(10); - - Assert.False(target.Verify(-1)); - Assert.False(target.Verify(0)); - Assert.False(target.Verify(9)); - Assert.True(target.Verify(10)); - Assert.False(target.Verify(11)); - Assert.False(target.Verify(int.MaxValue)); - } - - [Fact] - public void NeverChecksZeroTimes() - { - var target = Times.Never(); - - Assert.False(target.Verify(-1)); - Assert.True(target.Verify(0)); - Assert.False(target.Verify(1)); - Assert.False(target.Verify(int.MaxValue)); - } - - [Fact] - public void OnceChecksOneTime() - { - var target = Times.Once(); - - Assert.False(target.Verify(-1)); - Assert.False(target.Verify(0)); - Assert.True(target.Verify(1)); - Assert.False(target.Verify(int.MaxValue)); - } - } +using System; +using Xunit; + +namespace Moq.Tests +{ + public class TimesFixture + { + [Fact] + public void AtLeastOnceRangesBetweenOneAndMaxValue() + { + var target = Times.AtLeastOnce(); + + Assert.False(target.Verify(-1)); + Assert.False(target.Verify(0)); + Assert.True(target.Verify(1)); + Assert.True(target.Verify(5)); + Assert.True(target.Verify(int.MaxValue)); + } + + [Fact] + public void AtLeastThrowsIfTimesLessThanOne() + { + Assert.Throws(() => Times.AtLeast(0)); + Assert.Throws(() => Times.AtLeast(-1)); + } + + [Fact] + public void AtLeastRangesBetweenTimesAndMaxValue() + { + var target = Times.AtLeast(10); + + Assert.False(target.Verify(-1)); + Assert.False(target.Verify(0)); + Assert.False(target.Verify(9)); + Assert.True(target.Verify(10)); + Assert.True(target.Verify(int.MaxValue)); + } + + [Fact] + public void AtMostOnceRangesBetweenZeroAndOne() + { + var target = Times.AtMostOnce(); + + Assert.False(target.Verify(-1)); + Assert.True(target.Verify(0)); + Assert.True(target.Verify(1)); + Assert.False(target.Verify(5)); + Assert.False(target.Verify(int.MaxValue)); + } + + [Fact] + public void AtMostThrowsIfTimesLessThanZero() + { + Assert.Throws(() => Times.AtMost(-1)); + Assert.Throws(() => Times.AtMost(-2)); + } + + [Fact] + public void AtMostRangesBetweenZeroAndTimes() + { + var target = Times.AtMost(10); + + Assert.False(target.Verify(-1)); + Assert.True(target.Verify(0)); + Assert.True(target.Verify(6)); + Assert.True(target.Verify(10)); + Assert.False(target.Verify(11)); + Assert.False(target.Verify(int.MaxValue)); + } + + [Fact] + public void BetweenInclusiveThrowsIfFromLessThanZero() + { + Assert.Throws(() => Times.Between(-1, 10, Range.Inclusive)); + Assert.Throws(() => Times.Between(-2, 3, Range.Inclusive)); + } + + [Fact] + public void BetweenInclusiveThrowsIfFromGreaterThanTo() + { + Assert.Throws(() => Times.Between(3, 2, Range.Inclusive)); + Assert.Throws(() => Times.Between(-3, -2, Range.Inclusive)); + Assert.Throws(() => Times.Between(0, -2, Range.Inclusive)); + } + + [Fact] + public void BetweenInclusiveRangesBetweenFromAndTo() + { + var target = Times.Between(10, 20, Range.Inclusive); + + Assert.False(target.Verify(0)); + Assert.False(target.Verify(9)); + Assert.True(target.Verify(10)); + Assert.True(target.Verify(14)); + Assert.True(target.Verify(20)); + Assert.False(target.Verify(21)); + Assert.False(target.Verify(int.MaxValue)); + } + + [Fact] + public void BetweenExclusiveThrowsIfFromLessThanZero() + { + Assert.Throws(() => Times.Between(-1, 10, Range.Exclusive)); + Assert.Throws(() => Times.Between(-2, 3, Range.Exclusive)); + } + + [Fact] + public void BetweenExclusiveThrowsIfFromPlusOneGreaterThanToMinusOne() + { + Assert.Throws(() => Times.Between(2, 3, Range.Exclusive)); + Assert.Throws(() => Times.Between(3, 2, Range.Exclusive)); + Assert.Throws(() => Times.Between(0, -2, Range.Exclusive)); + } + + [Fact] + public void BetweenExclusiveRangesBetweenFromPlusOneAndToMinusOne() + { + var target = Times.Between(10, 20, Range.Exclusive); + + Assert.False(target.Verify(0)); + Assert.False(target.Verify(10)); + Assert.True(target.Verify(11)); + Assert.True(target.Verify(14)); + Assert.True(target.Verify(19)); + Assert.False(target.Verify(20)); + Assert.False(target.Verify(int.MaxValue)); + } + + [Fact] + public void ExactlyThrowsIfTimesLessThanZero() + { + Assert.Throws(() => Times.Exactly(-1)); + Assert.Throws(() => Times.Exactly(-2)); + } + + [Fact] + public void ExactlyCheckExactTimes() + { + var target = Times.Exactly(10); + + Assert.False(target.Verify(-1)); + Assert.False(target.Verify(0)); + Assert.False(target.Verify(9)); + Assert.True(target.Verify(10)); + Assert.False(target.Verify(11)); + Assert.False(target.Verify(int.MaxValue)); + } + + [Fact] + public void NeverChecksZeroTimes() + { + var target = Times.Never(); + + Assert.False(target.Verify(-1)); + Assert.True(target.Verify(0)); + Assert.False(target.Verify(1)); + Assert.False(target.Verify(int.MaxValue)); + } + + [Fact] + public void OnceChecksOneTime() + { + var target = Times.Once(); + + Assert.False(target.Verify(-1)); + Assert.False(target.Verify(0)); + Assert.True(target.Verify(1)); + Assert.False(target.Verify(int.MaxValue)); + } + } } \ No newline at end of file diff --git a/Visualizer/CallViewModel.cs b/Visualizer/CallViewModel.cs index 23f38f80e..6417c932d 100644 --- a/Visualizer/CallViewModel.cs +++ b/Visualizer/CallViewModel.cs @@ -1,120 +1,120 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; - -namespace Moq.Visualizer -{ - [Serializable] - public class CallViewModel - { - internal CallViewModel(MethodInfo methodInfo, object[] arguments, object returnValue) - { - this.Method = methodInfo.GetName(); - this.IsVoid = methodInfo.ReturnType == typeof(void); - - var index = 0; - this.Arguments = methodInfo.GetParameters() - .Select(pi => new ParameterViewModel(pi, this.GetValue(arguments[index++]))).ToArray(); - - this.ReturnValue = this.GetValue(returnValue); - this.MethodCall = this.GetMethodCall(methodInfo); - } - - private object GetValue(object value) - { - if (value == null) - { - return ""; - } - - // TODO get type from ParameterInfo, because of possible conversion errors - // NOTE Primitive types are: Boolean, Byte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64, IntPtr, UIntPtr, Char, Double, and Single - var type = value.GetType(); - if (type.IsPrimitive || value is decimal || value is DateTime || value is TimeSpan) - { - return value; - } - - // TODO take care about BitMap enums - if (type.IsEnum) - { - var values = value.ToString().Split( - new char[] { ',', ' ' }, - StringSplitOptions.RemoveEmptyEntries); - var typeName = type.GetName(); - return string.Join(" | ", values.Select(v => typeName + "." + v).ToArray()); - } - - if (value is string) - { - return "\"" + value + "\""; - } - - return "<" + type.GetName() + ">"; - } - - public IEnumerable Arguments { get; private set; } - - public bool IsExpanded - { - get { return false; } - } - - public bool IsVoid { get; private set; } - - public bool HasSetup { get; set; } - - public string Method { get; private set; } - - public object ReturnValue { get; private set; } - - public string MethodCall { get; private set; } - - // TODO Property formating - // TODO ParamArray method - // TODO Void members - // TODO indexers - private string GetMethodCall(MethodInfo method) - { - if (method.IsPropertyGetter()) - { - return method.Name.Substring(4) + " → " + this.ReturnValue; - } - - if (method.IsPropertySetter()) - { - return method.Name.Substring(4) + " = " + this.GetValue(this.Arguments.ElementAt(0).Value); - } - - var methodCall = this.Method + "(" + - string.Join(",", this.Arguments.Select(a => GetKind(a) + a.Name + ": " + a.Value.ToString()).ToArray()) + ")"; - if (this.IsVoid) - { - return methodCall; - } - - return " → " + this.ReturnValue.ToString(); - } - - private static string GetKind(ParameterViewModel a) - { - if (a.IsIn) - { - return string.Empty; - } - - if (a.IsOut) - { - return "out "; - } - - if (a.IsRef) - { - return "ref "; - } - - throw new Exception(); - } - } +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +namespace Moq.Visualizer +{ + [Serializable] + public class CallViewModel + { + internal CallViewModel(MethodInfo methodInfo, object[] arguments, object returnValue) + { + this.Method = methodInfo.GetName(); + this.IsVoid = methodInfo.ReturnType == typeof(void); + + var index = 0; + this.Arguments = methodInfo.GetParameters() + .Select(pi => new ParameterViewModel(pi, this.GetValue(arguments[index++]))).ToArray(); + + this.ReturnValue = this.GetValue(returnValue); + this.MethodCall = this.GetMethodCall(methodInfo); + } + + private object GetValue(object value) + { + if (value == null) + { + return ""; + } + + // TODO get type from ParameterInfo, because of possible conversion errors + // NOTE Primitive types are: Boolean, Byte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64, IntPtr, UIntPtr, Char, Double, and Single + var type = value.GetType(); + if (type.IsPrimitive || value is decimal || value is DateTime || value is TimeSpan) + { + return value; + } + + // TODO take care about BitMap enums + if (type.IsEnum) + { + var values = value.ToString().Split( + new char[] { ',', ' ' }, + StringSplitOptions.RemoveEmptyEntries); + var typeName = type.GetName(); + return string.Join(" | ", values.Select(v => typeName + "." + v).ToArray()); + } + + if (value is string) + { + return "\"" + value + "\""; + } + + return "<" + type.GetName() + ">"; + } + + public IEnumerable Arguments { get; private set; } + + public bool IsExpanded + { + get { return false; } + } + + public bool IsVoid { get; private set; } + + public bool HasSetup { get; set; } + + public string Method { get; private set; } + + public object ReturnValue { get; private set; } + + public string MethodCall { get; private set; } + + // TODO Property formating + // TODO ParamArray method + // TODO Void members + // TODO indexers + private string GetMethodCall(MethodInfo method) + { + if (method.IsPropertyGetter()) + { + return method.Name.Substring(4) + " → " + this.ReturnValue; + } + + if (method.IsPropertySetter()) + { + return method.Name.Substring(4) + " = " + this.GetValue(this.Arguments.ElementAt(0).Value); + } + + var methodCall = this.Method + "(" + + string.Join(",", this.Arguments.Select(a => GetKind(a) + a.Name + ": " + a.Value.ToString()).ToArray()) + ")"; + if (this.IsVoid) + { + return methodCall; + } + + return " → " + this.ReturnValue.ToString(); + } + + private static string GetKind(ParameterViewModel a) + { + if (a.IsIn) + { + return string.Empty; + } + + if (a.IsOut) + { + return "out "; + } + + if (a.IsRef) + { + return "ref "; + } + + throw new Exception(); + } + } } \ No newline at end of file diff --git a/Visualizer/ContainerViewModel.cs b/Visualizer/ContainerViewModel.cs index a6bd3eb31..d528522e6 100644 --- a/Visualizer/ContainerViewModel.cs +++ b/Visualizer/ContainerViewModel.cs @@ -1,30 +1,30 @@ -using System; -using System.Collections.Generic; - -namespace Moq.Visualizer -{ - [Serializable] - public abstract class ContainerViewModel - { - protected ContainerViewModel(string name) - { - this.Name = name; - } - - public string Name { get; private set; } - } - - [Serializable] - public class ContainerViewModel : ContainerViewModel - { - public ContainerViewModel(string name, IEnumerable children) - : base(name) - { - this.Children = children; - } - - public bool IsExpanded { get; set; } - - public IEnumerable Children { get; private set; } - } +using System; +using System.Collections.Generic; + +namespace Moq.Visualizer +{ + [Serializable] + public abstract class ContainerViewModel + { + protected ContainerViewModel(string name) + { + this.Name = name; + } + + public string Name { get; private set; } + } + + [Serializable] + public class ContainerViewModel : ContainerViewModel + { + public ContainerViewModel(string name, IEnumerable children) + : base(name) + { + this.Children = children; + } + + public bool IsExpanded { get; set; } + + public IEnumerable Children { get; private set; } + } } \ No newline at end of file diff --git a/Visualizer/MockContextViewModel.cs b/Visualizer/MockContextViewModel.cs index 0a8224e67..89720944e 100644 --- a/Visualizer/MockContextViewModel.cs +++ b/Visualizer/MockContextViewModel.cs @@ -1,84 +1,84 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Moq.Proxy; -using Moq.Visualizer.Properties; - -namespace Moq.Visualizer -{ - [Serializable] - public class MockContextViewModel - { - internal MockContextViewModel(Mock mock) - { - this.Behavior = mock.Behavior; - this.DefaultValue = mock.DefaultValue; - this.CallBase = mock.CallBase; - this.Mocks = new[] { GetMock(mock) }; - } - - public MockBehavior Behavior { get; private set; } - - public bool CallBase { get; private set; } - - public DefaultValue DefaultValue { get; private set; } - - public IEnumerable Mocks { get; private set; } - - private static ContainerViewModel CreateExpandedContainer(string name, IEnumerable children) - { - return new ContainerViewModel(name, children.ToArray()) { IsExpanded = true }; - } - - private static MockViewModel GetMock(Mock mock) - { - var actualCalls = mock.Interceptor.ActualCalls.ToDictionary(ac => ac, i => GetCall(i)); - - var setups = mock.Interceptor.OrderedCalls.Select(s => GetSetup(s, actualCalls)) - .OrderBy(s => s.SetupExpression); - var calls = actualCalls.Values.Where(c => !c.HasSetup); - var innerMocks = mock.InnerMocks.Values.Select(m => GetMock(m)); - - return new MockViewModel( - mock.MockedType, - CreateExpandedContainer(Resources.SetupsContainerName, setups), - CreateExpandedContainer(Resources.OtherCallsContainerName, calls), - CreateExpandedContainer(Resources.MocksContainerName, innerMocks)) - { - IsExpanded = true - }; - } - - private static CallViewModel GetCall(ICallContext callContext) - { - return new CallViewModel(callContext.Method, callContext.Arguments, callContext.ReturnValue); - } - - private static SetupViewModel GetSetup( - IProxyCall proxyCall, - IDictionary actualCalls) - { - if (proxyCall.Invoked) - { - var setupCalls = actualCalls.Keys.Where(ac => proxyCall.Matches(ac)) - .Select(ac => GetSetupCall(actualCalls[ac])); - return new SetupViewModel( - proxyCall.SetupExpression.ToStringFixed(), - proxyCall.IsVerifiable, - proxyCall.IsNever, - CreateExpandedContainer("Invocations", setupCalls)); - } - - return new SetupViewModel( - proxyCall.SetupExpression.ToStringFixed(), - proxyCall.IsVerifiable, - proxyCall.IsNever); - } - - private static CallViewModel GetSetupCall(CallViewModel call) - { - call.HasSetup = true; - return call; - } - } +using System; +using System.Collections.Generic; +using System.Linq; +using Moq.Proxy; +using Moq.Visualizer.Properties; + +namespace Moq.Visualizer +{ + [Serializable] + public class MockContextViewModel + { + internal MockContextViewModel(Mock mock) + { + this.Behavior = mock.Behavior; + this.DefaultValue = mock.DefaultValue; + this.CallBase = mock.CallBase; + this.Mocks = new[] { GetMock(mock) }; + } + + public MockBehavior Behavior { get; private set; } + + public bool CallBase { get; private set; } + + public DefaultValue DefaultValue { get; private set; } + + public IEnumerable Mocks { get; private set; } + + private static ContainerViewModel CreateExpandedContainer(string name, IEnumerable children) + { + return new ContainerViewModel(name, children.ToArray()) { IsExpanded = true }; + } + + private static MockViewModel GetMock(Mock mock) + { + var actualCalls = mock.Interceptor.ActualCalls.ToDictionary(ac => ac, i => GetCall(i)); + + var setups = mock.Interceptor.OrderedCalls.Select(s => GetSetup(s, actualCalls)) + .OrderBy(s => s.SetupExpression); + var calls = actualCalls.Values.Where(c => !c.HasSetup); + var innerMocks = mock.InnerMocks.Values.Select(m => GetMock(m)); + + return new MockViewModel( + mock.MockedType, + CreateExpandedContainer(Resources.SetupsContainerName, setups), + CreateExpandedContainer(Resources.OtherCallsContainerName, calls), + CreateExpandedContainer(Resources.MocksContainerName, innerMocks)) + { + IsExpanded = true + }; + } + + private static CallViewModel GetCall(ICallContext callContext) + { + return new CallViewModel(callContext.Method, callContext.Arguments, callContext.ReturnValue); + } + + private static SetupViewModel GetSetup( + IProxyCall proxyCall, + IDictionary actualCalls) + { + if (proxyCall.Invoked) + { + var setupCalls = actualCalls.Keys.Where(ac => proxyCall.Matches(ac)) + .Select(ac => GetSetupCall(actualCalls[ac])); + return new SetupViewModel( + proxyCall.SetupExpression.ToStringFixed(), + proxyCall.IsVerifiable, + proxyCall.IsNever, + CreateExpandedContainer("Invocations", setupCalls)); + } + + return new SetupViewModel( + proxyCall.SetupExpression.ToStringFixed(), + proxyCall.IsVerifiable, + proxyCall.IsNever); + } + + private static CallViewModel GetSetupCall(CallViewModel call) + { + call.HasSetup = true; + return call; + } + } } \ No newline at end of file diff --git a/Visualizer/MockViewModel.cs b/Visualizer/MockViewModel.cs index e86d56d4b..b92c1d29a 100644 --- a/Visualizer/MockViewModel.cs +++ b/Visualizer/MockViewModel.cs @@ -1,21 +1,21 @@ -using System; -using System.Collections.Generic; - -namespace Moq.Visualizer -{ - [Serializable] - public class MockViewModel - { - internal MockViewModel(Type mockedType, params ContainerViewModel[] containers) - { - this.MockedType = mockedType.GetFullName(); - this.Containers = containers; - } - - public bool IsExpanded { get; set; } - - public IEnumerable Containers { get; private set; } - - public string MockedType { get; private set; } - } +using System; +using System.Collections.Generic; + +namespace Moq.Visualizer +{ + [Serializable] + public class MockViewModel + { + internal MockViewModel(Type mockedType, params ContainerViewModel[] containers) + { + this.MockedType = mockedType.GetFullName(); + this.Containers = containers; + } + + public bool IsExpanded { get; set; } + + public IEnumerable Containers { get; private set; } + + public string MockedType { get; private set; } + } } \ No newline at end of file diff --git a/Visualizer/MockVisualizer.cs b/Visualizer/MockVisualizer.cs index 93521e0fd..df3a3058c 100644 --- a/Visualizer/MockVisualizer.cs +++ b/Visualizer/MockVisualizer.cs @@ -1,17 +1,17 @@ -using Microsoft.VisualStudio.DebuggerVisualizers; - -namespace Moq.Visualizer -{ - public class MockVisualizer : DialogDebuggerVisualizer - { - protected override void Show( - IDialogVisualizerService windowService, - IVisualizerObjectProvider objectProvider) - { - using (var visualizer = new MockVisualizerForm(objectProvider.GetObject())) - { - windowService.ShowDialog(visualizer); - } - } - } +using Microsoft.VisualStudio.DebuggerVisualizers; + +namespace Moq.Visualizer +{ + public class MockVisualizer : DialogDebuggerVisualizer + { + protected override void Show( + IDialogVisualizerService windowService, + IVisualizerObjectProvider objectProvider) + { + using (var visualizer = new MockVisualizerForm(objectProvider.GetObject())) + { + windowService.ShowDialog(visualizer); + } + } + } } \ No newline at end of file diff --git a/Visualizer/MockVisualizerForm.Designer.cs b/Visualizer/MockVisualizerForm.Designer.cs index 9bc40c667..0daaca086 100644 --- a/Visualizer/MockVisualizerForm.Designer.cs +++ b/Visualizer/MockVisualizerForm.Designer.cs @@ -1,70 +1,70 @@ -namespace Moq.Visualizer -{ - partial class MockVisualizerForm - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.visualizerHost = new System.Windows.Forms.Integration.ElementHost(); - this.mockVisualizerView = new Moq.Visualizer.MockVisualizerView(); - this.SuspendLayout(); - // - // visualizerHost - // - this.visualizerHost.CausesValidation = false; - this.visualizerHost.Dock = System.Windows.Forms.DockStyle.Fill; - this.visualizerHost.Location = new System.Drawing.Point(0, 0); - this.visualizerHost.Name = "visualizerHost"; - this.visualizerHost.Size = new System.Drawing.Size(453, 305); - this.visualizerHost.TabIndex = 0; - this.visualizerHost.Child = this.mockVisualizerView; - // - // MockVisualizerForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.AutoValidate = System.Windows.Forms.AutoValidate.Disable; - this.CausesValidation = false; - this.ClientSize = new System.Drawing.Size(453, 305); - this.Controls.Add(this.visualizerHost); - this.MinimizeBox = false; - this.Name = "MockVisualizerForm"; - this.ShowInTaskbar = false; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; - this.Text = "Mock Debugger Visualizer"; - this.ResumeLayout(false); - - } - - #endregion - - private System.Windows.Forms.Integration.ElementHost visualizerHost; - private MockVisualizerView mockVisualizerView; - - - - } +namespace Moq.Visualizer +{ + partial class MockVisualizerForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.visualizerHost = new System.Windows.Forms.Integration.ElementHost(); + this.mockVisualizerView = new Moq.Visualizer.MockVisualizerView(); + this.SuspendLayout(); + // + // visualizerHost + // + this.visualizerHost.CausesValidation = false; + this.visualizerHost.Dock = System.Windows.Forms.DockStyle.Fill; + this.visualizerHost.Location = new System.Drawing.Point(0, 0); + this.visualizerHost.Name = "visualizerHost"; + this.visualizerHost.Size = new System.Drawing.Size(453, 305); + this.visualizerHost.TabIndex = 0; + this.visualizerHost.Child = this.mockVisualizerView; + // + // MockVisualizerForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.AutoValidate = System.Windows.Forms.AutoValidate.Disable; + this.CausesValidation = false; + this.ClientSize = new System.Drawing.Size(453, 305); + this.Controls.Add(this.visualizerHost); + this.MinimizeBox = false; + this.Name = "MockVisualizerForm"; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Mock Debugger Visualizer"; + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Integration.ElementHost visualizerHost; + private MockVisualizerView mockVisualizerView; + + + + } } \ No newline at end of file diff --git a/Visualizer/MockVisualizerForm.cs b/Visualizer/MockVisualizerForm.cs index f6b17826b..e50961c99 100644 --- a/Visualizer/MockVisualizerForm.cs +++ b/Visualizer/MockVisualizerForm.cs @@ -1,13 +1,13 @@ -using System.Windows.Forms; - -namespace Moq.Visualizer -{ - public partial class MockVisualizerForm : Form - { - public MockVisualizerForm(object context) - { - this.InitializeComponent(); - this.visualizerHost.HostContainer.DataContext = context; - } - } +using System.Windows.Forms; + +namespace Moq.Visualizer +{ + public partial class MockVisualizerForm : Form + { + public MockVisualizerForm(object context) + { + this.InitializeComponent(); + this.visualizerHost.HostContainer.DataContext = context; + } + } } \ No newline at end of file diff --git a/Visualizer/MockVisualizerForm.resx b/Visualizer/MockVisualizerForm.resx index ff31a6db5..19dc0dd8b 100644 --- a/Visualizer/MockVisualizerForm.resx +++ b/Visualizer/MockVisualizerForm.resx @@ -1,120 +1,120 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + \ No newline at end of file diff --git a/Visualizer/MockVisualizerObjectSource.cs b/Visualizer/MockVisualizerObjectSource.cs index 2e42a752f..93fa33f85 100644 --- a/Visualizer/MockVisualizerObjectSource.cs +++ b/Visualizer/MockVisualizerObjectSource.cs @@ -1,13 +1,13 @@ -using System.IO; -using Microsoft.VisualStudio.DebuggerVisualizers; - -namespace Moq.Visualizer -{ - public class MockVisualizerObjectSource : VisualizerObjectSource - { - public override void GetData(object target, Stream outgoingData) - { - VisualizerObjectSource.Serialize(outgoingData, new MockContextViewModel((Mock)target)); - } - } +using System.IO; +using Microsoft.VisualStudio.DebuggerVisualizers; + +namespace Moq.Visualizer +{ + public class MockVisualizerObjectSource : VisualizerObjectSource + { + public override void GetData(object target, Stream outgoingData) + { + VisualizerObjectSource.Serialize(outgoingData, new MockContextViewModel((Mock)target)); + } + } } \ No newline at end of file diff --git a/Visualizer/MockVisualizerView.xaml b/Visualizer/MockVisualizerView.xaml index 509c52255..e699c1485 100644 --- a/Visualizer/MockVisualizerView.xaml +++ b/Visualizer/MockVisualizerView.xaml @@ -1,50 +1,50 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Visualizer/MockVisualizerView.xaml.cs b/Visualizer/MockVisualizerView.xaml.cs index 8c45a32ff..236b93f94 100644 --- a/Visualizer/MockVisualizerView.xaml.cs +++ b/Visualizer/MockVisualizerView.xaml.cs @@ -1,12 +1,12 @@ -using System.Windows.Controls; - -namespace Moq.Visualizer -{ - public partial class MockVisualizerView : UserControl - { - public MockVisualizerView() - { - this.InitializeComponent(); - } - } +using System.Windows.Controls; + +namespace Moq.Visualizer +{ + public partial class MockVisualizerView : UserControl + { + public MockVisualizerView() + { + this.InitializeComponent(); + } + } } \ No newline at end of file diff --git a/Visualizer/Moq.Visualizer.csproj b/Visualizer/Moq.Visualizer.csproj index b5993d355..701739d7b 100644 --- a/Visualizer/Moq.Visualizer.csproj +++ b/Visualizer/Moq.Visualizer.csproj @@ -1,167 +1,167 @@ - - - - Debug - AnyCPU - 9.0.30729 - 2.0 - {335EAF40-60EF-40D7-84A8-E33D255FA59F} - Library - Properties - Moq.Visualizer - Moq.Visualizer - v4.0 - 512 - true - ..\Moq.snk - - - 3.5 - - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - AllRules.ruleset - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - AllRules.ruleset - - - - - 3.0 - - - 3.0 - - - - 3.5 - - - - - - 3.5 - - - 3.0 - - - 3.0 - - - - - Form - - - MockVisualizerForm.cs - - - - - Code - - - - - - - - True - True - Resources.resx - - - - MockVisualizerView.xaml - - - - - Designer - MSBuild:Compile - MSBuild:Compile - Designer - - - - - Moq.snk - - - - - MockVisualizerForm.cs - - - ResXFileCodeGenerator - Resources.Designer.cs - - - - - False - .NET Framework 3.5 SP1 Client Profile - false - - - False - .NET Framework 3.5 SP1 - true - - - False - Microsoft Visual Basic PowerPacks 10.0 - true - - - False - Windows Installer 3.1 - true - - - - - {1C91AC30-5977-4BE5-BA67-8EB186C03514} - Moq - - - - + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {335EAF40-60EF-40D7-84A8-E33D255FA59F} + Library + Properties + Moq.Visualizer + Moq.Visualizer + v4.0 + 512 + true + ..\Moq.snk + + + 3.5 + + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + AllRules.ruleset + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + AllRules.ruleset + + + + + 3.0 + + + 3.0 + + + + 3.5 + + + + + + 3.5 + + + 3.0 + + + 3.0 + + + + + Form + + + MockVisualizerForm.cs + + + + + Code + + + + + + + + True + True + Resources.resx + + + + MockVisualizerView.xaml + + + + + Designer + MSBuild:Compile + MSBuild:Compile + Designer + + + + + Moq.snk + + + + + MockVisualizerForm.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + true + + + False + Microsoft Visual Basic PowerPacks 10.0 + true + + + False + Windows Installer 3.1 + true + + + + + {1C91AC30-5977-4BE5-BA67-8EB186C03514} + Moq + + + + \ No newline at end of file diff --git a/Visualizer/ParameterViewModel.cs b/Visualizer/ParameterViewModel.cs index 16b93e08c..70da94df2 100644 --- a/Visualizer/ParameterViewModel.cs +++ b/Visualizer/ParameterViewModel.cs @@ -1,31 +1,31 @@ -using System; -using System.Reflection; - -namespace Moq.Visualizer -{ - [Serializable] - public class ParameterViewModel - { - public ParameterViewModel(ParameterInfo parameterInfo, object value) - { - this.Name = parameterInfo.Name; - this.Type = parameterInfo.ParameterType.GetFullName(); - this.IsRef = parameterInfo.ParameterType.IsByRef && parameterInfo.Attributes != ParameterAttributes.Out; - this.IsOut = parameterInfo.ParameterType.IsByRef && parameterInfo.Attributes == ParameterAttributes.Out; - this.IsIn = !parameterInfo.ParameterType.IsByRef; - this.Value = value; - } - - public bool IsIn { get; private set; } - - public bool IsOut { get; private set; } - - public bool IsRef { get; private set; } - - public string Name { get; private set; } - - public string Type { get; private set; } - - public object Value { get; private set; } - } +using System; +using System.Reflection; + +namespace Moq.Visualizer +{ + [Serializable] + public class ParameterViewModel + { + public ParameterViewModel(ParameterInfo parameterInfo, object value) + { + this.Name = parameterInfo.Name; + this.Type = parameterInfo.ParameterType.GetFullName(); + this.IsRef = parameterInfo.ParameterType.IsByRef && parameterInfo.Attributes != ParameterAttributes.Out; + this.IsOut = parameterInfo.ParameterType.IsByRef && parameterInfo.Attributes == ParameterAttributes.Out; + this.IsIn = !parameterInfo.ParameterType.IsByRef; + this.Value = value; + } + + public bool IsIn { get; private set; } + + public bool IsOut { get; private set; } + + public bool IsRef { get; private set; } + + public string Name { get; private set; } + + public string Type { get; private set; } + + public object Value { get; private set; } + } } \ No newline at end of file diff --git a/Visualizer/Properties/AssemblyInfo.cs b/Visualizer/Properties/AssemblyInfo.cs index 62eb5bdc0..d5aff4a3d 100644 --- a/Visualizer/Properties/AssemblyInfo.cs +++ b/Visualizer/Properties/AssemblyInfo.cs @@ -1,29 +1,29 @@ -using System.Diagnostics; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using Moq; -using Moq.Visualizer; - -[assembly: AssemblyTitle("Moq.Visualizer")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyCompany("Clarius Consulting")] -[assembly: AssemblyProduct("Moq.Visualizer")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2009")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -[assembly: ComVisible(false)] - -[assembly: Guid("d1379ca2-5f85-4017-96fe-cd61fa448ff6")] - -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] - -[assembly: DebuggerVisualizer( - typeof(MockVisualizer), - typeof(MockVisualizerObjectSource), - Target = typeof(Mock), - Description = "MOQ Debugger Visualizer")] - +using System.Diagnostics; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using Moq; +using Moq.Visualizer; + +[assembly: AssemblyTitle("Moq.Visualizer")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyCompany("Clarius Consulting")] +[assembly: AssemblyProduct("Moq.Visualizer")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2009")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: ComVisible(false)] + +[assembly: Guid("d1379ca2-5f85-4017-96fe-cd61fa448ff6")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] + +[assembly: DebuggerVisualizer( + typeof(MockVisualizer), + typeof(MockVisualizerObjectSource), + Target = typeof(Mock), + Description = "MOQ Debugger Visualizer")] + [assembly: InternalsVisibleTo("Moq.Visualizer.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001009f7a95086500f8f66d892174803850fed9c22225c2ccfff21f39c8af8abfa5415b1664efd0d8e0a6f7f2513b1c11659bd84723dc7900c3d481b833a73a2bcf1ed94c16c4be64d54352c86956c89930444e9ac15124d3693e3f029818e8410f167399d6b995324b635e95353ba97bfab856abbaeb9b40c9b160070c6325e22ddc")] \ No newline at end of file diff --git a/Visualizer/Properties/Resources.Designer.cs b/Visualizer/Properties/Resources.Designer.cs index 30e72d7aa..0a3ff11b6 100644 --- a/Visualizer/Properties/Resources.Designer.cs +++ b/Visualizer/Properties/Resources.Designer.cs @@ -1,90 +1,90 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.21006.1 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace Moq.Visualizer.Properties { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Moq.Visualizer.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to Inner Mocks. - /// - internal static string MocksContainerName { - get { - return ResourceManager.GetString("MocksContainerName", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Invocations without setup. - /// - internal static string OtherCallsContainerName { - get { - return ResourceManager.GetString("OtherCallsContainerName", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Setups. - /// - internal static string SetupsContainerName { - get { - return ResourceManager.GetString("SetupsContainerName", resourceCulture); - } - } - } -} +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.21006.1 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Moq.Visualizer.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Moq.Visualizer.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Inner Mocks. + /// + internal static string MocksContainerName { + get { + return ResourceManager.GetString("MocksContainerName", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Invocations without setup. + /// + internal static string OtherCallsContainerName { + get { + return ResourceManager.GetString("OtherCallsContainerName", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Setups. + /// + internal static string SetupsContainerName { + get { + return ResourceManager.GetString("SetupsContainerName", resourceCulture); + } + } + } +} diff --git a/Visualizer/Properties/Resources.resx b/Visualizer/Properties/Resources.resx index ebf80601c..0cec23ed7 100644 --- a/Visualizer/Properties/Resources.resx +++ b/Visualizer/Properties/Resources.resx @@ -1,129 +1,129 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Inner Mocks - - - Invocations without setup - - - Setups - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Inner Mocks + + + Invocations without setup + + + Setups + \ No newline at end of file diff --git a/Visualizer/SetupViewModel.cs b/Visualizer/SetupViewModel.cs index 6a2ac4a40..9a9629785 100644 --- a/Visualizer/SetupViewModel.cs +++ b/Visualizer/SetupViewModel.cs @@ -1,34 +1,34 @@ -using System; -using System.Collections.Generic; - -namespace Moq.Visualizer -{ - [Serializable] - public class SetupViewModel - { - internal SetupViewModel( - string setupExpression, - bool isVerifiable, - bool isNever, - params ContainerViewModel[] containers) - { - this.SetupExpression = setupExpression; - this.IsNever = isNever; - this.IsVerifiable = isVerifiable; - this.Containers = containers; - } - - public IEnumerable Containers { get; private set; } - - public bool IsExpanded - { - get { return false; } - } - - public bool IsNever { get; private set; } - - public bool IsVerifiable { get; private set; } - - public string SetupExpression { get; private set; } - } +using System; +using System.Collections.Generic; + +namespace Moq.Visualizer +{ + [Serializable] + public class SetupViewModel + { + internal SetupViewModel( + string setupExpression, + bool isVerifiable, + bool isNever, + params ContainerViewModel[] containers) + { + this.SetupExpression = setupExpression; + this.IsNever = isNever; + this.IsVerifiable = isVerifiable; + this.Containers = containers; + } + + public IEnumerable Containers { get; private set; } + + public bool IsExpanded + { + get { return false; } + } + + public bool IsNever { get; private set; } + + public bool IsVerifiable { get; private set; } + + public string SetupExpression { get; private set; } + } } \ No newline at end of file