public void ExistingCetusCycleNotificationStateHasExpiredAndNewCetusCycleDetecetd() { var expired = new NotificationState { WfStatId = "0" }; var cetusCycle = new CetusCycle { Id = "1", State = "test", ShortString = "test", Expiry = DateTime.UtcNow + TimeSpan.FromMinutes(1) }; worldStateProcess.ProcessCetusCycle(expired, cetusCycle); // new states will be added var expected = new NotificationState { WfStatId = "1", WfStatType = nameof(WFStatType.CetusCycle) }; var actual = worldStateProcess.NewNotificationStates[0]; Assert.Equal(expected.WfStatId, actual.WfStatId); Assert.Equal(expected.WfStatType, actual.WfStatType); // old states will be deleted Assert.Equal("0", worldStateProcess.ExpiredNotificationStates[0].WfStatId); // fcm will be added var actualFCM = worldStateProcess.NotificationMessages[0]; Assert.Contains("pc-CetusCycle", actualFCM.Topic); }
public void ProcessCetusCycle(NotificationState state, CetusCycle cetus) { var sendFCM = ProcessSingleExpirable(state, cetus, cetus.StatType); if (sendFCM) { var ttl = cetus.TimeLeft; var message = FCM.CreateMessage($"{cetus.State.ToUpperFirst()} in Cetus", cetus.ShortString, platform, YawsNotification.Topic.CetusCycle, nameof(CetusCycle), ttl); NotificationMessages.Add(message); } }
public static string ToString(CetusCycle cycle) { var time = (cycle.Expiry - DateTime.Now).Humanize(int.MaxValue, CultureInfo.GetCultureInfo("zh-CN"), TimeUnit.Hour, TimeUnit.Second, " "); var status = cycle.IsDay ? "白天" : "夜晚"; var nextTime = !cycle.IsDay ? "白天" : "夜晚"; var sb = new StringBuilder(); sb.AppendLine($"现在地球平原的时间是: {status}"); //sb.AppendLine($"将在 {cycle.Expiry} 变为 {nextTime}"); sb.Append($"距离 {nextTime} 还有 {time}"); return(sb.ToString()); }
public void NoExistingCetusCycleNotificationStates() { var cetusCycle = new CetusCycle { Id = "1" }; worldStateProcess.ProcessCetusCycle(null, cetusCycle); // new states will be added var expected = new NotificationState { WfStatId = "1", WfStatType = nameof(WFStatType.CetusCycle) }; var actual = worldStateProcess.NewNotificationStates[0]; Assert.Equal(expected.WfStatId, actual.WfStatId); Assert.Equal(expected.WfStatType, actual.WfStatType); // nothing to delete Assert.Empty(worldStateProcess.ExpiredNotificationStates); // no FCM Assert.Empty(worldStateProcess.NotificationMessages); }
public void ExistingCetusCycleNotificationStateStillActive() { var state = new NotificationState { WfStatId = "1" }; var cetusCycle = new CetusCycle { Id = "1", State = "test", ShortString = "test", Expiry = DateTime.UtcNow + TimeSpan.FromMinutes(1) }; worldStateProcess.ProcessCetusCycle(state, cetusCycle); // nothing to add Assert.Empty(worldStateProcess.NewNotificationStates); // nothing to delete Assert.Empty(worldStateProcess.ExpiredNotificationStates); // no fcm Assert.Empty(worldStateProcess.NotificationMessages); }