public new void Setup() { vendorName = string.Format("{0}_TestData", DateTime.Now.Ticks); leaId1 = int.MaxValue - 1; leaId2 = int.MaxValue - 2; DeleteApplicationEducationOrganization(leaId1); DeleteApplicationEducationOrganization(leaId2); DeleteVendor(vendorName); var leaQuery = Stub <ITemplateDatabaseLeaQuery>(); A.CallTo(() => leaQuery.GetLocalEducationAgencyIds(A <string> ._)) .Returns( new[] { leaId1, leaId2 }); var configValueProvider = Stub <IConfigValueProvider>(); A.CallTo(() => configValueProvider.GetValue("DefaultApplicationName")) .Returns(_defaultApplicationName); A.CallTo(() => configValueProvider.GetValue("DefaultClaimSetName")) .Returns(_defaultClaimSet); A.CallTo(() => configValueProvider.GetValue("DefaultOperationalContextUri")) .Returns(_defaultOperationalContextUri); var usersContextFactory = Stub <IUsersContextFactory>(); A.CallTo(() => usersContextFactory.CreateContext()) .Returns(new SqlServerUsersContext()); using (var context = new SqlServerUsersContext()) { var vendor = new Vendor { VendorName = vendorName }; var application = vendor.CreateApplication(_defaultApplicationName + " Sample", _defaultClaimSet); application.CreateApplicationEducationOrganization(leaId1); application.OperationalContextUri = _defaultOperationalContextUri; context.Vendors.Add(vendor); context.SaveChanges(); var creator = new DefaultApplicationCreator(usersContextFactory, leaQuery, configValueProvider); _foundApplication = creator.FindOrCreateUpdatedDefaultSandboxApplication(vendor.VendorId, SandboxType.Sample); context.SaveChanges(); _applications = context.Applications.Where(a => a.Vendor.VendorName == vendorName) .Include(x => x.ApplicationEducationOrganizations) .ToArray(); _loadedApplication = _applications.FirstOrDefault(); } }
public new void Setup() { _vendorName = $"{DateTime.Now.Ticks}_TestData"; _leaId = int.MaxValue - 1; DeleteApplicationEducationOrganization(_leaId); DeleteVendor(_vendorName); var leaQuery = Stub <ITemplateDatabaseLeaQuery>(); A.CallTo(() => leaQuery.GetLocalEducationAgencyIds(A <string> ._)) .Returns( new[] { _leaId }); var configValueProvider = Stub <IConfigValueProvider>(); A.CallTo(() => configValueProvider.GetValue("DefaultApplicationName")) .Returns(_defaultApplicationName); A.CallTo(() => configValueProvider.GetValue("DefaultClaimSetName")) .Returns(_defaultClaimSet); A.CallTo(() => configValueProvider.GetValue("DefaultOperationalContextUri")) .Returns(_defaultOperationalContextUri); var usersContextFactory = Stub <IUsersContextFactory>(); A.CallTo(() => usersContextFactory.CreateContext()) .Returns(new SqlServerUsersContext()); using (var context = new SqlServerUsersContext()) { var vendor = new Vendor { VendorName = _vendorName }; context.Vendors.Add(vendor); context.SaveChanges(); var creator = new DefaultApplicationCreator(usersContextFactory, leaQuery, configValueProvider); _createdApplication = creator.FindOrCreateUpdatedDefaultSandboxApplication(vendor.VendorId, SandboxType.Sample); context.SaveChanges(); _loadedApplication = context.Applications.Where( a => a.ApplicationName == _createdApplication.ApplicationName && a.Vendor.VendorName == _vendorName) .Include(x => x.ApplicationEducationOrganizations) .Single(); } }
protected override void Arrange() { _transaction = new TransactionScope(); var config = new ConfigurationBuilder() .SetBasePath(TestContext.CurrentContext.TestDirectory) .AddJsonFile("appsettings.json", optional: true) .AddEnvironmentVariables() .Build(); var connectionStringProvider = new ConfigConnectionStringsProvider(config); string connectionstring = connectionStringProvider.GetConnectionString("EdFi_Admin"); var usersContextFactory = A.Fake <IUsersContextFactory>(); A.CallTo(() => usersContextFactory.CreateContext()) .Returns(new SqlServerUsersContext(connectionstring)); var clientAppRepo = new ClientAppRepo(usersContextFactory, config); _testClient = new ApiClient(true) { Name = $"ClientAppRepoTest{Guid.NewGuid():N}", Secret = "MySecret" }; using (var context = new SqlServerUsersContext(connectionstring)) { context.Clients.Add(_testClient); context.SaveChanges(); } _apiClientSecretProvider = new EdFiAdminApiClientIdentityProvider(clientAppRepo); }
protected override void Arrange() { _transaction = new TransactionScope(); var configValueProviderStub = Stub <IConfigValueProvider>(); var usersContextFactory = A.Fake <IUsersContextFactory>(); A.CallTo(() => usersContextFactory.CreateContext()) .Returns(new SqlServerUsersContext()); var clientAppRepo = new ClientAppRepo(usersContextFactory, configValueProviderStub); _testClient = new ApiClient(true) { Name = $"ClientAppRepoTest{Guid.NewGuid():N}", Secret = "MySecret" }; using (var context = new SqlServerUsersContext()) { context.Clients.Add(_testClient); context.SaveChanges(); } _apiClientSecretProvider = new EdFiAdminApiClientIdentityProvider(clientAppRepo); }
private static void MockInstanceRegistrationSetup(List <OdsInstanceRegistration> odsInstanceRegistrations) { var odsInstances = odsInstanceRegistrations.Select(x => new OdsInstance { OdsInstanceId = x.Id, Name = x.Name, InstanceType = "Ods", IsExtended = false, Status = "OK", Version = "1.0.0" }).ToList(); var applications = odsInstances.Select(x => new Application { ApplicationName = x.Name.GetAdminApplicationName(), OperationalContextUri = OperationalContext.DefaultOperationalContextUri, OdsInstance = x }).ToList(); foreach (var application in applications) { var client = new ApiClient { Name = application.ApplicationName, Key = "test key", Secret = "test secret", ActivationCode = "test activation code" }; var clientAccessToken = new ClientAccessToken { ApiClient = client, Expiration = DateTime.Now.AddDays(1) }; var appEduOrganization = new ApplicationEducationOrganization { Application = application, EducationOrganizationId = application.OdsInstance.Name.ExtractNumericInstanceSuffix() }; client.ClientAccessTokens.Add(clientAccessToken); application.ApiClients.Add(client); application.ApplicationEducationOrganizations.Add(appEduOrganization); } using (var database = new SqlServerUsersContext()) { foreach (var odsInstance in odsInstances) { database.OdsInstances.Add(odsInstance); } foreach (var application in applications) { database.Applications.Add(application); } database.SaveChanges(); } }
protected override void Arrange() { _transaction = new TransactionScope(); var configValueProviderStub = Stub <IConfigValueProvider>(); var usersContextFactory = A.Fake <IUsersContextFactory>(); A.CallTo(() => usersContextFactory.CreateContext()) .Returns(new SqlServerUsersContext()); var clientAppRepo = new ClientAppRepo(usersContextFactory, configValueProviderStub); var edOrgs = _expectedEducationOrganizations .Select( edOrgId => new ApplicationEducationOrganization { EducationOrganizationId = edOrgId }) .ToList(); var profiles = _expectedProfiles.Select( profile => new Profile { ProfileName = profile }) .ToList(); var application = new Application { Profiles = profiles, ClaimSetName = "MyTestClaimSetName", Vendor = new Vendor { VendorNamespacePrefixes = new List <VendorNamespacePrefix> { new VendorNamespacePrefix { NamespacePrefix = "MyTestNamespacePrefix" } } }, OperationalContextUri = "uri://ed-fi-api-host.org" }; _testClient = new ApiClient(true) { Name = $"ClientAppRepoTest{Guid.NewGuid():N}", Application = application, ApplicationEducationOrganizations = edOrgs }; using (var context = new SqlServerUsersContext()) { context.Clients.Add(_testClient); context.SaveChanges(); } _apiClientIdentityProvider = new EdFiAdminApiClientIdentityProvider(clientAppRepo); }
protected override void Arrange() { _transaction = new TransactionScope(); var config = new ConfigurationBuilder() .SetBasePath(TestContext.CurrentContext.TestDirectory) .AddJsonFile("appsettings.json", optional: true) .AddEnvironmentVariables() .Build(); var connectionStringProvider = new ConfigConnectionStringsProvider(config); string connectionstring = connectionStringProvider.GetConnectionString("EdFi_Admin"); var usersContextFactory = A.Fake <IUsersContextFactory>(); A.CallTo(() => usersContextFactory.CreateContext()) .Returns(new SqlServerUsersContext(connectionstring)); var clientAppRepo = new ClientAppRepo(usersContextFactory, config); var edOrgs = _expectedEducationOrganizations .Select( edOrgId => new ApplicationEducationOrganization { EducationOrganizationId = edOrgId }) .ToList(); var profiles = _expectedProfiles.Select( profile => new Profile { ProfileName = profile }) .ToList(); var application = new Application { Profiles = profiles, ClaimSetName = "MyTestClaimSetName", Vendor = new Vendor { VendorNamespacePrefixes = new List <VendorNamespacePrefix> { new VendorNamespacePrefix { NamespacePrefix = "MyTestNamespacePrefix" } } }, OperationalContextUri = "uri://ed-fi-api-host.org" }; _testClient = new ApiClient(true) { Name = $"ClientAppRepoTest{Guid.NewGuid():N}", Application = application, ApplicationEducationOrganizations = edOrgs }; using (var context = new SqlServerUsersContext(connectionstring)) { context.Clients.Add(_testClient); context.SaveChanges(); } _apiClientIdentityProvider = new EdFiAdminApiClientIdentityProvider(clientAppRepo); }