public void CanGetExpenseForApprovalFromCache() { Guid expenseIdToSave = Guid.NewGuid(); Assert.IsNull(util.DatabaseHelper.GetExpenseById(TestDatabaseConnectionString, expenseIdToSave)); var stubUser = new User { UserName = "******" }; var stubManager = "the manager"; var expenseToSave = new Model.Expense { Id = expenseIdToSave, Date = new DateTime(1900, 01, 01), Title = "Title", Description = "Description", Total = 1.0, ReimbursementMethod = ReimbursementMethod.DirectDeposit, CostCenter = "CostCenter", Approved = false, User = stubUser, ApproverName = stubManager }; var repository = new ExpenseRepository(TestDatabaseConnectionString, TimeSpan.MaxValue); repository.SaveExpense(expenseToSave); var expToApprove = repository.GetExpensesForApproval(stubManager); DatabaseHelper.BypassRepositoryAndDeleteExpense(TestDatabaseConnectionString, expenseToSave.Id); expToApprove = repository.GetExpensesForApproval(stubManager); Assert.AreEqual(1, expToApprove.Count()); Assert.AreEqual(expenseIdToSave, expToApprove.First().Id); }
public void UpdateUserPreferredReimbursementMethod(User user) { exManager.Process(() => { Guard.ArgumentNotNull(user, "user"); var profile = ProfileBase.Create(user.UserName); profile.SetPropertyValue("PreferredReimbursementMethod", Enum.GetName(typeof(ReimbursementMethod), user.PreferredReimbursementMethod)); profile.Save(); }, Constants.NotifyPolicy); }
public static Model.Expense GenerateExpenseStub() { Guid expenseIdToValidate = Guid.NewGuid(); var stubUser = new User { UserName = "******" }; var stubManager = "ADATUM\\mary"; return new Model.Expense { Id = expenseIdToValidate, Date = new DateTime(1900, 01, 01), Title = "Title", Description = "Description", Total = 1.0, ReimbursementMethod = ReimbursementMethod.DirectDeposit, CostCenter = "CostCenter", Approved = true, User = stubUser, ApproverName = stubManager }; }
public void SaveExpense() { Guid expenseIdToSave = Guid.Empty; var stubUser = new User { UserName = "******" }; var stubManager = "the manager"; var expenseToSave = new AExpense.Model.Expense { Id = expenseIdToSave, Date = new DateTime(1900, 01, 01), Title = "Title", Description = "Description", Total = 1.0, ReimbursementMethod = ReimbursementMethod.DirectDeposit, CostCenter = "CostCenter", Approved = true, User = stubUser, ApproverName = stubManager }; var repository = new ExpenseRepository(dataContext); repository.SaveExpense(expenseToSave); var expenseEntity = repository.GetExpenseById(expenseIdToSave); Assert.IsNotNull(expenseEntity); Assert.AreEqual(expenseToSave.Approved, expenseEntity.Approved); Assert.AreEqual(expenseToSave.CostCenter, expenseEntity.CostCenter); Assert.AreEqual(expenseToSave.Date, expenseEntity.Date); Assert.AreEqual(expenseToSave.Description, expenseEntity.Description); Assert.AreEqual(expenseToSave.Id, expenseEntity.Id); Assert.AreEqual(expenseToSave.ReimbursementMethod, expenseEntity.ReimbursementMethod); Assert.AreEqual(expenseToSave.Title, expenseEntity.Title); Assert.AreEqual(expenseToSave.User.UserName, expenseEntity.User.UserName); Assert.AreEqual(expenseToSave.ApproverName, expenseEntity.ApproverName); }
public void UpdatingAnExpenseUpdatesTheCache() { //Creation of expense Guid expenseIdToSave = Guid.NewGuid(); Assert.IsNull(util.DatabaseHelper.GetExpenseById(TestDatabaseConnectionString, expenseIdToSave)); var stubUser = new User { UserName = "******" }; var stubManager = "the manager"; var expenseToSave = new Model.Expense { Id = expenseIdToSave, Date = new DateTime(1900, 01, 01), Title = "Title", Description = "Description", Total = 1.0, ReimbursementMethod = ReimbursementMethod.DirectDeposit, CostCenter = "CostCenter", Approved = false, User = stubUser, ApproverName = stubManager }; //Get the repository with the highest cache expiration var repository = new ExpenseRepository(TestDatabaseConnectionString, TimeSpan.MaxValue); //Save expense repository.SaveExpense(expenseToSave); //Get expense (it also caches the expense) var savedExpense = repository.GetExpenseById(expenseIdToSave); //basic Assertion Assert.IsNotNull(savedExpense); //Approve the expense savedExpense.Approved = true; Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("test"), new string[] { "Manager" }); repository.UpdateApproved(savedExpense); //Delete expense in db so we make sure we will get expense from cache. DatabaseHelper.BypassRepositoryAndDeleteExpense(TestDatabaseConnectionString, savedExpense.Id); //Get expense (from cache) and verify new description var cachedExpense = repository.GetExpenseById(expenseIdToSave); //Assert Assert.IsNotNull(cachedExpense); Assert.IsTrue(cachedExpense.Approved); }
public void GetExpenseByIdIsGoneAfterCacheExpires() { Guid expenseIdToSave = Guid.NewGuid(); Assert.IsNull(util.DatabaseHelper.GetExpenseById(TestDatabaseConnectionString, expenseIdToSave)); var stubUser = new User { UserName = "******" }; var stubManager = "the manager"; var expenseToSave = new Model.Expense { Id = expenseIdToSave, Date = new DateTime(1900, 01, 01), Title = "Title", Description = "Description", Total = 1.0, ReimbursementMethod = ReimbursementMethod.DirectDeposit, CostCenter = "CostCenter", Approved = true, User = stubUser, ApproverName = stubManager }; var repository = new ExpenseRepository(TestDatabaseConnectionString, new TimeSpan(0, 0, 2)); repository.SaveExpense(expenseToSave); var expense = repository.GetExpenseById(expenseToSave.Id); DatabaseHelper.BypassRepositoryAndDeleteExpense(TestDatabaseConnectionString, expenseToSave.Id); Thread.Sleep(3000); expense = repository.GetExpenseById(expenseToSave.Id); Assert.IsNull(expense); }
public void AddExpenseLogsActivity() { using(var subscription = obsListener.LogToSqlDatabase("Activity", TracingDatabaseConnectionString)) { var repository = new ExpenseRepository(TestDatabaseConnectionString, TimeSpan.MinValue); Guid expenseIdToSave = Guid.NewGuid(); Assert.IsNull(DatabaseHelper.GetExpenseById(TestDatabaseConnectionString, expenseIdToSave)); var stubUser = new User { UserName = "******" }; var stubManager = "the manager"; var expenseToSave = new Model.Expense { Id = expenseIdToSave, Date = new DateTime(1900, 01, 01), Title = "Title", Description = "Description", Total = 1.0, ReimbursementMethod = ReimbursementMethod.DirectDeposit, CostCenter = "CostCenter", Approved = false, User = stubUser, ApproverName = stubManager }; repository.SaveExpense(expenseToSave); subscription.Sink.FlushAsync().Wait(); var logEntries = DatabaseHelper.GetAllLogEntries(TracingDatabaseConnectionString); Assert.AreEqual(6, logEntries.Count()); var SaveExpenseStartedEntry = logEntries.SingleOrDefault(e=> e.EventId == 290); Assert.IsNotNull(SaveExpenseStartedEntry); StringAssert.Contains(SaveExpenseStartedEntry.Payload, expenseToSave.Id.ToString()); var SaveExpenseInsertStartedEntry = logEntries.SingleOrDefault(e=> e.EventId == 295); Assert.IsNotNull(SaveExpenseInsertStartedEntry); StringAssert.Contains(SaveExpenseInsertStartedEntry.Payload, expenseToSave.Id.ToString()); var SaveExpenseInsertFinishedEntry = logEntries.SingleOrDefault(e=> e.EventId == 294); Assert.IsNotNull(SaveExpenseInsertFinishedEntry); StringAssert.Contains(SaveExpenseInsertFinishedEntry.Payload, expenseToSave.Id.ToString()); var SaveExpenseCacheUpdatedEntry = logEntries.SingleOrDefault(e=> e.EventId == 292); Assert.IsNotNull(SaveExpenseCacheUpdatedEntry); var SaveExpenseFinishedEntry = logEntries.SingleOrDefault(e => e.EventId == 291); Assert.IsNotNull(SaveExpenseFinishedEntry); StringAssert.Contains(SaveExpenseFinishedEntry.Payload, expenseToSave.Id.ToString()); } }