private ProviderMatch SetupComparedProviderDetails(OrganizationLicense orgLicense, List <ClauseMatch> comparedClauses) { // Get provider endpoint var endpoint = _providerEndpoints.FirstOrDefault(i => i.ID == orgLicense.ProviderEndpointID); // Get provider application var app = _applicationService.FirstOrDefault(i => i.ID == endpoint.ApplicationId); // Get provider organization var org = _organisations.FirstOrDefault(i => i.ID == app.OrganizationID); // Setup result var result = new ProviderMatch(); result.Clauses = new List <ClauseMatch>(); result.OrganizationName = org.Name; result.EndpointName = endpoint.Name; result.EndpointId = endpoint.ID; result.ProviderLicenseId = orgLicense.ID; // Setup compared clauses result.Clauses = comparedClauses; // Setup provider match flag result.IsMatch = !comparedClauses.Any(i => i.IsMatched == false); //result.IsMatch = true; // Return result return(result); }
private CustomFileDetails GetTemplatedLicenseForDownload(OrganizationLicense license, int providerOrgId, int consumerOrgId, string urlToSchema) { var result = new CustomFileDetails(); // Get license template var template = _licenseTemplates.FirstOrDefault(i => i.ID == license.LicenseTemplateID.Value); // Get license document var licenseDocument = _licenseContentBuilder.GetLicenseContent(organizationLicenseId: license.ID); // Get schema file var schemaFile = _schemaFiles.FirstOrDefault(i => i.DataSchemaID == license.DataSchemaID); // Build content for templated license _licenseContentBuilder.InsertLicenseDetails(licenseDocument, urlToSchema, _config.DataLinkerHost, providerOrgId, consumerOrgId); // Generate pdf file with content var pdfDocument = new HtmlToPdfConverter { PageFooterHtml = _licenseContentBuilder.GetFooterText(license.Status, _config.DataLinkerHost) }; var bytes = pdfDocument.GeneratePdf(licenseDocument.OuterXml); // Setup result result.Content = bytes; result.MimeType = "application/pdf"; result.FileName = $"{template.Name}.pdf"; // Return result return(result); }
private void SaveProviderLicense(int licenseTemplateId, int schemaId, int applicationId, List <SectionsWithClauses> model, LoggedInUserDetails user) { // Get endpoint var endpoint = _endpoints.Where(i => i.ApplicationId == applicationId) .FirstOrDefault(i => i.DataSchemaID == schemaId); // Setup organization license var license = new OrganizationLicense { LicenseTemplateID = licenseTemplateId, ApplicationID = applicationId, DataSchemaID = schemaId, ProviderEndpointID = endpoint.ID, CreatedBy = user.ID.Value, CreatedAt = GetDate, Status = (int)TemplateStatus.Draft }; // Save organization license _service.Add(license); // Save license clauses foreach (var section in model) { // Skip not selected section if (!_licenseClauses.IsClauseSelected(section)) { continue; } var selectedClause = section.Clauses.First(p => p.ClauseTemplateId == section.SelectedClause); var clause = SetupLicenseClause(selectedClause, license, user); _licenseClauseService.Add(clause); } }
public async Task CreateConnection_Success(OrganizationConnectionRequestModel model, BillingSyncConfig config, Guid cloudOrgId, OrganizationLicense organizationLicense, SutProvider <OrganizationConnectionsController> sutProvider) { organizationLicense.Id = cloudOrgId; model.Config = JsonDocumentFromObject(config); var typedModel = new OrganizationConnectionRequestModel <BillingSyncConfig>(model); typedModel.ParsedConfig.CloudOrganizationId = cloudOrgId; sutProvider.GetDependency <IGlobalSettings>().SelfHosted.Returns(true); sutProvider.GetDependency <ICreateOrganizationConnectionCommand>().CreateAsync <BillingSyncConfig>(default)
private OrganizationLicenseClause SetupLicenseClause(ClauseModel clause, OrganizationLicense license, LoggedInUserDetails user) { var clauseValue = _licenseClauses.GetClauseData(clause); var consumerClause = new OrganizationLicenseClause { LicenseClauseID = clause.ClauseId, OrganizationLicenseID = license.ID, CreatedBy = user.ID.Value, CreatedAt = GetDate, ClauseData = clauseValue }; return(consumerClause); }
private OrganisationLicenseType GetType(OrganizationLicense license) { // Setup default license type var licenseType = OrganisationLicenseType.FromTemplate; // Check whether license is custom if (license.CustomLicenseID != null) { licenseType = OrganisationLicenseType.Custom; } // Return license type return(licenseType); }
private string GetLicenseContent(OrganizationLicense licenseToProceed, int organisationId, OrganisationLicenseType type) { // Define result var result = string.Empty; OrganizationLicense license = licenseToProceed; // Check whether license is for consumer if (licenseToProceed.ProviderEndpointID == 0) { // Get license match var licenseMatch = _licenseMatches.FirstOrDefault(i => i.ConsumerLicenseID == licenseToProceed.ID); // Use provider license for generating content license = _orgLicenses.GetById(licenseMatch.ProviderLicenseID); } // Setup license content for license type switch (type) { case OrganisationLicenseType.FromTemplate: { // Get schema file var schemaFile = _schemaFiles.FirstOrDefault(i => i.DataSchemaID == license.DataSchemaID); // Setup url to schema var urlToSchema = _urls.ToDownloadSchema(schemaFile.ID); // Get content for license var licenseDocument = _licenseContent.GetLicenseContent(organizationLicenseId: license.ID); // Setup license content with details _licenseContent.InsertLicenseDetails(licenseDocument, urlToSchema, _config.DataLinkerHost, organisationId, license.ProviderEndpointID != 0); result = licenseDocument.OuterXml; break; } case OrganisationLicenseType.Custom: { // Get content for license var urlToDownloadLicese = _urls.ToDownloadLicense(license.ApplicationID, license.DataSchemaID, license.ID); result = urlToDownloadLicese; break; } } // return result return(result); }
public void CreateConsumerTemplatedLicense(int appId, int schemaId, int providerLicenseId, LoggedInUserDetails user) { // Check whether organisation is active if (!user.Organization.IsActive) { throw new BaseException(orgIsInactiveError); } // Get published template var licenseTemplate = _licenseTemplates.FirstOrDefault(i => i.Status == (int)TemplateStatus.Active); var providerLicense = _service.GetById(providerLicenseId); if (providerLicense == null) { throw new BaseException($"Provider license not found {providerLicenseId}"); } // Create consumer license var consumerLicense = new OrganizationLicense { ApplicationID = appId, DataSchemaID = schemaId, LicenseTemplateID = providerLicense.LicenseTemplateID, CustomLicenseID = providerLicense.CustomLicenseID, CreatedAt = GetDate, Status = (int)PublishStatus.Draft, CreatedBy = user.ID.Value }; _service.Add(consumerLicense); // Setup consumer match var consumerMatch = new LicenseMatch { ConsumerLicenseID = consumerLicense.ID, ProviderLicenseID = providerLicenseId, CreatedBy = user.ID.Value, CreatedAt = GetDate }; // Save consumer match _licenseMatches.Add(consumerMatch); // Send for legal approval RequestLicenseVerification(consumerLicense.ID, appId, schemaId, user); }
public List <OrganizationLicense> CreateConsumerCustomLicense(int appId, int schemaId, List <DataProvider> providers, LoggedInUserDetails user) { // Check access to application _security.CheckAccessToApplication(user, appId); // Get selected provider licenses var selectedProviders = providers.Where(i => i.IsSelected == true); // Define result var result = new List <OrganizationLicense>(); // Create organisation license with the same custom license id foreach (var providerLicense in selectedProviders) { var consumerLicense = new OrganizationLicense { ApplicationID = appId, DataSchemaID = schemaId, CustomLicenseID = providerLicense.CustomLicenseId, CreatedBy = user.ID.Value, CreatedAt = GetDate, Status = (int)PublishStatus.Draft }; // Save new consumer license to database _service.Add(consumerLicense); // Create license match for consumer & provider license var licenseMatch = new LicenseMatch { ConsumerLicenseID = consumerLicense.ID, ProviderLicenseID = providerLicense.LicenseId, CreatedAt = GetDate, CreatedBy = user.ID.Value }; // Save new license match _licenseMatches.Add(licenseMatch); // Add created license to result result.Add(consumerLicense); } // Return created data return(result); }
private void SendNotificationToLegalOfficers(OrganizationLicense license, List <User> legalOfficers, string schemaName, string urlToSchema, LoggedInUserDetails user) { // Send notification to legal officers foreach (var legalOfficer in legalOfficers) { // Generate secure token var tokenInfo = _tokens.GenerateLicenseVerificationToken(legalOfficer.ID, license.ID); // Create approval request var request = new LicenseApprovalRequest { accessToken = tokenInfo.TokenInfoEncoded, Token = tokenInfo.Token, ExpiresAt = tokenInfo.TokenExpire.Value, OrganizationLicenseID = license.ID, SentAt = GetDate, SentBy = user.ID.Value, SentTo = legalOfficer.ID }; // Save request _verificationRequests.Add(request); // Setup url to confirmation screen var urlToConfirmScreen = _urls.ToLicenseVerification(license.ApplicationID, license.DataSchemaID, tokenInfo.TokenInfoEncoded); // Send notificaion to legal officer with templated license if (license.LicenseTemplateID != null) { // Send notification _notificationService.LegalOfficer.LicenseIsPendingApprovalInBackground(legalOfficer.ID, $"{urlToConfirmScreen}#Clauses", urlToSchema, _config.DataLinkerHost, schemaName, license.ID); } // Send notificaion to legal officer with custom license if (license.CustomLicenseID != null) { // Send notification _notificationService.LegalOfficer.LicenseVerificationRequiredInBackground(legalOfficer.ID, urlToConfirmScreen, schemaName, license.ID); } } }
private void CreateOrganisationLicense(int applicationId, int schemaId, LoggedInUserDetails user, int customLicenseId) { // Get provider endpoint var endpoint = _endpoints.Where(i => i.ApplicationId == applicationId).FirstOrDefault(i => i.DataSchemaID == schemaId); // Setup organisation license for custom license var orgLicense = new OrganizationLicense { ApplicationID = applicationId, CreatedAt = GetDate, CreatedBy = user.ID.Value, ProviderEndpointID = endpoint.ID, DataSchemaID = schemaId, Status = (int)PublishStatus.Draft, CustomLicenseID = customLicenseId }; // Save organisation license _orgLicenses.Add(orgLicense); }
public void Init() { sysAdmin = new User { Email = "*****@*****.**", ID = 1, IsActive = true, IsSysAdmin = true, OrganizationID = 2 }; otherOrganization = new Organization { ID = 3, Name = "OrgName3", IsActive = true }; user = new User { Email = "*****@*****.**", ID = 2, IsSysAdmin = false, OrganizationID = 2 }; otherUser = new User { Email = "*****@*****.**", ID = 3, IsSysAdmin = false, OrganizationID = otherOrganization.ID }; organization = new Organization { ID = 2, Name = "OrgName2", IsActive = true }; activeService = new Application { OrganizationID = organization.ID, IsActive = true, Name = "activeService", PublicID = new Guid("421befd1-ef28-4c25-bcf6-5ead09dabb71"), ID = 1, IsIntroducedAsIndustryGood = true, IsProvider = true }; consumerApplication = new Application { OrganizationID = 2, IsActive = true, Name = "active applications", PublicID = new Guid("421befd1-ef28-4c25-bcf6-5ead09dabb71"), ID = 4, IsProvider = false }; notActiveService = new Application { OrganizationID = 2, IsActive = false, Name = "notActiveService", PublicID = new Guid("421befd1-ef28-4c25-bcf6-5ead09dabb71"), ID = 2, IsProvider = false }; otherService = new Application { OrganizationID = 3, IsActive = true, Name = "otherService", PublicID = new Guid("421befd1-ef28-4c25-bcf6-5ead09dabb71"), ID = 3, IsProvider = false }; dataSchema = new DataSchema { ID = 1, Name = "Schema1" }; providerEndpoint = new ProviderEndpoint { ApplicationId = activeService.ID, ID = 1, DataSchemaID = dataSchema.ID, IsIndustryGood = true, Description = "Description" }; licenseTemplate = new LicenseTemplate { ID = 1, LicenseID = 1, Status = (int)TemplateStatus.Active }; _organizationLicense = new OrganizationLicense { ID = 1, Status = (int)PublishStatus.Published, ProviderEndpointID = providerEndpoint.ID, DataSchemaID = providerEndpoint.DataSchemaID, LicenseTemplateID = licenseTemplate.ID }; applicationToken = new ApplicationToken { ID = 1, ApplicationID = activeService.ID, Token = "token" }; appService = new Mock <IApplicationsService>(); _userService = new Mock <IUserService>(); orgService = new Mock <IOrganizationService>(); schemaService = new Mock <IDataSchemaService>(); endpointService = new Mock <IProviderEndpointService>(); licenseTemplateService = new Mock <ILicenseTemplatesService>(); sectionService = new Mock <ILicenseSectionService>(); clauseService = new Mock <ILicenseClauseService>(); clauseTemplateService = new Mock <ILicenseClauseTemplateService>(); endpointLicClauseService = new Mock <IOrganizationLicenseClauseService>(); licenseService = new Mock <IOrganizationLicenseService>(); notificationService = new Mock <INotificationService>(); applicationTokenService = new Mock <IService <ApplicationToken> >(); applicationAuthenticationService = new Mock <IService <ApplicationAuthentication> >(); configService = new Mock <IConfigurationService>(); licenseContentBuilder = new Mock <ILicenseContentBuilder>(); adminNotificationService = new Mock <IAdminNotificationService>(); // Notification service notificationService.Setup(i => i.Admin).Returns(adminNotificationService.Object); configService.SetupProperty(p => p.ManageApplicationsPageSize, 5); var mockUrl = new Mock <UrlHelper>(); // Setup application token service applicationTokenService.Setup(i => i.Get(applicationToken.ID)).Returns(applicationToken); applicationTokenService.Setup(i => i.Add(It.IsAny <ApplicationToken>())).Returns(true); applicationTokenService.Setup(i => i.Update(It.IsAny <ApplicationToken>())).Returns(true); // Schema service schemaService.Setup(p => p.Get(dataSchema.ID)).Returns(dataSchema); schemaService.Setup(p => p.Get(10)).Returns(new DataSchema { ID = 10, IsIndustryGood = false }); schemaService.Setup(p => p.GetPublishedSchemas()).Returns(new List <DataSchema> { dataSchema, new DataSchema { ID = 10, IsIndustryGood = false } }); // Endpoint service endpointService.Setup(p => p.Get(It.IsAny <Expression <Func <ProviderEndpoint, bool> > >())) .Returns(new List <ProviderEndpoint> { providerEndpoint }); endpointService.Setup(p => p.Get(providerEndpoint.ID)).Returns(providerEndpoint); licenseService.Setup(p => p.Get(It.IsAny <Expression <Func <OrganizationLicense, bool> > >())) .Returns(new List <OrganizationLicense> { _organizationLicense }); // License template service licenseTemplateService.Setup(p => p.GetAll(false)).Returns(new List <LicenseTemplate> { licenseTemplate }); licenseTemplateService.Setup(p => p.GetPublishedGlobalLicense()).Returns(licenseTemplate); // Application service appService.Setup(p => p.GetApplicationsFor((int)user.OrganizationID)) .Returns(new List <Application> { activeService, notActiveService }); appService.Setup(p => p.GetAllApplications()) .Returns(new List <Application> { activeService, otherService, notActiveService }); appService.Setup(p => p.Get(activeService.ID)).Returns(activeService); appService.Setup(p => p.Get(notActiveService.ID)).Returns(notActiveService); appService.Setup(p => p.Get(otherService.ID)).Returns(otherService); appService.Setup(p => p.Get(consumerApplication.ID)).Returns(consumerApplication); appService.Setup(p => p.GetAuthenticationFor(activeService.ID)).Returns(new ApplicationAuthentication()); // Organization service orgService.Setup(p => p.Get(organization.ID)).Returns(organization); orgService.Setup(p => p.Get(otherOrganization.ID)).Returns(otherOrganization); var context = new Mock <ControllerContext>(); context.Setup(m => m.HttpContext.Request.Form).Returns(new FormCollection()); context.Setup(m => m.HttpContext.Request.Url).Returns(new Uri("http://test.com")); context.Setup(m => m.HttpContext.Request.Browser).Returns(new Mock <HttpBrowserCapabilitiesBase>().Object); controller = new ApplicationsController(appService.Object, applicationTokenService.Object, applicationAuthenticationService.Object, _userService.Object, orgService.Object, schemaService.Object, endpointService.Object, licenseService.Object, configService.Object, notificationService.Object); controller.ControllerContext = context.Object; controller.Url = mockUrl.Object; }
public async Task CreateConnection_BillingSyncType_InvalidLicense_Throws(OrganizationConnectionRequestModel model, BillingSyncConfig config, Guid cloudOrgId, OrganizationLicense organizationLicense, SutProvider <OrganizationConnectionsController> sutProvider) { model.Type = OrganizationConnectionType.CloudBillingSync; organizationLicense.Id = cloudOrgId; model.Config = JsonDocumentFromObject(config); var typedModel = new OrganizationConnectionRequestModel <BillingSyncConfig>(model); typedModel.ParsedConfig.CloudOrganizationId = cloudOrgId; sutProvider.GetDependency <ICurrentContext>() .OrganizationOwner(model.OrganizationId) .Returns(true); sutProvider.GetDependency <ILicensingService>() .ReadOrganizationLicenseAsync(model.OrganizationId) .Returns(organizationLicense); sutProvider.GetDependency <ILicensingService>() .VerifyLicense(organizationLicense) .Returns(false); await Assert.ThrowsAsync <BadRequestException>(async() => await sutProvider.Sut.CreateConnection(model)); }
private void SendNotificationToLegalOfficers(OrganizationLicense license, int consumerProviderRegistrationId, List <User> legalOfficers, string schemaName, string urlToSchema, LoggedInUserDetails user, bool toProviderLegal) { // Send notification to legal officers foreach (var legalOfficer in legalOfficers) { // Generate secure token //var tokenInfo = _tokens.GenerateLicenseVerificationToken(legalOfficer.ID, license.ID); var tokenInfo = _tokens.GenerateConsumerProviderRegistrationToken(legalOfficer.ID, license.ID, consumerProviderRegistrationId); // Create approval request var request = new LicenseApprovalRequest { accessToken = tokenInfo.TokenInfoEncoded, Token = tokenInfo.Token, ExpiresAt = tokenInfo.TokenExpire.Value, OrganizationLicenseID = license.ID, SentAt = DateTime.UtcNow, SentBy = user.ID.Value, SentTo = legalOfficer.ID }; // Save request _verificationRequests.Add(request); // Setup url to confirmation screen // var urlToConfirmScreen = _urls.ToLicenseVerification(license.ApplicationID, license.DataSchemaID, tokenInfo.TokenInfoEncoded); var urlToConfirmScreen = $"{_config.DataLinkerHost}/consumer-provider-registration/{consumerProviderRegistrationId}/consumer-legal-approval?token={tokenInfo.TokenInfoEncoded}"; if (toProviderLegal) { urlToConfirmScreen = $"{_config.DataLinkerHost}/consumer-provider-registration/{consumerProviderRegistrationId}/provider-legal-approval?token={tokenInfo.TokenInfoEncoded}"; } if (license.LicenseTemplateID != null) { urlToConfirmScreen = $"{urlToConfirmScreen}#Clauses"; } // Send notificaion to legal officer with templated license //if (license.LicenseTemplateID != null) //{ if (toProviderLegal) { _notificationService.ConsumerProviderRegistration.ProviderLegalApprovalRequestInBackground(legalOfficer.ID, urlToConfirmScreen, urlToSchema, _config.DataLinkerHost, schemaName, consumerProviderRegistrationId); } else { _notificationService.ConsumerProviderRegistration.ConsumerLegalApprovalRequestInBackground(legalOfficer.ID, urlToConfirmScreen, urlToSchema, _config.DataLinkerHost, schemaName, consumerProviderRegistrationId); } //} //// Send notificaion to legal officer with custom license //if (license.CustomLicenseID != null) //{ // if(toProviderLegal) // { // _notificationService.ConsumerProviderRegistration.ProviderLegalCustomLicenseApprovalRequestInBackground(legalOfficer.ID, urlToConfirmScreen, schemaName, license.ID); // } // else // { // _notificationService.ConsumerProviderRegistration.ConsumerLegalCustomLicenseApprovalRequestInBackground(legalOfficer.ID, urlToConfirmScreen, schemaName, license.ID); // } //} } }
private string GetRecordForLicense(List <LicenseMatch> consumerMatchesForMonth, OrganizationLicense providerLicense) { var licenseMatches = consumerMatchesForMonth.Where(i => i.ProviderLicenseID == providerLicense.ID).ToList(); var endpoint = _providerEndpoints.FirstOrDefault(i => i.ID == providerLicense.ProviderEndpointID); var schema = _schemas.FirstOrDefault(i => i.ID == endpoint.DataSchemaID); var providerApp = _applications.FirstOrDefault(i => i.ID == endpoint.ApplicationId); var provider = _organisations.FirstOrDefault(i => i.ID == providerApp.OrganizationID); // Add to report if consumers have any license matches to provider's license if (licenseMatches.Any()) { foreach (var licenseMatch in licenseMatches) { var consumerLicense = _licenses.FirstOrDefault(i => i.ID == licenseMatch.ConsumerLicenseID); var consumerApp = _applications.FirstOrDefault(i => i.ID == consumerLicense.ApplicationID); var consumer = _organisations.FirstOrDefault(i => i.ID == consumerApp.OrganizationID); return($"{provider.Name}:{endpoint.Name},{schema.Name},{consumer.Name}"); } } return($"{provider.Name}:{endpoint.Name},{schema.Name}"); }
public LicenseConfirmModel GetConfirmModel(string token, LoggedInUserDetails user) { OrganizationLicense license = null; LicenseApprovalRequest request = null; try { // Check access _security.CheckBasicAccess(user); // Process token var tokenInfo = _tokens.ParseLicenseVerificationToken(token); // Get license license = _orgLicenses.FirstOrDefault(i => i.ID == tokenInfo.ID.Value); // Get request request = _verificationRequests.FirstOrDefault(i => i.Token == tokenInfo.Token); // Check whether token exists if (request == null) { throw new BaseException("Access denied."); } // Check whether token belongs to user if (request.SentTo != user.ID.Value) { request.ExpiresAt = GetDate; _verificationRequests.Update(request); throw new BaseException("Access denied."); } // Check whether token expired if (request.ExpiresAt != tokenInfo.TokenExpire || request.ExpiresAt < DateTime.Now) { throw new BaseException( "Approval link is expired."); } // Check whether user is Legal officer for organisation CheckForLegalOfficer(user); // Check whether organisation is active if (!user.Organization.IsActive) { throw new BaseException( "Your organization is inactive. Please check if your organization has approved Legal Officer. For more details contact DataLinker team."); } // Check whether licese is pending approval if (license.Status != (int)PublishStatus.PendingApproval) { throw new BaseException("This license is not pending approval."); } // Get organisation details var organization = _organisations.FirstOrDefault(i => i.ID == user.Organization.ID); // Determine license type var type = GetType(license); // Get content for license var licenseContent = GetLicenseContent(license, organization.ID, type); // Setup result var result = new LicenseConfirmModel { OrganizationName = organization.Name, ID = license.ID, LicenseContent = licenseContent, Type = type, IsProvider = license.ProviderEndpointID != 0 }; // Return result return(result); } catch (BaseException) { // Set license status to draft if (license != null && license.Status == (int)PublishStatus.PendingApproval) { license.Status = (int)PublishStatus.Draft; _orgLicenses.Update(license); } throw; } finally { // Always expire request if (request != null) { request.ExpiresAt = GetDate; _verificationRequests.Update(request); } } }
public void Init() { schema = new DataSchema { PublicID = validSchema, Status = (int)TemplateStatus.Active, ID = 1 }; organization = new Organization { ID = 1, Name = "Org", IsActive = true }; providerApplication = new Application { PublicID = Guid.Parse("E86FA7A0-04EB-4B68-821E-7E221FEC4368"), ID = 1, Name = "application", IsProvider = true, OrganizationID = organization.ID }; consumerApplication = new Application { PublicID = Guid.Parse("b95c549e-d711-4597-89e0-fdc33d1d17ca"), ID = 2, Name = "application", IsProvider = false, OrganizationID = organization.ID }; organizationLicense = new OrganizationLicense { ApplicationID = providerApplication.ID, ID = 1, Status = (int)PublishStatus.Published, LicenseTemplateID = 1, ProviderEndpointID = 1, DataSchemaID = schema.ID }; _organizationService = new Mock <IOrganizationService>(); _applicationService = new Mock <IApplicationsService>(); _orgLicenseService = new Mock <IOrganizationLicenseService>(); _dataSchemaService = new Mock <IDataSchemaService>(); _agreementService = new Mock <ILicenseAgreementService>(); _notificationService = new Mock <INotificationService>(); _schemaFileService = new Mock <ISchemaFileService>(); _softwareStatementService = new Mock <ISoftwareStatementService>(); _legalOfficerNotificationService = new Mock <ILegalOfficerNotificationService>(); //Setup notification service _notificationService.SetupGet(i => i.LegalOfficer).Returns(_legalOfficerNotificationService.Object); // Setup Matches service mService = new MockService <LicenseMatch>(); matchesService = new LicenseMatchesService(mService); mService.Add(new LicenseMatch { ConsumerLicenseID = organizationLicense.ID }); mService.Add(new LicenseMatch { ProviderLicenseID = organizationLicense.ID, ConsumerLicenseID = organizationLicense.ID }); // Setup license service _orgLicenseService.Setup(i => i.GetForApplicationAndSchema(providerApplication.ID, schema.ID, true)) .Returns(new List <OrganizationLicense> { organizationLicense }); _orgLicenseService.Setup(i => i.GetForApplicationAndSchema(consumerApplication.ID, schema.ID, true)) .Returns(new List <OrganizationLicense> { organizationLicense }); _orgLicenseService.Setup(i => i.GetForApplicationAndSchema(0, schema.ID, true)).Returns(new List <OrganizationLicense>()); // Setup schemaFile _schemaFileService.Setup(i => i.Get(It.IsAny <Expression <Func <SchemaFile, bool> > >())) .Returns(new List <SchemaFile> { new SchemaFile() }); // Setup license agreement _agreementService.Setup(i => i.Add(It.IsAny <LicenseAgreement>())).Returns(true); // Setup application service _applicationService.Setup(i => i.Get(providerApplication.ID)).Returns(providerApplication); _applicationService.Setup(i => i.Get(consumerApplication.ID)).Returns(consumerApplication); _applicationService.Setup(i => i.Get(It.IsAny <Expression <Func <Application, bool> > >())) .Returns(new List <Application> { consumerApplication }); // Setup data schema service _dataSchemaService.Setup(i => i.Get(validSchema)).Returns(schema); // Setup Statement _softwareStatementService.SetupGet(i => i.TokenValidationParameters).Returns(TokenValidationParameters); context = new Mock <HttpRequestMessage>(); _controller = new LicenseAgreementsController(_organizationService.Object, _applicationService.Object, _orgLicenseService.Object, _dataSchemaService.Object, _agreementService.Object, _notificationService.Object, _schemaFileService.Object, _softwareStatementService.Object, matchesService) { Request = context.Object, LoggedInApp = new LoggedInApplication(providerApplication) { TokenUsedToAuthorize = applicationToken, Organization = new LoggedInOrganization(organization) } }; _controller.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration()); }
public void Init() { schemaModel = new SchemaModel { DataSchemaID = 1, Description = "Blah blah", Name = "Name", Status = TemplateStatus.Draft, Version = 1 }; dSchemaDraft = new DataSchema { ID = 1, Name = "Draft", CreatedBy = 1, CreatedAt = today, Status = (int)TemplateStatus.Draft }; dSchemaPublished = new DataSchema { ID = 2, Name = "Published", CreatedAt = today, CreatedBy = 1, PublishedAt = today }; dSchemaRetracted = new DataSchema { ID = 3, Name = "Retracted", CreatedAt = today, Status = (int)TemplateStatus.Retracted }; schemaFile = new SchemaFile { DataSchemaID = dSchemaDraft.ID, CreatedBy = 1, FileFormat = ".xml", ID = 1 }; consumerOrganization = new Organization { ID = 1 }; providerOrganization = new Organization { ID = 2 }; providerApplication = new Application { ID = 1, OrganizationID = providerOrganization.ID }; consumerApplication = new Application { ID = 2, OrganizationID = consumerOrganization.ID }; providerLicense = new OrganizationLicense { ID = 1, ApplicationID = providerApplication.ID }; consumerLicense = new OrganizationLicense { ID = 2, ApplicationID = consumerApplication.ID }; licenseMatch = new LicenseMatch { ID = 1, ConsumerLicenseID = consumerLicense.ID, ProviderLicenseID = providerLicense.ID }; endpoint = new ProviderEndpoint { ApplicationId = providerApplication.ID, DataSchemaID = dSchemaPublished.ID, IsActive = true }; var file = new Mock <HttpPostedFileBase>(); file.Setup(i => i.InputStream).Returns(new MemoryStream()); file.Setup(i => i.FileName).Returns("file.xml"); schemaModel.UploadFile = file.Object; var mock = new Mock <UrlHelper>(); // Setup file var fileMock = new Mock <HttpPostedFileBase>(); fileMock.Setup(x => x.FileName).Returns("file1.xml"); var context = new Mock <ControllerContext>(); context.Setup(m => m.HttpContext.Request.Files.Count).Returns(1); context.Setup(m => m.HttpContext.Request.Files[0]).Returns(fileMock.Object); context.Setup(m => m.HttpContext.Request.Url).Returns(new Uri("http://test.com")); sysAdmin = new User { ID = 1, IsActive = true, Email = "*****@*****.**", IsSysAdmin = true }; // Setup Services metaDataService = new Mock <IDataSchemaService>(); fileService = new Mock <ISchemaFileService>(); organizationService = new Mock <IOrganizationService>(); userService = new Mock <IUserService>(); notificationService = new Mock <INotificationService>(); endpointService = new Mock <IProviderEndpointService>(); applicationService = new Mock <IApplicationsService>(); configurationService = new Mock <IConfigurationService>(); organizationLicenseService = new Mock <IOrganizationLicenseService>(); userService.Setup(u => u.Get(sysAdmin.ID)).Returns(sysAdmin); configurationService.SetupProperty(p => p.ManageSchemasPageSize, 5); // Setup organization service organizationService.Setup(m => m.Get(consumerOrganization.ID)).Returns(consumerOrganization); organizationService.Setup(m => m.Get(providerOrganization.ID)).Returns(providerOrganization); // Setup application service applicationService.Setup(m => m.Get(providerApplication.ID)).Returns(providerApplication); applicationService.Setup(m => m.Get(consumerApplication.ID)).Returns(consumerApplication); // Setup endpoint service endpointService.Setup(m => m.Get(endpoint.ID)).Returns(endpoint); // Setup organization licenses organizationLicenseService.Setup(i => i.Get(It.IsAny <Expression <Func <OrganizationLicense, bool> > >())) .Returns(new List <OrganizationLicense>()); organizationLicenseService.Setup(m => m.GetAllProviderLicensesForMonth(It.IsAny <DateTime>())) .Returns(new List <OrganizationLicense> { providerLicense }); organizationLicenseService.Setup(m => m.Get(consumerLicense.ID)).Returns(consumerLicense); // Schema file service fileService.Setup(m => m.Add(It.IsAny <SchemaFile>())).Returns(true); fileService.Setup(m => m.Update(It.IsAny <SchemaFile>())).Returns(true); fileService.Setup(m => m.Get(schemaFile.ID)).Returns(schemaFile); fileService.Setup(m => m.Get(It.IsAny <Expression <Func <SchemaFile, bool> > >())) .Returns(new List <SchemaFile> { schemaFile }); // Dataschema service metaDataService.Setup(m => m.GetAllSchemas(1, false)).Returns(new List <DataSchema> { dSchemaDraft }); metaDataService.Setup(m => m.Add(It.IsAny <DataSchema>())).Returns(true); metaDataService.Setup(m => m.Update(It.IsAny <DataSchema>())).Returns(true); metaDataService.Setup(m => m.Get(dSchemaDraft.ID)).Returns(dSchemaDraft); metaDataService.Setup(m => m.Get(dSchemaPublished.ID)).Returns(dSchemaPublished); metaDataService.Setup(m => m.Get(dSchemaRetracted.ID)).Returns(dSchemaRetracted); // License matches var mService = new MockService <LicenseMatch>(); matchesService = new LicenseMatchesService(mService); matchesService.Add(licenseMatch); // Setup controller controller = new SchemasController(metaDataService.Object, fileService.Object, userService.Object, organizationService.Object, endpointService.Object, applicationService.Object, notificationService.Object, organizationLicenseService.Object, matchesService, configurationService.Object) { ControllerContext = context.Object, LoggedInUser = new LoggedInUserDetails(sysAdmin), Url = mock.Object }; }