Skip to content

Commit

Permalink
Merge pull request #16 from AndyCW/pipelinefixes
Browse files Browse the repository at this point in the history
Handling paged output, fixes to json only output
  • Loading branch information
AndyCW committed Aug 28, 2020
2 parents 0dd2b4a + 7a01201 commit 7b126e5
Show file tree
Hide file tree
Showing 18 changed files with 290 additions and 150 deletions.
143 changes: 130 additions & 13 deletions Azure-Custom-Translator-CLI.Tests/CommandTests/DocumentCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,123 @@ static string[] CommandIntoArgs(string command)
return command.Split(' ');
}


[Fact]
public void List_Documents()
{
// ARRANGE
var response1 = new DocumentsResponse()
{
PaginatedDocuments = new DocumentInfoResponse()
{
PageIndex = 1,
TotalPageCount = 2,
Documents = new List<DocumentInfo>()
{
new DocumentInfo()
{
Name = "firstdoc",
Id = 1,
Languages = new List<TranslatorLanguage>()
{
new TranslatorLanguage()
{
DisplayName = "Test",
LanguageCode = "ab",
Id = 255
}
}
},
new DocumentInfo()
{
Name = "seconddoc",
Id = 2,
Languages = new List<TranslatorLanguage>()
{
new TranslatorLanguage()
{
DisplayName = "Test",
LanguageCode = "cd",
Id = 255
}
}
}

}
}
};
var response2 = new DocumentsResponse()
{
PaginatedDocuments = new DocumentInfoResponse()
{
PageIndex = 2,
TotalPageCount = 2,
Documents = new List<DocumentInfo>()
{
new DocumentInfo()
{
Name = "thirddoc",
Id = 3,
Languages = new List<TranslatorLanguage>()
{
new TranslatorLanguage()
{
DisplayName = "Test",
LanguageCode = "ef",
Id = 255
}
}
},
new DocumentInfo()
{
Name = "fourthdoc",
Id = 4,
Languages = new List<TranslatorLanguage>()
{
new TranslatorLanguage()
{
DisplayName = "Test",
LanguageCode = "gh",
Id = 255
}
}
}
}
}
};

var mock = new Mock<IMicrosoftCustomTranslatorAPIPreview10>();
mock
.Setup(
m => m.GetDocumentsWithHttpMessagesAsync(string.Empty, 1, It.IsAny<string>(), null, null, null, null, null, CancellationToken.None)
)
.ReturnsAsync(
new HttpOperationResponse<DocumentsResponse>() { Body = response1 }
);
mock
.Setup(
m => m.GetDocumentsWithHttpMessagesAsync(string.Empty, 2, It.IsAny<string>(), null, null, null, null, null, CancellationToken.None)
)
.ReturnsAsync(
new HttpOperationResponse<DocumentsResponse>() { Body = response2 }
);

var app = InitApp(mock.Object);

// ACT
var args = CommandIntoArgs($"document list -ws 00000000-0000-0000-0000-000000000000");
app.Execute(args);

// ASSESS
string expectedResult = @"Getting documents...
1 ab firstdoc
2 cd seconddoc
3 ef thirddoc
4 gh fourthdoc
";

Assert.Equal(expectedResult, ((MockTestWriter)app.Out).ReadAsString());
}
[Fact]
public void Upload_LanguagePair_Invalid()
{
Expand Down Expand Up @@ -98,13 +215,13 @@ public void Upload_TargetFile_Missing()
{
new LanguagePair()
{
SourceLanguage = new TextTranslatorModelsTextTranslatorLanguage()
SourceLanguage = new TranslatorLanguage()
{
DisplayName = "Test",
LanguageCode = "ab",
Id = 255
},
TargetLanguage = new TextTranslatorModelsTextTranslatorLanguage()
TargetLanguage = new TranslatorLanguage()
{
DisplayName = "Test2",
LanguageCode = "yz",
Expand Down Expand Up @@ -142,13 +259,13 @@ public void Upload_SourceFile_Missing()
{
new LanguagePair()
{
SourceLanguage = new TextTranslatorModelsTextTranslatorLanguage()
SourceLanguage = new TranslatorLanguage()
{
DisplayName = "Test",
LanguageCode = "ab",
Id = 255
},
TargetLanguage = new TextTranslatorModelsTextTranslatorLanguage()
TargetLanguage = new TranslatorLanguage()
{
DisplayName = "Test2",
LanguageCode = "yz",
Expand Down Expand Up @@ -186,13 +303,13 @@ public void Upload_ComboFile_And_SourceFile_Combined()
{
new LanguagePair()
{
SourceLanguage = new TextTranslatorModelsTextTranslatorLanguage()
SourceLanguage = new TranslatorLanguage()
{
DisplayName = "Test",
LanguageCode = "ab",
Id = 255
},
TargetLanguage = new TextTranslatorModelsTextTranslatorLanguage()
TargetLanguage = new TranslatorLanguage()
{
DisplayName = "Test2",
LanguageCode = "yz",
Expand Down Expand Up @@ -232,13 +349,13 @@ public void Upload_ComboFile_And_TargetFile_Combined()
{
new LanguagePair()
{
SourceLanguage = new TextTranslatorModelsTextTranslatorLanguage()
SourceLanguage = new TranslatorLanguage()
{
DisplayName = "Test",
LanguageCode = "ab",
Id = 255
},
TargetLanguage = new TextTranslatorModelsTextTranslatorLanguage()
TargetLanguage = new TranslatorLanguage()
{
DisplayName = "Test2",
LanguageCode = "yz",
Expand Down Expand Up @@ -278,13 +395,13 @@ public void Upload_Document()
{
new LanguagePair()
{
SourceLanguage = new TextTranslatorModelsTextTranslatorLanguage()
SourceLanguage = new TranslatorLanguage()
{
DisplayName = "Test",
LanguageCode = "ab",
Id = 255
},
TargetLanguage = new TextTranslatorModelsTextTranslatorLanguage()
TargetLanguage = new TranslatorLanguage()
{
DisplayName = "Test2",
LanguageCode = "yz",
Expand Down Expand Up @@ -345,13 +462,13 @@ public void Upload_Document_Wait()
{
new LanguagePair()
{
SourceLanguage = new TextTranslatorModelsTextTranslatorLanguage()
SourceLanguage = new TranslatorLanguage()
{
DisplayName = "Test",
LanguageCode = "ab",
Id = 255
},
TargetLanguage = new TextTranslatorModelsTextTranslatorLanguage()
TargetLanguage = new TranslatorLanguage()
{
DisplayName = "Test2",
LanguageCode = "yz",
Expand Down Expand Up @@ -449,7 +566,7 @@ public void Upload_Document_Wait()
app.Execute(args);

// ASSESS
string expectedResult = @"Processing [...] Done
string expectedResult = @"
{
""jobName"": null,
""fileProcessingStatus"": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void Create_Model()

mock
.Setup(
m => m.GetProjectsByIdModelsWithHttpMessagesAsync(new Guid("00000000-0000-0000-0000-000000000000"), It.IsAny<string>(), 1, null, null, null, CancellationToken.None)
m => m.GetProjectsByIdModelsWithHttpMessagesAsync(new Guid("00000000-0000-0000-0000-000000000000"), It.IsAny<string>(), 1, It.IsAny<string>(), It.IsAny<string>(), null, CancellationToken.None)
)
.ReturnsAsync(new HttpOperationResponse<ModelsResponse>() { Body = response }
);
Expand Down Expand Up @@ -130,7 +130,7 @@ public void Create_Model_Wait_Json()
);
mock
.Setup(
m => m.GetProjectsByIdModelsWithHttpMessagesAsync(new Guid("00000000-0000-0000-0000-000000000000"), It.IsAny<string>(), 1, null, null, null, CancellationToken.None)
m => m.GetProjectsByIdModelsWithHttpMessagesAsync(new Guid("00000000-0000-0000-0000-000000000000"), It.IsAny<string>(), 1, It.IsAny<string>(), It.IsAny<string>(), null, CancellationToken.None)
)
.ReturnsAsync(new HttpOperationResponse<ModelsResponse>() { Body = response1 }
);
Expand Down Expand Up @@ -163,7 +163,7 @@ public void Create_Model_Wait_Json()
app.Execute(args);

// ASSESS
string expected = @"Processing [...] Done
string expected = @"
{
""id"": 1234,
""name"": ""testmodel"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,37 +71,33 @@ public void List_Json_Success()
app.Execute(args);

// ASSESS
string expected = @"{
""projects"": [
{
""id"": ""00000000-0000-0000-0000-000000000000"",
""name"": ""Moq"",
""label"": null,
""description"": null,
""languagePair"": null,
""category"": null,
""categoryDescriptor"": null,
""baselineBleuScorePunctuated"": null,
""bleuScorePunctuated"": null,
""baselineBleuScoreUnpunctuated"": null,
""bleuScoreUnpunctuated"": null,
""baselineBleuScoreCIPunctuated"": null,
""bleuScoreCIPunctuated"": null,
""baselineBleuScoreCIUnpunctuated"": null,
""bleuScoreCIUnpunctuated"": null,
""status"": null,
""modifiedDate"": ""0001-01-01T00:00:00"",
""createdDate"": ""0001-01-01T00:00:00"",
""createdBy"": null,
""modifiedBy"": null,
""apiDomain"": null,
""isAvailable"": false,
""hubCategory"": null
}
],
""pageIndex"": 0,
""totalPageCount"": 0
}
string expected = @"[
{
""id"": ""00000000-0000-0000-0000-000000000000"",
""name"": ""Moq"",
""label"": null,
""description"": null,
""languagePair"": null,
""category"": null,
""categoryDescriptor"": null,
""baselineBleuScorePunctuated"": null,
""bleuScorePunctuated"": null,
""baselineBleuScoreUnpunctuated"": null,
""bleuScoreUnpunctuated"": null,
""baselineBleuScoreCIPunctuated"": null,
""bleuScoreCIPunctuated"": null,
""baselineBleuScoreCIUnpunctuated"": null,
""bleuScoreCIUnpunctuated"": null,
""status"": null,
""modifiedDate"": ""0001-01-01T00:00:00"",
""createdDate"": ""0001-01-01T00:00:00"",
""createdBy"": null,
""modifiedBy"": null,
""apiDomain"": null,
""isAvailable"": false,
""hubCategory"": null
}
]
";
string actual = ((MockTestWriter)app.Out).ReadAsString();
Assert.Equal(expected, actual);
Expand Down

0 comments on commit 7b126e5

Please sign in to comment.