Example #1
0
        public void query_for_object_with_byte_array_with_default_TypeNameHandling()
        {
            using (var store = NewRemoteDocumentStore())
            {

                var json = GetResourceText("DocumentWithBytes.txt");
                var jsonSerializer = new DocumentConvention().CreateSerializer();
                var item = jsonSerializer.Deserialize<DesignResources>(new JsonTextReader(new StringReader(json)));

                using (var session = store.OpenSession())
                {
                    item.Id = "resources/123";
                    item.DesignId = "designs/123";
                    session.Store(item);
                    session.SaveChanges();
                }

                using (var session = store.OpenSession())
                {
                    session
                        .Query<DesignResources>()
                        .Customize(x => x.WaitForNonStaleResultsAsOfNow())
                        .Where(x => x.DesignId == "designs/123")
                        .ToList();
                }
            }
        }
		public void CanSerializeToJsonCorrectly()
		{
			var serializer = new DocumentConvention().CreateSerializer();
			var stringWriter = new StringWriter();
			serializer.Serialize(stringWriter, new Company("Hibernating Rhinos", "Middle East"));
			var deserializeObject = serializer.Deserialize<Company>(new JsonTextReader(new StringReader(stringWriter.GetStringBuilder().ToString())));
			Assert.Equal("Hibernating Rhinos", deserializeObject.Name);
			Assert.Equal("Middle East", deserializeObject.Region);
		}
        public void Can_read_date_time_offset_from_lucene_query()
        {
            var jsonSerializer = new DocumentConvention().CreateSerializer();

            using (var reader = new JsonTextReader(new StringReader(@"{""Item"": ""20090402193554412""}")))
            {
                var deserialize = jsonSerializer.Deserialize<Test>(reader);
                Assert.Equal(2009, deserialize.Item.Year);
            }
        }
Example #4
0
		public void CanBeDeSerializedProperly()
		{
			var jsonSerializer = new DocumentConvention().CreateSerializer();
			var stringWriter = new StringWriter();

			var item = new WithDic
			{
				Items = new Dictionary<DateTime, int>
				{
					{new DateTime(2011, 11, 24), 1}
				}
			};

			jsonSerializer.Serialize(stringWriter, item);

			var s = stringWriter.GetStringBuilder().ToString();
			var withDic = jsonSerializer.Deserialize<WithDic>(new JsonTextReader(new StringReader(s)));

			Assert.Equal(1, withDic.Items[new DateTime(2011, 11, 24)]);
		}
Example #5
0
		public void query_for_object_with_byte_array_with_TypeNameHandling_All()
		{
			using (var server = GetNewServer())
			using (var store = new DocumentStore { Url = "http://localhost:8079" })
			{
				store.Conventions = new DocumentConvention
				{
					CustomizeJsonSerializer = serializer =>
					{
						serializer.TypeNameHandling = TypeNameHandling.All;
					},
				};
				store.Initialize();

				var json = GetResourceText("DocumentWithBytes.txt");
				var jsonSerializer = new DocumentConvention().CreateSerializer();
				var item = jsonSerializer.Deserialize<DesignResources>(new JsonTextReader(new StringReader(json)));

				using (var session = store.OpenSession())
				{
					item.Id = "resources/123";
					item.DesignId = "designs/123";
					session.Store(item);
					session.SaveChanges();
				}

				using (var session = store.OpenSession())
				{
					session
						.Query<DesignResources>()
						.Customize(x => x.WaitForNonStaleResultsAsOfNow())
						.Where(x => x.DesignId == "designs/123")
						.ToList();
				}
			}
		}
Example #6
0
        public void load_object_with_byte_array_with_TypeNameHandling_All()
        {
            using (var store = NewRemoteDocumentStore(configureStore: documentStore =>
            {
                documentStore.Conventions = new DocumentConvention
                {
                    CustomizeJsonSerializer = serializer =>
                    {
                        serializer.TypeNameHandling = TypeNameHandling.All;
                    },
                };				
            }))
            {
                var json = GetResourceText("DocumentWithBytes.txt");
                var jsonSerializer = new DocumentConvention().CreateSerializer();
                var item = jsonSerializer.Deserialize<DesignResources>(new JsonTextReader(new StringReader(json)));

                using (var session = store.OpenSession())
                {
                    item.Id = "resources/123";
                    item.DesignId = "designs/123";
                    session.Store(item);
                    session.SaveChanges();
                }

                using (var session = store.OpenSession())
                    session.Load<DesignResources>("resources/123");
            }
        }
Example #7
0
 public void FromText()
 {
     var json = GetResourceText("DocumentWithBytes.txt");
     var jsonSerializer = new DocumentConvention().CreateSerializer();
     var item = jsonSerializer.Deserialize<DesignResources>(new JsonTextReader(new StringReader(json)));
 }
Example #8
0
        public void load_object_with_byte_array_with_default_TypeNameHandling()
        {
            using (var store = NewRemoteDocumentStore())
            {
                var json = GetResourceText("DocumentWithBytes.txt");
                var jsonSerializer = new DocumentConvention().CreateSerializer();
                var item = jsonSerializer.Deserialize<DesignResources>(new JsonTextReader(new StringReader(json)));

                using (var session = store.OpenSession())
                {
                    item.Id = "resources/123";
                    item.DesignId = "designs/123";
                    session.Store(item);
                    session.SaveChanges();
                }

                using (var session = store.OpenSession())
                {
                    session.Load<DesignResources>("resources/123");
                }
            }
        }