test(upserver): 归档存档迁移与玩法闭环回归工具
This commit is contained in:
@@ -0,0 +1 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><OutputType>Exe</OutputType><TargetFramework>net9.0</TargetFramework><ImplicitUsings>enable</ImplicitUsings><RestoreConfigFile>$(MSBuildThisFileDirectory)../MinimalLoginTests/NuGet.Config</RestoreConfigFile></PropertyGroup></Project>
|
||||
19
CodexOutput/upserver/LogoutStorageTests/Program.cs
Normal file
19
CodexOutput/upserver/LogoutStorageTests/Program.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
void Check(bool value,string message){if(!value)throw new Exception(message);}
|
||||
var s=new Subject();var pending=new Dictionary<string,string>{{"existing-key","existing-data"}};
|
||||
s.dataBuffer.AddLast(pending);var spare=s.swapData;
|
||||
PlayFabClientAPI.LoggedIn=false;s.Flush();
|
||||
Check(PlayFabClientAPI.Calls==0&&ReferenceEquals(pending,s.dataBuffer.First.Value)&&ReferenceEquals(spare,s.swapData),"unauthorized flush changed queue");
|
||||
var token=s.tokenSource.Token;s.Destroy();
|
||||
Check(token.IsCancellationRequested&&s.tokenSource==null&&PlayerPrefs.Saves==1,"destroy must cancel and save local cache");
|
||||
Check(PlayFabClientAPI.Calls==0&&pending["existing-key"]=="existing-data","destroy discarded pending data or uploaded without auth");
|
||||
PlayFabClientAPI.LoggedIn=true;s.Flush();
|
||||
Check(PlayFabClientAPI.Calls==1&&PlayFabClientAPI.Last.Data["existing-key"]=="existing-data","authorized upload regressed");
|
||||
Console.WriteLine("PASS real SyncData/OnDestroy: unauthenticated queue unchanged, local Save, cancellation and authorized upload");
|
||||
public static class PlayerPrefs{public static int Saves;public static void Save()=>Saves++;}
|
||||
public class UpdateUserDataRequest{public Dictionary<string,string> Data;public UserDataPermission Permission;}
|
||||
public enum UserDataPermission{Public}
|
||||
public static class PlayFabClientAPI{
|
||||
public static bool LoggedIn;public static int Calls;public static UpdateUserDataRequest Last;
|
||||
public static bool IsClientLoggedIn()=>LoggedIn;
|
||||
public static void UpdateUserData(UpdateUserDataRequest request,Action<object> ok,Action<object> fail){if(!LoggedIn)throw new Exception("not logged in");Calls++;Last=request;}
|
||||
}
|
||||
22
CodexOutput/upserver/LogoutStorageTests/generate.py
Normal file
22
CodexOutput/upserver/LogoutStorageTests/generate.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from pathlib import Path
|
||||
|
||||
s = Path('Client/Assets/Scripts/Core/PlayFabMgr.cs').read_text(encoding='utf-8-sig')
|
||||
def block(marker):
|
||||
start = s.index(marker)
|
||||
a = s.index('{', start)
|
||||
n, end = 1, a + 1
|
||||
while n:
|
||||
n += (s[end] == '{') - (s[end] == '}')
|
||||
end += 1
|
||||
return s[start:end]
|
||||
|
||||
code = '''using System;using System.Collections.Generic;using System.Threading;
|
||||
public class Subject {
|
||||
public LinkedList<Dictionary<string,string>> dataBuffer = new();
|
||||
public Dictionary<string,string> swapData = new();
|
||||
public CancellationTokenSource tokenSource = new();
|
||||
public void Flush()=>SyncData(); public void Destroy()=>OnDestroy();
|
||||
public void UpdateFaild(object error){}
|
||||
'''
|
||||
code += block('void OnDestroy()') + '\n' + block('private void SyncData()') + '\n}\n'
|
||||
Path('CodexOutput/upserver/LogoutStorageTests/Generated.cs').write_text(code, encoding='utf-8')
|
||||
Reference in New Issue
Block a user