public static string user_XmlFile_Location(this TM_FileStorage tmFileStorage, TMUser tmUser) { if (tmFileStorage.isNull()) return null; var fileName = tmUser.user_XmlFile_Name(); return fileName.valid() ? tmFileStorage.users_XmlFile_Location().pathCombine(fileName) : null; }
public void user_XmlFile_Name() { // check with username with size 10 or less (so that there will be not subString or safeFileName applied) var userName = 10.randomLetters(); var id = Guid.NewGuid(); var tmUser = new TMUser { UserName = userName, ID = id}; var expectedFileName = TMConsts.USERDATA_FORMAT_USER_XML_FILE.format(userName, id); var fileName1 = tmUser.user_XmlFile_Name(); var fileName2 = tmUser.user_XmlFile_Name(); // calling it twice should produce the same value Assert.AreEqual(fileName1, fileName2); Assert.AreEqual(fileName1, expectedFileName); // check when username has weird chars var weirdName = ":@^%" + 20.randomChars(); var normalizedName = weirdName.subString(0, 10).safeFileName(); Assert.IsFalse(new TMUser { UserName = weirdName, ID = id }.user_XmlFile_Name().contains(weirdName)); Assert.IsTrue (new TMUser { UserName = weirdName, ID = id }.user_XmlFile_Name().contains(normalizedName)); //Check nulls and empty values (note that the last two work) Assert.IsNull (new TMUser () .user_XmlFile_Name()); Assert.IsNull (new TMUser { UserName = "" }.user_XmlFile_Name()); Assert.IsNull (new TMUser { UserName = null }.user_XmlFile_Name()); Assert.IsNull (new TMUser { UserName = "******" , ID = Guid.Empty }.user_XmlFile_Name()); Assert.IsNull (new TMUser { UserName = "" , ID = Guid.NewGuid() }.user_XmlFile_Name()); Assert.IsNull (new TMUser { UserName = null , ID = Guid.NewGuid() }.user_XmlFile_Name()); Assert.IsNotNull(new TMUser { UserName = "******" , ID = Guid.NewGuid() }.user_XmlFile_Name()); Assert.IsNotNull(new TMUser { UserName = "******" }.user_XmlFile_Name()); }