Skip to content

Commit

Permalink
Add projects for settigs and extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
justinyoo committed Oct 26, 2017
1 parent c79a34c commit fe53f53
Show file tree
Hide file tree
Showing 10 changed files with 333 additions and 0 deletions.
14 changes: 14 additions & 0 deletions AglCodingTest.sln
Expand Up @@ -28,6 +28,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AglCodingTest.Models.Tests"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AglCodingTest.Services.Tests", "test\AglCodingTest.Services.Tests\AglCodingTest.Services.Tests.csproj", "{9BB791C9-FC8A-47F9-817F-D15ACB5621A5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AglCodingTest.Extensions", "src\AglCodingTest.Extensions\AglCodingTest.Extensions.csproj", "{B6BB1C52-6B75-4316-B50B-9A6A160B2252}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AglCodingTest.Settings", "src\AglCodingTest.Settings\AglCodingTest.Settings.csproj", "{074176DE-E0ED-455C-814B-C96C5C3E85DF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -58,6 +62,14 @@ Global
{9BB791C9-FC8A-47F9-817F-D15ACB5621A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9BB791C9-FC8A-47F9-817F-D15ACB5621A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9BB791C9-FC8A-47F9-817F-D15ACB5621A5}.Release|Any CPU.Build.0 = Release|Any CPU
{B6BB1C52-6B75-4316-B50B-9A6A160B2252}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B6BB1C52-6B75-4316-B50B-9A6A160B2252}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B6BB1C52-6B75-4316-B50B-9A6A160B2252}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B6BB1C52-6B75-4316-B50B-9A6A160B2252}.Release|Any CPU.Build.0 = Release|Any CPU
{074176DE-E0ED-455C-814B-C96C5C3E85DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{074176DE-E0ED-455C-814B-C96C5C3E85DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{074176DE-E0ED-455C-814B-C96C5C3E85DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{074176DE-E0ED-455C-814B-C96C5C3E85DF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -69,6 +81,8 @@ Global
{C7D5BBB5-482D-49F6-9E0E-9F33F95A64CD} = {74F77911-DFA1-428E-9C09-71334FD246A4}
{E8B18210-35FE-4DA5-8394-08C698AC8BE6} = {DFC84156-3B71-474C-A6AD-91D119C04EAF}
{9BB791C9-FC8A-47F9-817F-D15ACB5621A5} = {DFC84156-3B71-474C-A6AD-91D119C04EAF}
{B6BB1C52-6B75-4316-B50B-9A6A160B2252} = {74F77911-DFA1-428E-9C09-71334FD246A4}
{074176DE-E0ED-455C-814B-C96C5C3E85DF} = {74F77911-DFA1-428E-9C09-71334FD246A4}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {938129C8-CBE0-4346-B677-9B44A7D7A0D9}
Expand Down
52 changes: 52 additions & 0 deletions src/AglCodingTest.Extensions/AglCodingTest.Extensions.csproj
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{B6BB1C52-6B75-4316-B50B-9A6A160B2252}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AglCodingTest.Extensions</RootNamespace>
<AssemblyName>AglCodingTest.Extensions</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Legacy2CPSWorkaround" Version="1.0.0">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="GenericExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
38 changes: 38 additions & 0 deletions src/AglCodingTest.Extensions/GenericExtensions.cs
@@ -0,0 +1,38 @@
using System;

namespace AglCodingTest.Extensions
{
/// <summary>
/// This represents the extension entity for generic.
/// </summary>
public static class GenericExtensions
{
/// <summary>
/// Checks whether the given instance is <c>null</c> or empty.
/// </summary>
/// <typeparam name="T">Type of instance.</typeparam>
/// <param name="instance">Instance to check.</param>
/// <returns>Returns <c>True</c>, if the original instance is <c>null</c> or empty; otherwise returns <c>False</c>.</returns>
public static bool IsNullOrDefault<T>(this T instance)
{
return instance == null || instance.Equals(default(T));
}

/// <summary>
/// Throws an <see cref="ArgumentNullException"/> if the given instance is <c>null</c> or empty.
/// </summary>
/// <typeparam name="T">Type of instance.</typeparam>
/// <param name="instance">Instance to check.</param>
/// <returns>Returns the original instance, if the instance is NOT <c>null</c>; otherwise throws an <see cref="ArgumentNullException"/>.</returns>
/// <exception cref="ArgumentNullException"><paramref name="instance"/> is <see langword="null"/></exception>
public static T ThrowIfNullOrDefault<T>(this T instance)
{
if (instance.IsNullOrDefault())
{
throw new ArgumentNullException(nameof(instance));
}

return instance;
}
}
}
36 changes: 36 additions & 0 deletions src/AglCodingTest.Extensions/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("AglCodingTest.Extensions")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AglCodingTest.Extensions")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("b6bb1c52-6b75-4316-b50b-9a6a160b2252")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
61 changes: 61 additions & 0 deletions src/AglCodingTest.Settings/AglCodingTest.Settings.csproj
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{074176DE-E0ED-455C-814B-C96C5C3E85DF}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AglCodingTest.Settings</RootNamespace>
<AssemblyName>AglCodingTest.Settings</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Legacy2CPSWorkaround" Version="1.0.0">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>9.0.1</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http.Formatting">
<HintPath>..\..\..\..\..\Users\Justin\.nuget\packages\microsoft.aspnet.webapi.client\5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AglSettings.cs" />
<Compile Include="AppSettings.cs" />
<Compile Include="ConnectionStringSettings.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="StorageAccountSettings.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
17 changes: 17 additions & 0 deletions src/AglCodingTest.Settings/AglSettings.cs
@@ -0,0 +1,17 @@
using System;

namespace AglCodingTest.Settings
{
/// <summary>
/// This represents the settings entity for AGL coding test.
/// </summary>
public class AglSettings
{
private const string AglEndpoint = "Agl.Endpoint";

/// <summary>
/// Gets the endpoint URL.
/// </summary>
public virtual string Endpoint => Environment.GetEnvironmentVariable(AglEndpoint);
}
}
51 changes: 51 additions & 0 deletions src/AglCodingTest.Settings/AppSettings.cs
@@ -0,0 +1,51 @@
using System.Net.Http.Formatting;

using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;

namespace AglCodingTest.Settings
{
/// <summary>
/// This represents the app settings entity.
/// </summary>
public class AppSettings
{
/// <summary>
/// Initializes a new instance of the <see cref="AppSettings"/> class.
/// </summary>
public AppSettings()
{
var serialiserSettings = new JsonSerializerSettings()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
Converters = { new StringEnumConverter() },
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore,
MissingMemberHandling = MissingMemberHandling.Ignore
};
this.SerialiserSettings = serialiserSettings;
this.Formatter = new JsonMediaTypeFormatter() { SerializerSettings = serialiserSettings };
}

/// <summary>
/// Gets the <see cref="StorageAccountSettings"/> instance.
/// </summary>
public virtual StorageAccountSettings StorageAccount => new StorageAccountSettings();

/// <summary>
/// Gets the <see cref="AglSettings"/> instance.
/// </summary>
public virtual AglSettings Agl => new AglSettings();

/// <summary>
/// Gets the <see cref="JsonSerializerSettings"/> instance.
/// </summary>
public virtual JsonSerializerSettings SerialiserSettings { get; }

/// <summary>
/// Gets the <see cref="MediaTypeFormatter"/> instance.
/// </summary>
public virtual MediaTypeFormatter Formatter { get; }
}
}
13 changes: 13 additions & 0 deletions src/AglCodingTest.Settings/ConnectionStringSettings.cs
@@ -0,0 +1,13 @@
namespace AglCodingTest.Settings
{
/// <summary>
/// This represents the base settings entity for connection strings.
/// </summary>
public abstract class ConnectionStringSettings
{
/// <summary>
/// Gets the connection string value.
/// </summary>
public virtual string ConnectionString => string.Empty;
}
}
36 changes: 36 additions & 0 deletions src/AglCodingTest.Settings/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("AglCodingTest.Settings")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AglCodingTest.Settings")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("074176de-e0ed-455c-814b-c96c5c3e85df")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
15 changes: 15 additions & 0 deletions src/AglCodingTest.Settings/StorageAccountSettings.cs
@@ -0,0 +1,15 @@
using System;

namespace AglCodingTest.Settings
{
/// <summary>
/// This represents the settings entity for storage account.
/// </summary>
public class StorageAccountSettings : ConnectionStringSettings
{
private const string AzureWebJobsStorageKey = "AzureWebJobsStorage";

/// <inheritdoc />
public override string ConnectionString => Environment.GetEnvironmentVariable(AzureWebJobsStorageKey);
}
}

0 comments on commit fe53f53

Please sign in to comment.