Пример #1
0
 public void TestDuplicateConversions()
 {
     XmlConversionTable xmlConversion = new XmlInitTable().TableInit("Converter.TestCases.LengthDuplicateConversions.xml");
     Conversion meters = new Conversion(1, 10, (ConversionTable)xmlConversion.ConversionTable, (Unit)xmlConversion.Unit);
     var result = meters.Convert(2);
     Assert.AreEqual("1000 cm", result.Value + " " + result.UnitSymbol);
 }
Пример #2
0
 public void TestbigNumberToConvert()
 {
     XmlConversionTable xmlConversion = new XmlInitTable().TableInit("Converter.Configs.InformationUnits.xml");
     Conversion meters = new Conversion(1, 12345678901234567890, (ConversionTable)xmlConversion.ConversionTable, (Unit)xmlConversion.Unit);
     var result = meters.Convert(10);
     Assert.AreEqual("1.276513E-06 YB", result.Value + " " + result.UnitSymbol);
 }
Пример #3
0
 public void TestLengthConversionFromImplicitInit()
 {
     XmlConversionTable xmlConversion = new XmlInitTable().LengthTable;
     Conversion conversion = new Conversion(1, 100, (ConversionTable)xmlConversion.ConversionTable, (Unit)xmlConversion.Unit);
     Assert.AreEqual(conversion.UnitName, "Meter");
     Assert.AreEqual(conversion.UnitPlural, "Meters");
     Assert.AreEqual(conversion.UnitSymbol, "m");
     var result = conversion.Convert(3);
     Assert.AreEqual("10000cm", result.Value + result.UnitSymbol);
 }
Пример #4
0
 public void TestCreationFromFileImplicit()
 {
     XmlConversionTable xmlConversion = new XmlInitTable().InformationTable;
     Conversion conversion = new Conversion(1, 100, (ConversionTable)xmlConversion.ConversionTable, (Unit)xmlConversion.Unit);
     Assert.AreEqual(conversion.UnitName, "bit");
     Assert.AreEqual(conversion.UnitPlural, "bits");
     Assert.AreEqual(conversion.UnitSymbol, "b");
     var result = conversion.Convert(3);
     Assert.AreEqual("0.01220703 KB", result.Value + " " + result.UnitSymbol);
 }
Пример #5
0
        static void Main(string[] args)
        {
            string fromFileName = string.Empty;
            string toFileName = string.Empty;

            args.GetCommandLineSwitch(Constants.INFILE_SWITCH, ref fromFileName);
            args.GetCommandLineSwitch(Constants.OUTFILE_SWITCH, ref toFileName);
            try
            {
                if (fromFileName.Length > 0 && toFileName.Length > 0)
                {
                    long val = long.Parse(args[0]);
                    int fromVal = int.Parse(fromFileName);
                    int toVal = int.Parse(toFileName);
                    XmlConversionTable table = new XmlInitTable().LengthTable;
                    //ConversionTable table = InitTable.LengthTableInit("Converter.TestCases.LengthDuplicateUnits.xml");
                    Conversion meters = new Conversion(fromVal, val, (ConversionTable)table.ConversionTable, (Unit)table.Unit);
                    Conversion result = meters.Convert(toVal);
                    if(val > 1)
                    Console.WriteLine("ConversionTable from {0} to {1} is {2}", args[0] + " " + result.Unit.GetUnitPlural(fromVal), result.UnitPlural, result.Value + " " + result.UnitSymbol);
                    else
                    {
                        Console.WriteLine("ConversionTable from {0} to {1} is {2}", args[0] + " " + result.Unit.GetUnitName(fromVal), result.UnitName, result.Value + " " + result.UnitSymbol);
                    }
                    Console.ReadLine();
                }
                else
                {
                    CommandLineHelper.ShowUsage();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.ReadLine();
            }
        }
Пример #6
0
 public void TestWithZeroFactorValue()
 {
     XmlConversionTable xmlConversion = new XmlInitTable().TableInit("Converter.TestCases.LengthUnits0factor.xml");
     new LinearConverter(0, 12);
 }
Пример #7
0
 public void TestWithWrongUnitTagParameter()
 {
     XmlConversionTable xmlConversion = new XmlInitTable().TableInit("Converter.TestCases.LengthUnitsTagFail.xml");
     Conversion meters = new Conversion(1, 10, (ConversionTable)xmlConversion.ConversionTable, (Unit)xmlConversion.Unit);
 }
Пример #8
0
 public void TestNotExistingUnitCall()
 {
     XmlConversionTable xmlConversion = new XmlInitTable().TableInit("Converter.TestCases.LengthUnits.xml");
     Conversion meters = new Conversion(2, 100, (ConversionTable)xmlConversion.ConversionTable, (Unit)xmlConversion.Unit);
     var unitname = meters.UnitName;
 }
Пример #9
0
 public void TestNotAvailableConversion()
 {
     XmlConversionTable xmlConversion = new XmlInitTable().TableInit("Converter.TestCases.LengthUnits.xml");
     Conversion meters = new Conversion(2, 100, (ConversionTable)xmlConversion.ConversionTable, (Unit)xmlConversion.Unit);
     var result = meters.Convert(9);
 }
Пример #10
0
 public void TestDuplicateUnits()
 {
     XmlConversionTable xmlConversion = new XmlInitTable().TableInit("Converter.TestCases.LengthDuplicateUnits.xml");
     Conversion meters = new Conversion(1, 10, (ConversionTable)xmlConversion.ConversionTable, (Unit)xmlConversion.Unit);
 }