Exemplo n.º 1
0
		public void TestReadBulkData()
		{
			var path = Path.GetFullPath("test.txt");
			var bulkData = new BulkUriByteBuffer("file:" + path);

			Assert.Throws<InvalidOperationException>(() => bulkData.Data);
			Assert.Throws<InvalidOperationException>(() => bulkData.Size);

			bulkData.GetData();

			byte[] expected = File.ReadAllBytes("test.txt");

			Assert.True(bulkData.Data.SequenceEqual(expected));
			Assert.Equal(bulkData.Size, (uint)expected.Length);
		}
    public void BulkDataRead()
    {
      var path = Path.GetFullPath("test.txt");
      var bulkData = new BulkUriByteBuffer("file:" + path);

	    Assert.Throws<InvalidOperationException>(() => bulkData.Data);
	    Assert.Throws<InvalidOperationException>(() => bulkData.Size);

	    bulkData.GetData();

      var target = new DicomDataset();
      target.Add(new DicomOtherWord(DicomTag.PixelData, bulkData));
      var json = JsonConvert.SerializeObject(target, Formatting.Indented, new JsonDicomConverter());
      var reconstituated = JsonConvert.DeserializeObject<DicomDataset>(json, new JsonDicomConverter());
      Console.WriteLine(json);
      var json2 = JsonConvert.SerializeObject(reconstituated, Formatting.Indented, new JsonDicomConverter());
      Assert.Equal(json, json2);

	    ((BulkUriByteBuffer)reconstituated.Get<IByteBuffer>(DicomTag.PixelData)).GetData();

			Assert.True(ValueEquals(target, reconstituated));

      byte[] expectedPixelData = File.ReadAllBytes("test.txt");

      Assert.Equal(target.Get<IByteBuffer>(DicomTag.PixelData).Size, (uint)expectedPixelData.Length);
      Assert.True(target.Get<byte[]>(DicomTag.PixelData).SequenceEqual(expectedPixelData));
      Assert.Equal(reconstituated.Get<IByteBuffer>(DicomTag.PixelData).Size, (uint)expectedPixelData.Length);
      Assert.True(reconstituated.Get<byte[]>(DicomTag.PixelData).SequenceEqual(expectedPixelData));
    }