public virtual ApiChannelResponseModel MapBOToModel(
            BOChannel boChannel)
        {
            var model = new ApiChannelResponseModel();

            model.SetProperties(boChannel.Id, boChannel.DataVersion, boChannel.JSON, boChannel.LifecycleId, boChannel.Name, boChannel.ProjectId, boChannel.TenantTags);

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

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
        public async virtual Task <IActionResult> ByNameProjectId(string name, string projectId)
        {
            ApiChannelResponseModel response = await this.ChannelService.ByNameProjectId(name, projectId);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
Exemplo n.º 4
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiChannelModelMapper();
            var model  = new ApiChannelResponseModel();

            model.SetProperties("A", BitConverter.GetBytes(1), "A", "A", "A", "A", "A");
            ApiChannelRequestModel response = mapper.MapResponseToRequest(model);

            response.DataVersion.Should().BeEquivalentTo(BitConverter.GetBytes(1));
            response.JSON.Should().Be("A");
            response.LifecycleId.Should().Be("A");
            response.Name.Should().Be("A");
            response.ProjectId.Should().Be("A");
            response.TenantTags.Should().Be("A");
        }
Exemplo n.º 5
0
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <IChannelRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult <Channel>(null));
            var service = new ChannelService(mock.LoggerMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.ChannelModelValidatorMock.Object,
                                             mock.BOLMapperMockFactory.BOLChannelMapperMock,
                                             mock.DALMapperMockFactory.DALChannelMapperMock);

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

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <string>()));
        }
Exemplo n.º 6
0
        public void MapBOToModel()
        {
            var       mapper = new BOLChannelMapper();
            BOChannel bo     = new BOChannel();

            bo.SetProperties("A", BitConverter.GetBytes(1), "A", "A", "A", "A", "A");
            ApiChannelResponseModel response = mapper.MapBOToModel(bo);

            response.DataVersion.Should().BeEquivalentTo(BitConverter.GetBytes(1));
            response.Id.Should().Be("A");
            response.JSON.Should().Be("A");
            response.LifecycleId.Should().Be("A");
            response.Name.Should().Be("A");
            response.ProjectId.Should().Be("A");
            response.TenantTags.Should().Be("A");
        }
Exemplo n.º 7
0
        public async void ByNameProjectId_Exists()
        {
            var mock   = new ServiceMockFacade <IChannelRepository>();
            var record = new Channel();

            mock.RepositoryMock.Setup(x => x.ByNameProjectId(It.IsAny <string>(), It.IsAny <string>())).Returns(Task.FromResult(record));
            var service = new ChannelService(mock.LoggerMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.ChannelModelValidatorMock.Object,
                                             mock.BOLMapperMockFactory.BOLChannelMapperMock,
                                             mock.DALMapperMockFactory.DALChannelMapperMock);

            ApiChannelResponseModel response = await service.ByNameProjectId(default(string), default(string));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.ByNameProjectId(It.IsAny <string>(), It.IsAny <string>()));
        }
Exemplo n.º 8
0
        public async void Create_Errors()
        {
            ChannelControllerMockFacade mock = new ChannelControllerMockFacade();

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

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

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiChannelRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiChannelResponseModel> >(mockResponse.Object));
            ChannelController controller = new ChannelController(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 ApiChannelRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiChannelRequestModel>()));
        }
Exemplo n.º 9
0
        public async void All_Exists()
        {
            ChannelControllerMockFacade mock = new ChannelControllerMockFacade();
            var record  = new ApiChannelResponseModel();
            var records = new List <ApiChannelResponseModel>();

            records.Add(record);
            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records));
            ChannelController controller = new ChannelController(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 <ApiChannelResponseModel>;

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
Exemplo n.º 10
0
        public virtual async Task <IActionResult> Patch(string id, [FromBody] JsonPatchDocument <ApiChannelRequestModel> patch)
        {
            ApiChannelResponseModel record = await this.ChannelService.Get(id);

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

                UpdateResponse <ApiChannelResponseModel> result = await this.ChannelService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Exemplo n.º 11
0
        public async void TestGet()
        {
            ApiChannelResponseModel response = await this.Client.ChannelGetAsync("A");

            response.Should().NotBeNull();
        }