Skip to content

Commit

Permalink
Initial commit to add some unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bschmidt committed Mar 23, 2018
1 parent 1026c48 commit 0f836af
Show file tree
Hide file tree
Showing 7 changed files with 225 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/Stellar.Tests/Properties/AssemblyInfo.cs
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("Stellar.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Stellar.Tests")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[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("4335f266-3f71-4349-b926-d233307fc2f6")]

// 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")]
22 changes: 22 additions & 0 deletions src/Stellar.Tests/SimpleQueryTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Stellar;
using Xunit;

namespace Tests
{
public class SimpleQueryTest
{
private CosmosDbAccount BogusCosmosDbAccount => new Stellar.CosmosDbAccount(@"http://www.bogusendpoint.com", "bogustoken", "bogusdb", "");

[Fact]
public void SimpleQueryShouldIncludeSelectAndType()
{
var testObjectsQueryAsString = BogusCosmosDbAccount.Documents.Query<TestObject>().ToString().ToLower();

Assert.Contains("select", testObjectsQueryAsString);
Assert.Contains("*", testObjectsQueryAsString);
Assert.Contains("from", testObjectsQueryAsString);
Assert.Contains(typeof(TestObject).Name.ToString().ToLower(), testObjectsQueryAsString);
Assert.Contains("as", testObjectsQueryAsString);
}
}
}
45 changes: 45 additions & 0 deletions src/Stellar.Tests/SimpleQueryWithWhere.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Linq;
using Tests;
using Xunit;

namespace Stellar.Tests
{
public class SimpleQueryWithWhere
{
private CosmosDbAccount BogusCosmosDbAccount => new Stellar.CosmosDbAccount(@"http://www.bogusendpoint.com", "bogustoken", "bogusdb", "");

private const int testValue = 20;

[Fact]
public void WhereClauseShouldIncludeTestCondition()
{
var testObjectsQueryAsString = BogusCosmosDbAccount.Documents.Query<TestObject>()
.Where(x => x.SomeIntProperty == 20)
.ToString().ToLower();

Assert.Contains("where", testObjectsQueryAsString);
Assert.Contains("someintproperty", testObjectsQueryAsString);
Assert.Contains("20", testObjectsQueryAsString);
}

[Fact]
public void WhereClauseShouldIncludeTestValueWhetherLiteralOrFromAVariable()
{
var testObjectsQueryAsString = BogusCosmosDbAccount.Documents.Query<TestObject>()
.Where(x => x.SomeIntProperty == 20)
.ToString().ToLower();

Assert.Contains("where", testObjectsQueryAsString);
Assert.Contains("someintproperty", testObjectsQueryAsString);
Assert.Contains(testValue.ToString(), testObjectsQueryAsString);

var testObjectsQueryWithVariableAsString = BogusCosmosDbAccount.Documents.Query<TestObject>()
.Where(x => x.SomeIntProperty == testValue)
.ToString().ToLower();

Assert.Contains("where", testObjectsQueryWithVariableAsString);
Assert.Contains("someintproperty", testObjectsQueryWithVariableAsString);
Assert.Contains(testValue.ToString(), testObjectsQueryWithVariableAsString);
}
}
}
89 changes: 89 additions & 0 deletions src/Stellar.Tests/Stellar.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props')" />
<Import Project="..\packages\xunit.core.2.3.1\build\xunit.core.props" Condition="Exists('..\packages\xunit.core.2.3.1\build\xunit.core.props')" />
<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>{4335F266-3F71-4349-B926-D233307FC2F6}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Stellar.Tests</RootNamespace>
<AssemblyName>Stellar.Tests</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</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="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" />
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll</HintPath>
</Reference>
<Reference Include="xunit.assert, Version=2.3.1.3858, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.assert.2.3.1\lib\netstandard1.1\xunit.assert.dll</HintPath>
</Reference>
<Reference Include="xunit.core, Version=2.3.1.3858, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.core.2.3.1\lib\netstandard1.1\xunit.core.dll</HintPath>
</Reference>
<Reference Include="xunit.execution.desktop, Version=2.3.1.3858, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.execution.2.3.1\lib\net452\xunit.execution.desktop.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SimpleQueryTest.cs" />
<Compile Include="SimpleQueryWithWhere.cs" />
<Compile Include="TestObject.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\stellar\Stellar.csproj">
<Project>{fbc836b1-b067-412c-914d-17f205f7cce7}</Project>
<Name>Stellar</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\packages\xunit.analyzers.0.8.0\analyzers\dotnet\cs\xunit.analyzers.dll" />
</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\xunit.core.2.3.1\build\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.3.1\build\xunit.core.props'))" />
<Error Condition="!Exists('..\packages\xunit.core.2.3.1\build\xunit.core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.3.1\build\xunit.core.targets'))" />
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props'))" />
</Target>
<Import Project="..\packages\xunit.core.2.3.1\build\xunit.core.targets" Condition="Exists('..\packages\xunit.core.2.3.1\build\xunit.core.targets')" />
</Project>
8 changes: 8 additions & 0 deletions src/Stellar.Tests/TestObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Tests
{
public class TestObject
{
public string Name { get; set; }
public int SomeIntProperty { get; set; }
}
}
11 changes: 11 additions & 0 deletions src/Stellar.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="xunit" version="2.3.1" targetFramework="net461" />
<package id="xunit.abstractions" version="2.0.1" targetFramework="net461" />
<package id="xunit.analyzers" version="0.8.0" targetFramework="net461" />
<package id="xunit.assert" version="2.3.1" targetFramework="net461" />
<package id="xunit.core" version="2.3.1" targetFramework="net461" />
<package id="xunit.extensibility.core" version="2.3.1" targetFramework="net461" />
<package id="xunit.extensibility.execution" version="2.3.1" targetFramework="net461" />
<package id="xunit.runner.visualstudio" version="2.3.1" targetFramework="net461" developmentDependency="true" />
</packages>
14 changes: 14 additions & 0 deletions src/Stellar.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stellar", "stellar\Stellar.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stellar.Samples", "Stellar.Samples\Stellar.Samples.csproj", "{8C6C4AA9-4D96-4F5E-B841-3D7195F68F9D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Stellar.Tests", "Stellar.Tests\Stellar.Tests.csproj", "{4335F266-3F71-4349-B926-D233307FC2F6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -40,6 +42,18 @@ Global
{8C6C4AA9-4D96-4F5E-B841-3D7195F68F9D}.Release|x64.Build.0 = Release|Any CPU
{8C6C4AA9-4D96-4F5E-B841-3D7195F68F9D}.Release|x86.ActiveCfg = Release|Any CPU
{8C6C4AA9-4D96-4F5E-B841-3D7195F68F9D}.Release|x86.Build.0 = Release|Any CPU
{4335F266-3F71-4349-B926-D233307FC2F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4335F266-3F71-4349-B926-D233307FC2F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4335F266-3F71-4349-B926-D233307FC2F6}.Debug|x64.ActiveCfg = Debug|Any CPU
{4335F266-3F71-4349-B926-D233307FC2F6}.Debug|x64.Build.0 = Debug|Any CPU
{4335F266-3F71-4349-B926-D233307FC2F6}.Debug|x86.ActiveCfg = Debug|Any CPU
{4335F266-3F71-4349-B926-D233307FC2F6}.Debug|x86.Build.0 = Debug|Any CPU
{4335F266-3F71-4349-B926-D233307FC2F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4335F266-3F71-4349-B926-D233307FC2F6}.Release|Any CPU.Build.0 = Release|Any CPU
{4335F266-3F71-4349-B926-D233307FC2F6}.Release|x64.ActiveCfg = Release|Any CPU
{4335F266-3F71-4349-B926-D233307FC2F6}.Release|x64.Build.0 = Release|Any CPU
{4335F266-3F71-4349-B926-D233307FC2F6}.Release|x86.ActiveCfg = Release|Any CPU
{4335F266-3F71-4349-B926-D233307FC2F6}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 0f836af

Please sign in to comment.