public ForwardGate EvaluateNotGate(ForwardGate inputGate, GateContext gateContext, CircuitContext circuitContext)
        {
            ForwardGate gate = new ForwardNotGate(gateContext);

            inputGate.AddSuccessor(gate);
            return(gate);
        }
Exemple #2
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 #3
0
        public GateContext gate()
        {
            GateContext _localctx = new GateContext(Context, State);

            EnterRule(_localctx, 10, RULE_gate);
            int _la;

            try {
                EnterOuterAlt(_localctx, 1);
                {
                    State = 42;
                    _la   = TokenStream.LA(1);
                    if (!((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__5) | (1L << T__6) | (1L << T__7) | (1L << T__8) | (1L << T__9))) != 0)))
                    {
                        ErrorHandler.RecoverInline(this);
                    }
                    else
                    {
                        ErrorHandler.ReportMatch(this);
                        Consume();
                    }
                }
            }
            catch (RecognitionException re) {
                _localctx.exception = re;
                ErrorHandler.ReportError(this, re);
                ErrorHandler.Recover(this, re);
            }
            finally {
                ExitRule();
            }
            return(_localctx);
        }
Exemple #4
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 #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_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 #7
0
        public void PerformConditionalAsyncFunction_WithFailedCondition_ShouldPerformDefaultFunction()
        {
            VerifyAsync(async() =>
            {
                int count = 0;
                IGateContext gateContext = new GateContext(new UnitTestGatedRequest(), new BasicMachineInformation(), new DefaultExperimentContext());
                await gateContext.PerformConditionalFunction(
                    () => false,
                    new GatedAsyncFunc <int>(
                        Gates.GetGate("ActiveGate1"),
                        () =>
                {
                    count = 1;
                    return(Task.FromResult(count));
                }),
                    new GatedAsyncFunc <int>(
                        () =>
                {
                    count = 2;
                    return(Task.FromResult(count));
                }));

                Assert.Equal(count, 2);
            });
        }
Exemple #8
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 #9
0
        public void PerformConditionalFunction_WithFailedCondition_ShouldPerformDefaultFunction()
        {
            int          count       = 0;
            IGateContext gateContext = new GateContext(new UnitTestGatedRequest(), new BasicMachineInformation(), new DefaultExperimentContext());

            gateContext.PerformConditionalFunction(
                () =>
            {
                return(false);
            },
                new GatedFunc <int>(
                    Gates.GetGate("ActiveGate1"),
                    () =>
            {
                count += 1;
                return(count);
            }),
                new GatedFunc <int>(
                    () =>
            {
                count += 2;
                return(count);
            }));

            Assert.Equal(count, 2);
        }
Exemple #10
0
        public void PerformConditionalAsyncFunction_NonValidGates_ShouldNotPerformAnyGatedFunction()
        {
            VerifyAsync(async() =>
            {
                int count = 0;
                IGateContext gateContext = new GateContext(new UnitTestGatedRequest(), new BasicMachineInformation(), new DefaultExperimentContext());
                await gateContext.PerformConditionalFunction(
                    () => true,
                    new GatedAsyncFunc <int>(
                        Gates.GetGate("InactiveGate1"),
                        () =>
                {
                    count += 1;
                    return(Task.FromResult(count));
                }),
                    new GatedAsyncFunc <int>(
                        Gates.GetGate("InactiveGate2"),
                        () =>
                {
                    count += 2;
                    return(Task.FromResult(count));
                }));

                Assert.Equal(count, 0);
            });
        }
Exemple #11
0
        public void PerformConditionalFunction_NonValidGates_ShouldNotPerformAnyGatedFunction()
        {
            int          count       = 0;
            IGateContext gateContext = new GateContext(new UnitTestGatedRequest(), new BasicMachineInformation(), new DefaultExperimentContext());

            gateContext.PerformConditionalFunction(
                () =>
            {
                return(true);
            },
                new GatedFunc <int>(
                    Gates.GetGate("InactiveGate1"),
                    () =>
            {
                count += 1;
                return(count);
            }),
                new GatedFunc <int>(
                    Gates.GetGate("InactiveGate2"),
                    () =>
            {
                count += 2;
                return(count);
            }));

            Assert.Equal(count, 0);
        }
Exemple #12
0
        public void PerformFunction_SingleActiveGate_ShouldPerformScopedFunctionForActiveGate()
        {
            IGateContext gateContext = new GateContext(new UnitTestGatedRequest(), new BasicMachineInformation(), new DefaultExperimentContext());
            int          result      = gateContext.PerformFunction(Gates.GetGate("ActiveGate1"), () => { return(1); });

            Assert.Equal(result, 1);
            Assert.True(gateContext.ActivatedGates.Contains(Gates.GetGate("ActiveGate1")), "Expected one gate to be activated");
        }
Exemple #13
0
        public void PerformFunction_SingleInactiveGate_ShouldNotPerformScopedFunctionForInactiveGate()
        {
            IGateContext gateContext = new GateContext(new UnitTestGatedRequest(), new BasicMachineInformation(), new DefaultExperimentContext());
            int          result      = gateContext.PerformFunction(Gates.GetGate("InactiveGate1"), () => { return(1); });

            Assert.Equal(result, 0);
            Assert.Equal(gateContext.ActivatedGates.Count(), 0);
        }
Exemple #14
0
        public void IsGateApplicable_WhenGateIsDisabled_ReturnFalse()
        {
            IGatedRequest gatedRequest = SetupGatedRequest("ClientOne", "16.3.0.0", "en-us", "PreProduction", 0);
            GateContext   context      = new GateContext(gatedRequest, new UnitTestMachineInformation(), new DefaultExperimentContext());

            Assert.False(context.IsGateApplicable(m_dataset.GetGate("MyProduct.Test.DisabledGate")),
                         "Gate is disabled through the enabled flag in the xml.");
        }
        public int EvaluateNotGate(int value, GateContext gateContext, CircuitContext circuitContext)
        {
            int layerIndex = value;

            GetLayerStatisticsBuilder(layerIndex).AddLinearGate();
            UpdateContext(circuitContext);
            return(layerIndex);
        }
Exemple #16
0
        public void IsGateApplicable_OnSupplyChainServiceWithNoneServiceFlag_ReturnsGateToBeNotApplicable()
        {
            IGatedRequest gateRequest = SetupGatedRequest("ClientOne", "16.3.0.0", "en-us", null, 0);
            GateContext   context     = new GateContext(gateRequest, new UnitTestMachineInformation("ServiceFive"), new DefaultExperimentContext());

            Assert.False(context.IsGateApplicable(m_dataset.GetGate("MyProduct.Test.Services")),
                         "Gate should be not applicable for supplychain service as service flag is set to none.");
        }
        public int EvaluateXorGate(int leftValue, int rightValue, GateContext gateContext, CircuitContext circuitContext)
        {
            int layerIndex = Math.Max(leftValue, rightValue);

            GetLayerStatisticsBuilder(layerIndex).AddLinearGate();
            UpdateContext(circuitContext);
            return(layerIndex);
        }
Exemple #18
0
        public void IsGateApplicable_OnCoSubRetailerCanaryService_ReturnsGateToBeApplicable()
        {
            IGatedRequest gateRequest = SetupGatedRequest("ClientOne", "16.3.0.0", "en-us", null, 0);
            GateContext   context     = new GateContext(gateRequest, new UnitTestMachineInformation("ServiceTwo", true), new DefaultExperimentContext());

            Assert.True(context.IsGateApplicable(m_dataset.GetGate("MyProduct.Test.Services")),
                        "Gate should not be applicable for cosubretailer canary service.");
        }
Exemple #19
0
        public void IsGateApplicable_OnDataStoreService_ReturnsGateToBeApplicable()
        {
            IGatedRequest gateRequest = SetupGatedRequest("ClientOne", "16.3.0.0", "en-us", null, 0);
            GateContext   context     = new GateContext(gateRequest, new UnitTestMachineInformation("ServiceFour"), new DefaultExperimentContext());

            Assert.True(context.IsGateApplicable(m_dataset.GetGate("MyProduct.Test.Services")),
                        "Gate should be applicable for datastore service.");
        }
Exemple #20
0
        public void IsGateApplicable_RequestNotMadeFromBrowserWithGateBlockingBrowsers_ReturnsApplicable()
        {
            UnitTestGatedRequest request = new UnitTestGatedRequest("BrowserFive", -1);
            GateContext          context = new GateContext(request, new UnitTestMachineInformation(), new DefaultExperimentContext());

            Assert.True(context.IsGateApplicable(m_dataset.GetGate("MyProduct.Test.BlockedBrowsers.Browsers")),
                        "If request is not made from a browser and gate is blocking access for certain browsers, context should return applicable");
        }
Exemple #21
0
        public void IsGateApplicable_ForNoServiceDescribedInGateOnRetailerService_ReturnsGateToBeNotApplicable()
        {
            IGatedRequest gateRequest = SetupGatedRequest("ClientOne", "16.3.0.0", "en-us", null, 0);
            GateContext   context     = new GateContext(gateRequest, new UnitTestMachineInformation(), new DefaultExperimentContext());

            Assert.False(context.IsGateApplicable(m_dataset.GetGate("MyProduct.Test.ServicesWithOutAnyService")),
                         "Gate should not be applicable when service tag doesn't have any service");
        }
Exemple #22
0
        public void IsGateApplicable_GateWithNonCompatibleBlockedBrowserVersion_ReturnsApplicable()
        {
            UnitTestGatedRequest request = new UnitTestGatedRequest();
            GateContext          context = new GateContext(request, new UnitTestMachineInformation(), new DefaultExperimentContext());

            Assert.True(context.IsGateApplicable(m_dataset.GetGate("MyProduct.Test.BlockedBrowsers.NonCompatibleBrowserVersion")),
                        "Gate having non compatible blocked browser version should be applicable.");
        }
Exemple #23
0
        public void IsGateApplicable_GateWithCompatibleBlockedBrowserAndVersion_ReturnsNotApplicable()
        {
            UnitTestGatedRequest request = new UnitTestGatedRequest();
            GateContext          context = new GateContext(request, new UnitTestMachineInformation(), new DefaultExperimentContext());

            Assert.False(context.IsGateApplicable(m_dataset.GetGate("MyProduct.Test.BlockedBrowsers.Browsers")),
                         "Gate having compatible blocked browser should not be applicable.");
        }
Exemple #24
0
        public void IsGateApplicable_GateWithBlockedBrowserButNoVersion_ReturnsNotApplicable()
        {
            UnitTestGatedRequest request = new UnitTestGatedRequest();
            GateContext          context = new GateContext(request, new UnitTestMachineInformation(), new DefaultExperimentContext());

            Assert.False(context.IsGateApplicable(m_dataset.GetGate("MyProduct.Test.BlockedBrowsers.NoBlockedBrowserVersion")),
                         "Gate having no browser version constraint should be not applicable as the browser is blocked for all versions.");
        }
Exemple #25
0
        public void IsGateApplicable_RequestNotMadeFromBrowserWithGateExpectingBrowsers_ReturnsNotApplicable()
        {
            UnitTestGatedRequest request = new UnitTestGatedRequest("BrowserFive", -1);
            GateContext          context = new GateContext(request, new UnitTestMachineInformation(), new DefaultExperimentContext());

            Assert.False(context.IsGateApplicable(m_dataset.GetGate("MyProduct.Test.BrowserType.Browsers")),
                         "If request is not made from a browser and gate is active only for certain browsers, context should return not applicable");
        }
Exemple #26
0
        public void IsGateApplicable_GateWithBrowserButNoVersion_ReturnsApplicable()
        {
            UnitTestGatedRequest request = new UnitTestGatedRequest();
            GateContext          context = new GateContext(request, new UnitTestMachineInformation(), new DefaultExperimentContext());

            Assert.True(context.IsGateApplicable(m_dataset.GetGate("MyProduct.Test.BrowserType.NoBrowserVersion")),
                        "Gate having no browser version constraint should be applicable.");
        }
Exemple #27
0
        public void RequestWithEnvironment_Specified()
        {
            IGatedRequest gatedRequest = SetupGatedRequest("ClientOne", "16.3.0.0", "en-us", "PreProduction", 8);
            GateContext   context      = new GateContext(gatedRequest, new UnitTestMachineInformation(), new DefaultExperimentContext());

            Assert.True(context.IsGateApplicable(m_dataset.GetGate("MyProduct.Test.NoEnvironment")), "Gate with no environment restrictions should be applicable");
            Assert.True(context.IsGateApplicable(m_dataset.GetGate("MyProduct.Test.ReqEnvironment")), "Gate with environment restrictions should be applicable");
            Assert.True(context.IsGateApplicable(m_dataset.GetGate("DogfoodApps")), "Gate with environment restrictions and no client version restrictions should be applicable");
        }
Exemple #28
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 #29
0
        public void IsGateApplicable_GateWithDates_ReturnCorrectly()
        {
            IGatedRequest gateRequest = SetupGatedRequest("ClientOne", "16.3.0.0", "en-us", "PreProduction", 8);
            GateContext   context     = new GateContext(gateRequest, new UnitTestMachineInformation(), new DefaultExperimentContext());

            Assert.True(context.IsGateApplicable(m_dataset.GetGate("CorrectDate")), "Gate with correct dates should be applicable");
            Assert.False(context.IsGateApplicable(m_dataset.GetGate("BeforeStartDate")), "Gate Before Start Date should  ot be applicable");
            Assert.False(context.IsGateApplicable(m_dataset.GetGate("AfterEndDate")), "Gate after end date should not be applicable");
        }
Exemple #30
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);
        }