public void Inner_Array_Strings() { using (var documentStore = GetDocumentStore()) { using (var session = documentStore.OpenSession()) { session.Store(new Foo4 { Id = "foos/1", Strings = new[] { "A", "B", "C" } }); session.SaveChanges(); } using (var commands = documentStore.Commands()) { var doc = GetJsonString(commands, "foos/1"); Assert.Equal(LinuxTestUtils.Dos2Unix(@"{ ""Strings"": [ ""A"", ""B"", ""C"" ] }"), doc); } } }
public void ShouldNotGetErrors() { using (var store = GetDocumentStore()) { store.Maintenance.Send(new PutIndexesOperation(new[] { new IndexDefinition { Name = "test", Maps = { @"from brief in docs.TestCases select new { _tWarnings_AccessoryWarnings_Value = brief.Warnings.AccessoryWarnings.Select(y=>y.Value) }" } } })); using (var commands = store.Commands()) { var json = commands.ParseJson(LinuxTestUtils.Dos2Unix(@"{ ""Warnings"": { ""AccessoryWarnings"": [ { ""Value"": ""whatever"", ""Id"": 123 }, { ""Value"": ""dsfsdfsd sfsd sd"", ""Id"": 1234 } ] } }")); commands.Put("TestCases/TST00001", null, json, new Dictionary <string, object> { { Constants.Documents.Metadata.Collection, "TestCases" } }); json = commands.ParseJson(@"{ ""Warnings"": { ""AccessoryWarnings"": [] } }"); commands.Put("TestCases/TST00002", null, json, new Dictionary <string, object> { { Constants.Documents.Metadata.Collection, "TestCases" } }); } Indexes.WaitForIndexing(store); RavenTestHelper.AssertNoIndexErrors(store); } }
public void WillNotForgetCastToNullableDateTime() { var indexDefinition = new IndexDefinitionBuilder <Person> { Map = persons => from p in persons select new { DateTime = (DateTime?)null } }.ToIndexDefinition(DocumentConventions.Default); var expected = LinuxTestUtils.Dos2Unix(@"docs.People.Select(p => new { DateTime = ((DateTime ? ) null) })"); Assert.Equal(expected, indexDefinition.Maps.First()); }
public void CanSetPropertyOnArrayItem() { using (var store = GetDocumentStore()) { using (var commands = store.Commands()) { var json = commands.ParseJson(LinuxTestUtils.Dos2Unix(@"{ 'Privilege':[ { 'Level':'Silver', 'Code':'12312', 'EndDate':'12/12/2012' } ], 'Phones':[ { 'Cell':'123123', 'Home':'9783041284', 'Office':'1234123412' } ], 'MiddleName':'asdfasdfasdf', 'FirstName':'asdfasdfasdf' }")); commands.Put("patrons/1", null, json, new Dictionary <string, object> { { Constants.Documents.Metadata.Collection, "patrons" } }); } new Index1().Execute(store); Indexes.WaitForIndexing(store); store .Operations .Send(new PatchByQueryOperation( new IndexQuery { Query = $"FROM INDEX '{new Index1().IndexName}' UPDATE {{ this.Privilege[0].Level = 'Gold' }}" })) .WaitForCompletion(TimeSpan.FromSeconds(15)); using (var commands = store.Commands()) { dynamic document = commands.Get("patrons/1"); var level = document.Privilege[0].Level.ToString(); Assert.Equal("Gold", level); } } }
public void WillNotForgetCastToNullableDateTime() { var indexDefinition = new IndexDefinitionBuilder <Person>() { Map = persons => from p in persons select new { DateTime = (DateTime?)null } #pragma warning disable CS0618 // Type or member is obsolete }.ToIndexDefinition(new DocumentConventions { PrettifyGeneratedLinqExpressions = false }); #pragma warning restore CS0618 // Type or member is obsolete var expected = LinuxTestUtils.Dos2Unix(@"docs.People.Select(p => new { DateTime = ((DateTime ? ) null) })"); Assert.Equal(expected, indexDefinition.Maps.First()); }
public void WillGenerateDecimalCast() { Expression <Func <IEnumerable <Coin>, IEnumerable <object> > > query = x => from y in x group y by y.Denomination into g select new { Denomination = g.Key, Cost = g.Sum(z => z.Cost) }; var code = IndexDefinitionHelper.PruneToFailureLinqQueryAsStringToWorkableCode <Coin, Coin>(query, new DocumentConventions(), "docs", false); Assert.Equal(LinuxTestUtils.Dos2Unix(@"docs.GroupBy(y => y.Denomination).Select(g => new { Denomination = g.Key, Cost = Enumerable.Sum(g, z => ((double) z.Cost)) })"), code); }
public void CanCreateMultiMapIndex() { using (var store = GetDocumentStore(new Options { ModifyDocumentStore = s => s.Conventions.PrettifyGeneratedLinqExpressions = false })) { new CatsAndDogs().Execute(store); var indexDefinition = store.Maintenance.Send(new GetIndexOperation("CatsAndDogs")); Assert.Equal(2, indexDefinition.Maps.Count); Assert.Equal(LinuxTestUtils.Dos2Unix(@"docs.Cats.Select(cat => new { Name = cat.Name })"), indexDefinition.Maps.First()); Assert.Equal(LinuxTestUtils.Dos2Unix(@"docs.Dogs.Select(dog => new { Name = dog.Name })"), indexDefinition.Maps.Skip(1).First()); } }
public void WillProperlyCompileWhenUsingToString() { Expression <Func <IEnumerable <Coin>, IEnumerable <object> > > query = x => from y in x group y by y.Denomination into g select new { Denomination = g.Key, Cost = g.First().Cost.ToString() }; var code = IndexDefinitionHelper.PruneToFailureLinqQueryAsStringToWorkableCode <Coin, Coin>(query, new DocumentConventions(), "docs", false); Assert.Equal(LinuxTestUtils.Dos2Unix(@"docs.GroupBy(y => y.Denomination).Select(g => new { Denomination = g.Key, Cost = (DynamicEnumerable.FirstOrDefault(g)).Cost.ToString() })"), code); }
public void Inner_List_Objects() { using (var documentStore = GetDocumentStore()) { using (var session = documentStore.OpenSession()) { session.Store(new Foo7 { Id = "foos/1", Bars = new List <Bar> { new Bar { Baz = "A" }, new Bar { Baz = "B" }, new Bar { Baz = "C" } } }); session.SaveChanges(); } using (var commands = documentStore.Commands()) { var doc = GetJsonString(commands, "foos/1"); Assert.Equal(LinuxTestUtils.Dos2Unix(@"{ ""Bars"": [ { ""Baz"": ""A"" }, { ""Baz"": ""B"" }, { ""Baz"": ""C"" } ] }"), doc); } } }
public void CanIndexWithNoErrors_Datetime() { using (var store = GetDocumentStore()) { using (var commands = store.Commands()) { var json = commands.ParseJson(LinuxTestUtils.Dos2Unix(@"{ '$type': 'Domain.Model.Clicks.ClickAllocation, Domain', 'AccountId': 'accounts/4', 'Quantity': 90, 'Date': '2011-12-12T08:47:44.0706445', 'Key': null, 'OrderNumber': null, 'PurchaseOrderNumber': null, 'PurchaseDate': '0001-01-01T00:00:00.0000000-05:00', 'ReorderQuantity': 0, 'Type': 'Dealer', 'LastSavedDate': '2011-12-12T08:47:44.1643945-05:00', 'LastSavedUser': '******', 'SourceId': '00000000-0000-0000-0000-000000000000' }")); commands.Put("test/1", null, json, new Dictionary <string, object> { { Constants.Documents.Metadata.Collection, "ClickAllocations" } }); json = commands.ParseJson(LinuxTestUtils.Dos2Unix(@"{ '$type': 'Domain.Model.Clicks.ClickAllocation, Domain', 'AccountId': 'accounts/4', 'Quantity': 20, 'Date': '2012-02-28T16:05:18.7359910', 'Key': null, 'OrderNumber': null, 'PurchaseOrderNumber': null, 'PurchaseDate': '0001-01-01T00:00:00.0000000', 'ReorderQuantity': 5, 'Type': 'Dealer', 'LastSavedDate': '2012-02-28T16:05:19.3609910', 'LastSavedUser': '******', 'SourceId': '00000000-0000-0000-0000-000000000000' }")); commands.Put("test/2", null, json, new Dictionary <string, object> { { Constants.Documents.Metadata.Collection, "ClickAllocations" } }); } store.Maintenance.Send(new PutIndexesOperation(new[] { new IndexDefinition { Name = "test", Maps = { LinuxTestUtils.Dos2Unix(@"docs.ClickAllocations .Select(doc => new {AccountId = doc.AccountId, Date = doc.Date, Id = Id(doc), Key = doc.Key, LastSavedDate = doc.LastSavedDate, LastSavedUser = doc.LastSavedUser, OrderNumber = doc.OrderNumber, PurchaseDate = doc.PurchaseDate, PurchaseOrderNumber = doc.PurchaseOrderNumber, Quantity = doc.Quantity, ReorderQuantity = doc.ReorderQuantity, Type = doc.Type}) ") }, Reduce = LinuxTestUtils.Dos2Unix(@"results .GroupBy(result => result.AccountId) .Select(a => new {a = a, clickAllocation = a.OrderByDescending(x => x.Date).FirstOrDefault()}) .Select(__h__TransparentIdentifier0 => new {AccountId = __h__TransparentIdentifier0.clickAllocation.AccountId, Date = __h__TransparentIdentifier0.clickAllocation.Date, Id = __h__TransparentIdentifier0.clickAllocation.Id, Key = __h__TransparentIdentifier0.clickAllocation.Key, LastSavedDate = __h__TransparentIdentifier0.clickAllocation.LastSavedDate, LastSavedUser = __h__TransparentIdentifier0.clickAllocation.LastSavedUser, OrderNumber = __h__TransparentIdentifier0.clickAllocation.OrderNumber, PurchaseDate = __h__TransparentIdentifier0.clickAllocation.PurchaseDate, PurchaseOrderNumber = __h__TransparentIdentifier0.clickAllocation.PurchaseOrderNumber, Quantity = __h__TransparentIdentifier0.clickAllocation.Quantity, ReorderQuantity = __h__TransparentIdentifier0.clickAllocation.ReorderQuantity, Type = __h__TransparentIdentifier0.clickAllocation.Type})") } })); WaitForIndexing(store); RavenTestHelper.AssertNoIndexErrors(store); } }