Skip to content

Commit a250de9

Browse files
authored
Merge pull request #190 from mspnp/dev
Configuration Fix
2 parents d799dac + 9b31437 commit a250de9

23 files changed

Lines changed: 359 additions & 71 deletions

src/Components/Modals/AddModal.razor

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,11 @@
272272
</div>
273273
</div>
274274
</div>
275-
</div>
276275

277-
<div class="modern-modal-footer">
278-
<button title="Add" @onclick="Save" class="modern-btn-success">Add</button>
279-
<button title="Cancel" @onclick="Cancel" class="modern-btn-secondary">Cancel</button>
276+
<div class="modern-modal-footer">
277+
<button title="Add" @onclick="Save" class="modern-btn-success">Add</button>
278+
<button title="Cancel" @onclick="Cancel" class="modern-btn-secondary">Cancel</button>
279+
</div>
280280
</div>
281281

282282
@code {

src/Services/CustomComponentService.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,16 @@ public async Task<ServiceResponse> PostItemAsync(CustomComponent item)
193193
// Set the new id
194194
if (item.Id == 0)
195195
{
196-
item.Id = items.Count + 1;
196+
// Use max ID + 1 instead of count + 1 to avoid ID collisions after deletions
197+
item.Id = items.Count > 0 ? items.Max(x => x.Id) + 1 : 1;
197198
}
198199

199200
int position = 1;
200201
items = [.. items.OrderBy(x => x.SortOrder)];
201202

202203
if (item.SortOrder == 0)
203204
{
204-
if (items.Count > 0)
205-
{
206-
item.Id = items.Max(t => t.Id) + 1;
207-
}
205+
item.SortOrder = items.Count + 1;
208206
}
209207

210208
// Determine new item id

src/Services/ResourceComponentService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ public async Task<ServiceResponse> PostItemAsync(ResourceComponent item)
124124
// Set the new id
125125
if (item.Id == 0)
126126
{
127-
item.Id = items.Count + 1;
127+
// Use max ID + 1 instead of count + 1 to avoid ID collisions after deletions
128+
item.Id = items.Count > 0 ? items.Max(x => x.Id) + 1 : 1;
128129
}
129130

130131
int position = 1;

src/Services/ResourceDelimiterService.cs

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,20 @@ public async Task<ServiceResponse> PostItemAsync(ResourceDelimiter item)
144144
try
145145
{
146146
// Get list of items
147-
var items = (await _repository.GetAllAsync()).ToList();
147+
var itemsEnumerable = await _repository.GetAllAsync();
148+
if (itemsEnumerable == null)
149+
{
150+
serviceResponse.ResponseObject = "Resource Delimiters not found!";
151+
return serviceResponse;
152+
}
153+
var items = itemsEnumerable.ToList();
148154
if (GeneralHelper.IsNotNull(items))
149155
{
150156
// Set the new id
151157
if (item.Id == 0)
152158
{
153-
item.Id = items.Count + 1;
159+
// Use max ID + 1 instead of count + 1 to avoid ID collisions after deletions
160+
item.Id = items.Count > 0 ? items.Max(x => x.Id) + 1 : 1;
154161
}
155162
item.Enabled = true;
156163
int position = 1;
@@ -199,23 +206,40 @@ public async Task<ServiceResponse> PostItemAsync(ResourceDelimiter item)
199206
}
200207
else
201208
{
202-
item.Id = 1;
203-
item.SortOrder = 1;
209+
// Add new item - ID was already set above
210+
item.SortOrder = items.Count + 1;
211+
212+
// Disable other items if this new item is enabled
213+
if (item.Enabled)
214+
{
215+
foreach (var existingItem in items)
216+
{
217+
existingItem.Enabled = false;
218+
}
219+
}
220+
204221
items.Add(item);
205222
}
223+
}
224+
else
225+
{
226+
// Add first item to empty list
227+
item.SortOrder = 1;
228+
items.Add(item);
229+
}
206230

207-
position = 1;
208-
foreach (ResourceDelimiter thisitem in items.OrderBy(x => x.SortOrder).ToList())
209-
{
210-
thisitem.SortOrder = position;
211-
position += 1;
212-
}
213-
214-
// Write items to file
215-
await _repository.SaveAllAsync(items);
216-
serviceResponse.ResponseObject = "Resource Delimiter added/updated!";
217-
serviceResponse.Success = true;
231+
// Normalize sort order
232+
position = 1;
233+
foreach (ResourceDelimiter thisitem in items.OrderBy(x => x.SortOrder).ToList())
234+
{
235+
thisitem.SortOrder = position;
236+
position += 1;
218237
}
238+
239+
// Write items to file
240+
await _repository.SaveAllAsync(items);
241+
serviceResponse.ResponseObject = "Resource Delimiter added/updated!";
242+
serviceResponse.Success = true;
219243
}
220244
else
221245
{

src/Services/ResourceTypeService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ public async Task<ServiceResponse> PostItemAsync(ResourceType item)
139139
// Set the new id
140140
if (item.Id == 0)
141141
{
142-
item.Id = items.Count + 1;
142+
// Use max ID + 1 instead of count + 1 to avoid ID collisions after deletions
143+
item.Id = items.Count > 0 ? items.Max(x => x.Id) + 1 : 1;
143144
}
144145

145146
// Determine new item id

src/wwwroot/css/modern-components.css

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2966,7 +2966,7 @@ h3.blazored-modal-title,
29662966
padding: 16px 24px;
29672967
border-top: 1px solid var(--color-border);
29682968
background-color: var(--color-bg-secondary);
2969-
margin-top: auto; /* Push footer to bottom when content is short */
2969+
flex-shrink: 0; /* Prevent footer from shrinking */
29702970
}
29712971

29722972
/* Modal Animations */
@@ -2996,7 +2996,6 @@ h3.blazored-modal-title,
29962996
display: flex;
29972997
flex-direction: column;
29982998
max-height: 85vh;
2999-
overflow-y: auto; /* Enable scrolling on the modal content */
30002999
line-height: 1.6; /* Consistent line height for readability */
30013000
font-size: 14px; /* Consistent font size */
30023001
}
@@ -3015,7 +3014,6 @@ h3.blazored-modal-title,
30153014
flex: 1;
30163015
overflow-y: auto;
30173016
padding: 1.5rem;
3018-
max-height: calc(85vh - 120px); /* Account for header and footer */
30193017
line-height: 1.6; /* Consistent line height for readability */
30203018
font-size: 14px; /* Consistent font size */
30213019
}

tests/AzureNamingTool.UnitTests/AzureNamingTool.UnitTests.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
<Nullable>enable</Nullable>
66

77
<IsPackable>false</IsPackable>
88
</PropertyGroup>
99

1010
<ItemGroup>
1111
<PackageReference Include="FluentAssertions" Version="6.12.0" />
12-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0"/>
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0"/>
1313
<PackageReference Include="Moq" Version="4.20.70" />
14+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
1415
<PackageReference Include="xunit" Version="2.4.1"/>
1516
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
1617
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

tests/AzureNamingTool.UnitTests/Helpers/ValidationHelperTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -532,10 +532,10 @@ public void ValidateGeneratedName_ShouldHandleNullInvalidCharacterFields()
532532
Regx = "^[a-z0-9-]+$",
533533
LengthMin = "3",
534534
LengthMax = "20",
535-
InvalidCharacters = null,
536-
InvalidCharactersStart = null,
537-
InvalidCharactersEnd = null,
538-
InvalidCharactersConsecutive = null
535+
InvalidCharacters = string.Empty,
536+
InvalidCharactersStart = string.Empty,
537+
InvalidCharactersEnd = string.Empty,
538+
InvalidCharactersConsecutive = string.Empty
539539
};
540540
var name = "test-resource";
541541
var delimiter = "-";

tests/AzureNamingTool.UnitTests/Repositories/FileSystemStorageProviderTests.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ public async Task GetHealthAsync_ShouldIncludeMetadata_WhenFileSystemIsAccessibl
6363

6464
// Assert
6565
health.Metadata.Should().NotBeNull("metadata should be provided");
66+
health.Metadata!.Should().NotBeNull("metadata should be provided");
6667

6768
// If there was a file locking error (e.g., from concurrent test runs), skip the rest
68-
if (health.Metadata.ContainsKey("Error"))
69+
if (health.Metadata!.ContainsKey("Error"))
6970
{
7071
// File locking can occur in test scenarios - this is acceptable
7172
health.Metadata.Should().ContainKey("SettingsPath", "error metadata should include settings path");
@@ -127,9 +128,9 @@ public async Task GetHealthAsync_ShouldReportFileCount_WhenSettingsDirectoryHasF
127128

128129
// Assert
129130
health.Metadata.Should().ContainKey("FileCount");
130-
var fileCount = health.Metadata["FileCount"];
131+
var fileCount = health.Metadata!["FileCount"];
131132
fileCount.Should().BeOfType<int>("file count should be an integer");
132-
((int)fileCount).Should().BeGreaterThanOrEqualTo(0, "file count should not be negative");
133+
((int)fileCount!).Should().BeGreaterThanOrEqualTo(0, "file count should not be negative");
133134
}
134135

135136
/// <summary>
@@ -149,12 +150,12 @@ public async Task GetHealthAsync_ShouldReportMultipleFiles_InProductionEnvironme
149150

150151
// Assert
151152
health.IsHealthy.Should().BeTrue("production environment should be healthy");
152-
var fileCount = (int)health.Metadata["FileCount"];
153+
var fileCount = (int)health.Metadata!["FileCount"]!;
153154
fileCount.Should().BeGreaterThan(0, "settings directory should contain configuration files");
154155

155156
// Validate typical configuration files exist
156157
health.Metadata.Should().ContainKey("LastModified");
157-
health.Metadata["LastModified"].Should().NotBeNull("should report last modification time");
158+
health.Metadata!["LastModified"].Should().NotBeNull("should report last modification time");
158159
}
159160

160161
[Fact]

tests/AzureNamingTool.UnitTests/Services/AdminLogServiceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public async Task GetItemsAsync_ShouldReturnOrderedItems_WhenItemsExist()
3838
var returnedItems = result.ResponseObject as List<AdminLogMessage>;
3939
returnedItems.Should().NotBeNull();
4040
returnedItems!.Should().HaveCount(3);
41-
returnedItems[0].Id.Should().Be(2); // Most recent first
41+
returnedItems![0].Id.Should().Be(2); // Most recent first
4242
}
4343

4444
[Fact]

0 commit comments

Comments
 (0)