コード例 #1
0
 public void NotifyNewMessageTest()
 {
     var message = new Message
     {
         Algorithm = CryptoAlgorithm.None,
         Payload = new byte[] { 1, 2, 3 },
         Sender = new User { Name = "Florian" }
     };
     var mock = new Mock<IMessagingServiceCallback>();
     mock.Setup(x => x.NotifyNewMessage(message));
     var target = mock.Object;
     target.NotifyNewMessage(message);
     mock.Verify(x => x.NotifyNewMessage(message));
 }
コード例 #2
0
 public void SendTest()
 {
     var message = new Message
     {
         Algorithm = CryptoAlgorithm.None,
         Payload = new byte[] { 1, 2, 3 },
         Sender = new User { Name = "Florian" }
     };
     var session = new Session { ExpiryDate = DateTime.Today.AddDays(1), User = new User { Name = "Florian" } };
     var mock = new Mock<IMessagingService>();
     mock.Setup(x => x.Send(message, session));
     var target = mock.Object;
     var sender = new Session { ExpiryDate = DateTime.Today.AddDays(1), User = new User { Name = "Florian" } };
     target.Send(message, sender);
     mock.Verify(x => x.Send(message, sender));
 }
コード例 #3
0
ファイル: MessagingWindow.xaml.cs プロジェクト: famstutz/YAEM
        /// <summary>
        /// Adds the history message.
        /// </summary>
        /// <param name="message">The message.</param>
        private void AddHistoryMessage(Message message)
        {
            string payload;
            if (message.Algorithm == CryptoAlgorithm.None)
            {
                payload = message.GetPayload();
            }
            else
            {
                var cp = this.GetCryptoProvider(message.Algorithm);

                if (cp.InitalizationVector != null && cp.Key != null)
                {
                    payload = cp.Decrypt(message.Payload);
                }
                else
                {
                    payload = message.GetPayload();
                }
            }

            this.MessageHistoryTextBox.Text += string.Format("{0}\t{1}\t{2}\r\n", DateTime.Now, message.Sender.Name, payload);
        }
コード例 #4
0
ファイル: MessagingWindow.xaml.cs プロジェクト: famstutz/YAEM
        /// <summary>
        /// Sends the button click.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void SendButtonClick(object sender, RoutedEventArgs e)
        {
            var algo = (CryptoAlgorithm)this.CryptoAlgorithmComboBox.SelectedValue;

            if (algo == CryptoAlgorithm.None)
            {
                var m = new Message();
                m.SetPayload(this.MessageTextBox.Text);
                this.messagingProxy.Send(
                    m,
                    this.currentSession);
            }
            else
            {
                var cp = this.GetCryptoProvider(algo);

                this.messagingProxy.Send(
                    new Message
                    {
                        Payload = cp.Encrypt(this.MessageTextBox.Text),
                        Algorithm = (CryptoAlgorithm)this.CryptoAlgorithmComboBox.SelectedValue
                    },
                    this.currentSession);
            }

            this.MessageTextBox.Text = string.Empty;
        }
コード例 #5
0
ファイル: MessagingWindow.xaml.cs プロジェクト: famstutz/YAEM
        /// <summary>
        /// Notifies the new message.
        /// </summary>
        /// <param name="message">The message.</param>
        public void NotifyNewMessage(Message message)
        {
            SendOrPostCallback callback = state => this.AddHistoryMessage(message);

            this.uiSyncContext.Post(callback, message);
        }