public void TestUseDerivedInstanceInBaseClassCollectionProperty()
        {
            var storeName = MakeStoreName("useDerivedInstance");
            var context = new MyEntityContext(ConnectionString + storeName);
            var entity1 = context.DerivedEntities.Create();
            entity1.BaseStringValue = "Entity1";
            var entity2 = context.DerivedEntities.Create();
            entity2.BaseStringValue = "Entity2";
            var entity3 = context.BaseEntities.Create();
            entity3.BaseStringValue = "Entity3";
            entity1.RelatedEntities.Add(entity2);
            entity1.RelatedEntities.Add(entity3);
            context.SaveChanges();

            context=new MyEntityContext(ConnectionString + storeName);
            var baseEntities = context.BaseEntities.ToList();
            Assert.AreEqual(3, baseEntities.Count);
            var derivedEntities = context.DerivedEntities.ToList();
            Assert.AreEqual(2, derivedEntities.Count);
            entity1 = context.DerivedEntities.Where(x => x.BaseStringValue.Equals("Entity1")).FirstOrDefault();
            Assert.IsNotNull(entity1);
            Assert.AreEqual(2, entity1.RelatedEntities.Count);
            Assert.IsTrue(entity1.RelatedEntities.Any(x=>x.BaseStringValue.Equals("Entity2")));
            Assert.IsTrue(entity1.RelatedEntities.Any(x=>x.BaseStringValue.Equals("Entity3")));

        }
Exemplo n.º 2
0
        public void TestIssue128CannotSetFloatValueBelow1()
        {
            // Create an entity
            var entity = _myEntityContext.TestEntities.Create();
            // Set the properties that allow fractional values to values < 1.0
            entity.SomeDecimal = 0.14m;
            entity.SomeDouble = 0.14;
            entity.SomeFloat = 0.14F;
            // Persist the changes
            _myEntityContext.SaveChanges();
            var entityId = entity.Id;

            // Create a new context connection so that we don't get a locally cached value from the context
            var newContext = new MyEntityContext(_connectionString);
            // Retrieve the previously created entity
            var checkEntity = newContext.TestEntities.FirstOrDefault(e => e.Id.Equals(entityId));

            // Assert that the entity was found and the values we set are set to the values we originally provided
            Assert.IsNotNull(checkEntity);
            Assert.IsNotNull(checkEntity.SomeDecimal);
            Assert.IsNotNull(checkEntity.SomeDouble);
            Assert.IsNotNull(checkEntity.SomeFloat);
            Assert.AreEqual(0.14m, checkEntity.SomeDecimal);
            Assert.AreEqual(0.14, checkEntity.SomeDouble);
            Assert.AreEqual(0.14F, checkEntity.SomeFloat);
        }
        public QueryableCollectionsTests()
        {
            var connectionString = ConnectionString + "StoreName=SimpleCollectionFilter_" + DateTime.UtcNow.Ticks;
            _context = new MyEntityContext(connectionString);
            var gardening = _context.Skills.Create();
            gardening.Name = "Gardening";
            var painting = _context.Skills.Create();
            painting.Name = "Painting";
            var carpentry = _context.Skills.Create();
            carpentry.Name = "Carpentry";

            _dept = _context.Departments.Create();
            _dept.Name = "Department99";
            var andy = _context.Persons.Create();
            andy.Name = "Andy";
            andy.Skills.Add(gardening);
            andy.Skills.Add(painting);
            andy.Skills.Add(carpentry);

            var arnold = _context.Persons.Create();
            arnold.Name = "Arnold";
            arnold.Skills.Add(painting);

            var bert = _context.Persons.Create();
            bert.Name = "Bert";
            _dept.Persons.Add(andy);
            _dept.Persons.Add(bert);
            _context.SaveChanges();
        }
 public void TestSavingChangesUpdatesTimestamp()
 {
     IArticle article;
     DateTime saving, updating;
     using (var context = new MyEntityContext(_connectionString))
     {
         context.SavingChanges += UpdateTrackable;
         article = context.Articles.Create();
         article.Title = "My Test Article";
         saving = DateTime.Now;
         context.SaveChanges();
     }
     using (var context = new MyEntityContext(_connectionString))
     {
         context.SavingChanges += UpdateTrackable;
         article = context.Articles.FirstOrDefault(a => a.Id.Equals(article.Id));
         Assert.IsNotNull(article);
         Assert.IsTrue(article.Created >= saving);
         Assert.IsTrue(article.LastModified >= saving);
         article.BodyText = "Some body text";
         updating = DateTime.Now;
         context.SaveChanges();
     }
     using (var context = new MyEntityContext(_connectionString))
     {
         article = context.Articles.FirstOrDefault(a => a.Id.Equals(article.Id));
         Assert.IsNotNull(article);
         Assert.IsTrue(article.Created >= saving);
         Assert.IsTrue(article.LastModified >= updating);
     }
 }
Exemplo n.º 5
0
        public void TestSetAndGetSimpleProperty()
        {
            string storeName = Guid.NewGuid().ToString();
            var dataObjectStore = _dataObjectContext.CreateStore(storeName);
            var context = new MyEntityContext(dataObjectStore);
            var person = context.Persons.Create();
            Assert.IsNotNull(person);
            person.Name = "Kal";
            context.SaveChanges();
            var personId = person.Id;

            // Test that the property is still there when we retrieve the object again
            dataObjectStore = _dataObjectContext.OpenStore(storeName);
            context = new MyEntityContext(dataObjectStore);
            person = context.Persons.Where(p => p.Id == personId).FirstOrDefault();
            Assert.IsNotNull(person);
            Assert.IsNotNull(person.Name, "person.Name was NULL when retrieved back from server");
            Assert.AreEqual("Kal", person.Name, "Unexpected Name property value");

            // Test we can also use the simple property in a LINQ query
            dataObjectStore = _dataObjectContext.OpenStore(storeName);
            context = new MyEntityContext(dataObjectStore);
            person = context.Persons.Where(p => p.Name == "Kal").FirstOrDefault();
            Assert.IsNotNull(person, "Could not find person by Name");
            Assert.AreEqual(personId, person.Id, "Query for person by name returned an unexpected person entity");

            // Test we can use ToList()
            var people = context.Persons.Where(p => p.Name == "Kal").ToList();
            Assert.IsNotNull(people);
            Assert.AreEqual(1, people.Count);
            Assert.AreEqual(personId, people[0].Id);
        }
Exemplo n.º 6
0
        public void TestAddToInverse()
        {
            string productionId, performanceId;
            using (var context = new MyEntityContext(_connectionString))
            {
                var production = context.Productions.Create();
                var performance = context.Performances.Create();
                Assert.That(production.Performances.Count, Is.EqualTo(0));
                Assert.That(production.Photos.Count, Is.EqualTo(0));
                Assert.That(production.ProductionTeam.Count, Is.EqualTo(0));

                // Add the performance to the production's perfomances collection
                production.Performances.Add(performance);

                Assert.That(production.Performances.Count, Is.EqualTo(1));
                Assert.That(production.Photos.Count, Is.EqualTo(0));
                Assert.That(production.ProductionTeam.Count, Is.EqualTo(0));
                context.SaveChanges();
                productionId = production.Id;
                performanceId = performance.Id;
            }

            using (var context = new MyEntityContext(_connectionString))
            {
                var production = context.Productions.FirstOrDefault(x => x.Id.Equals(productionId));
                Assert.That(production, Is.Not.Null);
                Assert.That(production.Performances.Count, Is.EqualTo(1));
                Assert.That(production.Performances.First().Id, Is.EqualTo(performanceId));
                Assert.That(production.Photos.Count, Is.EqualTo(0));
                Assert.That(production.ProductionTeam.Count, Is.EqualTo(0));
            }
        }
Exemplo n.º 7
0
        public void TestInsertIntoDefaultGraph()
        {
            var storeName = "http://www.brightstardb.com/tests#empty";
            var connectionString = MakeStoreConnectionString(storeName);
            var dataObjectContext = BrightstarService.GetDataObjectContext(connectionString);

            string aliceId;
            using (var store = dataObjectContext.OpenStore(storeName))
            {
                using (var context = new MyEntityContext(store))
                {
                    var alice = context.FoafPersons.Create();
                    aliceId = alice.Id;
                    context.SaveChanges();
                }
            }
            using (var store = dataObjectContext.OpenStore(storeName))
            {
                using (var context = new MyEntityContext(store))
                {
                    var alice = context.FoafPersons.FirstOrDefault(p => p.Id.Equals(aliceId));
                    Assert.That(alice, Is.Not.Null);
                }
            }
        }
Exemplo n.º 8
0
 public void TestCreatePlainLiteral()
 {
     var storeName = "PlainLiteralTests_CreatePlainLiteral" + DateTime.Now.Ticks;
     using (var dataObjectStore = _dataObjectContext.CreateStore(storeName))
     {
         string conceptAId;
         using (var context = new MyEntityContext(dataObjectStore))
         {
             var conceptA = context.Concepts.Create();
             conceptA.PrefLabel = new []
                 {
                     new PlainLiteral("Default value"),
                     new PlainLiteral("English value", "en"), 
                     new PlainLiteral("US English value", "en-US"), 
                 };
             context.SaveChanges();
             conceptAId = conceptA.Id;
         }
         using (var context = new MyEntityContext(dataObjectStore))
         {
             var conceptA = context.Concepts.FirstOrDefault(c => c.Id.Equals(conceptAId));
             Assert.IsNotNull(conceptA);
             Assert.That(conceptA.PrefLabel.Count, Is.EqualTo(3));
             Assert.That(conceptA.PrefLabel.Any(l=>l.Value.Equals("Default value") && l.Language.Equals(String.Empty)));
             Assert.That(conceptA.PrefLabel.Any(l=>l.Value.Equals("English value") && l.Language.Equals("en")));
             Assert.That(conceptA.PrefLabel.Any(l=>l.Value.Equals("US English value") && l.Language.Equals("en-us")));
         }
     }
 }
Exemplo n.º 9
0
        public void TestMapToRdfDataTypeDate()
        {
            var storeName = "foaf_" + Guid.NewGuid().ToString();
            var embeddedClient =
                BrightstarService.GetClient("type=embedded;storesDirectory=c:\\brightstar;");
            embeddedClient.CreateStore(storeName);

            //add rdf data for a person
            var triples = new StringBuilder();
            triples.AppendLine(@"<http://www.networkedplanet.com/people/j.williams> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .");
            triples.AppendLine(@"<http://www.networkedplanet.com/people/j.williams> <http://xmlns.com/foaf/0.1/name> ""Jen Williams"" .");
            triples.AppendLine(@"<http://www.networkedplanet.com/people/j.williams> <http://dbpedia.org/ontology/birthDate> ""1921-11-28""^^<http://www.w3.org/2001/XMLSchema#date> .");
            

            embeddedClient.ExecuteTransaction(storeName, null, null, triples.ToString());

            //check EF can access all properties
            var context = new MyEntityContext(string.Format(@"type=embedded;storesDirectory=c:\\brightstar;storeName={0}", storeName));

            Assert.IsNotNull(context.FoafPersons);
            Assert.AreEqual(1, context.FoafPersons.Count());
            var person = context.FoafPersons.FirstOrDefault();
            Assert.IsNotNull(person);

            Assert.IsNotNull(person.Id);
            Assert.AreEqual("j.williams", person.Id);
            Assert.IsNotNull(person.Name);
            Assert.AreEqual("Jen Williams", person.Name);
            Assert.IsNotNull(person.BirthDate);
        }
Exemplo n.º 10
0
        public void TestSavingCallbackCalled()
        {
            var context = new MyEntityContext(_connectionString);
            _changedItems.Clear();
            context.SavingChanges += LogChangedItems;

            var alice = new Person {Name = "Alice"};
            context.Persons.Add(alice);
            var bob = context.Persons.Create();
            bob.Name = "Bob";
            context.SaveChanges();

            Assert.AreEqual(2, _changedItems.Count);
            Assert.IsTrue(_changedItems.Cast<Person>().Any(p=>p.Id.Equals(alice.Id)));
            Assert.IsTrue(_changedItems.Cast<Person>().Any(p=>p.Id.Equals(bob.Id)));
            _changedItems.Clear();

            bob.Friends.Add(alice);
            context.SaveChanges();
            Assert.AreEqual(1, _changedItems.Count);
            Assert.IsTrue(_changedItems.Cast<Person>().Any(p => p.Id.Equals(bob.Id)));
            _changedItems.Clear();

            var skill = new Skill {Name = "Programming"};
            context.Skills.Add(skill);
            context.SaveChanges();
            _changedItems.Clear();

            skill.SkilledPeople.Add(bob);
            context.SaveChanges();
            Assert.AreEqual(1, _changedItems.Count);
            Assert.IsTrue(_changedItems.Cast<Person>().Any(p => p.Id.Equals(bob.Id)));
            _changedItems.Clear();

        }
Exemplo n.º 11
0
        public void TestLinqCount()
        {
            var connectionString = _connectionString + "StoreName=" + Guid.NewGuid();
            var context = new MyEntityContext(connectionString);
            for(var i = 0; i<100; i++)
            {
                var entity = context.Entities.Create();
                entity.SomeString = "Entity " + i;
                entity.SomeInt = i;
            }
            context.SaveChanges();

            var context2 = new MyEntityContext(connectionString);
            var count = context2.Entities.Count();

            Assert.IsNotNull(count);
            Assert.AreEqual(100, count);

            for (var j = 0; j < 100; j++)
            {
                var entity = context2.Entities.Create();
                entity.SomeString = "Entity " + j;
                entity.SomeInt = j;
            }
            context2.SaveChanges();

            var context3 = new MyEntityContext(connectionString);
            var count2 = context3.Entities.Count();

            Assert.IsNotNull(count2);
            Assert.AreEqual(200, count2);
        }
Exemplo n.º 12
0
        public void TestCreateAndRetrieve()
        {
            string storeName = Guid.NewGuid().ToString();
            string personId;
            using (var dataObjectStore = _dataObjectContext.CreateStore(storeName))
            {
                using (var context = new MyEntityContext(dataObjectStore))
                {
                    var person = context.Persons.Create();
                    Assert.IsNotNull(person);
                    context.SaveChanges();
                    Assert.IsNotNull(person.Id);
                    personId = person.Id;
                }
            }

            using (var dataObjectStore = _dataObjectContext.OpenStore(storeName))
            {
                using (var context = new MyEntityContext(dataObjectStore))
                {
                    var person = context.Persons.FirstOrDefault(p => p.Id == personId);
                    Assert.IsNotNull(person);
                }
            }
        }
Exemplo n.º 13
0
        public void TestLinqCount()
        {
            var connectionString = GetConnectionString("TestLinqCount");
            var context = new MyEntityContext(connectionString);
            for(var i = 0; i<100; i++)
            {
                var entity = context.TestEntities.Create();
                entity.SomeString = "Entity " + i;
                entity.SomeInt = i;
            }
            context.SaveChanges();

            var count = context.TestEntities.Count();

            Assert.IsNotNull(count);
            Assert.AreEqual(100, count);

            for (var j = 0; j < 100; j++)
            {
                var entity = context.TestEntities.Create();
                entity.SomeString = "Entity " + j;
                entity.SomeInt = j;
            }
            context.SaveChanges();

            var count2 = context.TestEntities.Count();

            Assert.IsNotNull(count2);
            Assert.AreEqual(200, count2);
        }
 public void SetUp()
 {
     _context = new MyEntityContext("type=embedded;storesDirectory=" + Configuration.StoreLocation + ";storeName=EFStringComparisonTests_" + DateTime.Now.Ticks);
     var np = new Company {Name = "NetworkedPlanet"};
     var apple = new Company {Name = "Apple"};
     _context.Companies.Add(np);
     _context.Companies.Add(apple);
     _context.SaveChanges();
 }
Exemplo n.º 15
0
        public void TestSaveWorksWhenNoCallback()
        {
            var context = new MyEntityContext(_connectionString);
            var carol = new Person { Name = "Carol" };
            context.Persons.Add(carol);
            context.SaveChanges();

            var found = context.Persons.FirstOrDefault(p => p.Name.Equals("Carol"));
            Assert.IsNotNull(found);
        }
Exemplo n.º 16
0
 public void TestCannotCreateEntityWithKey()
 {
     string storeName = "CannotCreateEntityWithKey_" + DateTime.UtcNow.Ticks;
     using (var dataObjectStore = _dataObjectContext.CreateStore(storeName))
     {
         using (var context = new MyEntityContext(dataObjectStore))
         {
             // Should throw an exception as the Name property is required to generate the key
             context.StringKeyEntities.Create();
             context.SaveChanges();
         }
     }
 }
 public PropertyChangeNotificationTests()
 {
     _storeName = "PropertyChangeNotificationTests_" + DateTime.UtcNow.Ticks;
     _context = new MyEntityContext("type=embedded;storesDirectory=c:\\brightstar;storeName="+_storeName);
     _ftse = _context.Markets.Create();
     _nyse = _context.Markets.Create();
     _company = _context.Companies.Create();
     _company.Name = "Glaxo";
     _company.HeadCount = 20000;
     _company.PropertyChanged += HandlePropertyChanged;
     _person = _context.FoafPersons.Create();
     (_person.MboxSums as INotifyCollectionChanged).CollectionChanged += HandleCollectionChanged;
     _context.SaveChanges();
 }
        public void TestIdentifierPrefixOnBaseEntity()
        {
            var storeName = MakeStoreName("IdentifierPrefixOnBaseEntity");
            using (var context = new MyEntityContext(ConnectionString + storeName))
            {
                var entity1 = new DerivedEntity {Id = "entity1"};
                context.DerivedEntities.Add(entity1);
                entity1.BaseStringValue = "Entity1";
                context.SaveChanges();
            }

            var doContext = BrightstarDB.Client.BrightstarService.GetDataObjectContext(ConnectionString + storeName);
            var store = doContext.OpenStore(storeName);
            var dataObject = store.GetDataObject("http://example.org/entities/entity1");
            Assert.That(dataObject, Is.Not.Null);
        }
        public void TestInitializeWithStoreConfiguration()
        {
            var configFilePath = Path.GetFullPath(Configuration.DataLocation + "dataObjectStoreConfig.ttl");
            var connectionString = "type=dotNetRdf;configuration=" + configFilePath + ";storeName=example;store=http://www.brightstardb.com/tests#peopleStore";
            const string baseGraph = "http://example.org/people";

            var context = new MyEntityContext(connectionString, updateGraphUri:baseGraph, datasetGraphUris:new string[]{baseGraph});
            // Can find by property
            var alice = context.FoafPersons.FirstOrDefault(p => p.Name.Equals("Alice"));
            Assert.That(alice, Is.Not.Null);
            // Can find by ID
            alice = context.FoafPersons.FirstOrDefault(p => p.Id.Equals("alice"));
            Assert.That(alice, Is.Not.Null);
            Assert.That(alice.Name, Is.EqualTo("Alice"));
            Assert.That(alice.Knows, Is.Not.Null);
        }
Exemplo n.º 20
0
        public void TestLinqAverage()
        {
            var connectionString = _connectionString + "StoreName=" + Guid.NewGuid();
            var context = new MyEntityContext(connectionString);

            var e1 = context.Entities.Create();
            e1.SomeInt = 10;
            e1.SomeDecimal = 10;
            e1.SomeDouble = 10;
            
            var e2 = context.Entities.Create();
            e2.SomeInt = 12;
            e2.SomeDecimal = 12;
            e2.SomeDouble = 12;
            
            var e3 = context.Entities.Create();
            e3.SomeInt = 15;
            e3.SomeDecimal = 15;
            e3.SomeDouble = 15;
            
            var e4 = context.Entities.Create();
            e4.SomeInt = 10;
            e4.SomeDecimal = 10;
            e4.SomeDouble = 10;
            
            var e5 = context.Entities.Create();
            e5.SomeInt = 11;
            e5.SomeDecimal = 11;
            e5.SomeDouble = 11;


            context.SaveChanges();
            Assert.AreEqual(5, context.Entities.Count());

            var avInt = context.Entities.Average(e => e.SomeInt);
            Assert.IsNotNull(avInt);
            Assert.AreEqual(11.6, avInt);

            var avDec = context.Entities.Average(e => e.SomeDecimal);
            Assert.IsNotNull(avDec);
            Assert.AreEqual(11.6m, avDec);

            var avDbl = context.Entities.Average(e => e.SomeDouble);
            Assert.IsNotNull(avDbl);
            Assert.AreEqual(11.6, avDbl);

        }
Exemplo n.º 21
0
        public void TestCreateAndSetProperties()
        {
            var entity = _myEntityContext.TestEntities.Create();
            var now = DateTime.Now;
            entity.SomeDateTime = now;
            entity.SomeDecimal = 3.14m;
            entity.SomeDouble = 3.14;
            entity.SomeFloat = 3.14F;
            entity.SomeInt = 3;
            entity.SomeNullableDateTime = null;
            entity.SomeNullableInt = null;
            entity.SomeString = "test entity";

            entity.SomeBool = true;
            entity.SomeLong = 50L;

            _myEntityContext.SaveChanges();
            var entityId = entity.Id;

            var newContext = new MyEntityContext(_connectionString);
            var checkEntity = newContext.TestEntities.FirstOrDefault(e => e.Id.Equals(entityId));

            Assert.IsNotNull(checkEntity);
            Assert.IsNotNull(checkEntity.SomeDateTime);
            Assert.IsNotNull(checkEntity.SomeDecimal);
            Assert.IsNotNull(checkEntity.SomeDouble);
            Assert.IsNotNull(checkEntity.SomeFloat);
            Assert.IsNotNull(checkEntity.SomeInt);
            Assert.IsNull(checkEntity.SomeNullableDateTime);
            Assert.IsNull(checkEntity.SomeNullableInt);
            Assert.IsNotNull(checkEntity.SomeString);

            Assert.AreEqual(now, checkEntity.SomeDateTime);
            Assert.AreEqual(3.14m, checkEntity.SomeDecimal);
            Assert.AreEqual(3.14, checkEntity.SomeDouble);
            Assert.AreEqual(3.14F, checkEntity.SomeFloat);
            Assert.AreEqual(3, checkEntity.SomeInt);
            Assert.AreEqual("test entity", checkEntity.SomeString);
            Assert.IsTrue(checkEntity.SomeBool);
            Assert.AreEqual(50L, checkEntity.SomeLong);          
        }
Exemplo n.º 22
0
        public void TestCustomTriplesQuery()
        {
            string storeName = Guid.NewGuid().ToString();
            var people = new Person[10];
            using (var dataObjectStore = _dataObjectContext.CreateStore(storeName))
            {
                using (var context = new MyEntityContext(dataObjectStore))
                {
                    for (int i = 0; i < 10; i++)
                    {
                        var person = new Person { Age = 40 - i, Name = "Person #" + i };
                        context.Persons.Add(person);
                        people[i] = person;
                    }
                    context.SaveChanges();
                }
            }


            using (var dataObjectStore = _dataObjectContext.OpenStore(storeName))
            {
                using (var context = new MyEntityContext(dataObjectStore))
                {
                    var query = @"
select  ?s ?p ?o
where {
   ?s ?p ?o.
        ?s a <http://www.example.org/schema/Person>
}
";
                    IList<Person> results;
                    results = context.ExecuteQuery<Person>(query).ToList();
                    Assert.AreEqual(10, results.Count);

                    foreach (Person person in results)
                    {
                        Assert.AreNotEqual(0, person.Age);
                    }
                }
            }
        }
        public void TestBecomeAndUnbecome()
        {
            var storeName = MakeStoreName("becomeAndUnbecome");
            var context = new MyEntityContext(ConnectionString + storeName);
            var entity1 = context.BaseEntities.Create();
            entity1.BaseStringValue = "BecomeTest";
            context.SaveChanges();

            context = new MyEntityContext(ConnectionString + storeName);
            Assert.AreEqual(1, context.BaseEntities.Count());
            Assert.AreEqual(0, context.DerivedEntities.Count());
            var entity =
                context.BaseEntities.Where(x => x.BaseStringValue.Equals("BecomeTest")).FirstOrDefault();
            var derived = (entity as BrightstarEntityObject).Become<IDerivedEntity>();
            derived.DateTimeProperty = new DateTime(2011, 11,11);
            context.SaveChanges();

            context = new MyEntityContext(ConnectionString + storeName);
            Assert.AreEqual(1, context.BaseEntities.Count());
            Assert.AreEqual(1, context.DerivedEntities.Count());
            entity =
                context.BaseEntities.Where(x => x.BaseStringValue.Equals("BecomeTest")).FirstOrDefault();
            Assert.AreEqual("BecomeTest", entity.BaseStringValue);
            var derivedEntity = (entity as BrightstarEntityObject).Become<IDerivedEntity>();
            Assert.AreEqual("BecomeTest", derivedEntity.BaseStringValue);
            Assert.AreEqual(new DateTime(2011, 11, 11), derivedEntity.DateTimeProperty);

            context.SaveChanges();

            context = new MyEntityContext(ConnectionString + storeName);
            var d2 = context.DerivedEntities.Where(x => x.BaseStringValue.Equals("BecomeTest")).FirstOrDefault();
            Assert.IsNotNull(d2);
            (d2 as BrightstarEntityObject).Unbecome<IDerivedEntity>();
            context.SaveChanges();

            context = new MyEntityContext(ConnectionString + storeName);
            Assert.AreEqual(1, context.BaseEntities.Count());
            Assert.AreEqual(0, context.DerivedEntities.Count());

        }
Exemplo n.º 24
0
        public void TestEmbeddedClientMapToRdf()
        {
            var storeName = "foaf_" + Guid.NewGuid().ToString();
            var embeddedClient =
                BrightstarService.GetClient("type=embedded;storesDirectory=c:\\brightstar;");
            embeddedClient.CreateStore(storeName);

            //add rdf data for a person
            var triples = new StringBuilder();
            triples.AppendLine(@"<http://www.networkedplanet.com/people/j.williams> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .");
            triples.AppendLine(@"<http://www.networkedplanet.com/people/j.williams> <http://xmlns.com/foaf/0.1/nick> ""Jen"" .");
            triples.AppendLine(@"<http://www.networkedplanet.com/people/j.williams> <http://xmlns.com/foaf/0.1/name> ""Jen Williams"" .");
            triples.AppendLine(@"<http://www.networkedplanet.com/people/j.williams> <http://xmlns.com/foaf/0.1/Organization> ""Networked Planet"" .");

            var job = embeddedClient.ExecuteTransaction(storeName,null, null, triples.ToString());
            TestHelper.AssertJobCompletesSuccessfully(embeddedClient, storeName, job);

            //check EF can access all properties
            using (
                var context =
                    new MyEntityContext(string.Format(@"type=embedded;storesDirectory=c:\\brightstar;storeName={0}",
                                                      storeName)))
            {

                Assert.IsNotNull(context.FoafPersons);
                Assert.AreEqual(1, context.FoafPersons.Count());
                var person = context.FoafPersons.FirstOrDefault();
                Assert.IsNotNull(person);

                Assert.IsNotNull(person.Id);
                Assert.AreEqual("j.williams", person.Id);
                Assert.IsNotNull(person.Name);
                Assert.AreEqual("Jen Williams", person.Name);
                Assert.IsNotNull(person.Nickname);
                Assert.AreEqual("Jen", person.Nickname);
                Assert.IsNotNull(person.Organisation);
                Assert.AreEqual("Networked Planet", person.Organisation);
            }
        }
        public void TestRetrieveDerivedInstancesFromBaseCollection()
        {
            var storeName = MakeStoreName("retrieveDerviedInstances");
            var context = new MyEntityContext(ConnectionString + storeName);
            var derivedEntity = context.DerivedEntities.Create();
            derivedEntity.BaseStringValue = "This is a dervied entity";
            derivedEntity.DateTimeProperty = new DateTime(2011, 11, 11);
            var baseEntity = context.BaseEntities.Create();
            baseEntity.BaseStringValue = "This is a base entity";
            context.SaveChanges();

            context = new MyEntityContext(ConnectionString+storeName);

            var baseEntities = context.BaseEntities.ToList();
            Assert.AreEqual(2,baseEntities.Count);
            Assert.IsTrue(baseEntities.Any(x=>x.BaseStringValue.Equals("This is a base entity")));
            Assert.IsTrue(baseEntities.Any(x=>x.BaseStringValue.Equals("This is a dervied entity")));

            var derivedEntities = context.DerivedEntities.ToList();
            Assert.AreEqual(1, derivedEntities.Count);
            Assert.IsTrue(derivedEntities.Any(x=>x.BaseStringValue.Equals("This is a dervied entity")));
        }
Exemplo n.º 26
0
        public void TestChangeLiteralLanguage()
        {
            var storeName = "PlainLiteralTests_ChangeLiteralLanguage" + DateTime.Now.Ticks;
            using (var dataObjectStore = _dataObjectContext.CreateStore(storeName))
            {
                string conceptBId;
                using (var context = new MyEntityContext(dataObjectStore))
                {
                    var conceptB = context.Concepts.Create();
                    conceptB.PrefLabel = new[]
                        {
                            new PlainLiteral("US English value", "en")
                        };
                    context.SaveChanges();
                    conceptBId = conceptB.Id;
                }
                using (var context = new MyEntityContext(dataObjectStore))
                {
                    var conceptB = context.Concepts.FirstOrDefault(c => c.Id.Equals(conceptBId));
                    Assert.IsNotNull(conceptB);
                    var toReplace = conceptB.PrefLabel.FirstOrDefault(l => l.Language.Equals("en"));
                    Assert.IsNotNull(toReplace);
                    conceptB.PrefLabel.Remove(toReplace);
                    conceptB.PrefLabel.Add(new PlainLiteral(toReplace.Value, "en-us"));
                    context.SaveChanges();
                }

                using (var context = new MyEntityContext(dataObjectStore))
                {
                    var conceptB = context.Concepts.FirstOrDefault(c => c.Id.Equals(conceptBId));
                    Assert.IsNotNull(conceptB);
                    Assert.IsNull(conceptB.PrefLabel.FirstOrDefault(l=>l.Language.Equals("en")));
                    var label = conceptB.PrefLabel.FirstOrDefault(l => l.Language.Equals("en-us"));
                    Assert.IsNotNull(label);
                    Assert.AreEqual("US English value", label.Value);
                }
            }
        }
Exemplo n.º 27
0
        public void TestLinqLongCount()
        {
            var connectionString = _connectionString + "StoreName=" +Guid.NewGuid();
            var context = new MyEntityContext(connectionString);
            for (var i = 0; i < 10000; i++)
            {
                var entity = context.Entities.Create();
                entity.SomeString = "Entity " + i;
                if (i % 2000 == 0)
                {
                    context.SaveChanges();
                }
            }
            context.SaveChanges();

            var context2 = new MyEntityContext(connectionString);
            var count = context2.Entities.LongCount();

            Assert.IsNotNull(count);
            Assert.AreEqual(10000, count);

          
        }
Exemplo n.º 28
0
        public void TestHttpClientMapToRdf()
        {
            var storeName = "foaf_" + Guid.NewGuid().ToString();
            var httpClient = GetClient();
            httpClient.CreateStore(storeName);

            //add rdf data for a person
            var triples = new StringBuilder();
            triples.AppendLine(@"<http://www.networkedplanet.com/people/j.williams> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .");
            triples.AppendLine(@"<http://www.networkedplanet.com/people/j.williams> <http://xmlns.com/foaf/0.1/nick> ""Jen"" .");
            triples.AppendLine(@"<http://www.networkedplanet.com/people/j.williams> <http://xmlns.com/foaf/0.1/name> ""Jen Williams"" .");
            triples.AppendLine(@"<http://www.networkedplanet.com/people/j.williams> <http://xmlns.com/foaf/0.1/Organization> ""Networked Planet"" .");

            httpClient.ExecuteTransaction(storeName,null, null, triples.ToString());

            //check EF can access all properties
            using (
                var context =
                    new MyEntityContext(
                        string.Format(@"type=http;endpoint=http://localhost:8090/brightstar;storeName={0}", storeName)))
            {

                Assert.IsNotNull(context.FoafPersons);
                Assert.AreEqual(1, context.FoafPersons.Count());
                var person = context.FoafPersons.FirstOrDefault();
                Assert.IsNotNull(person);

                Assert.IsNotNull(person.Id);
                Assert.AreEqual("j.williams", person.Id);
                Assert.IsNotNull(person.Name);
                Assert.AreEqual("Jen Williams", person.Name);
                Assert.IsNotNull(person.Nickname);
                Assert.AreEqual("Jen", person.Nickname);
                Assert.IsNotNull(person.Organisation);
                Assert.AreEqual("Networked Planet", person.Organisation);
            }
        }
Exemplo n.º 29
0
        public void TestLinqOrderByInteger()
        {
            var connectionString = _connectionString + "StoreName=LinqOrderByInteger_" + DateTime.Now.Ticks;
            var context = new MyEntityContext(connectionString);

            var pe = context.Persons.Create();
            pe.Name = "Eddie";
            pe.Age = 51;

            var pb = context.Persons.Create();
            pb.Name = "Bill";
            pb.Age = 111;

            var pf = context.Persons.Create();
            pf.Name = "Freddie";
            pf.Age = 47;

            var pd = context.Persons.Create();
            pd.Name = "Dennis";
            pd.Age = 32;

            var pc = context.Persons.Create();
            pc.Name = "Carole";
            pc.Age = 18;

            var pa = context.Persons.Create();
            pa.Name = "Annie";
            pa.Age = 28;

            context.SaveChanges();

            Assert.AreEqual(6, context.Persons.Count());

            var orderedByAge = context.Persons.OrderBy(p => p.Age);
            Assert.IsNotNull(orderedByAge);
            Assert.AreEqual(6, orderedByAge.Count());
            var i = 0;
            foreach (var p in orderedByAge)
            {
                Assert.IsNotNull(p.Name);
                Assert.IsNotNull(p.Age);
                switch (i)
                {
                    case 0:
                        Assert.AreEqual("Carole", p.Name);
                        break;
                    case 1:
                        Assert.AreEqual("Annie", p.Name);
                        break;
                    case 2:
                        Assert.AreEqual("Dennis", p.Name);
                        break;
                    case 3:
                        Assert.AreEqual("Freddie", p.Name);
                        break;
                    case 4:
                        Assert.AreEqual("Eddie", p.Name);
                        break;
                    case 5:
                        Assert.AreEqual("Bill", p.Name);
                        break;
                }
                i++;
            }

            var orderedByAgeDesc = context.Persons.OrderByDescending(p => p.Age);
            Assert.IsNotNull(orderedByAgeDesc);
            Assert.AreEqual(6, orderedByAgeDesc.Count());
            var j = 0;
            foreach (var p in orderedByAgeDesc)
            {
                Assert.IsNotNull(p.Name);
                Assert.IsNotNull(p.Age);
                switch (j)
                {
                    case 5:
                        Assert.AreEqual("Carole", p.Name);
                        break;
                    case 4:
                        Assert.AreEqual("Annie", p.Name);
                        break;
                    case 3:
                        Assert.AreEqual("Dennis", p.Name);
                        break;
                    case 2:
                        Assert.AreEqual("Freddie", p.Name);
                        break;
                    case 1:
                        Assert.AreEqual("Eddie", p.Name);
                        break;
                    case 0:
                        Assert.AreEqual("Bill", p.Name);
                        break;
                }
                j++;
            }
            
        }
Exemplo n.º 30
0
        public void TestLinqOrderByDate()
        {
            var connectionString = _connectionString + "StoreName=" + Guid.NewGuid();
            var context = new MyEntityContext(connectionString);
            
            var pe = context.Persons.Create();
            pe.Name = "Eddie";
            pe.DateOfBirth = new DateTime(1969, 8, 8, 4, 5, 30);

            var pb = context.Persons.Create();
            pb.Name = "Bill";
            pb.DateOfBirth = new DateTime(1900, 1, 12);
            
            var pf = context.Persons.Create();
            pf.Name = "Freddie";
            pf.DateOfBirth = new DateTime(1969, 8, 8, 4, 6, 30);

            var pd = context.Persons.Create();
            pd.Name = "Dennis";
            pd.DateOfBirth = new DateTime(1962, 4, 20);

            var pc = context.Persons.Create();
            pc.Name = "Carole";
            pc.DateOfBirth = new DateTime(1962, 3, 11);
            
            var pa = context.Persons.Create();
            pa.Name = "Annie";
            pa.DateOfBirth = new DateTime(1950, 2, 2);

            context.SaveChanges();
            Assert.AreEqual(6, context.Persons.Count());

            var orderedByDob = context.Persons.OrderBy(p => p.DateOfBirth);
            Assert.IsNotNull(orderedByDob);
            Assert.AreEqual(6, orderedByDob.Count());
            var i = 0;
            foreach (var p in orderedByDob)
            {
                Assert.IsNotNull(p.Name);
                Assert.IsNotNull(p.DateOfBirth);
                switch (i)
                {
                    case 0:
                        Assert.AreEqual("Bill", p.Name);
                        break;
                    case 1:
                        Assert.AreEqual("Annie", p.Name);
                        break;
                    case 2:
                        Assert.AreEqual("Carole", p.Name);
                        break;
                    case 3:
                        Assert.AreEqual("Dennis", p.Name);
                        break;
                    case 4:
                        Assert.AreEqual("Eddie", p.Name);
                        break;
                    case 5:
                        Assert.AreEqual("Freddie", p.Name);
                        break;
                }
                i++;
            }

            var orderedByDobDesc = context.Persons.OrderByDescending(p => p.DateOfBirth);
            Assert.IsNotNull(orderedByDobDesc);
            Assert.AreEqual(6, orderedByDobDesc.Count());
            var j = 0;
            foreach (var p in orderedByDobDesc)
            {
                Assert.IsNotNull(p.Name);
                Assert.IsNotNull(p.DateOfBirth);
                switch (j)
                {
                    case 5:
                        Assert.AreEqual("Bill", p.Name);
                        break;
                    case 4:
                        Assert.AreEqual("Annie", p.Name);
                        break;
                    case 3:
                        Assert.AreEqual("Carole", p.Name);
                        break;
                    case 2:
                        Assert.AreEqual("Dennis", p.Name);
                        break;
                    case 1:
                        Assert.AreEqual("Eddie", p.Name);
                        break;
                    case 0:
                        Assert.AreEqual("Freddie", p.Name);
                        break;
                }
                j++;
            }
        }
Exemplo n.º 31
0
        public void TestCreateAndSetCollections()
        {
            var entity = _myEntityContext.Entities.Create();

            var now = DateTime.Now;

            for (var i = 0; i < 10; i++)
            {
                var date = now.AddDays(i);
                entity.CollectionOfDateTimes.Add(date);
            }
            for (var i = 0; i < 10; i++)
            {
                var dec = i + .5m;
                entity.CollectionOfDecimals.Add(dec);
            }
            for (var i = 0; i < 10; i++)
            {
                var dbl = i + .5;
                entity.CollectionOfDoubles.Add(dbl);
            }
            for (var i = 0; i < 10; i++)
            {
                var flt = i + .5F;
                entity.CollectionOfFloats.Add(flt);
            }
            for (var i = 0; i < 10; i++)
            {
                entity.CollectionOfInts.Add(i);
            }
            entity.CollectionOfBools.Add(true);
            entity.CollectionOfBools.Add(false);
            for (var i = 0; i < 10; i++)
            {
                var l = i * 100;
                entity.CollectionOfLong.Add(l);
            }
            for (var i = 0; i < 10; i++)
            {
                var s = "word" + i;
                entity.CollectionOfStrings.Add(s);
            }

            _myEntityContext.SaveChanges();
            var entityId = entity.Id;

            var newContext  = new MyEntityContext(_connectionString);
            var checkEntity = newContext.Entities.FirstOrDefault(e => e.Id.Equals(entityId));

            Assert.IsNotNull(checkEntity);
            Assert.IsNotNull(checkEntity.CollectionOfDateTimes);
            Assert.IsNotNull(checkEntity.CollectionOfDecimals);
            Assert.IsNotNull(checkEntity.CollectionOfDoubles);
            Assert.IsNotNull(checkEntity.CollectionOfFloats);
            Assert.IsNotNull(checkEntity.CollectionOfInts);
            Assert.IsNotNull(checkEntity.CollectionOfBools);
            Assert.IsNotNull(checkEntity.CollectionOfLong);
            Assert.IsNotNull(checkEntity.CollectionOfStrings);

            var lstDateTimes = checkEntity.CollectionOfDateTimes.OrderBy(e => e).ToList();
            var lstDecs      = checkEntity.CollectionOfDecimals.OrderBy(e => e).ToList();
            var lstDbls      = checkEntity.CollectionOfDoubles.OrderBy(e => e).ToList();
            var lstFloats    = checkEntity.CollectionOfFloats.OrderBy(e => e).ToList();
            var lstInts      = checkEntity.CollectionOfInts.OrderBy(e => e).ToList();
            var lstLongs     = checkEntity.CollectionOfLong.OrderBy(e => e).ToList();
            var lstStrings   = checkEntity.CollectionOfStrings.OrderBy(e => e).ToList();
            var lstBools     = checkEntity.CollectionOfBools.OrderBy(e => e).ToList();

            for (var i = 0; i < 10; i++)
            {
                var date = now.AddDays(i);
                var dec  = i + .5m;
                var dbl  = i + .5;
                var flt  = i + .5F;
                var l    = i * 100;
                var s    = "word" + i;

                Assert.AreEqual(date, lstDateTimes[i]);
                Assert.AreEqual(dec, lstDecs[i]);
                Assert.AreEqual(dbl, lstDbls[i]);
                Assert.AreEqual(flt, lstFloats[i]);
                Assert.AreEqual(l, lstLongs[i]);
                Assert.AreEqual(i, lstInts[i]);
                Assert.AreEqual(s, lstStrings[i]);
            }
            Assert.AreEqual(2, lstBools.Count);
        }
Exemplo n.º 32
0
 public void SetUp()
 {
     _myEntityContext = new MyEntityContext(_connectionString);
 }