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);


                A.CallTo(() => edOrgValueMapper.GetEducationOrganizationIdentifiers(default(int)))
                .WithAnyArguments()
                .Returns(suppliedEdOrgValueMap);

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


                A.CallTo(() => educationOrganizationIdentifiersProvider.GetAllEducationOrganizationIdentifiers())
                .WithAnyArguments()
                .Returns(
                    Task.Run(
                        () =>
                {
                    System.Threading.Thread.Sleep(10);
                    return((IEnumerable <EducationOrganizationIdentifiers>)
                           new[]
                    {
                        suppliedEducationOrganizationIdentifiers
                    });
                }));
            }
Esempio n. 2
0
            protected override void Arrange()
            {
                edfiOdsInstanceIdentificationProvider = Stub <IEdFiOdsInstanceIdentificationProvider>();
                edOrgValueMapper = Stub <IEducationOrganizationIdentifiersValueMapper>();
                educationOrganizationIdentifiersProvider = Stub <IEducationOrganizationCacheDataProvider>();

                educationOrganizationIdentifiersProvider.Stub(x => x.GetAllEducationOrganizationIdentifiers())
                .IgnoreArguments()
                .Return(
                    Task.Run(
                        () =>
                        (IEnumerable <EducationOrganizationIdentifiers>)
                        new EducationOrganizationIdentifiers[0]));

                edOrgValueMapper = mocks.StrictMock <IEducationOrganizationIdentifiersValueMapper>();

                SetupResult.For(edOrgValueMapper.GetEducationOrganizationIdentifiers(default(int)))
                .IgnoreArguments()
                .Return(EducationOrganizationIdentifiers.CreateLookupInstance(default(int)));
            }
Esempio n. 3
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);
            }
Esempio n. 4
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);
            }