// manually arrange aspnet web api dummies and mocks
        private ResourceLinkFactory GenerateFullSut(ResourceLinkFactoryTestData data)
        {
            var config = new Mock <HttpConfiguration>().Object;
            var prefix = new RoutePrefixAttribute(data.Prefix);
            var controllerDescriptor =
                new TestControllerDescriptor(config, data.ControllerName, typeof(ApiController), prefix);
            var actionParameters =
                data.RouteValues.Keys.Aggregate(new Collection <HttpParameterDescriptor>(),
                                                (collection, parameterName) =>
            {
                var mockParameterDescriptor = new Mock <HttpParameterDescriptor>();
                mockParameterDescriptor.Setup(x => x.ParameterName).Returns(parameterName);
                collection.Add(mockParameterDescriptor.Object);
                return(collection);
            });
            var methodInfo = new TestMethodInfo(new RouteAttribute(data.Template)
            {
                Name = data.RouteName
            });
            var actionDescriptor = new TestActionDescriptor(controllerDescriptor, methodInfo, actionParameters);

            actionDescriptor.SupportedHttpMethods.Add(new HttpMethod(data.Method));

            // httpContext
            var request  = new HttpRequest("", data.BaseUrl, "");
            var response = new HttpResponse(new StringWriter());

            HttpContext.Current = new HttpContext(request, response);

            return(new ResourceLinkFactory(new[] { actionDescriptor }));
        }
        public void GetRouteUrl_WithValidParameters_ReturnsRouteUrlString(ResourceLinkFactoryTestData data)
        {
            var sut = GenerateFullSut(data);

            // act
            var actual = sut.GetRouteUrl(data.RouteName, data.RouteValues);

            // assert
            Assert.Equal(data.ExpectedUrl, actual, StringComparer.OrdinalIgnoreCase);
        }
        public void Create_WithValidParameters_ReturnsValidResourceLink(ResourceLinkFactoryTestData data)
        {
            // arrange
            var sut = GenerateFullSut(data);

            // act
            var resourceLink = sut.Create(data.RouteName, data.RouteValues);

            // assert
            Assert.IsType <ResourceLink>(resourceLink);
            Assert.NotNull(resourceLink);
            Assert.Equal(data.ExpectedUrl, resourceLink.Href, StringComparer.OrdinalIgnoreCase);
            Assert.Equal(data.RouteName, resourceLink.Rel, StringComparer.OrdinalIgnoreCase);
            Assert.Equal(data.Method, resourceLink.Method, StringComparer.OrdinalIgnoreCase);
        }