public void TestNumberIncrementor() { Temperature belgrade = new Temperature(25, 'c', 1); int bgdBefore = belgrade.Value; PropertyManipulator valueManipulator = new PropertyManipulator("Value"); IEntryProcessor processor = new NumberIncrementor(valueManipulator, 1, true); IEntryProcessor processor1 = new NumberIncrementor(valueManipulator, 1, true); Assert.AreEqual(processor, processor1); Assert.AreEqual(processor.GetHashCode(), processor1.GetHashCode()); Assert.AreEqual(processor.ToString(), processor1.ToString()); LocalCache.Entry entry = new LocalCache.Entry(new LocalCache(), "belgrade", belgrade); processor.Process(entry); Assert.AreEqual(bgdBefore + 1, ((Temperature)entry.Value).Value); processor.Process(entry); Assert.AreEqual(bgdBefore + 2, ((Temperature)entry.Value).Value); // testing on Remote cache INamedCache cache = CacheFactory.GetCache(CacheName); cache.Clear(); Temperature bgd = new Temperature(25, 'c', 12); Temperature nyc = new Temperature(99, 'f', 12); cache.Insert("BGD", bgd); cache.Insert("NYC", nyc); PropertyManipulator manipulator = new PropertyManipulator("Value"); processor = new NumberIncrementor(manipulator, 1, true); object before = cache.Invoke("BGD", processor); Assert.AreEqual(bgd.Value, before); Temperature after = (Temperature)cache["BGD"]; Assert.AreEqual(((int)before) + 1, after.Value); processor = new NumberIncrementor(manipulator, -19, false); object newNYC = cache.Invoke("NYC", processor); Assert.AreEqual(nyc.Value - 19, newNYC); Score score = new Score(1, 1, 1, 1, 1, 1, 1, new RawInt128(new byte[] { 0 }), 1); LocalCache.Entry scoreEntry = new LocalCache.Entry(new LocalCache(), "score", score); valueManipulator = new PropertyManipulator("RawInt128Value"); processor = new NumberIncrementor(valueManipulator, 1, true); processor.Process(scoreEntry); CacheFactory.Shutdown(); }
public void TestUnitNumberIncrementor() { Score score = new Score(1, 1, 1, 1L, 1, 1, new decimal(1), new RawInt128(new byte[] { 1 }), 1); Score scoreOrig = new Score(1, 1, 1, 1L, 1, 1, new decimal(1), new RawInt128(new byte[] { 1 }), 1); PropertyManipulator byteManipulator = new PropertyManipulator("ByteValue"); PropertyManipulator shortManipulator = new PropertyManipulator("ShortValue"); PropertyManipulator intManipulator = new PropertyManipulator("IntValue"); PropertyManipulator longManipulator = new PropertyManipulator("LongValue"); PropertyManipulator floatManipulator = new PropertyManipulator("FloatValue"); PropertyManipulator doubleManipulator = new PropertyManipulator("DoubleValue"); PropertyManipulator decimalManipulator = new PropertyManipulator("DecimalValue"); PropertyManipulator int128Manipulator = new PropertyManipulator("RawInt128Value"); NumberIncrementor processorByte = new NumberIncrementor(byteManipulator, 2, true); NumberIncrementor processorByte2 = new NumberIncrementor("ByteValue", 2, false); Assert.IsTrue(processorByte.Equals(processorByte2)); NumberIncrementor processorShort = new NumberIncrementor(shortManipulator, 2, true); NumberIncrementor processorInt = new NumberIncrementor(intManipulator, 2, true); NumberIncrementor processorLong = new NumberIncrementor(longManipulator, 2, true); NumberIncrementor processorFloat = new NumberIncrementor(floatManipulator, 2, true); NumberIncrementor processorDouble = new NumberIncrementor(doubleManipulator, 2, true); NumberIncrementor processorDecimal = new NumberIncrementor(decimalManipulator, new decimal(2), true); Exception e = null; NumberIncrementor processorInt128 = null; try { processorInt128 = new NumberIncrementor(int128Manipulator, new RawInt128(new byte[] { 6 }), true); } catch (Exception ex) { e = ex; } Assert.IsNull(processorInt128); Assert.IsNotNull(e); Assert.IsInstanceOf(typeof(ArgumentException), e); LocalCache.Entry entry = new LocalCache.Entry(new LocalCache(), "score", score); object result1 = processorByte.Process(entry); Assert.IsNotNull(result1); Assert.IsInstanceOf(typeof(byte), result1); Assert.AreEqual((byte)result1, 1); result1 = processorByte2.Process(entry); Assert.IsNotNull(result1); Assert.IsInstanceOf(typeof(byte), result1); Assert.AreEqual((byte)result1, 5); processorShort.Process(entry); processorInt.Process(entry); processorLong.Process(entry); processorFloat.Process(entry); processorDouble.Process(entry); processorDecimal.Process(entry); e = null; try { processorInt128 = new NumberIncrementor("v", null, false); Assert.IsNotNull(processorInt128); processorInt128.Process(entry); } catch (Exception ex) { e = ex; } Assert.IsNotNull(e); Assert.IsInstanceOf(typeof(ArgumentNullException), e); processorInt128 = new NumberIncrementor(int128Manipulator, 5, false); processorInt128.Process(entry); Assert.AreEqual(scoreOrig.ByteValue + 4, ((Score)entry.Value).ByteValue); Assert.AreEqual(scoreOrig.ShortValue + 2, ((Score)entry.Value).ShortValue); Assert.AreEqual(scoreOrig.IntValue + 2, ((Score)entry.Value).IntValue); Assert.AreEqual(scoreOrig.LongValue + 2, ((Score)entry.Value).LongValue); Assert.AreEqual(scoreOrig.FloatValue + 2, ((Score)entry.Value).FloatValue); Assert.AreEqual(scoreOrig.DoubleValue + 2, ((Score)entry.Value).DoubleValue); Assert.AreEqual(scoreOrig.RawInt128Value.ToDecimal() + 5, ((Score)entry.Value).RawInt128Value.ToDecimal()); Assert.AreEqual(Decimal.Add(scoreOrig.DecimalValue, new Decimal(2)), ((Score)entry.Value).DecimalValue); }