Skip to content

Commit

Permalink
Merge with upstream master
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali-BenZarrouk-MB committed Aug 26, 2019
2 parents 7b2f93d + 69848b7 commit 5eba620
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ sudo: required
dist: xenial
dotnet: 2.2
env:
matrix:
- VERSION=1.6.1
global:
secure: dW4i1leTDXh38v7756n1XCC/l9FokZDmOlwjSdYD89BcgGsJzHh/g/K/9IISUhNw9ZXqs2GRGsHGUd4BnZ/dkju+9eyR9VvYBB6h9UfFxKk3+lLbIiWnIUpKzlqrmErpyoEr7tGtqk1JR4+rgRy/CP7giS9uCV2SlX+kntGz60bkrX2308n5PMidCjg9o6DeLnmpDO8+joAUBi2+v3/648+6pk9OIiFJqrYjj90fH+YlF+3vPYugS6arbSiRQ5lfn8lHWqfIuCzikHcjA3/MVeVqrXuYINtWz0xF03/n107Wrl00FtrRnXcp2ssixXZ1u6is9zJFvRewoKjxTSN3VjQIev9h+HTSBoua5KQdcbZ6Of2+f8SiC6lXvAz436OxOqyO7z11urHLBk/ZL+1iX5Qkh+9Aq+ZhdHsbufnZMzfgzx3MLRhrsgK0aJk+gnAOSqci7a/bZlkuGUlru4cN0jR/aP2+tIAM+beRwo0e0eTEHxy4wnKDs00sJnY0nOpq/K7zRqRuq/3DXkGq9+/8TzyiCp9mJ+z4lXzZfJWybmcaTnXKJqzcN1GmVV1UaGfEz0SZWRiJ28XTLyZkxpXRUN+n+zYJNGlonzFub92y0Q0v4td2NVuzIi2WNcC1G1MJJUr3DZ16/0D5QU6589O6JoVjhD31Diw7oK0ig+YedgY=
stages:
- name: test
- name: deploy
Expand Down
8 changes: 4 additions & 4 deletions MessageBird/MessageBird.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<Title>MessageBird</Title>
<Company>MessageBird</Company>
<Copyright>Copyright © 2014</Copyright>
<FileVersion>1.6.0.0</FileVersion>
<InformationalVersion>1.6.0.0</InformationalVersion>
<Version>1.6.0.0</Version>
<AssemblyVersion>1.6.0.0</AssemblyVersion>
<FileVersion>1.6.1.0</FileVersion>
<InformationalVersion>1.6.1.0</InformationalVersion>
<Version>1.6.1.0</Version>
<AssemblyVersion>1.6.1.0</AssemblyVersion>
<LangVersion>4</LangVersion>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion MessageBird/MessageBird.csproj.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<metadata>
<id>MessageBird</id>
<title>MessageBird's REST API for C#</title>
<version>1.6.0.0</version>
<version>1.6.1.0</version>
<authors>MessageBird,Remco Vermeulen</authors>
<owners>MessageBird</owners>
<licenseUrl>https://github.com/messagebird/csharp-rest-api/blob/master/LICENSE</licenseUrl>
Expand Down
2 changes: 1 addition & 1 deletion MessageBird/Net/RestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class RestClient : IRestClient

public string ClientVersion
{
get { return "1.6.0.0"; }
get { return "1.6.1.0"; }
}

public string ApiVersion
Expand Down
2 changes: 1 addition & 1 deletion MessageBird/Objects/Verify.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public string Originator
[JsonProperty("datacoding"), DefaultValue(DataEncoding.Plain), JsonConverter(typeof(StringEnumConverter))]
public DataEncoding Encoding { get; set; }

[JsonProperty("tokenLenght"), DefaultValue(6)]
[JsonProperty("tokenLength"), DefaultValue(6)]
public int TokenLength { get; set; }

[JsonProperty("type"), DefaultValue(MessageType.Sms), JsonConverter(typeof(StringEnumConverter))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
<PackageReference Include="Moq" Version="4.10.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
<PackageReference Include="Moq" Version="4.12.0" />
<PackageReference Include="WireMock.Net" Version="1.0.21" />
</ItemGroup>
<ItemGroup>
<Content Include="Responses\**">
Expand Down
118 changes: 118 additions & 0 deletions Tests/UnitTests/MessageBirdUnitTests/Resources/ClientVerifyTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
using MessageBird.Net;
using MessageBird.Objects;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WireMock.Server;

namespace MessageBirdTests.Resources
{
/**
* Using this class to be able to change the base url of the request.
*/
internal class VerifyWithUrl : MessageBird.Resources.Resource
{
public VerifyWithUrl(Verify verify)
: base("verify", verify)
{
}

private string VerifyBaseUrl;

private string Token
{
get
{
return (Object != null) ? ((Verify)Object).Token : null;
}
}

public override string QueryString
{
get
{
return string.IsNullOrEmpty(Token) ? string.Empty : "token=" + System.Uri.EscapeDataString(Token);
}
}

public void SetBaseUrl(string baseUrl)
{
VerifyBaseUrl = baseUrl;
}

public override string BaseUrl => VerifyBaseUrl;
}

[TestClass]
public class RestClientVerifyTest
{
private const string ENDPOINT = "http://localhost:";
private const string ACCESS_KEY = "SOME_ACCESS_KEY";
private const long RECIPIENT = 31612345678;
private const string TEMPLATE = "test template";
private const string ORIGINATOR = "test ori";
private const DataEncoding DATA_ENCODING = DataEncoding.Auto;
private const string REFERENCE = "testref";
private const int TIMEOUT = 1234;
private const int TOKEN_LENGTH = 15;
private const Voice VOICE = Voice.Female;
private const Language LANGUAGE = Language.BrazilianPortugese;

private const string CREATE_VERIFY_RESPONSE = @"{""id"": ""2cec4f419b7a4cf7b546a41c630a20b0"",""href"": ""some_ur"",""recipient"": 31627343907,""reference"": null,""messages"": {""href"": ""some_url""},""status"": ""sent"",""createdDatetime"": ""2019-07-04T08:23:37+00:00"",""validUntilDatetime"": ""2019-07-04T08:24:07+00:00""}";
private const string EXPECTED_REQUEST = @"{""recipient"":31612345678,""reference"":""testref"",""originator"":""test ori"",""template"":""test template"",""datacoding"":""auto"",""tokenLength"":15,""type"":""tts"",""timeout"":1234,""voice"":""female"",""language"":""pt-br""}";

[TestMethod]
public void CreateVerifyTest()
{
// arrange
var server = FluentMockServer.Start();
int port = server.Ports[0];


var restClient = new RestClient(ENDPOINT + port, ACCESS_KEY, null);

var verifyOptionalArguments = new VerifyOptionalArguments()
{
Template = TEMPLATE,
Encoding = DATA_ENCODING,
Originator = ORIGINATOR,
Reference = REFERENCE,
Type = MessageType.Tts,
Timeout = TIMEOUT,
TokenLength = TOKEN_LENGTH,
Voice = VOICE,
Language = LANGUAGE
};

server
.Given(
WireMock.RequestBuilders.Request.Create().WithPath("/verify").UsingPost()
)
.RespondWith(
WireMock.ResponseBuilders.Response.Create()
.WithStatusCode(201)
.WithHeader("Content-Type", "application/json")
.WithBody(CREATE_VERIFY_RESPONSE)
);

// act
var verify = new Verify(RECIPIENT, verifyOptionalArguments);
var verifyResource = new VerifyWithUrl(verify);
verifyResource.SetBaseUrl(ENDPOINT + port);

restClient.Create(verifyResource);

// assert
var allRequests = server.LogEntries;
var allRequestsEnumerator = allRequests.GetEnumerator();
allRequestsEnumerator.MoveNext();
var logEntry = allRequestsEnumerator.Current;

Assert.IsNotNull(logEntry);
Assert.AreEqual(EXPECTED_REQUEST, logEntry.RequestMessage.Body);
allRequestsEnumerator.MoveNext();
Assert.IsNull(allRequestsEnumerator.Current);

server.Dispose();
allRequestsEnumerator.Dispose();
}
}
}

0 comments on commit 5eba620

Please sign in to comment.