public void CanSaveCompleteAndValidProject() { var allAccounts = AccountRepository.GetAll(); var activeAccounts = new List<Account>(); foreach (Account account in allAccounts) { if (account.IsActive) { activeAccounts.Add(account); } } //TODO: Verify Account associations? var project = new Project { IsActive = true, Name = ValidValueName, Accounts = activeAccounts }; using (var ts = new TransactionScope()) { _projectRepository.EnsurePersistent(project); ts.CommitTransaction(); } Assert.AreEqual(false, project.IsTransient()); }
public void ActivityTypeDoesNotSaveWithIndicatorWith1Character() { //Invalid Indicator var activityType = new ActivityType { ActivityCategory = ActivityCategory, Indicator = "1", Name = ValidValueName }; try { using (var ts = new TransactionScope()) { _activityTypeRepository.EnsurePersistent(activityType); ts.CommitTransaction(); } } catch (Exception) { var results = activityType.ValidationResults().AsMessageList(); Assert.AreEqual(1, results.Count); results.AssertContains("Indicator: length must be between 2 and 2"); //Assert.AreEqual("Object of type FSNEP.Core.Domain.ActivityType could not be persisted\n\n\r\nValidation Errors: Indicator, The length of the value must fall within the range \"2\" (Inclusive) - \"2\" (Inclusive).\r\n", message.Message, "Expected Exception Not encountered"); throw; } }
/// <summary> /// Only Load Account data /// </summary> protected override void LoadData() { AccountRepository = new Repository<Account>(); using (var ts = new TransactionScope()) { CreateAccounts(AccountRepository); ts.CommitTransaction(); } }
public void StepWillSaveWithValidName() { var step = new Step { Name = "VALIDNAME" }; using (var ts = new TransactionScope()) { Repository.OfType<Step>().EnsurePersistent(step); ts.CommitTransaction(); } Assert.AreEqual(false, step.IsTransient()); }
public static void BeginReportRequest(IRepository repository, HonorsPostModel honorsModel, string userId) { var parameters = new Dictionary<string, string>(); var reportName = "/Commencement/Honors"; parameters.Add("CollegeId", honorsModel.College.Id); parameters.Add("TermCode", honorsModel.TermCode); parameters.Add("Honors4590", honorsModel.Honors4590.ToString()); parameters.Add("HighHonors4590", honorsModel.HighHonors4590.ToString()); parameters.Add("HighestHonors4590", honorsModel.HighestHonors4590.ToString()); parameters.Add("Honors90135", honorsModel.Honors90135.ToString()); parameters.Add("HighHonors90135", honorsModel.HighHonors90135.ToString()); parameters.Add("HighestHonors90135", honorsModel.HighestHonors90135.ToString()); parameters.Add("Honors135", honorsModel.Honors135.ToString()); parameters.Add("HighHonors135", honorsModel.HighHonors135.ToString()); parameters.Add("HighestHonors135", honorsModel.HighestHonors135.ToString()); var hr = honorsModel.Convert(); hr.User = repository.OfType<vUser>().Queryable.FirstOrDefault(a => a.LoginId == userId); // start the transaction just so we can record the request using (var ts = new TransactionScope()) { // create the history object, plus this will also set the request date time repository.OfType<HonorsReport>().EnsurePersistent(hr); ts.CommitTransaction(); } // make the call to get the report, then save it and email the user using (var ts = new TransactionScope()) { // get the actual report itself hr.Contents = GetHonorsReport(parameters); //Get(reportName, parameters); // persist the object repository.OfType<HonorsReport>().EnsurePersistent(hr); ts.CommitTransaction(); // email the user //var message = new MailMessage(); //message.To.Add(hr.User.Email); //message.Subject = "Commencement - Honors Report Completed"; //message.Body = "Your honors report request has completed."; //message.IsBodyHtml = true; //// settings are set in the web.config //var client = new SmtpClient(); //client.Send(message); } }
public void CanCreateNewCommittee() { var newCommittee = new Committee() {Name = "COMMITTEE", Inactive = false}; Assert.IsTrue(newCommittee.IsTransient(), "Should not yet be in the DB"); using (var ts = new TransactionScope()) { Repository.OfType<Committee>().EnsurePersistent(newCommittee); ts.CommitTransaction(); } Assert.IsFalse(newCommittee.IsTransient(), "Should now be in the DB"); }
protected override void LoadData() { base.LoadData(); using (var ts = new TransactionScope()) { LoadStatus(); LoadRecords(); ts.CommitTransaction(); } NHibernateSessionManager.Instance.GetSession().Flush(); }
public void CanNotSaveAuditWithoutSettingActionCode() { var audit = new Audit { AuditDate = DateTime.Now, ObjectName = "User", Username = "******" }; using (var ts = new TransactionScope()) { _auditRepository.EnsurePersistent(audit); ts.CommitTransaction(); } }
public void CanSaveAuditWithoutObjectId() { var audit = new Audit { AuditDate = DateTime.Now, ObjectName = "User", Username = "******" }; audit.SetActionCode(AuditActionType.Update); using (var ts = new TransactionScope()) { _auditRepository.EnsurePersistent(audit); ts.CommitTransaction(); } Assert.AreEqual(false, audit.IsTransient()); }
//Only Load ActivityCategory Data protected override void LoadData() { var activityCategoryRepository = new Repository<ActivityCategory>(); ActivityCategory = new ActivityCategory { Name = ValidValueName }; using (var ts = new TransactionScope()) { activityCategoryRepository.EnsurePersistent(ActivityCategory); ts.CommitTransaction(); } Assert.AreEqual(false, ActivityCategory.IsTransient()); }
public void CanSaveCompleteAndValidActivityType() { var activityType = new ActivityType { ActivityCategory = ActivityCategory, Indicator = ValidValueIndicator, Name = ValidValueName }; using (var ts = new TransactionScope()) { _activityTypeRepository.EnsurePersistent(activityType); ts.CommitTransaction(); } Assert.AreEqual(false, activityType.IsTransient()); }
public void CanNotSaveWithSpacesOnlyInIndicator() { var activityType = new ActivityType { ActivityCategory = ActivityCategory, Indicator = " ", Name = ValidValueName }; try { using (var ts = new TransactionScope()) { _activityTypeRepository.EnsurePersistent(activityType); ts.CommitTransaction(); } } catch (Exception) { var results = activityType.ValidationResults().AsMessageList(); Assert.AreEqual(1, results.Count); results.AssertContains("Indicator: may not be null or empty"); throw; } }
public void ActivityTypeDoesNotSaveWithNullName() { //ServiceLocatorInitializer.Init(); var activityType = new ActivityType { ActivityCategory = ActivityCategory, Indicator = ValidValueIndicator, Name = null }; try { using (var ts = new TransactionScope()) { _activityTypeRepository.EnsurePersistent(activityType); ts.CommitTransaction(); } } catch (Exception) { var results = activityType.ValidationResults().AsMessageList(); Assert.AreEqual(1, results.Count); results.AssertContains("Name: may not be null or empty"); //results.AssertContains("Name: length must be between 0 and 50"); //Assert.AreEqual("Object of type FSNEP.Core.Domain.ActivityType could not be persisted\n\n\r\nValidation Errors: Name, The value cannot be null.\r\nName, length must be between 0 and 50\r\n", message.Message, "Expected Exception Not encountered"); throw; } }
public void ActivityTypeDoesNotSaveWithNullActivityCategory() { var activityType = new ActivityType { ActivityCategory = null, Indicator = ValidValueIndicator, Name = ValidValueName }; try { using (var ts = new TransactionScope()) { _activityTypeRepository.EnsurePersistent(activityType); ts.CommitTransaction(); } } catch (Exception) { var results = activityType.ValidationResults().AsMessageList(); Assert.AreEqual(1, results.Count); results.AssertContains("ActivityCategory: may not be null"); //Assert.AreEqual("Object of type FSNEP.Core.Domain.ActivityType could not be persisted\n\n\r\nValidation Errors: ActivityCategory, The value cannot be null.\r\n", message.Message, "Expected Exception Not encountered"); throw; } }
public ActionResult ServiceMessages() { if(HttpContext.Cache[CacheKey]==null) { using (var ts = new TransactionScope()) { var currentDate = DateTime.UtcNow.ToPacificTime().Date; var serviceMessageListToCache = _serviceMessageRepository.Queryable.Where(a => a.IsActive && a.BeginDisplayDate <= currentDate && (a.EndDisplayDate == null || a.EndDisplayDate >= currentDate)).ToList(); System.Web.HttpContext.Current.Cache.Insert(CacheKey, serviceMessageListToCache, null, DateTime.UtcNow.ToPacificTime().Date.AddDays(1), Cache.NoSlidingExpiration); ts.CommitTransaction(); } } var serviceMessageList = HttpContext.Cache[CacheKey]; return PartialView("~/Views/Shared/_ServiceMessages.cshtml", serviceMessageList); }
/// <summary> /// Find an order by request number and redirect to the review page /// </summary> public ActionResult Lookup(string id) { var relatedOrderId = _repositoryFactory.OrderRepository.Queryable .Where(x => x.RequestNumber == id) .Select(x => x.Id) .SingleOrDefault(); if (relatedOrderId == default(int)) { Message = "Order Not Found"; return this.RedirectToAction<SearchController>(a => a.Index()); } OrderAccessLevel accessLevel; using (var ts = new TransactionScope()) { accessLevel = _securityService.GetAccessLevel(relatedOrderId); ts.CommitTransaction(); } if (accessLevel != OrderAccessLevel.Edit && accessLevel != OrderAccessLevel.Readonly) { if ( Repository.OfType<EmailQueueV2>().Queryable.Any( a => a.Order.Id == relatedOrderId && a.User.Id.ToLower() == CurrentUser.Identity.Name.ToLower())) { var order = _repositoryFactory.OrderRepository.Queryable.Single(a => a.Id == relatedOrderId); if (order.StatusCode.Id == OrderStatusCode.Codes.Cancelled) { Message = "This order has been cancelled"; } else if (order.StatusCode.Id == OrderStatusCode.Codes.Denied) { Message = "This order has been denied"; } else if (order.StatusCode.IsComplete) { Message = "This order has been completed"; } else { var person = string.Empty; var approval = order.Approvals.Where(a => !a.Completed).OrderBy(b => b.StatusCode.Level).FirstOrDefault(); if (approval == null || approval.User == null) { person = "Anyone in the workgroup"; } else { person = approval.User.FullName; } Message = string.Format("This order is currently being handled by {0} in the status {1}", person, order.StatusCode.Name); } return this.RedirectToAction<ErrorController>(a => a.NotAuthorized()); } } return RedirectToAction("Review", new {id = relatedOrderId}); }
public ActionResult MethodWithoutManualTransactionAttributeAndTransactionScope() { using (var ts = new TransactionScope()) { ts.CommitTransaction(); } return Content("String"); }