コード例 #1
0
        public void Outputs_GivenNull_ShouldRemovedEventHandlers()
        {
            //---------------Set up test pack-------------------
            var act = new DsfWebGetActivity {
                SourceId = Guid.NewGuid(), Outputs = null
            };
            var outputsRegion        = new OutputsRegion(ModelItemUtils.CreateModelItem(act), true);
            var serviceOutputMapping = new ServiceOutputMapping
            {
                MappedFrom = "j",
                MappedTo   = "H"
            };
            var outPutsChanged = false;

            serviceOutputMapping.PropertyChanged += (sender, args) =>
            {
                outPutsChanged |= args.PropertyName == "MappedFrom";
            };
            //---------------Assert Precondition----------------
            Assert.IsNotNull(outputsRegion.Outputs);
            //---------------Execute Test ----------------------
            outputsRegion.Outputs.Add(serviceOutputMapping);
            outputsRegion.Outputs.Add(new ServiceOutputMapping());
            outputsRegion.Outputs.First(mapping => mapping.MappedFrom == "j").MappedFrom = "b";
            Assert.IsTrue(outPutsChanged);
            outPutsChanged = false;
            //---------------Test Result -----------------------
            outputsRegion.Outputs.Remove(serviceOutputMapping);
            outputsRegion.Outputs.First().MappedFrom = "b";
            Assert.IsFalse(outPutsChanged);
        }
コード例 #2
0
        public void ServiceOutputMapping_Constructor_EmptyConstructor_ShouldStillConstruct()
        {
            //------------Setup for test--------------------------
            //------------Execute Test---------------------------
            var serviceOutputMapping = new ServiceOutputMapping();

            //------------Assert Results-------------------------
            Assert.IsNotNull(serviceOutputMapping);
        }
コード例 #3
0
        public void ServiceOutputMapping_Constructor_WhenNoRecordsetName_ShouldConstructorScalarMappedTo()
        {
            //------------Setup for test--------------------------
            const string mappingFrom   = "mapFrom";
            const string mapTo         = "mapTo";
            const string variableMapTo = "[[mapTo]]";
            //------------Execute Test---------------------------
            var serviceOutputMapping = new ServiceOutputMapping(mappingFrom, mapTo, "");

            //------------Assert Results-------------------------
            Assert.IsNotNull(serviceOutputMapping);
            Assert.AreEqual("", serviceOutputMapping.RecordSetName);
            Assert.AreEqual(mappingFrom, serviceOutputMapping.MappedFrom);
            Assert.AreEqual(variableMapTo, serviceOutputMapping.MappedTo);
        }
コード例 #4
0
        public void ServiceOutputMapping_Constructor_EmptyMappingTo_ShouldStillConsturct()
        {
            //------------Setup for test--------------------------
            const string mappingFrom = "mapFrom";
            const string recordSet   = "recset";

            //------------Execute Test---------------------------
            var serviceOutputMapping = new ServiceOutputMapping(mappingFrom, "", recordSet);

            //------------Assert Results-------------------------
            Assert.IsNotNull(serviceOutputMapping);
            Assert.AreEqual("", serviceOutputMapping.MappedTo);
            Assert.AreEqual(mappingFrom, serviceOutputMapping.MappedFrom);
            Assert.AreEqual(recordSet, serviceOutputMapping.RecordSetName);
        }
コード例 #5
0
        public void ServiceOutputMapping_Constructor_EmptyMappingFrom_ShouldStillConsturct()
        {
            //------------Setup for test--------------------------
            const string mappingTo             = "mapTo";
            const string recordSet             = "recset";
            const string variableNameMappingTo = "[[recset().mapTo]]";

            //------------Execute Test---------------------------
            var serviceOutputMapping = new ServiceOutputMapping("", mappingTo, recordSet);

            //------------Assert Results-------------------------
            Assert.IsNotNull(serviceOutputMapping);
            Assert.AreEqual(variableNameMappingTo, serviceOutputMapping.MappedTo);
            Assert.AreEqual(recordSet, serviceOutputMapping.RecordSetName);
        }
コード例 #6
0
        public void ServiceOutputMapping_RecordsetName_WhenContainedInMapTo_ShouldUpdateMapToValue()
        {
            //------------Setup for test--------------------------
            const string mappingFrom                  = "mapFrom";
            const string recordSet                    = "recset";
            const string mapTo                        = "mapTo";
            const string variableNameMappingTo        = "[[recset().mapTo]]";
            const string variableNameMappingToChanged = "[[rec().mapTo]]";
            var          serviceOutputMapping         = new ServiceOutputMapping(mappingFrom, mapTo, recordSet);

            //------------Assert Precondition--------------------
            Assert.IsNotNull(serviceOutputMapping);
            Assert.AreEqual(variableNameMappingTo, serviceOutputMapping.MappedTo);
            //------------Execute Test---------------------------
            serviceOutputMapping.RecordSetName = "rec";
            //------------Assert Results-------------------------
            Assert.AreEqual(variableNameMappingToChanged, serviceOutputMapping.MappedTo);
        }
コード例 #7
0
        List <IServiceOutputMapping> GetDbOutputMappingsFromTable(DataTable testResults)
        {
            var mappings = new List <IServiceOutputMapping>();

            if (testResults != null)
            {
                if (testResults.Columns.Count >= 1)
                {
                    var recordsetName = string.IsNullOrEmpty(testResults.TableName) ? Model.Action.Name.Replace(".", "_") : testResults.TableName;
                    _viewmodel.OutputsRegion.RecordsetName = recordsetName;
                    for (int i = 0; i < testResults.Columns.Count; i++)
                    {
                        var column          = testResults.Columns[i];
                        var dbOutputMapping = new ServiceOutputMapping(column.ToString(), column.ToString().Replace(" ", ""), recordsetName);
                        mappings.Add(dbOutputMapping);
                    }
                    return(mappings);
                }
                _viewmodel.OutputsRegion.RecordsetName = String.Empty;
            }
            return(new List <IServiceOutputMapping>());
        }
コード例 #8
0
        public void SaveWebService_Execute_FormDataParameters_NotNull_ExpectSuccess()
        {
            var testFileKey   = "testFileKey";
            var testFileName  = "testFileName";
            var testFileValue = "testFileContent";

            var testTextKey   = "testTextKey";
            var testTextValue = "testTextValue";

            var resourcePath = "c:\\path/to/save/resource.ext";

            var serializer = new Dev2JsonSerializer();

            var mockResourceCatalog = new Mock <IResourceCatalog>();

            mockResourceCatalog.Setup(o => o.GetResource <WebSource>(Guid.Empty, Guid.Empty))
            .Returns(new Mock <WebSource>().Object)
            .Verifiable();
            mockResourceCatalog.Setup(o => o.SaveResource(It.IsAny <Guid>(), It.IsAny <IResource>(), It.IsAny <string>()))
            .Verifiable();

            var mockExplorerServerResourceRepository = new Mock <IExplorerServerResourceRepository>();

            mockExplorerServerResourceRepository.Setup(o => o.UpdateItem(It.IsAny <IResource>()))
            .Verifiable();

            var saveWebService = new SaveWebService
            {
                ResourceCatalogue  = mockResourceCatalog.Object,
                ServerExplorerRepo = mockExplorerServerResourceRepository.Object
            };

            var mockWebClientWrapper = new Mock <IWebClientWrapper>();

            var mockWebSource = new Mock <IWebSource>();

            mockWebSource.Setup(o => o.Address).Returns("http://address.co.za/examples");
            mockWebSource.Setup(o => o.Client).Returns(mockWebClientWrapper.Object);
            mockWebSource.Setup(o => o.AuthenticationType).Returns(AuthenticationType.Anonymous);

            var serviceOutputMapping = new ServiceOutputMapping("from", "=", "[[rec().a]]");
            var webService           = new WebServiceDefinition
            {
                Path           = resourcePath,
                Source         = new WebServiceSourceDefinition(),
                OutputMappings = new List <IServiceOutputMapping> {
                    serviceOutputMapping
                },
                Headers            = new List <INameValue>(),
                FormDataParameters = new List <IFormDataParameters>
                {
                    new FormDataConditionExpression
                    {
                        Key  = testFileKey,
                        Cond = new FormDataConditionFile
                        {
                            FileBase64 = testFileValue,
                            FileName   = testFileName
                        }
                    }.ToFormDataParameter(),
                    new FormDataConditionExpression
                    {
                        Key  = testTextKey,
                        Cond = new FormDataConditionText
                        {
                            Value = testTextValue
                        }
                    }.ToFormDataParameter()
                },
                IsManualChecked   = false,
                IsFormDataChecked = true,
            };

            var values = new Dictionary <string, StringBuilder>
            {
                { "Webservice", serializer.SerializeToBuilder(webService) }
            };

            var result         = saveWebService.Execute(values, null);
            var executeMessage = serializer.Deserialize <ExecuteMessage>(result);

            Assert.IsNotNull(result);
            Assert.IsFalse(executeMessage.HasError);
            mockResourceCatalog.Verify(o => o.GetResource <WebSource>(Guid.Empty, Guid.Empty), Times.Once);
            mockResourceCatalog.Verify(o => o.SaveResource(Guid.Empty, It.IsAny <IResource>(), resourcePath), Times.Once);
            mockExplorerServerResourceRepository.Verify(o => o.UpdateItem(It.IsAny <IResource>()), Times.Once);
        }
コード例 #9
0
        public void ExecuteTest()
        {
            ViewErrors           = new List <IActionableErrorInfo>();
            Errors               = new List <string>();
            OutputArea.IsEnabled = true;
            TestResults          = null;
            IsTesting            = true;

            try
            {
                var testResult      = _serverModel.TestService(Model);
                var serializer      = new Dev2JsonSerializer();
                var responseService = serializer.Deserialize <RecordsetListWrapper>(testResult);
                if (responseService != null)
                {
                    if (responseService.RecordsetList.Any(recordset => recordset.HasErrors))
                    {
                        var errorMessage = string.Join(Environment.NewLine, responseService.RecordsetList.Select(recordset => recordset.ErrorMessage));
                        throw new Exception(errorMessage);
                    }
                    TestResults    = responseService.SerializedResult;
                    _recordsetList = responseService.RecordsetList;
                    if (_recordsetList.Any(recordset => recordset.HasErrors))
                    {
                        var errorMessage = string.Join(Environment.NewLine, _recordsetList.Select(recordset => recordset.ErrorMessage));
                        throw new Exception(errorMessage);
                    }
                    Description = responseService.Description;

                    var outputMapping = _recordsetList.SelectMany(recordset => recordset.Fields, (recordset, recordsetField) =>
                    {
                        var serviceOutputMapping = new ServiceOutputMapping(recordsetField.Name, recordsetField.Alias, recordset.Name)
                        {
                            Path = recordsetField.Path
                        };
                        return(serviceOutputMapping);
                    }).Cast <IServiceOutputMapping>().ToList();

                    _generateOutputArea.IsEnabled = true;
                    _generateOutputArea.Outputs   = outputMapping;
                }
                if (TestResults != null)
                {
                    TestResultsAvailable = TestResults != null;
                    IsTesting            = false;
                    TestPassed           = true;
                    TestFailed           = false;
                }
            }
            catch (JsonSerializationException)
            {
                OutputArea.Outputs = new List <IServiceOutputMapping> {
                    new ServiceOutputMapping("Result", "[[Result]]", "")
                };
            }
            catch (Exception e)
            {
                Errors.Add(e.Message);
                IsTesting  = false;
                TestPassed = false;
                TestFailed = true;
                _generateOutputArea.IsEnabled = false;
                _generateOutputArea.Outputs   = new List <IServiceOutputMapping>();
                _viewmodel.ErrorMessage(e, true);
            }
        }
コード例 #10
0
        public void ExecuteTest()
        {
            ViewErrors           = new List <IActionableErrorInfo>();
            Errors               = new List <string>();
            OutputArea.IsEnabled = true;
            TestResults          = null;
            IsTesting            = true;

            try
            {
                var testResult = _serverModel.TestService(Model);
                var serializer = new Dev2JsonSerializer();
                using (var responseService = serializer.Deserialize <WebService>(testResult))
                {
                    TestResults    = responseService.RequestResponse;
                    _recordsetList = responseService.Recordsets;
                    if (_recordsetList.Any(recordset => recordset.HasErrors))
                    {
                        var errorMessage = string.Join(Environment.NewLine, _recordsetList.Select(recordset => recordset.ErrorMessage));
                        throw new Exception(errorMessage);
                    }

                    Description = responseService.GetOutputDescription();
                }
                // ReSharper disable MaximumChainedReferences
                var outputMapping = _recordsetList.SelectMany(recordset => recordset.Fields, (recordset, recordsetField) =>
                {
                    var serviceOutputMapping = new ServiceOutputMapping(recordsetField.Name, recordsetField.Alias, recordset.Name)
                    {
                        Path = recordsetField.Path
                    };
                    return(serviceOutputMapping);
                }).Cast <IServiceOutputMapping>().ToList();
                // ReSharper restore MaximumChainedReferences
                _generateOutputArea.IsEnabled = true;
                _generateOutputArea.Outputs   = outputMapping;


                if (TestResults != null)
                {
                    TestResultsAvailable     = TestResults != null;
                    IsTesting                = false;
                    TestPassed               = true;
                    TestFailed               = false;
                    OutputCountExpandAllowed = true;
                }
            }
            catch (JsonSerializationException)
            {
                OutputArea.Outputs = new List <IServiceOutputMapping> {
                    new ServiceOutputMapping("Result", "[[Result]]", "")
                };
            }
            catch (Exception e)
            {
                Errors.Add(e.Message);
                IsTesting  = false;
                TestPassed = false;
                TestFailed = true;
                _generateOutputArea.IsEnabled = false;
                _generateOutputArea.Outputs   = new List <IServiceOutputMapping>();
                _viewmodel.ErrorMessage(e, true);
            }
            PasteResponseVisible = false;
        }