Exemple #1
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            Name = textBox.Text;

            Name = Name.Trim();

            MainWindow mainWindow = new MainWindow(Name);

            var awayStorage = new ConnectionServer();

            MyProfilePresenter myProfile = new MyProfilePresenter(awayStorage, this, mainWindow);

            myProfile.Initialize();

            try
            {
                LoadProfile?.Invoke(this, EventArgs.Empty);
            }
            catch (Exception)
            {
                MessageBox.Show("Нет соединения с сервером, попробуйте позже");
                mainWindow.Close();
                Close();
                return;
            }

            Hide();

            mainWindow.Show();

            Close();
        }
        public void MyProfilePresenterTest5()
        {
            var student = new Contact
            {
                MessageHistory = "2412",
                Name           = "40",
                Online         = true
            };

            var student2 = new Contact
            {
                MessageHistory = "2412",
                Name           = "42",
                Online         = true
            };

            var contactList = new List <Contact> {
                student, student2
            };

            var mock1 = new Mock <IMainWindowView>();
            var mock2 = new Mock <INameWindowView>();
            var mock3 = new Mock <IConnection>();
            var mock4 = new Mock <INewContactWindowView>();
            var mock5 = new Mock <IChooseContactWindowView>();

            var presenter = new MyProfilePresenter(mock3.Object, mock2.Object, mock1.Object);

            presenter.Initialize();

            mock1.Setup(m => m.ContaktsMessageHistory).Returns(new Dictionary <string, string> {
                { "Bron", "Bron" }
            });
            mock1.Setup(m => m.ActiveContact).Returns("Bron");
            mock3.Setup(m => m.Messages).Returns(new KeyValuePair <string, string>("dsafdas", "dasfsa"));
            mock1.Setup(m => m.UnreadMessages).Returns(new List <string>());
            mock3.Setup(m => m.AddContact(It.IsAny <string>())).Returns(contactList);
            mock4.Setup(m => m.CreateChooseContactWindow()).Returns(mock5.Object);
            mock5.Setup(m => m.ActiveContact).Returns("Bron");
            mock5.Setup(m => m.OnlineContactList).Returns(new List <string>());

            mock1.Setup(m => m.CreateContactWindow()).Returns(mock4.Object);

            mock3.Setup(m => m.LogIn(It.IsAny <string>())).Returns(new MyProfile {
                MyName = "Lol", MyContacts = contactList
            });
            mock2.Raise(m => m.LoadProfile += null, EventArgs.Empty);

            mock1.Raise(m => m.AddNewContakt += null, EventArgs.Empty);

            mock4.Verify(m => m.ShowWindow(), Times.Once);

            mock4.Raise(m => m.AddContact += null, EventArgs.Empty);

            mock5.Verify(m => m.UpdateContacts(It.IsAny <List <string> >(), It.IsAny <List <string> >()), Times.Once);

            mock5.Raise(m => m.ChooseContact += null, EventArgs.Empty);

            mock5.Verify(m => m.Close(), Times.Once);
        }
        public void MyProfilePresenterTest1()
        {
            var mock1 = new Mock <IMainWindowView>();
            var mock2 = new Mock <INameWindowView>();
            var mock3 = new Mock <IConnection>();

            var presenter = new MyProfilePresenter(mock3.Object, mock2.Object, mock1.Object);

            presenter.Initialize();

            mock1.Setup(m => m.ContaktsMessageHistory).Returns(new Dictionary <string, string> {
                { "Bron", "Bron" }
            });
            mock1.Setup(m => m.ActiveContact).Returns("Bron");

            mock3.Setup(m => m.LogIn(It.IsAny <string>())).Returns(new MyProfile {
                MyName = "Lol"
            });

            mock2.Raise(m => m.LoadProfile += null, EventArgs.Empty);

            mock1.Raise(m => m.SendMessage += null, EventArgs.Empty);

            mock3.Verify(m => m.SendMessage(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once);
        }
        public void MyProfilePresenterTest2()
        {
            var student = new Contact
            {
                MessageHistory = "2412",
                Name           = "40",
                Online         = true
            };

            var student2 = new Contact
            {
                MessageHistory = "2412",
                Name           = "42",
                Online         = true
            };

            var contactList = new List <Contact> {
                student, student2
            };

            var mock1 = new Mock <IMainWindowView>();
            var mock2 = new Mock <INameWindowView>();
            var mock3 = new Mock <IConnection>();

            var presenter = new MyProfilePresenter(mock3.Object, mock2.Object, mock1.Object);

            presenter.Initialize();

            mock1.Setup(m => m.ContaktsMessageHistory).Returns(new Dictionary <string, string> {
                { "Bron", "Bron" }
            });
            mock1.Setup(m => m.ActiveContact).Returns("Bron");
            mock3.Setup(m => m.Messages).Returns(new KeyValuePair <string, string>("dsafdas", "dasfsa"));
            mock1.Setup(m => m.UnreadMessages).Returns(new List <string>());

            mock3.Setup(m => m.LogIn(It.IsAny <string>())).Returns(new MyProfile {
                MyName = "Lol", MyContacts = contactList
            });

            mock2.Raise(m => m.LoadProfile += null, EventArgs.Empty);

            mock3.Raise(m => m.MessangePropertyChanged += null, new PropertyChangedEventArgs("Bar"));

            mock1.Verify(m => m.UpdateMessageScreen(), Times.Once);
        }