GetListOfStates() public method

public GetListOfStates ( List listToFill, string selectedItemName ) : void
listToFill List
selectedItemName string
return void
コード例 #1
0
ファイル: StateTests.cs プロジェクト: vchelaru/FlatRedBall
        public void TestCategories()
        {
            List<string> listToFill = new List<string>();

            AvailableStates availableStates = new AvailableStates(
                null,
                mEntitySave,
                mExposedStateVariable,
                null);


            listToFill.Clear();
            availableStates.GetListOfStates(listToFill, mDerivedEntitySave.CustomVariables[0].Name);

            if (listToFill.Contains("SharedStateSave") == false)
            {
                throw new Exception("GetListOfStates is not returnign states that are categorized but that share variables with others.");
            }


        }
コード例 #2
0
        public void TestExposingStates()
        {
            List<string> variables = ExposedVariableManager.GetExposableMembersFor(mEntitySave, false).Select(m=>m.Member).ToList();

            if (!variables.Contains("CurrentState"))
            {
                throw new Exception("ExposedVariableManager is not properly returning the CurrentState as an exposable variable");
            }
            if (!variables.Contains("CurrentStateCategoryState"))
            {
                throw new Exception("ExposedVariableManager is not properly returning categorized states as exposable variables");
            }

            // Let's remove uncategorized state to make sure the categorized state is still recognized:
            StateSave stateSave = mEntitySave.States[0];
            mEntitySave.States.RemoveAt(0);
            variables = ExposedVariableManager.GetExposableMembersFor(mEntitySave, false).Select(m=>m.Member).ToList();

            if (!variables.Contains("CurrentStateCategoryState"))
            {
                throw new Exception("ExposedVariableManager is not properly returning categorized states when there are no uncategorized states.");
            }
            // Add it back in case it's needed for other tests.
            mEntitySave.States.Add(stateSave);

            variables = ExposedVariableManager.GetExposableMembersFor(mEntityWithCategorizedThatShareVariables, false).Select(m => m.Member).ToList();
            if (!variables.Contains("CurrentState"))
            {
                throw new Exception("Entities that only have states in categories, but those categories share variables with other categories, are not exposing CurrentState and they should!");
            }

            List<string> listOfStates = new List<string>();
            AvailableStates availableStates = new AvailableStates(null, mContainerDerivedEntity, mContainerDerivedEntity.CustomVariables[0], null);
            availableStates.GetListOfStates(listOfStates, "TunneledStateVariable");
            if (listOfStates.Count == 0 || !listOfStates.Contains("StateInCategory1"))
            {
                throw new Exception("SetByDerived variables that tunnel in to categorized states do not properly return their list through GetListOfStates");
            }


            ScreenSave screenSave = new ScreenSave();
            StateSaveCategory category = new StateSaveCategory();
            category.Name = "Whatever";
            screenSave.StateCategoryList.Add(category);
            StateSave stateInScreen = new StateSave();
            stateInScreen.Name = "First";
            category.States.Add(stateInScreen);
            variables = ExposedVariableManager.GetExposableMembersFor(screenSave, false).Select(item=>item.Member).ToList();

            if (variables.Contains("CurrentState") == false)
            {
                throw new NotImplementedException("Screens with states that are in categories that share variables are not properly returning the CurrentState as a possible variable");
            }
        }
コード例 #3
0
ファイル: StateTests.cs プロジェクト: vchelaru/FlatRedBall
        public void Test()
        {
            AvailableStates availableStates = new AvailableStates(
                null,
                mEntitySave,
                mExposedStateInCategoryVariable,
                null);


            List<string> listToFill = new List<string>();



            availableStates.CurrentCustomVariable = mExposedStateVariable;
            listToFill.Clear();
            availableStates.GetListOfStates(listToFill, null);
            if (listToFill.Count != NumberOfUncategorizedAndSharedStates(mEntitySave) + 1 || listToFill[1] != "Uncategorized")
            {
                throw new Exception("GetListOfStates isn't properly filtering out categorized states");
            }



            listToFill.Clear();
            availableStates.CurrentCustomVariable = mExposedStateInCategoryVariable;
            availableStates.GetListOfStates(listToFill, null);

            if(listToFill.Count != 2 || listToFill[1] != "StateInCategory1")
            {
                throw new Exception("GetListOfStates isn't properly filtering out uncategorized states");
            }

            // Test getting states for variables that don't use the "CurrentWhatever" naming in categories
            listToFill.Clear();
            availableStates.CurrentElement = mContainerEntitySave;
            availableStates.CurrentNamedObject = mEntitySaveInstance;
            availableStates.CurrentCustomVariable = null;
            availableStates.GetListOfStates(listToFill, mRenamedExposedCategorizedStateVariable.Name);

            if(listToFill.Contains("StateInCategory1") == false)
            {
                throw new Exception("GetListOfStates doesn't work properly on states that are categorized and have variables that don't follow the typical CurrentWhatever naming.");
            }

            // Test getting states for variables that don't use the "CurrentWhatever" naming in categories, and are accessed through inheritance

            listToFill.Clear();
            availableStates.CurrentElement = mContainerEntitySave;
            availableStates.CurrentNamedObject = mDerivedSaveInstance;
            availableStates.CurrentCustomVariable = null;
            availableStates.GetListOfStates(listToFill, mRenamedExposedUncategorizedStateVariable.Name);
            if (listToFill.Count != mEntitySave.States.Count + 1)
            {
                throw new Exception("GetListOfStates on NOS's that are derived doesn't seem to work properly");
            }


            listToFill.Clear();
            availableStates.CurrentElement = mContainerEntitySave;
            availableStates.CurrentCustomVariable = null;
            availableStates.CurrentNamedObject = mEntitySaveInstance;
            availableStates.GetListOfStates(listToFill, "CurrentState");
            if(listToFill.Count != NumberOfUncategorizedAndSharedStates(mEntitySave) + 1 || listToFill[1] != "Uncategorized") // will include "<NONE>"
            {
                throw new Exception("GetListOfStates isn't properly filtering out categorized states");
            }

            // Test getting states for a variable that doesn't use the typical "CurrentWhatever" naming on uncategorized
            listToFill.Clear();
            availableStates.CurrentElement = mContainerEntitySave;
            availableStates.CurrentCustomVariable = null;
            availableStates.CurrentNamedObject = mEntitySaveInstance;
            availableStates.GetListOfStates(listToFill, mRenamedExposedUncategorizedStateVariable.Name);
            if (listToFill.Count != NumberOfUncategorizedAndSharedStates(mEntitySave) + 1 || listToFill[1] != "Uncategorized") // will include "<NONE>"
            {
                throw new Exception("GetListOfStates isn't properly filtering out categorized states");
            }

            // Test getting states for a tunneled variable that doesn't use the typical "CurrentWhatever" naming on uncategorized
            listToFill.Clear();
            availableStates.CurrentElement = mContainerEntitySave;
            availableStates.CurrentCustomVariable = mTunneledUncategorizedStateInContainer;
            availableStates.CurrentNamedObject = null;
            availableStates.GetListOfStates(listToFill, mRenamedExposedUncategorizedStateVariable.Name);
            if (listToFill.Count != NumberOfUncategorizedAndSharedStates(mEntitySave) + 1 || listToFill[1] != "Uncategorized") // will include "<NONE>"
            {
                throw new Exception("GetListOfStates isn't properly filtering out categorized states");
            }



            listToFill.Clear();
            availableStates.CurrentElement = mContainerEntitySave;
            availableStates.CurrentNamedObject = mEntitySaveInstance;
            availableStates.CurrentCustomVariable = null;

            availableStates.GetListOfStates(listToFill, "CurrentStateCategoryState");
            if(listToFill.Count != 2 || listToFill[1] != "StateInCategory1")
            {
                throw new Exception("GetListOfStates isn't properly filtering out uncategorized states");
            }


            string whyItIsntValid;
            if (NameVerifier.IsStateNameValid("Color", null, null, null, out whyItIsntValid))
            {
                throw new Exception("The state name Color should not be a valid name, but Glue allows it");
            }


            listToFill.Clear();
            availableStates.CurrentElement = mDerivedEntitySave;
            availableStates.CurrentCustomVariable = mDerivedEntitySave.CustomVariables[0];
            availableStates.CurrentNamedObject = null;
            availableStates.GetListOfStates(listToFill, mDerivedEntitySave.CustomVariables[0].Name);

            if (listToFill.Count == 0 || listToFill[1] != "Uncategorized")
            {
                throw new Exception("GetListOfStates is not properly finding uncategorized states defined in a base type");
            }

            listToFill.Clear();
            availableStates.CurrentElement = mDerivedEntitySave;
            availableStates.CurrentCustomVariable = mDerivedEntitySave.CustomVariables[1];
            availableStates.CurrentNamedObject = null;
            availableStates.GetListOfStates(listToFill, mDerivedEntitySave.CustomVariables[1].Name);

            if (listToFill.Count == 0 || listToFill[1] != "StateInCategory1")
            {
                throw new Exception("GetListOfStates is not properly finding categorized states defined in a base type");
            }

            // Test CurrentState variable tate in the Container
            listToFill.Clear();
            availableStates.CurrentElement = mContainerEntitySave;
            availableStates.CurrentCustomVariable = null;
            availableStates.CurrentStateSave = null;
            availableStates.CurrentNamedObject = mDerivedSaveInstance;
            availableStates.GetListOfStates(listToFill, "CurrentState");

            if (listToFill.Count != mEntitySave.States.Count + 1)
            {
                throw new Exception("Getting state on NamedObject that is of a derived type that gets its state from the base type is not working properly");

            }

            ////Test adding same name with shared category
            
            //Test shared vs shared
            var sharedCategoryElement = new EntitySave();
            string outString;
            sharedCategoryElement.StateCategoryList.Add(new StateSaveCategory{Name = "First", SharesVariablesWithOtherCategories = true});
            sharedCategoryElement.StateCategoryList[0].States.Add(new StateSave{Name = "State1"});
            sharedCategoryElement.StateCategoryList.Add(new StateSaveCategory{Name = "Second", SharesVariablesWithOtherCategories = true});
            if(NameVerifier.IsStateNameValid("State1", sharedCategoryElement, sharedCategoryElement.StateCategoryList[1], null,
                                          out outString))
            {
                throw new Exception("Should not allow adding same state name between shared categories.");
            }

            //Test shared vs main
            sharedCategoryElement = new EntitySave();
            sharedCategoryElement.StateCategoryList.Add(new StateSaveCategory { Name = "First", SharesVariablesWithOtherCategories = true });
            sharedCategoryElement.StateCategoryList[0].States.Add(new StateSave { Name = "State1" });
            if (NameVerifier.IsStateNameValid("State1", sharedCategoryElement, null, null,
                                          out outString))
            {
                throw new Exception("Should not allow adding same state name in main when exists in shared categories.");
            }

            //Test main vs shared
            sharedCategoryElement = new EntitySave();
            sharedCategoryElement.States.Add(new StateSave{Name = "State1"});
            sharedCategoryElement.StateCategoryList.Add(new StateSaveCategory { Name = "First", SharesVariablesWithOtherCategories = true });
            if (NameVerifier.IsStateNameValid("State1", sharedCategoryElement, sharedCategoryElement.StateCategoryList[0], null,
                                          out outString))
            {
                throw new Exception("Should not allow adding same state name in shared category when exists in main states.");
            }
        }