Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ public static class DriveItemRequestBuilderExtensions
/// </summary>
public static CustomDriveItemItemRequestBuilder ItemWithPath(this Microsoft.Graph.Drives.Item.Root.RootRequestBuilder rootRequestBuilder, string path)
{
if (!string.IsNullOrEmpty(path))
if (path is null)
throw new ArgumentNullException(nameof(path));
if (string.IsNullOrWhiteSpace(path))
throw new ArgumentException("path cannot be empty or whitespace.", nameof(path));

if (!path.StartsWith("/"))
{
if (!path.StartsWith("/"))
{
path = string.Format("/{0}", path);
}
path = string.Format("/{0}", path);
}

var requestInformation = rootRequestBuilder.ToGetRequestInformation();
Expand All @@ -67,12 +69,14 @@ public static CustomDriveItemItemRequestBuilder ItemWithPath(this Microsoft.Grap
/// </summary>
public static CustomDriveItemItemRequestBuilder ItemWithPath(this Microsoft.Graph.Drives.Item.Items.Item.DriveItemItemRequestBuilder rootRequestBuilder, string path)
{
if (!string.IsNullOrEmpty(path))
if (path is null)
throw new ArgumentNullException(nameof(path));
if (string.IsNullOrWhiteSpace(path))
throw new ArgumentException("path cannot be empty or whitespace.", nameof(path));

if (!path.StartsWith("/"))
{
if (!path.StartsWith("/"))
{
path = string.Format("/{0}", path);
}
path = string.Format("/{0}", path);
}

var requestInformation = rootRequestBuilder.ToGetRequestInformation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,37 @@ public void ItemByPath_BuildRequestWithNestedPathSlashAndMoreThanOneParameter()
Assert.NotNull(itemRequestInformation);
Assert.Equal(expectedRequestUri, itemRequestInformation.URI);
}
[Fact]
public void ItemByPath_ThrowsArgumentNullException_WhenPathIsNull_Root()
{
var graphServiceClient = new GraphServiceClient(new MockAuthenticationProvider().Object);
Assert.Throws<ArgumentNullException>(() => graphServiceClient.Drives["driveId"].Root.ItemWithPath(null));
}

[Theory]
[InlineData("")]
[InlineData(" ")]
public void ItemByPath_ThrowsArgumentException_WhenPathIsEmptyOrWhitespace_Root(string path)
{
var graphServiceClient = new GraphServiceClient(new MockAuthenticationProvider().Object);
Assert.Throws<ArgumentException>(() => graphServiceClient.Drives["driveId"].Root.ItemWithPath(path));
}

[Fact]
public void ItemByPath_ThrowsArgumentNullException_WhenPathIsNull_DriveItem()
{
var graphServiceClient = new GraphServiceClient(new MockAuthenticationProvider().Object);
Assert.Throws<ArgumentNullException>(() => graphServiceClient.Drives["driveId"].Items["itemId"].ItemWithPath(null));
}

[Theory]
[InlineData("")]
[InlineData(" ")]
public void ItemByPath_ThrowsArgumentException_WhenPathIsEmptyOrWhitespace_DriveItem(string path)
{
var graphServiceClient = new GraphServiceClient(new MockAuthenticationProvider().Object);
Assert.Throws<ArgumentException>(() => graphServiceClient.Drives["driveId"].Items["itemId"].ItemWithPath(path));
}

}
}