Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #202 from aspriddell/rewrite-tests
Browse files Browse the repository at this point in the history
Re-write tests
  • Loading branch information
aspriddell authored Dec 22, 2020
2 parents 41ca905 + 3860e32 commit b254c4b
Show file tree
Hide file tree
Showing 28 changed files with 333 additions and 379 deletions.
11 changes: 3 additions & 8 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Unit Tests

on: [ pull_request ]
on: [ pull_request, push ]

jobs:
test:
Expand All @@ -10,10 +10,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Install .NET Core
- name: Install .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.x'
dotnet-version: '5.0.x'

- name: Build
run: |
Expand All @@ -22,8 +22,3 @@ jobs:
- name: Unit Tests
run: dotnet test

- name: Demo App
run: |
cd DragonFruit.Six.API.Demo
dotnet run
17 changes: 0 additions & 17 deletions DragonFruit.Six.API.Demo/DragonFruit.Six.API.Demo.csproj

This file was deleted.

57 changes: 0 additions & 57 deletions DragonFruit.Six.API.Demo/Program.cs

This file was deleted.

This file was deleted.

53 changes: 0 additions & 53 deletions DragonFruit.Six.API.Tests.Common/TestData.cs

This file was deleted.

31 changes: 31 additions & 0 deletions DragonFruit.Six.API.Tests/Data/AccountActivityTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Dragon6 API Copyright 2020 DragonFruit Network <inbox@dragonfruit.network>
// Licensed under Apache-2. Please refer to the LICENSE file for more info

using System;
using System.Globalization;
using DragonFruit.Six.API.Data.Extensions;
using DragonFruit.Six.API.Enums;
using NUnit.Framework;

namespace DragonFruit.Six.API.Tests.Data
{
[TestFixture]
public class AccountActivityTests : Dragon6ApiTest
{
[TestCase("14c01250-ef26-4a32-92ba-e04aa557d619", Platform.PC, 20201201)]
[TestCase("352655b3-2ff4-4713-9ad5-c10eb080e6f6", Platform.PC, 20200901)]
[TestCase("a5e7c9c4-a225-4d8e-810f-0c529d829a34", Platform.PSN, 20191001)]
public void TestAccountActivity(string id, Platform platform, int lastLogin)
{
if (!DateTime.TryParseExact(lastLogin.ToString(), "yyyyMMdd", null, DateTimeStyles.None, out var lastLoginDate))
{
Assert.Inconclusive($"{nameof(lastLogin)} was in an invalid format");
}

var account = GetAccountInfoFor(id, platform);
var login = Client.GetLoginInfo(account);

Assert.IsTrue(login.Activity.Last.UtcDateTime.Date > lastLoginDate.Date);
}
}
}
39 changes: 39 additions & 0 deletions DragonFruit.Six.API.Tests/Data/AccountLookupTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Dragon6 API Copyright 2020 DragonFruit Network <inbox@dragonfruit.network>
// Licensed under Apache-2. Please refer to the LICENSE file for more info

using System;
using DragonFruit.Six.API.Data.Extensions;
using DragonFruit.Six.API.Enums;
using NUnit.Framework;

namespace DragonFruit.Six.API.Tests.Data
{
[TestFixture]
public class AccountLookupTests : Dragon6ApiTest
{
[TestCase("papa.curry", LookupMethod.Name)]
[TestCase("Frost_Bites_", LookupMethod.Name)]
[TestCase("a5e7c9c4-a225-4d8e-810f-0c529d829a34", LookupMethod.UserId, Platform.PSN)]
[TestCase("b6c8e00a-00f9-44fb-b83e-eb9135933b91", LookupMethod.UserId, Platform.XB1)]
public void TestAccountLookup(string identifier, LookupMethod method, Platform platform = Platform.PC)
{
var account = Client.GetUser(platform, method, identifier);

Assert.IsTrue(method switch
{
LookupMethod.Name => identifier.Equals(account.PlayerName, StringComparison.OrdinalIgnoreCase),
LookupMethod.UserId => identifier.Equals(account.Identifiers.Ubisoft),
LookupMethod.PlatformId => identifier.Equals(account.Identifiers.Platform),

_ => throw new ArgumentOutOfRangeException(nameof(method), method, null)
});
}

[TestCase("l52655b3-2ff4-4713-9ad5-c10eb080e6f6")]
[TestCase("352655b3-2ff4-4713-xxxx-c10eb080e6f6")]
public void TestInvalidAccountLookup(string identifier)
{
Assert.Catch<ArgumentException>(() => Client.GetUserByUbisoftId(identifier, Platform.PC));
}
}
}
55 changes: 55 additions & 0 deletions DragonFruit.Six.API.Tests/Data/GeneralStatsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Dragon6 API Copyright 2020 DragonFruit Network <inbox@dragonfruit.network>
// Licensed under Apache-2. Please refer to the LICENSE file for more info

using DragonFruit.Six.API.Data.Extensions;
using DragonFruit.Six.API.Enums;
using DragonFruit.Six.API.Utils;
using NUnit.Framework;

namespace DragonFruit.Six.API.Tests.Data
{
[TestFixture]
public class GeneralStatsTests : Dragon6ApiTest
{
private static object[] _accounts =
{
new object[] { "14c01250-ef26-4a32-92ba-e04aa557d619", Platform.PC },
new object[] { "b6c8e00a-00f9-44fb-b83e-eb9135933b91", Platform.XB1 },
new object[] { "a5e7c9c4-a225-4d8e-810f-0c529d829a34", Platform.PSN }
};

[Test]
[TestCaseSource(nameof(_accounts))]
public void GeneralStatsTest(string identifier, Platform platform)
{
var account = GetAccountInfoFor(identifier, platform);
Client.GetStats(account);
}

[Test]
[TestCaseSource(nameof(_accounts))]
public void WeaponStatsTest(string identifier, Platform platform)
{
var account = GetAccountInfoFor(identifier, platform);
Client.GetWeaponStats(account);
}

[Test]
[TestCaseSource(nameof(_accounts))]
public void PlayerLevelStatsTest(string identifier, Platform platform)
{
var account = GetAccountInfoFor(identifier, platform);
Client.GetLevel(account);
}

[Test]
[TestCaseSource(nameof(_accounts))]
public void PlayerOperatorStatsTest(string identifier, Platform platform)
{
OperatorInfo ??= Client.GetOperatorInfo();

var account = GetAccountInfoFor(identifier, platform);
Client.GetOperatorStats(account, OperatorInfo);
}
}
}
31 changes: 31 additions & 0 deletions DragonFruit.Six.API.Tests/Data/SeasonalStatsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Dragon6 API Copyright 2020 DragonFruit Network <inbox@dragonfruit.network>
// Licensed under Apache-2. Please refer to the LICENSE file for more info

using DragonFruit.Six.API.Data.Extensions;
using DragonFruit.Six.API.Enums;
using NUnit.Framework;

namespace DragonFruit.Six.API.Tests.Data
{
[TestFixture]
public class SeasonalStatsTests : Dragon6ApiTest
{
[TestCase("14c01250-ef26-4a32-92ba-e04aa557d619", Platform.PC, 17, 17)]
public void TestSeasonalStats(string identifier, Platform platform, int season, int maxRank)
{
var account = GetAccountInfoFor(identifier, platform);
var stats = Client.GetSeasonStats(account, season);

Assert.AreEqual(maxRank, stats.MaxRank);
}

[TestCase("14c01250-ef26-4a32-92ba-e04aa557d619", Platform.PC, "EMEA", 10, 13)]
public void TestLegacySeasonalStats(string identifier, Platform platform, string region, int season, int maxRank)
{
var account = GetAccountInfoFor(identifier, platform);
var stats = Client.GetSeasonStats(account, region, season);

Assert.AreEqual(maxRank, stats.MaxRank);
}
}
}
34 changes: 34 additions & 0 deletions DragonFruit.Six.API.Tests/Dragon6ApiTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Dragon6 API Copyright 2020 DragonFruit Network <inbox@dragonfruit.network>
// Licensed under Apache-2. Please refer to the LICENSE file for more info

using System.Collections.Generic;
using System.Linq;
using DragonFruit.Six.API.Data;
using DragonFruit.Six.API.Data.Extensions;
using DragonFruit.Six.API.Enums;

namespace DragonFruit.Six.API.Tests
{
public abstract class Dragon6ApiTest
{
private static readonly List<AccountInfo> Accounts = new();
protected static readonly Dragon6TestClient Client = new();

protected static IEnumerable<OperatorStats> OperatorInfo { get; set; }

protected AccountInfo GetAccountInfoFor(string identifier, Platform platform)
{
var account = Accounts.SingleOrDefault(x => identifier == x.Identifiers.Ubisoft);

if (account != null)
{
return account;
}

var onlineAccount = Client.GetUser(platform, LookupMethod.UserId, identifier);
Accounts.Add(onlineAccount);

return onlineAccount;
}
}
}
Loading

0 comments on commit b254c4b

Please sign in to comment.