当前位置: 首页>>代码示例>>C#>>正文


C# ApiController类代码示例

本文整理汇总了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);
        }
开发者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


注:本文中的ApiController类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。