public void SelfSelectorPasses() { #region Construct Enviroment //Model Hierarchy // - root: #main type=Model // - reciever: #main type=RecieverModel // - noneReciever: #main type=NoneRecieverModel // //View info // #main: // - SenderViewObj: ID=SenderViewObj, InstanceID=SenderViewObj, BinderID=SenderViewObj // - RecieverViewObj: ID=reciever, InstanceID=SenderViewObj, BinderID=SenderViewObj var root = new Model() { Name = "root", LogicalID = new ModelIDList("main") }; var recieverModel = new RecieverModel() { Name = "reciever", Parent = root, LogicalID = new ModelIDList("main") }; var noneRecieverModel = new NoneRecieverModel() { Name = "noneReciever", Parent = root, LogicalID = new ModelIDList("main") }; string viewReciever = "reciever"; var viewCreator = new DefaultViewInstanceCreator( (typeof(SenderViewObj), new SenderViewObj.ParamBinder()), (typeof(EventHandlerViewObj), new EventHandlerViewObj.ParamBinder()) ); var binderMap = new ModelViewBinderMap(viewCreator, new ModelViewBinder("#main", null, new ModelViewBinder.BindInfo(typeof(SenderViewObj)), new ModelViewBinder.BindInfo(viewReciever, typeof(EventHandlerViewObj)) )); var binderMapInstance = binderMap.CreateBinderInstaceMap(); binderMapInstance.RootModel = root; #endregion {//Modelを取得しようとした時のテスト //search root model => reciever //selector: Self, "", "" //result => reciever var selector = new ModelViewSelector(ModelRelationShip.Self, "", ""); var enumerable = selector.GetEnumerable(recieverModel, binderMapInstance); var errorMessage = "自身を取得できるようにしてください。"; Assert.AreEqual(1, enumerable.Count(), errorMessage); Assert.AreSame(recieverModel, enumerable.First(), errorMessage); } {//Viewを取得しようとした時のテスト //search root model => reciever //selector: Self, "", "reciever" //result => RecieverViewObj in reciever var selector = new ModelViewSelector(ModelRelationShip.Self, "", viewReciever); var enumerable = selector.GetEnumerable(recieverModel, binderMapInstance); var errorMessage = "Viewを指定した時はModelにバインドされているViewを取得できるようにしてください。"; AssertionUtils.AssertEnumerableByUnordered( binderMapInstance[recieverModel].ViewObjects.Where(_v => _v.UseBindInfo.ID.MainID == viewReciever) , enumerable, errorMessage); } {//Viewを取得しようとした時のテスト3(一致しないViewID) //search root model => noneReciever //selector: Self, "", "invalidIdentity" //result => (empty) var selector = new ModelViewSelector(ModelRelationShip.Self, "", "invalidIdentity"); var enumerable = selector.GetEnumerable(noneRecieverModel, binderMapInstance); var errorMessage = "ViewIdentityが一致していない時は取得できないようにしてください。"; Assert.IsFalse(enumerable.Any(), errorMessage); } }
public void ParentSelectorPasses() { #region Consturct Enviroment //Model Hierarchy // - root: #main type=RecieverModel // - reciever: #main type=RecieverModel // - noneReciever: #main type=NoneRecieverModel // - model: #main type=Model //View info // #main: // - SenderViewObj: ID=SenderViewObj, InstanceID=SenderViewObj, BinderID=SenderViewObj // - RecieverViewObj: ID=reciever, InstanceID=SenderViewObj, BinderID=SenderViewObj var root = new RecieverModel() { Name = "root", LogicalID = new ModelIDList("main") }; var recieverModel = new RecieverModel() { Name = "reciever", Parent = root, LogicalID = new ModelIDList("main") }; var noneRecieverModel = new NoneRecieverModel() { Name = "noneReciever", Parent = root, LogicalID = new ModelIDList("main") }; var model1 = new Model() { Name = "model", Parent = noneRecieverModel, LogicalID = new ModelIDList("main") }; string viewReciever = "reciever"; var viewCreator = new DefaultViewInstanceCreator( (typeof(SenderViewObj), new SenderViewObj.ParamBinder()), (typeof(EventHandlerViewObj), new EventHandlerViewObj.ParamBinder()) ); var binderMap = new ModelViewBinderMap(viewCreator, new ModelViewBinder("#main", null, new ModelViewBinder.BindInfo(typeof(SenderViewObj)), new ModelViewBinder.BindInfo(viewReciever, typeof(EventHandlerViewObj)) )); var binderMapInstance = binderMap.CreateBinderInstaceMap(); binderMapInstance.RootModel = root; #endregion {//Modelを取得しようとした時のテスト //search root model => reciever //selector: Parent, "", "" //result => root var selector = new ModelViewSelector(ModelRelationShip.Parent, "", ""); var enumerable = selector.GetEnumerable(recieverModel, binderMapInstance); var errorMessage = "Parentを取得できるようにしてください。"; Assert.AreEqual(1, enumerable.Count(), errorMessage); Assert.AreSame(root, enumerable.First(), errorMessage); } {//ParentがnullなModelのParentを指定した時のテスト //search root model => root //selector: Parent, "", "" //result => (empty) var selector = new ModelViewSelector(ModelRelationShip.Parent, "", ""); var enumerable = selector.GetEnumerable(root, binderMapInstance); var errorMessage = "ParentがないmodelのParentを指定した時は何も取得できないようにしてください。"; Assert.IsFalse(enumerable.Any(), errorMessage); } {//ParentがnullなModelのParentを指定した時のテスト2 //search root model => model //selector: Parent, "root", "" //result => root, noneReciever var selector = new ModelViewSelector(ModelRelationShip.Parent, "#main", ""); var enumerable = selector.GetEnumerable(model1, binderMapInstance); var errorMessage = "親指定のSelectorの時、クエリパスを指定した時はBinderInstanceMapのRootModelをクエリルートにし、検索対象のModelの親Modelのみを検索してください。"; AssertionUtils.AssertEnumerableByUnordered(new object[] { root, noneRecieverModel }, enumerable, errorMessage); } {//Viewを取得しようとした時のテスト //search root model => reciever //selector: Parent, "", "reciever" //result => RecieverViewObj in root var selector = new ModelViewSelector(ModelRelationShip.Parent, "", viewReciever); var enumerable = selector.GetEnumerable(recieverModel, binderMapInstance); var errorMessage = "Viewを指定した時はModelにバインドされているViewを取得できるようにしてください。"; AssertionUtils.AssertEnumerableByUnordered( binderMapInstance[root].ViewObjects.Where(_v => _v.UseBindInfo.ID.MainID == viewReciever) , enumerable , errorMessage); } {//Viewを取得しようとした時のテスト2 //search root model => model //selector: Parent, "", "reciever" //result => RecieverViewObj in noneReciever var selector = new ModelViewSelector(ModelRelationShip.Parent, "", viewReciever); var enumerable = selector.GetEnumerable(model1, binderMapInstance); var errorMessage = "バインドされているModelがIEventHandlerを継承していない場合でも取得できるようにしてください"; AssertionUtils.AssertEnumerableByUnordered( binderMapInstance[noneRecieverModel].ViewObjects .Where(_v => _v.UseBindInfo.ID.MainID == viewReciever) , enumerable , errorMessage); } {//Viewを取得しようとした時のテスト3(一致しないViewID) //search root model => model //selector: Parent, "", "invalidIdentity" //result => (empty) var selector = new ModelViewSelector(ModelRelationShip.Parent, "", "invalidIdentity"); var enumerable = selector.GetEnumerable(model1, binderMapInstance); var errorMessage = "ViewIdentityが一致していない時は取得できないようにしてください。"; Assert.IsFalse(enumerable.Any(), errorMessage); } {//QueryPathとViewIdentityを指定した時のテスト //search root model => model //selector: Parent, "root", "reciever" //result => root var selector = new ModelViewSelector(ModelRelationShip.Parent, "#main", viewReciever); var enumerable = selector.GetEnumerable(model1, binderMapInstance); var errorMessage = "親指定のrecieverSelectorの時、クエリパスを指定した時はBinderInstanceMapのRootModelをクエリルートにしてください。"; var rootViewObj = binderMapInstance[root].ViewObjects.Where(_v => _v.UseBindInfo.ID.MainID == viewReciever).First(); var parentViewObj = binderMapInstance[noneRecieverModel].ViewObjects.Where(_v => _v.UseBindInfo.ID.MainID == viewReciever).First(); AssertionUtils.AssertEnumerableByUnordered( binderMapInstance[noneRecieverModel].ViewObjects .Concat(binderMapInstance[root].ViewObjects) .Where(_v => _v.UseBindInfo.ID.MainID == viewReciever) , enumerable , errorMessage); } }
public void ChildSelectorPasses() { #region Consturct Enviroment //Model Hierarchy // - root: #main type=RecieverModel // - reciever: #main type=RecieverModel // - noneReciever: #main type=NoneRecieverModel // - reciever2: #main type=RecieverModel //View info // #main: // - SenderViewObj: ID=SenderViewObj, InstanceID=SenderViewObj, BinderID=SenderViewObj // - RecieverViewObj: ID=reciever, InstanceID=SenderViewObj, BinderID=SenderViewObj var root = new RecieverModel() { Name = "root", LogicalID = new ModelIDList("main") }; var recieverModel = new RecieverModel() { Name = "reciever", Parent = root, LogicalID = new ModelIDList("main") }; var noneRecieverModel = new NoneRecieverModel() { Name = "noneReciever", Parent = root, LogicalID = new ModelIDList("main") }; var recieverModel2 = new RecieverModel() { Name = "reciever2", Parent = noneRecieverModel, LogicalID = new ModelIDList("main") }; string viewReciever = "reciever"; var viewCreator = new DefaultViewInstanceCreator( (typeof(SenderViewObj), new SenderViewObj.ParamBinder()), (typeof(EventHandlerViewObj), new EventHandlerViewObj.ParamBinder()) ); var binderMap = new ModelViewBinderMap(viewCreator, new ModelViewBinder("#main", null, new ModelViewBinder.BindInfo(typeof(SenderViewObj)), new ModelViewBinder.BindInfo(viewReciever, typeof(EventHandlerViewObj)) )); var binderMapInstance = binderMap.CreateBinderInstaceMap(); binderMapInstance.RootModel = root; #endregion {//Modelを取得しようとした時のテスト //search root model => root //selector: Child, "", "" //result => reciever, noneReciever var selector = new ModelViewSelector(ModelRelationShip.Child, "", ""); var enumerable = selector.GetEnumerable(root, binderMapInstance); var errorMessage = "IEventHandlerを継承している時は取得できるようにしてください。"; AssertionUtils.AssertEnumerableByUnordered(new object[] { recieverModel, noneRecieverModel, }, enumerable, errorMessage); } {//Childがない時のModelのChildを指定した時のテスト //search root model => reciever //selector: Child, "", "" //result => (empty) var selector = new ModelViewSelector(ModelRelationShip.Child, "", ""); var enumerable = selector.GetEnumerable(recieverModel, binderMapInstance); var errorMessage = "ChildがないmodelのChildを指定した時は何も取得できないようにしてください。"; Assert.IsFalse(enumerable.Any(), errorMessage); } {//QueryPathを指定した時のテスト //search root model => root //selector: Child, "*", "" //result => reciever, reciever2 var selector = new ModelViewSelector(ModelRelationShip.Child, "*", ""); var enumerable = selector.GetEnumerable(root, binderMapInstance); var errorMessage = "QueryPathを指定した時はそれに一致するModel全て取得できるようにしてください"; AssertionUtils.AssertEnumerableByUnordered(new object[] { recieverModel, noneRecieverModel, recieverModel2, }, enumerable, errorMessage); } {//一致しないQueryPathを指定した時のテスト //search root model => root //selector: Child, "__invalid", "" //result => (empty) var selector = new ModelViewSelector(ModelRelationShip.Child, "__invalid", ""); var enumerable = selector.GetEnumerable(root, binderMapInstance); var errorMessage = "QueryPathが一致しない時は何も取得できないようにしてください。"; Assert.IsFalse(enumerable.Any(), errorMessage); } {//Viewを取得しようとした時のテスト //search root model => root //selector: Child, "", "reciever" //result => RecieverViewObj in reciever, RecieverViewObj in noneReciever var selector = new ModelViewSelector(ModelRelationShip.Child, "", viewReciever); var enumerable = selector.GetEnumerable(root, binderMapInstance); var errorMessage = "子モデルのViewを指定した時はModelにバインドされていて、かつIEventHandlerを継承しているViewを全て取得できるようにしてください。"; var viewObj1 = binderMapInstance[recieverModel].ViewObjects.Where(_v => _v.UseBindInfo.ID.MainID == viewReciever).First(); var viewObj2 = binderMapInstance[noneRecieverModel].ViewObjects.Where(_v => _v.UseBindInfo.ID.MainID == viewReciever).First(); AssertionUtils.AssertEnumerableByUnordered(new object[] { viewObj1, viewObj2 }, enumerable, errorMessage); } {//Viewを取得しようとした時のテスト(一致しないViewID) //search root model => root //selector: Child, "", "__invalid" //result => (empty) var selector = new ModelViewSelector(ModelRelationShip.Child, "", "__invalid"); var enumerable = selector.GetEnumerable(root, binderMapInstance); var errorMessage = "指定したViewIdentityと一致ない時は何も取得できないようにしてください。"; Assert.IsFalse(enumerable.Any(), errorMessage); } {//Viewを取得しようとした時のテスト(クエリパスを指定した時) //search root model => root //selector: Child, "reciever", "reciever" //result => RecieverViewObj in reciever, var selector = new ModelViewSelector(ModelRelationShip.Child, recieverModel.Name, viewReciever); var enumerable = selector.GetEnumerable(root, binderMapInstance); var errorMessage = "クエリパスを伴う子モデルのViewを指定した時はクエリパスに一致しModelにバインドされていて、かつIEventHandlerを継承しているViewを全て取得できるようにしてください。"; var viewObj1 = binderMapInstance[recieverModel].ViewObjects.Where(_v => _v.UseBindInfo.ID.MainID == viewReciever).First(); AssertionUtils.AssertEnumerable((new IViewObject[] { viewObj1 }).OfType <IEventHandler>(), enumerable, errorMessage); } {//Viewを取得しようとした時のテスト(クエリパスを指定し、ViewIDが一致しない時) //search root model => root //selector: Child, "reciever", "__invalid" //result => (empty) var selector = new ModelViewSelector(ModelRelationShip.Child, recieverModel.Name, "__invalid"); var enumerable = selector.GetEnumerable(root, binderMapInstance); var errorMessage = "指定したViewIdentityと一致ない時は何も取得できないようにしてください。"; Assert.IsFalse(enumerable.Any(), errorMessage); } }