void JsonTimeStampHandlesAllFormats(UUnitTestContext testContext) { string expectedJson, actualJson; DateTime expectedTime; ObjWithTimes actualObj; for (var i = 0; i < _examples.Length; i++) { // Define the time deserialization expectation testContext.True(DateTime.TryParseExact(_examples[i], PlayFabUtil._defaultDateTimeFormats, CultureInfo.CurrentCulture, DateTimeStyles.RoundtripKind, out expectedTime), "Index: " + i + "/" + _examples.Length + ", " + _examples[i]); // De-serialize the time using json expectedJson = "{\"timestamp\":\"" + _examples[i] + "\"}"; // We are provided a json string with every random time format actualObj = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer).DeserializeObject <ObjWithTimes>(expectedJson); actualJson = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer).SerializeObject(actualObj); if (i == PlayFabUtil.DEFAULT_UTC_OUTPUT_INDEX) // This is the only case where the json input will match the json output { testContext.StringEquals(expectedJson, actualJson); } // Verify that the times match var diff = (expectedTime - actualObj.timestamp).TotalSeconds; // We expect that we have parsed the time correctly according to expectations testContext.True(diff < 1, "\nActual time: " + actualObj.timestamp + " vs Expected time: " + expectedTime + ", diff: " + diff + "\nActual json: " + actualJson + " vs Expected json: " + expectedJson ); } testContext.EndTest(UUnitFinishState.PASSED, null); }
void JsonTimeStampHandlesAllFormats(UUnitTestContext testContext) { string expectedJson, actualJson; DateTime expectedTime; ObjWithTimes actualObj = new ObjWithTimes(); for (int i = 0; i < _examples.Length; i++) { // Define the time deserialization expectation testContext.True(DateTime.TryParseExact(_examples[i], PlayFabUtil._defaultDateTimeFormats, CultureInfo.CurrentCulture, DateTimeStyles.RoundtripKind, out expectedTime), "Index: " + i + "/" + _examples.Length + ", " + _examples[i]); // De-serialize the time using json expectedJson = "{\"timestamp\":\"" + _examples[i] + "\"}"; // We are provided a json string with every random time format actualObj = JsonWrapper.DeserializeObject<ObjWithTimes>(expectedJson, PlayFabUtil.ApiSerializerStrategy); actualJson = JsonWrapper.SerializeObject(actualObj, PlayFabUtil.ApiSerializerStrategy); if (i == PlayFabUtil.DEFAULT_UTC_OUTPUT_INDEX) // This is the only case where the json input will match the json output testContext.StringEquals(expectedJson, actualJson); // Verify that the times match double diff = (expectedTime - actualObj.timestamp).TotalSeconds; // We expect that we have parsed the time correctly according to expectations testContext.True(diff < 1, "\nActual time: " + actualObj.timestamp + " vs Expected time: " + expectedTime + ", diff: " + diff + "\nActual json: " + actualJson + " vs Expected json: " + expectedJson ); } testContext.EndTest(UUnitFinishState.PASSED, null); }
public void EmailPasswordLoginSuccess(UUnitTestContext testContext) { const string email = "*****@*****.**"; const string password = "******"; const string username = "******"; _emailAuthService = new PlayFabAuthService(); _emailAuthService.Email = email; _emailAuthService.Password = password; _emailAuthService.Username = username; _emailAuthService.OnLoginSuccess += (success) => { testContext.True(!string.IsNullOrEmpty(success.PlayFabId)); testContext.NotNull(_emailAuthService.IsClientLoggedIn()); testContext.EndTest(UUnitFinishState.PASSED, "Email & password auth success. " + success.PlayFabId); }; _emailAuthService.OnPlayFabError += (error) => { testContext.Fail("Email & password auth failed with error: " + error.GenerateErrorReport()); }; _emailAuthService.OnDisplayAuthentication += () => { testContext.Fail("Email & password auth failed."); }; _emailAuthService.Authenticate(AuthTypes.EmailPassword); }
public void SerializeExample(UUnitTestContext testContext) { TestSuiteReport[] actualSuites = JsonWrapper.DeserializeObject <TestSuiteReport[]>(EXAMPLE_JSON); testContext.NotNull(actualSuites); foreach (var expectedTestName in EXPECTED_TESTS) { var testFound = false; foreach (var suite in actualSuites) { foreach (var test in suite.testResults) { if (test.name == expectedTestName) { testFound = true; break; } } testContext.IntEquals(suite.tests, EXPECTED_TESTS.Length, "Total tests does not match expected {0}, {1}"); } testContext.True(testFound, "Test not found: " + expectedTestName); } testContext.EndTest(UUnitFinishState.PASSED, null); }
public override void SetUp(UUnitTestContext testContext) { PlayFabSettings.TitleId = TITLE_ID; var task = PlayFabClientAPI.LoginWithCustomIDAsync(new LoginWithCustomIDRequest { CreateAccount = true, CustomId = TEST_CUSTOM_ID, TitleId = TITLE_ID }); task.Wait(); testContext.True(PlayFabClientAPI.IsClientLoggedIn(), "User login not successful: " + PlayFabUtil.GetErrorReport(task.Result.Error)); }
void TimeStampHandlesAllFormats(UUnitTestContext testContext) { DateTime actualTime; var formats = PlayFabUtil._defaultDateTimeFormats; for (int i = 0; i < _examples.Length; i++) { string expectedFormat = i < formats.Length ? formats[i] : "default"; testContext.True(DateTime.TryParseExact(_examples[i], formats, CultureInfo.CurrentCulture, DateTimeStyles.RoundtripKind, out actualTime), "Index: " + i + "/" + _examples.Length + ", " + _examples[i] + " with " + expectedFormat); } DateTime expectedTime = DateTime.Now; for (int i = 0; i < formats.Length; i++) { string timeString = expectedTime.ToString(formats[i], CultureInfo.CurrentCulture); testContext.True(DateTime.TryParseExact(timeString, formats, CultureInfo.CurrentCulture, DateTimeStyles.RoundtripKind, out actualTime), "Index: " + i + "/" + formats.Length + ", " + formats[i] + " with " + timeString); testContext.True((actualTime - expectedTime).TotalSeconds < 1, "Expected: " + expectedTime + " vs actual:" + actualTime); } testContext.EndTest(UUnitFinishState.PASSED, null); }
void TimeStampHandlesAllFormats(UUnitTestContext testContext) { DateTime actualTime; var formats = PlayFabUtil._defaultDateTimeFormats; for (var i = 0; i < _examples.Length; i++) { var expectedFormat = i < formats.Length ? formats[i] : "default"; testContext.True(DateTime.TryParseExact(_examples[i], formats, CultureInfo.CurrentCulture, DateTimeStyles.RoundtripKind, out actualTime), "Index: " + i + "/" + _examples.Length + ", " + _examples[i] + " with " + expectedFormat); } var expectedTime = DateTime.Now; for (var i = 0; i < formats.Length; i++) { var timeString = expectedTime.ToString(formats[i], CultureInfo.CurrentCulture); testContext.True(DateTime.TryParseExact(timeString, formats, CultureInfo.CurrentCulture, DateTimeStyles.RoundtripKind, out actualTime), "Index: " + i + "/" + formats.Length + ", " + formats[i] + " with " + timeString); testContext.True((actualTime - expectedTime).TotalSeconds < 1, "Expected: " + expectedTime + " vs actual:" + actualTime); } testContext.EndTest(UUnitFinishState.PASSED, null); }
public void PassWithMessageJson(UUnitTestContext testContext) { var readFileName = Path.GetFullPath("../../testPassWithMessage.json"); testContext.True(File.Exists(readFileName), readFileName); var json = File.ReadAllText(readFileName); List <TestSuiteReport> testReport = JsonWrapper.DeserializeObject <List <TestSuiteReport> >(json); testContext.IntEquals(1, testReport.Count); foreach (var eachReport in testReport) { testContext.IntEquals(0, eachReport.failures); testContext.IntEquals(0, eachReport.skipped); testContext.NotNull(eachReport.testResults); foreach (var eachTest in eachReport.testResults) { testContext.True(eachTest.IsXmlSingleLine()); } } testContext.EndTest(UUnitFinishState.PASSED, null); }
public override void SetUp(UUnitTestContext testContext) { testTitleData = TestTitleDataLoader.Load(null); PlayFabSettings.staticSettings.TitleId = testTitleData.titleId; var task = clientApi.LoginWithCustomIDAsync(new LoginWithCustomIDRequest { CreateAccount = true, CustomId = TEST_CUSTOM_ID, TitleId = testTitleData.titleId }); task.Wait(); testContext.True(clientApi.IsClientLoggedIn(), "User login not successful: " + task.Result.Error?.GenerateErrorReport()); }
public void PassWithMessageXml(UUnitTestContext testContext) { var readFileName = Path.GetFullPath("../../testPassWithMessage.xml"); testContext.True(File.Exists(readFileName), readFileName); List <TestSuiteReport> inputReport = JUnitXml.ParseXmlFile(readFileName); JUnitXml.WriteXmlFile(_tempFileFullPath, inputReport, true); List <TestSuiteReport> testReport = JUnitXml.ParseXmlFile(_tempFileFullPath); testContext.IntEquals(1, testReport.Count); foreach (var eachReport in testReport) { testContext.IntEquals(0, eachReport.failures); testContext.IntEquals(0, eachReport.skipped); testContext.NotNull(eachReport.testResults); foreach (var eachTest in eachReport.testResults) { testContext.True(eachTest.IsXmlSingleLine()); } } testContext.EndTest(UUnitFinishState.PASSED, null); }
public void TestSilentLoginAfterUnlink(UUnitTestContext testContext) { var silentAuth = new PlayFabAuthService(); silentAuth.OnLoginSuccess += (success) => { testContext.True(success.PlayFabId != _emailAuthService.AuthenticationContext.PlayFabId, "Silent auth and email auth playFabIds is match!"); testContext.EndTest(UUnitFinishState.PASSED, "Silent auth completed as expected. New playFabId: " + success.PlayFabId); }; silentAuth.OnPlayFabError += (error) => { testContext.Fail("Silent auth abort with error: " + error.Error.ToString()); }; silentAuth.Authenticate(AuthTypes.Silent); }
/// <summary> /// Utility for tests to pass as soon as registration is successful /// On the first successful registration, this will piggyback some tests that can only occur on a successful registration /// </summary> /// <param name="testContext"></param> protected void PassOnSuccessfulRegistration(UUnitTestContext testContext) { if (_pushRegisterApiSuccessful) { testContext.True(PlayFabAndroidPushPlugin.IsPlayServicesAvailable(), "This test should have made Play Services available"); if (!_messagesTested) { PlayFabAndroidPushPlugin.AlwaysShowOnNotificationBar(false); // For the purpose of this test, hide the notifications from the device notification tray SendImmediateNotificationsAndWait(); SendScheduledNotificationsAndWait(); ActiveTick = WaitForExpectedMessages; } else { testContext.EndTest(UUnitFinishState.PASSED, null); } } }
/// <summary> /// Verify that: /// CSfunc_GetTestData clears any potential existing data /// CSfunc_SaveTestData adds test data /// CSfunc_TestDataExists can correctly verify both states /// </summary> // [UUnitTest] public void WriteTestSequence(UUnitTestContext testContext) { bool functionResult, callResult; string getErrorReport, saveErrorReport, fetchErrorReport; TestSuiteReport[] testResults; object nullReturn; var csListenCmd = new CloudScriptListener(); // Reset a previous test if relevant callResult = csListenCmd.ExecuteCloudScript(CloudScriptListener.CsFuncGetTestData, getRequest, testTitleData.extraHeaders, out testResults, out fetchErrorReport); //UUnitAssert.True(callResult, fetchErrorReport); // Verify that no data pre-exists callResult = csListenCmd.ExecuteCloudScript(CloudScriptListener.CsFuncTestDataExists, getRequest, testTitleData.extraHeaders, out functionResult, out getErrorReport); testContext.True(callResult, getErrorReport); testContext.False(functionResult, getErrorReport); // Save some data callResult = csListenCmd.ExecuteCloudScript(CloudScriptListener.CsFuncSaveTestData, saveRequest, testTitleData.extraHeaders, out nullReturn, out saveErrorReport); testContext.True(callResult, saveErrorReport); // Verify that the saved data exists callResult = csListenCmd.ExecuteCloudScript(CloudScriptListener.CsFuncTestDataExists, getRequest, testTitleData.extraHeaders, out functionResult, out getErrorReport); testContext.True(callResult, getErrorReport); testContext.True(functionResult, saveErrorReport); // Fetch that data callResult = csListenCmd.ExecuteCloudScript(CloudScriptListener.CsFuncGetTestData, getRequest, testTitleData.extraHeaders, out testResults, out fetchErrorReport); testContext.True(callResult, fetchErrorReport); testContext.NotNull(testResults, fetchErrorReport); // Verify that it was consumed callResult = csListenCmd.ExecuteCloudScript(CloudScriptListener.CsFuncTestDataExists, getRequest, testTitleData.extraHeaders, out functionResult, out getErrorReport); testContext.True(callResult, getErrorReport); testContext.False(functionResult, getErrorReport); testContext.EndTest(UUnitFinishState.PASSED, null); }
public async void EmitLightweightEventsAsync(UUnitTestContext testContext) #endif { // create and set settings for OneDS event pipeline var settings = new OneDSEventPipelineSettings(); settings.BatchSize = 8; settings.BatchFillTimeout = TimeSpan.FromSeconds(1); var logger = new DebugLogger(); // create OneDS event pipeline var oneDSPipeline = new OneDSEventPipeline(settings, logger); // create custom event API, add the pipeline var playFabEventApi = new PlayFabEventAPI(logger); #pragma warning disable 4014 playFabEventApi.EventRouter.AddAndStartPipeline(EventPipelineKey.OneDS, oneDSPipeline); #pragma warning restore 4014 // create and emit many lightweight events #if TPL_35 var results = new List <Task <IPlayFabEmitEventResponse> >(); #else var results = new List <Task>(); #endif for (int i = 0; i < 50; i++) { results.AddRange(playFabEventApi.EmitEvent(CreateSamplePlayFabEvent("Event_Custom", PlayFabEventType.Lightweight))); } // wait when the pipeline finishes sending all events #if TPL_35 Task.WhenAll(results).Await(); #else await Task.WhenAll(results); #endif // check results var sentBatches = new Dictionary <IList <IPlayFabEmitEventRequest>, int>(); foreach (var result in results) { testContext.True(result.IsCompleted, "Custom event emission task failed to complete"); PlayFabEmitEventResponse response = (PlayFabEmitEventResponse)((Task <IPlayFabEmitEventResponse>)result).Result; testContext.True(response.EmitEventResult == EmitEventResult.Success, "Custom event emission task failed to succeed"); testContext.True(response.PlayFabError == null && response.WriteEventsResponse != null, "Custom event failed to be sent"); if (!sentBatches.ContainsKey(response.Batch)) { sentBatches[response.Batch] = 0; } sentBatches[response.Batch]++; } int event8 = 0; int event2 = 0; foreach (var batch in sentBatches) { if (batch.Value == 8) { event8++; } else if (batch.Value == 2) { event2++; } } // 6 full batches of 8 events and 1 incomplete batch of 2 events are expected testContext.True(event8 == 6, "Wrong number of full batches"); testContext.True(event2 == 1, "Wrong number of incomplete batches"); testContext.EndTest(UUnitFinishState.PASSED, null); }
private static void CheckCallbacks(UUnitTestContext testContext, string expected, HashSet <string> actual) { testContext.True(actual.Contains(expected), "Want: " + expected + ", Got: " + string.Join(", ", actual.ToArray())); }
private static void CheckCallbacks(UUnitTestContext testContext, string expected, HashSet<string> actual) { testContext.True(actual.Contains(expected), "Want: " + expected + ", Got: " + string.Join(", ", actual.ToArray())); }
public void TestInstCallbacks_GeneralOnly(UUnitTestContext testContext) { _listener.Register(); PlayFabClientAPI.LoginWithCustomID(new LoginWithCustomIDRequest { CreateAccount = true, CustomId = "UnitySdk-UnitTest", TitleId = "6195" }, PlayFabUUnitUtils.ApiCallbackWrapper<LoginResult>(testContext, TestInstCallbacks_GeneralOnlyCallback), null, testContext); testContext.True(callbacks.Contains("OnRequest_InstGl"), string.Join(", ", callbacks.ToArray())); testContext.True(callbacks.Contains("OnRequest_InstLogin"), string.Join(", ", callbacks.ToArray())); testContext.IntEquals(2, callbacks.Count, string.Join(", ", callbacks.ToArray())); callbacks.Clear(); }