Esempio n. 1
0
        public void AddDialog()
        {
            var state = new RumorState();

            var wrong = false;
            var count = 0;

            state.OnSetDialog    += (obj, str) => wrong = true;
            state.OnAddDialog    += (obj, str) => count++;
            state.OnAddChoice    += (index, str) => wrong = true;
            state.OnRemoveChoice += (index, str) => wrong = true;
            state.OnClear        += (type) => wrong = true;

            // First use
            state.AddDialog("Narrator", "Hello World.");
            Assert.AreEqual(1, state.Dialog.Keys.Count);
            Assert.AreEqual(1, state.Dialog.Values.Count);
            Assert.True(state.Dialog["Narrator"] == "Hello World.");

            // Second use
            state.AddDialog("Someone", "Goodbye World.");
            Assert.AreEqual(2, state.Dialog.Keys.Count);
            Assert.AreEqual(2, state.Dialog.Values.Count);
            Assert.True(state.Dialog["Narrator"] == "Hello World.");
            Assert.True(state.Dialog["Someone"] == "Goodbye World.");

            // Check callback
            Assert.AreEqual(2, count);
            Assert.IsFalse(wrong);
        }
Esempio n. 2
0
        public void ClearDialog()
        {
            var state = new RumorState();

            var       wrong = false;
            ClearType?type  = null;

            state.OnAddChoice    += (index, str) => wrong = true;
            state.OnRemoveChoice += (index, str) => wrong = true;
            state.OnClear        += (t) => type = t;

            // Test Clear All
            state.AddDialog("Narrator", "Hello World.");
            state.AddDialog("Someone", "Goodbye World.");
            state.Clear();
            Assert.AreEqual(0, state.Dialog.Keys.Count);
            Assert.AreEqual(0, state.Dialog.Values.Count);
            Assert.AreEqual(ClearType.ALL, type);

            // Test Clear Dialog
            state.AddDialog("Narrator", "Hello World.");
            state.AddDialog("Someone", "Goodbye World.");
            state.ClearDialog();
            Assert.AreEqual(0, state.Dialog.Keys.Count);
            Assert.AreEqual(0, state.Dialog.Values.Count);
            Assert.AreEqual(ClearType.DIALOG, type);

            // Test Clear Choices
            state.AddDialog("Narrator", "Hello World.");
            state.AddDialog("Someone", "Goodbye World.");
            state.ClearChoices();
            Assert.AreEqual(2, state.Dialog.Keys.Count);
            Assert.AreEqual(2, state.Dialog.Values.Count);
            Assert.True(state.Dialog["Narrator"] == "Hello World.");
            Assert.True(state.Dialog["Someone"] == "Goodbye World.");
            Assert.AreEqual(ClearType.CHOICES, type);

            // Check callback
            Assert.IsFalse(wrong);
        }