private FaultScope CreateFaultScope(MethodBase m) { FaultRule rule = new FaultRule(m, BuiltInConditions.TriggerOnEveryCall, BuiltInFaults.ThrowExceptionFault(new TrapSuccess())); Console.WriteLine(rule.MethodSignature); return(new FaultScope(rule)); }
public override void SetupRules() { int maxQueryFailures = RANDOM.Next(1, MAX_ATTEMPTS); int maxUpdateFailures = MAX_ATTEMPTS - maxQueryFailures; Console.WriteLine("Max UPDATE fault failures: " + maxUpdateFailures); Console.WriteLine("Max QUERY fault failures: " + maxQueryFailures); Rules.Add(new FaultRule(MongoRepositoryHelper.Method.UPDATE_CAS, CustomConditions.TriggerRandomlyWithMax(maxUpdateFailures), BuiltInFaults.ThrowExceptionFault(expectedFault))); Rules.Add(new FaultRule(MongoRepositoryHelper.Method.SINGLE, CustomConditions.TriggerRandomly(1, maxQueryFailures), BuiltInFaults.ThrowExceptionFault(expectedFault))); }
public void TestTrapPerformanceWithFaultScope() { TimeSpan NoTrap = MeasurePerformance(PerformanceActionNoTrap); TimeSpan WithFaultScope; FaultRule faultRule = new FaultRule("Microsoft.Test.AcceptanceTests.FaultInjection.PerformanceTests.PerformanceActionWithTrap()", BuiltInConditions.TriggerOnEveryCall, BuiltInFaults.ReturnFault()); using (FaultScope fs = new FaultScope(faultRule)) { WithFaultScope = MeasurePerformance(PerformanceActionWithTrap); } // We allow it to be 150x slower. // BUG: This test is unstable -- in some cases the perf difference is as high as the following: // Time with no trap: 00:00:00.0042113; Time with trap in fault scope: 00:00:00.7645935 // so we are disabling the assert for now. if (WithFaultScope.Ticks >= NoTrap.Ticks * 150) { // Assert.Null(string.Format("Time with no trap: {0}; Time with trap in fault scope: {1}", NoTrap, WithFaultScope)); } }
public void FaultAppendText() { //This is a work-around, Xunit moves the reference dll's at run time so we need to call register //from the test, instead of TestApiCore. string processorArch = DetectProccessorArchitecture(); ComRegistrar.Register(@".\FaultInjectionEngine\" + processorArch + @"\FaultInjectionEngine.dll"); string sampleAppPath = "SampleApp.exe"; //Create the FaultRule and FaultSession FaultRule rule = new FaultRule( "SampleApp.Window1.Append(string, string)", BuiltInConditions.TriggerOnEveryCall, BuiltInFaults.ReturnValueFault("")); FaultSession session = new FaultSession(rule); //Start the app ProcessStartInfo psi = session.GetProcessStartInfo(sampleAppPath); OutOfProcessApplication testApp = new OutOfProcessApplication( new OutOfProcessApplicationSettings { ProcessStartInfo = psi, ApplicationImplementationFactory = new UIAutomationOutOfProcessApplicationFactory() }); testApp.Start(); try { testApp.WaitForMainWindow(TimeSpan.FromSeconds(15)); // Discover various elements in the UI AutomationElement mainWindowElement = (AutomationElement)testApp.MainWindow; AutomationElement inputTextBox = AutomationUtilities.FindElementsById(mainWindowElement, "inputTextBox")[0]; AutomationElement outputTextBox = AutomationUtilities.FindElementsById(mainWindowElement, "outputTextBox")[0]; AutomationElement appendButton = AutomationUtilities.FindElementsById(mainWindowElement, "appendButton")[0]; // Click on the input text box and simulate typing string inputText = "TestTest"; string expectedText = ""; //expected text should be nothing since we intercept the Append method WindowPattern winPattern = mainWindowElement.GetCurrentPattern(WindowPattern.Pattern) as WindowPattern; Helpers.MoveToAndClick(inputTextBox); winPattern.WaitForInputIdle(inputWaitTime); Microsoft.Test.Input.Keyboard.Type(inputText); winPattern.WaitForInputIdle(inputWaitTime); // Now click the button Helpers.MoveToAndClick(appendButton); winPattern.WaitForInputIdle(inputWaitTime); // Now, get the text of the outputTextBox and compare it against what's expected // Fail the test if expected != actual TextPattern textPattern = outputTextBox.GetCurrentPattern(TextPattern.Pattern) as TextPattern; string actualText = textPattern.DocumentRange.GetText(-1); // Report the test result Assert.Equal <string>(expectedText, actualText); } finally { // Close the tested application testApp.Close(); } }
private static FaultRule[] ConstructFaultRules() { FaultRule[] rules = new FaultRule[16]; rules[0] = new FaultRule("static Microsoft.Test.AcceptanceTests.ConstructorTestOuterClass.InnerClass.InnerClass()"); rules[0].Condition = BuiltInConditions.TriggerOnEveryCall; rules[0].Fault = BuiltInFaults.ReturnValueFault(3); //Take no effect rules[1] = new FaultRule("Microsoft.Test.AcceptanceTests.GenericSignatureTests.NestedGenericClass<T, S>.DoublyNestedClass.TriplyNestedGenericClass<R>.GenericTestMethod<P, Q>(System.Collections.Generic.List<System.Collections.Generic.List<System.Collections.Generic.List<System.Int32>>>,Microsoft.Test.AcceptanceTests.GenericSignatureTests.EmptyClass,System.Collections.Generic.Dictionary<P,System.String>,Q,Microsoft.Test.AcceptanceTests.GenericSignatureTests.NestedGenericClass<T, S>.DoublyNestedClass.TriplyNestedGenericClass<Microsoft.Test.AcceptanceTests.GenericSignatureTests.NestedGenericClass<T, S>.DoublyNestedClass.TriplyNestedGenericClass<E>>)"); rules[1].Condition = BuiltInConditions.TriggerOnEveryCall; rules[1].Fault = BuiltInFaults.ReturnValueFault(System.Boolean.Parse("false")); //Take no effect rules[2] = new FaultRule("Microsoft.Test.AcceptanceTests.NestedClassTests.NestedClass.NestedClassTest()"); rules[2].Condition = BuiltInConditions.TriggerOnEveryCall; rules[2].Fault = BuiltInFaults.ReturnValueFault(System.Boolean.Parse("false")); //Take no effect rules[3] = new FaultRule("Microsoft.Test.AcceptanceTests.NestedClassTests.NestedClass.DoublyNestedClass.DoublyNestedClassTest()"); rules[3].Condition = BuiltInConditions.TriggerOnEveryCall; rules[3].Fault = BuiltInFaults.ReturnValueFault(System.Boolean.Parse("false")); //Take no effect rules[4] = new FaultRule("Microsoft.Test.AcceptanceTests.NonGenericSignatureTests.TestMethod(out System.Int32[][],ref System.Object,Microsoft.Test.AcceptanceTests.NonGenericSignatureTests.TestEnum[,,], Microsoft.Test.AcceptanceTests.NonGenericSignatureTests.NestedClass[][], params int[])"); rules[4].Condition = BuiltInConditions.TriggerOnEveryCall; rules[4].Fault = BuiltInFaults.ReturnValueFault(System.Boolean.Parse("false")); //Take no effect rules[5] = new FaultRule("Microsoft.Test.AcceptanceTests.ReturnTypeErrorTests.NullValueTypeInt()"); rules[5].Condition = BuiltInConditions.TriggerOnEveryCall; rules[5].Fault = BuiltInFaults.ReturnValueFault(null); //Take no effect rules[6] = new FaultRule("Microsoft.Test.AcceptanceTests.ReturnTypeErrorTests.NullValueTypeBool()"); rules[6].Condition = BuiltInConditions.TriggerOnEveryCall; rules[6].Fault = BuiltInFaults.ReturnValueFault(null); //Take no effect rules[7] = new FaultRule("Microsoft.Test.AcceptanceTests.ReturnTypeErrorTests.ReturnTypeMismatchIntBool()"); rules[7].Condition = BuiltInConditions.TriggerOnEveryCall; rules[7].Fault = BuiltInFaults.ReturnValueFault(true); //Take no effect rules[8] = new FaultRule("Microsoft.Test.AcceptanceTests.ReturnTypeErrorTests.ReturnTypeMismatchBoolInt()"); rules[8].Condition = BuiltInConditions.TriggerOnEveryCall; rules[8].Fault = BuiltInFaults.ReturnValueFault(3); //Take no effect rules[9] = new FaultRule("Microsoft.Test.AcceptanceTests.ReturnValueTests.ReturnNullTest()"); rules[9].Condition = BuiltInConditions.TriggerOnEveryCall; rules[9].Fault = BuiltInFaults.ReturnFault(); //Take no effect rules[10] = new FaultRule("Microsoft.Test.AcceptanceTests.ReturnValueTests.ReturnIntTargetMethod(System.String,System.Int32)"); rules[10].Condition = BuiltInConditions.TriggerOnEveryCall; rules[10].Fault = BuiltInFaults.ReturnValueFault(232); rules[11] = new FaultRule("Microsoft.Test.AcceptanceTests.ReturnValueTests.ReturnBoolTargetMethod(System.String,System.Int32)"); rules[11].Condition = BuiltInConditions.TriggerOnEveryCall; rules[11].Fault = BuiltInFaults.ReturnValueFault(false); rules[12] = new FaultRule("Microsoft.Test.AcceptanceTests.ThrowExceptionTests.ThrowBuiltInExceptionTest()"); rules[12].Condition = BuiltInConditions.TriggerOnEveryCall; rules[12].Fault = BuiltInFaults.ThrowExceptionFault(new ApplicationException()); rules[13] = new FaultRule("Microsoft.Test.AcceptanceTests.ThrowExceptionTests.ThrowCustomExceptionTest()"); rules[13].Condition = BuiltInConditions.TriggerOnEveryCall; rules[13].Fault = BuiltInFaults.ThrowExceptionFault(new CustomizedException()); rules[14] = new FaultRule("Microsoft.Test.AcceptanceTests.ConstructorTestOuterClass.InnerClass.InnerClass()"); rules[14].Condition = BuiltInConditions.TriggerOnEveryCall; rules[14].Fault = BuiltInFaults.ReturnValueFault(3); //Take no effect rules[15] = new FaultRule("Microsoft.Test.AcceptanceTests.BuiltInTriggerTests.TesteeTriggerOnNthCallBy()"); rules[15].Condition = BuiltInConditions.TriggerOnNthCallBy(10, "Microsoft.Test.AcceptanceTests.BuiltInTriggerTests.TesterTriggerOnNthCallBy()"); rules[15].Fault = BuiltInFaults.ReturnValueFault(true); //Take no effect return(rules); }