Skip to content

Commit

Permalink
Added test for auto update. (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
OGKevin committed Jul 16, 2018
1 parent e09ff27 commit 00548ce
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion BunqSdk.Tests/Context/ApiContextTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Bunq.Sdk.Context;
using System;
using Bunq.Sdk.Context;
using Newtonsoft.Json.Linq;
using Xunit;

namespace Bunq.Sdk.Tests.Context
Expand All @@ -14,6 +16,12 @@ public class ApiContextTest : BunqSdkTestBase, IClassFixture<ApiContextTest>
/// </summary>
private const string ContextFilenameTest = "context-save-restore-test.conf";

/// <summary>
/// Field constatns.
/// </summary>
private const string FieldSessionContext = "session_context";
private const string FieldExpiryTime = "expiry_time";

private static ApiContext apiContext;

public ApiContextTest()
Expand Down Expand Up @@ -45,5 +53,26 @@ public void TestApiContextSaveRestore()

Assert.Equal(apiContextJson, apiContextRestored.ToJson());
}

[Fact]
public void TestAutoApiContextReLoad()
{
var apiContext = SetUpApiContext();
var contextJson = JObject.Parse(apiContext.ToJson());
var expiredTime = DateTime.Now.Subtract(TimeSpan.FromDays(20));
contextJson.SelectToken(FieldSessionContext)[FieldExpiryTime] = expiredTime.ToString();

var expiredApiContext = ApiContext.FromJson(contextJson.ToString());

Assert.NotEqual(apiContext, expiredApiContext);

BunqContext.UpdateApiContext(expiredApiContext);

Assert.Equal(expiredApiContext, BunqContext.ApiContext);

BunqContext.UserContext.RefreshUserContext();

Assert.True(BunqContext.ApiContext.IsSessionActive());
}
}
}

0 comments on commit 00548ce

Please sign in to comment.