예제 #1
0
        public void ToStringFailsWithoutCodeAndLanguageFieldsTest()
        {
            string barcode = string.Format(
                "{0}{1}{2}{3}{4}{1}{5}",
                EnumTextAttribute.GetText(IdField.BallotTypeId),
                PaperBallotIdentifier.SepMinor,
                1,
                PaperBallotIdentifier.SepMajor,
                EnumTextAttribute.GetText(IdField.Precinct),
                2);

            PaperBallotIdentifier identifier =
                PaperBallotIdentifier.Parse(barcode);

            string toString = identifier.ToString(),
                   field1   = string.Format(
                "{0}{1}{2}",
                EnumTextAttribute.GetText(IdField.BallotTypeId),
                PaperBallotIdentifier.SepMinor,
                1),
                   field2 = string.Format(
                "{0}{1}{2}",
                EnumTextAttribute.GetText(IdField.Precinct),
                PaperBallotIdentifier.SepMinor,
                2);

            Assert.IsTrue(toString.IndexOf(field1) > -1);
            Assert.IsTrue(toString.IndexOf(field2) > -1);
        }
예제 #2
0
        public void ParseCatchesException()
        {
            string barcode = "badidentifier" + PaperBallotIdentifier.SepMinor
                             + "something";

            PaperBallotIdentifier identifier =
                PaperBallotIdentifier.Parse(barcode);

            // no fields
            Assert.IsFalse(identifier.HasFields);

            // 1 field ok, 1 not ok (discarded)
            barcode = string.Format(
                barcode + "{0}{1}{2}{3}",
                PaperBallotIdentifier.SepMajor,
                EnumTextAttribute.GetText(IdField.Precinct),
                PaperBallotIdentifier.SepMinor,
                1);
            identifier = PaperBallotIdentifier.Parse(barcode);
            Assert.IsTrue(identifier.HasFields);

            // no fields either
            barcode    = "sometext";
            identifier = PaperBallotIdentifier.Parse(barcode);
            Assert.IsFalse(identifier.HasFields);
        }
예제 #3
0
        public void ToStringTest()
        {
            string barcode = string.Format(
                "{0}{1}{2}{3}{4}{1}{5}",
                EnumTextAttribute.GetText(IdField.Language),
                PaperBallotIdentifier.SepMinor,
                1,
                PaperBallotIdentifier.SepMajor,
                EnumTextAttribute.GetText(IdField.Code),
                2);

            PaperBallotIdentifier identifier =
                PaperBallotIdentifier.Parse(barcode);

            string toString = identifier.ToString(),
                   field1   = string.Format(
                "{0}{1}{2}",
                EnumTextAttribute.GetText(IdField.Language),
                PaperBallotIdentifier.SepMinor,
                1),
                   field2 = string.Format(
                "{0}{1}{2}",
                EnumTextAttribute.GetText(IdField.Code),
                PaperBallotIdentifier.SepMinor,
                2);

            Assert.IsTrue(toString.IndexOf(field1) > -1);
            Assert.IsTrue(toString.IndexOf(field2) > -1);

            identifier = new PaperBallotIdentifier();
            Assert.AreEqual(string.Empty, identifier.ToString());
        }
예제 #4
0
        public void ParseOk_Get_SetGet()
        {
            IdField[] fields  = (IdField[])Enum.GetValues(typeof(IdField));
            string    barcode = string.Empty;

            // builds a barcode string with all fields
            for (int i = 0; i < fields.Length; i++)
            {
                if (i > 0)
                {
                    barcode += PaperBallotIdentifier.SepMajor;
                }

                barcode += EnumTextAttribute.GetText(fields[i])
                           + PaperBallotIdentifier.SepMinor + i;
            }

            // parse the barcode string and build a new paper ballot identifier
            // instance
            PaperBallotIdentifier objId = PaperBallotIdentifier.Parse(barcode);

            // get each field and verify it was properly parsed
            for (int i = 0; i < fields.Length; i++)
            {
                Assert.AreEqual(objId.Get(fields[i]), i.ToString());
            }

            // set a new value to each field and verify again
            for (int i = 0, val; i < fields.Length; i++)
            {
                val = fields.Length + i;
                objId.Set(fields[i], val);
                Assert.AreEqual(objId.Get(fields[i]), val);
            }
        }
예제 #5
0
        public void ToStringKeepsEnumTypeFieldOrderTest()
        {
            string barcode = "CRD:4|BLT:2|LNG:EN|PCT:4|BLS:9|CDE:10";
            PaperBallotIdentifier identifier =
                PaperBallotIdentifier.Parse(barcode);

            string toString = identifier.ToString();

            Assert.AreNotEqual(barcode, toString);
        }