Exemple #1
0
        public void PerformAction_WhenMultipleMarketRestrictionsAreSpecifiedAndMarketExistsInRequest_RunsAction()
        {
            Gate gate = new Gate("markets")
            {
                Markets = new HashSet <string>(new string[] { "en-us", "fr-fr" }, StringComparer.OrdinalIgnoreCase)
            };

            UnitTestGates.AddGateOverride(gate.Name, gate);

            UnitTestGatedRequest gatedRequest = new UnitTestGatedRequest
            {
                Market = "en-us"
            };

            bool result = false;

            IGateContext gateContext = new GateContext(gatedRequest, new BasicMachineInformation(), new DefaultExperimentContext());

            gateContext.PerformAction(
                new GatedAction(UnitTestGates.GetGate(gate.Name),
                                () => { result = true; }));

            Assert.True(result, "Expected action to be run.");
            Assert.True(gateContext.ActivatedGates.Contains(gate), "Expected gate to be activated.");
        }
Exemple #2
0
        public void PerformAction_WhenTestGroupIsSpecifiedAndRequestDoesNotHaveMatchingUser_DoesNotRunAction()
        {
            Gate gate = new Gate("client")
            {
                Users     = new HashSet <string>(new string[] { "*****@*****.**" }, StringComparer.OrdinalIgnoreCase),
                UserTypes = UserGroupTypes.CustomGroup
            };

            UnitTestGates.AddGateOverride(gate.Name, gate);

            UnitTestGatedRequest gatedRequest = new UnitTestGatedRequest
            {
                Users = new List <GatedUser>()
                {
                    new GatedUser()
                    {
                        IsDogfoodUser = false, UserIdentifier = "*****@*****.**"
                    }
                }
            };

            bool result = false;

            IGateContext gateContext = new GateContext(gatedRequest, new BasicMachineInformation(), new DefaultExperimentContext());

            gateContext.PerformAction(
                new GatedAction(UnitTestGates.GetGate(gate.Name),
                                () => { result = true; }));

            Assert.False(result, "Did not expected action to be run.");
            Assert.False(gateContext.ActivatedGates.Contains(gate), "Did not expected gate to be activated.");
        }
Exemple #3
0
        public void PerformAction_WhenUsergroupNoneIsSpecifiedAndGateIsRequested_RunsAction()
        {
            Gate gate = new Gate("client")
            {
                UserTypes = UserGroupTypes.None
            };

            UnitTestGates.AddGateOverride(gate.Name, gate);

            UnitTestGatedRequest gatedRequest = new UnitTestGatedRequest
            {
                Users = new List <GatedUser>()
                {
                    new GatedUser()
                    {
                        IsDogfoodUser = false, UserIdentifier = "*****@*****.**"
                    }
                },
                RequestedGateIds = new HashSet <string>(new string[] { gate.Name })
            };

            bool result = false;

            IGateContext gateContext = new GateContext(gatedRequest, new BasicMachineInformation(), new DefaultExperimentContext());

            gateContext.PerformAction(
                new GatedAction(UnitTestGates.GetGate(gate.Name),
                                () => { result = true; }));

            Assert.True(result, "Expected action to be run.");
            Assert.True(gateContext.ActivatedGates.Contains(gate), "Expected gate to be activated.");
        }
Exemple #4
0
        public void PerformAction_WhenMarketRestrictionIsNotMetAndOverrideIsIncorrectlySpecified_DoesNotRunAction()
        {
            Gate gate = new Gate("override")
            {
                Markets = new HashSet <string>(new string[] { "en-us" }, StringComparer.OrdinalIgnoreCase)
            };

            UnitTestGates.AddGateOverride(gate.Name, gate);

            UnitTestGatedRequest gatedRequest = new UnitTestGatedRequest
            {
                RequestedGateIds = new HashSet <string>(StringComparer.OrdinalIgnoreCase)
                {
                    "nooverride"
                }
            };

            bool result = false;

            IGateContext gateContext = new GateContext(gatedRequest, new BasicMachineInformation(), new DefaultExperimentContext());

            gateContext.PerformAction(
                new GatedAction(UnitTestGates.GetGate(gate.Name),
                                () => { result = true; }));

            Assert.False(result, "Did not expected action to be run.");
            Assert.False(gateContext.ActivatedGates.Contains(gate), "Did not expected gate to be activated.");
        }
Exemple #5
0
        public void PerformAction_WhenClientVersionIntervalIsSpecifiedAndRequestHasClientMaxVersionExactlyOnInterval_DoesNotRunAction()
        {
            Gate gate = new Gate("client")
            {
                ClientVersions = new SortedDictionary <string, RequiredClient>(StringComparer.OrdinalIgnoreCase)
            };
            RequiredClient requiredClient = new RequiredClient()
            {
                Name = "Sharepoint", MinVersion = new ProductVersion(16, 0), MaxVersion = new ProductVersion(16, 2)
            };

            gate.ClientVersions.Add(requiredClient.Name, requiredClient);
            UnitTestGates.AddGateOverride(gate.Name, gate);

            UnitTestGatedRequest gatedRequest = new UnitTestGatedRequest
            {
                CallingClient = new GatedClient()
                {
                    Name = "Sharepoint", Version = new ProductVersion(16, 2)
                }
            };

            bool result = false;

            IGateContext gateContext = new GateContext(gatedRequest, new BasicMachineInformation(), new DefaultExperimentContext());

            gateContext.PerformAction(
                new GatedAction(UnitTestGates.GetGate(gate.Name),
                                () => { result = true; }));

            Assert.False(result, "Did not expected action to be run.");
            Assert.False(gateContext.ActivatedGates.Contains(gate), "Did not expected gate to be activated.");
        }
Exemple #6
0
        public void PerformAction_SingleActiveGate_ShouldPerformScopedActionForActiveGate()
        {
            int          count       = 0;
            IGateContext gateContext = new GateContext(new UnitTestGatedRequest(), new BasicMachineInformation(), new DefaultExperimentContext());

            gateContext.PerformAction(Gates.GetGate("ActiveGate1"), () => { count++; });
            Assert.Equal(count, 1);
            Assert.True(gateContext.ActivatedGates.Contains(Gates.GetGate("ActiveGate1")), "Expected one gate to be activated");
        }
Exemple #7
0
        public void PerformAction_SingleInactiveGate_ShouldNotPerformScopedActionForInactiveGate()
        {
            int          count       = 0;
            IGateContext gateContext = new GateContext(new UnitTestGatedRequest(), new BasicMachineInformation(), new DefaultExperimentContext());

            gateContext.PerformAction(Gates.GetGate("InactiveGate1"), () => { count++; });
            Assert.Equal(count, 0);
            Assert.Equal(gateContext.ActivatedGates.Count(), 0);
        }
Exemple #8
0
 public void PerformAsyncAction_SingleActiveGate_ShouldPerformScopedActionForActiveGate()
 {
     VerifyAsync(async() =>
     {
         int count = 0;
         IGateContext gateContext = new GateContext(new UnitTestGatedRequest(), new BasicMachineInformation(), new DefaultExperimentContext());
         await gateContext.PerformAction(Gates.GetGate("ActiveGate1"),
                                         async() =>
         {
             count++;
             await Task.Delay(10);
         });
         Assert.Equal(count, 1);
         Assert.True(gateContext.ActivatedGates.Contains(Gates.GetGate("ActiveGate1")));
     });
 }
Exemple #9
0
        private void Run(string[] args)
        {
            GateDataSetLoader = CreateGateDataSetLoader(false);
            Gates gates = new Gates(GateDataSetLoader);

            IGatedRequest gatedRequest = new SampleGatedRequest();
            IGateContext  gateContext  = new GateContext(gatedRequest, null, null);

            gateContext.PerformAction(new GatedAction(gates.GetGate("sample_allowed_gate"), SampleAction));

            Console.WriteLine("Loaded gates:");
            foreach (string gateName in gates.GateNames)
            {
                Console.WriteLine(gateName);
            }
        }
Exemple #10
0
        public void PerformAction_WhenNoRestrictionsAreSpecified_RunsAction()
        {
            Gate gate = new Gate("default");

            UnitTestGates.AddGateOverride(gate.Name, gate);

            bool  result    = false;
            IGate foundGate = UnitTestGates.GetGate(gate.Name);

            IGateContext gateContext = new GateContext(new UnitTestGatedRequest(), new BasicMachineInformation(), new DefaultExperimentContext());

            gateContext.PerformAction(
                new GatedAction(foundGate,
                                () => { result = true; }));

            Assert.True(result, "Expected action to be run.");
            Assert.True(gateContext.ActivatedGates.Contains(gate), "Expected gate to have been registered as activated.");
        }
Exemple #11
0
        public void PerformAction_WhenMarketRestrictionIsNotMetAndMultipleOverridesAreSpecified_RunsFirstMatchingAction()
        {
            // ARRANGE
            Gate gate = new Gate("override")
            {
                Markets = new HashSet <string>(new string[] { "en-us" }, StringComparer.OrdinalIgnoreCase)
            };

            UnitTestGates.AddGateOverride(gate.Name, gate);

            Gate secondGate = new Gate("secondOverride")
            {
                Markets = new HashSet <string>(new string[] { "en-us" }, StringComparer.OrdinalIgnoreCase)
            };

            UnitTestGates.AddGateOverride(secondGate.Name, secondGate);

            UnitTestGatedRequest gatedRequest = new UnitTestGatedRequest
            {
                RequestedGateIds = new HashSet <string>(StringComparer.OrdinalIgnoreCase)
                {
                    "override",
                    "secondOverride"
                }
            };

            // ACT
            bool result = false;

            IGateContext gateContext = new GateContext(gatedRequest, new BasicMachineInformation(), new DefaultExperimentContext());

            gateContext.PerformAction(
                new GatedAction(UnitTestGates.GetGate(gate.Name),
                                () => { result = true; }),
                new GatedAction(UnitTestGates.GetGate(secondGate.Name),
                                () => { result = false; }));

            // ASSERT
            Assert.True(result, "Expected action to be run.");
            Assert.True(gateContext.ActivatedGates.Contains(gate), "Expected gate to be activated.");
            Assert.False(gateContext.ActivatedGates.Contains(secondGate), "Expected second gate not to be activated.");
        }
Exemple #12
0
        public void PerformAction_WithUnscopedModeAndMultipleActiveAndInactiveGates_ShouldPerformUnscopedActionForFirstActiveGate()
        {
            int          count       = 0;
            IGateContext gateContext = new GateContext(new UnitTestGatedRequest(), new BasicMachineInformation(), new DefaultExperimentContext());

            gateContext.PerformAction(GatedCode.Modes.None,
                                      new GatedAction(Gates.GetGate("InactiveGate1"),
                                                      () => { Assert.False(true, "Should not perform action for inactive gate."); }),
                                      new GatedAction(Gates.GetGate("ActiveGate1"),
                                                      () => { count++; }),
                                      new GatedAction(Gates.GetGate("ActiveGate2"),
                                                      () => { Assert.False(true, "Should not perform action for second active gate."); }),
                                      new GatedAction(Gates.GetGate("InactiveGate2"),
                                                      () => { Assert.False(true, "Should not perform action for inactive gate."); }),
                                      new GatedAction(
                                          () => { Assert.False(true, "Should not perform action for base line."); }));

            Assert.Equal(count, 1);
            Assert.False(gateContext.ActivatedGates.Contains(Gates.GetGate("ActiveGate1")), "Expected one gate not to be reported as activated");
        }