public void GetWrongUserReplacesException()
        {
            using (var subscription = obsListener.LogToSqlDatabase("test", TracingDatabaseConnectionString, bufferingCount: 1))
            {
                string username = "******";
                var roles = new[] { "Employee" };
                Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity(username), roles);

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

                //assert that the friendly excetpion is thrown to the UI
                var ex = ExceptionAssertHelper.Throws<NotifyException>(() => repository.GetUser(username));

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

                var entries = DatabaseHelper.GetAllLogEntries(TracingDatabaseConnectionString);
                Assert.AreEqual(2, entries.Count);
                Assert.IsTrue(entries.Any(e => e.Level == (int)EventLevel.Error));
                Assert.IsTrue(entries.Any(e => e.EventId == 1000));
                Assert.IsTrue(entries.Any(e => e.Payload.Contains(Resources.UserNotRegisteredMessage)));

                Assert.IsNotNull(ex, "Exception not thrown");
                StringAssert.Contains(ex.Message, Resources.FriendlyMessage);
            }
        }
        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 GetUser()
        {
            string username = "******";
            var roles = new[] { "Employee" };
            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity(username), roles);

            var repository = new UserRepository(this.ldapStore, this.exceptionMgr, this.container);
            var user = repository.GetUser(username);

            Assert.IsNotNull(user);
            Assert.AreEqual(username, user.UserName);
            Assert.AreEqual(1, user.Roles.Count);
            Assert.AreEqual("Employee", user.Roles.First());
            Assert.AreEqual("John Doe", user.FullName);
            Assert.AreEqual("ADATUM\\mary", user.Manager);
            Assert.AreEqual("31023", user.CostCenter);
        }
        public void GetWrongUserReplacesException()
        {
            string username = "******";
            var roles = new[] { "Employee" };
            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity(username), roles);

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

            //assert that the friendly excetpion is thrown to the UI
            var ex = ExceptionAssertHelper.Throws<NotifyException>(
              () => repository.GetUser(username));

            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, Resources.UserNotRegisteredMessage);
            StringAssert.Contains(error.Title, Resources.NotifyExceptionTitle);

        }