Ejemplo n.º 1
0
        public async Task HandlerCompilation()
        {
            var service = new CallbackQueryService(new Container(), Substitute.For <ITelegramBotClient>());

            service.Register("example", typeof(ExampleAction));

            var action        = new ExampleAction();
            var callbackQuery = new CallbackQuery();

            var node = service.RegisteredActions["example"];

            var response = await Assert.IsType <Task <string> >(node.Handler(action, callbackQuery, Array.Empty <string>()));

            Assert.Equal("First", response);

            node = node.Next !;
            Assert.NotNull(node);

            response = await Assert.IsType <Task <string> >(node.Handler(action, callbackQuery, new[] { "arg" }));

            Assert.Equal("Arg: arg", response);

            node = node.Next !;
            Assert.NotNull(node);

            response = await Assert.IsType <Task <string> >(node.Handler(action, callbackQuery, Array.Empty <string>()));

            Assert.Equal("fallback", response);

            Assert.Null(node.Next);
        }
Ejemplo n.º 2
0
 private void CommandLogReflectsScript(ExampleAction target)
 {
     Approvals.Verify(
         new ApprovalTextWriter(Scrubbers.ScrubDates(recordingConnection.GetCommandLog())),
         new CustomUnitTestFrameworkNamer(target.ToString().Replace(" ", string.Empty)),
         Approvals.GetReporter());
 }
Ejemplo n.º 3
0
 void CommandLogReflectsScript(ExampleAction target, string testName)
 {
     this.Assent(
         logger.Log,
         new Configuration()
         .UsingSanitiser(Scrubbers.ScrubDates)
         .UsingNamer(new Namer(target, testName))
         );
 }
Ejemplo n.º 4
0
        void CommandLogReflectsScript(ExampleAction target, string testName)
        {
            var configuration = new Configuration()
                                .UsingSanitiser(Scrubbers.ScrubDates)
                                .UsingNamer(new Namer(target, testName));

            // Automatically approve the change, make sure to check the result before committing
            // configuration = configuration.UsingReporter((received, approved) => File.Copy(received, approved, true));

            this.Assent(logger.Log, configuration);
        }
Ejemplo n.º 5
0
        private static ExampleAction AddActionGuid(TriggerZone trigger)
        {
            GameObject actionChild = new GameObject("Action of " + trigger.name);

            actionChild.transform.SetParent(trigger.transform);
            actionChild.transform.localPosition = new Vector3(0, 0, 1);
            ExtGameObjectIcon.SetIcon(actionChild, ExtGameObjectIcon.Icon.CircleRed);
            ExampleAction action = actionChild.AddComponent(typeof(ExampleAction)) as ExampleAction;

            return(action);
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter Port");
            var           port   = Console.ReadLine();
            ExampleAction action = new ExampleAction();


            SimpleHTTPServer server = new SimpleHTTPServer(".", int.Parse(port));

            server.AddRoute("hello", action);
        }
Ejemplo n.º 7
0
        public void VerifyBasicSupport()
        {
            ExampleAction deployTo = null;

            this
            .Given(() => deployTo)
            .And(_ => TargetDatabaseIsEmpty())
            .And(_ => SingleScriptExists())
            .When(_ => UpgradeIsPerformed())
            .Then(_ => UpgradeIsSuccessful())
            .And(_ => CommandLogReflectsScript(deployTo), "Command log matches expected steps")
            .WithExamples(DatabaseExampleTable)
            .BDDfy();
        }
Ejemplo n.º 8
0
        public void VerifyVariableSubstitutions()
        {
            ExampleAction deployTo = null;

            this
            .Given(() => deployTo)
            .And(_ => TargetDatabaseIsEmpty())
            .And(_ => SingleScriptWithVariableUsageExists())
            .And(_ => VariableSubstitutionIsSetup())
            .When(_ => UpgradeIsPerformed())
            .Then(_ => UpgradeIsSuccessful())
            .And(_ => CommandLogReflectsScript(deployTo), "Variables substituted correctly in command log")
            .WithExamples(DatabaseExampleTable)
            .BDDfy();
        }
Ejemplo n.º 9
0
        public void VerifyJournalCreationIfNameChanged()
        {
            ExampleAction deployTo = null;

            this
            .Given(() => deployTo)
            .And(_ => TargetDatabaseIsEmpty())
            .And(_ => JournalTableNameIsCustomised())
            .And(_ => SingleScriptExists())
            .When(_ => UpgradeIsPerformed())
            .Then(_ => UpgradeIsSuccessful())
            .And(_ => CommandLogReflectsScript(deployTo, nameof(VerifyJournalCreationIfNameChanged)), "Command log matches expected steps")
            .WithExamples(DatabaseExampleTable)
            .BDDfy();
        }
Ejemplo n.º 10
0
        private static TriggerZoneNoPhysics CreateTrigger()
        {
            GameObject           triggerGameObject = CreateGameObject("Trigger No Physic", typeof(TriggerZoneNoPhysics));
            TriggerZoneNoPhysics trigger           = triggerGameObject.GetComponent <TriggerZoneNoPhysics>();

            ExtGameObjectIcon.SetIcon(triggerGameObject, ExtGameObjectIcon.Icon.CircleYellow);

            SerializedObject triggerObject = new SerializedObject(trigger);
            MovableCube      cube          = AddZoneShape <MovableCube>(trigger, triggerObject);
            ExampleAction    action        = AddActionGuid(trigger);

            LinkActionToTriggerZoneArray(trigger, triggerObject, action);

            return(trigger);
        }
Ejemplo n.º 11
0
        private static TriggerZonePhysics CreateTriggerPhysic()
        {
            GameObject         triggerGameObject = CreateGameObject("Trigger Physic", typeof(TriggerZonePhysics));
            TriggerZonePhysics trigger           = triggerGameObject.GetComponent <TriggerZonePhysics>();

            ExtGameObjectIcon.SetIcon(triggerGameObject, ExtGameObjectIcon.Icon.CircleYellow);

            SerializedObject triggerObject = new SerializedObject(trigger);
            BoxCollider      collider      = trigger.gameObject.AddComponent <BoxCollider>();

            collider.isTrigger = true;
            ExampleAction action = AddActionGuid(trigger);

            LinkActionToTriggerZoneArray(trigger, triggerObject, action);

            return(trigger);
        }
Ejemplo n.º 12
0
        public void CanUseActionsInExamples()
        {
            ExampleAction actionToPerform = null;
            int           valueShouldBe   = 0;
            var           story           = this.Given(_ => SomeSetup())
                                            .When(() => actionToPerform)
                                            .Then(_ => ShouldBe(valueShouldBe))
                                            .WithExamples(new ExampleTable("Action to perform", "Value should be")
            {
                { new ExampleAction("Do something", () => { _value = 42; }), 42 },
                { new ExampleAction("Do something else", () => { _value = 7; }), 7 }
            })
                                            .BDDfy();


            var textReporter = new TextReporter();

            textReporter.Process(story);
            textReporter.ToString().ShouldMatchApproved();
        }
Ejemplo n.º 13
0
        public async Task ShouldCallHandlerWithMatchedArgumentCount()
        {
            const string ExceptionMessage = "The argument count doesn't match";

            var service = new CallbackQueryService(new Container(), Substitute.For <ITelegramBotClient>());

            service.Register("example", typeof(ExampleAction));

            var results = new List <object>();

            var action        = new ExampleAction();
            var callbackQuery = new CallbackQuery();

            var node = service.RegisteredActions["example"];

            Assert.Equal(ExceptionMessage, (await Assert.ThrowsAsync <ArgumentException>(() => node.Handler(action, callbackQuery, new[] { "arg" }))).Message);

            node = node.Next !;

            Assert.Equal(ExceptionMessage, (await Assert.ThrowsAsync <ArgumentException>(() => node.Handler(action, callbackQuery, Array.Empty <string>()))).Message);
            Assert.Equal(ExceptionMessage, (await Assert.ThrowsAsync <ArgumentException>(() => node.Handler(action, callbackQuery, new[] { "arg", "arg2" }))).Message);
        }
Ejemplo n.º 14
0
 public Namer(ExampleAction target, string testName)
 {
     this.target   = target;
     this.testName = testName;
 }
Ejemplo n.º 15
0
        private static void LinkActionToTriggerZoneArray(TriggerZone trigger, SerializedObject triggerObject, ExampleAction action)
        {
            SerializedProperty actionProperty = triggerObject.FindProperty("_actions");

            actionProperty.arraySize++;
            triggerObject.ApplyModifiedProperties();
            GuidReference guid = new GuidReference(action);

            trigger.SetActionByIndex(guid, 0);
        }