コード例 #1
0
        public void HandlePushNotificationExistingConversationTest()
        {
            List<List<ConversationModel>>  conversations = new List<List<ConversationModel>>();
            List<UserModel>  owners = new List<UserModel>();
            this.LoadConversations(conversations, owners);

            for (int i = 0; i < conversations.Count; i++)
            {
                if (conversations[i].Count == 0)
                {
                    return;
                }

                MockServiceProxy serviceProxy = new MockServiceProxy() { Conversations = conversations[i] };
                MockUserSettings userSettings = new MockUserSettings();
                MockDataContextWrapper dataContextWrapper = new MockDataContextWrapper(new MockDatabase() { Conversations = conversations[i] });
                userSettings.Save(owners[i]);

                using (AllConversationsViewModel allConversations = new AllConversationsViewModel(serviceProxy, userSettings, dataContextWrapper))
                {
                    allConversations.LoadInitialConversations();

                    NotifyCollectionChangedTester<ConversationModel> collectionChangedTester = new NotifyCollectionChangedTester<ConversationModel>(allConversations.Conversations);
                    long existingConversationId = conversations[i].Count > 0 ? conversations[i][0].ConversationId : long.MaxValue;
                    int existingConversationUserId = -1;

                    foreach (UserModel user in conversations[i][0].ConversationParticipants)
                    {
                        if (user.Id != owners[i].Id)
                        {
                            existingConversationUserId = user.Id;
                        }
                    }

                    foreach (ConversationModel conversation in conversations[i])
                    {
                        foreach (UserModel user in conversation.ConversationParticipants)
                        {
                            if (user.Id != owners[i].Id)
                            {
                                Assert.AreEqual(conversation, allConversations.GetConversationFromConversationId(conversation.ConversationId), "Conversation cannot be retrieved by guid");
                                Assert.AreEqual(conversation, allConversations.GetConversation(user.Id), "Conversation cannot be retrieved by recipient");
                            }
                        }
                    }

                    PushNotificationEvent pushEvent = new PushNotificationEvent(this, (long)2000, existingConversationId, "test", DateTime.Now.Ticks, "HandlePushNotificationExistingConversationTest" + i.ToString(), existingConversationUserId);
                    Messenger.Default.Send<PushNotificationEvent>(pushEvent);

                    Assert.AreEqual(collectionChangedTester.Count, 1, "Push notification was not handled. The new conversation was not added to the collection");
                }
            }
        }
コード例 #2
0
        public void NewAllConversationsViewModelTest()
        {
            for (int i = 0; i < this.conversations.Count; i++)
            {
                MockServiceProxy serviceProxy = new MockServiceProxy(this.conversations[i]);
                AllConversationsViewModel allConversations = new AllConversationsViewModel(serviceProxy);
                NotifyPropertyChangedTester propertyChangedTester = new NotifyPropertyChangedTester(allConversations);
                allConversations.LoadInitialConversations();

                Assert.AreEqual(1, propertyChangedTester.Changes.Count, "IsLoaded property changed event was not generated");
                propertyChangedTester.AssertChange(0, "IsLoaded");
            }
        }
コード例 #3
0
ファイル: YapperChatViewModel.cs プロジェクト: nrag/yapper
        public YapperChatViewModel(bool startup)
        {
            Messenger.Default.Register<RefreshGroupsEvent>(this, this.ReadGroupsRefreshContactsPage);

            this.conversationsViewModel = ViewModelLocator.Instance.CreateOrGetViewModel<AllConversationsViewModel>();
            this.newTaskCountViewModel = ViewModelLocator.Instance.CreateOrGetViewModel<NewTaskCountViewModel>();
            this.newMessageCountViewModel = ViewModelLocator.Instance.CreateOrGetViewModel<NewMessageCountViewModel>();

            if (!startup)
            {
                this.registeredUsersViewModel = ViewModelLocator.Instance.CreateOrGetViewModel<RegisteredUsersViewModel>();
                this.groupsViewModel = ViewModelLocator.Instance.CreateOrGetViewModel<AllGroupsViewModel>();
                this.tasksViewModel = ViewModelLocator.Instance.CreateOrGetViewModel<AllTasksViewModel>();
            }
        }
コード例 #4
0
ファイル: YapperChatViewModel.cs プロジェクト: nrag/yapper
        public YapperChatViewModel(bool startup)
        {
            Messenger.Default.Register <RefreshGroupsEvent>(this, this.ReadGroupsRefreshContactsPage);

            this.conversationsViewModel   = ViewModelLocator.Instance.CreateOrGetViewModel <AllConversationsViewModel>();
            this.newTaskCountViewModel    = ViewModelLocator.Instance.CreateOrGetViewModel <NewTaskCountViewModel>();
            this.newMessageCountViewModel = ViewModelLocator.Instance.CreateOrGetViewModel <NewMessageCountViewModel>();

            if (!startup)
            {
                this.registeredUsersViewModel = ViewModelLocator.Instance.CreateOrGetViewModel <RegisteredUsersViewModel>();
                this.groupsViewModel          = ViewModelLocator.Instance.CreateOrGetViewModel <AllGroupsViewModel>();
                this.tasksViewModel           = ViewModelLocator.Instance.CreateOrGetViewModel <AllTasksViewModel>();
            }
        }
コード例 #5
0
        public void HandlePushNotificationNewConversationTest()
        {
            List<List<ConversationModel>> conversations = new List<List<ConversationModel>>();
            List<UserModel> owners = new List<UserModel>();
            this.LoadConversations(conversations, owners);

            for (int i = 0; i < conversations.Count; i++)
            {
                MockServiceProxy serviceProxy = new MockServiceProxy() { Conversations = conversations[i] };
                MockUserSettings userSettings = new MockUserSettings();
                MockDataContextWrapper dataContextWrapper = new MockDataContextWrapper(new MockDatabase() { Conversations = conversations[i] });
                userSettings.Save(owners[i]);

                using (AllConversationsViewModel allConversations = new AllConversationsViewModel(serviceProxy, userSettings, dataContextWrapper))
                {
                    allConversations.LoadInitialConversations();

                    NotifyCollectionChangedTester<ConversationModel> collectionChangedTester = new NotifyCollectionChangedTester<ConversationModel>(allConversations.Conversations);
                    int newUserId = 5000;
                    long newConversationId = long.MaxValue;
                    Messenger.Default.Send<PushNotificationEvent>(new PushNotificationEvent(this, (long)2000, newConversationId, "test", DateTime.Now.Ticks, "HandlePushNotificationNewConversationTest" + i.ToString(), newUserId));

                    // We should be able to retrieve the new conversation by recipient and by conversation id
                    Assert.AreNotEqual(null, allConversations.GetConversation(newUserId));
                    Assert.AreNotEqual(null, allConversations.GetConversationFromConversationId(newConversationId));

                    // There should be one collection changed event
                    Assert.AreEqual(collectionChangedTester.Count, 1, "Push notification was not handled. The new conversation was not added to the collection");
                }
            }
        }
コード例 #6
0
        public void ServiceUpdateExistingConversationTest()
        {
            List<List<ConversationModel>> conversations = new List<List<ConversationModel>>();
            List<UserModel> owners = new List<UserModel>();
            this.LoadConversations(conversations, owners);

            for (int i = 0; i < conversations.Count; i++)
            {
                if (conversations[i].Count == 0)
                {
                    return;
                }

                List<ConversationModel> serviceConversation = new List<ConversationModel>();
                for (int j = 0; j < conversations[i].Count; j++)
                {
                    ConversationModel newConversation = new ConversationModel();
                    newConversation.ConversationId = conversations[i][j].ConversationId;
                    newConversation.ConversationParticipants = conversations[i][j].ConversationParticipants;
                    newConversation.LastPostUtcTime = DateTime.Now;
                    newConversation.LastPostPreview = "New message for conversation" + j.ToString();
                    serviceConversation.Add(newConversation);
                }

                MockServiceProxy serviceProxy = new MockServiceProxy() { Conversations = serviceConversation };
                MockUserSettings userSettings = new MockUserSettings();
                MockDataContextWrapper dataContextWrapper = new MockDataContextWrapper(new MockDatabase() { Conversations = conversations[i] });
                userSettings.Save(owners[i]);

                using (AllConversationsViewModel allConversations = new AllConversationsViewModel(serviceProxy, userSettings, dataContextWrapper))
                {
                    allConversations.LoadInitialConversations();

                    NotifyCollectionChangedTester<ConversationModel> collectionChangedTester = new NotifyCollectionChangedTester<ConversationModel>(allConversations.Conversations);

                    while (!allConversations.IsLoaded)
                    {
                        System.Threading.Thread.Sleep(1000);
                    }

                    Assert.AreEqual(collectionChangedTester.Count, serviceConversation.Count, "Service proxy changes weren't generated");

                    for (int j = 0; j < allConversations.Conversations.Count; j++)
                    {
                        Assert.AreEqual(allConversations.Conversations[j].LastPostUtcTime, serviceConversation[j].LastPostUtcTime, "Date didn't match with the service proxy update");
                        Assert.AreEqual(allConversations.Conversations[j].LastPostPreview, serviceConversation[j].LastPostPreview, "preview didn't match with the service proxy update");
                    }
                }
            }
        }
コード例 #7
0
        public void ServiceAddNewConversationTest()
        {
            List<List<ConversationModel>> conversations = new List<List<ConversationModel>>();
            List<UserModel> owners = new List<UserModel>();
            this.LoadConversations(conversations, owners);

            for (int i = 0; i < conversations.Count; i++)
            {
                if (conversations[i].Count == 0)
                {
                    return;
                }

                int newConversations = 3;
                MockUserSettings userSettings = new MockUserSettings();
                MockDataContextWrapper dataContextWrapper = new MockDataContextWrapper(new MockDatabase() { Conversations = conversations[i] });
                userSettings.Save(owners[i]);

                Random random = new Random((int)DateTime.Now.Ticks);
                List<ConversationModel> serviceConversation = new List<ConversationModel>();
                serviceConversation.AddRange(conversations[i]);
                long conversationIdGenerator = long.MaxValue;
                for (int j = 0; j < newConversations; j++)
                {
                    ConversationModel newConversation = new ConversationModel();
                    newConversation.ConversationId = conversationIdGenerator--;
                    newConversation.ConversationParticipants = new List<UserModel>();
                    newConversation.ConversationParticipants.Add(userSettings.Me);
                    newConversation.ConversationParticipants.Add(new UserModel() { Id = random.Next(100, 2000), Name = "ServiceAddNewConversationTestUser" + j.ToString(), PhoneNumber = "425 111 1111" });
                    newConversation.LastPostUtcTime = DateTime.Now;
                    newConversation.LastPostPreview = "New message for conversation" + j.ToString();
                    serviceConversation.Add(newConversation);
                }

                MockServiceProxy serviceProxy = new MockServiceProxy() { Conversations = serviceConversation };

                using (AllConversationsViewModel allConversations = new AllConversationsViewModel(serviceProxy, userSettings, dataContextWrapper))
                {
                    allConversations.LoadInitialConversations();

                    NotifyCollectionChangedTester<ConversationModel> collectionChangedTester = new NotifyCollectionChangedTester<ConversationModel>(allConversations.Conversations);

                    while (!allConversations.IsLoaded)
                    {
                        System.Threading.Thread.Sleep(1000);
                    }

                    Assert.AreEqual(newConversations, collectionChangedTester.Count, "Service proxy changes weren't generated");

                    for (int j = 0; j < allConversations.Conversations.Count; j++)
                    {
                        Assert.AreEqual(allConversations.Conversations[j].LastPostUtcTime, serviceConversation[j].LastPostUtcTime, "Date didn't match with the service proxy update");
                        Assert.AreEqual(allConversations.Conversations[j].LastPostPreview, serviceConversation[j].LastPostPreview, "preview didn't match with the service proxy update");
                    }

                    Assert.AreEqual(((MockTable<ConversationModel>)dataContextWrapper.Table<ConversationModel>()).Count, serviceConversation.Count, "New conversation was not inserted in to the database");
                }
            }
        }
コード例 #8
0
        public void NewAllConversationsViewModelTest()
        {
            List<List<ConversationModel>> conversations = new List<List<ConversationModel>>();
            List<UserModel> owners = new List<UserModel>();
            this.LoadConversations(conversations, owners);

            for (int i = 0; i < conversations.Count; i++)
            {
                MockServiceProxy serviceProxy = new MockServiceProxy() { };
                MockUserSettings userSettings = new MockUserSettings();
                MockDataContextWrapper dataContextWrapper = new MockDataContextWrapper(new MockDatabase() { Conversations = conversations[i] });
                userSettings.Save(owners[i]);

                using (AllConversationsViewModel allConversations = new AllConversationsViewModel(serviceProxy, userSettings, dataContextWrapper))
                {
                    NotifyPropertyChangedTester propertyChangedTester = new NotifyPropertyChangedTester(allConversations);
                    NotifyCollectionChangedTester<ConversationModel> collectionChangedTester = new NotifyCollectionChangedTester<ConversationModel>(allConversations.Conversations);
                    allConversations.LoadInitialConversations();

                    while (!allConversations.IsLoaded)
                    {
                        System.Threading.Thread.Sleep(1000);
                    }

                    Assert.AreEqual(1, propertyChangedTester.Changes.Count, "IsLoaded property changed event was not generated");
                    propertyChangedTester.AssertChange(0, "IsLoaded");

                    Assert.AreEqual(conversations[i].Count, collectionChangedTester.Count, "Number of conversations in notify collection changed doesn't match");
                }
            }
        }