public void Add_Two_Spaces_Within_First_Open_Brackets() { var autoIndentWriter = new AutoIndentOutputWriter(_outputWriterMock); autoIndentWriter.Apply(".method public {"); autoIndentWriter.Apply(".maxstack 8"); _outputWriterMock.Received().Write(" .maxstack 8"); }
public void Be_Able_To_Support_Params_Keyword() { var type = DataHelper.SampleAssembly.Value.Modules.First().Types.First(x => x.Name == "PublicClass"); var methodDefinition = type.Methods.First(x => x.Name == "PublicVoidMethodParams"); methodDefinition.WriteILBody(_outputWriterMock); _outputWriterMock.Received(1).WriteLine(".param [1]"); _outputWriterMock.Received(1).WriteLine(".custom instance void [System.Runtime]System.ParamArrayAttribute::.ctor() = ( 01 00 00 00 )"); }
public void Write_Custom_Attributes() { var type = DataHelper.SampleAssembly.Value.Modules.First().Types.First(x => x.Name == "SomeClassWithAttribute"); var eventDefinition = type.Events.First(x => x.Name == "SomeEventWithAttribute"); eventDefinition.WriteILBody(_outputWriterMock); _outputWriterMock.Received(1).WriteLine(Arg.Is <string>( x => new string[] { #if NETFRAMEWORK ".custom instance void class dotnet_ildasm.Sample.Classes.SomeAttribute::.ctor() = ( 01 00 00 00 ) // ....", #else ".custom instance void class dotnet_ildasm.Sample.Classes.SomeAttribute::.ctor() = ( 01 00 00 00 ) // ....", #endif }.Contains(x) )); }
public void Support_Return_Value_Attributes() { var type = DataHelper.SampleAssembly.Value.Modules.First().Types.First(x => x.Name == "SomeClassWithAttribute"); var methodDefinition = type.Methods.First(x => x.Name == "SomeMethodWithAttributeOnReturnValue"); methodDefinition.WriteILBody(_outputWriterMock); _outputWriterMock.Received(1).WriteLine(".param [0]"); _outputWriterMock.Received(2).WriteLine(Arg.Is <string>( x => new string[] { ".custom instance void class dotnet_ildasm.Sample.Classes.SomeAttribute::.ctor() = ( 01 00 00 00 ) // ....", ".custom instance void class dotnet_ildasm.Sample.Classes.AnotherAttribute::.ctor() = ( 01 00 00 00 ) // ...." }.Contains(x) )); }
public void Write_ImageBase_Directive() { var expected = ".imagebase 0x00400000"; var directivesProcessor = new ModuleDirectivesProcessor(DotnetIldasmSampleStandardDll, _outputWriterMock); directivesProcessor.WriteImageBaseDirective(); _outputWriterMock.Received(1).WriteLine(expected); }
public void Write_Custom_Attributes() { var type = DataHelper.SampleAssembly.Value.Modules.First().Types.First(x => x.Name == "SomeClassWithAttribute"); var propertyDefinition = type.Properties.First(x => x.Name == "SomePropertyWithAttribute"); propertyDefinition.WriteILBody(_outputWriterMock); _outputWriterMock.Received(2).WriteLine(Arg.Is <string>( x => new string [] { #if NETFRAMEWORK ".custom instance void class dotnet_ildasm.Sample.Classes.SomeAttribute::.ctor() = ( 01 00 00 00 ) // ....", ".custom instance void class [mscorlib]System.Diagnostics.DebuggerDisplayAttribute::.ctor(string) = ( 01 00 0E 4C 65 76 65 6C 3D 50 72 6F 70 65 72 74 79 00 00 ) // ...Level.Property.." #else ".custom instance void class dotnet_ildasm.Sample.Classes.SomeAttribute::.ctor() = ( 01 00 00 00 ) // ....", ".custom instance void class [netstandard]System.Diagnostics.DebuggerDisplayAttribute::.ctor(string) = ( 01 00 0E 4C 65 76 65 6C 3D 50 72 6F 70 65 72 74 79 00 00 ) // ...Level.Property.." #endif }.Contains(x)
public void ShouldReadSecondArgument() { // Arrange IOutputWriter writerMock = Substitute.For <IOutputWriter>(); IInputReader readerMock = Substitute.For <IInputReader>(); readerMock.ReadLine().Returns("10"); var sut = new CustomLogicComponent(readerMock, writerMock); // Act sut.DivideExample(); // Assert writerMock.Received(1).Write(Arg.Is <string>(w => w == "Enter another number to be divided")); readerMock.Received(2).ReadLine(); }
public void ShouldProvideCorrectCalculationResults() { // Arrange IOutputWriter writerMock = Substitute.For <IOutputWriter>(); IInputReader readerStub = Substitute.For <IInputReader>(); Stack <int> readLineRetVals = new Stack <int>(); readLineRetVals.Push(2); readLineRetVals.Push(10); readerStub.ReadLine().Returns((info) => { return(readLineRetVals.Pop().ToString()); }); var cut = new CustomLogicComponent(readerStub, writerMock); // Act cut.DivideExample(); // Assert writerMock.Received(1).Write(Arg.Is <string>(w => w == "The result is: 5")); }