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); }
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); }
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()); }
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); } }
/// <summary> /// Returns a <see cref="T:System.String"/> that represents the /// current <see cref="PaperBallotIdentifier"/>. /// </summary> /// <returns> /// A <see cref="T:System.String"/> that represents the current /// <see cref="T:System.Object"/>. /// </returns> /// <externalUnit/> /// <revision revisor="dev11" date="12/24/2008" version="1.0.0.0"> /// Member Created /// </revision> /// <revision revisor="dev06" date="1/10/2009" version="1.0.0.0"> /// Updated so that the card identifer only shows the language and /// the code - this will need to be revised when we figure out how /// the mask will work /// </revision> /// <revision revisor="dev11" date="02/27/2009" version="1.0.8.1001"> /// the restriction for including only [language] and [code] has /// been removed /// </revision> public override string ToString() { string identifier = string.Empty, field; IdField[] fields = Enum.GetValues(typeof(IdField)) as IdField[]; for (int i = 0; i < fields.Length; i = i + 1) { if (this.fieldMap.ContainsKey(fields[i]) == true) { if (identifier.Length > 0) { identifier = identifier + SepMajor; } if (fields[i] == IdField.ControlBallot) { field = Convert.ToInt32( this.fieldMap[fields[i]]).ToString(); } else { field = this.fieldMap[fields[i]].ToString(); } identifier = identifier + EnumTextAttribute.GetText(fields[i]) + SepMinor + field; } } return(identifier); }
public void SetupEnumTests() { /* by calling GetText first, the hashtable is populated for the * tests */ EnumTest myEnum = EnumTest.EnumTypeWithTextAttribute; string myText = EnumTextAttribute.GetText(myEnum); }
public void TestSetup() { IdField[] fields = (IdField[])Enum.GetValues(typeof(IdField)); foreach (IdField field in fields) { EnumTextAttribute.GetText(field); } }
public void GetEnumText() { EnumTest myEnum = EnumTest.EnumTypeWithTextAttribute; string myText = EnumTextAttribute.GetText(myEnum); Assert.AreEqual("Testing Enum Text Attributes", myText); myEnum = EnumTest.EnumTypeWithNoTextAttribute; myText = EnumTextAttribute.GetText(myEnum); Assert.IsNull(myText); }
public void GetEnumValue() { string myText = "Testing Enum Text Attributes"; Enum myEnum = EnumTextAttribute.GetValue(myText); Assert.AreEqual(myEnum, EnumTest.EnumTypeWithTextAttribute); myEnum = EnumTextAttribute.GetValue("some text here"); Assert.IsNull(myEnum); myEnum = EnumTextAttribute.GetValue("Another text here"); Assert.IsNull(myEnum); EnumTextAttribute.GetText(EnumTest.EnumTypeWithAnotherText); myEnum = EnumTextAttribute.GetValue("Another text here"); Assert.IsNotNull(myEnum); Assert.AreNotEqual(myEnum, EnumTest.EnumTypeWithTextAttribute); Assert.AreNotEqual(myEnum, EnumTest.EnumTypeWithNoTextAttribute); Assert.AreEqual(myEnum, EnumTest.EnumTypeWithAnotherText); }