Agrendallan
Agrendallan

Reputation: 33

When using inlinedata is it possible to use string.empty?

I was wondering while writing some tests if it was possible to use the by @microsoft declared string.isempty when using xUnit tests. (See below)

I'm a programming student and my teachers recommended using @microsofts already defined methods and consts when possible.

I've tried it but it didn't seemed to work, so thought I might have done something wrong.

[Theory]
[InlineData(string.Empty)]
[InlineData(null)]
[InlineData("        ")]
[InlineData(" ")]
[InlineData(" someRandomText")]
// ... 
public void SetEmailaddress_WrongEmail_IllegalArgumentException(string data) // type of method that is being test, what kind of test, the expected outcome
   {
      //Assert
      Assert.Throws<ArgumentException>(() => _l.Emailaddress = data);
   }

Thanks in advance!

Greetingz

Upvotes: 1

Views: 2009

Answers (1)

gilliduck
gilliduck

Reputation: 2933

It has nothing to do with tests and everything to do with attributes. Attributes must be a compile time constant.

You can go to this question to find out why string.empty is not considered a constant vs ""

Upvotes: 3

Related Questions