Markus codechefs feature/generatefileifactualchangewasmade - #134
Merged
rappen merged 7 commits intoJul 29, 2026
Merged
Conversation
Add functionality to check if only the time changed
There was a problem hiding this comment.
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
WriteFileto 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
WriteFilereturnsfalsewhen only filename/date differ and the write is skipped. This test currently assertstrue, 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.Nowat assertion time rather than capturing the expected date before writing, which can be flaky around midnight. Capture the expected date string before callingWriteFileand 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 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"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added #131 as well in this branch, my mistake.