public void DeselectSchemaType_ShouldDeselectItsRelatedTypes()
        {
            var objectSelection = new SchemaTypesViewModel
            {
                SchemaTypes = new List <SchemaTypeModel>()
            };

            var listToLoad = new List <IEdmSchemaType>
            {
                new EdmEntityType("Test", "EntityType", new EdmEntityType("Test", "BaseEntityType")),
                new EdmEntityType("Test", "BaseEntityType")
            };

            objectSelection.LoadSchemaTypes(listToLoad, new Dictionary <IEdmStructuredType, List <IEdmOperation> >());

            objectSelection.SchemaTypes.First(x => x.ShortName == "BaseEntityType").IsSelected = false;

            objectSelection.SchemaTypes.ShouldBeEquivalentTo(new List <SchemaTypeModel>
            {
                new SchemaTypeModel {
                    ShortName = "BaseEntityType", Name = "Test.BaseEntityType", IsSelected = false
                },
                new SchemaTypeModel {
                    ShortName = "EntityType", Name = "Test.EntityType", IsSelected = false
                }
            });
        }
        public void LoadSchemaTypes_ShouldSetAllSchemaTypesAsSelectedAndOrderedByName()
        {
            using (var objectSelection = new SchemaTypesViewModel
            {
                SchemaTypes = new List <SchemaTypeModel>
                {
                    new SchemaTypeModel {
                        Name = "Type1", IsSelected = false
                    },
                    new SchemaTypeModel {
                        Name = "Type2", IsSelected = true
                    },
                    new SchemaTypeModel {
                        Name = "Type3", IsSelected = false
                    }
                }
            })
            {
                var listToLoad = new List <IEdmSchemaType>
                {
                    new EdmEnumType("Test", "EnumType"),
                    new EdmComplexType("Test", "ComplexType"),
                    new EdmUntypedStructuredType("Test", "UntypedStructuredType"),
                    new EdmEntityType("Test", "EntityType"),
                    new EdmTypeDefinition("Test", "TypeDef", EdmPrimitiveTypeKind.Boolean)
                };

                objectSelection.LoadSchemaTypes(listToLoad, new Dictionary <IEdmType, List <IEdmOperation> >());

                objectSelection.SchemaTypes.ShouldBeEquivalentTo(new List <SchemaTypeModel>
                {
                    new SchemaTypeModel {
                        ShortName = "ComplexType", Name = "Test.ComplexType", IsSelected = true
                    },
                    new SchemaTypeModel {
                        ShortName = "EntityType", Name = "Test.EntityType", IsSelected = true
                    },
                    new SchemaTypeModel {
                        ShortName = "EnumType", Name = "Test.EnumType", IsSelected = true
                    },
                    new SchemaTypeModel {
                        ShortName = "TypeDef", Name = "Test.TypeDef", IsSelected = true
                    },
                    new SchemaTypeModel {
                        ShortName = "UntypedStructuredType", Name = "Test.UntypedStructuredType", IsSelected = true
                    }
                });
            }
        }
        public void SelectSchemaType_ShouldSelectItsRelatedTypes()
        {
            using (var objectSelection = new SchemaTypesViewModel
            {
                SchemaTypes = new List <SchemaTypeModel>
                {
                    new SchemaTypeModel {
                        Name = "Type1", IsSelected = false
                    },
                    new SchemaTypeModel {
                        Name = "Type2", IsSelected = true
                    },
                    new SchemaTypeModel {
                        Name = "Type3", IsSelected = false
                    }
                }
            })
            {
                var relatedEntityType = new EdmEntityType("Test", "RelatedEntityType");
                var listToLoad        = new List <IEdmSchemaType>
                {
                    relatedEntityType,
                    new EdmComplexType("Test", "ComplexType", new EdmComplexType("Test", "BaseComplexType")),
                    new EdmEntityType("Test", "EntityType", relatedEntityType)
                };

                objectSelection.LoadSchemaTypes(listToLoad, new Dictionary <IEdmType, List <IEdmOperation> >());
                objectSelection.DeselectAllSchemaTypes();

                objectSelection.SchemaTypes.First(x => x.ShortName == "EntityType").IsSelected = true;

                objectSelection.SchemaTypes.ShouldBeEquivalentTo(new List <SchemaTypeModel>
                {
                    new SchemaTypeModel {
                        ShortName = "ComplexType", Name = "Test.ComplexType", IsSelected = false
                    },
                    new SchemaTypeModel {
                        ShortName = "EntityType", Name = "Test.EntityType", IsSelected = true
                    },
                    new SchemaTypeModel {
                        ShortName = "RelatedEntityType", Name = "Test.RelatedEntityType", IsSelected = true
                    }
                });
            }
        }
        public void LoadSchemaTypes_ShouldAddRelatedTypesForStructuredTypesWithBaseType()
        {
            using (var objectSelection = new SchemaTypesViewModel
            {
                SchemaTypes = new List <SchemaTypeModel>
                {
                    new SchemaTypeModel {
                        Name = "Type1", IsSelected = false
                    },
                    new SchemaTypeModel {
                        Name = "Type2", IsSelected = true
                    },
                    new SchemaTypeModel {
                        Name = "Type3", IsSelected = false
                    }
                }
            })
            {
                var listToLoad = new List <IEdmSchemaType>
                {
                    new EdmComplexType("Test", "ComplexType", new EdmComplexType("Test", "BaseComplexType")),
                    new EdmEntityType("Test", "EntityType", new EdmEntityType("Test", "BaseEntityType")),
                    new EdmEnumType("Test", "EnumType"),
                    new EdmTypeDefinition("Test", "TypeDef", EdmPrimitiveTypeKind.Boolean),
                    new EdmUntypedStructuredType("Test", "UntypedStructuredType")
                };

                objectSelection.LoadSchemaTypes(listToLoad, new Dictionary <IEdmType, List <IEdmOperation> >());

                var expectedRelatedTypes = new Dictionary <string, ICollection <string> >
                {
                    { "Test.BaseComplexType", new List <string> {
                          "Test.ComplexType"
                      } },
                    { "Test.BaseEntityType", new List <string> {
                          "Test.EntityType"
                      } },
                };

                objectSelection.RelatedTypes.ShouldBeEquivalentTo(expectedRelatedTypes);
            }
        }
Exemple #5
0
        public void SchemaTypeSelectionViewModel_PageEntering(object sender, EventArgs args)
        {
            if (sender is SchemaTypesViewModel entityTypeViewModel)
            {
                if (this.ProcessedEndpointForSchemaTypes != ConfigODataEndpointViewModel.Endpoint)
                {
                    var model           = EdmHelper.GetEdmModelFromFile(ConfigODataEndpointViewModel.MetadataTempPath);
                    var entityTypes     = EdmHelper.GetSchemaTypes(model);
                    var boundOperations = EdmHelper.GetBoundOperations(model);
                    SchemaTypesViewModel.LoadSchemaTypes(entityTypes, boundOperations);

                    if (Context.IsUpdating)
                    {
                        entityTypeViewModel.ExcludeSchemaTypes(this._serviceConfig?.ExcludedSchemaTypes ?? Enumerable.Empty <string>());
                    }
                }

                this.ProcessedEndpointForSchemaTypes = ConfigODataEndpointViewModel.Endpoint;
            }
        }
        public void LoadSchemaTypes_ShouldAddRelatedPropertyTypeForStructuredType_WherePropertyIsCollectionOfEnum()
        {
            using (var objectSelection = new SchemaTypesViewModel
            {
                SchemaTypes = new List <SchemaTypeModel>
                {
                    new SchemaTypeModel {
                        Name = "Type1", IsSelected = false
                    },
                    new SchemaTypeModel {
                        Name = "Type2", IsSelected = true
                    },
                    new SchemaTypeModel {
                        Name = "Type3", IsSelected = false
                    }
                }
            })
            {
                var enumType   = new EdmEnumType("Test", "EnumType");
                var entityType = new EdmEntityType("Test", "EntityType");
                entityType.AddStructuralProperty("collectionOfEnumProperty",
                                                 new EdmCollectionTypeReference(
                                                     new EdmCollectionType(new EdmEnumTypeReference(enumType, false))));
                var listToLoad = new List <IEdmSchemaType>
                {
                    entityType,
                    enumType
                };

                objectSelection.LoadSchemaTypes(listToLoad, new Dictionary <IEdmType, List <IEdmOperation> >());

                var expectedRelatedTypes = new Dictionary <string, ICollection <string> >
                {
                    { "Test.EnumType", new List <string> {
                          "Test.EntityType"
                      } },
                };

                objectSelection.RelatedTypes.ShouldBeEquivalentTo(expectedRelatedTypes);
            }
        }
        public void DeselectSchemaType_ShouldDeselectItsBoundOperations()
        {
            using (var objectSelection = new SchemaTypesViewModel
            {
                SchemaTypes = new List <SchemaTypeModel>()
            })
            {
                var schemaType = new EdmEntityType("Test", "BaseEntityType");
                var listToLoad = new List <IEdmSchemaType>
                {
                    new EdmEntityType("Test", "EntityType", new EdmEntityType("Test", "BaseEntityType")),
                    schemaType
                };

                var boundOperation1 = new EdmAction("Test", "BoundOperation1",
                                                    new EdmPrimitiveTypeReference(new EdmPrimitiveType(EdmPrimitiveTypeKind.Boolean), false), true,
                                                    new EdmPathExpression(string.Empty));
                boundOperation1.AddParameter("value",
                                             new EdmEntityTypeReference(schemaType, false));

                var boundOperation2 = new EdmAction("Test", "BoundOperation2",
                                                    new EdmPrimitiveTypeReference(new EdmPrimitiveType(EdmPrimitiveTypeKind.Boolean), false), true,
                                                    new EdmPathExpression(string.Empty));
                boundOperation2.AddParameter("value",
                                             new EdmEntityTypeReference(schemaType, false));

                objectSelection.LoadSchemaTypes(listToLoad, new Dictionary <IEdmType, List <IEdmOperation> >
                {
                    {
                        schemaType, new List <IEdmOperation>
                        {
                            boundOperation1,
                            boundOperation2
                        }
                    }
                });

                objectSelection.SchemaTypes.ShouldBeEquivalentTo(new List <SchemaTypeModel>
                {
                    new SchemaTypeModel {
                        ShortName = "BaseEntityType", Name = "Test.BaseEntityType", IsSelected = true, BoundOperations = new List <BoundOperationModel>
                        {
                            new BoundOperationModel
                            {
                                Name       = "BoundOperation1(Test.BaseEntityType)",
                                ShortName  = "BoundOperation1",
                                IsSelected = true
                            },
                            new BoundOperationModel
                            {
                                Name       = "BoundOperation2(Test.BaseEntityType)",
                                ShortName  = "BoundOperation2",
                                IsSelected = true
                            }
                        }
                    },
                    new SchemaTypeModel {
                        ShortName = "EntityType", Name = "Test.EntityType", IsSelected = true, BoundOperations = new List <BoundOperationModel>()
                    }
                });

                objectSelection.SchemaTypes.First(x => x.ShortName == "BaseEntityType").IsSelected = false;

                objectSelection.SchemaTypes.ShouldBeEquivalentTo(new List <SchemaTypeModel>
                {
                    new SchemaTypeModel {
                        ShortName = "BaseEntityType", Name = "Test.BaseEntityType", IsSelected = false, BoundOperations = new List <BoundOperationModel>
                        {
                            new BoundOperationModel
                            {
                                Name       = "BoundOperation1(Test.BaseEntityType)",
                                ShortName  = "BoundOperation1",
                                IsSelected = false
                            },
                            new BoundOperationModel
                            {
                                Name       = "BoundOperation2(Test.BaseEntityType)",
                                ShortName  = "BoundOperation2",
                                IsSelected = false
                            }
                        }
                    },
                    new SchemaTypeModel {
                        ShortName = "EntityType", Name = "Test.EntityType", IsSelected = false, BoundOperations = new List <BoundOperationModel>()
                    }
                });
            }
        }
        public void SelectBoundOperation_ShouldSelectItsRequiredType()
        {
            using (var objectSelection = new SchemaTypesViewModel
            {
                SchemaTypes = new List <SchemaTypeModel>
                {
                    new SchemaTypeModel {
                        Name = "Type1", IsSelected = false
                    },
                    new SchemaTypeModel {
                        Name = "Type2", IsSelected = true
                    },
                    new SchemaTypeModel {
                        Name = "Type3", IsSelected = false
                    }
                }
            })
            {
                var relatedEntityType = new EdmEntityType("Test", "RelatedEntityType");
                var listToLoad        = new List <IEdmSchemaType>
                {
                    relatedEntityType,
                    new EdmComplexType("Test", "ComplexType", new EdmComplexType("Test", "BaseComplexType")),
                    new EdmEntityType("Test", "EntityType", relatedEntityType)
                };

                var boundOperation = new EdmAction("Test", "BoundOperation",
                                                   new EdmPrimitiveTypeReference(new EdmPrimitiveType(EdmPrimitiveTypeKind.Boolean), false), true,
                                                   new EdmPathExpression(string.Empty));
                boundOperation.AddParameter("relatedEntityTypeParameter",
                                            new EdmEntityTypeReference(relatedEntityType, false));

                objectSelection.LoadSchemaTypes(listToLoad, new Dictionary <IEdmType, List <IEdmOperation> >
                {
                    {
                        relatedEntityType, new List <IEdmOperation>
                        {
                            boundOperation
                        }
                    }
                });
                objectSelection.DeselectAllSchemaTypes();

                objectSelection.SchemaTypes.FirstOrDefault(x => x.ShortName == "RelatedEntityType")?.IsSelected.Should()
                .BeFalse();
                objectSelection.SchemaTypes.First(x => x.ShortName == "RelatedEntityType").BoundOperations
                .First().IsSelected = true;
                objectSelection.SchemaTypes.FirstOrDefault(x => x.ShortName == "RelatedEntityType")?.IsSelected.Should()
                .BeTrue();

                objectSelection.SchemaTypes.ShouldBeEquivalentTo(new List <SchemaTypeModel>
                {
                    new SchemaTypeModel
                    {
                        ShortName       = "ComplexType", Name = "Test.ComplexType", IsSelected = false,
                        BoundOperations = new List <BoundOperationModel>()
                    },
                    new SchemaTypeModel
                    {
                        ShortName       = "EntityType", Name = "Test.EntityType", IsSelected = false,
                        BoundOperations = new List <BoundOperationModel>()
                    },
                    new SchemaTypeModel
                    {
                        ShortName       = "RelatedEntityType", Name = "Test.RelatedEntityType", IsSelected = true,
                        BoundOperations = new List <BoundOperationModel>
                        {
                            new BoundOperationModel
                            {
                                Name       = "BoundOperation(Test.RelatedEntityType)",
                                ShortName  = "BoundOperation",
                                IsSelected = true
                            }
                        }
                    }
                });
            }
        }
        public void FillingSearchText_ShouldFilterSchemaTypes()
        {
            using (var objectSelection = new SchemaTypesViewModel
            {
                SchemaTypes = new List <SchemaTypeModel>()
            })
            {
                var entityTypeWithBoundOperation = new EdmEntityType("Test", "WithBoundOperationEntityType");
                var boundOperation = new EdmAction("Test", "Enter",
                                                   new EdmPrimitiveTypeReference(new EdmPrimitiveType(EdmPrimitiveTypeKind.Boolean), false), true,
                                                   new EdmPathExpression(string.Empty));

                var listToLoad = new List <IEdmSchemaType>
                {
                    new EdmEntityType("Test", "EntityType", new EdmEntityType("Test", "BaseEntityType")),
                    new EdmEntityType("Test", "BaseEntityType"),
                    entityTypeWithBoundOperation
                };

                objectSelection.LoadSchemaTypes(listToLoad, new Dictionary <IEdmType, List <IEdmOperation> >
                {
                    {
                        entityTypeWithBoundOperation, new List <IEdmOperation>
                        {
                            boundOperation
                        }
                    }
                });

                objectSelection.FilteredSchemaTypes.ShouldBeEquivalentTo(new List <SchemaTypeModel>
                {
                    new SchemaTypeModel {
                        ShortName = "BaseEntityType", Name = "Test.BaseEntityType", IsSelected = true
                    },
                    new SchemaTypeModel {
                        ShortName = "EntityType", Name = "Test.EntityType", IsSelected = true
                    },
                    new SchemaTypeModel
                    {
                        ShortName       = "WithBoundOperationEntityType",
                        Name            = "Test.WithBoundOperationEntityType",
                        IsSelected      = true,
                        BoundOperations = new List <BoundOperationModel> {
                            new BoundOperationModel
                            {
                                Name       = "Enter(Test.WithBoundOperationEntityType)",
                                ShortName  = "Enter",
                                IsSelected = true
                            }
                        }
                    }
                });

                objectSelection.SearchText = "e";

                objectSelection.FilteredSchemaTypes.ShouldBeEquivalentTo(new List <SchemaTypeModel>
                {
                    new SchemaTypeModel {
                        ShortName = "EntityType", Name = "Test.EntityType", IsSelected = true
                    },
                    new SchemaTypeModel
                    {
                        ShortName       = "WithBoundOperationEntityType",
                        Name            = "Test.WithBoundOperationEntityType",
                        IsSelected      = true,
                        BoundOperations = new List <BoundOperationModel> {
                            new BoundOperationModel
                            {
                                Name       = "Enter(Test.WithBoundOperationEntityType)",
                                ShortName  = "Enter",
                                IsSelected = true
                            }
                        }
                    }
                });

                objectSelection.SearchText = "wrong";

                objectSelection.FilteredSchemaTypes.ShouldBeEquivalentTo(new List <SchemaTypeModel>());

                objectSelection.SearchText = string.Empty;

                objectSelection.FilteredSchemaTypes.ShouldBeEquivalentTo(new List <SchemaTypeModel>
                {
                    new SchemaTypeModel {
                        ShortName = "BaseEntityType", Name = "Test.BaseEntityType", IsSelected = true
                    },
                    new SchemaTypeModel {
                        ShortName = "EntityType", Name = "Test.EntityType", IsSelected = true
                    },
                    new SchemaTypeModel
                    {
                        ShortName       = "WithBoundOperationEntityType",
                        Name            = "Test.WithBoundOperationEntityType",
                        IsSelected      = true,
                        BoundOperations = new List <BoundOperationModel> {
                            new BoundOperationModel
                            {
                                Name       = "Enter(Test.WithBoundOperationEntityType)",
                                ShortName  = "Enter",
                                IsSelected = true
                            }
                        }
                    }
                });
            }
        }