示例#1
0
        public async Task Integration_InitServiceWithNewApplication()
        {
            // initialize
            var storage     = new SqlFeatureStorage(FeatureStorageLogger.Object, _dbContextFactory);
            var service     = new FeatureService(FeatureServiceLogger.Object, storage);
            var initialized = await service.Initialize(validApiKey, "OtherApplication");

            Assert.True(initialized);
        }
示例#2
0
        public async Task Integration_InitServiceWithInvalidApiKey()
        {
            // initialize
            var storage     = new SqlFeatureStorage(FeatureStorageLogger.Object, _dbContextFactory);
            var service     = new FeatureService(FeatureServiceLogger.Object, storage);
            var initialized = await service.Initialize(validApiKey, myApplication);

            Assert.True(initialized);
            service.Reset();
            var initResult = await service.Initialize("invalidApiKey", myApplication);

            Assert.NotNull(service);
            Assert.False(initResult);
        }
示例#3
0
        public async Task Integration_AdminUserCanModifyGlobalToggles()
        {
            var user = new List <Claim>
            {
                new Claim(ClaimTypes.Name, "TestUser"),
                new Claim(ClaimTypes.Role, "ToggleAdministrator"),
                new Claim(ClaimTypes.Role, myApplication)
            };
            var storage = new SqlFeatureStorage(FeatureStorageLogger.Object, _dbContextFactory);
            var service = new FeatureService(FeatureServiceLogger.Object, storage);

            var setValue = await service.SetGlobal(user, validApiKey, myApplication, "myToggle");

            var resetValue = await service.ResetGlobal(user, validApiKey, myApplication, "myToggle");

            Assert.True(setValue);
            Assert.True(resetValue);
        }
示例#4
0
        public async Task Integration_UserCanReadUserValue()
        {
            const string userName = "******";
            var          user     = new List <Claim>
            {
                new Claim(ClaimTypes.Name, userName),
                new Claim(ClaimTypes.Role, myApplication)
            };

            const string parameterName = "savedStringValue";
            var          storage       = new SqlFeatureStorage(FeatureStorageLogger.Object, _dbContextFactory);
            var          service       = new FeatureService(FeatureServiceLogger.Object, storage);

            var saveValue = await service.Save(user, validApiKey, myApplication, parameterName, "User string value");

            // Act
            var setValue = await service.Current <string>(user, validApiKey, myApplication, parameterName);

            Assert.Equal("User string value", setValue);
        }
示例#5
0
        public async Task Integration_UserCanSetUserValue()
        {
            const string userName = "******";
            var          user     = new List <Claim>
            {
                new Claim(ClaimTypes.Name, userName),
                new Claim(ClaimTypes.Role, myApplication)
            };

            const string parameterName = "userStringValue";
            var          storage       = new SqlFeatureStorage(FeatureStorageLogger.Object, _dbContextFactory);
            var          service       = new FeatureService(FeatureServiceLogger.Object, storage);

            // Act
            await service.Remove(user, validApiKey, myApplication, parameterName);

            var setValue = await service.Save(user, validApiKey, myApplication, parameterName, "New user value");

            // should return global value, not the new value
            Assert.Equal("Global User value", setValue);
        }
示例#6
0
        public async Task Integration_AdminUserCanModifyGlobalValue()
        {
            var user = new List <Claim>
            {
                new Claim(ClaimTypes.Name, "TestUser"),
                new Claim(ClaimTypes.Role, "ToggleAdministrator"),
                new Claim(ClaimTypes.Role, myApplication)
            };

            const string parameterName = "globalStringValue";
            var          storage       = new SqlFeatureStorage(FeatureStorageLogger.Object, _dbContextFactory);
            var          service       = new FeatureService(FeatureServiceLogger.Object, storage);

            // Act
            await service.SaveGlobal(user, validApiKey, myApplication, "userStringValue", "Global User value");

            await service.SaveGlobal(user, validApiKey, myApplication, parameterName, "Global string value");

            var setValue = await service.SaveGlobal(user, validApiKey, myApplication, parameterName, "New string value");

            Assert.Equal("Global string value", setValue);
        }