public void ApproveExpense()
        {
            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            = false,
                User                = new User {
                    UserName = "******"
                },
                ApproverName = "approver name"
            };

            var repository = new ExpenseRepository(dataContext);

            repository.SaveExpense(expected);

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("test"), new string[] { "Manager" });
            repository.UpdateApproved(expected);

            var actual = repository.GetExpenseById(expected.Id);

            Assert.IsNotNull(actual);
            Assert.AreEqual(expected.Approved, actual.Approved);
        }
示例#2
0
        private bool SaveExpense()
        {
            try
            {
                var user       = UserRepository.GetUser(this.User.Identity.Name);
                var newExpense = new Model.Expense();

                newExpense.Title               = this.ExpenseTitle.Text;
                newExpense.Details             = new List <ExpenseItem>(this.ExpenseItems);
                newExpense.CostCenter          = user.CostCenter;
                newExpense.ReimbursementMethod = (ReimbursementMethod)Enum.Parse(typeof(ReimbursementMethod), this.ExpenseReimbursementMethod.SelectedItem.Value);
                newExpense.User         = user;
                newExpense.Date         = DateTime.Parse(this.ExpenseDate.Text, CultureInfo.CurrentCulture);
                newExpense.ApproverName = this.Approver.Text;
                newExpense.Total        = this.ExpenseItems.Sum(i => i.Amount);

                Repository.SaveExpense(newExpense);

                user.PreferredReimbursementMethod = (ReimbursementMethod)Enum.Parse(typeof(ReimbursementMethod), this.ExpenseReimbursementMethod.SelectedValue);
                UserRepository.UpdateUserPreferredReimbursementMethod(user);
            }
            catch (NotifyException exception)
            {
                this.pageErrorMessage.Text = exception.Message;
                return(false);
            }
            return(true);
        }
        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 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 static Model.Expense ToModel(this DataAccessLayer.Expense entity)
        {
            if (entity == null) 
                return null;

            var expense = new Expense()
            {
                Id = entity.Id,
                Details = entity.ExpenseDetails.Select(i => i.ToModel()).ToList(),
                Approved = entity.Approved,
                CostCenter = entity.CostCenter,
                Date = entity.Date,
                ReimbursementMethod = (ReimbursementMethod)Enum.Parse(typeof(ReimbursementMethod), entity.ReimbursementMethod),
                Title = entity.Title,
                User = new User { UserName = entity.UserName },
                ApproverName = entity.Approver,
                Total = Convert.ToDouble(entity.Amount),
                Description = entity.Description
            };

            return expense;
        }
        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 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);

        }
示例#8
0
        private bool SaveExpense()
        {
            try
            {
                //SAW: #1 Writing a log entry from the app
                AExpenseEvents.Log.UiSaveExpenseStarted();

                var user       = UserRepository.GetUser(this.User.Identity.Name);
                var newExpense = new Model.Expense();

                newExpense.Id                  = Guid.NewGuid();
                newExpense.Title               = this.ExpenseTitle.Text;
                newExpense.Details             = new List <ExpenseItem>(this.ExpenseItems);
                newExpense.CostCenter          = user.CostCenter;
                newExpense.ReimbursementMethod = (ReimbursementMethod)Enum.Parse(typeof(ReimbursementMethod), this.ExpenseReimbursementMethod.SelectedItem.Value);
                newExpense.User                = user;
                newExpense.Date                = DateTime.Parse(this.ExpenseDate.Text, CultureInfo.CurrentCulture);
                newExpense.ApproverName        = this.Approver.Text;
                newExpense.Total               = this.ExpenseItems.Sum(i => i.Amount);

                Repository.SaveExpense(newExpense);

                user.PreferredReimbursementMethod = (ReimbursementMethod)Enum.Parse(typeof(ReimbursementMethod), this.ExpenseReimbursementMethod.SelectedValue);
                UserRepository.UpdateUserPreferredReimbursementMethod(user);

                AExpenseEvents.Log.UiSaveExpenseFinished();
            }
            catch (NotifyException exception)
            {
                //SAW: #2 Writing a log entry with parameters (2 ways)
                AExpenseEvents.Log.UiSaveExpenseFailed(exception);
                AExpenseEvents.Log.UiSaveExpenseFailed(exception.Message, exception.GetType().FullName);
                return(false);
            }

            return(true);
        }
        public void GetAllExpenses()
        {
            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.GetAllExpenses();

            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 ApproveExpense()
        {
            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 = false,
                User = new User { UserName = "******" },
                ApproverName = "approver name"
            };
           
            var repository = new ExpenseRepository(dataContext);
            repository.SaveExpense(expected);

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("test"), new string[] { "Manager" });
            repository.UpdateApproved(expected);

            var actual = repository.GetExpenseById(expected.Id);

            Assert.IsNotNull(actual);
            Assert.AreEqual(expected.Approved, actual.Approved);
        }
        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 GetAllExpensesForApproval()
        {
            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 = "approverName"
            };

            var anotherExpense = 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 = "approverName"
            };

            var notForMeExpense = 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 = "Another approverName"
            };

            var repository = new ExpenseRepository(dataContext);

            repository.SaveExpense(expected);
            repository.SaveExpense(anotherExpense);
            repository.SaveExpense(notForMeExpense);

            var expenses = repository.GetExpensesForApproval("approverName");

            Assert.IsNotNull(expenses);
            Assert.AreEqual(2, expenses.Count());
        }
        public void GetAllExpensesForApproval()
        {
            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 = "approverName"
            };

            var anotherExpense = 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 = "approverName"
            };

            var notForMeExpense = 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 = "Another approverName"
            };

            var repository = new ExpenseRepository(dataContext);

            repository.SaveExpense(expected);
            repository.SaveExpense(anotherExpense);
            repository.SaveExpense(notForMeExpense);

            var expenses = repository.GetExpensesForApproval("approverName");

            Assert.IsNotNull(expenses);
            Assert.AreEqual(2, expenses.Count());
        }
        private bool SaveExpense()
        {
            try
            {
                var user = UserRepository.GetUser(this.User.Identity.Name);
                var newExpense = new Model.Expense();
                
                newExpense.Title = this.ExpenseTitle.Text;
                newExpense.Details = new List<ExpenseItem>(this.ExpenseItems);
                newExpense.CostCenter = user.CostCenter;
                newExpense.ReimbursementMethod = (ReimbursementMethod)Enum.Parse(typeof(ReimbursementMethod), this.ExpenseReimbursementMethod.SelectedItem.Value);
                newExpense.User = user;
                newExpense.Date = DateTime.Parse(this.ExpenseDate.Text, CultureInfo.CurrentCulture);
                newExpense.ApproverName = this.Approver.Text;
                newExpense.Total = this.ExpenseItems.Sum(i => i.Amount);

                Repository.SaveExpense(newExpense);

                user.PreferredReimbursementMethod = (ReimbursementMethod)Enum.Parse(typeof(ReimbursementMethod), this.ExpenseReimbursementMethod.SelectedValue);
                UserRepository.UpdateUserPreferredReimbursementMethod(user);
            }
            catch (NotifyException exception)
            {
                this.pageErrorMessage.Text = exception.Message;
                return false;
            }
            return true;
        }