public void TestAddContactReverseAlphabeticalOrder() { MockServiceProxy serviceProxy = new MockServiceProxy() { Users = new List <UserModel>() }; MockUserSettings userSettings = new MockUserSettings(); MockDataContextWrapper dataContextWrapper = new MockDataContextWrapper(new MockDatabase() { Users = new List <UserModel>() }); MockContactSearchController searchController = new MockContactSearchController() { Users = new List <UserModel>() }; RegisteredUsersViewModel ruvm = new RegisteredUsersViewModel(serviceProxy, userSettings, dataContextWrapper, searchController); // start loading the users from database ruvm.Search(); while (ruvm.IsLoading) { System.Threading.Thread.Sleep(1000); } NotifyCollectionOfCollectionChangedTester <UserModel> collectionChanged = new NotifyCollectionOfCollectionChangedTester <UserModel>(ruvm.RegisteredUsers); // Sort it in reverse order this.users.Sort((x, y) => { return(-1 * string.Compare(x.Name, y.Name, StringComparison.OrdinalIgnoreCase)); }); for (int i = 0; i < this.users.Count; i++) { Messenger.Default.Send <NewContactEvent>(new NewContactEvent() { Contact = this.users[i] }, userSettings); } Assert.AreEqual(this.users.Count, collectionChanged.Count, "The contact should not be added"); Assert.AreEqual(this.users.Count, ((MockTable <UserModel>)dataContextWrapper.Table <UserModel>()).Count, "The database was not supposed to be modified."); // Sort it in alphabetical order and attempt to insert again this.users.Sort((x, y) => { return(string.Compare(x.Name, y.Name, StringComparison.OrdinalIgnoreCase)); }); for (int i = 0; i < this.users.Count; i++) { Messenger.Default.Send <NewContactEvent>(new NewContactEvent() { Contact = this.users[i] }, userSettings); } Assert.AreEqual(this.users.Count, collectionChanged.Count, "The contact should not be added"); Assert.AreEqual(this.users.Count, ((MockTable <UserModel>)dataContextWrapper.Table <UserModel>()).Count, "The database was not supposed to be modified."); }
public void LoadContactsFromService() { MockServiceProxy serviceProxy = new MockServiceProxy() { Users = this.users }; MockUserSettings userSettings = new MockUserSettings(); MockDataContextWrapper dataContextWrapper = new MockDataContextWrapper(new MockDatabase()); MockContactSearchController searchController = new MockContactSearchController() { Users = this.users }; RegisteredUsersViewModel ruvm = new RegisteredUsersViewModel(serviceProxy, userSettings, dataContextWrapper, searchController); // start loading the users from database NotifyCollectionOfCollectionChangedTester <UserModel> collectionChanged = new NotifyCollectionOfCollectionChangedTester <UserModel>(ruvm.RegisteredUsers); ruvm.Search(); while (ruvm.IsLoading) { System.Threading.Thread.Sleep(1000); } Assert.AreEqual(this.users.Count, collectionChanged.Count, "The users were not read from the database correctly"); Assert.AreEqual(this.users.Count, ((MockTable <UserModel>)dataContextWrapper.Table <UserModel>()).Count, "The database was not supposed to be modified."); }
public void LoadContactsFromDatabase() { MockServiceProxy serviceProxy = new MockServiceProxy() { }; MockUserSettings userSettings = new MockUserSettings(); MockDataContextWrapper dataContextWrapper = new MockDataContextWrapper(new MockDatabase() {Users = this.users}); MockContactSearchController searchController = new MockContactSearchController(); RegisteredUsersViewModel ruvm = new RegisteredUsersViewModel(serviceProxy, userSettings, dataContextWrapper, searchController); // start loading the users from database NotifyCollectionOfCollectionChangedTester<UserModel> collectionChanged = new NotifyCollectionOfCollectionChangedTester<UserModel>(ruvm.RegisteredUsers); ruvm.Search(); Assert.AreEqual(this.users.Count, collectionChanged.Count, "The users were not read from the database correctly"); Assert.AreEqual(this.users.Count, ((MockTable<UserModel>)dataContextWrapper.Table<UserModel>()).Count, "The database was not supposed to be modified."); }
public void LoadContactsFromDatabaseAndAddNewContact() { MockServiceProxy serviceProxy = new MockServiceProxy() { Users = this.users }; MockUserSettings userSettings = new MockUserSettings(); MockDataContextWrapper dataContextWrapper = new MockDataContextWrapper(new MockDatabase() { Users = this.users }); MockContactSearchController searchController = new MockContactSearchController() { Users = this.users }; RegisteredUsersViewModel ruvm = new RegisteredUsersViewModel(serviceProxy, userSettings, dataContextWrapper, searchController); // start loading the users from database ruvm.Search(); while (ruvm.IsLoading) { System.Threading.Thread.Sleep(1000); } Random random = new Random(); UserModel user = new UserModel() { Id = random.Next(100, 500), Name = "LoadContactsFromDatabaseAndNewServiceContacts", PhoneNumber = "+1 100-200-3000" }; NotifyCollectionOfCollectionChangedTester <UserModel> collectionChanged = new NotifyCollectionOfCollectionChangedTester <UserModel>(ruvm.RegisteredUsers); Messenger.Default.Send <NewContactEvent>(new NewContactEvent() { Contact = user }, userSettings); Assert.AreEqual(1, collectionChanged.Count, "The contact was not added"); Assert.AreEqual(this.users.Count + 1, ((MockTable <UserModel>)dataContextWrapper.Table <UserModel>()).Count, "The database was not supposed to be modified."); }
public void LoadContactsFromDatabaseAndAddExistingContact() { MockServiceProxy serviceProxy = new MockServiceProxy() { Users = this.users }; MockUserSettings userSettings = new MockUserSettings(); MockDataContextWrapper dataContextWrapper = new MockDataContextWrapper(new MockDatabase() { Users = this.users }); MockContactSearchController searchController = new MockContactSearchController() { Users = this.users }; RegisteredUsersViewModel ruvm = new RegisteredUsersViewModel(serviceProxy, userSettings, dataContextWrapper, searchController); // start loading the users from database ruvm.Search(); while (ruvm.IsLoading) { System.Threading.Thread.Sleep(1000); } NotifyCollectionOfCollectionChangedTester <UserModel> collectionChanged = new NotifyCollectionOfCollectionChangedTester <UserModel>(ruvm.RegisteredUsers); Messenger.Default.Send <NewContactEvent>(new NewContactEvent() { Contact = this.users[0] }); Assert.AreEqual(0, collectionChanged.Count, "The contact should not be added"); Assert.AreEqual(this.users.Count, ((MockTable <UserModel>)dataContextWrapper.Table <UserModel>()).Count, "The database was not supposed to be modified."); }
public void TestContactGroups() { MockServiceProxy serviceProxy = new MockServiceProxy() { Users = new List <UserModel>() }; MockUserSettings userSettings = new MockUserSettings(); MockDataContextWrapper dataContextWrapper = new MockDataContextWrapper(new MockDatabase() { Users = new List <UserModel>() }); MockContactSearchController searchController = new MockContactSearchController() { Users = new List <UserModel>() }; RegisteredUsersViewModel ruvm = new RegisteredUsersViewModel(serviceProxy, userSettings, dataContextWrapper, searchController); // start loading the users from database ruvm.Search(); while (ruvm.IsLoading) { System.Threading.Thread.Sleep(1000); } NotifyCollectionOfCollectionChangedTester <UserModel> collectionChanged = new NotifyCollectionOfCollectionChangedTester <UserModel>(ruvm.RegisteredUsers); int id = 1; // Add one user whose first letter is 't' UserModel tUser = new UserModel() { Name = "tUser", Id = id++, PhoneNumber = "123 456 789" + id }; Messenger.Default.Send <NewContactEvent>(new NewContactEvent() { Contact = tUser }, userSettings); Assert.AreEqual(1, collectionChanged.Count, "The contact should not be added"); Assert.AreEqual(1, ((MockTable <UserModel>)dataContextWrapper.Table <UserModel>()).Count, "The database was not supposed to be modified."); Assert.AreEqual(1, ruvm.RegisteredUsers.Count, "Wrong number of contact groups created"); // Add another user whose first letter is 'd' UserModel dUser = new UserModel() { Name = "dUser", Id = id++, PhoneNumber = "123 456 789" + id }; Messenger.Default.Send <NewContactEvent>(new NewContactEvent() { Contact = dUser }, userSettings); Assert.AreEqual(2, collectionChanged.Count, "The contact should not be added"); Assert.AreEqual(2, ((MockTable <UserModel>)dataContextWrapper.Table <UserModel>()).Count, "The database was not supposed to be modified."); Assert.AreEqual(2, ruvm.RegisteredUsers.Count, "Wrong number of contact groups created"); // Add another user whose first letter is 's' UserModel sUser = new UserModel() { Name = "sUser", Id = id++, PhoneNumber = "123 456 789" + id }; Messenger.Default.Send <NewContactEvent>(new NewContactEvent() { Contact = sUser }, userSettings); Assert.AreEqual(3, collectionChanged.Count, "The contact should not be added"); Assert.AreEqual(3, ((MockTable <UserModel>)dataContextWrapper.Table <UserModel>()).Count, "The database was not supposed to be modified."); Assert.AreEqual(3, ruvm.RegisteredUsers.Count, "Wrong number of contact groups created"); // Add another user whose first letter is 'd' UserModel dSecondUser = new UserModel() { Name = "dSecondUser", Id = id++, PhoneNumber = "123 456 789" + id }; Messenger.Default.Send <NewContactEvent>(new NewContactEvent() { Contact = dSecondUser }, userSettings); Assert.AreEqual(4, collectionChanged.Count, "The contact should not be added"); Assert.AreEqual(4, ((MockTable <UserModel>)dataContextWrapper.Table <UserModel>()).Count, "The database was not supposed to be modified."); Assert.AreEqual(3, ruvm.RegisteredUsers.Count, "Wrong number of contact groups created"); // Add another user whose first letter is 's'. UserModel sSecondUser = new UserModel() { Name = "sSecondUser", Id = id++, PhoneNumber = "123 456 789" + id }; Messenger.Default.Send <NewContactEvent>(new NewContactEvent() { Contact = sSecondUser }, userSettings); Assert.AreEqual(5, collectionChanged.Count, "The contact should not be added"); Assert.AreEqual(5, ((MockTable <UserModel>)dataContextWrapper.Table <UserModel>()).Count, "The database was not supposed to be modified."); Assert.AreEqual(3, ruvm.RegisteredUsers.Count, "Wrong number of contact groups created"); // Add another user whose first letter is 's'. Try different position in // the 's' groups sorted list UserModel sZUser = new UserModel() { Name = "sZUser", Id = id++, PhoneNumber = "123 456 789" + id }; Messenger.Default.Send <NewContactEvent>(new NewContactEvent() { Contact = sZUser }, userSettings); Assert.AreEqual(6, collectionChanged.Count, "The contact should not be added"); Assert.AreEqual(6, ((MockTable <UserModel>)dataContextWrapper.Table <UserModel>()).Count, "The database was not supposed to be modified."); Assert.AreEqual(3, ruvm.RegisteredUsers.Count, "Wrong number of contact groups created"); }
public void LoadContactsFromDatabaseAndNewServiceContacts() { List <UserModel> newUsers = new List <UserModel>(); Random random = new Random(); for (int i = 0; i < 5; i++) { newUsers.Add(new UserModel() { Id = 1000 + 100 * i, Name = "LoadContactsFromDatabaseAndNewServiceContacts" + i, PhoneNumber = "+1 100-200-300" + i }); } MockServiceProxy serviceProxy = new MockServiceProxy() { Users = newUsers }; MockUserSettings userSettings = new MockUserSettings(); MockDataContextWrapper dataContextWrapper = new MockDataContextWrapper(new MockDatabase() { Users = this.users }); MockContactSearchController searchController = new MockContactSearchController() { Users = newUsers }; RegisteredUsersViewModel ruvm = new RegisteredUsersViewModel(serviceProxy, userSettings, dataContextWrapper, searchController); // start loading the users from database NotifyCollectionOfCollectionChangedTester <UserModel> collectionChanged = new NotifyCollectionOfCollectionChangedTester <UserModel>(ruvm.RegisteredUsers); ruvm.Search(); while (ruvm.IsLoading) { System.Threading.Thread.Sleep(1000); } Assert.AreEqual(this.users.Count + newUsers.Count, collectionChanged.Count, "The users were not read from the database correctly"); Assert.AreEqual(this.users.Count + newUsers.Count, ((MockTable <UserModel>)dataContextWrapper.Table <UserModel>()).Count, "The database was not supposed to be modified."); }
public void LoadContactsFromDatabaseAndAddExistingContact() { MockServiceProxy serviceProxy = new MockServiceProxy() { Users = this.users }; MockUserSettings userSettings = new MockUserSettings(); MockDataContextWrapper dataContextWrapper = new MockDataContextWrapper(new MockDatabase() { Users = this.users }); MockContactSearchController searchController = new MockContactSearchController() { Users = this.users }; RegisteredUsersViewModel ruvm = new RegisteredUsersViewModel(serviceProxy, userSettings, dataContextWrapper, searchController); // start loading the users from database ruvm.Search(); while (ruvm.IsLoading) { System.Threading.Thread.Sleep(1000); } NotifyCollectionOfCollectionChangedTester<UserModel> collectionChanged = new NotifyCollectionOfCollectionChangedTester<UserModel>(ruvm.RegisteredUsers); Messenger.Default.Send<NewContactEvent>(new NewContactEvent() { Contact = this.users[0] }); Assert.AreEqual(0, collectionChanged.Count, "The contact should not be added"); Assert.AreEqual(this.users.Count, ((MockTable<UserModel>)dataContextWrapper.Table<UserModel>()).Count, "The database was not supposed to be modified."); }
public void TestContactGroups() { MockServiceProxy serviceProxy = new MockServiceProxy() { Users = new List<UserModel>() }; MockUserSettings userSettings = new MockUserSettings(); MockDataContextWrapper dataContextWrapper = new MockDataContextWrapper(new MockDatabase() { Users = new List<UserModel>() }); MockContactSearchController searchController = new MockContactSearchController() { Users = new List<UserModel>() }; RegisteredUsersViewModel ruvm = new RegisteredUsersViewModel(serviceProxy, userSettings, dataContextWrapper, searchController); // start loading the users from database ruvm.Search(); while (ruvm.IsLoading) { System.Threading.Thread.Sleep(1000); } NotifyCollectionOfCollectionChangedTester<UserModel> collectionChanged = new NotifyCollectionOfCollectionChangedTester<UserModel>(ruvm.RegisteredUsers); int id = 1; // Add one user whose first letter is 't' UserModel tUser = new UserModel() { Name = "tUser", Id = id++, PhoneNumber = "123 456 789" + id }; Messenger.Default.Send<NewContactEvent>(new NewContactEvent() { Contact = tUser }, userSettings); Assert.AreEqual(1, collectionChanged.Count, "The contact should not be added"); Assert.AreEqual(1, ((MockTable<UserModel>)dataContextWrapper.Table<UserModel>()).Count, "The database was not supposed to be modified."); Assert.AreEqual(1, ruvm.RegisteredUsers.Count, "Wrong number of contact groups created"); // Add another user whose first letter is 'd' UserModel dUser = new UserModel() { Name = "dUser", Id = id++, PhoneNumber = "123 456 789" + id }; Messenger.Default.Send<NewContactEvent>(new NewContactEvent() { Contact = dUser }, userSettings); Assert.AreEqual(2, collectionChanged.Count, "The contact should not be added"); Assert.AreEqual(2, ((MockTable<UserModel>)dataContextWrapper.Table<UserModel>()).Count, "The database was not supposed to be modified."); Assert.AreEqual(2, ruvm.RegisteredUsers.Count, "Wrong number of contact groups created"); // Add another user whose first letter is 's' UserModel sUser = new UserModel() { Name = "sUser", Id = id++, PhoneNumber = "123 456 789" + id }; Messenger.Default.Send<NewContactEvent>(new NewContactEvent() { Contact = sUser }, userSettings); Assert.AreEqual(3, collectionChanged.Count, "The contact should not be added"); Assert.AreEqual(3, ((MockTable<UserModel>)dataContextWrapper.Table<UserModel>()).Count, "The database was not supposed to be modified."); Assert.AreEqual(3, ruvm.RegisteredUsers.Count, "Wrong number of contact groups created"); // Add another user whose first letter is 'd' UserModel dSecondUser = new UserModel() { Name = "dSecondUser", Id = id++, PhoneNumber = "123 456 789" + id }; Messenger.Default.Send<NewContactEvent>(new NewContactEvent() { Contact = dSecondUser }, userSettings); Assert.AreEqual(4, collectionChanged.Count, "The contact should not be added"); Assert.AreEqual(4, ((MockTable<UserModel>)dataContextWrapper.Table<UserModel>()).Count, "The database was not supposed to be modified."); Assert.AreEqual(3, ruvm.RegisteredUsers.Count, "Wrong number of contact groups created"); // Add another user whose first letter is 's'. UserModel sSecondUser = new UserModel() { Name = "sSecondUser", Id = id++, PhoneNumber = "123 456 789" + id }; Messenger.Default.Send<NewContactEvent>(new NewContactEvent() { Contact = sSecondUser }, userSettings); Assert.AreEqual(5, collectionChanged.Count, "The contact should not be added"); Assert.AreEqual(5, ((MockTable<UserModel>)dataContextWrapper.Table<UserModel>()).Count, "The database was not supposed to be modified."); Assert.AreEqual(3, ruvm.RegisteredUsers.Count, "Wrong number of contact groups created"); // Add another user whose first letter is 's'. Try different position in // the 's' groups sorted list UserModel sZUser = new UserModel() { Name = "sZUser", Id = id++, PhoneNumber = "123 456 789" + id }; Messenger.Default.Send<NewContactEvent>(new NewContactEvent() { Contact = sZUser }, userSettings); Assert.AreEqual(6, collectionChanged.Count, "The contact should not be added"); Assert.AreEqual(6, ((MockTable<UserModel>)dataContextWrapper.Table<UserModel>()).Count, "The database was not supposed to be modified."); Assert.AreEqual(3, ruvm.RegisteredUsers.Count, "Wrong number of contact groups created"); }
public void TestAddContactReverseAlphabeticalOrder() { MockServiceProxy serviceProxy = new MockServiceProxy() { Users = new List<UserModel>() }; MockUserSettings userSettings = new MockUserSettings(); MockDataContextWrapper dataContextWrapper = new MockDataContextWrapper(new MockDatabase() { Users = new List<UserModel>() }); MockContactSearchController searchController = new MockContactSearchController() { Users = new List<UserModel>() }; RegisteredUsersViewModel ruvm = new RegisteredUsersViewModel(serviceProxy, userSettings, dataContextWrapper, searchController); // start loading the users from database ruvm.Search(); while (ruvm.IsLoading) { System.Threading.Thread.Sleep(1000); } NotifyCollectionOfCollectionChangedTester<UserModel> collectionChanged = new NotifyCollectionOfCollectionChangedTester<UserModel>(ruvm.RegisteredUsers); // Sort it in reverse order this.users.Sort((x, y) => { return -1 * string.Compare(x.Name, y.Name, StringComparison.OrdinalIgnoreCase); }); for (int i = 0; i < this.users.Count; i++) { Messenger.Default.Send<NewContactEvent>(new NewContactEvent() { Contact = this.users[i] }, userSettings); } Assert.AreEqual(this.users.Count, collectionChanged.Count, "The contact should not be added"); Assert.AreEqual(this.users.Count, ((MockTable<UserModel>)dataContextWrapper.Table<UserModel>()).Count, "The database was not supposed to be modified."); // Sort it in alphabetical order and attempt to insert again this.users.Sort((x, y) => { return string.Compare(x.Name, y.Name, StringComparison.OrdinalIgnoreCase); }); for (int i = 0; i < this.users.Count; i++) { Messenger.Default.Send<NewContactEvent>(new NewContactEvent() { Contact = this.users[i] }, userSettings); } Assert.AreEqual(this.users.Count, collectionChanged.Count, "The contact should not be added"); Assert.AreEqual(this.users.Count, ((MockTable<UserModel>)dataContextWrapper.Table<UserModel>()).Count, "The database was not supposed to be modified."); }
public void LoadContactsFromDatabaseAndNewServiceContacts() { List<UserModel> newUsers = new List<UserModel>(); Random random = new Random(); for (int i = 0; i < 5; i++) { newUsers.Add(new UserModel(){ Id = 1000 + 100*i, Name = "LoadContactsFromDatabaseAndNewServiceContacts" + i, PhoneNumber = "+1 100-200-300" + i}); } MockServiceProxy serviceProxy = new MockServiceProxy() { Users = newUsers}; MockUserSettings userSettings = new MockUserSettings(); MockDataContextWrapper dataContextWrapper = new MockDataContextWrapper(new MockDatabase() { Users = this.users }); MockContactSearchController searchController = new MockContactSearchController() { Users = newUsers }; RegisteredUsersViewModel ruvm = new RegisteredUsersViewModel(serviceProxy, userSettings, dataContextWrapper, searchController); // start loading the users from database NotifyCollectionOfCollectionChangedTester<UserModel> collectionChanged = new NotifyCollectionOfCollectionChangedTester<UserModel>(ruvm.RegisteredUsers); ruvm.Search(); while (ruvm.IsLoading) { System.Threading.Thread.Sleep(1000); } Assert.AreEqual(this.users.Count + newUsers.Count, collectionChanged.Count, "The users were not read from the database correctly"); Assert.AreEqual(this.users.Count + newUsers.Count, ((MockTable<UserModel>)dataContextWrapper.Table<UserModel>()).Count, "The database was not supposed to be modified."); }
public void LoadContactsFromDatabaseAndAddNewContact() { MockServiceProxy serviceProxy = new MockServiceProxy() { Users = this.users }; MockUserSettings userSettings = new MockUserSettings(); MockDataContextWrapper dataContextWrapper = new MockDataContextWrapper(new MockDatabase() { Users = this.users }); MockContactSearchController searchController = new MockContactSearchController() { Users = this.users }; RegisteredUsersViewModel ruvm = new RegisteredUsersViewModel(serviceProxy, userSettings, dataContextWrapper, searchController); // start loading the users from database ruvm.Search(); while (ruvm.IsLoading) { System.Threading.Thread.Sleep(1000); } Random random = new Random(); UserModel user = new UserModel() { Id = random.Next(100, 500), Name = "LoadContactsFromDatabaseAndNewServiceContacts", PhoneNumber = "+1 100-200-3000"}; NotifyCollectionOfCollectionChangedTester<UserModel> collectionChanged = new NotifyCollectionOfCollectionChangedTester<UserModel>(ruvm.RegisteredUsers); Messenger.Default.Send<NewContactEvent>(new NewContactEvent() { Contact = user }, userSettings); Assert.AreEqual(1, collectionChanged.Count, "The contact was not added"); Assert.AreEqual(this.users.Count + 1, ((MockTable<UserModel>)dataContextWrapper.Table<UserModel>()).Count, "The database was not supposed to be modified."); }
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"); } } }
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"); } } }