public void ShouldGetZeroExpensesFromNonExistingUser()
        {
            var expected = new AExpense.Model.Expense
            {
                Id                  = Guid.NewGuid(),
                Date                = new DateTime(1900, 01, 01),
                Title               = "Title",
                Description         = "Description",
                Total               = 1.0,
                ReimbursementMethod = ReimbursementMethod.DirectDeposit,
                CostCenter          = "CostCenter",
                Approved            = true,
                User                = new User {
                    UserName = "******"
                },
                ApproverName = "approver name"
            };

            var repository = new ExpenseRepository(dataContext);

            repository.SaveExpense(expected);

            var expenses = repository.GetExpensesByUser("no existing user name");

            Assert.AreEqual(0, expenses.Count());
        }
Beispiel #2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!this.IsPostBack)
     {
         var repository = new ExpenseRepository();
         var expenses   = repository.GetExpensesByUser(this.User.Identity.Name);
         this.MyExpensesGridView.DataSource = expenses;
         this.DataBind();
     }
 }
Beispiel #3
0
        public void GetExpenseByUserIsGoneAfterCacheExpires()
        {
            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.GetExpensesByUser(stubUser.UserName);

            DatabaseHelper.BypassRepositoryAndDeleteExpense(TestDatabaseConnectionString, expenseToSave.Id);

            Thread.Sleep(3000);

            expense = repository.GetExpensesByUser(stubUser.UserName);

            Assert.AreEqual(0, expense.Count());
        }
        public void GetAllExpensesByUser()
        {
            var expected = new AExpense.Model.Expense
            {
                Id                  = Guid.NewGuid(),
                Date                = new DateTime(1900, 01, 01),
                Title               = "Title",
                Description         = "Description",
                Total               = 1.0,
                ReimbursementMethod = ReimbursementMethod.DirectDeposit,
                CostCenter          = "CostCenter",
                Approved            = true,
                User                = new User {
                    UserName = "******"
                },
                ApproverName = "approver name"
            };

            var repository = new ExpenseRepository(dataContext);

            repository.SaveExpense(expected);

            var expenses = repository.GetExpensesByUser("user name");

            Assert.IsNotNull(expenses);
            var actual = expenses.ToList().Where(e => e.Id == expected.Id).FirstOrDefault();

            Assert.IsNotNull(actual);
            Assert.AreEqual(expected.Total, actual.Total);
            Assert.AreEqual(expected.Approved, actual.Approved);
            Assert.AreEqual(expected.CostCenter, actual.CostCenter);
            Assert.AreEqual(expected.Date, actual.Date);
            Assert.AreEqual(expected.Description, actual.Description);
            Assert.AreEqual(expected.Id, actual.Id);
            Assert.AreEqual(expected.ReimbursementMethod, actual.ReimbursementMethod);
            Assert.AreEqual(expected.Title, actual.Title);
            Assert.AreEqual(expected.User.UserName, actual.User.UserName);
        }
        public void ShouldGetZeroExpensesFromNonExistingUser()
        {
            var expected = new AExpense.Model.Expense
            {
                Id = Guid.NewGuid(),
                Date = new DateTime(1900, 01, 01),
                Title = "Title",
                Description = "Description",
                Total = 1.0,
                ReimbursementMethod = ReimbursementMethod.DirectDeposit,
                CostCenter = "CostCenter",
                Approved = true,
                User = new User { UserName = "******" },
                ApproverName = "approver name"
            };

            var repository = new ExpenseRepository(dataContext);
            repository.SaveExpense(expected);

            var expenses = repository.GetExpensesByUser("no existing user name");

            Assert.AreEqual(0, expenses.Count());
        }
        public void GetAllExpensesByUser()
        {
            var expected = new AExpense.Model.Expense
            {
                Id = Guid.NewGuid(),
                Date = new DateTime(1900, 01, 01),
                Title = "Title",
                Description = "Description",
                Total = 1.0,
                ReimbursementMethod = ReimbursementMethod.DirectDeposit,
                CostCenter = "CostCenter",
                Approved = true,
                User = new User { UserName = "******" },
                ApproverName = "approver name"
            };

            var repository = new ExpenseRepository(dataContext);
            repository.SaveExpense(expected);

            var expenses = repository.GetExpensesByUser("user name");

            Assert.IsNotNull(expenses);
            var actual = expenses.ToList().Where(e => e.Id == expected.Id).FirstOrDefault();
            Assert.IsNotNull(actual);
            Assert.AreEqual(expected.Total, actual.Total);
            Assert.AreEqual(expected.Approved, actual.Approved);
            Assert.AreEqual(expected.CostCenter, actual.CostCenter);
            Assert.AreEqual(expected.Date, actual.Date);
            Assert.AreEqual(expected.Description, actual.Description);
            Assert.AreEqual(expected.Id, actual.Id);
            Assert.AreEqual(expected.ReimbursementMethod, actual.ReimbursementMethod);
            Assert.AreEqual(expected.Title, actual.Title);
            Assert.AreEqual(expected.User.UserName, actual.User.UserName);
        }
        public void GetExpenseByUserIsGoneAfterCacheExpires()
        {

            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.GetExpensesByUser(stubUser.UserName);

            DatabaseHelper.BypassRepositoryAndDeleteExpense(TestDatabaseConnectionString, expenseToSave.Id);

            Thread.Sleep(3000);

            expense = repository.GetExpensesByUser(stubUser.UserName);

            Assert.AreEqual(0, expense.Count());

        }