Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,136 @@
//
// AuthenticationHeaderValueTest.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using System.Net.Http.Headers;
namespace MonoTests.System.Net.Http.Headers
{
[TestFixture]
public class AuthenticationHeaderValueTest
{
[Test]
public void Ctor_InvalidArguments ()
{
try {
new AuthenticationHeaderValue (null);
Assert.Fail ("#1");
} catch (ArgumentException) {
}
try {
new AuthenticationHeaderValue (" ", null);
Assert.Fail ("#2");
} catch (FormatException) {
}
}
[Test]
public void Equals ()
{
var value = new AuthenticationHeaderValue ("ab");
Assert.AreEqual (value, new AuthenticationHeaderValue ("ab"), "#1");
Assert.AreEqual (value, new AuthenticationHeaderValue ("AB"), "#2");
Assert.AreNotEqual (value, new AuthenticationHeaderValue ("AA"), "#3");
value = new AuthenticationHeaderValue ("ab", "DD");
Assert.AreEqual (value, new AuthenticationHeaderValue ("Ab", "DD"), "#4");
Assert.AreNotEqual (value, new AuthenticationHeaderValue ("AB"), "#5");
Assert.AreNotEqual (value, new AuthenticationHeaderValue ("Ab", "dd"), "#6");
}
[Test]
public void Parse ()
{
var res = AuthenticationHeaderValue.Parse ("c");
Assert.AreEqual ("c", res.Scheme, "#1");
Assert.IsNull (res.Parameter, "#2");
Assert.AreEqual ("c", res.ToString (), "#3");
res = AuthenticationHeaderValue.Parse ("ss p=3 , q = \"vvv\"");
Assert.AreEqual ("ss", res.Scheme, "#11");
Assert.AreEqual ("p=3 , q = \"vvv\"", res.Parameter, "#12");
Assert.AreEqual ("ss p=3 , q = \"vvv\"", res.ToString (), "#13");
}
[Test]
public void Parse_Invalid ()
{
try {
AuthenticationHeaderValue.Parse (null);
Assert.Fail ("#1");
} catch (FormatException) {
}
try {
AuthenticationHeaderValue.Parse (" ");
Assert.Fail ("#2");
} catch (FormatException) {
}
try {
AuthenticationHeaderValue.Parse ("a;b");
Assert.Fail ("#3");
} catch (FormatException) {
}
}
[Test]
public void Properties ()
{
var value = new AuthenticationHeaderValue ("s", "p");
Assert.AreEqual ("s", value.Scheme, "#1");
Assert.AreEqual ("p", value.Parameter, "#2");
value = new AuthenticationHeaderValue ("s");
Assert.AreEqual ("s", value.Scheme, "#3");
Assert.IsNull (value.Parameter, "#4");
}
[Test]
public void TryParse ()
{
AuthenticationHeaderValue res;
Assert.IsTrue (AuthenticationHeaderValue.TryParse ("a", out res), "#1");
Assert.AreEqual ("a", res.Scheme, "#2");
Assert.IsNull (res.Parameter, "#3");
}
[Test]
public void TryParse_Invalid ()
{
AuthenticationHeaderValue res;
Assert.IsFalse (AuthenticationHeaderValue.TryParse ("", out res), "#1");
Assert.IsNull (res, "#2");
}
}
}

View File

@@ -0,0 +1,191 @@
//
// CacheControlHeaderValueTest.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using System.Net.Http.Headers;
using System.Linq;
namespace MonoTests.System.Net.Http.Headers
{
[TestFixture]
public class CacheControlHeaderValueTest
{
[Test]
public void Ctor_Default ()
{
var value = new CacheControlHeaderValue ();
Assert.AreEqual (0, value.Extensions.Count, "#1");
Assert.IsNull (value.MaxAge, "#2");
Assert.IsFalse (value.MaxStale, "#3");
Assert.IsNull (value.MaxStaleLimit, "#4");
Assert.IsNull (value.MinFresh, "#5");
Assert.IsFalse (value.MustRevalidate, "#6");
Assert.IsFalse (value.NoCache, "#7");
Assert.IsFalse (value.NoStore, "#8");
Assert.IsFalse (value.NoTransform, "#9");
Assert.IsFalse (value.OnlyIfCached, "#10");
Assert.IsFalse (value.Private, "#11");
Assert.AreEqual (0, value.PrivateHeaders.Count, "#12");
Assert.IsFalse (value.ProxyRevalidate, "#13");
Assert.IsFalse (value.Public, "#14");
Assert.IsNull (value.SharedMaxAge, "#15");
}
[Test]
public void Equals ()
{
var value = new CacheControlHeaderValue ();
Assert.AreEqual (value, new CacheControlHeaderValue (), "#1");
Assert.AreNotEqual (value, new CacheControlHeaderValue () { MustRevalidate = true }, "#2");
}
[Test]
public void Parse ()
{
var res = CacheControlHeaderValue.Parse ("audio");
Assert.AreEqual ("audio", res.Extensions.First ().Name, "#1");
Assert.IsNull (res.Extensions.First ().Value, "#2");
Assert.AreEqual ("audio", res.ToString (), "#3");
res = CacheControlHeaderValue.Parse (null);
Assert.IsNull (res, "#4");
res = CacheControlHeaderValue.Parse ("no-cache, no-store , max-age = 44, max-stale = 66, min-fresh=333 ,no-transform, only-if-cached");
Assert.IsTrue (res.NoCache, "#10");
Assert.IsTrue (res.NoStore, "#11");
Assert.AreEqual (new TimeSpan (0, 0, 44), res.MaxAge, "#12");
Assert.IsTrue (res.MaxStale, "#13");
Assert.AreEqual (new TimeSpan (0, 1, 6), res.MaxStaleLimit, "#14");
Assert.AreEqual (new TimeSpan (0, 5, 33), res.MinFresh, "#15");
Assert.IsTrue (res.NoTransform, "#16");
Assert.IsTrue (res.OnlyIfCached, "#17");
Assert.AreEqual ("no-store, no-transform, only-if-cached, no-cache, max-age=44, max-stale=66, min-fresh=333", res.ToString (), "#18");
res = CacheControlHeaderValue.Parse ("anu = 333");
Assert.AreEqual ("anu", res.Extensions.First ().Name, "#20");
Assert.AreEqual ("333", res.Extensions.First ().Value, "#21");
Assert.AreEqual ("anu=333", res.ToString (), "#22");
res = CacheControlHeaderValue.Parse ("public, private = \"nnn \", no-cache =\"mmm\" , must-revalidate, proxy-revalidate, s-maxage=443");
Assert.IsTrue (res.Public, "#30");
Assert.IsTrue (res.Private, "#31");
Assert.AreEqual ("nnn", res.PrivateHeaders.First (), "#32");
Assert.IsTrue (res.NoCache, "#33");
Assert.AreEqual ("mmm", res.NoCacheHeaders.First (), "#34");
Assert.IsTrue (res.MustRevalidate, "#35");
Assert.IsTrue (res.ProxyRevalidate, "#36");
Assert.AreEqual (new TimeSpan (0, 7, 23), res.SharedMaxAge, "#37");
Assert.AreEqual ("public, must-revalidate, proxy-revalidate, no-cache=\"mmm\", s-maxage=443, private=\"nnn\"", res.ToString (), "#38");
res = CacheControlHeaderValue.Parse ("private = \"nnn , oo, xx\", bb= \" x \"");
Assert.IsTrue (res.Private, "#40");
Assert.AreEqual (3, res.PrivateHeaders.Count, "#41");
Assert.AreEqual ("oo", res.PrivateHeaders.ToList ()[1], "#42");
Assert.AreEqual ("\" x \"", res.Extensions.First ().Value, "#43");
Assert.AreEqual ("private=\"nnn, oo, xx\", bb=\" x \"", res.ToString (), "#44");
}
[Test]
public void Parse_Invalid ()
{
try {
CacheControlHeaderValue.Parse ("audio/");
Assert.Fail ("#1");
} catch (FormatException) {
}
try {
CacheControlHeaderValue.Parse ("max-age=");
Assert.Fail ("#2");
} catch (FormatException) {
}
try {
CacheControlHeaderValue.Parse ("me=");
Assert.Fail ("#3");
} catch (FormatException) {
}
}
[Test]
public void Properties ()
{
var value = new CacheControlHeaderValue () {
MaxAge = TimeSpan.MaxValue,
MaxStale = true,
MaxStaleLimit = TimeSpan.Zero,
MinFresh = TimeSpan.MinValue,
MustRevalidate = true,
NoCache = true,
NoStore = true,
NoTransform = true,
OnlyIfCached = true,
Private = true,
ProxyRevalidate = true,
Public = true,
SharedMaxAge = TimeSpan.MaxValue
};
Assert.AreEqual (0, value.Extensions.Count, "#1");
Assert.AreEqual (TimeSpan.MaxValue, value.MaxAge, "#2");
Assert.IsTrue (value.MaxStale, "#3");
Assert.AreEqual (TimeSpan.Zero, value.MaxStaleLimit, "#4");
Assert.AreEqual (TimeSpan.MinValue, value.MinFresh, "#5");
Assert.IsTrue (value.MustRevalidate, "#6");
Assert.IsTrue (value.NoCache, "#7");
Assert.IsTrue (value.NoStore, "#8");
Assert.IsTrue (value.NoTransform, "#9");
Assert.IsTrue (value.OnlyIfCached, "#10");
Assert.IsTrue (value.Private, "#11");
Assert.AreEqual (0, value.PrivateHeaders.Count, "#12");
Assert.IsTrue (value.ProxyRevalidate, "#13");
Assert.IsTrue (value.Public, "#14");
Assert.AreEqual (TimeSpan.MaxValue, value.SharedMaxAge, "#15");
}
[Test]
public void TryParse ()
{
CacheControlHeaderValue res;
Assert.IsTrue (CacheControlHeaderValue.TryParse ("*", out res), "#1");
Assert.AreEqual (1, res.Extensions.Count, "#2");
}
[Test]
public void TryParse_Invalid ()
{
MediaTypeWithQualityHeaderValue res;
Assert.IsFalse (MediaTypeWithQualityHeaderValue.TryParse ("", out res), "#1");
Assert.IsNull (res, "#2");
}
}
}

View File

@@ -0,0 +1,272 @@
//
// ContentDispositionHeaderValueTest.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using System.Net.Http.Headers;
using System.Linq;
namespace MonoTests.System.Net.Http.Headers
{
[TestFixture]
public class ContentDispositionHeaderValueTest
{
[Test]
public void Ctor_InvalidArguments ()
{
try {
new ContentDispositionHeaderValue (null);
Assert.Fail ("#1");
} catch (ArgumentException) {
}
try {
new ContentDispositionHeaderValue (" ");
Assert.Fail ("#2");
} catch (FormatException) {
}
}
[Test]
/*
* This fails on Windows with the .NET runtime:
*
* Test Case Failures:
* 1) MonoTests.System.Net.Http.Headers.ContentDispositionHeaderValueTest.Equals : System.NullReferenceException : Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
* bei System.Net.Http.Headers.ContentDispositionHeaderValue.set_Size(Nullable`1 value)
* bei MonoTests.System.Net.Http.Headers.ContentDispositionHeaderValueTest.Equals()
*
*/
[Category ("NotWorking")]
public void Equals ()
{
var value = new ContentDispositionHeaderValue ("x");
Assert.AreEqual (value, new ContentDispositionHeaderValue ("x"), "#1");
Assert.AreNotEqual (value, new ContentDispositionHeaderValue ("y"), "#2");
value = new ContentDispositionHeaderValue ("attachment");
value.Parameters.Add (new NameValueHeaderValue ("size", "66"));
Assert.AreEqual (value, new ContentDispositionHeaderValue ("attachment") { Size = 66 }, "#3");
Assert.AreNotEqual (value, new ContentDispositionHeaderValue ("attachment"), "#4");
Assert.AreNotEqual (value, new ContentDispositionHeaderValue ("attachment") { FileName="g" }, "#5");
}
[Test]
public void Parse ()
{
var res = ContentDispositionHeaderValue.Parse ("attachment");
Assert.AreEqual ("attachment", res.DispositionType, "#1");
Assert.AreEqual ("attachment", res.ToString (), "#2");
res = ContentDispositionHeaderValue.Parse ("attachmen;filename=foo;size=44; name=n2; filename*=UTF-8''Na%C3%AFve%20file.txt; creation-date=\"Wed, 02 Oct 2002 15:00:00 +0200\";modification-date=\"Wed, 02 Oct 2002 13:00:00 GMT\";read-date=\"Wed, 02 Oct 2002 15:00:00 +0000\";other=1");
Assert.AreEqual (new DateTimeOffset (2002, 10, 2, 15, 0, 0, TimeSpan.FromHours (2)), res.CreationDate, "#10");
Assert.AreEqual ("attachmen", res.DispositionType, "#11");
Assert.AreEqual ("foo", res.FileName, "#12");
Assert.AreEqual ("NaĂŻve file.txt", res.FileNameStar, "#13");
Assert.AreEqual (new DateTimeOffset (2002, 10, 2, 13, 0, 0, TimeSpan.Zero), res.ModificationDate, "#14");
Assert.AreEqual ("n2", res.Name, "#15");
Assert.AreEqual (8, res.Parameters.Count, "#16");
Assert.AreEqual (new DateTimeOffset (2002, 10, 2, 15, 0, 0, TimeSpan.Zero), res.ReadDate, "#17");
Assert.AreEqual (44, res.Size, "#18");
Assert.AreEqual ("attachmen; filename=foo; size=44; name=n2; filename*=UTF-8''Na%C3%AFve%20file.txt; creation-date=\"Wed, 02 Oct 2002 15:00:00 +0200\"; modification-date=\"Wed, 02 Oct 2002 13:00:00 GMT\"; read-date=\"Wed, 02 Oct 2002 15:00:00 +0000\"; other=1", res.ToString (), "#19");
res = ContentDispositionHeaderValue.Parse ("attachment; filename='foo.bar'");
Assert.AreEqual ("attachment", res.DispositionType, "#21");
Assert.AreEqual ("'foo.bar'", res.FileName, "#22");
Assert.AreEqual ("attachment; filename='foo.bar'", res.ToString (), "#23");
ContentDispositionHeaderValue.Parse ("aa;size=a4");
res = ContentDispositionHeaderValue.Parse ("att;filename=\"=?utf-8?B?xI0=?=\"");
Assert.AreEqual ("ÄŤ", res.FileName, "#31");
Assert.IsNull (res.FileNameStar, "#32");
res = ContentDispositionHeaderValue.Parse ("att;filename=\"=?utf-?B?xI0=?=\"");
Assert.AreEqual ("\"=?utf-?B?xI0=?=\"", res.FileName, "#41");
res = ContentDispositionHeaderValue.Parse ("att;filename=\"=?utf-16?b?xI0=?=\"");
Assert.AreEqual ("č·„", res.FileName, "#51");
res = ContentDispositionHeaderValue.Parse ("att;filename=\"=?utf-8?B?x/I0=?=\"");
Assert.AreEqual ("\"=?utf-8?B?x/I0=?=\"", res.FileName, "#61");
res = ContentDispositionHeaderValue.Parse ("att;filename*=utf-8''%C4%8Eas");
Assert.AreEqual ("ÄŽas", res.FileNameStar, "#71");
res = ContentDispositionHeaderValue.Parse ("att;filename*=btf-8''%C4%8E");
Assert.IsNull (res.FileNameStar, "#72");
res = ContentDispositionHeaderValue.Parse ("att;filename*=utf-8''%T4%8O%");
Assert.AreEqual ("%T4%8O%", res.FileNameStar, "#73");
}
[Test]
public void Parse_Invalid ()
{
try {
ContentDispositionHeaderValue.Parse (null);
Assert.Fail ("#1");
} catch (FormatException) {
}
try {
ContentDispositionHeaderValue.Parse (" ");
Assert.Fail ("#2");
} catch (FormatException) {
}
try {
ContentDispositionHeaderValue.Parse ("attachment; filename=foo.html ;");
Assert.Fail ("#3");
} catch (FormatException) {
}
try {
ContentDispositionHeaderValue.Parse ("attachment; filename=foo bar.html");
Assert.Fail ("#4");
} catch (FormatException) {
}
try {
ContentDispositionHeaderValue.Parse ("\"attachment\"");
Assert.Fail ("#5");
} catch (FormatException) {
}
try {
ContentDispositionHeaderValue.Parse ("att;filename*=utf-8''%T4%8â•—");
Assert.Fail ("#6");
} catch (FormatException) {
}
}
[Test]
public void Properties ()
{
var value = new ContentDispositionHeaderValue ("ttt");
Assert.IsNull (value.CreationDate, "#1");
Assert.AreEqual ("ttt", value.DispositionType, "#2");
Assert.IsNull (value.FileName, "#3");
Assert.IsNull (value.FileNameStar, "#4");
Assert.IsNull (value.ModificationDate, "#5");
Assert.IsNull (value.Name, "#6");
Assert.AreEqual (0, value.Parameters.Count, "#7");
Assert.IsNull (value.ReadDate, "#8");
Assert.IsNull (value.Size, "#9");
value.Parameters.Add (new NameValueHeaderValue ("creation-date", "\"20 Jun 82 11:34:11\""));
value.Parameters.Add (new NameValueHeaderValue ("filename", "g*"));
value.Parameters.Add (new NameValueHeaderValue ("filename*", "ag*"));
value.Parameters.Add (new NameValueHeaderValue ("modification-date", "\"20 Jun 22 4:6:22\""));
value.Parameters.Add (new NameValueHeaderValue ("name", "nnn"));
value.Parameters.Add (new NameValueHeaderValue ("read-date", "\"1 Jun 01 1:1:1\""));
value.Parameters.Add (new NameValueHeaderValue ("size", "5"));
Assert.AreEqual (new DateTimeOffset (1982, 6, 20, 11, 34, 11, TimeSpan.Zero), value.CreationDate, "#11");
Assert.AreEqual ("g*", value.FileName, "#12");
Assert.IsNull (value.FileNameStar, "#13");
Assert.AreEqual (new DateTimeOffset (2022, 6, 20, 4, 6, 22, TimeSpan.Zero), value.ModificationDate, "#14");
Assert.AreEqual ("nnn", value.Name, "#15");
Assert.AreEqual (new DateTimeOffset (2001, 6, 1, 1, 1, 1, TimeSpan.Zero), value.ReadDate, "#16");
Assert.AreEqual (5, value.Size, "#17");
}
[Test]
public void Properties_FileName ()
{
var value = new ContentDispositionHeaderValue ("a");
value.FileName = "aa";
Assert.AreEqual ("aa", value.FileName, "#1");
Assert.AreEqual (new NameValueHeaderValue ("filename", "aa"), value.Parameters.First (), "#2");
value.FileName = "ÄŤ";
Assert.AreEqual ("ÄŤ", value.FileName, "#11");
Assert.AreEqual (new NameValueHeaderValue ("filename", "\"=?utf-8?B?xI0=?=\""), value.Parameters.First (), "#12");
value.FileName = "(@)";
Assert.AreEqual ("\"(@)\"", value.FileName, "#21");
Assert.AreEqual (new NameValueHeaderValue ("filename", "\"(@)\""), value.Parameters.First (), "#22");
}
[Test]
public void Properties_FileNameStar ()
{
var value = new ContentDispositionHeaderValue ("a");
value.FileNameStar = "aa";
Assert.AreEqual ("aa", value.FileNameStar, "#1");
Assert.AreEqual (new NameValueHeaderValue ("filename*", "utf-8''aa"), value.Parameters.First (), "#2");
value.FileNameStar = "ÄŤ";
Assert.AreEqual ("ÄŤ", value.FileNameStar, "#11");
Assert.AreEqual (new NameValueHeaderValue ("filename*", "utf-8''%C4%8D"), value.Parameters.First (), "#12");
}
[Test]
public void Properties_ModificationDate ()
{
var value = new ContentDispositionHeaderValue ("a");
value.ModificationDate = new DateTimeOffset (2010, 12, 30, 22, 34, 2, TimeSpan.Zero); //.FromHours (-3));
Assert.AreEqual (new DateTimeOffset (2010, 12, 30, 22, 34, 2, TimeSpan.Zero), value.ModificationDate, "#1");
Assert.AreEqual (new NameValueHeaderValue ("modification-date", "\"Thu, 30 Dec 2010 22:34:02 GMT\""), value.Parameters.First (), "#2");
}
[Test]
public void Properties_Invalid ()
{
var value = new ContentDispositionHeaderValue ("a");
try {
value.Size = -9;
Assert.Fail ("#1");
} catch (ArgumentOutOfRangeException) {
}
}
[Test]
public void TryParse ()
{
ContentDispositionHeaderValue res;
Assert.IsTrue (ContentDispositionHeaderValue.TryParse ("attachment; filename*0*=ISO-8859-15''euro-sign%3d%a4; filename*=ISO-8859-1''currency-sign%3d%a4", out res), "#1");
Assert.AreEqual ("attachment", res.DispositionType, "#2");
Assert.AreEqual ("currency-sign=¤", res.FileNameStar, "#3");
}
[Test]
public void TryParse_Invalid ()
{
ContentDispositionHeaderValue res;
Assert.IsFalse (ContentDispositionHeaderValue.TryParse ("", out res), "#1");
Assert.IsNull (res, "#2");
}
}
}

View File

@@ -0,0 +1,172 @@
//
// ContentRangeHeaderValueTest.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using System.Net.Http.Headers;
namespace MonoTests.System.Net.Http.Headers
{
[TestFixture]
public class ContentRangeHeaderValueTest
{
[Test]
public void Ctor_InvalidArguments ()
{
try {
new ContentRangeHeaderValue (-1);
Assert.Fail ("#1");
} catch (ArgumentOutOfRangeException) {
}
try {
new ContentRangeHeaderValue (10, 5);
Assert.Fail ("#2");
} catch (ArgumentOutOfRangeException) {
}
try {
new ContentRangeHeaderValue (0, 1, 0);
Assert.Fail ("#3");
} catch (ArgumentOutOfRangeException) {
}
try {
new ContentRangeHeaderValue (-1, 15);
Assert.Fail ("#4");
} catch (ArgumentOutOfRangeException) {
}
}
[Test]
public void Equals ()
{
var value = new ContentRangeHeaderValue (8);
Assert.AreEqual (value, new ContentRangeHeaderValue (8), "#1");
Assert.AreNotEqual (value, new ContentRangeHeaderValue (8, 30), "#2");
value = new ContentRangeHeaderValue (5, 30, 100);
Assert.AreEqual (value, new ContentRangeHeaderValue (5, 30, 100), "#3");
Assert.AreNotEqual (value, new ContentRangeHeaderValue (5, 30, 101), "#4");
Assert.AreNotEqual (value, new ContentRangeHeaderValue (5, 30), "#5");
Assert.AreNotEqual (value, new ContentRangeHeaderValue (5, 30, 100) {
Unit = "g"
}, "#6");
}
[Test]
public void Parse ()
{
var res = ContentRangeHeaderValue.Parse ("bytes 0 - 499/ 1234");
Assert.AreEqual (0, res.From, "#1");
Assert.AreEqual (499, res.To, "#2");
Assert.AreEqual (1234, res.Length, "#3");
Assert.AreEqual ("bytes 0-499/1234", res.ToString (), "#4");
res = ContentRangeHeaderValue.Parse ("bytes */ 8");
Assert.IsNull (res.From, "#11");
Assert.IsNull (res.To, "#12");
Assert.AreEqual (8, res.Length, "#13");
Assert.AreEqual ("bytes */8", res.ToString (), "#14");
res = ContentRangeHeaderValue.Parse ("by */*");
Assert.IsNull (res.From, "#21");
Assert.IsNull (res.To, "#22");
Assert.IsNull (res.Length, "#23");
Assert.AreEqual ("by */*", res.ToString (), "#24");
}
[Test]
public void Parse_Invalid ()
{
try {
ContentRangeHeaderValue.Parse (null);
Assert.Fail ("#1");
} catch (FormatException) {
}
try {
ContentRangeHeaderValue.Parse (" ");
Assert.Fail ("#2");
} catch (FormatException) {
}
try {
ContentRangeHeaderValue.Parse ("a b");
Assert.Fail ("#3");
} catch (FormatException) {
}
try {
ContentRangeHeaderValue.Parse ("bytes 10/");
Assert.Fail ("#4");
} catch (FormatException) {
}
}
[Test]
public void Properties ()
{
var value = new ContentRangeHeaderValue (4);
Assert.IsNull (value.From, "#1");
Assert.IsTrue (value.HasLength, "#2");
Assert.IsFalse (value.HasRange, "#3");
Assert.AreEqual (4, value.Length, "#4");
Assert.IsNull (value.To, "#5");
Assert.AreEqual ("bytes", value.Unit, "#6");
value = new ContentRangeHeaderValue (1, 10, 20);
value.Unit = "mu";
Assert.AreEqual (1, value.From, "#11");
Assert.IsTrue (value.HasLength, "#12");
Assert.IsTrue (value.HasRange, "#13");
Assert.AreEqual (20, value.Length, "#14");
Assert.AreEqual (10, value.To, "#15");
Assert.AreEqual ("mu", value.Unit, "#16");
}
[Test]
public void TryParse ()
{
ContentRangeHeaderValue res;
Assert.IsTrue (ContentRangeHeaderValue.TryParse ("b 1-10/*", out res), "#1");
Assert.AreEqual (1, res.From, "#2");
Assert.AreEqual (10, res.To, "#3");
}
[Test]
public void TryParse_Invalid ()
{
ContentRangeHeaderValue res;
Assert.IsFalse (ContentRangeHeaderValue.TryParse ("", out res), "#1");
Assert.IsNull (res, "#2");
}
}
}

View File

@@ -0,0 +1,129 @@
//
// EntityTagHeaderValueTest.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using System.Net.Http.Headers;
namespace MonoTests.System.Net.Http.Headers
{
[TestFixture]
public class EntityTagHeaderValueTest
{
[Test]
public void Ctor_InvalidArguments ()
{
try {
new EntityTagHeaderValue (null);
Assert.Fail ("#1");
} catch (ArgumentException) {
}
try {
new EntityTagHeaderValue ("a");
Assert.Fail ("#2");
} catch (FormatException) {
}
}
[Test]
public void Equals ()
{
var tfhv = new EntityTagHeaderValue ("\"abc\"");
Assert.AreEqual (tfhv, new EntityTagHeaderValue ("\"abc\""), "#1");
Assert.AreNotEqual (tfhv, new EntityTagHeaderValue ("\"AbC\""), "#2");
Assert.AreNotEqual (tfhv, new EntityTagHeaderValue ("\"AA\""), "#3");
}
[Test]
public void Parse ()
{
var res = EntityTagHeaderValue.Parse ("\"c\"");
Assert.AreEqual ("\"c\"", res.Tag, "#1");
Assert.IsFalse (res.IsWeak, "#2");
Assert.AreEqual ("\"c\"", res.ToString (), "#3");
res = EntityTagHeaderValue.Parse ("W/ \"mm\"");
Assert.AreEqual ("\"mm\"", res.Tag, "#11");
Assert.IsTrue (res.IsWeak, "#12");
Assert.AreEqual ("W/\"mm\"", res.ToString (), "#13");
}
[Test]
public void Parse_Invalid ()
{
try {
EntityTagHeaderValue.Parse (null);
Assert.Fail ("#1");
} catch (FormatException) {
}
try {
EntityTagHeaderValue.Parse (" ");
Assert.Fail ("#2");
} catch (FormatException) {
}
try {
EntityTagHeaderValue.Parse ("W / \"a\"");
Assert.Fail ("#3");
} catch (FormatException) {
}
}
[Test]
public void Properties ()
{
var etv = new EntityTagHeaderValue ("\"tag\"", true);
Assert.AreEqual ("\"tag\"", etv.Tag, "#1");
Assert.IsTrue (etv.IsWeak, "#2");
Assert.AreEqual ("*", EntityTagHeaderValue.Any.Tag, "#3");
Assert.IsFalse (EntityTagHeaderValue.Any.IsWeak, "#4");
}
[Test]
public void TryParse ()
{
EntityTagHeaderValue res;
Assert.IsTrue (EntityTagHeaderValue.TryParse ("\"\"", out res), "#1");
Assert.AreEqual ("\"\"", res.Tag, "#2");
}
[Test]
public void TryParse_Invalid ()
{
EntityTagHeaderValue res;
Assert.IsFalse (EntityTagHeaderValue.TryParse ("", out res), "#1");
Assert.IsNull (res, "#2");
}
}
}

View File

@@ -0,0 +1,95 @@
//
// HttpHeaderValueCollectionTest.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using System.Net.Http.Headers;
using System.Net.Http;
using System.Linq;
namespace MonoTests.System.Net.Http.Headers
{
[TestFixture]
public class HttpHeaderValueCollectionTest
{
[Test]
public void ParseAdd ()
{
HttpRequestMessage message = new HttpRequestMessage ();
HttpRequestHeaders headers = message.Headers;
headers.TE.ParseAdd ("pp");
Assert.AreEqual ("pp", headers.TE.ToArray ()[0].Value, "#1");
Assert.AreEqual (1, headers.TE.Count);
}
[Test]
public void ParseAdd_Invalid ()
{
HttpRequestMessage message = new HttpRequestMessage ();
HttpRequestHeaders headers = message.Headers;
try {
headers.Via.ParseAdd ("pp");
} catch (FormatException) {
}
}
[Test]
public void TryParseAdd ()
{
HttpRequestMessage message = new HttpRequestMessage ();
HttpRequestHeaders headers = message.Headers;
Assert.IsTrue (headers.TE.TryParseAdd ("pp"), "#1");
Assert.AreEqual ("pp", headers.TE.ToArray ()[0].Value, "#2");
Assert.AreEqual (1, headers.TE.Count, "#3");
Assert.IsFalse (headers.Via.TryParseAdd ("wrong"), "#4");
}
[Test]
public void ToStringTest ()
{
HttpRequestMessage message = new HttpRequestMessage ();
HttpRequestHeaders headers = message.Headers;
Assert.AreEqual ("", headers.Connection.ToString (), "#1");
headers.Connection.Add ("kk");
Assert.AreEqual ("kk", headers.Connection.ToString (), "#2");
headers.Connection.Add ("ttt");
Assert.AreEqual ("kk, ttt", headers.Connection.ToString (), "#3");
}
}
}

View File

@@ -0,0 +1,151 @@
//
// HttpHeadersTest.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using System.Net.Http.Headers;
using System.Linq;
namespace MonoTests.System.Net.Http.Headers
{
[TestFixture]
public class HttpHeadersTest
{
HttpHeaders headers;
class HttpHeadersMock : HttpHeaders
{
}
[SetUp]
public void Setup ()
{
headers = new HttpHeadersMock ();
}
[Test]
public void Add ()
{
headers.Add ("aa", "value");
headers.Add ("aa", "value");
headers.Add ("Expires", (string) null);
}
[Test]
public void Add_InvalidArguments ()
{
try {
headers.Add (null, "value");
Assert.Fail ("#1");
} catch (ArgumentException) {
}
try {
headers.Add ("", "value");
Assert.Fail ("#2");
} catch (ArgumentException) {
}
}
[Test]
public void Clear ()
{
headers.Add ("aa", "value");
headers.Clear ();
}
[Test]
public void GetEnumerator ()
{
headers.Add ("aa", "value");
int i = 0;
foreach (var entry in headers) {
++i;
Assert.AreEqual ("aa", entry.Key);
var values = entry.Value.ToList ();
Assert.AreEqual (1, values.Count);
Assert.AreEqual ("value", values[0]);
}
Assert.AreEqual (1, i, "#10");
}
[Test]
public void GetValues ()
{
headers.Add ("aa", "v");
headers.Add ("aa", "v");
var r = headers.GetValues ("aa").ToList ();
Assert.AreEqual ("v", r[0], "#1");
Assert.AreEqual ("v", r[1], "#2");
}
[Test]
public void GetValues_Invalid ()
{
try {
headers.GetValues (null);
Assert.Fail ("#1");
} catch (ArgumentException) {
}
try {
headers.GetValues (" ");
Assert.Fail ("#2");
} catch (FormatException) {
}
try {
headers.GetValues ("x");
Assert.Fail ("#3");
} catch (InvalidOperationException) {
}
}
[Test]
public void TryGetValuesTest ()
{
IEnumerable<string> headerValues;
Assert.IsFalse (headers.TryGetValues (null, out headerValues), "#1");
Assert.IsFalse (headers.TryGetValues ("some-name", out headerValues), "#2");
}
[Test]
public void ToStringTest ()
{
headers.Add ("aa", "v");
headers.Add ("aa", "v");
headers.Add ("x", "v");
Assert.AreEqual ("aa: v, v\r\nx: v\r\n", headers.ToString ());
}
}
}

View File

@@ -0,0 +1,159 @@
//
// MediaTypeHeaderValueTest.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using System.Net.Http.Headers;
namespace MonoTests.System.Net.Http.Headers
{
[TestFixture]
public class MediaTypeHeaderValueTest
{
[Test]
public void Ctor_InvalidArguments ()
{
try {
new MediaTypeHeaderValue (null);
Assert.Fail ("#1");
} catch (ArgumentException) {
}
try {
new MediaTypeHeaderValue (" ");
Assert.Fail ("#2");
} catch (FormatException) {
}
}
[Test]
public void Equals ()
{
var value = new MediaTypeHeaderValue ("multipart/*");
Assert.AreEqual (value, new MediaTypeHeaderValue ("multipart/*"), "#1");
Assert.AreEqual (value, new MediaTypeHeaderValue ("Multipart/*"), "#2");
Assert.AreNotEqual (value, new MediaTypeHeaderValue ("multipart/A"), "#3");
value.CharSet = "chs";
Assert.AreNotEqual (value, new MediaTypeHeaderValue ("multipart/*"), "#5");
var custom_param = new MediaTypeHeaderValue ("Multipart/*");
custom_param.Parameters.Add (new NameValueHeaderValue ("Charset", "chs"));
Assert.AreEqual (value, custom_param, "#6");
}
[Test]
public void Parse ()
{
var res = MediaTypeHeaderValue.Parse ("multipart / b* ");
Assert.AreEqual ("multipart/b*", res.MediaType, "#1");
Assert.IsNull (res.CharSet, "#1b");
Assert.AreEqual ("multipart/b*", res.ToString (), "#1c");
res = MediaTypeHeaderValue.Parse ("mu / m; CHarset=jj' ");
Assert.AreEqual ("mu/m", res.MediaType, "#2");
Assert.AreEqual ("jj'", res.CharSet, "#2b");
Assert.AreEqual ("mu/m; CHarset=jj'", res.ToString (), "#2c");
}
[Test]
public void Parse_Invalid ()
{
try {
MediaTypeHeaderValue.Parse (null);
Assert.Fail ("#1");
} catch (FormatException) {
}
try {
MediaTypeHeaderValue.Parse (" ");
Assert.Fail ("#2");
} catch (FormatException) {
}
try {
MediaTypeHeaderValue.Parse ("a;b");
Assert.Fail ("#3");
} catch (FormatException) {
}
}
[Test]
public void Properties ()
{
var value = new MediaTypeHeaderValue ("multipart/*");
Assert.AreEqual ("multipart/*", value.MediaType, "#1");
Assert.IsNull (value.CharSet, "#2");
Assert.AreEqual (0, value.Parameters.Count, "#3");
value.CharSet = "chs";
Assert.AreEqual ("chs", value.CharSet, "#4");
value = new MediaTypeHeaderValue ("multipart/*");
value.Parameters.Add (new NameValueHeaderValue ("CHarSEt", "te-va"));
Assert.AreEqual ("te-va", value.CharSet, "#5");
}
[Test]
public void Properties_Invalid ()
{
var value = new MediaTypeHeaderValue ("multipart/*");
try {
value.CharSet = ";;";
Assert.Fail ("#1");
} catch (FormatException) {
}
try {
value.MediaType = null;
Assert.Fail ("#2");
} catch (ArgumentException) {
}
}
[Test]
public void TryParse ()
{
MediaTypeHeaderValue res;
Assert.IsTrue (MediaTypeHeaderValue.TryParse ("multipart/*", out res), "#1");
Assert.AreEqual ("multipart/*", res.MediaType, "#2");
Assert.IsNull (res.CharSet, "#3");
}
[Test]
public void TryParse_Invalid ()
{
MediaTypeHeaderValue res;
Assert.IsFalse (MediaTypeHeaderValue.TryParse ("", out res), "#1");
Assert.IsNull (res, "#2");
}
}
}

View File

@@ -0,0 +1,136 @@
//
// MediaTypeWithQualityHeaderValueTest.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using System.Net.Http.Headers;
using System.Linq;
namespace MonoTests.System.Net.Http.Headers
{
[TestFixture]
public class MediaTypeWithQualityHeaderValueTest
{
[Test]
public void Ctor_InvalidArguments ()
{
try {
new MediaTypeWithQualityHeaderValue (null);
Assert.Fail ("#1");
} catch (ArgumentException) {
}
try {
new MediaTypeWithQualityHeaderValue ("audio/", 0.1);
Assert.Fail ("#2");
} catch (FormatException) {
}
try {
new MediaTypeWithQualityHeaderValue ("audio/*", 2);
Assert.Fail ("#3");
} catch (ArgumentOutOfRangeException) {
}
}
[Test]
public void Equals ()
{
var value = new MediaTypeWithQualityHeaderValue ("audio/x");
Assert.AreEqual (value, new MediaTypeWithQualityHeaderValue ("audio/x"), "#1");
Assert.AreEqual (value, new MediaTypeWithQualityHeaderValue ("aUdio/X"), "#2");
Assert.AreNotEqual (value, new MediaTypeWithQualityHeaderValue ("audio/y"), "#3");
value = new MediaTypeWithQualityHeaderValue ("audio/x", 0.3);
Assert.AreEqual (value, new MediaTypeWithQualityHeaderValue ("audio/x", 0.3), "#4");
Assert.AreNotEqual (value, new MediaTypeWithQualityHeaderValue ("audio/x"), "#5");
Assert.AreNotEqual (value, new MediaTypeWithQualityHeaderValue ("audio/Y", 0.6), "#6");
}
[Test]
public void Parse ()
{
var res = MediaTypeWithQualityHeaderValue.Parse ("audio/ aa");
Assert.AreEqual ("audio/aa", res.MediaType, "#1");
Assert.AreEqual (0, res.Parameters.Count, "#1b");
Assert.AreEqual ("audio/aa", res.ToString (), "#1c");
}
[Test]
public void Parse_Invalid ()
{
try {
MediaTypeWithQualityHeaderValue.Parse (null);
Assert.Fail ("#1");
} catch (FormatException) {
}
try {
MediaTypeWithQualityHeaderValue.Parse (" ");
Assert.Fail ("#2");
} catch (FormatException) {
}
try {
MediaTypeWithQualityHeaderValue.Parse ("audio/");
Assert.Fail ("#3");
} catch (FormatException) {
}
}
[Test]
public void Properties ()
{
var value = new MediaTypeWithQualityHeaderValue ("audio/*", 0.3);
Assert.IsNull (value.CharSet, "#1");
Assert.AreEqual ("audio/*", value.MediaType, "#2");
Assert.AreEqual ("q", value.Parameters.First ().Name, "#3");
Assert.AreEqual (0.3, value.Quality, "#4");
value.Parameters.Add (new NameValueHeaderValue ("q", "b"));
}
[Test]
public void TryParse ()
{
MediaTypeWithQualityHeaderValue res;
Assert.IsTrue (MediaTypeWithQualityHeaderValue.TryParse ("audio/*", out res), "#1");
Assert.AreEqual (0, res.Parameters.Count, "#1");
}
[Test]
public void TryParse_Invalid ()
{
MediaTypeWithQualityHeaderValue res;
Assert.IsFalse (MediaTypeWithQualityHeaderValue.TryParse ("", out res), "#1");
Assert.IsNull (res, "#2");
}
}
}

View File

@@ -0,0 +1,165 @@
//
// NameValueHeaderValueTest.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using System.Net.Http.Headers;
namespace MonoTests.System.Net.Http.Headers
{
[TestFixture]
public class NameValueHeaderValueTest
{
[Test]
public void Ctor_InvalidArguments ()
{
try {
new NameValueHeaderValue (null);
Assert.Fail ("#1");
} catch (ArgumentException) {
}
try {
new NameValueHeaderValue (" ", null);
Assert.Fail ("#2");
} catch (FormatException) {
}
}
[Test]
public void Equals ()
{
var value = new NameValueHeaderValue ("ab");
Assert.AreEqual (value, new NameValueHeaderValue ("ab"), "#1");
Assert.AreEqual (value, new NameValueHeaderValue ("AB"), "#2");
Assert.AreNotEqual (value, new NameValueHeaderValue ("AA"), "#3");
Assert.AreEqual (value, new NameValueHeaderValue ("AB", ""), "#3-1");
value = new NameValueHeaderValue ("ab", "DD");
Assert.AreEqual (value, new NameValueHeaderValue ("Ab", "DD"), "#4");
Assert.AreNotEqual (value, new NameValueHeaderValue ("AB"), "#5");
Assert.AreEqual (value, new NameValueHeaderValue ("Ab", "dd"), "#6");
}
[Test]
public void Parse ()
{
var res = NameValueHeaderValue.Parse ("c");
Assert.AreEqual ("c", res.Name, "#1");
Assert.IsNull (res.Value, "#1a");
res = NameValueHeaderValue.Parse ("c = 1");
Assert.AreEqual ("c", res.Name, "#2");
Assert.AreEqual ("1", res.Value, "#2a");
Assert.AreEqual ("c=1", res.ToString (), "#2b");
res = NameValueHeaderValue.Parse ("c = \"1\"");
Assert.AreEqual ("c", res.Name, "#3");
Assert.AreEqual ("\"1\"", res.Value, "#3a");
Assert.AreEqual ("c=\"1\"", res.ToString (), "#3b");
}
[Test]
public void Parse_Invalid ()
{
try {
NameValueHeaderValue.Parse (null);
Assert.Fail ("#1");
} catch (FormatException) {
}
try {
NameValueHeaderValue.Parse (" ");
Assert.Fail ("#2");
} catch (FormatException) {
}
try {
NameValueHeaderValue.Parse ("a;b");
Assert.Fail ("#3");
} catch (FormatException) {
}
try {
NameValueHeaderValue.Parse ("c = 1;");
Assert.Fail ("#3");
} catch (FormatException) {
}
}
[Test]
public void Properties ()
{
var value = new NameValueHeaderValue ("s", "p");
Assert.AreEqual ("s", value.Name, "#1");
Assert.AreEqual ("p", value.Value, "#2");
value = new NameValueHeaderValue ("s");
Assert.AreEqual ("s", value.Name, "#3");
Assert.IsNull (value.Value, "#4");
value.Value = "bb";
Assert.AreEqual ("bb", value.Value, "#5");
value.Value = null;
}
[Test]
public void Properties_Invalid ()
{
var value = new NameValueHeaderValue ("s");
try {
value.Value = " ";
Assert.Fail ("#1");
} catch (FormatException) {
}
}
[Test]
public void TryParse ()
{
NameValueHeaderValue res;
Assert.IsTrue (NameValueHeaderValue.TryParse ("a", out res), "#1");
Assert.AreEqual ("a", res.Name, "#2");
Assert.IsNull (res.Value, "#3");
}
[Test]
public void TryParse_Invalid ()
{
NameValueHeaderValue res;
Assert.IsFalse (NameValueHeaderValue.TryParse ("", out res), "#1");
Assert.IsNull (res, "#2");
Assert.IsFalse (NameValueHeaderValue.TryParse ("\"a\"=b", out res), "#3");
Assert.IsNull (res, "#4");
}
}
}

View File

@@ -0,0 +1,155 @@
//
// NameValueWithParametersHeaderValueTest.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using System.Net.Http.Headers;
using System.Linq;
namespace MonoTests.System.Net.Http.Headers
{
[TestFixture]
public class NameValueWithParametersHeaderValueTest
{
[Test]
public void Ctor_InvalidArguments ()
{
try {
new NameValueWithParametersHeaderValue (null);
Assert.Fail ("#1");
} catch (ArgumentException) {
}
try {
new NameValueHeaderValue (" ", null);
Assert.Fail ("#2");
} catch (FormatException) {
}
}
[Test]
public void Equals ()
{
var value = new NameValueWithParametersHeaderValue ("ab");
Assert.AreEqual (value, new NameValueWithParametersHeaderValue ("ab"), "#1");
Assert.AreEqual (value, new NameValueWithParametersHeaderValue ("AB"), "#2");
Assert.AreNotEqual (value, new NameValueWithParametersHeaderValue ("AA"), "#3");
var second = new NameValueWithParametersHeaderValue ("AB");
second.Parameters.Add (new NameValueHeaderValue ("pv"));
Assert.AreNotEqual (value, second, "#4");
value.Parameters.Add (new NameValueHeaderValue ("pv"));
Assert.AreEqual (value, second, "#5");
}
[Test]
public void Parse ()
{
var res = NameValueWithParametersHeaderValue.Parse ("c");
Assert.AreEqual ("c", res.Name, "#1");
Assert.AreEqual ("c", res.ToString (), "#1b");
Assert.IsNull (res.Value, "#2");
res = NameValueWithParametersHeaderValue.Parse ("a=2 ; b = 555");
Assert.AreEqual ("a", res.Name, "#3");
Assert.AreEqual ("a=2; b=555", res.ToString (), "#3b");
Assert.AreEqual ("2", res.Value, "#4");
Assert.AreEqual ("b", res.Parameters.First().Name, "#5");
Assert.AreEqual (1, res.Parameters.Count, "#6");
}
[Test]
public void Parse_Invalid ()
{
try {
NameValueWithParametersHeaderValue.Parse (null);
Assert.Fail ("#1");
} catch (FormatException) {
}
try {
NameValueWithParametersHeaderValue.Parse (" ");
Assert.Fail ("#2");
} catch (FormatException) {
}
try {
NameValueWithParametersHeaderValue.Parse ("a=1;");
Assert.Fail ("#3");
} catch (FormatException) {
}
}
[Test]
public void Properties ()
{
var value = new NameValueWithParametersHeaderValue ("s", "p");
Assert.AreEqual ("s", value.Name, "#1");
Assert.AreEqual ("p", value.Value, "#2");
value = new NameValueWithParametersHeaderValue ("s");
Assert.AreEqual ("s", value.Name, "#3");
Assert.IsNull (value.Value, "#4");
value.Value = "bb";
Assert.AreEqual ("bb", value.Value, "#5");
}
[Test]
public void Properties_Invalid ()
{
var value = new NameValueWithParametersHeaderValue ("s");
try {
value.Value = " ";
Assert.Fail ("#1");
} catch (FormatException) {
}
}
[Test]
public void TryParse ()
{
NameValueWithParametersHeaderValue res;
Assert.IsTrue (NameValueWithParametersHeaderValue.TryParse ("a", out res), "#1");
Assert.AreEqual ("a", res.Name, "#2");
Assert.IsNull (res.Value, "#3");
}
[Test]
public void TryParse_Invalid ()
{
NameValueWithParametersHeaderValue res;
Assert.IsFalse (NameValueWithParametersHeaderValue.TryParse ("", out res), "#1");
Assert.IsNull (res, "#2");
}
}
}

View File

@@ -0,0 +1,153 @@
//
// ProductHeaderValueTest.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using System.Net.Http.Headers;
namespace MonoTests.System.Net.Http.Headers
{
[TestFixture]
public class ProductHeaderValueTest
{
[Test]
public void Ctor_InvalidArguments ()
{
try {
new ProductHeaderValue (null);
Assert.Fail ("#1");
} catch (ArgumentException) {
}
try {
new ProductHeaderValue ("x", " ");
Assert.Fail ("#2");
} catch (FormatException) {
}
try {
new ProductHeaderValue ("/");
Assert.Fail ("#3");
} catch (FormatException) {
}
}
[Test]
public void Ctor ()
{
new ProductHeaderValue ("aa", null);
}
[Test]
public void Equals ()
{
var value = new ProductHeaderValue ("ab");
Assert.AreEqual (value, new ProductHeaderValue ("ab"), "#1");
Assert.AreEqual (value, new ProductHeaderValue ("AB"), "#2");
Assert.AreNotEqual (value, new ProductHeaderValue ("AA"), "#3");
value = new ProductHeaderValue ("ab", "DD");
Assert.AreEqual (value, new ProductHeaderValue ("Ab", "DD"), "#4");
Assert.AreNotEqual (value, new ProductHeaderValue ("AB"), "#5");
Assert.AreEqual (value, new ProductHeaderValue ("Ab", "dd"), "#6");
}
[Test]
public void Parse ()
{
var res = ProductHeaderValue.Parse ("c");
Assert.AreEqual ("c", res.Name, "#1");
Assert.IsNull (res.Version, "#2");
Assert.AreEqual ("c", res.ToString (), "#3");
res = ProductHeaderValue.Parse (" mm / ppp");
Assert.AreEqual ("mm", res.Name, "#4");
Assert.AreEqual ("ppp", res.Version, "#5");
Assert.AreEqual ("mm/ppp", res.ToString (), "#6");
}
[Test]
public void Parse_Invalid ()
{
try {
ProductHeaderValue.Parse (null);
Assert.Fail ("#1");
} catch (FormatException) {
}
try {
ProductHeaderValue.Parse (" ");
Assert.Fail ("#2");
} catch (FormatException) {
}
try {
ProductHeaderValue.Parse ("a;b");
Assert.Fail ("#3");
} catch (FormatException) {
}
try {
ProductHeaderValue.Parse ("a/");
Assert.Fail ("#4");
} catch (FormatException) {
}
}
[Test]
public void Properties ()
{
var value = new ProductHeaderValue ("s", "p");
Assert.AreEqual ("s", value.Name, "#1");
Assert.AreEqual ("p", value.Version, "#2");
value = new ProductHeaderValue ("s");
Assert.AreEqual ("s", value.Name, "#3");
Assert.IsNull (value.Version, "#4");
}
[Test]
public void TryParse ()
{
ProductHeaderValue res;
Assert.IsTrue (ProductHeaderValue.TryParse ("a", out res), "#1");
Assert.AreEqual ("a", res.Name, "#2");
Assert.IsNull (res.Version, "#3");
}
[Test]
public void TryParse_Invalid ()
{
ProductHeaderValue res;
Assert.IsFalse (ProductHeaderValue.TryParse ("", out res), "#1");
Assert.IsNull (res, "#2");
}
}
}

View File

@@ -0,0 +1,149 @@
//
// ProductInfoHeaderValueTest.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using System.Net.Http.Headers;
namespace MonoTests.System.Net.Http.Headers
{
[TestFixture]
public class ProductInfoHeaderValueTest
{
[Test]
public void Ctor_InvalidArguments ()
{
try {
new ProductInfoHeaderValue (null as string);
Assert.Fail ("#1");
} catch (ArgumentException) {
}
try {
new ProductInfoHeaderValue (" ", null);
Assert.Fail ("#2");
} catch (FormatException) {
}
try {
new ProductInfoHeaderValue (null as ProductHeaderValue);
Assert.Fail ("#3");
} catch (ArgumentException) {
}
}
[Test]
public void Equals ()
{
var value = new ProductInfoHeaderValue ("(ab)");
Assert.AreEqual (value, new ProductInfoHeaderValue ("(ab)"), "#1");
Assert.AreNotEqual (value, new ProductInfoHeaderValue ("(AB)"), "#2");
Assert.AreNotEqual (value, new ProductInfoHeaderValue ("(AA)"), "#3");
value = new ProductInfoHeaderValue ("ab", "DD");
Assert.AreEqual (value, new ProductInfoHeaderValue ("Ab", "DD"), "#4");
Assert.AreNotEqual (value, new ProductInfoHeaderValue ("(AB)"), "#5");
Assert.AreEqual (value, new ProductInfoHeaderValue ("Ab", "dd"), "#6");
}
[Test]
public void Parse ()
{
var res = ProductInfoHeaderValue.Parse ("c");
Assert.AreEqual ("c", res.Product.Name, "#1");
Assert.IsNull (res.Product.Version, "#2");
Assert.IsNull (res.Comment, "#3");
Assert.AreEqual ("c", res.ToString (), "#4");
res = ProductInfoHeaderValue.Parse (" b / 6");
Assert.AreEqual ("b", res.Product.Name, "#11");
Assert.AreEqual ("6", res.Product.Version, "#12");
Assert.IsNull (res.Comment, "#13");
Assert.AreEqual ("b/6", res.ToString (), "#14");
res = ProductInfoHeaderValue.Parse (" ( cccc ) ");
Assert.IsNull (res.Product, "#21");
Assert.AreEqual ("( cccc )", res.Comment, "#22");
Assert.AreEqual ("( cccc )", res.ToString (), "#23");
}
[Test]
public void Parse_Invalid ()
{
try {
ProductInfoHeaderValue.Parse (null);
Assert.Fail ("#1");
} catch (FormatException) {
}
try {
ProductInfoHeaderValue.Parse (" ");
Assert.Fail ("#2");
} catch (FormatException) {
}
try {
ProductInfoHeaderValue.Parse ("a;b");
Assert.Fail ("#3");
} catch (FormatException) {
}
}
[Test]
public void Properties ()
{
var value = new ProductInfoHeaderValue ("s", "p");
Assert.AreEqual ("s", value.Product.Name, "#1");
Assert.AreEqual ("p", value.Product.Version, "#2");
Assert.IsNull (value.Comment, "#3");
value = new ProductInfoHeaderValue ("(s)");
Assert.AreEqual ("(s)", value.Comment, "#4");
Assert.IsNull (value.Product, "#5");
}
[Test]
public void TryParse ()
{
ProductInfoHeaderValue res;
Assert.IsTrue (ProductInfoHeaderValue.TryParse ("a", out res), "#1");
Assert.AreEqual ("a", res.Product.Name, "#2");
Assert.IsNull (res.Comment, "#3");
}
[Test]
public void TryParse_Invalid ()
{
ProductInfoHeaderValue res;
Assert.IsFalse (ProductInfoHeaderValue.TryParse ("", out res), "#1");
Assert.IsNull (res, "#2");
}
}
}

View File

@@ -0,0 +1,149 @@
//
// RangeConditionHeaderValueTest.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using System.Net.Http.Headers;
namespace MonoTests.System.Net.Http.Headers
{
[TestFixture]
public class RangeConditionHeaderValueTest
{
[Test]
public void Ctor_InvalidArguments ()
{
try {
new RangeConditionHeaderValue (null as string);
Assert.Fail ("#1");
} catch (ArgumentException) {
}
try {
new RangeConditionHeaderValue ("a");
Assert.Fail ("#2");
} catch (FormatException) {
}
try {
new RangeConditionHeaderValue (null as EntityTagHeaderValue);
Assert.Fail ("#3");
} catch (ArgumentNullException) {
}
}
[Test]
public void Equals ()
{
var value = new RangeConditionHeaderValue ("\"abc\"");
Assert.AreEqual (value, new RangeConditionHeaderValue ("\"abc\""), "#1");
Assert.AreNotEqual (value, new RangeConditionHeaderValue ("\"AbC\""), "#2");
value = new RangeConditionHeaderValue (DateTimeOffset.MinValue);
Assert.AreEqual (value, new RangeConditionHeaderValue (DateTimeOffset.MinValue), "#3");
Assert.AreNotEqual (value, new RangeConditionHeaderValue (DateTimeOffset.MaxValue), "#4");
Assert.AreNotEqual (value, new RangeConditionHeaderValue ("\"AbC\""), "#5");
}
[Test]
public void Parse ()
{
var res = RangeConditionHeaderValue.Parse ("\"c\"");
Assert.AreEqual ("\"c\"", res.EntityTag.Tag, "#1");
Assert.IsFalse (res.EntityTag.IsWeak, "#2");
Assert.IsNull (res.Date, "#3");
Assert.AreEqual ("\"c\"", res.ToString (), "#4");
res = RangeConditionHeaderValue.Parse ("W/\"\"");
Assert.AreEqual ("\"\"", res.EntityTag.Tag, "#11");
Assert.IsTrue (res.EntityTag.IsWeak, "#12");
Assert.IsNull (res.Date, "#13");
Assert.AreEqual ("W/\"\"", res.ToString (), "#14");
res = RangeConditionHeaderValue.Parse ("Sun Nov 6 08:49:37 1994");
Assert.IsNull (res.EntityTag, "#21");
Assert.AreEqual (new DateTimeOffset (1994, 11, 6, 8, 49, 37, 0, TimeSpan.Zero), res.Date, "#22");
Assert.AreEqual ("Sun, 06 Nov 1994 08:49:37 GMT", res.ToString (), "#23");
}
[Test]
public void Parse_Invalid ()
{
try {
RangeConditionHeaderValue.Parse (null);
Assert.Fail ("#1");
} catch (FormatException) {
}
try {
RangeConditionHeaderValue.Parse (" ");
Assert.Fail ("#2");
} catch (FormatException) {
}
try {
RangeConditionHeaderValue.Parse ("a b");
Assert.Fail ("#3");
} catch (FormatException) {
}
}
[Test]
public void Properties ()
{
var value = new RangeConditionHeaderValue ("\"b\"");
Assert.AreEqual (new EntityTagHeaderValue ("\"b\""), value.EntityTag, "#1");
Assert.IsNull (value.Date, "#2");
var dto = new DateTimeOffset (20000, new TimeSpan ());
value = new RangeConditionHeaderValue (dto);
Assert.AreEqual (null, value.EntityTag, "#3");
Assert.AreEqual (dto, value.Date, "#4");
}
[Test]
public void TryParse ()
{
RangeConditionHeaderValue res;
Assert.IsTrue (RangeConditionHeaderValue.TryParse ("\"\"", out res), "#1");
Assert.AreEqual ("\"\"", res.EntityTag.Tag, "#2");
Assert.IsNull (res.Date, "#3");
}
[Test]
public void TryParse_Invalid ()
{
RangeConditionHeaderValue res;
Assert.IsFalse (RangeConditionHeaderValue.TryParse ("", out res), "#1");
Assert.IsNull (res, "#2");
}
}
}

View File

@@ -0,0 +1,203 @@
//
// RangeHeaderValueTest.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using System.Net.Http.Headers;
using System.Linq;
namespace MonoTests.System.Net.Http.Headers
{
[TestFixture]
public class RangeHeaderValueTest
{
[Test]
public void Ctor_InvalidArguments ()
{
try {
new RangeHeaderValue (null, null);
Assert.Fail ("#1");
} catch (ArgumentException) {
}
try {
new RangeHeaderValue (long.MinValue, null);
Assert.Fail ("#2");
} catch (ArgumentOutOfRangeException) {
}
try {
new RangeHeaderValue (10, 1);
Assert.Fail ("#3");
} catch (ArgumentOutOfRangeException) {
}
}
[Test]
public void Equals ()
{
var value = new RangeHeaderValue (4, null);
Assert.AreEqual (value, new RangeHeaderValue (4, null), "#1");
Assert.AreNotEqual (value, new RangeHeaderValue (4, 5), "#2");
Assert.AreNotEqual (value, new RangeHeaderValue (), "#3");
value = new RangeHeaderValue (2, 4);
Assert.AreEqual (value, new RangeHeaderValue (2, 4), "#4");
Assert.AreNotEqual (value, new RangeHeaderValue (2, null), "#5");
Assert.AreNotEqual (value, new RangeHeaderValue (2, 3), "#6");
}
[Test]
public void Parse ()
{
var res = RangeHeaderValue.Parse ("bytes=2-40");
Assert.AreEqual ("bytes", res.Unit, "#1");
Assert.AreEqual (2, res.Ranges.First ().From, "#2");
Assert.AreEqual (40, res.Ranges.First ().To, "#3");
Assert.AreEqual ("bytes=2-40", res.ToString (), "#4");
res = RangeHeaderValue.Parse ("d-dd = 2 - ");
Assert.AreEqual ("d-dd", res.Unit, "#10");
Assert.AreEqual (2, res.Ranges.First ().From, "#11");
Assert.IsNull (res.Ranges.First ().To, "#12");
Assert.AreEqual ("d-dd=2-", res.ToString (), "#13");
res = RangeHeaderValue.Parse ("zz = - 6 , 5 - 9, -8");
Assert.AreEqual ("zz", res.Unit, "#20");
Assert.IsNull (res.Ranges.First ().From, "#21");
Assert.AreEqual (6, res.Ranges.First ().To, "#22");
Assert.AreEqual (5, res.Ranges.Skip (1).First ().From, "#21b");
Assert.AreEqual (9, res.Ranges.Skip (1).First ().To, "#22b");
Assert.AreEqual ("zz=-6, 5-9, -8", res.ToString (), "#23");
res = RangeHeaderValue.Parse ("ddd = 2 -, 1-4");
Assert.AreEqual ("ddd", res.Unit, "#30");
Assert.AreEqual (2, res.Ranges.First ().From, "#31");
Assert.IsNull (res.Ranges.First ().To, "#32");
Assert.AreEqual ("ddd=2-, 1-4", res.ToString (), "#33");
res = RangeHeaderValue.Parse ("bytes=0-");
Assert.AreEqual ("bytes", res.Unit, "#40");
Assert.AreEqual (0, res.Ranges.First ().From, "#41");
Assert.IsNull (res.Ranges.First ().To, "#42");
Assert.AreEqual ("bytes=0-", res.ToString (), "#43");
res = RangeHeaderValue.Parse ("bytes=0-,-9");
Assert.AreEqual ("bytes", res.Unit, "#50");
Assert.AreEqual (0, res.Ranges.First ().From, "#51");
Assert.IsNull (res.Ranges.First ().To, "#52");
Assert.IsNull (res.Ranges.Skip (1).First ().From, "#53");
Assert.AreEqual (9, res.Ranges.Skip (1).First ().To, "#54");
Assert.AreEqual ("bytes=0-, -9", res.ToString (), "#55");
}
[Test]
public void Parse_Invalid ()
{
try {
RangeHeaderValue.Parse (null);
Assert.Fail ("#1");
} catch (FormatException) {
}
try {
RangeHeaderValue.Parse (" ");
Assert.Fail ("#2");
} catch (FormatException) {
}
try {
RangeHeaderValue.Parse ("5-6");
Assert.Fail ("#3");
} catch (FormatException) {
}
try {
RangeHeaderValue.Parse ("bytes=");
Assert.Fail ("#4");
} catch (FormatException) {
}
try {
RangeHeaderValue.Parse ("byte=1");
Assert.Fail ("#5");
} catch (FormatException) {
}
try {
RangeHeaderValue.Parse ("byte=10-6");
Assert.Fail ("#6");
} catch (FormatException) {
}
}
[Test]
public void Properties ()
{
var value = new RangeHeaderValue (3, 9);
Assert.AreEqual ("bytes", value.Unit, "#1");
Assert.AreEqual (3, value.Ranges.First ().From, "#2");
Assert.AreEqual (9, value.Ranges.First ().To, "#3");
value = new RangeHeaderValue ();
Assert.AreEqual ("bytes", value.Unit, "#4");
Assert.AreEqual (0, value.Ranges.Count, "#5");
}
[Test]
public void Properties_Invalid ()
{
var value = new RangeHeaderValue ();
try {
value.Unit = "";
Assert.Fail ("#1");
} catch (ArgumentException) {
}
}
[Test]
public void TryParse ()
{
RangeHeaderValue res;
Assert.IsTrue (RangeHeaderValue.TryParse ("bytes=4-33", out res), "#1");
Assert.AreEqual ("bytes", res.Unit, "#2");
Assert.AreEqual (4, res.Ranges.First ().From, "#3");
Assert.AreEqual (33, res.Ranges.First ().To, "#4");
}
[Test]
public void TryParse_Invalid ()
{
RangeHeaderValue res;
Assert.IsFalse (RangeHeaderValue.TryParse ("bytes=4,33", out res), "#1");
Assert.IsNull (res, "#2");
}
}
}

View File

@@ -0,0 +1,93 @@
//
// RangeItemHeaderValueTest.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using System.Net.Http.Headers;
namespace MonoTests.System.Net.Http.Headers
{
[TestFixture]
public class RangeItemHeaderValueTest
{
[Test]
public void Ctor_InvalidArguments ()
{
try {
new RangeItemHeaderValue (null, null);
Assert.Fail ("#1");
} catch (ArgumentException) {
}
try {
new RangeItemHeaderValue (5, 2);
Assert.Fail ("#2");
} catch (ArgumentOutOfRangeException) {
}
try {
new RangeItemHeaderValue (-1, 2);
Assert.Fail ("#3");
} catch (ArgumentOutOfRangeException) {
}
}
[Test]
public void Ctor ()
{
var v = new RangeItemHeaderValue (1, null);
Assert.AreEqual ("1-", v.ToString (), "#1");
v = new RangeItemHeaderValue (null, 1);
Assert.AreEqual ("-1", v.ToString (), "#2");
}
[Test]
public void Equals ()
{
var value = new RangeItemHeaderValue (5, null);
Assert.AreEqual (value, new RangeItemHeaderValue (5, null), "#1");
Assert.AreNotEqual (value, new RangeItemHeaderValue (6, null), "#2");
Assert.AreNotEqual (value, new RangeItemHeaderValue (5, 10), "#3");
}
[Test]
public void Properties ()
{
var value = new RangeItemHeaderValue (3, 23);
Assert.AreEqual (3, value.From, "#1");
Assert.AreEqual (23, value.To, "#2");
value = new RangeItemHeaderValue (5, null);
Assert.AreEqual (5, value.From, "#3");
Assert.IsNull (value.To, "#4");
}
}
}

View File

@@ -0,0 +1,127 @@
//
// RetryConditionHeaderValueTest.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using System.Net.Http.Headers;
namespace MonoTests.System.Net.Http.Headers
{
[TestFixture]
public class RetryConditionHeaderValueTest
{
[Test]
public void Ctor_InvalidArguments ()
{
try {
new RetryConditionHeaderValue (TimeSpan.MaxValue);
Assert.Fail ("#1");
} catch (ArgumentException) {
}
}
[Test]
public void Equals ()
{
var value = new RetryConditionHeaderValue (new DateTimeOffset (DateTime.Today));
Assert.AreEqual (value, new RetryConditionHeaderValue (new DateTimeOffset (DateTime.Today)), "#1");
Assert.AreNotEqual (value, new RetryConditionHeaderValue (new DateTimeOffset ()), "#2");
value = new RetryConditionHeaderValue (new TimeSpan (300));
Assert.AreEqual (value, new RetryConditionHeaderValue (new TimeSpan (300)), "#4");
Assert.AreNotEqual (value, new RetryConditionHeaderValue (new TimeSpan (44)), "#5");
}
[Test]
public void Parse ()
{
var res = RetryConditionHeaderValue.Parse ("144");
Assert.IsNull (res.Date, "#1");
Assert.AreEqual (new TimeSpan (0, 0, 144), res.Delta, "#2");
Assert.AreEqual ("144", res.ToString (), "#3");
res = RetryConditionHeaderValue.Parse ("Fri, 31 Dec 1999 23:59:59 GMT");
Assert.AreEqual (new DateTimeOffset (1999, 12, 31, 23, 59, 59, 0, TimeSpan.Zero), res.Date, "#11");
Assert.IsNull (res.Delta, "#12");
Assert.AreEqual ("Fri, 31 Dec 1999 23:59:59 GMT", res.ToString (), "#13");
}
[Test]
public void Parse_Invalid ()
{
try {
RetryConditionHeaderValue.Parse (null);
Assert.Fail ("#1");
} catch (FormatException) {
}
try {
RetryConditionHeaderValue.Parse (" ");
Assert.Fail ("#2");
} catch (FormatException) {
}
try {
RetryConditionHeaderValue.Parse ("a");
Assert.Fail ("#3");
} catch (FormatException) {
}
}
[Test]
public void Properties ()
{
var value = new RetryConditionHeaderValue (new TimeSpan (5000));
Assert.IsNull (value.Date, "#1");
Assert.AreEqual (new TimeSpan (5000), value.Delta, "#2");
value = new RetryConditionHeaderValue (new DateTimeOffset (DateTime.Today));
Assert.AreEqual (new DateTimeOffset (DateTime.Today), value.Date, "#3");
Assert.IsNull (value.Delta, "#4");
}
[Test]
public void TryParse ()
{
RetryConditionHeaderValue res;
Assert.IsTrue (RetryConditionHeaderValue.TryParse ("124", out res), "#1");
Assert.IsNull (res.Date, "#2");
Assert.AreEqual (new TimeSpan (0, 2, 4), res.Delta, "#3");
}
[Test]
public void TryParse_Invalid ()
{
RetryConditionHeaderValue res;
Assert.IsFalse (RetryConditionHeaderValue.TryParse ("", out res), "#1");
Assert.IsNull (res, "#2");
}
}
}

View File

@@ -0,0 +1,184 @@
//
// StringWithQualityHeaderValueTest.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using System.Net.Http.Headers;
namespace MonoTests.System.Net.Http.Headers
{
[TestFixture]
public class StringWithQualityHeaderValueTest
{
[Test]
public void Ctor_InvalidArguments ()
{
try {
new StringWithQualityHeaderValue (null);
Assert.Fail ("#1");
} catch (ArgumentException) {
}
try {
new StringWithQualityHeaderValue (" ", 1);
Assert.Fail ("#2");
} catch (FormatException) {
}
try {
new StringWithQualityHeaderValue ("s", 1.1);
Assert.Fail ("#3");
} catch (ArgumentOutOfRangeException) {
}
}
[Test]
public void Ctor ()
{
var a = new StringWithQualityHeaderValue ("s", 0.123456);
Assert.AreEqual ("s; q=0.123", a.ToString ());
}
[Test]
public void Equals ()
{
var value = new StringWithQualityHeaderValue ("ab");
Assert.AreEqual (value, new StringWithQualityHeaderValue ("ab"), "#1");
Assert.AreEqual (value, new StringWithQualityHeaderValue ("AB"), "#2");
Assert.AreNotEqual (value, new StringWithQualityHeaderValue ("AA"), "#3");
Assert.AreEqual ("ab", value.ToString (), "#33");
value = new StringWithQualityHeaderValue ("ab", 1);
Assert.AreEqual (value, new StringWithQualityHeaderValue ("Ab", 1), "#4");
Assert.AreNotEqual (value, new StringWithQualityHeaderValue ("AB", 0), "#5");
Assert.AreNotEqual (value, new StringWithQualityHeaderValue ("AA", 1), "#6");
}
[Test]
public void Parse ()
{
var res = StringWithQualityHeaderValue.Parse ("c");
Assert.AreEqual ("c", res.Value, "#1");
Assert.IsNull (res.Quality, "#2");
Assert.AreEqual ("c", res.ToString (), "#3");
res = StringWithQualityHeaderValue.Parse (" * ; q = 0.2");
Assert.AreEqual ("*", res.Value, "#11");
Assert.AreEqual (0.2, res.Quality, "#12");
Assert.AreEqual ("*; q=0.2", res.ToString (), "#13");
res = StringWithQualityHeaderValue.Parse ("aa ;Q=0");
Assert.AreEqual ("aa", res.Value, "#21");
Assert.AreEqual (0, res.Quality, "#22");
Assert.AreEqual ("aa; q=0.0", res.ToString (), "#23");
}
[Test]
public void Parse_Invalid ()
{
try {
StringWithQualityHeaderValue.Parse (null);
Assert.Fail ("#1");
} catch (FormatException) {
}
try {
StringWithQualityHeaderValue.Parse (" ");
Assert.Fail ("#2");
} catch (FormatException) {
}
try {
StringWithQualityHeaderValue.Parse ("a,b");
Assert.Fail ("#3");
} catch (FormatException) {
}
try {
StringWithQualityHeaderValue.Parse ("b;");
Assert.Fail ("#4");
} catch (FormatException) {
}
try {
StringWithQualityHeaderValue.Parse ("b;q=");
Assert.Fail ("#5");
} catch (FormatException) {
}
try {
StringWithQualityHeaderValue.Parse ("b;q=2");
Assert.Fail ("#6");
} catch (FormatException) {
}
try {
StringWithQualityHeaderValue.Parse ("b;q=-0.2");
Assert.Fail ("#7");
} catch (FormatException) {
}
try {
StringWithQualityHeaderValue.Parse ("b;X=2");
Assert.Fail ("#8");
} catch (FormatException) {
}
}
[Test]
public void Properties ()
{
var value = new StringWithQualityHeaderValue ("s", 1);
Assert.AreEqual ("s", value.Value, "#1");
Assert.AreEqual (1, value.Quality, "#2");
value = new StringWithQualityHeaderValue ("ss");
Assert.AreEqual ("ss", value.Value, "#3");
Assert.IsNull (value.Quality, "#4");
}
[Test]
public void TryParse ()
{
StringWithQualityHeaderValue res;
Assert.IsTrue (StringWithQualityHeaderValue.TryParse ("a", out res), "#1");
Assert.AreEqual ("a", res.Value, "#2");
Assert.IsNull (res.Quality, "#3");
}
[Test]
public void TryParse_Invalid ()
{
StringWithQualityHeaderValue res;
Assert.IsFalse (StringWithQualityHeaderValue.TryParse ("", out res), "#1");
Assert.IsNull (res, "#2");
}
}
}

View File

@@ -0,0 +1,158 @@
//
// TransferCodingHeaderValueTest.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using System.Net.Http.Headers;
using System.Linq;
namespace MonoTests.System.Net.Http.Headers
{
[TestFixture]
public class TransferCodingHeaderValueTest
{
[Test]
public void Ctor_Invalid ()
{
try {
var tfhv = new TransferCodingHeaderValue (null);
Assert.Fail ("#1");
} catch (ArgumentException) {
}
try {
var tfhv = new TransferCodingHeaderValue ("my value");
Assert.Fail ("#2");
} catch (FormatException) {
}
}
[Test]
public void Equals ()
{
var tfhv = new TransferCodingHeaderValue ("abc");
Assert.AreEqual (tfhv, new TransferCodingHeaderValue ("abc"), "#1");
Assert.AreEqual (tfhv, new TransferCodingHeaderValue ("AbC"), "#2");
tfhv.Parameters.Add (new NameValueHeaderValue ("p", "v"));
Assert.AreNotEqual (tfhv, new TransferCodingHeaderValue ("abc"), "#3");
var tfhv2 = new TransferCodingHeaderValue ("abc");
Assert.AreNotEqual (tfhv, tfhv2, "#4");
tfhv2.Parameters.Add (new NameValueHeaderValue ("p", "v"));
Assert.AreEqual (tfhv, tfhv2, "#5");
}
[Test]
public void Parse ()
{
var res = TransferCodingHeaderValue.Parse ("content");
Assert.AreEqual ("content", res.Value, "#1");
Assert.AreEqual ("content", res.ToString (), "#1a");
res = TransferCodingHeaderValue.Parse (" a ;b;c ");
Assert.AreEqual ("a", res.Value, "#2");
Assert.AreEqual ("a; b; c", res.ToString (), "#2a");
Assert.AreEqual ("b", res.Parameters.First ().ToString (), "#2b");
res = TransferCodingHeaderValue.Parse (" a ; v = m ");
Assert.AreEqual ("a", res.Value, "#3");
Assert.AreEqual ("a; v=m", res.ToString (), "#3a");
Assert.AreEqual ("m", res.Parameters.First ().Value, "#3b");
res = TransferCodingHeaderValue.Parse ("\ta; v = \"mmm\" ");
Assert.AreEqual ("a", res.Value, "#4");
Assert.AreEqual ("a; v=\"mmm\"", res.ToString (), "#4a");
Assert.AreEqual ("\"mmm\"", res.Parameters.First ().Value, "#4b");
}
[Test]
public void Parse_Invalid ()
{
try {
TransferCodingHeaderValue.Parse (null);
Assert.Fail ("#1");
} catch (FormatException) {
}
try {
TransferCodingHeaderValue.Parse (" ");
Assert.Fail ("#2");
} catch (FormatException) {
}
try {
TransferCodingHeaderValue.Parse ("a b");
Assert.Fail ("#3");
} catch (FormatException) {
}
try {
TransferCodingHeaderValue.Parse ("a;");
Assert.Fail ("#4");
} catch (FormatException) {
}
try {
TransferCodingHeaderValue.Parse ("u;v=\"\"\"\"");
Assert.Fail ("#5");
} catch (FormatException) {
}
}
[Test]
public void TryParse ()
{
TransferCodingHeaderValue res;
Assert.IsTrue (TransferCodingHeaderValue.TryParse ("content", out res), "#1");
Assert.AreEqual ("content", res.Value, "#2");
}
[Test]
public void TryParse_Invalid ()
{
TransferCodingHeaderValue res;
Assert.IsFalse (TransferCodingHeaderValue.TryParse ("a b", out res), "#1");
Assert.IsNull (res, "#2");
}
[Test]
public void Value ()
{
var tfhv = new TransferCodingHeaderValue ("value");
Assert.AreEqual ("value", tfhv.Value, "#1");
Assert.IsNotNull (tfhv.Parameters, "#2");
}
}
}

View File

@@ -0,0 +1,137 @@
//
// TransferCodingWithQualityHeaderValueTest.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using System.Net.Http.Headers;
using System.Linq;
namespace MonoTests.System.Net.Http.Headers
{
[TestFixture]
public class TransferCodingWithQualityHeaderValueTest
{
[Test]
public void Ctor ()
{
var v = new TransferCodingWithQualityHeaderValue ("value");
Assert.AreEqual ("value", v.Value, "#1");
Assert.IsNull (v.Quality);
}
[Test]
public void Equals ()
{
var tfhv = new TransferCodingWithQualityHeaderValue ("abc");
Assert.AreEqual (tfhv, new TransferCodingWithQualityHeaderValue ("abc"), "#1");
Assert.AreEqual (tfhv, new TransferCodingWithQualityHeaderValue ("AbC"), "#2");
Assert.AreNotEqual (tfhv, new TransferCodingWithQualityHeaderValue ("ab"), "#3");
Assert.AreNotEqual (tfhv, new TransferCodingWithQualityHeaderValue ("ab", 1), "#3");
tfhv = new TransferCodingWithQualityHeaderValue ("abc", 0.3);
Assert.AreEqual (tfhv, new TransferCodingWithQualityHeaderValue ("abc", 0.3), "#4");
Assert.AreEqual (tfhv, new TransferCodingWithQualityHeaderValue ("AbC", 0.3), "#5");
Assert.AreNotEqual (tfhv, new TransferCodingWithQualityHeaderValue ("abc"), "#6");
var custom_param = new TransferCodingHeaderValue ("abc");
custom_param.Parameters.Add (new NameValueHeaderValue ("q", "0.3"));
Assert.AreEqual (tfhv, custom_param, "#7");
}
[Test]
public void Parse ()
{
var res = TransferCodingWithQualityHeaderValue.Parse ("1.1");
Assert.AreEqual (0, res.Parameters.Count, "#1");
Assert.IsNull (res.Quality, "#1b");
Assert.AreEqual ("1.1", res.Value, "#1c");
Assert.AreEqual ("1.1", res.ToString (), "#1d");
res = TransferCodingWithQualityHeaderValue.Parse ("a ; b ");
Assert.AreEqual (1, res.Parameters.Count, "#2");
Assert.IsNull (res.Quality, "#2b");
Assert.AreEqual ("a", res.Value, "#2c");
Assert.AreEqual ("a; b", res.ToString (), "#2d");
}
[Test]
public void Parse_Invalid ()
{
try {
TransferCodingWithQualityHeaderValue.Parse (null);
Assert.Fail ("#1");
} catch (FormatException) {
}
try {
TransferCodingWithQualityHeaderValue.Parse (" ");
Assert.Fail ("#2");
} catch (FormatException) {
}
}
[Test]
public void Properties ()
{
var v = new TransferCodingWithQualityHeaderValue ("value", 0.412);
Assert.AreEqual ("value", v.Value, "#1");
Assert.AreEqual (0.412, v.Quality, "#2");
Assert.AreEqual ("0.412", v.Parameters.First ().Value, "#3");
v.Parameters.Add (new NameValueHeaderValue ("q", "0.2"));
Assert.AreEqual (0.412, v.Quality, "#4");
v = new TransferCodingWithQualityHeaderValue ("value");
v.Parameters.Add (new NameValueHeaderValue ("q", "0.112"));
Assert.AreEqual (0.112, v.Quality, "#5");
v = new TransferCodingWithQualityHeaderValue ("value");
v.Parameters.Add (new NameValueHeaderValue ("q", "test"));
Assert.IsNull (v.Quality, "#6");
}
[Test]
public void Properties_Invalid ()
{
try {
new TransferCodingWithQualityHeaderValue ("value", 4);
Assert.Fail ("#1");
} catch (ArgumentOutOfRangeException) {
}
var v = new TransferCodingWithQualityHeaderValue ("value");
try {
v.Quality = -1;
Assert.Fail ("#2");
} catch (ArgumentOutOfRangeException) {
}
}
}
}

Some files were not shown because too many files have changed in this diff Show More