示例#1
0
        public async Task PlayAdventureTest(ActionType actionType)
        {
            // Arrange
            if (actionType == ActionType.Alter)
            {
                return;
            }

            var    api  = new AidAPI(_fixture.Token);
            var    rng  = new Random();
            string text = "";

            // Generate random text based on the initial prompt
            for (int i = 0; i < 20; i++)
            {
                text += $" {_fixture.InitialPromptWords[rng.Next(_fixture.InitialPromptWords.Length)]}";
            }

            // Act
            var response = await api.SendWebSocketRequestAsync(_fixture.NormalAdventureId, actionType, text);

            // Assert
            AssertResponseIsValid(response);

            var actionList = response.Payload.Data.SubscribeAdventure?.Actions ?? response.Payload.Data.Adventure?.Actions;

            Assert.NotNull(actionList);
            Assert.NotEmpty(actionList);
        }
示例#2
0
        public async Task DeleteAdventureTest()
        {
            // Arrange
            var api = new AidAPI(_fixture.Token);

            // Act
            var response = await api.SendWebSocketRequestAsync(new WebSocketRequest(_fixture.NormalAdventureId, RequestType.DeleteAdventure));

            // Assert
            AssertResponseIsValid(response);
        }
示例#3
0
        public async Task GetAdventureTest()
        {
            // Arrange
            var api = new AidAPI(_fixture.Token);

            // Act
            var response = await api.SendWebSocketRequestAsync(new WebSocketRequest(_fixture.NormalAdventureId, RequestType.GetAdventure));

            // Assert
            AssertResponseIsValid(response);

            var actionList = response.Payload.Data.Adventure.Actions;

            Assert.NotNull(actionList);
            Assert.NotEmpty(actionList);

            var lastAction = actionList[actionList.Count - 1];

            _fixture.LastActionId = uint.Parse(lastAction.Id, CultureInfo.InvariantCulture);
        }
示例#4
0
        public async Task CreateAdventureTest()
        {
            var api = new AidAPI(_fixture.Token);
            var rng = new Random();

            // Get mode list
            var response = await api.SendWebSocketRequestAsync(new WebSocketRequest(AidAPI.AllScenariosId, RequestType.GetScenario));

            AssertResponseIsValid(response);

            var content = response.Payload.Data.Scenario;

            Assert.NotNull(content?.Options);
            Assert.NotEmpty(content.Options);

            var filteredModeList = content.Options
                                   .Where(x => !x.Title.Contains("custom", StringComparison.OrdinalIgnoreCase))
                                   .ToList();

            string id = filteredModeList[rng.Next(filteredModeList.Count)].PublicId?.ToString();

            // Get scenario list from the a random mode
            response = await api.SendWebSocketRequestAsync(new WebSocketRequest(id, RequestType.GetScenario));

            AssertResponseIsValid(response);

            content = response.Payload.Data.Scenario;

            Assert.NotNull(content?.Options);
            Assert.NotEmpty(content.Options);

            var filteredScenarioList = content.Options
                                       .Where(x => !x.Title.Contains("custom", StringComparison.OrdinalIgnoreCase))
                                       .ToList();

            id = filteredScenarioList[rng.Next(filteredScenarioList.Count)].PublicId?.ToString();

            // Get character from a random scenario
            response = await api.SendWebSocketRequestAsync(new WebSocketRequest(id, RequestType.GetScenario));

            AssertResponseIsValid(response);

            content = response.Payload.Data.Scenario;

            Assert.NotNull(content);

            // Create adventure
            response = await api.SendWebSocketRequestAsync(new WebSocketRequest(content.Id, RequestType.CreateAdventure,
                                                                                content.Prompt.Replace("${character.name}", "Fergun", StringComparison.OrdinalIgnoreCase)));

            AssertResponseIsValid(response);

            string publicId = response.Payload.Data.AddAdventure?.PublicId?.ToString();

            Assert.NotNull(publicId);

            // Get adventure
            response = await api.SendWebSocketRequestAsync(new WebSocketRequest(publicId, RequestType.GetAdventure));

            AssertResponseIsValid(response);

            var adventure = response.Payload.Data.Adventure;

            _fixture.NormalAdventureId = adventure.PublicId?.ToString();

            Assert.NotNull(adventure);

            var actionList = adventure.Actions;

            Assert.NotNull(actionList);

            actionList.RemoveAll(x => string.IsNullOrEmpty(x.Text));

            Assert.NotEmpty(actionList);

            // Get initial prompt
            string initialPrompt = actionList[actionList.Count - 1].Text;

            if (actionList.Count > 1)
            {
                actionList.RemoveAt(actionList.Count - 1);
                initialPrompt = string.Concat(actionList.Select(x => x.Text)) + initialPrompt;
            }

            // Get initial prompt words
            _fixture.InitialPromptWords = initialPrompt.Split(' ');
        }