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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:13:11+00:00 2026-05-18T08:13:11+00:00

How can I assert that a variable satisfies any one of two values in

  • 0

How can I assert that a variable satisfies any one of two values in Visual Studio’s unit testing environment?

I’ve seen other testing frameworks do it like this:

Assert.That(result.ViewName, Is.EqualTo("HomePage") | Is.Empty);

I’m not experienced with Visual Studio’s unit testing environment.

  • 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-18T08:13:11+00:00Added an answer on May 18, 2026 at 8:13 am

    First of all, I think the sample line of code you typed contains an error, if you have no intention to perform a bitwise OR.

    Assert.That(result.ViewName, Is.EqualTo("HomePage") || Is.Empty);
    

    Secondly, I suspect a misleading test here, since unit testing shall tests for one and only one specific scenario. So, if you assigned, for example, one value to a property, you expect this very value to be returned by its getter.

    Third, here’s how I would go for it, considering I might miss your point and you definitely need to test for either result.

    Assert.IsTrue(string.Equals(result.ViewName, "HomePage") || string.Equals(result.ViewName, string.Empty));
    

    On the other hand, I have never ever tested a scenario where I expected two different results from the same unit test. Assert.That might be good as well.

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

Sidebar

Related Questions

In NUnit, I can write either Assert.That(5, Is.EqualTo(5)); or Assert.AreEqual(5, 5); Is there any
Is there a way that you can assert whether or not a variable is
In a Unit Test (in Visual Studio 2008) I want to compare the content
Suppose we have 3 variables and we need to ASSERT that they can either
I'm writing a unit test for a method that packs boolean values into a
I want to have one variable that contains the root path to all my
Is there a way to assert that a variable (or more specifically, a fact)
How can I assert my Ajax request and test the JSON output from Ruby
If I want to make a rule dynamic so i can use assert after
I was wondering, I am aware you can use assert to add facts or

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.