Example #1
0
        // UsePassedUserPermissionCheckerToCheckTheUserPermissions
        public void UsePassedUserPermissionCheckerToCheckPermissionsOfTheUser()
        {
            var permissionCheckerMock = new Mock <IUserPermissionChecker>();

            // Arrange
            ServicePermissionChecker <QueryStub> sut =
                new ServicePermissionChecker <QueryStub>(
                    permissionChecker: permissionCheckerMock.Object);

            // Act
            sut.CheckPermissionForCurrentUser();

            // Assert
            permissionCheckerMock.Verify(
                checker => checker.CheckPermission(
                    It.IsAny <string>()), Times.Once);
        }
Example #2
0
        public PermissionCommandServiceDecorator(
            ServicePermissionChecker <TCommand> permissionChecker,
            ICommandService <TCommand> decoratee)
        {
            if (permissionChecker is null)
            {
                throw new ArgumentNullException(nameof(permissionChecker));
            }

            if (decoratee is null)
            {
                throw new ArgumentNullException(nameof(decoratee));
            }

            this.permissionChecker = permissionChecker;
            this.decoratee         = decoratee;
        }
Example #3
0
        public void SavePassedUserPermissionCheckerWhenIsNotNull()
        {
            var permissionCheckerStub = new Mock <IUserPermissionChecker>();

            // Arrange && Act
            ServicePermissionChecker <QueryStub> sut =
                new ServicePermissionChecker <QueryStub>(
                    permissionChecker: permissionCheckerStub.Object);

            // Assert
            var actualPermissionChecker = sut.GetType()
                                          .GetFields(BindingFlags.Instance | BindingFlags.NonPublic)
                                          .First(fi => fi.FieldType == typeof(IUserPermissionChecker))
                                          .GetValue(sut);

            Assert.AreSame(permissionCheckerStub.Object, actualPermissionChecker);
        }
        public PermissionQueryServiceDecorator(
            ServicePermissionChecker <TQuery> permissionChecker,
            IQueryService <TQuery, TResult> decoratee)
        {
            if (permissionChecker is null)
            {
                throw new ArgumentNullException(nameof(permissionChecker));
            }

            if (decoratee is null)
            {
                throw new ArgumentNullException(nameof(decoratee));
            }

            this.permissionChecker = permissionChecker;
            this.decoratee         = decoratee;
        }
Example #5
0
        public void ExtractPermissionIdOfGivenGenericTypeParameter()
        {
            string expectedPermissionId =
                typeof(QueryStub)
                .GetCustomAttribute <PermissionAttribute>()
                .PermissionId;

            var permissionCheckerStub = new Mock <IUserPermissionChecker>();

            // Arrange && Act
            ServicePermissionChecker <QueryStub> sut =
                new ServicePermissionChecker <QueryStub>(
                    permissionChecker: permissionCheckerStub.Object);

            // Assert
            var actualPermissionId = sut.GetType()
                                     .GetFields(BindingFlags.Static | BindingFlags.NonPublic)
                                     .First(fi => fi.FieldType == typeof(string))
                                     .GetValue(sut);

            Assert.AreEqual(expectedPermissionId, actualPermissionId);
        }