Exemplo n.º 1
0
        public void OneOfParamIsNull_Should_Throw(
            bool contetIsNull,
            bool nextNodeIsNull
            )
        {
            // Arrange
            TestContent content = new TestContent();
            DialogNode <TestContent> nextDialogNode = DialogNode <TestContent> .CreateNew(content : new TestContent(), dialogOptions : new List <DialogOptionNext <TestContent> > {
            });

            if (contetIsNull)
            {
                content = null;
            }
            if (nextNodeIsNull)
            {
                nextDialogNode = null;
            }

            // Act
            Action action = () => new DialogOptionNext <TestContent>(content: content, nextNode: nextDialogNode);

            // Assert
            Assert.Throws <ArgumentNullException>(action);
        }
Exemplo n.º 2
0
        public void SelectOption_Should_ContaintNextNode()
        {
            // Arrange
            DialogNode <TestContent> realNextNode      = null;
            DialogNode <TestContent> currentDialogNode = DialogNode <TestContent> .CreateNew(content : new TestContent(), dialogOptions : new List <DialogOptionNext <TestContent> > {
            });

            DialogNode <TestContent> nextNode = DialogNode <TestContent> .CreateNew(content : new TestContent(), dialogOptions : new List <DialogOptionNext <TestContent> > {
            });

            DialogOptionNext <TestContent> optionToSelect = new DialogOptionNext <TestContent>(new TestContent(), nextNode);

            void FuncToFire(object sender, DialogNode <TestContent> e)
            {
                realNextNode = e;
            }

            optionToSelect.SelectEvent += FuncToFire;


            // Act
            optionToSelect.Select();

            // Assert
            Assert.Equal(nextNode, realNextNode);
        }
Exemplo n.º 3
0
        public void AllSet_Should_BeSet()
        {
            // Arrange
            TestContent content = new TestContent();
            DialogNode <TestContent> nextDialogNode = DialogNode <TestContent> .CreateNew(content : new TestContent(), dialogOptions : new List <DialogOptionNext <TestContent> > {
            });

            // Act
            DialogOptionNext <TestContent> dialogOption = new DialogOptionNext <TestContent>(content: content, nextNode: nextDialogNode);

            // Assert
            Assert.Equal(content, dialogOption.Content);
            Assert.Equal(nextDialogNode, dialogOption.NextNode);
        }
Exemplo n.º 4
0
        public void SimpleDialogStraight_Should_BePlayed()
        {
            //Arrange
            TestContent stepOneContent   = new TestContent("Hello! What's up?");
            TestContent stepTwoContent   = new TestContent("What one?");
            TestContent stepThreeContent = new TestContent("What's next?");

            DialogNode <TestContent> nodeThree = DialogNode <TestContent> .CreateExitNode(
                content : stepThreeContent,
                endOption : new DialogOptionEnd <TestContent>(new TestContent("Three lol.")));

            DialogNode <TestContent> nodeTwo = DialogNode <TestContent> .CreateNew(
                content : stepTwoContent,
                dialogOptions : new List <IDialogOption <TestContent> >
            {
                new DialogOptionNext <TestContent>(content: new TestContent("Two."), nextNode: nodeThree),
            });

            DialogNode <TestContent> nodeOne = DialogNode <TestContent> .CreateNew(
                content : stepOneContent,
                dialogOptions : new List <IDialogOption <TestContent> >
            {
                new DialogOptionNext <TestContent>(content: new TestContent("One."), nextNode: nodeTwo),
            });

            Dialog <TestContent> dialog = Dialog <TestContent> .CreateNew(startNode : nodeOne);

            // Act && Assert
            // Step 1
            Assert.Equal(stepOneContent, dialog.CurrentNode.Content);
            // Step 2
            dialog.CurrentNode.DialogOptions.FirstOrDefault().Select();
            Assert.Equal(stepTwoContent, dialog.CurrentNode.Content);
            // Step 3
            dialog.CurrentNode.DialogOptions.FirstOrDefault().Select();
            Assert.Equal(stepThreeContent, dialog.CurrentNode.Content);
        }
Exemplo n.º 5
0
        public void SimpleDialogWithBranch_Should_BePlayed(bool isFirstBranch)
        {
            //Arrange
            TestContent optionOneContent = new TestContent("Hi, I am fine.");
            TestContent optionTwoContent = new TestContent("Hi, evrything is so bad.");


            DialogNode <TestContent> nodeThree = DialogNode <TestContent> .CreateExitNode(
                content : new TestContent("I am sorry for you."),
                endOption : new DialogOptionEnd <TestContent>(new TestContent("Yeah")));

            DialogNode <TestContent> nodeTwo = DialogNode <TestContent> .CreateExitNode(
                content : new TestContent("So good."),
                endOption : new DialogOptionEnd <TestContent>(new TestContent("Bye")));

            DialogNode <TestContent> nodeOne = DialogNode <TestContent> .CreateNew(
                content : new TestContent("Hello! What's up?"),
                dialogOptions : new List <IDialogOption <TestContent> >
            {
                new DialogOptionNext <TestContent>(content: optionOneContent, nextNode: nodeTwo),
                new DialogOptionNext <TestContent>(content: optionTwoContent, nextNode: nodeThree)
            });

            Dialog <TestContent> dialog = Dialog <TestContent> .CreateNew(startNode : nodeOne);

            // Act && Assert
            if (isFirstBranch)
            {
                dialog.CurrentNode.DialogOptions.FirstOrDefault(o => o.Content == optionOneContent).Select();
                Assert.Equal(nodeTwo, dialog.CurrentNode);
            }
            else
            {
                dialog.CurrentNode.DialogOptions.FirstOrDefault(o => o.Content == optionTwoContent).Select();
                Assert.Equal(nodeThree, dialog.CurrentNode);
            }
        }
Exemplo n.º 6
0
        public void SelectOption_Should_RaiseEvent()
        {
            // Arrange
            bool isFired = false;
            DialogNode <TestContent> currentDialogNode = DialogNode <TestContent> .CreateNew(content : new TestContent(), dialogOptions : new List <DialogOptionNext <TestContent> > {
            });

            DialogOptionNext <TestContent> optionToSelect = new DialogOptionNext <TestContent>(new TestContent(), DialogNode <TestContent> .CreateNew(content: new TestContent(), dialogOptions: new List <DialogOptionNext <TestContent> > {
            }));

            void FuncToFire(object sender, DialogNode <TestContent> e)
            {
                isFired = true;
            }

            optionToSelect.SelectEvent += FuncToFire;


            // Act
            optionToSelect.Select();

            // Assert
            Assert.True(isFired);
        }