Skip to content

Commit 9cbe26c

Browse files
committed
XML comments added
Custom settings control
1 parent db867c0 commit 9cbe26c

11 files changed

+167
-14
lines changed

src/Simplify.Web.Postman/CollectionBuilder.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,27 @@
44

55
namespace Simplify.Web.Postman
66
{
7+
/// <summary>
8+
/// Provides postman collection model builder
9+
/// </summary>
710
public class CollectionBuilder
811
{
912
private readonly IList<ICollectionPartBuilder> _partBuilders;
1013

14+
/// <summary>
15+
/// Initializes a new instance of the <see cref="CollectionBuilder"/> class.
16+
/// </summary>
17+
/// <param name="partBuilders">The part builders.</param>
18+
/// <exception cref="ArgumentNullException">partBuilders</exception>
1119
public CollectionBuilder(IList<ICollectionPartBuilder> partBuilders)
1220
{
1321
_partBuilders = partBuilders ?? throw new ArgumentNullException(nameof(partBuilders));
1422
}
1523

24+
/// <summary>
25+
/// Builds the collection model.
26+
/// </summary>
27+
/// <returns></returns>
1628
public CollectionModel Create()
1729
{
1830
var model = new CollectionModel();

src/Simplify.Web.Postman/CollectionModelSerializer.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@
33

44
namespace Simplify.Web.Postman
55
{
6+
/// <summary>
7+
/// Provides postman collection model serializer
8+
/// </summary>
69
public class CollectionModelSerializer
710
{
11+
/// <summary>
12+
/// Serializes the specified model.
13+
/// </summary>
14+
/// <param name="model">The model.</param>
15+
/// <returns></returns>
816
public string Serialize(CollectionModel model)
917
{
1018
return JsonSerializer.Serialize(model);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
namespace Simplify.Web.Postman
2+
{
3+
/// <summary>
4+
/// Provides default PostmanGenerationSettings factory
5+
/// </summary>
6+
public static class DefaultPostmanGenerationSettingsFactory
7+
{
8+
/// <summary>
9+
/// Creates the new or updates the existing settings.
10+
/// </summary>
11+
/// <param name="settings">The settings.</param>
12+
/// <param name="projectAssemblyName">Name of the project assembly.</param>
13+
/// <returns></returns>
14+
public static PostmanGenerationSettings CreateOrUpdateSettings(PostmanGenerationSettings? settings, string projectAssemblyName)
15+
{
16+
if (settings == null)
17+
settings = new PostmanGenerationSettings();
18+
19+
if (settings.CollectionFileName == null)
20+
settings.CollectionFileName = projectAssemblyName;
21+
22+
if (settings.EnvironmentFileName == null)
23+
settings.EnvironmentFileName = projectAssemblyName;
24+
25+
return settings;
26+
}
27+
}
28+
}

src/Simplify.Web.Postman/FileCollectionExporter.cs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,33 @@
44

55
namespace Simplify.Web.Postman
66
{
7+
/// <summary>
8+
/// Provides postman collection to file exporter
9+
/// </summary>
10+
/// <seealso cref="ICollectionExporter" />
711
public class FileCollectionExporter : ICollectionExporter
812
{
9-
private const string GenerationFolderPath = "postman";
10-
private const string CollectionFileNamePostfix = ".postman_collection";
11-
1213
private readonly CollectionModelSerializer _serializer;
1314
private readonly IEnvironment _environment;
14-
private readonly string _projectAssemblyName;
15-
16-
public FileCollectionExporter(CollectionModelSerializer serializer, IEnvironment environment, string projectAssemblyName)
15+
private readonly PostmanGenerationSettings _settings;
16+
17+
/// <summary>
18+
/// Initializes a new instance of the <see cref="FileCollectionExporter"/> class.
19+
/// </summary>
20+
/// <param name="serializer">The serializer.</param>
21+
/// <param name="environment">The environment.</param>
22+
/// <param name="settings">The settings.</param>
23+
public FileCollectionExporter(CollectionModelSerializer serializer, IEnvironment environment, PostmanGenerationSettings settings)
1724
{
1825
_serializer = serializer;
1926
_environment = environment;
20-
_projectAssemblyName = projectAssemblyName;
27+
_settings = settings;
2128
}
2229

30+
/// <summary>
31+
/// Exports the specified model.
32+
/// </summary>
33+
/// <param name="model">The model.</param>
2334
public void Export(CollectionModel model)
2435
{
2536
var folderPath = GenerateExportFolderPath();
@@ -30,14 +41,14 @@ public void Export(CollectionModel model)
3041
File.WriteAllText(GenerateCollectionFilePath(folderPath), _serializer.Serialize(model));
3142
}
3243

33-
public string GenerateExportFolderPath()
44+
private string GenerateExportFolderPath()
3445
{
35-
return Path.Combine(_environment.SitePhysicalPath, GenerationFolderPath);
46+
return Path.Combine(_environment.SitePhysicalPath, _settings.GenerationFolderPath);
3647
}
3748

38-
public string GenerateCollectionFilePath(string folderPath)
49+
private string GenerateCollectionFilePath(string folderPath)
3950
{
40-
return Path.Combine(folderPath, _projectAssemblyName + CollectionFileNamePostfix + ".json");
51+
return Path.Combine(folderPath, _settings.CollectionFileName + _settings.CollectionFileNamePostfix + ".json");
4152
}
4253
}
4354
}

src/Simplify.Web.Postman/ICollectionExporter.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@
22

33
namespace Simplify.Web.Postman
44
{
5+
/// <summary>
6+
/// Represents postman collection exporter
7+
/// </summary>
58
public interface ICollectionExporter
69
{
10+
/// <summary>
11+
/// Exports the specified model.
12+
/// </summary>
13+
/// <param name="model">The model.</param>
714
void Export(CollectionModel model);
815
}
916
}

src/Simplify.Web.Postman/ICollectionPartBuilder.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@
22

33
namespace Simplify.Web.Postman
44
{
5+
/// <summary>
6+
/// Provides postman collection part builder
7+
/// </summary>
58
public interface ICollectionPartBuilder
69
{
10+
/// <summary>
11+
/// Builds the specified model part.
12+
/// </summary>
13+
/// <param name="model">The model.</param>
714
void Build(CollectionModel model);
815
}
916
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
namespace Simplify.Web.Postman.Models
22
{
3+
/// <summary>
4+
/// Provides postman collection header
5+
/// </summary>
36
public class CollectionHeader
47
{
58
}
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
namespace Simplify.Web.Postman.Models
22
{
3+
/// <summary>
4+
/// Provides postman collection model
5+
/// </summary>
36
public class CollectionModel
47
{
5-
public CollectionHeader Header { get; set; }
8+
/// <summary>
9+
/// Gets or sets the header.
10+
/// </summary>
11+
/// <value>
12+
/// The header.
13+
/// </value>
14+
public CollectionHeader? Header { get; set; }
615
}
716
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,58 @@
11
namespace Simplify.Web.Postman
22
{
3+
/// <summary>
4+
/// Provides postman files generation settings
5+
/// </summary>
36
public class PostmanGenerationSettings
47
{
8+
/// <summary>
9+
/// Initializes a new instance of the <see cref="PostmanGenerationSettings"/> class.
10+
/// </summary>
11+
public PostmanGenerationSettings()
12+
{
13+
GenerationFolderPath = "postman";
14+
CollectionFileNamePostfix = ".postman_collection";
15+
EnvironmentFileNamePostfix = ".postman_environment";
16+
}
17+
18+
/// <summary>
19+
/// Gets or sets the name of the collection file.
20+
/// </summary>
21+
/// <value>
22+
/// The name of the collection file.
23+
/// </value>
24+
public string? CollectionFileName { get; set; }
25+
26+
/// <summary>
27+
/// Gets or sets the collection file name postfix.
28+
/// </summary>
29+
/// <value>
30+
/// The collection file name postfix.
31+
/// </value>
32+
public string CollectionFileNamePostfix { get; set; }
33+
34+
/// <summary>
35+
/// Gets or sets the name of the environment file.
36+
/// </summary>
37+
/// <value>
38+
/// The name of the environment file.
39+
/// </value>
40+
public string? EnvironmentFileName { get; set; }
41+
42+
/// <summary>
43+
/// Gets or sets the environment file name postfix.
44+
/// </summary>
45+
/// <value>
46+
/// The environment file name postfix.
47+
/// </value>
48+
public string EnvironmentFileNamePostfix { get; set; }
49+
50+
/// <summary>
51+
/// Gets or sets the generation folder path.
52+
/// </summary>
53+
/// <value>
54+
/// The generation folder path.
55+
/// </value>
56+
public string GenerationFolderPath { get; set; }
557
}
658
}

src/Simplify.Web.Postman/PostmanGenerator.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,33 @@
22

33
namespace Simplify.Web.Postman
44
{
5+
/// <summary>
6+
/// Provides postman data generation root
7+
/// </summary>
58
public class PostmanGenerator
69
{
710
private readonly CollectionBuilder _builder;
811
private readonly ICollectionExporter _exporter;
912

13+
/// <summary>
14+
/// Initializes a new instance of the <see cref="PostmanGenerator"/> class.
15+
/// </summary>
16+
/// <param name="builder">The builder.</param>
17+
/// <param name="exporter">The exporter.</param>
18+
/// <exception cref="ArgumentNullException">
19+
/// builder
20+
/// or
21+
/// exporter
22+
/// </exception>
1023
public PostmanGenerator(CollectionBuilder builder, ICollectionExporter exporter)
1124
{
1225
_builder = builder ?? throw new ArgumentNullException(nameof(builder));
1326
_exporter = exporter ?? throw new ArgumentNullException(nameof(exporter));
1427
}
1528

29+
/// <summary>
30+
/// Generates the postman collection.
31+
/// </summary>
1632
public void GenerateCollection()
1733
{
1834
_exporter.Export(_builder.Create());

0 commit comments

Comments
 (0)