public void ShowAchievementsUiWorksWhenAuthenticated() { var mockClient = new AchievementClient(); var platform = new PlayGamesPlatform(mockClient); platform.ShowAchievementsUI(); Assert.AreEqual(1, mockClient.ShownUiCount); }
public void AchievementReportProgressIsRevealNoMapping() { var mockClient = new AchievementClient(); var platform = new PlayGamesPlatform(mockClient); platform.ReportProgress("achievement", 0.00000001, SentinelCallback); Assert.AreEqual("achievement", mockClient.RevealedId); }
public void AchievementReportProgressIncrementalProgressSmallAmount() { var mockClient = new AchievementClient(); var platform = new PlayGamesPlatform(mockClient); IncrementViaReportProgress(mockClient, platform, 0, 100, 25); Assert.AreEqual("incremental", mockClient.IncrementedId); Assert.AreEqual(25, mockClient.NewSteps.Value); }
public void AchievementReportProgressIncrementalBuildsOnInitialProgress() { var mockClient = new AchievementClient(); var platform = new PlayGamesPlatform(mockClient); IncrementViaReportProgress(mockClient, platform, 25, 100, 60); Assert.AreEqual("incremental", mockClient.IncrementedId); Assert.AreEqual(60, mockClient.NewSteps.Value); }
public void AchievementReportProgressIncrementalAllowsMoreThanOneHundredPercent() { var mockClient = new AchievementClient(); var platform = new PlayGamesPlatform(mockClient); IncrementViaReportProgress(mockClient, platform, 0, 100, 200); Assert.AreEqual("incremental", mockClient.IncrementedId); Assert.AreEqual(200, mockClient.NewSteps.Value); }
public void AchievementReportProgressIncrementalIgnoresZeroIncrement() { var mockClient = new AchievementClient(); var platform = new PlayGamesPlatform(mockClient); IncrementViaReportProgress(mockClient, platform, 25, 100, 25); Assert.IsNull(mockClient.IncrementedId); Assert.IsNull(mockClient.IncrementedSteps); }
public void AchievementReportProgressIncrementalAllInOneGo() { var mockClient = new AchievementClient(); var platform = new PlayGamesPlatform(mockClient); IncrementViaReportProgress(mockClient, platform, 0, 100, 100); Assert.AreEqual("incremental", mockClient.IncrementedId); Assert.AreEqual(100, mockClient.IncrementedSteps.Value); }
public void AchievementReportProgressUnknownAchievementTreatedAsNonIncremental() { var mockClient = new AchievementClient(); var platform = new PlayGamesPlatform(mockClient); platform.ReportProgress("unknown", 50, SentinelCallback); Assert.IsNull(mockClient.UnlockedId); Assert.IsNull(mockClient.UnlockedCallback); }
static void IncrementViaReportProgress(AchievementClient mockClient, PlayGamesPlatform platform, int current, int total, double progress) { Achievement incremental = new Achievement(); incremental.IsIncremental = true; incremental.CurrentSteps = current; incremental.TotalSteps = total; mockClient.CurrentAchievement = incremental; platform.ReportProgress("incremental", progress, SentinelCallback); }
public void AchievementReportProgressIncrementalBuildsOnInitialProgress() { var mockClient = new AchievementClient(); var platform = new PlayGamesPlatform(mockClient); IncrementViaReportProgress(mockClient, platform, 25, 100, 60); Assert.AreEqual("incremental", mockClient.IncrementedId); // Our target is 50 steps, initial value is 25 - delta of 25. Assert.AreEqual(35, mockClient.IncrementedSteps.Value); }
public void ShowAchievementsUiIsNoOpWhenUnauthenticated() { var mockClient = new AchievementClient(); var platform = new PlayGamesPlatform(mockClient); mockClient.Authenticated = false; platform.ShowAchievementsUI(); Assert.AreEqual(0, mockClient.ShownUiCount); }
public void AchievementIncrementForUnmappedId() { var mockClient = new AchievementClient(); var platform = new PlayGamesPlatform(mockClient); platform.SetStepsAtLeast("unmapped", 20, SentinelCallback); Assert.AreEqual("unmapped", mockClient.IncrementedId); Assert.AreEqual(20, mockClient.NewSteps); Assert.AreSame(SentinelCallback, mockClient.IncrementedCallback); }
private async Task Initialise() { string token = await _userService.GetTokenAsync(); _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); string baseUrl = Constants.ApiBaseUrl; _achievementClient = new AchievementClient(baseUrl, _httpClient); _rewardClient = new RewardClient(baseUrl, _httpClient); }
public void AchievementIncrementRequiresAuthentication() { var mockClient = new AchievementClient(); var platform = new PlayGamesPlatform(mockClient); var capturingCallback = new CapturingAction <bool>(); mockClient.Authenticated = false; platform.IncrementAchievement("noAuth", 10, capturingCallback.invoke); Assert.IsFalse(capturingCallback.Captured); }
public void AchievementReportProgressFailsWhenNotAuthenticated() { var mockClient = new AchievementClient(); var platform = new PlayGamesPlatform(mockClient); mockClient.Authenticated = false; var result = new CapturingAction <bool>(); platform.ReportProgress("achievement", 0.0, result.invoke); Assert.IsFalse(result.Captured); }
public void AchievementIncrementForMappedId() { var mockClient = new AchievementClient(); var platform = new PlayGamesPlatform(mockClient); platform.AddIdMapping("unmapped", "mapped"); platform.IncrementAchievement("unmapped", 30, SentinelCallback); Assert.AreEqual("mapped", mockClient.IncrementedId); Assert.AreEqual(30, mockClient.IncrementedSteps); Assert.AreSame(SentinelCallback, mockClient.IncrementedCallback); }
public void AchievementReportProgressNonIncremental() { var mockClient = new AchievementClient(); var platform = new PlayGamesPlatform(mockClient); Achievement nonIncremental = new Achievement(); mockClient.CurrentAchievement = nonIncremental; platform.ReportProgress("nonIncremental", 50, SentinelCallback); Assert.IsNull(mockClient.UnlockedId); Assert.IsNull(mockClient.UnlockedCallback); }
public void AchievementReportProgressIsRevealWithMapping() { var mockClient = new AchievementClient(); var platform = new PlayGamesPlatform(mockClient); platform.AddIdMapping("mappedId", "realId"); Achievement achievemnt = new Achievement(); achievemnt.Id = "realId"; mockClient.CurrentAchievement = achievemnt; platform.ReportProgress("mappedId", 0.00000001, SentinelCallback); Assert.AreEqual("realId", mockClient.RevealedId); }
public async Task WhenAchievementIsNull_CreateThrowsException() { var client = new AchievementClient(null); await Assert.ThrowsAsync <ArgumentNullException>(() => client.Create(null)); }
public async Task WhenSetupWithResponseData_Create_CallsUrlOnceAndReturnsCorrectResult() { var apiKey = BadgeUp.ApiKey.Create(ApiKey); var responseJson = @"{ 'id': 'cjktcmn5o635wmyd0w4ps', 'applicationId': 'g6jtshln48', 'name': 'Achievement name', 'description': 'Achievement description', 'awards': ['award-1','award-2','award-3'], 'options': { 'earnLimit': 5, 'suspended': true }, 'meta': { 'created': '2016-09-12T06:51:35.453Z', 'icon': 'https://example.com/favicon.ico' } }" .Replace("'", "\""); // setup the response action var url = $"{Host}/v2/apps/{apiKey.ApplicationId}/achievements"; var mockHttp = new MockHttpMessageHandler(); var expectedRequest = mockHttp.Expect(HttpMethod.Post, url).Respond("application/json", responseJson); mockHttp.Fallback.Throw(new InvalidOperationException("No matching mock handler")); using (var badgeUpHttpClient = new BadgeUpHttpClient(apiKey, Host)) { badgeUpHttpClient.SetHttpClient(mockHttp.ToHttpClient()); var client = new AchievementClient(badgeUpHttpClient); var result = await client.Create(new Achievement() { Name = "Achievement name", Description = "Achievement description", Awards = new[] { "award-1", "award-2", "award-3" }, // TODO: Add simple EvalTree test once client.Criterion.GetAll() is completed EvalTree = null, Options = new AchievementOptions() { EarnLimit = 5, Suspended = true }, Meta = new AchievementMeta() { Icon = "https://example.com/favicon.ico" } }); Assert.Equal("Achievement name", result.Name); Assert.Equal("Achievement description", result.Description); Assert.Equal("cjktcmn5o635wmyd0w4ps", result.Id); Assert.Equal(new[] { "award-1", "award-2", "award-3" }, result.Awards); Assert.True(result.Options.Suspended); Assert.Equal(5, result.Options.EarnLimit); Assert.Equal(new DateTime(2016, 09, 12, 06, 51, 35, 453), result.Meta.Created); Assert.Equal("https://example.com/favicon.ico", result.Meta.Icon); } mockHttp.VerifyNoOutstandingExpectation(); }