public void TestFromBody() { var sub = new DefaultRouteValueSubstitution(); Expression <Func <ControllerSample, ModelSample, ModelSample> > lambda = (c, m) => c.ControllerMethodPut(m.Id, m); var methodCallExpression = (MethodCallExpression)lambda.Body; var apiExplorerMoq = new Mock <IApiExplorer>(); apiExplorerMoq.Setup(_ => _.ApiDescriptions).Returns(new Collection <ApiDescription>() { new ApiDescription() { HttpMethod = HttpMethod.Get } }); var mr = new MappingRule(methodCallExpression, apiExplorerMoq.Object); var payload = _fixture.CreateAnonymous <ModelSample>(); var fields = ActionFieldsGenerator.Generate(mr, apiExplorerMoq.Object.ApiDescriptions[0], payload); Assume.That(fields, Is.Not.Null); var names = fields.ConvertAll(f => f.FieldName); Assume.That(names, Is.EquivalentTo(new[] { "Id", "Name", "Price", "email_address" })); var types = fields.ConvertAll(f => f.FieldType); Assume.That(types, Is.EqualTo(new object[] { null, null, null, "email" })); var values = fields.ConvertAll(f => f.FieldValue); Assume.That(values, Is.EqualTo(new object[] { payload.Id.ToString(), payload.Name, payload.Price.ToString(), payload.EMailAddress })); }
public void TestNotFromBodyNotGet() { var sub = new DefaultRouteValueSubstitution(); Expression <Func <ControllerSample, ModelSample, ModelSample> > lambda = (c, m) => c.ControllerMethod(m.Id, m.Name, QueryParameter.Is <string>(), QueryParameter.Is <int>()); var methodCallExpression = (MethodCallExpression)lambda.Body; var apiExplorerMoq = new Mock <IApiExplorer>(); apiExplorerMoq.Setup(_ => _.ApiDescriptions).Returns(new Collection <ApiDescription>() { new ApiDescription() { } }); var mr = new MappingRule(methodCallExpression, apiExplorerMoq.Object); var payload = _fixture.CreateAnonymous <ModelSample>(); var fields = ActionFieldsGenerator.Generate(mr, apiExplorerMoq.Object.ApiDescriptions[0], payload); Assume.That(fields, Is.Null); }