示例#1
0
        public void JsonDeserialize_WhenBlittableArrayBlittableObjectAndLazyStringAreNull_ShouldResultInCopy()
        {
            using (Server.ServerStore.ContextPool.AllocateOperationContext(out JsonOperationContext readContext))
            {
                Command actual;
                using (Server.ServerStore.ContextPool.AllocateOperationContext(out JsonOperationContext writeContext))
                    using (var writer = new BlittableJsonWriter(writeContext))
                    {
                        var jsonSerializer = new JsonSerializer
                        {
                            ContractResolver = new DefaultRavenContractResolver(DocumentConventions.Default.Serialization),
                        };
                        jsonSerializer.Converters.Add(BlittableJsonReaderArrayConverter.Instance);
                        jsonSerializer.Converters.Add(LazyStringValueJsonConverter.Instance);
                        jsonSerializer.Converters.Add(BlittableJsonConverter.Instance);

                        var command = new Command();
                        jsonSerializer.Serialize(writer, command);
                        writer.FinalizeDocument();

                        var toDeseialize = writer.CreateReader();

                        using (var reader = new BlittableJsonReader(readContext))
                        {
                            reader.Initialize(toDeseialize);
                            actual = jsonSerializer.Deserialize <Command>(reader);
                        }
                    }

                Assert.Null(actual.BlittableArray);
                Assert.Null(actual.BlittableObject);
                Assert.Null(actual.LazyString);
            }
        }
        public void SerializeAndDeserialize_MergedPutCommandTest()
        {
            using (Server.ServerStore.ContextPool.AllocateOperationContext(out JsonOperationContext context))
            {
                //Arrange
                var data         = new { ParentProperty = new { NestedProperty = "Some Value" } };
                var document     = DocumentConventions.Default.Serialization.DefaultConverter.ToBlittable(data, context);
                var changeVector = context.GetLazyString("Some Lazy String");
                var expected     = new MergedPutCommand(document, "user/", changeVector, null);

                //Action
                var jsonSerializer = GetJsonSerializer();
                BlittableJsonReaderObject blitCommand;
                using (var writer = new BlittableJsonWriter(context))
                {
                    var dto = expected.ToDto(context);
                    jsonSerializer.Serialize(writer, dto);
                    writer.FinalizeDocument();

                    blitCommand = writer.CreateReader();
                }
                var fromStream = SerializeTestHelper.SimulateSavingToFileAndLoading(context, blitCommand);
                MergedPutCommand actual;
                using (var reader = new BlittableJsonReader(context))
                {
                    reader.Initialize(fromStream);

                    var dto = jsonSerializer.Deserialize <MergedPutCommand.MergedPutCommandDto>(reader);
                    actual = dto.ToCommand(null, null);
                }

                //Assert
                Assert.Equal(expected, actual, new CustomComparer <MergedPutCommand>(context));
            }
        }
示例#3
0
        public void JsonDeserialize_WhenHasBlittableObjectProperty_ShouldResultInCopy()
        {
            using (Server.ServerStore.ContextPool.AllocateOperationContext(out JsonOperationContext readContext))
            {
                Command actual;
                BlittableJsonReaderObject expected;
                using (Server.ServerStore.ContextPool.AllocateOperationContext(out JsonOperationContext writeContext))
                    using (var writer = new BlittableJsonWriter(writeContext))
                    {
                        var data = new { Property = "Value" };
                        expected = DocumentConventions.Default.Serialization.DefaultConverter.ToBlittable(data, readContext);
                        var jsonSerializer = new JsonSerializer
                        {
                            ContractResolver = new DefaultRavenContractResolver(DocumentConventions.Default.Serialization),
                        };

                        jsonSerializer.Converters.Add(BlittableJsonConverter.Instance);
                        var command = new Command {
                            BlittableObject = expected
                        };
                        jsonSerializer.Serialize(writer, command);
                        writer.FinalizeDocument();

                        var toDeseialize = writer.CreateReader();

                        using (var reader = new BlittableJsonReader(readContext))
                        {
                            reader.Initialize(toDeseialize);
                            actual = jsonSerializer.Deserialize <Command>(reader);
                        }
                    }

                Assert.Equal(expected, actual.BlittableObject);
            }
        }
        private static async Task ReadStartRecordingDetailsAsync(IAsyncEnumerator <BlittableJsonReaderObject> iterator, DocumentsOperationContext context, PeepingTomStream peepingTomStream)
        {
            if (await iterator.MoveNextAsync().ConfigureAwait(false) == false)
            {
                throw new ReplayTransactionsException("Replay stream is empty", peepingTomStream);
            }
            using (iterator.Current)
            {
                var jsonSerializer = GetJsonSerializer();
                StartRecordingDetails startDetail;
                using (var reader = new BlittableJsonReader(context))
                {
                    reader.Initialize(iterator.Current);
                    startDetail = jsonSerializer.Deserialize <StartRecordingDetails>(reader);
                }

                if (string.IsNullOrEmpty(startDetail.Type))
                {
                    throw new ReplayTransactionsException($"Can't read {nameof(RecordingDetails.Type)} of replay detail", peepingTomStream);
                }

                if (string.IsNullOrEmpty(startDetail.Type))
                {
                    throw new ReplayTransactionsException($"Can't read {nameof(StartRecordingDetails.Version)} of replay instructions", peepingTomStream);
                }

                if (startDetail.Version != RavenVersionAttribute.Instance.Build)
                {
                    throw new ReplayTransactionsException($"Can't replay transaction instructions of different server version - Current version({ServerVersion.FullVersion}), Record version({startDetail.Version})", peepingTomStream);
                }
            }
        }
示例#5
0
        public void JsonDeserialize_WhenHasLazyStringProperty_ShouldResultInCopy()
        {
            using (Server.ServerStore.ContextPool.AllocateOperationContext(out JsonOperationContext readContext))
            {
                Command         actual;
                LazyStringValue expected;
                using (Server.ServerStore.ContextPool.AllocateOperationContext(out JsonOperationContext writeContext))
                    using (var writer = new BlittableJsonWriter(writeContext))
                    {
                        expected = readContext.GetLazyString("Some Lazy String");
                        var jsonSerializer = new JsonSerializer
                        {
                            ContractResolver    = new DefaultRavenContractResolver(DocumentConventions.Default.Serialization),
                            ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
                        };

                        jsonSerializer.Converters.Add(LazyStringValueJsonConverter.Instance);
                        var command = new Command {
                            LazyString = expected
                        };
                        jsonSerializer.Serialize(writer, command);
                        writer.FinalizeDocument();

                        var toDeseialize = writer.CreateReader();

                        using (var reader = new BlittableJsonReader(readContext))
                        {
                            reader.Initialize(toDeseialize);
                            actual = jsonSerializer.Deserialize <Command>(reader);
                        }
                    }

                Assert.Equal(expected, actual.LazyString);
            }
        }
        public void Directly()
        {
            var json = "{'Id':'users/1', 'Name': 'Oren', 'Dogs':['Arava','Oscar','Phoebe'], 'Age': 34, 'Children':[{'Name':'Date'}]}";

            using (var ctx = JsonOperationContext.ShortTermSingleUse())
            {
                BlittableJsonReaderObject reader = ctx.Read(new MemoryStream(Encoding.UTF8.GetBytes(json)), "users/1");

                var serializer          = new JsonSerializer();
                var blittableJsonReader = new BlittableJsonReader();
                blittableJsonReader.Initialize(reader);
                var u = serializer.Deserialize <User>(blittableJsonReader);

                Assert.Equal("Oren", u.Name);
                Assert.Equal("users/1", u.Id);
                Assert.Equal(3, u.Dogs.Length);
                Assert.Equal("Arava", u.Dogs[0]);
                Assert.Equal("Oscar", u.Dogs[1]);
                Assert.Equal("Phoebe", u.Dogs[2]);
                Assert.Equal(34, u.Age);

                Assert.Equal(1, u.Children.Count);
                Assert.Equal("Date", u.Children[0].Name);
            }
        }
示例#7
0
        public async Task SerializeAndDeserialize_DeleteDocumentCommandTest()
        {
            using (Server.ServerStore.ContextPool.AllocateOperationContext(out JsonOperationContext context))
            {
                //Arrange
                var expected = new DeleteDocumentCommand("Some Id", "Some Change Vector", null);

                //Action
                var jsonSerializer = GetJsonSerializer();
                BlittableJsonReaderObject blitCommand;
                using (var writer = new BlittableJsonWriter(context))
                {
                    var dto = expected.ToDto(context);
                    jsonSerializer.Serialize(writer, dto);
                    writer.FinalizeDocument();

                    blitCommand = writer.CreateReader();
                }
                var fromStream = await SerializeTestHelper.SimulateSavingToFileAndLoadingAsync(context, blitCommand);

                DeleteDocumentCommand actual;
                using (var reader = new BlittableJsonReader(context))
                {
                    reader.Initialize(fromStream);

                    var dto = jsonSerializer.Deserialize <DeleteDocumentCommandDto>(reader);
                    actual = dto.ToCommand(null, null);
                }

                //Assert
                Assert.Equal(expected, actual, new CustomComparer <DeleteDocumentCommand>(context));
            }
        }
示例#8
0
        public async Task SerializeAndDeserialize_MergedPutAttachmentCommand()
        {
            using (Server.ServerStore.ContextPool.AllocateOperationContext(out JsonOperationContext context))
                using (var database = CreateDocumentDatabase())
                {
                    //Arrange
                    var recordFilePath = NewDataPath();

                    var          attachmentStream = new StreamsTempFile(recordFilePath, database.DocumentsStorage.Environment);
                    var          stream           = attachmentStream.StartNewStream();
                    const string bufferContent    = "Menahem";
                    var          buffer           = Encoding.ASCII.GetBytes(bufferContent);
                    stream.Write(buffer);

                    var changeVector = context.GetLazyString("Some Lazy String");
                    var expected     = new AttachmentHandler.MergedPutAttachmentCommand
                    {
                        DocumentId           = "someId",
                        Name                 = "someName",
                        ExpectedChangeVector = changeVector,
                        ContentType          = "someContentType",
                        Stream               = stream,
                        Hash                 = "someHash",
                    };

                    //Serialize
                    var jsonSerializer = GetJsonSerializer();
                    BlittableJsonReaderObject blitCommand;
                    using (var writer = new BlittableJsonWriter(context))
                    {
                        var dto = expected.ToDto(context);
                        jsonSerializer.Serialize(writer, dto);
                        writer.FinalizeDocument();

                        blitCommand = writer.CreateReader();
                    }

                    var fromStream = await SerializeTestHelper.SimulateSavingToFileAndLoadingAsync(context, blitCommand);

                    //Deserialize
                    AttachmentHandler.MergedPutAttachmentCommand actual;
                    using (var reader = new BlittableJsonReader(context))
                    {
                        reader.Initialize(fromStream);

                        var dto = jsonSerializer.Deserialize <MergedPutAttachmentCommandDto>(reader);
                        actual = dto.ToCommand(null, null);
                    }

                    //Assert
                    Assert.Equal(expected, actual,
                                 new CustomComparer <AttachmentHandler.MergedPutAttachmentCommand>(context, new[] { typeof(Stream) }));

                    stream.Seek(0, SeekOrigin.Begin);
                    var expectedStream = expected.Stream.ReadData();
                    var actualStream   = actual.Stream.ReadData();
                    Assert.Equal(expectedStream, actualStream);
                }
        }
示例#9
0
        public async Task ImportSql()
        {
            using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
            {
                using (var sqlImportDoc = await context.ReadForMemoryAsync(RequestBodyStream(), "sql-migration-request"))
                {
                    MigrationRequest migrationRequest;

                    // we can't use JsonDeserializationServer here as it doesn't support recursive processing
                    var serializer = DocumentConventions.DefaultForServer.Serialization.CreateDeserializer();
                    using (var blittableJsonReader = new BlittableJsonReader())
                    {
                        blittableJsonReader.Initialize(sqlImportDoc);
                        migrationRequest = serializer.Deserialize <MigrationRequest>(blittableJsonReader);
                    }

                    var operationId = Database.Operations.GetNextOperationId();

                    var sourceSqlDatabase = migrationRequest.Source;

                    var dbDriver = DatabaseDriverDispatcher.CreateDriver(sourceSqlDatabase.Provider, sourceSqlDatabase.ConnectionString);
                    var schema   = dbDriver.FindSchema();
                    var token    = CreateOperationToken();

                    var result = new MigrationResult(migrationRequest.Settings);

                    var collectionsCount     = migrationRequest.Settings.Collections.Count;
                    var operationDescription = "Importing " + collectionsCount + " " + (collectionsCount == 1 ? "collection" : "collections") + " from SQL database: " + schema.CatalogName;

                    _ = Database.Operations.AddOperation(Database, operationDescription, Documents.Operations.Operations.OperationType.MigrationFromSql, onProgress =>
                    {
                        return(Task.Run(async() =>
                        {
                            try
                            {
                                // allocate new context as we executed this async
                                using (ContextPool.AllocateOperationContext(out DocumentsOperationContext migrationContext))
                                {
                                    await dbDriver.Migrate(migrationRequest.Settings, schema, Database, migrationContext, result, onProgress, token.Token);
                                }
                            }
                            catch (Exception e)
                            {
                                result.AddError($"Error occurred during import. Exception: {e.Message}");
                                onProgress.Invoke(result.Progress);
                                throw;
                            }

                            return (IOperationResult)result;
                        }));
                    }, operationId, token: token);
示例#10
0
        public async Task SerializeAndDeserialize_MergedInsertBulkCommandTest()
        {
            using (var database = CreateDocumentDatabase())
                using (database.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
                {
                    //Arrange
                    var data     = new { ParentProperty = new { NestedProperty = "Some Value" } };
                    var commands = new[]
                    {
                        new BatchRequestParser.CommandData
                        {
                            Type         = CommandType.PUT,
                            Id           = "Some Id",
                            ChangeVector = context.GetLazyString("Some Lazy String"),
                            Document     = DocumentConventions.Default.Serialization.DefaultConverter.ToBlittable(data, context),
                            Patch        = new PatchRequest("Some Script", PatchRequestType.None)
                        }
                    };
                    var expected = new BulkInsertHandler.MergedInsertBulkCommand
                    {
                        NumberOfCommands = commands.Length,
                        Commands         = commands
                    };

                    //Action
                    var jsonSerializer = GetJsonSerializer();
                    BlittableJsonReaderObject blitCommand;
                    using (var writer = new BlittableJsonWriter(context))
                    {
                        var dto = expected.ToDto(context);
                        jsonSerializer.Serialize(writer, dto);
                        writer.FinalizeDocument();

                        blitCommand = writer.CreateReader();
                    }
                    var fromStream = await SerializeTestHelper.SimulateSavingToFileAndLoadingAsync(context, blitCommand);

                    BulkInsertHandler.MergedInsertBulkCommand actual;
                    using (var reader = new BlittableJsonReader(context))
                    {
                        reader.Initialize(fromStream);

                        var dto = jsonSerializer.Deserialize <MergedInsertBulkCommandDto>(reader);
                        actual = dto.ToCommand(context, database);
                    }

                    //Assert
                    Assert.Equal(expected, actual, new CustomComparer <BulkInsertHandler.MergedInsertBulkCommand>(context));
                }
        }
示例#11
0
        public async Task SerializeAndDeserialize_MergedBatchPutCommandTest()
        {
            using (var database = CreateDocumentDatabase())
                using (database.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
                {
                    //Arrange
                    var data     = new { ParentProperty = new { NestedProperty = "Some Value" } };
                    var expected = new DatabaseDestination.MergedBatchPutCommand(database, BuildVersionType.V4, null);
                    var document = new DocumentItem
                    {
                        Document = new Document
                        {
                            ChangeVector = "Some Change Vector",
                            Data         = DocumentConventions.Default.Serialization.DefaultConverter.ToBlittable(data, context),
                            Id           = context.GetLazyString("Some Id")
                        }
                    };
                    expected.Add(document);

                    //Action
                    var jsonSerializer = GetJsonSerializer();
                    BlittableJsonReaderObject blitCommand;
                    using (var writer = new BlittableJsonWriter(context))
                    {
                        var dto = expected.ToDto(context);
                        jsonSerializer.Serialize(writer, dto);
                        writer.FinalizeDocument();

                        blitCommand = writer.CreateReader();
                    }
                    var fromStream = await SerializeTestHelper.SimulateSavingToFileAndLoadingAsync(context, blitCommand);

                    DatabaseDestination.MergedBatchPutCommand actual;
                    using (var reader = new BlittableJsonReader(context))
                    {
                        reader.Initialize(fromStream);

                        var dto = jsonSerializer.Deserialize <DatabaseDestination.MergedBatchPutCommandDto>(reader);
                        actual = dto.ToCommand(context, database);
                    }

                    //Assert
                    var expectedDoc = expected.Documents[0].Document;
                    var actualDoc   = actual.Documents[0].Document;

                    Assert.Equal(expectedDoc.Id, actualDoc.Id);
                    Assert.Equal(expectedDoc.ChangeVector, actualDoc.ChangeVector);
                    Assert.Equal(expectedDoc.Data, actualDoc.Data);
                }
        }
示例#12
0
        public async Task SerializeAndDeserialize_PatchDocumentCommandTest()
        {
            using (var database = CreateDocumentDatabase())
                using (database.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
                {
                    //Arrange
                    var data         = new { ParentProperty = new { NestedProperty = "Some Value" } };
                    var arg          = DocumentConventions.Default.Serialization.DefaultConverter.ToBlittable(data, context);
                    var patchRequest = new PatchRequest("", PatchRequestType.None);

                    var expected = new PatchDocumentCommand(
                        context,
                        "Some Id",
                        context.GetLazyString("Some Lazy String"),
                        false,
                        (patchRequest, arg),
                        (null, null),
                        null,
                        database,
                        false, false, false, false);

                    //Action
                    var jsonSerializer = GetJsonSerializer();
                    BlittableJsonReaderObject blitCommand;
                    using (var writer = new BlittableJsonWriter(context))
                    {
                        var dto = expected.ToDto(context);
                        jsonSerializer.Serialize(writer, dto);
                        writer.FinalizeDocument();

                        blitCommand = writer.CreateReader();
                    }
                    var fromStream = await SerializeTestHelper.SimulateSavingToFileAndLoadingAsync(context, blitCommand);

                    PatchDocumentCommand actual;
                    using (var reader = new BlittableJsonReader(context))
                    {
                        reader.Initialize(fromStream);

                        var dto = jsonSerializer.Deserialize <PatchDocumentCommandDto>(reader);
                        actual = dto.ToCommand(context, database);
                    }

                    //Assert
                    Assert.Equal(expected, actual, new CustomComparer <PatchDocumentCommand>(context));
                }
        }
示例#13
0
        public async Task SerializeAndDeserialize_PutResolvedConflictsCommand()
        {
            using (Server.ServerStore.ContextPool.AllocateOperationContext(out JsonOperationContext context))
                using (var database = CreateDocumentDatabase())
                {
                    //Arrange
                    var resolvedConflicts = new List <(DocumentConflict, long, bool)>
                    {
                        (new DocumentConflict
                        {
                            Id = context.GetLazyString("Some id"),
                            LowerId = context.GetLazyString("Some lower id"),
                            Collection = context.GetLazyString("Some collection"),
                            Doc = DocumentConventions.Default.Serialization.DefaultConverter.ToBlittable(new { SomeName = "Some Value" }, context)
                        }, 10, false)
                    };

                    var expected = new ResolveConflictOnReplicationConfigurationChange.PutResolvedConflictsCommand(
                        null, resolvedConflicts, null);
                    var expectedDto = expected.ToDto(context);

                    //Serialize
                    var jsonSerializer = GetJsonSerializer();
                    BlittableJsonReaderObject blitCommand;
                    using (var writer = new BlittableJsonWriter(context))
                    {
                        jsonSerializer.Serialize(writer, expectedDto);
                        writer.FinalizeDocument();

                        blitCommand = writer.CreateReader();
                    }

                    var fromStream = await SerializeTestHelper.SimulateSavingToFileAndLoadingAsync(context, blitCommand);

                    //Deserialize
                    using (var reader = new BlittableJsonReader(context))
                    {
                        reader.Initialize(fromStream);

                        var actualDto = jsonSerializer.Deserialize <PutResolvedConflictsCommandDto>(reader);

                        //Assert
                        //                    Assert.Equal(expectedDto.)
                    }
                }
        }
示例#14
0
        public async Task SerializeAndDeserialize_MergedDeleteAttachmentCommand()
        {
            using (Server.ServerStore.ContextPool.AllocateOperationContext(out JsonOperationContext context))
            {
                //Arrange
                var changeVector = context.GetLazyString("Some Lazy String");
                var expected     = new AttachmentHandler.MergedDeleteAttachmentCommand
                {
                    DocumentId           = "someId",
                    Name                 = "someName",
                    ExpectedChangeVector = changeVector
                };

                //Serialize
                var jsonSerializer = GetJsonSerializer();
                BlittableJsonReaderObject blitCommand;
                using (var writer = new BlittableJsonWriter(context))
                {
                    var dto = expected.ToDto(context);
                    jsonSerializer.Serialize(writer, dto);
                    writer.FinalizeDocument();

                    blitCommand = writer.CreateReader();
                }

                var fromStream = await SerializeTestHelper.SimulateSavingToFileAndLoadingAsync(context, blitCommand);

                //Deserialize
                AttachmentHandler.MergedDeleteAttachmentCommand actual;
                using (var reader = new BlittableJsonReader(context))
                {
                    reader.Initialize(fromStream);

                    var dto = jsonSerializer.Deserialize <MergedDeleteAttachmentCommandDto>(reader);
                    actual = dto.ToCommand(null, null);
                }

                //Assert
                Assert.Equal(expected, actual, new CustomComparer <AttachmentHandler.MergedDeleteAttachmentCommand>(context));
            }
        }
        private static TransactionOperationsMerger.MergedTransactionCommand DeserializeCommand(
            DocumentsOperationContext context,
            DocumentDatabase database,
            string type,
            BlittableJsonReaderObject wrapCmdReader,
            PeepingTomStream peepingTomStream)
        {
            if (!wrapCmdReader.TryGet(nameof(RecordingCommandDetails.Command), out BlittableJsonReaderObject commandReader))
            {
                throw new ReplayTransactionsException($"Can't read {type} for replay", peepingTomStream);
            }

            var jsonSerializer = GetJsonSerializer();

            using (var reader = new BlittableJsonReader(context))
            {
                reader.Initialize(commandReader);
                var dto = DeserializeCommandDto(type, jsonSerializer, reader, peepingTomStream);
                return(dto.ToCommand(context, database));
            }
        }
示例#16
0
        public void JsonDeserialize_WhenHasBlittableObjectPropertyAndWriteAndReadFromStream_ShouldResultInCommandWithTheProperty()
        {
            using (Server.ServerStore.ContextPool.AllocateOperationContext(out JsonOperationContext context))
            {
                var jsonSerializer = new JsonSerializer
                {
                    ContractResolver = new DefaultRavenContractResolver(DocumentConventions.Default.Serialization),
                };
                jsonSerializer.Converters.Add(BlittableJsonConverter.Instance);

                var data     = new { SomeProperty = "SomeValue" };
                var expected = DocumentConventions.Default.Serialization.DefaultConverter.ToBlittable(data, context);
                var command  = new Command {
                    BlittableObject = expected
                };

                //Serialize
                BlittableJsonReaderObject toStream;
                using (var writer = new BlittableJsonWriter(context))
                {
                    jsonSerializer.Serialize(writer, command);
                    writer.FinalizeDocument();

                    toStream = writer.CreateReader();
                }

                //Simulates copying to file and loading
                BlittableJsonReaderObject fromStream;
                using (Stream stream = new MemoryStream())
                {
                    //Pass to stream
                    using (var textWriter = new BlittableJsonTextWriter(context, stream))
                    {
                        context.Write(textWriter, toStream);
                    }

                    //Get from stream
                    stream.Position = 0;

                    var state            = new JsonParserState();
                    var parser           = new UnmanagedJsonParser(context, state, "some tag");
                    var peepingTomStream = new PeepingTomStream(stream, context);

                    using (context.GetMemoryBuffer(out var buffer))
                        using (var builder =
                                   new BlittableJsonDocumentBuilder(context, BlittableJsonDocumentBuilder.UsageMode.None, "some tag", parser, state))
                        {
                            UnmanagedJsonParserHelper.Read(peepingTomStream, parser, state, buffer);
                            UnmanagedJsonParserHelper.ReadObject(builder, peepingTomStream, parser, buffer);

                            fromStream = builder.CreateReader();
                        }
                }

                //Deserialize
                BlittableJsonReaderObject actual;
                using (var reader = new BlittableJsonReader(context))
                {
                    reader.Initialize(fromStream);
                    var deserialized = jsonSerializer.Deserialize <Command>(reader);
                    actual = deserialized.BlittableObject;
                }

                Assert.Equal(expected, actual);
            }
        }
示例#17
0
        public void Physical_store_test()
        {
            List <Car> cars;

            using (var documentStore = GetDocumentStore())
            {
                documentStore.Initialize();

                new CarIndex().Execute(documentStore);

                using (var session = documentStore.OpenSession())
                {
                    foreach (CarLot doc in Docs)
                    {
                        session.Store(doc);
                    }
                    session.SaveChanges();
                }

                string targetLeasee = CarLeasees[0].Id;

                using (var session = documentStore.OpenSession())
                {
                    //Synchronize indexes
                    session.Query <CarLot, CarIndex>().Customize(x => x.WaitForNonStaleResults(TimeSpan.FromMinutes(2))).FirstOrDefault();

                    var query = session.Query <CarLot, CarIndex>()
                                .Where(carLot => carLot.Cars.Any(car => car.LeaseHistory.Any(leasee => leasee.Id == targetLeasee)))
                                .Take(1024);

                    var deserializer = session.Advanced.DocumentStore.Conventions.Serialization.CreateSerializer();
                    var indexQuery   = RavenTestHelper.GetIndexQuery(query);

                    using (var commands = documentStore.Commands())
                    {
                        var queryResult = commands.Query(indexQuery);

                        var carLots = queryResult
                                      .Results
                                      .Select(x =>
                        {
                            using (var reader = new BlittableJsonReader())
                            {
                                reader.Initialize((BlittableJsonReaderObject)x);
                                return(deserializer.Deserialize <CarLot>(reader));
                            }
                        })
                                      .ToArray();

                        foreach (var carLot in carLots)
                        {
                            Assert.NotNull(carLot.Cars);
                            Assert.NotEmpty(carLot.Cars);
                        }

                        cars = carLots
                               .SelectMany(x => x.Cars)
                               .Where(car => car.LeaseHistory.Any(leasee => leasee.Id == targetLeasee))
                               .ToList();
                    }
                }
            }

            Assert.NotNull(cars);
            Assert.NotEmpty(cars);

            foreach (Car car in cars)
            {
                Assert.NotNull(car.LeaseHistory);
                Assert.NotEmpty(car.LeaseHistory);
            }
        }