Beispiel #1
0
        /// <summary>
        /// Get all information of countries states and cities
        /// </summary>
        /// <returns></returns>
        public DTInfoCountry GetAllCountry()
        {
            DTInfoCountry infocontry = new DTInfoCountry();

            try
            {
                //Query for get all contries states and cities in the same query.
                var Buscar = _ObjCountryRepository.Get(q => q
                                                       .Include(x => x.State)
                                                       .ThenInclude(y => y.City));
                if (Buscar != null)
                {
                    List <DTCountry> Countries = new List <DTCountry>();
                    List <DTState>   States    = new List <DTState>();
                    List <DTCity>    Cities    = new List <DTCity>();

                    foreach (Country item in Buscar)
                    {
                        DTCountry objcountry = new DTCountry();
                        objcountry = _Objmapper.Map <DTCountry>(item);
                        Countries.Add(objcountry);
                        foreach (State stat in item.State)
                        {
                            DTState objstate = new DTState();
                            objstate = _Objmapper.Map <DTState>(stat);
                            States.Add(objstate);
                            foreach (City cit in stat.City)
                            {
                                DTCity objcity = new DTCity();
                                objcity = _Objmapper.Map <DTCity>(cit);
                                Cities.Add(objcity);
                            }
                        }
                    }

                    infocontry.Countries = Countries;
                    infocontry.States    = States;
                    infocontry.Cities    = Cities;
                }
                return(infocontry);
            }
            catch (Exception)
            {
                throw;
            }
        }
        internal void SimplifyTestCase2()
        {
            List<DTElement> elements = new List<DTElement>();
            for (int i = 0; i < 3; i++)
                elements.Add(new DTElement { Name = string.Format("Condition {0}", i), Kind = DTElementKind.Condition });
            for (int i = 0; i < 2; i++)
                elements.Add(new DTElement { Name = string.Format("Action {0}", i), Kind = DTElementKind.Action });

            var actual = DTRuleSet.InitializeRules(elements);
            Assert.IsTrue(actual.Rules.Count == 8);

            var f = DTState.No;
            var t = DTState.Yes;
            var e = DTState.Empty;
            var a = DTState.ActionYes;

            //Conditions
            var states0 = new DTState[] { t, f, f, f, f };
            var states1 = new DTState[] { e, t, t, f, f };
            var states2 = new DTState[] { e, t, f, t, f };
            //Actions
            var states3 = new DTState[] { a, e, a, e, e };
            var states4 = new DTState[] { e, a, a, a, a };

            elements[0].SetStates(states0);
            elements[1].SetStates(states1);
            elements[2].SetStates(states2);
            elements[3].SetStates(states3);
            elements[4].SetStates(states4);

            DTRuleSet target = DTRuleSet.Simplify(elements);

            //Conditions
            var expectedStates0 = new DTState[] { t, f, f, f };
            var expectedStates1 = new DTState[] { e, t, t, f };
            var expectedStates2 = new DTState[] { e, t, f, e };
            //Actions
            var expectedStates3 = new DTState[] { a, e, a, e };
            var expectedStates4 = new DTState[] { e, a, a, a };

            CollectionAssert.AreEqual(target.GetStates(elements[0]).ToList(), expectedStates0.ToList());
            CollectionAssert.AreEqual(target.GetStates(elements[1]).ToList(), expectedStates1.ToList());
            CollectionAssert.AreEqual(target.GetStates(elements[2]).ToList(), expectedStates2.ToList());
            CollectionAssert.AreEqual(target.GetStates(elements[3]).ToList(), expectedStates3.ToList());
            CollectionAssert.AreEqual(target.GetStates(elements[4]).ToList(), expectedStates4.ToList());
        }
        public void InitializeRulesTest()
        {
            List<DTElement> elements = new List<DTElement>();
            for (int i = 0; i < 3; i++)
                elements.Add(new DTElement { Name = string.Format("Condition {0}", i), Kind = DTElementKind.Condition });
            for (int i = 0; i < 2; i++)
                elements.Add(new DTElement { Name = string.Format("Action {0}", i), Kind = DTElementKind.Action });

            var actual = DTRuleSet.InitializeRules(elements);
            Assert.IsTrue(actual.Rules.Count == 8);

            var f = DTState.No;
            var t = DTState.Yes;

            var firstConditionStates = new DTState[] { t, t, t, t, f, f, f, f };
            var secondConditionStates = new DTState[] { t, t, f, f, t, t, f, f };
            var thirdConditionStates = new DTState[] { t, f, t, f, t, f, t, f };
            var actionStates = Enumerable.Repeat(DTState.Empty, 8).ToList();

            CollectionAssert.AreEqual(actual.GetStates(elements[0]).ToList(), firstConditionStates);
            CollectionAssert.AreEqual(actual.GetStates(elements[1]).ToList(), secondConditionStates);
            CollectionAssert.AreEqual(actual.GetStates(elements[2]).ToList(), thirdConditionStates);

            CollectionAssert.AreEqual(actual.GetStates(elements[3]).ToList(), actionStates);
            CollectionAssert.AreEqual(actual.GetStates(elements[4]).ToList(), actionStates);
        }
        private void CalculateRuleCountTestCase3()
        {
            DTState stateA = new DTState { Name = "A" };
            DTState stateB = new DTState { Name = "B" };

            List<DTElement> elements = new List<DTElement>();
            for (int i = 0; i < 3; i++)
            {
                DTElement newDTElement = new DTElement { Name = string.Format("Condition {0}", i), Kind = DTElementKind.Condition };
                elements.Add(newDTElement);
            }
            for (int i = 0; i < 2; i++)
                elements.Add(new DTElement { Name = string.Format("Action {0}", i), Kind = DTElementKind.Action });

            elements[0].AddValidState(stateA);
            elements[0].AddValidState(stateB);

            elements[1].AddValidState(stateA);

            int expected = 24;
            int actual = DTRuleSet_Accessor.CalculateRuleCount(elements);
            Assert.AreEqual(expected, actual);
        }