Skip to content

Commit

Permalink
Fixes tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrueastman committed Jan 11, 2023
1 parent 7b2e378 commit 69e6ae5
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public static CustomDriveItemItemRequestBuilder ItemWithPath(this Microsoft.Grap

var requestInformation = rootRequestBuilder.ToGetRequestInformation();
var requestAdapter = rootRequestBuilder.GetRequestAdapter();
requestInformation.PathParameters.Add("baseurl", requestAdapter.BaseUrl);
var requestUrl = requestInformation.URI.OriginalString;

// Encode the path in accordance with the one drive spec
Expand Down Expand Up @@ -73,7 +72,6 @@ public static CustomDriveItemItemRequestBuilder ItemWithPath(this Microsoft.Grap

var requestInformation = rootRequestBuilder.ToGetRequestInformation();
var requestAdapter = rootRequestBuilder.GetRequestAdapter();
requestInformation.PathParameters.Add("baseurl", requestAdapter.BaseUrl);
var requestUrl = requestInformation.URI.OriginalString;

// Encode the path in accordance with the one drive spec
Expand Down Expand Up @@ -101,7 +99,6 @@ public static CustomDriveItemItemRequestBuilder ItemWithPath(this Microsoft.Grap

var requestInformation = rootRequestBuilder.ToGetRequestInformation();
var requestAdapter = rootRequestBuilder.GetRequestAdapter();
requestInformation.PathParameters.Add("baseurl", requestAdapter.BaseUrl);
var requestUrl = requestInformation.URI.OriginalString;

// Encode the path in accordance with the one drive spec
Expand Down Expand Up @@ -129,7 +126,6 @@ public static CustomDriveItemItemRequestBuilder ItemWithPath(this Microsoft.Grap

var requestInformation = rootRequestBuilder.ToGetRequestInformation();
var requestAdapter = rootRequestBuilder.GetRequestAdapter();
requestInformation.PathParameters.Add("baseurl", requestAdapter.BaseUrl);
var requestUrl = requestInformation.URI.OriginalString;

// Encode the path in accordance with the one drive spec
Expand Down Expand Up @@ -157,7 +153,6 @@ public static CustomDriveItemItemRequestBuilder ItemWithPath(this Microsoft.Grap

var requestInformation = rootRequestBuilder.ToGetRequestInformation();
var requestAdapter = rootRequestBuilder.GetRequestAdapter();
requestInformation.PathParameters.Add("baseurl", requestAdapter.BaseUrl);
var requestUrl = requestInformation.URI.OriginalString;

// Encode the path in accordance with the one drive spec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public void ItemById_BuildRequest()
var graphServiceClient = new GraphServiceClient(new MockAuthenticationProvider().Object);
var expectedRequestUri = new Uri(string.Format(Constants.Url.GraphBaseUrlFormatString, "beta") + "/drives/driveId/items/id");
var itemRequestInformation = graphServiceClient.Drives["driveId"].Items["id"].ToGetRequestInformation();
itemRequestInformation.PathParameters.Add("baseurl", graphServiceClient.RequestAdapter.BaseUrl);

Assert.NotNull(itemRequestInformation);
Assert.Equal(expectedRequestUri, itemRequestInformation.URI);
Expand All @@ -30,7 +29,6 @@ public void ItemByPath_BuildRequest()
var graphServiceClient = new GraphServiceClient(new MockAuthenticationProvider().Object);
var expectedRequestUri = new Uri(string.Format(Constants.Url.GraphBaseUrlFormatString, "beta") + "/drives/driveId/root:/item/with/path:");
var itemRequestInformation = graphServiceClient.Drives["driveId"].Root.ItemWithPath("item/with/path").ToGetRequestInformation();
itemRequestInformation.PathParameters.Add("baseurl", graphServiceClient.RequestAdapter.BaseUrl);

Assert.NotNull(itemRequestInformation);
Assert.Equal(expectedRequestUri, itemRequestInformation.URI);
Expand All @@ -42,7 +40,6 @@ public void ItemByPath_BuildRequest2()
var graphServiceClient = new GraphServiceClient(new MockAuthenticationProvider().Object);
var expectedRequestUri = new Uri(string.Format(Constants.Url.GraphBaseUrlFormatString, "beta") + "/drives/driveId/items/itemId:/item/with/path:");
var itemRequestInformation = graphServiceClient.Drives["driveId"].Items["itemId"].ItemWithPath("item/with/path").ToGetRequestInformation();
itemRequestInformation.PathParameters.Add("baseurl", graphServiceClient.RequestAdapter.BaseUrl);

Assert.NotNull(itemRequestInformation);
Assert.Equal(expectedRequestUri, itemRequestInformation.URI);
Expand All @@ -54,8 +51,7 @@ public void ItemByPath_BuildRequestWithLeadingSlash()
var graphServiceClient = new GraphServiceClient(new MockAuthenticationProvider().Object);
var expectedRequestUri = new Uri(string.Format(Constants.Url.GraphBaseUrlFormatString, "beta") + "/drives/driveId/root:/item/with/path:");
var itemRequestInformation = graphServiceClient.Drives["driveId"].Root.ItemWithPath("/item/with/path").ToGetRequestInformation();
itemRequestInformation.PathParameters.Add("baseurl", graphServiceClient.RequestAdapter.BaseUrl);


Assert.NotNull(itemRequestInformation);
Assert.Equal(expectedRequestUri, itemRequestInformation.URI);
}
Expand All @@ -75,7 +71,6 @@ public void ItemByPath_BuildRequestWithSpecialPoundCharacter(string pathInput, s
var graphServiceClient = new GraphServiceClient(new MockAuthenticationProvider().Object);
var expectedRequestUri = new Uri(string.Format(Constants.Url.GraphBaseUrlFormatString, "beta") + "/drives/driveId/root:/" + expectedEncodedPath + ":");
var itemRequestInformation = graphServiceClient.Drives["driveId"].Root.ItemWithPath(pathInput).ToGetRequestInformation();
itemRequestInformation.PathParameters.Add("baseurl", graphServiceClient.RequestAdapter.BaseUrl);

Assert.NotNull(itemRequestInformation);
Assert.Equal(expectedRequestUri, itemRequestInformation.URI);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public void DeletedItems()
var graphServiceClient = new GraphServiceClient(new MockAuthenticationProvider().Object);
var expectedRequestUri = new Uri(string.Format(Constants.Url.GraphBaseUrlFormatString, "beta") + "/me/mailFolders/DeletedItems");
var mailFolderRequestInformation = graphServiceClient.Me.MailFolders["DeletedItems"].ToGetRequestInformation();
mailFolderRequestInformation.PathParameters.Add("baseurl", graphServiceClient.RequestAdapter.BaseUrl);

Assert.NotNull(mailFolderRequestInformation);
Assert.Equal(expectedRequestUri, mailFolderRequestInformation.URI);
Expand All @@ -29,7 +28,6 @@ public void Drafts()
var graphServiceClient = new GraphServiceClient(new MockAuthenticationProvider().Object);
var expectedRequestUri = new Uri(string.Format(Constants.Url.GraphBaseUrlFormatString, "beta") + "/me/mailFolders/Drafts");
var mailFolderRequestInformation = graphServiceClient.Me.MailFolders["Drafts"].ToGetRequestInformation();
mailFolderRequestInformation.PathParameters.Add("baseurl", graphServiceClient.RequestAdapter.BaseUrl);

Assert.NotNull(mailFolderRequestInformation);
Assert.Equal(expectedRequestUri, mailFolderRequestInformation.URI);
Expand All @@ -41,7 +39,6 @@ public void Inbox()
var graphServiceClient = new GraphServiceClient(new MockAuthenticationProvider().Object);
var expectedRequestUri = new Uri(string.Format(Constants.Url.GraphBaseUrlFormatString, "beta") + "/me/mailFolders/Inbox");
var mailFolderRequestInformation = graphServiceClient.Me.MailFolders["Inbox"].ToGetRequestInformation();
mailFolderRequestInformation.PathParameters.Add("baseurl", graphServiceClient.RequestAdapter.BaseUrl);

Assert.NotNull(mailFolderRequestInformation);
Assert.Equal(expectedRequestUri, mailFolderRequestInformation.URI);
Expand All @@ -53,7 +50,6 @@ public void SentItems()
var graphServiceClient = new GraphServiceClient(new MockAuthenticationProvider().Object);
var expectedRequestUri = new Uri(string.Format(Constants.Url.GraphBaseUrlFormatString, "beta") + "/me/mailFolders/SentItems");
var mailFolderRequestInformation = graphServiceClient.Me.MailFolders["SentItems"].ToGetRequestInformation();
mailFolderRequestInformation.PathParameters.Add("baseurl", graphServiceClient.RequestAdapter.BaseUrl);

Assert.NotNull(mailFolderRequestInformation);
Assert.Equal(expectedRequestUri, mailFolderRequestInformation.URI);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,9 @@ public class ActionRequestTests
[Fact]
public void MultipleRequiredParameters()
{
var mockRequestAdapter = new Mock<IRequestAdapter>();
var graphServiceClient = new GraphServiceClient(mockRequestAdapter.Object);
var graphServiceClient = new GraphServiceClient(new MockAuthenticationProvider().Object);
var expectedRequestUrl = $"{string.Format(Constants.Url.GraphBaseUrlFormatString, "beta")}/me/microsoft.graph.assignLicense";

mockRequestAdapter.Setup(
adapter => adapter.SerializationWriterFactory.GetSerializationWriter(It.IsAny<string>())
).Returns(new JsonSerializationWriter());


var addLicenses = new List<AssignedLicense> { new AssignedLicense() };

var requestBody = new AssignLicensePostRequestBody
Expand All @@ -46,7 +41,6 @@ public void MultipleRequiredParameters()
};

var requestInformation = graphServiceClient.Me.AssignLicense.ToPostRequestInformation(requestBody);
requestInformation.PathParameters.Add("baseurl", string.Format(Constants.Url.GraphBaseUrlFormatString, "beta"));

Assert.NotNull(requestInformation);
Assert.Equal(new Uri(expectedRequestUrl), requestInformation.URI);
Expand All @@ -58,17 +52,11 @@ public void MultipleRequiredParameters()
[Fact]
public void OptionalParameterWithNonNullableType_NullValue()
{
var mockRequestAdapter = new Mock<IRequestAdapter>();
var graphServiceClient = new GraphServiceClient(mockRequestAdapter.Object);
var graphServiceClient = new GraphServiceClient(new MockAuthenticationProvider().Object);
var expectedRequestUrl = $"{string.Format(Constants.Url.GraphBaseUrlFormatString, "beta")}/me/microsoft.graph.getMemberGroups";

mockRequestAdapter.Setup(
adapter => adapter.SerializationWriterFactory.GetSerializationWriter(It.IsAny<string>())
).Returns(new JsonSerializationWriter());


var requestBody = new GetMemberGroupsPostRequestBody { };
var requestInformation = graphServiceClient.Me.GetMemberGroups.ToPostRequestInformation(requestBody);
requestInformation.PathParameters.Add("baseurl", string.Format(Constants.Url.GraphBaseUrlFormatString, "beta"));

Assert.NotNull(requestInformation);
Assert.Equal(new Uri(expectedRequestUrl), requestInformation.URI);
Expand All @@ -81,17 +69,11 @@ public void OptionalParameterWithNonNullableType_NullValue()
[Fact]
public void OptionalParameterWithNonNullableType_ValueSet()
{
var mockRequestAdapter = new Mock<IRequestAdapter>();
var graphServiceClient = new GraphServiceClient(mockRequestAdapter.Object);
var graphServiceClient = new GraphServiceClient(new MockAuthenticationProvider().Object);
var expectedRequestUrl = string.Format("{0}/me/microsoft.graph.getMemberGroups", string.Format(Constants.Url.GraphBaseUrlFormatString, "beta"));

mockRequestAdapter.Setup(
adapter => adapter.SerializationWriterFactory.GetSerializationWriter(It.IsAny<string>())
).Returns(new JsonSerializationWriter());

var requestBody = new GetMemberGroupsPostRequestBody { SecurityEnabledOnly = true};
var requestInformation = graphServiceClient.Me.GetMemberGroups.ToPostRequestInformation(requestBody);
requestInformation.PathParameters.Add("baseurl", string.Format(Constants.Url.GraphBaseUrlFormatString, "beta"));

Assert.NotNull(requestInformation);
Assert.Equal(new Uri(expectedRequestUrl), requestInformation.URI);
Expand All @@ -104,14 +86,12 @@ public void OptionalParameterWithNonNullableType_ValueSet()
[Fact]
public void NoParameters()
{
var mockRequestAdapter = new Mock<IRequestAdapter>();
var graphServiceClient = new GraphServiceClient(mockRequestAdapter.Object);
var graphServiceClient = new GraphServiceClient(new MockAuthenticationProvider().Object);
var messageId = "messageId";
var expectedRequestUrl = string.Format("{0}/me/mailFolders/Drafts/messages/{1}/microsoft.graph.send", string.Format(Constants.Url.GraphBaseUrlFormatString, "beta"), messageId);

var requestInformation = graphServiceClient.Me.MailFolders["Drafts"].Messages[messageId].Send.ToPostRequestInformation();
requestInformation.PathParameters.Add("baseurl", string.Format(Constants.Url.GraphBaseUrlFormatString, "beta"));


Assert.NotNull(requestInformation);
Assert.Equal(new Uri(expectedRequestUrl), requestInformation.URI);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.Graph.Beta;
using Microsoft.Graph.Beta.Models;
using Microsoft.Graph.Beta.Models.ODataErrors;
using Microsoft.Graph.DotnetCore.Test.Mocks;
using Microsoft.Kiota.Abstractions;
using Microsoft.Kiota.Abstractions.Serialization;
using Microsoft.Kiota.Serialization.Json;
Expand All @@ -25,11 +26,9 @@ public class CollectionReferencesRequestTests
[Fact]
public void BuildRequest()
{
var mockRequestAdapter = new Mock<IRequestAdapter>();
var graphServiceClient = new GraphServiceClient(mockRequestAdapter.Object);
var graphServiceClient = new GraphServiceClient(new MockAuthenticationProvider().Object);
var expectedRequestUri = new Uri(string.Format(Constants.Url.GraphBaseUrlFormatString, "beta") + "/groups/groupId/members/$ref");
var requestInformation = graphServiceClient.Groups["groupId"].Members.Ref.ToGetRequestInformation();
requestInformation.PathParameters.Add("baseurl", string.Format(Constants.Url.GraphBaseUrlFormatString, "beta"));

Assert.NotNull(requestInformation);
Assert.Equal(expectedRequestUri, requestInformation.URI);
Expand Down Expand Up @@ -90,12 +89,10 @@ public async System.Threading.Tasks.Task AddAsync_IdRequired()
[Fact]
public void Top()
{
var mockRequestAdapter = new Mock<IRequestAdapter>();
var graphServiceClient = new GraphServiceClient(mockRequestAdapter.Object);
var graphServiceClient = new GraphServiceClient(new MockAuthenticationProvider().Object);
var expectedRequestUrl = string.Format("{0}/groups/groupId/members?%24top=1", string.Format(Constants.Url.GraphBaseUrlFormatString, "beta"));

var requestInformation = graphServiceClient.Groups["groupId"].Members.ToGetRequestInformation(requestConfiguration => requestConfiguration.QueryParameters.Top = 1);
requestInformation.PathParameters.Add("baseurl", string.Format(Constants.Url.GraphBaseUrlFormatString, "beta"));

Assert.NotNull(requestInformation);
Assert.Equal(new Uri(expectedRequestUrl), requestInformation.URI);
Expand All @@ -107,14 +104,12 @@ public void Top()
[Fact]
public void OrderBy()
{
var mockRequestAdapter = new Mock<IRequestAdapter>();
var graphServiceClient = new GraphServiceClient(mockRequestAdapter.Object);
var graphServiceClient = new GraphServiceClient(new MockAuthenticationProvider().Object);
var expectedRequestUrl = string.Format("{0}/groups/groupId/members?%24orderby=value", string.Format(Constants.Url.GraphBaseUrlFormatString, "beta"));

var requestInformation = graphServiceClient.Groups["groupId"].Members
.ToGetRequestInformation(requestConfiguration =>
requestConfiguration.QueryParameters.Orderby = new[] { "value" });
requestInformation.PathParameters.Add("baseurl", string.Format(Constants.Url.GraphBaseUrlFormatString, "beta"));

Assert.NotNull(requestInformation);
Assert.Equal(new Uri(expectedRequestUrl), requestInformation.URI);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public void BuildRequest()
var graphServiceClient = new GraphServiceClient(new MockAuthenticationProvider().Object);
var expectedRequestUri = new Uri(string.Format(Constants.Url.GraphBaseUrlFormatString, "beta") + "/groups/groupId/members");
var requestInformation = graphServiceClient.Groups["groupId"].Members.ToGetRequestInformation();
requestInformation.PathParameters.Add("baseurl", graphServiceClient.RequestAdapter.BaseUrl);

Assert.NotNull(requestInformation);
Assert.Equal(expectedRequestUri, requestInformation.URI);
Expand Down Expand Up @@ -80,13 +79,11 @@ public async System.Threading.Tasks.Task GetAsync()
[Fact]
public void Top()
{
var mockRequestAdapter = new Mock<IRequestAdapter>();
var graphServiceClient = new GraphServiceClient(mockRequestAdapter.Object);
var graphServiceClient = new GraphServiceClient(new MockAuthenticationProvider().Object);
var expectedRequestUrl = string.Format("{0}/groups/groupId/members?%24top=1", string.Format(Constants.Url.GraphBaseUrlFormatString, "beta"));

var requestInformation = graphServiceClient.Groups["groupId"].Members.ToGetRequestInformation( requestConfiguration => requestConfiguration.QueryParameters.Top = 1);
requestInformation.PathParameters.Add("baseurl", string.Format(Constants.Url.GraphBaseUrlFormatString, "beta"));


Assert.NotNull(requestInformation);
Assert.Equal(new Uri(expectedRequestUrl),requestInformation.URI);
}
Expand Down
Loading

0 comments on commit 69e6ae5

Please sign in to comment.