Skip to content

Markus codechefs feature/generatefileifactualchangewasmade - #134

Merged
rappen merged 7 commits into
masterfrom
markus-codechefs-feature/generatefileifactualchangewasmade
Jul 29, 2026
Merged

Markus codechefs feature/generatefileifactualchangewasmade#134
rappen merged 7 commits into
masterfrom
markus-codechefs-feature/generatefileifactualchangewasmade

Conversation

@rappen

@rappen rappen commented Jul 29, 2026

Copy link
Copy Markdown
Owner

Added #131 as well in this branch, my mistake.

Copilot AI review requested due to automatic review settings July 29, 2026 12:06
@rappen
rappen merged commit f3c5cce into master Jul 29, 2026
1 check passed

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 generator to avoid rewriting output files when the effective generated content hasn’t changed (preserving the original header “Created” date / filename), improves error handling around generation, and includes a serialization compatibility fix related to Issue #131 (“'false' is not a valid value for CheckState”) when loading filters from XML.

Changes:

  • Update WriteFile to compare generated output against the existing file while ignoring volatile header fields (date/filename) and skip writing when unchanged.
  • Add MSTest coverage for date/filename preservation behavior using a reusable test-data template helper.
  • Adjust settings XML serialization for CheckState-backed filter properties to be tolerant of legacy persisted values.

Reviewed changes

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

Show a summary per file
File Description
LCGTests/testdata/ExpectedTestContent.cs Adds a string-format template representing a generated file header/body used by tests.
LCGTests/TestContentHelper.cs Test helper to load/format the expected template and provide sample generated content.
LCGTests/LCGTests.csproj Includes new test/helper sources and ensures template file is copied to output.
LCGTests/DatePreservationTests.cs Adds tests validating when dates/filenames should be preserved vs updated.
LCGCmd/LCGHelper.cs Updates CLI generation flow to surface “no changes” and wraps generation in try/catch.
LCG-UDG/Settings/Settings.cs Adds XML serialization wrappers for CheckState filter properties to address legacy values (Issue #131).
LCG-UDG/LCG.cs Updates UI generation flow for “no changes” and wraps generation in try/catch.
LCG-UDG/LCG-UDG-Common.csproj Includes the new FileHeaderConstants source file.
LCG-UDG/Generation/GenerationUtils.cs Removes internal MessageBox error handling and relies on caller for exceptions; returns Finalize result.
LCG-UDG/Generation/Extensions.cs Implements “skip write if unchanged” logic and centralizes file-header placeholder tokens.
LCG-UDG/Constants/FileHeaderConstants.cs Introduces constants for template placeholders and header labels used by comparison logic.
Comments suppressed due to low confidence (2)

LCGTests/DatePreservationTests.cs:94

  • WriteFile returns false when only filename/date differ and the write is skipped. This test currently asserts true, so it won’t validate the “preserve original filename” scenario correctly.
            // Assert
            Assert.IsTrue(result);
            var finalContent = File.ReadAllText(_testFilePath);

LCGTests/DatePreservationTests.cs:107

  • Similar to the changed-content test, this uses DateTime.Now at assertion time rather than capturing the expected date before writing, which can be flaky around midnight. Capture the expected date string before calling WriteFile and assert against that.
            // Arrange
            var settings = new Settings();
            settings.NameSpace = "TestNamespace";
            var dataContent = TestContentHelper.GetNewTestDataContent();

Comment on lines +37 to +44
if (settings.TemplateSettings.Template.AddAllRelationshipsAfterEntities)
{
MessageBox.Show($"Error:\n{ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
var relationships = selectedentities.SelectMany(e => e.Relationships.Where(r => r.IsSelected));
relationships = relationships.GroupBy(r => r.LogicalName).Select(r => r.FirstOrDefault()); // This will make it distinct by LogicalName
var allrelationshipsstring = GetRelationships(relationships, settings, addedrelationships);
fileWriter.WriteBlock(settings, allrelationshipsstring, "Relationships" + suffix);
}
return fileWriter.Finalize(settings);
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 +13 to +17
[TestInitialize]
public void Setup()
{
_testFilePath = Path.GetTempFileName();
}
Comment on lines +44 to +46
// Assert
Assert.IsTrue(result);
var finalContent = File.ReadAllText(_testFilePath);
Comment on lines +63 to +73
// 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");
}
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