Skip to content

Commit 380aef5

Browse files
committed
feat: Add SpecializationTypeIds class with constants for various types
1 parent 501bbd8 commit 380aef5

10 files changed

+92
-81
lines changed

Modules/Intent.Modules.AI.UnitTests/Intent.AI.UnitTests.imodspec

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,6 @@
1717
<dependency id="Intent.Common" version="3.8.0" />
1818
<dependency id="Intent.Common.AI" version="1.0.0-beta.12" />
1919
<dependency id="Intent.Common.Types" version="3.4.0" />
20-
<dependency id="Intent.Modelers.Domain" version="3.12.9" includeAssets="designerMetadata" />
21-
<dependency id="Intent.Modelers.Domain.Events" version="4.4.5" />
22-
<dependency id="Intent.Modelers.Domain.Repositories" version="3.6.0" />
23-
<dependency id="Intent.Modelers.Eventing" version="6.0.2" includeAssets="designerMetadata" />
24-
<dependency id="Intent.Modelers.Services" version="4.0.5" includeAssets="designerMetadata" />
25-
<dependency id="Intent.Modelers.Services.CQRS" version="6.0.4" includeAssets="designerMetadata" />
26-
<dependency id="Intent.Modelers.Services.DomainInteractions" version="2.3.8" includeAssets="designerMetadata" />
27-
<dependency id="Intent.Modelers.Services.EventInteractions" version="2.0.4" includeAssets="designerMetadata" />
2820
<dependency id="Intent.UnitTesting" version="1.0.2-pre.1" />
2921
</dependencies>
3022
<files>
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<outputFiles>
3-
<files />
3+
<files>
4+
<file relativePath="Intent.Modules.AI.UnitTests/Intent.AI.UnitTests.imodspec" state="ignored">
5+
<isIgnoredNotes><![CDATA[Prevent these dependencies from being installed]]></isIgnoredNotes>
6+
</file>
7+
</files>
48
</outputFiles>

Modules/Intent.Modules.AI.UnitTests/Intent.Modules.AI.UnitTests.application.output.log

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
<OverwriteBehaviour>always</OverwriteBehaviour>
1515
<ApplicationRelativeFilePath>Intent.AI.UnitTests.imodspec</ApplicationRelativeFilePath>
1616
<ProjectRelativeFilePath>Intent.AI.UnitTests.imodspec</ProjectRelativeFilePath>
17-
<IsIgnored>false</IsIgnored>
17+
<IsIgnored>true</IsIgnored>
18+
<IsIgnoredNotes>Prevent these dependencies from being installed</IsIgnoredNotes>
1819
</FileLog>
1920
<FileLog>
2021
<ProjectId>73a5c654-4bd1-4a47-8fc2-bee212dd3a0a</ProjectId>

Modules/Intent.Modules.AI.UnitTests/Intent.Modules.AI.UnitTests.csproj

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@
77
<ItemGroup>
88
<PackageReference Include="Intent.Modules.Common" Version="3.8.0" />
99
<PackageReference Include="Intent.Modules.Common.AI" Version="1.0.0-beta.12" />
10-
<PackageReference Include="Intent.Modules.Modelers.Domain.Events" Version="4.4.5" />
11-
<PackageReference Include="Intent.Modules.Modelers.Services" Version="4.0.5" />
12-
<PackageReference Include="Intent.Modules.Modelers.Services.CQRS" Version="6.0.4" />
13-
<PackageReference Include="Intent.Modules.Modelers.Services.DomainInteractions" Version="2.3.8" />
14-
<PackageReference Include="Intent.Modules.Modelers.Services.EventInteractions" Version="2.0.4" />
1510
<PackageReference Include="Intent.Modules.VisualStudio.Projects" Version="3.8.11" />
1611
<PackageReference Include="Intent.Packager" Version="3.6.0">
1712
<PrivateAssets>all</PrivateAssets>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Intent.Modules.AI.UnitTests;
2+
3+
public static class SpecializationTypeIds
4+
{
5+
public const string Command = "ccf14eb6-3a55-4d81-b5b9-d27311c70cb9";
6+
public const string Query = "e71b0662-e29d-4db2-868b-8a12464b25d0";
7+
public const string Operation = "e030c97a-e066-40a7-8188-808c275df3cb";
8+
public const string Service = "b16578a5-27b1-4047-a8df-f0b783d706bd";
9+
public const string IntegrationEventHandler = "c0582230-22f5-4f74-8eb0-ec6fc9364900";
10+
public const string DomainEventHandler = "d80e61c5-7e4c-4175-9df1-0413f664824c";
11+
}

Modules/Intent.Modules.AI.UnitTests/Tasks/GenerateCqrsHandlerUnitTestsWithAITask.cs

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
using Intent.Configuration;
66
using Intent.Engine;
77
using Intent.Metadata.Models;
8-
using Intent.Modelers.Domain.Api;
9-
using Intent.Modelers.Services.Api;
8+
using Intent.Modules.AI.UnitTests;
109
using Intent.Modules.AI.UnitTests.Utilities;
1110
using Intent.Modules.Common.AI;
1211
using Intent.Modules.Common.AI.CodeGeneration;
@@ -18,6 +17,7 @@
1817
using Intent.Utils;
1918
using Microsoft.SemanticKernel;
2019
using Newtonsoft.Json;
20+
using static Intent.Modules.AI.UnitTests.Utilities.UnitTestHelpers;
2121

2222
[assembly: DefaultIntentManaged(Mode.Fully)]
2323
[assembly: IntentTemplate("Intent.ModuleBuilder.Templates.ModuleTask", Version = "1.0")]
@@ -71,7 +71,10 @@ public string Execute(params string[] args)
7171
Logging.Log.Info($"Args: {string.Join(",", args)}");
7272
var kernel = _intentSemanticKernelFactory.BuildSemanticKernel(modelId, provider, null);
7373

74-
var queryModel = _metadataManager.Services(applicationId).Elements.FirstOrDefault(x => x.Id == elementId);
74+
var servicesDesigner = _metadataManager.GetDesigner(applicationId, "Services");
75+
var queryModel = servicesDesigner.GetElementsOfType(SpecializationTypeIds.Command)
76+
.Concat(servicesDesigner.GetElementsOfType(SpecializationTypeIds.Query))
77+
.FirstOrDefault(x => x.Id == elementId);
7578
if (queryModel == null)
7679
{
7780
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.");
@@ -827,7 +830,7 @@ private List<ICodebaseFile> GetInputFiles(IElement element)
827830
{
828831
inputFiles.AddRange(filesProvider.GetFilesForMetadata(element.TypeReference.Element));
829832
}
830-
foreach (var dto in element.ChildElements.Where(x => x.TypeReference.Element.IsDTOModel()).Select(x => x.TypeReference.Element))
833+
foreach (var dto in element.ChildElements.Where(x => x.TypeReference?.Element?.SpecializationTypeId == "a5e74323-9b24-48c8-9802-f8684e0aaa70").Select(x => x.TypeReference.Element))
831834
{
832835
inputFiles.AddRange(filesProvider.GetFilesForMetadata(dto));
833836
}
@@ -870,25 +873,6 @@ private List<ICodebaseFile> GetInputFiles(IElement element)
870873
return inputFiles;
871874
}
872875

873-
/// <summary>
874-
/// Takes the Command/Query and enumerates related elements including associations to help Intent know which files to include as input.
875-
/// </summary>
876-
private static List<ICanBeReferencedType> GetRelatedElements(IElement element)
877-
{
878-
var relatedElements = element.AssociatedElements.Where(x => x.TypeReference.Element != null)
879-
.Select(x => x.TypeReference.Element)
880-
.ToList();
881-
if (relatedElements.Count == 0)
882-
{
883-
return [];
884-
}
885-
var relatedClasses = relatedElements
886-
.Concat(relatedElements.Where(x => x.TypeReference?.Element?.IsDTOModel() == true).Select(x => x.TypeReference.Element))
887-
.Concat(relatedElements.Where(Intent.Modelers.Services.Api.OperationModelExtensions.IsOperationModel).Select(x => Intent.Modelers.Services.Api.OperationModelExtensions.AsOperationModel(x).ParentService.InternalElement))
888-
.Concat(relatedElements.Where(Intent.Modules.Common.Types.Api.OperationModelExtensions.IsOperationModel).Select(x => Intent.Modules.Common.Types.Api.OperationModelExtensions.AsOperationModel(x).InternalElement.ParentElement))
889-
.Concat(relatedElements.Where(x => x.IsClassModel()).Select(x => x.AsClassModel()).SelectMany(x => x.AssociatedClasses.Select(y => y.TypeReference.Element)))
890-
.ToList();
891-
return relatedClasses;
892-
}
876+
893877

894878
}

Modules/Intent.Modules.AI.UnitTests/Tasks/GenerateDomainEventHandlerUnitTestWithAITask.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
using Intent.Configuration;
77
using Intent.Engine;
88
using Intent.Metadata.Models;
9-
using Intent.Modelers.Domain.Events.Api;
10-
using Intent.Modelers.Services.Api;
9+
using Intent.Modules.AI.UnitTests;
1110
using Intent.Modules.AI.UnitTests.Utilities;
1211
using Intent.Modules.Common.AI;
1312
using Intent.Modules.Common.AI.CodeGeneration;
@@ -70,7 +69,9 @@ public string Execute(params string[] args)
7069
Logging.Log.Info($"Args: {string.Join(",", args)}");
7170
var kernel = _intentSemanticKernelFactory.BuildSemanticKernel(modelId, provider, null);
7271

73-
var eventHandlerElement = _metadataManager.Services(applicationId).Elements.FirstOrDefault(x => x.Id == elementId);
72+
var servicesDesigner = _metadataManager.GetDesigner(applicationId, "Services");
73+
var eventHandlerElement = servicesDesigner.GetElementsOfType(SpecializationTypeIds.DomainEventHandler)
74+
.FirstOrDefault(x => x.Id == elementId);
7475
if (eventHandlerElement == null)
7576
{
7677
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.");
@@ -594,7 +595,8 @@ private List<ICodebaseFile> GetInputFiles(string applicationId, IElement eventHa
594595
var entityName = match.Groups[1].Value; // Entity name like Store
595596

596597
// Try to find the entity in metadata - search across all designers
597-
var servicesElements = _metadataManager.Services(applicationId).Elements;
598+
var servicesDesigner = _metadataManager.GetDesigner(applicationId, "Services");
599+
var servicesElements = servicesDesigner.GetElementsOfType(SpecializationTypeIds.Service);
598600
var entityElement = servicesElements.FirstOrDefault(e => e.Name.Equals(entityName, StringComparison.Ordinal));
599601
if (entityElement != null)
600602
{
@@ -622,7 +624,8 @@ private List<ICodebaseFile> GetInputFiles(string applicationId, IElement eventHa
622624
var serviceName = match.Groups[0].Value;
623625

624626
// Try to find the service interface in metadata
625-
var servicesElements = _metadataManager.Services(applicationId).Elements;
627+
var servicesDesigner = _metadataManager.GetDesigner(applicationId, "Services");
628+
var servicesElements = servicesDesigner.GetElementsOfType(SpecializationTypeIds.Service);
626629
var serviceElement = servicesElements.FirstOrDefault(e => e.Name.Equals(serviceName.Substring(1), StringComparison.Ordinal) ||
627630
e.Name.Equals(serviceName, StringComparison.Ordinal));
628631
if (serviceElement != null)
@@ -635,7 +638,11 @@ private List<ICodebaseFile> GetInputFiles(string applicationId, IElement eventHa
635638
var publishedMessageTypes = DetectPublishedMessageTypes(handlerContent);
636639
foreach (var messageTypeName in publishedMessageTypes)
637640
{
638-
var servicesElements = _metadataManager.Services(applicationId).Elements;
641+
var servicesDesigner = _metadataManager.GetDesigner(applicationId, "Services");
642+
var servicesElements = servicesDesigner.GetElementsOfType(SpecializationTypeIds.Service)
643+
.Concat(servicesDesigner.GetElementsOfType(SpecializationTypeIds.Command))
644+
.Concat(servicesDesigner.GetElementsOfType(SpecializationTypeIds.Query))
645+
.ToList();
639646
var messageElement = servicesElements.FirstOrDefault(e => e.Name.Equals(messageTypeName, StringComparison.Ordinal));
640647
if (messageElement != null)
641648
{
@@ -657,7 +664,8 @@ private List<ICodebaseFile> GetInputFiles(string applicationId, IElement eventHa
657664
}
658665

659666
// Try to find the entity
660-
var servicesElements = _metadataManager.Services(applicationId).Elements;
667+
var servicesDesigner = _metadataManager.GetDesigner(applicationId, "Services");
668+
var servicesElements = servicesDesigner.GetElementsOfType(SpecializationTypeIds.Service);
661669
var entityElement = servicesElements.FirstOrDefault(e => e.Name.Equals(entityName, StringComparison.Ordinal));
662670
if (entityElement != null)
663671
{

Modules/Intent.Modules.AI.UnitTests/Tasks/GenerateIntegrationEventHandlerUnitTestsWithAITask.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
using Intent.Configuration;
77
using Intent.Engine;
88
using Intent.Metadata.Models;
9-
using Intent.Modelers.Services.Api;
10-
using Intent.Modelers.Services.EventInteractions;
9+
using Intent.Modules.AI.UnitTests;
1110
using Intent.Modules.AI.UnitTests.Utilities;
1211
using Intent.Modules.Common.AI;
1312
using Intent.Modules.Common.AI.CodeGeneration;
@@ -70,7 +69,9 @@ public string Execute(params string[] args)
7069
Logging.Log.Info($"Args: {string.Join(",", args)}");
7170
var kernel = _intentSemanticKernelFactory.BuildSemanticKernel(modelId, provider, null);
7271

73-
var eventHandlerElement = _metadataManager.Services(applicationId).Elements.FirstOrDefault(x => x.Id == elementId);
72+
var servicesDesigner = _metadataManager.GetDesigner(applicationId, "Services");
73+
var eventHandlerElement = servicesDesigner.GetElementsOfType(SpecializationTypeIds.IntegrationEventHandler)
74+
.FirstOrDefault(x => x.Id == elementId);
7475
if (eventHandlerElement == null)
7576
{
7677
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.");
@@ -585,7 +586,11 @@ private List<ICodebaseFile> GetInputFiles(string applicationId, IElement eventHa
585586
foreach (var messageTypeName in publishedMessageTypes)
586587
{
587588
// Try to find the message by scanning for matching elements in Services metadata
588-
var allElements = _metadataManager.Services(applicationId).Elements;
589+
var servicesDesigner = _metadataManager.GetDesigner(applicationId, "Services");
590+
var allElements = servicesDesigner.GetElementsOfType(SpecializationTypeIds.Service)
591+
.Concat(servicesDesigner.GetElementsOfType(SpecializationTypeIds.Command))
592+
.Concat(servicesDesigner.GetElementsOfType(SpecializationTypeIds.Query))
593+
.ToList();
589594
var messageElement = allElements.FirstOrDefault(e => e.Name.Equals(messageTypeName, StringComparison.Ordinal));
590595
if (messageElement != null)
591596
{

Modules/Intent.Modules.AI.UnitTests/Tasks/GenerateServiceUnitTestsWithAITask.cs

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
using Intent.Configuration;
66
using Intent.Engine;
77
using Intent.Metadata.Models;
8-
using Intent.Modelers.Domain.Api;
9-
using Intent.Modelers.Services.Api;
8+
using Intent.Modules.AI.UnitTests;
109
using Intent.Modules.AI.UnitTests.Utilities;
1110
using Intent.Modules.Common.AI;
1211
using Intent.Modules.Common.AI.CodeGeneration;
@@ -18,6 +17,7 @@
1817
using Intent.Utils;
1918
using Microsoft.SemanticKernel;
2019
using Newtonsoft.Json;
20+
using static Intent.Modules.AI.UnitTests.Utilities.UnitTestHelpers;
2121

2222
[assembly: DefaultIntentManaged(Mode.Fully)]
2323
[assembly: IntentTemplate("Intent.ModuleBuilder.Templates.ModuleTask", Version = "1.0")]
@@ -71,7 +71,10 @@ public string Execute(params string[] args)
7171
Logging.Log.Info($"Args: {string.Join(",", args)}");
7272
var kernel = _intentSemanticKernelFactory.BuildSemanticKernel(modelId, provider, null);
7373

74-
var queryModel = _metadataManager.Services(applicationId).Elements.FirstOrDefault(x => x.Id == elementId);
74+
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);
7578
if (queryModel == null)
7679
{
7780
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.");
@@ -716,7 +719,7 @@ private List<ICodebaseFile> GetInputFiles(IElement service)
716719
{
717720
inputFiles.AddRange(filesProvider.GetFilesForMetadata(operation.TypeReference.Element));
718721
}
719-
foreach (var paramType in operation.ChildElements.Where(x => x.TypeReference.Element.IsDTOModel()).Select(x => x.TypeReference.Element))
722+
foreach (var paramType in operation.ChildElements.Where(x => x.TypeReference?.Element?.SpecializationTypeId == "a5e74323-9b24-48c8-9802-f8684e0aaa70").Select(x => x.TypeReference.Element))
720723
{
721724
inputFiles.AddRange(filesProvider.GetFilesForMetadata(paramType));
722725
}
@@ -760,22 +763,4 @@ private List<ICodebaseFile> GetInputFiles(IElement service)
760763
return inputFiles;
761764
}
762765

763-
private static List<ICanBeReferencedType> GetRelatedElements(IElement element)
764-
{
765-
var relatedElements = element.AssociatedElements.Where(x => x.TypeReference.Element != null)
766-
.Select(x => x.TypeReference.Element)
767-
.ToList();
768-
if (relatedElements.Count == 0)
769-
{
770-
return [];
771-
}
772-
var relatedClasses = relatedElements
773-
.Concat(relatedElements.Where(x => x.TypeReference?.Element?.IsDTOModel() == true).Select(x => x.TypeReference.Element))
774-
.Concat(relatedElements.Where(Intent.Modelers.Services.Api.OperationModelExtensions.IsOperationModel).Select(x => Intent.Modelers.Services.Api.OperationModelExtensions.AsOperationModel(x).ParentService.InternalElement))
775-
.Concat(relatedElements.Where(Intent.Modules.Common.Types.Api.OperationModelExtensions.IsOperationModel).Select(x => Intent.Modules.Common.Types.Api.OperationModelExtensions.AsOperationModel(x).InternalElement.ParentElement))
776-
.Concat(relatedElements.Where(x => x.IsClassModel()).Select(x => x.AsClassModel()).SelectMany(x => x.AssociatedClasses.Select(y => y.TypeReference.Element)))
777-
.ToList();
778-
return relatedClasses;
779-
}
780-
781766
}

0 commit comments

Comments
 (0)