Skip to content

Commit

Permalink
Fixed all analysis errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Schulte committed May 10, 2016
1 parent 42cd603 commit 3eef4f2
Show file tree
Hide file tree
Showing 14 changed files with 334 additions and 755 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@ public class JSONSchemaTests
[Fact]
public void AddPropertyWithNullPropertyName()
{
JSONSchema jsonSchema = new JSONSchema();
JsonSchema jsonSchema = new JsonSchema();
Assert.Throws<ArgumentException>(() => { jsonSchema.AddProperty(null, null); });
}

[Fact]
public void AddPropertyWithEmptyPropertyName()
{
JSONSchema jsonSchema = new JSONSchema();
JsonSchema jsonSchema = new JsonSchema();
Assert.Throws<ArgumentException>(() => { jsonSchema.AddProperty("", null); });
}

[Fact]
public void AddPropertyWithWhitespacePropertyName()
{
JSONSchema jsonSchema = new JSONSchema();
JsonSchema jsonSchema = new JsonSchema();
Assert.Throws<ArgumentException>(() => { jsonSchema.AddProperty(" ", null); });
}

[Fact]
public void AddRequiredWithOneValueWhenPropertyDoesntExist()
{
JSONSchema jsonSchema = new JSONSchema();
JsonSchema jsonSchema = new JsonSchema();
Assert.Throws<ArgumentException>(() => { jsonSchema.AddRequired("a"); });
Assert.Null(jsonSchema.Properties);
Assert.Null(jsonSchema.Required);
Expand All @@ -43,18 +43,18 @@ public void AddRequiredWithOneValueWhenPropertyDoesntExist()
[Fact]
public void AddRequiredWithTwoValuesWhenSecondPropertyDoesntExist()
{
JSONSchema jsonSchema = new JSONSchema();
jsonSchema.AddProperty("a", new JSONSchema());
JsonSchema jsonSchema = new JsonSchema();
jsonSchema.AddProperty("a", new JsonSchema());
Assert.Throws<ArgumentException>(() => { jsonSchema.AddRequired("a", "b"); });
}

[Fact]
public void AddRequiredWithThreeValuesWhenAllPropertiesExist()
{
JSONSchema jsonSchema = new JSONSchema();
jsonSchema.AddProperty("a", new JSONSchema());
jsonSchema.AddProperty("b", new JSONSchema());
jsonSchema.AddProperty("c", new JSONSchema());
JsonSchema jsonSchema = new JsonSchema();
jsonSchema.AddProperty("a", new JsonSchema());
jsonSchema.AddProperty("b", new JsonSchema());
jsonSchema.AddProperty("c", new JsonSchema());

jsonSchema.AddRequired("a", "b", "c");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void ParseWithNullServiceClient()
public void ParseWithEmptyServiceClient()
{
ServiceClient serviceClient = new ServiceClient();
ResourceSchemaModel schema = ResourceSchemaParser.Parse(serviceClient);
ResourceSchema schema = ResourceSchemaParser.Parse(serviceClient);
Assert.NotNull(schema);
Assert.Null(schema.Id);
Assert.Equal("http://json-schema.org/draft-04/schema#", schema.Schema);
Expand Down Expand Up @@ -52,7 +52,7 @@ public void ParseWithServiceClientWithCreateResourceMethod()

serviceClient.Methods.Add(method);

ResourceSchemaModel schema = ResourceSchemaParser.Parse(serviceClient);
ResourceSchema schema = ResourceSchemaParser.Parse(serviceClient);
Assert.NotNull(schema);
Assert.Null(schema.Id);
Assert.Equal("http://json-schema.org/draft-04/schema#", schema.Schema);
Expand All @@ -61,23 +61,17 @@ public void ParseWithServiceClientWithCreateResourceMethod()
Assert.Equal(1, schema.ResourceDefinitions.Count);
Assert.Equal("mockResourceNames", schema.ResourceDefinitions.Keys.Single());
Assert.Equal(
new JSONSchema()
new JsonSchema()
{
JSONType = "object",
Properties = new Dictionary<string, JSONSchema>()
JsonType = "object",
Description = "Mock.Provider/mockResourceNames"
}
.AddProperty("type", new JsonSchema()
{
{
"type",
new JSONSchema()
{
JSONType = "string",
Enum = new string[] { "Mock.Provider/mockResourceNames" },
}
}
},
Required = new string[] { "type" },
Description = "Mock.Provider/mockResourceNames",
},
JsonType = "string"
}
.AddEnum("Mock.Provider/mockResourceNames"),
true),
schema.ResourceDefinitions["mockResourceNames"]);
Assert.Null(schema.Definitions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ResourceSchemaWriterTests
public void WriteWithNullJsonTextWriter()
{
JsonTextWriter writer = null;
ResourceSchemaModel resourceSchema = new ResourceSchemaModel();
ResourceSchema resourceSchema = new ResourceSchema();
Assert.Throws<ArgumentNullException>(() => { ResourceSchemaWriter.Write(writer, resourceSchema); });
}

Expand All @@ -24,7 +24,7 @@ public void WriteWithJsonTextWriterAndNullResourceSchema()
{
StringWriter stringWriter = new StringWriter();
JsonTextWriter writer = new JsonTextWriter(stringWriter);
ResourceSchemaModel resourceSchema = null;
ResourceSchema resourceSchema = null;
Assert.Throws<ArgumentNullException>(() => { ResourceSchemaWriter.Write(writer, resourceSchema); });
}

Expand All @@ -33,7 +33,7 @@ public void WriteWithEmptyResourceSchema()
{
StringWriter stringWriter = new StringWriter();
JsonTextWriter writer = new JsonTextWriter(stringWriter);
ResourceSchemaModel resourceSchema = new ResourceSchemaModel();
ResourceSchema resourceSchema = new ResourceSchema();
ResourceSchemaWriter.Write(writer, resourceSchema);
Assert.Equal("{}", stringWriter.ToString());
}
Expand All @@ -45,7 +45,7 @@ public void WriteWithId()
JsonTextWriter writer = new JsonTextWriter(stringWriter);
writer.QuoteChar = '\'';

ResourceSchemaModel resourceSchema = new ResourceSchemaModel();
ResourceSchema resourceSchema = new ResourceSchema();
resourceSchema.Id = "MockId";

ResourceSchemaWriter.Write(writer, resourceSchema);
Expand All @@ -59,7 +59,7 @@ public void WriteWithSchema()
JsonTextWriter writer = new JsonTextWriter(stringWriter);
writer.QuoteChar = '\'';

ResourceSchemaModel resourceSchema = new ResourceSchemaModel();
ResourceSchema resourceSchema = new ResourceSchema();
resourceSchema.Id = "MockId";
resourceSchema.Schema = "MockSchema";

Expand All @@ -74,7 +74,7 @@ public void WriteWithTitle()
JsonTextWriter writer = new JsonTextWriter(stringWriter);
writer.QuoteChar = '\'';

ResourceSchemaModel resourceSchema = new ResourceSchemaModel();
ResourceSchema resourceSchema = new ResourceSchema();
resourceSchema.Schema = "MockSchema";
resourceSchema.Title = "MockTitle";

Expand All @@ -89,7 +89,7 @@ public void WriteWithDescription()
JsonTextWriter writer = new JsonTextWriter(stringWriter);
writer.QuoteChar = '\'';

ResourceSchemaModel resourceSchema = new ResourceSchemaModel();
ResourceSchema resourceSchema = new ResourceSchema();
resourceSchema.Title = "MockTitle";
resourceSchema.Description = "MockDescription";

Expand All @@ -104,9 +104,9 @@ public void WriteWithOneResourceDefinition()
JsonTextWriter writer = new JsonTextWriter(stringWriter);
writer.QuoteChar = '\'';

ResourceSchemaModel resourceSchema = new ResourceSchemaModel();
ResourceSchema resourceSchema = new ResourceSchema();
resourceSchema.Description = "MockDescription";
resourceSchema.AddResourceDefinition("mockResource", new JSONSchema());
resourceSchema.AddResourceDefinition("mockResource", new JsonSchema());

ResourceSchemaWriter.Write(writer, resourceSchema);
Assert.Equal("{'description':'MockDescription','resourceDefinitions':{'mockResource':{}}}", stringWriter.ToString());
Expand All @@ -119,9 +119,9 @@ public void WriteWithOneDefinition()
JsonTextWriter writer = new JsonTextWriter(stringWriter);
writer.QuoteChar = '\'';

ResourceSchemaModel resourceSchema = new ResourceSchemaModel();
resourceSchema.AddResourceDefinition("mockResource", new JSONSchema());
resourceSchema.AddDefinition("mockDefinition", new JSONSchema());
ResourceSchema resourceSchema = new ResourceSchema();
resourceSchema.AddResourceDefinition("mockResource", new JsonSchema());
resourceSchema.AddDefinition("mockDefinition", new JsonSchema());

ResourceSchemaWriter.Write(writer, resourceSchema);
Assert.Equal("{'resourceDefinitions':{'mockResource':{}},'definitions':{'mockDefinition':{}}}", stringWriter.ToString());
Expand All @@ -138,7 +138,7 @@ public void WriteDefinitionWithEmptyDefinition()
writer.QuoteChar = '\'';

const string definitionName = "mockDefinition";
JSONSchema definition = new JSONSchema();
JsonSchema definition = new JsonSchema();

ResourceSchemaWriter.WriteDefinition(writer, definitionName, definition);
Assert.Equal("'mockDefinition':{}", stringWriter.ToString());
Expand All @@ -152,8 +152,8 @@ public void WriteDefinitionWithType()
writer.QuoteChar = '\'';

const string definitionName = "mockDefinition";
JSONSchema definition = new JSONSchema();
definition.JSONType = "MockType";
JsonSchema definition = new JsonSchema();
definition.JsonType = "MockType";

ResourceSchemaWriter.WriteDefinition(writer, definitionName, definition);
Assert.Equal("'mockDefinition':{'type':'MockType'}", stringWriter.ToString());
Expand All @@ -167,9 +167,11 @@ public void WriteDefinitionWithTypeAndEnum()
writer.QuoteChar = '\'';

const string definitionName = "mockDefinition";
JSONSchema definition = new JSONSchema();
definition.JSONType = "MockType";
definition.Enum = new string[] { "MockEnum1", "MockEnum2" };
JsonSchema definition = new JsonSchema()
{
JsonType = "MockType"
}
.AddEnum("MockEnum1", "MockEnum2");

ResourceSchemaWriter.WriteDefinition(writer, definitionName, definition);
Assert.Equal("'mockDefinition':{'type':'MockType','enum':['MockEnum1','MockEnum2']}", stringWriter.ToString());
Expand All @@ -183,9 +185,9 @@ public void WriteDefinitionWithEnumAndUnrequiredProperty()
writer.QuoteChar = '\'';

const string definitionName = "mockDefinition";
JSONSchema definition = new JSONSchema();
definition.Enum = new string[] { "MockEnum1", "MockEnum2" };
definition.AddProperty("mockPropertyName", new JSONSchema());
JsonSchema definition = new JsonSchema()
.AddEnum("MockEnum1", "MockEnum2")
.AddProperty("mockPropertyName", new JsonSchema());

ResourceSchemaWriter.WriteDefinition(writer, definitionName, definition);
Assert.Equal("'mockDefinition':{'enum':['MockEnum1','MockEnum2'],'properties':{'mockPropertyName':{}}}", stringWriter.ToString());
Expand All @@ -199,9 +201,9 @@ public void WriteDefinitionWithEnumAndRequiredProperty()
writer.QuoteChar = '\'';

const string definitionName = "mockDefinition";
JSONSchema definition = new JSONSchema();
definition.Enum = new string[] { "MockEnum1", "MockEnum2" };
definition.AddProperty("mockPropertyName", new JSONSchema(), true);
JsonSchema definition = new JsonSchema()
.AddEnum("MockEnum1", "MockEnum2")
.AddProperty("mockPropertyName", new JsonSchema(), true);

ResourceSchemaWriter.WriteDefinition(writer, definitionName, definition);
Assert.Equal("'mockDefinition':{'enum':['MockEnum1','MockEnum2'],'properties':{'mockPropertyName':{}},'required':['mockPropertyName']}", stringWriter.ToString());
Expand All @@ -215,8 +217,8 @@ public void WriteDefinitionWithRequiredPropertyAndDescription()
writer.QuoteChar = '\'';

const string definitionName = "mockDefinition";
JSONSchema definition = new JSONSchema();
definition.AddProperty("mockPropertyName", new JSONSchema(), true);
JsonSchema definition = new JsonSchema();
definition.AddProperty("mockPropertyName", new JsonSchema(), true);
definition.Description = "MockDescription";

ResourceSchemaWriter.WriteDefinition(writer, definitionName, definition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,10 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="JSONSchema.cs" />
<Compile Include="ResourceSchemaModel.cs" />
<Compile Include="JsonSchema.cs" />
<Compile Include="ResourceSchema.cs" />
<Compile Include="ResourceSchemaParser.cs" />
<Compile Include="ResourceSchemaWriter.cs" />
<Compile Include="SchemaProperty.cs" />
<Compile Include="Definition.cs" />
<Compile Include="ResourceProperty.cs" />
<Compile Include="ResourceSchema.cs" />
<Compile Include="AzureResourceSchemaCodeGenerator.cs" />
<Compile Include="$(SolutionDir)\Tools\AssemblyVersionInfo.cs">
<Link>Properties\AssemblyVersionInfo.cs</Link>
Expand Down Expand Up @@ -89,7 +85,6 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Resource.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public override void NormalizeClientModel(ServiceClient serviceClient)

public override async Task Generate(ServiceClient serviceClient)
{
ResourceSchemaModel resourceSchema = ResourceSchemaParser.Parse(serviceClient);
ResourceSchema resourceSchema = ResourceSchemaParser.Parse(serviceClient);

StringWriter stringWriter = new StringWriter();
ResourceSchemaWriter.Write(stringWriter, resourceSchema);
Expand Down

This file was deleted.

Loading

0 comments on commit 3eef4f2

Please sign in to comment.