private async Task RunWaitForNoVisualChangeInSceneTest() { AssertVisually assertVisually = NewAssertVisuallyInstance("Ui19_RunVisualRegression_ExampleUsage3"); Task visualChangeMonitorTask = assertVisually.WaitForNoVisualChangeInScene(); AssertV2.IsFalse(visualChangeMonitorTask.IsCompleted, "visualChangeMonitorTask.IsCompleted"); gameObject.AddChild(await NewUiFor <MyUserModelv1>()); // Change the UI await TaskV2.Delay(200); // After 200 ms the monitorTask should still be checking: AssertV2.IsFalse(visualChangeMonitorTask.IsCompleted, "visualChangeMonitorTask.IsCompleted"); gameObject.AddChild(await NewUiFor <MyUserModelv2>()); // Change the UI again await TaskV2.Delay(200); // After 200 ms the monitorTask should still be checking: AssertV2.IsFalse(visualChangeMonitorTask.IsCompleted, "visualChangeMonitorTask.IsCompleted"); gameObject.AddChild(await NewUiFor <MyUserModelv1>()); // Change the UI again await TaskV2.Delay(200); // After 200 ms the monitorTask should still be checking: AssertV2.IsFalse(visualChangeMonitorTask.IsCompleted, "visualChangeMonitorTask.IsCompleted"); await TaskV2.Delay(2000); // Dont change the UI for 2 sec // Now the change monitor task should have completed since the sceen did not change for 2 sec: AssertV2.IsTrue(visualChangeMonitorTask.IsCompleted, "visualChangeMonitorTask.IsCompleted"); await visualChangeMonitorTask; // await the task in case there was an exception }
public override IEnumerator RunTest() { // Show some empty view as a background for the toasts: ViewStackHelper.MainViewStack().ShowView(someUiScreenPrefabName); Toast.Show("Some toast 1", "Lorem ipsum 1"); yield return(new WaitForSeconds(1)); Toast.Show("Some toast 2"); // In between show another screen on the main view stack, to ensure it does not interrupt showing the toasts: ViewStackHelper.MainViewStack().SwitchToView(someUiScreenPrefabName); yield return(new WaitForSeconds(1)); var toast3 = Toast.Show("Some toast 3", "Lorem ipsum 3", 2500); AssertV2.IsFalse(toast3.IsDestroyed(), "Toast was already destroyed"); yield return(new WaitForSeconds(3)); AssertV2.IsTrue(toast3.IsDestroyed(), "Toast could not be destroyed"); RootCanvas.GetAllRootCanvases().Single().gameObject.Destroy(); Toast.Show("Some toast 4"); yield return(new WaitForSeconds(3)); }
public async Task <GameObject> NewViewFromSchema(JsonSchema schema, JsonSchemaToView generator) { AssertV2.IsNotNull(schema, "schema"); AssertV2.IsNotNull(generator, "generator"); if (schema.properties == null) { AssertV2.IsFalse(generator.schemaGenerator.schemas.IsNullOrEmpty(), "generator.schema dict is emtpy!"); if (generator.schemaGenerator.schemas.TryGetValue(schema.modelType, out JsonSchema vm)) { schema = vm; } else { Log.e($"No Schema found for schema.modelType={schema.modelType}"); } } AssertV2.IsNotNull(schema.properties, "schema.properties"); GameObject rootContainerView = await generator.NewRootContainerView(rootPrefabName); rootContainerView.GetComponentInChildren <FieldView>().field = schema; var innerContainer = await generator.SelectInnerViewContainerFromObjectFieldView(rootContainerView); await generator.ObjectJsonSchemaToView(schema, innerContainer); return(rootContainerView); }
private static string ReadFullString(StreamReader streamReader) { streamReader.DiscardBufferedData(); streamReader.BaseStream.Position = 0; var fullString = streamReader.ReadToEnd(); AssertV2.IsFalse(fullString.IsNullOrEmpty(), "The string loaded from the streamReader was null or emtpy"); return(fullString); }
private ImmutableList <ServerAction> MutateServerActions(T store, ServerAction a) { if (store.serverOutbox == null) { return(ImmutableList.Create <ServerAction>(a)); } AssertV2.IsFalse(store.serverOutbox.serverActions.Contains(a), "Action " + a + " already in the action list!"); return(store.serverOutbox.serverActions.Add(a)); }
private static bool JsonCouldBeFullyParsed(IJsonReader jsonReader, IJsonWriter jsonWriter, object result, string json) { try { AssertV2.IsFalse(string.IsNullOrEmpty(json), "Json isNullOrEmpty"); var input = jsonReader.Read <System.Collections.Generic.Dictionary <string, object> >(json); var parsed = jsonReader.Read <System.Collections.Generic.Dictionary <string, object> >(jsonWriter.Write(result)); AssertV2.IsNotNull(parsed, "parsed"); return(JsonCouldBeFullyParsed(jsonReader, result.GetType().Name, input, parsed, 0)); } catch (Exception e) { Log.e(new Exception("exception during parsing json=" + json, e)); } return(false); }
/// <summary> Moves up the tree until it reaches the direct child of the viewstack </summary> private GameObject GetRootFor(GameObject go) { AssertV2.IsFalse(go == gameObject, "Cant get root for ViewStack gameobject"); var parent = go.GetParent(); if (parent == gameObject) { return(go); } // stop when the GO of the viewstack is reached return(GetRootFor(parent)); }
public override IEnumerator RunTest() { Toast.Show("Some toast 1", "Lorem ipsum 1"); yield return(new WaitForSeconds(1)); Toast.Show("Some toast 2"); yield return(new WaitForSeconds(1)); var toast3 = Toast.Show("Some toast 3", "Lorem ipsum 3", 1000); AssertV2.IsFalse(toast3.IsDestroyed(), "Toast was already destroyed"); yield return(new WaitForSeconds(2)); AssertV2.IsTrue(toast3.IsDestroyed(), "Toast could not be destroyed"); }
public bool TryGetColor(string colorName, out Color c) { c = Color.clear; if (colors.IsNullOrEmpty()) { return(false); } AssertV2.IsNotNull(colorName, "colorName"); AssertV2.IsFalse(colors.IsNullOrEmpty(), "colors.IsNullOrEmpty"); var namedColor = colors.FirstOrDefault(x => x.colorName == colorName); if (namedColor != null) { c = namedColor.colorValue; return(true); } return(false); }
/// <summary> This example shows how to use the DialogLoader manually to have full control over the UI presenter </summary> private async Task UseDialogLoaderManually() { var loader = new DialogLoader <ConfirmCancelDialog>(new ConfirmCancelDialog(caption: "I am a dialog", message: "I can be awaited in the code, the async or coroutine can wait for the user " + "to make a decision (select cancel or confirm) before the code continues!")); GameObject dialogUi = loader.LoadDialogPrefab(new ConfirmCancelDialog.DefaultPresenter(), dialogPrefabName: "Dialogs/DefaultDialog1"); RootCanvas.GetOrAddRootCanvas().gameObject.AddChild(dialogUi); // Add dialog UI in a canvas var waitForUserInputInDialogTask = loader.ShowDialogAsync(); AssertV2.IsFalse(loader.data.dialogWasConfirmed, "Dialog was already confirmed!"); await SimulateConfirmButtonClick(); ConfirmCancelDialog dialog = await waitForUserInputInDialogTask; // Wait until user clicks cancel or confirm AssertV2.IsTrue(dialog.dialogWasConfirmed, "Dialog was not confirmed!"); }
private void RecordEntry(object action, object dispatcherResult, string exception = null) { if (!isRecording) { return; } if (action is ResetStoreAction) { throw Log.e("The recorded actions will include a ResetStoreAction"); } AssertV2.IsFalse(action is Delegate, "The recorder received a delegate action, should be prevented by Thunk"); try { Entry nextEntry = new Entry() { action = action, e = "" + exception }; persistance.Set(GetId(recordedActionsCount), jsonWriter.Write(nextEntry)); recordedActionsCount++; } catch (Exception e) { Log.e("Could not record action " + action, e); } }
public string GetFileNameOnServer() { var name = ExtractFileName(GetHeaderValue("content-disposition", null)); if (name.IsNullOrEmpty()) { Log.w("Filename not found, will try fallback to hash+mimetype"); name += GetHeaderValue("Last-Modified", ""); name += GetHeaderValue("Content-Length", ""); name += GetContentMimeType(""); AssertV2.IsFalse(name.IsNullOrEmpty(), "name was emtpy"); name = name.GetSHA1Hash(); string ext = GetFileExtensionFromMimeType(null); if (ext != null) { name += "." + ext; } } return(name); }
protected override void Start() { base.Start(); var assembliesToTest = anyTypeInTargetAssembly.Map(typeString => { try { return(Type.GetType(typeString).Assembly); } catch (Exception) { Log.e("Please check the XunitTestRunnerUi.anyTypeInTargetAssembly " + "list in your scene UI, it if's configured correctly. Could " + "not find type for string '" + typeString + "'", gameObject); return(null); } }); pm = new ProgressManager(); var progressUis = ResourcesV2.FindAllInScene <ProgressUi>(); AssertV2.IsFalse(progressUis.IsNullOrEmpty(), "progressUi"); foreach (var progrUi in progressUis) { progrUi.progressManager = pm; } // On the parent canvas level collect all links: var links = GetComponentInParent <Canvas>().gameObject.GetLinkMap(); var autoRunToggle = links.Get <Toggle>("AutoRunToggle"); autoRunToggle.isOn = autoRunAllTests; autoRunToggle.SetOnValueChangedAction(isChecked => { autoRunAllTests = isChecked; return(true); }); links.Get <Button>("StartButton").SetOnClickAction((_) => { CollectTests(assembliesToTest, links); UpdateSearchFilter(links); }); links.Get <InputField>("SearchInput").SetOnValueChangedActionThrottled((_) => { UpdateSearchFilter(links); }, 200); }
private static bool IsAlreadyDownloaded(this IFileRef self, Headers headers, FileEntry targetFile) { if (targetFile.Exists) { AssertV2.IsFalse(self.checksums.IsNullOrEmpty(), "targetFile.Exists but no checksums stored"); // Cancel download if etag header matches the locally stored one: if (self.HasMatchingChecksum(headers.GetEtagHeader())) { return(true); } // Cancel download if local file with the same MD5 hash exists: var onlineMD5 = headers.GetMD5Checksum(); if (!onlineMD5.IsNullOrEmpty()) { if (self.HasMatchingChecksum(onlineMD5)) { return(true); } if (onlineMD5 == targetFile.CalcFileMd5Hash()) { return(true); } } // Cancel download if local file with the exact last-write timestamp exists: if (headers.GetRawLastModifiedString() != null) { var distance = headers.GetLastModifiedUtcDate(DateTime.MinValue) - targetFile.LastWriteTime.ToUniversalTime(); Log.d("distance.Milliseconds: " + distance.Milliseconds); if (distance.Milliseconds == 0) { return(true); } } } return(false); }
public bool SetCookie(Cookie cookie, bool saveToCookieFile = true) { lock (cookieJarLock) { if (cookie.expirationDate.ToUnixTimestampUtc() <= 0) { } bool receivedCookieExpired = cookie.expirationDate.IsBefore(DateTimeV2.UtcNow); if (cookies.ContainsKey(cookie.name)) { for (int index = 0; index < cookies[cookie.name].Count; ++index) { Cookie collidableCookie = cookies[cookie.name][index]; if (collidableCookie.CollidesWith(new CookieAccessInfo(cookie))) { if (cookie.value.IsNullOrEmpty() && !collidableCookie.value.IsNullOrEmpty()) { Log.e((collidableCookie + " replaced by " + (receivedCookieExpired ? "expired " : " ") + cookie)); } if (receivedCookieExpired) { cookies[cookie.name].RemoveAt(index); if (cookies[cookie.name].Count == 0) { cookies.Remove(cookie.name); if (saveToCookieFile) { SaveAllCookies(); } } return(false); } else { cookies[cookie.name][index] = cookie; if (saveToCookieFile) { SaveAllCookies(); } return(true); } } } if (receivedCookieExpired) { Log.w("Expired cookie will not be added! cookie=" + cookie); return(false); } cookies[cookie.name].Add(cookie); if (saveToCookieFile) { SaveAllCookies(); } return(true); } if (receivedCookieExpired) { Log.w("Expired cookie will not be added! cookie=" + cookie); return(false); } AssertV2.IsFalse(cookies.ContainsKey(cookie.name), "cookies[cookie.name] was not null"); if (!cookies.ContainsKey(cookie.name)) { cookies[cookie.name] = new List <Cookie>(); } cookies[cookie.name].Add(cookie); ShowDebugWarningIfMoreThanOneCookieWithSameName(cookie.name); if (saveToCookieFile) { SaveAllCookies(); } return(true); } }