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,48 @@
//
// ChangeInterceptorAttributeTests.cs
//
// Author:
// Eric Maupin <me@ermau.com>
//
// Copyright (c) 2009 Eric Maupin (http://www.ermau.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 NUnit.Framework;
namespace System.Data.Services.Tests {
[TestFixture]
public class ChangeInterceptorAttributeTests {
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void CtorNull()
{
new ChangeInterceptorAttribute (null);
}
[Test]
public void Ctor()
{
var ci = new ChangeInterceptorAttribute ("setName");
Assert.AreEqual ("setName", ci.EntitySetName);
}
}
}

View File

@@ -0,0 +1,3 @@
2009-11-06 Eric Maupin <me@ermau.com>
* Added

View File

@@ -0,0 +1,71 @@
//
// DataServiceExceptionTests.cs
//
// Author:
// Eric Maupin <me@ermau.com>
//
// Copyright (c) 2009 Eric Maupin (http://www.ermau.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 NUnit.Framework;
namespace System.Data.Services.Tests {
[TestFixture]
public class DataServiceExceptionTests {
[Test]
public void CtorMessage()
{
var ex = new DataServiceException ("message");
Assert.AreEqual ("message", ex.Message);
Assert.IsNull (ex.InnerException);
}
[Test]
public void CtorMessageAndInner()
{
Exception inner = new Exception ("inner");
var ex = new DataServiceException ("message", inner);
Assert.AreEqual ("message", ex.Message);
Assert.AreEqual (inner, ex.InnerException);
}
[Test]
public void CtorStatusAndMessage()
{
var ex = new DataServiceException (404, "message");
Assert.AreEqual (404, ex.StatusCode);
Assert.AreEqual ("message", ex.Message);
}
[Test]
public void CtorStatusAndErrorMessageLanguageException()
{
Exception inner = new Exception ("inner");
var ex = new DataServiceException (404, "error", "message", "language", inner);
Assert.AreEqual ("message", ex.Message);
Assert.AreEqual (404, ex.StatusCode);
Assert.AreEqual ("language", ex.MessageLanguage);
Assert.AreEqual (inner, ex.InnerException);
}
}
}

View File

@@ -0,0 +1,82 @@
//
// DataServiceTests.cs
//
// Author:
// Eric Maupin <me@ermau.com>
//
// Copyright (c) 2009 Eric Maupin (http://www.ermau.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 NUnit.Framework;
namespace System.Data.Services.Tests {
[TestFixture]
public class DataServiceTests {
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void AttachHostNull()
{
var d = new DataService<string>();
d.AttachHost (null);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ProcessRequestForMessageNull()
{
var d = new DataService<string>();
d.ProcessRequestForMessage (null);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void HandleExceptionNull()
{
var d = new TestDataService<string>();
d.TestHandleException (null);
}
}
public class TestDataService<T>
: DataService<T>
{
public T TestCurrentDataSource
{
get { return this.CurrentDataSource; }
}
public T TestCreateDataSource()
{
return this.CreateDataSource();
}
public void TestHandleException (HandleExceptionArgs args)
{
this.HandleException (args);
}
public void TestOnStartProcessingRequest (ProcessRequestArgs args)
{
this.OnStartProcessingRequest (args);
}
}
}

View File

@@ -0,0 +1,66 @@
//
// ETagAttributeTests.cs
//
// Author:
// Eric Maupin <me@ermau.com>
//
// Copyright (c) 2009 Eric Maupin (http://www.ermau.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.Linq;
using NUnit.Framework;
namespace System.Data.Services.Tests {
[TestFixture]
public class ETagAttributeTests {
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void CtorPropertyNameNull()
{
new ETagAttribute ((string)null);
}
[Test]
public void CtorPropertyName()
{
var e = new ETagAttribute ("tag");
Assert.AreEqual (1, e.PropertyNames.Count);
Assert.AreEqual ("tag", e.PropertyNames.First());
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void CtorPropertyNamesNull()
{
new ETagAttribute ((string[])null);
}
[Test]
public void CtorPropertyNames()
{
var e = new ETagAttribute (new[] { "foo", "bar" });
Assert.AreEqual (2, e.PropertyNames.Count);
Assert.AreEqual ("foo", e.PropertyNames[0]);
Assert.AreEqual ("bar", e.PropertyNames[1]);
}
}
}

View File

@@ -0,0 +1,104 @@
//
// ExpandSegmentCollectionTests.cs
//
// Author:
// Eric Maupin <me@ermau.com>
//
// Copyright (c) 2009 Eric Maupin (http://www.ermau.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.Linq.Expressions;
using NUnit.Framework;
namespace System.Data.Services.Tests {
[TestFixture]
public class ExpandSegmentCollectionTests {
[Test]
public void CtorCapacity()
{
var esc = new ExpandSegmentCollection (20);
Assert.AreEqual (20, esc.Capacity);
}
[Test]
public void HasFilterInit()
{
var esc = new ExpandSegmentCollection();
Assert.IsFalse (esc.HasFilter);
}
[Test]
public void HasFilterAddNull()
{
var esc = new ExpandSegmentCollection();
esc.Add (new ExpandSegment ("first", null));
Assert.IsFalse (esc.HasFilter);
}
[Test]
public void HasFilterAddWithFilter()
{
var esc = new ExpandSegmentCollection();
esc.Add (new ExpandSegment ("first", null));
var param = Expression.Parameter (typeof (bool), "b");
var filter = Expression.Lambda (param, param);
var filteredSegment = new ExpandSegment ("second", filter);
esc.Add (filteredSegment);
Assert.IsTrue (esc.HasFilter);
}
[Test]
public void HasFilterRemoveFiltered()
{
var esc = new ExpandSegmentCollection();
esc.Add (new ExpandSegment ("first", null));
var param = Expression.Parameter (typeof (bool), "b");
var filter = Expression.Lambda (param, param);
var filteredSegment = new ExpandSegment ("second", filter);
esc.Add (filteredSegment);
esc.Remove (filteredSegment);
Assert.IsFalse (esc.HasFilter);
}
[Test]
public void HasFilterRemoveFilteredMultiple()
{
var esc = new ExpandSegmentCollection();
esc.Add (new ExpandSegment ("first", null));
var param = Expression.Parameter (typeof (bool), "b");
var filter = Expression.Lambda (param, param);
var filteredSegment = new ExpandSegment ("second", filter);
esc.Add (filteredSegment);
esc.Add (filteredSegment);
esc.Remove (filteredSegment);
Assert.IsTrue (esc.HasFilter);
esc.Remove (filteredSegment);
Assert.IsFalse (esc.HasFilter);
}
}
}

View File

@@ -0,0 +1,87 @@
//
// ExpandSegmentTests.cs
//
// Author:
// Eric Maupin <me@ermau.com>
//
// Copyright (c) 2009 Eric Maupin (http://www.ermau.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.Linq.Expressions;
using NUnit.Framework;
namespace System.Data.Services.Tests {
[TestFixture]
public class ExpandSegmentTests {
[Test]
public void CtorName()
{
var s = new ExpandSegment ("name", null);
Assert.AreEqual ("name", s.Name);
Assert.AreEqual (null, s.Filter);
Assert.IsFalse (s.HasFilter);
}
[Test]
public void CtorFilter()
{
var param = Expression.Parameter (typeof (bool), "b");
var filter = Expression.Lambda (param, param);
var s = new ExpandSegment ("name", filter);
Assert.AreEqual ("name", s.Name);
Assert.AreEqual (filter, s.Filter);
Assert.IsTrue (s.HasFilter);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void CtorNullName()
{
new ExpandSegment (null, null);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void PathHasFilterException()
{
ExpandSegment.PathHasFilter (null);
}
[Test]
public void PathHasFilter()
{
var param = Expression.Parameter (typeof (bool), "b");
var filter = Expression.Lambda (param, param);
Assert.IsTrue (ExpandSegment.PathHasFilter (new []
{ new ExpandSegment ("first", null), new ExpandSegment ("second", filter), new ExpandSegment ("third", null) }));
}
[Test]
public void PathDoesntHaveFilter()
{
Assert.IsFalse (ExpandSegment.PathHasFilter (new []
{ new ExpandSegment ("first", null), new ExpandSegment ("second", null), new ExpandSegment ("third", null) }));
}
}
}

View File

@@ -0,0 +1,66 @@
//
// IgnorePropertiesAttributeTests.cs
//
// Author:
// Eric Maupin <me@ermau.com>
//
// Copyright (c) 2009 Eric Maupin (http://www.ermau.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.Linq;
using NUnit.Framework;
namespace System.Data.Services.Tests {
[TestFixture]
public class IgnorePropertiesAttributeTests {
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void CtorPropertyNameNull()
{
new IgnorePropertiesAttribute ((string)null);
}
[Test]
public void CtorPropertyName()
{
var e = new IgnorePropertiesAttribute ("tag");
Assert.AreEqual (1, e.PropertyNames.Count);
Assert.AreEqual ("tag", e.PropertyNames.First());
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void CtorPropertyNamesNull()
{
new IgnorePropertiesAttribute ((string[])null);
}
[Test]
public void CtorPropertyNames()
{
var e = new IgnorePropertiesAttribute (new[] { "foo", "bar" });
Assert.AreEqual (2, e.PropertyNames.Count);
Assert.AreEqual ("foo", e.PropertyNames[0]);
Assert.AreEqual ("bar", e.PropertyNames[1]);
}
}
}

View File

@@ -0,0 +1,42 @@
//
// MimeTypeAttributeTests.cs
//
// Author:
// Eric Maupin <me@ermau.com>
//
// Copyright (c) 2009 Eric Maupin (http://www.ermau.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 NUnit.Framework;
namespace System.Data.Services.Tests {
[TestFixture]
public class MimeTypeAttributeTests {
[Test]
public void Ctor()
{
var mt = new MimeTypeAttribute ("member", "type");
Assert.AreEqual ("member", mt.MemberName);
Assert.AreEqual ("type", mt.MimeType);
}
}
}

View File

@@ -0,0 +1,48 @@
//
// QueryInterceptorAttributeTests.cs
//
// Author:
// Eric Maupin <me@ermau.com>
//
// Copyright (c) 2009 Eric Maupin (http://www.ermau.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 NUnit.Framework;
namespace System.Data.Services.Tests {
[TestFixture]
public class QueryInterceptorAttributeTests {
[Test]
public void Ctor()
{
var qi = new QueryInterceptorAttribute ("set");
Assert.AreEqual ("set", qi.EntitySetName);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void CtorNull()
{
new QueryInterceptorAttribute (null);
}
}
}

View File

@@ -0,0 +1,167 @@
//
// DataServiceProviderMethods.cs
//
// Author:
// Marek Habersack <grendel@twistedcode.net>
//
// Copyright (c) 2011 Novell, Inc
//
// 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.
#if NET_4_0
using System;
using System.Collections.Generic;
using System.Data.Services.Providers;
using NUnit.Framework;
using MonoTests.Common;
namespace MonoTests.System.Data.Services.Providers
{
[TestFixture]
public class DataServiceProviderMethodsTest
{
[Test]
public void TypeIs ()
{
var rt = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, null, "System", "String", false);
AssertExtensions.Throws<NotImplementedException> (() => {
DataServiceProviderMethods.TypeIs ("test", rt);
}, "#A1");
AssertExtensions.Throws<NotImplementedException> (() => {
DataServiceProviderMethods.TypeIs (null, null);
}, "#A2");
}
[Test]
public void Convert ()
{
var rt = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, null, "System", "String", false);
AssertExtensions.Throws<NotImplementedException> (() => {
DataServiceProviderMethods.Convert ("test", rt);
}, "#A1");
AssertExtensions.Throws<NotImplementedException> (() => {
DataServiceProviderMethods.Convert (null, null);
}, "#A2");
}
[Test]
public void GetSequenceValue ()
{
var rt = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, null, "System", "String", false);
var rp = new ResourceProperty ("Length", ResourcePropertyKind.ComplexType, rt);
AssertExtensions.Throws<NotImplementedException> (() => {
DataServiceProviderMethods.GetSequenceValue<string> ("test", rp);
}, "#A1");
AssertExtensions.Throws<NotImplementedException> (() => {
DataServiceProviderMethods.GetSequenceValue<string> (null, null);
}, "#A2");
}
[Test]
public void GetValue ()
{
var rt = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, null, "System", "String", false);
var rp = new ResourceProperty ("Length", ResourcePropertyKind.ComplexType, rt);
AssertExtensions.Throws<NotImplementedException> (() => {
DataServiceProviderMethods.GetValue ("test", rp);
}, "#A1");
AssertExtensions.Throws<NotImplementedException> (() => {
DataServiceProviderMethods.GetValue (null, null);
}, "#A2");
}
[Test]
public void Compare_String_String ()
{
Assert.AreEqual (1, DataServiceProviderMethods.Compare ("right", "left"), "#A1");
Assert.AreEqual (0, DataServiceProviderMethods.Compare ("right", "right"), "#A2");
Assert.AreEqual (0, DataServiceProviderMethods.Compare (String.Empty, String.Empty), "#A3");
Assert.AreEqual (-1, DataServiceProviderMethods.Compare ("left", "right"), "#A4");
Assert.AreEqual (-1, DataServiceProviderMethods.Compare (null, "right"), "#A5");
Assert.AreEqual (1, DataServiceProviderMethods.Compare ("right", null), "#A6");
Assert.AreEqual (0, DataServiceProviderMethods.Compare ((string)null, (string)null), "#A7");
}
[Test]
public void Compare_Bool_Bool ()
{
Assert.AreEqual (-1, DataServiceProviderMethods.Compare (false, true), "#A1");
Assert.AreEqual (0, DataServiceProviderMethods.Compare (false, false), "#A2");
Assert.AreEqual (1, DataServiceProviderMethods.Compare (true, false), "#A3");
Assert.AreEqual (0, DataServiceProviderMethods.Compare (true, true), "#A4");
}
[Test]
public void Compare_NullableBool_NullableBool ()
{
Assert.AreEqual (-1, DataServiceProviderMethods.Compare ((bool?) false, (bool?) true), "#A1");
Assert.AreEqual (0, DataServiceProviderMethods.Compare ((bool?) false, (bool?) false), "#A2");
Assert.AreEqual (1, DataServiceProviderMethods.Compare ((bool?) true, (bool?) false), "#A3");
Assert.AreEqual (0, DataServiceProviderMethods.Compare ((bool?) true, (bool?) true), "#A4");
Assert.AreEqual (1, DataServiceProviderMethods.Compare ((bool?) false, null), "#B1");
Assert.AreEqual (1, DataServiceProviderMethods.Compare ((bool?) true, null), "#B2");
Assert.AreEqual (-1, DataServiceProviderMethods.Compare (null, (bool?)false), "#B3");
Assert.AreEqual (-1, DataServiceProviderMethods.Compare (null, (bool?) true), "#B4");
Assert.AreEqual (0, DataServiceProviderMethods.Compare ((bool?) null, (bool?) null), "#B5");
}
[Test]
public void Compare_Guid_Guid ()
{
var guid1 = new Guid ("bdec809c-f8c5-4bc9-8b56-fb34a12a3e1c");
var guid2 = new Guid ("898b2fe2-3530-4f56-85de-79344e59a90f");
Assert.AreEqual (1, DataServiceProviderMethods.Compare (guid1, guid2), "#A1");
Assert.AreEqual (0, DataServiceProviderMethods.Compare (guid1, guid1), "#A2");
Assert.AreEqual (-1, DataServiceProviderMethods.Compare (guid2, guid1), "#A3");
guid1 = new Guid ("00000000-0000-0000-0000-000000000000");
guid2 = new Guid ("00000000-0000-0000-0000-000000000001");
Assert.AreEqual (-1, DataServiceProviderMethods.Compare (guid1, guid2), "#B1");
Assert.AreEqual (1, DataServiceProviderMethods.Compare (guid2, guid1), "#B2");
}
[Test]
public void Compare_NullableGuid_NullableGuid ()
{
var guid1 = new Guid ("bdec809c-f8c5-4bc9-8b56-fb34a12a3e1c");
var guid2 = new Guid ("898b2fe2-3530-4f56-85de-79344e59a90f");
Assert.AreEqual (1, DataServiceProviderMethods.Compare (guid1, guid2), "#A1");
Assert.AreEqual (0, DataServiceProviderMethods.Compare (guid1, guid1), "#A2");
Assert.AreEqual (-1, DataServiceProviderMethods.Compare (guid2, guid1), "#A3");
guid1 = new Guid ("00000000-0000-0000-0000-000000000000");
guid2 = new Guid ("00000000-0000-0000-0000-000000000001");
Assert.AreEqual (-1, DataServiceProviderMethods.Compare (guid1, guid2), "#B1");
Assert.AreEqual (1, DataServiceProviderMethods.Compare (guid2, guid1), "#B2");
Assert.AreEqual (1, DataServiceProviderMethods.Compare ((Guid?)guid1, (Guid?)null), "#C1");
Assert.AreEqual (0, DataServiceProviderMethods.Compare ((Guid?)null, (Guid?)null), "#C2");
Assert.AreEqual (-1, DataServiceProviderMethods.Compare ((Guid?) null, (Guid?)guid1), "#C3");
}
}
}
#endif

View File

@@ -0,0 +1,135 @@
//
// DataServiceProviderMethods.cs
//
// Author:
// Marek Habersack <grendel@twistedcode.net>
//
// Copyright (c) 2011 Novell, Inc
//
// 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.
#if NET_4_0
using System;
using System.Collections.Generic;
using System.Data.Services.Providers;
using NUnit.Framework;
using MonoTests.Common;
namespace MonoTests.System.Data.Services.Providers
{
[TestFixture]
public class ResourceTypeTest
{
[Test]
public void Constructor ()
{
var dummy = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, null, "System", "String", false);
ResourceType rt;
AssertExtensions.Throws<ArgumentNullException> (() => {
rt = new ResourceType (null, ResourceTypeKind.ComplexType, dummy, "System", "Null", false);
}, "#A1-1");
AssertExtensions.Throws<ArgumentNullException> (() => {
rt = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, dummy, "System", null, false);
}, "#A1-2");
AssertExtensions.Throws<ArgumentNullException> (() => {
rt = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, dummy, null, null, false);
}, "#A1-3");
AssertExtensions.Throws<ArgumentNullException> (() => {
rt = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, dummy, "System", String.Empty, false);
}, "#A1-4");
AssertExtensions.Throws<ArgumentException> (() => {
rt = new ResourceType (typeof (string), ResourceTypeKind.Primitive, null, "System", "String", false);
}, "#A2-1");
AssertExtensions.Throws<ArgumentException> (() => {
rt = new ResourceType (typeof (bool), ResourceTypeKind.Primitive, null, "System", "Bool", false);
}, "#A2-2");
AssertExtensions.Throws<ArgumentException> (() => {
rt = new ResourceType (typeof (int), ResourceTypeKind.EntityType, null, "System", "Int32", true);
}, "#A2-3");
rt = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, dummy, null, "String", false);
Assert.AreEqual (typeof (string), rt.InstanceType, "#B1-1");
Assert.AreEqual (ResourceTypeKind.ComplexType, rt.ResourceTypeKind, "#B1-2");
Assert.AreEqual (dummy, rt.BaseType, "#B1-3");
Assert.AreEqual (String.Empty, rt.Namespace, "#B1-4");
Assert.AreEqual ("String", rt.Name, "#B1-5");
Assert.AreEqual (false, rt.IsAbstract, "#B1-6");
Assert.AreEqual ("String", rt.FullName, "#B1-7");
rt = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, dummy, String.Empty, "String", false);
Assert.AreEqual (typeof (string), rt.InstanceType, "#B2-1");
Assert.AreEqual (ResourceTypeKind.ComplexType, rt.ResourceTypeKind, "#B2-2");
Assert.AreEqual (dummy, rt.BaseType, "#B2-3");
Assert.AreEqual (String.Empty, rt.Namespace, "#B2-4");
Assert.AreEqual ("String", rt.Name, "#B2-5");
Assert.AreEqual (false, rt.IsAbstract, "#B2-6");
Assert.AreEqual ("String", rt.FullName, "#B2-7");
rt = new ResourceType (typeof (string), ResourceTypeKind.ComplexType, null, "System", "String", false);
Assert.AreEqual (typeof (string), rt.InstanceType, "#B3-1");
Assert.AreEqual (ResourceTypeKind.ComplexType, rt.ResourceTypeKind, "#B3-2");
Assert.AreEqual (null, rt.BaseType, "#B3-3");
Assert.AreEqual ("System", rt.Namespace, "#B3-4");
Assert.AreEqual ("String", rt.Name, "#B3-5");
Assert.AreEqual (false, rt.IsAbstract, "#B3-6");
Assert.AreEqual ("System.String", rt.FullName, "#B3-7");
rt = new ResourceType (typeof (string), ResourceTypeKind.EntityType, null, "System", "String", false);
Assert.AreEqual (typeof (string), rt.InstanceType, "#B4-1");
Assert.AreEqual (ResourceTypeKind.EntityType, rt.ResourceTypeKind, "#B4-2");
Assert.AreEqual (null, rt.BaseType, "#B4-3");
Assert.AreEqual ("System", rt.Namespace, "#B4-4");
Assert.AreEqual ("String", rt.Name, "#B4-5");
Assert.AreEqual (false, rt.IsAbstract, "#B4-6");
Assert.AreEqual ("System.String", rt.FullName, "#B4-7");
rt = new ResourceType (typeof (string), ResourceTypeKind.EntityType, null, "System", "String", true);
Assert.AreEqual (typeof (string), rt.InstanceType, "#B5-1");
Assert.AreEqual (ResourceTypeKind.EntityType, rt.ResourceTypeKind, "#B5-2");
Assert.AreEqual (null, rt.BaseType, "#B5-3");
Assert.AreEqual ("System", rt.Namespace, "#B5-4");
Assert.AreEqual ("String", rt.Name, "#B5-5");
Assert.AreEqual (true, rt.IsAbstract, "#B5-6");
Assert.AreEqual ("System.String", rt.FullName, "#B5-7");
}
[Test]
public void CanReflectOnInstanceType ()
{
var rt = new ResourceType (typeof (string), ResourceTypeKind.EntityType, null, "System", "String", true);
Assert.AreEqual (true, rt.CanReflectOnInstanceType, "#A1-1");
rt.CanReflectOnInstanceType = false;
Assert.AreEqual (false, rt.CanReflectOnInstanceType, "#A1-2");
rt = new ResourceType (typeof (ResourceTypeTest), ResourceTypeKind.ComplexType, null, "MonoTests.System.Data.Services.Providers", "ResourceTypeTest", true);
Assert.AreEqual (true, rt.CanReflectOnInstanceType, "#A2-1");
rt.CanReflectOnInstanceType = false;
Assert.AreEqual (false, rt.CanReflectOnInstanceType, "#A2-2");
}
}
}
#endif