コード例 #1
0
        public void CanDeserialize()
        {
            var serializedDecision = new SerializedDecision
            {
                Id                  = "foo",
                Name                = "bar",
                DateCreatedUtc      = new System.DateTime(),
                Options             = new[] { "o1", "o2" },
                Criteria            = new[] { "c1", "c2" },
                CriteriaComparisons = new []
                {
                    new SerializedCriteriaComparison
                    {
                        CriterionOne = "c1",
                        CriterionTwo = "c2",
                        Weight       = Weight.GreaterThan
                    }
                },
                OptionComparisons = new []
                {
                    new SerializedOptionComparison
                    {
                        Criterion = "c1",
                        OptionOne = "o1",
                        OptionTwo = "o2",
                        Weight    = Weight.MuchGreaterThan
                    },
                    new SerializedOptionComparison
                    {
                        Criterion = "c2",
                        OptionOne = "o1",
                        OptionTwo = "o2",
                        Weight    = Weight.MuchLessThan
                    }
                }
            };

            var d = Decision.Deserialize(serializedDecision);

            Assert.AreEqual("foo", d.Id);
            Assert.AreEqual("bar", d.Name);
            Assert.AreEqual(serializedDecision.DateCreatedUtc, d.DateCreatedUtc);
            CollectionAssert.AreEqual(new[] { "c1", "c2" }, d.Criteria.Items.ToArray());
            CollectionAssert.AreEqual(new[] { "o1", "o2" }, d.Options.Items.ToArray());
            d.CriteriaComparisons.Single(cc => cc.CriterionOne == "c1" &&
                                         cc.CriterionTwo == "c2" &&
                                         cc.Weight == Weight.GreaterThan);
            d.OptionComparisons.Single(cc => cc.Criterion == "c1" &&
                                       cc.OptionOne == "o1" &&
                                       cc.OptionTwo == "o2" &&
                                       cc.Weight == Weight.MuchGreaterThan);
            d.OptionComparisons.Single(cc => cc.Criterion == "c2" &&
                                       cc.OptionOne == "o1" &&
                                       cc.OptionTwo == "o2" &&
                                       cc.Weight == Weight.MuchLessThan);

            Assert.AreEqual(2, d.Results.Count);
            var actualResults = d.Results.Select(r => (r.Option, r.Score.ToString("N4"))).ToArray();

            CollectionAssert.AreEqual(new[] {
コード例 #2
0
ファイル: Decision.cs プロジェクト: timplourde/dcidr-blazor
        public static Decision Deserialize(SerializedDecision serializedDecision)
        {
            var d = new Decision();

            d.Id             = serializedDecision.Id;
            d.Name           = serializedDecision.Name;
            d.DateCreatedUtc = serializedDecision.DateCreatedUtc;
            if (serializedDecision.Criteria != null)
            {
                foreach (var crit in serializedDecision.Criteria)
                {
                    d.Criteria.Add(crit);
                }
            }

            if (serializedDecision.Options != null)
            {
                foreach (var opt in serializedDecision.Options)
                {
                    d.Options.Add(opt);
                }
            }

            if (serializedDecision.OptionComparisons != null)
            {
                foreach (var soc in serializedDecision.OptionComparisons)
                {
                    var oc = d.OptionComparisons.FirstOrDefault(doc => doc.Criterion == soc.Criterion &&
                                                                doc.OptionOne == soc.OptionOne &&
                                                                doc.OptionTwo == soc.OptionTwo);
                    if (oc != null && soc.Weight.HasValue)
                    {
                        oc.SetWeight(soc.Weight.Value);
                    }
                }
            }

            if (serializedDecision.CriteriaComparisons != null)
            {
                foreach (var scc in serializedDecision.CriteriaComparisons)
                {
                    var cc = d.CriteriaComparisons.FirstOrDefault(dcc => dcc.CriterionOne == scc.CriterionOne &&
                                                                  dcc.CriterionTwo == scc.CriterionTwo);
                    if (cc != null && scc.Weight.HasValue)
                    {
                        cc.SetWeight(scc.Weight.Value);
                    }
                }
            }

            return(d);
        }