@@ -72,14 +72,28 @@ public string Execute(params string[] args)
7272 var kernel = _intentSemanticKernelFactory . BuildSemanticKernel ( modelId , provider , null ) ;
7373
7474 var servicesDesigner = _metadataManager . GetDesigner ( applicationId , "Services" ) ;
75- var queryModel = servicesDesigner . GetElementsOfType ( SpecializationTypeIds . Service )
76- . SelectMany ( s => s . ChildElements . Where ( o => o . SpecializationTypeId == SpecializationTypeIds . Operation ) )
77- . FirstOrDefault ( x => x . Id == elementId ) ;
78- if ( queryModel == null )
75+ // Attempt to resolve the element ID as a Service first.
76+ var serviceModel = servicesDesigner . GetElementsOfType ( SpecializationTypeIds . Service )
77+ . FirstOrDefault ( s => s . Id == elementId ) ;
78+ IElement ? selectedOperation = null ;
79+ if ( serviceModel == null )
7980 {
80- throw new Exception ( $ "An element was selected to be executed upon but could not be found. Please ensure you have saved your designer and try again.") ;
81+ // If not a Service, attempt to resolve as an Operation belonging to any Service.
82+ selectedOperation = servicesDesigner . GetElementsOfType ( SpecializationTypeIds . Service )
83+ . SelectMany ( s => s . ChildElements . Where ( o => o . SpecializationTypeId == SpecializationTypeIds . Operation ) )
84+ . FirstOrDefault ( o => o . Id == elementId ) ;
85+ if ( selectedOperation != null )
86+ {
87+ serviceModel = selectedOperation . ParentElement ;
88+ }
89+ }
90+ if ( serviceModel == null )
91+ {
92+ throw new Exception ( "An element was selected to be executed upon but could not be found. Please ensure you have saved your designer and try again." ) ;
8193 }
82- var inputFiles = GetInputFiles ( queryModel ) ;
94+
95+ var inputFiles = GetInputFiles ( serviceModel ) ;
96+ Logging . Log . Info ( $ "Resolved service: { serviceModel . Name } (Selected operation: { selectedOperation ? . Name ?? "All" } )") ;
8397 Logging . Log . Info ( $ "Context files included: { inputFiles . Count } files") ;
8498 Logging . Log . Debug ( $ "Files: { string . Join ( ", " , inputFiles . Select ( f => Path . GetFileName ( f . FilePath ) ) ) } ") ;
8599
@@ -90,9 +104,9 @@ public string Execute(params string[] args)
90104 {
91105 [ "inputFilesJson" ] = jsonInput ,
92106 [ "userProvidedContext" ] = userProvidedContext ,
93- [ "targetFileName" ] = queryModel . Name ,
107+ [ "targetFileName" ] = serviceModel . Name + "Tests" ,
94108 [ "mockFramework" ] = UnitTestHelpers . GetMockFramework ( _applicationConfigurationProvider ) ,
95- [ "slnRelativePath" ] = "/" + string . Join ( '/' , queryModel . GetParentPath ( ) . Select ( x => x . Name ) ) ,
109+ [ "slnRelativePath" ] = "/" + string . Join ( '/' , serviceModel . GetParentPath ( ) . Select ( x => x . Name ) ) ,
96110 [ "fileChangesSchema" ] = FileChangesSchema . GetPromptInstructions ( )
97111 } ) ;
98112
@@ -258,13 +272,13 @@ public class {ServiceName}Tests
258272 {
259273 private readonly Mock<IRepository> _repositoryMock;
260274 private readonly Mock<IMapper> _mapperMock; // Only if service uses IMapper
261- private readonly {ServiceName} _sut ;
275+ private readonly {ServiceName} _service ;
262276
263277 public {ServiceName}Tests()
264278 {
265279 _repositoryMock = new Mock<IRepository>();
266280 _mapperMock = new Mock<IMapper>(); // Only if needed
267- _sut = new {ServiceName}(_repositoryMock.Object, _mapperMock.Object);
281+ _service = new {ServiceName}(_repositoryMock.Object, _mapperMock.Object);
268282 }
269283
270284 // Test methods follow...
@@ -296,7 +310,7 @@ public async Task CreateProduct_AddsProductAndReturnsId()
296310 .ReturnsAsync(1);
297311
298312 // Act
299- var result = await _sut .CreateProduct(dto);
313+ var result = await _service .CreateProduct(dto);
300314
301315 // Assert
302316 Assert.Equal(expectedId, result);
@@ -324,7 +338,7 @@ public async Task UpdateProduct_UpdatesProduct_WhenFound()
324338 .ReturnsAsync(existingProduct);
325339
326340 // Act
327- await _sut .UpdateProduct(productId, dto);
341+ await _service .UpdateProduct(productId, dto);
328342
329343 // Assert
330344 Assert.Equal("NewName", existingProduct.Name);
@@ -342,7 +356,7 @@ public async Task UpdateProduct_ThrowsNotFoundException_WhenProductNotFound()
342356 .ReturnsAsync((Product)null);
343357
344358 // Act & Assert
345- await Assert.ThrowsAsync<NotFoundException>(() => _sut .UpdateProduct(dto.Id, dto));
359+ await Assert.ThrowsAsync<NotFoundException>(() => _service .UpdateProduct(dto.Id, dto));
346360 }
347361 ```
348362
@@ -360,7 +374,7 @@ public async Task DeleteProduct_RemovesProduct_WhenFound()
360374 .ReturnsAsync(product);
361375
362376 // Act
363- await _sut .DeleteProduct(productId);
377+ await _service .DeleteProduct(productId);
364378
365379 // Assert
366380 _productRepositoryMock.Verify(x => x.FindByIdAsync(productId, It.IsAny<CancellationToken>()), Times.Once);
@@ -377,7 +391,7 @@ public async Task DeleteProduct_ThrowsNotFoundException_WhenNotFound()
377391 .ReturnsAsync((Product)null);
378392
379393 // Act & Assert
380- await Assert.ThrowsAsync<NotFoundException>(() => _sut .DeleteProduct(productId));
394+ await Assert.ThrowsAsync<NotFoundException>(() => _service .DeleteProduct(productId));
381395 }
382396 ```
383397
@@ -402,7 +416,7 @@ public async Task FindProductById_ReturnsDto_WhenFound()
402416 .Returns(expectedDto);
403417
404418 // Act
405- var result = await _sut .FindProductById(productId);
419+ var result = await _service .FindProductById(productId);
406420
407421 // Assert
408422 Assert.NotNull(result);
@@ -423,7 +437,7 @@ public async Task FindProductById_ThrowsNotFoundException_WhenNotFound()
423437 .ReturnsAsync((Product)null);
424438
425439 // Act & Assert
426- await Assert.ThrowsAsync<NotFoundException>(() => _sut .FindProductById(productId));
440+ await Assert.ThrowsAsync<NotFoundException>(() => _service .FindProductById(productId));
427441 }
428442 ```
429443
@@ -451,7 +465,7 @@ public async Task FindProducts_ReturnsAllProducts()
451465 .Returns((Product p) => ProductDto.Create("", "", 0, "", p.Id));
452466
453467 // Act
454- var result = await _sut .FindProducts();
468+ var result = await _service .FindProducts();
455469
456470 // Assert
457471 Assert.NotNull(result);
@@ -497,7 +511,7 @@ public async Task FindProductsByCategory_ReturnsOnlyMatchingProducts()
497511 .Returns((Product p) => ProductDto.Create("", "", 0, "", Guid.NewGuid()));
498512
499513 // Act
500- var result = await _sut .FindProductsByCategory(categoryId);
514+ var result = await _service .FindProductsByCategory(categoryId);
501515
502516 // Assert - This single test verifies: predicate logic, repository call, mapper call, result correctness
503517 Assert.NotNull(result);
@@ -528,7 +542,7 @@ public async Task FindProductsByCategory_ReturnsEmpty_WhenNoProductsMatchFilter(
528542 });
529543
530544 // Act
531- var result = await _sut .FindProductsByCategory(categoryId);
545+ var result = await _service .FindProductsByCategory(categoryId);
532546
533547 // Assert
534548 Assert.Empty(result);
@@ -564,7 +578,7 @@ public async Task FindActiveProducts_ReturnsProducts_WhenProductsMatchCriteria()
564578 .Returns((Product p) => ProductDto.Create("", "", 0, "", p.Id));
565579
566580 // Act
567- var result = await _sut .FindActiveProducts(categoryId);
581+ var result = await _service .FindActiveProducts(categoryId);
568582
569583 // Assert
570584 Assert.NotNull(result);
@@ -588,7 +602,7 @@ public async Task FindActiveProducts_ReturnsEmpty_WhenNoProductsMatchCriteria()
588602 .ReturnsAsync(new List<Product>());
589603
590604 // Act
591- var result = await _sut .FindActiveProducts(categoryId);
605+ var result = await _service .FindActiveProducts(categoryId);
592606
593607 // Assert
594608 Assert.NotNull(result);
@@ -652,7 +666,7 @@ public async Task GetCompletedTransactions_ReturnsTransactions_WhenTransactionsM
652666 });
653667
654668 // Act
655- var result = await _sut .GetCompletedTransactions(fromDate, toDate);
669+ var result = await _service .GetCompletedTransactions(fromDate, toDate);
656670
657671 // Assert
658672 Assert.NotNull(result);
@@ -689,7 +703,7 @@ public async Task GetCompletedTransactions_ReturnsEmpty_WhenNoTransactionsMatchC
689703 });
690704
691705 // Act
692- var result = await _sut .GetCompletedTransactions(fromDate, toDate);
706+ var result = await _service .GetCompletedTransactions(fromDate, toDate);
693707
694708 // Assert
695709 Assert.NotNull(result);
@@ -716,10 +730,16 @@ private List<ICodebaseFile> GetInputFiles(IElement service)
716730 {
717731 inputFiles . AddRange ( filesProvider . GetFilesForMetadata ( operation . TypeReference . Element ) ) ;
718732 }
733+ // Include DTO parameter types
719734 foreach ( var paramType in operation . ChildElements . Where ( x => x . TypeReference ? . Element ? . SpecializationTypeId == SpecializationTypeIds . Dto ) . Select ( x => x . TypeReference . Element ) )
720735 {
721736 inputFiles . AddRange ( filesProvider . GetFilesForMetadata ( paramType ) ) ;
722737 }
738+ // Include Class (domain entity / value object) parameter types
739+ foreach ( var paramClass in operation . ChildElements . Where ( x => x . TypeReference ? . Element ? . SpecializationTypeId == SpecializationTypeIds . Class ) . Select ( x => x . TypeReference . Element ) )
740+ {
741+ inputFiles . AddRange ( filesProvider . GetFilesForMetadata ( paramClass ) ) ;
742+ }
723743
724744 inputFiles . AddRange ( UnitTestHelpers . GetRelatedElements ( operation ) . SelectMany ( x => filesProvider . GetFilesForMetadata ( x ) ) ) ;
725745 }
0 commit comments