public Response GetAll() { var response = new Response(); var harwareList = new List <Hardware>(); var config = LinksHelper.GetLinks("hardwareList"); if (config == null) { response.Status = Status.Error; response.AddErrorNotification("Configuration of hardwareList missing"); return(response); } foreach (LinkItem link in config) { var linkUrl = $"{link.Url.EnsureSlash()}hardware/get"; var responseItem = ApiClient.Get <Response>(linkUrl); if (responseItem.Status == Status.Success) { var innerResponse = (Response)responseItem.Data; response.Notifications.AddRange(innerResponse.Notifications); if (innerResponse.Status == Status.Success) { var data = ((JObject)innerResponse.Data).ToObject <Hardware>(); harwareList.Add(data); } } response.Notifications.AddRange(responseItem.Notifications); } response.Data = harwareList; return(response); }
/// <summary> /// Создать ссылку /// </summary> /// <param name="linkValue"></param> /// <param name="userId"></param> /// <returns></returns> public Link Create(string linkValue, Guid userId) { //ищем уже существующую var link = this._links.FindOneAndUpdate( l => l.Value == linkValue, Builders <Link> .Update.AddToSet(l => l.UsersIds, userId)); if (link != null) { return(link); } //если не нашли, то создаем новую ссылку var counter = this._counters.FindOneAndUpdate( c => c.Type == "links", Builders <Counter> .Update.Inc(c => c.SequenceValue, 1)); var addedLink = new Link { Value = linkValue, HitCount = 0, ShortValue = LinksHelper.GetShortValue(counter.SequenceValue), UsersIds = new List <Guid> { userId } }; this._links.InsertOne(addedLink); return(addedLink); }
public void WhenInput_IsNotValid_ExceptionIsNotThrown() { var html = @"invalid html"; var links = LinksHelper.ExtractLinks(html); links.Should().HaveCount(0); }
public void WhenInput_HasLinks_LinksAreExtracted() { var html = @"<!DOCTYPE html> <html> <body> <a href='#'></a> </body> </html> "; var links = LinksHelper.ExtractLinks(html); links.Should().HaveCount(1); links[0].Should().Be("#"); }
public void WhenInput_DoesNoHaveLinks_LinksAreExtracted() { var html = @"<!DOCTYPE html> <html> <body> <h1>This is <b>bold</b> heading</h1> <p>This is <u>underlined</u> paragraph</p> <h2>This is <i>italic</i> heading</h2> </body> </html> "; var links = LinksHelper.ExtractLinks(html); links.Should().HaveCount(0); }
// GET api/<controller> public Response Get() { var response = new Response(); _linkCollection = LinksHelper.GetLinks("links"); if (_linkCollection == null) { response.Status = Status.Error; response.AddErrorNotification("Configuration of links missing"); return(response); } var links = CacheManager.GetObjectFromCache("Links", _cacheLifecycle, GetLinksStatus); response.Data = links; return(response); }
private IList <Link> GetLinksStatus() { var links = new List <Link>(); var tasksToWait = _linkCollection.Select(link => Task.Run(() => { links.Add(LinksHelper.GetLinkStatus(link)); })).ToArray(); Task.WaitAll(tasksToWait.Where(t => t.Status == TaskStatus.Running).ToArray()); return(links.OrderBy(x => x.Name).ToList()); }
public void LinksHelper_GetShortValue() { var result = LinksHelper.GetShortValue(100); Assert.Equal("Be", result); }