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 ApiFollowingRequestModel(); createModel.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), "B"); CreateResponse <ApiFollowingResponseModel> createResult = await client.FollowingCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiFollowingResponseModel getResponse = await client.FollowingGetAsync("B"); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.FollowingDeleteAsync("B"); deleteResult.Success.Should().BeTrue(); ApiFollowingResponseModel verifyResponse = await client.FollowingGetAsync("B"); verifyResponse.Should().BeNull(); }
public virtual ApiFollowingResponseModel MapBOToModel( BOFollowing boFollowing) { var model = new ApiFollowingResponseModel(); model.SetProperties(boFollowing.UserId, boFollowing.DateFollowed, boFollowing.Muted); return(model); }
public void MapResponseToRequest() { var mapper = new ApiFollowingModelMapper(); var model = new ApiFollowingResponseModel(); model.SetProperties("A", DateTime.Parse("1/1/1987 12:00:00 AM"), "A"); ApiFollowingRequestModel response = mapper.MapResponseToRequest(model); response.DateFollowed.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Muted.Should().Be("A"); }
public void MapBOToModel() { var mapper = new BOLFollowingMapper(); BOFollowing bo = new BOFollowing(); bo.SetProperties("A", DateTime.Parse("1/1/1987 12:00:00 AM"), "A"); ApiFollowingResponseModel response = mapper.MapBOToModel(bo); response.DateFollowed.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Muted.Should().Be("A"); response.UserId.Should().Be("A"); }
public async void TestGet() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); ApiFollowingResponseModel response = await client.FollowingGetAsync("A"); response.Should().NotBeNull(); }
public async virtual Task <IActionResult> Get(string id) { ApiFollowingResponseModel response = await this.FollowingService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public async void Get_null_record() { var mock = new ServiceMockFacade <IFollowingRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult <Following>(null)); var service = new FollowingService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.FollowingModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLFollowingMapperMock, mock.DALMapperMockFactory.DALFollowingMapperMock); ApiFollowingResponseModel response = await service.Get(default(string)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <string>())); }
public async void TestUpdate() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); ApiFollowingResponseModel model = await client.FollowingGetAsync("A"); ApiFollowingModelMapper mapper = new ApiFollowingModelMapper(); UpdateResponse <ApiFollowingResponseModel> updateResponse = await client.FollowingUpdateAsync(model.UserId, mapper.MapResponseToRequest(model)); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); }
public async void Create_Errors() { FollowingControllerMockFacade mock = new FollowingControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiFollowingResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiFollowingResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiFollowingRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiFollowingResponseModel> >(mockResponse.Object)); FollowingController controller = new FollowingController(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 ApiFollowingRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiFollowingRequestModel>())); }
public async void All_Exists() { FollowingControllerMockFacade mock = new FollowingControllerMockFacade(); var record = new ApiFollowingResponseModel(); var records = new List <ApiFollowingResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); FollowingController controller = new FollowingController(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 <ApiFollowingResponseModel>; items.Count.Should().Be(1); mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>())); }
public virtual async Task <IActionResult> Patch(string id, [FromBody] JsonPatchDocument <ApiFollowingRequestModel> patch) { ApiFollowingResponseModel record = await this.FollowingService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiFollowingRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiFollowingResponseModel> result = await this.FollowingService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }