public void BranchTest()
{
// set up temp assembly.
var assembly = Utilities.CreateTempNetAssembly();
var tableStream = assembly.NetDirectory.MetadataHeader.GetStream<TableStream>();
var methodTable = tableStream.GetTable<MethodDefinition>();
// write code.
var body = methodTable[0].MethodBody;
body.Instructions.Clear();
var target = MsilInstruction.Create(MsilOpCodes.Nop);
body.Instructions.Add(MsilInstruction.Create(MsilOpCodes.Nop));
body.Instructions.Add(MsilInstruction.Create(MsilOpCodes.Br, target));
body.Instructions.Add(MsilInstruction.Create(MsilOpCodes.Nop));
body.Instructions.Add(MsilInstruction.Create(MsilOpCodes.Nop));
body.Instructions.Add(target);
body.Instructions.Add(MsilInstruction.Create(MsilOpCodes.Ret));
body.CalculateOffsets();
int offset = target.Offset;
// build and validate.
assembly = Utilities.RebuildNetAssembly(assembly);
methodTable = assembly.NetDirectory.MetadataHeader.GetStream<TableStream>().GetTable<MethodDefinition>();
var operand = methodTable[0].MethodBody.Instructions[1].Operand;
Assert.IsInstanceOfType(operand, typeof(MsilInstruction));
Assert.AreEqual(((MsilInstruction)operand).Offset, offset);
}