using Amazon.Runtime; using Amazon.SimpleNotificationService; using Amazon.SimpleNotificationService.Model; using AutoFixture; using Amazon.Sns.Wrapper.Implementations; using Amazon.Sns.Wrapper.Interfaces; using Moq; using System.Threading.Tasks; using Xunit; namespace Amazon.Sns.Wrapper.Tests { public class MobilePushNotificationTests { private Mock _fakeSnsClient; private Fixture _fixture; public MobilePushNotificationTests() { _fixture = new Fixture(); _fakeSnsClient = new Mock(); } [Fact] public async Task CreatePlatformApplicationIsSuccessful() { var fakeRequest = _fixture.Create(); var fakeResponse = GetResponseFixture(); _fakeSnsClient.Setup(p => p.CreatePlatformApplicationAsync(It.IsAny(), default)) .Returns(Task.FromResult(fakeResponse)); var response = await GetNotificationService().PushNotification.CreatePlatformApplicationAsync(fakeRequest.Name, Models.NotificationPlatform.GCM, fakeRequest.Attributes); Assert.Equal(response, fakeResponse.PlatformApplicationArn); } [Fact] public async Task CreatePlatformEndpointIsSuccessful() { var fakeRequest = _fixture.Create(); var fakeResponse = GetResponseFixture(); _fakeSnsClient.Setup(p => p.CreatePlatformEndpointAsync(It.IsAny(), default)) .Returns(Task.FromResult(fakeResponse)); var response = await GetNotificationService().PushNotification.CreatePlatformEndpointAsync(fakeRequest.PlatformApplicationArn, fakeRequest.Token, fakeRequest.CustomUserData, fakeRequest.Attributes); Assert.Equal(response, fakeResponse.EndpointArn); } [Fact] public async Task DeletePlatformApplicationIsSuccessful() { var fakeRequest = _fixture.Create(); var fakeResponse = GetResponseFixture(); _fakeSnsClient.Setup(p => p.DeletePlatformApplicationAsync(It.IsAny(), default)) .Returns(Task.FromResult(fakeResponse)); var response = await GetNotificationService().PushNotification.DeletePlatformApplicationAsync(fakeRequest.PlatformApplicationArn); Assert.True(response); } [Fact] public async Task DeletePlatformEndpointIsSuccessful() { var fakeRequest = _fixture.Create(); var fakeResponse = GetResponseFixture(); _fakeSnsClient.Setup(p => p.DeleteEndpointAsync(It.IsAny(), default)) .Returns(Task.FromResult(fakeResponse)); var response = await GetNotificationService().PushNotification.DeleteEndpointAsync(fakeRequest.EndpointArn); Assert.True(response); } [Fact] public async Task GetPlatformApplicationAttributesIsSuccessful() { var fakeRequest = _fixture.Create(); var fakeResponse = GetResponseFixture(); _fakeSnsClient.Setup(p => p.GetPlatformApplicationAttributesAsync(It.IsAny(), default)) .Returns(Task.FromResult(fakeResponse)); var response = await GetNotificationService().PushNotification.GetPlatformApplicationAttributesAsync(fakeRequest.PlatformApplicationArn); Assert.Equal(response.Count, fakeResponse.Attributes.Count); } [Fact] public async Task GetPlatformEndpointAttributesIsSuccessful() { var fakeRequest = _fixture.Create(); var fakeResponse = GetResponseFixture(); _fakeSnsClient.Setup(p => p.GetEndpointAttributesAsync(It.IsAny(), default)) .Returns(Task.FromResult(fakeResponse)); var response = await GetNotificationService().PushNotification.GetEndpointAttributesAsync(fakeRequest.EndpointArn); Assert.Equal(response.Count, fakeResponse.Attributes.Count); } [Fact] public async Task SetPlatformApplicationAttributesIsSuccessful() { var fakeRequest = _fixture.Create(); var fakeResponse = GetResponseFixture(); _fakeSnsClient.Setup(p => p.SetPlatformApplicationAttributesAsync(It.IsAny(), default)) .Returns(Task.FromResult(fakeResponse)); var response = await GetNotificationService().PushNotification.SetPlatformApplicationAttributesAsync(fakeRequest.PlatformApplicationArn, fakeRequest.Attributes); Assert.True(response); } [Fact] public async Task SetPlatformEndpointAttributesIsSuccessful() { var fakeRequest = _fixture.Create(); var fakeResponse = GetResponseFixture(); _fakeSnsClient.Setup(p => p.SetEndpointAttributesAsync(It.IsAny(), default)) .Returns(Task.FromResult(fakeResponse)); var response = await GetNotificationService().PushNotification.SetEndpointAttributesAsync(fakeRequest.EndpointArn, fakeRequest.Attributes); Assert.True(response); } [Fact] public async Task ListPlatformApplicationsIsSuccessful() { var fakeRequest = _fixture.Create(); var fakeResponse = GetResponseFixture(); _fakeSnsClient.Setup(p => p.ListPlatformApplicationsAsync(It.IsAny(), default)) .Returns(Task.FromResult(fakeResponse)); var response = await GetNotificationService().PushNotification.ListPlatformApplicationsAsync(); Assert.Equal(response.Count, fakeResponse.PlatformApplications.Count); } [Fact] public async Task ListPlatformEndpointsIsSuccessful() { var fakeRequest = _fixture.Create(); var fakeResponse = GetResponseFixture(); _fakeSnsClient.Setup(p => p.ListEndpointsByPlatformApplicationAsync(It.IsAny(), default)) .Returns(Task.FromResult(fakeResponse)); var response = await GetNotificationService().PushNotification.ListEndpointsByPlatformApplicationAsync(fakeRequest.PlatformApplicationArn); Assert.Equal(response.Count, fakeResponse.Endpoints.Count); } private INotificationService GetNotificationService() { return new NotificationService(_fakeSnsClient.Object); } private T GetResponseFixture() where T : AmazonWebServiceResponse { var response = _fixture.Create(); response.HttpStatusCode = System.Net.HttpStatusCode.OK; return response; } } }