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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:29:09+00:00 2026-06-17T22:29:09+00:00

I am creating a unit test that will test company information into the system

  • 0

I am creating a unit test that will test company information into the system but so I can test various assertions in my test.

Here is the code I wrote:

public static Random randnum = new Random();
private string _company = DateTime.Now.ToString("dd/MM/yy ") + ("company") + randnum.Next().ToString();

Basically I am just trying to get a random number to generate with each assertion where the company is listed. So am I writing this wrong or did I forget a piece?

I am using MBUnit.

Please help!

  • 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-17T22:29:10+00:00Added an answer on June 17, 2026 at 10:29 pm

    Rewrite your unit test to use the following.

    public static IEnumerable<object[]> Numbers
        {
            get
            {
                List<object[]> testCases = new List<object[]>();
                Random random = new Random();
                testCases.AddRange(
                    (from x in new[]
                    {1, 2, 3, 4, 5, 6, 7, 8}
                    select new object[] {x})
                    .OrderBy(x=>random.Next()));
                return testCases;
            }
        }
    
        [TestCaseSource("Numbers")]
        public void CreateApplication(
            int number
            )
        {
             string company = DateTime.Now.ToString("dd/MM/yy ") + ("company") + number.ToString();
    
        }
    

    I suspect your issue is with Immutability (Immutable object). You are setting a private _company field with an initial value. Calls to this value wont regenerate the random number but instead use the value created when this class was instantiated.

    Here is a good link which I found interesting regarding random numbers.

    How do I seed a random class to avoid getting duplicate random values

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

Sidebar

Related Questions

I am new to use moq. I am into creating some unit test case
It came to my attention lately that you can unit test abstract base classes
I am creating unit tests with DUnit. I have a class that takes quite
now i'm working on a project for creating audio unit instrument that provide the
I want a simple unit test configuration. My understanding is that the sqlite fluent
Does anybody know of a way in powermock you can unit test a constructor
I've researched some information about techniques I could use to unit test a DbContext
I have been creating Unit tests like crazy and find that I'm often having
I am trying to create a unit test that generates an empty test document
I have some written a number of unit tests that test a wrapper around

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.