public static async Task Test_Controller_Produces_AlreadyHasActiveSession_When_Session_Has()
        {
            //arrange
            IServiceProvider            serviceProvider = ControllerTestsHelpers.BuildServiceProvider <CharacterSessionController>("Test", 1);
            CharacterSessionController  controller      = serviceProvider.GetService <CharacterSessionController>();
            ICharacterRepository        characterRepo   = serviceProvider.GetService <ICharacterRepository>();
            ICharacterSessionRepository sessionRepo     = serviceProvider.GetService <ICharacterSessionRepository>();

            await characterRepo.TryCreateAsync(new CharacterEntryModel(1, "Testing"));

            await sessionRepo.TryCreateAsync(new CharacterSessionModel(1, 0));

            //We can't create the claimed session through this interface because it's a stored procedure.
            //Raw SQL can't execute. So we must interact directly with the DbSet
            //await sessionRepo.TryClaimUnclaimedSession(1, 1);
            CharacterDatabaseContext context = serviceProvider.GetService <CharacterDatabaseContext>();
            await context.ClaimedSession.AddAsync(new ClaimedSessionsModel(1));

            await context.SaveChangesAsync();

            //act
            CharacterSessionEnterResponse response = await controller.EnterSession(1);

            //assert
            Assert.False(response.isSuccessful, $"Characters that already have ");
            Assert.AreEqual(CharacterSessionEnterResponseCode.AccountAlreadyHasCharacterSession, response.ResultCode);
        }
Ejemplo n.º 2
0
        private async Task OnFinishedDisconnecting(int zoneId)
        {
            //Now we need to try to create a new session
            while (true)
            {
                CharacterSessionEnterResponse enterResponse = await CharacterService.SetCharacterSessionData(DataRepo.CharacterId, zoneId, AuthTokenRepo.RetrieveWithType())
                                                              .ConfigureAwait(false);

                //While the response isn't successful we shouild log way, and continue if it's
                if (enterResponse.isSuccessful)
                {
                    break;
                }

                await Task.Delay(500)
                .ConfigureAwait(false);

                Debug.LogError($"Failed to set character session data to ZoneId: {zoneId} for Reason: {enterResponse.ResultCode}");
            }

            //Join main unity thread
            await new UnityYieldAwaitable();

            //We should dispose any resources in the scene that are disposable before loading a new scene
            foreach (var d in Disposables)
            {
                d.Dispose();
            }

            //We just load to the loading screen and we'll reload the into the current zone
            SceneManager.LoadSceneAsync((int)GameSceneType.WorldDownloadingScreen, LoadSceneMode.Single).allowSceneActivation = true;
        }
        public static async Task Test_Controller_Produces_InvalidId_When_Empty()
        {
            //arrange
            IServiceProvider           serviceProvider = ControllerTestsHelpers.BuildServiceProvider <CharacterSessionController>("Test", 1);
            CharacterSessionController controller      = serviceProvider.GetService <CharacterSessionController>();

            //act
            CharacterSessionEnterResponse response = await controller.EnterSession(5);

            //assert
            Assert.False(response.isSuccessful);
            Assert.AreEqual(CharacterSessionEnterResponseCode.InvalidCharacterIdError, response.ResultCode);
        }
        public static async Task Test_Controller_Creates_UnclaimedSession_On_OnEnterSession(int accountId)
        {
            //arrange
            IServiceProvider           serviceProvider = ControllerTestsHelpers.BuildServiceProvider <CharacterSessionController>("Test", accountId);
            CharacterSessionController controller      = serviceProvider.GetService <CharacterSessionController>();
            ICharacterRepository       characterRepo   = serviceProvider.GetService <ICharacterRepository>();

            await characterRepo.TryCreateAsync(new CharacterEntryModel(accountId, "Testing"));

            //act: We also test that we can do it multiple times
            CharacterSessionEnterResponse response = await controller.EnterSession(1);

            //assert
            Assert.True(response.isSuccessful);
            Assert.AreEqual(CharacterSessionEnterResponseCode.Success, response.ResultCode);
        }
        public static async Task Test_Controller_Produces_InvalidId_When_Wrong_AccountId()
        {
            //arrange
            IServiceProvider            serviceProvider = ControllerTestsHelpers.BuildServiceProvider <CharacterSessionController>("Test", 2);
            CharacterSessionController  controller      = serviceProvider.GetService <CharacterSessionController>();
            ICharacterRepository        characterRepo   = serviceProvider.GetService <ICharacterRepository>();
            ICharacterSessionRepository sessionRepo     = serviceProvider.GetService <ICharacterSessionRepository>();

            await characterRepo.TryCreateAsync(new CharacterEntryModel(1, "Testing"));

            await sessionRepo.TryCreateAsync(new CharacterSessionModel(1, 0));

            //act
            CharacterSessionEnterResponse response = await controller.EnterSession(1);

            //assert
            Assert.False(response.isSuccessful, $"Characters should not be able to create sessions when the accountid doesn't match.");
            Assert.AreEqual(response.ResultCode, CharacterSessionEnterResponseCode.InvalidCharacterIdError);
        }
        public static async Task Test_Controller_Produces_SessionGranted_With_Zone_Id_If_UnclaimedSession_Exists(int accountId, int zoneid)
        {
            //arrange
            IServiceProvider            serviceProvider = ControllerTestsHelpers.BuildServiceProvider <CharacterSessionController>("Test", accountId);
            CharacterSessionController  controller      = serviceProvider.GetService <CharacterSessionController>();
            ICharacterRepository        characterRepo   = serviceProvider.GetService <ICharacterRepository>();
            ICharacterSessionRepository sessionRepo     = serviceProvider.GetService <ICharacterSessionRepository>();

            await characterRepo.TryCreateAsync(new CharacterEntryModel(accountId, "Testing"));

            await sessionRepo.TryCreateAsync(new CharacterSessionModel(1, zoneid));

            //act
            CharacterSessionEnterResponse response = await controller.EnterSession(1);

            //assert
            Assert.True(response.isSuccessful, $"Created sessions should be granted if no active account session or character session is claimed.");
            Assert.AreEqual(CharacterSessionEnterResponseCode.Success, response.ResultCode);
            Assert.AreEqual(zoneid, response.ZoneId, $"Provided zone id was not the same as the session.");
        }
Ejemplo n.º 7
0
        /// <inheritdoc />
        protected override void OnEventFired(object source, CharacterButtonClickedEventArgs args)
        {
            UnityExtended.UnityMainThreadContext.PostAsync(async() =>
            {
                //We must actually create a session
                //before the character can login.
                CharacterSessionEnterResponse enterResponse = await CharacterService.TryEnterSession(args.CharacterGuid.EntityId, AuthTokenRepo.RetrieveWithType())
                                                              .ConfigureAwait(true);

                //TODO: handle character session failure
                CharacterData.UpdateCharacterId(args.CharacterGuid.EntityId);

                if (Logger.IsInfoEnabled)
                {
                    Logger.Info($"Recieved character session entry response: {enterResponse.isSuccessful} Result: {enterResponse.ResultCode} for ZoneId: {enterResponse.ZoneId}");
                }

                //TODO: Use the scene manager service.
                //TODO: Don't hardcode scene ids. Don't load scenes directly.
                SceneManager.LoadSceneAsync(2).allowSceneActivation = true;
            });
        }