|
| 1 | +/* |
| 2 | + * Copyright 2021-2023 MONAI Consortium |
| 3 | + * Copyright 2019-2021 NVIDIA Corporation |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +using System; |
| 19 | +using System.Collections.Generic; |
| 20 | +using Newtonsoft.Json; |
| 21 | +using Xunit; |
| 22 | + |
| 23 | +namespace Monai.Deploy.InformaticsGateway.Api.Test |
| 24 | +{ |
| 25 | + public class Hl7ApplicationConfigEntityTest |
| 26 | + { |
| 27 | + [Fact] |
| 28 | + public void GivenAHl7ApplicationConfigEntity_WhenSendingIdKeyIsNotSet_ExpectValidateToReturnError() |
| 29 | + { |
| 30 | + var entity = new Hl7ApplicationConfigEntity |
| 31 | + { |
| 32 | + SendingId = new KeyValuePair<string, string>(string.Empty, "SendingIdValue"), |
| 33 | + DataLink = new KeyValuePair<string, DataLinkType>("DataLinkKey", DataLinkType.PatientId), |
| 34 | + DataMapping = StringKeyValuePair.FromDictionary(new Dictionary<string, string> { { "DataMappingKey", "DataMappingValue" } }) |
| 35 | + }; |
| 36 | + |
| 37 | + var errors = entity.Validate(); |
| 38 | + |
| 39 | + Assert.NotEmpty(errors); |
| 40 | + Assert.Contains($"{nameof(entity.SendingId.Key)} is missing.", errors); |
| 41 | + } |
| 42 | + |
| 43 | + [Fact] |
| 44 | + public void GivenAHl7ApplicationConfigEntity_WhenSendingIdValueIsNotSet_ExpectValidateToReturnError() |
| 45 | + { |
| 46 | + var entity = new Hl7ApplicationConfigEntity |
| 47 | + { |
| 48 | + SendingId = new KeyValuePair<string, string>("SendingIdKey", string.Empty), |
| 49 | + DataLink = new KeyValuePair<string, DataLinkType>("DataLinkKey", DataLinkType.PatientId), |
| 50 | + DataMapping = StringKeyValuePair.FromDictionary(new Dictionary<string, string> { { "DataMappingKey", "DataMappingValue" } }) |
| 51 | + }; |
| 52 | + |
| 53 | + var errors = entity.Validate(); |
| 54 | + |
| 55 | + Assert.NotEmpty(errors); |
| 56 | + Assert.Contains($"{nameof(entity.SendingId.Value)} is missing.", errors); |
| 57 | + } |
| 58 | + |
| 59 | + [Fact] |
| 60 | + public void GivenAHl7ApplicationConfigEntity_WhenDataLinkKeyIsNotSet_ExpectValidateToReturnError() |
| 61 | + { |
| 62 | + var entity = new Hl7ApplicationConfigEntity |
| 63 | + { |
| 64 | + SendingId = new KeyValuePair<string, string>("SendingIdKey", "SendingIdValue"), |
| 65 | + DataLink = new KeyValuePair<string, DataLinkType>(string.Empty, DataLinkType.PatientId), |
| 66 | + DataMapping = StringKeyValuePair.FromDictionary(new Dictionary<string, string> { { "DataMappingKey", "DataMappingValue" } }) |
| 67 | + }; |
| 68 | + |
| 69 | + var errors = entity.Validate(); |
| 70 | + |
| 71 | + Assert.NotEmpty(errors); |
| 72 | + Assert.Contains($"{nameof(entity.DataLink.Key)} is missing.", errors); |
| 73 | + } |
| 74 | + |
| 75 | + [Fact] |
| 76 | + public void GivenAHl7ApplicationConfigEntity_WhenDataMappingIsNotSet_ExpectValidateToReturnError() |
| 77 | + { |
| 78 | + var entity = new Hl7ApplicationConfigEntity |
| 79 | + { |
| 80 | + SendingId = new KeyValuePair<string, string>("SendingIdKey", "SendingIdValue"), |
| 81 | + DataLink = new KeyValuePair<string, DataLinkType>("DataLinkKey", DataLinkType.PatientId), |
| 82 | + DataMapping = StringKeyValuePair.FromDictionary(new Dictionary<string, string>()) |
| 83 | + }; |
| 84 | + |
| 85 | + var errors = entity.Validate(); |
| 86 | + |
| 87 | + Assert.NotEmpty(errors); |
| 88 | + Assert.Contains($"{nameof(entity.DataMapping)} is missing values.", errors); |
| 89 | + } |
| 90 | + |
| 91 | + [Fact] |
| 92 | + public void GivenAHl7ApplicationConfigEntity_WhenDataMappingKeyIsNotSet_ExpectValidateToReturnError() |
| 93 | + { |
| 94 | + var entity = new Hl7ApplicationConfigEntity |
| 95 | + { |
| 96 | + SendingId = new KeyValuePair<string, string>("SendingIdKey", "SendingIdValue"), |
| 97 | + DataLink = new KeyValuePair<string, DataLinkType>("DataLinkKey", DataLinkType.PatientId), |
| 98 | + DataMapping = StringKeyValuePair.FromDictionary(new Dictionary<string, string> { { string.Empty, "DataMappingValue" } }) |
| 99 | + }; |
| 100 | + |
| 101 | + var errors = entity.Validate(); |
| 102 | + |
| 103 | + Assert.NotEmpty(errors); |
| 104 | + Assert.Contains($"{nameof(entity.DataMapping)} is missing a name at index 0.", errors); |
| 105 | + } |
| 106 | + |
| 107 | + [Fact] |
| 108 | + public void GivenAHl7ApplicationConfigEntity_WhenDataMappingValueIsNotSet_ExpectValidateToReturnError() |
| 109 | + { |
| 110 | + var entity = new Hl7ApplicationConfigEntity |
| 111 | + { |
| 112 | + SendingId = new KeyValuePair<string, string>("SendingIdKey", "SendingIdValue"), |
| 113 | + DataLink = new KeyValuePair<string, DataLinkType>("DataLinkKey", DataLinkType.PatientId), |
| 114 | + DataMapping = StringKeyValuePair.FromDictionary(new Dictionary<string, string> { { "DataMappingKey", string.Empty } }) |
| 115 | + }; |
| 116 | + |
| 117 | + var errors = entity.Validate(); |
| 118 | + |
| 119 | + Assert.NotEmpty(errors); |
| 120 | + Assert.Contains($"{nameof(entity.DataMapping)} (DataMappingKey) @ index 0 is not a valid DICOM Tag.", errors); |
| 121 | + } |
| 122 | + |
| 123 | + [Fact] |
| 124 | + public void GivenAHl7ApplicationConfigEntity_WhenDataMappingValueIsNotAValidDicomTag_ExpectValidateToReturnError() |
| 125 | + { |
| 126 | + var entity = new Hl7ApplicationConfigEntity |
| 127 | + { |
| 128 | + SendingId = new KeyValuePair<string, string>("SendingIdKey", "SendingIdValue"), |
| 129 | + DataLink = new KeyValuePair<string, DataLinkType>("DataLinkKey", DataLinkType.PatientId), |
| 130 | + DataMapping = StringKeyValuePair.FromDictionary(new Dictionary<string, string> { { "DataMappingKey", "DataMappingValue" } }) |
| 131 | + }; |
| 132 | + |
| 133 | + var errors = entity.Validate(); |
| 134 | + |
| 135 | + Assert.NotEmpty(errors); |
| 136 | + Assert.Contains("DataMapping.Value is not a valid DICOM Tag. Error parsing DICOM tag ['DataMappingValue']", errors); |
| 137 | + } |
| 138 | + |
| 139 | + [Fact] |
| 140 | + public void GivenAHl7ApplicationConfigEntity_WhenDataMappingValueIsAValidDicomTag_ExpectValidateToReturnNoErrors() |
| 141 | + { |
| 142 | + var entity = new Hl7ApplicationConfigEntity |
| 143 | + { |
| 144 | + SendingId = new KeyValuePair<string, string>("SendingIdKey", "SendingIdValue"), |
| 145 | + DataLink = new KeyValuePair<string, DataLinkType>("DataLinkKey", DataLinkType.PatientId), |
| 146 | + DataMapping = StringKeyValuePair.FromDictionary(new Dictionary<string, string> { { "DataMappingKey", "0020,000D" } }) |
| 147 | + }; |
| 148 | + |
| 149 | + var errors = entity.Validate(); |
| 150 | + |
| 151 | + Assert.Empty(errors); |
| 152 | + } |
| 153 | + |
| 154 | + [Fact] |
| 155 | + public void GivenAHl7ApplicationConfigEntity_WhenDataMappingValueIsEmpty_ExpectValidateToReturnError() |
| 156 | + { |
| 157 | + var entity = new Hl7ApplicationConfigEntity |
| 158 | + { |
| 159 | + SendingId = new KeyValuePair<string, string>("SendingIdKey", "SendingIdValue"), |
| 160 | + DataLink = new KeyValuePair<string, DataLinkType>("DataLinkKey", DataLinkType.PatientId), |
| 161 | + DataMapping = StringKeyValuePair.FromDictionary(new Dictionary<string, string> { { "DataMappingKey", "" } }) |
| 162 | + }; |
| 163 | + |
| 164 | + var errors = entity.Validate(); |
| 165 | + |
| 166 | + Assert.NotEmpty(errors); |
| 167 | + Assert.Contains($"{nameof(entity.DataMapping)} (DataMappingKey) @ index 0 is not a valid DICOM Tag.", errors); |
| 168 | + } |
| 169 | + |
| 170 | + [Fact] |
| 171 | + public void GivenAHl7ApplicationConfigEntity_WhenToStringIsCalled_ExpectToStringToReturnExpectedValue() |
| 172 | + { |
| 173 | + var guid = Guid.NewGuid(); |
| 174 | + var dt = DateTime.UtcNow; |
| 175 | + var entity = new Hl7ApplicationConfigEntity |
| 176 | + { |
| 177 | + Id = guid, |
| 178 | + DateTimeCreated = dt, |
| 179 | + SendingId = new KeyValuePair<string, string>("SendingIdKey", "SendingIdValue"), |
| 180 | + DataLink = new KeyValuePair<string, DataLinkType>("DataLinkKey", DataLinkType.PatientId), |
| 181 | + DataMapping = StringKeyValuePair.FromDictionary(new Dictionary<string, string> { { "DataMappingKey", "0020,000D" } }) |
| 182 | + }; |
| 183 | + |
| 184 | + var result = entity.ToString(); |
| 185 | + |
| 186 | + var expected = JsonConvert.SerializeObject(entity); |
| 187 | + Assert.Equal(expected, result); |
| 188 | + } |
| 189 | + } |
| 190 | +} |
0 commit comments