public void Constructor_BaseAddress_MustBeAsSpected()
        {
            var client = new OneDriveClient(TokenBuilder.Create().Build());

            var expected = "https://graph.microsoft.com/v1.0/";
            var value    = client._HttpClient.BaseAddress.AbsoluteUri;

            Assert.Equal(expected, value);
        }
Ejemplo n.º 2
0
        public async void CreateMessage_WithContent_MustResultAsSpected()
        {
            var token   = TokenBuilder.Create().Build();
            var handler = new OneDriveClientHandler(token);

            var httpCode    = System.Net.HttpStatusCode.BadRequest;
            var httpContent = "Dummy Content";
            var value       = handler.CreateMessage(httpCode, httpContent);

            Assert.Equal(httpCode, value.StatusCode);
            Assert.Equal(httpContent, await value.Content.ReadAsStringAsync());
        }
Ejemplo n.º 3
0
        public void CreateMessage_WithoutContent_MustResultAsSpected()
        {
            var token   = TokenBuilder.Create().Build();
            var handler = new OneDriveClientHandler(token);

            var httpCode    = System.Net.HttpStatusCode.BadRequest;
            var httpContent = "";
            var value       = handler.CreateMessage(httpCode, httpContent);

            Assert.Equal(httpCode, value.StatusCode);
            Assert.Null(value.Content);
        }
Ejemplo n.º 4
0
        public async void SendAsync_WithoutTokenConnection_MustResultUnauthorized()
        {
            var token   = TokenBuilder.Create().Build();
            var handler = new OneDriveClientHandler(token);

#pragma warning disable CS0618 // Type or member is obsolete
            var value = await handler.InternalSendAsync(null, System.Threading.CancellationToken.None);

#pragma warning restore CS0618 // Type or member is obsolete

            Assert.Equal(System.Net.HttpStatusCode.Unauthorized, value.StatusCode);
            Assert.Equal("The token connect method has failed", await value.Content.ReadAsStringAsync());
        }
        public async void CheckConnectionAsync_InitialConnectionState_MustBeResultFalse()
        {
            var token = TokenBuilder
                        .Create()
                        .WithConnectionState(false)
                        .Build();
            var client = new OneDriveClient(token);

            var expected = false;
            var value    = await client.CheckConnectionAsync();

            Assert.Equal(expected, value);
        }
        public async void Connection_StateAfterConnect_MustResultTrue()
        {
            var token = TokenBuilder
                        .Create()
                        .WithConnectExecution(true)
                        .Build();
            var client = new OneDriveClient(token);

            var expected = true;
            var value    = await client.ConnectAsync();

            Assert.Equal(expected, value);
        }
Ejemplo n.º 7
0
        public async void SendAsync_WithTokenConnection_MustResultSpected()
        {
            var token   = TokenBuilder.Create().WithConnectionState(true).Build();
            var handler = new OneDriveClientHandler(token);

#pragma warning disable CS0618 // Type or member is obsolete
            var request = new HttpRequestMessage(HttpMethod.Get, "http://www.google.com");
            var value   = await handler.InternalSendAsync(request, new System.Threading.CancellationToken());

#pragma warning restore CS0618 // Type or member is obsolete

            Assert.Equal(System.Net.HttpStatusCode.OK, value.StatusCode);
            Assert.StartsWith("<!doctype html>", await value.Content.ReadAsStringAsync());
        }
        public async void GetAsync_WithException_MustThrowException()
        {
            var token      = TokenBuilder.Create().Build();
            var requestUri = "someDummyUrl";
            var exception  = new Exception("Some dummy exception");
            var httpClient = HandlerBuilder.Create().WithException(exception).Build();
            var client     = new OneDriveClient(token, httpClient);

            var expected = exception;
            var value    = await Assert.ThrowsAsync <Exception>(async() => await client.GetAsync(requestUri));

            Assert.NotNull(value);
            Assert.Equal(expected.Message, value.Message);
        }
        public async void PostAsync_WithSuccessOnSecondOverload_MustResultSpectedValue()
        {
            var token      = TokenBuilder.Create().Build();
            var requestUri = "someDummyUrl";
            var expected   = new ProfileVM {
                ID = "Some Test ID"
            };
            var httpClient = HandlerBuilder.Create().WithResult(expected).Build();
            var client     = new OneDriveClient(token, httpClient);

            var value = await client.PostAsync <ProfileVM, ProfileVM>(requestUri, expected);

            Assert.Equal(expected.ID, value.ID);
        }
        public async void GetValueAsync_WithException_MustThrowException()
        {
            var token      = TokenBuilder.Create().Build();
            var exception  = new Exception("Some dummy exception");
            var httpClient = HandlerBuilder.Create().WithException(exception).Build();
            var client     = new OneDriveClient(token, httpClient);

            var messageResponse = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest);

            messageResponse.Content = new StringContent(exception.Message);
            var value = await Assert.ThrowsAsync <Exception>(async() => await client.GetValueAsync <ProfileVM>(messageResponse));

            Assert.NotNull(value);
            Assert.Equal(exception.Message, value.Message);
        }
        public async void Connection_StateAfterDisconnect_MustResultFalse()
        {
            var token = TokenBuilder
                        .Create()
                        .WithConnectExecution(false)
                        .Build();
            var client = new OneDriveClient(token);

            await client.DisconnectAsync();

            var expected = false;
            var value    = await client.CheckConnectionAsync();

            Assert.Equal(expected, value);
        }