public async Task GetNotificationTest() { var id = Guid.NewGuid(); var record = new NotificationRecord { OwnerUserId = Guid.NewGuid().ToString(), Id = id, Parameters = new Dictionary <string, object> { { "testKey", "testValue" } }, Created = DateTimeOffset.UtcNow, Event = NotificationEvent.ArticleCreated }; var store = new Mock <INotificationHistoryDataStore>(); store.Setup(x => x.FindAsync(It.Is <Guid>(guid => guid == id))) .ReturnsAsync(record); var service = new NotificationHistoryService(store.Object, DefaultMapper); var result = await service.GetAsync(new GetNotificationRequest(record.OwnerUserId, id)); ValidateRecords(record, result); }
public EntityEntry <NotificationRecord> AddNotification(NotificationRecord record) { var result = _context.NotificationRecords.Add(record); _context.SaveChanges(); return(result); }
private void ValidateFetchedNotification(NotificationRecord expectedNotification, NotificationRecord fetchedNotification) { Assert.NotNull(expectedNotification); Assert.NotNull(fetchedNotification); Assert.True(fetchedNotification.Id != null); Assert.Same(expectedNotification, fetchedNotification); }
public async Task SaveRecordTest() { var newRecord = new NotificationRecord { OwnerUserId = Guid.NewGuid().ToString(), Event = NotificationEvent.PackageArrived, Parameters = new Dictionary <string, object> { { "test", "value" } } }; using (var context = GetContext()) { var store = new NotificationRecordDataStore(context, DefaultMapper); var result = await store.SaveAsync(newRecord); Assert.NotEqual(Guid.Empty, result.Id); Assert.NotEqual(new DateTimeOffset(), result.Created); } using (var context = GetContext()) { Assert.NotEmpty(context.NotificationRecords); } }
public void Notify(NotificationRecord target, IEnumerable <Item> items) { foreach (var item in items) { var message = target.Template.TemplateReplace(item); SendAsync(target.Value, item.Title, message); } }
private static void ValidateRecords(NotificationRecord expected, NotificationResponse actual) { Assert.NotNull(actual); Assert.Equal(expected.Id, actual.Id); Assert.Equal(expected.Parameters, actual.Parameters); Assert.Equal(expected.OwnerUserId, actual.OwnerUserId); Assert.Equal(expected.Event, actual.Event); Assert.Equal(expected.Created, actual.Created); }
public void Notify(NotificationRecord target, IEnumerable <Item> items) { foreach (var item in items) { var id = int.Parse(target.Value); var message = target.Template.TemplateReplace(item); SendMessage(message, id); } }
static JObject MakeTransferJson(uint blockIndex, ushort txIndex, NotificationRecord notification, ulong timestamp, UInt160 transferAddress) => new JObject { ["timestamp"] = timestamp, ["asset_hash"] = notification.ScriptHash.ToString(), ["transfer_address"] = Neo.Wallets.Helper.ToAddress(transferAddress), ["amount"] = notification.State[2].GetInteger().ToString(), ["block_index"] = blockIndex, ["transfer_notify_index"] = txIndex, ["tx_hash"] = notification.InventoryHash.ToString(), };
public void AddGain(BidShopItemRecord item) { var client = WorldServer.Instance.GetOnlineClient(item.AccountId); string notification = "Banque : + " + item.Price + " Kamas (vente de " + item.Quantity + " <b>[" + item.Template.Name + "]</b>) hors ligne."; if (client != null) { AccountInformationsRecord.AddBankKamas(item.AccountId, item.Price); client.Character.OnItemSelled(item.GId, item.Quantity, item.Price); } else { AccountInformationsRecord.AddBankKamas(item.AccountId, item.Price); NotificationRecord.Add(item.AccountId, notification); } }
public async Task GetInvalidOwnerNotificationFailedTest() { var id = Guid.NewGuid(); var record = new NotificationRecord { OwnerUserId = Guid.NewGuid().ToString(), Id = id }; var store = new Mock <INotificationHistoryDataStore>(); store.Setup(x => x.FindAsync(It.Is <Guid>(guid => guid == id))) .ReturnsAsync(record); var service = new NotificationHistoryService(store.Object, DefaultMapper); await Assert.ThrowsAsync <NotFoundException>(() => service.GetAsync(new GetNotificationRequest(Guid.NewGuid().ToString(), id))); store.Verify(x => x.FindAsync(id), Times.Once); }
public IActionResult AddNotification([FromBody] NotificationRecordModel model) { if (!ModelState.IsValid) { return(BadRequest()); } NotificationRecord record = new NotificationRecord() { UserId = model.UserId, Date = model.Date, Text = model.Text }; var result = _repository.AddNotification(record); var createdRecordId = result.Entity.Id; return(Created("api/v1/notification/" + createdRecordId, createdRecordId)); }
public async Task <NotificationRecord> SaveAsync(NotificationRecord record) { try { var collectionUri = GetCollectionUri(); var storeEntity = new Models.NotificationRecord(); storeEntity = Mapper.Map(record, storeEntity); storeEntity.Created = DateTimeOffset.UtcNow; storeEntity.Id = Guid.NewGuid(); await Client.CreateDocumentAsync(collectionUri, storeEntity); return(Mapper.Map <Models.NotificationRecord, NotificationRecord>(storeEntity)); } catch (DocumentClientException e) { throw GetException(e); } }
public async Task AddAsync(MsgItem item) { var records = await _notificationRepo.GetAllAsync(); var groupName = item.Type.ToString(); var record = records.FirstOrDefault(x => x.Group == groupName); var now = _clock.UtcNow; item.CreatedTime = now; if (record == null) { record = new NotificationRecord { Group = groupName, Id = now, Items = new List <MsgItem> { item }, UpdateTime = now }; } else { record.Items.Insert(0, item); while (record.Items.Count > 10) { record.Items.RemoveAt(record.Items.Count - 1); } record.UpdateTime = now; } await _notificationRepo.UpsertAsync(record); var status = await _simpleDataStorage.GetOrDefaultAsync <NotificationCenterStatus>(); status.NewMessage = true; await _simpleDataStorage.SaveAsync(status); await _afEventHub.PublishAsync(new NewNotificationEvent()); }
public async Task ShouldPostAndGetTemplateLikedNotification() { var ownerId = "F8F98F91-339D-4453-87F3-AEC05AD976EE"; var notification = new NotificationRecord { OwnerUserId = ownerId, Parameters = new Dictionary <string, object> { { "UserIdWhoLiked", "14CFB9BC-9055-4E0B-A547-2F1A9208B45A" } } }; await Store.SaveAsync(notification); var fetchedNotifications = await Store.ListAsync(ownerId, pageSize, new FilterOptions()); Assert.True(fetchedNotifications.Count() == 1); var fetchedNotification = fetchedNotifications.First(); ValidateFetchedNotification(notification, fetchedNotification); }
public async IAsyncEnumerable <(uint blockIndex, NotificationRecord notification)> EnumerateNotificationsAsync(IReadOnlySet <UInt160>?contractFilter, IReadOnlySet <string>?eventFilter) { JObject contractsArg = (contractFilter ?? Enumerable.Empty <UInt160>()) .Select(c => (JString)c.ToString()) .ToArray(); JObject eventsArg = (eventFilter ?? Enumerable.Empty <string>()) .Select(e => (JString)e) .ToArray(); var count = 0; while (true) { var json = await rpcClient.RpcSendAsync("expressenumnotifications", contractsArg, eventsArg, count, 3) .ConfigureAwait(false); var truncated = json["truncated"].AsBoolean(); var values = (JArray)json["notifications"]; foreach (var v in values) { var blockIndex = (uint)v["block-index"].AsNumber(); var scriptHash = UInt160.Parse(v["script-hash"].AsString()); var eventName = v["event-name"].AsString(); var invType = (InventoryType)(byte)v["inventory-type"].AsNumber(); var invHash = UInt256.Parse(v["inventory-hash"].AsString()); var state = (Neo.VM.Types.Array)Neo.Network.RPC.Utility.StackItemFromJson(v["state"]); var notification = new NotificationRecord(scriptHash, eventName, state, invType, invHash); yield return(blockIndex, notification); } if (!truncated) { break; } count += values.Count; } }
public async Task WhenSenderSucceedsThenRecordCreatedTest() { var userId = Guid.NewGuid().ToString(); var request = new SendNotificationRequest { EventType = NotificationEvent.ArticleCreated, RecipientUserId = userId, Parameters = new Dictionary <string, object> { { "testKey", "testValue" } } }; var store = new Mock <ISettingsDataStore>(); store.Setup(x => x.FindAsync(It.Is <string>(s => s == userId))) .ReturnsAsync(new UserSettings { Id = Guid.NewGuid(), UserId = userId }); NotificationRecord newRecord = null; var historyStore = new Mock <INotificationHistoryDataStore>(); historyStore.Setup(x => x.SaveAsync(It.IsAny <NotificationRecord>())) .Callback <NotificationRecord>(record => { newRecord = record; newRecord.Id = Guid.NewGuid(); }) .ReturnsAsync(() => newRecord); var skippedResult = new NotificationSendingResult(NotificationType.Email); skippedResult.Skip(); var sender1 = new Mock <INotificationSender>(); sender1.Setup(x => x.SendAsync(It.IsAny <NotificationMessage>(), It.IsAny <UserSettings>())) .ReturnsAsync(skippedResult); var successfulResult = new NotificationSendingResult(NotificationType.Push); var sender2 = new Mock <INotificationSender>(); sender2.Setup(x => x.SendAsync(It.IsAny <NotificationMessage>(), It.IsAny <UserSettings>())) .ReturnsAsync(successfulResult); var senders = new List <INotificationSender> { sender1.Object, sender2.Object }; var service = new NotificationService(store.Object, senders, historyStore.Object, DefaultMapper); var result = await service.PostAsync(request); Assert.NotNull(result); historyStore.Verify(x => x.SaveAsync(It.IsAny <NotificationRecord>()), Times.Once); sender1.Verify(x => x.SendAsync(It.IsAny <NotificationMessage>(), It.IsAny <UserSettings>()), Times.Once); sender2.Verify(x => x.SendAsync(It.IsAny <NotificationMessage>(), It.IsAny <UserSettings>()), Times.Once); Assert.NotNull(result.NotificationRecordId); Assert.Equal(1, result.Results.Count); Assert.DoesNotContain(skippedResult, result.Results); Assert.Contains(successfulResult, result.Results); Assert.Equal(newRecord.Id, result.NotificationRecordId); Assert.Equal(request.RecipientUserId, newRecord.OwnerUserId); Assert.Equal(request.Parameters, newRecord.Parameters); }
// TODO: should the event name comparison be case insensitive? // Native contracts use "Transfer" while neon preview 3 compiled contracts use "transfer" static bool IsNep17Transfer(NotificationRecord notification) => notification.InventoryType == InventoryType.TX && notification.State.Count == 3 && (notification.EventName == "Transfer" || notification.EventName == "transfer");
private NotificationResponse PopulateNotificationResponse(NotificationRecord notification) { var response = Mapper.Map <NotificationResponse>(notification); return(response); }