public string GenerateUpdateJsonFromObject(IncomeSource updateFrom)
        {
            // form the json (determine the fields that need to be updated)
            var sb     = new StringBuilder();
            var sw     = new StringWriter(sb);
            var writer = new JsonTextWriter(sw)
            {
                Formatting = Formatting.None
            };

            writer.WriteStartObject();
            writer.WritePropertyName(@"income_source");
            writer.WriteStartObject();

            if (!ProductServiceName.Equals(updateFrom.ProductServiceName))
            {
                writer.WritePropertyName("name");
                writer.WriteValue(updateFrom.ProductServiceName ?? @"");
            }

            if (!EstimatedVolumeProduced.Equals(updateFrom.EstimatedVolumeProduced))
            {
                writer.WritePropertyName("estimated_volume_produced");
                writer.WriteValue(updateFrom.EstimatedVolumeProduced ?? null);
            }

            if (!EstimatedVolumeSold.Equals(updateFrom.EstimatedVolumeSold))
            {
                writer.WritePropertyName("estimated_volume_sold");
                writer.WriteValue(updateFrom.EstimatedVolumeSold ?? null);
            }

            if (!UnitOfMeasure.Equals(updateFrom.UnitOfMeasure))
            {
                writer.WritePropertyName("unit_of_measure");
                writer.WriteValue(updateFrom.UnitOfMeasure ?? @"");
            }

            if (!EstimatedIncome.Equals(updateFrom.EstimatedIncome))
            {
                writer.WritePropertyName("estimated_income");
                writer.WriteValue(updateFrom.EstimatedIncome ?? null);
            }

            if (!Currency.Equals(updateFrom.Currency))
            {
                writer.WritePropertyName("currency");
                writer.WriteValue(updateFrom.Currency ?? @"");
            }

            if (!ExternalParentId.Equals(updateFrom.ExternalParentId))
            {
                writer.WritePropertyName("household_id");
                writer.WriteValue(updateFrom.ExternalParentId);
            }

            writer.WriteEndObject();
            writer.WriteEndObject();
            return(sw.ToString());
        }
 public bool GetObjectNeedsUpate(IncomeSource checkUpdateFrom)
 {
     if (!ProductServiceName.Equals(checkUpdateFrom.ProductServiceName))
     {
         return(true);
     }
     if (!EstimatedVolumeProduced.Equals(checkUpdateFrom.EstimatedVolumeProduced))
     {
         return(true);
     }
     if (!EstimatedVolumeSold.Equals(checkUpdateFrom.EstimatedVolumeSold))
     {
         return(true);
     }
     if (!UnitOfMeasure.Equals(checkUpdateFrom.UnitOfMeasure))
     {
         return(true);
     }
     if (!EstimatedIncome.Equals(checkUpdateFrom.EstimatedIncome))
     {
         return(true);
     }
     if (!Currency.Equals(checkUpdateFrom.Currency))
     {
         return(true);
     }
     if (!ExternalParentId.Equals(checkUpdateFrom.ExternalParentId))
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 3
0
        public void TestAllUnits()
        {
            foreach (Unit u in Enum.GetValues(typeof(Unit)))
            {
                UnitOfMeasure uom1 = sys.GetUOM(u);
                UnitOfMeasure uom2 = sys.GetUOM(u);
                Assert.IsTrue(uom1.Equals(uom2));

                Quantity q1 = new Quantity(10, uom1);
                Quantity q2 = q1.Convert(uom2);
                Assert.IsTrue(q1.Equals(q2));
            }
        }
        /// <summary>
        /// Returns true if BankingProductRateTier instances are equal
        /// </summary>
        /// <param name="other">Instance of BankingProductRateTier to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(BankingProductRateTier other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                     ) &&
                 (
                     UnitOfMeasure == other.UnitOfMeasure ||
                     UnitOfMeasure != null &&
                     UnitOfMeasure.Equals(other.UnitOfMeasure)
                 ) &&
                 (
                     MinimumValue == other.MinimumValue ||
                     MinimumValue != null &&
                     MinimumValue.Equals(other.MinimumValue)
                 ) &&
                 (
                     MaximumValue == other.MaximumValue ||
                     MaximumValue != null &&
                     MaximumValue.Equals(other.MaximumValue)
                 ) &&
                 (
                     RateApplicationMethod == other.RateApplicationMethod ||
                     RateApplicationMethod != null &&
                     RateApplicationMethod.Equals(other.RateApplicationMethod)
                 ) &&
                 (
                     ApplicabilityConditions == other.ApplicabilityConditions ||
                     ApplicabilityConditions != null &&
                     ApplicabilityConditions.SequenceEqual(other.ApplicabilityConditions)
                 ) &&
                 (
                     SubTier == other.SubTier ||
                     SubTier != null &&
                     SubTier.Equals(other.SubTier)
                 ));
        }
Exemplo n.º 5
0
        public void TestSIQuantity()
        {
            double ten = 10;

            UnitOfMeasure litre    = sys.GetUOM(Unit.LITRE);
            UnitOfMeasure m3       = sys.GetUOM(Unit.CUBIC_METRE);
            UnitOfMeasure m2       = sys.GetUOM(Unit.SQUARE_METRE);
            UnitOfMeasure m        = sys.GetUOM(Unit.METRE);
            UnitOfMeasure cm       = sys.GetUOM(Prefix.CENTI, m);
            UnitOfMeasure mps      = sys.GetUOM(Unit.METRE_PER_SEC);
            UnitOfMeasure secPerM  = sys.CreateQuotientUOM(UnitType.UNCLASSIFIED, null, "s/m", null, sys.GetSecond(), m);
            UnitOfMeasure oneOverM = sys.GetUOM(Unit.DIOPTER);
            UnitOfMeasure fperm    = sys.GetUOM(Unit.FARAD_PER_METRE);

            UnitOfMeasure oneOverCm = sys.CreateScalarUOM(UnitType.UNCLASSIFIED, null, "1/cm", null);

            oneOverCm.SetConversion(100, oneOverM);

            Quantity q1 = new Quantity(ten, litre);
            Quantity q2 = q1.Convert(m3);

            Assert.IsTrue(IsCloseTo(q2.Amount, 0.01, DELTA6));
            Assert.IsTrue(q2.UOM.Equals(m3));

            q2 = q1.Convert(litre);
            Assert.IsTrue(IsCloseTo(q2.Amount, ten, DELTA6));
            Assert.IsTrue(q2.UOM.Equals(litre));

            // Add
            q1 = new Quantity(2, m);
            q2 = new Quantity(2, cm);
            Quantity q3 = q1.Add(q2);

            Assert.IsTrue(IsCloseTo(q3.UOM.ScalingFactor, 1, DELTA6));
            Assert.IsTrue(q3.UOM.AbscissaUnit.Equals(m));
            Assert.IsTrue(IsCloseTo(q3.UOM.Offset, 0, DELTA6));
            Assert.IsTrue(IsCloseTo(q3.Amount, 2.02, DELTA6));

            Quantity q4 = q3.Convert(cm);

            Assert.IsTrue(IsCloseTo(q4.Amount, 202, DELTA6));
            Assert.IsTrue(q4.UOM.Equals(cm));

            // Subtract
            q3 = q3.Subtract(q1);
            Assert.IsTrue(IsCloseTo(q3.UOM.ScalingFactor, 1, DELTA6));
            Assert.IsTrue(q3.UOM.AbscissaUnit.Equals(m));
            Assert.IsTrue(IsCloseTo(q3.Amount, 0.02, DELTA6));

            q4 = q3.Convert(cm);
            Assert.IsTrue(IsCloseTo(q4.Amount, 2, DELTA6));
            Assert.IsTrue(q4.UOM.Equals(cm));

            // Multiply
            q3 = q1.Multiply(q2);
            Assert.IsTrue(IsCloseTo(q3.Amount, 4, DELTA6));
            UnitOfMeasure u = q3.UOM;

            Assert.IsTrue(IsCloseTo(u.ScalingFactor, 0.01, DELTA6));
            Assert.IsTrue(u.GetBaseSymbol().Equals(m2.GetBaseSymbol()));

            q4 = q3.Divide(q3);
            Assert.IsTrue(IsCloseTo(q4.Amount, 1, DELTA6));
            Assert.IsTrue(q4.UOM.Equals(sys.GetOne()));

            q4 = q3.Divide(q1);
            Assert.IsTrue(q4.Equals(q2));

            q4 = q3.Convert(m2);
            Assert.IsTrue(IsCloseTo(q4.Amount, 0.04, DELTA6));
            Assert.IsTrue(q4.UOM.Equals(m2));

            // Divide
            q3 = q3.Divide(q2);
            Assert.IsTrue(IsCloseTo(q3.Amount, 2.0, DELTA6));
            Assert.IsTrue(q3.UOM.Equals(m));
            Assert.IsTrue(q3.Equals(q1));

            q3 = q3.Convert(m);
            Assert.IsTrue(IsCloseTo(q3.Amount, 2.0, DELTA6));

            q1 = new Quantity(0, litre);

            try
            {
                q2 = q1.Divide(q1);
                Assert.Fail("Divide by zero)");
            }
            catch (Exception)
            {
            }

            q1 = q3.Convert(cm).Divide(ten);
            Assert.IsTrue(IsCloseTo(q1.Amount, 20, DELTA6));

            // Invert
            q1 = new Quantity(10, mps);
            q2 = q1.Invert();
            Assert.IsTrue(IsCloseTo(q2.Amount, 0.1, DELTA6));
            Assert.IsTrue(q2.UOM.Equals(secPerM));

            q2 = q2.Invert();
            Assert.IsTrue(IsCloseTo(q2.Amount, 10, DELTA6));
            Assert.IsTrue(q2.UOM.Equals(mps));

            q1 = new Quantity(10, cm);
            q2 = q1.Invert();
            Assert.IsTrue(IsCloseTo(q2.Amount, 0.1, DELTA6));
            u = q2.UOM;
            Assert.IsTrue(u.Equals(oneOverCm));

            q2 = q2.Convert(m.Invert());
            Assert.IsTrue(IsCloseTo(q2.Amount, 10, DELTA6));
            Assert.IsTrue(q2.UOM.Equals(oneOverM));

            Assert.IsTrue(q2.ToString() != null);

            // Newton-metres Divided by metres
            q1 = new Quantity(10, sys.GetUOM(Unit.NEWTON_METRE));
            q2 = new Quantity(1, sys.GetUOM(Unit.METRE));
            q3 = q1.Divide(q2);
            Assert.IsTrue(IsCloseTo(q3.Amount, 10, DELTA6));
            Assert.IsTrue(q3.UOM.Equals(sys.GetUOM(Unit.NEWTON)));

            // length multiplied by force
            q1 = new Quantity(10, sys.GetUOM(Unit.NEWTON));
            q2 = new Quantity(1, sys.GetUOM(Unit.METRE));
            q3 = q1.Multiply(q2);
            Assert.IsTrue(IsCloseTo(q3.Amount, 10, DELTA6));
            UnitOfMeasure nm1 = q3.UOM;
            UnitOfMeasure nm2 = sys.GetUOM(Unit.NEWTON_METRE);

            Assert.IsTrue(nm1.GetBaseSymbol().Equals(nm2.GetBaseSymbol()));
            q4 = q3.Convert(sys.GetUOM(Unit.JOULE));
            Assert.IsTrue(q4.UOM.Equals(sys.GetUOM(Unit.JOULE)));

            // farads
            q1 = new Quantity(10, fperm);
            q2 = new Quantity(1, m);
            q3 = q1.Multiply(q2);
            Assert.IsTrue(IsCloseTo(q3.Amount, 10, DELTA6));
            Assert.IsTrue(q3.UOM.Equals(sys.GetUOM(Unit.FARAD)));

            // amps
            q1 = new Quantity(10, sys.GetUOM(Unit.AMPERE_PER_METRE));
            q2 = new Quantity(1, m);
            q3 = q1.Multiply(q2);
            Assert.IsTrue(IsCloseTo(q3.Amount, 10, DELTA6));
            Assert.IsTrue(q3.UOM.Equals(sys.GetUOM(Unit.AMPERE)));

            // Boltzmann and Avogadro
            Quantity boltzmann = sys.GetQuantity(Constant.BOLTZMANN_CONSTANT);
            Quantity avogadro  = sys.GetQuantity(Constant.AVAGADRO_CONSTANT);
            Quantity gas       = sys.GetQuantity(Constant.GAS_CONSTANT);
            Quantity qR        = boltzmann.Multiply(avogadro);

            Assert.IsTrue(IsCloseTo(qR.UOM.ScalingFactor, gas.UOM.ScalingFactor, DELTA6));

            // Sieverts
            q1 = new Quantity(20, sys.GetUOM(Prefix.MILLI, Unit.SIEVERTS_PER_HOUR));
            q2 = new Quantity(24, sys.GetHour());
            q3 = q1.Multiply(q2);
            Assert.IsTrue(IsCloseTo(q3.Amount, 480, DELTA6));
        }
Exemplo n.º 6
0
        public void TestBridgeUnits1()
        {
            sys.ClearCache();

            // SI
            UnitOfMeasure kg      = sys.GetUOM(Unit.KILOGRAM);
            UnitOfMeasure m       = sys.GetUOM(Unit.METRE);
            UnitOfMeasure km      = sys.GetUOM(Prefix.KILO, m);
            UnitOfMeasure litre   = sys.GetUOM(Unit.LITRE);
            UnitOfMeasure N       = sys.GetUOM(Unit.NEWTON);
            UnitOfMeasure m3      = sys.GetUOM(Unit.CUBIC_METRE);
            UnitOfMeasure m2      = sys.GetUOM(Unit.SQUARE_METRE);
            UnitOfMeasure Nm      = sys.GetUOM(Unit.NEWTON_METRE);
            UnitOfMeasure kPa     = sys.GetUOM(Prefix.KILO, sys.GetUOM(Unit.PASCAL));
            UnitOfMeasure celsius = sys.GetUOM(Unit.CELSIUS);

            // US
            UnitOfMeasure lbm        = sys.GetUOM(Unit.POUND_MASS);
            UnitOfMeasure lbf        = sys.GetUOM(Unit.POUND_FORCE);
            UnitOfMeasure mi         = sys.GetUOM(Unit.MILE);
            UnitOfMeasure ft         = sys.GetUOM(Unit.FOOT);
            UnitOfMeasure gal        = sys.GetUOM(Unit.US_GALLON);
            UnitOfMeasure ft2        = sys.GetUOM(Unit.SQUARE_FOOT);
            UnitOfMeasure ft3        = sys.GetUOM(Unit.CUBIC_FOOT);
            UnitOfMeasure acre       = sys.GetUOM(Unit.ACRE);
            UnitOfMeasure ftlbf      = sys.GetUOM(Unit.FOOT_POUND_FORCE);
            UnitOfMeasure psi        = sys.GetUOM(Unit.PSI);
            UnitOfMeasure fahrenheit = sys.GetUOM(Unit.FAHRENHEIT);

            Assert.IsTrue(ft.BridgeOffset == double.MinValue);

            Quantity q1 = new Quantity(10, ft);
            Quantity q2 = q1.Convert(m);

            Assert.IsTrue(IsCloseTo(q2.Amount, 3.048, DELTA6));
            Quantity q3 = q2.Convert(q1.UOM);

            Assert.IsTrue(IsCloseTo(q3.Amount, 10, DELTA6));

            q1 = new Quantity(10, kg);
            q2 = q1.Convert(lbm);
            Assert.IsTrue(IsCloseTo(q2.Amount, 22.0462, DELTA4));
            q3 = q2.Convert(q1.UOM);
            Assert.IsTrue(IsCloseTo(q3.Amount, 10, DELTA6));

            q1 = new Quantity(212, fahrenheit);
            q2 = q1.Convert(celsius);
            Assert.IsTrue(IsCloseTo(q2.Amount, 100, DELTA6));
            q3 = q2.Convert(q1.UOM);
            Assert.IsTrue(IsCloseTo(q3.Amount, 212, DELTA6));

            UnitOfMeasure mm = sys.CreateProductUOM(UnitType.AREA, "name", "mxm", "", m, m);

            q1 = new Quantity(10, mm);
            q2 = q1.Convert(ft2);
            Assert.IsTrue(IsCloseTo(q2.Amount, 107.639104167, DELTA6));
            q2 = q2.Convert(m2);
            Assert.IsTrue(IsCloseTo(q2.Amount, 10, DELTA6));

            UnitOfMeasure mhr = sys.GetUOM("m/hr");

            if (mhr == null)
            {
                mhr = sys.CreateScalarUOM(UnitType.VELOCITY, "m/hr", "m/hr", "");
                mhr.SetConversion((double)1 / (double)3600, sys.GetUOM(Unit.METRE_PER_SEC));
            }

            q1 = new Quantity(10, psi);
            q2 = q1.Convert(kPa);
            Assert.IsTrue(IsCloseTo(q2.Amount, 68.94757280343134, DELTA6));
            q2 = q2.Convert(psi);
            Assert.IsTrue(IsCloseTo(q2.Amount, 10, DELTA6));

            q1 = new Quantity(10, mhr);
            q2 = q1.Convert(sys.GetUOM(Unit.FEET_PER_SEC));
            Assert.IsTrue(IsCloseTo(q2.Amount, 0.009113444152814231, DELTA6));
            q2 = q2.Convert(mhr);
            Assert.IsTrue(IsCloseTo(q2.Amount, 10, DELTA6));

            q1 = new Quantity(10, gal);
            q2 = q1.Convert(litre);
            Assert.IsTrue(IsCloseTo(q2.Amount, 37.8541178, DELTA6));
            q2 = q2.Convert(gal);
            Assert.IsTrue(IsCloseTo(q2.Amount, 10, DELTA6));

            q1 = new Quantity(10, m3);
            q2 = q1.Convert(ft3);
            Assert.IsTrue(IsCloseTo(q2.Amount, 353.1466672398284, DELTA6));
            q2 = q2.Convert(m3);
            Assert.IsTrue(IsCloseTo(q2.Amount, 10, DELTA6));

            q1 = new Quantity(10, N);
            q2 = q1.Convert(lbf);
            Assert.IsTrue(IsCloseTo(q2.Amount, 2.24809, DELTA6));
            q2 = q2.Convert(N);
            Assert.IsTrue(IsCloseTo(q2.Amount, 10, DELTA6));

            q1 = new Quantity(10, ftlbf);
            q2 = q1.Convert(Nm);
            Assert.IsTrue(IsCloseTo(q2.Amount, 13.558179483314004, DELTA6));
            q2 = q2.Convert(ftlbf);
            Assert.IsTrue(IsCloseTo(q2.Amount, 10, DELTA6));

            q1 = new Quantity(10, lbm);
            q2 = q1.Convert(kg);
            Assert.IsTrue(IsCloseTo(q2.Amount, 4.5359237, DELTA6));
            q2 = q2.Convert(lbm);
            Assert.IsTrue(IsCloseTo(q2.Amount, 10, DELTA6));

            q1 = new Quantity(10, km);
            q2 = q1.Convert(mi);
            Assert.IsTrue(IsCloseTo(q2.Amount, 6.21371192237, DELTA6));
            q2 = q2.Convert(km);
            Assert.IsTrue(IsCloseTo(q2.Amount, 10, DELTA6));

            // length
            q1 = new Quantity(10, sys.GetUOM(Unit.METRE));
            q2 = q1.Convert(sys.GetUOM(Unit.INCH));
            Assert.IsTrue(IsCloseTo(q2.Amount, 393.7007874015748, DELTA6));
            q2 = q2.Convert(sys.GetUOM(Unit.METRE));
            Assert.IsTrue(IsCloseTo(q2.Amount, 10, DELTA6));

            q2 = q1.Convert(sys.GetUOM(Unit.FOOT));
            Assert.IsTrue(IsCloseTo(q2.Amount, 32.80839895013123, DELTA6));
            q2 = q2.Convert(sys.GetUOM(Unit.METRE));
            Assert.IsTrue(IsCloseTo(q2.Amount, 10, DELTA6));

            // area
            q1 = new Quantity(10, sys.GetUOM(Unit.SQUARE_METRE));
            q2 = q1.Convert(sys.GetUOM(Unit.SQUARE_INCH));
            Assert.IsTrue(IsCloseTo(q2.Amount, 15500.031000062, DELTA6));
            q2 = q2.Convert(sys.GetUOM(Unit.SQUARE_METRE));
            Assert.IsTrue(IsCloseTo(q2.Amount, 10, DELTA6));

            q2 = q1.Convert(sys.GetUOM(Unit.SQUARE_FOOT));
            Assert.IsTrue(IsCloseTo(q2.Amount, 107.6391041670972, DELTA6));
            q2 = q2.Convert(sys.GetUOM(Unit.SQUARE_METRE));
            Assert.IsTrue(IsCloseTo(q2.Amount, 10, DELTA6));

            // volume
            q1 = new Quantity(10, sys.GetUOM(Unit.LITRE));
            q2 = q1.Convert(sys.GetUOM(Unit.US_GALLON));
            Assert.IsTrue(IsCloseTo(q2.Amount, 2.641720523581484, DELTA6));
            q2 = q2.Convert(sys.GetUOM(Unit.LITRE));
            Assert.IsTrue(IsCloseTo(q2.Amount, 10, DELTA6));

            q1 = new Quantity(4.0468564224, m);
            q2 = new Quantity(1000, m);
            q3 = q1.Multiply(q2);
            Assert.IsTrue(IsCloseTo(q3.Amount, 4046.8564224, DELTA6));

            UnitOfMeasure uom       = q3.UOM;
            UnitOfMeasure powerBase = uom.GetPowerBase();
            double        sf        = uom.ScalingFactor;

            Assert.IsTrue(uom.AbscissaUnit.Equals(m2));
            Assert.IsTrue(powerBase.Equals(m));
            Assert.IsTrue(IsCloseTo(sf, 1, DELTA6));

            Quantity q4 = q3.Convert(acre);

            Assert.IsTrue(IsCloseTo(q4.Amount, 1, DELTA6));
            Assert.IsTrue(q4.UOM.Equals(acre));

            UnitOfMeasure usSec = sys.GetSecond();

            UnitOfMeasure v1 = sys.GetUOM("m/hr");

            UnitOfMeasure v2 = sys.GetUOM(Unit.METRE_PER_SEC);
            UnitOfMeasure v3 = sys.CreateQuotientUOM(UnitType.VELOCITY, "", "ft/usec", "", ft, usSec);

            UnitOfMeasure d1 = sys.GetUOM(Unit.KILOGRAM_PER_CU_METRE);
            UnitOfMeasure d2 = sys.CreateQuotientUOM(UnitType.DENSITY, "density", "lbm/gal", "", lbm, gal);

            q1 = new Quantity(10, v1);
            q2 = q1.Convert(v3);

            q1 = new Quantity(10, v1);
            q2 = q1.Convert(v2);

            q1 = new Quantity(10, d1);
            q2 = q1.Convert(d2);
        }