Beispiel #1
0
        public async Task Setup()
        {
            context = await TestDatabase.GetDatabaseContext();

            MockAppsRepository      = new MockAppsRepository(context);
            MockUsersRepository     = new MockUsersRepository(context);
            MockAppAdminsRepository = new MockAppAdminsRepository(context);
            MockRolesRepository     = new MockRolesRepository(context);

            sut = new AppsService(
                MockAppsRepository.AppsRepositorySuccessfulRequest.Object,
                MockUsersRepository.UsersRepositorySuccessfulRequest.Object,
                MockAppAdminsRepository.AppAdminsRepositorySuccessfulRequest.Object,
                MockRolesRepository.RolesRepositorySuccessfulRequest.Object);

            sutAppRepoFailure = new AppsService(
                MockAppsRepository.AppsRepositoryFailedRequest.Object,
                MockUsersRepository.UsersRepositorySuccessfulRequest.Object,
                MockAppAdminsRepository.AppAdminsRepositoryFailedRequest.Object,
                MockRolesRepository.RolesRepositoryFailedRequest.Object);

            sutUserRepoFailure = new AppsService(
                MockAppsRepository.AppsRepositorySuccessfulRequest.Object,
                MockUsersRepository.UsersRepositoryFailedRequest.Object,
                MockAppAdminsRepository.AppAdminsRepositoryFailedRequest.Object,
                MockRolesRepository.RolesRepositorySuccessfulRequest.Object);

            sutPromoteUser = new AppsService(
                MockAppsRepository.AppsRepositorySuccessfulRequest.Object,
                MockUsersRepository.UsersRepositoryInitiatePasswordSuccessful.Object,
                MockAppAdminsRepository.AppAdminsRepositoryPromoteUser.Object,
                MockRolesRepository.RolesRepositorySuccessfulRequest.Object);;

            dateCreated = DateTime.UtcNow;
            license     = TestObjects.GetLicense();
            baseRequest = TestObjects.GetBaseRequest();
            paginator   = TestObjects.GetPaginator();
            userId      = 1;
            appId       = 1;
        }
        public async Task Setup()
        {
            userName = "******";
            password = "******";

            context = await TestDatabase.GetDatabaseContext();

            MockUsersRepository     = new MockUsersRepository(context);
            MockRolesRepository     = new MockRolesRepository(context);
            MockAppsRepository      = new MockAppsRepository(context);
            MockAppAdminsRepository = new MockAppAdminsRepository(context);

            MockUserManagementService = new MockUserManagementService();

            tokenManagement = new TokenManagement()
            {
                Secret   = "3c1ad157-be37-40d2-9cc8-e7527a56aa7b",
                Issuer   = "testProject",
                Audience = "testEnvironment"
            };

            IOptions <TokenManagement> options = Options.Create <TokenManagement>(tokenManagement);

            sutValid = new AuthenticateService(
                MockUsersRepository.UsersRepositorySuccessfulRequest.Object,
                MockRolesRepository.RolesRepositorySuccessfulRequest.Object,
                MockAppsRepository.AppsRepositorySuccessfulRequest.Object,
                MockAppAdminsRepository.AppAdminsRepositorySuccessfulRequest.Object,
                MockUserManagementService.UserManagementServiceSuccssfulRequest.Object,
                options);
            sutInvalid = new AuthenticateService(
                MockUsersRepository.UsersRepositoryFailedRequest.Object,
                MockRolesRepository.RolesRepositoryFailedRequest.Object,
                MockAppsRepository.AppsRepositoryFailedRequest.Object,
                MockAppAdminsRepository.AppAdminsRepositoryFailedRequest.Object,
                MockUserManagementService.UserManagementServiceFailedRequest.Object,
                options);
        }
        public async Task Setup()
        {
            context = await TestDatabase.GetDatabaseContext();

            MockEmailService                 = new MockEmailService();
            MockUsersRepository              = new MockUsersRepository(context);
            MockAppsRepository               = new MockAppsRepository(context);
            MockRolesRepository              = new MockRolesRepository(context);
            MockAppAdminsRepository          = new MockAppAdminsRepository(context);
            MockEmailConfirmationsRepository = new MockEmailConfirmationsRepository(context);
            MockPasswordResetRepository      = new MockPasswordResetsRepository(context);

            sut = new UsersService(
                MockUsersRepository.UsersRepositorySuccessfulRequest.Object,
                MockAppsRepository.AppsRepositorySuccessfulRequest.Object,
                MockRolesRepository.RolesRepositorySuccessfulRequest.Object,
                MockAppAdminsRepository.AppAdminsRepositorySuccessfulRequest.Object,
                MockEmailConfirmationsRepository.EmailConfirmationsRepositorySuccessfulRequest.Object,
                MockPasswordResetRepository.PasswordResetsRepositorySuccessfulRequest.Object,
                MockEmailService.EmailServiceSuccessfulRequest.Object);

            sutFailure = new UsersService(
                MockUsersRepository.UsersRepositoryFailedRequest.Object,
                MockAppsRepository.AppsRepositorySuccessfulRequest.Object,
                MockRolesRepository.RolesRepositorySuccessfulRequest.Object,
                MockAppAdminsRepository.AppAdminsRepositoryFailedRequest.Object,
                MockEmailConfirmationsRepository.EmailConfirmationsRepositoryFailedRequest.Object,
                MockPasswordResetRepository.PasswordResetsRepositorySuccessfulRequest.Object,
                MockEmailService.EmailServiceSuccessfulRequest.Object);

            sutEmailFailure = new UsersService(
                MockUsersRepository.UsersRepositoryEmailFailedRequest.Object,
                MockAppsRepository.AppsRepositorySuccessfulRequest.Object,
                MockRolesRepository.RolesRepositorySuccessfulRequest.Object,
                MockAppAdminsRepository.AppAdminsRepositoryFailedRequest.Object,
                MockEmailConfirmationsRepository.EmailConfirmationsRepositoryFailedRequest.Object,
                MockPasswordResetRepository.PasswordResetsRepositorySuccessfulRequest.Object,
                MockEmailService.EmailServiceSuccessfulRequest.Object);

            sutResetPassword = new UsersService(
                MockUsersRepository.UsersRepositoryInitiatePasswordSuccessful.Object,
                MockAppsRepository.AppsRepositoryInitiatePasswordSuccessfulRequest.Object,
                MockRolesRepository.RolesRepositorySuccessfulRequest.Object,
                MockAppAdminsRepository.AppAdminsRepositorySuccessfulRequest.Object,
                MockEmailConfirmationsRepository.EmailConfirmationsRepositorySuccessfulRequest.Object,
                MockPasswordResetRepository.PasswordResetsRepositorySuccessfulRequest.Object,
                MockEmailService.EmailServiceSuccessfulRequest.Object);

            sutResendEmailConfirmation = new UsersService(
                MockUsersRepository.UsersRepositoryResendEmailConfirmationSuccessful.Object,
                MockAppsRepository.AppsRepositorySuccessfulRequest.Object,
                MockRolesRepository.RolesRepositorySuccessfulRequest.Object,
                MockAppAdminsRepository.AppAdminsRepositorySuccessfulRequest.Object,
                MockEmailConfirmationsRepository.EmailConfirmationsRepositorySuccessfulRequest.Object,
                MockPasswordResetRepository.PasswordResetsRepositorySuccessfulRequest.Object,
                MockEmailService.EmailServiceSuccessfulRequest.Object);

            sutRequestPasswordReset = new UsersService(
                MockUsersRepository.UsersRepositorySuccessfulRequest.Object,
                MockAppsRepository.AppsRepositorySuccessfulRequest.Object,
                MockRolesRepository.RolesRepositorySuccessfulRequest.Object,
                MockAppAdminsRepository.AppAdminsRepositorySuccessfulRequest.Object,
                MockEmailConfirmationsRepository.EmailConfirmationsRepositorySuccessfulRequest.Object,
                MockPasswordResetRepository.PasswordResetsRepositorySuccessfullCreateRequest.Object,
                MockEmailService.EmailServiceSuccessfulRequest.Object);

            baseRequest = TestObjects.GetBaseRequest();
        }
Beispiel #4
0
        public MockRolesService(DatabaseContext context)
        {
            MockRolesRepository = new MockRolesRepository(context);

            RolesServiceSuccessfulRequest = new Mock <IRolesService>();
            RolesServiceFailedRequest     = new Mock <IRolesService>();

            RolesServiceSuccessfulRequest.Setup(rolesService =>
                                                rolesService.GetRole(It.IsAny <int>(), It.IsAny <bool>()))
            .Returns(Task.FromResult(new RoleResult()
            {
                Success = MockRolesRepository
                          .RolesRepositorySuccessfulRequest
                          .Object
                          .GetById(It.IsAny <int>(), It.IsAny <bool>())
                          .Result
                          .Success,
                Message = RolesMessages.RoleFoundMessage,
                Role    = (Role)MockRolesRepository
                          .RolesRepositorySuccessfulRequest
                          .Object
                          .GetById(It.IsAny <int>(), It.IsAny <bool>())
                          .Result
                          .Object
            } as IRoleResult));

            RolesServiceSuccessfulRequest.Setup(rolesService =>
                                                rolesService.GetRoles(It.IsAny <bool>()))
            .Returns(Task.FromResult(new RolesResult()
            {
                Success = MockRolesRepository
                          .RolesRepositorySuccessfulRequest
                          .Object
                          .GetAll(It.IsAny <bool>())
                          .Result
                          .Success,
                Message = RolesMessages.RolesFoundMessage,
                Roles   = MockRolesRepository
                          .RolesRepositorySuccessfulRequest
                          .Object
                          .GetAll(It.IsAny <bool>())
                          .Result
                          .Objects
                          .ConvertAll(r => (IRole)r)
            } as IRolesResult));

            RolesServiceSuccessfulRequest.Setup(rolesService =>
                                                rolesService.CreateRole(It.IsAny <string>(), It.IsAny <RoleLevel>()))
            .Returns(Task.FromResult(new RoleResult()
            {
                Success = MockRolesRepository
                          .RolesRepositorySuccessfulRequest
                          .Object
                          .Add(It.IsAny <Role>())
                          .Result
                          .Success,
                Message = RolesMessages.RoleCreatedMessage,
                Role    = (Role)MockRolesRepository
                          .RolesRepositorySuccessfulRequest
                          .Object
                          .Add(It.IsAny <Role>())
                          .Result
                          .Object
            } as IRoleResult));

            RolesServiceSuccessfulRequest.Setup(rolesService =>
                                                rolesService.UpdateRole(It.IsAny <int>(), It.IsAny <UpdateRoleRequest>()))
            .Returns(Task.FromResult(new BaseResult()
            {
                Success = MockRolesRepository
                          .RolesRepositorySuccessfulRequest
                          .Object
                          .Update(It.IsAny <Role>())
                          .Result
                          .Success,
                Message = RolesMessages.RoleUpdatedMessage
            } as IBaseResult));

            RolesServiceSuccessfulRequest.Setup(rolesService =>
                                                rolesService.DeleteRole(It.IsAny <int>()))
            .Returns(Task.FromResult(new BaseResult()
            {
                Success = MockRolesRepository
                          .RolesRepositorySuccessfulRequest
                          .Object
                          .Delete(It.IsAny <Role>())
                          .Result
                          .Success,
                Message = RolesMessages.RoleDeletedMessage
            } as IBaseResult));

            RolesServiceFailedRequest.Setup(rolesService =>
                                            rolesService.GetRole(It.IsAny <int>(), It.IsAny <bool>()))
            .Returns(Task.FromResult(new RoleResult()
            {
                Success = MockRolesRepository
                          .RolesRepositoryFailedRequest
                          .Object
                          .GetById(It.IsAny <int>(), It.IsAny <bool>())
                          .Result
                          .Success,
                Message = RolesMessages.RoleNotFoundMessage,
                Role    = (Role)MockRolesRepository
                          .RolesRepositoryFailedRequest
                          .Object
                          .GetById(It.IsAny <int>(), It.IsAny <bool>())
                          .Result
                          .Object
            } as IRoleResult));

            RolesServiceFailedRequest.Setup(rolesService =>
                                            rolesService.GetRoles(It.IsAny <bool>()))
            .Returns(Task.FromResult(new RolesResult()
            {
                Success = MockRolesRepository
                          .RolesRepositoryFailedRequest
                          .Object
                          .GetAll(It.IsAny <bool>())
                          .Result
                          .Success,
                Message = RolesMessages.RolesNotFoundMessage,
                Roles   = null
            } as IRolesResult));

            RolesServiceFailedRequest.Setup(rolesService =>
                                            rolesService.CreateRole(It.IsAny <string>(), It.IsAny <RoleLevel>()))
            .Returns(Task.FromResult(new RoleResult()
            {
                Success = MockRolesRepository
                          .RolesRepositoryFailedRequest
                          .Object
                          .Add(It.IsAny <Role>())
                          .Result
                          .Success,
                Message = RolesMessages.RoleNotCreatedMessage,
                Role    = (Role)MockRolesRepository
                          .RolesRepositoryFailedRequest
                          .Object
                          .Add(It.IsAny <Role>())
                          .Result
                          .Object
            } as IRoleResult));

            RolesServiceFailedRequest.Setup(rolesService =>
                                            rolesService.UpdateRole(It.IsAny <int>(), It.IsAny <UpdateRoleRequest>()))
            .Returns(Task.FromResult(new BaseResult()
            {
                Success = MockRolesRepository
                          .RolesRepositoryFailedRequest
                          .Object
                          .Update(It.IsAny <Role>())
                          .Result
                          .Success,
                Message = RolesMessages.RoleNotUpdatedMessage
            } as IBaseResult));

            RolesServiceFailedRequest.Setup(rolesService =>
                                            rolesService.DeleteRole(It.IsAny <int>()))
            .Returns(Task.FromResult(new BaseResult()
            {
                Success = MockRolesRepository
                          .RolesRepositoryFailedRequest
                          .Object
                          .Delete(It.IsAny <Role>())
                          .Result
                          .Success,
                Message = RolesMessages.RoleNotDeletedMessage
            } as IBaseResult));
        }