-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split Messages tests under separate categories (#363)
* Clean code smells in MessagesTests * Split MessagesTests into several sub-sections (SMS, MMS, WhatsApp, etc).
- Loading branch information
Showing
48 changed files
with
843 additions
and
786 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
136 changes: 136 additions & 0 deletions
136
Vonage.Test.Unit/Messages/Messenger/MessengerMessagesTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Vonage.Common; | ||
using Vonage.Common.Test; | ||
using Vonage.Messages; | ||
using Vonage.Messages.Messenger; | ||
using Vonage.Request; | ||
using Xunit; | ||
|
||
namespace Vonage.Test.Unit.Messages.Messenger | ||
{ | ||
public class MessengerMessagesTest : TestBase | ||
{ | ||
private readonly SerializationTestHelper helper; | ||
private readonly string expectedUri; | ||
|
||
public MessengerMessagesTest() | ||
{ | ||
this.expectedUri = $"{this.ApiUrl}/v1/messages"; | ||
this.helper = new SerializationTestHelper(typeof(MessengerMessagesTest).Namespace, | ||
JsonSerializer.BuildWithCamelCase()); | ||
} | ||
|
||
[Fact] | ||
public async Task SendMessengerAudioAsyncReturnsOk() | ||
{ | ||
var expectedResponse = this.helper.GetResponseJson(); | ||
var expectedRequest = this.helper.GetRequestJson(); | ||
var request = new MessengerAudioRequest | ||
{ | ||
To = "441234567890", | ||
From = "015417543010", | ||
Audio = new Attachment | ||
{ | ||
Url = "https://test.com/voice.mp3", | ||
}, | ||
ClientRef = "abcdefg", | ||
}; | ||
var creds = Credentials.FromAppIdAndPrivateKey(this.AppId, this.PrivateKey); | ||
this.Setup(this.expectedUri, expectedResponse, expectedRequest); | ||
var client = new VonageClient(creds); | ||
var response = await client.MessagesClient.SendAsync(request); | ||
Assert.NotNull(response); | ||
Assert.Equal(new Guid("aaaaaaaa-bbbb-cccc-dddd-0123456789ab"), response.MessageUuid); | ||
} | ||
|
||
[Fact] | ||
public async Task SendMessengerFileAsyncReturnsOk() | ||
{ | ||
var expectedResponse = this.helper.GetResponseJson(); | ||
var expectedRequest = this.helper.GetRequestJson(); | ||
var request = new MessengerFileRequest | ||
{ | ||
To = "441234567890", | ||
From = "015417543010", | ||
File = new Attachment | ||
{ | ||
Url = "https://test.com/me.txt", | ||
}, | ||
ClientRef = "abcdefg", | ||
}; | ||
var credentials = Credentials.FromAppIdAndPrivateKey(this.AppId, this.PrivateKey); | ||
this.Setup(this.expectedUri, expectedResponse, expectedRequest); | ||
var client = new VonageClient(credentials); | ||
var response = await client.MessagesClient.SendAsync(request); | ||
Assert.NotNull(response); | ||
Assert.Equal(new Guid("aaaaaaaa-bbbb-cccc-dddd-0123456789ab"), response.MessageUuid); | ||
} | ||
|
||
[Fact] | ||
public async Task SendMessengerImageAsyncReturnsOk() | ||
{ | ||
var expectedResponse = this.helper.GetResponseJson(); | ||
var expectedRequest = this.helper.GetRequestJson(); | ||
var request = new MessengerImageRequest | ||
{ | ||
To = "441234567890", | ||
From = "015417543010", | ||
Image = new Attachment | ||
{ | ||
Url = "https://test.com/image.png", | ||
}, | ||
ClientRef = "abcdefg", | ||
}; | ||
var credentials = Credentials.FromAppIdAndPrivateKey(this.AppId, this.PrivateKey); | ||
this.Setup(this.expectedUri, expectedResponse, expectedRequest); | ||
var client = new VonageClient(credentials); | ||
var response = await client.MessagesClient.SendAsync(request); | ||
Assert.NotNull(response); | ||
Assert.Equal(new Guid("aaaaaaaa-bbbb-cccc-dddd-0123456789ab"), response.MessageUuid); | ||
} | ||
|
||
[Fact] | ||
public async Task SendMessengerTextAsyncReturnsOk() | ||
{ | ||
var expectedResponse = this.helper.GetResponseJson(); | ||
var expectedRequest = this.helper.GetRequestJson(); | ||
var request = new MessengerTextRequest | ||
{ | ||
To = "441234567890", | ||
From = "015417543010", | ||
Text = "Hello mum", | ||
ClientRef = "abcdefg", | ||
}; | ||
var creds = Credentials.FromAppIdAndPrivateKey(this.AppId, this.PrivateKey); | ||
this.Setup(this.expectedUri, expectedResponse, expectedRequest); | ||
var client = new VonageClient(creds); | ||
var response = await client.MessagesClient.SendAsync(request); | ||
Assert.NotNull(response); | ||
Assert.Equal(new Guid("aaaaaaaa-bbbb-cccc-dddd-0123456789ab"), response.MessageUuid); | ||
} | ||
|
||
[Fact] | ||
public async Task SendMessengerVideoAsyncReturnsOk() | ||
{ | ||
var expectedResponse = this.helper.GetResponseJson(); | ||
var expectedRequest = this.helper.GetRequestJson(); | ||
var request = new MessengerVideoRequest | ||
{ | ||
To = "441234567890", | ||
From = "015417543010", | ||
Video = new Attachment | ||
{ | ||
Url = "https://test.com/me.mp4", | ||
}, | ||
ClientRef = "abcdefg", | ||
}; | ||
var creds = Credentials.FromAppIdAndPrivateKey(this.AppId, this.PrivateKey); | ||
this.Setup(this.expectedUri, expectedResponse, expectedRequest); | ||
var client = new VonageClient(creds); | ||
var response = await client.MessagesClient.SendAsync(request); | ||
Assert.NotNull(response); | ||
Assert.Equal(new Guid("aaaaaaaa-bbbb-cccc-dddd-0123456789ab"), response.MessageUuid); | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Vonage.Common; | ||
using Vonage.Common.Test; | ||
using Vonage.Messages; | ||
using Vonage.Messages.Mms; | ||
using Vonage.Request; | ||
using Xunit; | ||
|
||
namespace Vonage.Test.Unit.Messages.Mms | ||
{ | ||
public class MmsMessagesTest : TestBase | ||
{ | ||
private readonly SerializationTestHelper helper; | ||
private readonly string expectedUri; | ||
|
||
public MmsMessagesTest() | ||
{ | ||
this.expectedUri = $"{this.ApiUrl}/v1/messages"; | ||
this.helper = | ||
new SerializationTestHelper(typeof(MmsMessagesTest).Namespace, JsonSerializer.BuildWithCamelCase()); | ||
} | ||
|
||
[Fact] | ||
public async Task SendMmsAudioAsyncReturnsOk() | ||
{ | ||
var expectedResponse = this.helper.GetResponseJson(); | ||
var expectedRequest = this.helper.GetRequestJson(); | ||
var request = new MmsAudioRequest | ||
{ | ||
To = "441234567890", | ||
From = "015417543010", | ||
Audio = new CaptionedAttachment | ||
{ | ||
Url = "https://test.com/me.mp3", | ||
Caption = "Sounds I make", | ||
}, | ||
ClientRef = "abcdefg", | ||
}; | ||
var creds = Credentials.FromAppIdAndPrivateKey(this.AppId, this.PrivateKey); | ||
this.Setup(this.expectedUri, expectedResponse, expectedRequest); | ||
var client = new VonageClient(creds); | ||
var response = await client.MessagesClient.SendAsync(request); | ||
Assert.NotNull(response); | ||
Assert.Equal(new Guid("aaaaaaaa-bbbb-cccc-dddd-0123456789ab"), response.MessageUuid); | ||
} | ||
|
||
[Fact] | ||
public async Task SendMmsImageAsyncReturnsOk() | ||
{ | ||
var expectedResponse = this.helper.GetResponseJson(); | ||
var expectedRequest = this.helper.GetRequestJson(); | ||
var request = new MmsImageRequest | ||
{ | ||
To = "441234567890", | ||
From = "015417543010", | ||
Image = new Attachment | ||
{ | ||
Url = "https://test.com/image.png", | ||
}, | ||
ClientRef = "abcdefg", | ||
}; | ||
var creds = Credentials.FromAppIdAndPrivateKey(this.AppId, this.PrivateKey); | ||
this.Setup(this.expectedUri, expectedResponse, expectedRequest); | ||
var client = new VonageClient(creds); | ||
var response = await client.MessagesClient.SendAsync(request); | ||
Assert.NotNull(response); | ||
Assert.Equal(new Guid("aaaaaaaa-bbbb-cccc-dddd-0123456789ab"), response.MessageUuid); | ||
} | ||
|
||
[Fact] | ||
public async Task SendMmsVcardAsyncReturnsOk() | ||
{ | ||
var expectedResponse = this.helper.GetResponseJson(); | ||
var expectedRequest = this.helper.GetRequestJson(); | ||
var request = new MmsVcardRequest | ||
{ | ||
To = "441234567890", | ||
From = "015417543010", | ||
Vcard = new Attachment | ||
{ | ||
Url = "https://test.com/contact.vcf", | ||
}, | ||
ClientRef = "abcdefg", | ||
}; | ||
var creds = Credentials.FromAppIdAndPrivateKey(this.AppId, this.PrivateKey); | ||
this.Setup(this.expectedUri, expectedResponse, expectedRequest); | ||
var client = new VonageClient(creds); | ||
var response = await client.MessagesClient.SendAsync(request); | ||
Assert.NotNull(response); | ||
Assert.Equal(new Guid("aaaaaaaa-bbbb-cccc-dddd-0123456789ab"), response.MessageUuid); | ||
} | ||
|
||
[Fact] | ||
public async Task SendMmsVideoAsyncReturnsOk() | ||
{ | ||
var expectedResponse = this.helper.GetResponseJson(); | ||
var expectedRequest = this.helper.GetRequestJson(); | ||
var request = new MmsVideoRequest | ||
{ | ||
To = "441234567890", | ||
From = "015417543010", | ||
Video = new CaptionedAttachment | ||
{ | ||
Url = "https://test.com/image.mp4", | ||
Caption = "A video of me", | ||
}, | ||
ClientRef = "abcdefg", | ||
}; | ||
var creds = Credentials.FromAppIdAndPrivateKey(this.AppId, this.PrivateKey); | ||
this.Setup(this.expectedUri, expectedResponse, expectedRequest); | ||
var client = new VonageClient(creds); | ||
var response = await client.MessagesClient.SendAsync(request); | ||
Assert.NotNull(response); | ||
Assert.Equal(new Guid("aaaaaaaa-bbbb-cccc-dddd-0123456789ab"), response.MessageUuid); | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System; | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using Vonage.Common; | ||
using Vonage.Common.Test; | ||
using Vonage.Messages.Sms; | ||
using Vonage.Request; | ||
using Xunit; | ||
|
||
namespace Vonage.Test.Unit.Messages.Sms | ||
{ | ||
public class SmsMessagesTest : TestBase | ||
{ | ||
private readonly SerializationTestHelper helper; | ||
private readonly string expectedUri; | ||
|
||
public SmsMessagesTest() | ||
{ | ||
this.expectedUri = $"{this.ApiUrl}/v1/messages"; | ||
this.helper = | ||
new SerializationTestHelper(typeof(SmsMessagesTest).Namespace, JsonSerializer.BuildWithCamelCase()); | ||
} | ||
|
||
[Fact] | ||
public async Task SendSmsAsyncReturnsInvalidCredentials() | ||
{ | ||
var expectedResponse = this.helper.GetResponseJson(); | ||
var expectedRequest = this.helper.GetRequestJson(); | ||
var request = new SmsRequest | ||
{ | ||
To = "441234567890", | ||
From = "015417543010", | ||
Text = "This is a test", | ||
ClientRef = "abcdefg", | ||
}; | ||
var creds = Credentials.FromAppIdAndPrivateKey(this.AppId, this.PrivateKey); | ||
this.Setup(this.expectedUri, expectedResponse, expectedRequest, HttpStatusCode.Unauthorized); | ||
var client = new VonageClient(creds); | ||
var exception = | ||
await Assert.ThrowsAsync<VonageHttpRequestException>(async () => | ||
await client.MessagesClient.SendAsync(request)); | ||
Assert.NotNull(exception); | ||
Assert.Equal(expectedResponse, exception.Json); | ||
} | ||
|
||
[Fact] | ||
public async Task SendSmsAsyncReturnsOk() | ||
{ | ||
var expectedResponse = this.helper.GetResponseJson(); | ||
var expectedRequest = this.helper.GetRequestJson(); | ||
var request = new SmsRequest | ||
{ | ||
To = "441234567890", | ||
From = "015417543010", | ||
Text = "This is a test", | ||
ClientRef = "abcdefg", | ||
}; | ||
var creds = Credentials.FromAppIdAndPrivateKey(this.AppId, this.PrivateKey); | ||
this.Setup(this.expectedUri, expectedResponse, expectedRequest); | ||
var client = new VonageClient(creds); | ||
var response = await client.MessagesClient.SendAsync(request); | ||
Assert.NotNull(response); | ||
Assert.Equal(new Guid("aaaaaaaa-bbbb-cccc-dddd-0123456789ab"), response.MessageUuid); | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Vonage.Common; | ||
using Vonage.Common.Test; | ||
using Vonage.Messages; | ||
using Vonage.Messages.Viber; | ||
using Vonage.Request; | ||
using Xunit; | ||
|
||
namespace Vonage.Test.Unit.Messages.Viber | ||
{ | ||
public class ViberMessagesTest : TestBase | ||
{ | ||
private readonly SerializationTestHelper helper; | ||
private readonly string expectedUri; | ||
|
||
public ViberMessagesTest() | ||
{ | ||
this.expectedUri = $"{this.ApiUrl}/v1/messages"; | ||
this.helper = new SerializationTestHelper(typeof(ViberMessagesTest).Namespace, | ||
JsonSerializer.BuildWithCamelCase()); | ||
} | ||
|
||
[Fact] | ||
public async Task SendViberImageAsyncReturnsOk() | ||
{ | ||
var expectedResponse = this.helper.GetResponseJson(); | ||
var expectedRequest = this.helper.GetRequestJson(); | ||
var request = new ViberImageRequest | ||
{ | ||
To = "441234567890", | ||
From = "015417543010", | ||
Image = new Attachment | ||
{ | ||
Url = "https://test.com/image.png", | ||
}, | ||
ClientRef = "abcdefg", | ||
}; | ||
var credentials = Credentials.FromAppIdAndPrivateKey(this.AppId, this.PrivateKey); | ||
this.Setup(this.expectedUri, expectedResponse, expectedRequest); | ||
var client = new VonageClient(credentials); | ||
var response = await client.MessagesClient.SendAsync(request); | ||
Assert.NotNull(response); | ||
Assert.Equal(new Guid("aaaaaaaa-bbbb-cccc-dddd-0123456789ab"), response.MessageUuid); | ||
} | ||
|
||
[Fact] | ||
public async Task SendViberTextAsyncReturnsOk() | ||
{ | ||
var expectedResponse = this.helper.GetResponseJson(); | ||
var expectedRequest = this.helper.GetRequestJson(); | ||
var request = new ViberTextRequest | ||
{ | ||
To = "441234567890", | ||
From = "015417543010", | ||
Text = "Hello mum", | ||
ClientRef = "abcdefg", | ||
}; | ||
var credentials = Credentials.FromAppIdAndPrivateKey(this.AppId, this.PrivateKey); | ||
this.Setup(this.expectedUri, expectedResponse, expectedRequest); | ||
var client = new VonageClient(credentials); | ||
var response = await client.MessagesClient.SendAsync(request); | ||
Assert.NotNull(response); | ||
Assert.Equal(new Guid("aaaaaaaa-bbbb-cccc-dddd-0123456789ab"), response.MessageUuid); | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.