public async Task RemoveSameTags() { var hashtagSet = new HashtagSet { Id = 1, Text = @"#earth_shotz #earth_shotz #vscobalkan #doomshots #wanderlust #creartmood #mountainaddict #agameofdrones #beatifuldestinations #drones #vscosofia #traveling #earth #agameoftones #nature #gramslayers #traveladdict #vscobulgaria #droneporn #imaginativeuniverse #visualcreative #earthfocus #shotzdelight #mybulgaria #mountains #visualambassadors #droneshots #bestvisualz #igcreative_editz", }; await this.repository.AddAsync(hashtagSet); await this.repository.SaveChangesAsync(); var hashtags = this.repository.All().FirstOrDefault(x => x.Id == 1); var randomized = this.service.Randomize(1); var tags = hashtagSet.Text.Split('#').ToList().Count; var randomizedTags = randomized.Split('#').ToList().Count; Assert.Equal(tags, randomizedTags + 1); }
public async Task DeleteByIdAsync(int id, string userId) { HashtagSet post = this.hashtagsetsRepository.All().Where(h => h.Id == id).FirstOrDefault(); this.hashtagsetsRepository.Delete(post); await this.hashtagsetsRepository.SaveChangesAsync(); }
public async Task ProperCreatingHashtagSet() { var hashtagSet = new HashtagSet { UserId = "user", Text = @"#createcommune #earth_shotz #vscobalkan #doomshots #wanderlust #creartmood #mountainaddict #agameofdrones #beatifuldestinations #drones #vscosofia #traveling #earth #agameoftones #nature #gramslayers #traveladdict #vscobulgaria #droneporn #imaginativeuniverse #visualcreative #earthfocus #shotzdelight #mybulgaria #mountains #visualambassadors #droneshots #bestvisualz #igcreative_editz", CategoryId = 1, IsPrivate = true, }; var id = await this.service.CreateAsync(hashtagSet.Text, hashtagSet.UserId, hashtagSet.CategoryId, hashtagSet.IsPrivate); await this.repository.SaveChangesAsync(); var set = await this.repository.All().FirstOrDefaultAsync(x => x.UserId == "user"); Assert.Equal(id, set.Id); }
public async Task OneHashtag() { var hashtagSet = new HashtagSet { UserId = "user2", Text = "#droneshots", }; await this.repository.AddAsync(hashtagSet); await this.repository.SaveChangesAsync(); var hashtags = this.repository.All().FirstOrDefault(x => x.UserId == "user2"); var randomized = this.service.Randomize(1); Assert.Equal(hashtagSet.Text, randomized); }
public async Task EmptyString() { var hashtagSet = new HashtagSet { UserId = "user1", Text = string.Empty, }; await this.repository.AddAsync(hashtagSet); await this.repository.SaveChangesAsync(); var set = this.repository.All().FirstOrDefault(x => x.UserId == "user1"); var randomized = this.service.Randomize(set.Id); Assert.Equal(hashtagSet.Text, randomized); }
public async Task <int> CreateAsync(string text, string userId, int categoryId, bool isPrivate) { List <string> hashtags = text.Split(new char[] { '#', '\r', '\n', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList(); for (int i = 0; i < hashtags.Count; i++) { var hashtag = this.hashtagRepository.All().FirstOrDefault(h => h.Name == hashtags[i]); if (hashtag != null) { hashtag.PostCount++; this.hashtagRepository.Update(hashtag); } else { hashtag = new Hashtag { Name = hashtags[i], PostCount = 1, }; await this.hashtagRepository.AddAsync(hashtag); } } text = string.Join(' ', hashtags.Distinct().Select(h => "#" + h.ToString())); var hashtagSet = new HashtagSet { Text = text, IsPrivate = isPrivate, UserId = userId, CategoryId = categoryId, }; await this.hashtagsetsRepository.AddAsync(hashtagSet); await this.hashtagsetsRepository.SaveChangesAsync(); return(hashtagSet.Id); }