|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Threading.Tasks; |
| 4 | +using Box.V2.Managers; |
| 5 | +using Box.V2.Models; |
| 6 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 7 | +using Moq; |
| 8 | + |
| 9 | +namespace Box.V2.Test |
| 10 | +{ |
| 11 | + [TestClass] |
| 12 | + public class BoxAIManagerTest : BoxResourceManagerTest |
| 13 | + { |
| 14 | + private readonly BoxAIManager _aiManager; |
| 15 | + |
| 16 | + public BoxAIManagerTest() |
| 17 | + { |
| 18 | + _aiManager = new BoxAIManager(Config.Object, Service, Converter, AuthRepository); |
| 19 | + } |
| 20 | + |
| 21 | + [TestMethod] |
| 22 | + public async Task SendAiQuestionAsync_Success() |
| 23 | + { |
| 24 | + /** Arrange **/ |
| 25 | + IBoxRequest boxRequest = null; |
| 26 | + Handler.Setup(h => h.ExecuteAsync<BoxAIResponse>(It.IsAny<IBoxRequest>())) |
| 27 | + .Returns(Task.FromResult<IBoxResponse<BoxAIResponse>>(new BoxResponse<BoxAIResponse>() |
| 28 | + { |
| 29 | + Status = ResponseStatus.Success, |
| 30 | + ContentString = LoadFixtureFromJson("Fixtures/BoxAI/SendAiQuestion200.json") |
| 31 | + })) |
| 32 | + .Callback<IBoxRequest>(r => boxRequest = r); |
| 33 | + |
| 34 | + var requestBody = new BoxAIAskRequest() |
| 35 | + { |
| 36 | + Mode = BoxAIAskMode.single_item_qa, |
| 37 | + Prompt = "What is the value provided by public APIs based on this document?", |
| 38 | + Items = new List<BoxAIAskItem>() |
| 39 | + { |
| 40 | + new BoxAIAskItem() { Id = "9842787262" } |
| 41 | + } |
| 42 | + }; |
| 43 | + |
| 44 | + /*** Act ***/ |
| 45 | + BoxAIResponse response = await _aiManager.SendAIQuestionAsync(requestBody); |
| 46 | + |
| 47 | + /*** Assert ***/ |
| 48 | + // Request check |
| 49 | + Assert.IsNotNull(boxRequest); |
| 50 | + Assert.AreEqual(RequestMethod.Post, boxRequest.Method); |
| 51 | + Assert.AreEqual(new Uri("https://api.box.com/2.0/ai/ask"), boxRequest.AbsoluteUri); |
| 52 | + |
| 53 | + // Response check |
| 54 | + Assert.AreEqual("Public APIs are important because of key and important reasons.", response.Answer); |
| 55 | + Assert.AreEqual("done", response.CompletionReason); |
| 56 | + Assert.AreEqual(DateTimeOffset.Parse("2012-12-12T10:53:43-08:00"), response.CreatedAt); |
| 57 | + } |
| 58 | + |
| 59 | + |
| 60 | + [TestMethod] |
| 61 | + public async Task SendAiGenerateTextRequestAsync_Success() |
| 62 | + { |
| 63 | + /** Arrange **/ |
| 64 | + IBoxRequest boxRequest = null; |
| 65 | + Handler.Setup(h => h.ExecuteAsync<BoxAIResponse>(It.IsAny<IBoxRequest>())) |
| 66 | + .Returns(Task.FromResult<IBoxResponse<BoxAIResponse>>(new BoxResponse<BoxAIResponse>() |
| 67 | + { |
| 68 | + Status = ResponseStatus.Success, |
| 69 | + ContentString = LoadFixtureFromJson("Fixtures/BoxAI/SendAITextGenRequestSuccess200.json") |
| 70 | + })) |
| 71 | + .Callback<IBoxRequest>(r => boxRequest = r); |
| 72 | + |
| 73 | + var requestBody = new BoxAITextGenRequest() |
| 74 | + { |
| 75 | + Prompt = "Write an email to a client about the importance of public APIs", |
| 76 | + Items = new List<BoxAITextGenItem>() |
| 77 | + { |
| 78 | + new BoxAITextGenItem() { Id = "12345678", Content = "More information about public APIs" } |
| 79 | + }, |
| 80 | + DialogueHistory = new List<BoxAIDialogueHistory>() |
| 81 | + { |
| 82 | + new BoxAIDialogueHistory() |
| 83 | + { |
| 84 | + Prompt = "Make my email about public APIs sound more professional", |
| 85 | + Answer = "Here is the first draft of your professional email about public APIs", |
| 86 | + CreatedAt = DateTimeOffset.Parse("2013-12-12T10:53:43-08:00") |
| 87 | + }, |
| 88 | + new BoxAIDialogueHistory() |
| 89 | + { |
| 90 | + Prompt = "Can you add some more information?", |
| 91 | + Answer = "Public API schemas provide necessary information to integrate with APIs...", |
| 92 | + CreatedAt = DateTimeOffset.Parse("2013-12-12T11:20:43-08:00") |
| 93 | + } |
| 94 | + } |
| 95 | + }; |
| 96 | + |
| 97 | + /*** Act ***/ |
| 98 | + BoxAIResponse response = await _aiManager.SendAITextGenRequestAsync(requestBody); |
| 99 | + |
| 100 | + /*** Assert ***/ |
| 101 | + // Request check |
| 102 | + Assert.IsNotNull(boxRequest); |
| 103 | + Assert.AreEqual(RequestMethod.Post, boxRequest.Method); |
| 104 | + Assert.AreEqual(new Uri("https://api.box.com/2.0/ai/text_gen"), boxRequest.AbsoluteUri); |
| 105 | + |
| 106 | + // Response check |
| 107 | + Assert.AreEqual("Public APIs are important because of key and important reasons.", response.Answer); |
| 108 | + Assert.AreEqual("done", response.CompletionReason); |
| 109 | + Assert.AreEqual(DateTimeOffset.Parse("2012-12-12T10:53:43-08:00"), response.CreatedAt); |
| 110 | + } |
| 111 | + } |
| 112 | +} |
0 commit comments