예제 #1
0
        public async Task ListTasks_ReturnsSuccess()
        {
            var httpHandlerMock = new HttpMessageHandlerMock();
            var httpClient      = new HttpClient(httpHandlerMock);

            httpHandlerMock.SendAsyncFunc =
                (request, cancellationToken) =>
                Task.FromResult(
                    new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(
                    ListTasksResponseContent,
                    Encoding.UTF8,
                    "application/json")
            });

            var firstExpectedTask = GetTaskDetailsTests.GetCreatedTask();

            var egnyteClient = new EgnyteClient("token", "acme", httpClient);
            var tasksList    = await egnyteClient.Tasks.ListTasks(firstExpectedTask.File.GroupId);

            var requestMessage = httpHandlerMock.GetHttpRequestMessage();

            Assert.AreEqual(
                "https://acme.egnyte.com/pubapi/v1/tasks?groupId=" + firstExpectedTask.File.GroupId,
                requestMessage.RequestUri.ToString());

            Assert.AreEqual(2, tasksList.Count);
            Assert.AreEqual(2, tasksList.Tasks.Count);
            GetTaskDetailsTests.AssertTasksEqual(firstExpectedTask, tasksList.Tasks.First());
        }
예제 #2
0
        public async Task CreateTask_ReturnsSuccess()
        {
            var httpHandlerMock = new HttpMessageHandlerMock();
            var httpClient      = new HttpClient(httpHandlerMock);

            httpHandlerMock.SendAsyncFunc =
                (request, cancellationToken) =>
                Task.FromResult(
                    new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.Created,
                Content    = new StringContent(
                    GetTaskDetailsTests.CreatedTaskResponse,
                    Encoding.UTF8,
                    "application/json")
            });

            var expectedTask = GetTaskDetailsTests.GetCreatedTask();
            var newTask      = GetNewTask(expectedTask);

            var egnyteClient = new EgnyteClient("token", "acme", httpClient);
            var createdTask  = await egnyteClient.Tasks.CreateTask(newTask);

            var requestMessage = httpHandlerMock.GetHttpRequestMessage();

            Assert.AreEqual("https://acme.egnyte.com/pubapi/v1/tasks", requestMessage.RequestUri.ToString());

            var content = httpHandlerMock.GetRequestContentAsString();

            Assert.AreEqual(
                TestsHelper.RemoveWhitespaces(CreateTaskRequestContent),
                TestsHelper.RemoveWhitespaces(content));

            GetTaskDetailsTests.AssertTasksEqual(expectedTask, createdTask);
        }