Exemple #1
0
        public void TestNumberMultiplier()
        {
            Temperature         belgrade         = new Temperature(25, 'c', 1);
            int                 bgdBefore        = belgrade.Value;
            PropertyManipulator valueManipulator = new PropertyManipulator("Value");
            IEntryProcessor     processor        = new NumberMultiplier(valueManipulator, 2, true);
            IEntryProcessor     processor1       = new NumberMultiplier(valueManipulator, 2, 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 * 2, ((Temperature)entry.Value).Value);

            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 NumberMultiplier(manipulator, 2, false);
            object newTemp = cache.Invoke("BGD", processor);

            Assert.AreEqual(bgd.Value * 2, newTemp);

            Temperature newBGD = (Temperature)cache["BGD"];

            Assert.AreEqual(bgd.Value * 2, newBGD.Value);

            processor = new NumberMultiplier(manipulator, 0.5, false);
            object newNYC = cache.Invoke("NYC", processor);

            Assert.AreEqual(49, newNYC);

            CacheFactory.Shutdown();
        }
Exemple #2
0
        public void TestUnitNumberMultiplier()
        {
            Score score     = new Score(3, 3, 3, 3L, 3, 3, new decimal(3), new RawInt128(new byte[] { 3 }), 3);
            Score scoreOrig = new Score(3, 3, 3, 3L, 3, 3, new decimal(3), new RawInt128(new byte[] { 3 }), 3);

            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");

            NumberMultiplier processorByte  = new NumberMultiplier(byteManipulator, 2, true);
            NumberMultiplier processorByte2 = new NumberMultiplier("ByteValue", 2, false);

            Assert.IsTrue(processorByte.Equals(processorByte2));
            NumberMultiplier processorShort   = new NumberMultiplier(shortManipulator, 2, true);
            NumberMultiplier processorInt     = new NumberMultiplier(intManipulator, 2, true);
            NumberMultiplier processorLong    = new NumberMultiplier(longManipulator, 2, true);
            NumberMultiplier processorFloat   = new NumberMultiplier(floatManipulator, 2, true);
            NumberMultiplier processorDouble  = new NumberMultiplier(doubleManipulator, 2, true);
            NumberMultiplier processorDecimal = new NumberMultiplier(decimalManipulator, new decimal(2), true);

            Exception        e = null;
            NumberMultiplier processorInt128 = null;

            try
            {
                processorInt128 = new NumberMultiplier(int128Manipulator, new RawInt128(new byte[] { 6 }), true);
            }
            catch (Exception ex)
            {
                e = ex;
            }
            Assert.IsNull(processorInt128);
            Assert.IsNotNull(e);
            Assert.IsInstanceOf(typeof(ArgumentException), e);

            processorInt128 = new NumberMultiplier(int128Manipulator, 2, true);

            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, 3);
            result1 = processorByte2.Process(entry);
            Assert.IsNotNull(result1);
            Assert.IsInstanceOf(typeof(byte), result1);
            Assert.AreEqual((byte)result1, 12);

            processorShort.Process(entry);
            processorInt.Process(entry);
            processorLong.Process(entry);
            processorFloat.Process(entry);
            processorDouble.Process(entry);
            processorDecimal.Process(entry);
            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() * 2, ((Score)entry.Value).RawInt128Value.ToDecimal());
            Assert.AreEqual(Decimal.Multiply(scoreOrig.DecimalValue, new Decimal(2)), ((Score)entry.Value).DecimalValue);

            processorShort = new NumberMultiplier(shortManipulator, 2.5, true);
            processorLong  = new NumberMultiplier(longManipulator, 2.5, true);
            processorByte  = new NumberMultiplier(byteManipulator, 2.5, true);
            processorShort.Process(entry);
            processorLong.Process(entry);
            processorByte.Process(entry);
            Assert.AreEqual(scoreOrig.ByteValue * 10, ((Score)entry.Value).ByteValue);
            Assert.AreEqual(scoreOrig.ShortValue * 5, ((Score)entry.Value).ShortValue);
            Assert.AreEqual(scoreOrig.LongValue * 5, ((Score)entry.Value).LongValue);
        }