public void It_Should_Serialise_To_This() { const string expectedXML = BasicKeyXml; EntityKey key = new EntityKeyImpl(); string outputXML = new EntitySetSerialisationScheme().SerialiseKey(key); outputXML = XmlSqueezer.RemoveWhitespaceBetweenElements(outputXML); Assert.That(outputXML, Is.EqualTo(expectedXML)); }
public EntityImpl() { Key = new EntityKeyImpl(); Generator = new EntityGenerator("assigned"); Cache = new Cache() { Include = Cache.IncludeTypes.All, Region = "", Usage = Cache.UsageTypes.None }; Discriminator = new Discriminator(); }
public EntityImpl() { Key = new EntityKeyImpl(); Generator = new EntityGenerator("assigned"); Cache = new Cache() { Include = Cache.IncludeTypes.All, Region = "", Usage = Cache.UsageTypes.None }; Discriminator = new Discriminator(); }
public EntityKey DeserialiseKey(XmlNode keyNode, Entity parentEntity) { var key = new EntityKeyImpl(); key.Parent = parentEntity; if (keyNode.InnerXml == "") { return(key); } NodeProcessor keyProc = new NodeProcessor(keyNode); bool propertiesExist = false; bool componentExists = false; var nodes = keyNode.SelectNodes("Properties/Property"); if (nodes != null) { propertiesExist = true; foreach (XmlNode node in nodes) { key.AddProperty(node.InnerText); } } if (keyProc.Exists("Component")) { componentExists = true; string componentName = keyProc.SubNode("Component").Attributes.GetString("name"); Component component = parentEntity.Components.FirstOrDefault(c => c.Name == componentName); if (component == null) { throw new DeserialisationException(string.Format("Could not find component named {0} on Entity {1}", componentName, parentEntity.Name)); } key.Component = component; } if (keyProc.Attributes.Exists("keytype")) { key.KeyType = keyProc.Attributes.GetEnum <EntityKeyType>("keytype"); } else if (propertiesExist && componentExists) { throw new DeserialisationException(string.Format("Both a Component and a set of Properties were listed as the Key for entity {0}, but no keytype attribute was found on the Key node in the Entity Model XML.", parentEntity.Name)); } ProcessScriptBase(key, keyNode); return(key); }
public void It_Should_Serialise_To_This() { const string expectedXML = FullKeyXml; EntityKey key = new EntityKeyImpl(); key.AddProperty(new PropertyImpl { Name = "Property1" }); key.Component = new ComponentImpl { Name = "Component_Name" }; key.KeyType = EntityKeyType.Component; string outputXML = new EntitySetSerialisationScheme().SerialiseKey(key); outputXML = XmlSqueezer.RemoveWhitespaceBetweenElements(outputXML); Assert.That(outputXML, Is.EqualTo(expectedXML)); }
public void The_Form_Is_Set_Up() { IEntityKeyForm form = MockRepository.GenerateMock<IEntityKeyForm>(); IMainPanel panel = MockRepository.GenerateMock<IMainPanel>(); EntityKey obj = new EntityKeyImpl(); obj.Parent = new EntityImpl("Parent"); EntityKeyPresenter presenter = new EntityKeyPresenter(panel, form); presenter.AttachToModel(obj); form.AssertWasCalled(x => x.SetProperties(obj.Properties)); form.AssertWasCalled(x => x.KeyType = obj.KeyType); form.AssertWasCalled(x => x.Component = obj.Component); form.AssertWasCalled(x => x.SetParentEntityName(obj.Parent.Name)); form.AssertWasCalled(x => x.SetPossibleComponents(obj.Parent.Components)); form.AssertWasCalled(x => x.SetVirtualProperties(obj.Ex)); }
public void SetUp() { mainPanel = MockRepository.GenerateStub<IMainPanel>(); form = MockRepository.GenerateMock<IEntityForm>(); ms = MockRepository.GenerateStub<MappingSet>(); Property property = new PropertyImpl("Prop1"); EntityKey key = new EntityKeyImpl(); entity = new EntityImpl("Entity1") { Key = key }; entity.AddProperty(property); key.AddProperty(property); mapping = new MappingImpl(); form.Stub(f => f.Mappings).Return(new List<Mapping> { mapping }); EntitySet es = new EntitySetImpl(); es.AddEntity(entity); ms.EntitySet = es; es.MappingSet = ms; ms.Stub(m => m.GetMappingsContaining(entity)).Return(new List<Mapping>()); var presenter = new EntityPresenter(mainPanel, form); presenter.AttachToModel(entity); }
public void The_Presenter_Fills_In_The_Form() { IMainPanel mainPanel = MockRepository.GenerateStub<IMainPanel>(); IEntityForm form = MockRepository.GenerateMock<IEntityForm>(); form.Expect(f => f.Mappings = null) .IgnoreArguments() .WhenCalled(action => Assert.That(((IEnumerable<Mapping>) action.Arguments[0]).Count(), Is.EqualTo(0))); form.Expect(f => f.SetAvailableTables(null)) .IgnoreArguments() .WhenCalled(action => Assert.That(((IEnumerable<ITable>)action.Arguments[0]).Count(), Is.EqualTo(0))); form.Expect(f => f.SetProperties(null)) .IgnoreArguments() .WhenCalled(action => Assert.That(((IEnumerable<Property>)action.Arguments[0]).Count(), Is.EqualTo(1))); form.Expect(f => f.SetAvailableEntities(null)) .IgnoreArguments() .WhenCalled(action => Assert.That(((IEnumerable<Entity>)action.Arguments[0]).Count(), Is.EqualTo(2))); form.Expect(f => f.SetChildEntities(null)) .IgnoreArguments() .WhenCalled(action => Assert.That(((IEnumerable<Entity>)action.Arguments[0]).Count(), Is.EqualTo(1))); Entity parentEntity = new EntityImpl("Parent"); Entity childEntity = new EntityImpl("Child"); Property property = new PropertyImpl("Prop1"); EntityKey key = new EntityKeyImpl(); Entity entity = new EntityImpl("Entity1") { Key = key }; entity.Parent = parentEntity; entity.AddChild(childEntity); entity.AddProperty(property); key.AddProperty(property); EntitySet es = new EntitySetImpl(); es.AddEntity(parentEntity); es.AddEntity(entity); es.AddEntity(childEntity); MappingSet ms = new MappingSetImpl(); ms.EntitySet = es; var presenter = new EntityPresenter(mainPanel, form); presenter.AttachToModel(entity); form.AssertWasCalled(f => f.EntityName = entity.Name); form.AssertWasCalled(f => f.Discriminator = entity.Discriminator); form.AssertWasCalled(f => f.ParentEntity = entity.Parent); form.AssertWasCalled(f => f.SetVirtualProperties(entity.Ex)); form.VerifyAllExpectations(); }