Exemple #1
0
        /// <summary>
        /// Tests <paramref name="model"/> type and (optionally) calls validation callback function.
        /// </summary>
        /// <param name="model">The model to be tested.</param>
        public void Test(object model)
        {
            if (model == null || !TypeTester.IsOfType(model, typeof(TModel)))
            {
                string actualTypeName = (model == null) ? "null" : model.GetType().FullName;
                throw new ControllerTestException(
                          $"Expected model type: {typeof(TModel).FullName}. Actual: {actualTypeName}.");
            }

            _validate?.Invoke((TModel)model);
        }
Exemple #2
0
        private THttpActionResult AssertHttpActionResult <THttpActionResult>(IHttpActionResult actionResult) where THttpActionResult : IHttpActionResult
        {
            Type expectedType = typeof(THttpActionResult);

            if (actionResult == null || !TypeTester.IsOfType(actionResult, expectedType))
            {
                string actualTypeName = (actionResult == null) ? "null" : actionResult.GetType().FullName;
                throw new ControllerTestException($"Expected IHttpActionResult type {expectedType.FullName}. Actual: {actualTypeName}.");
            }

            return((THttpActionResult)actionResult);
        }