Example #1
0
 public void PartnersCanBeChanged()
 {
   var ctx = new StandardContext();
   ctx.Add("Hotrod");
   ctx.Replace("Douchebag");
   ctx.Get<string>().ShouldBeEqualTo("Douchebag");
 }
Example #2
0
 public void ContextDisposesOfDisposableThings()
 {
   var disp = MockRepository.GenerateMock<IDisposable>();
   using (var ctx = new StandardContext())
     ctx.Add(disp);
   disp.AssertWasCalled(d => d.Dispose());
 }
Example #3
0
 public void PrimitivePolymorphismIsThere()
 {
   var ctx = new StandardContext();
   var reader = new BinaryReader(new MemoryStream());
   ctx.Add<IDisposable>(reader);
   ctx.Get<IDisposable>().ShouldBeTheSameAs(reader);
 }
Example #4
0
 public void ContextIsCloneable()
 {
   StandardContext ctx = new StandardContext();
   ctx.Add("string");
   var ctx2 = ctx.CloneContext();
   ctx2.Get<string>().ShouldBeTheSameAs(ctx.Get<string>());
 }
Example #5
0
 public void ContextLeavesDisposableThingsAloneIfYouWant()
 {
   var disp = MockRepository.GenerateMock<IDisposable>();
   using (var ctx = new StandardContext())
     ctx.Add(disp, false);
   disp.AssertWasNotCalled(d => d.Dispose());
 }
Example #6
0
 public void AddingTwiceMakesContextChoke()
 {
   var ctx = new StandardContext();
   ctx.Add("Hello");
   ctx.Add("World");
 }
Example #7
0
 public void ContextAcceptsOneOfAKind()
 {
   var ctx = new StandardContext();
   ctx.Add("Hello");
   ctx.Get<string>().ShouldBeEqualTo("Hello");
 }
Example #8
0
    public void AnObjectAddedTwiceIsOnlyDisposedOnce()
    {
      var mock = MockRepository.GenerateMock<IDisposable>();
      mock.Expect(d => d.Dispose()).Repeat.Once();
      var ctx = new StandardContext();
      ctx.Add(mock);
      ctx.Add((object)mock);

      ctx.Dispose();
      mock.VerifyAllExpectations();
    }
Example #9
0
 public void ContextCloneCanBeModifiedWithoutAffectingTheOriginal()
 {
   StandardContext ctx = new StandardContext();
   ctx.Add("horse");
   var ctx2 = ctx.CloneContext();
   ctx2.Replace("dog");
   ctx2.Add(new StringBuilder());
   ctx.Get<string>().ShouldBeTheSameAs("horse");
   ctx.Get<StringBuilder>().ShouldBeNull();
 }