Ejemplo n.º 1
0
 public void OptionalTest4()
 {
     OptionalValue<string> a = new OptionalValue<string>();
     Assert.IsFalse(a.Hasvalue);
     a = "foo";
     Assert.IsTrue(a.Hasvalue);
     a.Clear();
     Assert.IsFalse(a.Hasvalue);
     a = null;
     Assert.IsTrue(a.Hasvalue);
     Assert.AreEqual(null, a.Value);
 }
Ejemplo n.º 2
0
        public void OptionalValueConstructorTest2()
        {
            bool caught = false;
            var a = new OptionalValue<int>();
            try {int b = a.Value;}
            catch (System.ArgumentException )
            {
                caught = true;
            }

            if (caught == false)
            {
                Assert.Fail("Did not catch expected exception");
            }
        }
Ejemplo n.º 3
0
 public void OptionalTest6()
 {
     // tests that assignment is copy of the value
     OptionalValue<string> a = new OptionalValue<string>();
     OptionalValue<string> b = new OptionalValue<string>();
     Assert.IsFalse(a.Hasvalue);
     Assert.IsFalse(b.Hasvalue);
     a = "FOO";
     Assert.AreEqual("FOO", a.Value);
     b = a;
     Assert.AreEqual("FOO", b.Value);
     a = "BAR";
     Assert.AreEqual("BAR", a.Value);
     Assert.AreEqual("FOO", b.Value);
 }
Ejemplo n.º 4
0
            public void ConvertsArray()
            {
                var instance = new OptionalValue(new TypeReference(
                                                     collection: new CollectionTypeReference(CollectionKind.Array,
                                                                                             new TypeReference(primitive: PrimitiveType.String)
                                                                                             )
                                                     ));

                JArray value = new JArray(
                    new JValue("myValue1"),
                    new JValue("myValue2")
                    );

                bool success = _converter.TryConvert(instance, typeof(object), _referenceMap, value, out object actual);

                Assert.True(success);
                Assert.IsType <string[]>(actual);
                Assert.Collection((string[])actual,
                                  element => Assert.Equal("myValue1", element, ignoreLineEndingDifferences: true),
                                  element => Assert.Equal("myValue2", element, ignoreLineEndingDifferences: true)
                                  );
            }
Ejemplo n.º 5
0
        private string GetPomElementOptionalValuesDefaultValue(ePomElementValuesType valuesType)
        {
            string      defaultValue       = string.Empty;
            ElementInfo selectedPOMElement = GetElementInfoFromCurerentPOMSelected();

            if (selectedPOMElement != null && selectedPOMElement.OptionalValuesObjectsList.Count > 0)        //For new implementation
            {
                OptionalValue defValue = selectedPOMElement.OptionalValuesObjectsList.Where(s => s.IsDefault == true).FirstOrDefault();
                if (defValue != null)
                {
                    if (valuesType == ePomElementValuesType.Values)
                    {
                        defaultValue = defValue.Value;
                    }
                    else
                    {
                        defaultValue = selectedPOMElement.OptionalValuesObjectsList.IndexOf(defValue).ToString();
                    }
                }
            }
            return(defaultValue);
        }
Ejemplo n.º 6
0
        private ObservableList <EnhancedActInputValue> GetEnhancedUpdatedParams(ObservableList <AppModelParameter> paramsList)
        {
            ObservableList <EnhancedActInputValue> enhancedParamsList = new ObservableList <EnhancedActInputValue>();

            foreach (AppModelParameter ADP in paramsList)
            {
                if (ADP.RequiredAsInput == true)
                {
                    EnhancedActInputValue AIV = new EnhancedActInputValue();
                    AIV.ParamGuid   = ADP.Guid;
                    AIV.Param       = ADP.PlaceHolder;
                    AIV.Description = ADP.Description;
                    foreach (OptionalValue optionalValue in ADP.OptionalValuesList)
                    {
                        AIV.OptionalValues.Add(optionalValue.Value);
                    }

                    EnhancedActInputValue EAIV = null;
                    EAIV = EnhancedInputValueList.Where(x => x.Param == ADP.PlaceHolder).FirstOrDefault();
                    if (EAIV != null)
                    {
                        AIV.Value = EAIV.Value;
                    }
                    else
                    {
                        OptionalValue ov = null;
                        ov = ADP.OptionalValuesList.Where(x => x.IsDefault == true).FirstOrDefault();
                        if (ov != null)
                        {
                            AIV.Value = ov.Value;
                        }
                        //No Default, and no value selected - what to put
                    }

                    enhancedParamsList.Add(AIV);
                }
            }
            return(enhancedParamsList);
        }
Ejemplo n.º 7
0
            public void ConvertsDateValues()
            {
                var instance = new OptionalValue(new TypeReference(primitive: PrimitiveType.Date));

                DateTime now     = DateTime.Now;
                bool     success = _converter.TryConvert(instance, _referenceMap, now, out object actual);

                Assert.True(success);
                Assert.IsType <JObject>(actual);

                var expected = new JObject
                {
                    new JProperty("$jsii.date", now.ToString("yyyy-MM-ddTHH\\:mm\\:ss.fffffffzzz"))
                };

                Assert.Equal(expected, actual);

                success = _converter.TryConvert(instance, _referenceMap, null, out actual);

                Assert.False(success);
                Assert.Null(actual);
            }
            public void ConvertsJsonValues()
            {
                var instance = new OptionalValue(new TypeReference(primitive: PrimitiveType.Json));

                JObject jObject = new JObject(
                    new JProperty("myArray", new JArray(
                                      new JValue(42),
                                      new JValue("myString"),
                                      new JValue(false),
                                      new JObject(),
                                      new JArray(),
                                      new JObject(
                                          new JProperty("nested1", "value1"),
                                          new JProperty("nested2", "value2")
                                          )
                                      ))
                    );

                bool success = _converter.TryConvert(instance, _referenceMap, jObject, out object?actual);

                Assert.True(success);
                Assert.Same(jObject, actual);
            }
            public void RecursivelyConvertsMapElementsWithArrayOfAny()
            {
                var instance = new OptionalValue(new TypeReference
                                                 (
                                                     collection: new CollectionTypeReference(CollectionKind.Map,
                                                                                             new TypeReference
                                                                                             (
                                                                                                 collection: new CollectionTypeReference(CollectionKind.Array,
                                                                                                                                         new TypeReference(primitive: PrimitiveType.Any)
                                                                                                                                         )
                                                                                             )
                                                                                             )
                                                 ));

                var frameworkArray = new Dictionary <string, object>()
                {
                    { "key", new [] { "true" } },
                    { "key2", new [] { false } },
                };

                // This will test the call to FrameworkToJsiiConverter.TryConvertCollectionElement()
                // In the case of a of a Map of Array of Any
                bool success = _converter.TryConvert(instance, _referenceMap, frameworkArray, out object?actual);

                Assert.True(success);
                Assert.IsType <JObject>(actual);

                var expected = JObject.Parse(@"{
                    ""$jsii.map"": {
                        ""key"": [""true""],
                        ""key2"": [false]
                    }
                }");

                Assert.True(JToken.DeepEquals(expected, actual as JObject),
                            $"Expected: {expected}\nActual:   {actual}");
            }
Ejemplo n.º 10
0
        private ObservableList <OptionalValue> GetListOfParamEnums(SwaggerParameter swaggerParameter)
        {
            ObservableList <OptionalValue> lstOptions = new ObservableList <OptionalValue>();

            try
            {
                if (swaggerParameter.Item != null && swaggerParameter.Item.Enumeration != null && swaggerParameter.Item.Enumeration.Count != 0)
                {
                    foreach (object item in swaggerParameter.Item.Enumeration)
                    {
                        OptionalValue value = new OptionalValue()
                        {
                            Value    = item.ToString(),
                            ItemName = item.ToString(),
                        };
                        lstOptions.Add(value);
                    }
                }
                if (swaggerParameter.Enumeration != null && swaggerParameter.Enumeration.Count > 0)
                {
                    foreach (object item in swaggerParameter.Enumeration)
                    {
                        OptionalValue value = new OptionalValue()
                        {
                            Value    = item.ToString(),
                            ItemName = item.ToString(),
                        };
                        lstOptions.Add(value);
                    }
                }
            }
            catch (Exception ex)
            {
                Reporter.ToLog(eLogLevel.ERROR, "Error in getting optional values enum", ex);
            }
            return(lstOptions);
        }
Ejemplo n.º 11
0
        private void DefaultValueRadioButton_Checked(object sender, RoutedEventArgs e)
        {
            OptionalValuesGrid.Grid.CommitEdit(DataGridEditingUnit.Row, true);

            RadioButton isDefaultRb = (RadioButton)sender;

            OptionalValue clickedOv = mAMDP.OptionalValuesList.Where(x => x.Guid == (Guid)isDefaultRb.Tag).FirstOrDefault();

            if (clickedOv != null && clickedOv.IsDefault != true)
            {
                clickedOv.IsDefault = true;
            }

            foreach (OptionalValue nonClickedOv in mAMDP.OptionalValuesList.Where(x => x.Guid != (Guid)isDefaultRb.Tag).ToList())
            {
                if (nonClickedOv.IsDefault != false)
                {
                    nonClickedOv.IsDefault = false;
                }
            }

            editWasDone = true;
            OptionalValuesGrid.Grid.CommitEdit(DataGridEditingUnit.Row, true);
        }
            public void RecursivelyConvertsMapElements()
            {
                var instance = new OptionalValue(new TypeReference(
                                                     collection: new CollectionTypeReference(CollectionKind.Map,
                                                                                             new TypeReference(
                                                                                                 collection: new CollectionTypeReference(CollectionKind.Map,
                                                                                                                                         new TypeReference(primitive: PrimitiveType.String)
                                                                                                                                         )
                                                                                                 )
                                                                                             )
                                                     ));

                var frameworkMap = new Dictionary <string, IDictionary <string, string> >
                {
                    { "myKey1", new Dictionary <string, string> {
                          { "mySubKey1", "myValue1" }
                      } },
                    { "myKey2", new Dictionary <string, string> {
                          { "mySubKey2", "myValue2" }
                      } },
                };

                bool success = _converter.TryConvert(instance, _referenceMap, frameworkMap, out object?actual);

                Assert.True(success);
                Assert.IsType <JObject>(actual);
                var expected = JObject.Parse(@"{
                    ""$jsii.map"": {
                        ""myKey1"": { ""$jsii.map"": { ""mySubKey1"": ""myValue1"" } },
                        ""myKey2"": { ""$jsii.map"": { ""mySubKey2"": ""myValue2"" } }
                    }
                }");

                Assert.True(JToken.DeepEquals(expected, actual as JObject),
                            $"Expected: {expected}\nActual:   {actual}");
            }
Ejemplo n.º 13
0
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            OptionalValuesGrid.Grid.CommitEdit(DataGridEditingUnit.Row, true);

            for (int i = 0; i < OptionalValuesGrid.Grid.Items.Count; i++)
            {
                OptionalValue OV = (OptionalValue)OptionalValuesGrid.Grid.Items[i];
                if (string.IsNullOrEmpty(OV.Value))
                {
                    if (OV.IsDefault)
                    {
                        ((OptionalValue)(OptionalValuesGrid.Grid.Items[0])).IsDefault = true;
                    }
                    mAMDP.OptionalValuesList.Remove(OV);
                    i--;
                }
            }

            OptionalValuesGrid.Grid.CommitEdit(DataGridEditingUnit.Row, true);

            mWin.Close();

            mAMDP.OnPropertyChanged(nameof(AppModelParameter.OptionalValuesString));
        }
Ejemplo n.º 14
0
        public void CreateScenarios(BusinessFlow BF)
        {
            string FileName = string.Empty;

            if (BF.ExternalID != null)
            {
                FileName = BF.ExternalID.Replace(@"~", WorkSpace.Instance.Solution.Folder);
            }

            if (!System.IO.File.Exists(FileName))
            {
                // General
                Reporter.ToUser(eUserMsgKey.GherkinFileNotFound, FileName);
                return;
            }

            Parser          parser          = new Parser();
            GherkinDocument gherkinDocument = parser.Parse(FileName);

            mBizFlow = BF;

            ClearGeneretedActivites(mBizFlow);
            ClearOptimizedScenariosVariables(mBizFlow);

            //Add Tags to BF
            foreach (var t in gherkinDocument.Feature.Tags)
            {
                Guid TagGuid = GetOrCreateTagInSolution(t.Name);
                mBizFlow.Tags.Add(TagGuid);
            }

            foreach (Gherkin.Ast.ScenarioDefinition sc in gherkinDocument.Feature.Children)
            {
                IEnumerable <Examples> examples = null;
                // In case of Scenario Outline we need to generate new BF per each line in the table of examples
                if (sc.Keyword == "Scenario Outline")
                {
                    ScenarioOutline so = (ScenarioOutline)sc;
                    examples = so.Examples;
                }

                // Create new BF per each scenario

                if (examples == null)
                {
                    CreateScenario(sc);
                }
                else
                {
                    int i = 0;
                    ValuesDict = new Dictionary <string, List <OptionalValue> >();

                    //TODO: handle case of more than one example table - check what is Gherking expected todo: all combinations!!??
                    foreach (Examples x in examples)
                    {
                        foreach (Gherkin.Ast.TableRow tr in x.TableBody)
                        {
                            i++;
                            ActivitiesGroup AG = CreateScenario(sc, i);
                            // Now the we have the flow created with activities, we update the activities var replacing <param> with value from table
                            var activities = from z in BF.Activities where z.ActivitiesGroupID == AG.Name select z;

                            foreach (Activity a in activities)
                            {
                                while (true)
                                {
                                    string ColName = General.GetStringBetween(a.ActivityName, "<", ">");
                                    if (string.IsNullOrEmpty(ColName))
                                    {
                                        break;
                                    }

                                    string val = GetExampleValue(x.TableHeader, tr, ColName);
                                    a.ActivityName = a.ActivityName.Replace("<" + ColName + ">", "\"" + val + "\"");

                                    VariableBase v = a.Variables.Where(y => y.Name == ColName).FirstOrDefault();

                                    OptionalValue ov = new OptionalValue(val);
                                    if (ValuesDict.ContainsKey(ColName))
                                    {
                                        ValuesDict[ColName].Add(ov);
                                    }
                                    else
                                    {
                                        List <OptionalValue> newList = new List <OptionalValue>();
                                        newList.Add(ov);
                                        ValuesDict.Add(ColName, newList);
                                    }
                                    ((VariableSelectionList)v).OptionalValuesList.Add(ov);
                                    ((VariableSelectionList)v).SelectedValue = val;
                                }
                            }
                        }
                    }

                    foreach (Activity a in BF.Activities)
                    {
                        foreach (VariableBase vb in a.Variables)
                        {
                            if (vb is VariableSelectionList)
                            {
                                if (ValuesDict.ContainsKey(vb.Name))
                                {
                                    foreach (OptionalValue ov in ValuesDict[vb.Name])
                                    {
                                        OptionalValue ExistedOV = ((VariableSelectionList)vb).OptionalValuesList.Where(y => y.Value == ov.Value).FirstOrDefault();
                                        if (ExistedOV == null)
                                        {
                                            ((VariableSelectionList)vb).OptionalValuesList.Add(ov);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(NotFoundItems))
            {
                Reporter.ToUser(eUserMsgKey.GherkinColumnNotExist, NotFoundItems);
            }
        }
Ejemplo n.º 15
0
        public static void Samples([CallerFilePath] string file = "")
        {
            var root = Path.GetDirectoryName(file);

            // ------------------------------------------------------------
            // Creating time series
            // ------------------------------------------------------------

            // [create-builder]
            var numNames = new SeriesBuilder <int, string>()
            {
                { 1, "one" }, { 2, "two" }, { 3, "three" }
            }.Series;

            numNames.Print();
            // [/create-builder]

            // [create-heterogen]
            // Create series builder and use it via 'dynamic'
            var     nameNumsBuild = new SeriesBuilder <string, int>();
            dynamic nameNumsDyn   = nameNumsBuild;

            nameNumsDyn.One   = 1;
            nameNumsDyn.Two   = 2;
            nameNumsDyn.Three = 3;

            // Build series and print it
            var nameNums = nameNumsBuild.Series;

            nameNums.Print();
            // [/create-heterogen]

            // [create-ordinal]
            var rnd      = new Random();
            var randNums = Enumerable.Range(0, 100)
                           .Select(_ => rnd.NextDouble()).ToOrdinalSeries();

            randNums.Print();
            // [/create-ordinal]

            // [create-kvp]
            var sin = Enumerable.Range(0, 1000)
                      .Select(x => KeyValue.Create(x, Math.Sin(x / 100.0)))
                      .ToSeries();

            sin.Print();
            // [/create-kvp]

            // [create-sparse]
            var opts = Enumerable.Range(0, 10)
                       .Select(x => KeyValue.Create(x, OptionalValue.OfNullable <int>(x)))
                       .ToSparseSeries();

            opts.Print();
            // [/create-sparse]

            // [create-csv]
            var frame     = Frame.ReadCsv(Path.Combine(root, "../data/stocks/msft.csv"));
            var frameDate = frame.IndexRows <DateTime>("Date").SortRowsByKey();
            var msftOpen  = frameDate.GetColumn <double>("Open");

            msftOpen.Print();
            // [/create-csv]

            // ------------------------------------------------------------
            // Lookup and slicing
            // ------------------------------------------------------------

            // [lookup-key]
            // Get value for a specified int and string key
            var tenth = randNums[10];
            var one   = nameNums["One"];

            // Get first and last value using index
            var fst = nameNums.GetAt(0);
            var lst = nameNums.GetAt(nameNums.KeyCount - 1);
            // [/lookup-key]

            // [lookup-opt]
            // Get value as OptionalValue<T> and use it
            var opt = opts.TryGet(5);

            if (opt.HasValue)
            {
                Console.Write(opt.Value);
            }

            // For value types, we can convert to nullable type
            int?value1 = opts.TryGet(5).AsNullable();
            int?value2 = opts.TryGetAt(0).AsNullable();
            // [/lookup-opt]

            // [lookup-ord]
            // Get value exactly at the specified key
            var jan3 = msftOpen
                       .Get(new DateTime(2012, 1, 3));

            // Get value at a key or for the nearest previous date
            var beforeJan1 = msftOpen
                             .Get(new DateTime(2012, 1, 1), Lookup.ExactOrSmaller);

            // Get value at a key or for the nearest later date
            var afterJan1 = msftOpen
                            .Get(new DateTime(2012, 1, 1), Lookup.ExactOrGreater);
            // [/lookup-ord]

            // [lookup-slice]
            // Get a series starting/ending at
            // the specified date (inclusive)
            var msftStartIncl = msftOpen.StartAt(new DateTime(2012, 1, 1));
            var msftEndIncl   = msftOpen.EndAt(new DateTime(2012, 12, 31));

            // Get a series starting/ending after/before
            // the specified date (exclusive)
            var msftStartExcl = msftOpen.After(new DateTime(2012, 1, 1));
            var msftEndExcl   = msftOpen.Before(new DateTime(2012, 12, 31));

            // Get prices for 2012 (both keys are inclusive)
            var msft2012 = msftOpen.Between
                               (new DateTime(2012, 1, 1), new DateTime(2012, 12, 31));
            // [/lookup-slice]

            // ------------------------------------------------------------
            // Statistics and calculations
            // ------------------------------------------------------------

            // [calc-stat]
            // Calculate median & mean price
            var msftMed = msft2012.Median();
            var msftAvg = msft2012.Mean();

            // Calculate sum of square differences
            var msftDiff = msft2012 - msftAvg;
            var msftSq   = (msftDiff * msftDiff).Sum();
            // [/calc-stat]

            // [calc-diff]
            // Subtract previous day value from current day
            var msftChange = msft2012 - msft2012.Shift(1);

            // Use built-in Diff method to do the same
            var msftChangeAlt = msft2012.Diff(1);

            // Get biggest loss and biggest gain
            var minMsChange = msftChange.Min();
            var maxMsChange = msftChange.Max();
            // [/calc-diff]

            // [calc-custom]
            var wackyStat = msft2012.Observations.Select(kvp =>
                                                         kvp.Value / (kvp.Key - msft2012.FirstKey()).TotalDays).Sum();
            // [/calc-custom]

            // ------------------------------------------------------------
            // Missing data
            // ------------------------------------------------------------

            // [fill-const-drop]
            // Fill missing data with constant
            var fillConst = opts.FillMissing(-1);

            fillConst.Print();

            // Drop keys with no value from the series
            var drop = opts.DropMissing();

            drop.Print();
            // [/fill-const-drop]

            // [fill-dir]
            // Fill with previous available value
            var fillFwd = opts.FillMissing(Direction.Forward);

            fillFwd.Print();

            // Fill with the next available value
            var fillBwd = opts.FillMissing(Direction.Backward);

            fillBwd.Print();
            // [/fill-dir]

            // ------------------------------------------------------------
            // Windows and chunks, grouping
            // ------------------------------------------------------------

            // [aggreg-group]
            // Group random numbers by the first digit & get distribution
            var buckets = randNums
                          .GroupBy(kvp => (int)(kvp.Value * 10))
                          .Select(kvp => OptionalValue.Create(kvp.Value.KeyCount));

            buckets.Print();
            // [/aggreg-group]

            // [aggreg-win]
            // Average over 25 element floating window
            var monthlyWinMean = msft2012.WindowInto(25, win => win.Mean());

            // Get floating window over 5 elements as series of series
            // and then apply average on each series individually
            var weeklyWinMean = msft2012.Window(5).Select(kvp =>
                                                          kvp.Value.Mean());
            // [/aggreg-win]

            // [aggreg-chunk]
            // Get chunks of size 25 and mean each (disjoint) chunk
            var monthlyChunkMean = msft2012.ChunkInto(25, win => win.Mean());

            // Get series containing individual chunks (as series)
            var weeklyChunkMean = msft2012.Chunk(5).Select(kvp =>
                                                           kvp.Value.Mean());
            // [/aggreg-chunk]

            // [aggreg-pair]
            // For each key, get the previous value and average them
            var twoDayAvgs = msft2012.Pairwise().Select(kvp =>
                                                        (kvp.Value.Item1 + kvp.Value.Item2) / 2.0);

            // [/aggreg-pair]

            // [aggreg-any]
            msft2012.Aggregate
                (                 // Get chunks while the month & year of the keys are the same
                Aggregation.ChunkWhile <DateTime>((k1, k2) =>
                                                  k1.Month == k2.Month && k2.Year == k1.Year),
                // For each chunk, return the first key as the key and
                // either average value or missing value if it was empty
                chunk => KeyValue.Create
                    (chunk.Data.FirstKey(),
                    chunk.Data.ValueCount > 0 ?
                    OptionalValue.Create(chunk.Data.Mean()) :
                    OptionalValue.Empty <double>()));
            // [/aggreg-any]


            // ------------------------------------------------------------
            // Operations (Select, where)
            // ------------------------------------------------------------

            // [linq-methods]
            var overMean = msft2012
                           .Select(kvp => kvp.Value - msftAvg)
                           .Where(kvp => kvp.Value > 0.0).KeyCount;
            // [/linq-methods]

            // [linq-query]
            var underMean =
                (from kvp in msft2012
                 where kvp.Value - msftAvg < 0.0
                 select kvp).KeyCount;

            // [/linq-query]

            Console.WriteLine(overMean);
            Console.WriteLine(underMean);

            // ------------------------------------------------------------
            // Indexing and sampling & resampling
            // ------------------------------------------------------------

            // [index-keys]
            // Turn DateTime keys into DateTimeOffset keys
            var byOffs = msft2012.SelectKeys(kvp =>
                                             new DateTimeOffset(kvp.Key));

            // Replace keys with ordinal numbers 0 .. KeyCount-1
            var byInt = msft2012.IndexOrdinally();
            // [/index-keys]

            // [index-with]
            // Replace keys with explictly specified new keys
            var byDays = numNames.IndexWith(new[] {
                DateTime.Today,
                DateTime.Today.AddDays(1.0),
                DateTime.Today.AddDays(2.0)
            });
            // [/index-with]
        }
Ejemplo n.º 16
0
        public void APIParsingSavingAndPulling()
        {
            // Arrange

            //Act

            ApplicationAPIModel AAMS1 = new ApplicationAPIModel();

            AAMS1.Name           = "Soap1";
            AAMS1.Description    = "Description";
            AAMS1.EndpointURL    = "EndpointURL";
            AAMS1.ReqHttpVersion = ApplicationAPIUtils.eHttpVersion.HTTPV10;
            AppModelParameter AMDP = new AppModelParameter()
            {
                PlaceHolder = "placeholder", Description = "Description"
            };
            OptionalValue OV1 = new OptionalValue("Value1");
            OptionalValue OV2 = new OptionalValue("Value2");

            AMDP.OptionalValuesList.Add(OV1);
            AMDP.OptionalValuesList.Add(OV2);
            AAMS1.AppModelParameters = new ObservableList <AppModelParameter>();
            AAMS1.AppModelParameters.Add(AMDP);

            APIModelKeyValue AMKV = new APIModelKeyValue("param", "value");

            //AAMS1.APIModelKeyValueHeaders = new ObservableList<APIModelKeyValue>();
            //AAMS1.APIModelKeyValueHeaders.Add(AMKV);

            AAMS1.NetworkCredentials          = ApplicationAPIUtils.eNetworkCredentials.Custom;
            AAMS1.URLUser                     = "******";
            AAMS1.URLDomain                   = "URLDomain";
            AAMS1.URLPass                     = "******";
            AAMS1.DoNotFailActionOnBadRespose = true;


            AAMS1.HttpHeaders = new ObservableList <APIModelKeyValue>();
            AAMS1.HttpHeaders.Add(AMKV);
            AAMS1.RequestBodyType      = ApplicationAPIUtils.eRequestBodyType.FreeText;
            AAMS1.CertificateType      = ApplicationAPIUtils.eCretificateType.AllSSL;
            AAMS1.CertificatePath      = "CertificatePath";
            AAMS1.ImportCetificateFile = true;
            AAMS1.CertificatePassword  = "******";
            AAMS1.SecurityType         = ApplicationAPIUtils.eSercurityType.Ssl3;
            AAMS1.AuthorizationType    = ApplicationAPIUtils.eAuthType.BasicAuthentication;

            AAMS1.TemplateFileNameFileBrowser = "TemplateFileNameFileBrowser";
            AAMS1.ImportRequestFile           = "ImportRequestFile";
            AAMS1.AuthUsername = "******";
            AAMS1.AuthPassword = "******";

            //APIParameter APIP = new APIParameter("parameterName", "parameterType", 1, 2);
            //AAMS1.ParametersList = new ObservableList<APIParameter>();
            //AAMS1.ParametersList.Add(APIP);
            AAMS1.SOAPAction = "SOAPAction";

            SR.AddRepositoryItem(AAMS1);

            //SR.ClearRepositoryItemsCache<ApplicationAPIModel>();    //TODO: we need to make sure this test run as stand alone or it will mess other UT

            ObservableList <ApplicationAPIModel> AAMBList = SR.GetAllRepositoryItems <ApplicationAPIModel>();
            ApplicationAPIModel AAMS2 = (ApplicationAPIModel)(from x in AAMBList where x.Guid == AAMS1.Guid select x).FirstOrDefault();

            // TODO: change 'Value Check' to the name of the field

            //Assert
            Assert.AreEqual(AAMS2.Name, "Soap1", "Value Check");
            Assert.AreEqual(AAMS2.Description, "Description", "Value Check");
            Assert.AreEqual(AAMS2.EndpointURL, "EndpointURL", "Value Check");
            Assert.AreEqual(AAMS2.ReqHttpVersion, ApplicationAPIUtils.eHttpVersion.HTTPV10, "Value Check");
            Assert.AreEqual(AAMS2.AppModelParameters.Count, 1, "Value Check");
            Assert.AreEqual(AAMS2.AppModelParameters[0].OptionalValuesList.Count, 2, "Value Check");
            //Assert.AreEqual(AAMS2.APIModelKeyValueHeaders.Count, 1, "Value Check");
            Assert.AreEqual(AAMS2.NetworkCredentials, ApplicationAPIUtils.eNetworkCredentials.Custom, "Value Check");
            Assert.AreEqual(AAMS2.URLUser, "URLUser", "Value Check");
            Assert.AreEqual(AAMS2.URLDomain, "URLDomain", "Value Check");
            Assert.AreEqual(AAMS2.URLPass, "URLPass", "Value Check");
            Assert.AreEqual(AAMS2.DoNotFailActionOnBadRespose, true, "Value Check");
            Assert.AreEqual(AAMS2.HttpHeaders.Count, 1, "Value Check");
            Assert.AreEqual(AAMS2.RequestBodyType, ApplicationAPIUtils.eRequestBodyType.FreeText, "Value Check");
            Assert.AreEqual(AAMS2.CertificateType, ApplicationAPIUtils.eCretificateType.AllSSL, "Value Check");
            Assert.AreEqual(AAMS2.CertificatePath, "CertificatePath", "Value Check");
            Assert.AreEqual(AAMS2.ImportCetificateFile, true, "Value Check");
            Assert.AreEqual(AAMS2.CertificatePassword, "CertificatePassword", "Value Check");
            Assert.AreEqual(AAMS2.SecurityType, ApplicationAPIUtils.eSercurityType.Ssl3, "Value Check");
            Assert.AreEqual(AAMS2.AuthorizationType, ApplicationAPIUtils.eAuthType.BasicAuthentication, "Value Check");
            Assert.AreEqual(AAMS2.TemplateFileNameFileBrowser, "TemplateFileNameFileBrowser", "Value Check");
            Assert.AreEqual(AAMS2.ImportRequestFile, "ImportRequestFile", "Value Check");
            Assert.AreEqual(AAMS2.AuthUsername, "AuthUsername", "Value Check");
            Assert.AreEqual(AAMS2.AuthPassword, "AuthPassword", "Value Check");
            //Assert.AreEqual(AAMS2.ParametersList.Count, 1, "Value Check");
            Assert.AreEqual(AAMS2.SOAPAction, "SOAPAction", "Value Check");
        }
Ejemplo n.º 17
0
 public void OptionalValueConstructorTest1()
 {
     var a = new OptionalValue<int>();
     Assert.IsFalse(a.Hasvalue);
 }
Ejemplo n.º 18
0
        public void OptionalTest7()
        {
            OptionalValue<string> a = new OptionalValue<string>();
            OptionalValue<string> b = new OptionalValue<string>();
            Assert.IsFalse(a.Hasvalue);
            Assert.IsFalse(b.Hasvalue);
            b.UpdateFrom(a);
            Assert.IsFalse(a.Hasvalue);
            Assert.IsFalse(b.Hasvalue);
            b.Value = "XXX";
            Assert.AreEqual("XXX", b.Value);
            b.UpdateFrom(a);
            Assert.IsFalse(a.Hasvalue);
            Assert.AreEqual("XXX", b.Value);

            a = "FOO";
            b.UpdateFrom(a);
            Assert.AreEqual("FOO", a.Value);
            Assert.AreEqual("FOO", b.Value);
        }
 public EnumValueWithDescriptionOptions()
 {
     OptionalValue = new OptionalValue <ValueWithDescription <T> >();
     OptionalValue.SelectedIndexChanged += delegate { OnValueUpdated(); };
 }
Ejemplo n.º 20
0
            public void RecursivelyConvertsMapElementsWithMapOfAny()
            {
                var instance = new OptionalValue(new TypeReference(
                                                     collection: new CollectionTypeReference(CollectionKind.Map,
                                                                                             new TypeReference(
                                                                                                 collection: new CollectionTypeReference(CollectionKind.Map,
                                                                                                                                         new TypeReference(primitive: PrimitiveType.Any)
                                                                                                                                         )
                                                                                                 )
                                                                                             )
                                                     ));

                var frameworkMap = new Dictionary <string, IDictionary <string, object> >
                {
                    { "myKey1", new Dictionary <string, object> {
                          { "mySubKey1", "myValue1" }
                      } },
                    { "myKey2", new Dictionary <string, object> {
                          { "mySubKey2", "myValue2" }
                      } },
                };

                // This will test the call to FrameworkToJsiiConverter.TryConvertCollectionElement()
                // In the case of a of a Map of Map of Any
                bool success = _converter.TryConvert(instance, _referenceMap, frameworkMap, out object actual);

                Assert.True(success);
                Assert.IsType <JObject>(actual);
                Assert.Collection
                (
                    ((IEnumerable <KeyValuePair <string, JToken> >)actual).OrderBy(kvp => kvp.Key),
                    kvp =>
                {
                    Assert.Equal("myKey1", kvp.Key);
                    Assert.IsType <JObject>(kvp.Value);
                    Assert.Collection
                    (
                        ((IEnumerable <KeyValuePair <string, JToken> >)kvp.Value),
                        subKvp =>
                    {
                        Assert.Equal("mySubKey1", subKvp.Key, ignoreLineEndingDifferences: true);
                        Assert.Equal("myValue1", subKvp.Value);
                    }
                    );
                },
                    kvp =>
                {
                    Assert.Equal("myKey2", kvp.Key, ignoreLineEndingDifferences: true);
                    Assert.IsType <JObject>(kvp.Value);
                    Assert.Collection
                    (
                        ((IEnumerable <KeyValuePair <string, JToken> >)kvp.Value),
                        subKvp =>
                    {
                        Assert.Equal("mySubKey2", subKvp.Key, ignoreLineEndingDifferences: true);
                        Assert.Equal("myValue2", subKvp.Value);
                    }
                    );
                }
                );
            }
 public HidAccessPropertyEnumValue()
 {
     OptionalValue = new OptionalValue <ValueWithDescription <T> >();
     OptionalValue.SelectedItemChanged += (sender, e) => { OnOptionalValueSelectedItemChanged(e); };
 }
Ejemplo n.º 22
0
 public OptionalValue <IAstNode> Generate(IAstNode ast)
 {
     return(OptionalValue.Create(ast));
 }
Ejemplo n.º 23
0
        public BusinessFlow ConvertQCTestSetToBF(QC.ALMTestSet testSet)
        {
            GingerActivitiesGroupsRepo = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems <ActivitiesGroup>();
            GingerActivitiesRepo       = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems <Activity>();
            try
            {
                if (testSet == null)
                {
                    return(null);
                }

                //Create Business Flow
                BusinessFlow busFlow = new BusinessFlow();
                busFlow.Name       = testSet.TestSetName;
                busFlow.ExternalID = testSet.TestSetID;
                busFlow.Status     = BusinessFlow.eBusinessFlowStatus.Development;
                busFlow.Activities = new ObservableList <Activity>();
                busFlow.Variables  = new ObservableList <VariableBase>();
                Dictionary <string, string> busVariables = new Dictionary <string, string>();//will store linked variables

                //Create Activities Group + Activities for each TC
                foreach (QC.ALMTSTest tc in testSet.Tests)
                {
                    //check if the TC is already exist in repository
                    ActivitiesGroup tcActivsGroup;
                    ActivitiesGroup repoActivsGroup = null;
                    if (repoActivsGroup == null)
                    {
                        repoActivsGroup = GingerActivitiesGroupsRepo.Where(x => x.ExternalID == tc.TestID).FirstOrDefault();
                    }
                    if (repoActivsGroup != null)
                    {
                        List <Activity> repoNotExistsStepActivity = GingerActivitiesRepo.Where(z => repoActivsGroup.ActivitiesIdentifiers.Select(y => y.ActivityExternalID).ToList().Contains(z.ExternalID))
                                                                    .Where(x => !tc.Steps.Select(y => y.StepID).ToList().Contains(x.ExternalID)).ToList();

                        tcActivsGroup = (ActivitiesGroup)repoActivsGroup.CreateInstance();

                        var ActivitySIdentifiersToRemove = tcActivsGroup.ActivitiesIdentifiers.Where(x => repoNotExistsStepActivity.Select(z => z.ExternalID).ToList().Contains(x.ActivityExternalID));
                        for (int indx = 0; indx < tcActivsGroup.ActivitiesIdentifiers.Count; indx++)
                        {
                            if ((indx < tcActivsGroup.ActivitiesIdentifiers.Count) && (ActivitySIdentifiersToRemove.Contains(tcActivsGroup.ActivitiesIdentifiers[indx])))
                            {
                                tcActivsGroup.ActivitiesIdentifiers.Remove(tcActivsGroup.ActivitiesIdentifiers[indx]);
                                indx--;
                            }
                        }

                        tcActivsGroup.ExternalID2 = tc.TestID;
                        busFlow.AddActivitiesGroup(tcActivsGroup);
                        busFlow.ImportActivitiesGroupActivitiesFromRepository(tcActivsGroup, GingerActivitiesRepo, ApplicationPlatforms, true);
                        busFlow.AttachActivitiesGroupsAndActivities();
                    }
                    else //TC not exist in Ginger repository so create new one
                    {
                        tcActivsGroup             = new ActivitiesGroup();
                        tcActivsGroup.Name        = tc.TestName;
                        tcActivsGroup.ExternalID  = tc.TestID;
                        tcActivsGroup.ExternalID2 = tc.LinkedTestID;
                        tcActivsGroup.Description = tc.Description;
                        busFlow.AddActivitiesGroup(tcActivsGroup);
                    }

                    //Add the TC steps as Activities if not already on the Activities group
                    foreach (QC.ALMTSTestStep step in tc.Steps)
                    {
                        Activity stepActivity;
                        bool     toAddStepActivity = false;

                        //check if mapped activity exist in repository
                        Activity repoStepActivity = (Activity)GingerActivitiesRepo.Where(x => x.ExternalID == step.StepID).FirstOrDefault();
                        if (repoStepActivity != null)
                        {
                            //check if it is part of the Activities Group
                            ActivityIdentifiers groupStepActivityIdent = (ActivityIdentifiers)tcActivsGroup.ActivitiesIdentifiers.Where(x => x.ActivityExternalID == step.StepID).FirstOrDefault();
                            if (groupStepActivityIdent != null)
                            {
                                //already in Activities Group so get link to it
                                stepActivity = (Activity)busFlow.Activities.Where(x => x.Guid == groupStepActivityIdent.ActivityGuid).FirstOrDefault();
                                // in any case update description/expected/name - even if "step" was taken from repository
                                stepActivity.Description  = StripHTML(step.Description);
                                stepActivity.Expected     = StripHTML(step.Expected);
                                stepActivity.ActivityName = tc.TestName + ">" + step.StepName;
                            }
                            else//not in ActivitiesGroup so get instance from repo
                            {
                                stepActivity      = (Activity)repoStepActivity.CreateInstance();
                                toAddStepActivity = true;
                            }
                        }
                        else//Step not exist in Ginger repository so create new one
                        {
                            stepActivity = new Activity();
                            stepActivity.ActivityName = tc.TestName + ">" + step.StepName;
                            stepActivity.ExternalID   = step.StepID;
                            stepActivity.Description  = StripHTML(step.Description);

                            toAddStepActivity = true;
                        }

                        if (toAddStepActivity)
                        {
                            //not in group- need to add it
                            busFlow.AddActivity(stepActivity, tcActivsGroup);
                        }

                        //pull TC-Step parameters and add them to the Activity level
                        List <string> stepParamsList = new List <string>();
                        foreach (string param in stepParamsList)
                        {
                            //get the param value
                            string paramSelectedValue         = string.Empty;
                            bool?  isflowControlParam         = null;
                            QC.ALMTSTestParameter tcParameter = tc.Parameters.Where(x => x.Name.ToUpper() == param.ToUpper()).FirstOrDefault();

                            //get the param value
                            if (tcParameter != null && tcParameter.Value != null && tcParameter.Value != string.Empty)
                            {
                                paramSelectedValue = tcParameter.Value;
                            }
                            else
                            {
                                isflowControlParam = null;//empty value
                                paramSelectedValue = "<Empty>";
                            }

                            //check if parameter is part of a link
                            string linkedVariable = null;
                            if (paramSelectedValue.StartsWith("#$#"))
                            {
                                string[] valueParts = paramSelectedValue.Split(new [] { "#$#" }, StringSplitOptions.None);
                                if (valueParts.Count() == 3)
                                {
                                    linkedVariable     = valueParts[1];
                                    paramSelectedValue = "$$_" + valueParts[2];//so it still will be considered as non-flow control

                                    if (!busVariables.Keys.Contains(linkedVariable))
                                    {
                                        busVariables.Add(linkedVariable, valueParts[2]);
                                    }
                                }
                            }

                            //determine if the param is Flow Control Param or not based on it value and agreed sign "$$_"
                            if (paramSelectedValue.StartsWith("$$_"))
                            {
                                isflowControlParam = false;
                                if (paramSelectedValue.StartsWith("$$_"))
                                {
                                    paramSelectedValue = paramSelectedValue.Substring(3);//get value without "$$_"
                                }
                            }
                            else if (paramSelectedValue != "<Empty>")
                            {
                                isflowControlParam = true;
                            }
                            //check if already exist param with that name
                            VariableBase stepActivityVar = stepActivity.Variables.Where(x => x.Name.ToUpper() == param.ToUpper()).FirstOrDefault();
                            if (stepActivityVar == null)
                            {
                                //#Param not exist so add it
                                if (isflowControlParam == true)
                                {
                                    //add it as selection list param
                                    stepActivityVar      = new VariableSelectionList();
                                    stepActivityVar.Name = param;
                                    stepActivity.AddVariable(stepActivityVar);
                                    stepActivity.AutomationStatus = eActivityAutomationStatus.Development;//reset status because new flow control param was added
                                }
                                else
                                {
                                    //add as String param
                                    stepActivityVar      = new VariableString();
                                    stepActivityVar.Name = param;
                                    ((VariableString)stepActivityVar).InitialStringValue = paramSelectedValue;
                                    stepActivity.AddVariable(stepActivityVar);
                                }
                            }
                            else
                            {
                                //#param exist
                                if (isflowControlParam == true)
                                {
                                    if (!(stepActivityVar is VariableSelectionList))
                                    {
                                        //flow control param must be Selection List so transform it
                                        stepActivity.Variables.Remove(stepActivityVar);
                                        stepActivityVar      = new VariableSelectionList();
                                        stepActivityVar.Name = param;
                                        stepActivity.AddVariable(stepActivityVar);
                                        stepActivity.AutomationStatus = eActivityAutomationStatus.Development;//reset status because flow control param was added
                                    }
                                }
                                else if (isflowControlParam == false)
                                {
                                    if (stepActivityVar is VariableSelectionList)
                                    {
                                        //change it to be string variable
                                        stepActivity.Variables.Remove(stepActivityVar);
                                        stepActivityVar      = new VariableString();
                                        stepActivityVar.Name = param;
                                        ((VariableString)stepActivityVar).InitialStringValue = paramSelectedValue;
                                        stepActivity.AddVariable(stepActivityVar);
                                        stepActivity.AutomationStatus = eActivityAutomationStatus.Development;//reset status because flow control param was removed
                                    }
                                }
                            }

                            //add the variable selected value
                            if (stepActivityVar is VariableSelectionList)
                            {
                                OptionalValue stepActivityVarOptionalVar = ((VariableSelectionList)stepActivityVar).OptionalValuesList.Where(x => x.Value == paramSelectedValue).FirstOrDefault();
                                if (stepActivityVarOptionalVar == null)
                                {
                                    //no such variable value option so add it
                                    stepActivityVarOptionalVar = new OptionalValue(paramSelectedValue);
                                    ((VariableSelectionList)stepActivityVar).OptionalValuesList.Add(stepActivityVarOptionalVar);
                                    if (isflowControlParam == true)
                                    {
                                        stepActivity.AutomationStatus = eActivityAutomationStatus.Development;//reset status because new param value was added
                                    }
                                }
                                //set the selected value
                                ((VariableSelectionList)stepActivityVar).SelectedValue = stepActivityVarOptionalVar.Value;
                            }
                            else
                            {
                                //try just to set the value
                                try
                                {
                                    stepActivityVar.Value = paramSelectedValue;
                                    if (stepActivityVar is VariableString)
                                    {
                                        ((VariableString)stepActivityVar).InitialStringValue = paramSelectedValue;
                                    }
                                }
                                catch (Exception ex) { Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); }
                            }

                            //add linked variable if needed
                            if (!string.IsNullOrEmpty(linkedVariable))
                            {
                                stepActivityVar.LinkedVariableName = linkedVariable;
                            }
                            else
                            {
                                stepActivityVar.LinkedVariableName = string.Empty;//clear old links
                            }
                        }
                    }

                    //order the Activities Group activities according to the order of the matching steps in the TC
                    try
                    {
                        int startGroupActsIndxInBf = 0;
                        if (busFlow.Activities.Count > 0)
                        {
                            startGroupActsIndxInBf = busFlow.Activities.IndexOf(tcActivsGroup.ActivitiesIdentifiers[0].IdentifiedActivity);
                        }
                        foreach (QC.ALMTSTestStep step in tc.Steps)
                        {
                            int stepIndx = tc.Steps.IndexOf(step) + 1;
                            ActivityIdentifiers actIdent = (ActivityIdentifiers)tcActivsGroup.ActivitiesIdentifiers.Where(x => x.ActivityExternalID == step.StepID).FirstOrDefault();
                            if (actIdent == null || actIdent.IdentifiedActivity == null)
                            {
                                break;//something wrong- shouldn't be null
                            }
                            Activity act          = (Activity)actIdent.IdentifiedActivity;
                            int      groupActIndx = tcActivsGroup.ActivitiesIdentifiers.IndexOf(actIdent);
                            int      bfActIndx    = busFlow.Activities.IndexOf(act);

                            //set it in the correct place in the group
                            int numOfSeenSteps = 0;
                            int groupIndx      = -1;
                            foreach (ActivityIdentifiers ident in tcActivsGroup.ActivitiesIdentifiers)
                            {
                                groupIndx++;
                                if (string.IsNullOrEmpty(ident.ActivityExternalID) ||
                                    tc.Steps.Where(x => x.StepID == ident.ActivityExternalID).FirstOrDefault() == null)
                                {
                                    continue;//activity which not originally came from the TC
                                }
                                numOfSeenSteps++;

                                if (numOfSeenSteps >= stepIndx)
                                {
                                    break;
                                }
                            }
                            ActivityIdentifiers identOnPlace = (ActivityIdentifiers)tcActivsGroup.ActivitiesIdentifiers[groupIndx];
                            if (identOnPlace.ActivityGuid != act.Guid)
                            {
                                //replace places in group
                                tcActivsGroup.ActivitiesIdentifiers.Move(groupActIndx, groupIndx);
                                //replace places in business flow
                                busFlow.Activities.Move(bfActIndx, startGroupActsIndxInBf + groupIndx);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex);
                        //failed to re order the activities to match the tc steps order, not worth breaking the import because of this
                    }
                }

                //Add the BF variables (linked variables)
                if (busVariables.Keys.Count > 0)
                {
                    foreach (KeyValuePair <string, string> var in busVariables)
                    {
                        //add as String param
                        VariableString busVar = new VariableString();
                        busVar.Name = var.Key;
                        busVar.InitialStringValue = var.Value;
                        busFlow.AddVariable(busVar);
                    }
                }

                return(busFlow);
            }
            catch (Exception ex)
            {
                Reporter.ToLog(eLogLevel.ERROR, "Failed to import QC test set and convert it into " + GingerDicser.GetTermResValue(eTermResKey.BusinessFlow), ex);
                return(null);
            }
        }
Ejemplo n.º 24
0
        public static BusinessFlow ConvertRallyTestPlanToBF(RallyTestPlan testPlan)
        {
            try
            {
                if (testPlan == null)
                {
                    return(null);
                }

                //Create Business Flow
                BusinessFlow busFlow = new BusinessFlow();
                busFlow.Name       = testPlan.Name;
                busFlow.ExternalID = "RallyID=" + testPlan.RallyID;
                busFlow.Status     = BusinessFlow.eBusinessFlowStatus.Development;
                busFlow.Activities = new ObservableList <Activity>();
                busFlow.Variables  = new ObservableList <VariableBase>();

                //Create Activities Group + Activities for each TC
                foreach (RallyTestCase tc in testPlan.TestCases)
                {
                    //check if the TC is already exist in repository
                    ActivitiesGroup tcActivsGroup;
                    ActivitiesGroup repoActivsGroup = null;
                    if (repoActivsGroup == null)
                    {
                        repoActivsGroup = GingerActivitiesGroupsRepo.Where(x => x.ExternalID != null ? x.ExternalID.Split('|').First().Split('=').Last() == tc.RallyID : false).FirstOrDefault();
                    }
                    if (repoActivsGroup != null)
                    {
                        tcActivsGroup = (ActivitiesGroup)repoActivsGroup.CreateInstance();
                        busFlow.AddActivitiesGroup(tcActivsGroup);
                        busFlow.ImportActivitiesGroupActivitiesFromRepository(tcActivsGroup, GingerActivitiesRepo, true, true);
                        busFlow.AttachActivitiesGroupsAndActivities();
                    }
                    else // TC not exist in Ginger repository so create new one
                    {
                        tcActivsGroup             = new ActivitiesGroup();
                        tcActivsGroup.Name        = tc.Name;
                        tcActivsGroup.Description = tc.Description;
                        tcActivsGroup.ExternalID  = "RallyID=" + tc.RallyID + "|AtsID=" + tc.BTSID;
                        busFlow.AddActivitiesGroup(tcActivsGroup);
                    }

                    foreach (RallyTestStep step in tc.TestSteps)
                    {
                        Activity stepActivity;
                        bool     toAddStepActivity = false;

                        // check if mapped activity exist in repository
                        Activity repoStepActivity = GingerActivitiesRepo.Where(x => x.ExternalID != null ? x.ExternalID.Split('|').First().Split('=').Last() == step.RallyIndex : false).FirstOrDefault();
                        if (repoStepActivity != null)
                        {
                            //check if it is part of the Activities Group
                            ActivityIdentifiers groupStepActivityIdent = tcActivsGroup.ActivitiesIdentifiers.Where(x => x.ActivityExternalID == step.RallyIndex).FirstOrDefault();
                            if (groupStepActivityIdent != null)
                            {
                                //already in Activities Group so get link to it
                                stepActivity = busFlow.Activities.Where(x => x.Guid == groupStepActivityIdent.ActivityGuid).FirstOrDefault();
                            }
                            else // not in ActivitiesGroup so get instance from repo
                            {
                                stepActivity      = (Activity)repoStepActivity.CreateInstance();
                                toAddStepActivity = true;
                            }
                        }
                        else //Step not exist in Ginger repository so create new one
                        {
                            string strBtsID = string.Empty;
                            stepActivity = new Activity();
                            stepActivity.ActivityName = tc.Name + ">" + step.Name;
                            stepActivity.ExternalID   = "RallyID=" + step.RallyIndex + "|AtsID=" + strBtsID;
                            stepActivity.Description  = StripHTML(step.Description);
                            stepActivity.Expected     = StripHTML(step.ExpectedResult);

                            toAddStepActivity = true;
                        }

                        if (toAddStepActivity)
                        {
                            // not in group- need to add it
                            busFlow.AddActivity(stepActivity);
                            tcActivsGroup.AddActivityToGroup(stepActivity);
                        }

                        //pull TC-Step parameters and add them to the Activity level
                        foreach (RallyTestParameter param in tc.Parameters)   // Params taken from TestScriptLevel only!!!! Also exists parapameters at TestCase, to check if them should be taken!!!
                        {
                            bool?isflowControlParam = null;

                            //detrmine if the param is Flow Control Param or not based on it value and agreed sign "$$_"
                            if (param.Value.ToString().StartsWith("$$_"))
                            {
                                isflowControlParam = false;
                                if (param.Value.ToString().StartsWith("$$_"))
                                {
                                    param.Value = param.Value.ToString().Substring(3); //get value without "$$_"
                                }
                            }
                            else if (param.Value.ToString() != "<Empty>")
                            {
                                isflowControlParam = true;
                            }

                            //check if already exist param with that name
                            VariableBase stepActivityVar = stepActivity.Variables.Where(x => x.Name.ToUpper() == param.Name.ToUpper()).FirstOrDefault();
                            if (stepActivityVar == null)
                            {
                                //#Param not exist so add it
                                if (isflowControlParam == true)
                                {
                                    //add it as selection list param
                                    stepActivityVar      = new VariableSelectionList();
                                    stepActivityVar.Name = param.Name;
                                    stepActivity.AddVariable(stepActivityVar);
                                    stepActivity.AutomationStatus = Activity.eActivityAutomationStatus.Development;//reset status because new flow control param was added
                                }
                                else
                                {
                                    //add as String param
                                    stepActivityVar      = new VariableString();
                                    stepActivityVar.Name = param.Name;
                                    ((VariableString)stepActivityVar).InitialStringValue = param.Value;
                                    stepActivity.AddVariable(stepActivityVar);
                                }
                            }
                            else
                            {
                                //#param exist
                                if (isflowControlParam == true)
                                {
                                    if (!(stepActivityVar is VariableSelectionList))
                                    {
                                        //flow control param must be Selection List so transform it
                                        stepActivity.Variables.Remove(stepActivityVar);
                                        stepActivityVar      = new VariableSelectionList();
                                        stepActivityVar.Name = param.Name;
                                        stepActivity.AddVariable(stepActivityVar);
                                        stepActivity.AutomationStatus = Activity.eActivityAutomationStatus.Development;//reset status because flow control param was added
                                    }
                                }
                                else if (isflowControlParam == false)
                                {
                                    if (stepActivityVar is VariableSelectionList)
                                    {
                                        //change it to be string variable
                                        stepActivity.Variables.Remove(stepActivityVar);
                                        stepActivityVar      = new VariableString();
                                        stepActivityVar.Name = param.Name;
                                        ((VariableString)stepActivityVar).InitialStringValue = param.Value;
                                        stepActivity.AddVariable(stepActivityVar);
                                        stepActivity.AutomationStatus = Activity.eActivityAutomationStatus.Development;//reset status because flow control param was removed
                                    }
                                }
                            }

                            //add the variable selected value
                            if (stepActivityVar is VariableSelectionList)
                            {
                                OptionalValue stepActivityVarOptionalVar = ((VariableSelectionList)stepActivityVar).OptionalValuesList.Where(x => x.Value == param.Value).FirstOrDefault();
                                if (stepActivityVarOptionalVar == null)
                                {
                                    //no such variable value option so add it
                                    stepActivityVarOptionalVar = new OptionalValue(param.Value);
                                    ((VariableSelectionList)stepActivityVar).OptionalValuesList.Add(stepActivityVarOptionalVar);
                                    if (isflowControlParam == true)
                                    {
                                        stepActivity.AutomationStatus = Activity.eActivityAutomationStatus.Development;//reset status because new param value was added
                                    }
                                }
                                //set the selected value
                                ((VariableSelectionList)stepActivityVar).SelectedValue = stepActivityVarOptionalVar.Value;
                            }
                            else
                            {
                                //try just to set the value
                                try
                                {
                                    stepActivityVar.Value = param.Value;
                                    if (stepActivityVar is VariableString)
                                    {
                                        ((VariableString)stepActivityVar).InitialStringValue = param.Value;
                                    }
                                }
                                catch (Exception ex) { Reporter.ToLog(eAppReporterLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); }
                            }
                        }
                    }
                }

                return(busFlow);
            }
            catch (Exception ex)
            {
                Reporter.ToLog(eAppReporterLogLevel.ERROR, "Failed to import Rally test set and convert it into " + GingerDicser.GetTermResValue(eTermResKey.BusinessFlow), ex);
                return(null);
            }
        }
Ejemplo n.º 25
0
        public void RefreshGlobalAppModelParams(ApplicationModelBase AppModel)
        {
            ObservableList <GlobalAppModelParameter> allGlobalParams = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems <GlobalAppModelParameter>();

            for (int i = 0; i < AppModel.GlobalAppModelParameters.Count; i++)
            {
                GlobalAppModelParameter apiGlobalParamInstance = AppModel.GlobalAppModelParameters[i];
                GlobalAppModelParameter globalParamInstance    = allGlobalParams.Where(x => x.Guid == apiGlobalParamInstance.Guid).FirstOrDefault();
                //If the param still exist in the global list
                if (globalParamInstance != null)
                {
                    //Check for change and update in Configurations tab
                    if (!globalParamInstance.PlaceHolder.Equals(apiGlobalParamInstance.PlaceHolder))
                    {
                        AppModel.UpdateParamsPlaceholder(this, new List <string> {
                            apiGlobalParamInstance.PlaceHolder
                        }, globalParamInstance.PlaceHolder);
                        apiGlobalParamInstance.PlaceHolder = globalParamInstance.PlaceHolder;
                    }
                    apiGlobalParamInstance.CurrentValue = globalParamInstance.CurrentValue;

                    if (globalParamInstance.OptionalValuesList.Count > 0)
                    {
                        bool recoverSavedOV       = false;
                        Guid currentDefaultOVGuid = new Guid();
                        //Save current default
                        if (apiGlobalParamInstance.OptionalValuesList.Count > 0)
                        {
                            currentDefaultOVGuid = apiGlobalParamInstance.OptionalValuesList.Where(x => x.IsDefault == true).FirstOrDefault().Guid;
                            recoverSavedOV       = true;
                        }

                        string newDefaultOV = null;
                        apiGlobalParamInstance.OptionalValuesList.ClearAll();
                        foreach (OptionalValue ov in globalParamInstance.OptionalValuesList)
                        {
                            OptionalValue newOV = new OptionalValue();
                            newOV.Guid  = ov.Guid;
                            newOV.Value = ov.Value;
                            if (ov.IsDefault)
                            {
                                newDefaultOV = ov.Guid.ToString();
                            }
                            apiGlobalParamInstance.OptionalValuesList.Add(newOV);
                        }

                        if (recoverSavedOV)
                        {
                            OptionalValue savedOV = apiGlobalParamInstance.OptionalValuesList.Where(x => x.Guid == currentDefaultOVGuid).FirstOrDefault();
                            if (savedOV != null)
                            {
                                savedOV.IsDefault = true;
                            }
                            else
                            {
                                apiGlobalParamInstance.OptionalValuesList.Where(x => x.Guid.ToString() == newDefaultOV).FirstOrDefault().IsDefault = true;
                            }
                        }
                        else
                        {
                            apiGlobalParamInstance.OptionalValuesList.Where(x => x.Guid.ToString() == newDefaultOV).FirstOrDefault().IsDefault = true;
                        }


                        apiGlobalParamInstance.OnPropertyChanged(nameof(AppModelParameter.OptionalValuesString));
                    }
                    else
                    {
                        apiGlobalParamInstance.OptionalValuesList.ClearAll();
                    }

                    apiGlobalParamInstance.OnPropertyChanged(nameof(AppModelParameter.PlaceHolder));
                }
                else
                {
                    AppModel.GlobalAppModelParameters.Remove(apiGlobalParamInstance);
                    i--;
                }
            }
        }
 public HidAccessPropertyOptional()
 {
     OptionalValue = new OptionalValue <T>();
     OptionalValue.SelectedItemChanged += (sender, e) => { OnOptionalValueSelectedItemChanged(e); };
 }
Ejemplo n.º 27
0
        public void OptionalValueConstructorTest1()
        {
            var a = new OptionalValue <int>();

            Assert.IsFalse(a.Hasvalue);
        }