Skip to content

Commit

Permalink
Generate RandomValueController when random value option is set
Browse files Browse the repository at this point in the history
  • Loading branch information
korser1 committed Jan 21, 2022
1 parent 0424c47 commit 2be22bb
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
"exclude": [
"Dockerfile"
]
},
{
"condition": "(!ConfigurationRandomValueOption)",
"exclude": [
"Controllers/RandomValueController.cs"
]
}
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;

namespace Company.WebApplication.CS.Controllers
{
[ApiController]
[Route("[controller]")]
public class RandomValueController : ControllerBase
{
private IConfiguration _config;

public RandomValueController(IConfiguration config)
{
_config = config;
}

[HttpGet]
public dynamic Index()
{
return new
{
intVal = _config["random:int"],
longVal = _config["random:long"],
int10 = _config["random:int(10)"],
long10 = _config["random:long(100)"],
int10_20 = _config["random:int(10,20)"],
long100_200 = _config["random:long(100,200)"],
uuid = _config["random:uuid"],
stringVal = _config["random:string"]
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
"exclude": [
"Dockerfile"
]
},
{
"condition": "(!ConfigurationRandomValueOption)",
"exclude": [
"Controllers/RandomValueController.fs"
]
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@

<ItemGroup>
<Compile Include="WeatherForecast.fs" />
<!--#if (ConfigurationRandomValueOption) -->
<Compile Include="Controllers/RandomValueController.fs" />
<!--#endif -->
<Compile Include="Controllers/WeatherForecastController.fs" />
<!--#if (CircuitBreakerHystrixOption) -->
<Compile Include="HelloHystrixCommand.fs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Company.WebApplication.FS.Controllers

open Microsoft.AspNetCore.Mvc
open Microsoft.Extensions.Configuration
open Microsoft.Extensions.Logging

type RandomValue = {intVal : int; longVal: int64; int10: int; long10: int64; int10_20: int; long100_200: int64; uuid: string; stringVal: string}

[<ApiController>]
[<Route("[controller]")>]
type RandomValueController (logger : ILogger<RandomValueController>, _config: IConfiguration) =
inherit ControllerBase()

[<HttpGet>]
member _.Get() =
{ intVal = int _config.["random:int"]
longVal = int64 _config.["random:long"]
int10 = int _config.["random:int(10)"]
long10 = int64 _config.["random:long(100)"]
int10_20 = int _config.["random:int(10,20)"]
long100_200 = int64 _config.["random:long(100,200)"]
uuid = _config.["random:uuid"]
stringVal = _config.["random:string"] }
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using FluentAssertions;
using Steeltoe.NetCoreTool.Template.WebApi.Test.Models;
using Xunit;
using Xunit.Abstractions;

namespace Steeltoe.NetCoreTool.Template.WebApi.Test
Expand All @@ -21,5 +24,21 @@ protected override void AssertProgramSnippetsHook(ProjectOptions options, List<s
snippets.Add("Steeltoe.Extensions.Configuration.RandomValue");
snippets.Add(".ConfigureAppConfiguration");
}

[Fact]
[Trait("Category", "ProjectGeneration")]
public async void TestDefaultNotPolluted()
{
using var sandbox = await TemplateSandbox("false");
sandbox.FileExists("Controllers/RandomValueController.cs").Should().BeFalse();
sandbox.FileExists("Controllers/RandomValueController.fs").Should().BeFalse();
}

protected override async Task AssertProjectGeneration(ProjectOptions options)
{
await base.AssertProjectGeneration(options);
Logger.WriteLine("asserting Controllers/RandomValueController");
Sandbox.FileExists(GetSourceFileForLanguage("Controllers/RandomValueController", options.Language)).Should().BeTrue();
}
}
}

0 comments on commit 2be22bb

Please sign in to comment.