public async Task TestFulfillOrderWithBackorder() { // instruct the mock inventory service to always return less quantity than requested // so that FulfillOrder always ends up in backordered status. MockInventoryService inventoryService = new MockInventoryService() { RemoveStockAsyncFunc = (itemId, quantity, cmid) => Task.FromResult(quantity - 1) }; MockServiceProxy serviceProxy = new MockServiceProxy(); serviceProxy.Supports <IInventoryService>(serviceUri => inventoryService); CustomerOrderActor target = new CustomerOrderActor(); PropertyInfo idProperty = typeof(ActorBase).GetProperty("Id"); idProperty.SetValue(target, new ActorId(Guid.NewGuid())); target.ServiceProxy = serviceProxy; await target.StateManager.SetStateAsync <CustomerOrderStatus>(RequestIdPropertyName, CustomerOrderStatus.Submitted); await target.StateManager.SetStateAsync <long>(RequestIdPropertyName, 0); await target.StateManager.SetStateAsync <List <CustomerOrderItem> >(OrderItemListPropertyName, new List <CustomerOrderItem>() { new CustomerOrderItem(new InventoryItemId(), 4) }); await target.FulfillOrderAsync(); Assert.AreEqual <CustomerOrderStatus>(CustomerOrderStatus.Backordered, await target.StateManager.GetStateAsync <CustomerOrderStatus>(OrderStatusPropertyName)); }
public async Task TestFulfillOrderSimple() { // The default mock inventory service behavior is to always complete an order. MockInventoryService inventoryService = new MockInventoryService(); MockServiceProxy serviceProxy = new MockServiceProxy(); serviceProxy.Supports<IInventoryService>(serviceUri => inventoryService); CustomerOrderActor target = new CustomerOrderActor(); PropertyInfo idProperty = typeof(Actor).GetProperty("Id"); idProperty.SetValue(target, new ActorId(Guid.NewGuid())); target.ServiceProxy = serviceProxy; await target.StateManager.SetStateAsync<CustomerOrderStatus>(RequestIdPropertyName, CustomerOrderStatus.Submitted); await target.StateManager.SetStateAsync<long>(RequestIdPropertyName, 0); await target.StateManager.SetStateAsync<List<CustomerOrderItem>>(OrderItemListPropertyName, new List<CustomerOrderItem>() { new CustomerOrderItem(new InventoryItemId(), 4) }); await target.FulfillOrderAsync(); Assert.AreEqual<CustomerOrderStatus>(CustomerOrderStatus.Shipped, await target.StateManager.GetStateAsync<CustomerOrderStatus>(OrderStatusPropertyName)); }
public void ReplacesFaultExceptionMessageWhenPostHandlingIsThrowNewException() { Uri serviceUri = new Uri("http://localhost:30003/Test"); ServiceHost host = new ServiceHost(typeof(MockService1), serviceUri); host.AddServiceEndpoint(typeof(IMockService), new BasicHttpBinding(), serviceUri); host.Open(); try { MockServiceProxy proxy = new MockServiceProxy(); proxy.Test(); } catch (FaultException fex) { Assert.AreEqual("Test EHAB - WCF", fex.Message); } finally { if (host.State == CommunicationState.Opened) { host.Close(); } } }
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 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"); } } }
public void ReturnsGenericShildingExceptionMessageWhenPolicyNameIsInvalid() { Uri serviceUri = new Uri("http://localhost:30003/Test"); ServiceHost host = new ServiceHost(typeof(MockService2), serviceUri); host.AddServiceEndpoint(typeof(IMockService), new BasicHttpBinding(), serviceUri); host.Open(); try { MockServiceProxy proxy = new MockServiceProxy(); proxy.Test(); } catch (FaultException fex) { Assert.IsTrue(fex.Message.Contains("An error has occurred while consuming this service. Please contact your administrator for more information.")); } finally { if (host.State == CommunicationState.Opened) { host.Close(); } } }
public async Task TestFulfillOrderSimple() { // The default mock inventory service behavior is to always complete an order. MockInventoryService inventoryService = new MockInventoryService(); MockServiceProxy serviceProxy = new MockServiceProxy(); serviceProxy.Supports <IInventoryService>(serviceUri => inventoryService); CustomerOrderActor target = new CustomerOrderActor(); PropertyInfo idProperty = typeof(Actor).GetProperty("Id"); idProperty.SetValue(target, new ActorId(Guid.NewGuid())); target.ServiceProxy = serviceProxy; await target.StateManager.SetStateAsync <CustomerOrderStatus>(RequestIdPropertyName, CustomerOrderStatus.Submitted); await target.StateManager.SetStateAsync <long>(RequestIdPropertyName, 0); await target.StateManager.SetStateAsync <List <CustomerOrderItem> >(OrderItemListPropertyName, new List <CustomerOrderItem>() { new CustomerOrderItem(new InventoryItemId(), 4) }); await target.FulfillOrderAsync(); Assert.AreEqual <CustomerOrderStatus>(CustomerOrderStatus.Shipped, await target.StateManager.GetStateAsync <CustomerOrderStatus>(OrderStatusPropertyName)); }
public async Task TestFulfillOrderWithBackorder() { // instruct the mock inventory service to always return less quantity than requested // so that FulfillOrder always ends up in backordered status. MockInventoryService inventoryService = new MockInventoryService() { RemoveStockAsyncFunc = (itemId, quantity, cmid) => Task.FromResult(quantity - 1) }; MockServiceProxy serviceProxy = new MockServiceProxy(); serviceProxy.Supports<IInventoryService>(serviceUri => inventoryService); CustomerOrderActor target = new CustomerOrderActor(); PropertyInfo idProperty = typeof(ActorBase).GetProperty("Id"); idProperty.SetValue(target, new ActorId(Guid.NewGuid())); target.ServiceProxy = serviceProxy; await target.StateManager.SetStateAsync<CustomerOrderStatus>(RequestIdPropertyName, CustomerOrderStatus.Submitted); await target.StateManager.SetStateAsync<long>(RequestIdPropertyName, 0); await target.StateManager.SetStateAsync<List<CustomerOrderItem>>(OrderItemListPropertyName, new List<CustomerOrderItem>() { new CustomerOrderItem(new InventoryItemId(), 4) }); await target.FulfillOrderAsync(); Assert.AreEqual<CustomerOrderStatus>(CustomerOrderStatus.Backordered, await target.StateManager.GetStateAsync<CustomerOrderStatus>(OrderStatusPropertyName)); }
public async Task TestFulfillOrderSimple() { // The default mock inventory service behavior is to always complete an order. MockInventoryService inventoryService = new MockInventoryService(); MockServiceProxy serviceProxy = new MockServiceProxy(); serviceProxy.Supports <IInventoryService>(serviceUri => inventoryService); CustomerOrderActor target = new CustomerOrderActor(); PropertyInfo idProperty = typeof(ActorBase).GetProperty("Id"); idProperty.SetValue(target, new ActorId(Guid.NewGuid())); target.ServiceProxy = serviceProxy; target.State = new CustomerOrderActorState(); target.State.Status = CustomerOrderStatus.Submitted; target.State.OrderedItems = new List <CustomerOrderItem>() { new CustomerOrderItem(new InventoryItemId(), 4) }; await target.FulfillOrderAsync(); Assert.AreEqual <CustomerOrderStatus>(CustomerOrderStatus.Shipped, target.State.Status); }
public async Task TestFulfillOrderWithBackorder() { // instruct the mock inventory service to always return less quantity than requested // so that FulfillOrder always ends up in backordered status. MockInventoryService inventoryService = new MockInventoryService() { RemoveStockAsyncFunc = (itemId, quantity, cmid) => Task.FromResult(quantity - 1) }; MockServiceProxy serviceProxy = new MockServiceProxy(); serviceProxy.Supports <IInventoryService>(serviceUri => inventoryService); MockServiceProxyFactory serviceProxyFactory = new MockServiceProxyFactory(); serviceProxyFactory.AssociateMockServiceAndName(new Uri("fabric:/someapp/" + InventoryServiceName), inventoryService); CustomerOrderActor target = await CreateCustomerOrderActor(serviceProxyFactory); await target.StateManager.SetStateAsync <CustomerOrderStatus>(RequestIdPropertyName, CustomerOrderStatus.Submitted); await target.StateManager.SetStateAsync <long>(RequestIdPropertyName, 0); await target.StateManager.SetStateAsync <List <CustomerOrderItem> >(OrderItemListPropertyName, new List <CustomerOrderItem>() { new CustomerOrderItem(new InventoryItemId(), 4) }); await target.FulfillOrderAsync(); Assert.AreEqual <CustomerOrderStatus>(CustomerOrderStatus.Backordered, await target.StateManager.GetStateAsync <CustomerOrderStatus>(OrderStatusPropertyName)); }
public async Task TestFulfillOrderCancelled() { // instruct the mock inventory service to return 0 for all items to simulate items that don't exist. // and have it return false when asked if an item exists to make sure FulfillOrder doesn't get into // an infinite backorder loop. MockInventoryService inventoryService = new MockInventoryService() { IsItemInInventoryAsyncFunc = itemId => Task.FromResult(false), RemoveStockAsyncFunc = (itemId, quantity, cmid) => Task.FromResult(0) }; MockServiceProxy serviceProxy = new MockServiceProxy(); serviceProxy.Supports <IInventoryService>(serviceUri => inventoryService); CustomerOrderActor target = new CustomerOrderActor(); PropertyInfo idProperty = typeof(ActorBase).GetProperty("Id"); idProperty.SetValue(target, new ActorId(Guid.NewGuid())); target.ServiceProxy = serviceProxy; target.State = new CustomerOrderActorState(); target.State.Status = CustomerOrderStatus.Submitted; target.State.OrderedItems = new List <CustomerOrderItem>() { new CustomerOrderItem(new InventoryItemId(), 5) }; await target.FulfillOrderAsync(); Assert.AreEqual <CustomerOrderStatus>(CustomerOrderStatus.Canceled, target.State.Status); }
public async Task TestFulfillOrderSimple() { // The default mock inventory service behavior is to always complete an order. MockInventoryService inventoryService = new MockInventoryService(); MockServiceProxy serviceProxy = new MockServiceProxy(); serviceProxy.Supports<IInventoryService>(serviceUri => inventoryService); CustomerOrderActor target = new CustomerOrderActor(); PropertyInfo idProperty = typeof(ActorBase).GetProperty("Id"); idProperty.SetValue(target, new ActorId(Guid.NewGuid())); target.ServiceProxy = serviceProxy; target.State = new CustomerOrderActorState(); target.State.Status = CustomerOrderStatus.Submitted; target.State.OrderedItems = new List<CustomerOrderItem>() { new CustomerOrderItem(new InventoryItemId(), 4) }; await target.FulfillOrderAsync(); Assert.AreEqual<CustomerOrderStatus>(CustomerOrderStatus.Shipped, target.State.Status); }
public void ReturnsOriginalExceptionMessageWhenPostHandlingIsThrowNewExceptionAndNoExceptionMessageIsConfiguredInThePolicy() { Uri serviceUri = new Uri("http://localhost:30003/Test"); ServiceHost host = new ServiceHost(typeof(MockService3), serviceUri); host.AddServiceEndpoint(typeof(IMockService), new BasicHttpBinding(), serviceUri); host.Open(); try { MockServiceProxy proxy = new MockServiceProxy(); proxy.Test(); } catch (FaultException fex) { Assert.AreEqual("MockService3 exception", fex.Message); } finally { if (host.State == CommunicationState.Opened) { host.Close(); } } }
public void TestNetStandardCompatibility() { var proxy = new MockServiceProxy <MyStatelessService>(); Assert.IsNotNull(proxy); Assert.IsNull(proxy.GetType().GetProperty("ServicePartitionClient")); Assert.IsNotNull(proxy.GetType().GetProperty("ServicePartitionClient2")); }
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"); } } } }
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 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"); } }
public async Task TestFulfillOrderToCompletion() { int itemCount = 5; // instruct the mock inventory service to only fulfill one item each time // so that FulfillOrder has to make multiple iterations to complete an order MockInventoryService inventoryService = new MockInventoryService() { RemoveStockAsyncFunc = (itemId, quantity, cmid) => Task.FromResult(1) }; MockServiceProxy serviceProxy = new MockServiceProxy(); serviceProxy.Supports <IInventoryService>(serviceUri => inventoryService); CustomerOrderActor target = new CustomerOrderActor(); PropertyInfo idProperty = typeof(ActorBase).GetProperty("Id"); idProperty.SetValue(target, new ActorId(Guid.NewGuid())); target.ServiceProxy = serviceProxy; await target.StateManager.SetStateAsync <CustomerOrderStatus>(RequestIdPropertyName, CustomerOrderStatus.Submitted); await target.StateManager.SetStateAsync <long>(RequestIdPropertyName, 0); await target.StateManager.SetStateAsync <List <CustomerOrderItem> >(OrderItemListPropertyName, new List <CustomerOrderItem>() { new CustomerOrderItem(new InventoryItemId(), 4) }); for (int i = 0; i < itemCount - 1; ++i) { await target.FulfillOrderAsync(); Assert.AreEqual <CustomerOrderStatus>(CustomerOrderStatus.Backordered, await target.StateManager.GetStateAsync <CustomerOrderStatus>(OrderStatusPropertyName)); } await target.FulfillOrderAsync(); Assert.AreEqual <CustomerOrderStatus>(CustomerOrderStatus.Shipped, await target.StateManager.GetStateAsync <CustomerOrderStatus>(OrderStatusPropertyName)); }
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 async Task TestFulfillOrderToCompletion() { int itemCount = 5; // instruct the mock inventory service to only fulfill one item each time // so that FulfillOrder has to make multiple iterations to complete an order MockInventoryService inventoryService = new MockInventoryService() { RemoveStockAsyncFunc = (itemId, quantity, cmid) => Task.FromResult(1) }; MockServiceProxy serviceProxy = new MockServiceProxy(); serviceProxy.Supports <IInventoryService>(serviceUri => inventoryService); MockServiceProxyFactory serviceProxyFactory = new MockServiceProxyFactory(); serviceProxyFactory.AssociateMockServiceAndName(new Uri("fabric:/someapp/" + InventoryServiceName), inventoryService); CustomerOrderActor target = await CreateCustomerOrderActor(serviceProxyFactory); await target.StateManager.SetStateAsync <CustomerOrderStatus>(RequestIdPropertyName, CustomerOrderStatus.Submitted); await target.StateManager.SetStateAsync <long>(RequestIdPropertyName, 0); await target.StateManager.SetStateAsync <List <CustomerOrderItem> >(OrderItemListPropertyName, new List <CustomerOrderItem>() { new CustomerOrderItem(new InventoryItemId(), 5) }); for (int i = 0; i < itemCount - 1; ++i) { await target.FulfillOrderAsync(); Assert.AreEqual <CustomerOrderStatus>(CustomerOrderStatus.Backordered, await target.StateManager.GetStateAsync <CustomerOrderStatus>(OrderStatusPropertyName)); } await target.FulfillOrderAsync(); Assert.AreEqual <CustomerOrderStatus>(CustomerOrderStatus.Shipped, await target.StateManager.GetStateAsync <CustomerOrderStatus>(OrderStatusPropertyName)); }
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 HandlePushNotificationTest() { for (int i = 0; i < this.conversationMessages.Count; i++) { for (int j = 0; j < this.conversationMessages[i].Count; j++) { MockServiceProxy serviceProxy = new MockServiceProxy() { Messages = this.conversationMessages[i][j].m_Item2 }; MockUserSettings userSettings = new MockUserSettings(); userSettings.Save(owners[i]); UserModel recipient = null; foreach (UserModel user in this.conversationMessages[i][j].m_Item1.ConversationParticipants) { if (!user.Equals(userSettings.Me)) { recipient = user; } } ConversationMessagesViewModel messages = new ConversationMessagesViewModel(serviceProxy, userSettings, this.conversationMessages[i][j].m_Item1.ConversationId, recipient); messages.LoadMessagesForConversations(); Random random = new Random((int)DateTime.Now.Ticks); long existingConversationId = this.conversationMessages[i][j].m_Item2.Count > 0 ? this.conversationMessages[i][j].m_Item2[0].ConversationId : long.MaxValue; int existingConversationUserId = this.conversationMessages[i][j].m_Item2.Count > 0 ? this.conversationMessages[i][j].m_Item2[0].Sender.Id : random.Next(1000, 2000); PushNotificationEvent pushEvent = new PushNotificationEvent(this, (long)2000, existingConversationId, "test", DateTime.Now.Ticks, "ConversationMessagesHandlePushNotificationTest" + i.ToString(), existingConversationUserId); int messageCountBeforePush = messages.Messages.Count; NotifyCollectionChangedTester <MessageModel> collectionChangedTester = new NotifyCollectionChangedTester <MessageModel>(messages.Messages); Messenger.Default.Send <PushNotificationEvent>(pushEvent); Assert.AreEqual(1, collectionChangedTester.Count, "Collection changed event was not generated"); Assert.AreEqual(messageCountBeforePush + 1, messages.Messages.Count, "Push notification was not handled properly"); } } }
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"); } } }
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"); } } }
public void CreateConversationMessagesViewModelTest() { for (int i = 0; i < this.conversationMessages.Count; i++) { for (int j = 0; j < this.conversationMessages[i].Count; j++) { MockServiceProxy serviceProxy = new MockServiceProxy() { Messages = this.conversationMessages[i][j].m_Item2 }; MockDataContextWrapper dataContext = new MockDataContextWrapper(new MockDatabase() { }); MockUserSettings userSettings = new MockUserSettings(); userSettings.Save(owners[i]); UserModel recipient = null; foreach (UserModel user in this.conversationMessages[i][j].m_Item1.ConversationParticipants) { if (!user.Equals(userSettings.Me)) { recipient = user; } } ConversationMessagesViewModel messages = new ConversationMessagesViewModel(serviceProxy, dataContext, userSettings, this.conversationMessages[i][j].m_Item1.ConversationId, recipient); NotifyPropertyChangedTester propertyChangedTester = new NotifyPropertyChangedTester(messages); NotifyCollectionChangedTester <MessageModel> collectionChangedTester = new NotifyCollectionChangedTester <MessageModel>(messages.Messages); messages.LoadMessagesForConversations(); Assert.AreEqual(1, propertyChangedTester.Changes.Count, "IsLoaded property changed event was not generated"); propertyChangedTester.AssertChange(0, "IsLoading"); Assert.AreEqual(this.conversationMessages[i][j].m_Item2.Count, collectionChangedTester.Count, "Number of messages in notify collection changed doesn't match"); } } }
public async Task TestFulfillOrderCancelled() { // instruct the mock inventory service to return 0 for all items to simulate items that don't exist. // and have it return false when asked if an item exists to make sure FulfillOrder doesn't get into // an infinite backorder loop. MockInventoryService inventoryService = new MockInventoryService() { IsItemInInventoryAsyncFunc = itemId => Task.FromResult(false), RemoveStockAsyncFunc = (itemId, quantity, cmid) => Task.FromResult(0) }; MockServiceProxy serviceProxy = new MockServiceProxy(); serviceProxy.Supports <IInventoryService>(serviceUri => inventoryService); MockServiceProxyFactory serviceProxyFactory = new MockServiceProxyFactory(); serviceProxyFactory.AssociateMockServiceAndName(new Uri("fabric:/someapp/" + InventoryServiceName), inventoryService); CustomerOrderActor target = await CreateCustomerOrderActor(serviceProxyFactory); await target.StateManager.SetStateAsync <CustomerOrderStatus>(RequestIdPropertyName, CustomerOrderStatus.Submitted); await target.StateManager.SetStateAsync <long>(RequestIdPropertyName, 0); await target.StateManager.SetStateAsync <List <CustomerOrderItem> >(OrderItemListPropertyName, new List <CustomerOrderItem>() { new CustomerOrderItem(new InventoryItemId(), 5) }); await target.FulfillOrderAsync(); CustomerOrderStatus status = await target.StateManager.GetStateAsync <CustomerOrderStatus>(OrderStatusPropertyName); Assert.AreEqual <CustomerOrderStatus>(CustomerOrderStatus.Canceled, status); }
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 async Task TestFulfillOrderToCompletion() { int itemCount = 5; // instruct the mock inventory service to only fulfill one item each time // so that FulfillOrder has to make multiple iterations to complete an order MockInventoryService inventoryService = new MockInventoryService() { RemoveStockAsyncFunc = (itemId, quantity, cmid) => Task.FromResult(1) }; MockServiceProxy serviceProxy = new MockServiceProxy(); serviceProxy.Supports<IInventoryService>(serviceUri => inventoryService); MockServiceProxyFactory serviceProxyFactory = new MockServiceProxyFactory(); serviceProxyFactory.AssociateMockServiceAndName(new Uri("fabric:/someapp/" + InventoryServiceName), inventoryService); CustomerOrderActor target = await CreateCustomerOrderActor(serviceProxyFactory); await target.StateManager.SetStateAsync<CustomerOrderStatus>(RequestIdPropertyName, CustomerOrderStatus.Submitted); await target.StateManager.SetStateAsync<long>(RequestIdPropertyName, 0); await target.StateManager.SetStateAsync<List<CustomerOrderItem>>(OrderItemListPropertyName, new List<CustomerOrderItem>() { new CustomerOrderItem(new InventoryItemId(), 5) }); for (int i = 0; i < itemCount - 1; ++i) { await target.FulfillOrderAsync(); Assert.AreEqual<CustomerOrderStatus>(CustomerOrderStatus.Backordered, await target.StateManager.GetStateAsync<CustomerOrderStatus>(OrderStatusPropertyName)); } await target.FulfillOrderAsync(); Assert.AreEqual<CustomerOrderStatus>(CustomerOrderStatus.Shipped, await target.StateManager.GetStateAsync<CustomerOrderStatus>(OrderStatusPropertyName)); }
public async Task TestFulfillOrderCancelled() { // instruct the mock inventory service to return 0 for all items to simulate items that don't exist. // and have it return false when asked if an item exists to make sure FulfillOrder doesn't get into // an infinite backorder loop. MockInventoryService inventoryService = new MockInventoryService() { IsItemInInventoryAsyncFunc = itemId => Task.FromResult(false), RemoveStockAsyncFunc = (itemId, quantity, cmid) => Task.FromResult(0) }; MockServiceProxy serviceProxy = new MockServiceProxy(); serviceProxy.Supports<IInventoryService>(serviceUri => inventoryService); CustomerOrderActor target = new CustomerOrderActor(); PropertyInfo idProperty = typeof(ActorBase).GetProperty("Id"); idProperty.SetValue(target, new ActorId(Guid.NewGuid())); target.ServiceProxy = serviceProxy; await target.StateManager.SetStateAsync<CustomerOrderStatus>(RequestIdPropertyName, CustomerOrderStatus.Submitted); await target.StateManager.SetStateAsync<long>(RequestIdPropertyName, 0); await target.StateManager.SetStateAsync<List<CustomerOrderItem>>(OrderItemListPropertyName, new List<CustomerOrderItem>() { new CustomerOrderItem(new InventoryItemId(), 5) }); await target.FulfillOrderAsync(); Assert.AreEqual<CustomerOrderStatus>(CustomerOrderStatus.Canceled, await target.StateManager.GetStateAsync<CustomerOrderStatus>(OrderStatusPropertyName)); }
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 async Task TestFulfillOrderCancelled() { // instruct the mock inventory service to return 0 for all items to simulate items that don't exist. // and have it return false when asked if an item exists to make sure FulfillOrder doesn't get into // an infinite backorder loop. MockInventoryService inventoryService = new MockInventoryService() { IsItemInInventoryAsyncFunc = itemId => Task.FromResult(false), RemoveStockAsyncFunc = (itemId, quantity, cmid) => Task.FromResult(0) }; MockServiceProxy serviceProxy = new MockServiceProxy(); serviceProxy.Supports<IInventoryService>(serviceUri => inventoryService); MockServiceProxyFactory serviceProxyFactory = new MockServiceProxyFactory(); serviceProxyFactory.AssociateMockServiceAndName(new Uri("fabric:/someapp/" + InventoryServiceName), inventoryService); CustomerOrderActor target = await CreateCustomerOrderActor(serviceProxyFactory); await target.StateManager.SetStateAsync<CustomerOrderStatus>(RequestIdPropertyName, CustomerOrderStatus.Submitted); await target.StateManager.SetStateAsync<long>(RequestIdPropertyName, 0); await target.StateManager.SetStateAsync<List<CustomerOrderItem>>(OrderItemListPropertyName, new List<CustomerOrderItem>() { new CustomerOrderItem(new InventoryItemId(), 5) }); await target.FulfillOrderAsync(); CustomerOrderStatus status = await target.StateManager.GetStateAsync<CustomerOrderStatus>(OrderStatusPropertyName); Assert.AreEqual<CustomerOrderStatus>(CustomerOrderStatus.Canceled, status); }
public async Task TestFulfillOrderWithBackorder() { // instruct the mock inventory service to always return less quantity than requested // so that FulfillOrder always ends up in backordered status. MockInventoryService inventoryService = new MockInventoryService() { RemoveStockAsyncFunc = (itemId, quantity, cmid) => Task.FromResult(quantity - 1) }; MockServiceProxy serviceProxy = new MockServiceProxy(); serviceProxy.Supports<IInventoryService>(serviceUri => inventoryService); MockServiceProxyFactory serviceProxyFactory = new MockServiceProxyFactory(); serviceProxyFactory.AssociateMockServiceAndName(new Uri("fabric:/someapp/" + InventoryServiceName), inventoryService); CustomerOrderActor target = await CreateCustomerOrderActor(serviceProxyFactory); await target.StateManager.SetStateAsync<CustomerOrderStatus>(RequestIdPropertyName, CustomerOrderStatus.Submitted); await target.StateManager.SetStateAsync<long>(RequestIdPropertyName, 0); await target.StateManager.SetStateAsync<List<CustomerOrderItem>>(OrderItemListPropertyName, new List<CustomerOrderItem>() { new CustomerOrderItem(new InventoryItemId(), 4) }); await target.FulfillOrderAsync(); Assert.AreEqual<CustomerOrderStatus>(CustomerOrderStatus.Backordered, await target.StateManager.GetStateAsync<CustomerOrderStatus>(OrderStatusPropertyName)); }
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 async Task TestFulfillOrderToCompletion() { int itemCount = 5; // instruct the mock inventory service to only fulfill one item each time // so that FulfillOrder has to make multiple iterations to complete an order MockInventoryService inventoryService = new MockInventoryService() { RemoveStockAsyncFunc = (itemId, quantity, cmid) => Task.FromResult(1) }; MockServiceProxy serviceProxy = new MockServiceProxy(); serviceProxy.Supports<IInventoryService>(serviceUri => inventoryService); CustomerOrderActor target = new CustomerOrderActor(); PropertyInfo idProperty = typeof(ActorBase).GetProperty("Id"); idProperty.SetValue(target, new ActorId(Guid.NewGuid())); target.ServiceProxy = serviceProxy; await target.StateManager.SetStateAsync<CustomerOrderStatus>(RequestIdPropertyName, CustomerOrderStatus.Submitted); await target.StateManager.SetStateAsync<long>(RequestIdPropertyName, 0); await target.StateManager.SetStateAsync<List<CustomerOrderItem>>(OrderItemListPropertyName, new List<CustomerOrderItem>() { new CustomerOrderItem(new InventoryItemId(), 4) }); for (int i = 0; i < itemCount - 1; ++i) { await target.FulfillOrderAsync(); Assert.AreEqual<CustomerOrderStatus>(CustomerOrderStatus.Backordered, await target.StateManager.GetStateAsync<CustomerOrderStatus>(OrderStatusPropertyName)); } await target.FulfillOrderAsync(); Assert.AreEqual<CustomerOrderStatus>(CustomerOrderStatus.Shipped, await target.StateManager.GetStateAsync<CustomerOrderStatus>(OrderStatusPropertyName)); }
public void SendNewMessageTest() { for (int i = 0; i < this.conversationMessages.Count; i++) { for (int j = 0; j < this.conversationMessages[i].Count; j++) { MockServiceProxy serviceProxy = new MockServiceProxy() { Messages = this.conversationMessages[i][j].m_Item2 }; MockUserSettings userSettings = new MockUserSettings(); userSettings.Save(owners[i]); UserModel recipient = null; foreach (UserModel user in this.conversationMessages[i][j].m_Item1.ConversationParticipants) { if (!user.Equals(userSettings.Me)) { recipient = user; } } ConversationMessagesViewModel messages = new ConversationMessagesViewModel(serviceProxy, userSettings, this.conversationMessages[i][j].m_Item1.ConversationId, recipient); messages.LoadMessagesForConversations(); NotifyCollectionChangedTester <MessageModel> collectionChangedTester = new NotifyCollectionChangedTester <MessageModel>(messages.Messages); /************************************************* * SendMessage chat heads enabled * ***********************************************/ int messageCountBeforeNewMessage = messages.Messages.Count; // Send a new message. // The mock proxy will invoke the callback immediately messages.SendNewMessage("SendNewMessageTest message chatheads disabled" + DateTime.Now.Ticks); Assert.AreEqual(1, collectionChangedTester.Count, "Collection changed event was not generated"); Assert.AreEqual(messageCountBeforeNewMessage + 1, messages.Messages.Count, "New message was not added to the collection"); /************************************************* * SendMessage chat heads enabled * ***********************************************/ // Send another message but this time with chatheads enabled. // Ensure that quit application event is generated. messageCountBeforeNewMessage = messages.Messages.Count; userSettings.ChatHeadEnabled = true; bool quitEventGenerated = false; collectionChangedTester.Count = 0; Messenger.Default.Register <QuitApplicationEvent>(this, (QuitApplicationEvent e) => { quitEventGenerated = true; }); messages.SendNewMessage("SendNewMessageTest message chatheads disabled" + DateTime.Now.Ticks); Assert.AreEqual(1, collectionChangedTester.Count, "IsLoaded property changed event was not generated"); Assert.AreEqual(messageCountBeforeNewMessage + 1, messages.Messages.Count, "New messaged was not added to the collection"); /************************************************* * SendMessage simulate failure * ***********************************************/ // Remember the count before new message messageCountBeforeNewMessage = messages.Messages.Count; // Set chat heads to enabled to true and userSettings.ChatHeadEnabled = true; // Simulate failure to true serviceProxy.SimulateSendMessageFailure = true; // Set quitEventGenerated to false quitEventGenerated = false; collectionChangedTester.Count = 0; Messenger.Default.Register <QuitApplicationEvent>(this, (QuitApplicationEvent e) => { quitEventGenerated = true; }); messages.SendNewMessage("SendNewMessageTest message chatheads disabled" + DateTime.Now.Ticks); Assert.AreEqual(0, collectionChangedTester.Count, "IsLoaded property changed event was not generated"); Assert.AreEqual(messageCountBeforeNewMessage, messages.Messages.Count, "New messaged was not added to the collection"); Assert.AreEqual(false, quitEventGenerated, "Quit Application event was not generated"); } } }