public void ExecuteProperty <V>( Func <V> setInitializer, Action <V> setExecutor, Action <V> setValidator, Func <V> getExecutor, Action <V, V> getValidator, [CallerMemberName] string callerName = "") { if (DisabledTests.Contains(callerName)) { if (PassDisabledTests) { Console.WriteLine("Test is on the Disabled Lists & Pass Disabled Tests is TRUE"); return; } if (!RunDisabledTests) { throw new AssertInconclusiveException("Test is on the Disabled List"); } } V setValue; V getValue; do { ++DataSequence; if (setExecutor != null) { try { setValue = setInitializer(); } catch (Exception ex) { throw new AssertInconclusiveException("Exception during Set Value Initialization", ex); } Type expected; ExpectedExceptions.TryGetValue(callerName, out expected); try { TrackObjectGraph(null, () => { setExecutor(setValue); if (expected != null) { throw new Exception(String.Format("Expected {0} was not thrown", expected.Name)); } }); } catch (ToBeImplementedException ex) { throw new AssertInconclusiveException("Target Set Accessor is yet to be implemented!", ex); } catch (Exception ex) { bool wasExpected = (expected != null) && (expected == ex.GetType()); if (!wasExpected) { throw; } } try { setValidator(setValue); } catch (Exception) { throw; } } else { setValue = default(V); } if (getExecutor != null) { try { getValue = getExecutor(); } catch (ToBeImplementedException ex) { throw new AssertInconclusiveException("Target Get Accessor is yet to be implemented!", ex); } catch (Exception) { throw; } try { getValidator(setValue, getValue); } catch (Exception) { throw; } } } while (MoreData); }
/// <summary> /// Executes the method. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="instanceCreator">The instance creator.</param> /// <param name="initializer">The initializer.</param> /// <param name="executor">The executor.</param> /// <param name="validator">The validator.</param> /// <param name="callerName">Name of the caller.</param> /// <exception cref="Microsoft.VisualStudio.TestTools.UnitTesting.AssertInconclusiveException"> /// Test is on the Disabled List /// or /// Instance Creator returned Null!! /// or /// Unable to Aquire Trarget Instance /// or /// Exception during Parameter Value Initialization /// or /// Target Method is yet to be implemented! /// </exception> /// <exception cref="Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException">Unable to Aquire Trarget Instance</exception> public void ExecuteMethod <T>(Func <T> instanceCreator, Action <T> initializer, Action <T> executor, Action <T> validator, [CallerMemberName] string callerName = "") { var count = Interlocked.Increment(ref m_Concurrent); if (count > 1) { throw new Exception(); } if (DisabledTests.Contains(callerName)) { if (PassDisabledTests) { Console.WriteLine("Test is on the Disabled Lists & Pass Disabled Tests is TRUE"); return; } if (!RunDisabledTests) { throw new AssertInconclusiveException("Test is on the Disabled List"); } } do { T instance = default(T); ++DataSequence; try { instance = instanceCreator(); if ((typeof(T).IsClass || typeof(T).IsInterface) & instance == null) { if (!AllowNullGetInstance) { throw new AssertInconclusiveException("Instance Creator returned Null!!"); } } } catch (Exception ex) { if (PassOnTargetAquisitionError) { return; } if (SkipOnTargetAquisitionError) { throw new AssertInconclusiveException("Unable to Aquire Trarget Instance", ex); } throw new AssertFailedException("Unable to Aquire Trarget Instance", ex); } try { initializer(instance); } catch (Exception ex) { throw new AssertInconclusiveException("Exception during Parameter Value Initialization", ex); } try { try { TrackObjectGraph(instance, () => executor(instance)); } catch (AggregateException ex) { if (ex.InnerExceptions.Count == 1) { Exception realEx = ex.InnerException; throw realEx; } throw; } } catch (ToBeImplementedException ex) { if (PassToBeImplementedTests) { return; } string yetToBeImplementedMessage = "Target Method is yet to be implemented!"; if (UseFluentMessages) { string className = instance.GetType().Name; object methodName = callerName.Replace("_UnitTest", ""); yetToBeImplementedMessage = String.Format("{0}.{1} is yet to be implemented!", className, methodName); } if (FailToBeImplementedTests) { throw new AssertFailedException(yetToBeImplementedMessage, ex); } throw new AssertInconclusiveException(yetToBeImplementedMessage, ex); } catch (Exception ex) { bool wasExpected = false; Type expected; if (ExpectedExceptions.TryGetValue(callerName, out expected)) { if (expected == ex.GetType()) { wasExpected = true; } } if (!wasExpected) { throw; } } try { validator(instance); } catch (Exception) { throw; } } while (MoreData); }
/// <summary> /// Executes the property. /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="V"></typeparam> /// <param name="instanceCreator">The instance creator.</param> /// <param name="setInitializer">The set initializer.</param> /// <param name="setExecutor">The set executor.</param> /// <param name="setValidator">The set validator.</param> /// <param name="getExecutor">The get executor.</param> /// <param name="getValidator">The get validator.</param> /// <param name="callerName">Name of the caller.</param> /// <exception cref="Microsoft.VisualStudio.TestTools.UnitTesting.AssertInconclusiveException"> /// Test is on the Disabled List /// or /// Instance Creator returned Null!! /// or /// Unable to Aquire Trarget Instance /// or /// Exception during Set Value Initialization /// or /// Target Set Accessor is yet to be implemented! /// or /// Target Get Accessor is yet to be implemented! /// </exception> /// <exception cref="Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException">Unable to Aquire Trarget Instance</exception> public void ExecuteProperty <T, V>(Func <T> instanceCreator, Func <T, V> setInitializer, Action <T, V> setExecutor, Action <T, V> setValidator, Func <T, V> getExecutor, Action <T, V, V> getValidator, [CallerMemberName] string callerName = "") { if (DisabledTests.Contains(callerName)) { if (PassDisabledTests) { Console.WriteLine("Test is on the Disabled Lists & Pass Disabled Tests is TRUE"); return; } if (!RunDisabledTests) { throw new AssertInconclusiveException("Test is on the Disabled List"); } } T instance; V setValue; V getValue; do { ++DataSequence; try { instance = instanceCreator(); if ((typeof(T).IsClass || typeof(T).IsInterface) & instance == null) { if (!AllowNullGetInstance) { throw new AssertInconclusiveException("Instance Creator returned Null!!"); } } } catch (Exception ex) { if (PassOnTargetAquisitionError) { return; } if (SkipOnTargetAquisitionError) { throw new AssertInconclusiveException("Unable to Aquire Trarget Instance", ex); } throw new AssertFailedException("Unable to Aquire Trarget Instance", ex); } if (setExecutor != null) { try { setValue = setInitializer(instance); } catch (Exception ex) { throw new AssertInconclusiveException("Exception during Set Value Initialization", ex); } Type expected; ExpectedExceptions.TryGetValue(callerName, out expected); try { TrackObjectGraph(instance, () => { setExecutor(instance, setValue); if (expected != null) { throw new Exception(String.Format("Expected {0} was not thrown", expected.Name)); } }); } catch (ToBeImplementedException ex) { if (PassToBeImplementedTests) { return; } string yetToBeImplementedMessage = "Target Set Accessor is yet to be implemented!"; if (UseFluentMessages) { string className = instance.GetType().Name; object methodName = callerName.Replace("_UnitTest", ""); yetToBeImplementedMessage = String.Format("{0}.{1} Set Accessor is yet to be implemented!", className, methodName); } if (FailToBeImplementedTests) { throw new AssertFailedException(yetToBeImplementedMessage, ex); } throw new AssertInconclusiveException(yetToBeImplementedMessage, ex); } catch (Exception ex) { bool wasExpected = (expected != null) && (expected == ex.GetType()); if (!wasExpected) { throw; } } try { setValidator(instance, setValue); } catch (Exception) { throw; } } else { setValue = default(V); } if (getExecutor != null) { try { getValue = getExecutor(instance); } catch (ToBeImplementedException ex) { if (PassToBeImplementedTests) { return; } string yetToBeImplementedMessage = "Target Get Accessor is yet to be implemented!"; if (UseFluentMessages) { string className = instance.GetType().Name; object methodName = callerName.Replace("_UnitTest", ""); yetToBeImplementedMessage = String.Format("{0}.{1} Get Accessor is yet to be implemented!", className, methodName); } if (FailToBeImplementedTests) { throw new AssertFailedException(yetToBeImplementedMessage, ex); } throw new AssertInconclusiveException(yetToBeImplementedMessage, ex); } catch (Exception) { throw; } try { getValidator(instance, setValue, getValue); } catch (Exception) { throw; } } } while (MoreData); }
/// <summary> /// Executes the method. /// </summary> /// <param name="initializer">The initializer.</param> /// <param name="executor">The executor.</param> /// <param name="validator">The validator.</param> /// <param name="callerName">Name of the caller.</param> /// <exception cref="Microsoft.VisualStudio.TestTools.UnitTesting.AssertInconclusiveException"> /// Test is on the Disabled List /// or /// Exception during Parameter Value Initialization /// or /// Target Method is yet to be implemented! /// </exception> public void ExecuteMethod(Action initializer, Action executor, Action validator, [CallerMemberName] string callerName = "") { if (DisabledTests.Contains(callerName)) { if (PassDisabledTests) { Console.WriteLine("Test is on the Disabled Lists & Pass Disabled Tests is TRUE"); return; } if (!RunDisabledTests) { throw new AssertInconclusiveException("Test is on the Disabled List"); } } do { ++DataSequence; try { initializer(); } catch (Exception ex) { throw new AssertInconclusiveException("Exception during Parameter Value Initialization", ex); } try { try { executor(); } catch (AggregateException ex) { if (ex.InnerExceptions.Count == 1) { Exception realEx = ex.InnerException; throw realEx; } throw; } } catch (ToBeImplementedException ex) { if (PassToBeImplementedTests) { return; } string yetToBeImplementedMessage = "Target Method is yet to be implemented!"; if (UseFluentMessages) { string className = this.GetType().Name.Replace("_UnitTests", ""); object methodName = callerName.Replace("_UnitTest", ""); yetToBeImplementedMessage = String.Format("{0}.{1} is yet to be implemented!", className, methodName); } if (FailToBeImplementedTests) { throw new AssertFailedException(yetToBeImplementedMessage, ex); } throw new AssertInconclusiveException(yetToBeImplementedMessage, ex); } catch (Exception ex) { bool wasExpected = false; Type expected; if (ExpectedExceptions.TryGetValue(callerName, out expected)) { if (expected == ex.GetType()) { wasExpected = true; } } if (!wasExpected) { throw; } } try { validator(); } catch (Exception) { throw; } } while (MoreData); }