public void MoveItemsTest() { // Arrange var id = Guid.NewGuid().ToString(); var sourceItems = new List <IDataItem>(); var sourceItem = new QuickContentDataItem(string.Empty, string.Empty, string.Empty, new SyncItem() { ID = id, TemplateID = id, ItemPath = "/sitecore/content/Home/Test1" }, true); sourceItems.Add(sourceItem); var targetItems = new List <IDataItem>(); var targetItem = new QuickContentDataItem(string.Empty, string.Empty, string.Empty, new SyncItem() { ID = id, TemplateID = id, ItemPath = "/sitecore/content/Home/Test2" }, true); targetItems.Add(targetItem); var sourceDataIterator = new TestDataIterator(sourceItems); var targetDataIterator = new TestDataIterator(targetItems); var engineMock = new Mock <DataEngine>(null, null, new List <ICommandFilter>()); // Act var commands = DiffGenerator.GetCommands(sourceDataIterator, targetDataIterator); //Assert Assert.AreEqual(1, commands.Count); Assert.AreEqual(1, commands.Count(x => x is ChangeItemCommand)); }
public void When_excel_product_does_not_match_eip_product_there_is_mismatch() { //arrange var logService = new Mock <ILogService>(); var eipProduct = new List <I07> { EipProductCodeAMakerA() }; var excelProduct = new List <ExcelProductData> { ExcelProductCodeAMakerB() }; var excelBlockData = new List <ExcelBlockData> { new ExcelBlockData { Date = new DateTime(2019, 7, 7), ProductData = excelProduct, SheetName = "A" } }; var generator = new DiffGenerator(logService.Object); var onlyMonthCheckSheets = new List <SheetCheckBoxItem>(); //assess var result = generator.GenerateDiffReport(eipProduct, excelBlockData, onlyMonthCheckSheets); var mismatches = result.Mismatches.ToList(); Assert.IsTrue(mismatches.Count == 1 && mismatches[0].ExcelData.Maker != mismatches[0].EipData.Maker); }
public void When_excel_has_more_products_then_eip___products_missing_from_eip_is_set() { //arrange var logService = new Mock <ILogService>(); var eipProduct = new List <I07> { EipProductCodeAMakerA() }; var excelProduct = new List <ExcelProductData> { ExcelProductCodeAMakerA(), ExcelProductCodeBMakerB() }; var excelBlockData = new List <ExcelBlockData> { new ExcelBlockData { Date = new DateTime(2019, 7, 7), ProductData = excelProduct, SheetName = "A" } }; var generator = new DiffGenerator(logService.Object); var onlyMonthCheckSheets = new List <SheetCheckBoxItem>(); //assess var result = generator.GenerateDiffReport(eipProduct, excelBlockData, onlyMonthCheckSheets); var missing = result.ProductsMissingFromEip.ToList(); Assert.IsTrue(!result.Mismatches.Any() && missing.Count == 1 && missing[0].Code == "B"); }
public void When_excel_product_matches_eip_product_there_are_no_mismatches() { //arrange var logService = new Mock <ILogService>(); var eipProduct = new List <I07> { EipProductCodeAMakerA() }; var excelProduct = new List <ExcelProductData> { ExcelProductCodeAMakerA() }; var excelBlockData = new List <ExcelBlockData> { new ExcelBlockData { Date = new DateTime(2019, 7, 7), ProductData = excelProduct, SheetName = "A" } }; var generator = new DiffGenerator(logService.Object); var onlyMonthCheckSheets = new List <SheetCheckBoxItem>(); //assess var result = generator.GenerateDiffReport(eipProduct, excelBlockData, onlyMonthCheckSheets); Assert.IsTrue(!result.Mismatches.Any()); }
public void When_special_sheets_are_not_selected_day_mismatch_is_counted() { //arrange var logService = new Mock <ILogService>(); var eipProduct = new List <I07> { EipProductCodeAMakerA() }; var product = ExcelProductCodeAMakerA(); product.Date = product.Date.AddDays(5); var excelProduct = new List <ExcelProductData> { product }; var excelBlockData = new List <ExcelBlockData> { new ExcelBlockData { Date = new DateTime(2019, 7, 7), ProductData = excelProduct, SheetName = "sheet" } }; var generator = new DiffGenerator(logService.Object); var onlyMonthCheckSheets = new List <SheetCheckBoxItem>(); //assess var result = generator.GenerateDiffReport(eipProduct, excelBlockData, onlyMonthCheckSheets); var mismatches = result.Mismatches.ToList(); Assert.IsTrue(mismatches.Count == 1); }
/// <summary> /// Mains the specified args. /// </summary> /// <param name="args">The arguments.</param> public static void Main(string[] args) { var options = new Options(); if (CommandLine.Parser.Default.ParseArguments(args, options)) { Console.WriteLine("Source: {0}", options.Source); Console.WriteLine("Target: {0}", options.Target); Console.WriteLine("Output: {0}", options.Output); Console.WriteLine("Collision behavior: {0}", options.CollisionBehavior); Console.WriteLine("Configuration: {0}", options.Configuration); Console.WriteLine("Path to project file: {0}", options.ScProjFilePath); if (ExclusionHandler.HasValidExclusions(options.Configuration, options.ScProjFilePath)) { var exclusions = ExclusionHandler.GetExcludedItems(options.ScProjFilePath, options.Configuration); ExclusionHandler.RemoveExcludedItems(options.Source, exclusions); ExclusionHandler.RemoveExcludedItems(options.Target, exclusions); } var diff = new DiffInfo( DiffGenerator.GetDiffCommands(options.Source, options.Target, options.CollisionBehavior), "Sitecore Courier Package", string.Empty, string.Format("Diff between serialization folders '{0}' and '{1}'.", options.Source, options.Target)); PackageGenerator.GeneratePackage(diff, string.Empty, options.Output); } else { Console.WriteLine(options.GetUsage()); } }
protected override void BeginProcessing() { try { var currentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", Path.Combine(currentDirectory, "Sitecore.Courier.dll.config")); ResetConfigMechanism(); string version = Guid.NewGuid().ToString(); Console.WriteLine("Source: {0}", Source); Console.WriteLine("Target: {0}", Target); Console.WriteLine("Output: {0}", Output); Console.WriteLine("SerializationProvider: {0}", SerializationProvider); Console.WriteLine("CollisionBehavior: {0}", CollisionBehavior); Console.WriteLine("IncludeFiles: {0}", IncludeFiles); Console.WriteLine("DacPac: {0}", DacPac); RainbowSerializationProvider.Enabled = SerializationProvider == SerializationProvider.Rainbow; RainbowSerializationProvider.IncludeFiles = IncludeFiles; RainbowSerializationProvider.EnsureRevision = EnsureRevision; var diff = new DiffInfo( DiffGenerator.GetDiffCommands(Source, Target, IncludeSecurity, version, CollisionBehavior), "Sitecore Courier Package", string.Empty, string.Format("Diff between serialization folders '{0}' and '{1}'.", Source, Target)); if (IncludeSecurity) { diff.Commands.Add(new PostStepFileSystemDataItem(currentDirectory, string.Empty, PostDeployDll) .GenerateAddCommand().FirstOrDefault()); diff.PostStep = PostStep; diff.Version = version; } if (DacPac) { SqlConverter c = new SqlConverter(); c.ConvertPackage(diff, Output); var builder = new DacPacBuilder(); DirectoryInfo d = new DirectoryInfo(Output); foreach (var file in d.GetFiles("*.sql")) { builder.ConvertToDacPac(file.FullName, Path.Combine(file.DirectoryName, $"{Path.GetFileNameWithoutExtension(file.Name)}.dacpac")); } } else { PackageGenerator.GeneratePackage(diff, string.Empty, Output); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); throw ex; } }
DiffGenerator GetDiffGenerator() { DiffGenerator gen = new DiffGenerator(); gen.CurrentStatusAdaptor = new ActionDiffAdaptor(Project); gen.NewStatusAdaptor = new XmlDiffAdaptor(); return(gen); }
public void TestDiff01() { Dictionary <string, string> files = TestUtils.ExtractZippedFiles("Files01"); (int added, int deleted) = DiffGenerator.GetLinesChanged(files["JsonSerializerTest_4793c7b.cs"], files["JsonSerializerTest_2368a8e.cs"]); Assert.AreEqual(23, added); Assert.AreEqual(0, deleted); }
private void InitComponents(SimulationOptions options) { m_PrSimulator = new PrSimulator(options); m_StSimulator = new StSimulator(options); m_DiffGenerator = new DiffGenerator(m_PrSimulator, m_StSimulator); m_Visualizer = new Visualizer2D(); }
public void StringComparison() { var json1 = "['qwe', 'asd', 'zxc']"; var json2 = "['qwe', 'asd', 'zxc']"; var diffs = DiffGenerator.SubsetDiffs(json1, json2); Assert.Equal(0, (int)diffs.Count); }
public void ListOfDictionaryWithListComparison() { var json1 = "[{'qwe' : 'asd', 'zxc' : 123, 'tyu' : [123, 456, 789]}, {'qwe' : 'asd', 'zxc' : 456}]".Deserialize(); var json2 = "[{'qwe' : 'asd', 'tyu' : [456, 123, 789], 'zxc' : 123}, {'qwe' : 'asd', 'zxc' : 456}]".Deserialize(); var diffs = DiffGenerator.SubsetDiffs(json1, json2); Assert.Equal(0, (int)diffs.Count); }
public void NullInListComparison() { var json1 = "[123, null, 789]".Deserialize(); var json2 = "[123, 789, null]".Deserialize(); var diffs = DiffGenerator.SubsetDiffs(json1, json2); Assert.Equal(0, (int)diffs.Count); }
public void ArrayComparison() { var json1 = new[] { 123, 456, 789 }; var json2 = new[] { 456, 123, 789 }; var diffs = DiffGenerator.SubsetDiffs(json1, json2); Assert.Equal(0, (int)diffs.Count); }
public void ListOfDictionaryComparison_DictionaryMissing() { var json1 = "[{'qwe' : 'asd', 'zxc' : 123}, {'qwe' : 'asd', 'zxc' : 456}]".Deserialize(); var json2 = "[{'qwe' : 'asd', 'zxc' : 456}]".Deserialize(); var diffs = DiffGenerator.SubsetDiffs(json1, json2); Assert.Equal(1, (int)diffs.Count); }
public void ListComparison() { var json1 = "['asd', 'qwe', 'zxc']".Deserialize(); var json2 = "['qwe', 'asd', 'zxc']".Deserialize(); var diffs = DiffGenerator.SubsetDiffs(json1, json2); Assert.Equal(0, (int)diffs.Count); }
public void DictionaryComparison() { var json1 = "{'qwe' : 'asd', 'zxc' : 123}".Deserialize(); var json2 = "{'zxc' : 123, 'qwe' : 'asd'}".Deserialize(); var diffs = DiffGenerator.SubsetDiffs(json1, json2); Assert.Equal(0, (int)diffs.Count); }
public void diff_should_return_empty_for_same_list() { var installerClient = new WindowsInstallerClient(); var diffGenerator = new DiffGenerator <WindowsInstallerRecord>(installerClient.GetRecords(), installerClient.GetRecords(), c => $"{c.Is64}_{c.Id}"); diffGenerator.Added().Should().BeEmpty(); diffGenerator.Removed().Should().BeEmpty(); diffGenerator.Updated().Should().BeEmpty(); }
DiffGenerator GetDiffGenerator() { DiffGenerator gen = new DiffGenerator(); gen.CurrentStatusAdaptor = new ActionDiffAdaptor(Project); XmlDiffAdaptor xad = new XmlDiffAdaptor(); xad.ChildElementName = "action"; gen.NewStatusAdaptor = xad; return(gen); }
DiffGenerator GetDiffGenerator(IProject prj) { DiffGenerator gen = new DiffGenerator(); gen.CurrentStatusAdaptor = new ActionDiffAdaptor(prj); XmlDiffAdaptor xad = new XmlDiffAdaptor(); xad.ChildElementName = "action-group"; xad.ProcessProperties = false; xad.ChildAdaptor = new XmlDiffAdaptor(); xad.ChildAdaptor.ChildElementName = "action"; gen.NewStatusAdaptor = xad; return(gen); }
public void diff_should_show_updated() { var installerClient = new WindowsInstallerClient(); var before = installerClient.GetRecords(); var after = installerClient.GetRecords(); after[20].Values["foo"] = "bar"; var diffGenerator = new DiffGenerator <WindowsInstallerRecord>(before, after, c => $"{c.Is64}_{c.Id}"); diffGenerator.Added().Should().BeEmpty(); diffGenerator.Removed().Should().BeEmpty(); diffGenerator.Updated().Should().OnlyContain(c => c.Values["foo"].ToString() == "bar"); }
public void TestOverlap() { string text1 = @" az az ab ac"; string text2 = @" az ab ac"; (int added, int deleted) = DiffGenerator.GetLinesChanged(text1, text2); Assert.AreEqual(0, added); Assert.AreEqual(1, deleted); }
public void diff_should_show_removed() { var installerClient = new WindowsInstallerClient(); var before = installerClient.GetRecords(); var after = installerClient.GetRecords(); after.RemoveAt(20); var diffGenerator = new DiffGenerator <WindowsInstallerRecord>(before, after, c => $"{c.Is64}_{c.Id}"); diffGenerator.Added().Should().BeEmpty(); diffGenerator.Removed().Should().HaveCount(1); diffGenerator.Updated().Should().BeEmpty(); }
public void DetectChangedNestedMappingNodeScalarNode() { var originalDocument = @" lorem: ipsum: dolor "; var changedDocument = @" lorem: ipsum: sit "; var result = new DiffGenerator(new NodeTraverser(), new NodeFinder(), new NodeComparer(new MappingNodeComparer(), new SequenceNodeComparer())).Generate(Parser.Parse(originalDocument), Parser.Parse(changedDocument)); Assert.Single(result); Assert.Equal(new object[] { "lorem", "ipsum" }, result.Single().Path.Segments); }
public ActionResult Revision(int id, int fileId, int revisionId) { return ExecApiMethod(() => { var userNameInfo = UserName; var settings = UserSettings; var changeList = GetChangeList(id); var changeFile = GetChangeFile(changeList, fileId); var gen = new DiffGenerator(db); var baseReviewId = gen.GetBaseReviewId(userNameInfo.userName, changeList.Id); var fileVersions = changeFile.FileVersions.ToArray(); var prev = 0; if (revisionId == 0 && fileVersions.Length == 1) { var left = fileVersions.First(); var right = left; var diffFile = gen.GenerateDiffFile(left, right, changeList.CL, baseReviewId, settings, force: false); if (string.IsNullOrEmpty(diffFile) || !System.IO.File.Exists(diffFile)) throw new ApplicationException(string.Format("Failed to create a diff file for change list id: {0} file id: {1} revision id: {2}", id, fileId, revisionId)); return StreamFile(diffFile); } for (var idx = prev + 1; idx < fileVersions.Length; prev = idx++) { if (revisionId != idx - 1) continue; var vid1 = fileVersions[prev].Id; var vid2 = fileVersions[idx].Id; var left = fileVersions[prev]; var right = fileVersions[idx]; var diffFile = gen.GenerateDiffFile(left, right, changeList.CL, baseReviewId, settings, force: false); if (string.IsNullOrEmpty(diffFile) || !System.IO.File.Exists(diffFile)) throw new ApplicationException(string.Format("Failed to create a diff file for change list id: {0} file id: {1} revision id: {2}", id, fileId, revisionId)); return StreamFile(diffFile); } throw new ApplicationException(string.Format("Did not find revision for change list id: {0} file id: {1} revision id: {2}", id, fileId, revisionId)); }); }
public override object ApplyUndoRedoDiff(object diff) { ObjectDiff actionsDiff = (ObjectDiff)diff; XmlElement status = UndoManager.GetObjectStatus(this); DiffGenerator differ = GetDiffGenerator(); differ.ApplyDiff(this, actionsDiff); actionsDiff = differ.GetDiff(this, status); UndoWriter writer = new UndoWriter(status.OwnerDocument, UndoManager); XmlElement newElem = Write(writer); UndoManager.UpdateObjectStatus(this, newElem); return(actionsDiff); }
/// <summary> /// Handles the Generate_ click event. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void Generate_Click(object sender, EventArgs e) { var sourcePath = this.SourcePath.Text; var targetPath = this.TargetPath.Text; var result = DiffGenerator.GetDiffCommands(sourcePath, targetPath); var fileName = "SitecoreCourier_{0}.update".FormatWith(Guid.NewGuid()); var filePath = string.Format("{0}/{1}", this.Server.MapPath("/temp"), fileName); result = FilterCommands(result); var diff = new DiffInfo(result, "Sitecore Courier Package", string.Empty, string.Format("Diff has been generated between '{0}' and '{1}'", this.SourcePath.Text, this.TargetPath.Text)); PackageGenerator.GeneratePackage(diff, string.Empty, filePath); this.DownloadLink.NavigateUrl = string.Format("/temp/{0}", fileName); this.DownloadLink.Visible = true; this.AnalyzeResults.Visible = false; }
/// <summary> /// Handles the Analyze_ click event. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void Analyze_Click(object sender, EventArgs e) { var sourcePath = this.SourcePath.Text; var targetPath = this.TargetPath.Text; var result = DiffGenerator.GetDiffCommands(sourcePath, targetPath); this.Added.Items.Clear(); this.Changed.Items.Clear(); this.Deleted.Items.Clear(); foreach (var command in result) { if (command.CommandPrefix == "addeditems") { var item = new ListItem(command.EntityPath.Substring(0, command.EntityPath.IndexOf("{", System.StringComparison.Ordinal) - 1), command.EntityID); item.Selected = true; this.Added.Items.Add(item); } if (command.CommandPrefix == "changeditems") { var item = new ListItem(command.EntityPath.Substring(0, command.EntityPath.IndexOf("{", System.StringComparison.Ordinal) - 1), command.EntityID); item.Selected = true; this.Changed.Items.Add(item); } if (command.CommandPrefix == "deleteditems") { var item = new ListItem(command.EntityPath.Substring(0, command.EntityPath.IndexOf("{", System.StringComparison.Ordinal) - 1), command.EntityID); item.Selected = true; this.Deleted.Items.Add(item); } } AddedCount.Text = Added.Items.Count.ToString(CultureInfo.InvariantCulture); DeletedCount.Text = Deleted.Items.Count.ToString(CultureInfo.InvariantCulture); ChangedCount.Text = Changed.Items.Count.ToString(CultureInfo.InvariantCulture); this.DownloadLink.Visible = false; this.AnalyzeResults.Visible = true; }
public void When_there_are_all_kinds_of_mismatches_diff_report_is_set_fully() { //arrange var logService = new Mock <ILogService>(); var eipProduct = new List <I07> { EipProductCodeAMakerA(), EipProductCodeCMakerA() }; var excelProduct = new List <ExcelProductData> { ExcelProductCodeAMakerB(), ExcelProductCodeBMakerB() }; var excelBlockData = new List <ExcelBlockData> { new ExcelBlockData { Date = new DateTime(2019, 7, 7), ProductData = excelProduct, SheetName = "A" } }; var generator = new DiffGenerator(logService.Object); var onlyMonthCheckSheets = new List <SheetCheckBoxItem>(); //assess var result = generator.GenerateDiffReport(eipProduct, excelBlockData, onlyMonthCheckSheets); var eipMissing = result.ProductsMissingFromEip.ToList(); var excelMissing = result.ProductsMissingFromExcel.ToList(); var mismatches = result.Mismatches.ToList(); Assert.IsTrue(eipMissing.Count == 1 && eipMissing[0].Code == "B" && mismatches.Count == 1 && excelMissing.Count == 1 && excelMissing[0].Code.First() == "C" && mismatches[0].ExcelData.Maker != mismatches[0].EipData.Maker); }
public void diff_should_show_added() { var installerClient = new WindowsInstallerClient(); var before = installerClient.GetRecords(); var after = installerClient.GetRecords(); var newRecord = new WindowsInstallerRecord { Id = "new" }; after.Add(newRecord); var diffGenerator = new DiffGenerator <WindowsInstallerRecord>(before, after, c => $"{c.Is64}_{c.Id}"); diffGenerator.Added().Should().OnlyContain(c => c == newRecord); diffGenerator.Removed().Should().BeEmpty(); diffGenerator.Updated().Should().BeEmpty(); }
public void DeleteItemsTest() { // Arrange var sourceItems = new List <IDataItem>(); var sourceItem = new QuickContentDataItem(string.Empty, string.Empty, string.Empty, new SyncItem()); sourceItems.Add(sourceItem); var targetItems = new List <IDataItem>(); var sourceDataIterator = new TestDataIterator(sourceItems); var targetDataIterator = new TestDataIterator(targetItems); var engineMock = new Mock <DataEngine>(null, null, new List <ICommandFilter>()); // Act var commands = DiffGenerator.GetCommands(sourceDataIterator, targetDataIterator); //Assert Assert.AreEqual(1, commands.Count); Assert.AreEqual(1, commands.Count(x => x is DeleteItemCommand)); }