public async Task <ValidationResult> ValidateUpdateAsync(string id, ApiSubscriptionRequestModel model) { this.IsDisabledRules(); this.JSONRules(); this.NameRules(); this.TypeRules(); return(await this.ValidateAsync(model, id)); }
private async Task <ApiSubscriptionResponseModel> CreateRecord() { var model = new ApiSubscriptionRequestModel(); model.SetProperties(true, "B", "B", "B"); CreateResponse <ApiSubscriptionResponseModel> result = await this.Client.SubscriptionCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public virtual async Task <IActionResult> Create([FromBody] ApiSubscriptionRequestModel model) { CreateResponse <ApiSubscriptionResponseModel> result = await this.SubscriptionService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Subscriptions/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public void MapModelToBO() { var mapper = new BOLSubscriptionMapper(); ApiSubscriptionRequestModel model = new ApiSubscriptionRequestModel(); model.SetProperties(true, "A", "A", "A"); BOSubscription response = mapper.MapModelToBO("A", model); response.IsDisabled.Should().Be(true); response.JSON.Should().Be("A"); response.Name.Should().Be("A"); response.Type.Should().Be("A"); }
public void MapResponseToRequest() { var mapper = new ApiSubscriptionModelMapper(); var model = new ApiSubscriptionResponseModel(); model.SetProperties("A", true, "A", "A", "A"); ApiSubscriptionRequestModel response = mapper.MapResponseToRequest(model); response.IsDisabled.Should().Be(true); response.JSON.Should().Be("A"); response.Name.Should().Be("A"); response.Type.Should().Be("A"); }
public virtual async Task <CreateResponse <ApiSubscriptionResponseModel> > Create( ApiSubscriptionRequestModel model) { CreateResponse <ApiSubscriptionResponseModel> response = new CreateResponse <ApiSubscriptionResponseModel>(await this.subscriptionModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.bolSubscriptionMapper.MapModelToBO(default(string), model); var record = await this.subscriptionRepository.Create(this.dalSubscriptionMapper.MapBOToEF(bo)); response.SetRecord(this.bolSubscriptionMapper.MapBOToModel(this.dalSubscriptionMapper.MapEFToBO(record))); } return(response); }
private async Task <ApiSubscriptionRequestModel> PatchModel(string id, JsonPatchDocument <ApiSubscriptionRequestModel> patch) { var record = await this.SubscriptionService.Get(id); if (record == null) { return(null); } else { ApiSubscriptionRequestModel request = this.SubscriptionModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public virtual BOSubscription MapModelToBO( string id, ApiSubscriptionRequestModel model ) { BOSubscription boSubscription = new BOSubscription(); boSubscription.SetProperties( id, model.IsDisabled, model.JSON, model.Name, model.Type); return(boSubscription); }
public void CreatePatch() { var mapper = new ApiSubscriptionModelMapper(); var model = new ApiSubscriptionRequestModel(); model.SetProperties(true, "A", "A", "A"); JsonPatchDocument <ApiSubscriptionRequestModel> patch = mapper.CreatePatch(model); var response = new ApiSubscriptionRequestModel(); patch.ApplyTo(response); response.IsDisabled.Should().Be(true); response.JSON.Should().Be("A"); response.Name.Should().Be("A"); response.Type.Should().Be("A"); }
public async void Create() { var mock = new ServiceMockFacade <ISubscriptionRepository>(); var model = new ApiSubscriptionRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Subscription>())).Returns(Task.FromResult(new Subscription())); var service = new SubscriptionService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.SubscriptionModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLSubscriptionMapperMock, mock.DALMapperMockFactory.DALSubscriptionMapperMock); CreateResponse <ApiSubscriptionResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.SubscriptionModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiSubscriptionRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Subscription>())); }
public async void Delete() { var mock = new ServiceMockFacade <ISubscriptionRepository>(); var model = new ApiSubscriptionRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.CompletedTask); var service = new SubscriptionService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.SubscriptionModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLSubscriptionMapperMock, mock.DALMapperMockFactory.DALSubscriptionMapperMock); ActionResponse response = await service.Delete(default(string)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <string>())); mock.ModelValidatorMockFactory.SubscriptionModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <string>())); }
public virtual async Task <UpdateResponse <ApiSubscriptionResponseModel> > Update( string id, ApiSubscriptionRequestModel model) { var validationResult = await this.subscriptionModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.bolSubscriptionMapper.MapModelToBO(id, model); await this.subscriptionRepository.Update(this.dalSubscriptionMapper.MapBOToEF(bo)); var record = await this.subscriptionRepository.Get(id); return(new UpdateResponse <ApiSubscriptionResponseModel>(this.bolSubscriptionMapper.MapBOToModel(this.dalSubscriptionMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiSubscriptionResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(string id, [FromBody] ApiSubscriptionRequestModel model) { ApiSubscriptionRequestModel request = await this.PatchModel(id, this.SubscriptionModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiSubscriptionResponseModel> result = await this.SubscriptionService.Update(id, request); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <IActionResult> Patch(string id, [FromBody] JsonPatchDocument <ApiSubscriptionRequestModel> patch) { ApiSubscriptionResponseModel record = await this.SubscriptionService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiSubscriptionRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiSubscriptionResponseModel> result = await this.SubscriptionService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }