public void Save(TestDocument document) { var watch = Stopwatch.StartNew(); _couch.Save(document); watch.Stop(); "Save completed in {0}" .ToInfo<ChangeWatcher>(watch.ElapsedMilliseconds); }
public void WouldBeIndexedProperly(string requestedStorage) { using (var store = NewDocumentStore(requestedStorage: requestedStorage)) { using (var session = store.OpenSession()) { // Create the temp index before we populate the db. session.Query<TestDocument>() .Customize(x => x.WaitForNonStaleResultsAsOfNow()) .Count(); } const int expectedCount = 5000; var ids = new ConcurrentQueue<string>(); for (int i = 0; i < expectedCount; i++) { { using (var session = store.OpenSession()) { var testDocument = new TestDocument(); session.Store(testDocument); ids.Enqueue(session.Advanced.GetDocumentId(testDocument)); session.SaveChanges(); } } } using (var session = store.OpenSession()) { var items = session.Query<TestDocument>() .Customize(x => x.WaitForNonStaleResults()) .Take(5005) .ToList(); var missing = new List<int>(); for (int i = 1; i <= 5000; i++) { if (items.Any(x => x.Id == i) == false) missing.Add(i); } WaitForUserToContinueTheTest(store); try { Assert.Equal(expectedCount, items.Count); } catch (Exception) { Console.WriteLine("Missing {0} documents", missing.Count); Console.WriteLine(string.Join(" , ", missing)); throw; } } } }
IDocument IDocumentManagerService.CreateDocument(string documentType, object viewModel, object parameter, object parentViewModel) { TestDocument doc = new TestDocument(documentType, viewModel, parameter, parentViewModel); ViewHelper.CreateAndInitializeView(doc, string.Empty, viewModel, parameter, parentViewModel); var vm = new TestSupportServices(); vm.ParentViewModel = parentViewModel; DocumentUIServiceBase.SetTitleBinding(doc, TestDocument.TitleProperty, doc); vm.Parameter = parameter; doc.Content = vm; docs.Add(doc); return doc; }
public void Add_single_doc_calls_operations_with_null_add_parameters() { var basicServer = new MSolrBasicOperations<TestDocument>(); basicServer.addWithBoost += (docs, param) => { Assert.IsNull(param); return null; }; basicServer.addWithBoost &= x => x.Expect(1); var mapper = new MReadOnlyMappingManager(); var validationManager = new MMappingValidator(); var s = new SolrServer<TestDocument>(basicServer, mapper, validationManager); var t = new TestDocument(); s.Add(t); basicServer.addWithBoost.Verify(); }
public void AddWithBoost_single_doc_calls_operations_with_null_add_parameters() { var basicServer = new MSolrBasicOperations<TestDocument>(); basicServer.addWithBoost += (a,b) => { Assert.IsNull(b); return null; }; var mapper = new MReadOnlyMappingManager(); var validationManager = new MMappingValidator(); var s = new SolrServer<TestDocument>(basicServer, mapper, validationManager); var t = new TestDocument(); s.AddWithBoost(t, 2.1); Assert.AreEqual(1, basicServer.addWithBoost.Calls); }
public void Add_single_doc_with_add_parameters_calls_operations_with_same_add_parameters() { var parameters = new AddParameters { CommitWithin = 4343 }; var basicServer = new MSolrBasicOperations<TestDocument>(); basicServer.addWithBoost += (_, p) => { Assert.AreEqual(parameters, p); return null; }; var mapper = new MReadOnlyMappingManager(); var validationManager = new MMappingValidator(); var s = new SolrServer<TestDocument>(basicServer, mapper, validationManager); var t = new TestDocument(); s.Add(t, parameters); Assert.AreEqual(1, basicServer.addWithBoost.Calls); }
public void AddWithBoost_single_doc_calls_operations_with_null_add_parameters() { var mocks = new MockRepository(); var basicServer = mocks.StrictMock<ISolrBasicOperations<TestDocument>>(); var mapper = mocks.StrictMock<IReadOnlyMappingManager>(); var validationManager = mocks.StrictMock<IMappingValidator>(); With.Mocks(mocks) .Expecting(() => Expect.Call( basicServer.AddWithBoost(Arg<IEnumerable<KeyValuePair<TestDocument, double?>>>.Is.Anything, Arg<AddParameters>.Is.Null)) .Repeat.Once()) .Verify(() => { var s = new SolrServer<TestDocument>(basicServer, mapper, validationManager); var t = new TestDocument(); s.AddWithBoost(t, 2.1); }); }
public void ClonesDocument() { // Given TestDocument document = new TestDocument() { { "Foo", "abc" } }; // When IDocument result = document.ToDocument(new MetadataItems { { "Bar", "123" } }); // Then result["Foo"].ShouldBe("abc"); result["Bar"].ShouldBe("123"); result.ShouldBeOfType <TestDocument>(); }
public void AddWithBoost_single_doc_calls_operations_with_null_add_parameters() { var mocks = new MockRepository(); var basicServer = mocks.StrictMock <ISolrBasicOperations <TestDocument> >(); var mapper = mocks.StrictMock <IReadOnlyMappingManager>(); var validationManager = mocks.StrictMock <IMappingValidator>(); With.Mocks(mocks) .Expecting(() => Expect.Call( basicServer.AddWithBoost(Arg <IEnumerable <KeyValuePair <TestDocument, double?> > > .Is.Anything, Arg <AddParameters> .Is.Null)) .Repeat.Once()) .Verify(() => { var s = new SolrServer <TestDocument>(basicServer, mapper, validationManager); var t = new TestDocument(); s.AddWithBoost(t, 2.1); }); }
public void SingleImageDownloadWithRequestHeader() { // Given IDocument document = new TestDocument(); IExecutionContext context = new TestExecutionContext(); RequestHeaders header = new RequestHeaders(); header.Accept.Add("image/jpeg"); IModule download = new Download().WithUri("https://wyam.io/Content/images/nav-logo.png", header); // When IList <IDocument> results = download.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list // Then using (Stream stream = results.Single().GetStream()) { stream.ReadByte().ShouldNotBe(-1); } }
public void AddWithBoost_single_doc_calls_operations_with_null_add_parameters() { var basicServer = new MSolrBasicOperations <TestDocument>(); basicServer.addWithBoost += (a, b) => { Assert.Null(b); return(null); }; var mapper = new MReadOnlyMappingManager(); var validationManager = new MMappingValidator(); var s = new SolrServer <TestDocument>(basicServer, mapper, validationManager); var t = new TestDocument(); s.AddWithBoost(t, 2.1); Assert.Equal(1, basicServer.addWithBoost.Calls); }
public async Task OrdersUsingCommonTypeConversion() { // Given TestDocument a = new TestDocument { { "Foo", "1/1/2010" } }; TestDocument c = new TestDocument { { "Foo", new DateTime(2009, 1, 1) } }; OrderDocuments order = new OrderDocuments("Foo"); // When IReadOnlyList <IDocument> results = await ExecuteAsync(new[] { a, c }, order); // Then results.ShouldBe(new[] { c, a }); }
public void MultipleHtmlDownload() { // Given IDocument document = new TestDocument(); TestExecutionContext context = new TestExecutionContext { HttpResponseFunc = (_, __) => { HttpResponseMessage response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("Fizz") }; response.Headers.Add("Foo", "Bar"); return(response); } }; IModule download = new Download().WithUris("https://wyam.io/", "https://github.com/Wyamio/Wyam"); // When IList <IDocument> results = download.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list // Then foreach (IDocument result in results) { Dictionary <string, string> headers = result[Keys.SourceHeaders] as Dictionary <string, string>; Assert.IsNotNull(headers, "Header cannot be null"); Assert.IsTrue(headers.Count > 0, "Headers must contain contents"); foreach (KeyValuePair <string, string> h in headers) { Assert.IsNotEmpty(h.Key, "Header key cannot be empty"); Assert.IsNotEmpty(h.Value, "Header value cannot be empty"); } using (Stream stream = result.GetStream()) { string content = new StreamReader(stream).ReadToEnd(); Assert.IsNotEmpty(content, "Download cannot be empty"); } } }
public void TestXlsx() { // Given string output = string.Empty + "\"\",\"A\",\"B\",\"C\",\"D\",\"E\",\"F\",\"G\"\r\n" + "\"1\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\"\r\n" + "\"2\",\"2\",\"4\",\"6\",\"8\",\"10\",\"12\",\"14\"\r\n" + "\"3\",\"3\",\"6\",\"9\",\"12\",\"15\",\"18\",\"21\"\r\n" + "\"4\",\"4\",\"8\",\"12\",\"16\",\"20\",\"24\",\"28\"\r\n" + "\"5\",\"5\",\"10\",\"15\",\"20\",\"25\",\"30\",\"35\"\r\n" + "\"6\",\"6\",\"12\",\"18\",\"24\",\"30\",\"36\",\"42\"\r\n" + "\"7\",\"7\",\"14\",\"21\",\"28\",\"35\",\"42\",\"49\"\r\n" + "\"8\",\"8\",\"16\",\"24\",\"32\",\"40\",\"48\",\"56\"\r\n" + "\"9\",\"9\",\"18\",\"27\",\"36\",\"45\",\"54\",\"63\"\r\n" + "\"10\",\"10\",\"20\",\"30\",\"40\",\"50\",\"60\",\"70\"\r\n" + "\"11\",\"11\",\"22\",\"33\",\"44\",\"55\",\"66\",\"77\"\r\n" + "\"12\",\"12\",\"24\",\"36\",\"48\",\"60\",\"72\",\"84\"\r\n" + "\"13\",\"13\",\"26\",\"39\",\"52\",\"65\",\"78\",\"91\"\r\n" + "\"14\",\"14\",\"28\",\"42\",\"56\",\"70\",\"84\",\"98\"\r\n" + "\"15\",\"15\",\"30\",\"45\",\"60\",\"75\",\"90\",\"105\"\r\n" + "\"16\",\"16\",\"32\",\"48\",\"64\",\"80\",\"96\",\"112\"\r\n" + "\"17\",\"17\",\"34\",\"51\",\"68\",\"85\",\"102\",\"119\"\r\n" + "\"18\",\"18\",\"36\",\"54\",\"72\",\"90\",\"108\",\"126\"\r\n" + "\"19\",\"19\",\"38\",\"57\",\"76\",\"95\",\"114\",\"133\"\r\n" + "\"20\",\"20\",\"40\",\"60\",\"80\",\"100\",\"120\",\"140\"\r\n" + "\"21\",\"21\",\"42\",\"63\",\"84\",\"105\",\"126\",\"147\"\r\n" + "\"22\",\"22\",\"44\",\"66\",\"88\",\"110\",\"132\",\"154\"\r\n" + "\"23\",\"23\",\"46\",\"69\",\"92\",\"115\",\"138\",\"161\"\r\n" + "\"24\",\"24\",\"48\",\"72\",\"96\",\"120\",\"144\",\"168\"\r\n" + "\"25\",\"25\",\"50\",\"75\",\"100\",\"125\",\"150\",\"175\"\r\n" + "\"26\",\"26\",\"52\",\"78\",\"104\",\"130\",\"156\",\"182\"\r\n"; TestExecutionContext context = new TestExecutionContext(); TestDocument document = new TestDocument(GetTestFileStream("test.xlsx")); ExcelToCsv module = new ExcelToCsv(); // When IList <IDocument> results = module.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list // Then results.Count.ShouldBe(1); results[0].Content.ShouldBe(output, StringCompareShould.IgnoreLineEndings); }
public async Task RenderModuleDefinedLayoutFile() { // Given Engine engine = new Engine(); TestExecutionContext context = GetExecutionContext(engine); TestDocument document = GetDocument( "/Layout/Test.cshtml", "<p>This is a test</p>"); RenderRazor razor = new RenderRazor().WithLayout((NormalizedPath)"_Layout.cshtml"); // When TestDocument result = await ExecuteAsync(document, context, razor).SingleAsync(); // Then result.Content.ShouldBe( @"LAYOUT <p>This is a test</p>", StringCompareShould.IgnoreLineEndings); }
public void FlattensTopLevel() { // Given TestExecutionContext context = new TestExecutionContext(); TestDocument document = new TestDocument(_jsonContent); Json json = new Json(); // When IList <IDocument> results = json.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list // Then IDocument result = results.Single(); result.Count.ShouldBe(4); ((string)result["Email"]).ShouldBe("*****@*****.**"); ((bool)result["Active"]).ShouldBeTrue(); ((DateTime)result["CreatedDate"]).ShouldBe(new DateTime(2013, 1, 20, 0, 0, 0, DateTimeKind.Utc)); ((IEnumerable)result["Roles"]).ShouldBe(new[] { "User", "Admin" }); }
public async Task LoadViewStartAndLayoutFile() { // Given Engine engine = new Engine(); TestExecutionContext context = GetExecutionContext(engine); TestDocument document = GetDocument( "/ViewStartAndLayout/Test.cshtml", "<p>This is a test</p>"); RenderRazor razor = new RenderRazor(); // When TestDocument result = await ExecuteAsync(document, context, razor).SingleAsync(); // Then result.Content.ShouldBe( @"LAYOUT2 <p>This is a test</p>", StringCompareShould.IgnoreLineEndings); }
public async Task ContextConfigContentReturnsCorrectDocumentWhenInputs() { // Given TestExecutionContext context = new TestExecutionContext(); context.Settings.Add("Foo", "Bar"); CreateDocuments create = new CreateDocuments(Config.FromContext(x => $"{x.Settings.GetString("Foo")}1")); TestDocument input = new TestDocument("Baz"); input.TestMetadata.Add("ABC", 123); // When IReadOnlyList <TestDocument> results = await ExecuteAsync(input, context, create); // Then results.Select(x => x.Content).ShouldBe(new[] { "Bar1" }); results.Select(x => x.ContainsKey("ABC")).ShouldBe(new bool[] { false }); }
public async Task RendersGist() { TestExecutionContext context = new TestExecutionContext(); TestDocument document = new TestDocument(); KeyValuePair <string, string>[] args = new KeyValuePair <string, string>[] { new KeyValuePair <string, string>(null, "abc"), new KeyValuePair <string, string>(null, "def"), new KeyValuePair <string, string>(null, "ghi"), }; GistShortcode shortcode = new GistShortcode(); // When TestDocument result = (TestDocument)await shortcode.ExecuteAsync(args, null, document, context); // Then result.Content.ShouldBe("<script src=\"//gist.github.com/def/abc.js?file=ghi\" type=\"text/javascript\"></script>"); }
public async Task MissingKey() { // Given TestExecutionContext context = new TestExecutionContext(); TestDocument document = new TestDocument(); KeyValuePair <string, string>[] args = new KeyValuePair <string, string>[] { new KeyValuePair <string, string>("Key", "Foo"), new KeyValuePair <string, string>("ValueKey", "Bar") }; ForEachShortcode shortcode = new ForEachShortcode(); // When IEnumerable <IDocument> result = await shortcode.ExecuteAsync(args, "Fizzbuzz", document, context); // Then result.ShouldBeNull(); }
public async Task CachesDocuments() { // Given TestDocument a1 = new TestDocument(new FilePath("/input/a"), "a"); TestDocument b1 = new TestDocument(new FilePath("/input/b"), "b"); TestDocument a2 = new TestDocument(new FilePath("/input/a"), "aa"); TestDocument b2 = new TestDocument(new FilePath("/input/b"), "b"); CacheDocuments cacheDocuments = new CacheDocuments( new SetMetadata("Content", Config.FromDocument(async doc => await doc.GetContentStringAsync()))); // When _ = await ExecuteAsync(new[] { a1, b1 }, cacheDocuments); IReadOnlyList <TestDocument> results = await ExecuteAsync(new[] { a2, b2 }, cacheDocuments); // Then CollectionAssert.AreEqual(new[] { "b", "aa" }, results.Select(x => x["Content"])); CollectionAssert.AreEqual(new[] { b1.Id, a2.Id }, results.Select(x => x.Id)); }
public async Task DoesNotRewriteOutsideQuerySelectorWhenNoReplacements() { // Given string inputContent = $"<div>@x.Select(x => x) <code>Foo bar</code></div>"; string expectedContent = $"<div>@x.Select(x => x) <code>Foo bar</code></div>"; TestDocument document = new TestDocument(inputContent); Dictionary <string, string> links = new Dictionary <string, string>(); InsertLinks autoLink = new InsertLinks(links) .WithQuerySelector("code") .WithMatchOnlyWholeWord() .WithStartWordSeparators('<') .WithEndWordSeparators('>'); // When TestDocument result = await ExecuteAsync(document, autoLink).SingleAsync(); // Then result.Content.ShouldBe(expectedContent); }
public void QueryLazilyOnStoringIndexWithTransformerInShardedSetup() { using (var session = store.OpenSession()) { var testDoc = new TestDocument { Id = "test_doc" }; session.Store(testDoc); session.SaveChanges(); var result = session.Query <CustomIndexObject, TestWithStorageIndex>() .Customize(x => x.WaitForNonStaleResults()) .Where(x => x.Id.Equals("shard/test_doc")) .TransformWith <TestTransformerFromStoredIndex, TestDto>() .Lazily(); var res = result.Value.FirstOrDefault(); Assert.NotNull(res); } }
public async Task MultipleShortcodeResultDocuments() { // Given TestExecutionContext context = new TestExecutionContext(); context.Shortcodes.Add <MultiShortcode>("S"); TestDocument document = new TestDocument("123<?# S /?>456") { { "Foo", 10 } }; ProcessShortcodes module = new ProcessShortcodes(); // When TestDocument result = await ExecuteAsync(document, context, module).SingleAsync(); // Then result.Content.ShouldBe("123aaaBBB456"); result["Foo"].ShouldBe(12); }
public async Task CallsOverridesOnException() { // Given TestDocument a = new TestDocument("A"); TestDocument b = new TestDocument("B"); IExecutionContext context = new TestExecutionContext(a, b); TestModule module = new TestModule(null, null, true); // When await Should.ThrowAsync(module.ExecuteAsync(context), typeof(Exception)); // Then module.BeforeExecutionCount.ShouldBe(1); module.BeforeExecutionAsyncCount.ShouldBe(1); module.AfterExecutionCount.ShouldBe(0); module.AfterExecutionAsyncCount.ShouldBe(0); module.FinallyCount.ShouldBe(1); module.FinallyAsyncCount.ShouldBe(1); }
public async Task ShortcodesCanAddMetadata() { // Given TestExecutionContext context = new TestExecutionContext(); context.Shortcodes.Add <AddsMetadataShortcode>("S1"); context.Shortcodes.Add <AddsMetadataShortcode2>("S2"); TestDocument document = new TestDocument("123<?# S1 /?>456<?# S2 /?>789"); ProcessShortcodes module = new ProcessShortcodes(); // When TestDocument result = await ExecuteAsync(document, context, module).SingleAsync(); // Then result.Content.ShouldBe("123456789"); result["A"].ShouldBe("3"); result["B"].ShouldBe("2"); result["C"].ShouldBe("4"); }
public async Task ChangesContentAndMetadata() { // Given const string input = @"<html> <head> <title>Foobar</title> </head> <body> <h1>Title</h1> <p>This is some Foobar text</p> <p>This is some other text</p> </body> </html>"; TestDocument document = new TestDocument(input); int c = 1; ProcessHtml process = new ProcessHtml("p", (e, m) => { e.Insert(AngleSharp.Dom.AdjacentPosition.AfterEnd, "Fuzz"); m.Add("Foo" + c++.ToString(), e.TextContent); }); // When IReadOnlyList <TestDocument> results = await ExecuteAsync(document, process); // Then TestDocument result = results.ShouldHaveSingleItem(); result.ShouldNotBe(document); result.Content.ShouldBe( @"<html><head> <title>Foobar</title> </head> <body> <h1>Title</h1> <p>This is some Foobar text</p>Fuzz <p>This is some other text</p>Fuzz </body></html>", StringCompareShould.IgnoreLineEndings); result["Foo1"].ShouldBe("This is some Foobar text"); result["Foo2"].ShouldBe("This is some other text"); }
public void Add_single_doc_calls_operations_with_null_add_parameters() { var basicServer = new MSolrBasicOperations <TestDocument>(); basicServer.addWithBoost += (docs, param) => { Assert.Null(param); return(null); }; basicServer.addWithBoost &= x => x.Expect(1); var mapper = new MReadOnlyMappingManager(); var validationManager = new MMappingValidator(); var s = new SolrServer <TestDocument>(basicServer, mapper, validationManager); var t = new TestDocument(); s.Add(t); basicServer.addWithBoost.Verify(); }
public void AddWithBoost_single_doc_with_add_parameters_calls_operations_with_same_add_parameters() { var basicServer = new MSolrBasicOperations<TestDocument>(); var parameters = new AddParameters { CommitWithin = 4343 }; var t = new TestDocument(); basicServer.addWithBoost += (docs, p) => { Assert.AreSame(parameters, p); var ldocs = docs.ToList(); Assert.AreEqual(1, ldocs.Count); var doc = ldocs[0]; Assert.AreEqual(2.1, doc.Value); Assert.AreSame(t, doc.Key); return null; }; var s = new SolrServer<TestDocument>(basicServer, null, null); s.AddWithBoost(t, 2.1, parameters); Assert.AreEqual(1, basicServer.addWithBoost.Calls); }
public void AllowNonAuthoratativeInformationAlwaysWorks() { const int callCount = 10000; using (IDocumentStore documentStore = new EmbeddableDocumentStore { RunInMemory = true }) { documentStore.Initialize(); int documentId; // create test document using (IDocumentSession session = documentStore.OpenSession()) { var testDocument = new TestDocument(); session.Store(testDocument); session.SaveChanges(); documentId = testDocument.Id; } // do many 'set property and check value' tests for (int i = 0; i < callCount; i++) { using (IDocumentSession session = documentStore.OpenSession()) using (var tx = new TransactionScope()) { session.Load <TestDocument>(documentId).Value = i; session.SaveChanges(); tx.Complete(); } using (IDocumentSession session = documentStore.OpenSession()) { session.Advanced.AllowNonAuthoritativeInformation = false; var loadedDoc = session.Load <TestDocument>(documentId); Assert.Equal(i, loadedDoc.Value); } } } }
public async Task WhenDocumentHasNotBeenSavedToStorage_ItShouldBeRetrievable() { // Arrange var documentStore = await FixtureHelper.CreateDocumentStore(); var session = documentStore.CreateSession(); var document = new TestDocument { Id = Guid.NewGuid().ToString(), PartitionKey = "Tests" }; session.Add(document); // Act var results = await session.LoadMany <TestDocument>(new [] { document.Id }); // Assert Assert.Contains(results, pair => pair.Key == document.Id); Assert.Same(document, results[document.Id]); }
public async Task AlternateIgnorePrefix() { // Given Engine engine = new Engine(); TestExecutionContext context = GetExecutionContext(engine); TestDocument document1 = GetDocument( "/AlternateIgnorePrefix/Test.cshtml", "<p>This is a test</p>"); TestDocument document2 = GetDocument( "/AlternateIgnorePrefix/IgnoreMe.cshtml", "<p>Ignore me</p>"); RenderRazor razor = new RenderRazor().IgnorePrefix("Ignore"); // When TestDocument result = await ExecuteAsync(new[] { document1, document2 }, context, razor).SingleAsync(); // Then result.Content.ShouldBe("<p>This is a test</p>"); }
public async Task FlattensTopLevelScalarNodes() { // Given TestDocument document = new TestDocument(@" A: 1 B: true C: Yes "); ParseYaml yaml = new ParseYaml(); // When TestDocument result = await ExecuteAsync(document, yaml).SingleAsync(); // Then result.Keys.ShouldBe(new[] { "A", "B", "C", "Source", "Destination", "ContentProvider" }, true); result["A"].ShouldBe("1"); result["B"].ShouldBe("true"); result["C"].ShouldBe("Yes"); }
public async Task AlternateRelativeViewStartPathWithRelativeLayout() { // Given Engine engine = new Engine(); TestExecutionContext context = GetExecutionContext(engine); TestDocument document = GetDocument( "/AlternateViewStartPath/Test.cshtml", "<p>This is a test</p>"); RenderRazor razor = new RenderRazor().WithViewStart((FilePath)"AlternateViewStart/_ViewStartRelativeLayout.cshtml"); // When TestDocument result = await ExecuteAsync(document, context, razor).SingleAsync(); // Then result.Content.ShouldBe( @"LAYOUT3 <p>This is a test</p>", StringCompareShould.IgnoreLineEndings); }
public async Task IgnoresNullResult() { // Given TestDocument[] inputs = new TestDocument[] { new TestDocument { { "Outputs", new string[] { "A", "B" } } }, new TestDocument() }; TestModule module = new TestModule(); // When ImmutableArray <TestDocument> results = await ExecuteAsync(inputs, module); // Then results.Select(x => x.Content).ShouldBe(new[] { "A", "B" }, true); }
public async Task Title_is_null_if_document_has_no_heading() { // ARRANGE var input = new TestDocument( @"<html> <head> </head> <body> </body> </html>"); var sut = new InferTitle(); // ACT var output = await ExecuteAsync(input, sut).SingleAsync(); // ASSERT output.Keys.Should().NotContain(DocsTemplateKeys.Title); }
public void AddsExtension() { // Given IDocument redirected = new TestDocument(new MetadataItems { { Keys.RedirectFrom, new List <FilePath> { new FilePath("foo/bar") } } }); IDocument notRedirected = new TestDocument(); IExecutionContext context = new TestExecutionContext(); Redirect redirect = new Redirect(); // When List <IDocument> results = redirect.Execute(new[] { redirected, notRedirected }, context).ToList(); // Make sure to materialize the result list // Then CollectionAssert.AreEqual(new[] { "foo/bar.html" }, results.Select(x => x.Get <FilePath>(Keys.WritePath).FullPath)); }
public void QueryOnReducedIndexWithTransformerInShardedSetup() { using (var session = store.OpenSession()) { var testDoc = new TestDocument { Id = "test_doc" }; session.Store(testDoc); session.SaveChanges(); var result = session.Query <TestReduceIndex.ReduceResult, TestReduceIndex>() .Customize(x => x.WaitForNonStaleResults()) .Where(x => x.Id.Equals("shard/test_doc")) .TransformWith <TestTransformer, TestDto>() .FirstOrDefault(); Assert.NotNull(result); } }
public void AllowNonAuthoritativeInformationAlwaysWorks() { const int callCount = 10000; using (var documentStore = NewDocumentStore(requestedStorage: "esent")) { EnsureDtcIsSupported(documentStore); int documentId; // create test document using (IDocumentSession session = documentStore.OpenSession()) { var testDocument = new TestDocument(); session.Store(testDocument); session.SaveChanges(); documentId = testDocument.Id; } // do many 'set property and check value' tests for (int i = 0; i < callCount; i++) { using (IDocumentSession session = documentStore.OpenSession()) using (var tx = new TransactionScope()) { session.Load<TestDocument>(documentId).Value = i; session.SaveChanges(); tx.Complete(); } using (IDocumentSession session = documentStore.OpenSession()) { session.Advanced.AllowNonAuthoritativeInformation = false; var loadedDoc = session.Load<TestDocument>(documentId); Assert.Equal(i, loadedDoc.Value); } } } }
public void AllowNonAuthoratativeInformationAlwaysWorks() { const int callCount = 10000; using (IDocumentStore documentStore = new EmbeddableDocumentStore { RunInMemory = true }) { documentStore.Initialize(); int documentId; // create test document using (IDocumentSession session = documentStore.OpenSession()) { var testDocument = new TestDocument(); session.Store(testDocument); session.SaveChanges(); documentId = testDocument.Id; } // do many 'set property and check value' tests for (int i = 0; i < callCount; i++) { using (IDocumentSession session = documentStore.OpenSession()) using (var tx = new TransactionScope()) { session.Load<TestDocument>(documentId).Value = i; session.SaveChanges(); tx.Complete(); } using (IDocumentSession session = documentStore.OpenSession()) { session.Advanced.AllowNonAuthoritativeInformation = false; var loadedDoc = session.Load<TestDocument>(documentId); Assert.Equal(i, loadedDoc.Value); } } } }
public Task Add(TestDocument doc) { var writer = new IndexWriter(Index, Analyzer, IndexWriter.MaxFieldLength.UNLIMITED); try { Document document = new Document(); document.Add(new Field("id", doc.Id.ToString(), Field.Store.YES, Field.Index.NO)); document.Add(new Field("text", doc.Text, Field.Store.YES, Field.Index.ANALYZED)); writer.AddDocument(document); } catch(Exception e) { // } finally { //Close the writer writer.Commit(); writer.Dispose(); } return Task.FromResult(0); }
public void Save(TestDocument document) { _couch.Save(document); }
public void Insert(int index, TestDocument entity) { base.Insert(index, entity); }
private static void DoTest(IDocumentStore store, string database = null) { if (database == null) { using (var session = store.OpenSession()) { session.Store(new { Exclude = false, Id = "Raven/Versioning/DefaultConfiguration", MaxRevisions = int.MaxValue }); session.SaveChanges(); } using (var session = store.OpenSession()) { var testDocument = new TestDocument{ Id = 1 }; session.Store(testDocument); session.SaveChanges(); } using (var session = store.OpenSession()) { var document = session.Load<TestDocument>(1); var metadata = session.Advanced.GetMetadataFor(document); Assert.True(metadata.ContainsKey("Raven-Document-Revision")); } } else { using (var session = store.OpenSession(database)) { session.Store(new { Exclude = false, Id = "Raven/Versioning/DefaultConfiguration", MaxRevisions = int.MaxValue }); session.SaveChanges(); } using (var session = store.OpenSession(database)) { var testDocument = new TestDocument { Id = 1 }; session.Store(testDocument); session.SaveChanges(); } using (var session = store.OpenSession(database)) { var document = session.Load<TestDocument>(1); var metadata = session.Advanced.GetMetadataFor(document); Assert.True(metadata.ContainsKey("Raven-Document-Revision")); } } }
public void Add(TestDocument entity) { base.Add(entity); }
public bool Remove(TestDocument entity) { return base.Remove(entity); }
protected override void When() { result = fullTextSession .CreateFullTextQuery<TestDocument>("StringProperty:dolor") .List<TestDocument>()[0]; }
protected override void When() { result = fullTextSession .CreateFullTextQuery<TestDocument>("Id:" + document.Id) .List<TestDocument>()[0]; }
public bool Contains(TestDocument entity) { return base.Contains(entity); }
public int IndexOf(TestDocument entity) { return base.IndexOf(entity); }
protected override void Given() { document = new TestDocument(); session.Save(document); session.Flush(); }
public void WouldBeIndexedProperly() { using (var store = NewDocumentStore()) { using (var session = store.OpenSession()) { // Create the temp index before we populate the db. session.Query<TestDocument>() .Customize(x => x.WaitForNonStaleResultsAsOfNow()) .Count(); } var tasks = new List<Task>(); const int expectedCount = 5000; var ids = new ConcurrentQueue<string>(); for (int i = 0; i < expectedCount; i++) { tasks.Add(Task.Factory.StartNew(() => { using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew)) { // Promote the transaction Transaction.Current.EnlistDurable(DummyEnlistmentNotification.Id, new DummyEnlistmentNotification(), EnlistmentOptions.None); using (var session = store.OpenSession()) { var testDocument = new TestDocument(); session.Store(testDocument); ids.Enqueue(session.Advanced.GetDocumentId(testDocument)); session.SaveChanges(); } scope.Complete(); } })); } Task.WaitAll(tasks.ToArray()); foreach (var id in ids) { using(var session = store.OpenSession()) { session.Advanced.AllowNonAuthoritativeInformation = false; Assert.NotNull(session.Load<TestDocument>(id)); } } using (var session = store.OpenSession()) { var items = session.Query<TestDocument>() .Customize(x => x.WaitForNonStaleResults()) .Take(5005) .ToList(); var missing = new List<int>(); for (int i = 0; i < 5000; i++) { if (items.Any(x => x.Id == i + 1) == false) missing.Add(i); } WaitForUserToContinueTheTest(store); Assert.Equal(expectedCount, items.Count); } } }
protected override void Given() { document = new TestDocument {StringProperty = "lorem ipsum dolor sit amet"}; session.Save(document); session.Flush(); }