@@ -1513,6 +1513,7 @@ public IEnumerator TestPublishWithMeta() {
1513
1513
Assert . True ( ! result . Timetoken . Equals ( 0 ) ) ;
1514
1514
Assert . True ( status . Error . Equals ( false ) ) ;
1515
1515
Assert . True ( status . StatusCode . Equals ( 0 ) , status . StatusCode . ToString ( ) ) ;
1516
+ Assert . True ( ! result . Timetoken . Equals ( 0 ) ) ;
1516
1517
} ) ;
1517
1518
yield return new WaitForSeconds ( PlayModeCommon . WaitTimeBetweenCalls3 ) ;
1518
1519
Assert . True ( tresult , "test didn't return" ) ;
@@ -1615,6 +1616,145 @@ public IEnumerator TestPublishAndHistory() {
1615
1616
pubnub . CleanUp ( ) ;
1616
1617
}
1617
1618
1619
+ [ UnityTest ]
1620
+ public IEnumerator TestPublishHistoryAndFetchWithMetaAndTT ( ) {
1621
+ return PublishHistoryAndFetchWithMetaCommon ( true , true ) ;
1622
+ }
1623
+
1624
+ [ UnityTest ]
1625
+ public IEnumerator TestPublishHistoryAndFetchWithMetaWithoutTT ( ) {
1626
+ return PublishHistoryAndFetchWithMetaCommon ( true , false ) ;
1627
+ }
1628
+
1629
+ [ UnityTest ]
1630
+ public IEnumerator TestPublishHistoryAndFetchWithTTWithoutMeta ( ) {
1631
+ return PublishHistoryAndFetchWithMetaCommon ( false , true ) ;
1632
+ }
1633
+
1634
+ [ UnityTest ]
1635
+ public IEnumerator TestPublishHistoryAndFetchWithoutMetaAndTT ( ) {
1636
+ return PublishHistoryAndFetchWithMetaCommon ( false , false ) ;
1637
+ }
1638
+
1639
+ public IEnumerator PublishHistoryAndFetchWithMetaCommon ( bool withMeta , bool withTimetoken ) {
1640
+ PNConfiguration pnConfiguration = PlayModeCommon . SetPNConfig ( false ) ;
1641
+ System . Random r = new System . Random ( ) ;
1642
+ pnConfiguration . UUID = "UnityTestConnectedUUID_" + r . Next ( 100 ) ;
1643
+ string channel = "UnityPublishAndHistoryChannel" + r . Next ( 100 ) ; ;
1644
+ string payload = string . Format ( "payload {0}" , pnConfiguration . UUID ) ;
1645
+
1646
+ PubNub pubnub = new PubNub ( pnConfiguration ) ;
1647
+
1648
+ List < string > channelList2 = new List < string > ( ) ;
1649
+ channelList2 . Add ( channel ) ;
1650
+ bool tresult = false ;
1651
+ Dictionary < string , string > metaDict = new Dictionary < string , string > ( ) ;
1652
+ metaDict . Add ( "region" , "east" ) ;
1653
+ long retTT = 0 ;
1654
+
1655
+ pubnub . Publish ( ) . Channel ( channel ) . Meta ( metaDict ) . Message ( payload ) . Async ( ( result , status ) => {
1656
+ bool timetokenMatch = ! result . Timetoken . Equals ( 0 ) ;
1657
+ bool statusError = status . Error . Equals ( false ) ;
1658
+ bool statusCodeMatch = status . StatusCode . Equals ( 0 ) ;
1659
+ retTT = result . Timetoken ;
1660
+ Assert . True ( timetokenMatch ) ;
1661
+ Assert . True ( statusError ) ;
1662
+ Assert . True ( statusCodeMatch , status . StatusCode . ToString ( ) ) ;
1663
+ tresult = statusCodeMatch && statusError && timetokenMatch ;
1664
+ } ) ;
1665
+ yield return new WaitForSeconds ( PlayModeCommon . WaitTimeBetweenCalls3 ) ;
1666
+ Assert . True ( tresult , "test didnt return 1" ) ;
1667
+
1668
+ tresult = false ;
1669
+ bool tresultMeta = false ;
1670
+ bool tresultTimetoken = false ;
1671
+ pubnub . History ( ) . Channel ( channel ) . IncludeMeta ( withMeta ) . IncludeTimetoken ( withTimetoken ) . Count ( 1 ) . Async ( ( result , status ) => {
1672
+ Assert . True ( status . Error . Equals ( false ) ) ;
1673
+ if ( ! status . Error ) {
1674
+
1675
+ if ( ( result . Messages != null ) && ( result . Messages . Count > 0 ) ) {
1676
+ PNHistoryItemResult pnHistoryItemResult = result . Messages [ 0 ] as PNHistoryItemResult ;
1677
+ Debug . Log ( "result.Messages[0]" + result . Messages [ 0 ] . ToString ( ) ) ;
1678
+ if ( pnHistoryItemResult != null ) {
1679
+ tresult = pnHistoryItemResult . Entry . ToString ( ) . Contains ( payload ) ;
1680
+
1681
+ if ( withMeta ) {
1682
+ Dictionary < string , object > metaDataDict = pnHistoryItemResult . Meta as Dictionary < string , object > ;
1683
+ object region ;
1684
+ metaDataDict . TryGetValue ( "region" , out region ) ;
1685
+ tresultMeta = region . ToString ( ) . Equals ( "east" ) ;
1686
+ } else {
1687
+ tresultMeta = true ;
1688
+ }
1689
+ if ( withTimetoken ) {
1690
+ tresultTimetoken = retTT . Equals ( pnHistoryItemResult . Timetoken ) ;
1691
+ } else {
1692
+ tresultTimetoken = true ;
1693
+ }
1694
+ } else {
1695
+ tresult = false ;
1696
+ tresultMeta = false ;
1697
+ }
1698
+ } else {
1699
+ tresult = false ;
1700
+ }
1701
+
1702
+ }
1703
+ } ) ;
1704
+ yield return new WaitForSeconds ( PlayModeCommon . WaitTimeBetweenCalls3 ) ;
1705
+ Assert . True ( tresult , "test didnt return 2" ) ;
1706
+ Assert . True ( tresultMeta , "test meta didnt return" ) ;
1707
+ Assert . True ( tresultTimetoken , "tresultTimetoken didnt return" ) ;
1708
+
1709
+ tresult = false ;
1710
+ tresultMeta = false ;
1711
+ pubnub . FetchMessages ( ) . Channels ( channelList2 ) . IncludeMeta ( withMeta ) . Async ( ( result , status ) => {
1712
+ if ( ! status . Error ) {
1713
+ if ( result . Channels != null ) {
1714
+ Dictionary < string , List < PNMessageResult > > fetchResult = result . Channels as Dictionary < string , List < PNMessageResult > > ;
1715
+ Debug . Log ( "fetchResult.Count:" + fetchResult . Count ) ;
1716
+ foreach ( KeyValuePair < string , List < PNMessageResult > > kvp in fetchResult ) {
1717
+ Debug . Log ( "Channel:" + kvp . Key ) ;
1718
+ if ( kvp . Key . Equals ( channel ) ) {
1719
+
1720
+ foreach ( PNMessageResult msg in kvp . Value ) {
1721
+ Debug . Log ( "msg.Channel:" + msg . Channel ) ;
1722
+ Debug . Log ( "msg.Payload.ToString():" + msg . Payload . ToString ( ) ) ;
1723
+ if ( msg . Channel . Equals ( channel ) && ( msg . Payload . ToString ( ) . Equals ( payload ) ) ) {
1724
+ tresult = true ;
1725
+ }
1726
+ if ( withMeta ) {
1727
+ Dictionary < string , object > metaDataDict = msg . UserMetadata as Dictionary < string , object > ;
1728
+ object region ;
1729
+ if ( metaDataDict != null ) {
1730
+ metaDataDict . TryGetValue ( "region" , out region ) ;
1731
+ tresultMeta = region . ToString ( ) . Equals ( "east" ) ;
1732
+ } else {
1733
+ Debug . Log ( "metaDataDict null" + msg . UserMetadata ) ;
1734
+ }
1735
+ } else {
1736
+ tresultMeta = true ;
1737
+ }
1738
+
1739
+ }
1740
+ if ( ! tresult && ! tresultMeta ) {
1741
+ break ;
1742
+ }
1743
+ }
1744
+ }
1745
+ }
1746
+
1747
+ }
1748
+
1749
+ } ) ;
1750
+ yield return new WaitForSeconds ( PlayModeCommon . WaitTimeBetweenCalls3 ) ;
1751
+ Assert . True ( tresult , "test didnt return for fetch" ) ;
1752
+ Assert . True ( tresultMeta , "test meta didnt return for fetch" ) ;
1753
+
1754
+
1755
+ pubnub . CleanUp ( ) ;
1756
+ }
1757
+
1618
1758
[ UnityTest ]
1619
1759
public IEnumerator TestPublishNoStore ( ) {
1620
1760
PNConfiguration pnConfiguration = PlayModeCommon . SetPNConfig ( false ) ;
0 commit comments