Esempio n. 1
0
        public StringBuilder Execute(Dictionary <string, StringBuilder> values, IWorkspace theWorkspace)
        {
            ExecuteMessage     msg        = new ExecuteMessage();
            Dev2JsonSerializer serializer = new Dev2JsonSerializer();

            try
            {
                Dev2Logger.Info("Test Plugin Service");
                StringBuilder resourceDefinition;

                values.TryGetValue("PluginService", out resourceDefinition);
                IPluginService src = serializer.Deserialize <IPluginService>(resourceDefinition);


                // ReSharper disable MaximumChainedReferences
                var parameters = src.Inputs?.Select(a => new MethodParameter {
                    EmptyToNull = a.EmptyIsNull, IsRequired = a.RequiredField, Name = a.Name, Value = a.Value, TypeName = a.TypeName
                }).ToList() ?? new List <MethodParameter>();
                // ReSharper restore MaximumChainedReferences
                var pluginsrc = ResourceCatalog.Instance.GetResource <PluginSource>(GlobalConstants.ServerWorkspaceID, src.Source.Id);
                var res       = new PluginService
                {
                    Method       = new ServiceMethod(src.Action.Method, src.Name, parameters, new OutputDescription(), new List <MethodOutput>(), "test"),
                    Namespace    = src.Action.FullName,
                    ResourceName = src.Name,
                    ResourceID   = src.Id,
                    Source       = pluginsrc
                };

                string serializedResult;
                var    result = PluginServices.Test(serializer.SerializeToBuilder(res).ToString(), out serializedResult);
                msg.HasError = false;
                msg.Message  = serializer.SerializeToBuilder(new RecordsetListWrapper {
                    Description = result.Description, RecordsetList = result, SerializedResult = serializedResult
                });
            }
            catch (Exception err)
            {
                msg.HasError = true;
                msg.Message  = new StringBuilder(err.Message);
                Dev2Logger.Error(err);
            }

            return(serializer.SerializeToBuilder(msg));
        }
Esempio n. 2
0
        public void PluginServices_Test_WhenTestingPluginReturningJsonString_ExpectValidPaths()
        {
            //------------Setup for test--------------------------
            var path = UnpackDLL("PrimativesTestDLL");

            if (string.IsNullOrEmpty(path))
            {
                Assert.Fail("Failed to unpack required DLL [ PrimativesTestDLL ] ");
            }

            var pluginServices = new PluginServices();
            var serviceDef     = JsonResource.Fetch("PrimitivePluginReturningJsonString");

            //------------Execute Test---------------------------
            var result = pluginServices.Test(serviceDef, out string serializedResult);

            ////------------Assert Results-------------------------
            Assert.AreEqual(1, result[0].Fields.Count);
            StringAssert.Contains(result[0].Fields[0].Alias, "message");
            StringAssert.Contains(result[0].Fields[0].Name, "message");
            StringAssert.Contains(result[0].Fields[0].Path.ActualPath, "message");
            StringAssert.Contains(result[0].Fields[0].Path.SampleData, "Howzit__COMMA__");
        }