Mercurial > altnet-hispano
changeset 232:806fd94727ce
Validación de parámetros en GUrlShortener
author | juanjose.montesdeocaarbos |
---|---|
date | Mon, 03 Oct 2011 07:50:54 -0300 |
parents | 4d05b5883eac |
children | 32e4e0e7a140 |
files | Agendas/trunk/src/Agendas.Google.Test/GUrlShortenerTest.cs Agendas/trunk/src/Agendas.Google/GUrlShortenerAdapter.cs |
diffstat | 2 files changed, 17 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/Agendas/trunk/src/Agendas.Google.Test/GUrlShortenerTest.cs Mon Sep 26 09:29:59 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Google.Test/GUrlShortenerTest.cs Mon Oct 03 07:50:54 2011 -0300 @@ -38,5 +38,14 @@ Assert.AreEqual(new Uri("http://altnethispano.org/Inicio.aspx"), response.ResponseUri); } - } + + [Test] + public void Parametros_Invalidos_En_GetShortUrl() + { + var gUrlShortener = new GUrlShortenerAdapter(); + + Assert.Throws<ArgumentException>(() => gUrlShortener.GetShortUrl(string.Empty)); + Assert.Throws<ArgumentNullException>(() => gUrlShortener.GetShortUrl(null)); + } + } }
--- a/Agendas/trunk/src/Agendas.Google/GUrlShortenerAdapter.cs Mon Sep 26 09:29:59 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Google/GUrlShortenerAdapter.cs Mon Oct 03 07:50:54 2011 -0300 @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; using System.Net; using AltNetHispano.Agendas.Configurations; @@ -15,6 +16,11 @@ public string GetShortUrl(string url) { + if (url == null) + throw new ArgumentNullException("url"); + else if (string.IsNullOrWhiteSpace(url)) + throw new ArgumentException(); + WebRequest request = WebRequest.Create(_config.UrlAPI); request.Method = WebRequestMethods.Http.Post; request.ContentType = "application/json";