1

I want to write a unit test case using xunit and moq for the below method. The method has a stored procedure call and uses executereader.

public bool IsInternalRecipient(string recipientAddress) {
    bool isInternalRecipient = false;
    int domains = recipientAddress.Count(F => f == ‘@‘);
    if (domains = 1) {
        MailAddress address = new MailAddress(recipientAddress)
        string domain = address.Host;
        using(SqlConnection connection = new SqlConnection(DelayedSendConnectionString)) {
            using(var cmd_select = new SqlCommand("spDomainExists", connection)) {
                DateTime LastModified = DateTime.Now.ToLocalTime();
                DateTime ServerSendTime = DateTime.Now.ToUniversalTime @)
                cmd_select.CommandType = CommandType.StoredProcedure;
                cmd_select.Parameters.Add("@Domain", SqlDbType.VarChar, 100).Value = domain;
                try {
                    connection.Open()
                } 
                catch (Exception ex) {
                }
                try {
                    int domainCount = Convert.ToInt16(cmd_select.ExecuteScalar());
                    if (domainCount == 1) {
                        isInternalRecipient = true;
                    }
                } 
                catch (Exception ex) {
                }
                finally {
                    connection.Close();
                }
        }
    }
    return isInternalRecipient;
}

For the above method 'IsInternalRecipient()' method I want to add success and exception unit test case. I am beginner to unit test. Can someone help me out?.

Nkosi
  • 235,767
  • 35
  • 427
  • 472
asif308
  • 90
  • 1
  • 1
  • 9

0 Answers0