Skip to content

Instantly share code, notes, and snippets.

@dtchepak
Created September 9, 2011 11:45
Show Gist options
  • Save dtchepak/1206005 to your computer and use it in GitHub Desktop.
Save dtchepak/1206005 to your computer and use it in GitHub Desktop.
Trying to replicate reported problem with NSub 1.2 and pure virtual classes
public class NHibernatishExample {
public interface IRepository { SampleEntity Get(int id); }
public class SampleEntity {
public virtual int Id { get; set; }
public virtual string Name { get; set; }
}
public class SomeService {
private readonly IRepository _repository;
public SomeService(IRepository repository) { _repository = repository; }
public SampleEntity DoSomething() {
return _repository.Get(4);
}
}
[Test]
public void DoSomething()
{
var mockRepository = Substitute.For<IRepository>();
var fakeEntity = new SampleEntity { Id = 4, Name = "Sample" };
mockRepository.Get(4).Returns(fakeEntity);
var result = new SomeService(mockRepository).DoSomething();
Assert.That(result.Id, Is.EqualTo(4));
Assert.That(result.Name, Is.EqualTo("Sample"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment