Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Added Tests for Setting Element#27807

Merged
danmoseley merged 3 commits intodotnet:masterfrom
Jlalond:configuration-unit-tests
Mar 8, 2018
Merged

Added Tests for Setting Element#27807
danmoseley merged 3 commits intodotnet:masterfrom
Jlalond:configuration-unit-tests

Conversation

@Jlalond
Copy link
Contributor

@Jlalond Jlalond commented Mar 7, 2018

For #15554

I did a small test class here, to get feed back on code style and how the corefx repo does it's unit tests.

While it's my first PR I might as well say I'm pretty new to the industry, and I'm here to contribute to the project in order to learn and grow as a developer. So feedback is appreciated!

Also, GetHashValue for a SettingElement throws a NullReferenceException, and I think that might be a bug.

@dnfclas
Copy link

dnfclas commented Mar 7, 2018

CLA assistant check
All CLA requirements met.

@danmoseley
Copy link
Member

Hi @Jlalond thanks a lot for your first contribution!

Could you please update to match
https://github.com/dotnet/corefx/blob/master/Documentation/coding-guidelines/coding-style.md
Also add the 3-line license text you'll see in most other code files at the top of your C# file?

public void AssureDefaultValueIsNull()
{
SettingElement Element = new SettingElement();
Assert.Equal(Element.Value.CurrentConfiguration, null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Assert.XXX overloads like Assert.Equal, the first parameter is the "expected" and the second parameter is the "actual". So these parameters should be reversed, in order to get accurate error messages if the assert fails.

https://github.com/xunit/assert.xunit/blob/dbb0b75cc8fa9349d63a97d2af453d2cd568faaf/EqualityAsserts.cs#L22

[Fact]
public void TestForInequality()
{
SettingElement ElementOne = new SettingElement("NotEqualOne", SettingsSerializeAs.String);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, per the coding guidelines, we generally use "var" iff the right side is a constructor of the same type. Basically if you are assigning "new Foo(..)" it's almost always into a variable of type "Foo" so it's OK to use "var" and we generally do that. So these SettingElement can be var.


public class SettingElementTests
{

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit extra line here. Also, we put using statements outside of namespace.

@@ -0,0 +1,69 @@
namespace System.Configuration
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We put tests in a namespace suffixed ".Tests"

}

[Fact]
public void AssureDefaultNameIsEmptyString()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, I think "Assure" should probably be "Ensure". Or, many people would just miss off the verb at the front.

Value = new SettingValueElement
{
ValueXml = new ConfigXmlDocument
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're not passing parameters I would not use an initializer (curlies) but instead regular parentheses on the same line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Dan, this is the only one I was confused about what you mean/how to do this without the initlializer

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant you can just do new ConfigXmlDocument() since you aren't setting parameters you don't need the initializer list ({.... })

It's not a big deal though - we can merge like this.

@danmoseley
Copy link
Member

Only a few comments - looks good otherwise! When you've had a chance to fix, someone will sign off and merge for you.

@danmoseley
Copy link
Member

GetHashValue for a SettingElement throws a NullReferenceException, and I think that might be a bug.

You are probably right. We generally do not throw NRE intentionally. However this code is old, and it is probably best not to change its behavior now.

{
var Element = new SettingElement();
Assert.Throws<NullReferenceException>(() => Element.GetHashCode());
//likely a bug
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with you fixing this, and would actually prefer it if you would (assuming you're ok with doing so).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm up for it, I figured I'd start with Tests to get used to code style and get some feedback on the cleanliness of my code (point of work it seems)

Fixing bugs sounds fun though

Copy link
Member

@danmoseley danmoseley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! If you'd like to fix the bug, please open an issue and go ahead and offer a PR for it.

@danmoseley danmoseley merged commit 7e64364 into dotnet:master Mar 8, 2018
@karelz karelz added this to the 2.1.0 milestone Mar 10, 2018
@Jlalond Jlalond deleted the configuration-unit-tests branch May 12, 2018 15:52
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* Added Tests for Setting Element

* Cleaning as per the corefx standards

* including .net license


Commit migrated from dotnet/corefx@7e64364
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants