public static Funcionalidad ControllerToFunctionality(IEnumerable <Funcionalidad> funcionalidades,
                                                              string controllerName)
        {
            Guard.AgainstArgumentNull(funcionalidades, "funcionalidades");

            //TODO: JSA. SE PUEDE MEJORAR SE CREA UN MAPPER (NOMBRE CONTROLLAR, FUNCIONALIDAD)

            //Buscar funcionalidades que tenga el nombre del controlador
            var funcionalidadesRelControlador = from f in funcionalidades
                                                where (f.Controlador.ToUpper().Equals(controllerName.ToUpper()))
                                                select f;

            var list = funcionalidadesRelControlador.ToList();

            log.DebugFormat("Resultado de convertir nombre de controlador : [{0}] a funcionalidad del sistema : [{1}], cantidad de resultados que coincide : [{2}]", controllerName.ToUpper(), (list.Count == 1 ? list[0].Nombre : ""), list.Count.ToString());

            if (list.Count == 0)
            {
                return(null);
            }

            if (list.Count > 1)
            {
                //No puede existir varias funcionalidades mapeadas al mismo controlador ???
                var fun = string.Join(", ", funcionalidades.Select(e => e.Nombre));
                log.WarnFormat("Existe varias funcionalidades [{0}] que tiene el mismo nombre de controlador [{1}], un total de [{2}] funcionalidades. Un controlador solo puede estar asociada a una funcionalidad", fun, controllerName, list.Count);
                return(null);
            }

            return(list[0]);
        }
        /// <summary>
        /// Applies the configuration embedded in the registar to the underlying container.
        /// </summary>
        /// <param name="registrar">
        /// Specifies the registrar.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Thrown when the supplied registrar is <c>null</c>.
        /// </exception>
        protected static void Configure(Registrar registrar)
        {
            Guard.AgainstArgumentNull(registrar, "registar");
            GuardAgainstStaticContext();

            _specificationController.Configure(registrar);
        }
        /// <summary>
        /// Shortcut for <see cref="Configure(Machine.Fakes.Registrar)"/>. This one will create
        /// a registrar for you and allow configuration via the delegate passed
        /// in via <paramref name="registrarExpression"/>.
        /// </summary>
        /// <param name="registrarExpression">
        /// Specifies the configuration for the registrar.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Thrown when the supplied registrar is <c>null</c>.
        /// </exception>
        protected static void Configure(Action <Registrar> registrarExpression)
        {
            Guard.AgainstArgumentNull(registrarExpression, "registar");
            GuardAgainstStaticContext();

            _specificationController.Configure(registrarExpression);
        }
示例#4
0
        /// <summary>Gives strong typed access to the generic <see cref="IFakeEngine.CreateFake"/> method.</summary>
        /// <typeparam name="T">Specifies the type to stub e.g. to create a fake for.</typeparam>
        /// <param name="fakeEngine">Specifies the <see cref="IFakeEngine"/>.</param>
        /// <param name="args">Constructor arguments for fake to create.</param>
        /// <returns>A new fake for the type specified via <typeparamref name="T"/>.</returns>
        public static T Stub <T>(this IFakeEngine fakeEngine, params object[] args)
        {
            Guard.AgainstArgumentNull(fakeEngine, "fakeEngine");

            return(args != null && args.Length > 0
                ? (T)fakeEngine.CreateFake(typeof(T), args)
                : (T)fakeEngine.CreateFake(typeof(T)));
        }
        public NSubstituteCommandOptions(TFake fake, Expression <Action <TFake> > action)
        {
            Guard.AgainstArgumentNull(fake, "fake");
            Guard.AgainstArgumentNull(action, "action");

            _fake   = fake;
            _action = action.Compile();
        }
示例#6
0
        public NSubstituteQueryOptions(TFake fake, Expression <Func <TFake, T> > expression)
        {
            Guard.AgainstArgumentNull(fake, "fake");
            Guard.AgainstArgumentNull(expression, "expression");

            _fake       = fake;
            _expression = expression.Compile();
        }
        /// <summary>
        /// Uses the instance supplied by <paramref name="instance"/> during the
        /// creation of the sut. The specified instance will be injected into the constructor.
        /// </summary>
        /// <typeparam name="TInterfaceType">Specifies the interface type.</typeparam>
        /// <param name="accessor">Specifies the fake accessor</param>
        /// <param name="instance">Specifies the instance to be used for the specification.</param>
        public static void Configure <TInterfaceType>(
            this IFakeAccessor accessor,
            TInterfaceType instance)
        {
            Guard.AgainstArgumentNull(accessor, "accessor");

            accessor.Configure(Registrar.New(config => config.For <TInterfaceType>().Use(instance)));
        }
        /// <summary>
        ///     Registered the type specified via <typeparamref name = "TImplementationType" /> as the default type
        ///     for the interface specified via <typeparamref name = "TInterfaceType" />. With this the type gets automatically
        ///     build when the subject is resolved.
        /// </summary>
        /// <param name = "accessor">
        ///     Specifies the fake accessor
        /// </param>
        /// <typeparam name = "TInterfaceType">
        ///     Specifies the interface type.
        /// </typeparam>
        /// <typeparam name = "TImplementationType">
        ///     Specifies the implementation type.
        /// </typeparam>
        public static void Configure <TInterfaceType, TImplementationType>(
            this IFakeAccessor accessor)
            where TImplementationType : TInterfaceType
        {
            Guard.AgainstArgumentNull(accessor, "accessor");

            accessor.Configure(Registrar.New(config => config.For <TInterfaceType>().Use <TImplementationType>()));
        }
示例#9
0
        /// <summary>
        /// Verifies that the behavior specified by <paramref name="func"/>
        /// was executed on the fake specified by <paramref name="fake"/>.
        /// </summary>
        /// <typeparam name="TFake">
        /// Specifies the type of the fake.
        /// </typeparam>
        /// <param name="fake">
        /// Specifies the fake instance.
        /// </param>
        /// <param name="func">
        /// Specifies the behavior that was supposed to happen.
        /// </param>
        /// <returns>
        /// A <see cref="IMethodCallOccurrence"/> which can be used
        /// to narrow down the expectations to a particular amount of times.
        /// </returns>
        public static IMethodCallOccurrence WasToldTo <TFake>(
            this TFake fake,
            Expression <Action <TFake> > func) where TFake : class
        {
            Guard.AgainstArgumentNull(fake, "fake");
            Guard.AgainstArgumentNull(func, "func");

            return(FakeEngineGateway.VerifyBehaviorWasExecuted(fake, func));
        }
示例#10
0
        /// <summary>
        /// Verifies that the behavior specified by <paramref name="func"/>
        /// was not executed on the fake specified by <paramref name="fake"/>.
        /// </summary>
        /// <typeparam name="TFake">
        /// Specifies the type of the fake.
        /// </typeparam>
        /// <param name="fake">
        /// Specifies the fake instance.
        /// </param>
        /// <param name="func">
        /// Specifies the behavior that was not supposed to happen.
        /// </param>
        public static void WasNotToldTo <TFake>(
            this TFake fake,
            Expression <Action <TFake> > func) where TFake : class
        {
            Guard.AgainstArgumentNull(fake, "fake");
            Guard.AgainstArgumentNull(func, "func");

            FakeEngineGateway.VerifyBehaviorWasNotExecuted(fake, func);
        }
        public static void ShouldRouteTo <TController>(
            this ActionResult actionResult,
            Expression <Action <TController> > controllerActionPointer) where TController : Controller
        {
            Guard.AgainstArgumentNull(actionResult, "actionResult");
            Guard.AgainstArgumentNull(controllerActionPointer, "controllerActionPointer");

            ShouldRouteTo((RedirectToRouteResult)actionResult, controllerActionPointer);
        }
示例#12
0
        public static void VerifyBehaviorWasNotExecuted <TFake>(
            TFake fake,
            Expression <Action <TFake> > func) where TFake : class
        {
            Guard.AgainstArgumentNull(fake, "fake");
            Guard.AgainstArgumentNull(func, "func");

            _fakeEngine.VerifyBehaviorWasNotExecuted(fake, func);
        }
示例#13
0
        public static ICommandOptions SetUpCommandBehaviorFor <TFake>(
            TFake fake,
            Expression <Action <TFake> > func) where TFake : class
        {
            Guard.AgainstArgumentNull(fake, "fake");
            Guard.AgainstArgumentNull(func, "func");

            return(_fakeEngine.SetUpCommandBehaviorFor(fake, func));
        }
示例#14
0
        public static IQueryOptions <TReturnValue> SetUpQueryBehaviorFor <TFake, TReturnValue>(
            TFake fake,
            Expression <Func <TFake, TReturnValue> > func) where TFake : class
        {
            Guard.AgainstArgumentNull(fake, "fake");
            Guard.AgainstArgumentNull(func, "func");

            return(_fakeEngine.SetUpQueryBehaviorFor(fake, func));
        }
示例#15
0
        /// <summary>
        /// Shortcut for inlining the configuration of a registrar via
        /// the nested closure pattern.
        /// </summary>
        /// <param name="configurationExpression">
        /// Specifies the expression that does the configuraition.
        /// </param>
        /// <returns>
        /// The configured registrar.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// Thrown when <paramref name="configurationExpression"/> is <c>null</c>.
        /// </exception>
        public static Registrar New(Action <Registrar> configurationExpression)
        {
            Guard.AgainstArgumentNull(configurationExpression, "configurationExpression");

            var registrar = new Registrar();

            configurationExpression(registrar);
            return(registrar);
        }
示例#16
0
        /// <summary>
        ///   Configures the behavior of the fake specified by <paramref name = "fake" />.
        /// </summary>
        /// <typeparam name = "TFake">
        ///   Specifies the type of the fake.
        /// </typeparam>
        /// <param name = "fake">
        ///   The fake to configure behavior on.
        /// </param>
        /// <param name = "func">
        ///   Configures the behavior. This must be a void method.
        /// </param>
        /// <returns>
        ///   A <see cref = "ICommandOptions" /> for further configuration.
        /// </returns>
        /// <remarks>
        ///   This method is used for command, e.g. methods returning void.
        /// </remarks>
        public static ICommandOptions WhenToldTo <TFake>(
            this TFake fake,
            Expression <Action <TFake> > func) where TFake : class
        {
            Guard.AgainstArgumentNull(fake, "fake");
            Guard.AgainstArgumentNull(func, "func");

            return(FakeEngineGateway.SetUpCommandBehaviorFor(fake, func));
        }
示例#17
0
        /// <summary>
        ///   Configures the behavior of the fake specified by <paramref name = "fake" />.
        /// </summary>
        /// <typeparam name = "TFake">
        ///   Specifies the type of the fake.
        /// </typeparam>
        /// <typeparam name = "TReturnValue">
        ///   Specifies the type of the return value.
        /// </typeparam>
        /// <param name = "fake">
        ///   The fake to configure behavior on.
        /// </param>
        /// <param name = "func">
        ///   Configures the behavior.
        /// </param>
        /// <returns>
        ///   A <see cref = "IQueryOptions{TReturn}" /> for further configuration.
        /// </returns>
        public static IQueryOptions <TReturnValue> WhenToldTo <TFake, TReturnValue>(
            this TFake fake,
            Expression <Func <TFake, TReturnValue> > func) where TFake : class
        {
            Guard.AgainstArgumentNull(fake, "fake");
            Guard.AgainstArgumentNull(func, "func");

            return(FakeEngineGateway.SetUpQueryBehaviorFor(fake, func));
        }
示例#18
0
        public void Delete(IList <TEntity> listEntity)
        {
            Guard.AgainstArgumentNull(listEntity, "listEntity");

            foreach (var entity in listEntity)
            {
                Delete(entity);
            }
        }
        /// <summary>
        ///     Shortcut for <see cref = "IFakeAccessor.Configure" />. This one will create
        ///     a registrar for you and allow configuration via the delegate passed
        ///     in via <paramref name = "registrarExpression" />.
        /// </summary>
        /// <param name = "accessor">
        ///     Specifies the fake accessor
        /// </param>
        /// <param name = "registrarExpression">
        ///     Specifies the configuration for the registrar.
        /// </param>
        /// <exception cref = "ArgumentNullException">
        ///     Thrown when the supplied registrar expression is <c>null</c>.
        /// </exception>
        public static void Configure(
            this IFakeAccessor accessor,
            Action <Registrar> registrarExpression)
        {
            Guard.AgainstArgumentNull(accessor, "accessor");
            Guard.AgainstArgumentNull(registrarExpression, "registrarExpression");

            accessor.Configure(Registrar.New(registrarExpression));
        }
示例#20
0
        /// <summary>
        ///   Initializes a new instance of the <see cref = "ReportEngine" /> class.
        /// </summary>
        /// <param name = "arguments">
        ///   Specifies the arguments.
        /// </param>
        /// <param name = "modelBuilder">
        ///   Specifies the model builder for building a report model from an assembly.</param>
        /// <param name = "reportGenerator">
        ///   Specifies the report generator which generates the output.
        /// </param>
        /// <exception cref = "ArgumentNullException">
        ///   Thrown when one of the parameters is <c>null</c>.
        /// </exception>
        public ReportEngine(IArguments arguments, IModelBuilder modelBuilder, IReportGenerator reportGenerator)
        {
            Guard.AgainstArgumentNull(arguments, "arguments");
            Guard.AgainstArgumentNull(modelBuilder, "modelBuilder");
            Guard.AgainstArgumentNull(reportGenerator, "reportGenerator");

            _arguments       = arguments;
            _modelBuilder    = modelBuilder;
            _reportGenerator = reportGenerator;
        }
示例#21
0
        public NSubstituteMethodCallOccurrence(TFake fake, Expression <Action <TFake> > func)
        {
            Guard.AgainstArgumentNull(fake, "fake");
            Guard.AgainstArgumentNull(func, "func");

            _fake = fake;
            _func = func;

            _func.Compile().Invoke(_fake.Received());
        }
示例#22
0
        public MoqMethodCallOccurrence(Mock <TFake> mock, Expression <Action <TFake> > func)
        {
            Guard.AgainstArgumentNull(mock, "mock");
            Guard.AgainstArgumentNull(func, "func");

            _mock = mock;
            _func = func;

            _mock.Verify(func, global::Moq.Times.AtLeastOnce());
        }
        public async Task <TResult> ProcessAsync <TQuery, TResult>(TQuery query) where TQuery : IQuery
        {
            Guard.AgainstArgumentNull(query);

            var handler = _resolver.Resolve <IQueryHandlerAsync <TQuery, TResult> >();

            Guard.AgainstNull <ArgumentException>(handler,
                                                  $"No handler of type IQueryHandlerAsync<TQuery, TResult>> found for query '{query.GetType().FullName}'");

            return(await handler.Retrieve(query));
        }
        public static void ShouldRouteTo <TController>(
            this RedirectToRouteResult redirectToRouteResult,
            Expression <Action <TController> > controllerActionPointer) where TController : Controller
        {
            Guard.AgainstArgumentNull(redirectToRouteResult, "redirectToRouteResult");
            Guard.AgainstArgumentNull(controllerActionPointer, "controllerActionPointer");

            var actionDictionary = Microsoft.Web.Mvc.Internal.ExpressionHelper.GetRouteValuesFromExpression(controllerActionPointer);

            actionDictionary.ShouldOnlyContain(redirectToRouteResult.RouteValues.ToArray());
        }
        public async Task <bool> Authorize(Accion action)
        {
            Guard.AgainstArgumentNull(action, "action");



            //1. Obtener usuario actual
            var usuario = _application.GetCurrentUser();

            if (usuario == null)
            {
                return(false);
            }

            log.DebugFormat("Verificar permiso de la accion {0} en la funcionalidad {1} para el usuario [{2}-{3}]", action.Codigo, action.FuncionalidadId,
                            usuario.Cuenta, usuario.Nombres);


            //Verificar si la accion se encuentra en las funcionalidades del modulo autentificado
            var modulo = _application.GetCurrentModule();
            var verificarAccionModuloAutentificado =
                (await ModuloService.GetModuleAndFunctionality(modulo.Id)).Funcionalidades.Any(f => f.Id == action.FuncionalidadId);

            if (!verificarAccionModuloAutentificado)
            {
                log.DebugFormat("La accion {0}, no se encuentra en las funcionalidades del modulo autentificado {1}", action.Codigo, modulo.Codigo);
                return(false);
            }


            if (usuario.Roles.Where(r => r.EsAdministrador).Any())
            {
                log.DebugFormat("El usuario {0}, posee un rol que es administrador", usuario.Cuenta);
                return(true);
            }

            //1. Obtener listado de Roles/Permisos asociadas al usuario autentificado
            var roles = (await RolService.GetAllRolAndPermissions())
                        .Where(r => usuario.Roles.Any(rUser => rUser.Id == r.Id)).ToList();


            //2. Recuperar Permisos que posee el rol Autentificado
            var permisos = (from r in roles
                            where r.Permisos.Any(p => p.AccionId == action.Id)
                            select r.Permisos).ToList();


            if (permisos.Any())
            {
                return(true);
            }

            return(false);
        }
示例#26
0
        public void Establish(object behaviorConfig, IFakeAccessor fakeAccessor)
        {
            Guard.AgainstArgumentNull(behaviorConfig, "behaviorConfig");
            Guard.AgainstArgumentNull(fakeAccessor, "fakeAccessor");

            behaviorConfig
            .GetFieldValues <OnEstablish>()
            .Each(establishDelegate => establishDelegate(fakeAccessor));

            _behaviorConfigs.Add(behaviorConfig);
        }
示例#27
0
        public void CleanUp(object subject)
        {
            Guard.AgainstArgumentNull(subject, "subject");

            _behaviorConfigs
            .SelectMany(config => config.GetFieldValues <OnCleanup>())
            .Each(cleanupDelegate => cleanupDelegate(subject));

            _behaviorConfigs.ForEach(config => config.ResetReferences());
            _behaviorConfigs.Clear();
        }
示例#28
0
        /// <summary>
        /// Establecer el usuario actual
        /// </summary>
        /// <param name="usuario"></param>
        public void SetCurrentUser(Usuario usuario)
        {
            Guard.AgainstArgumentNull(usuario, "GenericApplication.usuario");

            _usuarioActual = usuario;

            if (_rolActual != null)
            {
                _esAutenticado = true;
            }
        }
示例#29
0
        public void Delete(IList <TEntity> listEntity)
        {
            Guard.AgainstArgumentNull(listEntity, "listEntity");

            foreach (var entity in listEntity)
            {
                GetSet().Remove(entity);
            }

            _context.SaveChanges();
        }
示例#30
0
        public async Task PublishAsync <TEvent>(TEvent @event) where TEvent : IEvent
        {
            Guard.AgainstArgumentNull(@event);

            var handlers = _resolver.ResolveAll <IEventHandlerAsync <TEvent> >();

            foreach (var handler in handlers)
            {
                await handler.HandleAsync(@event);
            }
        }