コード例 #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 ApiLinkRequestModel();
			createModel.SetProperties(1, 1, DateTime.Parse("1/1/1988 12:00:00 AM"), DateTime.Parse("1/1/1988 12:00:00 AM"), "B", Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"), 1, "B", 2, "B", "B", 2);
			CreateResponse<ApiLinkResponseModel> createResult = await client.LinkCreateAsync(createModel);

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

			ApiLinkResponseModel getResponse = await client.LinkGetAsync(2);

			getResponse.Should().NotBeNull();

			ActionResponse deleteResult = await client.LinkDeleteAsync(2);

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

			ApiLinkResponseModel verifyResponse = await client.LinkGetAsync(2);

			verifyResponse.Should().BeNull();
		}
コード例 #2
0
		private async Task<ApiLinkResponseModel> CreateRecord(ApiClient client)
		{
			var model = new ApiLinkRequestModel();
			model.SetProperties(1, 1, DateTime.Parse("1/1/1988 12:00:00 AM"), DateTime.Parse("1/1/1988 12:00:00 AM"), "B", Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"), 1, "B", 2, "B", "B", 2);
			CreateResponse<ApiLinkResponseModel> result = await client.LinkCreateAsync(model);

			result.Success.Should().BeTrue();
			return result.Record;
		}
コード例 #3
0
        public virtual async Task <IActionResult> Create([FromBody] ApiLinkRequestModel model)
        {
            CreateResponse <ApiLinkResponseModel> result = await this.LinkService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Links/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
コード例 #4
0
        public virtual async Task <CreateResponse <ApiLinkResponseModel> > Create(
            ApiLinkRequestModel model)
        {
            CreateResponse <ApiLinkResponseModel> response = new CreateResponse <ApiLinkResponseModel>(await this.linkModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolLinkMapper.MapModelToBO(default(int), model);
                var record = await this.linkRepository.Create(this.dalLinkMapper.MapBOToEF(bo));

                response.SetRecord(this.bolLinkMapper.MapBOToModel(this.dalLinkMapper.MapEFToBO(record)));
            }

            return(response);
        }
コード例 #5
0
        private async Task <ApiLinkRequestModel> PatchModel(int id, JsonPatchDocument <ApiLinkRequestModel> patch)
        {
            var record = await this.LinkService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiLinkRequestModel request = this.LinkModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
コード例 #6
0
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiLinkRequestModel model)
 {
     this.AssignedMachineIdRules();
     this.ChainIdRules();
     this.DateCompletedRules();
     this.DateStartedRules();
     this.DynamicParametersRules();
     this.ExternalIdRules();
     this.LinkStatusIdRules();
     this.NameRules();
     this.OrderRules();
     this.ResponseRules();
     this.StaticParametersRules();
     this.TimeoutInSecondsRules();
     return(await this.ValidateAsync(model, id));
 }
コード例 #7
0
        public virtual async Task <UpdateResponse <ApiLinkResponseModel> > Update(
            int id,
            ApiLinkRequestModel model)
        {
            var validationResult = await this.linkModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolLinkMapper.MapModelToBO(id, model);
                await this.linkRepository.Update(this.dalLinkMapper.MapBOToEF(bo));

                var record = await this.linkRepository.Get(id);

                return(new UpdateResponse <ApiLinkResponseModel>(this.bolLinkMapper.MapBOToModel(this.dalLinkMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiLinkResponseModel>(validationResult));
            }
        }
コード例 #8
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <ILinkRepository>();
            var model = new ApiLinkRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Link>())).Returns(Task.FromResult(new Link()));
            var service = new LinkService(mock.LoggerMock.Object,
                                          mock.RepositoryMock.Object,
                                          mock.ModelValidatorMockFactory.LinkModelValidatorMock.Object,
                                          mock.BOLMapperMockFactory.BOLLinkMapperMock,
                                          mock.DALMapperMockFactory.DALLinkMapperMock,
                                          mock.BOLMapperMockFactory.BOLLinkLogMapperMock,
                                          mock.DALMapperMockFactory.DALLinkLogMapperMock);

            CreateResponse <ApiLinkResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.LinkModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiLinkRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Link>()));
        }
コード例 #9
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <ILinkRepository>();
            var model = new ApiLinkRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new LinkService(mock.LoggerMock.Object,
                                          mock.RepositoryMock.Object,
                                          mock.ModelValidatorMockFactory.LinkModelValidatorMock.Object,
                                          mock.BOLMapperMockFactory.BOLLinkMapperMock,
                                          mock.DALMapperMockFactory.DALLinkMapperMock,
                                          mock.BOLMapperMockFactory.BOLLinkLogMapperMock,
                                          mock.DALMapperMockFactory.DALLinkLogMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.LinkModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
コード例 #10
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiLinkModelMapper();
            var model  = new ApiLinkResponseModel();

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

            response.AssignedMachineId.Should().Be(1);
            response.ChainId.Should().Be(1);
            response.DateCompleted.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.DateStarted.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.DynamicParameters.Should().Be("A");
            response.ExternalId.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
            response.LinkStatusId.Should().Be(1);
            response.Name.Should().Be("A");
            response.Order.Should().Be(1);
            response.Response.Should().Be("A");
            response.StaticParameters.Should().Be("A");
            response.TimeoutInSeconds.Should().Be(1);
        }
コード例 #11
0
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiLinkRequestModel model)
        {
            ApiLinkRequestModel request = await this.PatchModel(id, this.LinkModelMapper.CreatePatch(model));

            if (request == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                UpdateResponse <ApiLinkResponseModel> result = await this.LinkService.Update(id, request);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
コード例 #12
0
        public virtual BOLink MapModelToBO(
            int id,
            ApiLinkRequestModel model
            )
        {
            BOLink boLink = new BOLink();

            boLink.SetProperties(
                id,
                model.AssignedMachineId,
                model.ChainId,
                model.DateCompleted,
                model.DateStarted,
                model.DynamicParameters,
                model.ExternalId,
                model.LinkStatusId,
                model.Name,
                model.Order,
                model.Response,
                model.StaticParameters,
                model.TimeoutInSeconds);
            return(boLink);
        }
コード例 #13
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiLinkRequestModel> patch)
        {
            ApiLinkResponseModel record = await this.LinkService.Get(id);

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

                UpdateResponse <ApiLinkResponseModel> result = await this.LinkService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
コード例 #14
0
        public void CreatePatch()
        {
            var mapper = new ApiLinkModelMapper();
            var model  = new ApiLinkRequestModel();

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

            JsonPatchDocument <ApiLinkRequestModel> patch = mapper.CreatePatch(model);
            var response = new ApiLinkRequestModel();

            patch.ApplyTo(response);
            response.AssignedMachineId.Should().Be(1);
            response.ChainId.Should().Be(1);
            response.DateCompleted.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.DateStarted.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.DynamicParameter.Should().Be("A");
            response.ExternalId.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
            response.LinkStatusId.Should().Be(1);
            response.Name.Should().Be("A");
            response.Order.Should().Be(1);
            response.Response.Should().Be("A");
            response.StaticParameter.Should().Be("A");
            response.TimeoutInSecond.Should().Be(1);
        }
コード例 #15
0
        public virtual async Task <UpdateResponse <ApiLinkResponseModel> > LinkUpdateAsync(int id, ApiLinkRequestModel item)
        {
            HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Links/{id}", item).ConfigureAwait(false);

            return(JsonConvert.DeserializeObject <UpdateResponse <ApiLinkResponseModel> >(httpResponse.Content.ContentToString()));
        }