Beispiel #1
0
        public IEnumerator StorylistItem_Select_Story_Test()
        {
            //Create a blank canvas
            Canvas canvas = CreateTestGameObject <Canvas>();

            //Fetch a dummy story
            Story story = GetStories()[0];//GetResources<Story>("Content/Stories/DummyStory");

            //Fetch prefab from resources
            StorylistItem storylistItem = GetResources <StorylistItem>("Prefabs/UI elements/StorylistItem");

            //Instantiate the prefab to the canvas
            Object.Instantiate(storylistItem, canvas.transform);

            //Get references to the storylistitem content components
            Text   title       = storylistItem.transform.Find("txtStorylistItemTitle").GetComponent <Text>();
            Text   description = storylistItem.transform.Find("txtStorylistItemDesc").GetComponent <Text>();
            Button button      = storylistItem.GetComponent <Button>();

            //Create a substitute for the item select callback
            IOnStoryItemSelected callback = Substitute.For <IOnStoryItemSelected>();

            //Construct the list item
            storylistItem.Constructor(title, description);
            storylistItem.SetItemContent(story, callback);

            //Simulate a click on the item
            button.onClick.Invoke();

            //Move to the next frame
            yield return(null);

            //Check if the selection was registered
            callback.Received().OnStoryItemSelected(story);
        }
Beispiel #2
0
        public IEnumerator StorylistView_Storyitem_Spawn_Test()
        {
            //Create a blank canvas
            Canvas canvas = CreateTestGameObject <Canvas>();

            //Create a gameobject to hold story items
            GameObject itemContainer = CreateTestGameObject();

            Object.Instantiate(itemContainer, canvas.transform);

            //Fetch the StorylistItem prefab asset
            StorylistItem storylistItem = GetResources <StorylistItem>("Prefabs/UI elements/StorylistItem");

            //Fetch a list of stories
            List <Story> stories = GetStories();

            //Fetch the StorylistView prefab asset
            StorylistView storylistView = GetResources <StorylistView>("Prefabs/Views/StorylistView");

            //Construct the storylistview
            storylistView.Construct(itemContainer, storylistItem, stories);
            //Instantiate the storylistview prefab to the scene
            Object.Instantiate(storylistView, canvas.transform);

            //Move to next frame
            yield return(null);

            //Check that the amount of stories given to the view match the amount of stories that have been spawned
            Assert.AreEqual(stories.Count, itemContainer.transform.childCount);
        }
Beispiel #3
0
    /// <summary>
    /// Instantiate a list item to the list of stories in the view
    /// </summary>
    /// <param name="story"><see cref="Story"/> for the item</param>
    public void SpawnStoryPrefab(Story story)
    {
        //Instantiate a new list item
        StorylistItem item = Instantiate(_storylistItem, _itemContainer.transform);

        //Set the item content
        item.SetItemContent(story, this);
    }
Beispiel #4
0
 /// <summary>
 /// Construct a new <see cref="StorylistView"/>, used for testing
 /// </summary>
 /// <param name="itemcontainer"><see cref="GameObject"/> acting as the parent for instantiated <see cref="StorylistItem"/>s</param>
 /// <param name="storylistitem">Reference to the list item prefab</param>
 /// <param name="storylist">List of stories to be displayed</param>
 public void Construct(GameObject itemcontainer, StorylistItem storylistitem, List <Story> storylist)
 {
     _itemContainer = itemcontainer;
     _storylistItem = storylistitem;
     _storylist     = storylist;
 }