Skip to content

Markus codechefs feature/generatefileifactualchangewasmade - #133

Merged
rappen merged 6 commits into
masterfrom
markus-codechefs-feature/generatefileifactualchangewasmade
Jul 25, 2026
Merged

Markus codechefs feature/generatefileifactualchangewasmade#133
rappen merged 6 commits into
masterfrom
markus-codechefs-feature/generatefileifactualchangewasmade

Conversation

@rappen

@rappen rappen commented Jul 25, 2026

Copy link
Copy Markdown
Owner

The idea and mainly the logic were from @markus-codechefs - thanks a LOT for that!
To know more: read his request #129 and his original PR #130

Copilot AI review requested due to automatic review settings July 25, 2026 16:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the generation pipeline to avoid rewriting output files when the actual generated content hasn’t changed (ignoring header fields like “Created” timestamp and “Filename”), and surfaces a “no changes” outcome to both the UI and command-line flows. It also adds unit tests and testdata to validate date/filename preservation behavior.

Changes:

  • Update Extensions.WriteFile to compare generated vs existing content (ignoring Created/Filename) and return false when no write is needed.
  • Move exception handling up to LCG.cs (UI) and LCGCmd/LCGHelper.cs (CLI) and add explicit “no changes” messaging when generation doesn’t save.
  • Add new test helper + template testdata and introduce DatePreservationTests to validate preservation/update behavior.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
LCGTests/testdata/ExpectedTestContent.cs Adds a template used to generate expected file content with parameterized filename/date.
LCGTests/TestContentHelper.cs Adds helper methods to produce test input content and formatted expected output.
LCGTests/LCGTests.csproj Includes new test files and ensures template testdata is copied to output.
LCGTests/DatePreservationTests.cs Adds tests intended to validate timestamp/filename preservation and update behavior.
LCGCmd/LCGHelper.cs Handles “no changes” and adds exception handling around generation in CLI flow.
LCG-UDG/LCG.cs Handles “no changes” and adds exception handling around generation in UI flow.
LCG-UDG/LCG-UDG-Common.csproj Adds new constants file to the build.
LCG-UDG/Generation/GenerationUtils.cs Removes internal try/catch so errors propagate to the caller; preserves generation flow.
LCG-UDG/Generation/Extensions.cs Implements “skip write if unchanged” behavior and refactors placeholder replacements via constants.
LCG-UDG/Constants/FileHeaderConstants.cs Introduces constants for placeholders and header labels used during header/data generation.
Comments suppressed due to low confidence (2)

LCGTests/DatePreservationTests.cs:45

  • WriteFile now returns false when it detects the generated content is unchanged (it skips writing). This test currently expects true, so it will fail even though the behavior is correct.
            Assert.IsTrue(result);

LCGTests/DatePreservationTests.cs:93

  • WriteFile returns false when only header fields like filename differ and the file is not rewritten; this assertion should expect false to match the new contract ("saved" vs "no changes").
            Assert.IsTrue(result);

Comment on lines +13 to +17
[TestInitialize]
public void Setup()
{
_testFilePath = Path.GetTempFileName();
}
Comment on lines +63 to +72
// Act - Write different content
var dataContent = TestContentHelper.GetModifiedTestDataContent();
var result = dataContent.WriteFile(_testFilePath, "https://test.crm.dynamics.com", settings);

// Assert
Assert.IsTrue(result);
var finalContent = File.ReadAllText(_testFilePath);
Assert.IsFalse(finalContent.Contains(originalDate), "Original date should not be preserved when content changes");
Assert.IsTrue(finalContent.Contains(DateTime.Now.ToString("yyyy-MM-dd")), "Current date should be used when content changes");
Assert.IsTrue(finalContent.Contains("modified_entity"), "Modified content should be present");
Comment thread LCGCmd/LCGHelper.cs
Comment on lines +61 to 64
catch (Exception ex)
{
Console.WriteLine("Error");
MessageBox.Show($"Error:\n{ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Comment on lines 8 to 10
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
Comment on lines +80 to +85
// Skip configuration section
if (line.Contains("LCG-configuration-BEGIN"))
{
skipConfiguration = true;
continue;
}
@rappen
rappen merged commit 3f68090 into master Jul 25, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants