public void Open_Calls_ModelOpenChat()
 {
     var modelMock = new Mock<IMainChatModel>();
     var viewModel = new MainPageViewModel(modelMock.Object);
     viewModel.Open();
     modelMock.Verify(x => x.OpenChat(), Times.Exactly(1), "Model method 'OpenChat' wasn't called.");
 }
 public void Close_Calls_ModelCloseChat()
 {
     var modelMock = new Mock<IMainChatModel>();
     var viewModel = new MainPageViewModel(modelMock.Object);
     viewModel.Close(null);
     modelMock.Verify(x => x.CloseChat(), Times.Exactly(1), "Model method 'CloseChat' wasn't called.");
 }
 public void ClosePersonalChat_Fires_ModelClosePersonal()
 {
     const string userName = "******";
     var modelMock = new Mock<IMainChatModel>();
     var viewModel = new MainPageViewModel(modelMock.Object);
     // don't know how to verify event firing
     viewModel.ClosePersonal += (sender, args) => Assert.AreEqual(userName, args.UserName, "User name mismatch.");
     viewModel.ClosePersonalChat(userName);
 }
 public void RefreshUsersTest()
 {
     const string userName = "******";
     var modelMock = new Mock<IMainChatModel>();
     var viewModel = new MainPageViewModel(modelMock.Object);
     Assert.AreEqual(0, viewModel.Users.Count, "Incorrect initial users count.");
     modelMock.Raise(x => x.RefreshUsers += null, new RefreshUsersEventArgs{Users = new[] {userName}});
     Assert.AreEqual(1, viewModel.Users.Count, "Incorrect initial users count.");
     Assert.AreEqual(userName, viewModel.Users.First());
 }
 public void NewPersonalChatTest()
 {
     const string userName = "******";
     var chatModelMock = new Mock<IChatModel>();
     var modelMock = new Mock<IMainChatModel>();
     modelMock.Setup(x => x.GetNewPersonalChat(userName)).Returns(chatModelMock.Object);
     var viewModel = new MainPageViewModel(modelMock.Object);
     modelMock.Raise(x => x.NewPersonalChat += null, new NewMessageEventArgs{UserName = userName});
     modelMock.Verify(x => x.GetNewPersonalChat(userName), Times.Exactly(1), "Model method 'GetNewPersonalChat' wasn't called.");
 }
 public void GetPersonalChat_Calls_ModelGetNewPersonalChat()
 {
     const string userName = "******";
     var chatModelMock = new Mock<IChatModel>();
     var modelMock = new Mock<IMainChatModel>();
     modelMock.Setup(x => x.GetNewPersonalChat(userName)).Returns(chatModelMock.Object);
     var viewModel = new MainPageViewModel(modelMock.Object);
     viewModel.GetPersonalChat(userName);
     modelMock.Verify(x => x.GetNewPersonalChat(userName), Times.Exactly(1), "Model method 'GetNewPersonalChat' wasn't called.");
 }
 public void SendMessage_Calls_ModelSendMessage()
 {
     const string userName = "******";
     const string message = "test message";
     var mainModelMock = new Mock<IMainChatModel>();
     mainModelMock.SetupGet(x => x.UserName).Returns(userName);
     var mainViewModel = new MainPageViewModel(mainModelMock.Object);
     var chatModelMock = new Mock<IChatModel>();
     var viewModel = new PersonalChatViewModel(chatModelMock.Object, mainViewModel);
     viewModel.SendMessage(message);
     chatModelMock.Verify(x => x.SendMessage(userName, message), Times.Exactly(1), "Model method 'SendMessage' wasn't called.");
 }
 public void NewMessageTest()
 {
     const string userName = "******";
     const string message = "test message";
     var mainModelMock = new Mock<IMainChatModel>();
     var mainViewModel = new MainPageViewModel(mainModelMock.Object);
     var chatModelMock = new Mock<IChatModel>();
     var viewModel = new PersonalChatViewModel(chatModelMock.Object, mainViewModel);
     Assert.AreEqual(0, viewModel.Messages.Count, "Incorrect initial messages count.");
     chatModelMock.Raise(x => x.NewMessage += null, new NewMessageEventArgs{Message = message, UserName = userName});
     Assert.AreEqual(1, viewModel.Messages.Count, "Incorrect messages count.");
 }
Ejemplo n.º 9
0
 private void BtnLogin_Click(object sender, RoutedEventArgs e)
 {
     if (!ValidateUserNameNotEmpty())
     {
         TxtbUserNameRequired.Visibility = Visibility.Visible;
         return;
     }
     var serviceClient = new ChatServiceClient(
         new PollingDuplexHttpBinding { DuplexMode = PollingDuplexMode.MultipleMessagesPerPoll },
         new EndpointAddress("../ChatService.svc"));
     var model = new MainChatModel(serviceClient, TxtUserName.Text);
     var mainPageViewModel = new MainPageViewModel(model);
     var mainPage = new MainPage {DataContext = mainPageViewModel };
     var app = (App) Application.Current;
     app.RedirectTo(mainPage);
 }
Ejemplo n.º 10
0
 public PersonalChatViewModel(IChatModel model, MainPageViewModel parent)
     : base(model)
 {
     _parent = parent;
 }