-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add some tests of Swagger.ObjectModel #128
Changes from 4 commits
264d2a2
3e8eb52
1db5810
ae38a29
c765427
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using Swagger.ObjectModel.Builders; | ||
using Xunit; | ||
|
||
namespace Swagger.ObjectModel.Tests.Builders | ||
{ | ||
public class BodyParameterBuilderTest | ||
{ | ||
private readonly BodyParameterBuilder builder; | ||
private readonly string name; | ||
private readonly Schema schema; | ||
public BodyParameterBuilderTest() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing a line break here |
||
{ | ||
this.builder = new BodyParameterBuilder(); | ||
|
||
this.name = "name"; | ||
this.schema = new Schema | ||
{ | ||
Description = "some description" | ||
}; | ||
} | ||
|
||
[Fact] | ||
public void Should_ThrowRequiredFieldException_WhenNameOrSchemaIsNull() | ||
{ | ||
// Assert | ||
Assert.Throws(typeof(RequiredFieldException), () => builder.Build()); | ||
Assert.Throws(typeof(RequiredFieldException), () => builder.Name(name).Build()); | ||
Assert.Throws(typeof(RequiredFieldException), () => builder.Name(string.Empty).Schema(schema).Build()); | ||
} | ||
|
||
[Fact] | ||
public void Should_AbleToSetNameAndSchema() | ||
{ | ||
// Arrange | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary comments |
||
// Act | ||
var bodyParameter = builder.Name(name) | ||
.Schema(schema) | ||
.Build(); | ||
|
||
// Assert | ||
Assert.NotNull(bodyParameter); | ||
Assert.Equal(name, bodyParameter.Name); | ||
Assert.Same(schema, bodyParameter.Schema); | ||
} | ||
|
||
[Fact] | ||
public void Should_AbleToSetDescription() | ||
{ | ||
// Arrange | ||
string description = "description"; | ||
|
||
// Act | ||
var bodyParameter = builder.Name(name) | ||
.Schema(schema) | ||
.Description(description) | ||
.Build(); | ||
|
||
// Assert | ||
Assert.NotNull(bodyParameter); | ||
Assert.Equal(description, bodyParameter.Description); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using Swagger.ObjectModel.Builders; | ||
using Xunit; | ||
|
||
namespace Swagger.ObjectModel.Tests.Builders | ||
{ | ||
public class ContactBuilderTest | ||
{ | ||
private readonly ContactBuilder builder; | ||
public ContactBuilderTest() | ||
{ | ||
this.builder = new ContactBuilder(); | ||
} | ||
|
||
[Fact] | ||
public void Should_AbleToSetName() | ||
{ | ||
// Arrange | ||
string name = "name"; | ||
|
||
// Act | ||
var contact = builder.Name(name).Build(); | ||
|
||
// Assert | ||
Assert.NotNull(contact); | ||
Assert.Equal(name, contact.Name); | ||
} | ||
|
||
[Fact] | ||
public void Should_AbleToSetEmailAddress() | ||
{ | ||
// Arrange | ||
string email = "[email protected]"; | ||
|
||
// Act | ||
var contact = builder.EmailAddress(email).Build(); | ||
|
||
// Assert | ||
Assert.NotNull(contact); | ||
Assert.Equal(email, contact.EmailAddress); | ||
} | ||
|
||
[Fact] | ||
public void Should_AbleToSetUrl() | ||
{ | ||
// Arrange | ||
string url = "https://github.com/yahehe/Nancy.Swagger"; | ||
|
||
// Act | ||
var contact = builder.Url(url).Build(); | ||
|
||
// Assert | ||
Assert.NotNull(contact); | ||
Assert.Equal(url, contact.Url); | ||
} | ||
|
||
[Fact] | ||
public void Should_AbleToSetAllProperties() | ||
{ | ||
// Arrange | ||
string name = "name"; | ||
string email = "[email protected]"; | ||
string url = "https://github.com/yahehe/Nancy.Swagger"; | ||
|
||
// Act | ||
var contact = builder.Name(name) | ||
.EmailAddress(email) | ||
.Url(url) | ||
.Build(); | ||
|
||
// Assert | ||
Assert.NotNull(contact); | ||
Assert.Equal(name, contact.Name); | ||
Assert.Equal(email, contact.EmailAddress); | ||
Assert.Equal(url, contact.Url); | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using Swagger.ObjectModel.Builders; | ||
using Xunit; | ||
|
||
namespace Swagger.ObjectModel.Tests.Builders | ||
{ | ||
public class ExternalDocumentationBuilderTest | ||
{ | ||
private readonly ExternalDocumentationBuilder builder; | ||
private readonly string url = string.Empty; | ||
public ExternalDocumentationBuilderTest() | ||
{ | ||
this.builder = new ExternalDocumentationBuilder(); | ||
this.url = "https://github.com/yahehe/Nancy.Swagger"; | ||
} | ||
|
||
[Fact] | ||
public void Should_ThrowRequiredFieldException_WhenUrlIsNullOrEmpty() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, the tests are not all following the same format. But could you follow one of the current ones? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh really? I'm actually usually a fan of using _ to separate sentences like that: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just feel like the keywords are helpful enough. I'm fine either way though - I mostly brought it up because there was the precedent not to use them. Maybe rename the existing functions then? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find some Open Source projectss use this style for their tests , such as NancyFx . I use _ to separate for both of my own projects as well , so what I did is just follow this style . |
||
{ | ||
// Assert | ||
Assert.Throws(typeof(RequiredFieldException), () => builder.Url("").Build()); | ||
Assert.Throws(typeof(RequiredFieldException), () => builder.Url(null).Build()); | ||
} | ||
|
||
[Fact] | ||
public void Should_ThrowRequiredFieldException_WhenUrlIsNotSet() | ||
{ | ||
// Assert | ||
Assert.Throws(typeof(RequiredFieldException), () => builder.Build()); | ||
Assert.Throws(typeof(RequiredFieldException), () => builder.Description("desc").Build()); | ||
} | ||
|
||
[Fact] | ||
public void Should_AbleToSetUrl() | ||
{ | ||
// Arrange | ||
// Act | ||
var externalDocumentation = builder.Url(url).Build(); | ||
|
||
// Assert | ||
Assert.NotNull(externalDocumentation); | ||
Assert.Equal(url, externalDocumentation.Url); | ||
} | ||
|
||
[Fact] | ||
public void Should_AbleToSetDescription() | ||
{ | ||
// Arrange | ||
string description = "description"; | ||
|
||
// Act | ||
var externalDocumentation = builder.Url(url) | ||
.Description(description) | ||
.Build(); | ||
|
||
// Assert | ||
Assert.NotNull(externalDocumentation); | ||
Assert.Equal(url, externalDocumentation.Url); | ||
Assert.Equal(description, externalDocumentation.Description); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using Swagger.ObjectModel.Builders; | ||
using Xunit; | ||
|
||
namespace Swagger.ObjectModel.Tests.Builders | ||
{ | ||
public class HeaderBuilderTest | ||
{ | ||
private readonly HeaderBuilder builder; | ||
public HeaderBuilderTest() | ||
{ | ||
this.builder = new HeaderBuilder(); | ||
} | ||
|
||
[Fact] | ||
public void Should_ReturnEmptyHeader_WhenSetNothing() | ||
{ | ||
// Arrange | ||
// Act | ||
var header = builder.Build(); | ||
|
||
// Assert | ||
Assert.NotNull(header); | ||
Assert.Null(header.Description); | ||
Assert.Null(header.Default); | ||
} | ||
|
||
[Fact] | ||
public void Should_AbleToSetDescription() | ||
{ | ||
// Arrange | ||
string description = "description"; | ||
|
||
// Act | ||
var header = builder.Description(description).Build(); | ||
|
||
// Assert | ||
Assert.NotNull(header); | ||
Assert.Equal(description,header.Description); | ||
} | ||
|
||
[Fact] | ||
public void Should_AbleToSetDefaultOfDataType() | ||
{ | ||
// Arrange | ||
object defaultValue = new object(); | ||
|
||
// Act | ||
var header = builder.Default(defaultValue).Build(); | ||
|
||
// Assert | ||
Assert.NotNull(header); | ||
Assert.Equal(defaultValue, header.Default); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using Should; | ||
using Xunit; | ||
|
||
namespace Swagger.ObjectModel.Tests | ||
{ | ||
public class UtilitiesTest | ||
{ | ||
[Fact] | ||
public void ToCamelCase_EmptyOrNull_ShouldReturnItself() | ||
{ | ||
// Arrange | ||
string emptyString = string.Empty; | ||
string nullString = null; | ||
string whiteSpaceString = ""; | ||
|
||
// Act | ||
var actual_empty = Utilities.ToCamelCase(emptyString); | ||
var actual_null = Utilities.ToCamelCase(nullString); | ||
var actual_whitespace = Utilities.ToCamelCase(whiteSpaceString); | ||
|
||
// Assert | ||
actual_empty.ShouldEqual(emptyString); | ||
actual_null.ShouldEqual(actual_null); | ||
actual_whitespace.ShouldEqual(whiteSpaceString); | ||
} | ||
|
||
[Fact] | ||
public void ToCamelCase_StartWithDigit_ShouldReturnStartWith_() | ||
{ | ||
// Arrange | ||
string val = "123"; | ||
|
||
// Act | ||
var actual = Utilities.ToCamelCase(val); | ||
|
||
// Assert | ||
actual.ShouldEqual("_123"); | ||
} | ||
|
||
[Fact] | ||
public void ToCamelCase_StartWithUpperLetter_ShouldReturnStartWithLowerLetter() | ||
{ | ||
// Arrange | ||
string val = "Abc"; | ||
|
||
// Act | ||
var actual = Utilities.ToCamelCase(val); | ||
|
||
// Assert | ||
actual.ShouldEqual("abc"); | ||
} | ||
|
||
[Fact] | ||
public void ToCamelCase__ShouldReturnCamelString() | ||
{ | ||
// Arrange | ||
string val = "AbC123dEf"; | ||
|
||
// Act | ||
var actual = Utilities.ToCamelCase(val); | ||
|
||
// Assert | ||
actual.ShouldEqual("abC123DEf"); | ||
} | ||
|
||
|
||
[Fact] | ||
public void ToCamelCase_WithSpecialSymbol__ShouldReturnCamelString() | ||
{ | ||
// Arrange | ||
string val = string.Format("{0}/{1}","get", "values"); | ||
|
||
// Act | ||
var actual = Utilities.ToCamelCase(val); | ||
|
||
// Assert | ||
actual.ShouldEqual("getValues"); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a fan of redundant comments usually
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All right , this comment needs to be remove !