public void Invoke(Invoke method) { // add the method to the list -> the gtk thread call every method inside isBlockedByDialog = true; waitsToInvoke = true; invokeMethods.Add(method); }
public void Using_CheckData_raises_exception_for_invalid_data(ICast cast) { // Arrange var joe = cast.Get <Joe>(); var theData = new SampleApiData { Name = "Invalid, crash expected", DateAndTime = DateTime.Today }; // Act & assert Assert.That(() => When(joe).AttemptsTo(Invoke.TheJsonWebService <CheckData>().WithTheData(theData).AndVerifyItSucceeds()), Throws.InstanceOf <WebApiException>()); }
public void Using_SetTheNumber_does_not_raise_exception(ICast cast) { // Arrange var joe = cast.Get <Joe>(); var theData = new SampleApiData() { NewNumber = 5 }; // Act & assert Assert.That(() => When(joe).AttemptsTo(Invoke.TheJsonWebService <SetNumber>().WithTheData(theData).AndVerifyItSucceeds()), Throws.Nothing); }
public void Using_GetData_returns_expected_result(ICast cast) { // Arrange var joe = cast.Get <Joe>(); // Act var result = When(joe).AttemptsTo(Invoke.TheJsonWebService(GetData.For(joe.Name)).AndReadTheResultAs <SampleApiData>()); // Assert Assert.That(result, Is.Not.Null, "Result should not be null"); Assert.That(result.Name, Is.EqualTo(joe.Name), "Result name should be as expected"); Assert.That(result.DateAndTime, Is.EqualTo(DataController.SampleDateTime), "Result date should be as expected"); }
public string EditUsers(string id, string name, string account, string password, string email, string roleid) { string data = Invoke.PostRequestApi("http://localhost:8848/api/EditUsers?" + "name=" + name + "&id=" + id + "&account=" + account + "&password="******"&email=" + email + "&roleid=" + roleid ); return(StringFormat.SF(data)); }
public void ChainedExecuteMethodBaseline() { // Setup Container .RegisterType(typeof(ICommand <>), typeof(ConcreteCommand <>), Invoke.Method("ChainedExecute")); // Act var result = Container.Resolve <ICommand <Account> >(); // Verify Assert.Fail(); }
public WorkContextService() { _repository = Invoke <IKernelRepository> .Call(); _sessionManager = Invoke <ISessionManager> .Call(); userSession = _sessionManager.GetCurrentSession(); if (userSession == null) { throw new BusinessException(Constants.Message.Exception.KeySentNotFound); } }
public virtual void ProvidingConcreteTypeForGenericFails() { Container.RegisterType(typeof(GenericService <, ,>), Invoke.Method("Method", Resolve.Parameter(typeof(string)))); // Act var result = Container.Resolve <GenericService <object, string, int> >(); // Verify Assert.IsNotNull(result); Assert.AreEqual(result.Called, 2); Assert.IsInstanceOfType(result.Value, typeof(string)); }
/// <summary> /// 命令模式 /// </summary> public static void CommandPatternMethods() { TV tv = new TV(); TVOffCommand offCommand = new TVOffCommand(tv); TVOnCommand onCommand = new TVOnCommand(tv); Invoke invoke = new Invoke(); invoke.command = onCommand; invoke.ExcuteCommand(); invoke.command = offCommand; invoke.ExcuteCommand(); }
public void NamedDependencyAttribute() { // Arrange Container.RegisterType <Service>(Invoke.Method(nameof(Service.NamedDependencyAttribute))); // Act var result = Container.Resolve <Service>(); // Assert Assert.AreEqual(result.Called, 3); Assert.IsInstanceOfType(result.Value, typeof(string)); Assert.AreEqual(result.Value, Name); }
public void AttributedWithTypedMissingOptional() { // Arrange Container.RegisterType <Service>( Invoke.Method(nameof(Service.Method), Resolve.Optional <ICommand <int> >())); // Act var result = Container.Resolve <Service>(); // Assert Assert.IsNull(result.Value); }
public virtual void ReturningInt() { // Setup Container.RegisterType(typeof(GuineaPig), Invoke.Method(nameof(GuineaPig.Inject3), 17)); // Act GuineaPig pig = Container.Resolve <GuineaPig>(); // Verify Assert.AreEqual(17, pig.IntValue); }
public void InjectedAttributedMethod() { // Arrange Container.RegisterType <Service>( Invoke.Method(nameof(Service.Method))); // Act var result = Container.Resolve <Service>(); // Assert Assert.IsNotNull(result.Value); Assert.IsInstanceOfType(result.Value, typeof(object)); }
/// <summary> /// Calculate number of words to fit complete instruction bytecode. /// </summary> /// <returns>Number of words in instruction bytecode.</returns> public override uint GetWordCount() { uint wordCount = 0; wordCount += IdResultType.GetWordCount(); wordCount += IdResult.GetWordCount(); wordCount += NDRange.GetWordCount(); wordCount += Invoke.GetWordCount(); wordCount += Param.GetWordCount(); wordCount += ParamSize.GetWordCount(); wordCount += ParamAlign.GetWordCount(); return(wordCount); }
public void Selection(string name, Type typeFrom, Type typeTo, Type typeToResolve, object[] parameters, Func <object, bool> validator) { // Setup Container.RegisterType(typeFrom, typeTo, name, null, Invoke.Constructor(parameters)); // Act var result = Container.Resolve(typeToResolve, name); // Verify Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeToResolve); Assert.IsTrue(validator?.Invoke(result) ?? true); }
public static OperationMiddleware Create(Type classMiddlewareType) { if (classMiddlewareType is null) { throw new ArgumentNullException(nameof(classMiddlewareType)); } TypeInfo classMiddlewareTypeInfo = classMiddlewareType.GetTypeInfo(); MethodInfo?invokeMethod = classMiddlewareTypeInfo.GetDeclaredMethod("InvokeAsync") ?? classMiddlewareTypeInfo.GetDeclaredMethod("Invoke"); if (invokeMethod is null) { throw new InvalidOperationException( "Class middleware must have a `Invoke` or a `InvokeAsync` method."); } ParameterExpression services = Expression.Parameter(typeof(IServiceProvider)); ParameterExpression next = Expression.Parameter(typeof(OperationDelegate)); NewExpression createInstance = CreateMiddleware(classMiddlewareTypeInfo, services, next); Factory factory = Expression.Lambda <Factory>( createInstance, services, next) .Compile(); ParameterExpression context = Expression.Parameter(typeof(IHttpOperationContext)); ParameterExpression instance = Expression.Parameter(typeof(object)); MethodCallExpression invokeMiddleware = Expression.Call( Expression.Convert(instance, classMiddlewareType), invokeMethod, CreateParameters(invokeMethod, services, context)); Invoke invoke = Expression.Lambda <Invoke>( invokeMiddleware, services, context, instance) .Compile(); return((s, n) => { object obj = factory(s, n); return c => invoke(s, c, obj); }); }
public static void Main() { var foo = new Foo(); // signature of foo.DoWork1 is suitable for Invoke.Measure, //so you can use it as MethodGroup var time1 = Invoke.Measure(foo.DoWork1); Console.WriteLine("Time for 'DoWork1' is {0}s", time1.TotalSeconds); // signature of foo.DoWork2 is not suitable for Invoke.Measure, // so you have to call it inside additional lambda var time2 = Invoke.Measure(() => foo.DoWork2(42)); Console.WriteLine("Time for 'DoWork2' is {0}s", time2.TotalSeconds); }
public void GenericParameterT3WithName() { // Setup Container.RegisterType(typeof(GenericService <, ,>), Invoke.Method("Method", Resolve.Generic("T3", "1"))); // Act var result = Container.Resolve <GenericService <object, string, int> >(); // Verify Assert.IsNotNull(result); Assert.AreEqual(result.Called, 3); Assert.AreEqual(result.Value, 1); }
public void AttributedWithTypedOptional() { // Arrange Container.RegisterType <Service>( Invoke.Method(nameof(Service.Method), Resolve.Optional <string>())); // Act var result = Container.Resolve <Service>(); // Assert Assert.IsNotNull(result.Value); Assert.AreSame(result.Value, Container.Resolve <string>()); }
public void CanProvideConstructorParameterViaResolveCall() { // Setup const int configuredValue = 15; // Just need a number, value has no significance. const int expectedValue = 42; // Just need a number, value has no significance. Container.RegisterType <SimpleTestObject>(Invoke.Constructor(configuredValue)); // Act var result = Container.Resolve <SimpleTestObject>(Override.Parameter("x", expectedValue)); // Verify Assert.AreEqual(expectedValue, result.X); }
/// <summary> /// Write instruction operands into bytecode stream. /// </summary> /// <param name="writer">Bytecode writer.</param> public override void WriteOperands(WordWriter writer) { Queue.Write(writer); Flags.Write(writer); NDRange.Write(writer); NumEvents.Write(writer); WaitEvents.Write(writer); RetEvent.Write(writer); Invoke.Write(writer); Param.Write(writer); ParamSize.Write(writer); ParamAlign.Write(writer); LocalSize.Write(writer); }
public void Method() { // Arrange Container.RegisterType <Service>( Invoke.Method(nameof(Service.MethodOne), Resolve.Parameter <string>())); // Act var result = Container.Resolve <Service>(); // Assert Assert.IsNotNull(result.ValueOne); Assert.AreEqual(result.ValueOne, Container.Resolve <string>()); }
public void GenericParameterT1() { // Arrange Container.RegisterType(typeof(GenericService <, ,>), Invoke.Method("Method", Resolve.Generic("T1"))); // Act var result = Container.Resolve <GenericService <object, string, int> >(); // Verify Assert.IsNotNull(result); Assert.AreEqual(result.Called, 1); Assert.IsInstanceOfType(result.Value, typeof(object)); }
public void MultipleConstructor() { // Arrange Container.RegisterType <TypeWithAmbiguousCtors>( Invoke.Constructor(), Invoke.Constructor()); // Act var instance = Container.Resolve <TypeWithAmbiguousCtors>(); // Validate Assert.IsNotNull(instance); Assert.AreEqual(TypeWithAmbiguousCtors.One, instance.Signature); }
public void ResolveCorrespondingType() { // Setup Container .RegisterType(typeof(ICommand <>), typeof(ConcreteCommand <>), Invoke.Method("Execute", Resolve.Parameter())); // Act var result = Container.Resolve <ICommand <Account> >(); // Verify Assert.IsNotNull(result); Assert.IsInstanceOfType(result.Executed, typeof(Account)); }
public void ResolveCorrespondingTypeNamed() { // Setup Container .RegisterType(typeof(ICommand <>), typeof(ConcreteCommand <>), Invoke.Method("Execute", Resolve.Parameter("1"))); // Act var result = Container.Resolve <ICommand <string> >(); // Verify Assert.IsNotNull(result); Assert.AreEqual(result.Executed, Container.Resolve <string>("1")); }
public void NamedExplicitOpenGeneric() { // Setup Container .RegisterType(typeof(ICommand <>), typeof(ConcreteCommand <>), "inner") .RegisterType(typeof(ICommand <>), typeof(ConcreteCommand <>), Invoke.Method("ChainedExecute", Resolve.Parameter(typeof(ICommand <>), "inner"))); // Act var result = Container.Resolve <ICommand <Account> >(); // Verify Assert.IsNotNull(result); Assert.IsInstanceOfType(result.Chained, typeof(ICommand <Account>)); }
public virtual void InjectTypeWithAnnotatdStatic() { // Setup Container.RegisterType <GuineaPig>( Invoke.Method(nameof(GuineaPig.Inject3), 37), Invoke.Method(nameof(GuineaPig.Inject2), "Hi there")); // Act GuineaPig pig = Container.Resolve <GuineaPig>(); // Verify Assert.AreEqual(37, pig.IntValue); Assert.AreEqual("Hi there", pig.StringValue); }
public void CanInjectNestedGenerics() { // Setup Container.RegisterType(typeof(ICommand <>), typeof(LoggingCommand <>), Invoke.Constructor(Resolve.Parameter(typeof(ICommand <>), "concrete"))) .RegisterType(typeof(ICommand <>), typeof(ConcreteCommand <>), "concrete"); // Act var cmd = Container.Resolve <ICommand <Customer?> >(); var logCmd = (LoggingCommand <Customer?>)cmd; // Verify Assert.IsNotNull(logCmd.Inner); Assert.IsInstanceOfType(logCmd.Inner, typeof(ConcreteCommand <Customer?>)); }
/// <summary> /// Invoked when the completion is closed, regardless of whether an item was applied or the completion was /// cancelled. In the former case, invocation occurs before that of <see cref="HandleItemCompleted" />. Therefore, /// it defers the notification of the handler(s) for some time, to make sure any <see cref="HandleItemCompleted" /> /// event arives first. /// </summary> private void HandleClosed(object sender, EventArgs eventArgs) { var isEscapePressed = Key.Escape.IsPressed(); OnClosed(); if (isEscapePressed) { _terminationTrigger = EventTrigger.Shortcut; OnCancel(); } else { _delayedCancelAction = Invoke.Later(OnCancel, 10000); } }
public void InjectDefaultCtorOpenGeneric() { // Arrange #region inject_default_ctor_open_generic_arrange Container.RegisterType(typeof(Service <>), Invoke.Constructor()); #endregion // Act var instance = Container.Resolve <Service <object> >(); // Validate Assert.AreEqual(1, instance.Ctor); }
public Invoke simpleFunc() { EnterRule_simpleFunc(); EnterRule("simpleFunc", 22); TraceIn("simpleFunc", 22); Invoke fi = default(Invoke); IToken identifier42 = default(IToken); List<List<IToken>> identifierListParam43 = default(List<List<IToken>>); fi = new Invoke(); try { DebugEnterRule(GrammarFileName, "simpleFunc"); DebugLocation(460, 1); try { // D:\\projects\\repository\\ifmo\\Компиляторы\\PascalCompiler\\PascalCompiler\\Grammar\\Pascal.g:465:2: ( identifier LPAREN ( identifierListParam )? RPAREN ) DebugEnterAlt(1); // D:\\projects\\repository\\ifmo\\Компиляторы\\PascalCompiler\\PascalCompiler\\Grammar\\Pascal.g:465:4: identifier LPAREN ( identifierListParam )? RPAREN { DebugLocation(465, 4); PushFollow(Follow._identifier_in_simpleFunc1631); identifier42=identifier(); PopFollow(); DebugLocation(466, 3); fi.SetName(identifier42); DebugLocation(469, 3); Match(input,LPAREN,Follow._LPAREN_in_simpleFunc1639); DebugLocation(470, 3); // D:\\projects\\repository\\ifmo\\Компиляторы\\PascalCompiler\\PascalCompiler\\Grammar\\Pascal.g:470:3: ( identifierListParam )? int alt20=2; try { DebugEnterSubRule(20); try { DebugEnterDecision(20, false); int LA20_0 = input.LA(1); if ((LA20_0==ID)) { alt20 = 1; } } finally { DebugExitDecision(20); } switch (alt20) { case 1: DebugEnterAlt(1); // D:\\projects\\repository\\ifmo\\Компиляторы\\PascalCompiler\\PascalCompiler\\Grammar\\Pascal.g:470:5: identifierListParam { DebugLocation(470, 5); PushFollow(Follow._identifierListParam_in_simpleFunc1645); identifierListParam43=identifierListParam(); PopFollow(); DebugLocation(471, 3); fi.SetArgs(identifierListParam43); } break; } } finally { DebugExitSubRule(20); } DebugLocation(474, 6); Match(input,RPAREN,Follow._RPAREN_in_simpleFunc1656); } } catch (RecognitionException e) { throw e; } finally { TraceOut("simpleFunc", 22); LeaveRule("simpleFunc", 22); LeaveRule_simpleFunc(); } DebugLocation(475, 1); } finally { DebugExitRule(GrammarFileName, "simpleFunc"); } return fi; }
void Start() { instance = this; }
public virtual void VisitInvoke(Invoke n) { }
public void SetGuid(string guid) { Invoke = new Invoke(_tcpClient, guid); Notify = new Notify(_tcpClient, guid); }