コード例 #1
0
ファイル: RavenDB815.cs プロジェクト: yitaom2/ravendb
        public void Inner_IList_Strings_From_Array()
        {
            using (var documentStore = GetDocumentStore())
            {
                using (var session = documentStore.OpenSession())
                {
                    session.Store(new Foo1 {
                        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);
                }
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
ファイル: RavenDB_483.cs プロジェクト: radtek/ravendb
        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());
        }
コード例 #4
0
ファイル: SetBased.cs プロジェクト: ikvm/ravendb
        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);
                }
            }
        }
コード例 #5
0
ファイル: RavenDB_483.cs プロジェクト: morhilai/ravendb
        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());
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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());
            }
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        public unsafe void RavenDB_15975()
        {
            using (var options = StorageEnvironmentOptions.ForPath(DataDir))
            {
                options.Encryption.MasterKey = Sodium.GenerateRandomBuffer((int)Sodium.crypto_aead_xchacha20poly1305_ietf_keybytes());

                using (var innerPager = LinuxTestUtils.GetNewPager(options, DataDir, "Raven.Voron"))
                {
                    AbstractPager cryptoPager;
                    using (cryptoPager = new CryptoPager(innerPager))
                    {
                        using (var tx = new TempPagerTransaction(isWriteTransaction: true))
                        {
                            var overflowSize = 4 * Constants.Storage.PageSize + 100;

                            cryptoPager.EnsureContinuous(26, 5);
                            var pagePointer = cryptoPager.AcquirePagePointerForNewPage(tx, 26, 5);

                            var header = (PageHeader *)pagePointer;
                            header->PageNumber   = 26;
                            header->Flags        = PageFlags.Overflow;
                            header->OverflowSize = overflowSize;

                            Memory.Set(pagePointer + PageHeader.SizeOf, (byte)'X', overflowSize);
                        }


                        using (var tx = new TempPagerTransaction())
                        {
                            var pagePointer = cryptoPager.AcquirePagePointer(tx, 26);

                            // Making sure that the data was decrypted and still holds those 'X' chars
                            Assert.True(pagePointer[PageHeader.SizeOf] == 'X');
                            Assert.True(pagePointer[666] == 'X');
                            Assert.True(pagePointer[1039] == 'X');
                        }
                    }
                }
            }
        }
コード例 #10
0
ファイル: RavenDB815.cs プロジェクト: rstonkus/ravendb
        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);
                }
            }
        }
コード例 #11
0
        public unsafe void WriteAndReadPageUsingCryptoPager()
        {
            using (var options = StorageEnvironmentOptions.ForPath(DataDir))
            {
                options.Encryption.MasterKey = Sodium.GenerateRandomBuffer((int)Sodium.crypto_aead_xchacha20poly1305_ietf_keybytes());

                using (var innerPager = LinuxTestUtils.GetNewPager(options, DataDir, "Raven.Voron"))
                {
                    AbstractPager cryptoPager;
                    using (cryptoPager = new CryptoPager(innerPager))
                    {
                        using (var tx = new TempPagerTransaction(isWriteTransaction: true))
                        {
                            cryptoPager.EnsureContinuous(17, 1); // We're gonna try to read and write to page 17
                            var pagePointer = cryptoPager.AcquirePagePointerForNewPage(tx, 17, 1);

                            var header = (PageHeader *)pagePointer;
                            header->PageNumber = 17;
                            header->Flags      = PageFlags.Single | PageFlags.FixedSizeTreePage;

                            Memory.Set(pagePointer + PageHeader.SizeOf, (byte)'X', Constants.Storage.PageSize - PageHeader.SizeOf);
                        }

                        using (var tx = new TempPagerTransaction())
                        {
                            var pagePointer = cryptoPager.AcquirePagePointer(tx, 17);

                            // Making sure that the data was decrypted and still holds those 'X' chars
                            Assert.True(pagePointer[PageHeader.SizeOf] == 'X');
                            Assert.True(pagePointer[666] == 'X');
                            Assert.True(pagePointer[1039] == 'X');
                        }
                    }
                }
            }
        }
コード例 #12
0
ファイル: Everett616.cs プロジェクト: yitaom2/ravendb
        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);
            }
        }
コード例 #13
0
ファイル: Checksum.cs プロジェクト: rstonkus/ravendb
        public unsafe void ValidatePageChecksumShouldDetectDataCorruption()
        {
            // Create some random data
            var treeNames = new List <string>();

            var random = new Random();

            var value1 = new byte[random.Next(1024 * 1024 * 2)];
            var value2 = new byte[random.Next(1024 * 1024 * 2)];

            random.NextBytes(value1);
            random.NextBytes(value2);

            const int treeCount   = 5;
            const int recordCount = 6;

            using (var env = new StorageEnvironment(StorageEnvironmentOptions.ForPath(DataDir)))
            {
                env.Options.ManualFlushing = true;

                for (int i = 0; i < treeCount; i++)
                {
                    using (var tx = env.WriteTransaction())
                    {
                        string name = "tree/" + i;
                        treeNames.Add(name);

                        var tree = tx.CreateTree(name);

                        for (int j = 0; j < recordCount; j++)
                        {
                            tree.Add(string.Format("{0}/items/{1}", name, j), j % 2 == 0 ? value1 : value2);
                        }

                        tx.Commit();
                    }
                }
                env.FlushLogToDataFile();
            }

            // Lets corrupt something
            using (var options = StorageEnvironmentOptions.ForPath(DataDir))
                using (var pager = LinuxTestUtils.GetNewPager(options, DataDir, "Raven.Voron"))
                    using (var tempTX = new TempPagerTransaction())
                    {
                        var writePtr = pager.AcquirePagePointer(tempTX, 2) + PageHeader.SizeOf + 43; // just some random place on page #2
                        for (byte i = 0; i < 8; i++)
                        {
                            writePtr[i] = i;
                        }
                    }

            // Now lets try to read it all back and hope we get an exception
            try
            {
                using (var env = new StorageEnvironment(StorageEnvironmentOptions.ForPath(DataDir)))
                {
                    using (var tx = env.ReadTransaction())
                    {
                        foreach (var treeName in treeNames)
                        {
                            var tree = tx.CreateTree(treeName);

                            for (int i = 0; i < recordCount; i++)
                            {
                                var readResult = tree.Read(string.Format("{0}/items/{1}", treeName, i));

                                Assert.NotNull(readResult);

                                if (i % 2 == 0)
                                {
                                    var readBytes = new byte[value1.Length];
                                    readResult.Reader.Read(readBytes, 0, readBytes.Length);
                                }
                                else
                                {
                                    var readBytes = new byte[value2.Length];
                                    readResult.Reader.Read(readBytes, 0, readBytes.Length);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Assert.True(e is InvalidOperationException || e is InvalidDataException);
            }
        }