public void TryGetString_InvalidDicomFile()
        {
            var filename = Path.GetTempFileName();

            using (var writer = new StreamWriter(filename))
            {
                writer.WriteLine("Hello World!");
            }

            var dicomToolkit = new DicomToolkit();

            Assert.False(dicomToolkit.TryGetString(filename, DicomTag.SOPClassUID, out var _));
        }
        public void HasValidHeader_False()
        {
            var filename = Path.GetTempFileName();

            using (var writer = new StreamWriter(filename))
            {
                writer.WriteLine("Hello World!");
            }

            var dicomToolkit = new DicomToolkit();

            Assert.False(dicomToolkit.HasValidHeader(filename));
        }
        public void TryGetString_ValidFile()
        {
            var dicomFile   = new DicomFile();
            var expectedSop = DicomUIDGenerator.GenerateDerivedFromUUID();

            dicomFile.Dataset.Add(DicomTag.SOPInstanceUID, expectedSop);
            dicomFile.FileMetaInfo.TransferSyntax             = DicomTransferSyntax.ExplicitVRLittleEndian;
            dicomFile.FileMetaInfo.MediaStorageSOPInstanceUID = DicomUIDGenerator.GenerateDerivedFromUUID();
            dicomFile.FileMetaInfo.MediaStorageSOPClassUID    = DicomUIDGenerator.GenerateDerivedFromUUID();

            var dicomToolkit = new DicomToolkit();

            Assert.True(dicomToolkit.TryGetString(dicomFile, DicomTag.SOPInstanceUID, out var sopInstanceUId));
            Assert.Equal(expectedSop.UID, sopInstanceUId);
        }
        public void Open_ValidFile()
        {
            var filename  = Path.GetTempFileName();
            var dicomFile = new DicomFile();

            dicomFile.Dataset.Add(DicomTag.SOPInstanceUID, DicomUIDGenerator.GenerateDerivedFromUUID());
            dicomFile.FileMetaInfo.TransferSyntax             = DicomTransferSyntax.ExplicitVRLittleEndian;
            dicomFile.FileMetaInfo.MediaStorageSOPInstanceUID = DicomUIDGenerator.GenerateDerivedFromUUID();
            dicomFile.FileMetaInfo.MediaStorageSOPClassUID    = DicomUIDGenerator.GenerateDerivedFromUUID();

            dicomFile.Save(filename);

            var dicomToolkit = new DicomToolkit();

            dicomToolkit.Open(filename);
        }
        public void Save_ValidFile()
        {
            var filename    = Path.GetTempFileName();
            var dicomFile   = new DicomFile();
            var expectedSop = DicomUIDGenerator.GenerateDerivedFromUUID();

            dicomFile.Dataset.Add(DicomTag.SOPInstanceUID, expectedSop);
            dicomFile.FileMetaInfo.TransferSyntax             = DicomTransferSyntax.ExplicitVRLittleEndian;
            dicomFile.FileMetaInfo.MediaStorageSOPInstanceUID = DicomUIDGenerator.GenerateDerivedFromUUID();
            dicomFile.FileMetaInfo.MediaStorageSOPClassUID    = DicomUIDGenerator.GenerateDerivedFromUUID();

            var dicomToolkit = new DicomToolkit();

            dicomToolkit.Save(dicomFile, filename);

            var savedFile = dicomToolkit.Open(filename);

            Assert.NotNull(savedFile);

            Assert.Equal(expectedSop.UID, savedFile.Dataset.GetSingleValue <string>(DicomTag.SOPInstanceUID));
        }