示例#1
0
        public void TripleStatement_ShouldPass()
        {
            var triplestatement = new Statement(htmlStatement + paranoicStatement + consoleStatement);

            triplestatement.Generate();
            Assert.AreEqual("<html>This is statement</html>", Receiver.Received);
            Receiver.Clear();
        }
示例#2
0
        public void AllStatementsAtOnce_ShouldPass()
        {
            var allstatements = new Statement(htmlStatement + jsonStatement + paranoicStatement + stringStatement + consoleStatement);

            allstatements.Generate();

            Assert.AreEqual("<html>This is statement</html>" + new MemoryStream() + "This is statement", Receiver.Received);
            Receiver.Clear();
        }
示例#3
0
        public void TwoStatements_ShouldPass()
        {
            var statement = new Statement(stringStatement + htmlStatement);

            statement.Generate();

            Assert.AreEqual("This is statement" + "<html>This is statement</html>", Receiver.Received);
            Receiver.Clear();
        }
示例#4
0
        public void SingleStatement_ShouldPass()
        {
            var statement = new Statement(stringStatement);

            statement.Generate();

            Assert.AreEqual("This is statement", Receiver.Received);
            Receiver.Clear();
        }
示例#5
0
        private void Send_Click(object sender, RoutedEventArgs e)
        {
            if (MainBody.Text != string.Empty || Subject.Text != string.Empty || Receiver.Text != string.Empty)
            {
                int maxid = 0;
                mConnection.Open();
                using (mConnection)
                {//SELECT TOP 1 * FROM Table ORDER BY ID DESC
                    string queryMax = "SELECT TOP 1 id FROM Message ORDER BY id DESC";
                    using (SqlCommand command1 = new SqlCommand(queryMax, mConnection))
                    {
                        SqlDataReader reader = command1.ExecuteReader();
                        reader.Read();
                        maxid = int.Parse(reader[0].ToString());
                        maxid++;
                        mConnection.Close();
                    }
                }

                mConnection = DatabaseManager.CreateConnectionToDatabase();
                using (mConnection)
                {
                    string query = "INSERT INTO Message (id, Sender, Receiver, Subject, Date, Body) VALUES (@id,@sender,@receiver,@subject,GETDATE(),@body)";
                    mConnection.Open();
                    using (SqlCommand command = new SqlCommand(query, mConnection))
                    {
                        command.Parameters.AddWithValue("@id", maxid);
                        command.Parameters.AddWithValue("@sender", mSender.ToString());
                        command.Parameters.AddWithValue("@receiver", Receiver.Text);
                        command.Parameters.AddWithValue("@subject", Subject.Text);
                        command.Parameters.AddWithValue("@body", MainBody.Text);

                        int result = command.ExecuteNonQuery();

                        if (result < 0)
                        {
                            Console.WriteLine("Error inserting data into Database!");
                        }
                        else
                        {
                            MessageBox.Show("Message saved and sent");
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Empty field detected, please fill in everything");
            }
            Receiver.Clear();
            Subject.Clear();
            MainBody.Clear();

            mConnection.Close();
        }