Skip to content

Commit db867c0

Browse files
committed
Minimal working generation carcass and setup
1 parent 2beeef8 commit db867c0

15 files changed

+209
-4
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Simplify.Web.Postman.Models;
4+
5+
namespace Simplify.Web.Postman
6+
{
7+
public class CollectionBuilder
8+
{
9+
private readonly IList<ICollectionPartBuilder> _partBuilders;
10+
11+
public CollectionBuilder(IList<ICollectionPartBuilder> partBuilders)
12+
{
13+
_partBuilders = partBuilders ?? throw new ArgumentNullException(nameof(partBuilders));
14+
}
15+
16+
public CollectionModel Create()
17+
{
18+
var model = new CollectionModel();
19+
20+
foreach (var partBuilder in _partBuilders)
21+
partBuilder.Build(model);
22+
23+
return model;
24+
}
25+
}
26+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Text.Json;
2+
using Simplify.Web.Postman.Models;
3+
4+
namespace Simplify.Web.Postman
5+
{
6+
public class CollectionModelSerializer
7+
{
8+
public string Serialize(CollectionModel model)
9+
{
10+
return JsonSerializer.Serialize(model);
11+
}
12+
}
13+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System.IO;
2+
using Simplify.Web.Modules;
3+
using Simplify.Web.Postman.Models;
4+
5+
namespace Simplify.Web.Postman
6+
{
7+
public class FileCollectionExporter : ICollectionExporter
8+
{
9+
private const string GenerationFolderPath = "postman";
10+
private const string CollectionFileNamePostfix = ".postman_collection";
11+
12+
private readonly CollectionModelSerializer _serializer;
13+
private readonly IEnvironment _environment;
14+
private readonly string _projectAssemblyName;
15+
16+
public FileCollectionExporter(CollectionModelSerializer serializer, IEnvironment environment, string projectAssemblyName)
17+
{
18+
_serializer = serializer;
19+
_environment = environment;
20+
_projectAssemblyName = projectAssemblyName;
21+
}
22+
23+
public void Export(CollectionModel model)
24+
{
25+
var folderPath = GenerateExportFolderPath();
26+
27+
if (!Directory.Exists(folderPath))
28+
Directory.CreateDirectory(folderPath);
29+
30+
File.WriteAllText(GenerateCollectionFilePath(folderPath), _serializer.Serialize(model));
31+
}
32+
33+
public string GenerateExportFolderPath()
34+
{
35+
return Path.Combine(_environment.SitePhysicalPath, GenerationFolderPath);
36+
}
37+
38+
public string GenerateCollectionFilePath(string folderPath)
39+
{
40+
return Path.Combine(folderPath, _projectAssemblyName + CollectionFileNamePostfix + ".json");
41+
}
42+
}
43+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Simplify.Web.Postman.Models;
2+
3+
namespace Simplify.Web.Postman
4+
{
5+
public interface ICollectionExporter
6+
{
7+
void Export(CollectionModel model);
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Simplify.Web.Postman.Models;
2+
3+
namespace Simplify.Web.Postman
4+
{
5+
public interface ICollectionPartBuilder
6+
{
7+
void Build(CollectionModel model);
8+
}
9+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace Simplify.Web.Postman.Models
2+
{
3+
public class CollectionHeader
4+
{
5+
}
6+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Simplify.Web.Postman.Models
2+
{
3+
public class CollectionModel
4+
{
5+
public CollectionHeader Header { get; set; }
6+
}
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace Simplify.Web.Postman
2+
{
3+
public class PostmanGenerationSettings
4+
{
5+
}
6+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
3+
namespace Simplify.Web.Postman
4+
{
5+
public class PostmanGenerator
6+
{
7+
private readonly CollectionBuilder _builder;
8+
private readonly ICollectionExporter _exporter;
9+
10+
public PostmanGenerator(CollectionBuilder builder, ICollectionExporter exporter)
11+
{
12+
_builder = builder ?? throw new ArgumentNullException(nameof(builder));
13+
_exporter = exporter ?? throw new ArgumentNullException(nameof(exporter));
14+
}
15+
16+
public void GenerateCollection()
17+
{
18+
_exporter.Export(_builder.Create());
19+
}
20+
}
21+
}

src/Simplify.Web.Postman/Simplify.Web.Postman.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@
2020
</PropertyGroup>
2121
<ItemGroup>
2222
<PackageReference Include="Simplify.Web" Version="4.0.0" />
23+
<PackageReference Include="System.Json" Version="4.7.0" />
2324
</ItemGroup>
2425
</Project>

0 commit comments

Comments
 (0)