Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5955771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:09:40+00:00 2026-05-22T18:09:40+00:00

Hi I have a simple method, where It takes a string as parameter (domainname//firstname.lastname)

  • 0

Hi I have a simple method, where It takes a string as parameter (domainname//firstname.lastname) and takes out (domainname//) and returns string as just firstname.lastname.

I need to unit test for the following case.

  1. check for single slash (domainname/firstname.lastname)
  2. Check for empty string
  3. Check for null value
  4. Check wheather the string contains // or not

I wrote the following but it does not make any sense to me, coz this is completely wrong.

#region Checking for null value
    [TestMethod]
    public void CheckForNullValueTest()
    {
        string expected = "";
        string source = @"domainname//hari.gillala";
        string actual = Function.RemoveSlash(source);
        assert.Equal(expected, actual);
    }
    #endregion

    #region Checking for empty
    [TestMethod]
    public void CheckForEmptyValueTest()
    {
        string expected = string.empty;
        string source = @"domainname//hari.gillala";
        string actual = Function.RemoveSlash(source);
        assert.Equal(expected, actual);
    }
    #endregion

    #region Checking for singleslash
    [TestMethod]
    public void CheckForEmptyValueTest()
    {
        string expected = @"domainname/hari.gillala";
        string source = "domainname//hari.gillala";
        string actual = Function.RemoveSlash(source);
        assert.Equal(expected, actual);
    }
    #endregion


    #region Checking for Doubleslash
    [TestMethod]
    public void CheckForEmptyValueTest()
    {
        string expected = @"domainname//hari.gillala";
        string source = "domainname//hari.gillala";
        string actual = Function.RemoveSlash(source);
        assert.Equal(expected, actual);
    }
    #endregion

I know I am completely wrong, but some can help me to understand, how to write, what are the mistakes. thanks for the patience

Many Thanks
Hari

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:09:40+00:00Added an answer on May 22, 2026 at 6:09 pm

    Your source should be a value you are performing test for:

    E.g. Checking for double slash your source string should contain //.

    Here’s a Sample test (NUnit).

    [Test]
    public void CheckForDoubleSlashValueTest()
    {
        string expected = "hari.gillala";
        string source = @"domainname//hari.gillala";
        string result = MyClass.GetString(source);
        Assert.AreEqual(expected, result);
    }
    
    [Test]
    public void CheckForSingleSlashValueTest()
    {
        string expected = "hari.gillala";
        string source = @"domainname/hari.gillala";
        string result = MyClass.GetString(source);
        Assert.AreEqual(expected, result);
    }
    
    [Test]
    public void CheckForEmptyValueTest()
    {
        string expected = String.Empty;
        string source = String.Empty;
        string result = MyClass.GetString(source);
        Assert.AreEqual(expected, result);
    }
    
    [Test]
    public void CheckForNullValueTest()
    {
        string expected = String.Empty;
        string source = null;
        string result = MyClass.GetString(source);
        Assert.AreEqual(expected, result);
    }
    

    The Class that the Test uses:

    public static class MyClass
        {
            //Returns empty string if source you pass is null or String.Empty
            public static string GetString(string s)
            {
                string name = String.Empty;
                if(!String.IsNullOrEmpty(s)){
                    string[] names = s.Split('/');
                    name = names[names.Length - 1];
                }
                return name;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method that (sometimes) takes in a string in the format dddd
My problem is the following. I have a method which simply takes an XML
Say I have this simple method: public IEnumerable<uint> GetNumbers() { uint n = 0;
I have a simple setter method for a property and null is not appropriate
I have a simple extension method on the int type so I can do
I am simply learing Ajax with jQuery and have a simple page method that
I was wondering if anyone knew why jQuery doesn't have a simple $().id() method.
I have only simple data types in method signature of service (such as int,
I have a simple mapview that has the following viewdidload method and didupdate to
Say I have a simple client/server scenario with one method: // client code $client

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.