Skip to content

Commit 8554c24

Browse files
committed
Initial commit
1 parent 55ce187 commit 8554c24

File tree

8 files changed

+240
-0
lines changed

8 files changed

+240
-0
lines changed

Eat.Tests/Eat.Tests.csproj

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\packages\NUnit.3.11.0\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.11.0\build\NUnit.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{E1B4341D-9BA0-4A88-A83E-70C686BB4D9D}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<RootNamespace>Eat.Tests</RootNamespace>
10+
<AssemblyName>Eat.Tests</AssemblyName>
11+
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
12+
</PropertyGroup>
13+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
14+
<DebugSymbols>true</DebugSymbols>
15+
<DebugType>full</DebugType>
16+
<Optimize>false</Optimize>
17+
<OutputPath>bin\Debug</OutputPath>
18+
<DefineConstants>DEBUG;</DefineConstants>
19+
<ErrorReport>prompt</ErrorReport>
20+
<WarningLevel>4</WarningLevel>
21+
</PropertyGroup>
22+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
23+
<Optimize>true</Optimize>
24+
<OutputPath>bin\Release</OutputPath>
25+
<ErrorReport>prompt</ErrorReport>
26+
<WarningLevel>4</WarningLevel>
27+
</PropertyGroup>
28+
<ItemGroup>
29+
<Reference Include="System" />
30+
<Reference Include="nunit.framework">
31+
<HintPath>..\packages\NUnit.3.11.0\lib\net45\nunit.framework.dll</HintPath>
32+
</Reference>
33+
</ItemGroup>
34+
<ItemGroup>
35+
<Compile Include="Test.cs" />
36+
</ItemGroup>
37+
<ItemGroup>
38+
<None Include="packages.config" />
39+
</ItemGroup>
40+
<ItemGroup>
41+
<ProjectReference Include="..\Eat\Eat.csproj">
42+
<Project>{9CFCA22E-0EB7-42D1-A26F-82EFD95FCADF}</Project>
43+
<Name>Eat</Name>
44+
</ProjectReference>
45+
</ItemGroup>
46+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
47+
</Project>

Eat.Tests/Test.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using NUnit.Framework;
2+
using System;
3+
4+
namespace Eat.Tests
5+
{
6+
[TestFixture]
7+
public class TestEat
8+
{
9+
[Test]
10+
public void IsExceptionThrown_Should_ReturnFalse_When_NoExceptionIsThrown()
11+
{
12+
var isException = Eat.IsExceptionThrown(() => { Console.WriteLine("Doing something that doesn't throw an exception."); });
13+
Assert.IsFalse(isException);
14+
}
15+
16+
[Test]
17+
public void IsExceptionThrown_Should_ReturnTrue_When_ExceptionIsThrown()
18+
{
19+
var isException = Eat.IsExceptionThrown(() => { throw new Exception("test"); });
20+
Assert.IsTrue(isException);
21+
}
22+
23+
[Test]
24+
public void Exception_Should_Continue_When_ExceptionIsThrown()
25+
{
26+
Eat.Exception(() => { throw new Exception("test"); });
27+
Assert.Pass();
28+
}
29+
30+
[Test]
31+
public void Exception_Should_ReturnValue_When_NoExceptionIsThrown()
32+
{
33+
var result = Eat.Exception(() => { return "test"; }, "defaultValue");
34+
Assert.AreEqual("test", result);
35+
}
36+
37+
[Test]
38+
public void Exception_Should_ReturnDefaultValueString_When_ExceptionIsThrown()
39+
{
40+
var result = Eat.Exception(() => { throw new Exception("test"); }, "defaultValue");
41+
Assert.AreEqual("defaultValue", result);
42+
}
43+
44+
[Test]
45+
public void Exception_Should_ReturnDefaultValueNull_When_ExceptionIsThrown()
46+
{
47+
var result = Eat.Exception<string>(() => { throw new Exception("test"); }, null);
48+
Assert.IsNull(result);
49+
}
50+
}
51+
}

Eat.Tests/packages.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="NUnit" version="3.11.0" targetFramework="net47" />
4+
</packages>

Eat.sln

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eat", "Eat\Eat.csproj", "{9CFCA22E-0EB7-42D1-A26F-82EFD95FCADF}"
5+
EndProject
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eat.Tests", "Eat.Tests\Eat.Tests.csproj", "{E1B4341D-9BA0-4A88-A83E-70C686BB4D9D}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{9CFCA22E-0EB7-42D1-A26F-82EFD95FCADF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{9CFCA22E-0EB7-42D1-A26F-82EFD95FCADF}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{9CFCA22E-0EB7-42D1-A26F-82EFD95FCADF}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{9CFCA22E-0EB7-42D1-A26F-82EFD95FCADF}.Release|Any CPU.Build.0 = Release|Any CPU
18+
{E1B4341D-9BA0-4A88-A83E-70C686BB4D9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{E1B4341D-9BA0-4A88-A83E-70C686BB4D9D}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{E1B4341D-9BA0-4A88-A83E-70C686BB4D9D}.Release|Any CPU.ActiveCfg = Release|Any CPU
21+
{E1B4341D-9BA0-4A88-A83E-70C686BB4D9D}.Release|Any CPU.Build.0 = Release|Any CPU
22+
EndGlobalSection
23+
EndGlobal

Eat/Eat.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
namespace Eat
3+
{
4+
public static class Eat
5+
{
6+
public static bool IsExceptionThrown(Action it)
7+
{
8+
try
9+
{
10+
it.Invoke();
11+
}
12+
catch
13+
{
14+
return true;
15+
}
16+
return false;
17+
}
18+
19+
public static void Exception(Action it)
20+
{
21+
try
22+
{
23+
it.Invoke();
24+
}
25+
catch
26+
{
27+
}
28+
}
29+
30+
public static T Exception<T>(Func<T> it, T defaultValue)
31+
{
32+
try
33+
{
34+
return it();
35+
}
36+
catch
37+
{
38+
return defaultValue;
39+
}
40+
}
41+
}
42+
}

Eat/Eat.csproj

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\packages\NuGet.Build.Packaging.0.2.0\build\NuGet.Build.Packaging.props" Condition="Exists('..\packages\NuGet.Build.Packaging.0.2.0\build\NuGet.Build.Packaging.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{9CFCA22E-0EB7-42D1-A26F-82EFD95FCADF}</ProjectGuid>
8+
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
9+
<OutputType>Library</OutputType>
10+
<RootNamespace>Eat</RootNamespace>
11+
<AssemblyName>Eat</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<TargetFrameworkProfile>Profile111</TargetFrameworkProfile>
14+
<PackageId>Eat</PackageId>
15+
<PackageVersion>1.0.0</PackageVersion>
16+
<Authors>Ben Barth</Authors>
17+
<Description>Eat</Description>
18+
</PropertyGroup>
19+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
20+
<DebugSymbols>true</DebugSymbols>
21+
<DebugType>full</DebugType>
22+
<Optimize>false</Optimize>
23+
<OutputPath>bin\Debug</OutputPath>
24+
<DefineConstants>DEBUG;</DefineConstants>
25+
<ErrorReport>prompt</ErrorReport>
26+
<WarningLevel>4</WarningLevel>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release</OutputPath>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Compile Include="Eat.cs" />
36+
<Compile Include="Properties\AssemblyInfo.cs" />
37+
</ItemGroup>
38+
<ItemGroup>
39+
<None Include="packages.config" />
40+
</ItemGroup>
41+
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
42+
<Import Project="..\packages\NuGet.Build.Packaging.0.2.0\build\NuGet.Build.Packaging.targets" Condition="Exists('..\packages\NuGet.Build.Packaging.0.2.0\build\NuGet.Build.Packaging.targets')" />
43+
</Project>

Eat/Properties/AssemblyInfo.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
4+
// Information about this assembly is defined by the following attributes.
5+
// Change them to the values specific to your project.
6+
7+
[assembly: AssemblyTitle("Eat")]
8+
[assembly: AssemblyDescription("")]
9+
[assembly: AssemblyConfiguration("")]
10+
[assembly: AssemblyCompany("")]
11+
[assembly: AssemblyProduct("")]
12+
[assembly: AssemblyCopyright("")]
13+
[assembly: AssemblyTrademark("")]
14+
[assembly: AssemblyCulture("")]
15+
16+
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
17+
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
18+
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
19+
20+
[assembly: AssemblyVersion("1.0.0.0")]
21+
22+
// The following attributes are used to specify the signing key for the assembly,
23+
// if desired. See the Mono documentation for more information about signing.
24+
25+
//[assembly: AssemblyDelaySign(false)]
26+
//[assembly: AssemblyKeyFile("")]

Eat/packages.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="NuGet.Build.Packaging" version="0.2.0" targetFramework="portable45-net45+win8+wpa81" developmentDependency="true" />
4+
</packages>

0 commit comments

Comments
 (0)