Exemplo n.º 1
0
        static void Main(string[] args)
        {
            if (args == null) return;

            var injector = new ThrowHelperIilInjector(args[0]);
            injector.Inject();
            injector.Save();
        }
        public void Must_Save_File()
        {
            var myAssembly = Assembly.GetExecutingAssembly();
            var path = myAssembly.CodeBase.Remove(0, 8);
            var fileInfo = new FileInfo(path);
            outputPath = string.Format("{0}/TempFile.dll", fileInfo.Directory.FullName);

            var ilInjector = new ThrowHelperIilInjector(path, outputPath);

            ilInjector.LoadAssemblyAndGetMethods();
            ilInjector.Inject();
            ilInjector.Save();

            File.Exists(outputPath).Should().Be.True();
        }
        public void Must_Inject_Throw_IfArgumentNull_For_Parameters_With_NotNullAttribute(string methodName, int additionalInstructions)
        {
            var myAssembly = Assembly.GetExecutingAssembly();
            var path = myAssembly.CodeBase.Remove(0, 8);
            var fileInfo = new FileInfo(path);
            outputPath = string.Format("{0}/TempFile.dll", fileInfo.Directory.FullName);
            var ilInjector = new ThrowHelperIilInjector(path, outputPath);

            ilInjector.LoadAssemblyAndGetMethods();
            var instructions = ilInjector.methods.First(x => x.Name.Equals(methodName)).Body.Instructions.Count;
            ilInjector.Inject();

            var currentTotalInstructions = ilInjector.methods.First(x => x.Name.Equals(methodName)).Body.Instructions.Count;

            currentTotalInstructions.Should().Be.EqualTo(instructions + additionalInstructions);
        }