PageRenderTime 52ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/Raven.Tests.Issues/RavenDB_3994.cs

http://github.com/ravendb/ravendb
C# | 98 lines | 96 code | 2 blank | 0 comment | 0 complexity | 200e8cd57f42e7d6efeedf1ab071ef77 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, Apache-2.0, BSD-3-Clause
  1. using System;
  2. using System.Linq;
  3. using FluentAssertions;
  4. using Raven.Abstractions.Data;
  5. using Raven.Abstractions.Indexing;
  6. using Raven.Client.Indexes;
  7. using Raven.Database.Linq.PrivateExtensions;
  8. using Raven.Json.Linq;
  9. using Raven.Tests.Bundles.ScriptedIndexResults;
  10. using Raven.Tests.Common;
  11. using Xunit;
  12. namespace Raven.Tests.Issues
  13. {
  14. public class RavenDB_3994 : RavenTest
  15. {
  16. protected override void ModifyConfiguration(Database.Config.InMemoryRavenConfiguration configuration)
  17. {
  18. configuration.Settings["Raven/ActiveBundles"] = "ScriptedIndexResults";
  19. }
  20. [Fact]
  21. public void EachDocumentOutputHasItsOwnKey()
  22. {
  23. using (var store = NewDocumentStore())
  24. {
  25. using (var s = store.OpenSession())
  26. {
  27. s.Store(new ScriptedIndexResults
  28. {
  29. Id = ScriptedIndexResults.IdPrefix + new AnimalsPseudoReduce().IndexName,
  30. IndexScript = @"",
  31. DeleteScript = @"PutDocument('DeleteScriptRan', {})"
  32. });
  33. s.SaveChanges();
  34. }
  35. string docId;
  36. using (var s = store.OpenSession())
  37. {
  38. var animal = new Animal
  39. {
  40. Id = "pluto",
  41. Name = "Pluto",
  42. Type = "Dog"
  43. };
  44. s.Store(animal);
  45. docId = s.Advanced.GetDocumentId(animal);
  46. s.SaveChanges();
  47. }
  48. new AnimalsPseudoReduce().Execute(store);
  49. WaitForIndexing(store);
  50. store.DatabaseCommands.Delete(docId, null);
  51. WaitForIndexing(store);
  52. using (var s = store.OpenSession())
  53. {
  54. s.Load<RavenJObject>("DeleteScriptRan").Should().NotBeNull();
  55. }
  56. }
  57. }
  58. public class AnimalsPseudoReduce : AbstractMultiMapIndexCreationTask<AnimalsPseudoReduce.Result>
  59. {
  60. public class Result
  61. {
  62. public string Id { get; set; }
  63. public string Name { get; set; }
  64. }
  65. public AnimalsPseudoReduce()
  66. {
  67. AddMap<Animal>(animals =>
  68. from animal in animals
  69. select new
  70. {
  71. animal.Id,
  72. animal.Name
  73. });
  74. Reduce = animals => from animal in animals
  75. group animal by animal.Id into a
  76. select new
  77. {
  78. Id = a.Single().Id,
  79. Name = a.Single().Name
  80. };
  81. Store(a => a.Name, FieldStorage.Yes);
  82. }
  83. }
  84. }
  85. }