public void get_value_or_default_returns_value_in_column() { var data = new DataRecord(new HeaderRecord(true, "Name", "Age", "Gender", "Relationship Status"), true, "Kent", "25", "M"); Assert.Equal("Kent", data.GetValueOrNull("Name")); Assert.Equal("25", data.GetValueOrNull("Age")); Assert.Equal("M", data.GetValueOrNull("Gender")); }
public void get_value_or_null_returns_null_if_column_is_not_found() { var data = new DataRecord(new HeaderRecord(true, "Name", "Age", "Gender", "Relationship Status"), true, "Kent", "25", "M"); Assert.Null(data.GetValueOrNull("foo")); Assert.Null(data.GetValueOrNull("name")); Assert.Null(data.GetValueOrNull("GENDER")); Assert.Null(data.GetValueOrNull("Relationship Status")); }
public void get_value_or_null_throws_if_there_is_no_header() { var data = new DataRecord(null); var ex = Assert.Throws <InvalidOperationException>(() => data.GetValueOrNull("anything")); Assert.Equal("No header record is associated with this DataRecord.", ex.Message); }
protected User CreateCSVUser(DataRecord record) { var role = (int)Enum.Parse(typeof(Role), record.GetValueOrNull("Role") ?? "Student"); var password = record.GetValueOrNull("Password"); if (string.IsNullOrEmpty(password)) { password = this.RandomPassword(); } var user = new User { Id = Guid.NewGuid(), Username = record.GetValueOrNull("Username") ?? string.Empty, Password = password, Email = record.GetValueOrNull("Email") ?? string.Empty, Name = record.GetValueOrNull("Name") ?? string.Empty, OpenId = record.GetValueOrNull("OpenId") ?? string.Empty, Deleted = false, IsApproved = true, ApprovedBy = this.GetCurrentUser().Id, CreationDate = DateTime.Now, }; if (!string.IsNullOrEmpty(user.OpenId) && !this.UserOpenIdAvailable(user.OpenId, Guid.Empty)) { user.OpenId = string.Empty; } user.UserRoles.Add(new UserRole { RoleRef = role, UserRef = user.Id }); return(user); }
public void get_value_or_null_throws_if_column_name_is_null() { var data = new DataRecord(new HeaderRecord(new string[] { "Name", "Age", "Gender" })); var ex = Assert.Throws<ArgumentNullException>(() => data.GetValueOrNull(null)); }
public void get_value_or_null_throws_if_there_is_no_header() { var data = new DataRecord(null); var ex = Assert.Throws<InvalidOperationException>(() => data.GetValueOrNull("anything")); Assert.Equal("No header record is associated with this DataRecord.", ex.Message); }
protected User CreateCSVUser(DataRecord record) { var role = (int)Enum.Parse(typeof(Role), record.GetValueOrNull("Role") ?? "Student"); var password = record.GetValueOrNull("Password"); if (string.IsNullOrEmpty(password)) { password = this.RandomPassword(); } var user = new User { Id = Guid.NewGuid(), Username = record.GetValueOrNull("Username") ?? string.Empty, Password = password, Email = record.GetValueOrNull("Email") ?? string.Empty, Name = record.GetValueOrNull("Name") ?? string.Empty, OpenId = record.GetValueOrNull("OpenId") ?? string.Empty, Deleted = false, IsApproved = true, ApprovedBy = this.GetCurrentUser().Id, CreationDate = DateTime.Now, }; if (!string.IsNullOrEmpty(user.OpenId) && !this.UserOpenIdAvailable(user.OpenId, Guid.Empty)) { user.OpenId = string.Empty; } user.UserRoles.Add(new UserRole { RoleRef = role, UserRef = user.Id }); return user; }
public void get_value_or_null_throws_if_column_name_is_null() { var data = new DataRecord(new HeaderRecord(new string[] { "Name", "Age", "Gender" })); var ex = Assert.Throws <ArgumentNullException>(() => data.GetValueOrNull(null)); }