當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。