예제 #1
0
        public async Task UpdateTaskStatusFails()
        {
            //Arrange
            var helperHttpClientMoq = new Mock <ITaskHttpClientHelper>();
            var taskId         = It.IsAny <Guid>();
            var taskStateValue = It.IsAny <int>();
            var context        = GetContext();

            var response = new TaskDataResponseModel(taskId, It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <DateTime>(),
                                                     It.IsAny <TaskState>(), It.IsAny <IReadOnlyList <AssignedActors> >(), It.IsAny <Reference>());

            var responseData = JsonConvert.SerializeObject(response);


            var taskUpdateStatus = new TaskUpdateStatus()
            {
                TaskAction  = TaskAction.Completed,
                TaskContext = TaskContext.Citizens
            };

            var error = new Error("123456", new string[] { "Some error occured while updating task status" }, "MCA");

            helperHttpClientMoq.Setup(x => x.UpdateTaskStatusByTaskIdFromMomentumCoreAsync($"/tasks/{taskId}/{taskStateValue}?applicationContext={TaskContext.Citizens}"))
            .Returns(Task.FromResult(new ResultOrHttpError <string, Error>(error, HttpStatusCode.BadRequest)));

            var taskService = new TaskService(helperHttpClientMoq.Object, context.Object);

            //Act
            var result = await taskService.UpdateTaskStatusByIdAsync(taskId.ToString(), taskUpdateStatus).ConfigureAwait(false);

            //Asert
            result.IsError.Should().BeTrue();
            result.Error.Errors[0].Should().BeEquivalentTo("Some error occured while updating task status");
        }
예제 #2
0
        public async Task UpdateTaskStatusSuccess()
        {
            //Arrange
            var helperHttpClientMoq = new Mock <ITaskHttpClientHelper>();
            var taskId         = It.IsAny <Guid>();
            var taskStateValue = It.IsAny <int>();
            var context        = GetContext();

            var response = new TaskDataResponseModel(taskId, It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <DateTime>(),
                                                     It.IsAny <TaskState>(), It.IsAny <IReadOnlyList <AssignedActors> >(), It.IsAny <Reference>());

            var responseData = JsonConvert.SerializeObject(response);


            var taskUpdateStatus = new TaskUpdateStatus()
            {
                TaskAction  = TaskAction.Completed,
                TaskContext = TaskContext.Citizens
            };

            helperHttpClientMoq.Setup(x => x.UpdateTaskStatusByTaskIdFromMomentumCoreAsync($"/tasks/{taskId}/{taskStateValue}?applicationContext={TaskContext.Citizens}"))
            .Returns(Task.FromResult(new ResultOrHttpError <string, Error>(responseData)));

            var taskService = new TaskService(helperHttpClientMoq.Object, context.Object);

            //Act
            var result = await taskService.UpdateTaskStatusByIdAsync(taskId.ToString(), taskUpdateStatus).ConfigureAwait(false);

            //Asert
            result.Should().NotBeNull();
            result.IsError.Should().BeFalse();
            result.Result.Should().BeEquivalentTo(response);
        }
예제 #3
0
        public async Task <ResultOrHttpError <TaskDataResponseModel, Error> > UpdateTaskStatusByIdAsync(string taskId, TaskUpdateStatus taskUpdateStatus)
        {
            var taskStateValue = (int)taskUpdateStatus.TaskAction;
            var response       = await _taskHttpClient.UpdateTaskStatusByTaskIdFromMomentumCoreAsync($"/tasks/{taskId}/{taskStateValue}?applicationContext={taskUpdateStatus.TaskContext}").ConfigureAwait(false);

            if (response.IsError)
            {
                var error = response.Error.Errors.Aggregate((a, b) => a + "," + b);
                Log.ForContext("CorrelationId", _correlationId)
                .ForContext("Client", _clientId)
                .ForContext("TaskId", taskId)
                .Error("An error occured while updating task state" + error);
                return(new ResultOrHttpError <TaskDataResponseModel, Error>(response.Error, response.StatusCode.Value));
            }

            var content     = response.Result;
            var taskDataObj = JsonConvert.DeserializeObject <TaskData>(content);

            var dataToReturn = new TaskDataResponseModel(taskDataObj.Id, taskDataObj.Title, taskDataObj.Description, taskDataObj.Deadline, taskDataObj.CreatedAt,
                                                         taskDataObj.StateChangedAt, taskDataObj.State, (IReadOnlyList <AssignedActors>)taskDataObj.AssignedActors, taskDataObj.Reference);

            Log.ForContext("CorrelationId", _correlationId)
            .ForContext("Client", _clientId)
            .ForContext("TaskId", taskDataObj.Id)
            .Information("The Task status is updated successfully");

            return(new ResultOrHttpError <TaskDataResponseModel, Error>(dataToReturn));
        }
예제 #4
0
        public async Task <ResultOrHttpError <TaskList, Error> > GetAllTasksByCaseworkerIdFromMomentumCoreAsync(string path, int pageNumber, string caseworkerId)
        {
            var pageSize = 100;

            pageNumber = pageNumber == 0 ? 1 : pageNumber;
            List <TaskDataResponseModel> totalRecords = new List <TaskDataResponseModel>();
            var Result = new TaskSearchQuery()
            {
                AssignedActors = new List <string>()
                {
                    caseworkerId
                },
                Types = new List <TaskType>()
                {
                },
            };
            string        serializedRequest = JsonConvert.SerializeObject(Result);
            StringContent stringContent     = new StringContent(serializedRequest, Encoding.UTF8, "application/json");

            var queryStringParams = $"pagingInfo.pageNumber={pageNumber}&pagingInfo.pageSize={pageSize}";

            var response = await _meaClient.PostAsync(path + "?" + queryStringParams, stringContent).ConfigureAwait(false);

            if (response.IsError)
            {
                return(new ResultOrHttpError <TaskList, Error>(response.Error, response.StatusCode.Value));
            }

            var content           = response.Result;
            var caseworkerDataObj = JsonConvert.DeserializeObject <TaskPagedData>(content);
            var records           = caseworkerDataObj.Data;

            foreach (var item in records)
            {
                var dataToReturn = new TaskDataResponseModel(item.Id, item.Title, item.Description, item.Deadline, item.CreatedAt,
                                                             item.StateChangedAt, item.State, (IReadOnlyList <AssignedActors>)item.AssignedActors, item.Reference);
                totalRecords.Add(dataToReturn);
            }

            var responseData = new TaskList()
            {
                PageNo           = pageNumber,
                TotalNoOfPages   = caseworkerDataObj.TotalPages,
                TotalSearchCount = caseworkerDataObj.TotalSearchCount,
                Result           = totalRecords
            };

            return(new ResultOrHttpError <TaskList, Error>(responseData));
        }