Exemplo n.º 1
0
        public Task InitializeAllAsync(ModelInitializationParameters initParams)
        {
            var csharpFilePaths = _fileSystem.Directory.GetFiles(initParams.FolderPath, "*.cs").ToList();

            var generatedDirectory = _fileSystem.Path.Combine(initParams.FolderPath, "Generated");

            _fileSystem.Directory.CreateDirectory(generatedDirectory);

            foreach (var filePath in csharpFilePaths)
            {
                var modelClassInfoResult = _modelClassInfoFactory.TryCreatingFromFile(filePath);
                if (modelClassInfoResult.IsSuccess)
                {
                    var testClass    = _modelTestClassFactory.Create(modelClassInfoResult.Value, initParams.TestAssemblyBaseNamespace);
                    var fullTestPath = _fileSystem.Path.Combine(generatedDirectory, testClass.FileName);
                    _fileSystem.File.WriteAllText(fullTestPath, testClass.FileContent);
                }
            }

            return(Task.CompletedTask);
        }
        public async Task InitializeAsync(ModelTestingViewModel context)
        {
            _context = context;

            await Task.Run(
                () =>
            {
                Commands = new CommandsViewData(
                    new List <ViewModelCommand>
                {
                    new ViewModelCommand(
                        "Create Model Tests",
                        new RelayCommand(
                            async() =>
                    {
                        var initParams = new ModelInitializationParameters(context.FolderPath, context.TestAssemblyBaseNamespce);
                        await _modelTestInitializationService.InitializeAllAsync(initParams);
                    },
                            () => !string.IsNullOrEmpty(context.FolderPath) && !string.IsNullOrEmpty(context.TestAssemblyBaseNamespce)))
                });
            });
        }