Пример #1
0
        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 ApiCallPersonServerModelMapper();
            ApplicationDbContext             context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            ICallPersonService               service = testServer.Host.Services.GetService(typeof(ICallPersonService)) as ICallPersonService;
            ApiCallPersonServerResponseModel model   = await service.Get(1);

            ApiCallPersonClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties("B", 1, 1);

            UpdateResponse <ApiCallPersonClientResponseModel> updateResponse = await client.CallPersonUpdateAsync(model.Id, request);

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

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.Note.Should().Be("B");
            updateResponse.Record.PersonId.Should().Be(1);
            updateResponse.Record.PersonTypeId.Should().Be(1);
        }
Пример #2
0
        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;

            ICallPersonService service = testServer.Host.Services.GetService(typeof(ICallPersonService)) as ICallPersonService;
            var model = new ApiCallPersonServerRequestModel();

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

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

            ActionResponse deleteResult = await client.CallPersonDeleteAsync(2);

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

            verifyResponse.Should().BeNull();
        }
Пример #3
0
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiCallPersonServerResponseModel response = await this.CallPersonService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
Пример #4
0
        public void MapServerResponseToRequest()
        {
            var mapper = new ApiCallPersonServerModelMapper();
            var model  = new ApiCallPersonServerResponseModel();

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

            response.Should().NotBeNull();
            response.Note.Should().Be("A");
            response.PersonId.Should().Be(1);
            response.PersonTypeId.Should().Be(1);
        }
Пример #5
0
        public async void Get_ShouldReturnNullBecauseRecordNotFound()
        {
            var mock = new ServiceMockFacade <ICallPersonService, ICallPersonRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <CallPerson>(null));
            var service = new CallPersonService(mock.LoggerMock.Object,
                                                mock.MediatorMock.Object,
                                                mock.RepositoryMock.Object,
                                                mock.ModelValidatorMockFactory.CallPersonModelValidatorMock.Object,
                                                mock.DALMapperMockFactory.DALCallPersonMapperMock);

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

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

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

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

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

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

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

            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 <ApiCallPersonServerRequestModel> patch)
        {
            ApiCallPersonServerResponseModel record = await this.CallPersonService.Get(id);

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

                UpdateResponse <ApiCallPersonServerResponseModel> result = await this.CallPersonService.Update(id, model);

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