public void CoordinatorDeclarativeWithAttributes() { ITestCoord coord = ctx["testCoordinator"] as ITestCoord; Assert.IsNotNull(coord); CallCountingTransactionManager ccm = ctx["transactionManager"] as CallCountingTransactionManager; Assert.IsNotNull(ccm); LoggingAroundAdvice advice = (LoggingAroundAdvice)ctx["consoleLoggingAroundAdvice"]; Assert.IsNotNull(advice); ITestObjectMgr testObjectMgr = ctx["testObjectManager"] as ITestObjectMgr; Assert.IsNotNull(testObjectMgr); //Proxied due to NameMatchMethodPointcutAdvisor Assert.IsTrue(AopUtils.IsAopProxy(coord)); //Proxied due to DefaultAdvisorAutoProxyCreator Assert.IsTrue(AopUtils.IsAopProxy(testObjectMgr)); TestObject to1 = new TestObject("Jack", 7); TestObject to2 = new TestObject("Jill", 6); Assert.AreEqual(0, ccm.begun); Assert.AreEqual(0, ccm.commits); Assert.AreEqual(0, advice.numInvoked); coord.WorkOn(to1,to2); Assert.AreEqual(1, ccm.begun); Assert.AreEqual(1, ccm.commits); Assert.AreEqual(1, advice.numInvoked); }
public void CannotCommitTransaction() { ITransactionAttribute txatt = new DefaultTransactionAttribute(); MethodInfo m = typeof (ITestObject).GetMethod("GetDescription"); MethodMapTransactionAttributeSource tas = new MethodMapTransactionAttributeSource(); tas.AddTransactionalMethod(m, txatt); IPlatformTransactionManager ptm = PlatformTxManagerForNewTransaction(); ITransactionStatus status = TransactionStatusForNewTransaction(); Expect.On(ptm).Call(ptm.GetTransaction(txatt)).Return(status); UnexpectedRollbackException ex = new UnexpectedRollbackException("foobar", null); ptm.Commit(status); LastCall.On(ptm).Throw(ex); mocks.ReplayAll(); TestObject to = new TestObject(); ITestObject ito = (ITestObject) Advised(to, ptm, tas); try { ito.GetDescription(); Assert.Fail("Shouldn't have succeeded"); } catch (UnexpectedRollbackException thrown) { Assert.IsTrue(thrown == ex); } mocks.VerifyAll(); }
public void WithNonSerializableObject() { TestObject o = new TestObject(); Assert.IsFalse(o is ISerializable); Assert.IsFalse(IsSerializable(o)); TrySerialization(o); }
public static void PerformOperations(ITestObjectManager mgr, ITestObjectDao dao) { Assert.IsNotNull(mgr); TestObject to1 = new TestObject(); to1.Name = "Jack"; to1.Age = 7; TestObject to2 = new TestObject(); to2.Name = "Jill"; to2.Age = 8; mgr.SaveTwoTestObjects(to1, to2); TestObject to = dao.FindByName("Jack"); Assert.IsNotNull(to); to = dao.FindByName("Jill"); Assert.IsNotNull(to); Assert.AreEqual("Jill", to.Name); mgr.DeleteTwoTestObjects("Jack", "Jill"); to = dao.FindByName("Jack"); Assert.IsNull(to); to = dao.FindByName("Jill"); Assert.IsNull(to); }
public void AddAndRemoveEventHandlerThroughIntroduction() { TestObject target = new TestObject(); DoubleClickableIntroduction dci = new DoubleClickableIntroduction(); DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(dci); CountingBeforeAdvice countingBeforeAdvice = new CountingBeforeAdvice(); target.Name = "SOME-NAME"; ProxyFactory pf = new ProxyFactory(target); pf.AddIntroduction(advisor); pf.AddAdvisor(new DefaultPointcutAdvisor(countingBeforeAdvice)); object proxy = pf.GetProxy(); ITestObject to = proxy as ITestObject; Assert.IsNotNull(to); Assert.AreEqual("SOME-NAME", to.Name); IDoubleClickable doubleClickable = proxy as IDoubleClickable; // add event handler through introduction doubleClickable.DoubleClick += new EventHandler(OnClick); OnClickWasCalled = false; doubleClickable.FireDoubleClickEvent(); Assert.IsTrue(OnClickWasCalled); Assert.AreEqual(3, countingBeforeAdvice.GetCalls()); // remove event handler through introduction doubleClickable.DoubleClick -= new EventHandler(OnClick); OnClickWasCalled = false; doubleClickable.FireDoubleClickEvent(); Assert.IsFalse(OnClickWasCalled); Assert.AreEqual(5, countingBeforeAdvice.GetCalls()); }
public void WithNonSerializableObject() { TestObject o = new TestObject(); Assert.IsFalse(o is ISerializable); Assert.IsFalse(IsSerializable(o)); Assert.Throws<SerializationException>(() => TrySerialization(o)); }
public void Update(TestObject to) { AdoTemplate.ExecuteNonQuery(CommandType.Text, String.Format("UPDATE TestObjects SET Age={0}, Name='{1}' where TestObjectNo = {2}", to.Age, to.Name, to.ObjectNumber)); }
protected override object MapRow(IDataReader reader, int num) { TestObject to = new TestObject(); to.ObjectNumber = reader.GetInt32(0); to.Age = reader.GetInt32(1); to.Name = reader.GetString(2); return to; }
public void ApplyResources() { TestObject value = new TestObject(); StaticMessageSource msgSource = new StaticMessageSource(); msgSource.ApplyResources(value, "testObject", CultureInfo.InvariantCulture); Assert.AreEqual("Mark", value.Name, "Name property value not applied."); Assert.AreEqual(35, value.Age, "Age property value not applied."); }
public void SaveTwoTestObjects(TestObject to1, TestObject to2) { LOG.Debug("TransactionActive = " + TransactionSynchronizationManager.ActualTransactionActive); //Console.WriteLine("TransactionSynchronizationManager.CurrentTransactionIsolationLevel = " + // TransactionSynchronizationManager.CurrentTransactionIsolationLevel); //Console.WriteLine("System.Transactions.Transaction.Current.IsolationLevel = " + System.Transactions.Transaction.Current.IsolationLevel); testObjectDao.Create(to1.Name, to1.Age); testObjectDao.Create(to2.Name, to2.Age); }
public void ApplyResources() { //Add another resource manager to the list TestObject to = new TestObject(); ComponentResourceManager mgr = new ComponentResourceManager(to.GetType()); resourceManagerList.Add(mgr); messageSource.ResourceManagers = resourceManagerList; messageSource.ApplyResources(to, "testObject", CultureInfo.CurrentCulture); Assert.AreEqual("Mark", to.Name); Assert.AreEqual(35, to.Age); }
public object ExtractData(IDataReader reader) { IList testObjects = new ArrayList(); while (reader.Read()) { TestObject to = new TestObject(); //object foo = reader.GetDataTypeName(0); to.ObjectNumber = (int) reader.GetInt64(0); to.Name = reader.GetString(1); testObjects.Add(to); } return testObjects; }
public static void PerformOperations(ITestCoordinator coordinator, ITestObjectDao dao) { TestObject to1 = new TestObject(); to1.Name = "Jack"; to1.Age = 7; TestObject to2 = new TestObject(); to2.Name = "Jill"; to2.Age = 8; coordinator.WorkOn(to1, to2); coordinator.TestObjectManager.DeleteTwoTestObjects("Jack", "Jill"); }
public void ProxyIsJustInterface() { TestObject target = new TestObject(); target.Age = 32; AdvisedSupport advised = new AdvisedSupport(); advised.Target = target; advised.Interfaces = new Type[] { typeof(ITestObject) }; object proxy = CreateProxy(advised); Assert.IsTrue(proxy is ITestObject); Assert.IsFalse(proxy is TestObject); }
public void TestIntroductionInterceptorWithDelegation() { TestObject raw = new TestObject(); Assert.IsTrue(! (raw is ITimeStamped)); ProxyFactory factory = new ProxyFactory(raw); ITimeStampedIntroduction ts = MockRepository.GenerateMock<ITimeStampedIntroduction>(); ts.Stub(x => x.TimeStamp).Return(EXPECTED_TIMESTAMP); DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(ts); factory.AddIntroduction(advisor); ITimeStamped tsp = (ITimeStamped) factory.GetProxy(); Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP); }
public void TestIntroductionInterceptorWithInterfaceHierarchy() { TestObject raw = new TestObject(); Assert.IsTrue(! (raw is ISubTimeStamped)); ProxyFactory factory = new ProxyFactory(raw); ISubTimeStampedIntroduction ts = MockRepository.GenerateMock<ISubTimeStampedIntroduction>(); ts.Stub(x => x.TimeStamp).Return(EXPECTED_TIMESTAMP); DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(ts); // we must add introduction, not an advisor factory.AddIntroduction(advisor); object proxy = factory.GetProxy(); ISubTimeStamped tsp = (ISubTimeStamped) proxy; Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP); }
public void testIntroductionInterceptorWithDelegation() { TestObject raw = new TestObject(); Assert.IsTrue(! (raw is ITimeStamped)); ProxyFactory factory = new ProxyFactory(raw); IDynamicMock tsControl = new DynamicMock(typeof(ITimeStampedIntroduction)); ITimeStampedIntroduction ts = (ITimeStampedIntroduction) tsControl.Object; tsControl.ExpectAndReturn("TimeStamp", EXPECTED_TIMESTAMP); DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(ts); factory.AddIntroduction(advisor); ITimeStamped tsp = (ITimeStamped) factory.GetProxy(); Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP); tsControl.Verify(); }
public void testIntroductionInterceptorWithInterfaceHierarchy() { TestObject raw = new TestObject(); Assert.IsTrue(! (raw is ISubTimeStamped)); ProxyFactory factory = new ProxyFactory(raw); IDynamicMock tsControl = new DynamicMock(typeof(ISubTimeStampedIntroduction)); ISubTimeStampedIntroduction ts = (ISubTimeStampedIntroduction) tsControl.Object; tsControl.ExpectAndReturn("TimeStamp", EXPECTED_TIMESTAMP); DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(ts); // we must add introduction, not an advisor factory.AddIntroduction(advisor); object proxy = factory.GetProxy(); ISubTimeStamped tsp = (ISubTimeStamped) proxy; Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP); tsControl.Verify(); }
public IndexedTestObject() { TestObject to0 = new TestObject("name0", 0); TestObject to1 = new TestObject("name1", 0); TestObject to2 = new TestObject("name2", 0); TestObject to3 = new TestObject("name3", 0); TestObject to4 = new TestObject("name4", 0); TestObject to5 = new TestObject("name5", 0); TestObject to6 = new TestObject("name6", 0); TestObject to7 = new TestObject("name7", 0); array = new TestObject[] {to0, to1}; list = new ArrayList(); list.Add(to2); list.Add(to3); set = new HashedSet(); set.Add(to6); set.Add(to7); map = new Hashtable(); map["key1"] = to4; map["key2"] = to5; }
private void DoTestRollbackOnException(Exception exception, bool shouldRollback, bool rollbackException) { ITransactionAttribute txatt = new ConfigurableTransactionAttribute(shouldRollback); MethodInfo mi = typeof (ITestObject).GetMethod("Exceptional"); MethodMapTransactionAttributeSource tas = new MethodMapTransactionAttributeSource(); tas.AddTransactionalMethod(mi, txatt); ITransactionStatus status = TransactionStatusForNewTransaction(); IPlatformTransactionManager ptm = (IPlatformTransactionManager) mocks.DynamicMock(typeof (IPlatformTransactionManager)); Expect.On(ptm).Call(ptm.GetTransaction(txatt)).Return(status); if (shouldRollback) { ptm.Rollback(status); } else { ptm.Commit(status); } TransactionSystemException tex = new TransactionSystemException("system exception"); if (rollbackException) { LastCall.On(ptm).Throw(tex).Repeat.Once(); } else { LastCall.On(ptm).Repeat.Once(); } mocks.ReplayAll(); TestObject to = new TestObject(); ITestObject ito = (ITestObject) Advised(to, ptm, tas); try { ito.Exceptional(exception); Assert.Fail("Should have thrown exception"); } catch (Exception e) { if (rollbackException) { Assert.AreEqual(tex, e); } else { Assert.AreEqual(exception, e); } } mocks.VerifyAll(); }
public void RemoveAdvisorByReference() { TestObject target = new TestObject(); ProxyFactory pf = new ProxyFactory(target); NopInterceptor nop = new NopInterceptor(); CountingBeforeAdvice cba = new CountingBeforeAdvice(); IAdvisor advisor = new DefaultPointcutAdvisor(cba); pf.AddAdvice(nop); pf.AddAdvisor(advisor); ITestObject proxied = (ITestObject)pf.GetProxy(); proxied.Age = 5; Assert.AreEqual(1, cba.GetCalls()); Assert.AreEqual(1, nop.Count); Assert.IsFalse(pf.RemoveAdvisor(null)); Assert.IsTrue(pf.RemoveAdvisor(advisor)); Assert.AreEqual(5, proxied.Age); Assert.AreEqual(1, cba.GetCalls()); Assert.AreEqual(2, nop.Count); Assert.IsFalse(pf.RemoveAdvisor(new DefaultPointcutAdvisor(null))); }
public bool Contains(TestObject value) { return(IndexOf(value) >= 0); }
public void TestIntroductionInterceptorWithSuperInterface() { TestObject raw = new TestObject(); Assert.IsTrue(! (raw is ITimeStamped)); ProxyFactory factory = new ProxyFactory(raw); ISubTimeStamped ts = MockRepository.GenerateMock<ISubTimeStampedIntroduction>(); ts.Stub(x => x.TimeStamp).Return(EXPECTED_TIMESTAMP); factory.AddIntroduction(0, new DefaultIntroductionAdvisor( (ISubTimeStampedIntroduction)ts, typeof(ITimeStamped)) ); ITimeStamped tsp = (ITimeStamped) factory.GetProxy(); Assert.IsTrue(!(tsp is ISubTimeStamped)); Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP); }
public void TestAutomaticInterfaceRecognitionInDelegate() { IIntroductionAdvisor ia = new DefaultIntroductionAdvisor(new Test(EXPECTED_TIMESTAMP)); TestObject target = new TestObject(); ProxyFactory pf = new ProxyFactory(target); pf.AddIntroduction(0, ia); ITimeStamped ts = (ITimeStamped) pf.GetProxy(); Assert.IsTrue(ts.TimeStamp == EXPECTED_TIMESTAMP); ((ITest) ts).Foo(); int age = ((ITestObject) ts).Age; }
public virtual int IndexOf(TestObject value) { return(Array.IndexOf(this._array, value, 0, this._count)); }
public virtual TestObject[] ToArray() { TestObject[] array = new TestObject[this._count]; Array.Copy(this._array, array, this._count); return(array); }
public void ApplyResourcesWithNullObject() { TestObject value = new TestObject(); StaticMessageSource msgSource = new StaticMessageSource(); msgSource.ApplyResources(null, "testObject", CultureInfo.InvariantCulture); Assert.AreEqual(null, value.Name); Assert.AreEqual(0, value.Age); }
public void GetResourceObjectWithCode() { TestObject value = new TestObject("Rick", 30); StaticMessageSource msgSource = new StaticMessageSource(); msgSource.AddObject("rick", CultureInfo.CurrentUICulture, value); TestObject retrieved = (TestObject) msgSource.GetResourceObject("rick"); Assert.IsNotNull(retrieved, "Object previously added to StaticMessageSource was not retrieved " + "when using same lookup code."); Assert.IsTrue(ReferenceEquals(value, retrieved), "Object returned from StaticMessageSource was not the same one " + "that was previously added (it must be)."); }
public void GetResourceObjectWithCodeAssumesCurrentUICulture() { TestObject value = new TestObject("Rick", 30); StaticMessageSource msgSource = new StaticMessageSource(); msgSource.AddObject("rick", CultureInfo.InvariantCulture, value); // assumes object was previously added using CultureInfo.CurrentUICulture TestObject retrieved = (TestObject) msgSource.GetResourceObject("rick"); Assert.IsNull(retrieved, "Object previously added to StaticMessageSource " + "(using CultureInfo.InvariantCulture) was (wrongly) retrieved " + "when using same lookup code."); }
public void ApplyResourcesWithNullLookupKey() { TestObject value = new TestObject(); StaticMessageSource msgSource = new StaticMessageSource(); try { msgSource.ApplyResources(value, null, CultureInfo.InvariantCulture); Assert.Fail("ArgumentNullException was expected"); } catch (ArgumentNullException e) { Assert.IsNotNull(e); } Assert.AreEqual(null, value.Name); Assert.AreEqual(0, value.Age); }
public void ReplaceAdvisor() { TestObject target = new TestObject(); ProxyFactory pf = new ProxyFactory(target); NopInterceptor nop = new NopInterceptor(); CountingBeforeAdvice cba1 = new CountingBeforeAdvice(); CountingBeforeAdvice cba2 = new CountingBeforeAdvice(); IAdvisor advisor1 = new DefaultPointcutAdvisor(cba1); IAdvisor advisor2 = new DefaultPointcutAdvisor(cba2); pf.AddAdvisor(advisor1); pf.AddAdvice(nop); ITestObject proxied = (ITestObject)pf.GetProxy(); // Use the type cast feature // Replace etc methods on advised should be same as on ProxyFactory IAdvised advised = (IAdvised)proxied; proxied.Age = 5; Assert.AreEqual(1, cba1.GetCalls()); Assert.AreEqual(0, cba2.GetCalls()); Assert.AreEqual(1, nop.Count); Assert.IsFalse(advised.ReplaceAdvisor(null, null)); Assert.IsFalse(advised.ReplaceAdvisor(null, advisor2)); Assert.IsFalse(advised.ReplaceAdvisor(advisor1, null)); Assert.IsTrue(advised.ReplaceAdvisor(advisor1, advisor2)); Assert.AreEqual(advisor2, pf.Advisors[0]); Assert.AreEqual(5, proxied.Age); Assert.AreEqual(1, cba1.GetCalls()); Assert.AreEqual(2, nop.Count); Assert.AreEqual(1, cba2.GetCalls()); Assert.IsFalse(pf.ReplaceAdvisor(new DefaultPointcutAdvisor(null), advisor1)); }
public virtual int BinarySearch(TestObject value) { return(Array.BinarySearch(this._array, 0, this._count, value)); }
public void RemoveAdvisorByIndex() { TestObject target = new TestObject(); ProxyFactory pf = new ProxyFactory(target); NopInterceptor nop = new NopInterceptor(); CountingBeforeAdvice cba = new CountingBeforeAdvice(); IAdvisor advisor = new DefaultPointcutAdvisor(cba); pf.AddAdvice(nop); pf.AddAdvisor(advisor); NopInterceptor nop2 = new NopInterceptor(2); // make instance unique (see SPRNET-847) pf.AddAdvice(nop2); ITestObject proxied = (ITestObject)pf.GetProxy(); proxied.Age = 5; Assert.AreEqual(1, cba.GetCalls()); Assert.AreEqual(1, nop.Count); Assert.AreEqual(1, nop2.Count); // Removes counting before advisor pf.RemoveAdvisor(1); Assert.AreEqual(5, proxied.Age); Assert.AreEqual(1, cba.GetCalls()); Assert.AreEqual(2, nop.Count); Assert.AreEqual(2, nop2.Count); // Removes Nop1 pf.RemoveAdvisor(0); Assert.AreEqual(5, proxied.Age); Assert.AreEqual(1, cba.GetCalls()); Assert.AreEqual(2, nop.Count); Assert.AreEqual(3, nop2.Count); // Check out of bounds try { pf.RemoveAdvisor(-1); Assert.Fail("Supposed to throw exception"); } catch (AopConfigException) { // Ok } try { pf.RemoveAdvisor(2); Assert.Fail("Supposed to throw exception"); } catch (AopConfigException) { // Ok } Assert.AreEqual(5, proxied.Age); Assert.AreEqual(4, nop2.Count); }
public void IndexOfMethods() { TestObject target = new TestObject(); ProxyFactory pf = new ProxyFactory(target); NopInterceptor nop = new NopInterceptor(); IAdvisor advisor = new DefaultPointcutAdvisor(new CountingBeforeAdvice()); IAdvised advised = (IAdvised)pf.GetProxy(); // Can use advised and ProxyFactory interchangeably advised.AddAdvice(nop); pf.AddAdvisor(advisor); Assert.AreEqual(-1, pf.IndexOf((IInterceptor)null)); Assert.AreEqual(-1, pf.IndexOf(new NopInterceptor())); Assert.AreEqual(0, pf.IndexOf(nop)); Assert.AreEqual(-1, advised.IndexOf((IAdvisor)null)); Assert.AreEqual(1, pf.IndexOf(advisor)); Assert.AreEqual(-1, advised.IndexOf(new DefaultPointcutAdvisor(null))); }