Public
Class
PrivateMethodDoInstead
Private
Function
GetSomeQuantity(
ByRef
quantity
As
Long
)
As
Boolean
'....get quantity from the database code would be here
Return
quantity > 0
End
Function
Public
Function
HandleRecords()
As
Boolean
Dim
quantity
As
Long
Dim
returnValue
As
Boolean
= GetSomeQuantity(quantity)
If
returnValue
Then
StoreTotals(quantity)
End
If
Return
returnValue
End
Function
Private
Sub
StoreTotals(quantity
As
Long
)
' do something
End
Sub
End
Class
Mock.Arrange(
Function
() testInstance.GetSomeQuantity(
Arg.IsAny(Of
Long
))
).DoInstead(
Function
(
ByRef
quantity
As
Long
)
As
Boolean
quantity = 5
Return
True
End
Function
).Returns(
True
)
I had a first try with JustMock on a Linux build machine (Jenkins) and xunit (Mono 4.6 is installed there). Unfortuntely, I get the following exception (one of them):
01.
Tnsa.Foundation.Test.Composition.Internal.CompositionContextServiceProviderAdapterTest.GetService_ExportFactories_enumerable_generic_2_success [FAIL]
02.
System.Runtime.Remoting.RemotingException : Cannot get the real proxy from an object that is not a transparent proxy.
03.
Stack Trace:
04.
at System.Runtime.Remoting.RemotingServices.GetRealProxy (System.Object proxy) [0x0000b] in <
94fd79a3b7144c54b4cb162b50fc7761
>:0
05.
at Telerik.JustMock.Core.TransparentProxy.MockingProxy.GetRealProxy (System.Object instance) [0x00005] in <
45764d21e4e34d73b89fbb0a6b2e6054
>:0
06.
at Telerik.JustMock.Core.TransparentProxy.MockingProxy.GetMockMixin (System.Object instance) [0x00000] in <
45764d21e4e34d73b89fbb0a6b2e6054
>:0
07.
at Telerik.JustMock.Core.MocksRepository.GetMockMixinFromAnyMock (System.Object mock) [0x00000] in <
45764d21e4e34d73b89fbb0a6b2e6054
>:0
08.
at Telerik.JustMock.Core.MocksRepository.GetMockMixin (System.Object obj, System.Type objType) [0x00000] in <
45764d21e4e34d73b89fbb0a6b2e6054
>:0
09.
at Telerik.JustMock.Core.MocksRepository.ConvertExpressionToCallPattern (System.Linq.Expressions.Expression expr, Telerik.JustMock.Core.CallPattern callPattern) [0x00564] in <
45764d21e4e34d73b89fbb0a6b2e6054
>:0
10.
at Telerik.JustMock.Core.MocksRepository.Arrange[TMethodMock] (System.Linq.Expressions.Expression expr, System.Func`1[TResult] methodMockFactory) [0x00049] in <
45764d21e4e34d73b89fbb0a6b2e6054
>:0
11.
at Telerik.JustMock.Helpers.FluentHelper.DoArrange[TContainer] (System.Object obj, System.Type objType, System.Linq.Expressions.LambdaExpression expression, System.Func`1[TResult] containerFactory) [0x00036] in <
45764d21e4e34d73b89fbb0a6b2e6054
>:0
12.
at Telerik.JustMock.Helpers.FluentHelper+<>c__DisplayClass2`2[T,TResult].<
Arrange
>b__0 () [0x0002e] in <
45764d21e4e34d73b89fbb0a6b2e6054
>:0
13.
at Telerik.JustMock.Core.ProfilerInterceptor.GuardInternal[T] (System.Func`1[TResult] guardedAction) [0x0000c] in <
45764d21e4e34d73b89fbb0a6b2e6054
>:0
14.
at Telerik.JustMock.Helpers.FluentHelper.Arrange[T,TResult] (T obj, System.Linq.Expressions.Expression`1[TDelegate] expression) [0x00020] in <
45764d21e4e34d73b89fbb0a6b2e6054
>:0
15.
at Tnsa.Foundation.Test.Composition.Internal.CompositionContextServiceProviderAdapterTest.GetService_ExportFactories_enumerable_generic_2_success () [0x0006f] in <
e1aa8dcdd51045fda2db8ea7350c0c44
>:0
16.
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
17.
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in <
94fd79a3b7144c54b4cb162b50fc7761
>:0
Is this scenario supported on Linux/Mono at all? Can I do something to make this work?
Thanks, Ioan
For some reason, the ReturnsMany method does not work for me. I have the follwing code:
List<ORGANIZATION> existingOrganizations =
new
List<ORGANIZATION>()
{
new
ORGANIZATION() {ID = 1, NAME =
"Organization1"
, ISINCLUDEDINSAMPLE =
false
},
new
ORGANIZATION() {ID = 2, NAME =
"Organization2"
, ISINCLUDEDINSAMPLE =
false
},
new
ORGANIZATION() {ID = 3, NAME =
"Organization3"
, ISINCLUDEDINSAMPLE =
false
},
};
container.Arrange<IOrganizationRepository>(or => or.GetById(Arg.AnyLong)).ReturnsMany(existingOrganizations);
And the exception I'm getting:
System.InvalidCastException : Unable to cast
object
of type
'System.Collections.Generic.List`1[Cpims.WFM.Domain.Organizations.ORGANIZATION]'
to type
'Cpims.WFM.Domain.Organizations.ORGANIZATION'
.
at Castle.Proxies.IOrganizationRepositoryProxy.GetById(Int64 primaryKey, Expression`1[] includeNavigationProperties)
In a method like
void ReturnIfObjectIsNull()
{
var obj = new SomeObject();
if (obj == null)
return;
// Do other stuff..
}
How do I assert that the early return fired (without asserting that the stuff that would have happened afterword never occurred).
Asserting the object is null is not enough. I would need to assert that he function returned early when the object was null.
Thanks.
// Obtain an HTTP web Request object for the desired URI
var Request = WebRequest.Create(strUri)
as
HttpWebRequest;
if
(Request !=
null
)
{
Request.KeepAlive =
false
;
Request.Method =
"GET"
;
Request.ContentType =
"application/ems-v3+xml"
;
// Obtain the HTTP web response
using
(var Response = Request.GetResponse()
as
HttpWebResponse)
{
// Read the response text stream (the XML) into a local string
if
(Response !=
null
)
using
(var ResponseStreamReader =
new
StreamReader(Response.GetResponseStream()))
{
//get XML Result
result = ResponseStreamReader.ReadToEnd();
}
}
}
Hi All,
I have started using JustMock Few days back in my solution. and Now I am trying to Integrate this into my Build Definition which is in VSO.
Any Idea how we can Integrate JustMock with my Solution.
Note: I cannot Install this JustMock on my Build Server.
JustMock R3 2016 (2016.3.914.2)
The below test will pass when the second ArrangeSet should fail instead. I tried reporting the issue through VS2013 but I got a CommunicationException error: The server did not provide a meaningful reply.
[TestMethod]
public void Test()
{
var pageMock = Mock.Create<IPage>()
Mock.ArrangeSet(() => pageMock.WebControl1.Enabled = false).OccursNever();
Mock.ArrangeSet(() => pageMock.WebControl2.Enabled = false).MustBeCalled();
Mock.Assert(pageMock);
}
JustMock Q2 2016 SP1 (2016.2.713.2)
I have the JustMock license. I installed JustMock (the JustMock_2016_2_713_2_Dev.msi file). Also I downloaded and extracted the `JustMock_2016_2_713_2_Help3.zip` file. Now I launch the `Install_TelerikJustMock.bat` file but I get the error message:
> Error: It isn't possible to find the specified section or parameter in the register.
> Ensuring same version not registered...
> ""\HelpLibManager.exe"" isn't internal or external
> command, runtime program or batch file.
> Registering the new version...
> ""\HelpLibManager.exe"" isn't internal or external
> command, runtime program or batch file.
> Done.
> Press any key for exit...