コード例 #1
0
        public void TestUpdateToggle()
        {
            //Given
            var data = new Dictionary <string, Object>();

            data.Add("name", (object)"feature 1");
            var uct = new UCIToggle();

            // NOTE insert "feature 1" without BL
            uct.RegistToggle(data);

            //When
            Toggle rt1 = uct.returnToggle("feature 1");
            App    aA  = new App("a", "1");
            App    aB  = new App("b", "1");

            BWList.ListColor color = BWList.ListColor.BLACK;
            rt1.AddToList(color, aA);
            rt1.AddToList(color, aB);

            // NOTE updated "feature 1" with a BL
            uct.UpdateToggle(rt1, $"Added {aA.ID} and {aB.ID} to toggle {rt1.Name} to {color} list.");


            //Then
            Toggle rt2 = uct.returnToggle("feature 1");

            Assert.Equal(rt1.GetBlackList(), rt2.GetBlackList());
        }
コード例 #2
0
        public void TestIsAppOnBLForToggleNotSameRef()
        {
            //Given
            var data = new Dictionary <string, Object>();

            data.Add("name", (object)"feature 1");
            var uci_t = new UCIToggle();

            uci_t.RegistToggle(data);

            //When
            Toggle t     = uci_t.returnToggle("feature 1");
            App    app_a = new App("alpha app", "1");

            BWList.ListColor color = BWList.ListColor.BLACK;
            t.AddToList(color, app_a);
            uci_t.UpdateToggle(t, $"Added {app_a.ID} to toggle {t.Name} to {color} list.");

            //When
            Toggle t1      = new Toggle("feature 1"); // NOTE this is a new instance
            bool   current = t1.isAppOnBL(app_a);

            //Then
            Assert.True(t1.BwCount(BWList.ListColor.BLACK) == 0);
            Assert.False(current);
        }
コード例 #3
0
        public void TestIsAppOnBLForToggle()
        {
            //Given
            var data = new Dictionary <string, Object>();

            data.Add("name", (object)"feature 1");
            var uci_t = new UCIToggle();

            uci_t.RegistToggle(data);

            //When
            Toggle t     = uci_t.returnToggle("feature 1");
            App    app_a = new App("alpha app", "1");
            App    app_b = new App("bravo app", "1");

            BWList.ListColor color = BWList.ListColor.BLACK;
            t.AddToList(color, app_a);
            t.AddToList(color, app_b);
            uci_t.UpdateToggle(t, $"Added {app_a.ID} and {app_b.ID} to toggle {t.Name} to {color} list.");

            //bool current = uci_t.isAppOnBLForToggle(app_a.ID, app_a.version, t);
            bool current = t.isAppOnBL(app_a);

            //Then
            Assert.True(current);
        }
コード例 #4
0
        public void TestRegistToggleNameIsNull()
        // TODO TestRegistToggleNameIsNull
        {
            //Given
            var uc = new UCIToggle();

            //When
            var current = uc.returnToggle(null);

            //Then
            Assert.Null(current);
        }
コード例 #5
0
        public void TestRetrieveToggleWhenNone()
        // TODO TestRetrieveToggleWhenNone
        {
            //Given
            var uc = new UCIToggle();

            //When
            var current = uc.returnToggle("feature 1");

            //Then
            Assert.Null(current);
        }
コード例 #6
0
        public Toggle retrieveToggle(string name, string user_token, string appID, string appVersion)
        {
            Toggle res = null;

            if (!authenticationService.isValidToken(user_token))
            {
                throw new TogglerExpectionNotValidToken();
            }

            res = _uciToggle.returnToggle(name);

            if (res == null)
            {
                throw new TogglerExpectionUnknownToggle();
            }

            // NOTE admin can access the toggle
            if (this.authenticationService.isAdmin(user_token))
            {
                return(res);
            }

            // NOTE other users need to send their id and version.
            if (appID == null || appVersion == null)
            {
                throw new TogglerExpectionInvalidAppIDVersion();
            }

            bool can_use = true;

            if (res != null && res.HasWL() && !res.isAppOnWL(new App(appID, appVersion)))
            {
                Console.WriteLine($"App {appID} is on WL for toggle {res.Name}");
                can_use = false;
            }

            if (res != null && res.HasBL() && res.isAppOnBL(new App(appID, appVersion)))
            {
                Console.WriteLine($"App {appID} is on BL for toggle {res.Name}");
                can_use = false;
            }

            if (!can_use)
            {
                throw new TogglerExpectionNotAllowedToUseToggle();
            }

            return(res);
        }
コード例 #7
0
        public void TestRegistToggle()
        {
            //Given
            var uc   = new UCIToggle();
            var data = new Dictionary <string, Object>();

            data.Add("name", (object)"feature 1");

            //When
            uc.RegistToggle(data);

            //Then
            var current  = uc.returnToggle("feature 1");
            var expected = new Toggle("feature 1");

            Assert.Equal(expected, current);
        }