public void PfPush_JavaSerialization(UUnitTestContext testContext) { var javaPkg = new AndroidJavaObject("com.playfab.unityplugin.GCM.PlayFabNotificationPackage"); var expectedPkgs = new[] { new PlayFabNotificationPackage("test message0", "test title", 10), new PlayFabNotificationPackage("test message1", "test title", 11), new PlayFabNotificationPackage("test message2", "test title", 12), }; expectedPkgs[0].SetScheduleTime(DateTime.Now + TimeSpan.FromSeconds(10), ScheduleTypes.ScheduledLocal); expectedPkgs[1].SetScheduleTime(DateTime.UtcNow + TimeSpan.FromSeconds(10), ScheduleTypes.ScheduledUtc); expectedPkgs[2].SetScheduleTime(null, ScheduleTypes.None); for (var i = 0; i < expectedPkgs.Length; i++) { var expectedPkg = expectedPkgs[i]; expectedPkg.ToJava(ref javaPkg); var javaScheduleType = javaPkg.Get <string>("ScheduleType"); testContext.StringEquals(expectedPkg.ScheduleType.ToString(), javaScheduleType, "ScheduleType not assigned " + i + ", " + expectedPkg.ScheduleType + ", " + javaScheduleType); var actualPkg = PlayFabNotificationPackage.FromJava(javaPkg); testContext.StringEquals(expectedPkg.Message, actualPkg.Message, "Message mismatch " + i + ", " + expectedPkg.Message + ", " + actualPkg.Message); testContext.StringEquals(expectedPkg.Title, actualPkg.Title, "Title mismatch " + i + ", " + expectedPkg.Title + ", " + actualPkg.Title); testContext.IntEquals(expectedPkg.Id, actualPkg.Id, "Id mismatch " + i + ", " + expectedPkg.Id + ", " + actualPkg.Id); testContext.ObjEquals(expectedPkg.ScheduleType, actualPkg.ScheduleType, "ScheduleType mismatch " + i + ", " + expectedPkg.ScheduleType + ", " + actualPkg.ScheduleType); testContext.DateTimeEquals(expectedPkg.ScheduleDate, actualPkg.ScheduleDate, TimeSpan.FromSeconds(1), javaPkg.Get <string>("ScheduleDate")); } testContext.EndTest(UUnitFinishState.PASSED, null); }
public void MultipleInstanceWithDifferentSettings(UUnitTestContext testContext) { PlayFabApiSettings settings1 = new PlayFabApiSettings(); settings1.ProductionEnvironmentUrl = "https://test1.playfabapi.com"; settings1.TitleId = "test1"; settings1.DeveloperSecretKey = "key1"; PlayFabApiSettings settings2 = new PlayFabApiSettings(); settings2.ProductionEnvironmentUrl = "https://test2.playfabapi.com"; settings2.TitleId = "test2"; settings2.DeveloperSecretKey = "key2"; PlayFabServerInstanceAPI serverInstance1 = new PlayFabServerInstanceAPI(settings1); testContext.StringEquals("test1", serverInstance1.apiSettings.TitleId, "MultipleInstanceWithDifferentSettings can not be completed"); testContext.StringEquals("https://test1.playfabapi.com", serverInstance1.apiSettings.ProductionEnvironmentUrl, "MultipleInstanceWithDifferentSettings can not be completed"); testContext.StringEquals("key1", serverInstance1.apiSettings.DeveloperSecretKey, "MultipleInstanceWithDifferentSettings can not be completed"); PlayFabServerInstanceAPI serverInstance2 = new PlayFabServerInstanceAPI(settings2); testContext.StringEquals("test2", serverInstance2.apiSettings.TitleId, "MultipleInstanceWithDifferentSettings can not be completed"); testContext.StringEquals("https://test2.playfabapi.com", serverInstance2.apiSettings.ProductionEnvironmentUrl, "MultipleInstanceWithDifferentSettings can not be completed"); testContext.StringEquals("key2", serverInstance2.apiSettings.DeveloperSecretKey, "MultipleInstanceWithDifferentSettings can not be completed"); testContext.EndTest(UUnitFinishState.PASSED, null); }
public void StaticLogin(UUnitTestContext testContext) { var loginRequest = new LoginWithCustomIDRequest { CustomId = PlayFabSettings.BuildIdentifier, CreateAccount = true, }; var loginTask = PlayFabClientAPI.LoginWithCustomIDAsync(loginRequest); loginTask.Wait(); testContext.True(PlayFabClientAPI.IsClientLoggedIn(), "p2 client context leaked to static context"); testContext.True(PlayFabAuthenticationAPI.IsEntityLoggedIn(), "p2 entity context leaked to static context"); testContext.False(client1.IsClientLoggedIn(), "Static login leaked to Client1"); testContext.False(client2.IsClientLoggedIn(), "tatic login leaked to Client2"); testContext.False(auth1.IsEntityLoggedIn(), "Static login leaked to Auth1"); testContext.False(auth2.IsEntityLoggedIn(), "Static login leaked to Auth2"); // Verify useful player information testContext.NotNull(PlayFabSettings.staticPlayer.PlayFabId); testContext.NotNull(PlayFabSettings.staticPlayer.EntityId); testContext.NotNull(PlayFabSettings.staticPlayer.EntityType); PlayFabClientAPI.ForgetAllCredentials(); testContext.EndTest(UUnitFinishState.PASSED, PlayFabSettings.staticSettings.TitleId + ", " + loginTask.Result.Result.PlayFabId); }
public void OtherSpecificDatatypes(UUnitTestContext testContext) { var expectedObj = new OtherSpecificDatatypes { StringDict = new Dictionary <string, string> { { "stringKey", "stringValue" } }, EnumDict = new Dictionary <string, Region> { { "enumKey", Region.Japan } }, IntDict = new Dictionary <string, int> { { "intKey", int.MinValue } }, UintDict = new Dictionary <string, uint> { { "uintKey", uint.MaxValue } }, TestString = "yup", }; // Convert the object to json and back, and verify that everything is the same var actualJson = JsonWrapper.SerializeObject(expectedObj, PlayFabUtil.ApiSerializerStrategy).Replace(" ", "").Replace("\n", "").Replace("\r", "").Replace("\t", ""); var actualObject = JsonWrapper.DeserializeObject <OtherSpecificDatatypes>(actualJson, PlayFabUtil.ApiSerializerStrategy); testContext.ObjEquals(expectedObj.TestString, actualObject.TestString); testContext.SequenceEquals(expectedObj.IntDict, actualObject.IntDict); testContext.SequenceEquals(expectedObj.UintDict, actualObject.UintDict); testContext.SequenceEquals(expectedObj.StringDict, actualObject.StringDict); testContext.SequenceEquals(expectedObj.EnumDict, actualObject.EnumDict); testContext.EndTest(UUnitFinishState.PASSED, null); }
public void AsyncMultiUserLogin(UUnitTestContext testContext) { var player1LoginRequest = new LoginWithCustomIDRequest { CustomId = PlayFabSettings.BuildIdentifier + "0", CreateAccount = true }; var player2LoginRequest = new LoginWithCustomIDRequest { CustomId = PlayFabSettings.BuildIdentifier + "1", CreateAccount = true }; PlayFabClientAPI.LoginWithCustomID(player1LoginRequest, x => _player1 = x.AuthenticationContext, PlayFabUUnitUtils.ApiActionWrapper <PlayFabError>(testContext, SharedErrorCallback), testContext); PlayFabClientAPI.LoginWithCustomID(player2LoginRequest, x => _player2 = x.AuthenticationContext, PlayFabUUnitUtils.ApiActionWrapper <PlayFabError>(testContext, SharedErrorCallback), testContext); _tickAction = () => { // return if players not loaded yet if (_player1 == null || _player2 == null) { return; } // reset delegate to avoid calling this method again _tickAction = null; // players must not be equals testContext.False(_player1.PlayFabId == _player2.PlayFabId); testContext.EndTest(UUnitFinishState.PASSED, "Two players are successfully login. " + _player1.PlayFabId + ", " + _player2.PlayFabId); }; }
public void PluginManagerMultiplePluginsPerContract(UUnitTestContext testContext) { const string customTransportName1 = "Custom transport client 1"; const string customTransportName2 = "Custom transport client 2"; var playFabTransport = PluginManager.GetPlugin <ITransportPlugin>(PluginContract.PlayFab_Transport); var expectedTransport1 = new CustomTransportPlugin() { Name = customTransportName1 }; var expectedTransport2 = new CustomTransportPlugin() { Name = customTransportName2 }; // Set custom plugins PluginManager.SetPlugin(expectedTransport1, PluginContract.PlayFab_Transport, customTransportName1); PluginManager.SetPlugin(expectedTransport2, PluginContract.PlayFab_Transport, customTransportName2); // Verify var actualTransport = PluginManager.GetPlugin <ITransportPlugin>(PluginContract.PlayFab_Transport); testContext.True(object.ReferenceEquals(actualTransport, playFabTransport)); // the default one is still the same var actualTransport1 = PluginManager.GetPlugin <ITransportPlugin>(PluginContract.PlayFab_Transport, customTransportName1); testContext.True(object.ReferenceEquals(actualTransport1, expectedTransport1)); var actualTransport2 = PluginManager.GetPlugin <ITransportPlugin>(PluginContract.PlayFab_Transport, customTransportName2); testContext.True(object.ReferenceEquals(actualTransport2, expectedTransport2)); testContext.EndTest(UUnitFinishState.PASSED, null); }
public void CheckWithAuthContextAndWithoutAuthContext(UUnitTestContext testContext) { PlayFabSettings.DeveloperSecretKey = testTitleData.developerSecretKey; //IT will use static developer key - Should has no error PlayFabServerInstanceAPI serverInstance1 = new PlayFabServerInstanceAPI(); var result = serverInstance1.GetAllSegmentsAsync(new GetAllSegmentsRequest()).Result; PlayFabAuthenticationContext context = new PlayFabAuthenticationContext(); context.DeveloperSecretKey = "WRONGKEYTOFAIL"; //IT will use context developer key - Should has error because of wrong key PlayFabServerInstanceAPI serverInstance2 = new PlayFabServerInstanceAPI(context); var result2 = serverInstance2.GetAllSegmentsAsync(new GetAllSegmentsRequest()).Result; try { testContext.NotNull(result.Result, "Server Instance1 result is null"); testContext.IsNull(result.Error, "Server Instance1 result got error message : " + result.Error?.ErrorMessage ?? string.Empty); testContext.IsNull(result2.Result, "Server Instance2 result is not null"); testContext.NotNull(result2.Error, "Server Instance2 got no error message"); testContext.IntEquals(401, result2.Error.HttpCode, "Server Instance2 got wrong error"); testContext.EndTest(UUnitFinishState.PASSED, null); } catch (Exception ex) { testContext.Fail("CheckWithAuthContextAndWithoutAuthContext failed : " + ex.Message); } }
public void Instance2Login(UUnitTestContext testContext) { var loginRequest = new LoginWithCustomIDRequest { CustomId = PlayFabSettings.BuildIdentifier, CreateAccount = true, }; var loginTask = client2.LoginWithCustomIDAsync(loginRequest); loginTask.Wait(); testContext.True(player2.IsClientLoggedIn(), "player2 client login failed, "); testContext.True(client2.IsClientLoggedIn(), "client2 client login failed"); testContext.True(player2.IsEntityLoggedIn(), "player2 entity login failed"); testContext.True(auth2.IsEntityLoggedIn(), "auth2 entity login failed"); testContext.False(PlayFabClientAPI.IsClientLoggedIn(), "p2 client context leaked to static context"); testContext.False(PlayFabAuthenticationAPI.IsEntityLoggedIn(), "p2 entity context leaked to static context"); // Verify useful player information testContext.NotNull(player2.PlayFabId); testContext.NotNull(player2.EntityId); testContext.NotNull(player2.EntityType); testContext.EndTest(UUnitFinishState.PASSED, PlayFabSettings.staticSettings.TitleId + ", " + loginTask.Result.Result.PlayFabId); }
public void MultiplePlayerApiCall(UUnitTestContext testContext) { if (authenticationContext1?.ClientSessionTicket == null || authenticationContext2?.ClientSessionTicket == null) { testContext.Skip("To run this test MultipleLoginWithStaticMethods test should be passed and store authenticationContext values"); } var getPlayerProfileRequest = new GetPlayerProfileRequest() { AuthenticationContext = authenticationContext1, PlayFabId = authenticationContext1.PlayFabId }; var getPlayerProfileRequest2 = new GetPlayerProfileRequest() { AuthenticationContext = authenticationContext2, PlayFabId = authenticationContext2.PlayFabId }; var getPlayerProfileTask = clientApi.GetPlayerProfileAsync(getPlayerProfileRequest, null, testTitleData.extraHeaders).Result; var getPlayerProfileTask2 = clientApi.GetPlayerProfileAsync(getPlayerProfileRequest2, null, testTitleData.extraHeaders).Result; testContext.NotNull(getPlayerProfileTask.Result, "GetPlayerProfile Failed for getPlayerProfileRequest"); testContext.NotNull(getPlayerProfileTask2.Result, "GetPlayerProfile Failed for getPlayerProfileRequest2"); testContext.IsNull(getPlayerProfileTask.Error, "GetPlayerProfile error occured for getPlayerProfileRequest: " + getPlayerProfileTask.Error?.ErrorMessage ?? string.Empty); testContext.IsNull(getPlayerProfileTask2.Error, "GetPlayerProfile error occured for getPlayerProfileRequest2: " + getPlayerProfileTask2.Error?.ErrorMessage ?? string.Empty); testContext.EndTest(UUnitFinishState.PASSED, null); }
void DeleteFiles(UUnitTestContext testContext, List <string> fileName, bool shouldEndTest, UUnitFinishState finishState, string finishMessage) { if (!_shouldDeleteFiles) // Only delete the file if it was created { return; } var request = new DataModels.DeleteFilesRequest { Entity = new DataModels.EntityKey { Id = _entityId, Type = _entityType }, FileNames = fileName, }; _shouldDeleteFiles = false; // We have successfully deleted the file, it should not try again in teardown PlayFabDataAPI.DeleteFiles(request, result => { if (shouldEndTest) { testContext.EndTest(finishState, finishMessage); } }, PlayFabUUnitUtils.ApiActionWrapper <PlayFabError>(testContext, SharedErrorCallback), testContext); }
private void ProcessBothLogins(UUnitTestContext testContext) { testContext.False(InstancePlayFabId1 == InstancePlayFabId2); if (!string.IsNullOrEmpty(InstancePlayFabId1) && !string.IsNullOrEmpty(InstancePlayFabId2)) { testContext.EndTest(UUnitFinishState.PASSED, null); } }
public void PluginManagerDefaultPlugins(UUnitTestContext testContext) { var playFabSerializer = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer); var playFabTransport = PluginManager.GetPlugin <ITransportPlugin>(PluginContract.PlayFab_Transport); testContext.NotNull(playFabSerializer); testContext.NotNull(playFabTransport); testContext.EndTest(UUnitFinishState.PASSED, null); }
public void TestDeserializeToObject(UUnitTestContext testContext) { var testInt = PlayFabSimpleJson.DeserializeObject <object>("1"); var testString = PlayFabSimpleJson.DeserializeObject <object>("\"a string\""); testContext.IntEquals((int)(ulong)testInt, 1); testContext.StringEquals((string)testString, "a string"); testContext.EndTest(UUnitFinishState.PASSED, null); }
public void TimeSpanJson(UUnitTestContext testContext) { TimeSpan span = TimeSpan.FromSeconds(5); string actualJson = JsonWrapper.SerializeObject(span, PlayFabUtil.ApiSerializerStrategy); string expectedJson = "5"; testContext.StringEquals(expectedJson, actualJson, actualJson); testContext.EndTest(UUnitFinishState.PASSED, null); }
public void TimeSpanJson(UUnitTestContext testContext) { var span = TimeSpan.FromSeconds(5); var actualJson = JsonWrapper.SerializeObject(span); var expectedJson = "5"; testContext.StringEquals(expectedJson, actualJson, actualJson); testContext.EndTest(UUnitFinishState.PASSED, null); }
public void CreateMultipleServerInstance(UUnitTestContext testContext) { PlayFabServerInstanceAPI serverInstanceWithoutAnyParameter = new PlayFabServerInstanceAPI(); PlayFabServerInstanceAPI serverInstanceWithSettings = new PlayFabServerInstanceAPI(instanceSettings); PlayFabServerInstanceAPI serverInstanceWithContext = new PlayFabServerInstanceAPI(instanceContext); PlayFabServerInstanceAPI serverInstanceWithSameParameter = new PlayFabServerInstanceAPI(instanceContext); PlayFabServerInstanceAPI serverInstanceWithSettingsAndContext = new PlayFabServerInstanceAPI(instanceSettings, instanceContext); testContext.EndTest(UUnitFinishState.PASSED, null); }
//[UUnitTest] public void TimeSpanJson(UUnitTestContext testContext) { var span = TimeSpan.FromSeconds(5); var actualJson = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer).SerializeObject(span); var expectedJson = "5"; testContext.StringEquals(expectedJson, actualJson, actualJson); testContext.EndTest(UUnitFinishState.PASSED, null); }
public void MultipleLoginWithStaticMethods(UUnitTestContext testContext) { // If the setup failed to log in a user, we need to create one. var loginRequest1 = new LoginWithCustomIDRequest { TitleId = PlayFabSettings.staticSettings.TitleId, CustomId = "test_SDK1", CreateAccount = true, }; var loginRequest2 = new LoginWithCustomIDRequest { TitleId = PlayFabSettings.staticSettings.TitleId, CustomId = "test_SDK2", CreateAccount = true, }; var loginRequest3 = new LoginWithCustomIDRequest { TitleId = PlayFabSettings.staticSettings.TitleId, CustomId = "test_SDK3", CreateAccount = true, }; var loginTask1 = clientApi.LoginWithCustomIDAsync(loginRequest1, null, testTitleData.extraHeaders).Result; var loginTask2 = clientApi.LoginWithCustomIDAsync(loginRequest2, null, testTitleData.extraHeaders).Result; var loginTask3 = clientApi.LoginWithCustomIDAsync(loginRequest3, null, testTitleData.extraHeaders).Result; testContext.NotNull(loginTask1.Result, "Login Result is null for loginRequest1"); testContext.NotNull(loginTask2.Result, "Login Result is null for loginRequest2"); testContext.NotNull(loginTask3.Result, "Login Result is null for loginRequest3"); testContext.IsNull(loginTask1.Error, "Login error occured for loginRequest1: " + loginTask1.Error?.ErrorMessage ?? string.Empty); testContext.IsNull(loginTask2.Error, "Login error occured for loginRequest2: " + loginTask2.Error?.ErrorMessage ?? string.Empty); testContext.IsNull(loginTask3.Error, "Login error occured for loginRequest3: " + loginTask3.Error?.ErrorMessage ?? string.Empty); testContext.NotNull(loginTask1.Result.AuthenticationContext, "AuthenticationContext is not set for loginRequest1,"); testContext.NotNull(loginTask2.Result.AuthenticationContext, "AuthenticationContext is not set for loginRequest2"); testContext.NotNull(loginTask3.Result.AuthenticationContext, "AuthenticationContext is not set for loginRequest3"); if (string.Equals(loginTask1.Result.AuthenticationContext.ClientSessionTicket, loginTask2.Result.AuthenticationContext.ClientSessionTicket)) { testContext.Fail("Multiple Login Failed AuthenticationContexts are same for task1 and task2: " + loginTask1.Result.AuthenticationContext.ClientSessionTicket); } if (string.Equals(loginTask2.Result.AuthenticationContext.ClientSessionTicket, loginTask3.Result.AuthenticationContext.ClientSessionTicket)) { testContext.Fail("Multiple Login Failed AuthenticationContexts are same for task2 and task3: " + loginTask2.Result.AuthenticationContext.ClientSessionTicket); } if (string.Equals(loginTask1.Result.AuthenticationContext.ClientSessionTicket, loginTask3.Result.AuthenticationContext.ClientSessionTicket)) { testContext.Fail("Multiple Login Failed AuthenticationContexts are same for task1 and task3: " + loginTask1.Result.AuthenticationContext.ClientSessionTicket); } authenticationContext1 = loginTask1.Result.AuthenticationContext; authenticationContext2 = loginTask2.Result.AuthenticationContext; authenticationContext3 = loginTask3.Result.AuthenticationContext; testContext.EndTest(UUnitFinishState.PASSED, null); }
//[UUnitTest] public void TestDeserializeToObject(UUnitTestContext testContext) { var serializer = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer); var testInt = serializer.DeserializeObject <object>("1"); var testString = serializer.DeserializeObject <object>("\"a string\""); testContext.IntEquals((int)(ulong)testInt, 1); testContext.StringEquals((string)testString, "a string"); testContext.EndTest(UUnitFinishState.PASSED, null); }
private static void ContinueWithContext <T>(Task <PlayFabResult <T> > srcTask, UUnitTestContext testContext, Action <PlayFabResult <T>, UUnitTestContext, string> continueAction, bool expectSuccess, string failMessage, bool endTest) where T : PlayFabResultCommon { srcTask.ContinueWith(task => { var failed = true; try { if (expectSuccess) { testContext.NotNull(task.Result, failMessage); testContext.IsNull(task.Result.Error, PlayFabUtil.GetErrorReport(task.Result.Error)); testContext.NotNull(task.Result.Result, failMessage); } if (continueAction != null) { continueAction.Invoke(task.Result, testContext, failMessage); } failed = false; } catch (UUnitSkipException uu) { // Silence the assert and ensure the test is marked as complete - The exception is just to halt the test process testContext.EndTest(UUnitFinishState.SKIPPED, uu.Message); } catch (UUnitException uu) { // Silence the assert and ensure the test is marked as complete - The exception is just to halt the test process testContext.EndTest(UUnitFinishState.FAILED, uu.Message + "\n" + uu.StackTrace); } catch (Exception e) { // Report this exception as an unhandled failure in the test testContext.EndTest(UUnitFinishState.FAILED, e.ToString()); } if (!failed && endTest) { testContext.EndTest(UUnitFinishState.PASSED, null); } } ); }
private void GetObjects2Continued(PlayFabResult <GetObjectsResponse> result, UUnitTestContext testContext, string failMessage) { testContext.IntEquals(result.Result.Objects.Count, 1); testContext.StringEquals(result.Result.Objects[TEST_DATA_KEY].ObjectName, TEST_DATA_KEY); if (!int.TryParse(result.Result.Objects[TEST_DATA_KEY].EscapedDataObject, out int actualValue)) { actualValue = -1000; } testContext.IntEquals(_testInteger, actualValue, "Failed: " + _testInteger + "!=" + actualValue + ", Returned json: " + result.Result.Objects[TEST_DATA_KEY].EscapedDataObject); testContext.EndTest(UUnitFinishState.PASSED, null); }
public void PlayerStatisticsApi(UUnitTestContext testContext) { if (!TITLE_CAN_UPDATE_SETTINGS) { testContext.EndTest(UUnitFinishState.SKIPPED, "This title cannot update statistics from the client"); return; } var getRequest = new GetPlayerStatisticsRequest(); PlayFabClientAPI.GetPlayerStatistics(getRequest, PlayFabUUnitUtils.ApiActionWrapper <GetPlayerStatisticsResult>(testContext, GetPlayerStatsCallback1), PlayFabUUnitUtils.ApiActionWrapper <PlayFabError>(testContext, SharedErrorCallback), testContext); }
/// <summary> /// Test-wrapper callback for API-Callbacks /// If there are unhandled exceptions in those tests, make sure it gets reported to the test as a failure /// This is ONLY meant to be used by the PlayFab UUnit test framework /// </summary> public static Action <T> ApiActionWrapper <T>(UUnitTestContext testContext, Action <T> myfunc) { Action <T> subWrapper = (response) => { try { myfunc(response); } catch (UUnitException uu) { // Silence the assert and ensure the test is marked as complete - The exception is just to halt the test process testContext.EndTest(testContext.FinishState, uu.Message + "\n" + uu.StackTrace); } catch (Exception e) { // Report this exception as an unhandled failure in the test testContext.EndTest(UUnitFinishState.FAILED, e.ToString()); } }; return(subWrapper); }
/// <summary> /// Ensure that exceptions in any test-functions are relayed to the testContext as failures /// </summary> private void Wrap(UUnitTestContext testContext, Action <UUnitTestContext> testFunc) { try { testFunc(testContext); } catch (UUnitSkipException uu) { // Silence the assert and ensure the test is marked as complete - The exception is just to halt the test process testContext.EndTest(UUnitFinishState.SKIPPED, uu.Message); } catch (UUnitException uu) { // Silence the assert and ensure the test is marked as complete - The exception is just to halt the test process testContext.EndTest(UUnitFinishState.FAILED, uu.Message + "\n" + uu.StackTrace); } catch (Exception e) { // Report this exception as an unhandled failure in the test testContext.EndTest(UUnitFinishState.FAILED, e.ToString()); } }
//[UUnitTest] public void ArrayOfObjects(UUnitTestContext testContext) { var actualJson = "[{\"a\":\"aValue\"}, {\"b\":\"bValue\"}]"; var actualObjectList = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer).DeserializeObject <List <object> >(actualJson); var actualObjectArray = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer).DeserializeObject <object[]>(actualJson); testContext.IntEquals(actualObjectList.Count, 2); testContext.IntEquals(actualObjectArray.Length, 2); testContext.StringEquals(((JsonObject)actualObjectList[0])["a"] as string, "aValue"); testContext.StringEquals(((JsonObject)actualObjectList[1])["b"] as string, "bValue"); testContext.EndTest(UUnitFinishState.PASSED, null); }
public void ArrayOfObjects(UUnitTestContext testContext) { string actualJson = "[{\"a\":\"aValue\"}, {\"b\":\"bValue\"}]"; var actualObjectList = JsonWrapper.DeserializeObject <List <object> >(actualJson); var actualObjectArray = JsonWrapper.DeserializeObject <object[]>(actualJson); testContext.IntEquals(actualObjectList.Count, 2); testContext.IntEquals(actualObjectArray.Length, 2); testContext.StringEquals(((JsonObject)actualObjectList[0])["a"] as string, "aValue"); testContext.StringEquals(((JsonObject)actualObjectList[1])["b"] as string, "bValue"); testContext.EndTest(UUnitFinishState.PASSED, null); }
public void ArrayAsObject(UUnitTestContext testContext) { string json = "{\"Version\": \"2016-06-21_23-57-16\", \"ObjectArray\": [{\"Id\": 2, \"Name\": \"Stunned\", \"Type\": \"Condition\", \"ShowNumber\": true, \"EN_text\": \"Stunned\", \"EN_reminder\": \"Can\'t attack, block, or activate\"}, {\"Id\": 3, \"Name\": \"Poisoned\", \"Type\": \"Condition\", \"ShowNumber\": true, \"EN_text\": \"Poisoned\", \"EN_reminder\": \"Takes {N} damage at the start of each turn. Wears off over time.\" }], \"StringArray\": [\"NoSubtype\", \"Aircraft\"]}"; var result = JsonWrapper.DeserializeObject <Dictionary <string, object> >(json); var version = result["Version"] as string; var objArray = result["ObjectArray"] as List <object>; var strArray = result["StringArray"] as List <object>; testContext.NotNull(result); testContext.True(!string.IsNullOrEmpty(version)); testContext.True(objArray != null && objArray.Count > 0); testContext.True(strArray != null && strArray.Count > 0); testContext.EndTest(UUnitFinishState.PASSED, null); }
public void Test200Response(UUnitTestContext testContext) { mockHttpPlugin.AssignResponse(HttpStatusCode.OK, "{\"data\": {\"RSAPublicKey\": \"Test Result\"} }", null); // GetTitlePublicKey has no auth, and trivial input/output so it's pretty ideal for a fake API call var task = PlayFabClientAPI.GetTitlePublicKeyAsync(null); task.Wait(); testContext.IsNull(task.Result.Error); testContext.NotNull(task.Result.Result); testContext.StringEquals("Test Result", task.Result.Result.RSAPublicKey); testContext.EndTest(UUnitFinishState.PASSED, null); }
public void NullableJson(UUnitTestContext testContext) { var testObj = new NullableTestClass(); var actualJson = JsonWrapper.SerializeObject(testObj, PlayFabUtil.ApiSerializerStrategy); var actualObj = JsonWrapper.DeserializeObject <NullableTestClass>(actualJson); testContext.IsNull(actualObj.IntField, "Nullable integer field does not serialize properly: " + testObj.IntField + ", from " + actualJson); testContext.IsNull(actualObj.IntProperty, "Nullable integer property does not serialize properly: " + testObj.IntProperty + ", from " + actualJson); testContext.IsNull(actualObj.TimeField, "Nullable struct field does not serialize properly: " + testObj.TimeField + ", from " + actualJson); testContext.IsNull(actualObj.TimeProperty, "Nullable struct property does not serialize properly: " + testObj.TimeProperty + ", from " + actualJson); testContext.IsNull(actualObj.EnumField, "Nullable enum field does not serialize properly: " + testObj.EnumField + ", from " + actualJson); testContext.IsNull(actualObj.EnumProperty, "Nullable enum property does not serialize properly: " + testObj.EnumProperty + ", from " + actualJson); testContext.EndTest(UUnitFinishState.PASSED, null); }
public void CreateMultipleServerInstance(UUnitTestContext testContext) { PlayFabApiSettings settings = new PlayFabApiSettings(); settings.TitleId = testTitleData.titleId; settings.DeveloperSecretKey = testTitleData.developerSecretKey; var instance1 = new PlayFabServerInstanceAPI(); var instance2 = new PlayFabServerInstanceAPI(settings); instance1.ForgetAllCredentials(); instance2.ForgetAllCredentials(); testContext.EndTest(UUnitFinishState.PASSED, null); }