public void Interceptor_AreNotified_OnSelectAllExecuted() { var service = new InterceptionManager(); var i1 = new MyInterceptorOne(); var i2 = new MyInterceptorTwo(); service.AddInterceptor(i1); service.AddInterceptor(i2); var result = new List <string> { "a", "b" }; DbCommand command = DbProviderFactories.GetFactory("System.Data.SqlClient").CreateCommand(); service.OnSelectAllExecuted(command, new DbInterceptionContext(result)); Assert.AreEqual(true, i1.SelectAllExecutedCalled); Assert.AreEqual(command, i1.SelectAllExecutedCommand); Assert.IsNotNull(i1.SelectAllExecutedContext); Assert.AreEqual(result, i1.SelectAllExecutedContext.Result); Assert.AreEqual(true, i2.SelectAllExecutedCalled); Assert.AreEqual(command, i2.SelectAllExecutedCommand); Assert.IsNotNull(i2.SelectAllExecutedContext); Assert.AreEqual(result, i2.SelectAllExecutedContext.Result); }
public void Interceptor_AreNotified_OnInserting() { var service = new InterceptionManager(); var i1 = new MyInterceptorOne(); var i2 = new MyInterceptorTwo(); service.AddInterceptor(i1); service.AddInterceptor(i2); var model = new User { UserName = "******" }; DbCommand command = DbProviderFactories.GetFactory("System.Data.SqlClient").CreateCommand(); service.OnInserting(command, model); Assert.AreEqual(true, i1.InsertingCalled); Assert.AreEqual(command, i1.InsertingCommand); Assert.AreEqual(model, i1.InsertingModel); Assert.AreEqual(true, i2.InsertingCalled); Assert.AreEqual(command, i2.InsertingCommand); Assert.AreEqual(model, i2.InsertingModel); }
public void Interceptor_AreNotified_OnSelectOneExecuting() { var service = new InterceptionManager(); var i1 = new MyInterceptorOne(); var i2 = new MyInterceptorTwo(); service.AddInterceptor(i1); service.AddInterceptor(i2); DbCommand command = DbProviderFactories.GetFactory("System.Data.SqlClient").CreateCommand(); service.OnSelectOneExecuting(command); Assert.AreEqual(true, i1.SelectOneCalled); Assert.AreEqual(command, i1.SelectOneCommand); Assert.AreEqual(true, i2.SelectOneCalled); Assert.AreEqual(command, i2.SelectOneCommand); }
public void Interceptor_AreNotified_OnDeleted() { var service = new InterceptionManager(); var i1 = new MyInterceptorOne(); var i2 = new MyInterceptorTwo(); service.AddInterceptor(i1); service.AddInterceptor(i2); var model = new User { UserName = "******" }; var result = 10; DbCommand command = DbProviderFactories.GetFactory("System.Data.SqlClient").CreateCommand(); service.OnDeleted(command, new DbInterceptionContext(model, result)); Assert.AreEqual(true, i1.DeletedCalled); Assert.AreEqual(command, i1.DeletedCommand); Assert.AreEqual(model, i1.DeletedContext.Model); Assert.AreEqual(result, i1.DeletedContext.Result); Assert.AreEqual(true, i2.DeletedCalled); Assert.AreEqual(command, i2.DeletedCommand); Assert.AreEqual(model, i2.DeletedContext.Model); Assert.AreEqual(result, i2.DeletedContext.Result); Assert.IsFalse(i1.SelectAllCalled); Assert.IsFalse(i1.SelectOneCalled); Assert.IsFalse(i1.InsertingCalled); Assert.IsFalse(i1.UpdatingCalled); Assert.IsFalse(i1.DeletingCalled); Assert.IsFalse(i1.SelectAllExecutedCalled); Assert.IsFalse(i1.SelectOneExecutedCalled); Assert.IsFalse(i1.InsertedCalled); Assert.IsFalse(i1.UpdatedCalled); }
public void Register_Unregister() { var service = new InterceptionManager(); var i1 = new MyInterceptorOne(); var i2 = new MyInterceptorTwo(); service.AddInterceptor(i1); service.AddInterceptor(i2); Assert.AreEqual(2, service.Interceptors.Count); service.RemoveInterceptor(i2); Assert.AreEqual(1, service.Interceptors.Count); Assert.AreEqual("MyInterceptorOne", service.Interceptors[0].GetType().Name); service.RemoveInterceptor(i1); Assert.AreEqual(0, service.Interceptors.Count); }