public void ValidatePart_InvalidContentSize() { // Arrange Application app = TestDataUtil.GetApplication("ttd", "events"); string partName = "hundebilde"; string contentType = "application/pdf"; using Stream stream = new MemoryStream(); RequestPart part = new RequestPart { Name = partName, ContentType = contentType, Stream = stream }; string expectedErrorMessage = $"The multipart section named {partName} has no data. Cannot process empty part."; RequestPartValidator sut = new RequestPartValidator(app); // Act string actual = sut.ValidatePart(part); // Assert Assert.Equal(expectedErrorMessage, actual); }
public void ValidatePartTest_ValidElement_ReturnsNull() { // Arrange Application application = new Application { ElementTypes = new List <ElementType> { new ElementType { Id = "default", AllowedContentType = new List <string> { "application/xml" }, MaxCount = 1 } } }; RequestPartValidator target = new RequestPartValidator(application); RequestPart part = new RequestPart { Name = "default", ContentType = "application/xml", Stream = new MemoryStream(Encoding.UTF8.GetBytes("viktig melding")) }; // Act string error = target.ValidatePart(part); // Assert Assert.Null(error); }
public void ValidatePart_MissingContentType() { // Arrange Application app = TestDataUtil.GetApplication("ttd", "events"); string partName = "hundebilde"; RequestPart part = new RequestPart { Name = partName }; string expectedErrorMessage = $"The multipart section named {partName} is missing Content-Type."; RequestPartValidator sut = new RequestPartValidator(app); // Act string actual = sut.ValidatePart(part); // Assert Assert.Equal(expectedErrorMessage, actual); }
public void ValidatePart_InvalidDataType() { // Arrange Application app = TestDataUtil.GetApplication("ttd", "events"); string partName = "kattebilde"; RequestPart part = new RequestPart { Name = partName }; string expectedErrorMessage = $"Multipart section named, '{partName}' does not correspond to an element type in application metadata"; RequestPartValidator sut = new RequestPartValidator(app); // Act string actual = sut.ValidatePart(part); // Assert Assert.Equal(expectedErrorMessage, actual); }
public void ValidatePartTest_InstanceElementWithWrongContentType_ReturnsError() { // Arrange Application application = new Application(); RequestPartValidator target = new RequestPartValidator(application); RequestPart part = new RequestPart { Name = "instance", ContentType = "application/xml", Stream = new MemoryStream(Encoding.UTF8.GetBytes("viktig melding")) // Content isn't validated atm. }; // Act string error = target.ValidatePart(part); // Assert Assert.Contains("Expecting 'application/json'", error); }
public void ValidatePartTest_ValidInstanceElement_ReturnsNull() { // Arrange Application application = new Application(); RequestPartValidator target = new RequestPartValidator(application); RequestPart part = new RequestPart { Name = "instance", ContentType = "application/json", Stream = new MemoryStream(Encoding.UTF8.GetBytes("viktig melding")) // Content isn't validated atm. }; // Act string error = target.ValidatePart(part); // Assert Assert.Null(error); }
public void ValidatePart_ValidateInstance_ValidInstance() { // Arrange Application app = TestDataUtil.GetApplication("ttd", "events"); string partName = "instance"; string contentType = "application/json"; RequestPart part = new RequestPart { Name = partName, ContentType = contentType, }; RequestPartValidator sut = new RequestPartValidator(app); // Act var actual = sut.ValidatePart(part); // Assert Assert.Null(actual); }
public void ValidatePart_ValidateInstance_InvalidContentType() { // Arrange Application app = TestDataUtil.GetApplication("ttd", "events"); string partName = "instance"; string contentType = "application/pdf"; RequestPart part = new RequestPart { Name = partName, ContentType = contentType, }; string expectedErrorMessage = $"Unexpected Content-Type '{contentType}' of embedded instance template. Expecting 'application/json'"; RequestPartValidator sut = new RequestPartValidator(app); // Act string actual = sut.ValidatePart(part); // Assert Assert.Equal(expectedErrorMessage, actual); }
public void ValidatePart_InvalidContentType() { // Arrange Application app = TestDataUtil.GetApplication("ttd", "events"); string partName = "hundebilde"; string dataTypeId = "hundebilde"; string contentType = "application/xml"; RequestPart part = new RequestPart { Name = partName, ContentType = contentType }; string expectedErrorMessage = $"The multipart section named {partName} has a Content-Type '{contentType}' which is invalid for element type '{dataTypeId}'"; RequestPartValidator sut = new RequestPartValidator(app); // Act string actual = sut.ValidatePart(part); // Assert Assert.Equal(expectedErrorMessage, actual); }
public void ValidatePart_ExceedsAllowedContentSize() { // Arrange Application app = TestDataUtil.GetApplication("ttd", "events"); string partName = "hundebilde"; string dataTypeId = "hundebilde"; string contentType = "application/pdf"; RequestPart part = new RequestPart { Name = partName, ContentType = contentType, FileSize = 1337 * 1024 * 1024 }; string expectedErrorMessage = $"The multipart section named {partName} exceeds the size limit of element type '{dataTypeId}'"; RequestPartValidator sut = new RequestPartValidator(app); // Act string actual = sut.ValidatePart(part); // Assert Assert.Equal(expectedErrorMessage, actual); }