Пример #1
0
        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);
            }
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        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);
                });
            }
        }
Пример #5
0
        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);
            }
        }
Пример #6
0
        private INotificationHistoryDataStore CreateNotificationClient()
        {
            var options            = ConfigurationHelper.GetDefaultDocumentDbNotification();
            var notificationClient = new NotificationRecordDataStore(new CosmosDbClientFactory(options), options, null);

            return(notificationClient);
        }