GetUserByUsername() public method

public GetUserByUsername ( string username ) : User
username string
return User
        public void Should_Import_All_Pages_Categories_And_Usernames()
        {
            // Arrange
            ApplicationSettings applicationSettings = new ApplicationSettings();
            applicationSettings.AttachmentsFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ScrewturnImport");

            if (Directory.Exists(applicationSettings.AttachmentsFolder))
                Directory.Delete(applicationSettings.AttachmentsFolder, true);

            Directory.CreateDirectory(applicationSettings.AttachmentsFolder);

            applicationSettings.ConnectionString = _connectionString;
            applicationSettings.DataStoreType = DataStoreType.SqlServer2012;

            IRepository repository = new LightSpeedRepository(applicationSettings);
            repository.Startup(applicationSettings.DataStoreType,
                                applicationSettings.ConnectionString,
                                false);

            // Clear the database
            repository.Install(applicationSettings.DataStoreType,
                                applicationSettings.ConnectionString,
                                false);
            ScrewTurnImporter importer = new ScrewTurnImporter(applicationSettings, repository);

            // Act
            importer.ImportFromSqlServer(SqlExpressSetup.ConnectionString);

            // Assert
            User user = repository.GetUserByUsername("user2");
            Assert.That(user.Id, Is.Not.EqualTo(Guid.Empty));

            List<Page> pages = repository.AllPages().ToList();
            Assert.That(pages.Count, Is.EqualTo(3));

            Page page1 = pages.FirstOrDefault(x => x.Title == "Screwturn page 1");
            PageContent pageContent1 = repository.GetLatestPageContent(page1.Id);
            Assert.That(page1.Tags, Is.EqualTo("Category1,"));
            Assert.That(page1.CreatedOn.ToString("u"), Is.EqualTo("2013-08-11 19:05:49Z"));
            Assert.That(page1.ModifiedOn.ToString("u"), Is.EqualTo("2013-08-11 19:05:49Z"));
            Assert.That(page1.CreatedBy, Is.EqualTo("admin"));
            Assert.That(page1.ModifiedBy, Is.EqualTo("admin"));
            Assert.That(pageContent1.Text, Is.EqualTo("This is an amazing Screwturn page."));

            Page page2 = pages.FirstOrDefault(x => x.Title == "Screwturn page 2");
            PageContent pageContent2 = repository.GetLatestPageContent(page2.Id);
            Assert.That(page2.Tags, Is.EqualTo("Category1,Category2,"));
            Assert.That(page2.CreatedOn.ToString("u"), Is.EqualTo("2013-08-11 19:06:54Z"));
            Assert.That(page2.ModifiedOn.ToString("u"), Is.EqualTo("2013-08-11 19:06:54Z"));
            Assert.That(page2.CreatedBy, Is.EqualTo("user2"));
            Assert.That(page2.ModifiedBy, Is.EqualTo("user2"));
            Assert.That(pageContent2.Text, Is.EqualTo("Amazing screwturn page 2"));
        }
Example #2
0
        /// <summary>
        /// Returns the user name
        /// </summary>
        public string GetUser(string username)
        {

            string _usernames = "unknown";
            try
            {

                LightSpeedRepository repository = new LightSpeedRepository(GetAppSettings());
                User _user;
                _user = repository.GetUserByUsername(username);
                _usernames = _user.Firstname + " " + _user.Lastname;
            }
            catch { }

            return _usernames;

        }