Source

Linq2vk / src / VkontakteAPI / Linq2vk.Tests / ApiTests.fs

Full commit
namespace Linq2vk.Tests

open System
open NUnit.Framework
open Linq2vk

[<TestFixture>]
type ApiTests() =

    [<Test>]
    member this.SignatureGenerationTest() =
        let query = Query.fromSeq [
                        ("fields", "photo,sex");
                        ("format", "JSON");
                        ("api_id", "1854119");
                        ("method", "getProfiles");
                        ("uids", "100172");
                        ("v", "3.0");
                    ]
        let apiHandle = Api.create 0L 100172L "655df68ded" "somesid" 0L
        let actual = Api.HelperFunctions.createSignature apiHandle query
        let expected = "4a5bf45c9fe5c66d3afa73d8520fe46a"
        Assert.AreEqual(expected, actual)

    member private this.IsNone = function
        | None -> ()
        | Some _ -> Assert.Fail("Is not None")

    member private this.IsSome = function
        | Some _ -> ()
        | None -> Assert.Fail("Is None")

    [<Test>]
    member this.CleanQueryTest () =
        let query = Query.fromSeq [
                        // should be cleaned
                        ("format", "JSON");
                        ("api_id", "1854119");
                        ("sig", "");
                        ("sid", "");
                        ("v", "3.0");
                        // should remain
                        ("method", "getProfiles");
                        ("fields", "photo,sex");
                    ]
        let resultQ = Api.HelperFunctions.cleanQuery query
        let (Query.Query kvs) = resultQ

        this.IsNone <| List.tryFind (fun (k, _) -> k = "api_id") kvs
        this.IsNone <| List.tryFind (fun (k, _) -> k = "format") kvs
        this.IsNone <| List.tryFind (fun (k, _) -> k = "v") kvs
        this.IsNone <| List.tryFind (fun (k, _) -> k = "sig") kvs
        this.IsNone <| List.tryFind (fun (k, _) -> k = "sid") kvs

        this.IsSome <| List.tryFind (fun (k, _) -> k = "method") kvs
        this.IsSome <| List.tryFind (fun (k, _) -> k = "fields") kvs


    [<Test>]
    [<Explicit>]
    member this.GenerateLoginUrl () =
        printfn "%s" <| Login.makeLoginUrl Settings.AppId 130L

    [<Test>]
    [<Explicit>]
    member this.GenerateGetFriendsRequestUrl () =
        let handle = Settings.Handle

        let query = Query.init ()
                    |> Query.add "method" "friends.get"                    

        let queryString = Api.createQueryString handle query
        printfn "%s?%s" Api.BaseUrl queryString