Skip to content

A MonoTouch port #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix issue with reading plist config, adding in more unit tests, remov…
…ing use of Rhino.Mock
  • Loading branch information
adamnation committed Jul 15, 2013
commit f7aaa5957af2f0147399cd8627ca7af6b13c27dc
Binary file modified src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,21 @@
</ItemGroup>
<ItemGroup>
<None Include="Info.plist" />
<None Include="Settings.bundle\Common.Logging.plist" />
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="UnitTestAppDelegate.cs" />
<Compile Include="Logging\SImple\ConsoleOutLoggerTests.cs" />
<Compile Include="Logging\SImple\AbstractSimpleLoggerTests.cs" />
<Compile Include="Logging\SImple\AbstractSimpleLoggerTestsBase.cs" />
<Compile Include="Logging\Configuration\ArgUtilsTests.cs" />
<Compile Include="Logging\Factory\AbstractLoggerTests.cs" />
<Compile Include="Logging\Configuration\MonoTouchConfigurationReaderTests.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<BundleResource Include="Settings.bundle\Root.plist" />
<BundleResource Include="Settings.bundle\Common.Logging.plist" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common.Logging.MonoTouch\Common.Logging.MonoTouch.csproj">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
#region License

/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#endregion

using System;
using System.Collections.Specialized;
using System.Runtime.Serialization;
using NUnit.Framework;

namespace Common.Logging.Configuration
{
/// <summary>
/// </summary>
/// <author>Erich Eichinger</author>
[TestFixture]
public class ArgUtilsTests
{
[Test]
public void GetValue()
{
NameValueCollection nvc = new NameValueCollection();
nvc["key"] = "value";

Assert.AreEqual( null, ArgUtils.GetValue(null, "key"));
Assert.AreEqual("value", ArgUtils.GetValue(nvc, "key"));
Assert.AreEqual(null, ArgUtils.GetValue(nvc, "wrongkey"));
Assert.AreEqual("defaultValue", ArgUtils.GetValue(null, "wrongkey", "defaultValue"));
Assert.AreEqual("defaultValue", ArgUtils.GetValue(nvc, "wrongkey", "defaultValue"));
}

[Test]
public void Coalesce()
{
Assert.AreEqual(null, ArgUtils.Coalesce());
Assert.AreEqual(null, ArgUtils.Coalesce(null, null));
Assert.AreEqual("x", ArgUtils.Coalesce(string.Empty, null, "x"));
// null predicate causes the use the default predicate of (v!=null)
Assert.AreEqual(string.Empty, ArgUtils.Coalesce( (Predicate<string>)null, string.Empty, (string)null, "x"));
Assert.AreEqual(null, ArgUtils.Coalesce<object>( delegate(object v) { return v != null; } ));
Assert.AreEqual(string.Empty, ArgUtils.Coalesce<object>( delegate(object v) { return v != null; }, null, string.Empty, "x"));
}

[Test]
public void TryParseEnum()
{
Assert.Throws(
Is.TypeOf<ArgumentException>().And.Message.EqualTo( string.Format("Type '{0}' is not an enum type", typeof(int).FullName) )
, delegate
{
ArgUtils.TryParseEnum((int) 1, "0");
}
);

Assert.AreEqual( LogLevel.Fatal, ArgUtils.TryParseEnum(LogLevel.All, "fatal") );
Assert.AreEqual( LogLevel.Debug, ArgUtils.TryParseEnum(LogLevel.Debug, "invalid value") );
Assert.AreEqual( LogLevel.Debug, ArgUtils.TryParseEnum(LogLevel.Debug, null) );
}

[Test]
public void TryParse()
{
Assert.Throws(
Is.TypeOf<ArgumentException>()
.And.Message.EqualTo(string.Format("There is no parser registered for type {0}", typeof(object).FullName))
, delegate
{
ArgUtils.TryParse(new object(), "0");
}
);

Assert.AreEqual( true, ArgUtils.TryParse(false, "trUE") );
Assert.AreEqual( 1, ArgUtils.TryParse(2, "1") );
Assert.AreEqual( 2, ArgUtils.TryParse(2, "2invalidnumber1") );
Assert.AreEqual( (short)1, ArgUtils.TryParse((short)2, "1") );
Assert.AreEqual( (long)1, ArgUtils.TryParse((long)2, "1") );
Assert.AreEqual( (float)1, ArgUtils.TryParse((float)2, "1") );
Assert.AreEqual( (double)1, ArgUtils.TryParse((double)2, "1") );
Assert.AreEqual( (decimal)1, ArgUtils.TryParse((decimal)2, "1") );
}

[Test]
public void AssertIsAssignable()
{
Assert.Throws(
Is.TypeOf<ArgumentNullException>()
.And.Message.EqualTo(new ArgumentNullException("valType").Message)
, delegate
{
ArgUtils.AssertIsAssignable<IConvertible>("arg", null);
}
);

Assert.Throws(
Is.TypeOf<ArgumentOutOfRangeException>()
.And.Message.EqualTo(new ArgumentOutOfRangeException("this", this.GetType(),string.Format("Type '{0}' of parameter '{1}' is not assignable to target type '{2}'"
, this.GetType().AssemblyQualifiedName
, "this"
, typeof (ISerializable).AssemblyQualifiedName) ).Message)
, delegate
{
ArgUtils.AssertIsAssignable<ISerializable>("this", this.GetType());
}
);

Type type = typeof(Int32);
Assert.AreSame(type, ArgUtils.AssertIsAssignable<IConvertible>("arg", type));
}

[Test]
public void AssertNotNullThrowsArgumentNullException()
{
object tmp = new object();
Assert.AreSame(tmp, ArgUtils.AssertNotNull("arg", tmp));
Assert.Throws(Is.TypeOf<ArgumentNullException>()
.And.Message.EqualTo(new ArgumentNullException("tmp").Message),
delegate { ArgUtils.AssertNotNull("tmp", (object)null); });
Assert.Throws(Is.TypeOf<ArgumentNullException>().And.Message.EqualTo(new ArgumentNullException("tmp", "message msgarg").Message),
delegate { ArgUtils.AssertNotNull("tmp", (object)null, "message {0}", "msgarg"); });
}

[Test]
public void Guard()
{
ArgUtils.Guard(delegate { }, "format {0}", "fmtarg");
Assert.AreEqual(1, ArgUtils.Guard<int>(delegate { return 1; }, "format {0}", "fmtarg"));

Assert.Throws(Is.TypeOf<ConfigurationException>()
.And.Message.EqualTo("innermessage"),
delegate
{
ArgUtils.Guard(delegate { throw new ConfigurationException("innermessage"); }, "format {0}", "fmtarg");
});

Assert.Throws(Is.TypeOf<ConfigurationException>()
.And.Message.EqualTo("format fmtarg"),
delegate
{
ArgUtils.Guard(delegate { throw new ArgumentException("innermessage"); }, "format {0}", "fmtarg");
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#region License

/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#endregion

using System.Collections.Specialized;
using NUnit.Framework;

namespace Common.Logging.Configuration
{
/// <summary>
/// </summary>
/// <author>Erich Eichinger</author>
[TestFixture]
public class MonoTouchConfigurationReaderTests
{
[Test]
public void ReadsAppConfig()
{
Assert.AreEqual("FromAppConfig", ((NameValueCollection)new MonoTouchConfigurationReader().GetSection("Settings.bundle/Common.Logging.plist"))["appConfigCheck"]);
}
}
}
Loading