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 ApiFollowerRequestModel(); createModel.SetProperties("B", DateTime.Parse("1/1/1988 12:00:00 AM"), "B", 1, 1, "B"); CreateResponse <ApiFollowerResponseModel> createResult = await client.FollowerCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiFollowerResponseModel getResponse = await client.FollowerGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.FollowerDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiFollowerResponseModel verifyResponse = await client.FollowerGetAsync(2); verifyResponse.Should().BeNull(); }
private async Task <ApiFollowerResponseModel> CreateRecord(ApiClient client) { var model = new ApiFollowerRequestModel(); model.SetProperties("B", DateTime.Parse("1/1/1988 12:00:00 AM"), "B", 1, 1, "B"); CreateResponse <ApiFollowerResponseModel> result = await client.FollowerCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiFollowerRequestModel model) { this.BlockedRules(); this.DateFollowedRules(); this.FollowRequestStatuRules(); this.FollowedUserIdRules(); this.FollowingUserIdRules(); this.MutedRules(); return(await this.ValidateAsync(model, id)); }
public virtual async Task <IActionResult> Create([FromBody] ApiFollowerRequestModel model) { CreateResponse <ApiFollowerResponseModel> result = await this.FollowerService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Followers/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
private async Task <ApiFollowerRequestModel> PatchModel(int id, JsonPatchDocument <ApiFollowerRequestModel> patch) { var record = await this.FollowerService.Get(id); if (record == null) { return(null); } else { ApiFollowerRequestModel request = this.FollowerModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public void MapResponseToRequest() { var mapper = new ApiFollowerModelMapper(); var model = new ApiFollowerResponseModel(); model.SetProperties(1, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1, 1, "A"); ApiFollowerRequestModel response = mapper.MapResponseToRequest(model); response.Blocked.Should().Be("A"); response.DateFollowed.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.FollowRequestStatu.Should().Be("A"); response.FollowedUserId.Should().Be(1); response.FollowingUserId.Should().Be(1); response.Muted.Should().Be("A"); }
public virtual async Task <CreateResponse <ApiFollowerResponseModel> > Create( ApiFollowerRequestModel model) { CreateResponse <ApiFollowerResponseModel> response = new CreateResponse <ApiFollowerResponseModel>(await this.FollowerModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.BolFollowerMapper.MapModelToBO(default(int), model); var record = await this.FollowerRepository.Create(this.DalFollowerMapper.MapBOToEF(bo)); response.SetRecord(this.BolFollowerMapper.MapBOToModel(this.DalFollowerMapper.MapEFToBO(record))); } return(response); }
public virtual BOFollower MapModelToBO( int id, ApiFollowerRequestModel model ) { BOFollower boFollower = new BOFollower(); boFollower.SetProperties( id, model.Blocked, model.DateFollowed, model.FollowRequestStatu, model.FollowedUserId, model.FollowingUserId, model.Muted); return(boFollower); }
public async void Create() { var mock = new ServiceMockFacade <IFollowerRepository>(); var model = new ApiFollowerRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Follower>())).Returns(Task.FromResult(new Follower())); var service = new FollowerService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.FollowerModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLFollowerMapperMock, mock.DALMapperMockFactory.DALFollowerMapperMock); CreateResponse <ApiFollowerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.FollowerModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiFollowerRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Follower>())); }
public async void Delete() { var mock = new ServiceMockFacade <IFollowerRepository>(); var model = new ApiFollowerRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new FollowerService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.FollowerModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLFollowerMapperMock, mock.DALMapperMockFactory.DALFollowerMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.FollowerModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public void CreatePatch() { var mapper = new ApiFollowerModelMapper(); var model = new ApiFollowerRequestModel(); model.SetProperties("A", DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1, 1, "A"); JsonPatchDocument <ApiFollowerRequestModel> patch = mapper.CreatePatch(model); var response = new ApiFollowerRequestModel(); patch.ApplyTo(response); response.Blocked.Should().Be("A"); response.DateFollowed.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.FollowRequestStatu.Should().Be("A"); response.FollowedUserId.Should().Be(1); response.FollowingUserId.Should().Be(1); response.Muted.Should().Be("A"); }
public virtual async Task <UpdateResponse <ApiFollowerResponseModel> > Update( int id, ApiFollowerRequestModel model) { var validationResult = await this.FollowerModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.BolFollowerMapper.MapModelToBO(id, model); await this.FollowerRepository.Update(this.DalFollowerMapper.MapBOToEF(bo)); var record = await this.FollowerRepository.Get(id); return(new UpdateResponse <ApiFollowerResponseModel>(this.BolFollowerMapper.MapBOToModel(this.DalFollowerMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiFollowerResponseModel>(validationResult)); } }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiFollowerRequestModel model) { ApiFollowerRequestModel request = await this.PatchModel(id, this.FollowerModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiFollowerResponseModel> result = await this.FollowerService.Update(id, request); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiFollowerRequestModel> patch) { ApiFollowerResponseModel record = await this.FollowerService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiFollowerRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiFollowerResponseModel> result = await this.FollowerService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <UpdateResponse <ApiFollowerResponseModel> > FollowerUpdateAsync(int id, ApiFollowerRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Followers/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiFollowerResponseModel> >(httpResponse.Content.ContentToString())); }