protected override T CreateNMSInstance <T, P>(BaseTestCase test, P parent) { IMessageConsumer consumer = test.CreateConsumer((ISession)parent, this.GetDestination(test)); InitializeConsumerProperties(consumer); return((T)consumer); }
private void SetupBaseTestCase(BaseTestCase testCase) { eventType = testCase.eventType; if (testCase.hoveredBone >= 0) { m_BindPoseView.LayoutBone(mousePosition - Vector2.one * 1000f, mousePosition + Vector2.one * 1000f, testCase.hoveredBone); } if (testCase.hoveredBoneNode >= 0) { m_BindPoseView.LayoutBone(mousePosition, mousePosition + Vector2.one, testCase.hoveredBoneNode); } if (testCase.forceNearestControl >= 0) { nearestControl = testCase.forceNearestControl; } SetGUIWrapperState(testCase.state); if (testCase.selectedBone >= 0) { m_Selection.Count.Returns(1); m_Selection.single.Returns(testCase.selectedBone); m_Selection.IsSelected(testCase.selectedBone).Returns(true); } }
protected override T CreateNMSInstance <T, P>(BaseTestCase test, P parent) { IConnection Parent = (IConnection)parent; Parent.AcknowledgementMode = AckMode; return((T)test.CreateSession(Parent)); }
private async void RunTests() { EnableButtons(false); List <ConfigFile> lstConfigFiles = BaseTestCase.LoadConfigFile("config_file.json"); string _testcasetype = string.Empty; foreach (var item in lstConfigFiles) { try { _testcasetype = item.TestCaseType; string testResultString = string.Format(item.Purpose + "\r\n\r\n"); testCaseRunner = new TestCaseRunner(item.FilePath); testCaseRunner.TestCaseOutputEventHandler += TestCaseRunner_TestCaseOutputEventHandler; testCaseRunner.RunTestCases(); } catch (Exception ex) { await Dispatcher.InvokeAsync(new Action(() => TestResultVM.TestResultObservableCollection.Add(new TestCaseResult { Target = item.TestName, InputJsonFileName = item.FilePath, Result = "Fail", Description = ex.Message }))); } } EnableButtons(true); }
protected void InitializeTest <T, P>(BaseTestCase nmsTest, bool fromAction = false) { if (nmsTest != null && (!IsTestAction || fromAction)) { BaseTestCase.Logger.Info("IsTestAction : " + IsTestAction + " fromAction " + fromAction + ""); if (BaseTestCase.Logger.IsDebugEnabled) { BaseTestCase.Logger.Debug("Initial test state: " + nmsTest.ToString()); } P parent = GetParentNMSInstance <P>(nmsTest); if (BaseTestCase.Logger.IsDebugEnabled) { BaseTestCase.Logger.Debug("Added parent test state: " + nmsTest.ToString()); } for (int i = 0; i < nmsInstanceIds.Length; i++) { string id = nmsInstanceIds[i]; T instance = CreateNMSInstance <T, P>(nmsTest, parent); if (BaseTestCase.Logger.IsDebugEnabled) { BaseTestCase.Logger.Debug("Adding Instance " + id + " test state: " + nmsTest.ToString()); } AddInstance(nmsTest, instance, id); if (BaseTestCase.Logger.IsDebugEnabled) { BaseTestCase.Logger.Debug("Added Instance " + id + " test state: " + nmsTest.ToString()); } } } }
public void LoadNetworkTestsFromJson() { /** * Hello world goal: * Execute a command based on the loaded json * * later on: group of tests that define success * for now, keep it simple. all or nothing */ List <BaseTestCase> myTests = BaseTestCase.LoadTests("network_tests.json"); Assert.IsTrue(myTests.Count == 3); Assert.IsTrue(myTests[0].TestName == "HP Daas"); Assert.IsTrue(myTests[0] is HTTPTestCase); HTTPTestCase httpTestCase = myTests[0] as HTTPTestCase; Assert.IsTrue(httpTestCase.FollowRedirect == false); Assert.IsTrue(httpTestCase.Target == "https://www.hpdaas.com"); Assert.IsTrue(httpTestCase.ExpectedResponseCode == 200); Assert.IsTrue(myTests[1].TestName == "Look at redirect location"); HTTPTestCase secondTestCase = myTests[1] as HTTPTestCase; //Assert.IsTrue(secondTestCase.FollowRedirect == true); Assert.IsTrue(secondTestCase.Target == "http://o.ss2.us/"); Assert.IsTrue(secondTestCase.RedirectLocation == "http://www.starfieldtech.com/"); Assert.IsTrue(secondTestCase.ExpectedResponseCode == 301); Assert.IsTrue(myTests[2].TestName == "Network redirect"); HTTPTestCase thirdTestCase = myTests[2] as HTTPTestCase; //Assert.IsTrue(secondTestCase.FollowRedirect == true); Assert.IsTrue(thirdTestCase.Target == "http://o.ss2.us/"); Assert.IsTrue(thirdTestCase.ExpectedResponseCode == 200); }
protected StringDictionary GetConnectionProperties(BaseTestCase nmsTest) { StringDictionary properties = new StringDictionary(); if (EncodingType != null) { properties[NMSPropertyConstants.NMS_CONNECTION_ENCODING] = EncodingType; } if (MaxFrameSize != 0) { properties[NMSPropertyConstants.NMS_CONNECTION_MAX_FRAME_SIZE] = MaxFrameSize.ToString(); } if (CloseTimeout != 0) { properties[NMSPropertyConstants.NMS_CONNECTION_CLOSE_TIMEOUT] = CloseTimeout.ToString(); } if (RequestTimeout > 0) { if (properties.ContainsKey(NMSPropertyConstants.NMS_CONNECTION_REQUEST_TIMEOUT)) { properties.Add(NMSPropertyConstants.NMS_CONNECTION_REQUEST_TIMEOUT, RequestTimeout.ToString()); } else { properties[NMSPropertyConstants.NMS_CONNECTION_REQUEST_TIMEOUT] = RequestTimeout.ToString(); } }//*/ return(properties); }
protected virtual void TestSetupFailure(BaseTestCase test, string message, Exception cause) { test.PrintTestFailureAndAssert( TestName, message, cause ); }
public virtual void Setup(BaseTestCase nmsTest) { TestName = TestContext.CurrentContext.Test.MethodName; if (type == SetupType.Unknown) { type = SetupType.TestSetup; } }
protected void InitializeNUnitTest <T, P>(ITest test) { BaseTestCase nmsTest = GetTest(test); if (IsTestAction) { InitializeTest <T, P>(nmsTest, true); } }
protected virtual void TestSetupFailureDestinationNotFound(BaseTestCase test) { string destinationId = DestinationId ?? destinationIndex.ToString(); string message = string.Format("Failed to find IDestination {0}, when creating {1}.", destinationId, InstanceName ); TestSetupFailure(test, message); }
protected override T CreateNMSInstance <T, P>(BaseTestCase test, P parent) { IConnection instance = test.CreateConnection((IConnectionFactory)parent); if (this.ClientId != null && !String.IsNullOrWhiteSpace(this.ClientId)) { instance.ClientId = this.ClientId; } return((T)instance); }
protected virtual void TestSetupFailureParentNotFound(BaseTestCase test) { string id = (NmsParentId == null) ? parentIndex.ToString() : NmsParentId; string message = string.Format( "Failed to find Parent {0} {1} to create {2}.", ParentName, id, InstanceName ); TestSetupFailure(test, message); }
private static void AddAnalyzer(List<AnalyzerComposite> tests, BaseTestCase analyzer) { foreach (var composite in tests) { if (!analyzer.TargetTypes.Any(type => composite.TargetTypes.Contains(type))) { composite.Add(analyzer); return; } } tests.Add(new AnalyzerComposite() { analyzer }); }
protected void RestrictTestInstance <T>(BaseTestCase test) { T nmsInstance = this.GetParentNMSInstance <T>(test); IList <IRestriction <T> > restrictions = GetRestrictions <T>(); foreach (IRestriction <T> r in restrictions) { if (!r.Apply(nmsInstance)) { this.HandleUnsatisfiedRestriction(r, nmsInstance); } } }
private static void RunTests(string configFileName) { List <ConfigFile> lstConfigFiles = BaseTestCase.LoadConfigFile(configFileName); string _testcasetype = string.Empty; foreach (var item in lstConfigFiles) { try { _testcasetype = item.TestCaseType; //string testResultString = string.Format(item.Purpose + "\r\n\r\n"); //Console.WriteLine(testResultString); // make configurable? //Replace curl with C# default httpWebRequest API testCaseRunner = new TestCaseRunner(item.FilePath); //testCaseRunner.PathToCurl = "curl.exe"; testCaseRunner.TestCaseOutputEventHandler += TestCaseRunner_TestCaseOutputEventHandler; //TODO: hook up string streaming testCaseRunner.RunTestCases(); //testResultString = string.Format(item.TestName + " test case status : {0} \r\n\r\n", testCaseRunner.DidAllTestCasesPass()); //Console.WriteLine(testResultString); } catch (Exception ex) { Console.WriteLine(string.Format("\t" + ex.Message + "\r\n\r\n")); } } Console.WriteLine("Do you want to export test case result? [yes/no]"); string option = Console.ReadLine(); if (option == "yes") { string filename = "TestCaseResult" + DateTime.Now.ToString("yyyy''MM''dd'T'HH''mm''ss") + ".csv"; if (itemList == null || itemList.Count == 0) { return; } var sb = new StringBuilder(); string csvHeaderRow = String.Join(",", typeof(TestCaseResult).GetProperties(BindingFlags.Public | BindingFlags.Instance).Select(x => x.Name).ToArray <string>()) + Environment.NewLine; sb.AppendLine(csvHeaderRow); foreach (var data in itemList) { sb.AppendLine(data.Target + "," + data.ProxyURL + "," + data.ProxyType + "," + data.InputJsonFileName + "," + data.ExpectedStatusCode + "," + data.ActualStatusCode + "," + data.Result + "," + data.Description); } File.WriteAllText(filename, sb.ToString()); Console.WriteLine(string.Format("Test case data has been exported to {0} file in current directory", filename)); } }
public void ExerciseTestCaseResultField() { // TODO: repurpose test cases to exercise resetting List <BaseTestCase> myTests = BaseTestCase.LoadTests("SampleConfigFile.json"); CommandTestCase commandTestCase = myTests[0] as CommandTestCase; Assert.IsTrue(commandTestCase.ActualReturnCode == 0); commandTestCase.ActualReturnCode = 1; commandTestCase.CaseStatus = BaseTestCase.TestCaseStatus.FINISHED; Assert.IsTrue(commandTestCase.ActualReturnCode == 1); Assert.IsTrue(commandTestCase.CaseStatus == BaseTestCase.TestCaseStatus.FINISHED); commandTestCase.ClearTestResult(); Assert.IsTrue(commandTestCase.ActualReturnCode == 0); Assert.IsTrue(commandTestCase.CaseStatus == BaseTestCase.TestCaseStatus.NOT_YET_RUN); }
private static string BuildCurrentAnalysisMessage(BaseTestCase test, IEnumerable <ConfigureSignature> suspectedMethods) { var builder = new StringBuilder(); if (test != null) { builder.AppendLine(test.ToString()); builder.AppendFormat("{0} types tested, {1} suspected methods" + Environment.NewLine + Environment.NewLine, test.TargetTypes.Count(), suspectedMethods.Count()); } else { builder.AppendLine("Nothing analyzed yet"); } return(builder.ToString()); }
public void LoadTestCaseFromJson() { /** * Hello world goal: * Execute a command based on the loaded json * * later on: group of tests that define success * for now, keep it simple. all or nothing */ List <BaseTestCase> myTests = BaseTestCase.LoadTests("SampleConfigFile.json"); Assert.IsTrue(myTests.Count == 2); Assert.IsTrue(myTests[0].TestName == "My test case"); Assert.IsTrue(myTests[0] is CommandTestCase); CommandTestCase commandTestCase = myTests[0] as CommandTestCase; //Assert.IsTrue(commandTestCase.TestCommand == "c:\\Some command.exe"); Assert.IsTrue(commandTestCase.ExpectedResponseCode == 0); Assert.IsTrue(commandTestCase.Params == "-param1 -param2 3"); }
protected override P GetParentNMSInstance <P>(BaseTestCase test) { IConnection connection = null; if (!test.NMSInstanceExists <IConnection>(parentIndex)) { if (NmsParentId == null) { TestSetupFailureParentNotFound(test); } else { connection = test.GetConnection(NmsParentId); } } else { connection = test.GetConnection(parentIndex); } return((P)connection); }
protected IDestination GetDestination(BaseTestCase test) { IDestination destination = null; if (!test.NMSInstanceExists <IDestination>(destinationIndex)) { if (DestinationId == null) { TestSetupFailureDestinationNotFound(test); } else { destination = test.GetDestination(DestinationId); } } else { destination = test.GetDestination(destinationIndex); } return(destination); }
private void SetupBaseTestCase(BaseTestCase testCase) { SetGUIWrapperState(testCase.state); eventType = testCase.eventType; if (testCase.transformIndex != -1) { var transform = m_Transforms[testCase.transformIndex]; mousePosition = Vector3.Lerp(transform.position, transform.TransformPoint(Vector3.right), testCase.hoverPositionRatio); foreach (var t in m_Transforms) { m_BoneGizmoView.LayoutBone(t, 1f); } } if (testCase.forceNearestControl >= 0) { nearestControl = testCase.forceNearestControl; } }
protected IConnectionFactory GetConnectionFactory(BaseTestCase nmsTest) { IConnectionFactory cf = null; if (!nmsTest.NMSInstanceExists <IConnectionFactory>(parentIndex)) { cf = nmsTest.CreateConnectionFactory(); nmsTest.AddConnectionFactory(cf, NmsParentId); } else { if (NmsParentId == null) { cf = nmsTest.GetConnectionFactory(); } else { cf = nmsTest.GetConnectionFactory(NmsParentId); } } BaseTestCase.Logger.Info("Found Connection Factory " + cf + ""); return(cf); }
protected override T CreateNMSInstance <T, P>(BaseTestCase test, P parent) { throw new NotImplementedException(); }
protected override T GetParentNMSInstance <T>(BaseTestCase nmsTest) { nmsTest.InitConnectedFactoryProperties(GetConnectionProperties(nmsTest)); return((T)GetConnectionFactory(nmsTest)); }
protected override void AddInstance <T>(BaseTestCase test, T instance, string id) { BaseTestCase.Logger.Info("Adding Session " + id + " to test " + TestName); test.AddSession((ISession)instance, id); }
protected override void AddInstance <T>(BaseTestCase test, T instance, string id) { test.AddConnection((IConnection)instance, id); }
protected override void AddInstance <T>(BaseTestCase test, T instance, string id) { throw new NotImplementedException(); }
public override void Setup(BaseTestCase nmsTest) { base.Setup(nmsTest); InitializeTest <IConnection, IConnectionFactory>(nmsTest); }
protected virtual void TestSetupFailure(BaseTestCase test, string message) { TestSetupFailure(test, message, FailureException); }