public void ExcludedSchemaTypeNames_ShouldReturnNamesOfDeselectedTypes()
        {
            using (var objectSelection = new SchemaTypesViewModel
            {
                SchemaTypes = new List <SchemaTypeModel>
                {
                    new SchemaTypeModel {
                        ShortName = "Type1", Name = "Test.Type1", IsSelected = false
                    },
                    new SchemaTypeModel {
                        ShortName = "Type2", Name = "Test.Type2", IsSelected = true
                    },
                    new SchemaTypeModel {
                        ShortName = "Type3", Name = "Test.Type3", IsSelected = false
                    }
                }
            })
            {
                var excluded = objectSelection.ExcludedSchemaTypeNames.ToList();

                excluded.ShouldBeEquivalentTo(new List <string> {
                    "Test.Type1", "Test.Type3"
                });
            }
        }
Esempio n. 2
0
        public override async Task <ConnectedServiceInstance> GetFinishedServiceInstanceAsync()
        {
            // ensure that the data has been loaded from wizard pages and saved to UserSettings
            if (Context.IsUpdating)
            {
                if (!OperationImportsViewModel.IsEntered)
                {
                    await OperationImportsViewModel.OnPageEnteringAsync(null).ConfigureAwait(false);

                    await OperationImportsViewModel.OnPageLeavingAsync(null).ConfigureAwait(false);
                }

                if (!SchemaTypesViewModel.IsEntered)
                {
                    await SchemaTypesViewModel.OnPageEnteringAsync(null).ConfigureAwait(false);

                    await SchemaTypesViewModel.OnPageLeavingAsync(null).ConfigureAwait(false);
                }

                if (!AdvancedSettingsViewModel.IsEntered)
                {
                    await AdvancedSettingsViewModel.OnPageEnteringAsync(null).ConfigureAwait(false);

                    await AdvancedSettingsViewModel.OnPageLeavingAsync(null).ConfigureAwait(false);
                }
            }

            UserSettings.Save();
            ServiceInstance.InstanceId           = UserSettings.GeneratedFileNamePrefix;
            ServiceInstance.Name                 = UserSettings.ServiceName;
            ServiceInstance.MetadataTempFilePath = ConfigODataEndpointViewModel.MetadataTempPath;
            ServiceInstance.ServiceConfig        = CreateServiceConfiguration();

            return(await Task.FromResult <ConnectedServiceInstance>(ServiceInstance).ConfigureAwait(false));
        }
        public void ClearBoundOperationList_ShouldResetBoundOperationsForTheSpecificTypeToAnEmptyList()
        {
            var schemaType = new SchemaTypeModel {
                ShortName = "Type1", Name = "Test.Type1", IsSelected = false, BoundOperations = new List <BoundOperationModel>
                {
                    new BoundOperationModel
                    {
                        Name       = "BoundOperation1(Test.Type1)",
                        IsSelected = false
                    }
                }
            };

            using (var objectSelection = new SchemaTypesViewModel
            {
                SchemaTypes = new List <SchemaTypeModel>
                {
                    schemaType,
                    new SchemaTypeModel {
                        ShortName = "Type2", Name = "Test.Type2", IsSelected = true
                    },
                    new SchemaTypeModel {
                        ShortName = "Type3", Name = "Test.Type3", IsSelected = false
                    }
                }
            })
            {
                objectSelection.ClearBoundOperationList(schemaType);

                objectSelection.SchemaTypes.FirstOrDefault(s => s.Name == "Test.Type1")?.BoundOperations.Should().BeEmpty();
            }
        }
Esempio n. 4
0
        public void SchemaTypeSelectionViewModel_PageLeaving(object sender, EventArgs args)
        {
            var model = EdmHelper.GetEdmModelFromFile(ConfigODataEndpointViewModel.MetadataTempPath);

            // exclude related operation imports for excluded types
            var operations          = EdmHelper.GetOperationImports(model);
            var operationsToExclude = operations.Where(x => !OperationImportsViewModel.IsOperationImportIncluded(x,
                                                                                                                 SchemaTypesViewModel.ExcludedSchemaTypeNames.ToList())).ToList();

            foreach (var operationImport in OperationImportsViewModel.OperationImports)
            {
                if (operationsToExclude.Any(x => x.Name == operationImport.Name))
                {
                    operationImport.IsSelected = false;
                }
            }

            // exclude bound operations for excluded types
            var boundOperations          = EdmHelper.GetBoundOperations(model);
            var boundOperationsToExclude = boundOperations.SelectMany(x => x.Value)
                                           .Where(x => !SchemaTypesViewModel.IsBoundOperationIncluded(x,
                                                                                                      SchemaTypesViewModel.ExcludedSchemaTypeNames.ToList())).ToList();

            foreach (var boundOperation in SchemaTypesViewModel.SchemaTypes.SelectMany(x => x.BoundOperations))
            {
                if (boundOperationsToExclude.Any(x => $"{x.Name}({x.Parameters.First().Type.Definition.FullTypeName()})" == boundOperation.Name))
                {
                    boundOperation.IsSelected = false;
                }
            }
        }
        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 DeselectAllSchemaTypes_ShouldMarkAllTypesAsNotSelected()
        {
            var objectSelection = new SchemaTypesViewModel
            {
                SchemaTypes = new List <SchemaTypeModel>
                {
                    new SchemaTypeModel {
                        ShortName = "Type1", Name = "Test.Type1", IsSelected = false
                    },
                    new SchemaTypeModel {
                        ShortName = "Type2", Name = "Test.Type2", IsSelected = true
                    },
                    new SchemaTypeModel {
                        ShortName = "Type3", Name = "Test.Type3", IsSelected = false
                    }
                }
            };

            objectSelection.DeselectAllSchemaTypes();

            objectSelection.SchemaTypes.ShouldBeEquivalentTo(new List <SchemaTypeModel>
            {
                new SchemaTypeModel {
                    ShortName = "Type1", Name = "Test.Type1", IsSelected = false
                },
                new SchemaTypeModel {
                    ShortName = "Type2", Name = "Test.Type2", IsSelected = false
                },
                new SchemaTypeModel {
                    ShortName = "Type3", Name = "Test.Type3", IsSelected = false
                }
            });
        }
        public void ExcludeBoundOperations_ShouldDeselectTheSpecifiedBoundOperations()
        {
            var schemaTypeModel = new SchemaTypeModel
            {
                ShortName       = "Type1",
                Name            = "Test.Type1",
                IsSelected      = true,
                BoundOperations = new List <BoundOperationModel>
                {
                    new BoundOperationModel
                    {
                        Name       = "BoundOperation1(Test.Type1)",
                        IsSelected = true
                    },
                    new BoundOperationModel
                    {
                        Name       = "BoundOperation2(Test.Type1)",
                        IsSelected = true
                    }
                }
            };

            using (var objectSelection = new SchemaTypesViewModel
            {
                SchemaTypes = new List <SchemaTypeModel>
                {
                    schemaTypeModel,
                    new SchemaTypeModel {
                        ShortName = "Type2", Name = "Test.Type2", IsSelected = true
                    },
                    new SchemaTypeModel {
                        ShortName = "Type3", Name = "Test.Type3", IsSelected = false
                    },
                    new SchemaTypeModel {
                        ShortName = "Type4", Name = "Test.Type4", IsSelected = true
                    }
                }
            })
            {
                objectSelection.ExcludeBoundOperations(schemaTypeModel, new string[] { "BoundOperation1(Test.Type1)" });

                schemaTypeModel.BoundOperations.ShouldAllBeEquivalentTo(new List <BoundOperationModel>
                {
                    new BoundOperationModel
                    {
                        Name       = "BoundOperation1(Test.Type1)",
                        IsSelected = false
                    },
                    new BoundOperationModel
                    {
                        Name       = "BoundOperation2(Test.Type1)",
                        IsSelected = true
                    }
                });
            }
        }
        public void DeselectAllBoundOperations_ShouldMarkBoundOperationsForAllTypesAsNotSelected()
        {
            using (var objectSelection = new SchemaTypesViewModel
            {
                SchemaTypes = new List <SchemaTypeModel>
                {
                    new SchemaTypeModel {
                        ShortName = "Type1", Name = "Test.Type1", IsSelected = false, BoundOperations = new List <BoundOperationModel>
                        {
                            new BoundOperationModel
                            {
                                Name = "BoundOperation1(Test.Type1)",
                                IsSelected = true
                            }
                        }
                    },
                    new SchemaTypeModel {
                        ShortName = "Type2", Name = "Test.Type2", IsSelected = true, BoundOperations = new List <BoundOperationModel>
                        {
                            new BoundOperationModel
                            {
                                Name = "BoundOperation2(Test.Type2)",
                                IsSelected = true
                            }
                        }
                    },
                    new SchemaTypeModel {
                        ShortName = "Type3", Name = "Test.Type3", IsSelected = false
                    }
                }
            })
            {
                objectSelection.DeselectAllBoundOperations();

                objectSelection.SchemaTypes.FirstOrDefault(s => s.Name == "Test.Type1")?.BoundOperations.ShouldAllBeEquivalentTo(new List <BoundOperationModel>
                {
                    new BoundOperationModel
                    {
                        Name       = "BoundOperation1(Test.Type1)",
                        IsSelected = false
                    }
                });
                objectSelection.SchemaTypes.FirstOrDefault(s => s.Name == "Test.Type2")?.BoundOperations.ShouldAllBeEquivalentTo(new List <BoundOperationModel>
                {
                    new BoundOperationModel
                    {
                        Name       = "BoundOperation2(Test.Type2)",
                        IsSelected = false
                    }
                });
            }
        }
        public void ExcludedBoundOperationsNames_ShouldReturnNamesOfDeselectedBoundOperationsOrderedByName()
        {
            using (var objectSelection = new SchemaTypesViewModel
            {
                SchemaTypes = new List <SchemaTypeModel>
                {
                    new SchemaTypeModel {
                        ShortName = "Type1", Name = "Test.Type1", IsSelected = false, BoundOperations = new List <BoundOperationModel>
                        {
                            new BoundOperationModel
                            {
                                Name = "BoundOperation1(Test.Type1)",
                                IsSelected = false
                            }
                        }
                    },
                    new SchemaTypeModel {
                        ShortName = "Type2", Name = "Test.Type2", IsSelected = true, BoundOperations = new List <BoundOperationModel>
                        {
                            new BoundOperationModel
                            {
                                Name = "BoundOperation2(Test.Type2)",
                                IsSelected = true
                            },
                            new BoundOperationModel
                            {
                                Name = "BoundOperation0(Test.Type2)",
                                IsSelected = false
                            }
                        }
                    },
                    new SchemaTypeModel {
                        ShortName = "Type3", Name = "Test.Type3", IsSelected = false, BoundOperations = new List <BoundOperationModel>
                        {
                            new BoundOperationModel
                            {
                                Name = "BoundOperation4(Test.Type3)",
                                IsSelected = true
                            }
                        }
                    }
                }
            })
            {
                var excluded = objectSelection.ExcludedBoundOperationsNames.ToList();

                excluded.ShouldBeEquivalentTo(new List <string> {
                    "BoundOperation0(Test.Type2)", "BoundOperation1(Test.Type1)"
                });
            }
        }
        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
                    }
                });
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Cleanup object references
        /// </summary>
        /// <param name="disposing"></param>
        protected override void Dispose(bool disposing)
        {
            try
            {
                if (disposing)
                {
                    if (AdvancedSettingsViewModel != null)
                    {
                        AdvancedSettingsViewModel.Dispose();
                        AdvancedSettingsViewModel = null;
                    }

                    if (OperationImportsViewModel != null)
                    {
                        OperationImportsViewModel.Dispose();
                        OperationImportsViewModel = null;
                    }

                    if (SchemaTypesViewModel != null)
                    {
                        SchemaTypesViewModel.Dispose();
                        SchemaTypesViewModel = null;
                    }

                    if (ConfigODataEndpointViewModel != null)
                    {
                        ConfigODataEndpointViewModel.Dispose();
                        ConfigODataEndpointViewModel = null;
                    }

                    if (serviceInstance != null)
                    {
                        serviceInstance.Dispose();
                        serviceInstance = null;
                    }
                }
            }
            finally
            {
                base.Dispose(disposing);
            }
        }
        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);
            }
        }
Esempio n. 14
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);
            }
        }
Esempio n. 16
0
        public ODataConnectedServiceWizard(ConnectedServiceProviderContext context)
        {
            this.Context      = context;
            this.UserSettings = UserSettings.Load(context?.Logger);

            // Since ServiceConfigurationV4 is a derived type of ServiceConfiguration. So we can deserialize a ServiceConfiguration into a ServiceConfigurationV4.
            this._serviceConfig = this.Context?.GetExtendedDesignerData <ServiceConfigurationV4>();

            ConfigODataEndpointViewModel = new ConfigODataEndpointViewModel(this.UserSettings, this);
            AdvancedSettingsViewModel    = new AdvancedSettingsViewModel(this.UserSettings);
            SchemaTypesViewModel         = new SchemaTypesViewModel(this.UserSettings);
            OperationImportsViewModel    = new OperationImportsViewModel(this.UserSettings);

            OperationImportsViewModel.PageEntering += OperationImportsViewModel_PageEntering;

            SchemaTypesViewModel.PageEntering += SchemaTypeSelectionViewModel_PageEntering;
            SchemaTypesViewModel.PageLeaving  += SchemaTypeSelectionViewModel_PageLeaving;
            if (this.Context != null && this.Context.IsUpdating)
            {
                ConfigODataEndpointViewModel.Endpoint          = this._serviceConfig?.Endpoint;
                ConfigODataEndpointViewModel.EdmxVersion       = this._serviceConfig?.EdmxVersion;
                ConfigODataEndpointViewModel.ServiceName       = this._serviceConfig?.ServiceName;
                ConfigODataEndpointViewModel.CustomHttpHeaders = this._serviceConfig?.CustomHttpHeaders;

                // Restore the main settings to UI elements.
                ConfigODataEndpointViewModel.PageEntering += ConfigODataEndpointViewModel_PageEntering;

                // The ViewModel should always be filled otherwise if the wizard is completed without visiting this page the generated code becomes wrong
                AdvancedSettingsViewModel_PageEntering(AdvancedSettingsViewModel, EventArgs.Empty);

                // Restore the advanced settings to UI elements.
                AdvancedSettingsViewModel.PageEntering += AdvancedSettingsViewModel_PageEntering;
            }

            this.Pages.Add(ConfigODataEndpointViewModel);
            this.Pages.Add(SchemaTypesViewModel);
            this.Pages.Add(OperationImportsViewModel);
            this.Pages.Add(AdvancedSettingsViewModel);
            this.IsFinishEnabled = true;
        }
        public void ClearSchemaTypes_ShouldResetSchemaTypesToAnEmptyCollection()
        {
            var objectSelection = new SchemaTypesViewModel
            {
                SchemaTypes = new List <SchemaTypeModel>
                {
                    new SchemaTypeModel {
                        ShortName = "Type1", Name = "Test.Type1", IsSelected = false
                    },
                    new SchemaTypeModel {
                        ShortName = "Type2", Name = "Test.Type2", IsSelected = true
                    },
                    new SchemaTypeModel {
                        ShortName = "Type3", Name = "Test.Type3", IsSelected = false
                    }
                }
            };

            objectSelection.ClearSchemaTypes();

            objectSelection.SchemaTypes.Count().Should().Be(0);
        }
        public void ExcludeSchemaTypes_ShouldDeselectTheSpecifiedTypes()
        {
            var objectSelection = new SchemaTypesViewModel
            {
                SchemaTypes = new List <SchemaTypeModel>
                {
                    new SchemaTypeModel {
                        ShortName = "Type1", Name = "Test.Type1", IsSelected = true
                    },
                    new SchemaTypeModel {
                        ShortName = "Type2", Name = "Test.Type2", IsSelected = true
                    },
                    new SchemaTypeModel {
                        ShortName = "Type3", Name = "Test.Type3", IsSelected = false
                    },
                    new SchemaTypeModel {
                        ShortName = "Type4", Name = "Test.Type4", IsSelected = true
                    }
                }
            };

            objectSelection.ExcludeSchemaTypes(new string[] { "Test.Type1", "Test.Type3", "Test.Type4" });

            objectSelection.SchemaTypes.ShouldBeEquivalentTo(new List <SchemaTypeModel>()
            {
                new SchemaTypeModel {
                    ShortName = "Type1", Name = "Test.Type1", IsSelected = false
                },
                new SchemaTypeModel {
                    ShortName = "Type2", Name = "Test.Type2", IsSelected = true
                },
                new SchemaTypeModel {
                    ShortName = "Type3", Name = "Test.Type3", IsSelected = false
                },
                new SchemaTypeModel {
                    ShortName = "Type4", Name = "Test.Type4", IsSelected = false
                }
            });
        }
Esempio n. 19
0
        public ODataConnectedServiceWizard(ConnectedServiceProviderContext context)
        {
            Context = context;
            // We only use most recently used endpoints from the config file saved in user's isolated storage
            // The UserSettings constructor will load those endpoints
            UserSettings = new UserSettings(context?.Logger);

            // Since ServiceConfigurationV4 is a derived type of ServiceConfiguration,
            // we can deserialize a ServiceConfiguration into a ServiceConfigurationV4.
            ServiceConfig = Context?.GetExtendedDesignerData <ServiceConfigurationV4>();

            ConfigODataEndpointViewModel = new ConfigODataEndpointViewModel(UserSettings);
            AdvancedSettingsViewModel    = new AdvancedSettingsViewModel(UserSettings);
            SchemaTypesViewModel         = new SchemaTypesViewModel(UserSettings);
            OperationImportsViewModel    = new OperationImportsViewModel(UserSettings);

            OperationImportsViewModel.PageEntering += OperationImportsViewModel_PageEntering;
            SchemaTypesViewModel.PageEntering      += SchemaTypeSelectionViewModel_PageEntering;
            SchemaTypesViewModel.PageLeaving       += SchemaTypeSelectionViewModel_PageLeaving;

            if (Context != null && Context.IsUpdating)
            {
                LoadUserSettingsFromServiceConfig();
                ConfigODataEndpointViewModel.EdmxVersion = ServiceConfig?.EdmxVersion;

                // Restore the main settings to UI elements.
                ConfigODataEndpointViewModel.PageEntering += ConfigODataEndpointViewModel_PageEntering;
                // The ViewModel should always be filled otherwise if the wizard is completed without visiting this page the generated code becomes wrong
                AdvancedSettingsViewModel_PageEntering(AdvancedSettingsViewModel, EventArgs.Empty);
                // Restore the advanced settings to UI elements.
                AdvancedSettingsViewModel.PageEntering += AdvancedSettingsViewModel_PageEntering;
            }

            Pages.Add(ConfigODataEndpointViewModel);
            Pages.Add(SchemaTypesViewModel);
            Pages.Add(OperationImportsViewModel);
            Pages.Add(AdvancedSettingsViewModel);
            IsFinishEnabled = 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
                            }
                        }
                    }
                });
            }
        }
        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 SelectAllBoundOperationsForSchemaType_ShouldMarkAllBoundOperationsForTheSpecificTypeAsSelected()
        {
            var schemaType = new SchemaTypeModel
            {
                ShortName       = "Type1",
                Name            = "Test.Type1",
                IsSelected      = false,
                BoundOperations = new List <BoundOperationModel>
                {
                    new BoundOperationModel
                    {
                        Name       = "BoundOperation1(Test.Type1)",
                        IsSelected = false
                    },
                    new BoundOperationModel
                    {
                        Name       = "BoundOperation2(Test.Type1)",
                        IsSelected = false
                    }
                }
            };

            using (var objectSelection = new SchemaTypesViewModel
            {
                SchemaTypes = new List <SchemaTypeModel>
                {
                    schemaType,
                    new SchemaTypeModel {
                        ShortName = "Type2", Name = "Test.Type2", IsSelected = true, BoundOperations = new List <BoundOperationModel>
                        {
                            new BoundOperationModel
                            {
                                Name = "BoundOperation3(Test.Type2)",
                                IsSelected = false
                            }
                        }
                    },
                    new SchemaTypeModel {
                        ShortName = "Type3", Name = "Test.Type3", IsSelected = false
                    }
                }
            })
            {
                objectSelection.SelectAllBoundOperationsForSchemaType(schemaType);

                objectSelection.SchemaTypes.FirstOrDefault(s => s.Name == "Test.Type1")?.BoundOperations.ShouldAllBeEquivalentTo(new List <BoundOperationModel>
                {
                    new BoundOperationModel
                    {
                        Name       = "BoundOperation1(Test.Type1)",
                        IsSelected = true
                    },
                    new BoundOperationModel
                    {
                        Name       = "BoundOperation2(Test.Type1)",
                        IsSelected = true
                    }
                });
                objectSelection.SchemaTypes.FirstOrDefault(s => s.Name == "Test.Type2")?.BoundOperations.ShouldAllBeEquivalentTo(new List <BoundOperationModel>
                {
                    new BoundOperationModel
                    {
                        Name       = "BoundOperation3(Test.Type2)",
                        IsSelected = false
                    }
                });
            }
        }
        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 ExcludeSchemaTypes_ShouldDeselectTheSpecifiedTypesWithSpecifiedBoundOperations()
        {
            using (var objectSelection = new SchemaTypesViewModel
            {
                SchemaTypes = new List <SchemaTypeModel>
                {
                    new SchemaTypeModel
                    {
                        ShortName = "Type1",
                        Name = "Test.Type1",
                        IsSelected = true,
                        BoundOperations = new List <BoundOperationModel>
                        {
                            new BoundOperationModel
                            {
                                IsSelected = true,
                                Name = "BoundOperation1(Type1)"
                            }
                        }
                    },
                    new SchemaTypeModel {
                        ShortName = "Type2", Name = "Test.Type2", IsSelected = true
                    },
                    new SchemaTypeModel {
                        ShortName = "Type3", Name = "Test.Type3", IsSelected = false
                    },
                    new SchemaTypeModel {
                        ShortName = "Type4", Name = "Test.Type4", IsSelected = true
                    }
                }
            })
            {
                objectSelection.ExcludeSchemaTypes(new string[] { "Test.Type1", "Test.Type3", "Test.Type4" }, new string[] { "BoundOperation1(Type1)" });

                objectSelection.SchemaTypes.ShouldBeEquivalentTo(new List <SchemaTypeModel>()
                {
                    new SchemaTypeModel
                    {
                        ShortName       = "Type1",
                        Name            = "Test.Type1",
                        IsSelected      = false,
                        BoundOperations = new List <BoundOperationModel>
                        {
                            new BoundOperationModel
                            {
                                IsSelected = false,
                                Name       = "BoundOperation1(Type1)"
                            }
                        }
                    },
                    new SchemaTypeModel {
                        ShortName = "Type2", Name = "Test.Type2", IsSelected = true
                    },
                    new SchemaTypeModel {
                        ShortName = "Type3", Name = "Test.Type3", IsSelected = false
                    },
                    new SchemaTypeModel {
                        ShortName = "Type4", Name = "Test.Type4", IsSelected = false
                    }
                });
            }
        }