public async Task CreateJournalNoteAsyncSuccess() { //Arrange var pageNumber = 1; var client = _factory.CreateClient(); var tokenHelper = new TokenGenerator(); var accessToken = await tokenHelper.GetToken().ConfigureAwait(false); client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken); var dataToGetCitizenId = await client.GetAsync($"/citizens?pagenumber={pageNumber}").ConfigureAwait(false); var dataBody = await dataToGetCitizenId.Content.ReadAsStringAsync().ConfigureAwait(false); var actualData = JsonConvert.DeserializeObject <CitizenList>(dataBody); var momentumCitizenId = actualData.Result.Select(x => x.CitizenId).FirstOrDefault(); var requestUri = $"/citizens/journal/{momentumCitizenId}"; List <JournalNoteDocumentRequestModel> documentList = new List <JournalNoteDocumentRequestModel>() { new JournalNoteDocumentRequestModel() { Content = "testContent", ContentType = "application/octet-stream", Name = "TestName.pdf" } }; JournalNoteRequestModel mcaRequestModel = new JournalNoteRequestModel() { Cpr = "0101005402", Title = "testTitle", Body = "testBody", Type = JournalNoteType.SMS, Documents = documentList }; string _serializedRequest = JsonConvert.SerializeObject(mcaRequestModel); //Act var response = await client.PostAsync(requestUri, new StringContent(_serializedRequest, Encoding.UTF8, "application/json")); var responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var actualResponse = JsonConvert.DeserializeObject(responseBody); //Assert response.StatusCode.Should().Be(HttpStatusCode.OK); actualResponse.Should().BeEquivalentTo("OK"); }
private static void CreateJournalNote(CommandLineConfig config) { JournalNoteDocumentRequestModel journalNoteDocumentRequestModel = new JournalNoteDocumentRequestModel() { Content = config.Content, ContentType = config.ContentType, Name = config.Name, }; IList <JournalNoteDocumentRequestModel> GetReadOnlyValues() { List <JournalNoteDocumentRequestModel> journalNoteDocumentRequestModelList = new List <JournalNoteDocumentRequestModel>() { journalNoteDocumentRequestModel, }; return(journalNoteDocumentRequestModelList.AsReadOnly()); } JournalNoteRequestModel journalNoteRequestModel = new JournalNoteRequestModel() { Body = config.Body, Cpr = config.Cpr, Documents = GetReadOnlyValues(), Title = config.Title, Type = config.Type, }; if (journalNoteRequestModel == null) { Log.Information("One or more JournalNoteDocumentRequestModel property is not mentioned", config.TaskId); throw new System.Exception("You must specify a properties of JournalNoteDocumentRequestModel "); } if (string.IsNullOrEmpty(config.CitizenId)) { Log.Information("CitizenId is not mentioned", config.CitizenId); throw new System.Exception("You must specify a CitizenId"); } var client = GetApi(config); var response = client.CreateJournalNote(journalNoteRequestModel, config.CitizenId); Log.Information("Created a Journal Note with attachment", response); }
public async Task CreateJournalNoteAsyncFail() { //Arrange var helperHttpClientMoq = new Mock <ICitizenHttpClientHelper>(); var context = GetContext(); var configurationMoq = new Mock <IConfiguration>(); JournalNoteDocumentRequestModel[] requestDocumentModel = { new JournalNoteDocumentRequestModel() { Content = "testContent", ContentType = "testContentType", Name = "testDocumentName" } }; var requestModel = new JournalNoteRequestModel() { Cpr = "testCpr", Body = "testBody", Title = "testTitle", Type = JournalNoteType.SMS, Documents = requestDocumentModel }; var error = new Error("123456", new string[] { "Some error occured when creating note" }, "MCA"); helperHttpClientMoq.Setup(x => x.CreateJournalNoteInMomentumCoreAsync("journals/note", "testCitizenId", requestModel)) .Returns(Task.FromResult(new ResultOrHttpError <string, Error>(error, HttpStatusCode.BadRequest))); var citizenService = new CitizenService(helperHttpClientMoq.Object, configurationMoq.Object, context.Object); //Act var result = await citizenService.CreateJournalNoteAsync("testCitizenId", requestModel).ConfigureAwait(false); //Asert result.IsError.Should().BeTrue(); result.Error.Errors[0].Should().BeEquivalentTo("Some error occured when creating note"); }
public async Task CreateJournalNoteAsyncSuccess() { //Arrange var helperHttpClientMoq = new Mock <ICitizenHttpClientHelper>(); var context = GetContext(); var configurationMoq = new Mock <IConfiguration>(); JournalNoteDocumentRequestModel[] requestDocumentModel = { new JournalNoteDocumentRequestModel() { Content = "testContent", ContentType = "testContentType", Name = "testDocumentName" } }; var requestModel = new JournalNoteRequestModel() { Cpr = "testCpr", Body = "testBody", Title = "testTitle", Type = JournalNoteType.SMS, Documents = requestDocumentModel }; helperHttpClientMoq.Setup(x => x.CreateJournalNoteInMomentumCoreAsync("journals/note", "testCitizenId", requestModel)) .Returns(Task.FromResult(new ResultOrHttpError <string, Error>(""))); var citizenService = new CitizenService(helperHttpClientMoq.Object, configurationMoq.Object, context.Object); //Act var result = await citizenService.CreateJournalNoteAsync("testCitizenId", requestModel).ConfigureAwait(false); //Asert result.Should().NotBeNull(); result.IsError.Should().BeFalse(); result.Result.Should().BeEquivalentTo(""); }
public async Task <ResultOrHttpError <string, Error> > CreateJournalNoteAsync(string momentumCitizenId, JournalNoteRequestModel requestModel) { var response = await _citizenHttpClient.CreateJournalNoteInMomentumCoreAsync("journals/note", momentumCitizenId, requestModel).ConfigureAwait(false); if (response.IsError) { var error = response.Error.Errors.Aggregate((a, b) => a + "," + b); Log.ForContext("CorrelationId", _correlationId) .ForContext("ClientId", _clientId) .ForContext("CitizenId", momentumCitizenId) .Error("An Error Occured while creating Journal Note" + error); return(new ResultOrHttpError <string, Error>(response.Error, response.StatusCode.Value)); } Log.ForContext("CorrelationId", _correlationId) .ForContext("ClientId", _clientId) .ForContext("CitizenId", momentumCitizenId) .Information("Journal Note is created successfully"); return(new ResultOrHttpError <string, Error>(response.Result)); }
public async Task <ActionResult> CreateJournalNote([Required][FromRoute] string momentumCitizenId, [Required][FromBody] JournalNoteRequestModel requestModel) { var result = await _citizenService.CreateJournalNoteAsync(momentumCitizenId, requestModel).ConfigureAwait(false); if (result.IsError) { return(StatusCode((int)(result.StatusCode ?? HttpStatusCode.BadRequest), result.Error.Errors)); } else { return(Ok("OK")); } }
public async Task <ResultOrHttpError <string, Error> > CreateJournalNoteInMomentumCoreAsync(string path, string momentumCitizenId, JournalNoteRequestModel requestModel) { List <JournalNoteAttachmentModel> attachmentList = new List <JournalNoteAttachmentModel>(); if (requestModel.Documents != null) { foreach (var doc in requestModel.Documents) { if (!isValidDocument(doc)) { var error = new Error(_correlationId, new string[] { "Invalid document type" }, "Mea"); return(new ResultOrHttpError <string, Error>(error, HttpStatusCode.BadRequest)); } var attachemnt = new JournalNoteAttachmentModel() { ContentType = doc.ContentType, Document = doc.Content, Title = doc.Name }; attachmentList.Add(attachemnt); } } JournalNoteModel mcaRequestModel = new JournalNoteModel() { Id = requestModel.Cpr, OccurredAt = DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss.ff'Z'"), Title = requestModel.Title, Body = requestModel.Body, Source = "Mea", ReferenceId = momentumCitizenId, JournalTypeId = requestModel.Type == JournalNoteType.SMS ? "022.247.000" : "022.420.000", Attachments = attachmentList }; string serializedRequest = JsonConvert.SerializeObject(mcaRequestModel); StringContent stringContent = new StringContent(serializedRequest, Encoding.UTF8, "application/json"); var response = await _meaClient.PostAsync(path, stringContent).ConfigureAwait(false); if (response.IsError) { return(new ResultOrHttpError <string, Error>(response.Error, response.StatusCode.Value)); } var content = response.Result; return(new ResultOrHttpError <string, Error>(content)); }
/// <summary> /// Create a Journal Note with attachment /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='body'> /// The requestmodel to save as a journal note record, in the Core system /// </param> /// <param name='momentumCitizenId'> /// The MomentumCitizenID or CitizenId to Create the journal note record in the /// Core system /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <ProblemDetails> CreateJournalNoteAsync(this IInternalClient operations, JournalNoteRequestModel body, string momentumCitizenId, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.CreateJournalNoteWithHttpMessagesAsync(body, momentumCitizenId, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Create a Journal Note with attachment /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='body'> /// The requestmodel to save as a journal note record, in the Core system /// </param> /// <param name='momentumCitizenId'> /// The MomentumCitizenID or CitizenId to Create the journal note record in the /// Core system /// </param> public static ProblemDetails CreateJournalNote(this IInternalClient operations, JournalNoteRequestModel body, string momentumCitizenId) { return(operations.CreateJournalNoteAsync(body, momentumCitizenId).GetAwaiter().GetResult()); }