Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 29th, 2012  |  syntax: None  |  size: 2.36 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Rhino mock assert.IsNotNull failed
  2. public interface IOrder
  3. {
  4.     Allocation GetAllocation();
  5.     Group GetParentGroup();
  6. }
  7. public class Order : IOrder
  8. {
  9.     public virtual int Id { get; set; }
  10.     public virtual GroupMembership ParentGroupMembership { get; set; }
  11.  
  12.     public virtual Allocation GetAllocation()
  13.     {
  14.         var parentGroup = GetParentGroup();
  15.         return parentGroup.GetAllocationForOrder( this );
  16.     }
  17.  
  18.     public virtual Group GetParentGroup()
  19.     {
  20.         return ParentGroupMembership.ParentGroup;
  21.     }
  22. }
  23.  
  24. public interface IGroupMembership
  25. {
  26.  
  27. }
  28. public class GroupMembership : IGroupMembership
  29. {
  30.     public virtual int Id { get; set; }
  31.     public virtual Group ParentGroup { get; set; }
  32.     public virtual Order Order { get; set; }
  33. }
  34.  
  35. public interface IGroup
  36. {
  37.     Allocation GetAllocationForOrder( Order order );
  38. }
  39. public class Group : IGroup
  40. {
  41.     public virtual int Id { get; set; }
  42.     public virtual ICollection<Allocation> Allocations { get; private set; }
  43.  
  44.     public Group()
  45.     {
  46.         Allocations = new List<Allocation>();
  47.     }
  48.  
  49.     public virtual Allocation GetAllocationForOrder( Order order )
  50.     {
  51.         return Allocations.Single( a => a.OrderId == order.Id );
  52.     }
  53. }
  54.  
  55. public interface IAllocation
  56. {
  57.  
  58. }
  59. public class Allocation : IAllocation
  60. {
  61.     public virtual int Id { get; set; }
  62.     public virtual int OrderId { get; set; }
  63. }
  64.  
  65. [TestMethod]
  66. public void TestGetAllocation()
  67. {
  68.     var order = MockRepository.Stub<Order>();
  69.     order.Id = 1;
  70.  
  71.     var parentGroupMembership = MockRepository.Stub<GroupMembership>();
  72.     parentGroupMembership.Id = 2;
  73.  
  74.     var parentGroup = MockRepository.Stub<Group>();
  75.     parentGroup.Id = 3;
  76.  
  77.     parentGroupMembership.ParentGroup = parentGroup;
  78.     order.ParentGroupMembership = parentGroupMembership;
  79.  
  80.     var allocation = new Allocation { Id = 4, OrderId = 1 };
  81.  
  82.     using ( MockRepository.Record() )
  83.     {
  84.         Expect.Call( order.GetParentGroup() ).Return( parentGroup );
  85.         Expect.Call( parentGroup.GetAllocationForOrder( order ) ).Return( allocation );
  86.     }
  87.     using ( MockRepository.Playback() )
  88.     {
  89.         var actual = order.GetAllocation();
  90.  
  91.         Assert.IsNotNull( actual );
  92.         Assert.AreEqual( actual.OrderId, allocation.OrderId );
  93.     }
  94. }
  95.        
  96. public virtual Child GetChild(ChildIdentifier identifier)
  97.        
  98. var order = MockRepository.Stub<Order>();
  99.        
  100. var order = MockRepository.PartialMock<Order>();