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

  • SEARCH
  • Home
  • 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 385113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:26:53+00:00 2026-05-12T15:26:53+00:00

I have been asked to assist in coding a number of MS Unit Tests

  • 0

I have been asked to assist in coding a number of MS Unit Tests for a number of object to object mappings. Can anyone advise what level of testing is appropriate to test the mapping functionality?

Shown below is some (non production) sample code.

public class Foo
{
    public enum FooType
    {
        Active, Deleted, Open, Closed
    }

    public bool IsConditionMet { get; set; }
    public FooType SimpleType { get; set; }
}

public class Bar
{
    public string SomeCondition { get; set; }
    public string SomeAbbreviatedType { get; set; }
}

public static class BarMapper
{
    // sample to mapping code 
    public static Foo Map(Bar bar)
    {
        var foo = new Foo
                      {
                          IsConditionMet = bar.SomeCondition.Equals("y", StringComparison.OrdinalIgnoreCase)
                      };

        // this is sample code and not used in production
        switch (bar.SomeAbbreviatedType)
        {
            case "A":
                foo.SimpleType = Foo.FooType.Active;
                break;

            case "D":
                foo.SimpleType = Foo.FooType.Deleted;
                break;

            case "O":
                foo.SimpleType = Foo.FooType.Open;
                break;

            case "C":
                foo.SimpleType = Foo.FooType.Closed;
                break;
        }

        return foo;
    }
}

I’m not looking for a definition of a unit test, how to write one or an explanation on TDD but specifically looking for an example of what unit tests you’d write given the above example.

Note: Unfortunately due to the nature of the source data using a mapping framework like AutoMapper will not add any value to the project.

Update: This is my example on the appropriate level of testing.

[TestMethod]
public void IsMappingToIsConditionMetCorrect()
{
    var fooIsConditionMetShouldBeTrue = BarMapper.Map(new Bar { SomeCondition = "Y" });
    var fooIsConditionMetShouldBeFalse = BarMapper.Map(new Bar { SomeCondition = "N" });
    var fooIsConditionMetShouldBeFalse_BecauseSomeConditionIsInvalid = BarMapper.Map(new Bar { SomeCondition = "SOMETHING" });

    Assert.IsTrue(fooIsConditionMetShouldBeTrue);
    Assert.IsFalse(fooIsConditionMetShouldBeFalse);
    Assert.IsFalse(fooIsConditionMetShouldBeFalse_BecauseSomeConditionIsInvalid);
}

[TestMethod]
public void TestsCanBuild()
{
    var fooAbbreviatedTypeShouldBeA = BarMapper.Map(new Bar { SomeAbbreviatedType = "A" });
    var fooAbbreviatedTypeShouldBeD = BarMapper.Map(new Bar { SomeAbbreviatedType = "D" });
    var fooAbbreviatedTypeShouldBeO = BarMapper.Map(new Bar { SomeAbbreviatedType = "O" });
    var fooAbbreviatedTypeShouldBeC = BarMapper.Map(new Bar { SomeAbbreviatedType = "C" });

    Assert.AreSame(Foo.FooType.Active, fooAbbreviatedTypeShouldBeA);
    Assert.AreSame(Foo.FooType.Deleted, fooAbbreviatedTypeShouldBeD);
    Assert.AreSame(Foo.FooType.Open, fooAbbreviatedTypeShouldBeO);
    Assert.AreSame(Foo.FooType.Closed, fooAbbreviatedTypeShouldBeC);

    // TODO: test for an incorrect "SomeAbbreviatedType" property value
}
  • 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-12T15:26:53+00:00Added an answer on May 12, 2026 at 3:26 pm

    Your tests look fairly reasonably (when you implement TODO: test for an incorrect “SomeAbbreviatedType” property value), there is not much more you can test. One thing I would personally look into a bit more is error handling, e.g. is it valid for Bar to have SomeAbbreviatedType empty? Maybe should it be an enum, etc.? But from testing perspective its alright.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been asked to audit any/all changes in a MySQL table. Does anyone
I have been asked to migrate a schema from our testing area into our
I have been asked to do this: Please input Number: 4 +-+-+-+ + +
I have been asked to program a routine to decide the number of possible
I have been asked about creating a site where some users can upload Microsoft
I have been asked in an interview how one can return more than one
I have been asked to order products on a site to show any products
I have been asked to lend a hand on a hobby project that a
I have been asked to standardize the screen saver and desktop background used by
I have been asked to develop some usercontrols in ASP.NET that will at a

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.