コード例 #1
0
 public ChangedObjectForSampleClass(string pathToContainer, SampleClass before, SampleClass after)
     : base(pathToContainer, before,
            new[]
                {
                    new AttributeChange("FieldLongValue", before.FieldLongValue, after.FieldLongValue),
                    new AttributeChange("FieldStringValue", before.FieldStringValue, after.FieldStringValue),
                    new AttributeChange("PropertyLongValue", before.PropertyLongValue, after.PropertyLongValue),
                    new AttributeChange("PropertyStringValue", before.PropertyStringValue,
                                        after.PropertyStringValue)
                })
 {
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: StrixG/MTAEir
        //--------

        static void TestNonStaticMethodHook()
        {
            SampleClass cls = new SampleClass();

            object o = cHook.Hook(typeof(SampleClass), "Call", new Type[] { typeof(string), typeof(string) },
                                  typeof(MySampleClass), "Call", new Type[] { typeof(string), typeof(string) });

            cls.Call("Non-Static Method Hook\r\rThis should be hooked", "HookTest");
            cHook.Unhook(o);

            cls.Call("Non-Static Method Hook\r\rThis should NOT be hooked", "HookTest");

            //find the method we want to hook
            //replace with our method. REMEMBER THAT FUNCTION SIGNATURE MUST MATCH!!
        }
コード例 #3
0
        public void TestingProductQty()
        {
            var datasource = new Mock <IDataSource>();
            var p          = new Product(5);

            datasource
            .Setup(m => m.GetProduct(It.IsAny <Guid>()))
            .Returns(p);

            var testingclass = new SampleClass(datasource.Object);

            var checkingQty = testingclass.checkQty(Guid.NewGuid());

            Assert.True(checkingQty);
        }
コード例 #4
0
        public async Task CanAccessPropertiesAndFields()
        {
            string code = @"
import Test.SampleClass;
function<int> testFunc(SampleClass sc, int x)
{
    return sc.SampleField + sc.SampleProperty + x;
}";

            Compiler.ExposeAssembly(Assembly.GetExecutingAssembly());
            GlobalContext module = await MakeModule(code);

            Lambda      lambda = module.LookupVariable("testFunc") as Lambda;
            SampleClass sc     = new SampleClass
            {
                SampleField    = 5,
                SampleProperty = 3
            };

            Assert.Equal(10, lambda.Run(sc, 2));
        }
コード例 #5
0
        public async Task CanParseModules()
        {
            string code = @"
import Test.SampleClass;
function<int> testFunc(SampleClass sc, int x)
{
    return sc.SampleMethod(x);
}";

            Compiler.ExposeAssembly(Assembly.GetExecutingAssembly());
            GlobalContext module = await MakeModule(code);

            Lambda      lambda = module.LookupVariable("testFunc") as Lambda;
            SampleClass sc     = new SampleClass
            {
                SampleField = 5
            };

            Assert.Equal(5, lambda.Run(sc, 11));
            Assert.Equal(11, sc.SampleField);
        }
コード例 #6
0
 private void MakeSomeChanges(SampleClass after)
 {
     ChangeValues(after);
     after.Children.RemoveAt(1);
     after.Children.Add(CreateObject(4));
     after.Children[0].Children.RemoveAt(1);
     ChangeValues(after.Children[0].Children[0]);
 }
コード例 #7
0
 private IEnumerable<Difference> GetExpectedDifferences(SampleClass before, SampleClass after)
 {
     var expectedDifferences = new List<Difference>
                                   {
                                       new ChangedObjectForSampleClass("", before, after),
                                       new DeletedObject("", before, before.Children[1]),
                                       new AddedObject("", after, after.Children[1]),
                                       new DeletedObject("1", before.Children[0], before.Children[0].Children[1]),
                                       new ChangedObjectForSampleClass("1, 2", before.Children[0].Children[0],
                                                                       after.Children[0].Children[0])
                                   };
     return expectedDifferences;
 }
コード例 #8
0
        private SampleClass CreateObject(int seed)
        {
            var obj = new SampleClass();
            obj.Id = seed;
            obj.IdentifyingText = seed.ToString(CultureInfo.InvariantCulture);

            obj.FieldLongValue = seed + 1;
            obj.FieldStringValue = (seed + 2).ToString(CultureInfo.InvariantCulture);
            obj.PropertyLongValue = seed + 3;
            obj.PropertyStringValue = (seed + 4).ToString(CultureInfo.InvariantCulture);

            return obj;
        }
コード例 #9
0
 private void ChangeValues(SampleClass target)
 {
     target.FieldLongValue += 1;
     target.PropertyLongValue += 1;
     target.FieldStringValue += "changed";
     target.PropertyStringValue += "changed";
 }
コード例 #10
0
ファイル: Program.cs プロジェクト: StrixG/MTAEir
            public DialogResult Call(string text, string caption)
            {
                SampleClass _this = (object)this as SampleClass;

                return(_this.Call(text, "HOOKED!!!"));
            }
コード例 #11
0
ファイル: Program.cs プロジェクト: blaquee/Deviare-InProc
        //--------
        static void TestNonStaticMethodHook()
        {
            SampleClass cls = new SampleClass();

            object o = cHook.Hook(typeof(SampleClass), "Call", new Type[] { typeof(string), typeof(string) },
                                  typeof(MySampleClass), "Call", new Type[] { typeof(string), typeof(string) });
            cls.Call("Non-Static Method Hook\r\rThis should be hooked", "HookTest");
            cHook.Unhook(o);

            cls.Call("Non-Static Method Hook\r\rThis should NOT be hooked", "HookTest");

            //find the method we want to hook
            //replace with our method. REMEMBER THAT FUNCTION SIGNATURE MUST MATCH!!
        }