本文整理汇总了C#中ApiController类的典型用法代码示例。如果您正苦于以下问题:C# ApiController类的具体用法?C# ApiController怎么用?C# ApiController使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ApiController类属于命名空间,在下文中一共展示了ApiController类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetUserEntityAsync
private static async Task<User> GetUserEntityAsync(ApiController controller)
{
ClaimsPrincipal principal = (ClaimsPrincipal)controller.User;
string provider = principal.FindFirst("http://schemas.microsoft.com/identity/claims/identityprovider").Value;
ProviderCredentials creds;
if (string.Equals(provider, "microsoftaccount", StringComparison.OrdinalIgnoreCase))
{
creds = await controller.User.GetAppServiceIdentityAsync<MicrosoftAccountCredentials>(controller.Request);
}
//else if (string.Equals(provider, "facebook", StringComparison.OrdinalIgnoreCase))
//{
// creds = await controller.User.GetAppServiceIdentityAsync<FacebookCredentials>(controller.Request);
//}
//else if (string.Equals(provider, "google", StringComparison.OrdinalIgnoreCase))
//{
// creds = await controller.User.GetAppServiceIdentityAsync<GoogleCredentials>(controller.Request);
//}
//else if (string.Equals(provider, "twitter", StringComparison.OrdinalIgnoreCase))
//{
// creds = await controller.User.GetAppServiceIdentityAsync<TwitterCredentials>(controller.Request);
//}
else
{
throw new NotImplementedException();
}
return GetUserEntity(creds);
}
示例2: DefaultControllerBehaviorConfig
public DefaultControllerBehaviorConfig(ApiController controller)
{
var request = new HttpRequestMessage();
var cfg = new HttpConfiguration();
request.Properties[HttpPropertyKeys.HttpConfigurationKey] = cfg;
controller.Request = request;
}
示例3: BaseTestBuilder
/// <summary>
/// Initializes a new instance of the <see cref="BaseTestBuilder" /> class.
/// </summary>
/// <param name="controller">Controller on which will be tested.</param>
/// <param name="controllerAttributes">Collected attributes from the tested controller.</param>
protected BaseTestBuilder(
ApiController controller,
IEnumerable<object> controllerAttributes = null)
{
this.Controller = controller;
this.ControllerLevelAttributes = controllerAttributes;
}
示例4: LocationIsCorrectlyInitialized
public void LocationIsCorrectlyInitialized(Uri location, ApiController controller)
{
// Exercise system
var result = new JSendRedirectResult(location, controller);
// Verify outcome
result.Location.Should().Be(location);
}
示例5: ApiControllerExtensionsTests
public ApiControllerExtensionsTests()
{
HttpConfiguration config = new HttpConfiguration();
IWebHookUser user = new WebHookUser();
_managerMock = new Mock<IWebHookManager>();
_resolverMock = new Mock<IDependencyResolver>();
_resolverMock.Setup(r => r.GetService(typeof(IWebHookManager)))
.Returns(_managerMock.Object)
.Verifiable();
_resolverMock.Setup(r => r.GetService(typeof(IWebHookUser)))
.Returns(user)
.Verifiable();
config.DependencyResolver = _resolverMock.Object;
ClaimsIdentity identity = new ClaimsIdentity();
Claim claim = new Claim(ClaimTypes.Name, "TestUser");
identity.AddClaim(claim);
_principal = new ClaimsPrincipal(identity);
_context = new HttpRequestContext()
{
Configuration = config,
Principal = _principal
};
_controller = new TestController()
{
RequestContext = _context
};
}
示例6: ContentIsCorrectlyInitialized
public void ContentIsCorrectlyInitialized(Uri location, Model content, ApiController controller)
{
// Exercise system
var result = new JSendCreatedResult<Model>(location, content, controller);
// Verify outcome
result.Content.Should().Be(content);
}
示例7: SetupControllerForTesting
private void SetupControllerForTesting(ApiController controller, string controllerName)
{
string serverUrl = "http://sample-url.com";
// Setup the Request object of the controller
var request = new HttpRequestMessage()
{
RequestUri = new Uri(serverUrl)
};
controller.Request = request;
// Setup the configuration of the controller
var config = new HttpConfiguration();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional });
controller.Configuration = config;
// Apply the routes to the controller
controller.RequestContext.RouteData = new HttpRouteData(
route: new HttpRoute(),
values: new HttpRouteValueDictionary
{
{ "controller", controllerName }
});
}
示例8: ReasonIsCorrectlyInitialized
public void ReasonIsCorrectlyInitialized(string reason, ApiController controller)
{
// Exercise system
var result = new JSendBadRequestResult(reason, controller);
// Verify outcome
result.Reason.Should().Be(reason);
}
示例9: ConstructorThrowsWhenRouteNameIsNull
public void ConstructorThrowsWhenRouteNameIsNull(
Dictionary<string, object> routeValues, Model content, ApiController controller)
{
// Exercise system and verify outcome
Action ctor = () => new JSendCreatedAtRouteResult<Model>(null, routeValues, content, controller);
ctor.ShouldThrow<ArgumentNullException>();
}
示例10: GetErrorResult
public static IHttpActionResult GetErrorResult(this IdentityResult result, ApiController controller)
{
if (result == null)
{
return new System.Web.Http.Results.InternalServerErrorResult(controller);
}
if (!result.Succeeded)
{
if (result.Errors != null)
{
foreach (string error in result.Errors)
{
controller.ModelState.AddModelError("", error);
}
}
if (controller.ModelState.IsValid)
{
// No ModelState errors are available to send, so just return an empty BadRequest.
return new System.Web.Http.Results.BadRequestResult(controller);
}
return new System.Web.Http.Results.BadRequestResult(controller);
}
return new System.Web.Http.Results.OkResult(controller);
}
示例11: ConstructorThrowsWhenReasonIsWhiteSpace
public void ConstructorThrowsWhenReasonIsWhiteSpace(ApiController controller)
{
// Exercise system and verify outcome
Action ctor = () => new JSendBadRequestResult(" ", controller);
ctor.ShouldThrow<ArgumentException>()
.And.Message.Should().StartWith(StringResources.BadRequest_WhiteSpaceReason);
}
示例12: CopyMulipartContent
public async static Task<dynamic> CopyMulipartContent(ApiController controller)
{
if (!controller.Request.Content.IsMimeMultipartContent())
{
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
}
var root = HttpContext.Current.Server.MapPath("~/App_Data");
var provider = new MultipartFormDataStreamProvider(root);
var tempPath = HttpContext.Current.Server.MapPath("~/Content/Temp/");
var fileNames = new List<string>();
await controller.Request.Content.ReadAsMultipartAsync(provider);
foreach (MultipartFileData file in provider.FileData)
{
_fileId++;
if (_fileId + 1 > Int32.MaxValue)
_fileId = 0;
var filename = tempPath + _fileId + "_" + file.Headers.ContentDisposition.FileName.Replace("\"", "").Replace("\\", "");
fileNames.Add(filename);
File.Copy(file.LocalFileName, filename);
FileHelper.WaitFileUnlockedAsync(() => File.Delete(file.LocalFileName), file.LocalFileName, 30, 800);
}
return new { formData = provider.FormData, fileNames };
}
示例13: OAuthImplicitAccessTokenResult
public OAuthImplicitAccessTokenResult(string redirectUrl, OAuthImplicitAccessTokenResponse response,
ApiController controller)
{
RedirectUrl = redirectUrl;
Response = response;
Request = controller.Request;
}
示例14: OkFileDownloadResult
public OkFileDownloadResult(string localPath, string contentType, string downloadFileName,
ApiController controller)
{
if (localPath == null)
{
throw new ArgumentNullException("localPath");
}
if (contentType == null)
{
throw new ArgumentNullException("contentType");
}
if (downloadFileName == null)
{
throw new ArgumentNullException("downloadFileName");
}
if (controller == null)
{
throw new ArgumentNullException("controller");
}
LocalPath = localPath;
ContentType = contentType;
DownloadFileName = downloadFileName;
_controller = controller;
}
示例15: RequestIsCorrectlyInitializedUsingController
public void RequestIsCorrectlyInitializedUsingController(ApiController controller)
{
// Exercise system
var result = new JSendOkResult(controller);
// Verify outcome
result.Request.Should().Be(controller.Request);
}