Skip to content

Commit

Permalink
Added integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JSkimming committed Aug 3, 2015
1 parent 0da8869 commit 923ae70
Show file tree
Hide file tree
Showing 14 changed files with 249 additions and 14 deletions.
22 changes: 8 additions & 14 deletions src/CloudFlare.NET/Zone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/// <seealso href="https://api.cloudflare.com/#zone-properties"/>
public class Zone
{
private static readonly IReadOnlyList<string> EmptyString = Enumerable.Empty<string>().ToList();
private static readonly IReadOnlyList<string> EmptyStrings = Enumerable.Empty<string>().ToArray();

/// <summary>
/// Initializes a new instance of the <see cref="Zone"/> class.
Expand All @@ -20,33 +20,27 @@ public Zone(
IdentifierTag id,
string name,
int developmentMode,
IReadOnlyList<string> originalNameServers,
string originalRegistrar,
string originalDnshost,
DateTimeOffset createdOn,
DateTimeOffset modifiedOn,
IReadOnlyList<string> originalNameServers = null,
string originalRegistrar = null,
string originalDnshost = null,
IReadOnlyList<string> nameServers = null)
{
if (id == null)
throw new ArgumentNullException(nameof(id));
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentNullException(nameof(name));
if (originalNameServers == null)
throw new ArgumentNullException(nameof(originalNameServers));
if (string.IsNullOrWhiteSpace(originalRegistrar))
throw new ArgumentNullException(nameof(originalRegistrar));
if (string.IsNullOrWhiteSpace(originalDnshost))
throw new ArgumentNullException(nameof(originalDnshost));

Id = id;
Name = name;
DevelopmentMode = developmentMode;
OriginalNameServers = originalNameServers;
OriginalRegistrar = originalRegistrar;
OriginalDnshost = originalDnshost;
OriginalNameServers = originalNameServers ?? EmptyStrings;
OriginalRegistrar = originalRegistrar ?? string.Empty;
OriginalDnshost = originalDnshost ?? string.Empty;
CreatedOn = createdOn;
ModifiedOn = modifiedOn;
NameServers = nameServers ?? EmptyString;
NameServers = nameServers ?? EmptyStrings;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" 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>{B6869F85-BD98-418D-89F7-7E15BB9F1240}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CloudFlare.NET</RootNamespace>
<AssemblyName>CloudFlare.NET.IntegrationTests</AssemblyName>
<TargetFrameworkVersion>v4.6</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>
<Reference Include="Machine.Specifications, Version=0.9.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Machine.Specifications.0.9.3\lib\net45\Machine.Specifications.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Machine.Specifications.Clr4, Version=0.9.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Machine.Specifications.0.9.3\lib\net45\Machine.Specifications.Clr4.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Machine.Specifications.Should, Version=0.7.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Machine.Specifications.Should.0.7.2\lib\net45\Machine.Specifications.Should.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.Extensions, Version=2.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Extensions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net.Http.Primitives, Version=4.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Primitives.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net.Http.WebRequest" />
</ItemGroup>
<ItemGroup>
<Compile Include="Helper.cs" />
<Compile Include="ZonesSpec.cs" />
<None Include="app.config" />
<None Include="packages.config" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\CloudFlare.NET\CloudFlare.NET.csproj">
<Project>{895ae2d8-6602-406e-b2ed-7ca9bc3174a5}</Project>
<Name>CloudFlare.NET</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
</Target>
<Import Project="..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CheckNamespace/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=InconsistentNaming/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UnusedMember_002ELocal/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/EXPLICIT_PRIVATE_MODIFIER/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Binary file not shown.
30 changes: 30 additions & 0 deletions src/Tests/CloudFlare.NET.IntegrationTests/Helper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace CloudFlare.NET
{
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;

internal static class Helper
{
public static string AuthEmail { get; } = Environment.GetEnvironmentVariable("CloudFlare.NET.AuthEmail");

public static string AuthKey { get; } = Environment.GetEnvironmentVariable("CloudFlare.NET.AuthKey");

/// <summary>
/// Gets the setting my the <paramref name="name"/>.
/// </summary>
/// <param name="name">The name of the setting.</param>
/// <returns>The setting my the <paramref name="name"/>.</returns>
public static string GetSetting(string name)
{
if (name == null)
throw new ArgumentNullException(nameof(name));

return ("True".Equals(Environment.GetEnvironmentVariable("APPVEYOR"), StringComparison.OrdinalIgnoreCase)
? Environment.GetEnvironmentVariable(name)
: ConfigurationManager.AppSettings[name])
?? string.Empty;
}
}
}
Original file line number Diff line number Diff line change
@@ -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("CloudFlare.NET.IntegrationTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CloudFlare.NET.IntegrationTests")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[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("b6869f85-bd98-418d-89f7-7e15bb9f1240")]

// 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")]
25 changes: 25 additions & 0 deletions src/Tests/CloudFlare.NET.IntegrationTests/ZonesSpec.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace CloudFlare.NET
{
using System;
using System.Collections.Generic;
using System.Linq;
using Machine.Specifications;

[Subject("Zones")]
public class ZonesSpec
{
static ICloudFlareClient _client;
static CloudFlareAuth _auth;
static IReadOnlyList<Zone> _zones;

Establish context = () =>
{
_client = new CloudFlareClient();
_auth = new CloudFlareAuth(Helper.AuthEmail, Helper.AuthKey);
};

Because of = () => _zones = _client.GetZonesAsync(_auth).Await().AsTask.Result;

It should_return_the_zones = () => _zones.ShouldNotBeEmpty();
}
}
15 changes: 15 additions & 0 deletions src/Tests/CloudFlare.NET.IntegrationTests/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.29.0" newVersion="4.2.29.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
8 changes: 8 additions & 0 deletions src/Tests/CloudFlare.NET.IntegrationTests/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Machine.Specifications" version="0.9.3" targetFramework="net46" />
<package id="Machine.Specifications.Should" version="0.7.2" targetFramework="net46" />
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="net46" />
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net46" />
<package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net46" />
</packages>
1 change: 1 addition & 0 deletions src/Tests/CloudFlare.NET.Tests/CloudFlare.NET.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
<EmbeddedResource Include="Serialization\ErrorResponse.json" />
<EmbeddedResource Include="Serialization\SuccessResponse.json" />
<EmbeddedResource Include="Serialization\Zone.json" />
<EmbeddedResource Include="Serialization\ZoneMinimal.json" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\CloudFlare.NET\CloudFlare.NET.csproj">
Expand Down
2 changes: 2 additions & 0 deletions src/Tests/CloudFlare.NET.Tests/Serialization/SampleJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ public static JObject Load(string fileName)
public static JObject SuccessResponse => Load(nameof(SuccessResponse));

public static JObject Zone => Load(nameof(Zone));

public static JObject ZoneMinimal => Load(nameof(ZoneMinimal));
}
}
4 changes: 4 additions & 0 deletions src/Tests/CloudFlare.NET.Tests/Serialization/ZoneMinimal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"id": "9a7806061c88ada191ed06f989cc3dac",
"name": "example.com"
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,21 @@ public class When_deserializing_zone
It should_deserialize_name_servers =
() => _zone.NameServers.ShouldContainOnly(_zoneJson["name_servers"].ToObject<List<string>>());
}

[Subject(typeof(Zone))]
public class When_deserializing_zone_minimal
{
static JObject _zoneJson;
static Zone _zone;

Because of = () =>
{
_zoneJson = SampleJson.ZoneMinimal;
_zone = _zoneJson.ToObject<Zone>();
};

It should_deserialize_id = () => _zone.Id.ToString().ShouldEqual(_zoneJson["id"].Value<string>());

It should_deserialize_name = () => _zone.Name.ShouldEqual(_zoneJson["name"].Value<string>());
}
}
7 changes: 7 additions & 0 deletions src/cloudflare.net.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{872E03EB
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CloudFlare.NET.Tests", "Tests\CloudFlare.NET.Tests\CloudFlare.NET.Tests.csproj", "{33243227-AB2D-45FE-ABD3-2473A50CFD9B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CloudFlare.NET.IntegrationTests", "Tests\CloudFlare.NET.IntegrationTests\CloudFlare.NET.IntegrationTests.csproj", "{B6869F85-BD98-418D-89F7-7E15BB9F1240}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -23,11 +25,16 @@ Global
{33243227-AB2D-45FE-ABD3-2473A50CFD9B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{33243227-AB2D-45FE-ABD3-2473A50CFD9B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{33243227-AB2D-45FE-ABD3-2473A50CFD9B}.Release|Any CPU.Build.0 = Release|Any CPU
{B6869F85-BD98-418D-89F7-7E15BB9F1240}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B6869F85-BD98-418D-89F7-7E15BB9F1240}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B6869F85-BD98-418D-89F7-7E15BB9F1240}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B6869F85-BD98-418D-89F7-7E15BB9F1240}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{33243227-AB2D-45FE-ABD3-2473A50CFD9B} = {872E03EB-A9C9-45C8-9644-8442B9CF5C4F}
{B6869F85-BD98-418D-89F7-7E15BB9F1240} = {872E03EB-A9C9-45C8-9644-8442B9CF5C4F}
EndGlobalSection
EndGlobal

0 comments on commit 923ae70

Please sign in to comment.