コード例 #1
0
        public async Task SendAsync_OrderedNotificationsUpdateFailed_ThrowsInvalidOperationException()
        {
            // Arrange
            NotificationStorage
            .Setup(m => m.StoreEnvelopeAsync(DispatchedNotification.To.ToIdentity(), DispatchedNotification))
            .ReturnsAsync(true)
            .Verifiable();

            NotificationStorage
            .Setup(m => m.StoreEnvelopeAsync(FailedNotification.To.ToIdentity(), FailedNotification))
            .ReturnsAsync(false)
            .Verifiable();

            NotificationStorage
            .Setup(m => m.DeleteEnvelopeAsync(FailedNotification.To.ToIdentity(), DispatchedNotification.Id))
            .ReturnsAsync(true)
            .Verifiable();

            NotificationStorage
            .SetupSequence(m => m.GetEnvelopeAsync(DispatchedNotification.To.ToIdentity(), DispatchedNotification.Id))
            .Returns(Task.FromResult <Notification>(null))
            .Returns(Task.FromResult <Notification>(DispatchedNotification));

            // Act
            await Target.Value.SendAsync(DispatchedNotification, CancellationToken);

            await Target.Value.SendAsync(FailedNotification, CancellationToken).ShouldThrowAsync <InvalidOperationException>();
        }
コード例 #2
0
        public async Task SendAsync_OrderedNotifications_UpdatesOnStorage()
        {
            // Arrange
            NotificationStorage
            .Setup(m => m.StoreEnvelopeAsync(DispatchedNotification.To.ToIdentity(), DispatchedNotification))
            .ReturnsAsync(true)
            .Verifiable();

            NotificationStorage
            .Setup(m => m.StoreEnvelopeAsync(FailedNotification.To.ToIdentity(), FailedNotification))
            .ReturnsAsync(true)
            .Verifiable();

            NotificationStorage
            .Setup(m => m.DeleteEnvelopeAsync(FailedNotification.To.ToIdentity(), DispatchedNotification.Id))
            .ReturnsAsync(true)
            .Verifiable();

            NotificationStorage
            .SetupSequence(m => m.GetEnvelopeAsync(DispatchedNotification.To.ToIdentity(), DispatchedNotification.Id))
            .Returns(Task.FromResult <Notification>(null))
            .Returns(Task.FromResult <Notification>(DispatchedNotification));

            // Act
            await Target.Value.SendAsync(DispatchedNotification, CancellationToken);

            await Target.Value.SendAsync(FailedNotification, CancellationToken);

            // Assert
            NotificationStorage.Verify();
        }
コード例 #3
0
        public async Task SendAsync_NotificationStorageFailed_ThrowsInvalidOperationException()
        {
            // Arrange
            NotificationStorage
            .Setup(m => m.StoreEnvelopeAsync(DispatchedNotification.To.ToIdentity(), DispatchedNotification))
            .ReturnsAsync(false);

            // Act
            await Target.Value.SendAsync(DispatchedNotification, CancellationToken).ShouldThrowAsync <InvalidOperationException>();
        }
コード例 #4
0
        public async Task SendAsync_FailedNotification_SendsToStorage()
        {
            // Arrange
            NotificationStorage
            .Setup(m => m.StoreEnvelopeAsync(FailedNotification.To.ToIdentity(), FailedNotification))
            .ReturnsAsync(true)
            .Verifiable();

            // Act
            await Target.Value.SendAsync(FailedNotification, CancellationToken);

            // Assert
            NotificationStorage.Verify();
        }
コード例 #5
0
        public async Task ProcessMessageAsync_ValidMessageFailedNotification_ReturnsNotification()
        {
            // Arrange
            NotificationStorage
            .Setup(n => n.StoreEnvelopeAsync(It.IsAny <Identity>(), It.IsAny <Notification>()))
            .ReturnsAsync(true);

            // Act
            var notificationTask = Target.Value.ProcessMessageAsync(TextMessage, WaitUntilEvent, CancellationToken);
            await Target.Value.SendAsync(AcceptedNotification, CancellationToken);

            await Target.Value.SendAsync(FailedNotification, CancellationToken);

            // Assert
            var actual = await notificationTask;

            actual.ShouldBe(FailedNotification);
        }
コード例 #6
0
        public async Task ProcessCommandAsync_ValidCommand_ReturnsResponse()
        {
            // Arrange
            NotificationStorage
            .Setup(n => n.StoreEnvelopeAsync(It.IsAny <Identity>(), It.IsAny <Notification>()))
            .ReturnsAsync(true);

            // Act
            var commandTask = Target.Value.ProcessCommandAsync(PresenceRequestCommand, CancellationToken);
            await Target.Value.SendAsync(PresenceResponseCommand, CancellationToken);

            // Assert
            var actual = await commandTask;

            actual.ShouldBe(PresenceResponseCommand);

            // Check for the removal of the pending notification
            NotificationStorage.Verify(n => n.StoreEnvelopeAsync(It.IsAny <Identity>(), It.IsAny <Notification>()), Times.Never());
            await Target.Value.SendAsync(DispatchedNotification, CancellationToken);

            NotificationStorage.Verify(n => n.StoreEnvelopeAsync(It.IsAny <Identity>(), It.IsAny <Notification>()), Times.Once());
        }
コード例 #7
0
        public async Task SendAsync_UnorderedNotificationsWithFailed_KeepsTheLastestOnStorage()
        {
            // Arrange
            NotificationStorage
            .Setup(m => m.StoreEnvelopeAsync(FailedNotification.To.ToIdentity(), FailedNotification))
            .ReturnsAsync(true)
            .Verifiable();

            NotificationStorage
            .SetupSequence(m => m.GetEnvelopeAsync(FailedNotification.To.ToIdentity(), FailedNotification.Id))
            .Returns(Task.FromResult <Notification>(null))
            .Returns(Task.FromResult <Notification>(FailedNotification));

            // Act
            await Target.Value.SendAsync(FailedNotification, CancellationToken);

            await Target.Value.SendAsync(AcceptedNotification, CancellationToken);

            // Assert
            NotificationStorage.Verify();
            NotificationStorage.Verify(m => m.StoreEnvelopeAsync(AcceptedNotification.To.ToIdentity(), AcceptedNotification), Times.Never());
            NotificationStorage.Verify(m => m.DeleteEnvelopeAsync(FailedNotification.To.ToIdentity(), FailedNotification.Id), Times.Never());
        }
コード例 #8
0
        public async Task ProcessMessageAsync_ValidMessage_ReturnsNotification()
        {
            // Arrange
            NotificationStorage
            .Setup(n => n.StoreEnvelopeAsync(It.IsAny <Identity>(), It.IsAny <Notification>()))
            .ReturnsAsync(true);

            // Act
            var notificationTask = Target.Value.ProcessMessageAsync(TextMessage, WaitUntilEvent, CancellationToken);
            await Target.Value.SendAsync(AcceptedNotification, CancellationToken);

            await Target.Value.SendAsync(DispatchedNotification, CancellationToken);

            // Assert
            var actual = await notificationTask;

            actual.ShouldBe(DispatchedNotification);

            // Check for the removal of the pending notification
            NotificationStorage.Verify(n => n.StoreEnvelopeAsync(It.IsAny <Identity>(), It.IsAny <Notification>()), Times.Never());
            await Target.Value.SendAsync(DispatchedNotification, CancellationToken);

            NotificationStorage.Verify(n => n.StoreEnvelopeAsync(It.IsAny <Identity>(), It.IsAny <Notification>()), Times.Once());
        }
コード例 #9
0
ファイル: DataSource.cs プロジェクト: fbmnds/GitMe
        /// <summary>
        /// throws exception
        /// </summary>
        /// <param name="page"></param>
        /// <param name="notes"></param>
        /// <returns></returns>
        private async Task ProcessFetchedDataAsync(List <Octokit.Notification> notes)
        {
            if (notificationStore == null)
            {
                notificationStore = new NotificationStorage();
            }
            if (repositoryStore == null)
            {
                repositoryStore = new RepositoryStorage();
            }
            if (userStore == null)
            {
                userStore = new UserStorage();
            }

            var dict = new UpdatableDictionary <int, DenormalizedNotification>();

            if (_notes != null)
            {
                foreach (var item in _notes)
                {
                    var _item = item as DenormalizedNotification;
                    dict.UpdateOrInsert(_item.Id, _item);
                }
            }

            foreach (var note in notes)
            {
                try
                {
                    string responseBuffer = await GetDetailsResponse(note.Subject.LatestCommentUrl);

                    Response details = Serializer.DeserializeToResponse(responseBuffer);

                    int id;
                    if (!Int32.TryParse(note.Id, out id))
                    {
                        throw new ArgumentException();
                    }
                    string userimagepath = await GetImagePath(details.User.Id.ToString(), Constants.AvatarSize);

                    var newNote = new DenormalizedNotification(id,
                                                               details.HtmlUrl,
                                                               details.User.Login,
                                                               note.Repository.FullName,
                                                               note.Subject.Title,
                                                               userimagepath,
                                                               DateTimeHelper.ParsedOrDefaultDateTime(note.UpdatedAt),
                                                               details.Body);

                    dict.UpdateOrInsert(newNote.Id, newNote);

                    notificationStore.UpdateOrInsert(id, note, details);
                    repositoryStore.UpdateOrInsert(id, note, details);
                    userStore.UpdateOrInsert(id, note, details);
                }
                catch
                {
                    // ignore
#if DEBUG
                    throw;
#endif
                }
            }
            _notes = new ObservableCollection <IDataItem>();
            var list = dict.Values.OrderByDescending(i => i.UpdatedAt).Take(Constants.NotificationStorageMaxSize);
            foreach (var value in list)
            {
                _notes.Add(value);
            }
        }
コード例 #10
0
ファイル: DataSource.cs プロジェクト: fbmnds/GitMe
        public static async Task LoadDenormalizeNotificationsAsync()
        {
            if (notificationStore == null)
            {
                notificationStore = new NotificationStorage();
            }
            if (repositoryStore == null)
            {
                repositoryStore = new RepositoryStorage();
            }
            if (userStore == null)
            {
                userStore = new UserStorage();
            }

            //await GetStorageFileAsync("Repositories");
            //await GetStorageFileAsync("Users");
            await GetStorageFileAsync("Notifications");

            if (notificationStore == null)
            {
                notificationStore = new NotificationStorage();
                return;
            }

            if (notificationStore.Count == 0)
            {
                return;
            }

            var dict = new UpdatableDictionary <int, DenormalizedNotification>();

            if (_notes.Count > 0)
            {
                foreach (var item in _notes)
                {
                    var _item = item as DenormalizedNotification;
                    dict.UpdateOrInsert(_item.Id, _item);
                }
            }

            foreach (var note in notificationStore.Values)
            {
                string imagePath = await GetImagePath(note.UserId.ToString(), Constants.AvatarSize);

                try
                {
                    var denormalizedNote = new DenormalizedNotification(note.Id,
                                                                        note.HtmlUrl,
                                                                        note.UserLogin,
                                                                        note.RepoFullName,
                                                                        note.SubjectTitle,
                                                                        imagePath,
                                                                        DateTimeHelper.ParsedOrDefaultDateTime(note.TimeStamp),
                                                                        note.Body);
                    dict.UpdateOrInsert(denormalizedNote.Id, denormalizedNote);
                }
                catch
                {
                    //ignore
                }
            }

            _notes = new ObservableCollection <IDataItem>();
            var list = dict.Values.OrderByDescending(i => i.UpdatedAt).Take(Constants.NotificationStorageMaxSize);

            foreach (var value in list)
            {
                _notes.Add(value);
            }
        }
コード例 #11
0
ファイル: JsonHelper.cs プロジェクト: fbmnds/GitMe
        public static dynamic DeserializeToStorage(string storageType, string storageText)
        {
            JsonObject storageJsonObject;
            JsonArray  storageJsonArray;

            dynamic jsonStore;

            switch (storageType)
            {
            case "Notifications":
                jsonStore = new NotificationStorage();
                break;

            case "Repositories":
                jsonStore = new RepositoryStorage();
                break;

            case "Users":
                jsonStore = new UserStorage();
                break;

            default:
                throw new System.ArgumentException(storageType);
            }

            try
            {
                storageJsonObject = JsonObject.Parse(storageText);
                storageJsonArray  = storageJsonObject[storageType].GetArray();
            }
            catch
            {
                return(jsonStore);
            }

            foreach (JsonValue storageValue in storageJsonArray)
            {
                try
                {
                    dynamic storageItem;

                    switch (storageType)
                    {
                    case "Notifications":
                        storageItem = Serializer.DeserializeToNotification(storageValue.Stringify());
                        storageItem.SubjectTitle = DecodeBase64(storageItem.SubjectTitle);
                        storageItem.Body         = DecodeBase64(storageItem.Body);
                        jsonStore.UpdateOrInsert(storageItem.Id, storageItem);
                        break;

                    case "Repositories":
                        storageItem = Serializer.DeserializeToRepository(storageValue.Stringify());
                        jsonStore.UpdateOrInsert(storageItem.Id, storageItem);
                        break;

                    case "Users":
                        storageItem = Serializer.DeserializeToUser(storageValue.Stringify());
                        jsonStore.UpdateOrInsert(storageItem.Id, storageItem);
                        break;

                    default:
                        throw new System.ArgumentException(storageType);
                    }
                }
                catch
                {
                    throw;
                }
            }
            return(jsonStore);
        }