public LinkDto GetLinks(ShortLinkDto shortLinkDto) { ShortLinkEntity entity = _repository.GetLinks(shortLinkDto.shortlink); return(new LinkDto() { deeplink = entity.Deeplink, webUrl = entity.WebUrl }); }
internal static ShortLinkDetailsDto CreateFromEntity(ShortLinkEntity entity) { return(new ShortLinkDetailsDto { Id = Guid.Parse(entity.RowKey), EndpointUrl = entity.EndpointUrl, ShortCode = entity.ShortCode, CreatedOn = entity.CreatedOn, ExpirationOn = entity.ExpiresOn, TotalHits = entity.TotalHits }); }
public ShortLinkEntity Insert(string deeplink, string weblink, string shortlink) { ShortLinkEntity shortLinkEntity = new ShortLinkEntity() { ShortLink = shortlink, WebUrl = weblink, Deeplink = deeplink, CreationDate = DateTime.Now, IsActive = true }; _context.ShortLinks.Add(shortLinkEntity); _context.SaveChanges(); return(shortLinkEntity); }
public ShortLinkDto GetShortLink(WebUrlDto webUrlDto) { ShortLinkEntity entity = _repository.GetByWebUrl(webUrlDto.webUrl); if (entity == null) { string shortlink = ShortLinkHelper.GenerateShortLink(); DeeplinkDto deeplinkDto = _helper.ConvertWebLinkToDeeplink(webUrlDto); entity = _repository.Insert(deeplinkDto.deeplink, webUrlDto.webUrl, shortlink); } return(new ShortLinkDto() { shortlink = entity.ShortLink }); }
public async Task ResolveShortCode_Fail_InvalidCode(string code) { // Assemble var targetEndpoint = "https://google.com"; var context = new DefaultHttpContext(); var request = context.Request; var collectorMock = new Mock <IAsyncCollector <LinkClickedMessage> >(); var entity = new ShortLinkEntity() { EndpointUrl = targetEndpoint }; var ctor = typeof(TableQuerySegment <ShortLinkEntity>) .GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic) .FirstOrDefault(c => c.GetParameters().Count() == 1); var segmentMock = ctor.Invoke(new object[] { new List <ShortLinkEntity>() { entity } }) as TableQuerySegment <ShortLinkEntity>; var tableMock = new Mock <CloudTable>(new Uri("https://hexmaster.com/account"), (TableClientConfiguration)null); tableMock.Setup(t => t.ExecuteQuerySegmentedAsync(It.IsAny <TableQuery <ShortLinkEntity> >(), It.IsAny <TableContinuationToken>())) .ReturnsAsync(segmentMock); var logger = NullLogger.Instance; // Act var result = await ResolveShortCodeFunction.ResolveShortCode(request, collectorMock.Object, tableMock.Object, code, logger); // Assert Assert.IsInstanceOf <RedirectResult>(result); var redirectResult = result as RedirectResult; Assert.AreEqual("https://app.4dn.me/", redirectResult.Url); }
public async Task <ShortLinkDetailsDto> CreateNewShortLinkAsync( string shortCode, string endpointUrl, string ownerId) { var table = await _tableFactory.GetCloudTableReferenceAsync(TableNames.ShortLinks); var shortLinkEntity = new ShortLinkEntity { PartitionKey = PartitionKeys.ShortLinks, RowKey = Guid.NewGuid().ToString(), EndpointUrl = endpointUrl, ShortCode = shortCode, CreatedOn = DateTimeOffset.UtcNow, ExpiresOn = DateTimeOffset.UtcNow.AddMonths(3), OwnerId = ownerId, TotalHits = 0, Timestamp = DateTimeOffset.UtcNow }; var tableOperation = TableOperation.Insert(shortLinkEntity); await table.ExecuteAsync(tableOperation); return(ShortLinkDetailsDto.CreateFromEntity(shortLinkEntity)); }
public ShortLinkEntity GetLinks(string shortlink) { ShortLinkEntity shortLinkEntity = _context.ShortLinks.FirstOrDefault(x => x.ShortLink == shortlink && x.IsActive); return(shortLinkEntity); }