public void HttpFeatureToggleClient_should_update_rules_after_update()
        {
            // Arrange
            var httpClientDouble = new HttpClientDouble();

            httpClientDouble.Setup_GetString(ValidJsonDocument);

            var client = new HttpFeatureToggleClient(httpClientDouble, "url");

            // Assert
            Assert.AreEqual("default", client.GetTreatmentAsync("Feature2", "H", "default").Result);
            Assert.AreEqual("default", client.GetTreatmentAsync("Feature2", "Z", "default").Result);
            Assert.AreEqual("default", client.GetTreatmentAsync("Feature3", "M", "default").Result);

            // Act
            client.UpdateAsync().Wait();

            // Assert
            Assert.AreEqual("Treatment2A", client.GetTreatmentAsync("Feature2", "H", "default").Result);
            Assert.AreEqual("default", client.GetTreatmentAsync("Feature2", "Z", "default").Result);
            Assert.AreEqual("Disabled", client.GetTreatmentAsync("Feature3", "M", "default").Result);

            // Arrange
            httpClientDouble.Setup_GetString(AnotherValidJsonDocument);

            // Act
            client.UpdateAsync().Wait();

            // Assert
            Assert.AreEqual("Treatment2B", client.GetTreatmentAsync("Feature2", "Z", "default").Result);

            // Arrange
            httpClientDouble.Setup_GetString(EmptyValidJsonDocument);

            // Act
            client.UpdateAsync().Wait();

            // Assert
            Assert.AreEqual("default", client.GetTreatmentAsync("Feature2", "H", "default").Result);
            Assert.AreEqual("default", client.GetTreatmentAsync("Feature2", "Z", "default").Result);
            Assert.AreEqual("default", client.GetTreatmentAsync("Feature3", "M", "default").Result);
        }
        public void HttpFeatureToggleClient_should_ignore_invalid_responses()
        {
            // Arrange
            var httpClientDouble = new HttpClientDouble();

            httpClientDouble.Setup_GetString(ValidJsonDocument);
            var client = new HttpFeatureToggleClient(httpClientDouble, "url");

            client.UpdateAsync().Wait();

            Assert.AreEqual("Treatment2A", client.GetTreatmentAsync("Feature2", "H", "default").Result);
            Assert.AreEqual("default", client.GetTreatmentAsync("Feature2", "Z", "default").Result);
            Assert.AreEqual("Disabled", client.GetTreatmentAsync("Feature3", "M", "default").Result);

            httpClientDouble.Setup_GetString("INVALID CONTENT");

            // Act
            try
            {
                client.UpdateAsync().Wait();
            }
            catch
            {
                // Ignoring exception, UpdatePeriodically ignore them
            }

            // Assert
            Assert.AreEqual("Treatment2A", client.GetTreatmentAsync("Feature2", "H", "default").Result);
            Assert.AreEqual("default", client.GetTreatmentAsync("Feature2", "Z", "default").Result);
            Assert.AreEqual("Disabled", client.GetTreatmentAsync("Feature3", "M", "default").Result);
        }
        public void HttpFeatureToggleClient_update_rules_based_on_remote_resource()
        {
            // Arrange
            var client = new HttpFeatureToggleClient(OnlineExample1); // OnlineExample1 refers to a real online JSON file

            // Assert
            Assert.AreEqual("default", client.GetTreatmentAsync("UnexistentFeature", "AnyValue", "default").Result);
            Assert.AreEqual("default", client.GetTreatmentAsync("Example1Feature2", "Example1H", "default").Result);
            Assert.AreEqual("default", client.GetTreatmentAsync("Example1Feature2", "Example1Z", "default").Result);
            Assert.AreEqual("default", client.GetTreatmentAsync("Example1Feature3", "Example1M", "default").Result);

            // Act
            client.UpdateAsync().Wait();

            // Assert
            Assert.AreEqual("default", client.GetTreatmentAsync("UnexistentFeature", "AnyValue", "default").Result);
            Assert.AreEqual("Example1Treatment2A", client.GetTreatmentAsync("Example1Feature2", "Example1H", "default").Result);
            Assert.AreEqual("default", client.GetTreatmentAsync("Example1Feature2", "Example1Z", "default").Result);
            Assert.AreEqual("Disabled", client.GetTreatmentAsync("Example1Feature3", "Example1M", "default").Result);
        }