public void TestTimingSM() { Stopwatch sw = new Stopwatch(); sw.Start(); var sb = new StringManipulator(); for (int x = 0; x < 1000; x++) { sb.Append("Hello "); } for (int x = 0; x < 1000; x++) { sb.Insert("World", 50); } for (int x = 0; x < 1000; x++) { sb.Replace("Hello ", "Hey "); } sw.Stop(); Assert.IsFalse(true, $"{sw.ElapsedMilliseconds}"); }
public ActionResult GenerateInvite(string email) { // Only allow admins to submit a new code if (MembershipAuth.IsAdmin(HttpContext.Request)) { // Generate the invite code Random rand = new Random(); string code = StringManipulator.CreateInviteCode(rand.Next(58, 65)); // Get information from database to populate the invite string userName = MembershipAuth.GetCurrentUser(HttpContext.Request); int orgID = db.Users.SingleOrDefault(u => u.Email == userName).OrganizationID; int createdBy = db.Users.SingleOrDefault(u => u.Email == userName).Id; // Create new invite code InviteCode invite = new InviteCode { Code = code, DateCreated = DateTime.Now, OrganizationID = orgID, IsExpired = false, CreatedBy = createdBy, SentTo = email }; // Add and commit to database db.InviteCodes.Add(invite); db.SaveChanges(); } // Return error screen return(RedirectToAction("Error", "Error", new { error = 3 })); }
private static void TestStringManipulator() { Console.Write("String Manipulator: "); Stopwatch sw = new Stopwatch(); sw.Start(); var sb = new StringManipulator(); for (int x = 0; x < 1000; x++) { sb.Append("Hello "); } for (int x = 0; x < 1000; x++) { sb.Insert("World", 50); } for (int x = 0; x < 1000; x++) { sb.Replace("Hello ", "Hey "); } sw.Stop(); Console.WriteLine(sw.ElapsedMilliseconds); }
public ActionResult Login(User user, string ReturnUrl) { // Check that credentials were entered if (user != null || !string.IsNullOrEmpty(user.Email)) { // Find the user with the appropriate username, and check hashed password User login = db.Users.FirstOrDefault(a => a.Email.Equals(user.Email)); string pass = StringManipulator.GenerateHashedPassword(login.Salt, user.Password); // If a user was found, log them in if (login != null && login.Password == pass) { FormsAuthentication.SetAuthCookie(login.Email.Trim(), false); // If user was previouly logged in, redirect them to their previous page. // Otherwise send them to the default page. if (this.Url.IsLocalUrl(ReturnUrl)) { EventLogger.LogNewEvent(login.Id, login.OrganizationID, LoggingEventType.UserLogin, ""); return(Redirect(ReturnUrl)); } else { EventLogger.LogNewEvent(login.Id, login.OrganizationID, LoggingEventType.UserLogin, ""); return(RedirectToAction("Time", "TimeCard")); } } } // A user wasn't found, try again ViewBag.Error = true; return(View()); }
public void Test_StringManipulator_SubstringSingleSection() { StringManipulator m = new StringManipulator(); m.Append("hello cruel world"); Assert.AreEqual("cruel", m.Substring(6, 5)); }
public void Test_StringManipulator_AddString() { StringManipulator m = new StringManipulator(); m.Append("hello"); Assert.AreEqual("hello", m.ToString()); }
public void SortStringsViaLamda() { var masResult = StringManipulator.SortStrings(new StringManipulator.SortSchema((x, y) => string.CompareOrdinal(x, y)), _masUnsorted); var masExpected = _masUnsorted.OrderBy(x => x); Assert.IsTrue(masExpected.SequenceEqual(masResult), "Строки отсиротированы не корректно"); }
public void SortStringsViaInterface() { var masResult = StringManipulator.SortStrings(new StringAscendingComparer(), _masUnsorted); var masExpected = _masUnsorted.OrderBy(x => x); Assert.IsTrue(masExpected.SequenceEqual(masResult), "Строки отсиротированы не корректно"); }
public void Init() { var _stringManipulator = new StringManipulator(); stringManipulator = _stringManipulator; validData = "Hello out there."; inValidData = ""; }
public void Test_StringManipulator_IndexOfStringInSecondSections() { StringManipulator m = new StringManipulator(); m.Append("hello cru"); m.Append("el world"); Assert.AreEqual("hello cruel world".IndexOf("rld"), m.IndexOf("rld")); }
public void Test_StringManipulator_InsertString() { StringManipulator m = new StringManipulator(); m.Append("hello"); m.Append(" world"); m.Insert("cruel", 6); Assert.AreEqual("hello cruel world", m.ToString()); }
public void Test_StringManipulator_RemoveTwoStringsInsideSection() { StringManipulator m = new StringManipulator(); m.Append("hello cruel world"); m.Remove("l"); Assert.AreEqual("heo crue word", m.ToString()); }
public void Test_StringManipulator_ReplaceMany() { StringManipulator m = new StringManipulator(); m.Append("hello cruel world"); m.Replace("l", "L"); Assert.AreEqual("heLLo crueL worLd", m.ToString()); }
public void Test_StringManipulator_ReplaceSingle() { StringManipulator m = new StringManipulator(); m.Append("hello cruel world"); m.Replace("cruel", "big"); Assert.AreEqual("hello big world", m.ToString()); }
public void Test_StringManipulator_IndexOfSingleLetter() { StringManipulator m = new StringManipulator(); m.Append("hello cru"); m.Append("el world"); Assert.AreEqual("hello".IndexOf('l'), m.IndexOf("l")); }
public void Test_StringManipulator_IndexOfStringStartIndexInLaterSectionNotFound() { StringManipulator m = new StringManipulator(); m.Append("hello cru"); m.Append("el world"); Assert.AreEqual("hello cruel world".IndexOf("k", 7), m.IndexOf("k", 7)); }
public void Test_StringManipulator_IndexOfStringStartIndex() { StringManipulator m = new StringManipulator(); m.Append("hello cru"); m.Append("el world"); Assert.AreEqual("hello cruel world".IndexOf("l", 3), m.IndexOf("l", 3)); }
public static void Main() { new StringFormatterTests(); var StringManipulator = new StringManipulator(new StringFormatter()); Console.WriteLine(StringManipulator.DisplayWordsOnNewLineAndPadWithAstericks("Blue")); Console.ReadLine(); }
public string parse(string val) { NumberOfNibble = Int32.Parse(StringManipulator.getByte(val, 1)); TON_NPI = StringManipulator.getByte(val, 2); int temp = (NumberOfNibble + 1) / 2; Address = StringManipulator.getBytes(val, 3, temp).ToUpper(); return(val.Substring((temp + 2) * 2)); }
public void Test_StringManipulator_RemoveWholeFirstSection() { StringManipulator m = new StringManipulator(); m.Append("hello "); m.Append("world"); m.Remove("hello "); Assert.AreEqual("world", m.ToString()); }
public void Test_StringManipulator_RemoveSingleStringAcrossTwoSections() { StringManipulator m = new StringManipulator(); m.Append("hello cr"); m.Append("uel world"); m.Remove("cruel"); Assert.AreEqual("hello world", m.ToString()); }
public void SortStringsViaFunc() { var comparer = new Func <string, string, int>((x, y) => string.CompareOrdinal(x, y)); var masResult = StringManipulator.SortStrings(comparer, _masUnsorted); var masExpected = _masUnsorted.OrderBy(x => x); Assert.IsTrue(masExpected.SequenceEqual(masResult), "Строки отсиротированы не корректно"); }
public void Test_StringManipulator_RemoveWholeLastSectionAndReplace() { StringManipulator m = new StringManipulator(); m.Append("hello "); m.Append("cruel "); m.Append("world"); m.Replace("world", "suzy"); Assert.AreEqual("hello cruel suzy", m.ToString()); }
public void ShouldReplace() { string inStr = "PARM1=${PARM1}, PARM2=${PARM2}, PARM3=${PARM3}"; string expected1 = "PARM1=PARM1, PARM2=${PARM2}, PARM3=${PARM3}"; string expected2 = "PARM1=PARM1, PARM2=PARM2, PARM3=${PARM3}"; string expected3 = "PARM1=PARM1, PARM2=PARM2, PARM3=PARM3"; Assert.True(StringManipulator.Replace(inStr, "PARM1", "PARM1") == expected1); Assert.True(StringManipulator.Replace(expected1, "PARM2", "PARM2") == expected2); Assert.True(StringManipulator.Replace(expected2, "PARM3", "PARM3") == expected3); }
public void Test_StringManipulator_RemoveSingleStringAcrossThreeSections() { StringManipulator m = new StringManipulator(); m.Append("hello cr"); m.Append("u"); m.Append("el world"); m.Remove("cruel"); Assert.AreEqual("hello world", m.ToString()); Assert.AreEqual("hello world".Length, m.Length, "The Lengths should be the same too"); }
public void ReplaceWords_StrDictIsNotNull_ReturnsTrue() { string testStr = "This is a test"; var testDict = new Dictionary <string, string>() { { "test", "hest" } }; var sm = new StringManipulator(); var result = sm.ReplaceWords(testStr, testDict); Assert.IsNotNull(result); }
public void SortStringsViaDelegate() { var comparer = new StringManipulator.SortSchema(delegate(string x, string y) { return(string.CompareOrdinal(x, y)); }); var masResult = StringManipulator.SortStrings(comparer, _masUnsorted); var masExpected = _masUnsorted.OrderBy(x => x); Assert.IsTrue(masExpected.SequenceEqual(masResult), "Строки отсиротированы не корректно"); }
public static string ConvertToBaseN(ulong Number, int TargetBase, CharAlphabet alphabet = null, int MinDigits = 1, int sign = 0) { //Exceptions if (alphabet.Chars.Count() < TargetBase) { throw new ArgumentException(LangManager.GetString("exception_alphabet_too_short", CurrentCulture)); } if (Number < 0) { sign = -1; } //Defaults if (alphabet == null) { alphabet = Alphabet.Hexadecimal; } //Init string result = ""; ulong placeholder = Number; //Conversion if (Number == 0) { sign = 0; result = result.Insert(0, alphabet.Chars[0].ToString()); } else { while (placeholder != 0) { result += alphabet.Chars[(int)placeholder % TargetBase]; placeholder -= placeholder % (ulong)TargetBase; placeholder /= (ulong)TargetBase; } } //Add mindigits if (result.Length < MinDigits) { for (int x = result.Length; x < MinDigits; x++) { result = result.Insert(0, alphabet.Chars[0].ToString()); } } return(StringManipulator.Reverse(result)); }
public void ShouldReplaceDictionary() { Dictionary <string, string> data = new Dictionary <string, string>() { { "PARM1", "PARM1" }, { "PARM2", "PARM2" }, { "PARM3", "PARM3" } }; string inStr = "PARM1=${PARM1}, PARM2=${PARM2}, PARM3=${PARM3}"; string expected = "PARM1=PARM1, PARM2=PARM2, PARM3=PARM3"; string result = StringManipulator.Replace(inStr, data); Assert.True(result == expected); }
public static string GetReplied(ITweetable tweet) { string textReplied = ""; textReplied = "@" + tweet.Author.ScreenName + " "; foreach (string user in StringManipulator.GetUserNames(tweet.Text)) { if (DataTransfer.CurrentAccount != null && user != "@" + DataTransfer.CurrentAccount.ScreenName) { textReplied += user + " "; } } return(textReplied); }