Move models into dedicated project
This commit is contained in:
Родитель
16c9960783
Коммит
ebd6f1b0ce
|
@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Steeltoe.Initializr.WebApi"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Steeltoe.Initializr.WebApi.Test", "test\Steeltoe.Initializr.WebApi.Test\Steeltoe.Initializr.WebApi.Test.csproj", "{EA849C8F-7118-45DB-BBF2-D36CE1FD43B4}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Steeltoe.Initializr.WebApi.Test", "test\Steeltoe.Initializr.WebApi.Test\Steeltoe.Initializr.WebApi.Test.csproj", "{EA849C8F-7118-45DB-BBF2-D36CE1FD43B4}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Steeltoe.Initializr.WebApi.Models", "src\Steeltoe.Initializr.WebApi.Models\Steeltoe.Initializr.WebApi.Models.csproj", "{ACE6FEE1-9CEA-4A95-9D76-C62A41947C8F}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
@ -44,5 +46,17 @@ Global
|
||||||
{EA849C8F-7118-45DB-BBF2-D36CE1FD43B4}.Release|x64.Build.0 = Release|Any CPU
|
{EA849C8F-7118-45DB-BBF2-D36CE1FD43B4}.Release|x64.Build.0 = Release|Any CPU
|
||||||
{EA849C8F-7118-45DB-BBF2-D36CE1FD43B4}.Release|x86.ActiveCfg = Release|Any CPU
|
{EA849C8F-7118-45DB-BBF2-D36CE1FD43B4}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{EA849C8F-7118-45DB-BBF2-D36CE1FD43B4}.Release|x86.Build.0 = Release|Any CPU
|
{EA849C8F-7118-45DB-BBF2-D36CE1FD43B4}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{ACE6FEE1-9CEA-4A95-9D76-C62A41947C8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{ACE6FEE1-9CEA-4A95-9D76-C62A41947C8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{ACE6FEE1-9CEA-4A95-9D76-C62A41947C8F}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{ACE6FEE1-9CEA-4A95-9D76-C62A41947C8F}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{ACE6FEE1-9CEA-4A95-9D76-C62A41947C8F}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{ACE6FEE1-9CEA-4A95-9D76-C62A41947C8F}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{ACE6FEE1-9CEA-4A95-9D76-C62A41947C8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{ACE6FEE1-9CEA-4A95-9D76-C62A41947C8F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{ACE6FEE1-9CEA-4A95-9D76-C62A41947C8F}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{ACE6FEE1-9CEA-4A95-9D76-C62A41947C8F}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{ACE6FEE1-9CEA-4A95-9D76-C62A41947C8F}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{ACE6FEE1-9CEA-4A95-9D76-C62A41947C8F}.Release|x86.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
/bin/
|
||||||
|
/obj/
|
|
@ -1,9 +1,9 @@
|
||||||
namespace Steeltoe.Initializr.WebApi.Models
|
namespace Steeltoe.Initializr.WebApi.Models.Project
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A model ofi the configuration used to generate a project.
|
/// A model ofi the configuration used to generate a project.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ProjectConfiguration
|
public class Configuration
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Compares the specified object to this object.
|
/// Compares the specified object to this object.
|
|
@ -0,0 +1,7 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
|
@ -9,17 +9,17 @@ namespace Steeltoe.Initializr.WebApi.Controllers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
public class ConfigurationController : ControllerBase
|
public class MetadataController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly IConfigurationRepository _configurationRepository;
|
private readonly IMetadataRepository _metadataRepository;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new ConfigurationController.
|
/// Create a new ConfigurationController.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="configurationRepository">configuration repository</param>
|
/// <param name="metadataRepository">configuration repository</param>
|
||||||
public ConfigurationController(IConfigurationRepository configurationRepository)
|
public MetadataController(IMetadataRepository metadataRepository)
|
||||||
{
|
{
|
||||||
_configurationRepository = configurationRepository;
|
_metadataRepository = metadataRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -29,7 +29,7 @@ namespace Steeltoe.Initializr.WebApi.Controllers
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<IActionResult> Get()
|
public async Task<IActionResult> Get()
|
||||||
{
|
{
|
||||||
var config = await _configurationRepository.GetConfiguration();
|
var config = await _metadataRepository.GetConfiguration();
|
||||||
return Ok(config);
|
return Ok(config);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Steeltoe.Initializr.WebApi.Models;
|
using Steeltoe.Initializr.WebApi.Models.Project;
|
||||||
using Steeltoe.Initializr.WebApi.Services;
|
using Steeltoe.Initializr.WebApi.Services;
|
||||||
|
|
||||||
namespace Steeltoe.Initializr.WebApi.Controllers
|
namespace Steeltoe.Initializr.WebApi.Controllers
|
||||||
|
@ -32,7 +32,7 @@ namespace Steeltoe.Initializr.WebApi.Controllers
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<ActionResult> Get()
|
public async Task<ActionResult> Get()
|
||||||
{
|
{
|
||||||
var config = new ProjectConfiguration();
|
var config = new Configuration();
|
||||||
var stream = await _projectGenerator.GenerateProject(config);
|
var stream = await _projectGenerator.GenerateProject(config);
|
||||||
var buf = new MemoryStream();
|
var buf = new MemoryStream();
|
||||||
await stream.CopyToAsync(buf);
|
await stream.CopyToAsync(buf);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Steeltoe.Initializr.WebApi.Models;
|
using Steeltoe.Initializr.WebApi.Models.Project;
|
||||||
|
|
||||||
namespace Steeltoe.Initializr.WebApi.Services
|
namespace Steeltoe.Initializr.WebApi.Services
|
||||||
{
|
{
|
||||||
|
@ -10,7 +10,7 @@ namespace Steeltoe.Initializr.WebApi.Services
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DummyProjectGenerator : IProjectGenerator
|
public class DummyProjectGenerator : IProjectGenerator
|
||||||
{
|
{
|
||||||
public Task<Stream> GenerateProject(ProjectConfiguration projectConfiguration)
|
public Task<Stream> GenerateProject(Configuration configuration)
|
||||||
{
|
{
|
||||||
var bytes = new UnicodeEncoding().GetBytes("DummyProject");
|
var bytes = new UnicodeEncoding().GetBytes("DummyProject");
|
||||||
var stream = new MemoryStream(bytes.Length);
|
var stream = new MemoryStream(bytes.Length);
|
||||||
|
|
|
@ -6,7 +6,7 @@ namespace Steeltoe.Initializr.WebApi.Services
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contract for configuration repository implementations.
|
/// Contract for configuration repository implementations.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IConfigurationRepository
|
public interface IMetadataRepository
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the project generation configuration.
|
/// Gets the project generation configuration.
|
|
@ -1,6 +1,6 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Steeltoe.Initializr.WebApi.Models;
|
using Steeltoe.Initializr.WebApi.Models.Project;
|
||||||
|
|
||||||
namespace Steeltoe.Initializr.WebApi.Services
|
namespace Steeltoe.Initializr.WebApi.Services
|
||||||
{
|
{
|
||||||
|
@ -12,8 +12,8 @@ namespace Steeltoe.Initializr.WebApi.Services
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generates a project as a byte stream.
|
/// Generates a project as a byte stream.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="projectConfiguration">Project configuration</param>
|
/// <param name="configuration">Project configuration</param>
|
||||||
/// <returns>project bundle byte stream</returns>
|
/// <returns>project bundle byte stream</returns>
|
||||||
public Task<Stream> GenerateProject(ProjectConfiguration projectConfiguration);
|
public Task<Stream> GenerateProject(Configuration configuration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ namespace Steeltoe.Initializr.WebApi.Services
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A configuration repository that loads configuration from a local JSON file.
|
/// A configuration repository that loads configuration from a local JSON file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class LocalConfigurationRepository : IConfigurationRepository
|
public class LocalMetadataRepository : IMetadataRepository
|
||||||
{
|
{
|
||||||
private const string ConfigurationFile = "initializr-configuration.json";
|
private const string ConfigurationFile = "initializr-configuration.json";
|
||||||
|
|
||||||
|
@ -28,9 +28,9 @@ namespace Steeltoe.Initializr.WebApi.Services
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new LocalConfigurationRepository.
|
/// Create a new LocalConfigurationRepository.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public LocalConfigurationRepository(ILoggerFactory loggerFactory)
|
public LocalMetadataRepository(ILoggerFactory loggerFactory)
|
||||||
{
|
{
|
||||||
_logger = loggerFactory.CreateLogger<LocalConfigurationRepository>();
|
_logger = loggerFactory.CreateLogger<LocalMetadataRepository>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
|
@ -19,7 +19,7 @@ namespace Steeltoe.Initializr.WebApi
|
||||||
// This method gets called by the runtime. Use this method to add services to the container.
|
// This method gets called by the runtime. Use this method to add services to the container.
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddScoped<IConfigurationRepository, LocalConfigurationRepository>();
|
services.AddScoped<IMetadataRepository, LocalMetadataRepository>();
|
||||||
services.AddScoped<IProjectGenerator, DummyProjectGenerator>();
|
services.AddScoped<IProjectGenerator, DummyProjectGenerator>();
|
||||||
services.AddControllers();
|
services.AddControllers();
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,5 +21,9 @@
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Steeltoe.Initializr.WebApi.Models\Steeltoe.Initializr.WebApi.Models.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -11,13 +11,13 @@ using Xunit;
|
||||||
|
|
||||||
namespace Steeltoe.Initializr.WebApi.Test.Controllers
|
namespace Steeltoe.Initializr.WebApi.Test.Controllers
|
||||||
{
|
{
|
||||||
public class ConfigurationControllerTest
|
public class MetadataControllerTest
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task EndpointExists()
|
public async Task EndpointExists()
|
||||||
{
|
{
|
||||||
var client = new HttpClientBuilder().Build();
|
var client = new HttpClientBuilder().Build();
|
||||||
var response = await client.GetAsync("/api/configuration");
|
var response = await client.GetAsync("/api/metadata");
|
||||||
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,9 +25,9 @@ namespace Steeltoe.Initializr.WebApi.Test.Controllers
|
||||||
public async Task EndpointReturnsAConfiguration()
|
public async Task EndpointReturnsAConfiguration()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var mockRepo = new Mock<IConfigurationRepository>();
|
var mockRepo = new Mock<IMetadataRepository>();
|
||||||
mockRepo.Setup(repo => repo.GetConfiguration()).ReturnsAsync(new Configuration());
|
mockRepo.Setup(repo => repo.GetConfiguration()).ReturnsAsync(new Configuration());
|
||||||
var controller = new ConfigurationController(mockRepo.Object);
|
var controller = new MetadataController(mockRepo.Object);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = await controller.Get();
|
var result = await controller.Get();
|
|
@ -5,7 +5,7 @@ using FluentAssertions;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Steeltoe.Initializr.WebApi.Controllers;
|
using Steeltoe.Initializr.WebApi.Controllers;
|
||||||
using Steeltoe.Initializr.WebApi.Models;
|
using Steeltoe.Initializr.WebApi.Models.Project;
|
||||||
using Steeltoe.Initializr.WebApi.Services;
|
using Steeltoe.Initializr.WebApi.Services;
|
||||||
using Steeltoe.Initializr.WebApi.Test.Utils;
|
using Steeltoe.Initializr.WebApi.Test.Utils;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
@ -32,7 +32,7 @@ namespace Steeltoe.Initializr.WebApi.Test.Controllers
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var mockGenerator = new Mock<IProjectGenerator>();
|
var mockGenerator = new Mock<IProjectGenerator>();
|
||||||
mockGenerator.Setup(g => g.GenerateProject(new ProjectConfiguration())).ReturnsAsync(new MemoryStream());
|
mockGenerator.Setup(g => g.GenerateProject(new Configuration())).ReturnsAsync(new MemoryStream());
|
||||||
var controller = new ProjectController(mockGenerator.Object);
|
var controller = new ProjectController(mockGenerator.Object);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
|
@ -6,12 +6,12 @@ using Xunit;
|
||||||
|
|
||||||
namespace Steeltoe.Initializr.WebApi.Test.Services
|
namespace Steeltoe.Initializr.WebApi.Test.Services
|
||||||
{
|
{
|
||||||
public class LocalConfigurationRepositoryTest
|
public class LocalMetadataRepositoryTest
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ConfigurationShouldNotBeNull()
|
public async Task ConfigurationShouldNotBeNull()
|
||||||
{
|
{
|
||||||
var configRepo = new LocalConfigurationRepository(new NullLoggerFactory());
|
var configRepo = new LocalMetadataRepository(new NullLoggerFactory());
|
||||||
var config = await configRepo.GetConfiguration();
|
var config = await configRepo.GetConfiguration();
|
||||||
config.Should().NotBeNull();
|
config.Should().NotBeNull();
|
||||||
}
|
}
|
Загрузка…
Ссылка в новой задаче