public void CommentIsAddedToRepository() { var result = controller.AddComment(model); Mock.Get(repository).Verify(r => r.Save(model)); Assert.That(result, Is.TypeOf <OkResult>()); }
// Use this for initialization void Start() { VoiceRecorder voiceRecorder = voiceManager.GetComponent <VoiceRecorder>(); AudioRecognizer audioRecognizer = voiceManager.GetComponent <AudioRecognizer>(); recordButton.OnClickAsObservable().Subscribe(_ => { if (!isRecording) { voiceRecorder.StartRecord(); materialButton.iconVectorImageData = stopIcon; } else { materialButton.iconVectorImageData = startIcon; var rec_data = voiceRecorder.FinishRecord(); audioRecognizer.SpeechToText(rec_data); audioRecognizer.transcriptSubject.Subscribe(txt => { inputField.text = txt; }); } isRecording = !isRecording; }); addButton.OnClickAsObservable().Subscribe(_ => { if (inputField.text != "") { commentController.AddComment(inputField.text); inputField.text = ""; } }); }
public async Task Call_CommentServiceWithCorrectParams_OnPost() { // Arrange string commentText = "Very interesting. Would love to see it!"; string title = "Avengers EndGame"; string userName = "******"; var commentServiceMock = new Mock <ICommentService>(); var model = new CommentViewModel(); commentServiceMock.Setup(asm => asm.AddComment(commentText, title, userName)) .ReturnsAsync(model); var createModel = new CreateCommentViewModel() { Text = commentText, Title = title, User = userName }; var sut = new CommentController(commentServiceMock.Object); // Act var result = await sut.AddComment(createModel); // Assert commentServiceMock.Verify(x => x.AddComment(commentText, title, userName), Times.Once); }
private async void SecurityRejectButton_Clicked(object sender, EventArgs e) { CommentsStack.IsVisible = true; if (string.IsNullOrEmpty(CommentsEditor.Text) || string.IsNullOrWhiteSpace(CommentsEditor.Text)) { await DisplayAlert("Comments Required", "Please enter a brief description of your reason for rejecting this application.", "OK"); } else { bool confirm = await DisplayAlert("Confirm", "Are you sure you want to reject this application?", "Yes", "No"); if (confirm) { Comment comment = new Comment { applicationid = applicationid, commenter = "NA", comment_by = "SECURITY", comment_time = DateTime.UtcNow, comment = CommentsEditor.Text }; //SEND COMMENTS TO API and Update app_status to REJECTED CommentController.AddComment(comment); Models.Application app = ApplicationController.GetApplication(int.Parse(applicationid)); } } }
private async void RejectButton_Clicked(object sender, EventArgs e) { //Comments are REQUIRED to be submitted at rejection //To Be Done : Implement content validation of Comments Content to ensure users aren't sending null/whitespace/single character. Check if at least 15 characters are inputted. StackLayout commentsStack = CurrentPage.FindByName <StackLayout>("CommentsStack"); commentsStack.IsVisible = true; var commentsContent = commentsStack.FindByName <Editor>("CommentsEditor").Text; commentsStack.FindByName <Editor>("CommentsEditor").Focus(); if (string.IsNullOrEmpty(commentsContent) || string.IsNullOrWhiteSpace(commentsContent)) { await DisplayAlert("Comments Required", "Please enter a brief description of your reason for rejecting this application.", "OK"); } else { bool confirm = await DisplayAlert("Confirm", "Are you sure you want to reject this application?", "Yes", "No"); if (confirm) { int applicationid = int.Parse(viewModel.ReviewAppList[Children.IndexOf(CurrentPage)].applicationid); Comment comment = new Comment { applicationid = applicationid.ToString(), commenter = DataHandler.getEmployeeData().name, comment_by = "MANAGER", comment_time = DateTime.UtcNow, comment = commentsContent }; //Add Comment to Database //To be done : Implement feature for applicant to view comments on their HomePage as to why application was rejected CommentController.AddComment(comment); //Update Application Status to CANCELLED ApplicationController.RejectApplication(applicationid); //Once REJECTED, remove current application from ReviewAppList (list of applications to review that are visible to Manager) viewModel.ReviewAppList.RemoveAt(Children.IndexOf(CurrentPage)); if (viewModel.ReviewAppList.Count == 0) { HomePage.viewModel.ResetHomePageUI_OnNoApplicationstoReview(); } Navigation.PopAsync(); } } }
public void CannotAddInvalidComment() { //Arrange CommentController target = new CommentController(_postRepositoryMock.Object); target.ModelState.AddModelError("Error", "Error"); PostComment postComment = new PostComment(); //Act target.AddComment(postComment); //Assert _postRepositoryMock.Verify(m => m.Update(It.IsAny <Post>()), Times.Never); }
public void TestAddComment() { var contextMock = new Mock <HttpContext>(); contextMock.Setup(x => x.User).Returns(new ClaimsPrincipal(claims)); mockAuthorService.Setup(x => x.GetById(It.IsAny <string>())).Returns(author); mockCommentService.Setup(x => x.Add(It.IsAny <Comment>())).Returns(cmt); var _commenController = new CommentController(mockCommentService.Object, mockAuthorService.Object); _commenController.ControllerContext.HttpContext = contextMock.Object; var addcomment = _commenController.AddComment(cmt); var type = addcomment.GetType(); Assert.AreEqual(type.Name, "OkObjectResult"); }
public void CanAddValidComment() { //Arrange CommentController target = new CommentController(_postRepositoryMock.Object); PostComment postComment = new PostComment() { Content = "Test", Id = 6, PostId = 2 }; //Act target.AddComment(postComment); //Assert _postRepositoryMock.Verify(m => m.Update(It.IsAny <Post>()), Times.Once); }
public async Task RedirectToCorrectAction_OnPost() { // Arrange string commentText = "Very interesting. Would love to see it!"; string title = "Avengers EndGame"; string userName = "******"; var commentServiceMock = new Mock <ICommentService>(); var model = new CommentViewModel(); commentServiceMock.Setup(asm => asm.AddComment(commentText, title, userName)) .ReturnsAsync(model); var createModel = new CreateCommentViewModel() { Text = commentText, Title = title, User = userName }; var sut = new CommentController(commentServiceMock.Object); // Act var result = await sut.AddComment(createModel); // Assert Assert.IsInstanceOfType(result, typeof(RedirectToActionResult)); var redirect = (RedirectToActionResult)result; Assert.IsTrue(redirect.ControllerName == "News"); Assert.IsTrue(redirect.ActionName == "Details"); }
public void TestAddComment() { // Arrange var context = new Mock <HttpContextBase>(); var mock = new Mock <ControllerContext>(); // If using local DB, the user id is different var dbconnection = System.Configuration.ConfigurationManager.AppSettings["SiteConnectionString"]; var appid = "f752739e-8d58-4bf5-a140-fc225cc5ebdb"; if (dbconnection == "ZapreadLocal") { appid = "96b762df-5fb3-43ff-ba55-7da1fc9750c8"; } var identity = new GenericIdentity("test"); identity.AddClaim(new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", appid)); //test user var principal = new GenericPrincipal(identity, new[] { "user" }); context.Setup(s => s.User).Returns(principal); var userStore = new Mock <IUserStore <ApplicationUser> >(); var userManager = new Mock <ApplicationUserManager>(userStore.Object); var authenticationManager = new Mock <IAuthenticationManager>(); var signInManager = new Mock <ApplicationSignInManager>(userManager.Object, authenticationManager.Object); var claimsIdentity = new Mock <ClaimsIdentity>(MockBehavior.Loose); claimsIdentity.Setup(x => x.AddClaim(It.IsAny <Claim>())); IList <UserLoginInfo> userlogins = new List <UserLoginInfo>(); userManager.Setup(x => x.GetPhoneNumberAsync(It.IsAny <string>())).Returns(Task.FromResult("123")); userManager.Setup(x => x.GetTwoFactorEnabledAsync(It.IsAny <string>())).Returns(Task.FromResult(true)); userManager.Setup(x => x.GetLoginsAsync(It.IsAny <string>())).Returns(Task.FromResult(userlogins)); var routeData = new RouteData(); routeData.Values.Add("controller", "MessagesController"); routeData.Values.Add("action", "GetMessage"); mock.SetupGet(m => m.RouteData).Returns(routeData); var view = new Mock <IView>(); var engine = new Mock <IViewEngine>(); var viewEngineResult = new ViewEngineResult(view.Object, engine.Object); engine.Setup(e => e.FindPartialView(It.IsAny <ControllerContext>(), It.IsAny <string>(), It.IsAny <bool>())).Returns(viewEngineResult); ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(engine.Object); CommentController controller = new CommentController(new EventService()); controller.ControllerContext = new ControllerContext(context.Object, routeData, controller); var newComment = new CommentController.NewComment() { IsDeleted = true, CommentContent = "test", IsReply = true, CommentId = 1, PostId = 1, IsTest = true, }; // Act JsonResult result = controller.AddComment(newComment).Result as JsonResult; // Assert Assert.IsNotNull(result); }