Exemplo n.º 1
0
        public async Task Should_Get_Correct_Values()
        {
            var session = new MyChangableSession();

            var settingManager = new SettingManager(CreateMockSettingDefinitionManager());

            settingManager.SettingStore = new MemorySettingStore();
            settingManager.AbpSession   = session;

            session.TenantId = 1;

            //Inherited setting

            session.UserId = 1;
            (await settingManager.GetSettingValueAsync(MyAllLevelsSetting)).ShouldBe("user 1 stored value");

            session.UserId = 2;
            (await settingManager.GetSettingValueAsync(MyAllLevelsSetting)).ShouldBe("user 2 stored value");

            session.UserId = 3;
            (await settingManager.GetSettingValueAsync(MyAllLevelsSetting)).ShouldBe("tenant 1 stored value"); //Because no user value in the store

            session.TenantId = 3;
            session.UserId   = 3;
            (await settingManager.GetSettingValueAsync(MyAllLevelsSetting)).ShouldBe("application level stored value"); //Because no user and tenant value in the store

            //Not inherited setting

            session.TenantId = 1;
            session.UserId   = 1;

            (await settingManager.GetSettingValueForApplicationAsync(MyNotInheritedSetting)).ShouldBe("application value");
            (await settingManager.GetSettingValueForTenantAsync(MyNotInheritedSetting, session.TenantId.Value)).ShouldBe("default-value");
            (await settingManager.GetSettingValueAsync(MyNotInheritedSetting)).ShouldBe("default-value");
        }
Exemplo n.º 2
0
        public async Task Should_Get_Correct_Values()
        {
            var session = new MyChangableSession();

            var settingManager = CreateSettingManager();
            settingManager.SettingStore = new MemorySettingStore();
            settingManager.AbpSession = session;

            session.TenantId = 1;

            //Inherited setting

            session.UserId = 1;
            (await settingManager.GetSettingValueAsync(MyAllLevelsSetting)).ShouldBe("user 1 stored value");

            session.UserId = 2;
            (await settingManager.GetSettingValueAsync(MyAllLevelsSetting)).ShouldBe("user 2 stored value");

            session.UserId = 3;
            (await settingManager.GetSettingValueAsync(MyAllLevelsSetting)).ShouldBe("tenant 1 stored value"); //Because no user value in the store

            session.TenantId = 3;
            session.UserId = 3;
            (await settingManager.GetSettingValueAsync(MyAllLevelsSetting)).ShouldBe("application level stored value"); //Because no user and tenant value in the store

            //Not inherited setting

            session.TenantId = 1;
            session.UserId = 1;

            (await settingManager.GetSettingValueForApplicationAsync(MyNotInheritedSetting)).ShouldBe("application value");
            (await settingManager.GetSettingValueForTenantAsync(MyNotInheritedSetting, session.TenantId.Value)).ShouldBe("default-value");
            (await settingManager.GetSettingValueAsync(MyNotInheritedSetting)).ShouldBe("default-value");
        }
Exemplo n.º 3
0
        public void Should_Change_Setting_Values()
        {
            var session = new MyChangableSession();

            var settingManager = new SettingManager(CreateMockSettingDefinitionManager());

            settingManager.SettingStore = new MemorySettingStore();
            settingManager.Session      = session;

            //Application level changes

            settingManager.ChangeSettingForApplication(MyAppLevelSetting, "53");
            settingManager.ChangeSettingForApplication(MyAllLevelsSetting, "application level changed value");

            settingManager.GetSettingValue <int>(MyAppLevelSetting).ShouldBe(53);
            settingManager.GetSettingValue(MyAllLevelsSetting).ShouldBe("application level changed value");

            //Tenant level changes

            session.TenantId = 1;
            settingManager.ChangeSettingForTenant(1, MyAllLevelsSetting, "tenant 1 changed value");
            settingManager.GetSettingValue(MyAllLevelsSetting).ShouldBe("tenant 1 changed value");

            //User level changes

            session.UserId = 1;
            settingManager.ChangeSettingForUser(1, MyAllLevelsSetting, "user 1 changed value");
            settingManager.GetSettingValue(MyAllLevelsSetting).ShouldBe("user 1 changed value");
        }
Exemplo n.º 4
0
        public void Should_Change_Setting_Values()
        {
            var session = new MyChangableSession();

            var settingManager = new SettingManager(CreateMockSettingDefinitionManager(), new ObjectThreadSafeCacheFactoryService());

            settingManager.SettingStore = new MemorySettingStore();
            settingManager.Session      = session;

            //Application level changes

            settingManager.ChangeSettingForApplication(MyAppLevelSetting, "53");
            settingManager.ChangeSettingForApplication(MyAppLevelSetting, "54");
            settingManager.ChangeSettingForApplication(MyAllLevelsSetting, "application level changed value");

            settingManager.SettingStore.GetSettingOrNull(null, null, MyAppLevelSetting).Value.ShouldBe("54");

            settingManager.GetSettingValue <int>(MyAppLevelSetting).ShouldBe(54);
            settingManager.GetSettingValue(MyAllLevelsSetting).ShouldBe("application level changed value");

            //Tenant level changes

            session.TenantId = Guid.NewGuid();
            settingManager.ChangeSettingForTenant(session.TenantId.Value, MyAllLevelsSetting, "tenant 1 changed value");
            settingManager.GetSettingValue(MyAllLevelsSetting).ShouldBe("tenant 1 changed value");

            //User level changes

            session.UserId = Guid.NewGuid();
            settingManager.ChangeSettingForUser(session.UserId.Value, MyAllLevelsSetting, "user 1 changed value");
            settingManager.GetSettingValue(MyAllLevelsSetting).ShouldBe("user 1 changed value");
        }
        public void Should_Change_Setting_Values()
        {
            var session = new MyChangableSession();

            var settingManager = new SettingManager(CreateMockSettingDefinitionManager(), new ObjectThreadSafeCacheFactoryService());
            settingManager.SettingStore = new MemorySettingStore();
            settingManager.Session = session;

            //Application level changes

            settingManager.ChangeSettingForApplication(MyAppLevelSetting, "53");
            settingManager.ChangeSettingForApplication(MyAppLevelSetting, "54");
            settingManager.ChangeSettingForApplication(MyAllLevelsSetting, "application level changed value");

            settingManager.SettingStore.GetSettingOrNull(null, null, MyAppLevelSetting).Value.ShouldBe("54");

            settingManager.GetSettingValue<int>(MyAppLevelSetting).ShouldBe(54);
            settingManager.GetSettingValue(MyAllLevelsSetting).ShouldBe("application level changed value");

            //Tenant level changes

            session.TenantId = Guid.NewGuid();
            settingManager.ChangeSettingForTenant(session.TenantId.Value, MyAllLevelsSetting, "tenant 1 changed value");
            settingManager.GetSettingValue(MyAllLevelsSetting).ShouldBe("tenant 1 changed value");

            //User level changes

            session.UserId = Guid.NewGuid();
            settingManager.ChangeSettingForUser(session.UserId.Value, MyAllLevelsSetting, "user 1 changed value");
            settingManager.GetSettingValue(MyAllLevelsSetting).ShouldBe("user 1 changed value");
        }
        public async Task Should_Delete_Setting_Values_On_Default_Value()
        {
            var session = new MyChangableSession();
            var store   = new MemorySettingStore();

            var settingManager = new SettingManager(CreateMockSettingDefinitionManager())
            {
                SettingStore = store,
                Session      = session
            };

            session.TenantId = 1;
            session.UserId   = 1;

            //We can get user's personal stored value
            (await store.GetSettingOrNullAsync(null, 1, MyAllLevelsSetting)).ShouldNotBe(null);
            (await settingManager.GetSettingValueAsync(MyAllLevelsSetting)).ShouldBe("user 1 stored value");

            //This will delete setting for the user since it's same as tenant's setting value
            await settingManager.ChangeSettingForUserAsync(1, MyAllLevelsSetting, "tenant 1 stored value");

            (await store.GetSettingOrNullAsync(null, 1, MyAllLevelsSetting)).ShouldBe(null);

            //We can get tenant's setting value
            (await store.GetSettingOrNullAsync(1, null, MyAllLevelsSetting)).ShouldNotBe(null);
            (await settingManager.GetSettingValueAsync(MyAllLevelsSetting)).ShouldBe("tenant 1 stored value");

            //This will delete setting for tenant since it's same as application's setting value
            await settingManager.ChangeSettingForTenantAsync(1, MyAllLevelsSetting, "application level stored value");

            (await store.GetSettingOrNullAsync(null, 1, MyAllLevelsSetting)).ShouldBe(null);

            //We can get application's value
            (await store.GetSettingOrNullAsync(null, null, MyAllLevelsSetting)).ShouldNotBe(null);
            (await settingManager.GetSettingValueAsync(MyAllLevelsSetting)).ShouldBe("application level stored value");

            //This will delete setting for application since it's same as the default value of the setting
            await settingManager.ChangeSettingForApplicationAsync(MyAllLevelsSetting, "application level default value");

            (await store.GetSettingOrNullAsync(null, null, MyAllLevelsSetting)).ShouldBe(null);

            //Now, there is no setting value, default value should return
            (await settingManager.GetSettingValueAsync(MyAllLevelsSetting)).ShouldBe("application level default value");
        }
Exemplo n.º 7
0
        public void Should_Delete_Setting_Values_On_Default_Value()
        {
            var session = new MyChangableSession();
            var store   = new MemorySettingStore();

            var settingManager = new SettingManager(CreateMockSettingDefinitionManager(), new ObjectThreadSafeCacheFactoryService());

            settingManager.SettingStore = store;
            settingManager.Session      = session;

            session.TenantId = Guid.NewGuid();
            session.UserId   = Guid.NewGuid();

            //We can get user's personal stored value
            store.GetSettingOrNull(null, session.UserId, MyAllLevelsSetting).ShouldNotBe(null);
            settingManager.GetSettingValue(MyAllLevelsSetting).ShouldBe("user 1 stored value");

            //This will delete setting for the user since it's same as tenant's setting value
            settingManager.ChangeSettingForUser(session.UserId.Value, MyAllLevelsSetting, "tenant 1 stored value");
            store.GetSettingOrNull(null, session.UserId, MyAllLevelsSetting).ShouldBe(null);

            //We can get tenant's setting value
            store.GetSettingOrNull(session.TenantId, null, MyAllLevelsSetting).ShouldNotBe(null);
            settingManager.GetSettingValue(MyAllLevelsSetting).ShouldBe("tenant 1 stored value");

            //This will delete setting for tenant since it's same as application's setting value
            settingManager.ChangeSettingForTenant(session.TenantId.Value, MyAllLevelsSetting, "application level stored value");
            store.GetSettingOrNull(null, session.UserId, MyAllLevelsSetting).ShouldBe(null);

            //We can get application's value
            store.GetSettingOrNull(null, null, MyAllLevelsSetting).ShouldNotBe(null);
            settingManager.GetSettingValue(MyAllLevelsSetting).ShouldBe("application level stored value");

            //This will delete setting for application since it's same as the default value of the setting
            settingManager.ChangeSettingForApplication(MyAllLevelsSetting, "application level default value");
            store.GetSettingOrNull(null, null, MyAllLevelsSetting).ShouldBe(null);

            //Now, there is no setting value, default value should return
            settingManager.GetSettingValue(MyAllLevelsSetting).ShouldBe("application level default value");
        }
        public void Should_Delete_Setting_Values_On_Default_Value()
        {
            var session = new MyChangableSession();
            var store = new MemorySettingStore();

            var settingManager = new SettingManager(CreateMockSettingDefinitionManager(), new ObjectThreadSafeCacheFactoryService());
            settingManager.SettingStore = store;
            settingManager.Session = session;

            session.TenantId = Guid.NewGuid();
            session.UserId = Guid.NewGuid();

            //We can get user's personal stored value
            store.GetSettingOrNull(null, session.UserId, MyAllLevelsSetting).ShouldNotBe(null);
            settingManager.GetSettingValue(MyAllLevelsSetting).ShouldBe("user 1 stored value");

            //This will delete setting for the user since it's same as tenant's setting value
            settingManager.ChangeSettingForUser(session.UserId.Value, MyAllLevelsSetting, "tenant 1 stored value");
            store.GetSettingOrNull(null, session.UserId, MyAllLevelsSetting).ShouldBe(null);

            //We can get tenant's setting value
            store.GetSettingOrNull(session.TenantId, null, MyAllLevelsSetting).ShouldNotBe(null);
            settingManager.GetSettingValue(MyAllLevelsSetting).ShouldBe("tenant 1 stored value");

            //This will delete setting for tenant since it's same as application's setting value
            settingManager.ChangeSettingForTenant(session.TenantId.Value, MyAllLevelsSetting, "application level stored value");
            store.GetSettingOrNull(null, session.UserId, MyAllLevelsSetting).ShouldBe(null);

            //We can get application's value
            store.GetSettingOrNull(null, null, MyAllLevelsSetting).ShouldNotBe(null);
            settingManager.GetSettingValue(MyAllLevelsSetting).ShouldBe("application level stored value");

            //This will delete setting for application since it's same as the default value of the setting
            settingManager.ChangeSettingForApplication(MyAllLevelsSetting, "application level default value");
            store.GetSettingOrNull(null, null, MyAllLevelsSetting).ShouldBe(null);

            //Now, there is no setting value, default value should return
            settingManager.GetSettingValue(MyAllLevelsSetting).ShouldBe("application level default value");
        }
        public async Task Should_Change_Setting_Values()
        {
            var session = new MyChangableSession();

            var settingManager = new SettingManager(CreateMockSettingDefinitionManager())
            {
                SettingStore = new MemorySettingStore(),
                Session      = session
            };

            //Application level changes

            await settingManager.ChangeSettingForApplicationAsync(MyAppLevelSetting, "53");

            await settingManager.ChangeSettingForApplicationAsync(MyAppLevelSetting, "54");

            await settingManager.ChangeSettingForApplicationAsync(MyAllLevelsSetting, "application level changed value");

            (await settingManager.SettingStore.GetSettingOrNullAsync(null, null, MyAppLevelSetting)).Value.ShouldBe("54");

            (await settingManager.GetSettingValueAsync <int>(MyAppLevelSetting)).ShouldBe(54);
            (await settingManager.GetSettingValueAsync(MyAllLevelsSetting)).ShouldBe("application level changed value");

            //Tenant level changes

            session.TenantId = 1;
            await settingManager.ChangeSettingForTenantAsync(1, MyAllLevelsSetting, "tenant 1 changed value");

            (await settingManager.GetSettingValueAsync(MyAllLevelsSetting)).ShouldBe("tenant 1 changed value");

            //User level changes

            session.UserId = 1;
            await settingManager.ChangeSettingForUserAsync(1, MyAllLevelsSetting, "user 1 changed value");

            (await settingManager.GetSettingValueAsync(MyAllLevelsSetting)).ShouldBe("user 1 changed value");
        }
Exemplo n.º 10
0
        public void Should_Get_Correct_Values()
        {
            var session = new MyChangableSession();

            var settingManager = new SettingManager(CreateMockSettingDefinitionManager(), new ObjectThreadSafeCacheFactoryService());

            settingManager.SettingStore = new MemorySettingStore();
            settingManager.Session      = session;

            session.TenantId = Guid.NewGuid();

            session.UserId = Guid.NewGuid();
            settingManager.GetSettingValue(MyAllLevelsSetting).ShouldBe("user 1 stored value");

            session.UserId = Guid.NewGuid();
            settingManager.GetSettingValue(MyAllLevelsSetting).ShouldBe("user 2 stored value");

            session.UserId = Guid.NewGuid();
            settingManager.GetSettingValue(MyAllLevelsSetting).ShouldBe("tenant 1 stored value"); //Because no user value in the store

            session.TenantId = Guid.NewGuid();
            session.UserId   = Guid.NewGuid();
            settingManager.GetSettingValue(MyAllLevelsSetting).ShouldBe("application level stored value"); //Because no user and tenant value in the store
        }
Exemplo n.º 11
0
        public async Task Should_Delete_Setting_Values_On_Default_Value()
        {
            var session = new MyChangableSession();
            var store = new MemorySettingStore();

            var settingManager = CreateSettingManager();
            settingManager.SettingStore = store;
            settingManager.AbpSession = session;

            session.TenantId = 1;
            session.UserId = 1;

            //We can get user's personal stored value
            (await store.GetSettingOrNullAsync(null, 1, MyAllLevelsSetting)).ShouldNotBe(null);
            (await settingManager.GetSettingValueAsync(MyAllLevelsSetting)).ShouldBe("user 1 stored value");

            //This will delete setting for the user since it's same as tenant's setting value
            await settingManager.ChangeSettingForUserAsync(1, MyAllLevelsSetting, "tenant 1 stored value");
            (await store.GetSettingOrNullAsync(null, 1, MyAllLevelsSetting)).ShouldBe(null);

            //We can get tenant's setting value
            (await store.GetSettingOrNullAsync(1, null, MyAllLevelsSetting)).ShouldNotBe(null);
            (await settingManager.GetSettingValueAsync(MyAllLevelsSetting)).ShouldBe("tenant 1 stored value");

            //This will delete setting for tenant since it's same as application's setting value
            await settingManager.ChangeSettingForTenantAsync(1, MyAllLevelsSetting, "application level stored value");
            (await store.GetSettingOrNullAsync(null, 1, MyAllLevelsSetting)).ShouldBe(null);

            //We can get application's value
            (await store.GetSettingOrNullAsync(null, null, MyAllLevelsSetting)).ShouldNotBe(null);
            (await settingManager.GetSettingValueAsync(MyAllLevelsSetting)).ShouldBe("application level stored value");

            //This will delete setting for application since it's same as the default value of the setting
            await settingManager.ChangeSettingForApplicationAsync(MyAllLevelsSetting, "application level default value");
            (await store.GetSettingOrNullAsync(null, null, MyAllLevelsSetting)).ShouldBe(null);

            //Now, there is no setting value, default value should return
            (await settingManager.GetSettingValueAsync(MyAllLevelsSetting)).ShouldBe("application level default value");
        }
Exemplo n.º 12
0
        public async Task Should_Change_Setting_Values()
        {
            var session = new MyChangableSession();

            var settingManager = CreateSettingManager();
            settingManager.SettingStore = new MemorySettingStore();
            settingManager.AbpSession = session;

            //Application level changes

            await settingManager.ChangeSettingForApplicationAsync(MyAppLevelSetting, "53");
            await settingManager.ChangeSettingForApplicationAsync(MyAppLevelSetting, "54");
            await settingManager.ChangeSettingForApplicationAsync(MyAllLevelsSetting, "application level changed value");

            (await settingManager.SettingStore.GetSettingOrNullAsync(null, null, MyAppLevelSetting)).Value.ShouldBe("54");

            (await settingManager.GetSettingValueAsync<int>(MyAppLevelSetting)).ShouldBe(54);
            (await settingManager.GetSettingValueAsync(MyAllLevelsSetting)).ShouldBe("application level changed value");

            //Tenant level changes

            session.TenantId = 1;
            await settingManager.ChangeSettingForTenantAsync(1, MyAllLevelsSetting, "tenant 1 changed value");
            (await settingManager.GetSettingValueAsync(MyAllLevelsSetting)).ShouldBe("tenant 1 changed value");

            //User level changes

            session.UserId = 1;
            await settingManager.ChangeSettingForUserAsync(1, MyAllLevelsSetting, "user 1 changed value");
            (await settingManager.GetSettingValueAsync(MyAllLevelsSetting)).ShouldBe("user 1 changed value");
        }
        public void Should_Get_Correct_Values()
        {
            var session = new MyChangableSession();

            var settingManager = new SettingManager(CreateMockSettingDefinitionManager(), new ObjectThreadSafeCacheFactoryService());
            settingManager.SettingStore = new MemorySettingStore();
            settingManager.Session = session;

            session.TenantId = Guid.NewGuid();

            session.UserId = Guid.NewGuid();
            settingManager.GetSettingValue(MyAllLevelsSetting).ShouldBe("user 1 stored value");

            session.UserId = Guid.NewGuid();
            settingManager.GetSettingValue(MyAllLevelsSetting).ShouldBe("user 2 stored value");

            session.UserId = Guid.NewGuid();
            settingManager.GetSettingValue(MyAllLevelsSetting).ShouldBe("tenant 1 stored value"); //Because no user value in the store

            session.TenantId = Guid.NewGuid();
            session.UserId = Guid.NewGuid();
            settingManager.GetSettingValue(MyAllLevelsSetting).ShouldBe("application level stored value"); //Because no user and tenant value in the store
        }