public async Task Ensure_Client_Caching_Works_With_Jwt() { var service = BoostrapApnsService(); var jwtOpt1 = new ApnsJwtOptions() { KeyId = "1234567890", TeamId = "1234567890", BundleId = "bundleid1", CertContent = _certs.P8CertData }; var jwtOpt2 = new ApnsJwtOptions() { KeyId = "1234567890", TeamId = "1234567890", BundleId = "bundleid2", CertContent = _certs.P8CertData }; var firstPush = ApplePush.CreateContentAvailable().AddToken("token"); var secondPush = ApplePush.CreateAlert(new ApplePushAlert(null, "body")).AddToken("token"); var thirdPush = ApplePush.CreateAlert(new ApplePushAlert(null, "body")).AddToken("token"); var fourthPush = ApplePush.CreateContentAvailable().AddToken("token"); await service.SendPush(firstPush, jwtOpt1); await service.SendPush(secondPush, jwtOpt1); await service.SendPush(thirdPush, jwtOpt2); await service.SendPush(fourthPush, jwtOpt2); Assert.Equal(2, ((IDictionary)service.GetType().GetField("_cachedJwtClients", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(service)).Count); }
public void Sending_NonVoip_Type_With_Voip_Cert_Fails() { var apns = ApnsClient.CreateUsingCert("voip.p12"); var push = ApplePush.CreateAlert(new ApplePushAlert("title", "body")).AddToken("token"); Assert.ThrowsAsync <InvalidOperationException>(async() => await apns.Send(push)); }
public void Ensure_Priority_Corresponds_To_Payload() { var pushWithContentAvailable = ApplePush.CreateContentAvailable(); var pushWithAlert = ApplePush.CreateAlert(new ApplePushAlert("title", "body")); Assert.Equal(5, pushWithContentAvailable.Priority); Assert.Equal(10, pushWithAlert.Priority); }
public void Ensure_Type_Correspond_To_Payload() { var pushWithContentAvailable = ApplePush.CreateContentAvailable(); var pushWithAlert = ApplePush.CreateAlert(new ApplePushAlert("title", "body")); Assert.Equal(ApplePushType.Background, pushWithContentAvailable.Type); Assert.Equal(ApplePushType.Alert, pushWithAlert.Type); }
public void Sending_NonVoip_Type_With_Voip_Cert_Fails() { #if !NETCOREAPP3_1 return; #endif var apns = ApnsClient.CreateUsingCert(_certs.P12Cert); var push = ApplePush.CreateAlert(new ApplePushAlert("title", "body")).AddToken("token"); Assert.ThrowsAsync <InvalidOperationException>(async() => await apns.SendAsync(push)); }
public async Task Sending_Push_Not_Throws() { var client = BoostrapApnsClient(); var push = ApplePush.CreateAlert("body") .AddToken("token") .AddBadge(1) .AddSound() .AddLocation("location"); await client.Send(push); }
public void Adding_Token_and_VoipToken_Together_Fails() { var pushWithToken = ApplePush.CreateContentAvailable().AddToken("token"); var pushWithVoipToken = ApplePush.CreateContentAvailable(true).AddVoipToken("voip"); var alertPushWithToken = ApplePush.CreateAlert(new ApplePushAlert("title", "body")).AddToken("token"); Assert.Throws <InvalidOperationException>(() => pushWithToken.AddVoipToken("voip")); Assert.Throws <InvalidOperationException>(() => pushWithVoipToken.AddToken("token")); Assert.Throws <InvalidOperationException>(() => alertPushWithToken.AddVoipToken("voip")); }
//[Fact] cert uses real handler. Can't test until refactored. public async Task Ensure_Client_Caching_Works_With_Cert() { var service = BoostrapApnsService(); var firstPush = ApplePush.CreateContentAvailable().AddToken("token"); var secondPush = ApplePush.CreateAlert(new ApplePushAlert(null, "body")).AddToken("token"); await service.SendPush(firstPush, _certs.P12Cert); await service.SendPush(secondPush, _certs.P12Cert); Assert.Single((IDictionary)service.GetType().GetField("_cachedJwtClients", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(service)); }
public void AddCustomProperty_Correctly_Adds_String_Value() { var push = ApplePush .CreateAlert("testAlert") .AddCustomProperty("customPropertyKey", "customPropertyValue"); var payload = push.GeneratePayload(); string payloadJson = JsonConvert.SerializeObject(payload); const string referencePayloadJson = "{\"aps\":{\"alert\":\"testAlert\"},\"customPropertyKey\":\"customPropertyValue\"}"; Assert.Equal(referencePayloadJson, payloadJson); }
public void AddCustomProperty_Correctly_Adds_Complex_Value() { var push = ApplePush .CreateAlert("testAlert") .AddCustomProperty("customPropertyKey", new { value1 = "123", value2 = 456 }); var payload = push.GeneratePayload(); string payloadJson = JsonConvert.SerializeObject(payload); const string referencePayloadJson = "{\"aps\":{\"alert\":\"testAlert\"},\"customPropertyKey\":{\"value1\":\"123\",\"value2\":456}}"; Assert.Equal(referencePayloadJson, payloadJson); }
public void Adding_Voip_To_Alert_Push_Throws_InvalidOperationException() { var alertPush = ApplePush.CreateAlert(new ApplePushAlert("title", "body")); Assert.Throws <InvalidOperationException>(() => alertPush.AddVoipToken("voip")); }