Example #1
0
        public virtual ApiMutexResponseModel MapBOToModel(
            BOMutex boMutex)
        {
            var model = new ApiMutexResponseModel();

            model.SetProperties(boMutex.Id, boMutex.JSON);

            return(model);
        }
        public void MapResponseToRequest()
        {
            var mapper = new ApiMutexModelMapper();
            var model  = new ApiMutexResponseModel();

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

            response.JSON.Should().Be("A");
        }
Example #3
0
        public void MapBOToModel()
        {
            var     mapper = new BOLMutexMapper();
            BOMutex bo     = new BOMutex();

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

            response.Id.Should().Be("A");
            response.JSON.Should().Be("A");
        }
        public async virtual Task <IActionResult> Get(string id)
        {
            ApiMutexResponseModel response = await this.MutexService.Get(id);

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

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult <Mutex>(null));
            var service = new MutexService(mock.LoggerMock.Object,
                                           mock.RepositoryMock.Object,
                                           mock.ModelValidatorMockFactory.MutexModelValidatorMock.Object,
                                           mock.BOLMapperMockFactory.BOLMutexMapperMock,
                                           mock.DALMapperMockFactory.DALMutexMapperMock);

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

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

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

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

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

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

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

            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 <ApiMutexRequestModel> patch)
        {
            ApiMutexResponseModel record = await this.MutexService.Get(id);

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

                UpdateResponse <ApiMutexResponseModel> result = await this.MutexService.Update(id, model);

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

            response.Should().NotBeNull();
        }