public void ChangeTotalIsSumOfAllCoins() { var change = new Change(); change.Add(TestHelpers.Quarter); change.Add(TestHelpers.Quarter); change.Add(TestHelpers.Dime); change.Value.ShouldBe(TestHelpers.Quarter.MonetaryValue * 2 + TestHelpers.Dime.MonetaryValue); }
public override async Task Check(Repository repo) { l($"Checking for solo collaborators on {repo.Name}", 1); repositoryQuery = new graphqueries.RepoCollaborators(Graph, repo.Name); var memberships = await repositoryQuery.GetCollaborators(); var admins = await GetOrganisationAdmins(); var collabs = memberships // only grab collaborators in this repo .Where(m => m.Contexts.Select(s => s.IsCollaborator()).Any(s => s)) .Select(m => m.Login) // and filter out the admins, because they don't count .Except(admins); if (collabs.Any()) { collabs.ToList().ForEach(c => l($"[UPDATE] Will remove {c} from {repo.Name}", 2)); Change.Add(new KeyValuePair <Repository, IList <string> >(repo, collabs.ToList())); } else { l($"[SKIP] Did not find any collaborators outside of the team in {repo.Name}", 2); } }
private void ShowAllObjects(Change change) { var hidden = change.Document.Map.Root.Find(x => x.Data.OfType <CordonHidden>().Any()).ToList(); foreach (var o in hidden) { o.Data.Remove(x => x is CordonHidden); change.Add(o); } }
public void UpdateTest2() { var expression = new UpdateExpression(new[] { Change.Add("list", new[] { "A", "B", "C" }), Change.Remove("deleted") }, new JsonObject(), new AttributeCollection()); Assert.Equal(@"REMOVE deleted ADD list :v0", expression.ToString()); }
private void SetObjectVisibilities(Change change, Box bounds) { // Hide objects that are currently visible but shouldn't be // Show objects that are not currently visible but should be foreach (var o in change.Document.Map.Root.FindAll()) { var shouldBeVisible = o.BoundingBox != null && o.BoundingBox.IntersectsWith(bounds); var isCurrentlyVisible = !o.Data.OfType <CordonHidden>().Any(); if (shouldBeVisible && !isCurrentlyVisible) { o.Data.Remove(x => x is CordonHidden); change.Add(o); } else if (!shouldBeVisible && isCurrentlyVisible) { o.Data.Add(new CordonHidden()); change.Add(o); } } }
public override async Task Check(Repository repo) { var message = UPDATE; var settings = RepoSettingsFor(repo.Name); var update = new RepoUpdate { Name = repo.Name, DefaultBranch = repo.DefaultBranch }; if (await ShouldSetStrict(settings, repo)) { if (!message.Equals(UPDATE)) { message += " and "; } message += "will remove strict reviewers"; update.UpdateStrictReviews = true; } if (await ShouldSetReviewers(settings, update, repo)) { if (!message.Equals(UPDATE)) { message += " and "; } message += "will set "; var changes = new List <string>(); if (update.UpdateReviewers) { changes.Add($"required reviewers to {settings.Reviewers}"); } if (update.UpdateRequireOwners) { changes.Add($"require codeowners to {settings.RequireCodeOwnerReviews}"); } if (update.UpdateDismissStale) { changes.Add($"dismiss state reviews to {settings.DismissStaleReviews}"); } message += string.Join(',', changes); } if (message.Equals(UPDATE)) { l($"[OK] {repo.Name} already has {repo.DefaultBranch} branch protection with the number of reviewers {settings.Reviewers}, {(settings.RequireStrictReviews ? "non-" : string.Empty)}strict and {(settings.RequireCodeOwnerReviews ? "should " : "shouldn\'t") }code owners reviews", 1); } else { l($"{message} on {repo.Name}", 1); Change.Add(update); } }
public void UpdateTest4() { var expression = new UpdateExpression(new[] { Change.Replace("deleted", new DateTime(2015, 01, 01)), Change.Replace("colors", new [] { "red", "yellow", "blue" }), Change.Remove("deleted"), Change.Add("version", 1), Change.Replace("modified", DateTime.UtcNow) }, new JsonObject(), new AttributeCollection()); Assert.Equal(@"SET deleted = :v0, colors = :v1, modified = :v3 REMOVE deleted ADD version :v2", expression.ToString()); }
public Result Write(string value, int at) { if (value == null) { return(Result.Failed("Couldn't insert null.")); } if (at < 0) { return(Result.Failed($"Couldn't insert \"{value}\": index [ {at} ] is less than zero.")); } if (at > _length) { return(Result.Failed($"Couldn't insert \"{value}\": index [ {at} ] is greater than [ {_length} ] length.")); } _changes.Add(Change.Add(value, at)); _length += value.Length; return(Result.Succeded()); }
public void WhenVendorCancelsMachineReturnsAllCoins() { var mockedChange = new Change(); mockedChange.Add(TestHelpers.Quarter); var mockedChangeCalculator = new Mock <IChangeCalculator>(); mockedChangeCalculator.Setup(m => m.GetChange(It.IsAny <double>())).Returns(mockedChange); VendingMachine = new VendingMachine(mockedChangeCalculator.Object); VendingMachine.InsertCoin(TestHelpers.Quarter); var response = VendingMachine.ReturnCoins(); response.ShouldNotBeNull(); response.Change.Coins.Count.ShouldBe(1); VendingMachine.CurrentTransaction.ShouldBeNull(); VendingMachine.GetCurrentState().Message.ShouldBe("INSERT COIN"); }
public async Task <Change> Reverse(MapDocument document) { var ch = new Change(document); var par = document.Map.Root.FindByID(_parentId); _idsToDetatch = _detatchedObjects.Select(x => x.ID).ToList(); foreach (var o in _detatchedObjects) { // Add parent ch.Add(o); // Add all descendants ch.AddRange(o.FindAll()); o.Hierarchy.Parent = par; } _detatchedObjects = null; return(ch); }
public async Task <Change> Perform(MapDocument document) { var ch = new Change(document); var par = document.Map.Root.FindByID(_parentId); _attachedIds = _objectsToAttach.Select(x => x.ID).ToList(); foreach (var o in _objectsToAttach) { // Add parent ch.Add(o); // Add all descendants ch.AddRange(o.FindAll()); o.Hierarchy.Parent = par; } _objectsToAttach = null; return(ch); }
public void WhenProductSelectedCostsLessThanBalanceReturnTheChange() { var mockedChange = new Change(); mockedChange.Add(TestHelpers.Quarter); var mockedChangeCalculator = new Mock <IChangeCalculator>(); mockedChangeCalculator.Setup(m => m.GetChange(It.IsAny <double>())).Returns(mockedChange); VendingMachine = new VendingMachine(mockedChangeCalculator.Object); VendingMachine.InsertCoin(TestHelpers.Quarter); VendingMachine.InsertCoin(TestHelpers.Quarter); VendingMachine.InsertCoin(TestHelpers.Quarter); VendingMachine.InsertCoin(TestHelpers.Quarter); VendingMachine.InsertCoin(TestHelpers.Quarter); var response = VendingMachine.SelectProduct(ProductCode.Cola); response.Change.Coins.Count.ShouldBe(1); }
public override async Task Check(Repository repo) { MergeSettingsFor(repo.Name, out var allowMerge, out var allowRebase, out var allowSquash); var allowed = FormatMessage(allowMerge, allowRebase, allowSquash); // Merge settings are not part of the hashing algo when generating a ETag on the // github cache. Meaning that changing these settings will not trigger a cache // invalidation. This means that somebody could change these settings and we wouldn't // be the wiser. While this isn't ideal, actions like pullrequest and commits do // update the etag. So we might not catch it right away, but we'll catch it eventually. var r = await Client.Repository.Get(repo.Owner.Login, repo.Name); if (r.AllowMergeCommit != allowMerge || r.AllowRebaseMerge != allowRebase || r.AllowSquashMerge != allowSquash) { l($"[UPDATE] Changing {repo.Name} to {allowed}", 1); Change.Add(repo); } else { l($"[OK] {repo.Name} is already set to {allowed}", 1); } }
async Task LoadChanges() { if (IsBusy) { return; } IsBusy = true; Change.Clear(); DateTime date = DateTime.Today; if (App.Current.Properties["ChangeState"].ToString() != "2") { Title = App.Current.Properties["ChangeState"].ToString(); } int state = Int32.Parse(Title); date = date.AddDays(state); var weekday = (int)date.DayOfWeek; if ((int)date.DayOfWeek > 5) { int ile = 8 - (int)date.DayOfWeek; date = date.AddDays(ile); } string MyClass = App.Current.Properties["Class"].ToString(); string day = date.Day.ToString(); string monthday = date.Month.ToString().PadLeft(2, '0'); try { string url = "http://www.zse.srem.pl/index.php?opcja=modules/zastepstwa/view_id&id=" + (int)date.DayOfWeek; HtmlWeb web = new HtmlWeb { CachePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/Change" + state, UsingCache = true }; HtmlDocument htmldoc = await Task.Run(() => web.Load(url)); var html1 = htmldoc.DocumentNode.SelectNodes("//span[contains(text(),'Zastępstwa')]"); if (html1 != null) { string html1_title = html1[0].InnerText; html1_title = html1_title.Replace(" ", ""); Debug.WriteLine(html1_title); if (html1_title.Contains(day + "." + monthday)) { var htmlNodes = htmldoc.DocumentNode.SelectNodes("//p//span"); foreach (var node in htmlNodes) { if (node.SelectSingleNode("//strike") != null) { node.SelectSingleNode("//strike").Remove(); } string line = node.InnerText; if (node.InnerHtml != "<br>") { if (line.Contains("\r\n")) { line = line.Replace("\r\n", " "); } if (line.Contains(monthday + ".")) { line = line.Replace(monthday + ".", monthday); } if (line.IndexOf(" l.") != -1) { string Class = line.Substring(0, line.IndexOf(" l.")); Class = Class.Substring(4); line = line.Substring(line.IndexOf(" l.") + 1); if (Class.ToLower() == MyClass) { Change.Add(new ChangeList() { Changed = line }); } } } else { break; } } if (Change.Count == 0) { Change.Add(new ChangeList() { Changed = "Brak zastępstw dla twojej klasy 😞" }); } } else { Change.Add(new ChangeList() { Changed = "Zastępstwa na ten dzień nie zostały jeszcze wpisane 😞" }); } } else { Change.Add(new ChangeList() { Changed = "Strona zastępstw na ten dzień jest pusta 😞" }); } } catch (System.Net.WebException) { Change.Add(new ChangeList() { Changed = "Brak połączenia z serwerem 🚫" }); } catch (Exception ex) { Debug.WriteLine(ex); } IsBusy = false; }