1+ /*
2+ * Copyright (c) 2024 PlayEveryWare
3+ *
4+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5+ * of this software and associated documentation files (the "Software"), to deal
6+ * in the Software without restriction, including without limitation the rights
7+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+ * copies of the Software, and to permit persons to whom the Software is
9+ * furnished to do so, subject to the following conditions:
10+ *
11+ * The above copyright notice and this permission notice shall be included in
12+ * all copies or substantial portions of the Software.
13+ *
14+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+ * SOFTWARE.
21+ */
22+
23+ namespace PlayEveryWare . EpicOnlineServices . Tests . Connect
24+ {
25+ using Epic . OnlineServices ;
26+ using Epic . OnlineServices . Achievements ;
27+ using Epic . OnlineServices . Stats ;
28+ using NUnit . Framework ;
29+ using System . Collections ;
30+ using UnityEngine ;
31+ using UnityEngine . TestTools ;
32+
33+ public class ConnectTests
34+ {
35+ GameObject eosObject ;
36+ protected const float LoginTestTimeout = 30f ;
37+
38+ [ TearDown ]
39+ public void ShutdownEOS ( )
40+ {
41+ EOSManager . Instance ? . OnShutdown ( ) ;
42+ UnityEngine . Object . Destroy ( eosObject ) ;
43+ }
44+
45+ /// <summary>
46+ /// This test creates a new EOSManager object, and uses it to auth-login.
47+ /// Then it does a Connect login.
48+ /// After a successful Connect login, it tries to perform another Connect login.
49+ /// The result should be as expected.
50+ /// </summary>
51+ /// <returns></returns>
52+ [ UnityTest ]
53+ public IEnumerator ConnectLogin_WhileAlreadyLoggedIn_ReturnsExpectedResult ( )
54+ {
55+ eosObject = new GameObject ( ) ;
56+ var eosManager = eosObject . AddComponent < EOSManager > ( ) ;
57+
58+ UnitTestConfig config = EpicOnlineServices . Config . Get < UnitTestConfig > ( ) ;
59+
60+ // Auth login
61+ // This isn't what this test is testing, but we must first auth login before connect login
62+ Epic . OnlineServices . Auth . LoginCallbackInfo ? loginResult = null ;
63+ EOSManager . Instance . StartLoginWithLoginTypeAndToken ( Epic . OnlineServices . Auth . LoginCredentialType . Developer ,
64+ $ "{ config . EOSDevAuthToolIP } :{ config . EOSDevAuthToolPort } ",
65+ config . EOSDevAuthToolUserName ,
66+ data => { loginResult = data ; } ) ;
67+
68+ yield return new EOSTestBase . WaitUntilDone ( LoginTestTimeout , ( ) => loginResult != null ) ;
69+
70+ Assert . IsNotNull ( loginResult ,
71+ "Could not log into EOS, loginResult was not set." ) ;
72+
73+ Assert . AreEqual ( Result . Success , loginResult . Value . ResultCode ,
74+ $ "Login result failed: { loginResult . Value . ResultCode } ") ;
75+
76+ // Now that this is logged in, attempt connect login
77+ Epic . OnlineServices . Connect . LoginCallbackInfo ? callbackInfo = null ;
78+ EOSManager . Instance . StartConnectLoginWithEpicAccount ( loginResult . Value . LocalUserId , data =>
79+ {
80+ callbackInfo = data ;
81+ } ) ;
82+
83+ yield return new EOSTestBase . WaitUntilDone ( LoginTestTimeout , ( ) => callbackInfo != null ) ;
84+
85+ Assert . IsNotNull ( callbackInfo ,
86+ "Could not connect with Epic account, callbackInfo was not set." ) ;
87+
88+ Assert . AreEqual ( Result . Success , callbackInfo . Value . ResultCode ,
89+ $ "Could not connect with Epic account: { callbackInfo . Value . ResultCode } ") ;
90+
91+ Assert . That ( EOSManager . Instance . GetProductUserId ( ) . IsValid ( ) ,
92+ "Current player is invalid." ) ;
93+
94+ // Subsequent connect login, check for expected results
95+ callbackInfo = null ;
96+ EOSManager . Instance . StartConnectLoginWithEpicAccount ( loginResult . Value . LocalUserId , data =>
97+ {
98+ callbackInfo = data ;
99+ } ) ;
100+
101+ yield return new EOSTestBase . WaitUntilDone ( LoginTestTimeout , ( ) => callbackInfo != null ) ;
102+
103+ Assert . IsNotNull ( callbackInfo ,
104+ "Could not connect with Epic account, callbackInfo was not set." ) ;
105+
106+ Assert . AreEqual ( Result . Success , callbackInfo . Value . ResultCode ,
107+ $ "Could not connect with Epic account: { callbackInfo . Value . ResultCode } ") ;
108+
109+ Assert . That ( EOSManager . Instance . GetProductUserId ( ) . IsValid ( ) ,
110+ "Current player is invalid." ) ;
111+ }
112+ }
113+ }
0 commit comments