private async Task <ActionResult <IEnumerable <Message> > > GetMessagesByReceiverIdAsyncActualAsync() { var messages = GetMessageList(); var mockDifiMessageRepository = new Mock <IDifiMessageRepository>(); var difiList = new List <DifiMessage> { messages.ElementAt(0).DifiMessage, messages.ElementAt(1).DifiMessage }; mockDifiMessageRepository.Setup(repository => repository.GetMessagesByReceiverIdAsync("922308055", "989778471")).ReturnsAsync(difiList); var mockElementsMessageRepisitory = new Mock <IElementsMessageRepository>(); var elementsList = new List <ElementsMessage> { messages.ElementAt(0).ElementsMessage, messages.ElementAt(1).ElementsMessage }; mockElementsMessageRepisitory.Setup(repository => repository.GetElementsMessagesByReceiverIdAsync("922308055", "989778471")).ReturnsAsync(elementsList); var mockMessageMergeService = new Mock <IMessageMergeService>(); mockMessageMergeService.Setup(service => service.MergeMessagesListsOutAsync("922308055", elementsList, difiList)).ReturnsAsync(messages); var messageController = new MessagesController(); var actual = await messageController.GetMessagesByReceiverIdAsync("922308055", "989778471", mockDifiMessageRepository.Object, mockMessageMergeService.Object, mockElementsMessageRepisitory.Object); return(actual); }
public async Task Post_Activity_Exception_Occurs() { var activity = new Activity { Type = ActivityTypes.Message, ChannelId = ChannelIds.Directline }; var telemetryClient = new TelemetryClient(); var builder = new ContainerBuilder(); builder .Register((c, x) => telemetryClient) .AsSelf(); builder .RegisterType <RootDialog>() .AsSelf(); var container = builder.Build(); var botService = new Mock <IBotService>(); var dialogInvoker = new Mock <IDialogInvoker>(); var target = new MessagesController(botService.Object, container, dialogInvoker.Object, telemetryClient) { Request = new HttpRequestMessage() }; dialogInvoker.Setup(i => i.SendAsync(activity, It.IsAny <Func <IDialog <object> > >())).Throws <Exception>(); var result = await target.Post(activity); result.StatusCode.Should().Be(HttpStatusCode.InternalServerError); }
public async void AddMessage_ReturnsCreatedAtRouteResult_WithMessageData() { //Arrange _mockUserService.Setup(Service => Service.CheckIfUserExists(It.IsAny <Guid>())) .ReturnsAsync(true) .Verifiable(); MessageDto messageEntity = _mapper.Map <MessageDto>(_messageToAdd); messageEntity.Id = new Guid(ConstIds.ExampleMessageId); _mockMessagesService.Setup(Service => Service.AddMessageAsync(It.IsAny <Guid>(), It.IsAny <MessageToAddDto>())) .ReturnsAsync(messageEntity) .Verifiable(); var controller = new MessagesController(_loggerMock.Object, _mockMessagesService.Object, _mockUserService.Object); //Act var result = await controller.AddMessage(ConstIds.ExampleUserId, _messageToAdd); //Assert var redirectToActionResult = Assert.IsType <CreatedAtRouteResult>(result.Result); Assert.Equal(ConstIds.ExampleUserId, redirectToActionResult.RouteValues["userId"].ToString()); Assert.Equal(ConstIds.ExampleMessageId, redirectToActionResult.RouteValues["messageId"].ToString()); Assert.Equal("GetMessage", redirectToActionResult.RouteName); Assert.IsType <MessageDto>(redirectToActionResult.Value); _mockUserService.Verify(); _mockMessagesService.Verify(); }
protected void LoadItems() { if (!HasEditPermission) { dgMessages.Columns[dgMessages.Columns.Count - 1].Visible = false; } List <MessageUI> items = MessagesController.GetAllMessages("");//txtSearch.Text.Trim()); //bool isSearchActive; //if (!bool.TryParse(hfIsSearchActive.Value, out isSearchActive)) isSearchActive = false; //dgMessages.VirtualItemCount = items.Count; //if (dgMessages.VirtualItemCount == 0) //{ // phHasItems.Visible = false; // phHasNoItems.Visible = true; // lblNoItems.Text = isSearchActive ? MessagesStrings.GetText(@"MessageNoMessagesFound") : MessagesStrings.GetText(@"MessageNoDataHere"); //} //else //{ // phHasItems.Visible = true; // phHasNoItems.Visible = false; // if (dgMessages.PageSize * dgMessages.CurrentPageIndex > dgMessages.VirtualItemCount) // { // dgMessages.CurrentPageIndex = 0; // hfCurrentPageIndex_dgMessages.Value = dgMessages.CurrentPageIndex.ToString(); // } // items.GetRange(dgMessages.PageSize * dgMessages.CurrentPageIndex, (dgMessages.PageSize > items.Count ? items.Count : dgMessages.PageSize)); //LimitRows(dgMessages.PageSize).OffsetRows(dgMessages.PageSize * dgMessages.CurrentPageIndex); BindList(items); //} }
public async void Returns_ListOfThreadOut_when_ThreadsFound() { List <ThreadOut> listThreadOut = new List <ThreadOut>() { new ThreadOut(), new ThreadOut() }; StatusCode <List <ThreadOut> > status = new StatusCode <List <ThreadOut> >(StatusCodes.Status200OK, listThreadOut); Mock <IMessageService> messageService = new Mock <IMessageService>(); messageService.Setup(_ => _.GetThreadsByUser(It.IsAny <string>())) .Returns(Task.FromResult(status)); MessagesController messagesController = new MessagesController(messageService.Object, UserManagerHelper.GetUserManager(ADMIN_USERNAME)); messagesController.Authenticate(ADMIN_USERNAME); IActionResult result = await messagesController.GetThreads(); Assert.NotNull(result); OkObjectResult okObjectResult = result as OkObjectResult; Assert.NotNull(okObjectResult); Assert.NotNull(okObjectResult.Value); Assert.IsType <List <ThreadOut> >(okObjectResult.Value); Assert.Equal(2, (okObjectResult.Value as List <ThreadOut>).Count); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); Configuration.BaseUri = "https://api.messagemedia.com"; Configuration.BasicAuthUserName = "******"; Configuration.BasicAuthPassword = "******"; MessageMediaMessagesClient client = new MessageMediaMessagesClient(); MessagesController messages = client.Messages; SendMessagesRequest body = new SendMessagesRequest(); body.Messages = new List <Message>(); Message body_messages_0 = new Message(); body_messages_0.Content = "Hello world!"; body_messages_0.DestinationNumber = "+614<number>"; body.Messages.Add(body_messages_0); try { dynamic result = messages.SendMessagesAsync(body).Result; } catch (APIException e) { Console.WriteLine(e.Message + e.ResponseCode + e.HttpContext.ToString()); }; }
protected IntegrationTestBase() { host = new Linq2Db(); storage = new Storage(host); messagesController = new MessagesController(storage); }
public async void Returns_MessageOut_when_MessageSend() { MessageOut messageOut = new MessageOut { ID = Guid.NewGuid(), Content = "Message's content", SendingUserUsername = ADMIN_USERNAME, }; StatusCode <MessageOut> status = new StatusCode <MessageOut>(StatusCodes.Status200OK, messageOut); Mock <IMessageService> messageService = new Mock <IMessageService>(); messageService.Setup(_ => _.SendMessage(It.IsAny <MessagePost>(), It.IsAny <string>())) .Returns(Task.FromResult(status)); MessagesController messagesController = new MessagesController(messageService.Object, UserManagerHelper.GetUserManager(ADMIN_USERNAME)); messagesController.Authenticate(ADMIN_USERNAME); MessagePost messagePost = new MessagePost { ToUserUsername = ADMIN_USERNAME, Content = "Message's content" }; IActionResult result = await messagesController.SendMessage(messagePost); Assert.NotNull(result); OkObjectResult okObjectResult = result as OkObjectResult; Assert.NotNull(okObjectResult); Assert.IsType <MessageOut>(okObjectResult.Value); }
public MessagesControllerTest() { _service = new AirTableServiceFake(); _configuration = new ConfigurationBuilder() .Build(); _controller = new MessagesController(_configuration, _service); }
/// <summary> /// Inicializa la comunicación con otros plugins /// </summary> public override void InitComunicationBetweenPlugins() { // Inicializa los proyectos MessagesController.RequestProjectDefinitions(); // Llama al método base base.InitComunicationBetweenPlugins(); }
public MessagesControllerTests() { var mockDataService = new MockDataService(); ILoggerFactory loggerFactory = new LoggerFactory(); _sut = new MessagesController(mockDataService, loggerFactory); }
public async Task Post_Activity_ConversationUpdate() { var activity = new Activity { Type = ActivityTypes.ConversationUpdate, ChannelId = ChannelIds.Directline }; var telemetryClient = new TelemetryClient(); var builder = new ContainerBuilder(); builder .Register((c, x) => telemetryClient) .AsSelf(); builder .RegisterType <RootDialog>() .AsSelf(); var container = builder.Build(); var botService = new Mock <IBotService>(); var dialogInvoker = new Mock <IDialogInvoker>(); var target = new MessagesController(botService.Object, container, dialogInvoker.Object, telemetryClient) { Request = new HttpRequestMessage { RequestUri = new Uri("https://somekindofurl/api/messages") } }; var result = await target.Post(activity); dialogInvoker.Verify(i => i.SendAsync(activity, It.IsAny <Func <IDialog <object> > >())); result.StatusCode.Should().Be(HttpStatusCode.OK); }
public async Task MessagesController_Get_Returns_OKObjectResult_When_MessageBoardService_Is_Valid() { // Arrange var response = new GetMessagesResponse(new List <Message> { new Message { User = "******", Content = "Hello Tom.", Created = DateTime.Now.AddMinutes(5) }, new Message { User = "******", Content = "It works.", Created = DateTime.Now } }); var service = new Mock <IMessageBoardService>(); service.Setup(s => s.GetAsync()).ReturnsAsync(response); var logger = new Mock <ILogger <MessagesController> >(); var controller = new MessagesController(service.Object, logger.Object); // Act var result = await controller.Get(); // Assert Assert.IsType <OkObjectResult>(result); Assert.Equal(2, ((result as OkObjectResult).Value as GetMessagesResponse).Messages.Count); }
public void DeleteReturnsNotFound() { MessagesController messagesController = new MessagesController(); IHttpActionResult deleteActionResult = messagesController.Delete(100); Assert.IsInstanceOfType(deleteActionResult, typeof(NotFoundResult)); }
public async Task ShareMessageUrl_SuccessfullyRetrievesMessageUrlWhenMessageExistsWithGateway() { // Arrange var gatewayHost = "gatewayHost"; var request = new Mock <HttpRequest>(); var context = new Mock <HttpContext>(); request.SetupGet(t => t.Scheme).Returns(testHttpScheme); request.SetupGet(t => t.Host).Returns(new HostString(gatewayHost, testPort)); request.SetupGet(t => t.Headers).Returns( new HeaderDictionary { { "X-Original-Host", gatewayHost } }); context.SetupGet(t => t.Request).Returns(request.Object); controllerContext = new ControllerContext() { HttpContext = context.Object }; controller = new MessagesController(messageService.Object, logger.Object); controller.ControllerContext = controllerContext; messageService.Setup(e => e.MessageExists(testKey)).ReturnsAsync(true); // Act var result = await controller.ShareMessageUrl(testKey); // Assert var actualResult = result as ViewResult; Assert.IsNotNull(actualResult); Assert.AreEqual(typeof(ShowMessageUrlViewModel), actualResult.Model.GetType()); Assert.AreEqual(((ShowMessageUrlViewModel)actualResult.Model).Url, $"{testHttpScheme}://{gatewayHost}:{testPort}/messages/view/{testKey}"); messageService.VerifyAll(); }
public async Task TopViewsTest() { int messagesCount = 10; MessagesController controller = GetMessagesController(); await SendMessagesWithNumbers(controller, messagesCount); List <MessageResponse> messages = await controller.GetMessages(new GetMessageRequest { CurrentLocation = _zeroLocation }); var topMessageToView = messages[4].Id; var secondMessageToView = messages[7].Id; await controller.AddViewToMessage(new List <Guid> { topMessageToView }); await controller.AddViewToMessage(new List <Guid> { topMessageToView }); await controller.AddViewToMessage(new List <Guid> { topMessageToView, secondMessageToView }); messages = await controller.GetTopViewedMessages(new SkipTakeMessagesRequest()); Assert.AreEqual(1, messages.Count); Assert.AreEqual(messages[0].Id, topMessageToView); }
public void Init() { this.messageService = TestObjectFactory.GetMessagesService(); this.controller = new MessagesController(this.messageService); this.presenceService = TestObjectFactory.GetPresenceService(); this.controllerWithPresence = new MessagesController(this.messageService, this.presenceService); }
public async Task Post_Activity_Exception_Occurs() { var activity = new Activity { Type = ActivityTypes.Message, ChannelId = ChannelIds.Directline }; var telemetryClient = new TelemetryClient(); var builder = new ContainerBuilder(); builder .Register((c, x) => telemetryClient) .AsSelf(); builder .RegisterType <RootDialog>() .AsSelf(); var container = builder.Build(); var target = new MessagesController(container, telemetryClient) { Request = new HttpRequestMessage() }; var result = await target.Post(activity); result.StatusCode.Should().Be(HttpStatusCode.InternalServerError); }
public void MessagesController_Should_Return_View_With_Error_If_Message_Content_Empty() { var messageService = new Mock <IMessageService>(); var message = new MessageInputModel { Message = null, ReceiverName = "someName", SenderName = "anotherName", SendDate = DateTime.Now }; var httpContext = new DefaultHttpContext(); var tempData = new TempDataDictionary(httpContext, Mock.Of <ITempDataProvider>()) { [GlobalConstants.Error] = GlobalConstants.EmptyMessage }; var controller = new MessagesController(messageService.Object) { TempData = tempData }; var result = controller.SendMessage(message); string action = "Profile"; result.Should().BeOfType <RedirectToActionResult>().Which.ActionName.Should().Be(action); }
public async Task GetMessage_ValidMime() { DateTime startDate = DateTime.Now; DbModel.Message testMessage1 = await GetTestMessage1(); TestMessagesRepository messagesRepository = new TestMessagesRepository(testMessage1); MessagesController messagesController = new MessagesController(messagesRepository); ApiModel.Message result = messagesController.GetMessage(testMessage1.Id); Assert.Null(result.MimeParseError); Assert.Equal(testMessage1.Id, result.Id); Assert.InRange(result.ReceivedDate, startDate, DateTime.Now); Assert.Equal("*****@*****.**", result.From); Assert.Equal("*****@*****.**", result.To); Assert.Equal("*****@*****.**", result.Bcc); Assert.Equal("*****@*****.**", result.Cc); Assert.Equal("subject", result.Subject); var allParts = result.Parts.Flatten(p => p.ChildParts).ToList(); Assert.Equal(6, allParts.Count); Assert.All(allParts, p => { Assert.Equal(testMessage1.Id, p.MessageId); Assert.NotNull(p.Id); Assert.NotEqual("", p.Id); }); //All parts have a unique Id Assert.Equal(allParts.Count, allParts.Select(p => p.Id).Distinct().Count()); }
public async Task EmptyMessageCollectionTest() { MessagesController controller = GetMessagesController(); List <MessageResponse> messages = await controller.GetMessages(); Assert.IsEmpty(messages); }
public async Task GetAllCommentsOfUserMessages() { MessagesController messagesController = GetMessagesController(); MessageCommentsController messageCommentsController = GetMessageCommentsController(); await messagesController.SendMessage(new AddMessageRequest { Text = _defaultMessageText, Location = _zeroLocation }); List <MessageResponse> messages = await messagesController.GetMessages(new GetMessageRequest { CurrentLocation = _zeroLocation }); await messageCommentsController.SendComment(new AddMessageCommentRequest { Text = _defaultCommentsText, MessageId = messages[0].Id }); List <MessageCommentResponse> comments = await messageCommentsController.GetAllCommentsOfUserMessages(); Assert.AreEqual(1, comments.Count); Assert.AreEqual(_defaultCommentsText, comments[0].Text); Assert.AreEqual(messages[0].Id, comments[0].MessageId); }
public async Task AddCommentToAnotherComment() { MessagesController messagesController = GetMessagesController(); MessageCommentsController messageCommentsController = GetMessageCommentsController(); await messagesController.SendMessage(new AddMessageRequest { Text = _defaultMessageText, Location = _zeroLocation }); List <MessageResponse> messages = await messagesController.GetMessages(new GetMessageRequest { CurrentLocation = _zeroLocation }); await messageCommentsController.SendComment(new AddMessageCommentRequest { Text = _defaultCommentsText, MessageId = messages[0].Id }); List <MessageCommentResponse> comments = await messageCommentsController.GetComments(messages[0].Id); await messageCommentsController.SendComment(new AddMessageCommentRequest { Text = _secondCommentsText, MessageId = comments[0].MessageId }); comments = await messageCommentsController.GetComments(messages[0].Id); Assert.AreEqual(2, comments.Count); Assert.AreEqual(_defaultCommentsText, comments[0].Text); Assert.AreEqual(_secondCommentsText, comments[1].Text); }
public void GetAll_ShouldDefaultIsPublishedParameterTrue(bool isPublished) { var publishedCount = 3; var unpublishedCount = 2; for (var i = 0; i < publishedCount; i++) { var testMessage = TestData.CreateMessage($"published-{i.ToString()}", "test description", 0, true, false); testMessage.Id = Guid.NewGuid(); context.Message.Add(testMessage); } for (var i = 0; i < unpublishedCount; i++) { var testMessage = TestData.CreateMessage($"unpublished-{i.ToString()}", "test description", 0, false, false); testMessage.Id = Guid.NewGuid(); context.Message.Add(testMessage); } context.SaveChanges(); var controller = new MessagesController(context, logger.Object, mapper); var result = controller.GetAll(isPublished) as ObjectResult; result.Should().BeOfType <OkObjectResult>(); var models = result.Value as ICollection <Message>; models.Count().Should().Be(isPublished ? publishedCount : unpublishedCount); }
public async Task MarkMessageAsRead_UnauthorizedUserIdPassed_ReturnsUnauthorizedResult() { var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.NameIdentifier, "1"), })); var mapperMock = new Mock <IMapper>(); var repositoryMock = new Mock <IRepositoryWrapper>(); repositoryMock.Setup(r => r.MessageRepository.GetMessageAsync(It.IsAny <int>())).ReturnsAsync(new Message() { RecipientId = 1 }); repositoryMock.Setup(r => r.SaveAllAsync()).ReturnsAsync(true); var controllerMock = new MessagesController(repositoryMock.Object, mapperMock.Object); controllerMock.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = user } }; var result = await controllerMock.MarkMessageAsRead(2, 2); Assert.IsType <UnauthorizedResult>(result); }
public async Task GetMessage_ExistingMessageIdPassed_ReturnsOkResult() { var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.NameIdentifier, "1"), })); var repositoryMock = new Mock <IRepositoryWrapper>(); var messageToReturn = new Message { Id = 1 }; repositoryMock.Setup(r => r.MessageRepository.GetMessageAsync(1)).ReturnsAsync(() => messageToReturn); var mapperMock = new Mock <IMapper>(); var controllerMock = new MessagesController(repositoryMock.Object, mapperMock.Object); controllerMock.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = user } }; var result = await controllerMock.GetMessage(1, 1) as OkObjectResult; Assert.IsType <OkObjectResult>(result); Assert.Equal(messageToReturn, result.Value); }
public async Task DeleteMessage_ValidUserIdAndMessageIdPassed_ReturnsNoContentResult() { var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.NameIdentifier, "1"), })); var mapperMock = new Mock <IMapper>(); var repositoryMock = new Mock <IRepositoryWrapper>(); repositoryMock.Setup(r => r.MessageRepository.GetMessageAsync(It.IsAny <int>())).ReturnsAsync(new Message()); repositoryMock.Setup(r => r.SaveAllAsync()).ReturnsAsync(true); var controllerMock = new MessagesController(repositoryMock.Object, mapperMock.Object); controllerMock.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = user } }; var result = await controllerMock.DeleteMessage(1, 1); Assert.IsType <NoContentResult>(result); }
public async Task GetMessage_NotExistingMessageIdPassed_ReturnsNotFound() { var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.NameIdentifier, "1"), })); var repositoryMock = new Mock <IRepositoryWrapper>(); repositoryMock.Setup(r => r.MessageRepository.GetMessageAsync(0)).ReturnsAsync(() => null); var mapperMock = new Mock <IMapper>(); var controllerMock = new MessagesController(repositoryMock.Object, mapperMock.Object); controllerMock.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = user } }; var result = await controllerMock.GetMessage(1, 0); Assert.IsType <NotFoundResult>(result); }
public async Task GetMessageThread_InvalidRequest_ReturnsUnauthorizedResult() { var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.NameIdentifier, "1"), })); var mapperMock = new Mock <IMapper>(); var repositoryMock = new Mock <IRepositoryWrapper>(); repositoryMock.Setup(r => r.MessageRepository.GetMessageThreadAsync(1, 1)).ReturnsAsync(new List <Message>()); mapperMock.Setup(m => m.Map <IEnumerable <MessageToReturnDto> >(It.IsAny <List <Message> >())).Returns(new List <MessageToReturnDto>()); var controllerMock = new MessagesController(repositoryMock.Object, mapperMock.Object); controllerMock.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = user } }; var result = await controllerMock.GetMessageThread(2, 1); Assert.IsType <UnauthorizedResult>(result); }
public async Task SendMessage_Happy() { var message = new MessageRequestModel { Text = "banaismailde", ToUserName = "******" }; var messageService = new Mock <IMessageService>(); var controller = new MessagesController(messageService.Object); var userName = "******"; var user = new ClaimsPrincipal(new GenericIdentity(userName)); controller.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = user } }; OkResult result = await controller.Post(message) as OkResult; messageService.Verify(x => x.SendMessage(userName, message.ToUserName, message.Text)); Assert.NotNull(result); }
public async Task EmptyMessageCollectionTest() { MessagesController controller = GetMessagesController(); List <MessageResponse> messages = await controller.GetMessages(new GetMessageRequest { CurrentLocation = _zeroLocation }); Assert.IsEmpty(messages); }
public static void Main() { var robotEventAggregator = new RobotEventAggregator(); var nrfController = new NrfController(); var messagesController = new MessagesController(robotEventAggregator, nrfController); var robot = new Robot(robotEventAggregator, nrfController); robot.Start(); messagesController.Start(); nrfController.Initialize("ROBOT", "CONTR"); Thread.Sleep(Timeout.Infinite); }
public void TestQueryRetriever() { var messagesController = new MessagesController(); messagesController.GetQueryInformation("Who owns OSI?"); }
public void Initialize() { this.unitOfWorkMock = new MeetyChatDataMock(); this.controller = new MessagesController(this.unitOfWorkMock, UserIdProviderMock.GetUserIdProvider().Object); this.serializer = new JavaScriptSerializer(); this.SetupController(); }