Skip to content
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

Split Messages tests under separate categories #363

Merged
merged 2 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 136 additions & 0 deletions Vonage.Test.Unit/Messages/Messenger/MessengerMessagesTest.cs
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);
}
}
}
118 changes: 118 additions & 0 deletions Vonage.Test.Unit/Messages/Mms/MmsMessagesTest.cs
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);
}
}
}
66 changes: 66 additions & 0 deletions Vonage.Test.Unit/Messages/Sms/SmsMessagesTest.cs
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);
}
}
}
67 changes: 67 additions & 0 deletions Vonage.Test.Unit/Messages/Viber/ViberMessagesTest.cs
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);
}
}
}
Loading