Beispiel #1
0
        public void MapBOToModel()
        {
            var          mapper = new BOLServerTaskMapper();
            BOServerTask bo     = new BOServerTask();

            bo.SetProperties("A", DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), "A", "A", 1, "A", "A", true, true, "A", "A", "A", DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), "A", DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), "A", "A");
            ApiServerTaskResponseModel response = mapper.MapBOToModel(bo);

            response.CompletedTime.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM"));
            response.ConcurrencyTag.Should().Be("A");
            response.Description.Should().Be("A");
            response.DurationSeconds.Should().Be(1);
            response.EnvironmentId.Should().Be("A");
            response.ErrorMessage.Should().Be("A");
            response.HasPendingInterruptions.Should().Be(true);
            response.HasWarningsOrErrors.Should().Be(true);
            response.Id.Should().Be("A");
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
            response.ProjectId.Should().Be("A");
            response.QueueTime.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM"));
            response.ServerNodeId.Should().Be("A");
            response.StartTime.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM"));
            response.State.Should().Be("A");
            response.TenantId.Should().Be("A");
        }
Beispiel #2
0
        public virtual ApiServerTaskResponseModel MapBOToModel(
            BOServerTask boServerTask)
        {
            var model = new ApiServerTaskResponseModel();

            model.SetProperties(boServerTask.Id, boServerTask.CompletedTime, boServerTask.ConcurrencyTag, boServerTask.Description, boServerTask.DurationSeconds, boServerTask.EnvironmentId, boServerTask.ErrorMessage, boServerTask.HasPendingInterruptions, boServerTask.HasWarningsOrErrors, boServerTask.JSON, boServerTask.Name, boServerTask.ProjectId, boServerTask.QueueTime, boServerTask.ServerNodeId, boServerTask.StartTime, boServerTask.State, boServerTask.TenantId);

            return(model);
        }
        public async virtual Task <IActionResult> Get(string id)
        {
            ApiServerTaskResponseModel response = await this.ServerTaskService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <IServerTaskRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult <ServerTask>(null));
            var service = new ServerTaskService(mock.LoggerMock.Object,
                                                mock.RepositoryMock.Object,
                                                mock.ModelValidatorMockFactory.ServerTaskModelValidatorMock.Object,
                                                mock.BOLMapperMockFactory.BOLServerTaskMapperMock,
                                                mock.DALMapperMockFactory.DALServerTaskMapperMock);

            ApiServerTaskResponseModel response = await service.Get(default(string));

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <string>()));
        }
        public async void Create_Errors()
        {
            ServerTaskControllerMockFacade mock = new ServerTaskControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiServerTaskResponseModel> >(new FluentValidation.Results.ValidationResult());
            var mockRecord   = new ApiServerTaskResponseModel();

            mockResponse.SetupGet(x => x.Success).Returns(false);

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiServerTaskRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiServerTaskResponseModel> >(mockResponse.Object));
            ServerTaskController controller = new ServerTaskController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Create(new ApiServerTaskRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiServerTaskRequestModel>()));
        }
        public async void All_Exists()
        {
            ServerTaskControllerMockFacade mock = new ServerTaskControllerMockFacade();
            var record  = new ApiServerTaskResponseModel();
            var records = new List <ApiServerTaskResponseModel>();

            records.Add(record);
            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records));
            ServerTaskController controller = new ServerTaskController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.All(1000, 0);

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            var items = (response as OkObjectResult).Value as List <ApiServerTaskResponseModel>;

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
        public virtual async Task <IActionResult> Patch(string id, [FromBody] JsonPatchDocument <ApiServerTaskRequestModel> patch)
        {
            ApiServerTaskResponseModel record = await this.ServerTaskService.Get(id);

            if (record == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                ApiServerTaskRequestModel model = await this.PatchModel(id, patch);

                UpdateResponse <ApiServerTaskResponseModel> result = await this.ServerTaskService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
        public async void TestGet()
        {
            ApiServerTaskResponseModel response = await this.Client.ServerTaskGetAsync("A");

            response.Should().NotBeNull();
        }