I'm using the AAA-pattern and Rhino mocks for my unit-testing. I want to assert that a specific value (e-mail) has been set on an entity before I call SaveChanges() on DbContext. I have a test-method which looks like this:
[TestMethod]
public void ShouldAssignEmailBeforeSave()
{
Context.AssertWasCalled(x => x.SaveChanges(),
options => options.WhenCalled(y =>
Assert.IsTrue(_entity.Email == "somevalue")));
}
But I'm realizing that the "WhenCalled"-method isn't executing, because I've also tried this:
[TestMethod]
public void ShouldAssignEmailBeforeSave()
{
Context.Expect(x => x.SaveChanges())
.WhenCalled(y => Assert.IsTrue(false));
}
I have also tried this syntax:
[TestMethod]
public void ShouldAssignEmailBeforeSave()
{
Context.AssertWasCalled(x => x.SaveChanges(),
options => options.WhenCalled(z => Assert.IsTrue(false)));
}
Both asserts above passes, which makes it obvious that I'm not using the WhenCalled correctly. Context is a mocked object of my DBSet. I've left the Arrange and the Act outside of the question for now because they seem to do what they should. It's the Assert that's not working.
How do I verify that a property is set on an entity before a method was called?
Aucun commentaire:
Enregistrer un commentaire