public virtual ApiSubscriptionResponseModel MapBOToModel(
            BOSubscription boSubscription)
        {
            var model = new ApiSubscriptionResponseModel();

            model.SetProperties(boSubscription.Id, boSubscription.IsDisabled, boSubscription.JSON, boSubscription.Name, boSubscription.Type);

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

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
        public void MapResponseToRequest()
        {
            var mapper = new ApiSubscriptionModelMapper();
            var model  = new ApiSubscriptionResponseModel();

            model.SetProperties("A", true, "A", "A", "A");
            ApiSubscriptionRequestModel response = mapper.MapResponseToRequest(model);

            response.IsDisabled.Should().Be(true);
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
            response.Type.Should().Be("A");
        }
Exemplo n.º 4
0
        public void MapBOToModel()
        {
            var            mapper = new BOLSubscriptionMapper();
            BOSubscription bo     = new BOSubscription();

            bo.SetProperties("A", true, "A", "A", "A");
            ApiSubscriptionResponseModel response = mapper.MapBOToModel(bo);

            response.Id.Should().Be("A");
            response.IsDisabled.Should().Be(true);
            response.JSON.Should().Be("A");
            response.Name.Should().Be("A");
            response.Type.Should().Be("A");
        }
Exemplo n.º 5
0
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <ISubscriptionRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult <Subscription>(null));
            var service = new SubscriptionService(mock.LoggerMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.SubscriptionModelValidatorMock.Object,
                                                  mock.BOLMapperMockFactory.BOLSubscriptionMapperMock,
                                                  mock.DALMapperMockFactory.DALSubscriptionMapperMock);

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

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

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

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

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

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

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

            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 <ApiSubscriptionRequestModel> patch)
        {
            ApiSubscriptionResponseModel record = await this.SubscriptionService.Get(id);

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

                UpdateResponse <ApiSubscriptionResponseModel> result = await this.SubscriptionService.Update(id, model);

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

            response.Should().NotBeNull();
        }