Пример #1
0
        public async Task CallThePassedDecoratee()
        {
            var userPermissionCheckerMock = new Mock <IUserPermissionChecker>();
            var permissionCheckerStub     = new ServicePermissionCheckerStub(
                permissionChecker: userPermissionCheckerMock.Object);

            var deorateeMock = new Mock <IQueryService <QueryStub, object> >();

            // Arrange
            PermissionQueryServiceDecorator <QueryStub, object> sut =
                new PermissionQueryServiceDecorator <QueryStub, object>(
                    permissionChecker: permissionCheckerStub,
                    decoratee: deorateeMock.Object);

            // Act
            await sut.ExecuteAsync(new QueryStub());

            // Assert
            deorateeMock.Verify(
                x => x.ExecuteAsync(It.IsAny <QueryStub>()), Times.Once);
        }
Пример #2
0
        public void SavePassedDecorateeWhenIsNotNull()
        {
            var userPermissionCheckerStub = new Mock <IUserPermissionChecker>();
            var permissionCheckerStub     = new ServicePermissionCheckerStub(
                permissionChecker: userPermissionCheckerStub.Object);

            QueryServiceStub decoratee = new QueryServiceStub();

            // Arrange && Act
            PermissionQueryServiceDecorator <QueryStub, object> sut = new PermissionQueryServiceDecorator <QueryStub, object>(
                permissionChecker: permissionCheckerStub,
                decoratee: decoratee);

            // Assert
            var actualDecoratee = sut.GetType()
                                  .GetFields(BindingFlags.Instance | BindingFlags.NonPublic)
                                  .First(fi => fi.FieldType == typeof(IQueryService <QueryStub, object>))
                                  .GetValue(sut);

            Assert.AreSame(decoratee, actualDecoratee);
        }
Пример #3
0
        public async Task CheckPermissionsOfTheUserWhenInvoked()
        {
            var userPermissionCheckerMock = new Mock <IUserPermissionChecker>();
            var permissionCheckerStub     = new ServicePermissionCheckerStub(
                permissionChecker: userPermissionCheckerMock.Object);

            QueryServiceStub decorateeStub = new QueryServiceStub();

            // Arrange
            PermissionQueryServiceDecorator <QueryStub, object> sut =
                new PermissionQueryServiceDecorator <QueryStub, object>(
                    permissionChecker: permissionCheckerStub,
                    decoratee: decorateeStub);

            // Act
            await sut.ExecuteAsync(new QueryStub());

            // Assert
            userPermissionCheckerMock.Verify(
                x => x.CheckPermission(It.IsAny <string>()), Times.Once);
        }