public Toggle AddAppToToggle(BWList.ListColor color, string toggleID, App app, string user_token) { Toggle res = null; if (!this.authenticationService.isValidToken(user_token)) { throw new TogglerExceptionNotAdmin(); } Toggle t; try { t = this.retrieveToggle(toggleID, user_token, app.ID, app.Version); } catch (Exception) // NOTE catch em all { throw; } try { t.AddToList(color, app); res = this.UpdateToggle(t, user_token, $"Added app [{app.ID}] to Toggle [{t.Name}] {color} list"); } catch (Exception) { t.RemoveFromBW(color, app); throw; } return(res); }
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()); }
public void RewriteBW(BWList.ListColor color, HashSet <App> otherBWL) { if (color == BWList.ListColor.BLACK) { HashSet <App> otherBLCopy = new HashSet <App>(); foreach (var app in otherBWL) { otherBLCopy.Add(app); } RemoveAllFromBL(); foreach (var app in otherBLCopy) { GetBlackList().Add(app); } } else if (color == BWList.ListColor.WHITE) { HashSet <App> otherWLCopy = new HashSet <App>(); foreach (var app in otherBWL) { otherWLCopy.Add(app); } RemoveAllFromWL(); foreach (var app in otherWLCopy) { GetWhiteList().Add(app); } } }
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); }
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); }
public int BwCount(BWList.ListColor color) { int res = 0; if (color == BWList.ListColor.BLACK) { res = GetBlackList().Count; } if (color == BWList.ListColor.WHITE) { res = GetWhiteList().Count; } return(res); }
public bool RemoveFromBW(BWList.ListColor color, App app) { bool res = false; if (color == BWList.ListColor.BLACK) { if (!isAppOnBL(app)) { return(res); } res = GetBlackList().Remove(app); } else if (color == BWList.ListColor.WHITE) { if (!isAppOnWL(app)) { return(res); } res = GetWhiteList().Remove(app); } return(res); }
public bool AddToList(BWList.ListColor color, App app) { bool res = false; if (color == BWList.ListColor.BLACK) { if (HasWL()) { return(res); } res = GetBlackList().AddToList(app); } else if (color == BWList.ListColor.WHITE) { if (HasBL()) { return(res); } res = GetWhiteList().AddToList(app); } return(res); }