Esempio n. 1
0
        public void TaskConverterEntityToModelWithStructureTest()
        {
            IJsonConverter            jsonConverter            = new JsonConverter(LoggerFactory);
            ICachedExpressionCompiler cachedExpressionCompiler = new CachedExpressionCompiler(LoggerFactory);
            IExpressionConverter      expressionConverter      = new ExpressionConverter(jsonConverter, cachedExpressionCompiler, LoggerFactory);
            ITaskConverter            taskConverter            = new TaskConverter(expressionConverter, jsonConverter, LoggerFactory);

            TestTaskConverterClass instance = new TestTaskConverterClass();

            ActivationData activationData = expressionConverter.Convert(() => instance.MethodJustClass(TaskCancellationToken.Null));

            TaskModel taskModel = new TaskModel(1, 2, 3, activationData, TaskStates.New, new ScheduleInformation(1));

            TaskEntity taskEntity = taskConverter.Convert(taskModel);

            Assert.IsNotNull(taskEntity);

            TaskModel actual = taskConverter.Convert(taskEntity);

            Assert.IsNotNull(actual);

            Assert.AreEqual(taskEntity.Id, actual.Id);
            Assert.AreEqual(taskEntity.QueueId, actual.QueueId);
            Assert.AreEqual(taskEntity.TaskState, actual.TaskState);
        }
Esempio n. 2
0
        public async Task <IActionResult> GetTaskAsync([FromRoute] string taskId, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (!Guid.TryParse(taskId, out var modeltaskId))
            {
                return(this.NotFound());
            }

            Models.Tasks.MyTask modelTask = null;
            try
            {
                modelTask = await this.tasks.GetAsync(modeltaskId, cancellationToken);
            }
            catch (Models.Tasks.TaskNotFoundException)
            {
                return(this.NotFound());
            }

            if (!UserHaveTaskAccess(modelTask))
            {
                return(Forbid());
            }

            var clientTask = TaskConverter.Convert(modelTask);

            return(this.Ok(clientTask));
        }