public bool ReturnsSwitchState_DependantOnCookieValue(bool cookieValue)
            {
                var featureSwitch = new PercentageFeatureSwitch
                {
                    IsEnabled = true,
                    Name = "testPercentageFeatureSwitch"
                };

                _cookies.Add(new HttpCookie(featureSwitch.Name, cookieValue.ToString()));
                return featureSwitch.IsOn(_femahContext);
            }
            public void SetsCookie_IfNoCookieExists()
            {
                var featureSwitch = new PercentageFeatureSwitch
                {
                    IsEnabled = true,
                    Name = "testPercentageFeatureSwitch"
                };

                var result = featureSwitch.IsOn(_femahContext);

                _cookies.Count.ShouldBe(1);
                _cookies[0].Name.ShouldBe(featureSwitch.Name);
                _cookies[0].Value.ShouldBe(result.ToString());
            }
示例#3
0
        public void GivenTwoPercentageFeatureSwitches_ReturnsTrue_IfAllPropertyValuesAreIdentical()
        {
            //Arrange
            const string validFeatureType = "Femah.Core.FeatureSwitchTypes.SimpleFeatureSwitch, Femah.Core, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null";
            var customAttributes1 = new Dictionary<string, string> { { "percentage", "50" } };
            var customAttributes2 = new Dictionary<string, string> { { "percentage", "50" } };

            var featureSwitch1 = new PercentageFeatureSwitch
            {
                Name = "TestFeatureSwitch1",
                FeatureType = validFeatureType,
                IsEnabled = true
            };
            featureSwitch1.SetCustomAttributes(customAttributes1);

            var featureSwitch2 = new PercentageFeatureSwitch
            {
                Name = "TestFeatureSwitch1",
                FeatureType = validFeatureType,
                IsEnabled = true
            };
            featureSwitch2.SetCustomAttributes(customAttributes2);

            var providerMock = new Mock<IFeatureSwitchProvider>();
            providerMock.Setup(p => p.Get("TestFeatureSwitch1"))
                .Returns(featureSwitch1);

            Femah.Configure()
                .FeatureSwitchEnum(typeof(FeatureSwitches))
                .Provider(providerMock.Object)
                .Initialise();

            //Act
            var equal = featureSwitch1.Equals(featureSwitch2);

            //Assert
            Assert.IsTrue(equal);
        }
            public void GivenTwoFeatureSwitches_ReturnsFalse_IfFeatureTypesAreDifferent()
            {
                //Arrange
                const string validFeatureType1 = "Femah.Core.FeatureSwitchTypes.SimpleFeatureSwitch, Femah.Core, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null";
                const string validFeatureType2 = "Femah.Core.FeatureSwitchTypes.PercentageFeatureSwitch, Femah.Core, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null";

                var featureSwitch1 = new SimpleFeatureSwitch
                {
                    Name = "TestFeatureSwitch1",
                    FeatureType = validFeatureType1
                };

                var featureSwitch2 = new PercentageFeatureSwitch
                {
                    Name = "TestFeatureSwitch1",
                    FeatureType = validFeatureType2
                };

                //Act
                var equal = featureSwitch1.Equals(featureSwitch2);

                //Assert
                Assert.IsFalse(equal);
            }
示例#5
0
        public void AssertApiResponseBuilderCallsUpdateOnFeatureTypeStateIsEnabledStateAndAttributes()
        {
            //Arrange
            const string validFeatureType = "Femah.Core.FeatureSwitchTypes.PercentageFeatureSwitch, Femah.Core, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null";
            //const string jsonResponse = "{\"PercentageOn\":75,\"Description\":\"A simple feature switch that is on for a set percentage of users. The state of the switch is persisted in the user's cookies.If no cookie exists the state is chosen at random (weighted according to the percentage), and then stored in a cookie.\",\"ConfigurationInstructions\":\"Set PercentageOn to the percentage of users who should see this feature. Eg. 10 means the feature is on for 10% of users.\",\"IsEnabled\":true,\"Name\":\"TestFeatureSwitch1\",\"FeatureType\":\"Femah.Core.FeatureSwitchTypes.PercentageFeatureSwitch, Femah.Core, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null\"}";

            var currentFeatureSwitchState = new PercentageFeatureSwitch
            {
                Name = "TestFeatureSwitch1",
                FeatureType = validFeatureType,
                IsEnabled = true,
                PercentageOn = 50
            };

            var desiredFeatureSwitchState = new PercentageFeatureSwitch
            {
                Name = "TestFeatureSwitch1",
                FeatureType = validFeatureType,
                IsEnabled = true,
                PercentageOn = 75
            };

            var providerMock = new Mock<IFeatureSwitchProvider>();
            providerMock.Setup(p => p.Get("TestFeatureSwitch1"))
                .Returns(currentFeatureSwitchState);

            var femahMock = new Mock<Femah>();
            //femahMock.Setup(f => f)
            //TODO: Can't currently mock Femah easily, seeing as it's both sealed and the methods we're interested in are internal static, thoughts?

            Femah.Configure()
                .FeatureSwitchEnum(typeof(FeatureSwitches))
                .Provider(providerMock.Object)
                .Initialise();

            //Act
            ApiResponse apiResponse;
            using (var apiResponseBuilder = new ApiResponseBuilder())
            {
                apiResponse = apiResponseBuilder.CreateWithUpdatedFeatureSwitch(desiredFeatureSwitchState);
            }

            //Assert
            //Assert.AreEqual((int)HttpStatusCode.OK, apiResponse.HttpStatusCode);
            //Assert.AreEqual(jsonResponse, apiResponse.Body);
        }
示例#6
0
        public void ApiResponseBuilderSetsHttpStatusCodeTo200AndReturnsDesiredFeatureSwitchStateIfPutRequestIncludesFeatureSwitchChangesToCustomParameters()
        {
            //Arrange
            const string validFeatureType = "Femah.Core.FeatureSwitchTypes.PercentageFeatureSwitch, Femah.Core, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null";
            const string jsonResponse = "{\"PercentageOn\":75,\"Description\":\"A simple feature switch that is on for a set percentage of users. The state of the switch is persisted in the user's cookies.If no cookie exists the state is chosen at random (weighted according to the percentage), and then stored in a cookie.\",\"ConfigurationInstructions\":\"Set PercentageOn to the percentage of users who should see this feature. Eg. 10 means the feature is on for 10% of users.\",\"IsEnabled\":true,\"Name\":\"TestFeatureSwitch1\",\"FeatureType\":\"Femah.Core.FeatureSwitchTypes.PercentageFeatureSwitch, Femah.Core, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null\"}";

            var currentFeatureSwitchState = new PercentageFeatureSwitch
            {
                Name = "TestFeatureSwitch1",
                FeatureType = validFeatureType,
                IsEnabled = true,
                PercentageOn = 50
            };

            var desiredFeatureSwitchState = new PercentageFeatureSwitch
            {
                Name = "TestFeatureSwitch1",
                FeatureType = validFeatureType,
                IsEnabled = true,
                PercentageOn = 75
            };

            var providerMock = new Mock<IFeatureSwitchProvider>();
            providerMock.Setup(p => p.Get("TestFeatureSwitch1"))
                .Returns(currentFeatureSwitchState);

            Femah.Configure()
                .FeatureSwitchEnum(typeof(FeatureSwitches))
                .Provider(providerMock.Object)
                .Initialise();

            //Act
            ApiResponse apiResponse;
            using (var apiResponseBuilder = new ApiResponseBuilder())
            {
                apiResponse = apiResponseBuilder.CreateWithUpdatedFeatureSwitch(desiredFeatureSwitchState);
            }

            //Assert
            Assert.AreEqual((int)HttpStatusCode.OK, apiResponse.HttpStatusCode);
            Assert.AreEqual(jsonResponse, apiResponse.Body);
        }
示例#7
0
        public void TwoFeatureSwitchesAreNotEqualIfCustomAttributesAreDifferent()
        {
            //Arrange
            const string validFeatureType = "Femah.Core.FeatureSwitchTypes.PercentageFeatureSwitch, Femah.Core, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null";

            var featureSwitch1 = new PercentageFeatureSwitch
            {
                Name = "TestFeatureSwitch1",
                FeatureType = validFeatureType,
                IsEnabled = true,
                PercentageOn = 50
            };

            var featureSwitch2 = new PercentageFeatureSwitch
            {
                Name = "TestFeatureSwitch1",
                FeatureType = validFeatureType,
                IsEnabled = true,
                PercentageOn = 75
            };

            var providerMock = new Mock<IFeatureSwitchProvider>();
            providerMock.Setup(p => p.Get("TestFeatureSwitch1"))
                .Returns(featureSwitch1);
            providerMock.Setup(p => p.Get("TestFeatureSwitch1"))
                .Returns(featureSwitch2);

            Femah.Configure()
                .FeatureSwitchEnum(typeof(FeatureSwitches))
                .Provider(providerMock.Object)
                .Initialise();

            //Act
            var equal = featureSwitch1.Equals(featureSwitch2);

            //Assert
            Assert.IsFalse(equal);
        }