Esempio n. 1
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);
        }
Esempio n. 2
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}).");
            }
        }