public static IEnumerable <object[]> GetTestData() { // x is null & y is null yield return(new object[] { null, null, 0 }); // x is null yield return(new object[] { null, AcceptHeaderHelpers.CreateAcceptHeader(), -1 }); // y is null yield return(new object[] { AcceptHeaderHelpers.CreateAcceptHeader(), null, 1 }); // x.quality is null & y.quality is null yield return(new object[] { AcceptHeaderHelpers.CreateAcceptHeader(quality: null), AcceptHeaderHelpers.CreateAcceptHeader(quality: null), 0 }); // x.quality is null yield return(new object[] { AcceptHeaderHelpers.CreateAcceptHeader(quality: null), AcceptHeaderHelpers.CreateAcceptHeader(quality: 0.5), 1 }); yield return(new object[] { AcceptHeaderHelpers.CreateAcceptHeader(quality: null), AcceptHeaderHelpers.CreateAcceptHeader(quality: 1), 0 }); // y.quality is null yield return(new object[] { AcceptHeaderHelpers.CreateAcceptHeader(quality: 0.5), AcceptHeaderHelpers.CreateAcceptHeader(quality: null), -1 }); yield return(new object[] { AcceptHeaderHelpers.CreateAcceptHeader(quality: 1), AcceptHeaderHelpers.CreateAcceptHeader(quality: null), 0 }); // x.quality>y.quality yield return(new object[] { AcceptHeaderHelpers.CreateAcceptHeader(quality: 0.6), AcceptHeaderHelpers.CreateAcceptHeader(quality: 0.5), 1 }); // x.quality<y.quality yield return(new object[] { AcceptHeaderHelpers.CreateAcceptHeader(quality: 0.5), AcceptHeaderHelpers.CreateAcceptHeader(quality: 0.6), -1 }); // x.quality=y.quality yield return(new object[] { AcceptHeaderHelpers.CreateAcceptHeader(quality: 0), AcceptHeaderHelpers.CreateAcceptHeader(quality: 0), 0 }); }
public void GivenDescriptorsIsNotNull_WhenConstructAcceptHeaderDescriptors_ThenShouldSucceed() { AcceptHeader acceptHeader = AcceptHeaderHelpers.CreateAcceptHeader(); AcceptHeaderDescriptor descriptor = AcceptHeaderDescriptorHelpers.CreateAcceptHeaderDescriptor(acceptHeader, match: true); AcceptHeaderDescriptors descriptors = new AcceptHeaderDescriptors(descriptor); Assert.Single(descriptors.Descriptors); Assert.Same(descriptor, descriptors.Descriptors.First()); }
public void GivenAcceptHeaders_WhenNoMatch_ThenShouldReturnFalse() { AcceptHeader acceptHeader = AcceptHeaderHelpers.CreateAcceptHeader(); AcceptHeaderDescriptor notMatchDescriptor1 = AcceptHeaderDescriptorHelpers.CreateAcceptHeaderDescriptor(acceptHeader, match: false); AcceptHeaderDescriptor notMatchDescriptor2 = AcceptHeaderDescriptorHelpers.CreateAcceptHeaderDescriptor(acceptHeader, match: false); AcceptHeaderDescriptors acceptHeaderDescriptors = new AcceptHeaderDescriptors(notMatchDescriptor1, notMatchDescriptor2); AcceptHeaderDescriptor result; string transferSyntax; Assert.False(acceptHeaderDescriptors.TryGetMatchedDescriptor(acceptHeader, out result, out transferSyntax)); }
private (AcceptHeader, AcceptHeaderDescriptor) CreateAcceptHeaderAndDescriptorForPayloadType(PayloadTypes descriptorPayloadType, PayloadTypes acceptHeaderPayloadType) { AcceptHeader acceptHeader = AcceptHeaderHelpers.CreateAcceptHeader(payloadType: acceptHeaderPayloadType); AcceptHeaderDescriptor descriptor = new AcceptHeaderDescriptor( payloadType: descriptorPayloadType, mediaType: acceptHeader.MediaType.Value, isTransferSyntaxMandatory: true, transferSyntaxWhenMissing: string.Empty, acceptableTransferSyntaxes: new HashSet <string>() { acceptHeader.TransferSyntax.Value }); return(acceptHeader, descriptor); }
private (AcceptHeader, AcceptHeaderDescriptor) CreateAcceptHeaderAndDescriptorForTransferSyntaxMandatory(bool isTransferSyntaxMandatory, string transferSyntaxWhenMissing, string acceptHeaderTransferSyntax) { AcceptHeader acceptHeader = AcceptHeaderHelpers.CreateAcceptHeader(transferSyntax: acceptHeaderTransferSyntax); AcceptHeaderDescriptor descriptor = new AcceptHeaderDescriptor( payloadType: acceptHeader.PayloadType, mediaType: acceptHeader.MediaType.Value, isTransferSyntaxMandatory: isTransferSyntaxMandatory, transferSyntaxWhenMissing: transferSyntaxWhenMissing, acceptableTransferSyntaxes: new HashSet <string>() { acceptHeader.TransferSyntax.Value }); return(acceptHeader, descriptor); }
public void GivenAcceptHeaders_WhenSeveralMatchAndOthersNot_ThenShouldReturnFirstMatched() { AcceptHeader acceptHeader = AcceptHeaderHelpers.CreateAcceptHeader(); AcceptHeaderDescriptor matchDescriptor1 = AcceptHeaderDescriptorHelpers.CreateAcceptHeaderDescriptor(acceptHeader, match: true); AcceptHeaderDescriptor matchDescriptor2 = AcceptHeaderDescriptorHelpers.CreateAcceptHeaderDescriptor(acceptHeader, match: true); AcceptHeaderDescriptor notMatchDescriptor = AcceptHeaderDescriptorHelpers.CreateAcceptHeaderDescriptor(acceptHeader, match: false); AcceptHeaderDescriptors acceptHeaderDescriptors = new AcceptHeaderDescriptors(matchDescriptor1, matchDescriptor2, notMatchDescriptor); AcceptHeaderDescriptor result; string transferSyntax; Assert.True(acceptHeaderDescriptors.TryGetMatchedDescriptor(acceptHeader, out result, out transferSyntax)); Assert.Same(result, matchDescriptor1); // Actual transferSyntax should be from matchDescriptor1 string expectedTransferSyntax; matchDescriptor1.IsAcceptable(acceptHeader, out expectedTransferSyntax); Assert.Equal(transferSyntax, expectedTransferSyntax); }