public void createBranches() { _mainBranch = new Mock<Branch>().Object; _refBranch = new Mock<Branch>().Object; _mainBranch.Name = "Main"; _refBranch.Name = "Ref"; }
public ComparerResult Compare(Branch mainBranch, Branch refBranch) { var allCommitsMatch = true; var result = new ComparerResult(); result.MainBranch = mainBranch; result.RefBranch = refBranch; foreach (var mainCommit in mainBranch.Commits) { if (!refBranch.Commits.Select(c => c.Id).Contains(mainCommit.Id)) { var potentialByMsg = refBranch.Commits.Where(c => c.Message == mainCommit.Message); var potentialByName = potentialByMsg.Where(c => c.Name == mainCommit.Name); var potentialByFiles = potentialByName.Where(c => c.Files == mainCommit.Files); if (!potentialByFiles.Any()) { allCommitsMatch = false; break; } } } if (allCommitsMatch) { result.Status = ResultStatus.Yes; } else { result.Status = ResultStatus.No; } return result; }
public ComparerResult Compare(Branch mainBranch, Branch refBranch) { var containsAllIds = true; var result = new ComparerResult(); result.MainBranch = mainBranch; result.RefBranch = refBranch; foreach (var mainCommit in mainBranch.Commits.Select(c => c.Id)) { if (!refBranch.Commits.Select(c => c.Id).Contains(mainCommit)) { containsAllIds = false; break; } } if (containsAllIds) { result.Status = ResultStatus.Yes; } else { result.Status = ResultStatus.Unknown; } return result; }
public ComparerResult Compare(Branch mainBranch, Branch refBranch) { var result = new ComparerResult { MainBranch = mainBranch, RefBranch = refBranch }; if (mainBranch.Name == refBranch.Name) { result.Status = ResultStatus.No; } else { foreach (var comparer in _comparers) { result = comparer.Compare(mainBranch, refBranch); if (result.Status == ResultStatus.Yes || result.Status == ResultStatus.No) { break; } } } Log.Information("Branches compared: " + mainBranch.Name + " + " + refBranch.Name + ", Result: " + result.Status + "."); return result; }
public ComparerResult Compare(Branch mainBranch, Branch refBranch) { var mainCommits = mainBranch.Commits.Count(); var refCommits = refBranch.Commits.Count(); var result = new ComparerResult(); result.MainBranch = mainBranch; result.RefBranch = refBranch; // If there are no commits on the main branch, then the main branch // should be deleted if (mainCommits == 0) { result.Status = ResultStatus.Yes; } // If the main branch contains more commits than the reference branch, // then the main branch should not be deleted else if (mainCommits > refCommits) { result.Status = ResultStatus.No; } // If the main branch contains the same number of commits/fewer commits than // the reference branch, then we cannot deduce whether the main branch should // be deleted else { result.Status = ResultStatus.Unknown; } return result; }
/* * Compares a main branch against all branches in a list of branches. */ public ComparerResult CheckBranch(Branch mainBranch, List<Branch> branches) { var result = new ComparerResult(); foreach (var refBranch in branches) { result = _branchComparer.Compare(mainBranch, refBranch); if (result.Status == ResultStatus.Yes) { break; } } return result; }
public void When_The_Main_Branch_And_The_Ref_Branch_Have_The_Same_Number_Of_Commits_But_All_With_Different_Commit_Ids_Then_Its_Unknown_Wheter_The_Main_Branch_Should_Be_Deletable() { /* Setup */ var mainBranch = new Branch { Commits = new List<Commit> { new Commit { Id = _sha1 }, new Commit { Id = _sha2 } } }; var refBranch = new Branch { Commits = new List<Commit> { new Commit { Id = _sha3 }, new Commit { Id = _sha4 } } }; /* Test */ var result = _comparer.Compare(mainBranch, refBranch); /* Assert */ Assert.That(result.Status, Is.EqualTo(ResultStatus.Unknown)); }
public void When_The_Main_Branch_And_Ref_Branch_Have_The_Same_Number_Of_Commits_With_Identical_Commit_Ids_Then_The_Main_Branch_Should_Be_Deletable() { /* Setup */ var mainBranch = new Branch { Commits = new List<Commit> { new Commit { Id = _sha1 }, new Commit { Id = _sha2 } } }; var refBranch = new Branch { Commits = new List<Commit> { new Commit { Id = _sha1 }, new Commit { Id = _sha2 } } }; /* Test */ var result = _comparer.Compare(mainBranch, refBranch); /* Assert */ Assert.That(result.Status, Is.EqualTo(ResultStatus.Yes)); }
public void When_The_Main_Branch_Has_No_Commits_Then_The_Main_Branch_Should_Be_Deletable() { var mainBranch = new Branch { Commits = new List<Commit>() }; var refBranch = new Branch { Commits = new List<Commit>() }; /* Test */ var result = _comparer.Compare(mainBranch, refBranch); /* Assert */ Assert.That(result.Status, Is.EqualTo(ResultStatus.Yes)); Assert.That(result.MainBranch, Is.EqualTo(mainBranch)); Assert.That(result.RefBranch, Is.EqualTo(refBranch)); }
public void When_The_Main_Branch_Has_More_Commits_Than_The_Ref_Branch_Then_The_Main_Branch_Should_Not_Be_Deletable() { /* Setup */ var mainBranch = new Branch { Commits = new List<Commit> { new Commit(), new Commit() } }; var refBranch = new Branch { Commits = new List<Commit> { new Commit() } }; /* Test */ var result = _comparer.Compare(mainBranch, refBranch); /* Assert */ Assert.That(result.Status, Is.EqualTo(ResultStatus.No)); Assert.That(result.MainBranch, Is.EqualTo(mainBranch)); Assert.That(result.RefBranch, Is.EqualTo(refBranch)); }
public void When_The_Main_Branch_And_The_Ref_Branch_Has_The_Same_Number_Of_Commits_Then_Its_Unknown_Whether_The_Main_Branch_Should_Be_Deletable() { /* Setup */ var mainBranch = new Branch { Commits = new List<Commit> { new Commit() } }; var refBranch = new Branch { Commits = new List<Commit> { new Commit() } }; /* Test */ var result = _comparer.Compare(mainBranch, refBranch); /* Assert */ Assert.That(result.Status, Is.EqualTo(ResultStatus.Unknown)); Assert.That(result.MainBranch, Is.EqualTo(mainBranch)); Assert.That(result.RefBranch, Is.EqualTo(refBranch)); }
public void When_The_Ref_Branch_Has_More_Commits_Than_The_Main_Branch_But_Contains_Only_Some_Of_Main_Branchs_Commit_Ids_Then_Its_Unknown_Whether_The_Main_Branch_Should_Be_Deletable() { /* Setup */ var mainBranch = new Branch { Commits = new List<Commit> { new Commit { Id = _sha1 }, new Commit { Id = _sha2 } } }; var refBranch = new Branch { Commits = new List<Commit> { new Commit { Id = _sha1 }, new Commit { Id = _sha3 } } }; /* Test */ var result = _comparer.Compare(mainBranch, refBranch); /* Assert */ Assert.That(result.Status, Is.EqualTo(ResultStatus.Unknown)); Assert.That(result.MainBranch, Is.EqualTo(mainBranch)); Assert.That(result.RefBranch, Is.EqualTo(refBranch)); }
public void When_Remove_Invalid_Results_Is_Called_All_Results_That_Have_The_Same_Main_And_Ref_Branches_As_An_Earlier_Result_Should_Be_Removed() { /* SetUp */ var branch1 = new Branch { Name = "Branch 1" }; var branch2 = new Branch { Name = "Branch 2" }; var branch3 = new Branch { Name = "Branch 3" }; var mockComp = new Mock<IBranchComparer>().Object; var selector = new ComparisonSelector(mockComp); var results = new List<ComparerResult> { new ComparerResult { MainBranch = branch1, RefBranch = branch2 }, new ComparerResult { MainBranch = branch1, RefBranch = branch3 }, new ComparerResult { MainBranch = branch2, RefBranch = branch1 }, new ComparerResult { MainBranch = branch2, RefBranch = branch3 }, new ComparerResult { MainBranch = branch3, RefBranch = branch2 } }; var expectedResults = new List<ComparerResult> { new ComparerResult { MainBranch = branch1, RefBranch = branch2 }, new ComparerResult { MainBranch = branch1, RefBranch = branch3 }, new ComparerResult { MainBranch = branch2, RefBranch = branch3 } }; /* Test */ var finalResults = selector.RemoveInvalidResults(results); /* Assert */ Assert.That(finalResults.Select(r => r.MainBranch), Is.EqualTo(expectedResults.Select(r => r.MainBranch))); Assert.That(finalResults.Select(r => r.RefBranch), Is.EqualTo(expectedResults.Select(r => r.RefBranch))); }
public void When_Remove_Duplicates_Is_Called_Only_The_First_Instance_Of_All_Results_That_Have_The_Same_Main_Branch_Should_Be_Kept() { /* Setup */ var branch1 = new Branch { Name = "Branch 1"}; var branch2 = new Branch { Name = "Branch 2"}; var branch3 = new Branch { Name = "Branch 3"}; var results = new List<ComparerResult> { new ComparerResult { MainBranch = branch1, RefBranch = branch2 }, new ComparerResult { MainBranch = branch1, RefBranch = branch3 }, new ComparerResult { MainBranch = branch2, RefBranch = branch1 }, new ComparerResult { MainBranch = branch2, RefBranch = branch3 }, new ComparerResult { MainBranch = branch3, RefBranch = branch2 } }; var expectedResults = new List<ComparerResult> { new ComparerResult { MainBranch = branch1, RefBranch = branch2 }, new ComparerResult { MainBranch = branch2, RefBranch = branch1 }, new ComparerResult { MainBranch = branch3, RefBranch = branch2 } }; var mockComparer = new Mock<IBranchComparer>().Object; var selector = new ComparisonSelector(mockComparer); /* Test */ var finalResults = selector.RemoveDuplicates(results); /* Assert */ Assert.That(finalResults.Select(r => r.MainBranch), Is.EqualTo(expectedResults.Select(r => r.MainBranch))); Assert.That(finalResults.Select(r => r.RefBranch), Is.EqualTo(expectedResults.Select(r => r.RefBranch))); }
/* * Compares two submitted branches. */ public ComparerResult CompareBranches(Branch mainBranch, Branch refBranch) { var result = _branchComparer.Compare(mainBranch, refBranch); return result; }
public void When_All_Of_The_Main_Branchs_Commits_Share_Commit_Id_Or_Message_And_Author_Name_And_Files_With_All_Of_The_Ref_Branchs_Commits_Then_The_Main_Branch_Should_Be_Deletable() { /* Setup */ var mainBranch = new Branch { Commits = new List<Commit> { new Commit { Id = _sha1 }, new Commit { Id = _sha2, Message = _msg2, Name = _name2, Files = _files2 } } }; var refBranch = new Branch { Commits = new List<Commit> { new Commit { Id = _sha1 }, new Commit { Id = _sha3, Message = _msg2, Name = _name2, Files = _files2} } }; /* Test */ var result = _comparer.Compare(mainBranch, refBranch); /* Assert */ Assert.That(result.Status, Is.EqualTo(ResultStatus.Yes)); Assert.That(result.MainBranch, Is.EqualTo(mainBranch)); Assert.That(result.RefBranch, Is.EqualTo(refBranch)); }