Questions tagged [rhino-mocks]
Rhino.Mocks is a dynamic mock object framework for the .NET platform. Rhino.Mock's purpose is to ease testing by allowing the developer to create mock implementations of custom objects and verify the interactions using unit testing.
1,222
questions
0
votes
1
answer
13
views
How to use the Stub in Rhino.Mocks to simulate System functions
In unit testing, I often use Stub to mock third-party functions.
But I don't know how to Stub a code like this.
enter image description here
I want to control the return value of registry.
I tried to ...
0
votes
2
answers
1k
views
c# unit test httpclient postasync
I am very new to Testing. I am trying to understand how can I unit test since I do not really need to actually trigger these services but probably mock every step.
How can I unit test the following ...
1
vote
1
answer
73
views
Unit testing DelegateCommand using Rhino Mock
I am trying to unit test a command execution for a command that displays a dialog, however I keep getting NullReferenceException and I do not know why. Any suggestion would be appreciated.
The ...
2
votes
1
answer
91
views
Making RhinoMock Stub Return Value Dependent on a Paramter
Is it possible to set a "default" return value for a RhinoMock stub?
For ex: I have a method that takes in an int from 1-175 and returns a bool:
internal bool myFunction(int number)
I want ...
0
votes
0
answers
375
views
This action is invalid when the mock object is in replay state
I'm converting MSUnit test to XUnit.
public class ClassName
{
protected IDomainQueries MockILogQueries { get; private set; }
protected IQueryContext MockQueryContext { get; private set; }
...
0
votes
0
answers
47
views
C# Stubbing HttpApplicationCompleteRequest() causing NullReferenceException
I have this setup in my unit test
HttpApplication application = MockRepository.GenerateStub<HttpApplication>();
application.Stub(a => a.CompleteRequest());
And when I run the tests it throws ...
6
votes
2
answers
1k
views
can't stub class with NullableContextAttribute
I'm using a third party library which has some classes I'm trying to mock using Rhino Mocks. When I attempt to create a stub for a class, I'm getting the following error. I cna't find a reference to ...
0
votes
2
answers
230
views
Replacement Rhino Mocks GetArgumentsForCallsMadeOn() for Moq Callback() not receiving original arguments
I am trying to replace this Rhino Mocks implementation:
private bool IsHandshakeCalled()
{
var args = httpExecutorBuilderStub.GetArgumentsForCallsMadeOn(st => st.ExecuteHttpWebRequestAndReturn(
...
1
vote
1
answer
236
views
Rhino Mocks exception "Expected #1, Actual #0" in apparently working code
I have a piece of code from an old book on MVVM which works, but a test using Rhino Mocks fails with this message:
Test method TestProject.UnitTest1.UpdateCustomer_Always_CallsUpdateWithCustomer ...
0
votes
0
answers
28
views
Rhino Mocks: Expect a method call after property set
I have a class to test that associates with an interface:
interface IMyFactory
{
int MyProperty {get; set;}
int Create(int x);
}
class ClassToTest
{
public IMyFactory Factory {get; set;}
...
0
votes
1
answer
152
views
Rhino Mocks use input parameters of stubbed function to create return value
I have two interfaces:
interface ITimeframe
{
DateTime beginTime {get;}
DateTime endTime {get;}
}
interface ITimeframeFactory
{
ITimeframe Create(Datetime beginTime, DateTime endTime);
}...
1
vote
1
answer
155
views
How do you stub a method that accepts an IEnumerable in RhinoMocks?
I've got a SqlLayer class I'm trying to Mock that has a GetDataReader method that accepts a string query and an IEnumerable of SqlParameters. I've tried stubbing out the method call like this:
var ...
0
votes
0
answers
136
views
How to handle mocking (Rhino Mock) and unity container in different unit test classes?
I am working on a large desktop application. The application communicates with number of external services and application is using Unity container to resolve the objects. I am facing issue in writing ...
0
votes
0
answers
36
views
Rhino Mocks: reset recorded call
I have a method CreateGraph(DateTime) that takes a long time to execute.
I don't want to call it if not needed, hence, it the input parameter is not changed, I do not want to call CreateGraph, but ...
2
votes
1
answer
278
views
Unit Test INotifyPropertyChanged using Rhino Mocks
I have a class that implements INotifyPropertyChanged and I need to test if this interface is implemented correctly. I want to do this using a Rhino Mock object.
class MyClass : ...
0
votes
1
answer
175
views
Rhino mocks AssertWasCalled does not work
I wrote the following test case to illustrate my problem using Rhino Mocks:
[TestClass]
public class Tester
{
public class TestList<T> : List<T>
{
public override bool ...
11
votes
2
answers
14k
views
Simulating CancellationToken.IsCancellationRequested when unit testing
I would like to test a task that is supposed to run continuously until killed. Suppose the following method is being tested:
public class Worker
{
public async Task Run(CancellationToken ...
1
vote
1
answer
62
views
Testing a property set to an instance of a new object in Rhino Mocks 3.4.0
Background
I'm fixing unit tests which have been neglected for a long time for legacy code in our organisation. They're written using Rhino Mocks 3.4.0, and I'm struggling to find a way of making ...
0
votes
1
answer
347
views
Convert Rhino Mock to NSubstitute
currently I am changing some implementation of Rhino Mock to NSubstitute. Now I have some difficulty here.
could someone help me ?
var provider = MockRepository.GenerateStub<IProvider&...
0
votes
1
answer
419
views
Rhino Mocks Stub not calling .WhenCalled action
I'm writing unit tests using NUnit and Rhino Mocks to generate a stub. I'd like to use the .WhenCalled method to control the return value of a stubbed method. It works as expected when I pass a lambda ...
1
vote
1
answer
261
views
How to set a default return value in a Rhino Mocks stub
Say I want to use Rhino Mocks to generate a stub of the following interface:
public interface IFooBar
{
string Foo(string bar);
}
I stub the method Foo in the one-time setup method for my suite of ...
1
vote
2
answers
195
views
How to ensure that a method is not called anymore in RhinoMocks?
I have a code which looks like example below:
public interface IDependency
{
void Foo();
}
public class MainClass{
Timer tmr = new Timer(100);
IDependency dependency;
public ...
0
votes
0
answers
211
views
How to test when "as" type casting is used in Rhino Mocks
I am using Rhino mocks to unit test, and I have a statement like the below in my code
Class1 message =
msg as Class1;
message.X="jdjk";
msg is of type Imsg and it is been ...
2
votes
1
answer
1k
views
Mocking ASPNET MVC DependencyResolver with Rhino mock
While writing a unit test for one of the business logic(method), not able to mock ASP NET MVC DependencyResolver due to that getting null for this. Below is the line of code
DependencyResolver....
2
votes
0
answers
118
views
When should I use GeneratePartialMock and GenerateStub in Rhino.Mocks?
I'm trying to test a virtual method and while debuging in VS 2017, I can't enter the method to see what it is doing. It seems like the method isn't being called because I've instantiated it with ...
2
votes
1
answer
412
views
What is Moq's equivalent of LastCall in RhinoMocks?
I'm upgrading to .Net Core which involves converting a number of unit tests from RhinoMocks to Moq since it supports .Net Standard.
I've been converting LastCall by repeating the most recent mocked ...
0
votes
1
answer
103
views
How to test functionality using unit test if flow is event based in C#?
I am writing a unit test for a flow which is event based. Let me tell you the complete flow with code. I have a application App1 which send some commands(one way) to App2. Then App2 sends events after ...
0
votes
1
answer
592
views
The same Moq SetupSequence is being used for different objects
Edit: Solved
The code is actually fine. Actually the method being evaluated actually is called more than once. But then Rhino Mocks Repeat.Once() don't show proper behavior...
I'm migrating from ...
1
vote
1
answer
147
views
What is the correct way to create a stub/mock for the Scheme property present under Uri in Rhinomocks
I'm writing a Unit Test case for a c# method with the help of Rhinomocks framework. Inside my actual method I access the Scheme property from the Uri property present under System.Net.Http....
0
votes
1
answer
432
views
Exception in constructor: Rhino.Mocks.Exceptions.ExpectationViolationException: Expected #0, Actual #1
I had a working Rhino Mock test for this constructor
public MyClassDataAccess(IMyClassLogger logger)
{
_logger = logger ?? throw new ArgumentNullException("logger");
}
Here's the ...
1
vote
1
answer
138
views
RhinoMock - AssertWasCalled on same method with different parameter doesn't work
I have this method:
public void Handle(ShipmentConfirmedEvent message)
{
try
{
var trackingOrderDto = new ShipmentConfirmedDto
{
...
2
votes
2
answers
4k
views
How to mock the class object which is created inside a method using new keyword in MOQ
I am using Moq to write a unit test cases.
Code:
public class SavingAccount
{
public void Data()
{
//Some logic
}
}
public class Account
{
public void ...
0
votes
1
answer
269
views
Mock Stub and Moq Setup act differently ? What is the equivalent of Stub in Moq?
I realized while writing unit testing in two different projects that the behavior of setup in Moq is different than Stub in Rhino-Mocks.
One class uses Mock which has one of these scenarios where I ...
1
vote
1
answer
217
views
NUnit Test method with Rhino mocks does not work - C#
I have created a web api project and implemented the below HTTP POST method in AccountController and the related service method & repository method in AccountService & AccountRepository ...
1
vote
0
answers
27
views
Rhino mocks sub method always returns null
here is my unit test code:
var aFake = new A(false);
var bFake = new B(aFake);
var mock = MockRepository.GenerateMock<IC>();
mock.Stub(x => x.GetTypeB()).Return(bFake);
And when it gets ...
0
votes
1
answer
78
views
Use Rhino Mocking to unit test delete functionality
I am using Rhino mocking for unit testing to test a method that deletes a transport.However I am unsure how to test it. Below is what I have but it is failing (Assert.AreEqual is failing as result ...
1
vote
1
answer
846
views
Rhino Mocks async unit testing
Environment
Rhino Mocks version: 3.6.1
Visual Studio: 2017
Resharper: 2017.3.3
Nunit: 2.6.4
I run the 2 test fixtures together using Resharper. When I do so I get an error:
System....
2
votes
1
answer
457
views
How to mock a protected method in base class using Rhino?
internal abstract class ClassB: IInterface
{
protected void Execute();
}
abstract class ClassA : ClassB
{
public void methodToUT()
{
---logic that I want to unit test----
...
1
vote
0
answers
4k
views
Rhino Mock compatibility with .NetCore
I was working on Azure functions with.Net f/w and my unit test cases were running fine. Unit test cases were using Rhino Mock. After migrating it to.Net Core, these test cases are giving runtime ...
2
votes
1
answer
254
views
Unit Test (Rhino) DBUp in Azure Durable HTTPStart Method
Technology Stack
DBUP for DB upgrades
Azure Durable for activities
Rhino mocks for unit testing.
Situation
Currently, I have placed my DB Upgrade (DBUp) statements in the HTTPStart method as its ...
0
votes
1
answer
648
views
RhinoMocks Expect not working as 'expected'
I have the following test code
//setup the mock
SomeResource mock = MockRepository.GenerateMock<SomeResource>();
mock.Stub(m => m.GetNumOfResources()).Return(1);
mock.Stub(m => m.SomeProp)...
0
votes
0
answers
132
views
Rhino mocks AssertWasNotCalled extracted to generic method fails
I was trying to implement common extension "shortcut" method to check if Dispose() was not called on the mock (Rhino):
public static void AssertNotDisposed<T>(this T disposable) where T : ...
0
votes
2
answers
246
views
Faking Stream for sealed PngBitmapEncoder
This is a follow up question to Unit testing with I/O dependencies.
How do I make PngBitmapEncoder to accept wrapped/mocked FileStream?
In BitmapService.SaveBitmapAsPngImage() I want to assert that ...
0
votes
0
answers
93
views
How to mock ObjOutlookApplication.Session.Stores using Moq.Mock or Rhino.Mocks
I am developing Outlook Addin using c# code. I am writing a unit test case for the below-listed method. I am stuck at one point.
Can anyone help me to write a unit test case for the below-listed ...
1
vote
1
answer
831
views
Unit testing with I/O dependencies
I would like to test the following class but I/O and sealed class dependencies are making it quite hard.
public class ImageDrawingCombiner
{
/// <summary>
/// Save image to a ...
1
vote
1
answer
41
views
Mock IOC Unity Object Creation call
public class ExcelHelper : IExcelHelper
{
private ICustomLoadRepository _customLoadRepository;
public ExcelHelper(IUnityContainer unityContainer)
{
_customLoadRepository= ...
-1
votes
1
answer
323
views
How to ignore a call of a method inside another method?
I'm using Rhinomock in C#, I would like to ignore a call inside a method. Lets see, Does anybody knows how to ignore (or skip) the method MyMethodToIgnore in following code sample? Is that posible ...
1
vote
1
answer
549
views
RhinoMock - mocking multiple stubs for the same class
Say I have a class that is being called from within my MainClass method that I am testing.
public class MainClass
{
private readonly SubClass;
// constructor not shown
public method ...
0
votes
0
answers
485
views
Unit Testing .NET Standard injection results in "wrong type"
I have a .NET Standard 2.0 DLL, and a Unit Test Assembly (.NET 4.7.1 full framework).
In my Standard DLL, I have a constructor that allows my test to inject a fake HttpClient:
public Constructor(...
0
votes
2
answers
1k
views
C# Mock the object and expect its constructor to return mocked object using Rhino Mocks
I have an object which I initialize inside using block to dispose few things. Then later inside using block I am calling some method of that object.
public void MyMethod()
{
using(var obj = new ...