public void InvokeTest() { var invoker = new InterceptorsInvoker(); var mf = new MockRepository(MockBehavior.Strict); var i1 = mf.Create <IInterceptor>(); var i2 = mf.Create <IInterceptor>(); var i3 = mf.Create <IInterceptor>(); var ctx = new RibEfTestContext(); var appTask1 = new AppTask { Id = 1 }; var appTask2 = new AppTask { Id = 2 }; ctx.Set <AppTask>().Attach(appTask1); ctx.Set <AppTask>().Attach(appTask2); var e1 = ctx.Entry(appTask1); var e2 = ctx.Entry(appTask2); var callOrder = 0; i3.Setup(x => x.IsApplicable(e1)).Returns(false).Verifiable(); i3.Setup(x => x.IsApplicable(e2)).Returns(false).Verifiable(); i1.Setup(x => x.IsApplicable(e1)).Returns(true).Verifiable(); i2.Setup(x => x.IsApplicable(e1)).Returns(true).Verifiable(); i1.Setup(x => x.Order(e1)).Returns(1).Verifiable(); i2.Setup(x => x.Order(e1)).Returns(2).Verifiable(); i1.Setup(x => x.BeforeSave(e1)).Callback(() => Assert.AreEqual(0, callOrder++)).Verifiable(); i2.Setup(x => x.BeforeSave(e1)).Callback(() => Assert.AreEqual(1, callOrder++)).Verifiable(); i1.Setup(x => x.IsApplicable(e2)).Returns(true).Verifiable(); i2.Setup(x => x.IsApplicable(e2)).Returns(true).Verifiable(); i1.Setup(x => x.Order(e2)).Returns(2).Verifiable(); i2.Setup(x => x.Order(e2)).Returns(1).Verifiable(); i1.Setup(x => x.BeforeSave(e2)).Callback(() => Assert.AreEqual(3, callOrder++)).Verifiable(); i2.Setup(x => x.BeforeSave(e2)).Callback(() => Assert.AreEqual(2, callOrder++)).Verifiable(); invoker.InvokeBeforeSave(new[] { i1.Object, i2.Object, i3.Object }, new DbEntityEntry[] { e1, e2 }); Assert.AreEqual(4, callOrder); mf.VerifyAll(); }
public void IsApplicableTest() { var ic = new TestInterceptor(); var ctx = new RibEfTestContext(); var t1 = new AppTask { Id = 1 }; var t2 = new AppTask { Id = 2 }; var t3 = new AppTask(); var p1 = new Project { Id = 1 }; var p2 = new Project(); ctx.Tasks.Attach(t1); ctx.Tasks.Attach(t2); ctx.Tasks.Add(t3); ctx.Set <Project>().Attach(p1); ctx.Set <Project>().Add(p2); var t1e = ctx.Entry(t1); var t2e = ctx.Entry(t2); var t3e = ctx.Entry(t3); var p1e = ctx.Entry(p1); var p2e = ctx.Entry(p2); Assert.IsFalse(ic.IsApplicable(t1e)); Assert.IsFalse(ic.IsApplicable(t2e)); Assert.IsTrue(ic.IsApplicable(t3e)); Assert.IsFalse(ic.IsApplicable(p1e)); Assert.IsFalse(ic.IsApplicable(p2e)); }