public interface IAnimal { int Legs { get; set; } int Eyes { get; set; } string Name { get; set; } string Species { get; set; } event EventHandler Hungry; string GetMood(); }[Test] public void CreateAnimalStub() { MockRepository mocks = new MockRepository(); IAnimal animal = mocks.DynamicMock<IAnimal>(); Expect.Call(animal.Legs).PropertyBehavior(); Expect.Call(animal.Eyes).PropertyBehavior(); Expect.Call(animal.Name).PropertyBehavior(); Expect.Call(animal.Species).PropertyBehavior(); }
public interface IAnimal { int Legs { get; set; } int Eyes { get; set; } string Name { get; set; } string Species { get; set; } event EventHandler Hungry; string GetMood(); }
[Test] // Tests stub creation with the GenerateStub method public void CreateAnimalStub_GenerateStub() { IAnimal animal = MockRepository.GenerateStub<IAnimal>(); animal.Name = "Snoopy"; Assert.AreEqual( "Snoopy", animal.Name ); }
[Test] public void CreateAnimalStub_MockRepositoryStub() { MockRepository mocks = new MockRepository(); IAnimal animal = mocks.Stub<IAnimal>(); animal.Name = "Snoopy"; Assert.AreEqual( "Snoopy", animal.Name ); }
[Test] public void CreateAnimalStub_NonGenerics() { MockRepository mocks = new MockRepository(); IAnimal animal = (IAnimal) mocks.Stub( typeof ( IAnimal ), null ); animal.Name = "Snoopy"; Assert.AreEqual( "Snoopy", animal.Name ); }