public void TestGetValue_LengthNotAlwaysEqualsMaxLength() { // Arrange const int maxLength = 16; var randomText = new RandomText { Text = "word1 word2 word3. Word4 word5? Some text and more text." }; randomTextRepo.Setup(rtr => rtr.GetRandom()).Returns(randomText); var columnInfo = new RandomTextColumnInfo { IsNullable = false, MaxLength = maxLength }; var strategy = new RandomTextColumnValueStrategy(RepoFactory); // Act bool isFound = false; for (int i = 0; i < 1000; i++) { string value = strategy.GetValue(columnInfo, EmptyCountry); isFound = value.Length < maxLength; if (isFound) { break; } } // Assert Assert.IsTrue(isFound); }
public override SendSMSResponseBody ExecuteCore() { string randText = RandomText.GetNum(6); //生成6位验证码 var codeInfo = SendContentConfig.SMSRegisterDesc(randText); //组织发送内容 string error = ""; bool succ = SmsSend.ToUser(this.request.Mobile, codeInfo, out error);//开始发送 if (!succ) { throw new Exception(error); } int codeId = User.UserUtility.AddCode(db, CodeType.Register, randText, codeInfo, this.request.Mobile); //发送成功后记录验证码 if (codeId <= 0) { throw new Exception("验证码发送失败"); } return(new SendSMSResponseBody() { Status = ResultStatus.Success, //CheckCode = randText }); }
/// <summary> /// Initialize a new publisher client for the specified IP and port to test with /// </summary> /// <param name="topic">The name of the publisher's topic (created upon starting the publisher client)</param> private static void StartPublisherClient(string ipAddress, int port, string topic) { try { // Start the publisher client PublisherClient client = new PublisherClient(ipAddress, port); client.StartClient(); Logger.Info("Publisher client started"); // Create a topic Logger.Info("Requesting creation of topic \"" + topic + "\"..."); client.AddRequest(new CreateTopicRequest(topic)); Thread.Sleep(1000); // Give subscribers time to subscribe Logger.Info("Waiting for subscribers..."); Thread.Sleep(5000); // Publish some random-data messages to the topic Random rand = new Random(); for (int i = 0; i < 10; i++) { string message = RandomText.Substring(rand.Next(0, RandomText.Length - 21), 20); Logger.Info("Attempting to publish message: " + message); client.AddRequest(client.MakePublishRequest(client.OwnedTopics[0], message)); Thread.Sleep(rand.Next(1000, 6000)); } } catch (Exception e) { Logger.Error("Publisher client failed to start" + Environment.NewLine + e.Message); } }
private void ExecuteEvents(TimelineHandler handler) { try { foreach (var timelineEvent in handler.TimeLineEvents) { var path = GetSavePath(typeof(LightExcelHandler), handler, timelineEvent, "docx"); var list = RandomText.GetDictionary.GetDictionaryList(); var rt = new RandomText(list.ToArray()); rt.AddSentence(5); var title = rt.Content; rt.AddContentParagraphs(2, 3, 5, 7, 22); var paragraph = rt.Content; Domain.Code.Office.Word.Write(path, title, paragraph); FileListing.Add(path); this.Report(handler.HandlerType.ToString(), timelineEvent.Command, timelineEvent.CommandArgs[0].ToString()); } } catch (Exception e) { _log.Error(e); } }
public override SendEmailResponseBody ExecuteCore() { string randText = RandomText.GetNum(6); //生成6位验证码 var emailInfo = SendContentConfig.EmailRegisterDesc(randText); //组织发送内容 string error = ""; bool succ = EmailAction.SendEmail(emailInfo.Item1, emailInfo.Item2, this.request.Email, out error);//开始发送 if (!succ) { throw new Exception(error); } int codeId = User.UserUtility.AddCode(db, CodeType.Register, randText, emailInfo.Item2, this.request.Email); //发送成功后记录验证码 if (codeId <= 0) { throw new Exception("Check code send failed."); } return(new SendEmailResponseBody() { CurrentEmail = this.request.Email, Status = ResultStatus.Success, //CheckCode = randText }); }
public ActionResult GetPosts() { var text = new RandomText(); text.AddContentParagraphs(RandomGenerator.GenerateLockedRandom(1, 10), 1, RandomGenerator.GenerateLockedRandom(10, 20), RandomGenerator.GenerateLockedRandom(1, 10), RandomGenerator.GenerateLockedRandom(10, 30)); var model = new PostViewModel() { PostedOn = DateTime.Now.AddSeconds(-90), PostedBy = _defaultHelper.GetUser(User.Identity.GetUserId()), Title = new RandomText().GetNewSentence(5), Description = text.Content, Rate = RandomGenerator.GenerateLockedRandom(20, 400), PostImages = new List <ImageViewModel>() { new ImageViewModel() { ImageUrl = $"/images/postimages/image{RandomGenerator.GenerateLockedRandom(1, 14)}.jpg" } } }; return(PartialView(@"~\Views\Index\_PostDetail.cshtml", model)); }
public static MultiString MultiString() { var value = new MultiString(); value.Put("en", RandomText.Text(15, 50)); return(value); }
public static string GetRandomText() { string[] words = { "salmon", "a", "bass", "the", "lingcod", "and", "trout", "with", "rockfish", "made", "true cod", "mean", "lobster", "for", "dungeness crab", "part", "eating", "learn", "smelt", "think", "sardine", "peace", "herring", "for", "shark", "late", "anchovy", "seal" }; RandomText text = new RandomText(words); text.AddContentParagraphs(2, 2, 4, 5, 12); return text.Content; }
public void Nuget_MaxLengthTest2() { for (int i = 1; i < 1000; i++) { var actual = new RandomText(i).ToString(); //length should be greater than i char max Assert.IsTrue(actual.Length <= i); } }
// Use this for initialization void Start() { text.text = ""; randText = GetComponent <RandomText>(); talker = GameObject.FindGameObjectWithTag("Player").GetComponent <Talk>(); startColor = GetComponent <SpriteRenderer>().color; backgroundColor = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Camera>().backgroundColor; lover = GameObject.FindGameObjectWithTag("Lover").GetComponent <AppearAfterComplete>(); }
string GenerateRandomText() { string[] words = { "anemone", "wagstaff", "man", "the", "for", "and", "a", "with", "bird", "fox", "Sand", "Air", "Live", "This", "", "Private ", "sentence ", "itself", "methods ", "separated ", "words", "create " }; RandomText text = new RandomText(words); text.AddContentParagraphs(2, 2, 4, 5, 12); return(text.Content); }
public void RandomText_Success() { var encrypter = new RandomText(); var result = encrypter.CreateRandomText(); var result2 = encrypter.CreateRandomText(); Assert.AreNotEqual(result, result2); Assert.AreNotEqual(result, result2); }
public CaptchaImage(ref string s, int width, int height, int iFrom, int iTo) { s = RandomText.Generate(iFrom, iTo); this.text = s; this.bc = Color.White; this.width = width; this.height = height; this.GenerateImage(); }
public static DummyCacheObject GenerateCacheObject() { return(new DummyCacheObject { Id = NextId(), Name = "CacheObject_" + RandomText.Word(), Resource = RandomText.Stuff() + RandomText.Word() }); }
public CaptchaImage(ref string s, int width, int height, int length) { s = RandomText.Generate(length); this.text = s; this.bc = Color.LightGoldenrodYellow; this.width = width; this.height = height; this.GenerateImageAll(); }
//Methods private void Start() { randomText = gameObject.AddComponent <RandomText>(); SetUpDefaultUpgrades(); if (Application.isPlaying) { countDownScript = GameObject.Find("CountDownText").GetComponent <CountDownScript>(); } }
/// <summary> /// 获取一个验证码字串及PNG图片数据 /// </summary> /// <param name="length">验证码长度(4比较合适)</param> /// <param name="checkcode">随机生成的验证码字符串</param> /// <returns></returns> public static byte[] GetImage(int length, out string checkcode) { checkcode = RandomText.String(length); var random = new Random(); //注意,字体应该是所在操作系统中存在的字体 "Comic Sans MS" var font = new Font("Comic Sans MS", 20, FontStyle.Bold | FontStyle.Italic, GraphicsUnit.Pixel); var stringFormat = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }; using (var bitmap = new Bitmap((int)Math.Ceiling((double)(length * 18)), 27, PixelFormat.Format24bppRgb)) { using (var graphics = Graphics.FromImage(bitmap)) { graphics.Clear(Color.White); graphics.SmoothingMode = SmoothingMode.AntiAlias; graphics.TextRenderingHint = TextRenderingHint.AntiAlias; //画图片的背景噪音线 for (int i = 0; i < 5; i++) { int x1 = random.Next(bitmap.Width); int x2 = random.Next(bitmap.Width); int y1 = random.Next(bitmap.Height); int y2 = random.Next(bitmap.Height); graphics.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2); } graphics.DrawString(checkcode, font, Brushes.Black, new RectangleF(0f, 0f, (float)bitmap.Width, (float)bitmap.Height), stringFormat); //画图片的前景噪音点 for (int i = 0; i < 20; i++) { int x = random.Next(bitmap.Width); int y = random.Next(bitmap.Height); bitmap.SetPixel(x, y, Color.FromArgb(random.Next())); } } using (var bitmap2 = WaveDistortion(bitmap)) { using (var ms = new System.IO.MemoryStream()) { bitmap2.Save(ms, ImageFormat.Png); //bitmap2.Save("img.jpg"); return(ms.ToArray()); } } } }
public static GuideV1 CreateGuide() { return(new GuideV1 { Id = IdGenerator.NextLong(), Name = RandomText.Name(), Type = RandomGuideType(), App = RandomText.Phrase(1, 50), MinVer = RandomLong.NextLong(int.MaxValue), MaxVer = RandomLong.NextLong(int.MaxValue), Tags = new List <string> { RandomText.Stuff(), IdGenerator.NextLong(), RandomText.Color(), RandomText.Name(), RandomText.Phone(), RandomText.Adjective(), "tag1" }, AllTags = new List <string> { RandomText.Stuff(), RandomText.Color(), RandomText.Name(), RandomText.Phone(), RandomText.Adjective() }, Status = RandomText.Verb(), CreateTime = DateTime.UtcNow, Pages = new List <GuidePageV1> { new GuidePageV1 { Title = new Dictionary <string, string> { { IdGenerator.NextShort(), RandomText.Word() }, { IdGenerator.NextShort(), RandomText.Word() } }, Content = new Dictionary <string, string> { { IdGenerator.NextShort(), RandomText.Word() }, { IdGenerator.NextShort(), RandomText.Word() } }, Color = RandomText.Color(), PicId = IdGenerator.NextShort(), PicUri = IdGenerator.NextLong() }, new GuidePageV1 { Title = new Dictionary <string, string> { { IdGenerator.NextShort(), RandomText.Word() }, { IdGenerator.NextShort(), RandomText.Word() } }, Content = new Dictionary <string, string> { { IdGenerator.NextShort(), RandomText.Word() }, { IdGenerator.NextShort(), RandomText.Word() } }, Color = RandomText.Color(), PicId = IdGenerator.NextShort(), PicUri = IdGenerator.NextLong() } } }); }
public static string[] Tags() { var count = RandomInteger.NextInteger(0, 5); var tags = new string[count]; for (var index = 0; index < count; index++) { tags[index] = RandomText.Word().ToLower(); } return(tags); }
public async Task It_Should_Update_Guide() { // arrange var guide1 = await _client.CreateGuideAsync(null, TestModel.CreateGuide()); // act guide1.Name = RandomText.Word(); var result = await _client.UpdateGuideAsync(null, guide1); // assert Assert.NotNull(result); TestModel.AssertEqual(guide1, result); }
public static BeaconV1 CreateBeacon() { return(new BeaconV1() { Id = RandomString.NextString(10, 20), SiteId = RandomString.NextString(10, 20), Type = RandomText.Word(), Udi = RandomString.NextString(10, 20), Label = RandomText.Word(), Center = new CenterObject(RandomText.Word(), new int[] { RandomInteger.NextInteger(1, 10), RandomInteger.NextInteger(1, 10) }), Radius = RandomDouble.NextDouble(100.0) }); }
public async Task It_Should_Update_Guide() { // arrange var guide = await Invoke <GuideV1>("create_guide", new { guide = TestModel.CreateGuide(), paging = _defaultPagingParams, }); // act guide.Name = RandomText.Word(); var result = await Invoke <GuideV1>("update_guide", new { guide = guide, paging = _defaultPagingParams, }); // assert TestModel.AssertEqual(guide, result); }
public void SetCaptcha() { // Set image string s = RandomText.Generate(); // Encrypt string ens = Encryptor.Encrypt(s, "srgerg$%^bg", Convert.FromBase64String("srfjuoxp")); // Save to session Session["captcha"] = s.ToLower(); // Set url imgBtnCaptcha.ImageUrl = "CaptchaGenericHandler.ashx?w=200&h=48&c=" + ens + "&bc=" + color; }
public static BlobInfoV1 Blob() { return(new BlobInfoV1 { Id = IdGenerator.NextLong(), Group = RandomText.Name(), Name = RandomText.Name(), Size = RandomLong.NextLong(100, 100000), ContentType = RandomArray.Pick(new string[] { "text/plain", "application/binary", "application/json" }), CreateTime = DateTime.UtcNow, ExpireTime = RandomDateTime.NextDateTime(DateTime.UtcNow, new DateTime(2010, 1, 1)), Completed = RandomBoolean.NextBoolean() }); }
//private event CaptchaEventHandler success; //private event CaptchaEventHandler failure; private void SetCaptcha() { // Set image string s = RandomText.Generate(); // Encrypt string ens = Encryptor.Encrypt(s, "srgerg$%^bg", Convert.FromBase64String("srfjuoxp")); // Save to session Session["captcha"] = s.ToLower(); // Set url imgCaptcha.ImageUrl = "~/Captcha.ashx?w=305&h=92&c=" + ens + "&bc=" + color; }
void SetCaptcha(Setting setting) { string ens; string s; do { s = RandomText.Generate(); ens = Encryptor.Encrypt(s, "srgerg$%^bg", Convert.FromBase64String("srfjuoxp")); }while (CheckPermissionHttpModule.QueryStringContainsIllegalCharacters(ens)); Session["captcha"] = s.ToLower(); setting.CaptchaText = ""; setting.CaptchaImageUrl = "../HttpHandler/Captcha.ashx?w=185&h=92&c=" + ens + "&bc=" + "#ff87691"; }
//token発行 public Token CreateToken() { var token = new Token(); _randomText = new RandomText(); var tokenText = _randomText.CreateRandomText(); DateTime startTime = DateTime.UtcNow.AddHours(9); DateTime endTime = startTime.AddHours(1); token.TokenText = tokenText; token.StartTime = startTime; token.EndTime = endTime; return(token); }
public void NUGET_AddContentParagraphsTest2() { var target = new RandomText(); const int numberParagraphs = 1; const int minSentences = 4; const int maxSentences = minSentences; const int minWords = 4; const int maxWords = minWords; target.AddContentParagraphs(numberParagraphs, minSentences, maxSentences, minWords, maxWords); string actualOutput = target.ToString().Replace("\n\n", string.Empty).Trim(); int numberOfSentances = actualOutput.Split('.').Length - 1; int numberOfWords = actualOutput.Split(' ').Length / numberOfSentances; Assert.AreEqual(minSentences, numberOfSentances, "Incorrect number of sentances generated."); Assert.AreEqual(minWords, numberOfWords, "Incorrect number of words generated"); }
public void TestGetValue_WithWordCountMoreThanTextContains() { // Arrange var randomText = new RandomText { Text = "word1 word2 word3 Word4" }; randomTextRepo.Setup(rtr => rtr.GetRandom()).Returns(randomText); var columnInfo = new RandomTextColumnInfo { IsNullable = false, WordCount = 10 }; var strategy = new RandomTextColumnValueStrategy(RepoFactory); // Act string value = strategy.GetValue(columnInfo, EmptyCountry); // Assert Assert.AreEqual(randomText.Text, value); }
public void TestGetValue() { // Arrange var randomText = new RandomText { Text = "word1 word2 word3 Word4" }; randomTextRepo.Setup(rtr => rtr.GetRandom()).Returns(randomText); var columnInfo = new RandomTextColumnInfo { IsNullable = false, WordCount = 2 }; var strategy = new RandomTextColumnValueStrategy(RepoFactory); // Act string value = strategy.GetValue(columnInfo, EmptyCountry); // Assert Assert.AreEqual(2, value.Split(new char[0], StringSplitOptions.RemoveEmptyEntries).Length); }
public void TestGetValue_WithSpecifiedMaxLength() { // Arrange const int maxLength = 7; var randomText = new RandomText { Text = "word1 word2 word3 Word4" }; randomTextRepo.Setup(rtr => rtr.GetRandom()).Returns(randomText); var columnInfo = new RandomTextColumnInfo { IsNullable = false, WordCount = 3, MaxLength = maxLength }; var strategy = new RandomTextColumnValueStrategy(RepoFactory); // Act string value = strategy.GetValue(columnInfo, EmptyCountry); // Assert Assert.AreEqual(randomText.Text.Substring(0, maxLength), value); }
// Start is called before the first frame update void Start() { UserName = RandomText.NameText(); UserGender = RandomText.gender; Week = 1; Money = 500; Points = 50; Food = MaxFood; Health = MaxHealth; Level = 1; //Salary = 270; //freelancing variable tutor = 15; //end for freelancing variable healthSlider.maxValue = MaxHealth; foodSlider.maxValue = MaxFood; //Education Variable intilize IsUniversityAdmited = false; IsCollegeAdmited = false; IsUniversityGraduated = false; IsCollegeGraduated = false; CollegePeriod = 0; UniversityPeriod = 0; //end for education variable UpdateUI(); LoadGame(); setupAcademy(); if (UserName == "") { UserInfoBox.SetActive(true); } UpdateUI(); }
public IActionResult Entrance() { List <SelectListItem> items = new List <SelectListItem>() { new SelectListItem() { Text = "Select Active position", Value = "", Selected = true } }; List <SelectListItem> geoItems = posService.GetActiveGeoInfos(0)?.ConvertAll(c => new SelectListItem() { Value = c.ToString(), Text = c.Details, Selected = false }); if (geoItems != null && geoItems.Count > 0) { items.AddRange(geoItems); } ViewBag.GeoInfos = items; string randomText = RandomText.GetString(6); PushModel defaultPushModel = new PushModel() { PushMessageType = PushMessageType.NearCirlce, SourceType = SourceType.TestCreate, PositionType = PushPositionType.Near, MessageModel = new PushMessageModel() { Content = $"content-{randomText}", //ImageUrls = null, } }; return(View(defaultPushModel)); }
public void NUGET_RandomTextConstructorTest() { var target = new RandomText(); Assert.AreEqual((target.WordList.Length > 5), true, "Default Wordlist was not set correctly."); }
public void NUGET_RandomTextConstructorTest1() { string[] words = "How Now Brown Cow".Split(' '); var target = new RandomText(words); Assert.AreEqual(target.WordList.Length, words.Length, "Wordlist was not set correctly."); }
public void run(int port) { // Create and start a server and client. TcpListener server = null; TcpClient client = null; try { server = new TcpListener(IPAddress.Any, port); server.Start(); client = new TcpClient("localhost", port); // Obtain the sockets from the two ends of the connection. We are using the blocking AcceptSocket() // method here, which is OK for a test case. Socket serverSocket = server.AcceptSocket(); Socket clientSocket = client.Client; // Wrap the two ends of the connection into StringSockets StringSocket sendSocket = new StringSocket(serverSocket, new UTF8Encoding()); StringSocket receiveSocket = new StringSocket(clientSocket, new UTF8Encoding()); // This will coordinate communication between the threads of the test cases mre1 = new ManualResetEvent(false); mre2 = new ManualResetEvent(false); // Make two receive requests receiveSocket.BeginReceive(CompletedReceive1, 1); receiveSocket.BeginReceive(CompletedReceive2, 2); List<string> sentences = new List<string>(); string[] words = { "?", "wagstaff", "nicol", "the", "for", "and", "a", "with", "naruto", "fox", "23", "mao" }; for (int i = 0; i < 2; i++) { RandomText text = new RandomText(words); text.AddContentParagraphs(1, 2, 4, 200, 200); sentences.Add(text.Content); } String msg = sentences[0] + "\n" + sentences[1] + "\n"; foreach (char c in msg) { sendSocket.BeginSend(c.ToString(), (e, o) => { }, null); } // Make sure the lines were received properly. Assert.AreEqual(true, mre1.WaitOne(timeout), "Timed out waiting 1"); Assert.AreEqual(sentences[0], s1); Assert.AreEqual(1, p1); Assert.AreEqual(true, mre2.WaitOne(timeout), "Timed out waiting 2"); Assert.AreEqual(sentences[1], s2); Assert.AreEqual(2, p2); } finally { server.Stop(); client.Close(); } }
public void NUGET_RandomTextConstructorTest2() { var target = new RandomText(); Assert.IsTrue(target.WordList.ToString().Length > 0); }
public void NUGET_ParameterLessTest2() { var actual = new RandomText().ToString(); //length should be greater than 1000 char. Assert.IsTrue(actual.Length > 1000); }
public void Nuget_ParameterLessTest1() { var target = new RandomText(); var actual = target.ToString(); //length should be greater than 1000 char. Assert.IsTrue(actual.Length > 1000); }