public async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());

            var createModel = new ApiPostTypeRequestModel();

            createModel.SetProperties("B");
            CreateResponse <ApiPostTypeResponseModel> createResult = await client.PostTypeCreateAsync(createModel);

            createResult.Success.Should().BeTrue();

            ApiPostTypeResponseModel getResponse = await client.PostTypeGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.PostTypeDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();

            ApiPostTypeResponseModel verifyResponse = await client.PostTypeGetAsync(2);

            verifyResponse.Should().BeNull();
        }
        public virtual ApiPostTypeResponseModel MapBOToModel(
            BOPostType boPostType)
        {
            var model = new ApiPostTypeResponseModel();

            model.SetProperties(boPostType.Id, boPostType.Type);

            return(model);
        }
        public void MapResponseToRequest()
        {
            var mapper = new ApiPostTypeModelMapper();
            var model  = new ApiPostTypeResponseModel();

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

            response.Type.Should().Be("A");
        }
        public void MapBOToModel()
        {
            var        mapper = new BOLPostTypeMapper();
            BOPostType bo     = new BOPostType();

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

            response.Id.Should().Be(1);
            response.Type.Should().Be("A");
        }
        public async void TestGet()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());
            ApiPostTypeResponseModel response = await client.PostTypeGetAsync(1);

            response.Should().NotBeNull();
        }
Beispiel #6
0
		public async virtual Task<IActionResult> Get(int id)
		{
			ApiPostTypeResponseModel response = await this.PostTypeService.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 <IPostTypeRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <PostType>(null));
            var service = new PostTypeService(mock.LoggerMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.PostTypeModelValidatorMock.Object,
                                              mock.BOLMapperMockFactory.BOLPostTypeMapperMock,
                                              mock.DALMapperMockFactory.DALPostTypeMapperMock);

            ApiPostTypeResponseModel response = await service.Get(default(int));

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
        public async void TestUpdate()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());

            ApiPostTypeResponseModel model = await client.PostTypeGetAsync(1);

            ApiPostTypeModelMapper mapper = new ApiPostTypeModelMapper();

            UpdateResponse <ApiPostTypeResponseModel> updateResponse = await client.PostTypeUpdateAsync(model.Id, mapper.MapResponseToRequest(model));

            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
        }
Beispiel #9
0
        public async void Create_Errors()
        {
            PostTypeControllerMockFacade mock = new PostTypeControllerMockFacade();

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

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

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

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiPostTypeRequestModel>()));
        }
Beispiel #10
0
        public async void All_Exists()
        {
            PostTypeControllerMockFacade mock = new PostTypeControllerMockFacade();
            var record  = new ApiPostTypeResponseModel();
            var records = new List <ApiPostTypeResponseModel>();

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

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
Beispiel #11
0
		public virtual async Task<IActionResult> Patch(int id, [FromBody] JsonPatchDocument<ApiPostTypeRequestModel> patch)
		{
			ApiPostTypeResponseModel record = await this.PostTypeService.Get(id);

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

				UpdateResponse<ApiPostTypeResponseModel> result = await this.PostTypeService.Update(id, model);

				if (result.Success)
				{
					return this.Ok(result);
				}
				else
				{
					return this.StatusCode(StatusCodes.Status422UnprocessableEntity, result);
				}
			}
		}