Comments (4)
Thank you for the reporting!
It seems that you copy the settings to wrong Stub Settings File.
Which the assembly does the member belong?
You can only write the settings to the Stub Settings File that is generated from the assembly that the member belongs. For example, the settings for System.DateTime.Now
can only write to mscorlib.v4.0.30319.v4.0.0.0.prig
. MessageBox.Show
must be into System.Windows.Forms.v4.0.30319.v4.0.0.0.prig
.
from prig.
@urasandesu I am using Visual Studio 2015 and MSTest.
from prig.
Thanks @urasandesu , I got it. Sorry, i missed that part in the Readme. The build is successful and i am able to get the Prig class in my test. But, i have some other doubts.
Eg. I have a class calculator and 2 methods: Add and Multiply
public class Calculator
{
public int Add(int a, int b)
{
int c = Multiply(a, b);
return a + b + c;
}
public int Multiply(int a, int b)
{
return a * b;
}
}
The settings are there in the Stub File as:
<stubs>
<!--
PCalculator.AddInt32Int32().Body =
args =>
{ // args[0]: global::TapeManager.Calculator @this, args[1]: global::System.Int32 a, args[2]: global::System.Int32 b
throw new NotImplementedException();
};
-->
<add name="AddInt32Int32" alias="AddInt32Int32">
<RuntimeMethodInfo xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:x="http://www.w3.org/2001/XMLSchema" z:Id="1" z:FactoryType="MemberInfoSerializationHolder" z:Type="System.Reflection.MemberInfoSerializationHolder" z:Assembly="0" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" xmlns="http://schemas.datacontract.org/2004/07/System.Reflection">
<Name z:Id="2" z:Type="System.String" z:Assembly="0" xmlns="">Add</Name>
<AssemblyName z:Id="3" z:Type="System.String" z:Assembly="0" xmlns="">TapeManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</AssemblyName>
<ClassName z:Id="4" z:Type="System.String" z:Assembly="0" xmlns="">TapeManager.Calculator</ClassName>
<Signature z:Id="5" z:Type="System.String" z:Assembly="0" xmlns="">Int32 Add(Int32, Int32)</Signature>
<Signature2 z:Id="6" z:Type="System.String" z:Assembly="0" xmlns="">System.Int32 Add(System.Int32, System.Int32)</Signature2>
<MemberType z:Id="7" z:Type="System.Int32" z:Assembly="0" xmlns="">8</MemberType>
<GenericArguments i:nil="true" xmlns="" />
</RuntimeMethodInfo>
</add>
<!--
PCalculator.MultiplyInt32Int32().Body =
args =>
{ // args[0]: global::TapeManager.Calculator @this, args[1]: global::System.Int32 a, args[2]: global::System.Int32 b
throw new NotImplementedException();
};
-->
<add name="MultiplyInt32Int32" alias="MultiplyInt32Int32">
<RuntimeMethodInfo xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:x="http://www.w3.org/2001/XMLSchema" z:Id="1" z:FactoryType="MemberInfoSerializationHolder" z:Type="System.Reflection.MemberInfoSerializationHolder" z:Assembly="0" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" xmlns="http://schemas.datacontract.org/2004/07/System.Reflection">
<Name z:Id="2" z:Type="System.String" z:Assembly="0" xmlns="">Multiply</Name>
<AssemblyName z:Id="3" z:Type="System.String" z:Assembly="0" xmlns="">TapeManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</AssemblyName>
<ClassName z:Id="4" z:Type="System.String" z:Assembly="0" xmlns="">TapeManager.Calculator</ClassName>
<Signature z:Id="5" z:Type="System.String" z:Assembly="0" xmlns="">Int32 Multiply(Int32, Int32)</Signature>
<Signature2 z:Id="6" z:Type="System.String" z:Assembly="0" xmlns="">System.Int32 Multiply(System.Int32, System.Int32)</Signature2>
<MemberType z:Id="7" z:Type="System.Int32" z:Assembly="0" xmlns="">8</MemberType>
<GenericArguments i:nil="true" xmlns="" />
</RuntimeMethodInfo>
</add>
<!--
PCalculator.Constructor().Body =
args =>
{ // args[0]: global::TapeManager.Calculator @this
throw new NotImplementedException();
};
-->
<add name="Constructor" alias="Constructor">
<RuntimeConstructorInfo xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:x="http://www.w3.org/2001/XMLSchema" z:Id="1" z:FactoryType="MemberInfoSerializationHolder" z:Type="System.Reflection.MemberInfoSerializationHolder" z:Assembly="0" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" xmlns="http://schemas.datacontract.org/2004/07/System.Reflection">
<Name z:Id="2" z:Type="System.String" z:Assembly="0" xmlns="">.ctor</Name>
<AssemblyName z:Id="3" z:Type="System.String" z:Assembly="0" xmlns="">TapeManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</AssemblyName>
<ClassName z:Id="4" z:Type="System.String" z:Assembly="0" xmlns="">TapeManager.Calculator</ClassName>
<Signature z:Id="5" z:Type="System.String" z:Assembly="0" xmlns="">Void .ctor()</Signature>
<Signature2 z:Id="6" z:Type="System.String" z:Assembly="0" xmlns="">.ctor()</Signature2>
<MemberType z:Id="7" z:Type="System.Int32" z:Assembly="0" xmlns="">1</MemberType>
<GenericArguments i:nil="true" xmlns="" />
</RuntimeConstructorInfo>
</add>
</stubs>
I am trying to write test case for Addition using MSTest:
1. [TestClass()]
2. public class CalculatorTests
3. {
4. [TestMethod()]
5. public void AddTest()
6. {
7. using (new IndirectionsContext())
8. {
9. int a = 10, b = 3, c = 4;
10. PCalculator.MultiplyInt32Int32().Body = ???????????
11. int actual = new Calculator().Add(a, b);
12. }
13. Assert.Fail();
14. }
15. }
In line 10, i am getting that we are trying to give the definition of the method at run-time. In the Stub Setting file, the MultiplyInt32Int32() takes 3 args. How to pass those args. I have tried many ways but it is giving an error that cannot implicit convert to Work.
Please tell me how to use this and one more thing, if i do not want to write a body of the method and just want to return something, suppose i want Multiply(a,b) should return c,something like,
PCalculator.MultiplyInt32Int32().Return = 10;
How to make it work ?
Thanks in advance
from prig.
It seems that you create the stub against a non-public member (see our wiki section Indirection Delegate).
I guess that you copied the setting from the old assembly that is before you make the class public. Try to refresh assembly and copy the setting again.
from prig.
Related Issues (20)
- install the prig without visual studio HOT 5
- Mocking not working at all under VS 2015 Professional (Windows 7 Pro SP1) HOT 1
- Cannot re-register after unregistering Prig
- Cannot target x86 architecture on a x64 machine
- Houston is anyone there? HOT 1
- This project is now dead? HOT 1
- Support Run All HOT 4
- Problem debugging prig MSTests with ReSharper test runner HOT 4
- TeamCity Support HOT 7
- Prig test run crashing (when a nested static, unstubbed method is called) HOT 40
- MsTest: The method of generic type that has declaring type parameter excluding this cannot detour HOT 1
- MsTest: Test runner will crash when stubbing a shared member that shouldn't matter HOT 8
- Add Prig Assembly is failed immediately after installation
- Visual Studio 2017 support HOT 18
- From VS IDE unable to successfully run multiple test projects HOT 2
- Cannot uninstall Prig except for en-us locale environment
- Dotnet core support HOT 2
- How would i use this on CI HOT 1
- Stub a method of the parent type HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prig.