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 ApiReplyRequestModel(); createModel.SetProperties("B", DateTime.Parse("1/1/1988 12:00:00 AM"), 1, TimeSpan.Parse("1")); CreateResponse <ApiReplyResponseModel> createResult = await client.ReplyCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiReplyResponseModel getResponse = await client.ReplyGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.ReplyDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiReplyResponseModel verifyResponse = await client.ReplyGetAsync(2); verifyResponse.Should().BeNull(); }
public virtual ApiReplyResponseModel MapBOToModel( BOReply boReply) { var model = new ApiReplyResponseModel(); model.SetProperties(boReply.ReplyId, boReply.Content, boReply.Date, boReply.ReplierUserId, boReply.Time); return(model); }
public async void TestGet() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); ApiReplyResponseModel response = await client.ReplyGetAsync(1); response.Should().NotBeNull(); }
public void MapResponseToRequest() { var mapper = new ApiReplyModelMapper(); var model = new ApiReplyResponseModel(); model.SetProperties(1, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1, TimeSpan.Parse("0")); ApiReplyRequestModel response = mapper.MapResponseToRequest(model); response.Content.Should().Be("A"); response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.ReplierUserId.Should().Be(1); response.Time.Should().Be(TimeSpan.Parse("0")); }
public async virtual Task <IActionResult> Get(int id) { ApiReplyResponseModel response = await this.ReplyService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public void MapBOToModel() { var mapper = new BOLReplyMapper(); BOReply bo = new BOReply(); bo.SetProperties(1, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1, TimeSpan.Parse("0")); ApiReplyResponseModel response = mapper.MapBOToModel(bo); response.Content.Should().Be("A"); response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.ReplierUserId.Should().Be(1); response.ReplyId.Should().Be(1); response.Time.Should().Be(TimeSpan.Parse("0")); }
public async void Get_null_record() { var mock = new ServiceMockFacade <IReplyRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Reply>(null)); var service = new ReplyService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ReplyModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLReplyMapperMock, mock.DALMapperMockFactory.DALReplyMapperMock); ApiReplyResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void TestUpdate() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); ApiReplyResponseModel model = await client.ReplyGetAsync(1); ApiReplyModelMapper mapper = new ApiReplyModelMapper(); UpdateResponse <ApiReplyResponseModel> updateResponse = await client.ReplyUpdateAsync(model.ReplyId, mapper.MapResponseToRequest(model)); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); }
public async void Create_Errors() { ReplyControllerMockFacade mock = new ReplyControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiReplyResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiReplyResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiReplyRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiReplyResponseModel> >(mockResponse.Object)); ReplyController controller = new ReplyController(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 ApiReplyRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiReplyRequestModel>())); }
public async void All_Exists() { ReplyControllerMockFacade mock = new ReplyControllerMockFacade(); var record = new ApiReplyResponseModel(); var records = new List <ApiReplyResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); ReplyController controller = new ReplyController(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 <ApiReplyResponseModel>; items.Count.Should().Be(1); mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>())); }
public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiReplyRequestModel> patch) { ApiReplyResponseModel record = await this.ReplyService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiReplyRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiReplyResponseModel> result = await this.ReplyService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }