public void IRepository_Template_Test() { var template = new IRepositoryTemplate(new SmartAppInfo { Id = ApplicationId }); var output = template.TransformText(); Assert.NotNull(output); Assert.NotEmpty(output); Assert.Contains($"namespace {ApplicationId}.Backend", output); Assert.Contains("public interface IRepository<T>", output); }
public void GenerateDataServiceProject(DomainDataService dataService, string outputFolder) { outputFolder = Path.Combine(outputFolder, $"{dataService.Solution.NamespacePrefix}.{dataService.Name}.DataService"); var interfacesFolder = Path.Combine(outputFolder, "Interfaces"); var mappingsFolder = Path.Combine(outputFolder, "Mappings"); var recordTypesFolder = Path.Combine(outputFolder, "RecordTypes"); var validatorsFolder = Path.Combine(outputFolder, "Validators"); ReplaceDirectories(interfacesFolder, mappingsFolder, recordTypesFolder, validatorsFolder); var session = new Dictionary <string, object>(); session.Add("DomainDataService", dataService); DataServiceProjectTemplate projectTemplate = new DataServiceProjectTemplate(); projectTemplate.Session = session; projectTemplate.Initialize(); string content = projectTemplate.TransformText(); File.WriteAllText(Path.Combine(outputFolder, $"{dataService.Solution.NamespacePrefix}.{dataService.Name}.DataService.csproj"), content); IRepositoryTemplate repositoryInterfaceTemplate = new IRepositoryTemplate(); repositoryInterfaceTemplate.Session = session; repositoryInterfaceTemplate.Initialize(); content = repositoryInterfaceTemplate.TransformText(); File.WriteAllText(Path.Combine(interfacesFolder, $"I{dataService.Name}DataServiceRespository.cs"), content); IDataServiceTemplate dataServiceInterfaceTemplate = new IDataServiceTemplate(); dataServiceInterfaceTemplate.Session = session; dataServiceInterfaceTemplate.Initialize(); content = dataServiceInterfaceTemplate.TransformText(); File.WriteAllText(Path.Combine(interfacesFolder, $"I{dataService.Name}DataService.cs"), content); RepositoryTemplate repositoryTemplate = new RepositoryTemplate(); repositoryTemplate.Session = session; repositoryTemplate.Initialize(); content = repositoryTemplate.TransformText(); File.WriteAllText(Path.Combine(outputFolder, $"{dataService.Name}DataServiceRespository.cs"), content); DataServiceTemplate dataServiceTemplate = new DataServiceTemplate(); dataServiceTemplate.Session = session; dataServiceTemplate.Initialize(); content = dataServiceTemplate.TransformText(); File.WriteAllText(Path.Combine(outputFolder, $"{dataService.Name}DataService.cs"), content); KernelManipulationsTemplate kernelManipulationsTemplate = new KernelManipulationsTemplate(); kernelManipulationsTemplate.Session = session; kernelManipulationsTemplate.Initialize(); content = kernelManipulationsTemplate.TransformText(); File.WriteAllText(Path.Combine(outputFolder, $"{dataService.Name}KernelManipulations.cs"), content); StartupTaskTemplate startupTaskTemplate = new StartupTaskTemplate(); startupTaskTemplate.Session = session; startupTaskTemplate.Initialize(); content = startupTaskTemplate.TransformText(); File.WriteAllText(Path.Combine(outputFolder, $"{dataService.Name}Startup.cs"), content); if (!(dataService.Schemas is null)) { foreach (var domainObject in dataService.Schemas.SelectMany(s => s.Objects)) { session["CurrentObject"] = domainObject; MappingTemplate mappingTemplate = new MappingTemplate(); mappingTemplate.Session = session; mappingTemplate.Initialize(); content = mappingTemplate.TransformText(); File.WriteAllText(Path.Combine(mappingsFolder, $"{domainObject.ObjectName}Mapping.cs"), content); RecordTypeTemplate recordTypeTemplate = new RecordTypeTemplate(); recordTypeTemplate.Session = session; recordTypeTemplate.Initialize(); content = recordTypeTemplate.TransformText(); File.WriteAllText(Path.Combine(recordTypesFolder, $"{domainObject.ObjectName}RecordType.cs"), content); if (domainObject.SupportsIHaveId()) { var modelValidatorsFolder = Path.Combine(validatorsFolder, domainObject.ObjectName); ReplaceDirectories(modelValidatorsFolder); ValidatorTemplate validatorTemplate = new ValidatorTemplate(); validatorTemplate.Session = session; validatorTemplate.Initialize(); content = validatorTemplate.TransformText(); File.WriteAllText(Path.Combine(modelValidatorsFolder, $"{domainObject.ObjectName}Validator.cs"), content); DeleteValidatorTemplate deleteValidatorTemplate = new DeleteValidatorTemplate(); deleteValidatorTemplate.Session = session; deleteValidatorTemplate.Initialize(); content = deleteValidatorTemplate.TransformText(); File.WriteAllText(Path.Combine(modelValidatorsFolder, $"{domainObject.ObjectName}DeleteValidator.cs"), content); BatchValidatorTemplate batchValidatorTemplate = new BatchValidatorTemplate(); batchValidatorTemplate.Session = session; batchValidatorTemplate.Initialize(); content = batchValidatorTemplate.TransformText(); File.WriteAllText(Path.Combine(modelValidatorsFolder, $"{domainObject.ObjectName}BatchValidator.cs"), content); } } } }
public void IRepository_Template_NullParameter_Test() { var template = new IRepositoryTemplate(null); Assert.Throws <NullReferenceException>(() => template.TransformText()); }
private void TransformDataIRepositoryTemplate(SmartAppInfo manifest) { var template = new IRepositoryTemplate(manifest); _writingService.WriteFile(Path.Combine(_context.BasePath, template.OutputPath), template.TransformText()); }