public void UpdatePreferredReimbursementMethod()
        {
            string username = "******";
            var roles = new[] { "UpdatePreferredReimbursementMethod_Role" };
            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity(username), roles);
            var repository = new UserRepository(this.ldapStore, this.exceptionMgr, this.container);

            var actual = repository.GetUser(username);
            actual.PreferredReimbursementMethod = ReimbursementMethod.Cash;

            repository.UpdateUserPreferredReimbursementMethod(actual);

            var updated = repository.GetUser(username);

            Assert.IsNotNull(updated);
            Assert.AreEqual(ReimbursementMethod.Cash, updated.PreferredReimbursementMethod);
        }
        public void InvalidUserInUpdateReplacesException()
        {

            var repository = new UserRepository(LDAPStore, exceptionMgr, container);

            var ex = ExceptionAssertHelper.Throws<NotifyException>(
              () => repository.UpdateUserPreferredReimbursementMethod(null));

            //assert that the friendly execption is thrown to the UI

            Assert.IsNotNull(ex, "Exception not thrown");
            StringAssert.Contains(ex.Message, Resources.FriendlyMessage);

            //assert that the inner execption is logged to the database

            var errors = DatabaseHelper.GetExceptionsFromDB(LoggingDatabaseConnectionString);
            var error = errors.FirstOrDefault();
            Assert.IsNotNull(error, "Inner exception not logged to the db");
            StringAssert.Contains(error.FormattedMessage, "System.ArgumentNullException");
            StringAssert.Contains(error.Title, Resources.NotifyExceptionTitle);
        }
        public void InvalidUserInUpdateReplacesException()
        {
            using (var subscription = obsListener.LogToSqlDatabase("test", TracingDatabaseConnectionString, bufferingCount: 1))
            {
                var repository = new UserRepository(ldapStore, exceptionMgr, container);

                var ex = ExceptionAssertHelper.Throws<NotifyException>(
                  () => repository.UpdateUserPreferredReimbursementMethod(null));

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

                var entries = DatabaseHelper.GetAllLogEntries(TracingDatabaseConnectionString);
                Assert.AreEqual(2, entries.Count);
                Assert.AreEqual((int)EventLevel.Error, entries.Last().Level);
                Assert.AreEqual(1000, entries.Last().EventId);
                StringAssert.Contains(entries.Last().Payload, "System.ArgumentNullException");

                //assert that the friendly execption is thrown to the UI

                Assert.IsNotNull(ex, "Exception not thrown");
                StringAssert.Contains(ex.Message, Resources.FriendlyMessage);
            }
        }