public async Task FileUtility_GetHealth_ReturnsActiveHeathCheckResult_WhenAllGood() { //Arrange const string fileContents = "<helloworld/>"; var fileBytes = Encoding.ASCII.GetBytes(fileContents); const string fileName = "helloworld.txt"; var getFileResult = new GetFileResult(fileBytes, fileName); var getFileResultBehaviorMock = new Mock <IGetFileBehavior>(); getFileResultBehaviorMock.Setup(x => x.GetFileAsync(It.IsAny <string>())).Returns(Task.FromResult(HttpFragileOperationResult <GetFileResult> .CreateSuccessfulResult(getFileResult, HttpStatusCode.OK, ""))); const string resultIdentifier = "123456"; var storeFileResult = new StoreFileResult(resultIdentifier); var storeFileResultBehaviorMock = new Mock <IStoreFileBehavior>(); storeFileResultBehaviorMock.Setup(x => x.StoreFileAsync(It.IsAny <byte[]>(), It.IsAny <string>())).Returns(Task.FromResult(HttpFragileOperationResult <StoreFileResult> .CreateSuccessfulResult(storeFileResult, HttpStatusCode.OK, ""))); var getPublicUrlResult = new GetPublicUrlResult("SomeUrl"); var getPublicUrlBehaviorMock = new Mock <IGetPublicUrlBehavior>(); getPublicUrlBehaviorMock.Setup(x => x.GetPublicUrlAsync(It.IsAny <string>(), It.IsAny <int>())).Returns(Task.FromResult(HttpFragileOperationResult <GetPublicUrlResult> .CreateSuccessfulResult(getPublicUrlResult, HttpStatusCode.OK, ""))); var fileUtility = new FileUtility(getFileResultBehaviorMock.Object, storeFileResultBehaviorMock.Object, getPublicUrlBehaviorMock.Object); var result = await fileUtility.GetHealthAsync().ConfigureAwait(false); Assert.AreEqual(HealthStatus.Active, result.Status); Assert.AreEqual("Files", result.Description); Assert.AreEqual(3, result.Vitals.Count); }
public GetFileResult GetFile(string path) { IRestRequest request = new RestRequest($"/{Client.Version}/containers/{Name}/files?path={path}", Method.GET, DataFormat.None); IRestResponse response = API.Get(request); return(GetFileResult.Create(response)); }
public static GetFileResult GetFile(ref string file) { //TODO: this does not work with UTF8 StringBuilder sb = new StringBuilder(4097); //max 4096 chars according to IUP docs. +1 for safety for zero term. if (file != null) { sb.Append(file); } GetFileResult res = (GetFileResult)NativeIUP.IupGetFile(sb); file = sb.ToString(); return(res); }
public async Task FileUtility_GetFile_ReturnsStoreFileBehaviorResult() { //Arrange const string fileContents = "<helloworld/>"; var fileBytes = Encoding.ASCII.GetBytes(fileContents); const string fileName = "helloworld.txt"; var getFileResult = new GetFileResult(fileBytes, fileName); var getFileResultBehaviorMock = new Mock <IGetFileBehavior>(); getFileResultBehaviorMock.Setup(x => x.GetFileAsync(It.IsAny <string>())).Returns(Task.FromResult(HttpFragileOperationResult <GetFileResult> .CreateSuccessfulResult(getFileResult, HttpStatusCode.OK, ""))); //Act var result = await getFileResultBehaviorMock.Object.GetFileAsync("anything").ConfigureAwait(false); //Assert Assert.IsTrue(fileBytes.SequenceEqual(result.Result.Bytes)); Assert.AreEqual(fileName, result.Result.FileName); Assert.AreEqual(Status.Success, result.Status); Assert.AreEqual(0, result.ErrorMessages.Count()); }