示例#1
0
        public void LoadTestAssembly()
        {
            var binary = DllTestHelper.CompileTestBinary(_folder);

            File.WriteAllBytes("test.dll", binary);
            _stream          = new MemoryStream(File.ReadAllBytes("test.dll"));
            _module          = ModuleDefinition.ReadModule(_stream);
            _stream.Position = 0;
        }
示例#2
0
        public void BooleanConstant_PreMutation(bool expected, string constant)
        {
            // Arrange
            var binary = DllTestHelper.CompileTestBinary(folder);

            // Act
            using (var binaryInteractor = new DllTestHelper(binary))
            {
                var actual = binaryInteractor.GetField(nameSpace, constant);
                // Assert
                Assert.AreEqual(expected, actual);
            }
        }
示例#3
0
        public void StringConstantTwoCharacters_PreMutation_Is_AB()
        {
            // Arrange
            var binary   = DllTestHelper.CompileTestBinary(folder);
            var expected = "AB";

            // Act
            using (var binaryInteractor = new DllTestHelper(binary))
            {
                var actual = binaryInteractor.GetField(nameSpace, ConstantStringTwoCharactersName);

                // Assert
                Assert.AreEqual(expected, actual);
            }
        }
示例#4
0
        public void IntConstant_PreMutation_Is_1()
        {
            // Arrange
            var binary   = DllTestHelper.CompileTestBinary(folder);
            var expected = 1;

            // Act
            using (var binaryInteractor = new DllTestHelper(binary))
            {
                var actual = binaryInteractor.GetField(nameSpace, ConstantIntName);

                // Assert
                Assert.AreEqual(expected, actual);
            }
        }
示例#5
0
        public void Bitwise_PreMutation(string methodName, object argument1, object argument2, uint expected)
        {
            // Arrange
            var binary = DllTestHelper.CompileTestBinary(_folder);

            // Act
            using (var binaryInteractor = new DllTestHelper(binary))
            {
                var actual = (uint)binaryInteractor.DynamicMethodCall(_nameSpace, methodName.FirstCharToUpper(),
                                                                      new[] { argument1, argument2 });

                // Assert
                Assert.AreEqual(expected, actual);
            }
        }
示例#6
0
        public void Logical_PreMutation_Or()
        {
            // Arrange
            var binary   = DllTestHelper.CompileTestBinary(folder);
            var expected = true;

            // Act
            using (var binaryInteractor = new DllTestHelper(binary))
            {
                var  instance = binaryInteractor.CreateInstance(nameSpace);
                bool actual   = instance.OrOperator(true, true);

                // Assert
                Assert.AreEqual(expected, actual);
            }
        }
示例#7
0
        public void ByteConstant_PostMutation_IsNot_240()
        {
            // Arrange
            var  binary   = DllTestHelper.CompileTestBinary(folder);
            byte expected = 240;

            // Act
            var mutatedBinary = DllTestHelper.MutateConstant <NumberConstantMutationAnalyzer>(binary, ConstantByteName);

            using (var binaryInteractor = new DllTestHelper(mutatedBinary))
            {
                var actual = binaryInteractor.GetField(nameSpace, ConstantByteName);

                // Assert
                Assert.AreNotEqual(expected, actual);
            }
        }
示例#8
0
        public void BooleanBranch_PreMutation(string methodName, object expectedReturn)
        {
            // Arrange
            var binary   = DllTestHelper.CompileTestBinary(_folder);
            var expected = true;

            // Act

            using (var binaryInteractor = new DllTestHelper(binary))
            {
                var actual = (bool)binaryInteractor.DynamicMethodCall(_nameSpace, methodName.FirstCharToUpper(),
                                                                      new[] { expectedReturn });

                // Assert
                Assert.AreEqual(expected, actual);
            }
        }
示例#9
0
        public void BooleanConstant_PostMutation_FalseToTrue()
        {
            // Arrange
            var binary   = DllTestHelper.CompileTestBinary(folder);
            var expected = true;

            // Act
            var mutatedBinary =
                DllTestHelper.MutateField <BooleanConstantMutationAnalyzer>(binary, ConstantBoolFalseName, true);

            using (var binaryInteractor = new DllTestHelper(mutatedBinary))
            {
                var actual = binaryInteractor.GetField(nameSpace, ConstantBoolTrueName);

                // Assert
                Assert.AreEqual(expected, actual);
            }
        }
示例#10
0
        public void StringConstantTwoCharacters_PostMutation_IsNot_AB()
        {
            // Arrange
            var binary   = DllTestHelper.CompileTestBinary(folder);
            var expected = "AB";

            // Act
            var mutatedBinary =
                DllTestHelper.MutateConstant <StringConstantMutationAnalyzer>(binary, ConstantStringTwoCharactersName);

            using (var binaryInteractor = new DllTestHelper(mutatedBinary))
            {
                var actual = binaryInteractor.GetField(nameSpace, ConstantStringTwoCharactersName);

                // Assert
                Assert.AreNotEqual(expected, actual);
            }
        }
示例#11
0
        public void Logical_PostMutation_AndToXor02()
        {
            // Arrange
            var binary   = DllTestHelper.CompileTestBinary(folder);
            var expected = true;

            // Act
            var mutatedBinary = DllTestHelper.MutateMethod <BitwiseMutationAnalyzer>(binary, "AndOperator", OpCodes.Xor);

            using (var binaryInteractor = new DllTestHelper(mutatedBinary))
            {
                var  instance = binaryInteractor.CreateInstance(nameSpace);
                bool actual   = instance.AndOperator(true, false);

                // Assert
                Assert.AreEqual(expected, actual);
            }
        }
示例#12
0
        public void Boolean_Variable_PostMutation(string methodName, bool expected, bool simplify)
        {
            // Arrange
            var binary = DllTestHelper.CompileTestBinary(_folder);

            // Act
            var mutatedBinary =
                DllTestHelper.MutateMethodVariables <VariableMutationAnalyzer>(binary, methodName, simplify);

            using (var binaryInteractor = new DllTestHelper(mutatedBinary))
            {
                var actual =
                    (bool)binaryInteractor.DynamicMethodCall(_nameSpace, methodName.FirstCharToUpper(),
                                                             new object[] { });

                // Assert
                Assert.AreEqual(expected, actual);
            }
        }
示例#13
0
        public void Bitwise_PostMutation(string methodName, object argument1, object argument2,
                                         string expectedOpCodeName, uint expected)
        {
            // Arrange
            var binary         = DllTestHelper.CompileTestBinary(_folder);
            var opCodeExpected = expectedOpCodeName.ParseOpCode();

            // Act
            var mutatedBinary =
                DllTestHelper.MutateMethod <BitwiseMutationAnalyzer>(binary, methodName, opCodeExpected);

            using (var binaryInteractor = new DllTestHelper(mutatedBinary))
            {
                var actual = (uint)binaryInteractor.DynamicMethodCall(_nameSpace, methodName.FirstCharToUpper(),
                                                                      new[] { argument1, argument2 });

                // Assert
                Assert.AreEqual(expected, actual);
            }
        }
示例#14
0
        public void BooleanBranch_PostMutation(string methodName, string expectedOpCodeName, object argument1,
                                               bool simplify)
        {
            // Arrange
            var binary         = DllTestHelper.CompileTestBinary(_folder);
            var expected       = false;
            var opCodeExpected = expectedOpCodeName.ParseOpCode();

            // Act
            var mutatedBinary =
                DllTestHelper.MutateMethod <BooleanBranchMutationAnalyzer>(binary, methodName, opCodeExpected, simplify);

            using (var binaryInteractor = new DllTestHelper(mutatedBinary))
            {
                var actual =
                    (bool)binaryInteractor.DynamicMethodCall(_nameSpace, methodName.FirstCharToUpper(),
                                                             new[] { argument1 });

                // Assert
                Assert.AreEqual(expected, actual);
            }
        }
示例#15
0
        public void Array_PostMutation(string methodName)
        {
            // Arrange
            var binary = DllTestHelper.CompileTestBinary(_folder);

            object original;
            object actual;

            // Act
            using (var originalInteractor = new DllTestHelper(binary))
            {
                original = originalInteractor.DynamicMethodCall(_nameSpace, methodName, null);
            }

            var mutatedBinary = DllTestHelper.MutateArray <ArrayMutationAnalyzer>(binary, methodName);

            using (var binaryInteractor = new DllTestHelper(mutatedBinary))
            {
                actual = binaryInteractor.DynamicMethodCall(_nameSpace, methodName, null);
            }

            // Assert
            Assert.AreNotEqual(original, actual);
        }
示例#16
0
        public void Equality_PostMutation_Branch(string methodName, string defaultOpCodeName, string expectedOpCodeName,
                                                 object argument1, object argument2)
        {
            // Arrange
            var binary         = DllTestHelper.CompileTestBinary(_folder);
            var expected       = false;
            var opCodeDefault  = defaultOpCodeName.ParseOpCode();
            var opCodeExpected = expectedOpCodeName.ParseOpCode();

            // Act
            binary = Utils.Utils.ChangeComparisonToBranchOperator(binary, methodName, opCodeDefault);
            var mutatedBinary =
                DllTestHelper.MutateMethod <ComparisonMutationAnalyzer>(binary, methodName, opCodeExpected);

            using (var binaryInteractor = new DllTestHelper(mutatedBinary))
            {
                var instance = binaryInteractor.CreateInstance(_nameSpace);
                var method   = ((object)instance).GetType().GetMethod(methodName.FirstCharToUpper());
                var actual   = (bool)method.Invoke(instance, new[] { argument1, argument2 });

                // Assert
                Assert.AreEqual(expected, actual);
            }
        }
示例#17
0
        public void LoadTestAssembly()
        {
            var binary = DllTestHelper.CompileTestBinary(_folder);

            File.WriteAllBytes("test.dll", binary);
        }