Exemplo n.º 1
0
 public DialogueSystem(
     ITextPresenter textPresenter,
     ICoroutineAccessor coroutineAccessor,
     IDialogueSystemElements elements)
 {
     this.textPresenter     = textPresenter;
     this.coroutineAccessor = coroutineAccessor;
     Elements = elements;
 }
        public IEnumerator Say_ShouldWriteAllSpeechTextOnElementSpeechText_WhenPresentingEnds()
        {
            // ARRANGE
            string             targetText        = "Hello World";
            ICoroutineAccessor coroutineAccessor = DialogueTestHelpers.GetMockCoroutineAccessor();
            ISpeech            mockSpeech        = DialogueTestHelpers.GetMockSpeech(
                targetText,
                DialogueTestHelpers.GetMockSpeechSettings()
                );

            ITextPresenter mockTextPresenter = new MockTextPresenter(coroutineAccessor);

            TextMeshProUGUI txtSpeakerName = DialogueTestHelpers.CreateMonoBehaviourObject <TextMeshProUGUI>();
            TextMeshProUGUI txtSpeechText  = DialogueTestHelpers.CreateMonoBehaviourObject <TextMeshProUGUI>();
            GameObject      gameObject     = new GameObject();

            string speakerName = string.Empty;
            string speechText  = string.Empty;
            IDialogueSystemElements mockDialogueSystemElements = Substitute.For <IDialogueSystemElements>();

            mockDialogueSystemElements.DialoguePanel.Returns(gameObject);
            mockDialogueSystemElements.SpeakerNameDisplay.Returns(txtSpeakerName);
            mockDialogueSystemElements.SpeakerNameDisplay.Returns(txtSpeakerName);
            mockDialogueSystemElements.SpeechTextDisplay.Returns(txtSpeechText);
            mockDialogueSystemElements.SpeakerText.Returns(speakerName);
            mockDialogueSystemElements.SpeechText.Returns(speechText);

            IDialogueSystem dialogueSystem = new DialogueSystem(
                mockTextPresenter,
                coroutineAccessor,
                mockDialogueSystemElements
                );

            // ACT
            dialogueSystem.Say(mockSpeech);

            while (dialogueSystem.IsSpeaking())
            {
                yield return(new WaitForFixedUpdate());
            }

            // ASSERT
            Assert.AreEqual(targetText, mockDialogueSystemElements.SpeechText);
        }
        public void Show_ShouldDisplayAllTextInstantly()
        {
            // ARRANGE
            string targetText = "Hello World";

            ITextPresenter textPresenter = Substitute.For <ITextPresenter>();

            textPresenter.CurrentText.Returns(targetText);

            TextMeshProUGUI txtSpeakerName = DialogueTestHelpers.CreateMonoBehaviourObject <TextMeshProUGUI>();
            TextMeshProUGUI txtSpeechText  = DialogueTestHelpers.CreateMonoBehaviourObject <TextMeshProUGUI>();
            GameObject      gameObject     = new GameObject();

            string speakerName = string.Empty;
            string speechText  = string.Empty;
            IDialogueSystemElements dialogueSystemElements = Substitute.For <IDialogueSystemElements>();

            dialogueSystemElements.DialoguePanel.Returns(gameObject);
            dialogueSystemElements.SpeakerNameDisplay.Returns(txtSpeakerName);
            dialogueSystemElements.SpeakerNameDisplay.Returns(txtSpeakerName);
            dialogueSystemElements.SpeechTextDisplay.Returns(txtSpeechText);
            dialogueSystemElements.SpeakerText.Returns(speakerName);
            dialogueSystemElements.SpeechText.Returns(speechText);

            ISpeech speech = DialogueTestHelpers.GetMockSpeech(
                targetText,
                DialogueTestHelpers.GetMockSpeechSettings()
                );

            IDialogueSystem dialogueSystem = new DialogueSystem(
                textPresenter,
                DialogueTestHelpers.GetMockCoroutineAccessor(),
                dialogueSystemElements
                );

            // ACT
            dialogueSystem.Show(speech);

            // ASSERT
            Assert.AreEqual(speech.SpeechText, dialogueSystemElements.SpeechText);
        }