public void PluginRuntimeHandler_InvokePlugin_WhenValidDll_ExpectValidResults() { //------------Setup for test-------------------------- var source = CreatePluginSource(); var svc = CreatePluginService(); //------------Execute Test--------------------------- using (Isolated <PluginRuntimeHandler> isolated = new Isolated <PluginRuntimeHandler>()) { var args = new PluginInvokeArgs { AssemblyLocation = source.AssemblyLocation , AssemblyName = "Foo" , Fullname = svc.Namespace , Method = svc.Method.Name , Parameters = svc.Method.Parameters }; var result = PluginServiceExecutionFactory.InvokePlugin(args); //------------Assert Results------------------------- var castResult = JsonConvert.DeserializeObject(result.ToString()) as dynamic; if (castResult != null) { StringAssert.Contains(castResult.Name.ToString(), "test data"); } else { Assert.Fail("Failed Conversion for Assert"); } } }
protected override object ExecuteService(List <MethodParameter> methodParameters, int update, out ErrorResultTO errors, IOutputFormatter formater = null) { errors = new ErrorResultTO(); var args = new PluginInvokeArgs { AssemblyLocation = Source.AssemblyLocation, AssemblyName = Source.AssemblyName, Fullname = Service.Namespace, Method = Service.Method.Name, Parameters = Service.Method.Parameters, OutputFormatter = formater }; object result = null; try { result = PluginServiceExecutionFactory.InvokePlugin(args); } catch (Exception e) { errors.AddError(e.Message); } return(result); }
void RegularMethodExecution(Isolated <PluginRuntimeHandler> appDomain, PluginExecutionDto pluginExecutionDto, IDev2MethodInfo dev2MethodInfo, int i, int update, IDSFDataObject dataObject) { var start = DateTime.Now; pluginExecutionDto.ObjectString = ObjectResult; var result = PluginServiceExecutionFactory.InvokePlugin(appDomain, pluginExecutionDto, dev2MethodInfo, out string objString); pluginExecutionDto.ObjectString = objString; ObjectResult = objString; var pluginAction = MethodsToRun[i]; pluginAction.MethodResult = result.MethodResult; pluginAction.HasError = result.HasError; pluginAction.ErrorMessage = result.ErrorMessage; dev2MethodInfo.HasError = result.HasError; dev2MethodInfo.ErrorMessage = result.ErrorMessage; if (result.HasError) { DispatchDebugStateForMethod(pluginAction, dataObject, update, false, start); return; } AssignMethodResult(pluginAction, update, dataObject, start); if (!string.IsNullOrEmpty(ObjectName) && !pluginExecutionDto.IsStatic) { var jToken = JToken.Parse(ObjectResult) as JContainer ?? ObjectResult.DeserializeToObject(); dataObject.Environment.AddToJsonObjects(ObjectName, jToken); } }
protected void ExecuteService(int update, out ErrorResultTO errors, IPluginAction method, INamespaceItem namespaceItem, IDSFDataObject dataObject) { errors = new ErrorResultTO(); var itrs = new List<IWarewolfIterator>(5); IWarewolfListIterator itrCollection = new WarewolfListIterator(); var methodParameters = Inputs.Select(a => new MethodParameter { EmptyToNull = a.EmptyIsNull, IsRequired = a.RequiredField, Name = a.Name, Value = a.Value, TypeName = a.TypeName }).ToList(); BuildParameterIterators(update, methodParameters.ToList(), itrCollection, itrs, dataObject); var args = new PluginInvokeArgs { AssemblyLocation = Namespace.AssemblyLocation, AssemblyName = Namespace.AssemblyName, Fullname = namespaceItem.FullName, Method = method.Method, Parameters = methodParameters }; try { while (itrCollection.HasMoreData()) { int pos = 0; foreach (var itr in itrs) { string injectVal = itrCollection.FetchNextValue(itr); var param = methodParameters.ToList()[pos]; param.Value = param.EmptyToNull && (injectVal == null || string.Compare(injectVal, string.Empty, StringComparison.InvariantCultureIgnoreCase) == 0) ? null : injectVal; pos++; } if (!IsObject) { int i = 0; foreach (var serviceOutputMapping in Outputs) { OutputDescription.DataSourceShapes[0].Paths[i].OutputExpression = DataListUtil.AddBracketsToValueIfNotExist(serviceOutputMapping.MappedTo); i++; } var outputFormatter = OutputFormatterFactory.CreateOutputFormatter(OutputDescription); args.OutputFormatter = outputFormatter; } var result = PluginServiceExecutionFactory.InvokePlugin(args).ToString(); ResponseManager = new ResponseManager { OutputDescription = OutputDescription, Outputs = Outputs, IsObject = IsObject, ObjectName = ObjectName }; ResponseManager.PushResponseIntoEnvironment(result, update, dataObject,false); } } catch (Exception e) { errors.AddError(e.Message); } }
void RegularConstructorExecution(IDSFDataObject dataObject, Isolated <PluginRuntimeHandler> appDomain, ref PluginExecutionDto pluginExecutionDto) { pluginExecutionDto = PluginServiceExecutionFactory.ExecuteConstructor(appDomain, pluginExecutionDto); ObjectResult = pluginExecutionDto.ObjectString; if (!string.IsNullOrEmpty(ObjectName) && !pluginExecutionDto.IsStatic) { var jToken = JToken.Parse(ObjectResult) as JContainer ?? ObjectResult.DeserializeToObject(); dataObject.Environment.AddToJsonObjects(ObjectName, jToken); } }
public void PluginRuntimeHandler_GetNamespaces_WhenValidDll_ExpectNamespaces() { //------------Setup for test-------------------------- var source = CreatePluginSource(); //------------Execute Test--------------------------- var result = PluginServiceExecutionFactory.GetNamespaces(source); //------------Assert Results------------------------- Assert.IsTrue(result.Count > 0); }
public void PluginRuntimeHandler_Validate_WhenValidDll_ExpectBlankMessage() { //------------Setup for test-------------------------- var source = CreatePluginSource(); //------------Execute Test--------------------------- var result = PluginServiceExecutionFactory.ValidatePlugin(source.AssemblyLocation); //------------Assert Results------------------------- StringAssert.Contains(result, string.Empty); }
public void PluginRuntimeHandler_GetNamespacesWithJsonObjects_WhenValidDll_ExpectNamespaces() { //------------Setup for test-------------------------- var source = CreatePluginSource(); //------------Execute Test--------------------------- //using (Isolated<PluginRuntimeHandler> isolated = new Isolated<PluginRuntimeHandler>()) { var result = PluginServiceExecutionFactory.GetNamespacesWithJsonObjects(source); //------------Assert Results------------------------- Assert.IsTrue(result.Count > 0); } }
public NamespaceList GetNamespacesWithJsonObjects(PluginSource pluginSource) { try { return(PluginServiceExecutionFactory.GetNamespacesWithJsonObjects(pluginSource)); } catch (BadImageFormatException) { throw; } }
public void PluginRuntimeHandler_GetMethods_WhenValidDll_ExpectValidResults() { //------------Setup for test-------------------------- var source = CreatePluginSource(); var service = CreatePluginService(); //------------Execute Test--------------------------- var result = PluginServiceExecutionFactory.GetMethods(source.AssemblyLocation, source.AssemblyName, service.Namespace); //------------Assert Results------------------------- Assert.IsTrue(result.Count > 0); }
public NamespaceList GetNamespacesWithJsonObjects(PluginSource pluginSource) { try { return(PluginServiceExecutionFactory.GetNamespacesWithJsonObjects(pluginSource)); } // ReSharper disable once RedundantCatchClause catch (BadImageFormatException) { throw; } }
public void PluginRuntimeHandler_GetConstructors_WhenValidDll_ExpectValidResults() { //------------Setup for test-------------------------- var source = CreatePluginSource(); var service = CreatePluginService(); //------------Execute Test--------------------------- using (Isolated <PluginRuntimeHandler> isolated = new Isolated <PluginRuntimeHandler>()) { var result = PluginServiceExecutionFactory.GetConstructors(source.AssemblyLocation, source.AssemblyName, service.Namespace); //------------Assert Results------------------------- Assert.IsTrue(result.Count > 0); } }
#pragma warning disable S1541 // Methods and properties should not be too complex void TryExecuteService(int update, IDSFDataObject dataObject, PluginExecutionDto pluginExecutionDto, PluginInvokeArgs args) #pragma warning restore S1541 // Methods and properties should not be too complex { using (var appDomain = PluginServiceExecutionFactory.CreateAppDomain()) { if (dataObject.IsServiceTestExecution) { var serviceTestStep = dataObject.ServiceTest?.TestSteps?.Flatten(step => step.Children)?.FirstOrDefault(step => step.ActivityID == pluginExecutionDto.Args.PluginConstructor.ID); if (serviceTestStep != null && serviceTestStep.Type == StepType.Mock) { var start = DateTime.Now; MockConstructorExecution(dataObject, serviceTestStep, ref pluginExecutionDto); DebugStateForConstructorInputsOutputs(dataObject, update, true, start); } else { var start = DateTime.Now; RegularConstructorExecution(dataObject, appDomain, ref pluginExecutionDto); DebugStateForConstructorInputsOutputs(dataObject, update, false, start); } } else { var start = DateTime.Now; RegularConstructorExecution(dataObject, appDomain, ref pluginExecutionDto); DebugStateForConstructorInputsOutputs(dataObject, update, false, start); } var index = 0; foreach (var dev2MethodInfo in args.MethodsToRun) { if (dataObject.IsServiceTestExecution) { var serviceTestStep = dataObject.ServiceTest?.TestSteps?.Flatten(step => step.Children)?.FirstOrDefault(step => step.ActivityID == dev2MethodInfo.ID); MethodExecution(update, dataObject, pluginExecutionDto, appDomain, index, dev2MethodInfo, serviceTestStep); } else { RegularMethodExecution(appDomain, pluginExecutionDto, dev2MethodInfo, index, update, dataObject); } if (dev2MethodInfo.HasError) { break; } index++; } } }
/// <summary> /// Tests the plugin. /// </summary> /// <param name="pluginService">The plugin service.</param> /// <returns></returns> public IOutputDescription TestPlugin(PluginService pluginService) { PluginInvokeArgs args = new PluginInvokeArgs { AssemblyLocation = ((PluginSource)pluginService.Source).AssemblyLocation, AssemblyName = ((PluginSource)pluginService.Source).AssemblyName, Method = pluginService.Method.Name, Fullname = pluginService.Namespace, Parameters = pluginService.Method.Parameters }; var pluginResult = PluginServiceExecutionFactory.TestPlugin(args); return(pluginResult); }
public void PluginRuntimeHandler_GetMethodsWithReturns_WhenValidDllMethodIsVoid_ExpectValidResultsWithVoidMethod() { //------------Setup for test-------------------------- var source = CreatePluginSource(); var service = CreatePluginService(); //------------Execute Test--------------------------- using (Isolated <PluginRuntimeHandler> isolated = new Isolated <PluginRuntimeHandler>()) { var result = PluginServiceExecutionFactory.GetMethodsWithReturns(source.AssemblyLocation, source.AssemblyName, service.Namespace); //------------Assert Results------------------------- Assert.IsTrue(result.Count > 0); Assert.IsTrue(result.Any(method => method.IsVoid)); } }
public void PluginRuntimeHandler_InvokePlugin_WhenValidDll_ExpectValidResults() { //------------Setup for test-------------------------- var source = CreatePluginSource(); var svc = CreatePluginService(); PluginInvokeArgs args = new PluginInvokeArgs { AssemblyLocation = source.AssemblyLocation, AssemblyName = "Foo", Fullname = svc.Namespace, Method = svc.Method.Name, Parameters = svc.Method.Parameters }; //------------Execute Test--------------------------- var result = PluginServiceExecutionFactory.InvokePlugin(args); var castResult = result as DummyClassForPluginTest; //------------Assert Results------------------------- if (castResult != null) { StringAssert.Contains(castResult.Name, "test data"); } else { Assert.Fail("Failed Conversion for Assert"); } }
private void TryExecute(int update, IDSFDataObject dataObject, List <IWarewolfIterator> itrs, IWarewolfListIterator itrCollection, List <MethodParameter> methodParameters, PluginInvokeArgs args) { while (itrCollection.HasMoreData()) { var pos = 0; foreach (var itr in itrs) { var injectVal = itrCollection.FetchNextValue(itr); var param = methodParameters.ToList()[pos]; param.Value = param.EmptyToNull && (injectVal == null || string.Compare(injectVal, string.Empty, StringComparison.InvariantCultureIgnoreCase) == 0) ? null : injectVal; pos++; } if (!IsObject) { var i = 0; foreach (var serviceOutputMapping in Outputs) { OutputDescription.DataSourceShapes[0].Paths[i].OutputExpression = DataListUtil.AddBracketsToValueIfNotExist(serviceOutputMapping.MappedTo); i++; } var outputFormatter = OutputFormatterFactory.CreateOutputFormatter(OutputDescription); args.OutputFormatter = outputFormatter; } var result = PluginServiceExecutionFactory.InvokePlugin(args).ToString(); ResponseManager = new ResponseManager { OutputDescription = OutputDescription, Outputs = Outputs, IsObject = IsObject, ObjectName = ObjectName }; ResponseManager.PushResponseIntoEnvironment(result, update, dataObject, false); } }
public bool ValidatePlugin(string toLoad, out string error) { error = PluginServiceExecutionFactory.ValidatePlugin(toLoad); return(error == string.Empty); }
/// <summary> /// Gets the methods. /// </summary> /// <param name="assemblyLocation">The assembly location.</param> /// <param name="assemblyName">Name of the assembly.</param> /// <param name="fullName">The full name.</param> /// <returns></returns> public ServiceMethodList GetMethods(string assemblyLocation, string assemblyName, string fullName) { return(PluginServiceExecutionFactory.GetMethods(assemblyLocation, assemblyName, fullName)); }
/// <summary> /// Gets the namespaces. /// </summary> /// <param name="pluginSource">The plugin source.</param> /// <returns></returns> public NamespaceList GetNamespaces(PluginSource pluginSource) { return(PluginServiceExecutionFactory.GetNamespaces(pluginSource)); }
public void PluginRuntimeHandler_GetNamespacesWithJsonObjects_WhenNullDll_ExpectException() { //------------Execute Test--------------------------- PluginServiceExecutionFactory.GetNamespacesWithJsonObjects(null); }
public ServiceMethodList GetMethodsWithReturns(string assemblyLocation, string assemblyName, string fullName) => PluginServiceExecutionFactory.GetMethodsWithReturns(assemblyLocation, assemblyName, fullName);
public ServiceConstructorList GetConstructors(string assemblyLocation, string assemblyName, string fullName) { return(PluginServiceExecutionFactory.GetConstructors(assemblyLocation, assemblyName, fullName)); }
private void ExecuteService(int update, out ErrorResultTO errors, IPluginConstructor constructor, INamespaceItem namespaceItem, IDSFDataObject dataObject) { _childStatesToDispatch = new List <IDebugState>(); errors = new ErrorResultTO(); PluginExecutionDto pluginExecutionDto; if (Constructor.IsExistingObject) { var existingObj = DataListUtil.AddBracketsToValueIfNotExist(Constructor.ConstructorName); var warewolfEvalResult = dataObject.Environment.EvalForJson(existingObj); var existingObject = ExecutionEnvironment.WarewolfEvalResultToString(warewolfEvalResult); pluginExecutionDto = new PluginExecutionDto(existingObject); ObjectResult = pluginExecutionDto.ObjectString; } else { pluginExecutionDto = new PluginExecutionDto(string.Empty); } constructor.Inputs = new List <IConstructorParameter>(); foreach (var parameter in ConstructorInputs) { var resultToString = GetEvaluatedResult(dataObject, parameter.Value, parameter.EmptyIsNull, update); constructor.Inputs.Add(new ConstructorParameter() { TypeName = parameter.TypeName, Name = parameter.Name, Value = resultToString, EmptyToNull = parameter.EmptyIsNull, IsRequired = parameter.RequiredField }); } var args = BuidlPluginInvokeArgs(update, constructor, namespaceItem, dataObject); pluginExecutionDto.Args = args; try { using (var appDomain = PluginServiceExecutionFactory.CreateAppDomain()) { if (dataObject.IsServiceTestExecution) { var serviceTestStep = dataObject.ServiceTest?.TestSteps?.Flatten(step => step.Children)?.FirstOrDefault(step => step.UniqueId == pluginExecutionDto.Args.PluginConstructor.ID); if (serviceTestStep != null && serviceTestStep.Type == StepType.Mock) { var start = DateTime.Now; MockConstructorExecution(dataObject, serviceTestStep, ref pluginExecutionDto); DebugStateForConstructorInputsOutputs(dataObject, update, true, start); } else { var start = DateTime.Now; RegularConstructorExecution(dataObject, appDomain, ref pluginExecutionDto); DebugStateForConstructorInputsOutputs(dataObject, update, false, start); } } else { var start = DateTime.Now; RegularConstructorExecution(dataObject, appDomain, ref pluginExecutionDto); DebugStateForConstructorInputsOutputs(dataObject, update, false, start); } var index = 0; foreach (var dev2MethodInfo in args.MethodsToRun) { if (dataObject.IsServiceTestExecution) { var serviceTestStep = dataObject.ServiceTest?.TestSteps?.Flatten(step => step.Children)?.FirstOrDefault(step => step.UniqueId == dev2MethodInfo.ID); if (serviceTestStep != null) { if (serviceTestStep.Type == StepType.Mock) { MockMethodExecution(dataObject, serviceTestStep, dev2MethodInfo, index); } else { RegularMethodExecution(appDomain, pluginExecutionDto, dev2MethodInfo, index, update, dataObject); } } else { RegularMethodExecution(appDomain, pluginExecutionDto, dev2MethodInfo, index, update, dataObject); } } else { RegularMethodExecution(appDomain, pluginExecutionDto, dev2MethodInfo, index, update, dataObject); } if (dev2MethodInfo.HasError) { break; } index++; } } } catch (Exception e) { if (e.Message.Contains("Cannot convert given JSON to target type")) { errors.AddError(ErrorResource.JSONIncompatibleConversionError + Environment.NewLine + e.Message); } else { errors.AddError(e.Message); } } }
public void PluginRuntimeHandler_Validate_WhenNullDll_ExpectException() { //------------Execute Test--------------------------- PluginServiceExecutionFactory.ValidatePlugin(null); }