public void Right_NewHandler() { CompleteInClass(@" private event Handler E; private delegate void Handler(int i); private void Listener(int i) { } public void M() { E += new Handler(Listener); $ } "); var en = ResultSST.Methods.GetEnumerator(); en.MoveNext(); // .Listener en.MoveNext(); // .M Assert.NotNull(en.Current); var stmt = en.Current.Body.FirstOrDefault(new EventSubscriptionStatement()); var esStmt = stmt as IEventSubscriptionStatement; Assert.NotNull(esStmt); var inv = esStmt.Expression as IInvocationExpression; Assert.NotNull(inv); var actual = inv.MethodName; var delegateType = Names.Type("d:[{0}] [N.C+Handler, TestProject].([{1}] i)", Fix.Void, Fix.Int); var parameter = Names.Parameter("[{0}] target", delegateType); var ctor = Fix.Ctor(delegateType, parameter); Assert.AreEqual(ctor, actual); }
public void Right_NewHandler() { CompleteInClass(@" private event Handler E; private delegate void Handler(int i); private void Listener(int i) { } public void M() { E += new Handler(Listener); $ } "); var delegateType = Names.Type(string.Format("d:[{0}] [N.C+Handler, TestProject].([{1}] i)", Fix.Void, Fix.Int)); var parameter = Names.Parameter("[{0}] target", delegateType); var ctor = Fix.Ctor(delegateType, parameter); var listenerName = Names.Method(string.Format("[{0}] [{1}].Listener([{2}] i)", Fix.Void, Fix.TestClass, Fix.Int)); AssertBody( "M", new EventSubscriptionStatement { Reference = EventRef("E", delegateType), Operation = EventSubscriptionOperation.Add, Expression = InvokeCtor(ctor, RefExpr(MethodRef(listenerName, VarRef("this")))) }, ExprStmt(new CompletionExpression())); }