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 ApiPersonRequestModel();

            createModel.SetProperties("B");
            CreateResponse <ApiPersonResponseModel> createResult = await client.PersonCreateAsync(createModel);

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

            ApiPersonResponseModel getResponse = await client.PersonGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.PersonDeleteAsync(2);

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

            ApiPersonResponseModel verifyResponse = await client.PersonGetAsync(2);

            verifyResponse.Should().BeNull();
        }
Esempio n. 2
0
        public async void Get()
        {
            var mock   = new ServiceMockFacade <IPersonRepository>();
            var record = new Person();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(record));
            var service = new PersonService(mock.LoggerMock.Object,
                                            mock.RepositoryMock.Object,
                                            mock.ModelValidatorMockFactory.PersonModelValidatorMock.Object,
                                            mock.BOLMapperMockFactory.BOLPersonMapperMock,
                                            mock.DALMapperMockFactory.DALPersonMapperMock,
                                            mock.BOLMapperMockFactory.BOLBusinessEntityContactMapperMock,
                                            mock.DALMapperMockFactory.DALBusinessEntityContactMapperMock,
                                            mock.BOLMapperMockFactory.BOLEmailAddressMapperMock,
                                            mock.DALMapperMockFactory.DALEmailAddressMapperMock,
                                            mock.BOLMapperMockFactory.BOLPasswordMapperMock,
                                            mock.DALMapperMockFactory.DALPasswordMapperMock,
                                            mock.BOLMapperMockFactory.BOLPersonPhoneMapperMock,
                                            mock.DALMapperMockFactory.DALPersonPhoneMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
        public virtual ApiPersonResponseModel MapBOToModel(
            BOPerson boPerson)
        {
            var model = new ApiPersonResponseModel();

            model.SetProperties(boPerson.BusinessEntityID, boPerson.AdditionalContactInfo, boPerson.Demographic, boPerson.EmailPromotion, boPerson.FirstName, boPerson.LastName, boPerson.MiddleName, boPerson.ModifiedDate, boPerson.NameStyle, boPerson.PersonType, boPerson.Rowguid, boPerson.Suffix, boPerson.Title);

            return(model);
        }
Esempio n. 4
0
        public virtual ApiPersonResponseModel MapBOToModel(
            BOPerson boPerson)
        {
            var model = new ApiPersonResponseModel();

            model.SetProperties(boPerson.PersonId, boPerson.PersonName);

            return(model);
        }
        public void MapResponseToRequest()
        {
            var mapper = new ApiPersonModelMapper();
            var model  = new ApiPersonResponseModel();

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

            response.PersonName.Should().Be("A");
        }
Esempio n. 6
0
        public void MapBOToModel()
        {
            var      mapper = new BOLPersonMapper();
            BOPerson bo     = new BOPerson();

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

            response.PersonId.Should().Be(1);
            response.PersonName.Should().Be("A");
        }
Esempio n. 7
0
        public async void TestGet()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());
            ApiPersonResponseModel response = await client.PersonGetAsync(1);

            response.Should().NotBeNull();
        }
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiPersonResponseModel response = await this.PersonService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
Esempio n. 9
0
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <IPersonRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Person>(null));
            var service = new PersonService(mock.LoggerMock.Object,
                                            mock.RepositoryMock.Object,
                                            mock.ModelValidatorMockFactory.PersonModelValidatorMock.Object,
                                            mock.BOLMapperMockFactory.BOLPersonMapperMock,
                                            mock.DALMapperMockFactory.DALPersonMapperMock);

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

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

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

            ApiPersonResponseModel model = await client.PersonGetAsync(1);

            ApiPersonModelMapper mapper = new ApiPersonModelMapper();

            UpdateResponse <ApiPersonResponseModel> updateResponse = await client.PersonUpdateAsync(model.BusinessEntityID, mapper.MapResponseToRequest(model));

            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
        }
Esempio n. 11
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiPersonModelMapper();
            var model  = new ApiPersonResponseModel();

            model.SetProperties(1, "A", "A", 1, "A", "A", "A", DateTime.Parse("1/1/1987 12:00:00 AM"), true, "A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), "A", "A");
            ApiPersonRequestModel response = mapper.MapResponseToRequest(model);

            response.AdditionalContactInfo.Should().Be("A");
            response.Demographic.Should().Be("A");
            response.EmailPromotion.Should().Be(1);
            response.FirstName.Should().Be("A");
            response.LastName.Should().Be("A");
            response.MiddleName.Should().Be("A");
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.NameStyle.Should().Be(true);
            response.PersonType.Should().Be("A");
            response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
            response.Suffix.Should().Be("A");
            response.Title.Should().Be("A");
        }
Esempio n. 12
0
        public async void Create_Errors()
        {
            PersonControllerMockFacade mock = new PersonControllerMockFacade();

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

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

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

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiPersonRequestModel>()));
        }
Esempio n. 13
0
        public async void All_Exists()
        {
            PersonControllerMockFacade mock = new PersonControllerMockFacade();
            var record  = new ApiPersonResponseModel();
            var records = new List <ApiPersonResponseModel>();

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

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
Esempio n. 14
0
        public void MapBOToModel()
        {
            var      mapper = new BOLPersonMapper();
            BOPerson bo     = new BOPerson();

            bo.SetProperties(1, "A", "A", 1, "A", "A", "A", DateTime.Parse("1/1/1987 12:00:00 AM"), true, "A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), "A", "A");
            ApiPersonResponseModel response = mapper.MapBOToModel(bo);

            response.AdditionalContactInfo.Should().Be("A");
            response.BusinessEntityID.Should().Be(1);
            response.Demographic.Should().Be("A");
            response.EmailPromotion.Should().Be(1);
            response.FirstName.Should().Be("A");
            response.LastName.Should().Be("A");
            response.MiddleName.Should().Be("A");
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.NameStyle.Should().Be(true);
            response.PersonType.Should().Be("A");
            response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
            response.Suffix.Should().Be("A");
            response.Title.Should().Be("A");
        }
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiPersonRequestModel> patch)
        {
            ApiPersonResponseModel record = await this.PersonService.Get(id);

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

                UpdateResponse <ApiPersonResponseModel> result = await this.PersonService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Esempio n. 16
0
        public async void TestGet()
        {
            ApiPersonResponseModel response = await this.Client.PersonGetAsync(1);

            response.Should().NotBeNull();
        }