public void TestConstructors() { try { DicomAttributeDA attrib = new DicomAttributeDA(DicomTagDictionary.GetDicomTag(DicomTags.AccessionNumber)); Assert.Fail("Above statement should throw exception"); } catch (DicomException) { } CreateAttribute(); }
public void TestSet() { DicomImplementation.UnitTest = true; DicomAttributeDA attrib; #region Set from string attrib = CreateAttribute(); attrib.SetStringValue("20001012"); Assert.AreEqual(1, attrib.Count); Assert.IsTrue(attrib.StreamLength == "20001012".Length); attrib.SetStringValue("20001012\\20910214"); Assert.AreEqual(2, attrib.Count); Assert.IsTrue(attrib.StreamLength == "20001012\\20910294".Length + 1); attrib = CreateAttribute(); attrib.SetString(0, "20001012"); Assert.AreEqual(1, attrib.Count); Assert.IsTrue(attrib.StreamLength == "20001012".Length); attrib.SetString(1, "20001013"); Assert.AreEqual(2, attrib.Count); Assert.IsTrue(attrib.StreamLength == "20001012\\20910294".Length + 1); // special case: invalid format attrib = CreateAttribute(); try { attrib.SetString(0, "something"); Assert.Fail("Above statement should fail: invalid format"); } catch (DicomDataException e) { Assert.AreEqual(0, attrib.Count); Assert.AreEqual(0, attrib.StreamLength); } // special case: invalid date attrib = CreateAttribute(); try { attrib.SetString(0, "20071240"); Assert.Fail("Above statement should fail: invalid date"); } catch (DicomDataException e) { Assert.AreEqual(0, attrib.Count); Assert.AreEqual(0, attrib.StreamLength); } // special case: set null attrib = CreateAttribute(); attrib.SetString(0, null); Assert.AreEqual(1, attrib.Count); Assert.AreEqual(0, attrib.StreamLength); attrib.SetString(1, null); Assert.AreEqual(2, attrib.Count); Assert.AreEqual(2, attrib.StreamLength); // two empty values, separated by "\" and padded to even length // special case: set "" attrib = CreateAttribute(); attrib.SetString(0, ""); Assert.AreEqual(1, attrib.Count); Assert.AreEqual(0, attrib.StreamLength); attrib.SetString(1, ""); Assert.AreEqual(2, attrib.Count); Assert.AreEqual(2, attrib.StreamLength); // two empty values, separated by "\" and padded to even length // special case: invalid index attrib = CreateAttribute(); try { attrib.SetString(10, "20001012"); Assert.Fail("Above statement should fail: invalid index"); } catch (IndexOutOfRangeException e) { Assert.AreEqual(0, attrib.Count); Assert.AreEqual(0, attrib.StreamLength); } #endregion #region set from date time attrib = new DicomAttributeDA(DicomTagDictionary.GetDicomTag(DicomTags.ScheduledProcedureStepEndDate)); DateTime d1 = DateTime.Parse("2/16/1992", CultureInfo); attrib.SetDateTime(0, d1); Assert.AreEqual(1, attrib.Count); Assert.AreEqual(DateParser.DicomDateFormat.Length, attrib.StreamLength); DateTime d2 = DateTime.Parse("12/02/2000", CultureInfo); attrib.SetDateTime(1, d2); Assert.AreEqual(2, attrib.Count); Assert.AreEqual(DateParser.DicomDateFormat.Length * 2 + "\\".Length + 1, attrib.StreamLength); #endregion }
public DicomAttributeDA CreateAttribute() { DicomAttributeDA attrib = new DicomAttributeDA(DicomTagDictionary.GetDicomTag(DicomTags.ScheduledProcedureStepEndDate)); Assert.AreEqual(0, attrib.Count); Assert.AreEqual(0, attrib.StreamLength); return attrib; }