Пример #1
0
        public static void BuildActionAndCompareToStaticAction(
            FluentActionBase fluentAction,
            Type staticControllerType,
            ILogger logger = null)
        {
            var builtController = BuildAction(fluentAction, logger);

            AssertConstantValuesOfBuiltController(builtController, fluentAction);

            CompareBuiltControllerToStaticController(builtController.TypeInfo.UnderlyingSystemType, staticControllerType);
        }
Пример #2
0
        public static void BuildActionAndCompareToStaticActionWithResult(
            FluentActionBase fluentAction,
            Type staticControllerType,
            object[] actionMethodArguments,
            ILogger logger = null)
        {
            var builtController = BuildAction(fluentAction, logger);

            AssertConstantValuesOfBuiltController(builtController, fluentAction);

            CompareBuiltControllerToStaticController(builtController.TypeInfo.UnderlyingSystemType, staticControllerType);

            CompareActionMethodResults(fluentAction, builtController, staticControllerType, actionMethodArguments);
        }
Пример #3
0
        public static void CompareActionMethodResults(FluentActionBase fluentAction, FluentActionControllerDefinition builtController, Type staticControllerType, object[] actionMethodArguments = null)
        {
            var resultsFromBuiltController  = InvokeActionMethod(builtController.TypeInfo, actionMethodArguments);
            var resultsFromStaticController = InvokeActionMethod(staticControllerType.GetTypeInfo(), actionMethodArguments);

            if (resultsFromBuiltController == null)
            {
                throw new Exception($"Invoked action method returns null of built controller {builtController.Name}.");
            }

            if (resultsFromStaticController == null)
            {
                throw new Exception($"Invoked action method returns null of statically defined controller {staticControllerType.Name}.");
            }

            var returnTypeIsAsync = fluentAction.Definition.IsAsync;
            var returnType        = returnTypeIsAsync
                ? typeof(Task <>).MakeGenericType(fluentAction.Definition.ReturnType)
                : fluentAction.Definition.ReturnType;

            if (!returnType.IsAssignableFrom(resultsFromBuiltController.GetType()))
            {
                throw new Exception($"Incorrect return type from invoked action method of built controller {builtController.Name} ({resultsFromBuiltController.GetType().Name} should be {fluentAction.Definition.ReturnType}).");
            }

            if (!returnType.IsAssignableFrom(resultsFromStaticController.GetType()))
            {
                throw new Exception($"Incorrect return type from invoked action method of statically defined controller {staticControllerType.Name} ({resultsFromStaticController.GetType().Name} should be {fluentAction.Definition.ReturnType}).");
            }

            if (returnTypeIsAsync)
            {
                resultsFromBuiltController  = GetTaskResult(resultsFromBuiltController);
                resultsFromStaticController = GetTaskResult(resultsFromStaticController);
            }

            if (!IsEqual(resultsFromBuiltController, resultsFromStaticController))
            {
                throw new Exception($"Results from invoked action methods does not match between built controller {builtController.Name} and statically defined controller {staticControllerType.Name} ({resultsFromBuiltController} vs {resultsFromStaticController}).");
            }
        }
Пример #4
0
        public static void AssertConstantValuesOfBuiltController(FluentActionControllerDefinition builtController, FluentActionBase fluentAction)
        {
            var builtControllerTypeInfo = builtController.TypeInfo;

            Assert.Equal(fluentAction.RouteTemplate, builtController.RouteTemplate);
            Assert.Equal("HandlerAction", builtController.ActionName);
            Assert.Equal(builtControllerTypeInfo.Name, builtController.Id);
            Assert.Equal(builtControllerTypeInfo.Name, builtController.Name);
            Assert.Equal(fluentAction, builtController.FluentAction);

            Assert.StartsWith("FluentAction", builtControllerTypeInfo.Name);
            Assert.EndsWith("Controller", builtControllerTypeInfo.Name);
        }
Пример #5
0
        public static FluentActionControllerDefinition BuildAction(FluentActionBase fluentAction, ILogger logger = null)
        {
            var controllerBuilder = new FluentActionControllerDefinitionBuilder();

            return(controllerBuilder.Build(fluentAction, logger));
        }