Example #1
0
        public void it_should_handle_Create_request_correctly()
        {
            var person = new Person()
            {
                Key = 1
            };
            string callUri;
            var    controllerDescription = new ControllerInfo <CrudController>(
                null,
                (HttpUrl)UrlParser.Parse("api/test"),
                Controller.GetType().GetMethod("Get").ToOperationInfo("api/test", Verb.GET, out callUri, person.Key),
                Controller.GetType().GetMethod("Create").ToOperationInfo("api/test", Verb.POST, out callUri, person));

            ControllerDescriptionBuilder.As <IControllerDescriptionBuilder>().Setup(instance => instance.BuildDescriptor()).Returns(controllerDescription);

            var result = Composer.ComposeResponse(CreateRequestMapping("Create", Verb.POST, person), person.Key, person);

            result.Should().BeOfType <StringResponseInfo>();
            result.Status.Should().Be(HttpStatusCode.Created);
            result.Headers.Should().ContainKey("Location").WhichValue.Should().Be("/api/test/" + person.Key);
            Converter.Verify(instance => instance.ConvertFrom(person.Key, It.IsAny <IResponseInfo>()), Times.Never);
        }