Exemple #1
0
        public void Can_Store_and_Load_Dynamic_Documents()
        {                                          
            //When running in the XUnit GUI strange things happen is we just create a path relative to 
            //the .exe itself, so make our folder in the System temp folder instead ("<user>\AppData\Local\Temp")
            string directoryName =  Path.Combine(Path.GetTempPath(), "ravendb.RavenDynamicDocs");
            IOExtensions.DeleteDirectory(directoryName);
            dynamic person = new CustomDynamicClass();
            person.FirstName = "Ellen";
            person.LastName = "Adams";

            dynamic employee = new ExpandoObject();
            employee.Name = "John Smith";
            employee.Age = 33;
            employee.Phones = new ExpandoObject();
            employee.Phones.Home = "0111 123123";
            employee.Phones.Office = "0772 321123";
            employee.Prices = new List<decimal>() { 123.4M, 123432.54M };

            using (var db = new EmbeddablDocumentStore() { DataDirectory = directoryName })
            {
                db.Initialize();
                
                using (var session = db.OpenSession())
                {
                    session.Store(employee);
                    string idEmployee = employee.Id;
                                        
                    session.Store(person);
                    string idPerson = person.Id;

                    //Check that a field called "Id" is added to the dynamic object (as it doesn't already exist)
                    //and that it has something in it (not null and not empty)
                    Assert.False(String.IsNullOrEmpty(idEmployee));
                    Assert.False(String.IsNullOrEmpty(idPerson));

                    session.SaveChanges();
                    session.Advanced.Clear();
                    //Pull the docs back out of RavenDB and see if the values are the same
                    dynamic employeeLoad = session.Load<dynamic>(idEmployee);
					Assert.Equal("John Smith", employeeLoad.Name);
					Assert.Equal("0111 123123", employeeLoad.Phones.Home);
					Assert.Equal("0772 321123", employeeLoad.Phones.Office);
					Assert.Contains(123.4D, employeeLoad.Prices);
					Assert.Contains(123432.54D, employeeLoad.Prices);
					Assert.Null(employeeLoad.Address);

                    dynamic personLoad = session.Load<dynamic>(idPerson);
					Assert.Equal("Ellen", personLoad.FirstName);
					Assert.Equal("Adams", personLoad.LastName);
					Assert.Null(personLoad.Age);

                }
            }
        }
Exemple #2
0
        protected EmbeddablDocumentStore NewDocumentStore()
		{
			path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(DocumentStoreServerTests)).CodeBase);
			path = Path.Combine(path, "TestDb").Substring(6);

            IOExtensions.DeleteDirectory(path);

            var documentStore = new EmbeddablDocumentStore()
			{
				Configuration = new RavenConfiguration
				{
					DataDirectory = path,
					RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true
				}

			};
			documentStore.Initialize();
			return documentStore;
		}
		public void WillNotSerializeEvents()
		{
            IOExtensions.DeleteDirectory("Data");
            try
			{
                using (var documentStore = new EmbeddablDocumentStore())
				{
					documentStore.Configuration.DataDirectory = "Data";
					documentStore.Conventions.CustomizeJsonSerializer = x => x.TypeNameHandling = TypeNameHandling.Auto;
					documentStore.Initialize();

					var bar = new Bar();
					var foo = new Foo();
					foo.PropertyChanged += bar.FooChanged;

					using (var session = documentStore.OpenSession())
					{
						session.Store(foo);
						session.SaveChanges();
					}
				}
			}
			finally
			{
                IOExtensions.DeleteDirectory("Data");
			}
		}