Example #1
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);
            }
            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);
            }