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

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

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            var mapper = new ApiPostTypeServerModelMapper();
            ApplicationDbContext           context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IPostTypeService               service = testServer.Host.Services.GetService(typeof(IPostTypeService)) as IPostTypeService;
            ApiPostTypeServerResponseModel model   = await service.Get(1);

            ApiPostTypeClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties("B");

            UpdateResponse <ApiPostTypeClientResponseModel> updateResponse = await client.PostTypeUpdateAsync(model.Id, request);

            context.Entry(context.Set <PostType>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <PostType>().ToList()[0].RwType.Should().Be("B");

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.RwType.Should().Be("B");
        }
        public virtual async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);
            var        client     = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;

            IPostTypeService service = testServer.Host.Services.GetService(typeof(IPostTypeService)) as IPostTypeService;
            var model = new ApiPostTypeServerRequestModel();

            model.SetProperties("B");
            CreateResponse <ApiPostTypeServerResponseModel> createdResponse = await service.Create(model);

            createdResponse.Success.Should().BeTrue();

            ActionResponse deleteResult = await client.PostTypeDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();
            ApiPostTypeServerResponseModel verifyResponse = await service.Get(2);

            verifyResponse.Should().BeNull();
        }
        public void MapServerResponseToRequest()
        {
            var mapper = new ApiPostTypeServerModelMapper();
            var model  = new ApiPostTypeServerResponseModel();

            model.SetProperties(1, "A");
            ApiPostTypeServerRequestModel response = mapper.MapServerResponseToRequest(model);

            response.Should().NotBeNull();
            response.RwType.Should().Be("A");
        }
예제 #4
0
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiPostTypeServerResponseModel response = await this.PostTypeService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
예제 #5
0
        public async void Get_ShouldReturnNullBecauseRecordNotFound()
        {
            var mock = new ServiceMockFacade <IPostTypeService, IPostTypeRepository>();

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

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

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
예제 #6
0
        public async void Create_Errors()
        {
            PostTypeControllerMockFacade mock = new PostTypeControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiPostTypeServerResponseModel> >(null as ApiPostTypeServerResponseModel);
            var mockRecord   = new ApiPostTypeServerResponseModel();

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

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiPostTypeServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiPostTypeServerResponseModel> >(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 ApiPostTypeServerRequestModel());

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

            records.Add(record);
            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).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, string.Empty);

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

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

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

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

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