本文整理汇总了C#中ApiController类的典型用法代码示例。如果您正苦于以下问题:C# ApiController类的具体用法?C# ApiController怎么用?C# ApiController使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ApiController类属于命名空间,在下文中一共展示了ApiController类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:pglazkov,项目名称:Linqua,代码行数:30,代码来源:ApiControllerExtensions.cs
示例2: DefaultControllerBehaviorConfig
public DefaultControllerBehaviorConfig(ApiController controller)
{
var request = new HttpRequestMessage();
var cfg = new HttpConfiguration();
request.Properties[HttpPropertyKeys.HttpConfigurationKey] = cfg;
controller.Request = request;
}
开发者ID:howarddierking,项目名称:RestBugs,代码行数:7,代码来源:DefaultControllerBehaviorConfig.cs
示例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;
}
开发者ID:joehoughton,项目名称:cycle-analysis-software,代码行数:12,代码来源:BaseTestBuilder.cs
示例4: LocationIsCorrectlyInitialized
public void LocationIsCorrectlyInitialized(Uri location, ApiController controller)
{
// Exercise system
var result = new JSendRedirectResult(location, controller);
// Verify outcome
result.Location.Should().Be(location);
}
开发者ID:lofrank,项目名称:JSendWebApi,代码行数:7,代码来源:JSendRedirectResultTests.cs
示例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
};
}
开发者ID:Joshzx,项目名称:WebHooks,代码行数:31,代码来源:ApiControllerExtensionsTests.cs
示例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);
}
开发者ID:lofrank,项目名称:JSendWebApi,代码行数:7,代码来源:JSendCreatedResultTests.cs
示例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 }
});
}
开发者ID:vsavov1,项目名称:SoftwareUniversity,代码行数:28,代码来源:MyBidsUnitTestsWithMocking.cs
示例8: ReasonIsCorrectlyInitialized
public void ReasonIsCorrectlyInitialized(string reason, ApiController controller)
{
// Exercise system
var result = new JSendBadRequestResult(reason, controller);
// Verify outcome
result.Reason.Should().Be(reason);
}
开发者ID:lofrank,项目名称:JSendWebApi,代码行数:7,代码来源:JSendBadRequestResultTests.cs
示例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>();
}
开发者ID:lofrank,项目名称:JSendWebApi,代码行数:7,代码来源:JSendCreatedAtRouteResultTests.cs
示例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);
}
开发者ID:thomas-parrish,项目名称:INAB,代码行数:28,代码来源:UserAccountController.cs
示例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);
}
开发者ID:lofrank,项目名称:JSendWebApi,代码行数:7,代码来源:JSendBadRequestResultTests.cs
示例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 };
}
开发者ID:jmptrader,项目名称:spa-template,代码行数:27,代码来源:ControllerHelper.cs
示例13: OAuthImplicitAccessTokenResult
public OAuthImplicitAccessTokenResult(string redirectUrl, OAuthImplicitAccessTokenResponse response,
ApiController controller)
{
RedirectUrl = redirectUrl;
Response = response;
Request = controller.Request;
}
开发者ID:KuduApps,项目名称:PreviewSpa5,代码行数:7,代码来源:OAuthImplicitAccessTokenResult.cs
示例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;
}
开发者ID:andreychizhov,项目名称:microsoft-aspnet-samples,代码行数:28,代码来源:OkFileDownloadResult.cs
示例15: RequestIsCorrectlyInitializedUsingController
public void RequestIsCorrectlyInitializedUsingController(ApiController controller)
{
// Exercise system
var result = new JSendOkResult(controller);
// Verify outcome
result.Request.Should().Be(controller.Request);
}
开发者ID:lofrank,项目名称:JSendWebApi,代码行数:7,代码来源:JSendOkResultTests.cs
示例16: ValidateAccessToken
/// <summary>
/// Validates the access token for any OAuth connector.
/// </summary>
/// <param name="authController">The connector controller which uses access token based authentication</param>
/// <param name="connectorName">The name of the connector for which the validation will be done.</param>
/// <param name="getAccessTokenVerificationRequest">Callback that computes the request object that will be used to do access token verification.</param>
/// <param name="webResponseProcessor">Callback that processes the web response from 3rd party service.</param>
/// <returns>A status check record indiciating the outcome of access token check.</returns>
public static async Task<StatusCheckEntry> ValidateAccessToken(ApiController authController, string connectorName, Func<Task<HttpWebRequest>> getAccessTokenVerificationRequest = null, Func<WebResponse, StatusCheckEntry> webResponseProcessor = null)
{
Logger.LogMessage(authController.Request, false, "Retrieving {0} connector status", connectorName);
if (getAccessTokenVerificationRequest == null)
{
throw new ArgumentNullException("getAccessTokenVerificationRequest", "getAccessTokenVerificationRequest cannot be null");
}
return await Task.Factory.StartNew(() =>
{
var accessTokenStatusCheck = new StatusCheckEntry();
try
{
// Constructing the outgoing request object
HttpWebRequest outgoingRequest = null;
Logger.LogMessage(authController.Request, false, "Constructing outgoing request object");
outgoingRequest = getAccessTokenVerificationRequest().Result;
outgoingRequest.ReadWriteTimeout = -1;
outgoingRequest.Timeout = -1;
outgoingRequest.KeepAlive = false;
Logger.LogMessage(authController.Request, false, "Calling {0} API with Request URI: {1}", connectorName, outgoingRequest.RequestUri.ToString());
// Make the call and check the response code
WebResponse webResponse = outgoingRequest.GetResponse();
HttpStatusCode statusCode = ((HttpWebResponse)webResponse).StatusCode;
Logger.LogMessage(authController.Request, false, "Status returning , {0}", statusCode);
if (webResponseProcessor != null)
{
accessTokenStatusCheck = webResponseProcessor(webResponse);
}
else
{
accessTokenStatusCheck = ProcessStatusCheckResponse(authController, webResponse);
}
}
catch (Exception ex)
{
if (ex.Message.Equals("The remote server returned an error: (401) Unauthorized."))
{
Logger.LogMessage(authController.Request, ex.Message);
accessTokenStatusCheck = GetInvalidAccessTokenStatusCheckEntry();
}
else
{
// Log the exception stack
Logger.LogException(authController.Request, ex);
// Construct a status check entry mentioning that status check failed
accessTokenStatusCheck.Level = StatusLevel.Error;
accessTokenStatusCheck.Message = string.Format(CommonResource.StatusCheckFailed, connectorName);
accessTokenStatusCheck.Name = StatusMessages.StatusCheckFailed;
}
}
return accessTokenStatusCheck;
}
);
}
开发者ID:sudarsanan-krishnan,项目名称:DynamicsCRMConnector,代码行数:67,代码来源:OAuthTokenValidator.cs
示例17: RequestIsCorrectlyInitializedUsingController
public void RequestIsCorrectlyInitializedUsingController(
string message, int? code, Exception data, ApiController controller)
{
// Exercise system
var result = new JSendInternalServerErrorResult(message, code, data, controller);
// Verify outcome
result.Request.Should().Be(controller.Request);
}
开发者ID:lofrank,项目名称:JSendWebApi,代码行数:8,代码来源:JSendInternalServerErrorResultTests.cs
示例18: RequestIsCorrectlyInitializedUsingController
public void RequestIsCorrectlyInitializedUsingController(
string routeName, Dictionary<string, object> routeValues, Model content, ApiController controller)
{
// Exercise system
var result = new JSendCreatedAtRouteResult<Model>(routeName, routeValues, content, controller);
// Verify outcome
result.Request.Should().Be(controller.Request);
}
开发者ID:lofrank,项目名称:JSendWebApi,代码行数:8,代码来源:JSendCreatedAtRouteResultTests.cs
示例19: UrlFactoryIsCorrectlyInitialized
public void UrlFactoryIsCorrectlyInitialized(string routeName, Dictionary<string, object> routeValues,
ApiController controller)
{
// Exercise system
var result = new JSendRedirectToRouteResult(routeName, routeValues, controller);
// Verify outcome
result.UrlFactory.Should().BeSameAs(controller.Url);
}
开发者ID:lofrank,项目名称:JSendWebApi,代码行数:8,代码来源:JSendRedirectToRouteResultTests.cs
示例20: VoidActionResultTestBuilder
/// <summary>
/// Initializes a new instance of the <see cref="VoidActionResultTestBuilder" /> class.
/// </summary>
/// <param name="controller">Controller on which the action will be tested.</param>
/// <param name="actionName">Name of the tested action.</param>
/// <param name="caughtException">Caught exception during the action execution.</param>
/// <param name="actionAttributes">Collected action attributes from the method call.</param>
public VoidActionResultTestBuilder(
ApiController controller,
string actionName,
Exception caughtException,
IEnumerable<object> actionAttributes)
: base(controller, actionName, caughtException, actionAttributes)
{
}
开发者ID:joehoughton,项目名称:cycle-analysis-software,代码行数:15,代码来源:VoidActionResultTestBuilder.cs
注:本文中的ApiController类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论