Exemple #1
0
        /// <summary>
        /// Validates the mock API resource.
        /// </summary>
        /// <param name="mockApi">The mock API.</param>
        /// <exception cref="ValidationException"></exception>
        public static void ValidateMockApiResource(MockApiResourceModel mockApi, ILanguageBindingFactory languageBindingFactory)
        {
            List <string> errors = new List <string>();

            // verify name
            if (IsNameInvalid(mockApi.Name))
            {
                errors.Add(Constants.InvalidMockApiNameMessage);
            }

            // verify verb
            if (mockApi.Verb == MockApiHttpVerb.None)
            {
                errors.Add(Constants.InvalidApiVerbMessage);
            }

            // verify body
            var sourceValidator = languageBindingFactory.CreateLanguageValidator(mockApi.Language);

            try
            {
                sourceValidator.Validate(mockApi.Body);
            }
            catch (ValidationException ex)
            {
                errors.AddRange(ex.Errors);
            }

            // verify route template
            if (RouteUtil.IsInvalidRouteTemplate(mockApi.RouteTemplate))
            {
                errors.Add(Constants.InvalidApiTempateMessage);
            }

            if (errors.Count > 0)
            {
                throw new ValidationException(errors);
            }
        }
Exemple #2
0
 /// <summary>
 /// Froms the domain model.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns></returns>
 public static MockApiCollectionResourceModel FromDomainModel(MockApiCollectionModel model) => new MockApiCollectionResourceModel()
 {
     Name     = model.Name,
     MockApis = model.MockApis.Select(x => MockApiResourceModel.FromDomainModel(x)).ToList()
 };