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

Untitled

By: a guest on Aug 6th, 2012  |  syntax: None  |  size: 1.67 KB  |  hits: 8  |  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. Setting Up MOQ Update Test
  2. agg.Setup(a => a.InsertOnPersist<Thingy>(model)).Callback(() => mockThingies.Add(model));
  3.        
  4. agg.Setup(a => a.GetObjectStore<Artist>()).Returns(mockThingies.AsQueryable());
  5.        
  6. public List<Thingy> mockThingies; //this is our repository
  7.  [TestInitialize]
  8.  public void SetupTests()
  9.  {
  10.     mockThingies= new List<Thingy>();
  11.     Thingy someThingy = new Thingy();
  12.     someThingy.Name = "MyName";
  13.     someThingy.ID = 1;
  14.     mockThingies.Add(someThingy);
  15.   }
  16.  
  17.     [TestMethod]
  18.     public void CanEditExistingThingy()
  19.     {
  20.         Mock<BusinessExceptionBroadcaster> beb = new Mock<BusinessExceptionBroadcaster>();
  21.         Mock<IValidationEngine> valid = new Mock<IValidationEngine>();
  22.         Mock<IAggregate> agg = new Mock<IAggregate>();
  23.         agg.Setup(a => a.GetObjectStore<Thingy>()).Returns(mockThingies.AsQueryable());
  24.         ThingyRepository repo = new ThingyRepository (agg.Object);
  25.         ThingyService service = new ThingyService (repo, beb.Object, valid.Object);
  26.         Thingy newThingy = new Thingy();
  27.         newThingy.ID = 1; //same as old
  28.         newThingy.Name = "newname"; //new name
  29.         Assert.AreNotEqual(newThingy.Name,mockThingies[0].Name);
  30.         Assert.IsTrue(service.Update(newThingy));
  31.         Assert.AreEqual(newThingy.Name, mockThingies[0].Name); //FAILS HERE
  32.     }
  33.        
  34. public bool Update(Thingy entity)
  35.     {  
  36.             Thingy existingThingy= _Thingy.FirstOrDefault(t=>t.ID == entity.ID);
  37.             if (existingThingy != null)
  38.             {
  39.                 _Thingy.PersistAll();
  40.                 return true;
  41.             }
  42.             else
  43.             {
  44.                //unimportant
  45.             }
  46.         }
  47.         return false;
  48.     }