Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit cb5f7a0

Browse files
committed
common file classes unit tests
1 parent 956b2a7 commit cb5f7a0

File tree

4 files changed

+57
-3
lines changed

4 files changed

+57
-3
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using Xunit;
2+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common;
3+
using System;
4+
using System.IO;
5+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Create;
6+
7+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Test
8+
{
9+
public class FileReaderTests
10+
{
11+
[Fact]
12+
public async void ShouldConvertYAMLConfigToCreatorConfiguration()
13+
{
14+
// arrange
15+
FileReader fileReader = new FileReader();
16+
string fileLocation = String.Concat("..", Path.DirectorySeparatorChar,
17+
"..", Path.DirectorySeparatorChar,
18+
"..", Path.DirectorySeparatorChar,
19+
"..", Path.DirectorySeparatorChar,
20+
"apimtemplate", Path.DirectorySeparatorChar,
21+
"Creator", Path.DirectorySeparatorChar,
22+
"ExampleFiles", Path.DirectorySeparatorChar,
23+
"YAMLConfigs", Path.DirectorySeparatorChar, "valid.yml");
24+
25+
// act
26+
CreatorConfig creatorConfig = await fileReader.ConvertConfigYAMLToCreatorConfigAsync(fileLocation);
27+
28+
// assert
29+
Assert.Equal("0.0.1", creatorConfig.version);
30+
Assert.Equal("myAPIMService", creatorConfig.apimServiceName);
31+
Assert.Equal(@"C:\Users\myUsername\GeneratedTemplates", creatorConfig.outputLocation);
32+
Assert.Equal("myAPI", creatorConfig.apis[0].name);
33+
}
34+
35+
[Fact]
36+
public async void ShouldRetrieveFileContentsWithoutError()
37+
{
38+
// arrange
39+
FileReader fileReader = new FileReader();
40+
string fileLocation = "https://petstore.swagger.io/v2/swagger.json";
41+
42+
// act
43+
try
44+
{
45+
var content = await fileReader.RetrieveFileContentsAsync(fileLocation);
46+
// assert
47+
Assert.True(true);
48+
}
49+
catch (Exception ex)
50+
{
51+
// assert
52+
Assert.NotNull(ex);
53+
}
54+
}
55+
}
56+
}

src/APIM_ARMTemplate/apimtemplate/Common/FileHandlers/FileNameGenerator.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using Newtonsoft.Json;
2-
using System.IO;
3-
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Create;
1+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Create;
42

53
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common
64
{

0 commit comments

Comments
 (0)