@@ -12,138 +12,138 @@ type TinyIntMapping = SqlEnumProvider<"SELECT * FROM (VALUES(('One'), CAST(1 AS
1212
1313[<Fact>]
1414let tinyIntMapping () =
15- Assert.Equal<( string * byte) seq>([| " One" , 1 uy; " Two" , 2 uy |], TinyIntMapping.Items)
15+ Assert.Equal<( string * byte) seq>([| " One" , 1 uy; " Two" , 2 uy |], TinyIntMapping.Items)
1616
1717[<Fact>]
1818let parse () =
19- Assert.Equal( TinyIntMapping.One, TinyIntMapping.Parse( " one" , ignoreCase = true ))
20- Assert.Equal( TinyIntMapping.One, TinyIntMapping.Parse( " One" , ignoreCase = false ))
21- Assert.Equal( TinyIntMapping.One, TinyIntMapping.Parse( " One" ))
22- Assert.Throws< ArgumentException>( fun () -> box ( TinyIntMapping.Parse( " blah-blah" ))) |> ignore
23- Assert.Throws< ArgumentException>( fun () -> box ( TinyIntMapping.Parse( " one" ))) |> ignore
19+ Assert.Equal( TinyIntMapping.One, TinyIntMapping.Parse( " one" , ignoreCase = true ))
20+ Assert.Equal( TinyIntMapping.One, TinyIntMapping.Parse( " One" , ignoreCase = false ))
21+ Assert.Equal( TinyIntMapping.One, TinyIntMapping.Parse( " One" ))
22+ Assert.Throws< ArgumentException>( fun () -> box ( TinyIntMapping.Parse( " blah-blah" ))) |> ignore
23+ Assert.Throws< ArgumentException>( fun () -> box ( TinyIntMapping.Parse( " one" ))) |> ignore
2424
2525[<Fact>]
2626let Enums () =
27- let succ , result = EnumMapping.TryParse( " One" )
28- Assert.True succ
29- Assert.Equal( EnumMapping.One, result)
27+ let succ , result = EnumMapping.TryParse( " One" )
28+ Assert.True succ
29+ Assert.Equal( EnumMapping.One, result)
3030
31- Assert.Equal( 1 , int EnumMapping.One)
32- Assert.True( EnumMapping.One = ( Enum.Parse( typeof< EnumMapping>, " One" ) |> unbox))
33- Assert.Equal( enum 1 , EnumMapping.One)
31+ Assert.Equal( 1 , int EnumMapping.One)
32+ Assert.True( EnumMapping.One = ( Enum.Parse( typeof< EnumMapping>, " One" ) |> unbox))
33+ Assert.Equal( enum 1 , EnumMapping.One)
3434
3535[<Fact>]
3636let Name () =
37- let value = TinyIntMapping.One
38- Assert.Equal( Some " One" , TinyIntMapping.TryFindName value)
39- Assert.Equal( None, TinyIntMapping.TryFindName Byte.MinValue)
37+ let value = TinyIntMapping.One
38+ Assert.Equal( Some " One" , TinyIntMapping.TryFindName value)
39+ Assert.Equal( None, TinyIntMapping.TryFindName Byte.MinValue)
4040
4141type SingleColumnSelect = SqlEnumProvider< " SELECT Name FROM Purchasing.ShipMethod" , ConnectionStrings.AdventureWorksNamed>
4242
4343[<Fact>]
4444let SingleColumn () =
45- Assert.Equal< string>( " CARGO TRANSPORT 5" , SingleColumnSelect.`` CARGO TRANSPORT 5 `` )
46- let all =
47- use cmd = new SqlCommandProvider< " SELECT Name, Name FROM Purchasing.ShipMethod" , ConnectionStrings.AdventureWorksNamed, ResultType.Tuples>()
48- cmd.Execute() |> Seq.toArray
49- let items = SingleColumnSelect.Items
50- Assert.Equal<_ seq>( all, items)
45+ Assert.Equal< string>( " CARGO TRANSPORT 5" , SingleColumnSelect.`` CARGO TRANSPORT 5 `` )
46+ let all =
47+ use cmd = new SqlCommandProvider< " SELECT Name, Name FROM Purchasing.ShipMethod" , ConnectionStrings.AdventureWorksNamed, ResultType.Tuples>()
48+ cmd.Execute() |> Seq.toArray
49+ let items = SingleColumnSelect.Items
50+ Assert.Equal<_ seq>( all, items)
5151
5252[<Fact>]
5353let PatternMatchingOn () =
54- let actual =
55- SingleColumnSelect.Items
56- |> Seq.choose ( fun ( tag , value ) ->
57- match value with
58- | SingleColumnSelect.`` CARGO TRANSPORT 5 ``
59- | SingleColumnSelect.`` OVERNIGHT J-FAST ``
60- | SingleColumnSelect.`` OVERSEAS - DELUXE ``
61- | SingleColumnSelect.`` XRQ - TRUCK GROUND ``
62- | SingleColumnSelect.`` ZY - EXPRESS `` -> Some tag
63- | _ -> None
64- )
65-
66- Assert.Equal<_ seq>(
67- SingleColumnSelect.Items |> Seq.map fst,
68- actual
69- )
54+ let actual =
55+ SingleColumnSelect.Items
56+ |> Seq.choose ( fun ( tag , value ) ->
57+ match value with
58+ | SingleColumnSelect.`` CARGO TRANSPORT 5 ``
59+ | SingleColumnSelect.`` OVERNIGHT J-FAST ``
60+ | SingleColumnSelect.`` OVERSEAS - DELUXE ``
61+ | SingleColumnSelect.`` XRQ - TRUCK GROUND ``
62+ | SingleColumnSelect.`` ZY - EXPRESS `` -> Some tag
63+ | _ -> None
64+ )
65+
66+ Assert.Equal<_ seq>(
67+ SingleColumnSelect.Items |> Seq.map fst,
68+ actual
69+ )
7070
7171type MoreThan2Columns = SqlEnumProvider< @"
72- select * from (
72+ select * from (
7373values
74- ('a', 1, 'this is a')
75- , ('b', 2, 'this is b')
76- , ('c', 3, 'this is c')
74+ ('a', 1, 'this is a')
75+ , ('b', 2, 'this is b')
76+ , ('c', 3, 'this is c')
7777) as v(code, id, description)
7878" , connectionString>
7979
8080[<Fact>]
8181let MoreThan2ColumnReturnsCorrectTuples () =
82- Assert.Equal(( 1 , " this is a" ), MoreThan2Columns.a)
83- Assert.Equal<_[]>(
84- expected = [|
85- ( " a" , ( 1 , " this is a" ))
86- ( " b" , ( 2 , " this is b" ))
87- ( " c" , ( 3 , " this is c" ))
88- |],
89- actual = Array.ofSeq MoreThan2Columns.Items
90- )
82+ Assert.Equal(( 1 , " this is a" ), MoreThan2Columns.a)
83+ Assert.Equal<_[]>(
84+ expected = [|
85+ ( " a" , ( 1 , " this is a" ))
86+ ( " b" , ( 2 , " this is b" ))
87+ ( " c" , ( 3 , " this is c" ))
88+ |],
89+ actual = Array.ofSeq MoreThan2Columns.Items
90+ )
9191
9292type CurrencyCode =
93- SqlEnumProvider< "
94- SELECT CurrencyCode
95- FROM Sales.Currency
96- WHERE CurrencyCode IN ('USD', 'EUR', 'GBP')
97- " , ConnectionStrings.AdventureWorksLiteral, Kind = SqlEnumKind.UnitsOfMeasure>
93+ SqlEnumProvider< "
94+ SELECT CurrencyCode
95+ FROM Sales.Currency
96+ WHERE CurrencyCode IN ('USD', 'EUR', 'GBP')
97+ " , ConnectionStrings.AdventureWorksLiteral, Kind = SqlEnumKind.UnitsOfMeasure>
9898
9999[<Fact>]
100100let ConvertUsdToGbp () =
101- let getLatestRate = new SqlCommandProvider< "
102- SELECT TOP 1 *
103- FROM Sales.CurrencyRate
104- WHERE FromCurrencyCode = @fromCurrency
101+ let getLatestRate = new SqlCommandProvider< "
102+ SELECT TOP 1 *
103+ FROM Sales.CurrencyRate
104+ WHERE FromCurrencyCode = @fromCurrency
105105 AND ToCurrencyCode = @toCurrency
106- ORDER BY CurrencyRateDate DESC
107- " , ConnectionStrings.AdventureWorksNamed, SingleRow = true >()
108- let rate =
109- getLatestRate.Execute( fromCurrency = " USD" , toCurrency = " GBP" )
110- |> Option.map( fun x -> x.AverageRate * 1 M< CurrencyCode.GBP/ CurrencyCode.USD>)
111- |> Option.get
106+ ORDER BY CurrencyRateDate DESC
107+ " , ConnectionStrings.AdventureWorksNamed, SingleRow = true >()
108+ let rate =
109+ getLatestRate.Execute( fromCurrency = " USD" , toCurrency = " GBP" )
110+ |> Option.map( fun x -> x.AverageRate * 1 M< CurrencyCode.GBP/ CurrencyCode.USD>)
111+ |> Option.get
112112
113- let actual = 42 M< CurrencyCode.USD> * rate
114- let expected = 26.5986 M< CurrencyCode.GBP>
115- Assert.Equal( expected, actual)
113+ let actual = 42 M< CurrencyCode.USD> * rate
114+ let expected = 26.5986 M< CurrencyCode.GBP>
115+ Assert.Equal( expected, actual)
116116
117117type ProductsUnitsOfMeasure = SqlEnumProvider< " SELECT UnitMeasureCode FROM Production.UnitMeasure" , ConnectionStrings.AdventureWorksLiteral, Kind = SqlEnumKind.UnitsOfMeasure>
118118type ProductCategory = SqlEnumProvider< " SELECT Name FROM Production.ProductCategory" , ConnectionStrings.AdventureWorksLiteral>
119119
120120type Bikes = {
121- Id: int
122- Name: string
123- Weight: decimal < ProductsUnitsOfMeasure .``LB `` > option
124- Size: float < ProductsUnitsOfMeasure .``CM `` > option
121+ Id: int
122+ Name: string
123+ Weight: decimal < ProductsUnitsOfMeasure .``LB `` > option
124+ Size: float < ProductsUnitsOfMeasure .``CM `` > option
125125}
126126
127127[<Fact>]
128128let ProductWeightAndSizeUnitsOfMeasure () =
129- let allBikes = [
130- use cmd =
131- new SqlCommandProvider< "
132- SELECT ProductID, Product.Name, Size, SizeUnitMeasureCode, Weight, WeightUnitMeasureCode
133- FROM Production.Product
129+ let allBikes = [
130+ use cmd =
131+ new SqlCommandProvider< "
132+ SELECT ProductID, Product.Name, Size, SizeUnitMeasureCode, Weight, WeightUnitMeasureCode
133+ FROM Production.Product
134134 JOIN Production.ProductCategory ON ProductSubcategoryID = ProductCategoryID
135- WHERE ProductCategory.Name = @category
136- " , ConnectionStrings.AdventureWorksNamed>()
135+ WHERE ProductCategory.Name = @category
136+ " , ConnectionStrings.AdventureWorksNamed>()
137137
138- for x in cmd.Execute( ProductCategory.Bikes) do
139- yield {
140- Id = x.ProductID
141- Name = x.Name
142- Weight = x.Weight |> Option.map( fun weight -> weight * 1 M<_>)
143- Size = x.Size |> Option.map( fun size -> size |> float |> LanguagePrimitives.FloatWithMeasure )
144- }
145- ]
146-
147- let bigBikes = allBikes |> List.choose ( fun x -> if x.Size = Some 52. < ProductsUnitsOfMeasure.`` CM `` > then Some x.Name else None)
148-
149- Assert.Equal<_ list>( [ " Mountain-500 Silver, 52" ; " Mountain-500 Black, 52" ], bigBikes)
138+ for x in cmd.Execute( ProductCategory.Bikes) do
139+ yield {
140+ Id = x.ProductID
141+ Name = x.Name
142+ Weight = x.Weight |> Option.map( fun weight -> weight * 1 M<_>)
143+ Size = x.Size |> Option.map( fun size -> size |> float |> LanguagePrimitives.FloatWithMeasure )
144+ }
145+ ]
146+
147+ let bigBikes = allBikes |> List.choose ( fun x -> if x.Size = Some 52. < ProductsUnitsOfMeasure.`` CM `` > then Some x.Name else None)
148+
149+ Assert.Equal<_ list>( [ " Mountain-500 Silver, 52" ; " Mountain-500 Black, 52" ], bigBikes)
0 commit comments