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 8529961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:08:55+00:00 2026-06-11T09:08:55+00:00

Hello I’m trying to test a class that represents layout theme of GUI. It

  • 0

Hello I’m trying to test a class that represents layout theme of GUI. It has color and size properties and a method that sets the default values.

public class LayoutTheme : ILayoutTheme
{
    public LayoutTheme()
    {
        SetTheme();
    }

    public void SetTheme()
    {
        WorkspaceGap = 4;
        SplitBarWidth = 4;
        ApplicationBack = ColorTranslator.FromHtml("#EFEFF2");
        SplitBarBack = ColorTranslator.FromHtml("#CCCEDB");
        PanelBack = ColorTranslator.FromHtml("#FFFFFF ");
        PanelFore = ColorTranslator.FromHtml("#1E1E1E ");
        // ...
    }

    public int WorkspaceGap { get; set; }
    public int SplitBarWidth{ get; set; }
    public Color ApplicationBack { get; set; }
    public Color SplitBarBack { get; set; }
    public Color PanelBack { get; set; }
    public Color PanelFore { get; set; }
    // ...
}

I need to test:
1. If all of the properties are set by the SetTheme method.
2. If there is no duplication in setting a property.

For the first test, I first cycle through all properties and set an unusual value. After that I call SetTheme method and cycle again to check if all properties are changed.

[Test]
public void LayoutTheme_IfPropertiesSet()
{
    var theme = new LayoutTheme();
    Type typeTheme = theme.GetType();

    PropertyInfo[] propInfoList = typeTheme.GetProperties();

    int intValue = int.MinValue;
    Color colorValue = Color.Pink;

    // Set unusual value
    foreach (PropertyInfo propInfo in propInfoList)
    {
        if (propInfo.PropertyType == typeof(int))
            propInfo.SetValue(theme, intValue, null);
        else if (propInfo.PropertyType == typeof(Color))
            propInfo.SetValue(theme, colorValue, null);
        else
            Assert.Fail("Property '{0}' of type '{1}' is not tested!", propInfo.Name, propInfo.PropertyType);
    }

    theme.SetTheme();

    // Check if value changed
    foreach (PropertyInfo propInfo in propInfoList)
    {
        if (propInfo.PropertyType == typeof(int))
            Assert.AreNotEqual(propInfo.GetValue(theme, null), intValue, string.Format("Property '{0}' is not set!", propInfo.Name));
        else if (propInfo.PropertyType == typeof(Color))
            Assert.AreNotEqual(propInfo.GetValue(theme, null), colorValue, string.Format("Property '{0}' is not set!", propInfo.Name));
    }
}

Actually the test works well and I even found two missed settings, but I don’t think it is written well.
Probably it can be don with Moq of the interface and check if all properties are set.

About the second test, don’t have idea how to do it. Probably mocking and checking the number of calls can do it. Any help?

Thank you!

  • 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-06-11T09:08:57+00:00Added an answer on June 11, 2026 at 9:08 am

    For testing if all properties are set to certain values, I would implement Equals() for this class and create a second object with known values and check for equality. This also comes in handy when testing for state changes etc.

    I would certainly not test if a property gets set multiply times if there is no explicit reason to do it.

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

Sidebar

Related Questions

Hello I am trying to create a stacked barplot using the following code: test
Hello everyone i am trying to format the input number range with php number_format
hello friends i am trying to get a list of user id and want
Hello guys I need to pass a string array over to a setter that
Hello Guys I am trying to figure out why i am gettings this error
Hello I have this problem with PyQt4-dev-tools that include: * a user interface compiler
Hello All I am trying to flatten a list in Ocaml. I am a
Hello There, I am new to phonegap.I am trying to record a audio clip
Hello I want to know how to highlight all Words that is inputted in
Hello does any one know that setting I need to ON for connect to

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.