Beispiel #1
0
        public async Task InstallTemplates_Should_Return_InstalledTemplates()
        {
            // Arrange
            var executor = new Mock <ICommandExecutor>();

            executor.SetupSequence(c => c.ExecuteAsync($"{NetCoreTool.Command} new --list", null, -1))
            .ReturnsAsync(new CommandResult
            {
                ExitCode = 0,
                Output   = @"
-------------------  --------  ---------  ---------
My Template          myt       lang       tags
My Other Template    myot      otherlang  othertags
",
            }
                          )
            .ReturnsAsync(new CommandResult
            {
                ExitCode = 0,
                Output   = @"
-------------------  --------  ---------  ----------
A New Template       ant       smalltalk  newstuff
My Template          myt       lang       tags
My Other Template    myot      otherlang  othertags
Other New Template   ont       bigtalk    otherstuff
",
            }
                          );
            executor.Setup(c => c.ExecuteAsync($"{NetCoreTool.Command} new --install My.Templates", null, -1))
            .ReturnsAsync(new CommandResult
            {
                ExitCode = 0,
                Output   = "",
            }
                          );
            var controller = new NewController(executor.Object);

            // Act
            var result = await controller.InstallTemplates("My.Templates");

            // Assert
            var createdResult = Assert.IsType <CreatedAtActionResult>(result);
            var templates     = Assert.IsType <TemplateDictionary>(createdResult.Value);

            templates.Count.Should().Be(2);
            templates["ant"].Name.Should().Be("A New Template");
            templates["ant"].Languages.Should().Be("smalltalk");
            templates["ant"].Tags.Should().Be("newstuff");
            templates["ont"].Name.Should().Be("Other New Template");
            templates["ont"].Languages.Should().Be("bigtalk");
            templates["ont"].Tags.Should().Be("otherstuff");
        }
Beispiel #2
0
        public async Task InstallTemplates_UnknownNuGet_Should_Return_BadRequest()
        {
            // Arrange
            var executor = new Mock <ICommandExecutor>();

            executor.Setup(c => c.ExecuteAsync($"{NetCoreTool.Command} new --list", null, -1))
            .ReturnsAsync(new CommandResult
            {
                ExitCode = 0,
                Output   = @"
-------------------  --------  ---------  ---------
My Template          myt       lang       tags
My Other Template    myot      otherlang  othertags
",
            }
                          );
            executor.Setup(c =>
                           c.ExecuteAsync($"{NetCoreTool.Command} new --install No.Such.Template", null, -1))
            .ReturnsAsync(new CommandResult
            {
                ExitCode = 2,
                Output   = @"
... error NU1101: Unable to find package No.Such.Template. No packages exist with this id in source(s): myget.org, nuget.org
Failed to restore ...
",
            });

            var controller = new NewController(executor.Object);

            // Act
            var result = await controller.InstallTemplates("No.Such.Template");

            // Assert
            var badRequest = Assert.IsType <BadRequestObjectResult>(result);

            badRequest.Value.Should()
            .Be(
                "Unable to find package No.Such.Template. No packages exist with this id in source(s): myget.org, nuget.org");
        }