How do I check if Create was not called without using the Rhino Mocks AssertWasNotCalled method.
Here is the test:
[Test]
public void When_try_to_create_directory_that_already_exits_return_false()
{
var directoryInfoMock = MockRepository.GenerateMock<IDirectoryInfoWrap>();
directoryInfoMock.Stub(x => x.Exist...
I have a security rule that a newly registered user has full permissions over their own user entity. I'm using Rhino.Security and the code works fine, but I want to create a unit test to make sure the appropriate call is made to setup the permission. Here is a simplified verison of the code:
public User Register(UserRegisterTask userR...
In the code below, if I understand it correctly, I am stubbing the Speed property and setting it to 0 which should call the Stop method, but when I run the test, it is saying that it expected Stop to be called, but it was not called. Here is the code:
public class Car
{
public virtual int Speed { get; set; }
public virtual b...
Hello. I have an integration test LoadFile_DataLoaded_Succefully(). And I want to refactor it to the unit test for breaking dependency with filesytem.
P.S. I am new in TDD:
Here are my production class :
public class LocalizationData
{
private bool IsValidFileName(string fileName)
{
if (fileName.ToLower().EndsWith("...
I am playing around with MbUnit and Rhino Mocks and made a simple test. It may be poorly designed code, but I am more focused on just seeing if I can get the test to pass. Basically, When the engine light of a car is on, the car should an oil change. Here is code:
public interface ICar
{
bool EngineLight { get; set; }
void Get...
I have the following test to verify that my repository is calling it's respective session (I've rewritten it to highlight the actual problem):
[Test]
public void Why_Does_This_Fail()
{
var objectUnderTest = new SomeGenericsProblem();
var fakeSession = MockRepository.GenerateMock<ISession>();
fakeSession....
Here is the code:
public interface IAccessPoint
{
int BackHaulMaximum { get; set; }
bool BackHaulMaximumReached();
void EmailNetworkProvider();
}
public class AccessPoint : IAccessPoint
{
public int BackHaulMaximum { get; set; }
public bool BackHaulMaximumReached()
{
if (BackHaulMaximum > 80)
...
Here is code:
public interface IAccessPoint
{
int BackHaulMaximum { get; set; }
bool BackHaulMaximumReached();
void EmailNetworkProvider();
}
public class AccessPoint : IAccessPoint
{
private IMailProvider Mailer { get; set; }
public AccessPoint(IMailProvider provider)
{
this.Mailer = provider ?? new D...
I have read a lot about mocking, particularly using Rhino Mocks and have learned that Rhino Mocks can only mock interface methods which are virtual or virtual methods in concrete classes. I have read that the reason for this is because Rhino mocks can't intercept non-virtual methods and this is where I am stuck. What does it mean by in...
My company is trying to decide if we are going to standardize on Moq, Rhino Mocks or MS Moles and Stubs.
I know Rhino Mocks and Moles and Stubs fairly well. But I am unfamiliar with Moq. How does the syntax work? Does it support Arrange Act Assert (AAA) like Rhino Mocks (I hear they created it, but I am not sure). Does it have stron...
I have the following class structure that I need to unit test:
public interface IFoo
{
int Value { get;}
int GetValue();
}
public class BaseClass : IFoo
{
public virtual int Value { get { return 100; } }
public virtual int GetValue()
{
return Value;
}
}
public class ChildClass : BaseClass, IFoo
{
pu...
I'm trying to figure out how to unit test my object that persists itself to session state.
The controller does something like...
[HttpPost]
public ActionResult Update(Account a)
{
SessionManager sm = SessionManager.FromSessionState(HttpContext.Current.Session);
if ( a.equals(sm.Account) )
sm.Acco...
Hello,
we have a weired problem when using Rhino Mocks and Threads. I've
tried to isolate the problem, but now I'm stuck to this:
[TestClass]
public class FoolTests
{
[TestMethod]
public void TestMethod_Scenario_Result()
{
for (int i = 0; i < 5; i++)
{
var fool = MockRepository.GenerateStub<IFool>();
...
Hi all,
I'm wondering how can I mock IO/Network classes. For example I have a class that do FTP operations or a class that writes into a file. How can I use mocking to mock and unit test such classes?
I'm a C#/NHibernate/Castle ActiveRecord/Rhino Mocks developer.
...
I am trying to use the AAA syntax in Rhino Mocks with VB.Net to validate that a method was called only one time. I can't seem to get it right. With this code, if the repository is called twice, it returns nothing on the second call, and the test passes. I would have expected the test to fail when VerifyAllExpectations was called.
<Te...
I've been using TDD/SSR for a while. I'm trying to transition to BDD: context, becauseOf, and Asserts.
I'm using Rhino Mocks to isolate, and I'm struggling with syntax now. Here's what I've got so far (note: ContextSpecification class source):
public static class DocumentIdAdapterTests {
public class DocumentIdAdapterContext : Co...
Hello,
I'm trying to mock an interface's events like the following:
[TestMethod]
public void NeedingDataFiresEvents()
{
//Arrange
var service = MockRepository.GenerateMock<IService>();
service.Expect(i => i.GetValue()).Return(5);
var view = MockRepository.GenerateMock<ILogView>();
view.NeedData += null;
LastCall...
Hello, I have following extension method written:
static public IQueryable<OutboundPattern> ByClientID(this IQueryable<OutboundPattern> qry, int clientID)
{
return from p in qry
where p.ClientID == clientID
select p;
}
I also have the following service layer method written:
public I...
I have custom event logger, and I want to test it.
[Test]
public void AddLogWithExceptionAndEventLogEntryTypeTest()
{
const string loggerName = "mockLoggerName";
var logger = new MyLogger(loggerName);
System.Diagnostics.EventLog log = new System.Diagnostics.EventLog("System");
string log...
I want to create an IList of objects that are all different concrete types, so:
var tasks = new List<ITask>();
foreach (string taskName in taskNames)
{
var task = MockRepository.GenerateStub<ITask>();
task.Stub(t => t.Name).Return(taskName);
tasks.Add(task);
}
return tasks;
The problem is that each stub object is all the s...