public void PublishNotificationPostsByBuildingQueryAndPayload() { IRestResponse restResponse = Helpers.SetUpRestResponse(HttpStatusCode.OK); _request.ExecuteJsonRequest(Arg.Any <string>(), Arg.Any <Method>(), Arg.Any <object>()) .Returns(restResponse); var recipients = Substitute.For <INotificationRecipients>(); recipients.BuildQuery().Returns("query"); var appleNotification = new AppleNotification("appleNotifierName", "appleTestMessge", "chime"); var googleNotification = new AndroidNotification("googleNotifierName", "androidTestMessage"); var deliverAt = DateTime.Now.AddDays(1); var expireAt = DateTime.Now.AddDays(2); var schedulerSettings = new NotificationSchedulerSettings { DeliverAt = deliverAt, ExpireAt = expireAt }; //call PublishNotification _notificationsManager.PublishNotification(new Notification[] { appleNotification, googleNotification }, recipients, schedulerSettings); //assert recipients.Received(1).BuildQuery(); Func <NotificationPayload, bool> validatePayload = p => { bool isValid = true; isValid &= p.DeliverAt == deliverAt.ToUnixTime(); isValid &= p.ExpireAt == expireAt.ToUnixTime(); var applePayload = p.Payloads["appleNotifierName"].GetReflectedProperty("aps"); isValid &= (string)applePayload.GetReflectedProperty("alert") == "appleTestMessge"; isValid &= (string)applePayload.GetReflectedProperty("sound") == "chime"; var googlePayload = p.Payloads["googleNotifierName"].GetReflectedProperty("data"); isValid &= (string)googlePayload == "androidTestMessage"; return(isValid); }; _request.Received(1).ExecuteJsonRequest("query", Method.POST, Arg.Is <NotificationPayload>( p => validatePayload(p))); }