public virtual async void TestUpdate() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); var mapper = new ApiBankAccountServerModelMapper(); ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext; IBankAccountService service = testServer.Host.Services.GetService(typeof(IBankAccountService)) as IBankAccountService; ApiBankAccountServerResponseModel model = await service.Get(1); ApiBankAccountClientRequestModel request = mapper.MapServerResponseToClientRequest(model); request.SetProperties("B", 1, "B"); UpdateResponse <ApiBankAccountClientResponseModel> updateResponse = await client.BankAccountUpdateAsync(model.Id, request); context.Entry(context.Set <BankAccount>().ToList()[0]).Reload(); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); updateResponse.Record.Id.Should().Be(1); context.Set <BankAccount>().ToList()[0].AccountNumber.Should().Be("B"); context.Set <BankAccount>().ToList()[0].ArtistId.Should().Be(1); context.Set <BankAccount>().ToList()[0].RoutingNumber.Should().Be("B"); updateResponse.Record.Id.Should().Be(1); updateResponse.Record.AccountNumber.Should().Be("B"); updateResponse.Record.ArtistId.Should().Be(1); updateResponse.Record.RoutingNumber.Should().Be("B"); }
public void MapServerResponseToRequest() { var mapper = new ApiBankAccountServerModelMapper(); var model = new ApiBankAccountServerResponseModel(); model.SetProperties(1, "A", 1, "A"); ApiBankAccountServerRequestModel response = mapper.MapServerResponseToRequest(model); response.Should().NotBeNull(); response.AccountNumber.Should().Be("A"); response.ArtistId.Should().Be(1); response.RoutingNumber.Should().Be("A"); }
public async virtual Task <IActionResult> Get(int id) { ApiBankAccountServerResponseModel response = await this.BankAccountService.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 <IBankAccountRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <BankAccount>(null)); var service = new BankAccountService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.BankAccountModelValidatorMock.Object, mock.DALMapperMockFactory.DALBankAccountMapperMock); ApiBankAccountServerResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void Create_Errors() { BankAccountControllerMockFacade mock = new BankAccountControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiBankAccountServerResponseModel> >(null as ApiBankAccountServerResponseModel); var mockRecord = new ApiBankAccountServerResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiBankAccountServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiBankAccountServerResponseModel> >(mockResponse.Object)); BankAccountController controller = new BankAccountController(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 ApiBankAccountServerRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiBankAccountServerRequestModel>())); }
public async void All_Exists() { BankAccountControllerMockFacade mock = new BankAccountControllerMockFacade(); var record = new ApiBankAccountServerResponseModel(); var records = new List <ApiBankAccountServerResponseModel>(); records.Add(record); mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult(records)); BankAccountController controller = new BankAccountController(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 <ApiBankAccountServerResponseModel>; items.Count.Should().Be(1); mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())); }
public virtual async void TestDelete() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext; IBankAccountService service = testServer.Host.Services.GetService(typeof(IBankAccountService)) as IBankAccountService; var model = new ApiBankAccountServerRequestModel(); model.SetProperties("B", 1, "B"); CreateResponse <ApiBankAccountServerResponseModel> createdResponse = await service.Create(model); createdResponse.Success.Should().BeTrue(); ActionResponse deleteResult = await client.BankAccountDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiBankAccountServerResponseModel verifyResponse = await service.Get(2); verifyResponse.Should().BeNull(); }
public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiBankAccountServerRequestModel> patch) { ApiBankAccountServerResponseModel record = await this.BankAccountService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiBankAccountServerRequestModel model = await this.PatchModel(id, patch) as ApiBankAccountServerRequestModel; UpdateResponse <ApiBankAccountServerResponseModel> result = await this.BankAccountService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }