Esempio n. 1
0
        public async Task Short_Url_Command_Returns_Not_Null()
        {
            SubjectUrlForAzureTable url = new SubjectUrlForAzureTable("https://www.microsoft.com/en-my/", connectionString);
            ICommand command            = new ShortUrlAzureTableCommand(url, UrlAction.Short);
            var      result             = await command.ExecuteAction();

            Assert.NotNull(result);
        }
Esempio n. 2
0
        public async Task Is_Shorting_Url_And_Write_To_Table()
        {
            var url = "https://www.microsoft.com/en-my/";
            SubjectUrlForAzureTable subjectUrl = new SubjectUrlForAzureTable(url, connectionString);
            var result = await subjectUrl.ShortenUrlAndSaveToAzureTable();

            Assert.NotNull(result);
        }
Esempio n. 3
0
        public async Task Retrieve_Long_Url_For_Given_Short_Url()
        {
            var givenUrl    = "MccLSngp";
            var expectedUrl = "https://www.microsoft.com/en-my/";
            SubjectUrlForAzureTable subjectUrl = new SubjectUrlForAzureTable(givenUrl, connectionString);
            var result = await subjectUrl.DeshortenUrlFromAzureTable();

            Assert.Equal(result, expectedUrl);
        }
Esempio n. 4
0
        public async Task <IActionResult> ShortUrl([FromBody] SubjectUrl subjectUrl)
        {
            SubjectUrlForAzureTable url = new SubjectUrlForAzureTable(subjectUrl.Url, connectionString);

            ICommand doShort    = new ShortUrlAzureTableCommand(url, UrlAction.Short);
            string   shortenUrl = await doShort.ExecuteAction();

            return(Ok(shortenUrl));
        }
Esempio n. 5
0
        public async Task Deshort_Url_Command_Gives_Correct_Value()
        {
            var givenUrl                = "MccLSngp";
            var expectedUrl             = "https://www.microsoft.com/en-my/";
            SubjectUrlForAzureTable url = new SubjectUrlForAzureTable(givenUrl, connectionString);
            ICommand command            = new ShortUrlAzureTableCommand(url, UrlAction.Deshort);
            var      result             = await command.ExecuteAction();

            Assert.Equal(result, expectedUrl);
        }
        public async Task <IActionResult> GetAndRedirectToLongUrl(string shortUrl)
        {
            SubjectUrlForAzureTable url = new SubjectUrlForAzureTable(shortUrl, connectionString);

            ICommand doDeshort    = new ShortUrlAzureTableCommand(url, UrlAction.Deshort);
            string   deshortenUrl = await doDeshort.ExecuteAction();


            return(Redirect(deshortenUrl));
        }
Esempio n. 7
0
 public ShortUrlAzureTableCommand(SubjectUrlForAzureTable url, UrlAction urlAction)
 {
     this.url       = url;
     this.urlAction = urlAction;
 }