コード例 #1
0
        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());
        }
コード例 #2
0
ファイル: BaseTest.cs プロジェクト: mingyaaaa/Brochure
 /// <summary>
 /// Sets the mock service.
 /// </summary>
 /// <param name="mockService">The mock service.</param>
 private void SetMockService <T>(IMock <T> mockService) where T : class
 {
     Service.TryAddSingleton <T>(mockService.Object);
     MockService.Add(typeof(T), mockService);
 }