public TermsOfServiceService_Tests()
        {
            var config = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new TermsOfServiceSubmitResourceTermsOfServiceModel());
                cfg.AddProfile(new TermsOfServiceResourceTermsOfServiceModel());
            });

            mapper             = config.CreateMapper();
            termsOfServiceGuid = Guid.NewGuid();

            mockedTermsOfServiceModel = new TermsOfServiceModel
            {
                AgreementName             = "Test TermsOfService",
                Id                        = termsOfServiceGuid,
                TermsOfServiceAcceptances = new List <TermsOfServiceUserAcceptanceModel>()
            };

            mockedTermsOfServiceModel.Teams = new List <TeamModel>
            {
                new TeamModel
                {
                    TermsOfService = mockedTermsOfServiceModel,
                    Name           = "Team Name"
                }
            };

            mockedTermsOfServiceSubmitModel = new TermsOfServiceSubmit()
            {
                Uuid          = mockedTermsOfServiceModel.Id,
                AgreementName = mockedTermsOfServiceModel.AgreementName,
            };
        }
Exemplo n.º 2
0
 internal TermsOfService(Api api, TermsOfServiceModel model)
 {
     _api      = api;
     Id        = model.Id;
     TermsType = model.TermsType;
     Passive   = model.Passive;
     AccountId = model.AccountId;
     Content   = model.Content;
 }
Exemplo n.º 3
0
        private async Task ValidateTermsOfServiceEntry(Guid?termsOfServiceId)
        {
            if (termsOfServiceId == null)
            {
                return;
            }

            TermsOfServiceModel existingTermsOfService = await termsOfServiceRepository.GetByIdAsync((Guid)termsOfServiceId, includeRelations : false, includeFileContents : false);

            if (existingTermsOfService == null)
            {
                throw new ItemNotFoundException($"TermsOfService entry with Id '{termsOfServiceId} not found.");
            }
        }
Exemplo n.º 4
0
        /// <inheritdoc />
        public RequestResult <TermsOfServiceModel> GetActiveTermsOfService()
        {
            this.logger.LogDebug($"Getting active terms of service...");
            DBResult <LegalAgreement> retVal = this.legalAgreementDelegate.GetActiveByAgreementType(LegalAgreementType.TermsofService);

            return(new RequestResult <TermsOfServiceModel>()
            {
                ResultStatus = retVal.Status != DBStatusCode.Error ? ResultType.Success : ResultType.Error,
                ResourcePayload = TermsOfServiceModel.CreateFromDbModel(retVal.Payload),
                ResultError = retVal.Status != DBStatusCode.Error ? null : new RequestResultError()
                {
                    ResultMessage = retVal.Message, ErrorCode = ErrorTranslator.ServiceError(ErrorType.CommunicationInternal, ServiceType.Database)
                },
            });
        }
        public void ShouldGetLastTermsOfService()
        {
            // Setup
            var termsOfService = new TermsOfServiceModel()
            {
                Id            = Guid.NewGuid(),
                Content       = "abc",
                EffectiveDate = DateTime.Today
            };
            RequestResult <TermsOfServiceModel> expectedResult = new RequestResult <TermsOfServiceModel>()
            {
                ResultStatus    = ResultType.Success,
                ResourcePayload = termsOfService,
            };

            Mock <IUserProfileService> userProfileServiceMock = new Mock <IUserProfileService>();

            userProfileServiceMock.Setup(s => s.GetActiveTermsOfService()).Returns(expectedResult);

            Mock <IHttpContextAccessor> httpContextAccessorMock = CreateValidHttpContext(token, userId, hdid);
            Mock <IUserEmailService>    emailServiceMock        = new Mock <IUserEmailService>();
            Mock <IUserSMSService>      smsServiceMock          = new Mock <IUserSMSService>();

            UserProfileController service = new UserProfileController(
                new Mock <ILogger <UserProfileController> >().Object,
                userProfileServiceMock.Object,
                httpContextAccessorMock.Object,
                emailServiceMock.Object,
                smsServiceMock.Object
                );

            var actualResult = service.GetLastTermsOfService();

            Assert.IsType <JsonResult>(actualResult);
            Assert.True(((JsonResult)actualResult).Value.IsDeepEqual(expectedResult));
        }
        public TermsOfServiceController_Tests()
        {
            var mockOptionsAccessor    = Substitute.For <IOptions <IdentityOptions> >();
            var mockPasswordHasher     = Substitute.For <IPasswordHasher <UserModel> >();
            var mockUserValidators     = Substitute.For <IEnumerable <IUserValidator <UserModel> > >();
            var mockPasswordValidators = Substitute.For <IEnumerable <IPasswordValidator <UserModel> > >();
            var mockKeyNormalizer      = Substitute.For <ILookupNormalizer>();
            var mockErrors             = Substitute.For <IdentityErrorDescriber>();
            var mockServices           = Substitute.For <IServiceProvider>();
            var mockUserLogger         = Substitute.For <ILogger <UserManager <UserModel> > >();
            var fakeA3SContext         = new A3SContextFake(new Microsoft.EntityFrameworkCore.DbContextOptions <A3SContext>());

            mockConfiguration = Substitute.For <IConfiguration>();
            var fakesCustomUserStore = new CustomUserStoreFake(fakeA3SContext, mockConfiguration);

            fakeUserManager = new CustomUserManagerFake(fakesCustomUserStore, mockOptionsAccessor, mockPasswordHasher, mockUserValidators, mockPasswordValidators, mockKeyNormalizer,
                                                        mockErrors, mockServices, mockUserLogger);

            var mockContextAccessor = Substitute.For <IHttpContextAccessor>();
            var mocClaimsFactory    = Substitute.For <IUserClaimsPrincipalFactory <UserModel> >();
            var mockSignInLogger    = Substitute.For <ILogger <SignInManager <UserModel> > >();
            var mockLdapAuthenticationModeRepository = Substitute.For <LdapAuthenticationModeRepository>(fakeA3SContext, mockConfiguration);
            var mockLdapConnectionService            = Substitute.For <ILdapConnectionService>();

            mockAuthenticationSchemeProvider = Substitute.For <IAuthenticationSchemeProvider>();
            var mockUserConfirmation = Substitute.For <IUserConfirmation <UserModel> >();

            fakeSignInManager = new CustomSignInManagerFake <UserModel>(fakeUserManager, mockContextAccessor, mocClaimsFactory, mockOptionsAccessor, mockSignInLogger, fakeA3SContext,
                                                                        mockAuthenticationSchemeProvider, mockLdapAuthenticationModeRepository, mockLdapConnectionService, mockUserConfirmation);

            termsOfServiceRepository             = Substitute.For <ITermsOfServiceRepository>();
            mockClientStore                      = Substitute.For <IClientStore>();
            mockEventService                     = Substitute.For <IEventService>();
            mockIdentityServerInteractionService = Substitute.For <IIdentityServerInteractionService>();

            userModel = new UserModel()
            {
                UserName = "******",
                Id       = Guid.NewGuid().ToString()
            };

            termsOfServiceModel = new TermsOfServiceModel()
            {
                AgreementName = "Test agreement",
                Version       = "2019.1",
                HtmlContents  = "<html />",
                CssContents   = ".my-class { font-size: 2; }"
            };

            // Prepare controller contexts
            authorizationRequest = new AuthorizationRequest()
            {
                IdP       = "testIdp",
                ClientId  = "clientId1",
                LoginHint = "LoginHint"
            };

            client = new Client()
            {
                EnableLocalLogin = true
            };
        }