public void AddTwoComments() { var profile = (ProfileDTO)profiles[0].Tag; var profile1 = (ProfileDTO)profiles[1].Tag; SessionData data = CreateNewSession(profile, ClientInformation); TrainingDayDTO day = new TrainingDayDTO(DateTime.Now); day.ProfileId = profile.GlobalId; BlogEntryDTO blogEntry = new BlogEntryDTO(); blogEntry.Comment = "jakis tekst"; day.AllowComments = true; day.AddEntry(blogEntry); SaveTrainingDayResult result = null; RunServiceMethod(delegate(InternalBodyArchitectService Service) { result = Service.SaveTrainingDay(data.Token, day); day = result.TrainingDay; }); TrainingDayCommentDTO comment = new TrainingDayCommentDTO(); comment.Profile = profile; comment.Comment = "msg"; DateTime time = DateTime.UtcNow; RunServiceMethod(delegate(InternalBodyArchitectService Service) { TimerService.UtcNow = time; TrainingDayCommentOperationParam arg = new TrainingDayCommentOperationParam(); arg.TrainingDayId = day.GlobalId; arg.Comment = comment; arg.OperationType = TrainingDayOperationType.Add; Service.TrainingDayCommentOperation(data.Token, arg); }); data = CreateNewSession(profile1, ClientInformation); comment = new TrainingDayCommentDTO(); comment.Profile = profile1; comment.Comment = "msg1"; time = DateTime.UtcNow.AddHours(2); RunServiceMethod(delegate(InternalBodyArchitectService Service) { TimerService.UtcNow = time; TrainingDayCommentOperationParam arg = new TrainingDayCommentOperationParam(); arg.TrainingDayId = day.GlobalId; arg.Comment = comment; arg.OperationType = TrainingDayOperationType.Add; Service.TrainingDayCommentOperation(data.Token, arg); }); var dbDay = Session.QueryOver <TrainingDay>().SingleOrDefault(); Assert.IsNotNull(dbDay); Assert.AreEqual(2, dbDay.CommentsCount); Assert.IsTrue(dbDay.LastCommentDate.Value.CompareDateTime(time)); }
private void btnAdd_Click(object sender, EventArgs e) { if (txtComment.Text == string.Empty) { return; } this.Focus(); progressBar.ShowProgress(true, ApplicationStrings.BlogPage_ProgressSavingComment); var m = new ServiceManager <TrainingDayCommentOperationCompletedEventArgs>(delegate(BodyArchitectAccessServiceClient client1, EventHandler <TrainingDayCommentOperationCompletedEventArgs> operationCompleted) { TrainingDayCommentOperationParam operation = new TrainingDayCommentOperationParam(); operation.OperationType = TrainingDayOperationType.Add; var dto = new TrainingDayCommentDTO(); dto.Comment = txtComment.Text; dto.Profile = ApplicationState.Current.SessionData.Profile; operation.Comment = dto; operation.TrainingDayId = viewModel.Day.GlobalId; client1.TrainingDayCommentOperationAsync(ApplicationState.Current.SessionData.Token, operation); client1.TrainingDayCommentOperationCompleted -= operationCompleted; client1.TrainingDayCommentOperationCompleted += operationCompleted; }); m.OperationCompleted += (s1, a1) => { FaultException <BAServiceException> serviceEx = a1.Error as FaultException <BAServiceException>; if (serviceEx != null && serviceEx.Detail.ErrorCode == ErrorCode.InvalidOperationException) { BAMessageBox.ShowError(ApplicationStrings.ErrCommentsAreDisabled); return; } else if (a1.Error != null) { progressBar.ShowProgress(false); BAMessageBox.ShowError(ApplicationStrings.BlogPage_ErrSavingComment); return; } else { txtComment.Text = string.Empty; progressBar.ShowProgress(true, ApplicationStrings.BlogPage_ProgressRetrieveComments); viewModel.LoadComments(); } }; if (!m.Run()) { progressBar.ShowProgress(false); if (ApplicationState.Current.IsOffline) { BAMessageBox.ShowError(ApplicationStrings.ErrOfflineMode); } else { BAMessageBox.ShowError(ApplicationStrings.ErrNoNetwork); } return; } }
public void AddComment_SetLoginData() { var profile = (ProfileDTO)profiles[0].Tag; var profile1 = (ProfileDTO)profiles[1].Tag; SessionData data = CreateNewSession(profile, ClientInformation); TrainingDayDTO day = new TrainingDayDTO(DateTime.Now); day.ProfileId = profile.GlobalId; BlogEntryDTO blogEntry = new BlogEntryDTO(); blogEntry.Comment = "jakis tekst"; day.AllowComments = true; day.AddEntry(blogEntry); SaveTrainingDayResult result = null; RunServiceMethod(delegate(InternalBodyArchitectService Service) { result = Service.SaveTrainingDay(data.Token, day); day = result.TrainingDay; }); LoginData loginData = new LoginData(); loginData.ApiKey = apiKey; loginData.ApplicationVersion = "1.0.0"; loginData.LoginDateTime = DateTime.UtcNow; loginData.ApplicationLanguage = "en"; loginData.PlatformVersion = "NUnit"; insertToDatabase(loginData); data = CreateNewSession(profile1, ClientInformation, loginData); TrainingDayCommentDTO comment = new TrainingDayCommentDTO(); comment.Profile = profile1; comment.Comment = "msg"; DateTime time = DateTime.UtcNow; RunServiceMethod(delegate(InternalBodyArchitectService Service) { TimerService.UtcNow = time; TrainingDayCommentOperationParam arg = new TrainingDayCommentOperationParam(); arg.TrainingDayId = day.GlobalId; arg.Comment = comment; arg.OperationType = TrainingDayOperationType.Add; Service.TrainingDayCommentOperation(data.Token, arg); }); var dbDay = Session.QueryOver <TrainingDay>().SingleOrDefault(); Assert.AreEqual(loginData.ApiKey.ApiKey, dbDay.Comments.First().LoginData.ApiKey.ApiKey); }
public void AddComment_SendEMailAndMessage() { var profile = (ProfileDTO)profiles[0].Tag; var profile1 = (ProfileDTO)profiles[1].Tag; profiles[0].Settings.NotificationBlogCommentAdded = ProfileNotification.Message | ProfileNotification.Email; insertToDatabase(profiles[0]); SessionData data = CreateNewSession(profile, ClientInformation); TrainingDayDTO day = new TrainingDayDTO(DateTime.Now); day.ProfileId = profile.GlobalId; BlogEntryDTO blogEntry = new BlogEntryDTO(); blogEntry.Comment = "jakis tekst"; day.AllowComments = true; day.AddEntry(blogEntry); SaveTrainingDayResult result = null; RunServiceMethod(delegate(InternalBodyArchitectService Service) { result = Service.SaveTrainingDay(data.Token, day); day = result.TrainingDay; }); data = CreateNewSession(profile1, ClientInformation); TrainingDayCommentDTO comment = new TrainingDayCommentDTO(); comment.Profile = profile1; comment.Comment = "msg"; DateTime time = DateTime.UtcNow; RunServiceMethod(delegate(InternalBodyArchitectService Service) { TimerService.UtcNow = time; TrainingDayCommentOperationParam arg = new TrainingDayCommentOperationParam(); arg.TrainingDayId = day.GlobalId; arg.Comment = comment; arg.OperationType = TrainingDayOperationType.Add; Service.TrainingDayCommentOperation(data.Token, arg); Assert.True(((MockEmailService)Service.EMailService).EMailSent); }); var messages = Session.QueryOver <Message>().Where(x => x.Receiver == profiles[0]).SingleOrDefault(); Assert.IsNotNull(messages); Assert.IsNotNull(messages.Content); Assert.AreEqual(MessagePriority.System, messages.Priority); }
public void AddComment_AnotherProfile() { var profile = (ProfileDTO)profiles[0].Tag; var profile1 = (ProfileDTO)profiles[1].Tag; SessionData data = CreateNewSession(profile, ClientInformation); TrainingDayDTO day = new TrainingDayDTO(DateTime.Now); day.ProfileId = profile.GlobalId; BlogEntryDTO blogEntry = new BlogEntryDTO(); blogEntry.Comment = "jakis tekst"; day.AllowComments = true; day.AddEntry(blogEntry); SaveTrainingDayResult result = null; RunServiceMethod(delegate(InternalBodyArchitectService Service) { result = Service.SaveTrainingDay(data.Token, day); day = result.TrainingDay; }); data = CreateNewSession(profile1, ClientInformation); TrainingDayCommentDTO comment = new TrainingDayCommentDTO(); comment.Profile = profile; comment.Comment = "msg"; DateTime time = DateTime.UtcNow; RunServiceMethod(delegate(InternalBodyArchitectService Service) { TimerService.UtcNow = time; TrainingDayCommentOperationParam arg = new TrainingDayCommentOperationParam(); arg.TrainingDayId = day.GlobalId; arg.Comment = comment; arg.OperationType = TrainingDayOperationType.Add; Service.TrainingDayCommentOperation(data.Token, arg); }); }