public void SendDryRunMessage() { var token = "your-token-here"; var service = new FcmService(Fixture.ConfigService.Get <ServiceConfig>().FcmServiceConfig, ProxyConfig.DefaultConfig); var msg = new FcmMessageBuilder() .AddReceiver(token) .SetDebug() .SetData(new { Foo = "Bar" }) .SetPriority(FcmMessagePriority.High) .SetNotification(new FcmNotification() { Title = "Foobar", Body = "Foo", Sound = "default", ClickAction = "" }) .Build(); var response = service.Send(msg); Assert.Equal(200, response.ErrorCode); Assert.NotNull(response.ResponseMessage); // Assert.Equal(1, response.ResponseMessage.Success); // Assert.Equal(0, response.ResponseMessage.Failure); }
public void SendDryRun200ErrorMessage() { //Send 200OK message but with internal failure var service = new FcmService(Fixture.ConfigService.Get <ServiceConfig>().FcmServiceConfig, ProxyConfig.DefaultConfig); var msg = new FcmMessageBuilder() .AddReceiver("", "some_sample_receiver_key") .SetDebug() .SetData(new { Foo = "Bar" }) .Build(); var response = service.Send(msg); Assert.Equal(200, response.ErrorCode); Assert.NotNull(response.ResponseMessage); Assert.Equal(0, response.ResponseMessage.Success); Assert.Equal(2, response.ResponseMessage.Failure); var errText = response.ResponseMessage.Results.First().Error; Assert.Equal(ResponseError.MissingRegistration, errText); errText = response.ResponseMessage.Results.Last().Error; Assert.Equal(ResponseError.InvalidRegistration, errText); }
public bool SendFcmMessage(object data, params DeviceId[] deviceIds) { var tokens = new LinkedList <string>(); foreach (var deviceId in deviceIds) { if (_persistenceProvider.TryGetDeviceInfos(deviceId, out var deviceInfo)) { tokens.AddLast(deviceInfo.FcmToken); } else { Logger.Info($"DeviceToken for Id: {deviceId?.FullId} not found!"); } } var tokenArr = tokens.Where(x => x != null).ToArray(); if (tokens.Count > 0) { try { var msg = new FcmMessageBuilder() .AddReceiver(tokenArr) .SetDebug(false) .SetPriority(FcmMessagePriority.High) .SetData(data) .Build(); var response = _fcmService.Send(msg); if (response.Error == ResponseError.NoError) { Logger.Debug( $"FCM Response: [Success={response.ResponseMessage?.Success}, Failure={response.ResponseMessage?.Failure}]"); return(true); } Logger.Error($"FCM Response Error - Code: {response.ErrorCode}, \"{response.ErrorMessage}\""); return(false); } catch (FcmMessageBuilderException e) { Logger.Error("FCM Builder encountered an Error:", e); return(false); } } Logger.Debug("FcmNotification: Found no devices for notification"); return(true); }
public void TestFirebase() { //TODO Token from config var token = "your-token-here"; var msg = new FcmMessageBuilder() .AddReceiver(token) .SetDebug(false) .SetPriority(FcmMessagePriority.High) .SetData(new { foo = "bar" }) .Build(); var response = Send(msg); Assert.Equal(200, response.ErrorCode); Assert.NotNull(response.ResponseMessage); Assert.Equal(1, response.ResponseMessage.Success); Assert.Equal(0, response.ResponseMessage.Failure); }
public void SendDryRun400ErrorMessage() { //Send 400InvalidJson message var service = new FcmService(Fixture.ConfigService.Get <ServiceConfig>().FcmServiceConfig, ProxyConfig.DefaultConfig); Assert.Throws <FcmMessageBuilderException>(() => { var msg = new FcmMessageBuilder() .SetDebug() .SetData(new { Foo = "Bar" }) .Build(); }); // // var response = service.Send(msg); // Assert.Equal(400, response.ErrorCode); // Assert.NotNull(response.ErrorMessage); }