public Message CreateMessage(Message mesage) { var createRequest = new MessageCreateRequest(); ModelCopier.CopyModel(mesage, createRequest); return(Api.Messages.Create(createRequest)); }
public Message Create(MessageCreateRequest createRequest) { var content = Api.Post <Message>("/projects/{0}/messages.json".FormatWith(createRequest.ProjectId), createRequest); content.ProjectId = createRequest.ProjectId; return(content); }
public async Task CreateAsync_ShouldReturnErrorWhenExceptionInQuery2() { var newMessageFile = new MessageFile { Id = 10, Name = "NewFileName", FileTypeId = 1 }; var mockMessageFilesQuery = new Mock <IMessageFileQuery>(); mockMessageFilesQuery .Setup(m => m.Create(It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync(newMessageFile); var mockMessagesQuery = new Mock <IMessagesQuery>(); mockMessagesQuery.Setup(m => m.Create(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <byte>(), It.IsAny <int?>())) .ThrowsAsync(new Exception("Mock exception")); var mockFileService = new Mock <IFileService <ChatFilesConfiguration> >(); var mockContextFactory = SetupContextFactory(mockMessagesQuery.Object, mockMessageFilesQuery.Object, null); _sut = new TeacherChatService(mockContextFactory.Object, mockFileService.Object, _mapper); var request = new MessageCreateRequest { Sender = 1, Recipients = new int[] { 1, 2, 3 }, Text = "NewMessageText" }; // ACT var actual = await _sut.CreateAsync(request); // ASSERT Assert.Equal("Mock exception", actual.Error.Message); }
public async Task CreateAsync_ShouldReturnErrorWhenExceptionInQuery1() { var mockMessageFilesQuery = new Mock <IMessageFileQuery>(); mockMessageFilesQuery .Setup(m => m.Create(It.IsAny <string>(), It.IsAny <string>())) .ThrowsAsync(new Exception("Mock exception 1")); var mockFileService = new Mock <IFileService <ChatFilesConfiguration> >(); mockFileService .Setup(f => f.UploadAsync(It.IsAny <IFormFile>())) .ReturnsAsync("Some name"); var mockFormFile = new Mock <IFormFile>(); mockFormFile.SetupGet(f => f.ContentType).Returns(GetTestFileTypes().First().Type); mockFormFile.SetupGet(f => f.FileName).Returns("Some name"); var mockContextFactory = SetupContextFactory(null, mockMessageFilesQuery.Object, null); _sut = new TeacherChatService(mockContextFactory.Object, mockFileService.Object, _mapper); var request = new MessageCreateRequest { Sender = 1, Recipients = new int[] { 1, 2, 3 }, Text = "NewMessageText", AppliedFile = mockFormFile.Object }; // ACT var actual = await _sut.CreateAsync(request); // ASSERT Assert.Equal("Mock exception 1", actual.Error.Message); }
public async Task <IActionResult> Create([FromBody] MessageCreateRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await changeDataCaptureService.CreateAsync(request); return(Ok()); }
public async Task CreateAsync_ShouldReturnErrorWhenRecipientsNumberIsLarge() { var mockMessagesQuery = new Mock <IMessagesQuery>(); var mockFileService = new Mock <IFileService <ChatFilesConfiguration> >(); var mockContextFactory = SetupContextFactory(mockMessagesQuery.Object, null, null); _sut = new TeacherChatService(mockContextFactory.Object, mockFileService.Object, _mapper); var request = new MessageCreateRequest { Sender = 1, Recipients = GetTestRecipientsArray(), Text = "NewMessageText" }; // ACT var actual = await _sut.CreateAsync(request); // ASSERT Assert.Equal("Количество получателей должно быть максимум 1000", actual.Error.Message); }
public async Task CreateAsync_ShouldReturnErrorWhenRecipientsIsNull() { var mockMessagesQuery = new Mock <IMessagesQuery>(); var mockFileService = new Mock <IFileService <ChatFilesConfiguration> >(); var mockContextFactory = SetupContextFactory(mockMessagesQuery.Object, null, null); _sut = new TeacherChatService(mockContextFactory.Object, mockFileService.Object, _mapper); var request = new MessageCreateRequest { Sender = 1, Recipients = null, Text = "NewMessageText" }; // ACT var actual = await _sut.CreateAsync(request); // ASSERT Assert.Equal("Получатели не указаны", actual.Error.Message); }
public async Task CreateAsync_ShouldReturnTrueWhenAplliedFileNotNull() { var newMessageFile = new MessageFile { Id = 10, Name = "NewFileName", FileTypeId = 1 }; var mockMessageFilesQuery = new Mock <IMessageFileQuery>(); mockMessageFilesQuery .Setup(m => m.Create(It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync(newMessageFile); var mockMessagesQuery = new Mock <IMessagesQuery>(); mockMessagesQuery .Setup(m => m.Create(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <byte>(), It.IsAny <int?>())) .ReturnsAsync(0); var mockFormFile = new Mock <IFormFile>(); mockFormFile.SetupGet(f => f.ContentType).Returns(GetTestFileTypes().First().Type); mockFormFile.SetupGet(f => f.FileName).Returns(newMessageFile.Name); var mockFileService = new Mock <IFileService <ChatFilesConfiguration> >(); mockFileService .Setup(f => f.UploadAsync(It.IsAny <IFormFile>())) .ReturnsAsync(newMessageFile.Name); var mockContextFactory = SetupContextFactory(mockMessagesQuery.Object, mockMessageFilesQuery.Object, null); _sut = new TeacherChatService(mockContextFactory.Object, mockFileService.Object, _mapper); var request = new MessageCreateRequest { Sender = 1, Recipients = new int[] { 2, 3 }, Text = "NewMessageText", AppliedFile = mockFormFile.Object }; // ACT var actual = await _sut.CreateAsync(request); // ASSERT Assert.True(actual.Entity); }
public async Task CreateAsync(MessageCreateRequest request) { var message = new Message <string, string> { Key = request.Id, Value = request.Value }; IEnumerable <Resource> resources = await oracleMonitorRepository.List(request.Schema, request.Table, Operation.Create); foreach (Resource resource in resources) { bool exists = await kafkaAdminClientRepository.TopicExistsAsync(resource.Topico.Nome); if (!exists) { await kafkaAdminClientRepository.AddTopicAsync(resource.Topico); } await kafkaProducerRepository.AddMessage(resource.Topico.Nome, message); } }
public async Task CreateAsync_ShouldReturnTrueWhenAplliedFileIsNull() { var mockMessagesQuery = new Mock <IMessagesQuery>(); mockMessagesQuery .Setup(m => m.Create(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <byte>(), It.IsAny <int?>())) .ReturnsAsync(0); var mockFileService = new Mock <IFileService <ChatFilesConfiguration> >(); var mockContextFactory = SetupContextFactory(mockMessagesQuery.Object, null, null); _sut = new TeacherChatService(mockContextFactory.Object, mockFileService.Object, _mapper); var request = new MessageCreateRequest { Sender = 1, Recipients = new int[] { 2, 3 }, Text = "NewMessageText" }; // ACT var actual = await _sut.CreateAsync(request); // ASSERT Assert.True(actual.Entity); }
public async Task <MessageCreateRequest> CreateMessage(string message, string title, string AppKey, int prioity = 2) { using (var request = new HttpRequestMessage(HttpMethod.Post, path)) { request.Headers.Add("X-Gotify-Key", AppKey); SendMessage messageToSend = new SendMessage(); messageToSend.title = title; messageToSend.message = message; messageToSend.priority = prioity; var str = JsonConvert.SerializeObject(messageToSend); request.Content = new StringContent(str, Encoding.UTF8, "application/json"); var httpclient = services.GetService <IHttpClientFactory>(); var client = httpclient.CreateClient("TokenAuth"); using (HttpResponseMessage result = await client.SendAsync(request)) { if (result.IsSuccessStatusCode) { var parsedJson = JsonConvert.DeserializeObject <SendMessage>(await result.Content.ReadAsStringAsync()); MessageCreateRequest messageModel = new MessageCreateRequest(true, parsedJson); return(messageModel); } else { var parsedJson = JsonConvert.DeserializeObject <RequestError>(await result.Content.ReadAsStringAsync()); MessageCreateRequest messageModel = new MessageCreateRequest(false, parsedJson); return(messageModel); } } } }
public async Task CreateAsync_ShouldReturnErrorWhenAplliedFileTypeIsNotAllowed() { var mockMessagesQuery = new Mock <IMessagesQuery>(); var mockFormFile = new Mock <IFormFile>(); mockFormFile.SetupGet(f => f.ContentType).Returns("application/bat"); mockFormFile.SetupGet(f => f.FileName).Returns("NewFileName.bat"); var mockFileService = new Mock <IFileService <ChatFilesConfiguration> >(); var mockContextFactory = SetupContextFactory(mockMessagesQuery.Object, null, null); _sut = new TeacherChatService(mockContextFactory.Object, mockFileService.Object, _mapper); var request = new MessageCreateRequest { Sender = 1, Recipients = new int[] { 2, 3 }, Text = "NewMessageText", AppliedFile = mockFormFile.Object }; // ACT var actual = await _sut.CreateAsync(request); // ASSERT Assert.Equal("Файл \"" + request.AppliedFile.FileName + "\" не может быть загружен", actual.Error.Message); }
public async Task <ActionResult <MessageDto> > CreateMessage(Guid id, MessageCreateRequest values) { return(Ok(await subchannelService.CreateMessage(id, values))); }
public async Task SendMessage(Guid id, MessageCreateRequest values) { var message = await subchannelService.CreateMessage(id, values); await Clients.Group(id.ToString()).SendAsync("ReceiveMessage", message); }
public Message CreateMessage(MessageCreateRequest request) { request.ProjectId = this.Id; return(Api.Messages.Create(request)); }