public void TryExpandUriParameters_FromUri_Succeeds( string expectedPath, Type parameterType, string parameterName ) { // Arrange string finalPath; List <ApiParameterDescription> descriptions = new List <ApiParameterDescription>() { CreateApiParameterDescription(parameterType, parameterName), }; // Act bool isExpanded = ApiExplorer.TryExpandUriParameters( new HttpRoute(), new HttpParsedRoute(new List <PathSegment>()), descriptions, out finalPath ); // Assert Assert.True(isExpanded); Assert.Equal(expectedPath, finalPath); }
public void TryExpandUriParameters_CompositeParametersFromUri_Succeeds() { // Arrange string finalPath; const string expectedPath = "?id[0]={id[0]}&id[1]={id[1]}&property[0]={property[0]}&property[1]={property[1]}&name={name}"; List <ApiParameterDescription> descriptions = new List <ApiParameterDescription>() { CreateApiParameterDescription(typeof(int[]), "id"), CreateApiParameterDescription(typeof(ICollection <string>), "property"), CreateApiParameterDescription(typeof(string), "name"), }; // Act bool isExpanded = ApiExplorer.TryExpandUriParameters( new HttpRoute(), new HttpParsedRoute(new List <PathSegment>()), descriptions, out finalPath ); // Assert Assert.True(isExpanded); Assert.Equal(expectedPath, finalPath); }
public void TryExpandUriParameters_EnsureNoKeyConflicts() { // This test ensures that keys adding to parameterValuesForRoute are case-insensitive // and would not cause any exeception if it already has the key. So set up two // ApiParameterDescription instances, one with "id" and another with "Id". Act the // method and assert that no exception occurs and the output is correct. // Arrange string expectedExpandedRouteTemplate = "?id={id}"; string expandedRouteTemplate; Mock <HttpParameterDescriptor> parameterDescriptorMock = new Mock <HttpParameterDescriptor>(); parameterDescriptorMock.SetupGet(p => p.ParameterType).Returns(typeof(ClassWithId)); List <ApiParameterDescription> descriptions = new List <ApiParameterDescription>() { new ApiParameterDescription() { Source = ApiParameterSource.FromUri, Name = "id" }, new ApiParameterDescription() { Source = ApiParameterSource.FromUri, ParameterDescriptor = parameterDescriptorMock.Object }, }; // Act bool isExpanded = ApiExplorer.TryExpandUriParameters( new HttpRoute(), new HttpParsedRoute(new List <PathSegment>()), descriptions, out expandedRouteTemplate ); // Assert Assert.True(isExpanded); Assert.Equal(expectedExpandedRouteTemplate, expandedRouteTemplate); }