コード例 #1
0
        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);
        }
コード例 #2
0
        public void GetAllExpensesForApproval()
        {
            var expected = new 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 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 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"
            };

            util.DatabaseHelper.CreateExpense(TestDatabaseConnectionString, expected);
            util.DatabaseHelper.CreateExpense(TestDatabaseConnectionString, anotherExpense);
            util.DatabaseHelper.CreateExpense(TestDatabaseConnectionString, notForMeExpense);

            var repository = new ExpenseRepository(TestDatabaseConnectionString);
            var expenses   = repository.GetExpensesForApproval("approverName");

            Assert.IsNotNull(expenses);
            Assert.AreEqual(2, expenses.Count());
        }
コード例 #3
0
        public void GetAllExpensesForApprovalLogsActivity()
        {
            using (var subscription = obsListener.LogToSqlDatabase("Activity", TracingDatabaseConnectionString))
            {
                var repository = new ExpenseRepository(TestDatabaseConnectionString, TimeSpan.MinValue);
                repository.GetExpensesForApproval("ApproverUser");

                subscription.Sink.FlushAsync().Wait();

                var logEntries = DatabaseHelper.GetAllLogEntries(TracingDatabaseConnectionString);

                Assert.AreEqual(6, logEntries.Count());

                var GetExpensesForApprovalStartedEntry = logEntries.SingleOrDefault(e => e.EventId == 320);
                Assert.IsNotNull(GetExpensesForApprovalStartedEntry);
                StringAssert.Contains(GetExpensesForApprovalStartedEntry.Payload, "ApproverUser");

                var GetExpensesForApprovalQueryStartedEntry = logEntries.SingleOrDefault(e => e.EventId == 327);
                Assert.IsNotNull(GetExpensesForApprovalQueryStartedEntry);
                StringAssert.Contains(GetExpensesForApprovalQueryStartedEntry.Payload, "ApproverUser");

                var GetExpensesForApprovalQueryFinishedEntry = logEntries.SingleOrDefault(e => e.EventId == 324);
                Assert.IsNotNull(GetExpensesForApprovalQueryFinishedEntry);
                StringAssert.Contains(GetExpensesForApprovalQueryFinishedEntry.Payload, "ApproverUser");

                var GetExpensesForApprovalCacheUpdateEntry = logEntries.SingleOrDefault(e => e.EventId == 326);
                Assert.IsNotNull(GetExpensesForApprovalCacheUpdateEntry);
                StringAssert.Contains(GetExpensesForApprovalCacheUpdateEntry.Payload, "ApproverUser");

                var GetExpensesForApprovalFinishedEntry = logEntries.SingleOrDefault(e => e.EventId == 321);
                Assert.IsNotNull(GetExpensesForApprovalFinishedEntry);
                StringAssert.Contains(GetExpensesForApprovalFinishedEntry.Payload, "ApproverUser");
            }
        }
コード例 #4
0
        public void GetExpenseForApprovalAreGoneAfterCacheExpires()
        {
            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, new TimeSpan(0, 0, 2));

            repository.SaveExpense(expenseToSave);

            var expToApprove = repository.GetExpensesForApproval(stubManager);

            DatabaseHelper.BypassRepositoryAndDeleteExpense(TestDatabaseConnectionString, expenseToSave.Id);

            Thread.Sleep(3000);

            expToApprove = repository.GetExpensesForApproval(stubManager);

            Assert.AreEqual(0, expToApprove.Count());
        }
コード例 #5
0
        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());
        }
コード例 #6
0
        public void GetAllExpensesForApprovalLogsActivity()
        {
            using (var subscription = obsListener.LogToSqlDatabase("Activity", TracingDatabaseConnectionString))
            {
                var repository = new ExpenseRepository(TestDatabaseConnectionString, TimeSpan.MinValue);
                repository.GetExpensesForApproval("ApproverUser");

                subscription.Sink.FlushAsync().Wait();

                var logEntries = DatabaseHelper.GetAllLogEntries(TracingDatabaseConnectionString);

                Assert.AreEqual(6, logEntries.Count());

                var GetExpensesForApprovalStartedEntry = logEntries.SingleOrDefault(e => e.EventId == 320);
                Assert.IsNotNull(GetExpensesForApprovalStartedEntry);
                StringAssert.Contains(GetExpensesForApprovalStartedEntry.Payload, "ApproverUser");

                var GetExpensesForApprovalQueryStartedEntry = logEntries.SingleOrDefault(e => e.EventId == 327);
                Assert.IsNotNull(GetExpensesForApprovalQueryStartedEntry);
                StringAssert.Contains(GetExpensesForApprovalQueryStartedEntry.Payload, "ApproverUser");

                var GetExpensesForApprovalQueryFinishedEntry = logEntries.SingleOrDefault(e => e.EventId == 324);
                Assert.IsNotNull(GetExpensesForApprovalQueryFinishedEntry);
                StringAssert.Contains(GetExpensesForApprovalQueryFinishedEntry.Payload, "ApproverUser");

                var GetExpensesForApprovalCacheUpdateEntry = logEntries.SingleOrDefault(e => e.EventId == 326);
                Assert.IsNotNull(GetExpensesForApprovalCacheUpdateEntry);
                StringAssert.Contains(GetExpensesForApprovalCacheUpdateEntry.Payload, "ApproverUser");

                var GetExpensesForApprovalFinishedEntry = logEntries.SingleOrDefault(e => e.EventId == 321);
                Assert.IsNotNull(GetExpensesForApprovalFinishedEntry);
                StringAssert.Contains(GetExpensesForApprovalFinishedEntry.Payload, "ApproverUser");
            }
        }