protected override void Act()
            {
                var         memoryCacheOption   = A.Fake <IOptions <MemoryCacheOptions> >();
                MemoryCache memoryCache         = new MemoryCache(memoryCacheOption);
                var         memoryCacheProvider = new MemoryCacheProvider(memoryCache);

                var educationOrganizationCache = new EducationOrganizationCache(
                    memoryCacheProvider,
                    edfiOdsInstanceIdentificationProvider,
                    edOrgValueMapper,
                    educationOrganizationIdentifiersProvider,
                    synchronousInitialization: true);

                var listLock = new object();
                var tasks    = new List <Task>();

                for (var i = 0; i < 50; i++)
                {
                    tasks.Add(
                        Task.Run(
                            () =>
                    {
                        var educationOrganizationIdentifiers =
                            educationOrganizationCache.GetEducationOrganizationIdentifiers(
                                suppliedEducationOrganizationIdentifiers.EducationOrganizationId);

                        lock (listLock)
                        {
                            actualEducationOrganizationIdentifiers.Add(educationOrganizationIdentifiers);
                        }
                    }));
                }

                Task.WaitAll(tasks.ToArray());
            }
            protected override void Act()
            {
                var memoryCacheProvider        = Stub <MemoryCacheProvider>();
                var educationOrganizationCache = new EducationOrganizationCache(
                    memoryCacheProvider,
                    edfiOdsInstanceIdentificationProvider,
                    edOrgValueMapper,
                    educationOrganizationIdentifiersProvider,
                    synchronousInitialization: true);

                actualEdOrgIdsFromDefault     = educationOrganizationCache.GetEducationOrganizationIdentifiers(default(int));
                actualEdOrgIdsFromNonExisting = educationOrganizationCache.GetEducationOrganizationIdentifiers(-1);
            }
            protected override void Act()
            {
                var memoryCacheProvider = Stub <MemoryCacheProvider>();

                var educationOrganizationCache = new EducationOrganizationCache(
                    memoryCacheProvider,
                    edfiOdsInstanceIdentificationProvider,
                    edOrgValueMapper,
                    educationOrganizationIdentifiersProvider,
                    synchronousInitialization: true);

                //Two Calls

                educationOrganizationCache.GetEducationOrganizationIdentifiers(suppliedEdOrgValueMap.EducationOrganizationId);
                actualEdOrgIds = educationOrganizationCache.GetEducationOrganizationIdentifiers(suppliedEdOrgValueMap.EducationOrganizationId);
            }
示例#4
0
            protected override void Act()
            {
                var memoryCacheProvider = new MemoryCacheProvider
                {
                    MemoryCache = new MemoryCache("IsolatedForUnitTest")
                };

                var educationOrganizationCache = new EducationOrganizationCache(
                    memoryCacheProvider,
                    edfiOdsInstanceIdentificationProvider,
                    edOrgValueMapper,
                    educationOrganizationIdentifiersProvider,
                    synchronousInitialization: true);

                // Synchronous initialization should result in values being supplied by the edorg identifier provider result

                // Launch 50 threads to try and obtain the USI
                var listLock = new object();
                var tasks    = new List <Task>();

                for (var i = 0; i < 50; i++)
                {
                    tasks.Add(
                        Task.Run(
                            () =>
                    {
                        var educationOrganizationIdentifiers =
                            educationOrganizationCache.GetEducationOrganizationIdentifiers(
                                suppliedEducationOrganizationIdentifiers.EducationOrganizationId);

                        lock (listLock)
                        {
                            actualEducationOrganizationIdentifiers.Add(educationOrganizationIdentifiers);
                        }
                    }));
                }

                Task.WaitAll(tasks.ToArray());
            }
示例#5
0
            protected override void ExecuteBehavior()
            {
                // Provide external dependencies not needing specific behavior in this test
                var cacheProvider = new MemoryCacheProvider
                {
                    MemoryCache = new MemoryCache("IsolatedForUnitTest")
                };

                var configValueProvider = mocks.Stub <IConfigValueProvider>();

                // Create Faked dependencies
                var connectionStringProvider = new FakeConnectionStringProvider();

                var educationOrganizationCacheDataProvider =
                    new FakeEducationOrganizationCacheDataProvider(connectionStringProvider);

                var suppliedIdentifierSet1 = new List <EducationOrganizationIdentifiers>
                {
                    new EducationOrganizationIdentifiers(
                        9,
                        "LocalEducationAgency",
                        stateEducationAgencyId: 1,
                        localEducationAgencyId: 9),
                    new EducationOrganizationIdentifiers(
                        99,
                        "School",
                        stateEducationAgencyId: 1,
                        localEducationAgencyId: 9,
                        schoolId: 99),
                    new EducationOrganizationIdentifiers(
                        999,
                        "School",
                        stateEducationAgencyId: 1,
                        localEducationAgencyId: 9,
                        schoolId: 999)
                };

                var suppliedIdentifierSet2 = new List <EducationOrganizationIdentifiers>
                {
                    new EducationOrganizationIdentifiers(
                        8,
                        "LocalEducationAgency",
                        stateEducationAgencyId: 1,
                        localEducationAgencyId: 8),
                    new EducationOrganizationIdentifiers(
                        88,
                        "School",
                        stateEducationAgencyId: 1,
                        localEducationAgencyId: 8,
                        schoolId: 88),
                    new EducationOrganizationIdentifiers(
                        888,
                        "School",
                        stateEducationAgencyId: 1,
                        localEducationAgencyId: 8,
                        schoolId: 888)
                };

                // Set up the cache data provider to return different data based on different connection strings
                educationOrganizationCacheDataProvider.AddResult("String1", suppliedIdentifierSet1);
                educationOrganizationCacheDataProvider.AddResult("String2", suppliedIdentifierSet2);

                // Create the cache
                var edOrgCache = new EducationOrganizationCache(
                    cacheProvider,
                    new EdFiOdsInstanceIdentificationProvider(connectionStringProvider),
                    educationOrganizationCacheDataProvider,
                    educationOrganizationCacheDataProvider,
                    true);

                // First retrieve values for the first connection string
                connectionStringProvider.CurrentValue = "String1";
                actual88ResultForString1 = edOrgCache.GetEducationOrganizationIdentifiers(88);
                actual99ResultForString1 = edOrgCache.GetEducationOrganizationIdentifiers(99);

                // Then retrieve values for the second connection string
                connectionStringProvider.CurrentValue = "String2";
                actual88ResultForString2 = edOrgCache.GetEducationOrganizationIdentifiers(88);
                actual99ResultForString2 = edOrgCache.GetEducationOrganizationIdentifiers(99);
            }
示例#6
0
            protected override void Arrange()
            {
                edfiOdsInstanceIdentificationProvider = Stub <IEdFiOdsInstanceIdentificationProvider>();
                edOrgValueMapper = Stub <IEducationOrganizationIdentifiersValueMapper>();
                educationOrganizationIdentifiersProvider = Stub <IEducationOrganizationCacheDataProvider>();

                // edorg value mapper
                suppliedEdOrgValueMap = new EducationOrganizationIdentifiers(
                    educationOrganizationId: 123456,
                    educationOrganizationType: "District",
                    stateEducationAgencyId: 1,
                    educationServiceCenterId: 330950,
                    localEducationAgencyId: 123456);

                edOrgValueMapper.Stub(x => x.GetEducationOrganizationIdentifiers(default(int)))
                .IgnoreArguments()
                .Return(suppliedEdOrgValueMap);

                // edorg identifiers provider
                suppliedEducationOrganizationIdentifiers = new EducationOrganizationIdentifiers(
                    educationOrganizationId: 123456,
                    educationOrganizationType: "District",
                    stateEducationAgencyId: 1,
                    educationServiceCenterId: 330950,
                    localEducationAgencyId: 8675309);

                var memoryCacheProvider = new MemoryCacheProvider
                {
                    MemoryCache = new MemoryCache("IsolatedForUnitTest")
                };

                var educationOrganizationCache = new EducationOrganizationCache(
                    memoryCacheProvider,
                    edfiOdsInstanceIdentificationProvider,
                    edOrgValueMapper,
                    educationOrganizationIdentifiersProvider,
                    synchronousInitialization: false);

                var listLock = new object();

                for (var i = 0; i < TaskCount; i++)
                {
                    _tasks.Add(
                        new Task(
                            () =>
                    {
                        var educationOrganizationIdentifiers =
                            educationOrganizationCache.GetEducationOrganizationIdentifiers(
                                suppliedEducationOrganizationIdentifiers.EducationOrganizationId);

                        lock (listLock)
                        {
                            actualEducationOrganizationIdentifiers.Add(educationOrganizationIdentifiers);
                        }
                    }));
                }

                educationOrganizationIdentifiersProvider.Stub(x => x.GetAllEducationOrganizationIdentifiers())
                .IgnoreArguments()
                .Return(
                    Task.Run(
                        () =>
                {
                    Task.WaitAll(_tasks.ToArray());

                    return((IEnumerable <EducationOrganizationIdentifiers>)
                           new[]
                    {
                        suppliedEducationOrganizationIdentifiers
                    });
                }));
            }
            protected override void Act()
            {
                // Provide external dependencies not needing specific behavior in this test
                var         memoryCacheOption = A.Fake <IOptions <MemoryCacheOptions> >();
                MemoryCache memoryCache       = new MemoryCache(memoryCacheOption);
                var         cacheProvider     = new MemoryCacheProvider(memoryCache);

                // Create Faked dependencies
                var connectionStringProvider = Stub <IOdsDatabaseConnectionStringProvider>();

                var educationOrganizationCacheDataProvider =
                    new FakeEducationOrganizationCacheDataProvider(connectionStringProvider);

                var suppliedIdentifierSet1 = new List <EducationOrganizationIdentifiers>
                {
                    new EducationOrganizationIdentifiers(
                        9,
                        "LocalEducationAgency",
                        stateEducationAgencyId: 1,
                        localEducationAgencyId: 9),
                    new EducationOrganizationIdentifiers(
                        99,
                        "School",
                        stateEducationAgencyId: 1,
                        localEducationAgencyId: 9,
                        schoolId: 99),
                    new EducationOrganizationIdentifiers(
                        999,
                        "School",
                        stateEducationAgencyId: 1,
                        localEducationAgencyId: 9,
                        schoolId: 999)
                };

                var suppliedIdentifierSet2 = new List <EducationOrganizationIdentifiers>
                {
                    new EducationOrganizationIdentifiers(
                        8,
                        "LocalEducationAgency",
                        stateEducationAgencyId: 1,
                        localEducationAgencyId: 8),
                    new EducationOrganizationIdentifiers(
                        88,
                        "School",
                        stateEducationAgencyId: 1,
                        localEducationAgencyId: 8,
                        schoolId: 88),
                    new EducationOrganizationIdentifiers(
                        888,
                        "School",
                        stateEducationAgencyId: 1,
                        localEducationAgencyId: 8,
                        schoolId: 888)
                };

                educationOrganizationCacheDataProvider.AddResult("String1", suppliedIdentifierSet1);
                educationOrganizationCacheDataProvider.AddResult("String2", suppliedIdentifierSet2);

                // Create the cache
                var edOrgCache = new EducationOrganizationCache(
                    cacheProvider,
                    new EdFiOdsInstanceIdentificationProvider(connectionStringProvider),
                    educationOrganizationCacheDataProvider,
                    educationOrganizationCacheDataProvider,
                    true);

                // First retrieve values for the first connection string
                A.CallTo(() => connectionStringProvider.GetConnectionString())
                .Returns("String1");

                _actual88ResultForString1 = edOrgCache.GetEducationOrganizationIdentifiers(88);
                _actual99ResultForString1 = edOrgCache.GetEducationOrganizationIdentifiers(99);

                // Then retrieve values for the second connection string
                A.CallTo(() => connectionStringProvider.GetConnectionString())
                .Returns("String2");

                _actual88ResultForString2 = edOrgCache.GetEducationOrganizationIdentifiers(88);
                _actual99ResultForString2 = edOrgCache.GetEducationOrganizationIdentifiers(99);
            }