Skip to content

Commit 19a7c21

Browse files
committed
Fix it and forget
1 parent b84d54b commit 19a7c21

File tree

2 files changed

+10
-49
lines changed

2 files changed

+10
-49
lines changed

dotnet/src/webdriver/PrintOptions.cs

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,9 @@ public bool ShrinkToFit
106106
public PageSize PageDimensions
107107
{
108108
get { return pageSize; }
109-
set
110-
{
111-
if (value == null)
112-
{
113-
throw new ArgumentNullException("PageDimensions cannot be set to null");
114-
}
115-
116-
pageSize = value;
109+
set
110+
{
111+
pageSize = value ?? throw new ArgumentNullException(nameof(value));
117112
}
118113
}
119114

@@ -123,14 +118,9 @@ public PageSize PageDimensions
123118
public Margins PageMargins
124119
{
125120
get { return margins; }
126-
set
127-
{
128-
if (value == null)
129-
{
130-
throw new ArgumentNullException("PageMargins cannot be set to null");
131-
}
132-
133-
margins = value;
121+
set
122+
{
123+
margins = value ?? throw new ArgumentNullException(nameof(value));
134124
}
135125
}
136126

@@ -216,7 +206,7 @@ internal Dictionary<string, object> ToDictionary()
216206
{
217207
toReturn["shrinkToFit"] = this.shrinkToFit;
218208
}
219-
209+
220210
if (this.pageSize.Height != DefaultPageHeight || this.pageSize.Width != DefaultPageWidth)
221211
{
222212
Dictionary<string, object> pageSizeDictionary = new Dictionary<string, object>();
@@ -274,11 +264,6 @@ public double Height
274264
get { return height; }
275265
set
276266
{
277-
if (value == null)
278-
{
279-
throw new ArgumentNullException("Height cannot be set to null");
280-
}
281-
282267
if (value < 0)
283268
{
284269
throw new ArgumentException("Height must be greater than or equal to zero.");
@@ -296,11 +281,6 @@ public double Width
296281
get { return width; }
297282
set
298283
{
299-
if (value == null)
300-
{
301-
throw new ArgumentNullException("Width cannot be set to null");
302-
}
303-
304284
if (value < 0)
305285
{
306286
throw new ArgumentException("Width must be greater than or equal to zero.");
@@ -347,11 +327,6 @@ public double Top
347327
get { return top; }
348328
set
349329
{
350-
if (value == null)
351-
{
352-
throw new ArgumentNullException("Top cannot be set to null");
353-
}
354-
355330
if (value < 0)
356331
{
357332
throw new ArgumentException("Top margin must be greater than or equal to zero.");
@@ -369,11 +344,6 @@ public double Bottom
369344
get { return bottom; }
370345
set
371346
{
372-
if (value == null)
373-
{
374-
throw new ArgumentNullException("Bottom cannot be set to null");
375-
}
376-
377347
if (value < 0)
378348
{
379349
throw new ArgumentException("Bottom margin must be greater than or equal to zero.");
@@ -391,11 +361,6 @@ public double Left
391361
get { return left; }
392362
set
393363
{
394-
if (value == null)
395-
{
396-
throw new ArgumentNullException("Left cannot be set to null");
397-
}
398-
399364
if (value < 0)
400365
{
401366
throw new ArgumentException("Left margin must be greater than or equal to zero.");
@@ -413,11 +378,6 @@ public double Right
413378
get { return right; }
414379
set
415380
{
416-
if (value == null)
417-
{
418-
throw new ArgumentNullException("Right cannot be set to null");
419-
}
420-
421381
if (value < 0)
422382
{
423383
throw new ArgumentException("Right margin must be greater than or equal to zero.");

dotnet/test/common/PrintTest.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using NUnit.Framework;
2+
using System;
23

34
namespace OpenQA.Selenium
45
{
@@ -61,13 +62,13 @@ public void CanPrintWithMostParams()
6162
[Test]
6263
public void PageSizeCannotBeNull()
6364
{
64-
assert.That(() => printer.Print(new PrintOptions { PageDimensions = null }), Throws.InstanceOf<ArgumentNullException>());
65+
Assert.That(() => new PrintOptions { PageDimensions = null }, Throws.InstanceOf<ArgumentNullException>());
6566
}
6667

6768
[Test]
6869
public void MarginsCannotBeNull()
6970
{
70-
assert.That(() => printer.Print(new PrintOptions { PageMargins = null }), Throws.InstanceOf<ArgumentNullException>());
71+
Assert.That(() => new PrintOptions { PageMargins = null }, Throws.InstanceOf<ArgumentNullException>());
7172
}
7273
}
7374
}

0 commit comments

Comments
 (0)