public virtual async void TestUpdate() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); client.SetBearerToken(JWTTestHelper.GenerateBearerToken()); var mapper = new ApiPaymentTypeServerModelMapper(); ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext; IPaymentTypeService service = testServer.Host.Services.GetService(typeof(IPaymentTypeService)) as IPaymentTypeService; ApiPaymentTypeServerResponseModel model = await service.Get(1); ApiPaymentTypeClientRequestModel request = mapper.MapServerResponseToClientRequest(model); request.SetProperties("B"); UpdateResponse <ApiPaymentTypeClientResponseModel> updateResponse = await client.PaymentTypeUpdateAsync(model.Id, request); context.Entry(context.Set <PaymentType>().ToList()[0]).Reload(); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); updateResponse.Record.Id.Should().Be(1); context.Set <PaymentType>().ToList()[0].Name.Should().Be("B"); updateResponse.Record.Id.Should().Be(1); updateResponse.Record.Name.Should().Be("B"); }
public virtual async void TestDelete() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); client.SetBearerToken(JWTTestHelper.GenerateBearerToken()); ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext; IPaymentTypeService service = testServer.Host.Services.GetService(typeof(IPaymentTypeService)) as IPaymentTypeService; var model = new ApiPaymentTypeServerRequestModel(); model.SetProperties("B"); CreateResponse <ApiPaymentTypeServerResponseModel> createdResponse = await service.Create(model); createdResponse.Success.Should().BeTrue(); ActionResponse deleteResult = await client.PaymentTypeDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiPaymentTypeServerResponseModel verifyResponse = await service.Get(2); verifyResponse.Should().BeNull(); }
public void MapServerResponseToRequest() { var mapper = new ApiPaymentTypeServerModelMapper(); var model = new ApiPaymentTypeServerResponseModel(); model.SetProperties(1, "A"); ApiPaymentTypeServerRequestModel response = mapper.MapServerResponseToRequest(model); response.Should().NotBeNull(); response.Name.Should().Be("A"); }
public async virtual Task <IActionResult> Get(int id) { ApiPaymentTypeServerResponseModel response = await this.PaymentTypeService.Get(id); if (response == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { return(this.Ok(response)); } }
public async void Get_ShouldReturnNullBecauseRecordNotFound() { var mock = new ServiceMockFacade <IPaymentTypeService, IPaymentTypeRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <PaymentType>(null)); var service = new PaymentTypeService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.PaymentTypeModelValidatorMock.Object, mock.DALMapperMockFactory.DALPaymentTypeMapperMock, mock.DALMapperMockFactory.DALSaleMapperMock); ApiPaymentTypeServerResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void Create_Errors() { PaymentTypeControllerMockFacade mock = new PaymentTypeControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiPaymentTypeServerResponseModel> >(null as ApiPaymentTypeServerResponseModel); var mockRecord = new ApiPaymentTypeServerResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiPaymentTypeServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiPaymentTypeServerResponseModel> >(mockResponse.Object)); PaymentTypeController controller = new PaymentTypeController(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 ApiPaymentTypeServerRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiPaymentTypeServerRequestModel>())); }
public async void All_Exists() { PaymentTypeControllerMockFacade mock = new PaymentTypeControllerMockFacade(); var record = new ApiPaymentTypeServerResponseModel(); var records = new List <ApiPaymentTypeServerResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult(records)); PaymentTypeController controller = new PaymentTypeController(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, string.Empty); response.Should().BeOfType <OkObjectResult>(); (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK); var items = (response as OkObjectResult).Value as List <ApiPaymentTypeServerResponseModel>; items.Count.Should().Be(1); mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())); }
public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiPaymentTypeServerRequestModel> patch) { ApiPaymentTypeServerResponseModel record = await this.PaymentTypeService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiPaymentTypeServerRequestModel model = await this.PatchModel(id, patch) as ApiPaymentTypeServerRequestModel; UpdateResponse <ApiPaymentTypeServerResponseModel> result = await this.PaymentTypeService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }