public void EFDataSourceShouldDeleteEntity()
 {
     var source = new TestDataSource();
     var entity = TestEntityFactory.GetEntity();
     source.Save(entity);
     source.SaveChanges();
     var id = entity.Id;
     source.Delete(entity);
     entity = source.Set<TestEntity>().Find(new object[] { id });
     Assert.AreEqual(System.Data.Entity.EntityState.Deleted, source.Entry(entity).State);
     source.SaveChanges();
 }
        public void EFDataSourceShouldDeleteAListOfEntities()
        {
            var source = new TestDataSource();
            var existing = source.Query<TestEntity>().GetList();

            if (existing.Count > 0)
            {
                source.Delete(existing);
                source.SaveChanges();
            }

            var list = new List<TestEntity>()
            {
                new TestEntity
                {
                    Name = "Test generated 1",
                    Number = 1
                },
                new TestEntity
                {
                    Name = "Test generated 2",
                    Number = 2
                },
                new TestEntity
                {
                    Name = "Test generated 3",
                    Number = 3
                }
            };

            source.Save(list);
            source.SaveChanges();
            source.Delete(list);
            source.SaveChanges();
            existing = source.Query<TestEntity>().GetList();
            Assert.AreEqual(0, existing.Count);
        }
        public void MapShouldReturnListWithExistingPropertiesOnlyUsingIQueryableOnDatabase()
        {
            Init();
            var source = new TestDataSource();
            var list = new List<TestEntity>()
            {
                new TestEntity
                {
                    Name = "Test generated 1",
                    Number = 1
                },
                new TestEntity
                {
                    Name = "Test generated 2",
                    Number = 2
                },
                new TestEntity
                {
                    Name = "Test generated 3",
                    Number = 3
                }
            };

            source.Save(list);
            source.SaveChanges();
            source = new TestDataSource();

            var entities = source.IntEntities.GetList();
            var result = entities.Map<TestEntityViewModel>().ToList();

            source.Delete(entities);
            source.SaveChanges();

            Assert.IsTrue(result.Count == 3);
            Assert.IsTrue(result.All(r => !string.IsNullOrWhiteSpace(r.Name)));
            Assert.IsTrue(result.All(r => r.Number > 0));
            Assert.IsTrue(result.All(r => r.NotAvailable == null));
        }
        public void EFDataSourceShouldSaveAListOfIntEntities()
        {
            var source = new TestDataSource();
            var entities = TestEntityFactory.GetEntityList();
            var result = source.Save(entities);
            source.SaveChanges();
            source.Delete(entities);
            source.SaveChanges();
            Assert.AreEqual(6, result.Count);

            foreach (var item in result)
            {
                Assert.AreNotEqual(0, item.Id);
            }
        }
 public void EFDataSourceIsInitializedSuccessfullyWithCustomConnection()
 {
     var source = new TestDataSource("CustomConnection");
     Assert.IsNotNull(source);
     Assert.IsTrue(source.Database.Connection.ConnectionString.Contains("ToolsTestCustomConnection"));
 }
 public void EFDataSourceIsInitializedSuccessfullyWithBasicConnection()
 {
     var source = new TestDataSource();
     Assert.IsNotNull(source);
     Assert.IsTrue(source.Database.Connection.ConnectionString.Contains("ServicesTest"));
 }
        public void QueryWithRelationsShouldReturnEntitiesWithRelations()
        {
            var source = new TestDataSource();
            int id = 0;

            var customField = new TestCustomField { Name = "Test", FieldType = CustomFieldType.String, GroupId = Guid.NewGuid() };
            source.Save(customField);
            source.SaveChanges();

            var entity = new TestEntity
            {
                Name = "Test generated 1",
                Number = 1,
                CustomFields = new List<TestCustomFieldValue> { new TestCustomFieldValue { StringValue = "Test", Culture = "en", CustomField = customField, CustomFieldId = customField.Id } }
            };

            source.Save(entity);
            source.SaveChanges();
            id = entity.Id;

            var newSource = new TestDataSource();
            var result = newSource.Query<TestEntity>().Include(c => c.CustomFields).First(t => t.Id == id);
            Assert.IsNotNull(result.CustomFields);
            Assert.AreEqual("Test", result.CustomFields.First().StringValue);
            newSource.Delete(result);
            newSource.SaveChanges();
        }
 public void EFDataSourceShouldSaveNewIntEntity()
 {
     var source = new TestDataSource();
     var entity = TestEntityFactory.GetEntity();
     var result = source.Save(entity);
     source.SaveChanges();
     source.Delete(result);
     source.SaveChanges();
     Assert.IsNotNull(result);
     Assert.AreNotEqual(0, entity.Id);
 }
 public void EFDataSourceShouldSaveNewGuidEntityAndSetItsKey()
 {
     var source = new TestDataSource();
     var entity = new GuidEntity { Name = "Test" };
     var result = source.Save(entity);
     Assert.IsNotNull(result);
     Assert.AreNotEqual(Guid.Empty, entity.Id);
 }
 public void EFDataSourceShouldSaveNewCompositeKeyEntityAndNotSetItsGuidKey()
 {
     var source = new TestDataSource();
     var entity = new CompositeKeyEntity();
     var result = source.Save(entity);
     Assert.IsNotNull(result);
     Assert.AreEqual(Guid.Empty, entity.Id);
 }