public void GetParameters_InstructionsThatReadParameters_ReturnsParameters()
        {
            MethodReference method = CecilUtility.Import(() => string.Format("Test", 12));

            var instructions = new[]
            {
                Instruction.Create(OpCodes.Ldarg_1),
                Instruction.Create(OpCodes.Ldarg_0)
            };

            Parameter parameter = new Parameter(CecilUtility.Import(typeof(string)), 0);

            _instructionHelperMock
            .Setup(helper => helper.ReadsParameter(method, instructions[0], out parameter))
            .Returns(true);

            Parameter parameter2 = new Parameter(CecilUtility.Import(typeof(int)), 1);

            _instructionHelperMock
            .Setup(helper => helper.ReadsParameter(method, instructions[1], out parameter2))
            .Returns(true);

            var subject = new ParameterDeducer(_instructionHelperMock.Object);

            TypeReference[] result = subject.GetParameters(method, instructions);

            Assert.AreEqual(2, result.Length);
            Assert.AreEqual(parameter.ParameterType, result[0]);
            Assert.AreEqual(parameter2.ParameterType, result[1]);
        }
Esempio n. 2
0
        public void GetParameters_InstructionsThatReadParameters_ReturnsParameters()
        {
            MethodReference method = CecilUtility.Import(() => string.Format("Test", 12));

            var instructions = new[]
            {
                Instruction.Create(OpCodes.Ldarg_1),
                Instruction.Create(OpCodes.Ldarg_0)
            };

            Parameter parameter = new Parameter(CecilUtility.Import(typeof(string)), 0);
            _instructionHelperMock
                .Setup(helper => helper.ReadsParameter(method, instructions[0], out parameter))
                .Returns(true);

            Parameter parameter2 = new Parameter(CecilUtility.Import(typeof(int)), 1);
            _instructionHelperMock
                .Setup(helper => helper.ReadsParameter(method, instructions[1], out parameter2))
                .Returns(true);

            var subject = new ParameterDeducer(_instructionHelperMock.Object);
            TypeReference[] result = subject.GetParameters(method, instructions);

            Assert.AreEqual(2, result.Length);
            Assert.AreEqual(parameter.ParameterType, result[0]);
            Assert.AreEqual(parameter2.ParameterType, result[1]);
        }
        public void GetParameters_EmptyInstructions_EmptyResult()
        {
            MethodReference method = CecilUtility.Import(() => Console.WriteLine());

            var subject = new ParameterDeducer(_instructionHelperMock.Object);
            var result  = subject.GetParameters(method, Enumerable.Empty <Instruction>());

            Assert.AreEqual(0, result.Length);
        }
Esempio n. 4
0
        public void GetParameters_EmptyInstructions_EmptyResult()
        {
            MethodReference method = CecilUtility.Import(() => Console.WriteLine());

            var subject = new ParameterDeducer(_instructionHelperMock.Object);
            var result = subject.GetParameters(method, Enumerable.Empty<Instruction>());

            Assert.AreEqual(0, result.Length);
        }