- Rhino mock assert.IsNotNull failed
- public interface IOrder
- {
- Allocation GetAllocation();
- Group GetParentGroup();
- }
- public class Order : IOrder
- {
- public virtual int Id { get; set; }
- public virtual GroupMembership ParentGroupMembership { get; set; }
- public virtual Allocation GetAllocation()
- {
- var parentGroup = GetParentGroup();
- return parentGroup.GetAllocationForOrder( this );
- }
- public virtual Group GetParentGroup()
- {
- return ParentGroupMembership.ParentGroup;
- }
- }
- public interface IGroupMembership
- {
- }
- public class GroupMembership : IGroupMembership
- {
- public virtual int Id { get; set; }
- public virtual Group ParentGroup { get; set; }
- public virtual Order Order { get; set; }
- }
- public interface IGroup
- {
- Allocation GetAllocationForOrder( Order order );
- }
- public class Group : IGroup
- {
- public virtual int Id { get; set; }
- public virtual ICollection<Allocation> Allocations { get; private set; }
- public Group()
- {
- Allocations = new List<Allocation>();
- }
- public virtual Allocation GetAllocationForOrder( Order order )
- {
- return Allocations.Single( a => a.OrderId == order.Id );
- }
- }
- public interface IAllocation
- {
- }
- public class Allocation : IAllocation
- {
- public virtual int Id { get; set; }
- public virtual int OrderId { get; set; }
- }
- [TestMethod]
- public void TestGetAllocation()
- {
- var order = MockRepository.Stub<Order>();
- order.Id = 1;
- var parentGroupMembership = MockRepository.Stub<GroupMembership>();
- parentGroupMembership.Id = 2;
- var parentGroup = MockRepository.Stub<Group>();
- parentGroup.Id = 3;
- parentGroupMembership.ParentGroup = parentGroup;
- order.ParentGroupMembership = parentGroupMembership;
- var allocation = new Allocation { Id = 4, OrderId = 1 };
- using ( MockRepository.Record() )
- {
- Expect.Call( order.GetParentGroup() ).Return( parentGroup );
- Expect.Call( parentGroup.GetAllocationForOrder( order ) ).Return( allocation );
- }
- using ( MockRepository.Playback() )
- {
- var actual = order.GetAllocation();
- Assert.IsNotNull( actual );
- Assert.AreEqual( actual.OrderId, allocation.OrderId );
- }
- }
- public virtual Child GetChild(ChildIdentifier identifier)
- var order = MockRepository.Stub<Order>();
- var order = MockRepository.PartialMock<Order>();