public void DoesNotExcludeAllScriptEvaluation() { // Given TestExecutionContext context = new TestExecutionContext(); context.ScriptHelper = new ScriptHelper(context); ScriptMetadataValue.TryGetScriptMetadataValue("Bar", "=> 1 + 2", context, out ScriptMetadataValue fooValue); ScriptMetadataValue.TryGetScriptMetadataValue("Foo", "=> 3 + 4", context, out ScriptMetadataValue barValue); TestDocument document = new TestDocument { { "Foo", fooValue }, { "Bar", barValue }, { Keys.ExcludeFromEvaluation, false } }; // When object fooResult = document.Get("Foo"); object barResult = document.Get("bar"); // Then fooResult.ShouldBe(3); barResult.ShouldBe(7); }
public void ExcludesMultipleValuesFromScriptEvaluation() { // Given TestExecutionContext context = new TestExecutionContext(); context.ScriptHelper = new ScriptHelper(context); ScriptMetadataValue.TryGetScriptMetadataValue("Foo", "=> 1 + 2", context, out ScriptMetadataValue fooValue); ScriptMetadataValue.TryGetScriptMetadataValue("Bar", "=> 3 + 4", context, out ScriptMetadataValue barValue); TestDocument document = new TestDocument { { "Foo", fooValue }, { "Bar", barValue }, { Keys.ExcludeFromEvaluation, new string[] { "foo", "Bar" } } }; // When object fooResult = document.Get("Foo"); object barResult = document.Get("bar"); // Then fooResult.ShouldBe("=> 1 + 2"); barResult.ShouldBe("=> 3 + 4"); }
public async Task Document_Upload_Stores_Document() { var repo = Substitute.For <IDocumentRepository>(); DocumentOrchestrator orchestrator = new DocumentOrchestrator(repo); Document document = new Document(); document.Content = TestDocument.Get(TestDocumentType.Pdf); document.Name = "my_document.pdf"; await orchestrator.UploadAsync(document); await repo.Received(1).CreateAsync(document); }
public async Task Document_Upload_200_Response() { Document document = new Document(); document.Content = TestDocument.Get(TestDocumentType.Pdf); document.Name = "my_document.pdf"; DocumentOrchestrator orchestrator = new DocumentOrchestrator(Substitute.For <IDocumentRepository>()); IActionResult result = await orchestrator.UploadAsync(document); var typedResult = result as OkObjectResult; Assert.IsNotNull(typedResult); Assert.AreEqual(200, typedResult.StatusCode); }
public async Task Document_Upload_Rejects_Large_Payload() { var repo = Substitute.For <IDocumentRepository>(); DocumentOrchestrator orchestrator = new DocumentOrchestrator(repo); Document document = new Document(); document.Content = TestDocument.Get(TestDocumentType.LargePdf); document.Name = "my_document.pdf"; IActionResult result = await orchestrator.UploadAsync(document); var typedResult = result as StatusCodeResult; Assert.IsNotNull(typedResult); Assert.AreEqual(413, typedResult.StatusCode); }
public async Task Document_Upload_Rejects_NonPdf() { var repo = Substitute.For <IDocumentRepository>(); DocumentOrchestrator orchestrator = new DocumentOrchestrator(repo); Document document = new Document(); document.Content = TestDocument.Get(TestDocumentType.Word); document.Name = "my_document.docx"; IActionResult result = await orchestrator.UploadAsync(document); var typedResult = result as UnsupportedMediaTypeResult; Assert.IsNotNull(typedResult); Assert.AreEqual(415, typedResult.StatusCode); }
public void EvaluatesIntScriptResult() { // Given TestExecutionContext context = new TestExecutionContext(); context.ScriptHelper = new ScriptHelper(context); ScriptMetadataValue.TryGetScriptMetadataValue("Foo", "=> 1 + 2", context, out ScriptMetadataValue scriptMetadataValue); TestDocument document = new TestDocument { { "Foo", scriptMetadataValue } }; // When object result = document.Get("Foo"); // Then result.ShouldBe(3); }