Skip to content

Commit 36190b6

Browse files
committed
[#3] [add] Impl
1 parent d7908c2 commit 36190b6

File tree

11 files changed

+88
-26
lines changed

11 files changed

+88
-26
lines changed

src/Simplify.Web.Postman/Assembly/Collection/PartBuilders/CollectionHeaderBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class CollectionHeaderBuilder : ICollectionPartBuilder
2424
public void Build(CollectionModel model) =>
2525
model.Header = new CollectionHeader
2626
{
27-
Name = _settings.CollectionName
27+
Name = _settings.ProjectName
2828
};
2929
}
3030
}
Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
using System.Collections.Generic;
12
using System;
23
using Simplify.Web.Postman.Models;
4+
using Simplify.Web.Postman.Settings;
35

46
namespace Simplify.Web.Postman.Assembly.Environment
57
{
@@ -8,10 +10,30 @@ namespace Simplify.Web.Postman.Assembly.Environment
810
/// </summary>
911
public class EnvironmentBuilder
1012
{
13+
private readonly IPostmanGenerationSettings _settings;
14+
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="EnvironmentBuilder"/> class.
17+
/// </summary>
18+
/// <param name="settings">The settings.</param>
19+
public EnvironmentBuilder(IPostmanGenerationSettings settings) => _settings = settings;
20+
1121
/// <summary>
1222
/// Creates this environment model.
1323
/// </summary>
1424
/// <returns></returns>
15-
public EnvironmentModel Create() => throw new NotImplementedException();
25+
public EnvironmentModel Create() =>
26+
new()
27+
{
28+
Name = _settings.ProjectName,
29+
Values = new List<PostmanValue>
30+
{
31+
new PostmanValue
32+
{
33+
Key = "BaseUrl",
34+
Value = "http://localhost:5000"
35+
}
36+
}
37+
};
1638
}
1739
}

src/Simplify.Web.Postman/Generators/FileBasedEnvironmentGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ public FileBasedEnvironmentGenerator(EnvironmentBuilder builder, ModelToFileExpo
3333
public void Generate() => _exporter.Export(_builder.Create(), GenerateFileName());
3434

3535
private string GenerateFileName() =>
36-
Path.Combine(_settings.CollectionFileName + _settings.CollectionFileNamePostfix + ".json");
36+
Path.Combine(_settings.EnvironmentFileName + _settings.EnvironmentFileNamePostfix + ".json");
3737
}
3838
}

src/Simplify.Web.Postman/Models/EnvironmentModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ public class EnvironmentModel
2323
/// <value>
2424
/// The values.
2525
/// </value>
26-
public IDictionary<string, string> Values { get; set; }
26+
public IList<PostmanValue> Values { get; set; }
2727
}
2828
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#nullable disable
2+
3+
namespace Simplify.Web.Postman.Models
4+
{
5+
/// <summary>
6+
/// Provides postman value
7+
/// </summary>
8+
public class PostmanValue
9+
{
10+
/// <summary>
11+
/// Gets or sets the key.
12+
/// </summary>
13+
/// <value>
14+
/// The key.
15+
/// </value>
16+
public string Key { get; set; }
17+
18+
/// <summary>
19+
/// Gets or sets the value.
20+
/// </summary>
21+
/// <value>
22+
/// The value.
23+
/// </value>
24+
public string Value { get; set; }
25+
26+
/// <summary>
27+
/// Gets or sets a value indicating whether this <see cref="PostmanValue"/> is enabled.
28+
/// </summary>
29+
/// <value>
30+
/// <c>true</c> if enabled; otherwise, <c>false</c>.
31+
/// </value>
32+
public bool Enabled { get; set; } = true;
33+
}
34+
}

src/Simplify.Web.Postman/Settings/IPostmanGenerationSettings.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ namespace Simplify.Web.Postman.Settings
66
public interface IPostmanGenerationSettings
77
{
88
/// <summary>
9-
/// Gets or sets the name of the collection.
9+
/// Gets or sets the name of the project.
1010
/// </summary>
1111
/// <value>
12-
/// The name of the collection.
12+
/// The name of the project.
1313
/// </value>
14-
string CollectionName { get; }
14+
string ProjectName { get; }
1515

1616
/// <summary>
1717
/// Gets or sets the name of the collection file.

src/Simplify.Web.Postman/Settings/PostmanGenerationSettings.cs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Simplify.Web.Postman.Settings
77
/// </summary>
88
public class PostmanGenerationSettings : IPostmanGenerationSettings
99
{
10-
private string _collectionName;
10+
private string _projectName;
1111
private string _collectionFileName;
1212
private string _collectionFileNamePostfix;
1313
private string _environmentFileName;
@@ -21,7 +21,7 @@ public PostmanGenerationSettings()
2121
{
2222
var projectAssemblyName = global::System.Reflection.Assembly.GetEntryAssembly()?.GetName().Name ?? "App";
2323

24-
_collectionName = projectAssemblyName;
24+
_projectName = projectAssemblyName;
2525
_collectionFileName = projectAssemblyName;
2626
_collectionFileNamePostfix = ".postman_collection";
2727
_environmentFileName = projectAssemblyName;
@@ -35,11 +35,10 @@ public PostmanGenerationSettings()
3535
/// <value>
3636
/// The name of the collection.
3737
/// </value>
38-
public string CollectionName
38+
public string ProjectName
3939
{
40-
get => _collectionName;
41-
set => _collectionName = value ??
42-
throw new ArgumentNullException(nameof(value));
40+
get => _projectName;
41+
set => _projectName = value ?? throw new ArgumentNullException(nameof(value));
4342
}
4443

4544
/// <summary>
@@ -51,8 +50,7 @@ public string CollectionName
5150
public string CollectionFileName
5251
{
5352
get => _collectionFileName;
54-
set => _collectionFileName = value ??
55-
throw new ArgumentNullException(nameof(value));
53+
set => _collectionFileName = value ?? throw new ArgumentNullException(nameof(value));
5654
}
5755

5856
/// <summary>
@@ -64,8 +62,7 @@ public string CollectionFileName
6462
public string CollectionFileNamePostfix
6563
{
6664
get => _collectionFileNamePostfix;
67-
set => _collectionFileNamePostfix = value ??
68-
throw new ArgumentNullException(nameof(value));
65+
set => _collectionFileNamePostfix = value ?? throw new ArgumentNullException(nameof(value));
6966
}
7067

7168
/// <summary>
@@ -77,8 +74,7 @@ public string CollectionFileNamePostfix
7774
public string EnvironmentFileName
7875
{
7976
get => _environmentFileName;
80-
set => _environmentFileName = value ??
81-
throw new ArgumentNullException(nameof(value));
77+
set => _environmentFileName = value ?? throw new ArgumentNullException(nameof(value));
8278
}
8379

8480
/// <summary>
@@ -90,8 +86,7 @@ public string EnvironmentFileName
9086
public string EnvironmentFileNamePostfix
9187
{
9288
get => _environmentFileNamePostfix;
93-
set => _environmentFileNamePostfix = value ??
94-
throw new ArgumentNullException(nameof(value));
89+
set => _environmentFileNamePostfix = value ?? throw new ArgumentNullException(nameof(value));
9590
}
9691

9792
/// <summary>
@@ -103,8 +98,7 @@ public string EnvironmentFileNamePostfix
10398
public string GenerationFolderPath
10499
{
105100
get => _generationFolderPath;
106-
set => _generationFolderPath = value ??
107-
throw new ArgumentNullException(nameof(value));
101+
set => _generationFolderPath = value ?? throw new ArgumentNullException(nameof(value));
108102
}
109103
}
110104
}
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
using System;
2+
using System.Threading.Tasks;
23
using Simplify.Web;
34
using Simplify.Web.Attributes;
45
using TesterApp.ViewModels;
56

67
namespace TesterApp.Controllers.Api.v1
78
{
89
[Post("/api/v1/testIn")]
9-
public class TestInController : Controller<TestViewModel>
10+
public class TestInController : AsyncController<TestViewModel>
1011
{
11-
public override ControllerResponse Invoke()
12+
public override async Task<ControllerResponse> Invoke()
1213
{
13-
throw new NotImplementedException();
14+
await ReadModelAsync();
15+
16+
return Content($"Prop1 = '{Model.Prop1}', Prog2 = '{Model.Prop2}'");
1417
}
1518
}
1619
}

src/TesterApp/Setup/IocRegistrations.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Simplify.DI;
22
using Simplify.Web.Bootstrapper;
3+
using Simplify.Web.Json;
34
using Simplify.Web.Postman;
45
using Simplify.Web.Postman.Setup;
56

@@ -10,6 +11,7 @@ public static class IocRegistrations
1011
public static IDIContainerProvider RegisterAll(this IDIContainerProvider containerProvider)
1112
{
1213
containerProvider.RegisterSimplifyWeb()
14+
.RegisterJsonModelBinder()
1315
.RegisterSimplifyWebPostman();
1416

1517
return containerProvider;

src/TesterApp/Startup.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using Microsoft.Extensions.Hosting;
55
using Simplify.DI;
66
using Simplify.Web;
7+
using Simplify.Web.Json.Model.Binding;
8+
using Simplify.Web.Model;
79
using Simplify.Web.Postman.Setup;
810
using TesterApp.Setup;
911

@@ -16,6 +18,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
1618
if (env.IsDevelopment())
1719
app.UseDeveloperExceptionPage();
1820

21+
HttpModelHandler.RegisterModelBinder<JsonModelBinder>();
22+
1923
app.UseSimplifyWebWithoutRegistrations();
2024

2125
if (env.IsDevelopment())

0 commit comments

Comments
 (0)