Пример #1
0
        public void AddPackages_Adds_New_Depedenency()
        {
            string initialJson  = @"{
  ""dependencies"": {
    ""Newtonsoft.Json"": ""5.0.8"",
    ""Microsoft.Net.Runtime.Interfaces"": """"
    }
}";
            string expectedJson = @"{
  ""dependencies"": {
    ""Newtonsoft.Json"": ""5.0.8"",
    ""Microsoft.Net.Runtime.Interfaces"": """",
    ""Microsoft.Net.Runtime"": ""1.0.0""
  }
}";

            _mockFileSystem.WriteAllText(_projectJsonPath, initialJson);

            _packageInstaller.AddPackages(new[] { new PackageMetadata()
                                                  {
                                                      Name    = "Microsoft.Net.Runtime",
                                                      Version = "1.0.0"
                                                  } });

            var actualJson = _mockFileSystem.ReadAllText(_projectJsonPath);

            Assert.Equal(expectedJson, actualJson);
        }
        public async Task AddFileFromTemplateAsync_Writes_If_Template_Processing_Is_Successful()
        {
            var mockFilesLocator = new Mock <IFilesLocator>();
            var mockTemplating   = new Mock <ITemplating>();
            var mockFileSystem   = new MockFileSystem();

            var templateName    = "TemplateName";
            var templatePath    = "C:\template.cshtml";
            var templateContent = "TemplateContent";
            var outputPath      = @"C:\Output.txt";
            var generatedText   = "GeneratedText";

            mockFilesLocator.Setup(fl => fl.GetFilePath(templateName, It.IsAny <IEnumerable <string> >()))
            .Returns(templatePath);
            mockFileSystem.WriteAllText(templatePath, templateContent);
            mockTemplating.Setup(templating => templating.RunTemplateAsync(templateContent, null))
            .Returns(Task.FromResult(new TemplateResult()
            {
                ProcessingException = null,
                GeneratedText       = generatedText
            }));

            var codeGeneratorActionService = new CodeGeneratorActionsService(
                mockTemplating.Object, mockFilesLocator.Object, mockFileSystem);

            await codeGeneratorActionService.AddFileFromTemplateAsync(outputPath,
                                                                      templateName,
                                                                      new[] { "TemplateFolder1", "TemplateFolder2" },
                                                                      null);

            Assert.True(mockFileSystem.FileExists(outputPath));
            Assert.Equal(generatedText, mockFileSystem.ReadAllText(outputPath));
        }
        public async Task AddFileFromTemplateAsync_Writes_If_Template_Processing_Is_Successful()
        {
            var mockFilesLocator = new Mock<IFilesLocator>();
            var mockTemplating = new Mock<ITemplating>();
            var mockFileSystem = new MockFileSystem();

            var templateName = "TemplateName";
            var templatePath = "C:\template.cshtml";
            var templateContent = "TemplateContent";
            var outputPath = @"C:\Output.txt";
            var generatedText = "GeneratedText";

            mockFilesLocator.Setup(fl => fl.GetFilePath(templateName, It.IsAny<IEnumerable<string>>()))
                .Returns(templatePath);
            mockFileSystem.WriteAllText(templatePath, templateContent);
            mockTemplating.Setup(templating => templating.RunTemplateAsync(templateContent, null))
                .Returns(Task.FromResult(new TemplateResult()
                {
                    ProcessingException = null,
                    GeneratedText = generatedText
                }));

            var codeGeneratorActionService = new CodeGeneratorActionsService(
                mockTemplating.Object, mockFilesLocator.Object, mockFileSystem);

            await codeGeneratorActionService.AddFileFromTemplateAsync(outputPath,
                    templateName,
                    new[] { "TemplateFolder1", "TemplateFolder2" },
                    null);

            Assert.True(mockFileSystem.FileExists(outputPath));
            Assert.Equal(generatedText, mockFileSystem.ReadAllText(outputPath));
        }