public void SourceApplicationEntity_InvalidWhenAeTitleIsEmpty() { var sourceApplicationEntity = new SourceApplicationEntity(); sourceApplicationEntity.AeTitle = " "; Assert.False(sourceApplicationEntity.IsValid(new List <string>(), out _)); sourceApplicationEntity.AeTitle = "ABCDEFGHIJKLMNOPQRSTUVW"; Assert.False(sourceApplicationEntity.IsValid(new List <string>(), out _)); }
public async Task <ActionResult <string> > Create(SourceApplicationEntity item) { try { if (!item.IsValid(_dicomAdapterRepository.AsQueryable().Select(p => p.AeTitle), out IList <string> validationErrors)) { throw new ConfigurationException(string.Join(Environment.NewLine, validationErrors)); } await _dicomAdapterRepository.AddAsync(item); await _dicomAdapterRepository.SaveChangesAsync(); _logger.Log(LogLevel.Information, $"DICOM source added AE Title={item.AeTitle}, Host/IP={item.HostIp}."); return(CreatedAtAction(nameof(GetAeTitle), new { aeTitle = item.AeTitle }, item)); } catch (ConfigurationException ex) { return(Problem(title: "Validation error.", statusCode: (int)System.Net.HttpStatusCode.BadRequest, detail: ex.Message)); } catch (Exception ex) { _logger.Log(LogLevel.Error, ex, "Error adding new Source Application Entity."); return(Problem(title: "Error adding new Source Application Entity.", statusCode: (int)System.Net.HttpStatusCode.InternalServerError, detail: ex.Message)); } }
public void SourceApplicationEntity_Valid() { var sourceApplicationEntity = new SourceApplicationEntity(); sourceApplicationEntity.AeTitle = "AET"; sourceApplicationEntity.HostIp = "HOSTNAME"; Assert.True(sourceApplicationEntity.IsValid(new List <string>(), out _)); }
public void SourceApplicationEntity_InvalidWhenHostIsEmpty() { var sourceApplicationEntity = new SourceApplicationEntity(); sourceApplicationEntity.HostIp = " "; sourceApplicationEntity.AeTitle = "AET"; Assert.False(sourceApplicationEntity.IsValid(new List <string>(), out _)); }
public void SourceApplicationEntity_ShallThrowOnNull() { SourceApplicationEntity sourceApplicationEntity = null; Assert.Throws <ArgumentNullException>(() => sourceApplicationEntity.IsValid(new List <string>(), out _)); sourceApplicationEntity = new SourceApplicationEntity(); Assert.Throws <ArgumentNullException>(() => sourceApplicationEntity.IsValid(null, out _)); }
public void SourceApplicationEntity_InvalidIfAlreadyExists() { var sourceApplicationEntity = new SourceApplicationEntity(); sourceApplicationEntity.AeTitle = "AET"; sourceApplicationEntity.HostIp = "HOST"; Assert.False(sourceApplicationEntity.IsValid(new List <string>() { "AET" }, out _)); }