示例#1
0
        public async Task When_CreateRole_InputIsValid_Return(string roleName)
        {
            using var scope = ServiceScopeProvider.CreateScope();
            var sp       = scope.ServiceProvider;
            var mediator = sp.GetService <IMediator>();
            //Act
            var response = await mediator.Send(new CreateRoleCommand()
            {
                Name = roleName
            });

            //Assert
            response.Should().NotBeNull();
        }
示例#2
0
        public async Task When_ApplicationGetPermissionsQuery_InputIsValid_ReturnRoleVM(string name)
        {
            using var scope = ServiceScopeProvider.CreateScope();
            var sp       = scope.ServiceProvider;
            var mediator = sp.GetService <IMediator>();
            //Act

            var response = await mediator.Send(new GetPermissionsQuery()
            {
                ApplicationName = name
            });

            //Assert
            response.Should().NotBeNull();
        }
示例#3
0
        public async Task When_UserGetPermissionsQueryy_InputIsValid_ReturnOk()
        {
            using var scope = ServiceScopeProvider.CreateScope();
            var sp       = scope.ServiceProvider;
            var mediator = sp.GetService <IMediator>();
            //Act

            var response = await mediator.Send(new GetPermissionsQuery()
            {
                ApplicationName = Constants.App,
                Username        = Constants.UserAdmin,
            });

            //Assert
            response.Should().NotBeNull().And.HaveCountGreaterOrEqualTo(1);
        }
示例#4
0
        public async Task When_SearchRolesQuery_InputIsValid_ReturnList(string userName)
        {
            using var scope = ServiceScopeProvider.CreateScope();
            var sp = scope.ServiceProvider;

            var mediator = sp.GetService <IMediator>();
            //Act

            var response = await mediator.Send(new SearchUsersQuery()
            {
                UserName = userName
            });

            //Assert
            response.Should().HaveCountGreaterOrEqualTo(1);
        }
示例#5
0
        public async Task When_DisabledUser_InputIsValid_Return(string userName)
        {
            using var scope = ServiceScopeProvider.CreateScope();
            var sp = scope.ServiceProvider;

            var mediator = sp.GetService<IMediator>();
            var rolemanager = sp.GetService<IAppDbContext>();

            //Act
            var response = await mediator.Send(new DisabledUserCommand()
            {
                UserName = userName
            });
            //Assert
            response.Should().NotBeNull();

        }
示例#6
0
        public async Task When_CreateRole_InputIsValid_ThrowExistsException(string roleName)
        {
            using var scope = ServiceScopeProvider.CreateScope();
            var sp = scope.ServiceProvider;

            var mediator = sp.GetService <IMediator>();
            //Act
            Func <Task> act = async() =>
            {
                await mediator.Send(new CreateRoleCommand()
                {
                    Name = roleName
                });
            };

            //Assert
            act.Should().Throw <ExistsException>();
        }
示例#7
0
        public async Task When_DisabledUser_InputIsValid_ThrowNotFoundException(string userName)
        {
            using var scope = ServiceScopeProvider.CreateScope();
            var sp = scope.ServiceProvider;
            var mediator = sp.GetService<IMediator>();
            //Act
            Func<Task<Unit>> act = async () =>
            {
                var response = await mediator.Send(new DisabledUserCommand()
                {
                    UserName = userName
                });
                return response;
            };
            //Assert
            act.Should().Throw<NotFoundException>();

        }
示例#8
0
        public async Task When_ApplicationGetPermissionsQuery_InputIsValid_ThrowNotFoundException(string roleName)
        {
            using var scope = ServiceScopeProvider.CreateScope();
            var sp       = scope.ServiceProvider;
            var mediator = sp.GetService <IMediator>();

            //Act
            Func <Task <IEnumerable <PermissionDto> > > act = async() =>
            {
                var response = await mediator.Send(new GetPermissionsQuery()
                {
                    ApplicationName = roleName
                });

                return(response);
            };

            //Assert
            act.Should().Throw <NotFoundException>();
        }
示例#9
0
        public async Task When_GetRoleQuery_InputIsValid_ThrowNotFoundException(string roleName)
        {
            using var scope = ServiceScopeProvider.CreateScope();
            var sp       = scope.ServiceProvider;
            var mediator = sp.GetService <IMediator>();

            //Act
            Func <Task <RoleVM> > act = async() =>
            {
                var cancellationSourceToken = new CancellationTokenSource();
                var response = await mediator.Send(new GetRoleQuery()
                {
                    Name = roleName
                });

                return(response);
            };

            //Assert
            act.Should().Throw <NotFoundException>();
        }
示例#10
0
        public async Task When_UserGetPermissionsQuery_InputIsValid_ThrowDisabledException()
        {
            using var scope = ServiceScopeProvider.CreateScope();
            var sp      = scope.ServiceProvider;
            var dbUsers = sp.GetService <DbSet <User> >();

            dbUsers.FirstOrDefault(u => u.UserName == Constants.UserAdmin).IsEnabled = false;
            var mediator = sp.GetService <IMediator>();

            //Act
            Func <Task <IEnumerable <PermissionDto> > > act = async() =>
            {
                var response = await mediator.Send(new GetPermissionsQuery()
                {
                    ApplicationName = Constants.App,
                    Username        = Constants.UserAdmin,
                });

                return(response);
            };

            //Assert
            act.Should().Throw <NotFoundException>();
        }