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) }) { }
//-------- 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!! }
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); }
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)); }
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); }
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]); }
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; }
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; }
private void ChangeValues(SampleClass target) { target.FieldLongValue += 1; target.PropertyLongValue += 1; target.FieldStringValue += "changed"; target.PropertyStringValue += "changed"; }
public DialogResult Call(string text, string caption) { SampleClass _this = (object)this as SampleClass; return(_this.Call(text, "HOOKED!!!")); }