-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
unknown
authored and
unknown
committed
Apr 30, 2010
0 parents
commit e5a0b2b
Showing
11 changed files
with
561 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
namespace DALTestDriver | ||
|
||
open System | ||
open FSharpDAL | ||
open NUnit.Framework | ||
|
||
type Person = {Id:int;FirstName:string;LastName:string;Age:int} | ||
type Cat = {PetName:string;Color:string;IsCute:bool;IsMean:bool} | ||
|
||
[<TestFixture>] | ||
type FSharpDALTests = | ||
static member DefaultMasterConnectionString = "Server=localhost;Integrated security=SSPI;database=master" | ||
static member DefaultDataConnectionString = "Server=localhost;Integrated security=SSPI;database=PeopleData;MultipleActiveResultSets=true" | ||
|
||
[<Test>] | ||
static member TestDatabaseExists = | ||
let databaseThatShouldNotExist = Guid.NewGuid().ToString() | ||
let exists = DatabaseExists databaseThatShouldNotExist FSharpDALTests.DefaultMasterConnectionString | ||
Assert.AreEqual(false, exists) | ||
|
||
[<Test>] | ||
static member TestCreateDatabase = | ||
do DropDatabase "WeatherData" FSharpDALTests.DefaultMasterConnectionString | ||
do CreateDatabase "WeatherData" FSharpDALTests.DefaultMasterConnectionString | ||
let existsAfterCreate = DatabaseExists "WeatherData" FSharpDALTests.DefaultMasterConnectionString | ||
Assert.AreEqual(true, existsAfterCreate) | ||
|
||
[<Test>] | ||
static member TestCreatePeopleTable = | ||
do DropDatabase "WeatherData" FSharpDALTests.DefaultMasterConnectionString | ||
do CreateDatabase "WeatherData" FSharpDALTests.DefaultMasterConnectionString | ||
do CreateTableFor<Person> FSharpDALTests.DefaultDataConnectionString | ||
Assert.AreEqual(true, TableExistsFor<Person> FSharpDALTests.DefaultDataConnectionString) | ||
|
||
[<Test>] | ||
static member TestCreateAaronErickson = | ||
do DropDatabase "WeatherData" FSharpDALTests.DefaultMasterConnectionString | ||
do CreateDatabase "WeatherData" FSharpDALTests.DefaultMasterConnectionString | ||
do CreateTableFor<Person> FSharpDALTests.DefaultDataConnectionString | ||
use context = new ForDataContext(FSharpDALTests.DefaultDataConnectionString) | ||
let rowsAffected = context.Create {Id=42;FirstName="Aaron";LastName="Erickson";Age=37} | ||
Assert.AreEqual(1, rowsAffected) | ||
|
||
[<Test>] | ||
static member TestReadPeopleAndPets = | ||
|
||
do DropDatabase "PeopleData" FSharpDALTests.DefaultMasterConnectionString | ||
|
||
do CreateDatabase "PeopleData" FSharpDALTests.DefaultMasterConnectionString | ||
|
||
do CreateTableFor<Person> FSharpDALTests.DefaultDataConnectionString | ||
|
||
use context = new ForDataContext(FSharpDALTests.DefaultDataConnectionString) | ||
do context.Create {Id=1;FirstName="Aaron";LastName="Erickson";Age=37} |> ignore | ||
do context.Create {Id=2;FirstName="Erin";LastName="Erickson";Age=34} |> ignore | ||
do context.Create {Id=3;FirstName="Adriana";LastName="Erickson";Age=13} |> ignore | ||
do context.Create {Id=4;FirstName="Matthew";LastName="Erickson";Age=8} |> ignore | ||
|
||
let people = context.SequenceFrom<Person>( <@ fun p -> p.LastName = "Erickson" @> ) |> Seq.toArray | ||
|
||
Assert.AreEqual(people.Length,4) | ||
|
||
do CreateTableFor<Cat> FSharpDALTests.DefaultDataConnectionString | ||
do context.Create {PetName="Puppy Cat";Color="Ginger";IsCute=true;IsMean=false} |> ignore | ||
do context.Create {PetName="Dmitry";Color="Blue-Gray";IsCute=true;IsMean=true} |> ignore | ||
|
||
let theCats = context.SequenceFrom<Cat>() |> Seq.toArray | ||
|
||
Assert.AreEqual(theCats.Length,2) | ||
|
||
|
||
[<Test>] | ||
static member TestReadAaron = | ||
use context = new ForDataContext(FSharpDALTests.DefaultDataConnectionString) | ||
let query = <@ fun p -> p.FirstName = "Aaron" @> | ||
let people = context.SequenceFrom<Person>( query ) |> Seq.toArray | ||
Assert.AreEqual(people.Length,1) | ||
|
||
[<Test>] | ||
static member TestReadAaronErickson = | ||
use context = new ForDataContext(FSharpDALTests.DefaultDataConnectionString) | ||
let query = <@ fun p -> p.FirstName = "Aaron" && p.LastName = "Erickson" @> | ||
let people = context.SequenceFrom<Person>( query ) |> Seq.toArray | ||
Assert.AreEqual(people.Length,1) | ||
|
||
[<Test>] | ||
static member TestReadSuperCompound = | ||
use context = new ForDataContext(FSharpDALTests.DefaultDataConnectionString) | ||
let query = <@ fun(p:Person) -> (p.FirstName = "Aaron" && p.LastName = "Erickson") || (p.FirstName = "Ted" && p.LastName = "Neward") @> | ||
let people = context.SequenceFrom<Person>( query ) |> Seq.toArray | ||
Assert.AreEqual(people.Length,2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProductVersion>8.0.30703</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{b08584b5-d720-49c9-b1bf-8728219f7d59}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<RootNamespace>DALTestDriver</RootNamespace> | ||
<AssemblyName>DALTestDriver</AssemblyName> | ||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> | ||
<Name>DALTestDriver</Name> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<Tailcalls>false</Tailcalls> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<WarningLevel>3</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<Tailcalls>true</Tailcalls> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<WarningLevel>3</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="mscorlib" /> | ||
<Reference Include="FSharp.Core" /> | ||
<Reference Include="nunit.framework"> | ||
<HintPath>C:\Program Files\NUnit 2.5.2\bin\net-2.0\framework\nunit.framework.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Numerics" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="DALTestDriver.fs" /> | ||
<Compile Include="RawADOExample.fs" /> | ||
<Compile Include="NHibernateExample.fs" /> | ||
<Compile Include="Main.fs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\FSharpDAL\FSharpDAL.fsproj"> | ||
<Name>FSharpDAL</Name> | ||
<Project>{44bf3d3d-1767-4ab0-a6bd-f94af4f34893}</Project> | ||
<Private>True</Private> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildExtensionsPath32)\..\Microsoft F#\v4.0\Microsoft.FSharp.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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Main | ||
open DALTestDriver | ||
//do FSharpDALTests.TestCreateDatabase |> ignore | ||
//do FSharpDALTests.TestDatabaseExists |> ignore | ||
do FSharpDALTests.TestReadPeopleAndPets |> ignore | ||
//do FSharpDALTests.TestReadAaron |> ignore | ||
//do FSharpDALTests.TestCreateAaronErickson |> ignore | ||
//do FSharpDALTests.TestReadAaronErickson |> ignore | ||
//do FSharpDALTests.TestReadSuperCompound |> ignore | ||
//do FSharpDALTests.TestCreatePeopleTable |> ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Learn more about F# at http://fsharp.net | ||
|
||
module Module1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module NHibernateExample | ||
|
||
type NHPerson() = class | ||
let mutable _id : int = 0 | ||
let mutable _firstName : string = "" | ||
let mutable _lastName : string = "" | ||
|
||
abstract Id : int with get, set | ||
default x.Id with get() = _id and set(v) = _id <- v | ||
|
||
abstract FirstName : string with get, set | ||
default x.FirstName with get() = _firstName and set(v) = _firstName <- v | ||
|
||
abstract LastName : string with get, set | ||
default x.LastName with get() = _lastName and set(v) = _lastName <- v | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
module RawADOExample | ||
open System.Data | ||
open System.Data.SqlClient | ||
|
||
type PersonName = {Id:int;FirstName:string;LastName:string} | ||
//raw ADO example | ||
let retrievePeople = | ||
use connection = new SqlConnection("Server=localhost;Integrated security=SSPI;database=DemoData") | ||
connection.Open() | ||
use command = new SqlCommand("select id, firstname, lastname from person",connection) | ||
let rawResult = command.ExecuteReader() | ||
let people = seq { | ||
while rawResult.Read() do | ||
yield { | ||
Id = rawResult.["Id"] :?> int; | ||
FirstName = rawResult.["FirstName"] :?> string; | ||
LastName = rawResult.["LastName"] :?> string | ||
} | ||
} | ||
people |> Seq.toList | ||
|
||
let retrievePeopleNamed firstName = | ||
use connection = new SqlConnection("Server=localhost;Integrated security=SSPI;database=DemoData") | ||
connection.Open() | ||
use command = new SqlCommand("select id, firstname, lastname from person where firstname = @firstname",connection) | ||
let parameter = new SqlParameter("firstName",firstName) | ||
do command.Parameters.Add parameter |> ignore | ||
let rawResult = command.ExecuteReader() | ||
let people = seq { | ||
while rawResult.Read() do | ||
yield { | ||
Id = rawResult.["Id"] :?> int; | ||
FirstName = rawResult.["FirstName"] :?> string; | ||
LastName = rawResult.["LastName"] :?> string | ||
} | ||
} | ||
people |> Seq.toList | ||
|
||
let doCreateUpdateDelete() = | ||
use connection = new SqlConnection("Server=localhost;Integrated security=SSPI;database=DemoData") | ||
connection.Open() | ||
//create | ||
use createCommand = | ||
new SqlCommand("insert into person (firstname,lastname) values (@firstname,@lastname)",connection) | ||
let firstNameParameterCreate = new SqlParameter("firstName","Aaron") | ||
let lastNameParameterCreate = new SqlParameter("lastName","Erickson") | ||
do createCommand.Parameters.Add firstNameParameterCreate |> ignore | ||
do createCommand.Parameters.Add lastNameParameterCreate |> ignore | ||
do createCommand.ExecuteNonQuery() |> ignore | ||
//update | ||
use updateCommand = | ||
new SqlCommand("update person set firstname=@firstname, lastname=@lastname where id=@id", connection) | ||
let firstNameParameterUpdate = new SqlParameter("firstName","Not") | ||
let lastNameParameterUpdate = new SqlParameter("lastName","Sure") | ||
let idParameterUpdate = new SqlParameter("id",42) | ||
do updateCommand.Parameters.Add firstNameParameterUpdate |> ignore | ||
do updateCommand.Parameters.Add lastNameParameterUpdate |> ignore | ||
do updateCommand.Parameters.Add idParameterUpdate |> ignore | ||
do updateCommand.ExecuteNonQuery() |> ignore | ||
//delete | ||
use deleteCommand = new SqlCommand("delete person where id=@id", connection) | ||
let idParameterDelete = new SqlParameter("id","42") | ||
do deleteCommand.Parameters.Add idParameterDelete |> ignore | ||
do deleteCommand.ExecuteNonQuery() |> ignore | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 11.00 | ||
# Visual Studio 2010 | ||
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharpDAL", "FSharpDAL\FSharpDAL.fsproj", "{44BF3D3D-1767-4AB0-A6BD-F94AF4F34893}" | ||
EndProject | ||
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "DALTestDriver", "DALTestDriver\DALTestDriver.fsproj", "{B08584B5-D720-49C9-B1BF-8728219F7D59}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{44BF3D3D-1767-4AB0-A6BD-F94AF4F34893}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{44BF3D3D-1767-4AB0-A6BD-F94AF4F34893}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{44BF3D3D-1767-4AB0-A6BD-F94AF4F34893}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{44BF3D3D-1767-4AB0-A6BD-F94AF4F34893}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{B08584B5-D720-49C9-B1BF-8728219F7D59}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{B08584B5-D720-49C9-B1BF-8728219F7D59}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{B08584B5-D720-49C9-B1BF-8728219F7D59}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{B08584B5-D720-49C9-B1BF-8728219F7D59}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
Binary file not shown.
Oops, something went wrong.