diff --git a/src/FSharp.Azure.StorageTypeProvider/Queue/ProvidedQueueTypes.fs b/src/FSharp.Azure.StorageTypeProvider/Queue/ProvidedQueueTypes.fs index 5c5a52b..f739386 100644 --- a/src/FSharp.Azure.StorageTypeProvider/Queue/ProvidedQueueTypes.fs +++ b/src/FSharp.Azure.StorageTypeProvider/Queue/ProvidedQueueTypes.fs @@ -14,7 +14,7 @@ type PopReceipt = | PopReceipt of string type ProvidedMessageId = | ProvidedMessageId of MessageId : MessageId * PopReceipt : PopReceipt /// Represents a single message that has been dequeued. -type ProvidedQueueMessage = +type ProvidedQueueMessage = { /// The composite key of this message, containing both the message id and the pop receipt. Id : ProvidedMessageId /// The number of times this message has been dequeued. @@ -26,9 +26,9 @@ type ProvidedQueueMessage = /// The time that this message will next become visible. NextVisibleTime : DateTimeOffset option /// Gets the contents of the message as a byte array. - AsBytes : byte array + AsBytes : Lazy /// Gets the contest of the message as a string. - AsString : string } + AsString : Lazy } module internal Factory = let unpackId messageId = @@ -41,8 +41,8 @@ module internal Factory = InsertionTime = message.InsertionTime |> Option.ofNullable ExpirationTime = message.ExpirationTime |> Option.ofNullable NextVisibleTime = message.NextVisibleTime |> Option.ofNullable - AsBytes = message.AsBytes - AsString = message.AsString } + AsBytes = Lazy.Create(fun _ -> message.AsBytes) + AsString = Lazy.Create(fun _ -> message.AsString) } let toAzureQueueMessage providedMessageId = let messageId, popReceipt = providedMessageId |> unpackId diff --git a/src/FSharp.Azure.StorageTypeProvider/Table/ProvidedTableTypes.fs b/src/FSharp.Azure.StorageTypeProvider/Table/ProvidedTableTypes.fs index 2ead074..503574f 100644 --- a/src/FSharp.Azure.StorageTypeProvider/Table/ProvidedTableTypes.fs +++ b/src/FSharp.Azure.StorageTypeProvider/Table/ProvidedTableTypes.fs @@ -93,12 +93,9 @@ type AzureTable internal (defaultConnection, tableName) = /// Asynchronously deletes an entire partition from the table member __.DeletePartitionAsync(partitionKey, ?connectionString) = async { let table = getTableForConnection (defaultArg connectionString defaultConnection) - let connStringToUse = - match connectionString with - | Some c -> c - | None -> defaultConnection + let connectionString = defaultArg connectionString defaultConnection let filter = Table.TableQuery.GenerateFilterCondition ("PartitionKey", Table.QueryComparisons.Equal, partitionKey) - let! response = executeGenericQueryAsync connStringToUse table.Name Int32.MaxValue filter (fun e -> (Partition(e.PartitionKey), Row(e.RowKey))) + let! response = executeGenericQueryAsync connectionString table.Name Int32.MaxValue filter (fun e -> (Partition(e.PartitionKey), Row(e.RowKey))) return! response |> __.DeleteAsync diff --git a/tests/IntegrationTests/QueueUnitTests.fs b/tests/IntegrationTests/QueueUnitTests.fs index 565cb51..61da60b 100644 --- a/tests/IntegrationTests/QueueUnitTests.fs +++ b/tests/IntegrationTests/QueueUnitTests.fs @@ -12,22 +12,22 @@ type Local = AzureTypeProvider<"DevStorageAccount", ""> type ResetQueueDataAttribute() = inherit BeforeAfterTestAttribute() - override x.Before(methodUnderTest) = QueueHelpers.resetData() - override x.After(methodUnderTest) = QueueHelpers.resetData() + override __.Before _ = QueueHelpers.resetData() + override __.After _ = QueueHelpers.resetData() [] let ``Correctly identifies queues``() = // compiles! Local.Queues.``sample-queue`` |> ignore Local.Queues.``second-sample`` |> ignore - Local.Queues.``third-sample`` + Local.Queues.``third-sample`` |> ignore let queue = Local.Queues.``sample-queue`` [] [] let ``Enqueues a message``() = - queue.Enqueue("Foo") |> Async.RunSynchronously + queue.Enqueue "Foo" |> Async.RunSynchronously test <@ queue.GetCurrentLength() = 1 @> [] @@ -36,7 +36,7 @@ let ``Dequeues a message``() = let message = async { do! queue.Enqueue "Foo" return! queue.Dequeue() } |> Async.RunSynchronously - test <@ message.Value.AsString = "Foo" @> + test <@ message.Value.AsString.Value = "Foo" @> [] [] @@ -44,14 +44,22 @@ let ``Dequeues a message of bytes``() = let message = async { do! queue.Enqueue [| 0uy; 1uy; 2uy; |] return! queue.Dequeue() } |> Async.RunSynchronously - test <@ message.Value.AsBytes = [| 0uy; 1uy; 2uy; |] @> + test <@ message.Value.AsBytes.Value = [| 0uy; 1uy; 2uy; |] @> + +[] +[] +let ``Safely supports lazy evaluation of "bad data"``() = + let message = async { do! queue.Enqueue [| 0uy; 1uy; 2uy; |] + return! queue.Dequeue() } + |> Async.RunSynchronously + test <@ message.Value.AsString.Value <> null @> [] [] let ``Deletes a message``() = async { do! queue.Enqueue "Foo" let! message = queue.Dequeue() - do! queue.DeleteMessage(message.Value.Id) } + do! queue.DeleteMessage message.Value.Id } |> Async.RunSynchronously test <@ queue.GetCurrentLength() = 0 @> @@ -69,7 +77,7 @@ let ``Update Message affects the text message body``() = return! queue.Dequeue() } |> Async.RunSynchronously - test <@ message.Value.AsString = "Bar" @> + test <@ message.Value.AsString.Value = "Bar" @> [] [] @@ -80,7 +88,7 @@ let ``Update Message affects the bytes message body``() = return! queue.Dequeue() } |> Async.RunSynchronously - test <@ message.Value.AsBytes = [| 2uy; 1uy; 0uy |] @> + test <@ message.Value.AsBytes.Value = [| 2uy; 1uy; 0uy |] @> [] [] @@ -88,9 +96,9 @@ let ``Dequeue Count is correctly emitted``() = let message = async { do! queue.Enqueue("Foo") let! message = queue.Dequeue() - do! queue.UpdateMessage(message.Value.Id, TimeSpan.FromSeconds(0.)) + do! queue.UpdateMessage(message.Value.Id, TimeSpan.FromSeconds 0.) let! message = queue.Dequeue() - do! queue.UpdateMessage(message.Value.Id, TimeSpan.FromSeconds(0.)) + do! queue.UpdateMessage(message.Value.Id, TimeSpan.FromSeconds 0.) return! queue.Dequeue() } |> Async.RunSynchronously test <@ message.Value.DequeueCount = 3 @>