Beispiel #1
0
        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 ApiFamilyRequestModel();

            createModel.SetProperties("B", "B", "B", "B", "B");
            CreateResponse <ApiFamilyResponseModel> createResult = await client.FamilyCreateAsync(createModel);

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

            ApiFamilyResponseModel getResponse = await client.FamilyGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.FamilyDeleteAsync(2);

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

            ApiFamilyResponseModel verifyResponse = await client.FamilyGetAsync(2);

            verifyResponse.Should().BeNull();
        }
        public virtual ApiFamilyResponseModel MapBOToModel(
            BOFamily boFamily)
        {
            var model = new ApiFamilyResponseModel();

            model.SetProperties(boFamily.Id, boFamily.Note, boFamily.PrimaryContactEmail, boFamily.PrimaryContactFirstName, boFamily.PrimaryContactLastName, boFamily.PrimaryContactPhone);

            return(model);
        }
        public virtual ApiFamilyResponseModel MapBOToModel(
            BOFamily boFamily)
        {
            var model = new ApiFamilyResponseModel();

            model.SetProperties(boFamily.Id, boFamily.Notes, boFamily.PcEmail, boFamily.PcFirstName, boFamily.PcLastName, boFamily.PcPhone, boFamily.StudioId);

            return(model);
        }
Beispiel #4
0
        public async void TestGet()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());
            ApiFamilyResponseModel response = await client.FamilyGetAsync(1);

            response.Should().NotBeNull();
        }
Beispiel #5
0
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiFamilyResponseModel response = await this.FamilyService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
Beispiel #6
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiFamilyModelMapper();
            var model  = new ApiFamilyResponseModel();

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

            response.Note.Should().Be("A");
            response.PrimaryContactEmail.Should().Be("A");
            response.PrimaryContactFirstName.Should().Be("A");
            response.PrimaryContactLastName.Should().Be("A");
            response.PrimaryContactPhone.Should().Be("A");
        }
        public void MapResponseToRequest()
        {
            var mapper = new ApiFamilyModelMapper();
            var model  = new ApiFamilyResponseModel();

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

            response.Notes.Should().Be("A");
            response.PcEmail.Should().Be("A");
            response.PcFirstName.Should().Be("A");
            response.PcLastName.Should().Be("A");
            response.PcPhone.Should().Be("A");
            response.StudioId.Should().Be(1);
        }
Beispiel #8
0
        public void MapBOToModel()
        {
            var      mapper = new BOLFamilyMapper();
            BOFamily bo     = new BOFamily();

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

            response.Id.Should().Be(1);
            response.Note.Should().Be("A");
            response.PrimaryContactEmail.Should().Be("A");
            response.PrimaryContactFirstName.Should().Be("A");
            response.PrimaryContactLastName.Should().Be("A");
            response.PrimaryContactPhone.Should().Be("A");
        }
        public void MapBOToModel()
        {
            var      mapper = new BOLFamilyMapper();
            BOFamily bo     = new BOFamily();

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

            response.Id.Should().Be(1);
            response.Notes.Should().Be("A");
            response.PcEmail.Should().Be("A");
            response.PcFirstName.Should().Be("A");
            response.PcLastName.Should().Be("A");
            response.PcPhone.Should().Be("A");
            response.StudioId.Should().Be(1);
        }
Beispiel #10
0
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <IFamilyRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Family>(null));
            var service = new FamilyService(mock.LoggerMock.Object,
                                            mock.RepositoryMock.Object,
                                            mock.ModelValidatorMockFactory.FamilyModelValidatorMock.Object,
                                            mock.BOLMapperMockFactory.BOLFamilyMapperMock,
                                            mock.DALMapperMockFactory.DALFamilyMapperMock,
                                            mock.BOLMapperMockFactory.BOLStudentMapperMock,
                                            mock.DALMapperMockFactory.DALStudentMapperMock);

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

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

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

            ApiFamilyResponseModel model = await client.FamilyGetAsync(1);

            ApiFamilyModelMapper mapper = new ApiFamilyModelMapper();

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

            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
        }
        public async void Create_Errors()
        {
            FamilyControllerMockFacade mock = new FamilyControllerMockFacade();

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

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

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

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

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

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

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

                UpdateResponse <ApiFamilyResponseModel> result = await this.FamilyService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Beispiel #15
0
        public async void TestGet()
        {
            ApiFamilyResponseModel response = await this.Client.FamilyGetAsync(1);

            response.Should().NotBeNull();
        }