public void Basic() { InitTest(); var fieldBool = new MemoryFieldFunc <bool>("BoolTrue", (pool) => true); var testField = new MemoryFieldFunc <int>("IsItCorrect", (pool) => { Assert.AreEqual(drvPool, pool); return(1337); }); Assert.AreEqual("IsItCorrect", testField.Name); Assert.AreEqual(0, testField.Address); Assert.AreEqual(0, testField.Size); Assert.AreEqual(0, testField.Offset); Assert.False(testField.IsConstant); Assert.False(testField.IsDynamic); Assert.False(testField.IsStatic); drvPool.Add(fieldBool); drvPool.Add(testField); memory.Refresh(); Assert.AreEqual(0, actionLogbook.Count); Assert.True(drvPool.ReadAs <bool>("BoolTrue")); Assert.AreEqual(1337, drvPool.ReadAs <int>("IsItCorrect")); // func() are always 'changing' Assert.True(fieldBool.HasChanged()); Assert.True(testField.HasChanged()); Assert.True(fieldBool.HasChanged()); Assert.True(testField.HasChanged()); Assert.True(fieldBool.HasChanged()); Assert.True(testField.HasChanged()); }
public void CounterField() { InitTest(); int iCounter = 0; var fieldCounter = new MemoryFieldFunc <int>("Counter", (pool) => { iCounter++; return(iCounter); }); drvPool.Add(fieldCounter); memory.Refresh(); Assert.AreEqual(1, drvPool.ReadAs <int>("Counter")); Assert.AreEqual(2, drvPool.ReadAs <int>("Counter")); Assert.AreEqual(3, drvPool.ReadAs <int>("Counter")); Assert.AreEqual(4, drvPool.ReadAs <int>("Counter")); Assert.AreEqual(5, drvPool.ReadAs <int>("Counter")); Assert.AreEqual(6, drvPool.ReadAs <int>("Counter")); Assert.AreEqual(7, drvPool.ReadAs <int>("Counter")); }