コード例 #1
0
        public static ResourceNotFoundException NotFoundException(int projectId, int?artifactId)
        {
            var errorMessage = artifactId == null
                ? I18NHelper.FormatInvariant("The project (Id:{0}) can no longer be accessed. It may have been deleted, or is no longer accessible by you.", projectId)
                : I18NHelper.FormatInvariant("Artifact (Id:{0}) in Project (Id:{1}) is not found.", artifactId, projectId);

            return(new ResourceNotFoundException(errorMessage, ErrorCodes.ResourceNotFound));
        }
コード例 #2
0
        public static AuthorizationException ForbiddenException(int projectId, int?artifactId)
        {
            if (artifactId.HasValue)
            {
                return(ArtifactForbiddenException(artifactId.Value));
            }

            var errorMessage = I18NHelper.FormatInvariant("User does not have permissions for Project (Id:{0}).", projectId);

            return(new AuthorizationException(errorMessage, ErrorCodes.UnauthorizedAccess));
        }
コード例 #3
0
        public static void AssertMethodAttributes(this HttpConfiguration config, Predicate <object[]> predicate, string messageFormat)
        {
            foreach (var route in config.Routes.SelectLeaves(r => r as IEnumerable <IHttpRoute>))
            {
                Assert.IsNotNull(route.DataTokens, "Missing DataTokens");
                var actions = route.DataTokens["actions"] as object[];
                Assert.IsNotNull(actions, "Missing actions in DataTokens");
                var actionDescriptor = actions.OfType <ReflectedHttpActionDescriptor>().FirstOrDefault();
                Assert.IsNotNull(actionDescriptor, "No ReflectedHttpActionDescriptor in DataTokens");
                var method = actionDescriptor.MethodInfo;

                Assert.IsTrue(predicate(method.GetCustomAttributes(false)), I18NHelper.FormatInvariant(messageFormat, method));
            }
        }
コード例 #4
0
        public static BadRequestException ArtifactDoesNotSupportOperation(int artifactId)
        {
            var errorMessage = I18NHelper.FormatInvariant("Operation cannot be invoked on Artifact with (Id:{0}).", artifactId);

            return(new BadRequestException(errorMessage, ErrorCodes.BadRequest));
        }
コード例 #5
0
        public static ConflictException ArtifactNotLockedException(int artifactId, int userId)
        {
            var errorMessage = I18NHelper.FormatInvariant("Artifact (Id:{0}) is not locked by user (Id:{1}).", artifactId, userId);

            return(new ConflictException(errorMessage, ErrorCodes.LockedByOtherUser));
        }
コード例 #6
0
        public static AuthorizationException ArtifactForbiddenException(int artifactId)
        {
            var errorMessage = I18NHelper.FormatInvariant("User does not have permissions for Artifact (Id:{0}).", artifactId);

            return(new AuthorizationException(errorMessage, ErrorCodes.UnauthorizedAccess));
        }
コード例 #7
0
        public static ResourceNotFoundException ArtifactNotFoundException(int artifactId)
        {
            var errorMessage = I18NHelper.FormatInvariant("Artifact (Id:{0}) is not found.", artifactId);

            return(new ResourceNotFoundException(errorMessage, ErrorCodes.ResourceNotFound));
        }