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); }
private void CommandLogReflectsScript(ExampleAction target) { Approvals.Verify( new ApprovalTextWriter(Scrubbers.ScrubDates(recordingConnection.GetCommandLog())), new CustomUnitTestFrameworkNamer(target.ToString().Replace(" ", string.Empty)), Approvals.GetReporter()); }
void CommandLogReflectsScript(ExampleAction target, string testName) { this.Assent( logger.Log, new Configuration() .UsingSanitiser(Scrubbers.ScrubDates) .UsingNamer(new Namer(target, testName)) ); }
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); }
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); }
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); }
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(); }
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(); }
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(); }
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); }
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); }
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(); }
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); }
public Namer(ExampleAction target, string testName) { this.target = target; this.testName = testName; }
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); }