Exemplo n.º 1
0
        public async Task PermissionDenied()
        {
            access.Setup(x => x.CanDo("1", appSettings.ApplicationName, Permission.AddUsers.ToString())).Returns(false);

            var decorator = new RequirePermissionDecorator <TestCommandWithPermission>(new TestHandlerWithPermission(), access.Object, appSettings);
            var result    = await decorator.Handle(new TestCommandWithPermission());

            Assert.IsFalse(result.IsSuccess);
            Assert.AreEqual(CommandError.Forbidden().Code, result.Error.Code);
        }
Exemplo n.º 2
0
        public override Task <CommandResult <TResult> > Handle(TQuery query)
        {
            var perm = query as IRequirePermission;

            if (perm == null)
            {
                throw new Exception($"Command must implement {typeof(IRequirePermission)}");
            }

            if (access.CanDo(perm.TenantId, appSettings.ApplicationName, perm.Permission.ToString()))
            {
                return(queryHandler.Handle(query));
            }
            else
            {
                return(CommandResult <TResult> .Fail(CommandError.Forbidden($"Permission denied for {perm.Permission}")).AsTaskTyped());
            }
        }