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 async Task GetNotificationValidationFailedTest()
        {
            var store = new Mock <INotificationHistoryDataStore>();

            var service = new NotificationHistoryService(store.Object, DefaultMapper);
            await Assert.ThrowsAsync <ArgumentNullException>(() => service.GetAsync(null));

            store.Verify(x => x.FindAsync(It.IsAny <Guid>()), Times.Never);
        }
        public async Task DeleteAllSuccessTest()
        {
            var store = new Mock <INotificationHistoryDataStore>();

            var service = new NotificationHistoryService(store.Object, DefaultMapper);
            var userId  = Guid.NewGuid().ToString();
            var request = new UserRequest(userId);

            await service.DeleteAllAsync(request);

            store.Verify(x => x.DeleteAllAsync(userId), Times.Once);
        }
        public async Task GetMissingNotificationFailedTest()
        {
            var store = new Mock <INotificationHistoryDataStore>();

            store.Setup(x => x.FindAsync(It.IsAny <Guid>()))
            .ReturnsAsync((NotificationRecord)null);

            var id      = Guid.NewGuid();
            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 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 async Task ListRecordsValidationFailedTest()
        {
            var userId  = Guid.NewGuid().ToString();
            var results = new List <NotificationRecord>
            {
                new NotificationRecord
                {
                    Event       = NotificationEvent.ArticleCreated,
                    OwnerUserId = userId,
                    Id          = Guid.NewGuid(),
                    Parameters  = new Dictionary <string, object> {
                        { "testKey", "testValue" }
                    }
                },
                new NotificationRecord
                {
                    Event       = NotificationEvent.CommentLiked,
                    OwnerUserId = userId,
                    Id          = Guid.NewGuid(),
                    Parameters  = new Dictionary <string, object> {
                        { "testKey2", "testValue2" }
                    }
                }
            };
            var store = new Mock <INotificationHistoryDataStore>();

            store.Setup(x => x.ListAsync(It.Is <string>(s => s == userId), It.IsAny <int>(), It.IsAny <FilterOptions>()))
            .ReturnsAsync(results);

            var service  = new NotificationHistoryService(store.Object, DefaultMapper);
            var response = await service.ListAsync(new GetNotificationsRequest(userId, new FilterOptions(), 5));

            Assert.NotNull(response);
            Assert.Equal(results.Count, response.ItemsCount);
            Assert.All(response.Results, notificationResponse =>
            {
                var item = results.First(x => x.Id == notificationResponse.Id);
                ValidateRecords(item, notificationResponse);
            });
        }