public void CanEmitVoidMethodsThatPrintTheirNameToConsole() { //-- Arrange DeriveClassFrom <object>() .ImplementInterface <IArsenicTestInterface>() .DefaultConstructor() .VoidMethods().Implement(m => { m.EmitFromLambda(() => Console.WriteLine(m.MethodInfo.Name)); }); //-- Act IArsenicTestInterface obj = base.CreateClassInstanceAs <IArsenicTestInterface>().UsingDefaultConstructor(); obj.First(); obj.Second(); obj.Third(); //-- Assert string expectedOutput = "First" + Environment.NewLine + "Second" + Environment.NewLine + "Third" + Environment.NewLine; Assert.That(m_TestConsoleOut.ToString(), Is.EqualTo(expectedOutput)); }
public void CanImplementInterfaceWithVoidParameterlessMethods() { //-- Arrange DeriveClassFrom <object>() .ImplementInterface <IArsenicTestInterface>() .DefaultConstructor() .VoidMethods().Implement(m => { m.EmitFromLambda(() => Console.WriteLine(m.MethodInfo.Name)); }); //-- Act IArsenicTestInterface obj = base.CreateClassInstanceAs <IArsenicTestInterface>().UsingDefaultConstructor(); obj.First(); obj.Second(); obj.Third(); //-- Assert Assert.That(obj.GetType().IsClass); Assert.That(obj.GetType().BaseType, Is.SameAs(typeof(object))); Assert.That(obj.GetType().Assembly.IsDynamic); Assert.That(obj.GetType().Assembly.GetName().Name, Is.EqualTo(DynamicAssemblyName)); }