public async Task DeleteAllTest() { var userId = Guid.NewGuid().ToString(); using (var context = GetContext()) { await context.NotificationRecords.AddAsync(new Models.NotificationRecord { Created = DateTimeOffset.UtcNow, Id = Guid.NewGuid(), Event = NotificationEvent.PackageArrived, OwnerUserId = userId, Parameters = new Dictionary <string, object> { { "test", "value" } } }); await context.SaveChangesAsync(); } using (var context = GetContext()) { var store = new NotificationRecordDataStore(context, DefaultMapper); await store.DeleteAllAsync(userId); Assert.Empty(context.NotificationRecords); } }
public async Task FindRecordAsync() { var record = new Models.NotificationRecord { Created = DateTimeOffset.UtcNow, Id = Guid.NewGuid(), Event = NotificationEvent.PackageArrived, OwnerUserId = Guid.NewGuid().ToString(), Parameters = new Dictionary <string, object> { { "test", "value" } } }; using (var context = GetContext()) { await context.NotificationRecords.AddAsync(record); await context.SaveChangesAsync(); } using (var context = GetContext()) { var store = new NotificationRecordDataStore(context, DefaultMapper); var result = await store.FindAsync(record.Id); Assert.NotNull(result); Assert.Equal(record.Created, result.Created); Assert.Equal(record.Event, result.Event); Assert.Equal(record.OwnerUserId, result.OwnerUserId); } }
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 async Task ListRecordsFilterTest(DateTimeOffset?startTime, DateTimeOffset?endTime, IList <Guid> expectedIds) { var userId = Guid.NewGuid().ToString(); var filter = new FilterOptions(startTime, endTime); var records = CreateRecords(userId); using (var context = GetContext()) { await context.NotificationRecords.AddRangeAsync(records); await context.SaveChangesAsync(); } using (var context = GetContext()) { var store = new NotificationRecordDataStore(context, DefaultMapper); var results = await store.ListAsync(userId, 5, filter); Assert.NotNull(results); expectedIds.All(x => { Assert.Contains(results, y => y.Id == x); return(true); }); } }
public async Task ListRecordsPageSizeTest(int size, int expectedSize) { var userId = Guid.NewGuid().ToString(); var records = CreateRecords(userId); using (var context = GetContext()) { await context.NotificationRecords.AddRangeAsync(records); await context.SaveChangesAsync(); } using (var context = GetContext()) { var store = new NotificationRecordDataStore(context, DefaultMapper); var results = await store.ListAsync(userId, size); Assert.NotNull(results); Assert.Equal(expectedSize, results.Count()); var expected = records.OrderByDescending(x => x.Created).Take(size).ToList(); expected.ForEach(x => Assert.Contains(results, y => y.Id == x.Id)); Assert.Equal(records.Last().Id, results.First().Id); } }
private INotificationHistoryDataStore CreateNotificationClient() { var options = ConfigurationHelper.GetDefaultDocumentDbNotification(); var notificationClient = new NotificationRecordDataStore(new CosmosDbClientFactory(options), options, null); return(notificationClient); }