public async Task Delete_SuccessResponse() { //arrange var invoice = await CreateInvoiceAsync(); CreateStatementRequest createModel = new CreateStatementRequest() { Date = DateTime.UtcNow, Notes = "NOTES", Amount = 1, InvoiceId = invoice.Id }; var createViewModel = await CreateStatementAsync(createModel); //act var response = await _client.DeleteAsync($"/statement/{createViewModel.Id}"); var content = await response.Content.ReadAsStringAsync(); var responseViewModel = JsonConvert.DeserializeObject <SuccessfulResponse <string> >(content); //assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); }
/// <summary> /// This request is used to create a new Statement in the Phoenix query server. /// </summary> public async Task <CreateStatementResponse> CreateStatementRequestAsync(string connectionId, RequestOptions options) { CreateStatementRequest req = new CreateStatementRequest { ConnectionId = connectionId }; WireMessage msg = new WireMessage { Name = Constants.WireMessagePrefix + "CreateStatementRequest", WrappedMessage = req.ToByteString() }; using (Response webResponse = await PostRequestAsync(msg.ToByteArray(), options)) { if (webResponse.WebResponse.StatusCode != HttpStatusCode.OK) { WireMessage output = WireMessage.Parser.ParseFrom(webResponse.WebResponse.GetResponseStream()); ErrorResponse res = ErrorResponse.Parser.ParseFrom(output.WrappedMessage); throw new WebException( string.Format( "CreateStatementRequestAsync failed! connectionId: {0}, Response code was: {1}, Response body was: {2}", connectionId, webResponse.WebResponse.StatusCode, res.ToString())); } else { WireMessage output = WireMessage.Parser.ParseFrom(webResponse.WebResponse.GetResponseStream()); CreateStatementResponse res = CreateStatementResponse.Parser.ParseFrom(output.WrappedMessage); return(res); } } }
public async Task Post_FailureResponse_InvalidAmount() { //arrange var invoice = await CreateInvoiceAsync(); CreateStatementRequest model = new CreateStatementRequest() { Date = DateTime.UtcNow, Notes = "NOTES", Amount = -1, InvoiceId = invoice.Id }; //act var response = await _client.PostAsync("/statement", new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json")); var content = await response.Content.ReadAsStringAsync(); var responseViewModel = JsonConvert.DeserializeObject <FailureResponse>(content); //assert Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); Assert.Equal("The Statement Amount must be a positive number.", responseViewModel.Message); }
public async Task Post_SuccessResponse() { //arrange var invoice = await CreateInvoiceAsync(); CreateStatementRequest model = new CreateStatementRequest() { Date = DateTime.UtcNow, Notes = "NOTES", Amount = 123, InvoiceId = invoice.Id }; //act var response = await _client.PostAsync("/statement", new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json")); var content = await response.Content.ReadAsStringAsync(); var responseViewModel = JsonConvert.DeserializeObject <SuccessfulResponse <StatementResponse> >(content); //assert Assert.Equal(HttpStatusCode.Created, response.StatusCode); Assert.Equal(model.Date.Day, responseViewModel.Data.Date.Day); Assert.Equal(model.Date.Month, responseViewModel.Data.Date.Month); Assert.Equal(model.Date.Year, responseViewModel.Data.Date.Year); Assert.Equal(0, responseViewModel.Data.Date.Hour); Assert.Equal(0, responseViewModel.Data.Date.Minute); Assert.Equal(0, responseViewModel.Data.Date.Second); Assert.Equal(model.Notes, responseViewModel.Data.Notes); Assert.Equal(model.Amount, responseViewModel.Data.Amount); Assert.Equal(model.InvoiceId, responseViewModel.Data.InvoiceId); Assert.NotEmpty(responseViewModel.Data.Id.ToString()); }
public async Task GetById_SuccessResponse() { //arrange var invoice = await CreateInvoiceAsync(); CreateStatementRequest createModel = new CreateStatementRequest() { Date = DateTime.UtcNow, Notes = "NOTES", Amount = 1, InvoiceId = invoice.Id }; var createViewModel = await CreateStatementAsync(createModel); //act var response = await _client.GetAsync($"/statement/{createViewModel.Id}"); var content = await response.Content.ReadAsStringAsync(); var responseViewModel = JsonConvert.DeserializeObject <SuccessfulResponse <StatementResponse> >(content); //assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(createViewModel.Date.Day, responseViewModel.Data.Date.Day); Assert.Equal(createViewModel.Date.Month, responseViewModel.Data.Date.Month); Assert.Equal(createViewModel.Date.Year, responseViewModel.Data.Date.Year); Assert.Equal(0, responseViewModel.Data.Date.Hour); Assert.Equal(0, responseViewModel.Data.Date.Minute); Assert.Equal(0, responseViewModel.Data.Date.Second); Assert.Equal(createViewModel.Notes, responseViewModel.Data.Notes); Assert.Equal(createViewModel.Amount, responseViewModel.Data.Amount); Assert.Equal(createViewModel.InvoiceId, responseViewModel.Data.InvoiceId); Assert.NotEmpty(responseViewModel.Data.Id.ToString()); }
private async Task <StatementResponse> CreateStatementAsync(CreateStatementRequest model) { var response = await _client.PostAsync("/statement", new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json")); var content = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { Assert.True(response.IsSuccessStatusCode, "POST /statement/ is failing with an error. Verify"); } return(JsonConvert.DeserializeObject <SuccessfulResponse <StatementResponse> >(content).Data); }
public async Task <IActionResult> Create( [FromBody] CreateStatementRequest model) { var result = await _statementService.Create(model); if (result.Successful) { return(SuccessResponse(result)); } else { return(FailureResponse(result)); } }
public async Task Put_FailureResponse_DuplicateStatement() { //arrange var invoice = await CreateInvoiceAsync(); CreateStatementRequest createModelFirst = new CreateStatementRequest() { Date = DateTime.UtcNow, Notes = "NOTES", Amount = 1, InvoiceId = invoice.Id }; var createViewModelFirst = await CreateStatementAsync(createModelFirst); CreateStatementRequest createModelSecond = new CreateStatementRequest() { Date = DateTime.UtcNow.AddDays(1), Notes = "NOTES", Amount = 1, InvoiceId = invoice.Id }; var createViewModelSecond = await CreateStatementAsync(createModelSecond); var updateModel = new UpdateStatementRequest() { Id = createViewModelSecond.Id, Date = createViewModelFirst.Date, Notes = createViewModelSecond.Notes, Amount = createViewModelSecond.Amount, InvoiceId = createViewModelSecond.InvoiceId }; //act var response = await _client.PutAsync($"/statement/{updateModel.Id}", new StringContent(JsonConvert.SerializeObject(updateModel), Encoding.UTF8, "application/json")); var content = await response.Content.ReadAsStringAsync(); var responseViewModel = JsonConvert.DeserializeObject <FailureResponse>(content); //assert Assert.Equal(HttpStatusCode.Conflict, response.StatusCode); Assert.NotNull(responseViewModel.Message); }
public async Task <Response <StatementResponse> > Create(CreateStatementRequest viewModel) { var command = _mapper.Map <CreateStatementCommand>(viewModel); var result = await _mediatorHandler.SendCommand(command); if (result) { var statementEvent = _eventStore.GetEvent <StatementCreatedEvent>(); var data = _mapper.Map <Expenses.Domain.Models.Statement, StatementResponse>(statementEvent.New); return(SuccessfulResponse(data, statementEvent)); } else { var validationEvent = _eventStore.GetEvent <DomainValidationEvent>(); return(FailureResponse <StatementResponse>(validationEvent)); } }
public async Task Post_FailureResponse_InvoiceNotFound() { //arrange CreateStatementRequest model = new CreateStatementRequest() { Date = DateTime.UtcNow, Notes = "NOTES", Amount = 123, InvoiceId = Guid.NewGuid() }; //act var response = await _client.PostAsync("/statement", new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json")); var content = await response.Content.ReadAsStringAsync(); var responseViewModel = JsonConvert.DeserializeObject <FailureResponse>(content); //assert Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); Assert.Equal("Statement Invoice ID does not exist. Please select a valid value.", responseViewModel.Message); }
/// <summary> /// This request is used to create a new Statement in the Phoenix query server. /// </summary> public async Task<CreateStatementResponse> CreateStatementRequestAsync(string connectionId, RequestOptions options) { CreateStatementRequest req = new CreateStatementRequest { ConnectionId = connectionId }; WireMessage msg = new WireMessage { Name = Constants.WireMessagePrefix + "CreateStatementRequest", WrappedMessage = req.ToByteString() }; using (Response webResponse = await PostRequestAsync(msg.ToByteArray(), options)) { if (webResponse.WebResponse.StatusCode != HttpStatusCode.OK) { WireMessage output = WireMessage.Parser.ParseFrom(webResponse.WebResponse.GetResponseStream()); ErrorResponse res = ErrorResponse.Parser.ParseFrom(output.WrappedMessage); throw new WebException( string.Format( "CreateStatementRequestAsync failed! connectionId: {0}, Response code was: {1}, Response body was: {2}", connectionId, webResponse.WebResponse.StatusCode, res.ToString())); } else { WireMessage output = WireMessage.Parser.ParseFrom(webResponse.WebResponse.GetResponseStream()); CreateStatementResponse res = CreateStatementResponse.Parser.ParseFrom(output.WrappedMessage); return res; } } }