Beispiel #1
0
    public async Task ChoiceMustBeNullWhenAllOptionsAreInvisible()
    {
        var when = A.Fake <ICondition>(i => i.Strict());

        A.CallTo(() => when.Evaluate(variables)).Returns(false);

        var choiceNode = new TestChoiceNode
        {
            Options = new()
            {
                new TestChoiceOptionNode {
                    Key = "a", Text = "Opção1", VisibleWhen = when
                },
                new TestChoiceOptionNode {
                    Key = "b", Text = "Opção2", VisibleWhen = when
                }
            }
        };

        var sut     = new BalloonTextNode(textSource, BalloonType.Speech, choiceNode);
        var invoker = new TestInvoker(context);

        await sut.EnterAsync(context);

        invoker.ShouldContainSingle <IBalloonTextEvent>(
            i => i.Should().BeEquivalentTo(new
        {
            Text          = balloonText,
            BalloonType   = BalloonType.Speech,
            IsProtagonist = true,
            Choice        = (IChoice)null
        })
            );
    }
Beispiel #2
0
    public async Task ChoiceMustBeNullWhenThereAreNoOptions()
    {
        var when = A.Fake <ICondition>(i => i.Strict());

        A.CallTo(() => when.Evaluate(variables)).Returns(false);

        var choiceNode = new TestChoiceNode {
            Options = new()
        };

        var sut     = new BalloonTextNode(textSource, BalloonType.Tutorial, choiceNode);
        var invoker = new TestInvoker(context);

        await sut.EnterAsync(context);

        invoker.ShouldContainSingle <IBalloonTextEvent>(
            i => i.Should().BeEquivalentTo(new
        {
            Text          = balloonText,
            BalloonType   = BalloonType.Tutorial,
            IsProtagonist = true,
            Choice        = (IChoice)null
        })
            );
    }
        public void GetHttpFunctionOrNull_DecodesUriProperly()
        {
            WebHostSettings      webHostSettings = new WebHostSettings();
            WebScriptHostManager manager         = new WebScriptHostManager(new ScriptHostConfiguration(), new SecretManager(), webHostSettings);

            // Initialize the
            FunctionMetadata metadata = new FunctionMetadata();

            metadata.Bindings.Add(new HttpTriggerBindingMetadata
            {
                Type = "HttpTrigger"
            });
            TestInvoker invoker = new TestInvoker();
            Collection <ParameterDescriptor> parameters = new Collection <ParameterDescriptor>();
            Collection <FunctionDescriptor>  functions  = new Collection <FunctionDescriptor>()
            {
                new FunctionDescriptor("Foo Bar", invoker, metadata, parameters),
                new FunctionDescriptor("éà  中國", invoker, metadata, parameters)
            };

            manager.InitializeHttpFunctions(functions);

            Uri uri    = new Uri("http://local/api/Foo Bar");
            var result = manager.GetHttpFunctionOrNull(uri);

            Assert.Same(functions[0], result);

            uri    = new Uri("http://local/api/éà  中國");
            result = manager.GetHttpFunctionOrNull(uri);
            Assert.Same(functions[1], result);
        }
Beispiel #4
0
    public async Task OnEnterAsyncShouldRaiseEvent(MoodType moodType, string personName, string protagonist)
    {
        var isProtagonist = personName == protagonist;

        var context = A.Dummy <INavigationContext>();

        context.State.PersonName      = personName;
        context.State.ProtagonistName = protagonist;
        context.State.MoodType        = null;

        var invoker = new TestInvoker(context);

        var sut = new MoodNode(moodType);

        var ret = await sut.EnterAsync(context);

        ret.Should().BeNull();

        invoker.ShouldContainSingle <IMoodChangeEvent>(
            i => i.Should().BeEquivalentTo(new
        {
            MoodType      = moodType,
            PersonName    = personName,
            IsProtagonist = isProtagonist
        })
            );
    }
Beispiel #5
0
    public async Task EnterAsyncShouldRaiseEvent()
    {
        var invoker = new TestInvoker(context);
        await sut.EnterAsync(context);

        invoker.ShouldContainSingle <IBackgroundChangeEvent>(i => i.State.Should().BeSameAs(newState));
    }
Beispiel #6
0
    public async Task ShouldDoNothingWhenStateArgIsNotBackgroundState(object stateArg)
    {
        var invoker = new TestInvoker(context);
        await sut.EnterAsync(context, stateArg);

        invoker.Count.Should().Be(0);
    }
Beispiel #7
0
    public async Task OnEnterAsyncShouldEvaluateOptionEnabledCondition()
    {
        var when1 = A.Fake <ICondition>(i => i.Strict());

        A.CallTo(() => when1.Evaluate(variables)).Returns(true);
        var when2 = A.Fake <ICondition>(i => i.Strict());

        A.CallTo(() => when2.Evaluate(variables)).Returns(false);
        var when3 = A.Fake <ICondition>(i => i.Strict());

        A.CallTo(() => when3.Evaluate(variables)).Returns(false);

        var choiceNode = new TestChoiceNode
        {
            Options = new()
            {
                new TestChoiceOptionNode {
                    Key = "a", Text = "Opção1", DisabledText = "Inativa", EnabledWhen = when1
                },
                new TestChoiceOptionNode {
                    Key = "b", Text = "Opção2", DisabledText = "Não ativa", EnabledWhen = when2
                },
                new TestChoiceOptionNode {
                    Key = "c", Text = "Opção3", EnabledWhen = when3
                }
            }
        };

        var sut     = new BalloonTextNode(textSource, BalloonType.Speech, choiceNode);
        var invoker = new TestInvoker(context);

        await sut.EnterAsync(context);

        invoker.ShouldContainSingle <IBalloonTextEvent>(
            i => i.Should().BeEquivalentTo(new
        {
            Text          = balloonText,
            BalloonType   = BalloonType.Speech,
            IsProtagonist = true,
            Choice        = new
            {
                TimeLimit = (TimeSpan?)null,
                Default   = (string)null,
                Options   = new[]
                {
                    new { Key = "a", Text = "Opção1", IsEnabled = true, ImageName = (string)null, HelpText = (string)null },
                    new { Key = "b", Text = "Não ativa", IsEnabled = false, ImageName = (string)null, HelpText = (string)null },
                    new { Key = "c", Text = "Opção3", IsEnabled = false, ImageName = (string)null, HelpText = (string)null }
                }
            }
        })
            );

        A.CallTo(() => when1.Evaluate(variables)).MustHaveHappenedOnceExactly();
        A.CallTo(() => when2.Evaluate(variables)).MustHaveHappenedOnceExactly();
        A.CallTo(() => when3.Evaluate(variables)).MustHaveHappenedOnceExactly();
    }
Beispiel #8
0
 public void SetUp()
 {
     Driver = new ChromeDriver();
     Driver.Manage().Window.Maximize();
     Calculator = new CalculatorMainPage(Driver);
     Calculator.GoToPage();
     Calculator.Initialize();
     TestInvoker = new TestInvoker(this.Calculator);
 }
Beispiel #9
0
 public void BeforeEach()
 {
     _viewModel = new TestViewModel();
     _command   = new TestCommand(_viewModel);
     _binder    = Create.Binder(_viewModel);
     _control   = new TestControl();
     _invoker   = new TestInvoker();
     Invoker.Override(_invoker);
 }
Beispiel #10
0
    public async Task ShouldNotRaiseEventIfThereIsNoChangeInBackground()
    {
        var invoker = new TestInvoker(context);

        context.State.Background = newState;
        await sut.EnterAsync(context);

        invoker.Count.Should().Be(0);
    }
Beispiel #11
0
    public async Task EnterAsyncWithStateArgShouldDoNothing()
    {
        var context = A.Dummy <INavigationContext>();
        var invoker = new TestInvoker(context);

        var duration = TimeSpan.FromMilliseconds(234567);

        var sut = new TimedPauseNode(duration, null);
        await sut.EnterAsync(context, null);

        invoker.Count.Should().Be(0);
    }
Beispiel #12
0
        private static void RunTest(string testName, TestInvoker methodToTest)
        {
            Console.Write("Running test '{0}'.......", testName);

            try
            {
                methodToTest();
                Console.WriteLine("PASSED");
            }
            catch (Exception ex)
            {
                Console.WriteLine("FAILED Reason: {0}", ex);
            }
        }
Beispiel #13
0
    public async Task OnEnterAsyncShouldNotRaiseEventIfProtagonistWasNotChanged(string value)
    {
        var context = A.Dummy <INavigationContext>();

        context.State.ProtagonistName = value;

        var invoker = new TestInvoker(context);

        var sut = new ProtagonistNode(value, null);
        var ret = await sut.EnterAsync(context);

        ret.Should().Be(value);

        invoker.Count.Should().Be(0);
    }
Beispiel #14
0
    public async Task IgnoreOnInvalidState(BackgroundType type, BackgroundPosition position)
    {
        var oldState = new BackgroundState("alpha", type, position);
        var context  = A.Dummy <INavigationContext>();

        context.State.Background = oldState;
        var invoker = new TestInvoker(context);

        var sut = new ScrollNode(null);
        var ret = await sut.EnterAsync(context);

        ret.Should().BeNull();
        context.State.Background.Should().BeSameAs(oldState);
        invoker.Count.Should().Be(0);
    }
Beispiel #15
0
        public async Task InvokeAsync_SameThreadNoValue()
        {
            var threadIds = new List <int> {
                Thread.CurrentThread.ManagedThreadId
            };

            var ti = new TestInvoker();
            await ti.InvokeAsync(null, async() => { threadIds.Add(Thread.CurrentThread.ManagedThreadId); await Task.Delay(0); });

            threadIds.Add(Thread.CurrentThread.ManagedThreadId);

            Assert.AreEqual(1, threadIds.Distinct().Count());
            Assert.AreEqual(1, ti.ThreadIds.Distinct().Count());
            Assert.AreEqual(threadIds.Distinct().First(), ti.ThreadIds.Distinct().First());
        }
Beispiel #16
0
    public async Task OnEnterAsyncShouldNotRaiseEventIfMusicWasNotChanged()
    {
        var context = A.Dummy <INavigationContext>();

        context.State.MusicName = "crime_fighter";

        var invoker = new TestInvoker(context);

        var sut = new MusicNode("crime_fighter", null);
        var ret = await sut.EnterAsync(context);

        ret.Should().Be("crime_fighter");

        invoker.Count.Should().Be(0);
    }
Beispiel #17
0
    public async Task ShouldRaiseEventWithStateArg(string stateArg)
    {
        var context = A.Dummy <INavigationContext>();

        context.State.MusicName = "theme";

        var invoker = new TestInvoker(context);

        var sut = new MusicNode("goodbye", null);
        await sut.EnterAsync(context, stateArg);

        invoker.ShouldContainSingle <IMusicChangeEvent>(
            i => i.Should().BeEquivalentTo(new { MusicName = stateArg })
            );
    }
Beispiel #18
0
    public async Task OnEnterShouldRaiseEvent(string currentValue, string newValue)
    {
        var context = A.Dummy <INavigationContext>();

        context.State.ProtagonistName = currentValue;

        var invoker = new TestInvoker(context);

        var sut = new ProtagonistNode(newValue, null);
        await sut.EnterAsync(context);

        invoker.ShouldContainSingle <IProtagonistChangeEvent>(
            i => i.Should().BeEquivalentTo(new { PersonName = newValue })
            );
    }
Beispiel #19
0
    public async Task RandomOrder()
    {
        var choiceNode = new TestChoiceNode
        {
            RandomOrder = true,
            Options     = new()
            {
                new TestChoiceOptionNode {
                    Key = "a", Text = "Opção1"
                },
                new TestChoiceOptionNode {
                    Key = "b", Text = "Opção2"
                }
            }
        };

        var shuffled = new List <IChoiceOption>
        {
            A.Fake <IChoiceOption>(i => i.ConfigureFake(i => {
                A.CallTo(() => i.IsEnabled).Returns(true);
            }))
        };

        var randomizer = A.Fake <IRandomizer>(i => i.Strict());

        A.CallTo(() => randomizer.Shuffle(A <List <IChoiceOption> > .Ignored)).Returns(shuffled);
        A.CallTo(() => context.Randomizer).Returns(randomizer);

        var sut     = new BalloonTextNode(textSource, BalloonType.Speech, choiceNode);
        var invoker = new TestInvoker(context);

        await sut.EnterAsync(context);

        invoker.ShouldContainSingle <IBalloonTextEvent>(
            i => i.Should().BeEquivalentTo(new
        {
            Text          = balloonText,
            BalloonType   = BalloonType.Speech,
            IsProtagonist = true,
            Choice        = new
            {
                TimeLimit = (TimeSpan?)null,
                Default   = (string)null,
                Options   = shuffled
            }
        })
            );
    }
Beispiel #20
0
    public async Task ShouldNotRaiseEventForNomalMoodWhenContextMoodIsNull()
    {
        var context = A.Dummy <INavigationContext>();

        context.State.MoodType = null;

        var invoker = new TestInvoker(context);

        var sut = new MoodNode(MoodType.Normal);

        var ret = await sut.EnterAsync(context);

        ret.Should().BeNull();

        invoker.Count.Should().Be(0);
    }
Beispiel #21
0
    public async Task OnEnterShouldNotRaiseEventIfMoodWasNotChanged()
    {
        var context = A.Dummy <INavigationContext>();

        context.State.MoodType = MoodType.Happy;

        var invoker = new TestInvoker(context);

        var sut = new MoodNode(MoodType.Happy);

        var ret = await sut.EnterAsync(context);

        ret.Should().Be(MoodType.Happy);

        invoker.Count.Should().Be(0);
    }
Beispiel #22
0
    public async Task EnterAsync()
    {
        var context = A.Dummy <INavigationContext>();
        var invoker = new TestInvoker(context);

        var duration = TimeSpan.FromMilliseconds(234567);

        var sut = new TimedPauseNode(duration, null);
        var ret = await sut.EnterAsync(context);

        ret.Should().BeNull();

        invoker.ShouldContainSingle <ITimedPauseEvent>(
            i => i.Should().BeEquivalentTo(new { Duration = duration })
            );
    }
Beispiel #23
0
    public async Task ShouldRaiseEventWithStateArg(string stageArg)
    {
        var context = A.Dummy <INavigationContext>();

        context.State.ProtagonistName = "alpha";

        var invoker = new TestInvoker(context);

        var sut = new ProtagonistNode("beta", null);
        await sut.EnterAsync(context, stageArg);

        invoker.ShouldContainSingle <IProtagonistChangeEvent>(
            i => i.Should().BeEquivalentTo(new { PersonName = stageArg })
            );

        context.State.ProtagonistName.Should().Be(stageArg);
    }
Beispiel #24
0
        public Tester(BalloonType balloonType, bool isProtagonist)
        {
            var state = A.Dummy <INavigationState>();

            state.PersonName      = "alpha";
            state.ProtagonistName = isProtagonist ? "alpha" : "beta";

            var context = A.Fake <INavigationContext>(i => i.Strict());

            A.CallTo(() => context.State).Returns(state);

            var childBlock = A.Dummy <IBlock>();

            BalloonNode = new BalloonNode(balloonType, childBlock);
            Context     = context;
            Invoker     = new TestInvoker(context);
        }
Beispiel #25
0
    public async Task OnEnterAsyncWithChoice()
    {
        state.PersonName      = "mu";
        state.ProtagonistName = "pi";

        var choiceNode = new TestChoiceNode
        {
            TimeLimit = TimeSpan.FromSeconds(3),
            Default   = "a",
            Options   = new()
            {
                new TestChoiceOptionNode {
                    Key = "a", Text = "Opção1"
                },
                new TestChoiceOptionNode {
                    Key = "b", Text = "Opção2", ImageName = "abc", HelpText = "help"
                }
            }
        };

        var sut     = new BalloonTextNode(textSource, BalloonType.Speech, choiceNode);
        var invoker = new TestInvoker(context);

        await sut.EnterAsync(context);

        invoker.ShouldContainSingle <IBalloonTextEvent>(
            i => i.Should().BeEquivalentTo(new
        {
            Text          = balloonText,
            BalloonType   = BalloonType.Speech,
            IsProtagonist = false,
            Choice        = new
            {
                TimeLimit = TimeSpan.FromSeconds(3),
                Default   = "a",
                Options   = new[]
                {
                    new { Key = "a", Text = "Opção1", IsEnabled = true, ImageName = (string)null, HelpText = (string)null },
                    new { Key = "b", Text = "Opção2", IsEnabled = true, ImageName = "abc", HelpText = "help" }
                }
            }
        })
            );
    }
Beispiel #26
0
        public Test(Fixture fixture, ParameterSet constructorArgs, TestHarness harness, ParameterSet methodArgs)
        {
            Category    = harness.Category;
            Description = harness.Description;
            if (Timeout != System.Threading.Timeout.Infinite)
            {
                Timeout = harness.Timeout;
            }


            UniqueName = string.Format("M:{0}.{1}", harness.Method.DeclaringType.Namespace, harness.Method.DeclaringType.Name);

            Name = String.Empty;
            if (constructorArgs.Parameters.Any())
            {
                var nameArgs = constructorArgs.Parameters.Select(it => it.ToString()).ToList();

                UniqueName += string.Format("({0})[{1}]", String.Join(",", nameArgs.ToArray()), constructorArgs.Index);

                Name += string.Format("({0})", String.Join(",", nameArgs.ToArray()));
            }



            UniqueName += "." + harness.Method.Name;
            Name       += harness.Method.Name;

            if (methodArgs.Parameters.Any())
            {
                var nameArgs = methodArgs.Parameters.Select(it => it.ToString());

                UniqueName += string.Format("({0})[{1}]", String.Join(",", nameArgs.ToArray()), constructorArgs.Index);

                Name += string.Format("({0})", String.Join(",", nameArgs.ToArray()));
            }

            _init            = fixture.Attribute.FixtureInit;
            _type            = fixture.Type;
            _invoke          = harness.Attribute.TestInvoke;
            _constructorArgs = constructorArgs.Retain();
            _method          = harness.Method;
            _methodArgs      = methodArgs.Retain();
        }
Beispiel #27
0
    public async Task OnLeaveAsyncShouldRaiseEvent(string personName, string protagonist)
    {
        var isProtagonist = personName == protagonist;

        var context = A.Dummy <INavigationContext>();

        context.State.ProtagonistName = protagonist;

        var invoker = new TestInvoker(context);

        var childBlock = A.Dummy <IBlock>();
        var sut        = new PersonNode(personName, childBlock);

        await sut.LeaveAsync(context);

        invoker.ShouldContainSingle <IPersonLeaveEvent>(
            i => i.Should().BeEquivalentTo(new { PersonName = personName, IsProtagonist = isProtagonist })
            );
    }
Beispiel #28
0
        public Test(Fixture fixture, ParameterSet constructorArgs, TestHarness harness, ParameterSet methodArgs)
        {
            Category = harness.Category;
            Description = harness.Description;
            if (Timeout != System.Threading.Timeout.Infinite)
            {
                Timeout = harness.Timeout;
            }

            UniqueName = string.Format("M:{0}.{1}", harness.Method.DeclaringType.Namespace, harness.Method.DeclaringType.Name);

            Name = String.Empty;
            if (constructorArgs.Parameters.Any())
            {
                var nameArgs = constructorArgs.Parameters.Select(it => it.ToString()).ToList();

                UniqueName += string.Format("({0})[{1}]", String.Join(",", nameArgs.ToArray()), constructorArgs.Index);

                Name += string.Format("({0})", String.Join(",", nameArgs.ToArray()));
            }

            UniqueName += "." + harness.Method.Name;
            Name += harness.Method.Name;

            if (methodArgs.Parameters.Any())
            {
                var nameArgs = methodArgs.Parameters.Select(it => it.ToString());

                UniqueName += string.Format("({0})[{1}]", String.Join(",", nameArgs.ToArray()), constructorArgs.Index);

                Name += string.Format("({0})", String.Join(",", nameArgs.ToArray()));
            }

            _init = fixture.Attribute.FixtureInit;
            _type = fixture.Type;
            _invoke = harness.Attribute.TestInvoke;
            _constructorArgs = constructorArgs.Retain();
            _method = harness.Method;
            _methodArgs = methodArgs.Retain();
        }
Beispiel #29
0
    public async Task OnEnterAsyncShouldRaiseEvent(BalloonType balloonType, bool isProtagonist)
    {
        state.PersonName      = "alpha";
        state.ProtagonistName = isProtagonist ? "alpha" : "beta";

        var sut     = new BalloonTextNode(textSource, balloonType, null);
        var invoker = new TestInvoker(context);

        var ret = await sut.EnterAsync(context);

        ret.Should().BeNull();

        invoker.ShouldContainSingle <IBalloonTextEvent>(
            i => i.Should().BeEquivalentTo(new
        {
            Text          = balloonText,
            BalloonType   = balloonType,
            IsProtagonist = isProtagonist,
            Choice        = (IChoice)null
        })
            );
    }
Beispiel #30
0
    public async Task ShouldRaiseEventWithStateArg(MoodType moodType)
    {
        var context = A.Dummy <INavigationContext>();

        context.State.PersonName      = "alpha";
        context.State.ProtagonistName = "alpha";
        context.State.MoodType        = MoodType.Happy;

        var invoker = new TestInvoker(context);

        var sut = new MoodNode(MoodType.Happy);

        await sut.EnterAsync(context, moodType);

        invoker.ShouldContainSingle <IMoodChangeEvent>(
            i => i.Should().BeEquivalentTo(new
        {
            MoodType      = moodType,
            PersonName    = "alpha",
            IsProtagonist = true
        })
            );
    }
Beispiel #31
0
    public async Task OnEnterShouldReturnPreviousMood()
    {
        var context = A.Dummy <INavigationContext>();

        context.State.MoodType   = MoodType.Surprised;
        context.State.PersonName = "abc";

        var invoker = new TestInvoker(context);

        var sut = new MoodNode(MoodType.Happy);
        var ret = await sut.EnterAsync(context);

        ret.Should().Be(MoodType.Surprised);

        invoker.ShouldContainSingle <IMoodChangeEvent>(
            i => i.Should().BeEquivalentTo(new
        {
            MoodType      = MoodType.Happy,
            PersonName    = "abc",
            IsProtagonist = false
        })
            );
    }
Beispiel #32
0
        private static void RunTest(string testName, TestInvoker methodToTest)
        {
            Console.Write("Running test '{0}'.......", testName);

            try
            {
                methodToTest();
                Console.WriteLine("PASSED");
            }
            catch(Exception ex)
            {
                Console.WriteLine("FAILED Reason: {0}", ex);
            }
        }