public void Equatable_WithOtherMiniGuids_ViaEquals() { object miniGuid1 = MiniGuid.NewGuid(); object miniGuid2 = MiniGuid.NewGuid(); Assert.True(miniGuid1.Equals(miniGuid1)); Assert.False(miniGuid1.Equals(miniGuid2)); }
private static User createUser(string name, string email, UserType type) => new User { Id = MiniGuid.NewGuid(), Name = name, Email = email, UserType = type };
public void IsAlphabetical_AndOf26Chars() { for (int i = 0; i < 1000; i++) { var str = MiniGuid.NewGuid().ToString(); Assert.Matches("^[a-zA-Z]{26}$", str); } }
public void Equatable_WithNormalGuids_ViaEquals() { var miniGuid = MiniGuid.NewGuid(); object guid1 = (Guid)miniGuid; object guid2 = Guid.NewGuid(); Assert.True(miniGuid.Equals(guid1)); Assert.False(miniGuid.Equals(guid2)); }
public void AllChars_AreUsed() { var allChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".ToHashSet(); var usedChars = Enumerable.Range(0, 1000) .SelectMany(_ => MiniGuid.NewGuid().ToString()) .ToHashSet(); Assert.True(usedChars.SetEquals(allChars)); }
public void Equatable_WithOtherMiniGuids_ViaOperator() { var miniGuid1 = MiniGuid.NewGuid(); var miniGuid2 = MiniGuid.NewGuid(); Assert.True(miniGuid1 == miniGuid1); Assert.False(miniGuid1 == miniGuid2); Assert.True(miniGuid1 != miniGuid2); Assert.False(miniGuid1 != miniGuid1); }
public void Create_CreatesNoDuplicates() { var counts = Enumerable.Range(0, 1000) .Select(_ => MiniGuid.NewGuid()) .GroupBy(m => m) .Select(g => g.Count()) .ToHashSet(); Assert.Equal(new HashSet <int>(new[] { 1 }), counts); }
public void Equatable_WithString_ViaEquals() { var miniGuid = MiniGuid.NewGuid(); object str1 = miniGuid.ToString(); object str2 = MiniGuid.NewGuid().ToString(); Assert.True(miniGuid.Equals(str1)); Assert.False(miniGuid.Equals(str2)); }
public void ToString_Parse_RoundTrip() { for (int i = 0; i < 1000; i++) { var guid1 = MiniGuid.NewGuid(); var guid2 = MiniGuid.Parse(guid1.ToString()); Assert.Equal(guid1, guid2); } }
public void StringConversion_RoundTrip() { for (int i = 0; i < 100; i++) { var miniGuid1 = MiniGuid.NewGuid(); var @string = (string)miniGuid1; var miniGuid2 = (MiniGuid)@string; Assert.Equal(miniGuid1, miniGuid2); } }
public void Equatable_WithString_ViaOperator() { var miniGuid = MiniGuid.NewGuid(); var str1 = miniGuid.ToString(); var str2 = MiniGuid.NewGuid().ToString(); Assert.True(miniGuid == str1); Assert.False(miniGuid == str2); Assert.True(miniGuid != str2); Assert.False(miniGuid != str1); }
public void Equatable_WithNormalGuids_ViaOperator() { var miniGuid = MiniGuid.NewGuid(); var guid1 = (Guid)miniGuid; var guid2 = Guid.NewGuid(); Assert.True(miniGuid == guid1); Assert.False(miniGuid == guid2); Assert.True(miniGuid != guid2); Assert.False(miniGuid != guid1); }
public Person(string firstName, string lastName) { this.FirstName = firstName; this.LastName = lastName; this.Id = MiniGuid.NewGuid(); this.Parents = new List <IPerson>(); this.Children = new List <IPerson>(); this.Partners = new List <IPerson>(); }
public OauthHelper(string _serviceName, string _configFolderPath, string _authEndPoint, string _tokenEndPoint, string _clientId, string _secret, string _redirectEndPoint, string _scope = null) { ServiceName = _serviceName; ContentFolderPath = _configFolderPath; AuthReqState = MiniGuid.NewGuid(); RedirectEndPoint = _redirectEndPoint; ClientId = _clientId; AuthEndPoint = _authEndPoint; TokenEndPoint = _tokenEndPoint; Scope = _scope; ClientSecret = _secret; }
public void Serializes_ToString() { var guid = MiniGuid.NewGuid(); var json = JsonConvert.SerializeObject(new { guid }); var guidProp = JObject.Parse(json) .Property("guid"); Assert.Equal(JTokenType.String, guidProp.Value.Type); Assert.Equal(guid.ToString(), guidProp.Value.Value <string>()); }
public void SameString_AlwaysProduced() { for (int i = 0; i < 100; i++) { var miniGuid = MiniGuid.NewGuid(); var strings = Enumerable.Range(0, 100) .Select(_ => miniGuid.ToString()) .ToHashSet(); Assert.Single(strings); } }
public static string GeneatePromo() { var miniGuid = MiniGuid.NewGuid(); //implicit conversions (and vice-versa too) string someString = miniGuid; Guid someGuid = miniGuid; //explicit stringifying and parsing var str = miniGuid.ToString(); var sameMiniGuid = str.Substring(0, 5); var intGuid = codeFromCoupon(str); var PromoCode = sameMiniGuid + intGuid.ToString().Substring(0, 6); Random num = new Random(); PromoCode = new string(PromoCode.ToCharArray(). OrderBy(s => (num.Next(2) % 2) == 0).ToArray()); return(PromoCode); }
public Models.FishModels.AmazonS3Url UploadToS3(MemoryStream stream, string testName) { try { string userID = getUserID(); int anglerID = dbClass.GetAnglerID(); MiniGuid g = MiniGuid.NewGuid(); string objectKey = string.Format("imgs/{0}/{1}.jpg", anglerID.ToString(), g); PutObjectResponse response = new PutObjectResponse(); // Create S3 service client. using (IAmazonS3 s3Client = new AmazonS3Client(RegionEndpoint.USEast1)) { // Setup request for putting an object in S3. PutObjectRequest request = new PutObjectRequest { BucketName = _awsBucketName, Key = objectKey, InputStream = stream //SEND THE FILE STREAM }; //todo: change this expiration stuff to a few months. Not sure if changing it here is enough, forgot how the caching stuff worked. request.Headers.Expires = new DateTime(2020, 1, 1); //.. this shouldnt be a set date anyway... request.Headers.CacheControl = "max-age=77760000"; //..this might be the one that sets time //request.Headers["expires"] = "Thu, 01 Dec 1994 16:00:00 GMT"; response = s3Client.PutObject(request); // Make service call and get back the response. } FishModels.AmazonS3Url s3UrlObject = new Models.FishModels.AmazonS3Url(); s3UrlObject = dbClass.GeneratePreSignedURL(objectKey); return(s3UrlObject); } catch (Exception ex) { ErrorLoggingClass errorLog = new ErrorLoggingClass(); errorLog.logError(ex.Message, ex.Source, ex.StackTrace, "Upload Image", "FishController", "UploadToS3", User.Identity.Name, ""); return(null); } }
public FishModels.NewFishInfo GetNewFishInfo() { try { FishModels.NewFishInfo NewFishInfo = new FishModels.NewFishInfo(); NewFishInfo.fishID = MiniGuid.NewGuid(); //https://github.com/jasonholloway/miniguid NewFishInfo.LastSpecies = 9; //todo - fix //todo get the rest... // gps cords // species caught return(NewFishInfo); } catch (Exception ex) { error.logError(ex.Message, ex.Source, ex.StackTrace, "Enter Fish", "DatabaseClass", "getNewFishInfo", HttpContext.Current.User.Identity.Name, null); FishModels.NewFishInfo NewFishInfo = new FishModels.NewFishInfo(); return(NewFishInfo); } }
private async Task <string> Seed(IDocumentStore store) { string newId(string collection) => $"{collection}/{MiniGuid.NewGuid().ToString()}"; long now() => DateTime.Now.Ticks; long days(int nbr) => new TimeSpan(nbr, 0, 0, 0).Ticks; using (var sess = store.OpenAsyncSession()) { // Web log var webLogId = newId(Collection.WebLog); await sess.StoreAsync(new WebLog { Id = webLogId, Name = "Dos Blog", Subtitle = "Nancy in C# solution", DefaultPage = "", ThemePath = "", UrlBase = "http://*****:*****@example.com", PasswordHash = "####", FirstName = "Dos", LastName = "Admin", PreferredName = "Bob", Url = "http://localhost:5000", Authorizations = new[] { new Authorization { Level = AuthorizationLevel.Administrator, WebLogId = webLogId } } }); // Pages var aboutId = newId(Collection.Page); var aboutNow = now(); await sess.StoreAsync(new Page { Id = aboutId, WebLogId = webLogId, AuthorId = userId, Title = "About This Blog", Permalink = "/about.html", PublishedOn = aboutNow, UpdatedOn = aboutNow, ShowInPageList = true, Text = new HtmlArticleContent { Text = "This blog is written in <strong>C#</strong> using Nancy" }, Revisions = new[] { new Revision { AsOf = aboutNow, Text = new HtmlArticleContent { Text = "This blog is written in <strong>C#</strong> using Nancy" } } } }); var contactId = newId(Collection.Page); var contactNow = now(); await sess.StoreAsync(new Page { Id = contactId, WebLogId = webLogId, AuthorId = userId, Title = "Contact Me", Permalink = "/contact-me.html", PublishedOn = contactNow, UpdatedOn = contactNow, ShowInPageList = true, Text = new MarkdownArticleContent { Text = "Just **call** _(123)_ 555-1234" }, Revisions = new[] { new Revision { AsOf = contactNow, Text = new MarkdownArticleContent { Text = "Just **call** _(123)_ 555-1234" } } } }); // Posts var postNews1Id = newId(Collection.Post); var postNews1Now = now(); await sess.StoreAsync(new Post { Id = postNews1Id, WebLogId = webLogId, AuthorId = userId, Status = PostStatus.Published, Title = "Nice People on the Street", Permalink = "/2019/nice-people-on-the-street.html", PostedOn = postNews1Now - days(3), UpdatedOn = postNews1Now - days(2), Text = new MarkdownArticleContent { Text = "I couldn't _believe_ it!" }, CategoryIds = new[] { catNewsId }, Tags = new[] { "nice", "street", "unbelievable" }, Revisions = new[] { new Revision { AsOf = postNews1Now - days(3), Text = new MarkdownArticleContent { Text = "I coudln't _believe_ it!" } }, new Revision { AsOf = postNews1Now - days(2), Text = new MarkdownArticleContent { Text = "I couldn't _believe_ it!" } } } }); var postNews2Id = newId(Collection.Post); var postNews2Now = now() - days(7); var postNews2Text = "In a historic, never-before-seen circumstance, the presidential election ended in a tie. The Constitution does not provide for any sort of tie-breaker, so the Supreme Court has ruled that neither party has won. Surprisingly, the candidates believe this may be the best thing for the country; one of them was quoted as saying, \"Last month, one of my competitors called Congress a 'do-nothing Congress', and the next day, their approval rating had actually gone **up** 5 points. It's like the American people just want us to leave them alone, and they couldn't have sent a clearer message with today's results.\" Americans are generally optimistic about the next 4 years with no leader in the White House, though they remain apprehensive that, without the responsibility of actually governing, the candidates will just continue campaigning for another 4 years."; await sess.StoreAsync(new Post { Id = postNews2Id, WebLogId = webLogId, AuthorId = userId, Status = PostStatus.Published, Title = "Presidential Election Ends in Tie; Nation Named Winner", Permalink = "/2019/presidential-election-ends-in-tie-nation-named-winner.html", PostedOn = postNews2Now, UpdatedOn = postNews2Now, Text = new MarkdownArticleContent { Text = postNews2Text }, CategoryIds = new[] { catNewsId }, Tags = new[] { "candidate", "congress", "election", "president", "result" }, Revisions = new[] { new Revision { AsOf = postNews2Now, Text = new MarkdownArticleContent { Text = postNews2Text } } } }); var postSportsId = newId(Collection.Post); var postSportsNow = now() - days(10); await sess.StoreAsync(new Post { Id = postSportsId, WebLogId = webLogId, AuthorId = userId, Status = PostStatus.Published, Title = "My Team Rules", Permalink = "/2019/my-team-rules.html", PostedOn = postSportsNow, UpdatedOn = postSportsNow, Text = new HtmlArticleContent { Text = "...and your team drools!" }, CategoryIds = new[] { catSportsId }, Tags = new[] { "teams" }, Revisions = new[] { new Revision { AsOf = postSportsNow, Text = new HtmlArticleContent { Text = "...and your team drools!" } } } }); await sess.SaveChangesAsync(); } return("All done!"); }
public void ImplicitlyConverts_ToString() { string str = MiniGuid.NewGuid(); }