public void Init() { userSettings = new UserSettings(); serviceWizard = new ODataConnectedServiceWizard(null); configOdataEndPointViewModel = new ConfigODataEndpointViewModel(userSettings, serviceWizard); CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture; }
public void TestDisableReaOonlyFieldsWhenUpdating() { ServiceConfigurationV4 savedConfig = GetTestConfig(); var context = new TestConnectedServiceProviderContext(true, savedConfig); var wizard = new ODataConnectedServiceWizard(context); // endpoint page var endpointPage = wizard.ConfigODataEndpointViewModel; endpointPage.OnPageEnteringAsync(new WizardEnteringArgs(null)).Wait(); var endpointView = endpointPage.View as ConfigODataEndpoint; Assert.False(endpointView.ServiceName.IsEnabled); Assert.False(endpointView.Endpoint.IsEnabled); Assert.False(endpointView.OpenConnectedServiceJsonFileButton.IsEnabled); // if endpoint is a http address, then file dialog should be disabled savedConfig.Endpoint = "http://service"; endpointPage.OnPageEnteringAsync(null).Wait(); Assert.False(endpointView.OpenEndpointFileButton.IsEnabled); // advanced settings page var advancedPage = wizard.AdvancedSettingsViewModel; advancedPage.OnPageEnteringAsync(new WizardEnteringArgs(endpointPage)).Wait(); var advancedView = advancedPage.View as AdvancedSettings; Assert.False(advancedView.IncludeT4File.IsEnabled); Assert.False(advancedView.GenerateMultipleFiles.IsEnabled); }
public ConfigODataEndpointViewModel(UserSettings userSettings, ODataConnectedServiceWizard serviceWizard) : base() { this.Title = "Configure endpoint"; this.Description = "Enter or choose an OData service endpoint to begin"; this.Legend = "Endpoint"; this.ServiceWizard = serviceWizard; this.UserSettings = userSettings; this.ServiceName = Constants.DefaultServiceName; }
private void UserControl_Loaded(object sender, RoutedEventArgs e) { ODataConnectedServiceWizard connectedServiceWizard = GetODataConnectedServiceWizard(); UserSettings = connectedServiceWizard.UserSettings; if (Endpoint.Items.Count > 0 && !connectedServiceWizard.Context.IsUpdating) { Endpoint.SelectedItem = Endpoint.Items[0]; } }
public void TestLoadUserSettingsWhenWizardIsCreated() { var settings = new UserSettings(); settings.ServiceName = "Some Service"; settings.MruEndpoints.Add("Endpoint"); settings.Save(); var context = new TestConnectedServiceProviderContext(); var wizard = new ODataConnectedServiceWizard(context); Assert.Equal("Some Service", wizard.UserSettings.ServiceName); Assert.Contains("Endpoint", wizard.UserSettings.MruEndpoints); }
public void GetFinishedServiceInstanceAsync_WhenUpdating_ShouldUseSavedConfigWhenUserDoesNotVisitPages() { var savedConfig = GetTestConfig(); savedConfig.Endpoint = MetadataPath; var context = new TestConnectedServiceProviderContext(true, savedConfig); var wizard = new ODataConnectedServiceWizard(context); var endpointPage = wizard.ConfigODataEndpointViewModel; endpointPage.OnPageEnteringAsync(null).Wait(); endpointPage.OnPageLeavingAsync(null).Wait(); var serviceInstance = wizard.GetFinishedServiceInstanceAsync().Result as ODataConnectedServiceInstance; var config = serviceInstance.ServiceConfig as ServiceConfigurationV4; Assert.Equal("GeneratedCode", serviceInstance.InstanceId); Assert.Equal("MyService", serviceInstance.Name); Assert.NotNull(serviceInstance.MetadataTempFilePath); Assert.Equal("MyService", config.ServiceName); Assert.Equal(MetadataPath, config.Endpoint); Assert.Equal(Constants.EdmxVersion4, config.EdmxVersion); Assert.True(config.IncludeCustomHeaders); Assert.Equal("Key1:Val1\nKey2:Val2", config.CustomHttpHeaders); Assert.True(config.IncludeWebProxy); Assert.Equal("http://localhost:8080", config.WebProxyHost); Assert.True(config.IncludeWebProxyNetworkCredentials); Assert.Equal("domain", config.WebProxyNetworkCredentialsDomain); Assert.Null(config.WebProxyNetworkCredentialsUsername); Assert.Null(config.WebProxyNetworkCredentialsPassword); config.ExcludedOperationImports.ShouldBeEquivalentTo(new List <string>() { "GetPersonWithMostFriends", "ResetDataSource" }); config.ExcludedSchemaTypes.ShouldBeEquivalentTo(new List <string>() { "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Employee", "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person", "Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender" }); Assert.Equal("GeneratedCode", config.GeneratedFileNamePrefix); Assert.True(config.UseNamespacePrefix); Assert.Equal("Namespace", config.NamespacePrefix); Assert.True(config.EnableNamingAlias); Assert.True(config.MakeTypesInternal); Assert.True(config.IncludeT4File); Assert.True(config.GenerateMultipleFiles); Assert.True(config.OpenGeneratedFilesInIDE); }
public void ShouldDeselectOperations_WhenRelatedTypeIsDeselectedBefore() { var context = new TestConnectedServiceProviderContext(); var wizard = new ODataConnectedServiceWizard(context); var endpointPage = wizard.ConfigODataEndpointViewModel; endpointPage.OnPageEnteringAsync(null).Wait(); endpointPage.Endpoint = MetadataPath; endpointPage.OnPageLeavingAsync(null).Wait(); var typesPage = wizard.SchemaTypesViewModel; typesPage.OnPageEnteringAsync(null).Wait(); typesPage.SchemaTypes.First(t => t.ShortName == "Airport").IsSelected = false; typesPage.SchemaTypes.First(t => t.ShortName == "Person").IsSelected = false; typesPage.OnPageLeavingAsync(null).Wait(); var operationsPage = wizard.OperationImportsViewModel; operationsPage.OnPageEnteringAsync(null).Wait(); operationsPage.OperationImports.First(o => o.Name == "GetNearestAirport").IsSelected.Should().BeFalse(); operationsPage.OperationImports.First(o => o.Name == "GetPersonWithMostFriends").IsSelected.Should().BeFalse(); operationsPage.OnPageLeavingAsync(null).Wait(); var serviceInstance = wizard.GetFinishedServiceInstanceAsync().Result as ODataConnectedServiceInstance; var config = serviceInstance?.ServiceConfig as ServiceConfigurationV4; config?.ExcludedOperationImports.ShouldBeEquivalentTo(new List <string> { "GetNearestAirport", "GetPersonWithMostFriends" }); config?.ExcludedSchemaTypes.ShouldBeEquivalentTo(new List <string> { "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport", "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Employee", "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Flight", "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person" }); }
public void UnsupportedFeaturesAreDisabledOrHidden_WhenServiceIsV3OrLess() { var context = new TestConnectedServiceProviderContext(); var wizard = new ODataConnectedServiceWizard(context); var endpointPage = wizard.ConfigODataEndpointViewModel; endpointPage.Endpoint = MetadataPathV3; endpointPage.OnPageLeavingAsync(null).Wait(); Assert.Equal(Constants.EdmxVersion1, endpointPage.EdmxVersion); var operationsPage = wizard.OperationImportsViewModel; operationsPage.OnPageEnteringAsync(null).Wait(); Assert.False(operationsPage.View.IsEnabled); Assert.False(operationsPage.IsSupportedODataVersion); var advancedPage = wizard.AdvancedSettingsViewModel; advancedPage.OnPageEnteringAsync(null).Wait(); var advancedView = advancedPage.View as AdvancedSettings; advancedView.settings.RaiseEvent(new RoutedEventArgs(Hyperlink.ClickEvent)); Assert.Equal(Visibility.Hidden, advancedView.AdvancedSettingsForv4.Visibility); }
private void OpenConnectedServiceJsonFileButton_Click(object sender, RoutedEventArgs e) { var fileDialogTitle = "Open OData Connected Service Config File"; var openFileDialog = new Win32.OpenFileDialog { DefaultExt = ".json", Filter = "JSON File (.json)|*.json", Title = fileDialogTitle }; if (!(openFileDialog.ShowDialog() == true)) // Result of ShowDialog() call is bool? { return; } if (!File.Exists(openFileDialog.FileName)) { MessageBox.Show( $"File \"{openFileDialog.FileName}\" does not exists.", string.Format(CultureInfo.InvariantCulture, fileDialogTitle), MessageBoxButton.OK, MessageBoxImage.Warning); return; } var jsonFileText = File.ReadAllText(openFileDialog.FileName); if (string.IsNullOrWhiteSpace(jsonFileText)) { MessageBox.Show("Config file is empty.", string.Format(CultureInfo.InvariantCulture, fileDialogTitle), MessageBoxButton.OK, MessageBoxImage.Warning); return; } ConnectedServiceJsonFileData connectedServiceData; try { connectedServiceData = JsonConvert.DeserializeObject <ConnectedServiceJsonFileData>(jsonFileText); } catch (JsonException ex) { System.Diagnostics.Debug.Assert(ex != null); MessageBox.Show( "Contents of the config file could not be deserialized.", string.Format(CultureInfo.InvariantCulture, fileDialogTitle), MessageBoxButton.OK, MessageBoxImage.Warning); return; } // connectedServiceData not expected to be null at this point if (connectedServiceData.ExtendedData != null) { this.UserSettings.CopyPropertiesFrom(connectedServiceData.ExtendedData); } ODataConnectedServiceWizard connectedServiceWizard = GetODataConnectedServiceWizard(); // get Operation Imports and bound operations from metadata for excluding ExcludedOperationImports and ExcludedBoundOperations try { connectedServiceWizard.ConfigODataEndpointViewModel.MetadataTempPath = connectedServiceWizard.ConfigODataEndpointViewModel.GetMetadata(out var version); connectedServiceWizard.ConfigODataEndpointViewModel.EdmxVersion = version; if (version == Constants.EdmxVersion4) { Edm.IEdmModel model = EdmHelper.GetEdmModelFromFile(connectedServiceWizard.ConfigODataEndpointViewModel.MetadataTempPath); IEnumerable <Edm.IEdmSchemaType> entityTypes = EdmHelper.GetSchemaTypes(model); IDictionary <Edm.IEdmType, List <Edm.IEdmOperation> > boundOperations = EdmHelper.GetBoundOperations(model); connectedServiceWizard.SchemaTypesViewModel.LoadSchemaTypes(entityTypes, boundOperations); connectedServiceWizard.ProcessedEndpointForSchemaTypes = this.UserSettings.Endpoint; connectedServiceWizard.SchemaTypesViewModel.LoadFromUserSettings(); IEnumerable <Edm.IEdmOperationImport> operations = EdmHelper.GetOperationImports(model); connectedServiceWizard.OperationImportsViewModel.LoadOperationImports(operations, new HashSet <string>(), new Dictionary <string, SchemaTypeModel>()); connectedServiceWizard.ProcessedEndpointForOperationImports = this.UserSettings.Endpoint; connectedServiceWizard.OperationImportsViewModel.LoadFromUserSettings(); } } catch { // ignored } }
public void ShouldReloadOperationsAndTypesForNewEndpoint_WhenEndpointIsChangedBeforeFinishing() { var context = new TestConnectedServiceProviderContext(); var wizard = new ODataConnectedServiceWizard(context); var endpointPage = wizard.ConfigODataEndpointViewModel; endpointPage.OnPageEnteringAsync(null).Wait(); endpointPage.Endpoint = MetadataPath; endpointPage.OnPageLeavingAsync(null).Wait(); var typesPage = wizard.SchemaTypesViewModel; typesPage.OnPageEnteringAsync(null).Wait(); typesPage.SchemaTypes.FirstOrDefault(t => t.ShortName == "Employee").IsSelected = false; typesPage.OnPageLeavingAsync(null).Wait(); var operationsPage = wizard.OperationImportsViewModel; operationsPage.OnPageEnteringAsync(null).Wait(); operationsPage.OperationImports.FirstOrDefault(o => o.Name == "GetNearestAirport").IsSelected = false; operationsPage.OnPageLeavingAsync(null).Wait(); // go back to first page and change endpoint endpointPage.OnPageEnteringAsync(null).Wait(); endpointPage.Endpoint = MetadataPathSimple; endpointPage.OnPageLeavingAsync(null).Wait(); typesPage.OnPageEnteringAsync(null).Wait(); typesPage.SchemaTypes.ShouldBeEquivalentTo(new List <SchemaTypeModel>() { new SchemaTypeModel("SimpleService.Models.OtherThing", "OtherThing") { IsSelected = true }, new SchemaTypeModel("SimpleService.Models.Thing", "Thing") { IsSelected = true } }); typesPage.SchemaTypes.FirstOrDefault(t => t.ShortName == "OtherThing").IsSelected = false; typesPage.OnPageLeavingAsync(null).Wait(); operationsPage.OnPageEnteringAsync(null).Wait(); operationsPage.OperationImports.ShouldBeEquivalentTo(new List <OperationImportModel>() { new OperationImportModel() { Name = "GetRandomThing", IsSelected = true }, new OperationImportModel() { Name = "ResetThings", IsSelected = true } }); operationsPage.OperationImports.FirstOrDefault(o => o.Name == "ResetThings").IsSelected = false; var serviceInstance = wizard.GetFinishedServiceInstanceAsync().Result as ODataConnectedServiceInstance; var config = serviceInstance.ServiceConfig as ServiceConfigurationV4; Assert.Equal(MetadataPathSimple, config.Endpoint); config.ExcludedOperationImports.ShouldBeEquivalentTo(new List <string>() { "ResetThings" }); config.ExcludedSchemaTypes.ShouldBeEquivalentTo(new List <string>() { "SimpleService.Models.OtherThing" }); }
public void ShouldPreserveState_WhenMovingBetweenPagesAndBack_WhenUpdating() { var savedConfig = GetTestConfig(); savedConfig.Endpoint = MetadataPath; var context = new TestConnectedServiceProviderContext(true, savedConfig); var wizard = new ODataConnectedServiceWizard(context); var endpointPage = wizard.ConfigODataEndpointViewModel; endpointPage.OnPageEnteringAsync(null).Wait(); endpointPage.OnPageLeavingAsync(null).Wait(); var typesPage = wizard.SchemaTypesViewModel; typesPage.OnPageEnteringAsync(null).Wait(); var typeGender = typesPage.SchemaTypes.FirstOrDefault(t => t.ShortName == "PersonGender"); Assert.False(typeGender.IsSelected); typeGender.IsSelected = true; var typePerson = typesPage.SchemaTypes.FirstOrDefault(t => t.ShortName == "Person"); Assert.False(typePerson.IsSelected); typesPage.OnPageLeavingAsync(null).Wait(); var operationsPage = wizard.OperationImportsViewModel; operationsPage.OnPageEnteringAsync(null).Wait(); var operationNearestAirport = operationsPage.OperationImports.FirstOrDefault(o => o.Name == "GetNearestAirport"); Assert.True(operationNearestAirport.IsSelected); operationNearestAirport.IsSelected = false; operationsPage.OnPageLeavingAsync(null).Wait(); var advancedPage = wizard.AdvancedSettingsViewModel; advancedPage.OnPageEnteringAsync(null).Wait(); advancedPage.UseDataServiceCollection = true; advancedPage.MakeTypesInternal = true; advancedPage.UseNamespacePrefix = true; advancedPage.OnPageLeavingAsync(null).Wait(); endpointPage.OnPageEnteringAsync(null).Wait(); Assert.Equal(savedConfig.ServiceName, endpointPage.ServiceName); Assert.Equal(savedConfig.Endpoint, endpointPage.Endpoint); endpointPage.IncludeCustomHeaders = true; endpointPage.CustomHttpHeaders = "A:b"; endpointPage.OnPageLeavingAsync(null).Wait(); advancedPage.OnPageEnteringAsync(null).Wait(); Assert.True(advancedPage.UseNamespacePrefix); Assert.True(advancedPage.UseDataServiceCollection); Assert.True(advancedPage.MakeTypesInternal); advancedPage.NamespacePrefix = "MyNamespace"; advancedPage.GenerateMultipleFiles = true; advancedPage.UseDataServiceCollection = false; advancedPage.OnPageLeavingAsync(null).Wait(); operationsPage.OnPageEnteringAsync(null).Wait(); operationNearestAirport = operationsPage.OperationImports.FirstOrDefault(o => o.Name == "GetNearestAirport"); Assert.False(operationNearestAirport.IsSelected); var operationResetDataSource = operationsPage.OperationImports.FirstOrDefault(o => o.Name == "ResetDataSource"); Assert.False(operationResetDataSource.IsSelected); operationResetDataSource.IsSelected = true; operationsPage.OnPageLeavingAsync(null).Wait(); typesPage.OnPageEnteringAsync(null).Wait(); typeGender = typesPage.SchemaTypes.FirstOrDefault(t => t.ShortName == "PersonGender"); Assert.True(typeGender.IsSelected); var typeFlight = typesPage.SchemaTypes.FirstOrDefault(t => t.ShortName == "Flight"); typeFlight.IsSelected = false; typePerson = typesPage.SchemaTypes.FirstOrDefault(t => t.ShortName == "Person"); Assert.False(typePerson.IsSelected); typesPage.OnPageLeavingAsync(null).Wait(); var serviceInstance = wizard.GetFinishedServiceInstanceAsync().Result as ODataConnectedServiceInstance; var config = serviceInstance.ServiceConfig as ServiceConfigurationV4; Assert.Equal(savedConfig.ServiceName, config.ServiceName); Assert.Equal(savedConfig.Endpoint, config.Endpoint); Assert.True(config.IncludeCustomHeaders); Assert.Equal("A:b", config.CustomHttpHeaders); Assert.True(config.GenerateMultipleFiles); Assert.True(config.MakeTypesInternal); Assert.True(config.UseNamespacePrefix); Assert.Equal("MyNamespace", config.NamespacePrefix); Assert.False(config.UseDataServiceCollection); config.ExcludedOperationImports.ShouldAllBeEquivalentTo(new List <string>() { "GetNearestAirport", "GetPersonWithMostFriends" }); config.ExcludedSchemaTypes.ShouldBeEquivalentTo(new List <string>() { "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Employee", "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Flight", "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person", }); }
public void TestGetFinishedServiceInstanceAsync_SavesUserSettingsAndReturnsServiceInstanceWithConfigFromTheWizard() { var context = new TestConnectedServiceProviderContext(false); var wizard = new ODataConnectedServiceWizard(context); var endpointPage = wizard.ConfigODataEndpointViewModel; endpointPage.ServiceName = "TestService"; endpointPage.Endpoint = MetadataPath; endpointPage.EdmxVersion = Constants.EdmxVersion4; endpointPage.IncludeCustomHeaders = true; endpointPage.CustomHttpHeaders = "Key:val"; endpointPage.IncludeWebProxy = true; endpointPage.WebProxyHost = "http://localhost:8080"; endpointPage.IncludeWebProxyNetworkCredentials = true; endpointPage.WebProxyNetworkCredentialsDomain = "domain"; endpointPage.WebProxyNetworkCredentialsUsername = "******"; endpointPage.WebProxyNetworkCredentialsPassword = "******"; var operationsPage = wizard.OperationImportsViewModel; endpointPage.OnPageLeavingAsync(new WizardLeavingArgs(operationsPage)).Wait(); operationsPage.OperationImports = new List <OperationImportModel>() { new OperationImportModel() { Name = "GetNearestAirport", IsSelected = false }, new OperationImportModel() { Name = "GetPersonWithMostFriends", IsSelected = true }, new OperationImportModel() { Name = "ResetDataSource", IsSelected = false } }; var typesPage = wizard.SchemaTypesViewModel; typesPage.OnPageEnteringAsync(new WizardEnteringArgs(operationsPage)).Wait(); typesPage.SchemaTypes = new List <SchemaTypeModel>() { new SchemaTypeModel("Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline", "Airline") { IsSelected = false }, new SchemaTypeModel("Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport", "Airport") { IsSelected = false }, new SchemaTypeModel("Microsoft.OData.Service.Sample.TrippinInMemory.Models.City", "City") { IsSelected = true }, new SchemaTypeModel("Microsoft.OData.Service.Sample.TrippinInMemory.Models.Employee", "Employee") { IsSelected = false }, new SchemaTypeModel("Microsoft.OData.Service.Sample.TrippinInMemory.Models.Flight", "Flight") { IsSelected = true }, new SchemaTypeModel("Microsoft.OData.Service.Sample.TrippinInMemory.Models.Location", "Location") { IsSelected = true }, new SchemaTypeModel("Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person", "Person") { IsSelected = true }, new SchemaTypeModel("Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender", "PersonGender") { IsSelected = true }, new SchemaTypeModel("Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip", "Trip") { IsSelected = true }, }; var advancedPage = wizard.AdvancedSettingsViewModel; advancedPage.GeneratedFileNamePrefix = "GeneratedFile"; advancedPage.UseNamespacePrefix = true; advancedPage.NamespacePrefix = "TestNamespace"; advancedPage.UseDataServiceCollection = true; advancedPage.EnableNamingAlias = true; advancedPage.MakeTypesInternal = true; advancedPage.IncludeT4File = true; advancedPage.GenerateMultipleFiles = true; advancedPage.OpenGeneratedFilesInIDE = true; operationsPage.OnPageLeavingAsync(new WizardLeavingArgs(typesPage)).Wait(); typesPage.OnPageLeavingAsync(new WizardLeavingArgs(advancedPage)).Wait(); advancedPage.OnPageLeavingAsync(new WizardLeavingArgs(null)).Wait(); var serviceInstance = wizard.GetFinishedServiceInstanceAsync().Result as ODataConnectedServiceInstance; var config = serviceInstance.ServiceConfig as ServiceConfigurationV4; // saved user settings var settings = UserSettings.Load(null); Assert.Equal("TestService", settings.ServiceName); Assert.Equal(MetadataPath, settings.Endpoint); // moves endpoint to top of mru list Assert.Equal(MetadataPath, settings.MruEndpoints.First()); Assert.Equal(1, settings.MruEndpoints.Count(e => e == MetadataPath)); Assert.True(settings.IncludeCustomHeaders); Assert.Equal("Key:val", settings.CustomHttpHeaders); Assert.True(settings.IncludeWebProxy); Assert.Equal("http://localhost:8080", settings.WebProxyHost); Assert.True(settings.IncludeWebProxyNetworkCredentials); Assert.Equal("domain", settings.WebProxyNetworkCredentialsDomain); Assert.Equal("user", settings.WebProxyNetworkCredentialsUsername); Assert.Equal("pass", settings.WebProxyNetworkCredentialsPassword); settings.ExcludedOperationImports.ShouldBeEquivalentTo(new List <string>() { "GetNearestAirport", "ResetDataSource" }); settings.ExcludedSchemaTypes.ShouldBeEquivalentTo(new List <string>() { "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline", "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport", "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Employee" }); Assert.Equal("GeneratedFile", config.GeneratedFileNamePrefix); Assert.True(config.UseNamespacePrefix); Assert.Equal("TestNamespace", settings.NamespacePrefix); Assert.True(settings.EnableNamingAlias); Assert.True(settings.MakeTypesInternal); Assert.True(settings.IncludeT4File); Assert.True(settings.GenerateMultipleFiles); Assert.True(settings.OpenGeneratedFilesInIDE); // service configuration created Assert.Equal("GeneratedFile", serviceInstance.InstanceId); Assert.Equal("TestService", serviceInstance.Name); Assert.Equal(endpointPage.MetadataTempPath, serviceInstance.MetadataTempFilePath); Assert.Equal("TestService", config.ServiceName); Assert.Equal(MetadataPath, config.Endpoint); Assert.Equal(Constants.EdmxVersion4, config.EdmxVersion); Assert.True(config.IncludeCustomHeaders); Assert.Equal("Key:val", config.CustomHttpHeaders); Assert.True(config.IncludeWebProxy); Assert.Equal("http://localhost:8080", config.WebProxyHost); Assert.True(config.IncludeWebProxyNetworkCredentials); Assert.Equal("domain", config.WebProxyNetworkCredentialsDomain); Assert.Equal("user", config.WebProxyNetworkCredentialsUsername); Assert.Equal("pass", config.WebProxyNetworkCredentialsPassword); config.ExcludedOperationImports.ShouldBeEquivalentTo(new List <string>() { "GetNearestAirport", "ResetDataSource" }); config.ExcludedSchemaTypes.ShouldBeEquivalentTo(new List <string>() { "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline", "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport", "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Employee" }); Assert.Equal("GeneratedFile", config.GeneratedFileNamePrefix); Assert.True(config.UseNamespacePrefix); Assert.Equal("TestNamespace", config.NamespacePrefix); Assert.True(config.EnableNamingAlias); Assert.True(config.MakeTypesInternal); Assert.True(config.IncludeT4File); Assert.True(config.GenerateMultipleFiles); Assert.True(config.OpenGeneratedFilesInIDE); }
public void TestConstructor_LoadsSavedConfigWhenUpdating() { var savedConfig = GetTestConfig(); var context = new TestConnectedServiceProviderContext(true, savedConfig); var wizard = new ODataConnectedServiceWizard(context); Assert.Equal(savedConfig, wizard.ServiceConfig); var endpointPage = wizard.ConfigODataEndpointViewModel; endpointPage.OnPageEnteringAsync(new WizardEnteringArgs(null)).Wait(); Assert.Equal("https://service/$metadata", endpointPage.Endpoint); Assert.Equal("MyService", endpointPage.ServiceName); Assert.True(endpointPage.IncludeCustomHeaders); Assert.Equal("Key1:Val1\nKey2:Val2", endpointPage.CustomHttpHeaders); Assert.True(endpointPage.IncludeWebProxy); Assert.Equal("http://localhost:8080", endpointPage.WebProxyHost); Assert.True(endpointPage.IncludeWebProxyNetworkCredentials); Assert.Equal("domain", endpointPage.WebProxyNetworkCredentialsDomain); // username and password are not restored from the config Assert.Null(endpointPage.WebProxyNetworkCredentialsUsername); Assert.Null(endpointPage.WebProxyNetworkCredentialsPassword); var operationsPage = wizard.OperationImportsViewModel; endpointPage.MetadataTempPath = MetadataPath; endpointPage.EdmxVersion = Constants.EdmxVersion4; operationsPage.OnPageEnteringAsync(new WizardEnteringArgs(endpointPage)).Wait(); operationsPage.OperationImports.ShouldBeEquivalentTo(new List <OperationImportModel>() { new OperationImportModel() { Name = "GetNearestAirport", IsSelected = true }, new OperationImportModel() { Name = "GetPersonWithMostFriends", IsSelected = false }, new OperationImportModel() { Name = "ResetDataSource", IsSelected = false } }); var typesPage = wizard.SchemaTypesViewModel; typesPage.OnPageEnteringAsync(new WizardEnteringArgs(operationsPage)).Wait(); typesPage.SchemaTypes.ShouldBeEquivalentTo(new List <SchemaTypeModel>() { new SchemaTypeModel("Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline", "Airline") { IsSelected = true }, new SchemaTypeModel("Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport", "Airport") { IsSelected = true }, new SchemaTypeModel("Microsoft.OData.Service.Sample.TrippinInMemory.Models.City", "City") { IsSelected = true }, new SchemaTypeModel("Microsoft.OData.Service.Sample.TrippinInMemory.Models.Employee", "Employee") { IsSelected = false }, new SchemaTypeModel("Microsoft.OData.Service.Sample.TrippinInMemory.Models.Flight", "Flight") { IsSelected = true }, new SchemaTypeModel("Microsoft.OData.Service.Sample.TrippinInMemory.Models.Location", "Location") { IsSelected = true }, new SchemaTypeModel("Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person", "Person") { IsSelected = false }, new SchemaTypeModel("Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender", "PersonGender") { IsSelected = false }, new SchemaTypeModel("Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip", "Trip") { IsSelected = true }, }); var advancedPage = wizard.AdvancedSettingsViewModel; advancedPage.OnPageEnteringAsync(new WizardEnteringArgs(typesPage)).Wait(); Assert.Equal("GeneratedCode", advancedPage.GeneratedFileNamePrefix); Assert.True(advancedPage.UseNamespacePrefix); Assert.Equal("Namespace", advancedPage.NamespacePrefix); Assert.True(advancedPage.UseDataServiceCollection); Assert.True(advancedPage.EnableNamingAlias); Assert.True(advancedPage.OpenGeneratedFilesInIDE); Assert.True(advancedPage.IncludeT4File); Assert.True(advancedPage.GenerateMultipleFiles); Assert.True(advancedPage.IgnoreUnexpectedElementsAndAttributes); Assert.True(advancedPage.MakeTypesInternal); }
public void Init() { userSettings = new UserSettings(); serviceWizard = new ODataConnectedServiceWizard(null); configOdataEndPointViewModel = new ConfigODataEndpointViewModel(userSettings, serviceWizard); }
private void OpenConnectedServiceJsonFileButton_Click(object sender, RoutedEventArgs e) { var openFileDialog = new Microsoft.Win32.OpenFileDialog { DefaultExt = ".json", Filter = "JSON File (.json)|*.json", Title = "Open OData Connected Service Config File" }; var result = openFileDialog.ShowDialog(); if (result == false) { return; } if (!File.Exists(openFileDialog.FileName)) { MessageBox.Show($"File \"{openFileDialog.FileName}\" does not exists.", "Open OData Connected Service json-file", MessageBoxButton.OK, MessageBoxImage.Warning); return; } var jsonFileText = File.ReadAllText(openFileDialog.FileName); if (string.IsNullOrWhiteSpace(jsonFileText)) { MessageBox.Show("File have not content.", "Open OData Connected Service json-file", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (JObject.Parse(jsonFileText) == null) { MessageBox.Show("Can't convert file content to JObject.", "Open OData Connected Service json-file", MessageBoxButton.OK, MessageBoxImage.Warning); return; } var microsoftConnectedServiceData = JsonConvert.DeserializeObject <ConnectedServiceJsonFileData>(jsonFileText); if (microsoftConnectedServiceData != null) { this.UserSettings = new UserSettings(); this.UserSettings.Endpoint = microsoftConnectedServiceData.ExtendedData?.Endpoint ?? this.UserSettings.Endpoint; this.UserSettings.ServiceName = microsoftConnectedServiceData.ExtendedData?.ServiceName ?? this.UserSettings.ServiceName; this.UserSettings.GeneratedFileNamePrefix = microsoftConnectedServiceData.ExtendedData?.GeneratedFileNamePrefix ?? this.UserSettings.GeneratedFileNamePrefix; this.UserSettings.OpenGeneratedFilesInIDE = microsoftConnectedServiceData.ExtendedData?.OpenGeneratedFilesInIDE ?? this.UserSettings.OpenGeneratedFilesInIDE; this.UserSettings.MakeTypesInternal = microsoftConnectedServiceData.ExtendedData?.MakeTypesInternal ?? this.UserSettings.MakeTypesInternal; this.UserSettings.NamespacePrefix = microsoftConnectedServiceData.ExtendedData?.NamespacePrefix ?? this.UserSettings.NamespacePrefix; this.UserSettings.UseDataServiceCollection = microsoftConnectedServiceData.ExtendedData?.UseDataServiceCollection ?? this.UserSettings.UseDataServiceCollection; this.UserSettings.UseNamespacePrefix = microsoftConnectedServiceData.ExtendedData?.UseNamespacePrefix ?? this.UserSettings.UseNamespacePrefix; this.UserSettings.IncludeT4File = microsoftConnectedServiceData.ExtendedData?.IncludeT4File ?? this.UserSettings.IncludeT4File; this.UserSettings.IgnoreUnexpectedElementsAndAttributes = microsoftConnectedServiceData.ExtendedData?.IgnoreUnexpectedElementsAndAttributes ?? this.UserSettings.IgnoreUnexpectedElementsAndAttributes; this.UserSettings.GenerateMultipleFiles = microsoftConnectedServiceData.ExtendedData?.GenerateMultipleFiles ?? this.UserSettings.GenerateMultipleFiles; this.UserSettings.EnableNamingAlias = microsoftConnectedServiceData.ExtendedData?.EnableNamingAlias ?? this.UserSettings.EnableNamingAlias; this.UserSettings.CustomHttpHeaders = microsoftConnectedServiceData.ExtendedData?.CustomHttpHeaders ?? this.UserSettings.CustomHttpHeaders; this.UserSettings.IncludeCustomHeaders = microsoftConnectedServiceData.ExtendedData?.IncludeCustomHeaders ?? this.UserSettings.IncludeCustomHeaders; this.UserSettings.ExcludedOperationImports = microsoftConnectedServiceData.ExtendedData?.ExcludedOperationImports ?? new List <string>(); this.UserSettings.WebProxyHost = microsoftConnectedServiceData.ExtendedData?.WebProxyHost ?? this.UserSettings.WebProxyHost; this.UserSettings.IncludeWebProxy = microsoftConnectedServiceData.ExtendedData?.IncludeWebProxy ?? this.UserSettings.IncludeWebProxy; this.UserSettings.IncludeWebProxyNetworkCredentials = microsoftConnectedServiceData.ExtendedData?.IncludeWebProxyNetworkCredentials ?? this.UserSettings.IncludeWebProxyNetworkCredentials; this.UserSettings.WebProxyNetworkCredentialsDomain = microsoftConnectedServiceData.ExtendedData?.WebProxyNetworkCredentialsDomain ?? this.UserSettings.WebProxyNetworkCredentialsDomain; this.UserSettings.WebProxyNetworkCredentialsPassword = microsoftConnectedServiceData.ExtendedData?.WebProxyNetworkCredentialsPassword ?? this.UserSettings.WebProxyNetworkCredentialsPassword; this.UserSettings.WebProxyNetworkCredentialsUsername = microsoftConnectedServiceData.ExtendedData?.WebProxyNetworkCredentialsUsername ?? this.UserSettings.WebProxyNetworkCredentialsUsername; ODataConnectedServiceWizard ServiceWizard = ((ConfigODataEndpointViewModel)this.DataContext).ServiceWizard; this.UserSettings.MruEndpoints = UserSettings.Load(ServiceWizard.Context.Logger)?.MruEndpoints; ServiceWizard.ConfigODataEndpointViewModel.UserSettings = this.UserSettings; ServiceWizard.ConfigODataEndpointViewModel.LoadFromUserSettings(); ServiceWizard.AdvancedSettingsViewModel.UserSettings = this.UserSettings; ServiceWizard.AdvancedSettingsViewModel.LoadFromUserSettings(); ServiceWizard.OperationImportsViewModel.UserSettings = this.UserSettings; // get Operation Imports from metadata for excluding ExcludedOperationImports try { ServiceWizard.ConfigODataEndpointViewModel.MetadataTempPath = ServiceWizard.ConfigODataEndpointViewModel.GetMetadata(out var version); ServiceWizard.ConfigODataEndpointViewModel.EdmxVersion = version; if (version == Constants.EdmxVersion4) { var model = EdmHelper.GetEdmModelFromFile(ServiceWizard.ConfigODataEndpointViewModel.MetadataTempPath); var operations = EdmHelper.GetOperationImports(model); ServiceWizard.OperationImportsViewModel.LoadOperationImports(operations, new HashSet <string>(), new Dictionary <string, SchemaTypeModel>()); ServiceWizard.ProcessedEndpointForOperationImports = this.UserSettings.Endpoint; ServiceWizard.OperationImportsViewModel.LoadFromUserSettings(); ServiceWizard.SchemaTypesViewModel.LoadFromUserSettings(); } } catch { // ignored } } }
private void OpenConnectedServiceJsonFileButton_Click(object sender, RoutedEventArgs e) { var openFileDialog = new Microsoft.Win32.OpenFileDialog { DefaultExt = ".json", Filter = "JSON File (.json)|*.json", Title = "Open OData Connected Service Config File" }; var result = openFileDialog.ShowDialog(); if (result == false) { return; } if (!File.Exists(openFileDialog.FileName)) { MessageBox.Show($"File \"{openFileDialog.FileName}\" does not exists.", "Open OData Connected Service json-file", MessageBoxButton.OK, MessageBoxImage.Warning); return; } var jsonFileText = File.ReadAllText(openFileDialog.FileName); if (string.IsNullOrWhiteSpace(jsonFileText)) { MessageBox.Show("File have not content.", "Open OData Connected Service json-file", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (JObject.Parse(jsonFileText) == null) { MessageBox.Show("Can't convert file content to JObject.", "Open OData Connected Service json-file", MessageBoxButton.OK, MessageBoxImage.Warning); return; } var microsoftConnectedServiceData = JsonConvert.DeserializeObject <ConnectedServiceJsonFileData>(jsonFileText); if (microsoftConnectedServiceData != null) { this.UserSettings = new UserSettings(); this.UserSettings.Endpoint = microsoftConnectedServiceData.ExtendedData?.Endpoint ?? this.UserSettings.Endpoint; this.UserSettings.ServiceName = microsoftConnectedServiceData.ExtendedData?.ServiceName ?? this.UserSettings.ServiceName; this.UserSettings.GeneratedFileNamePrefix = microsoftConnectedServiceData.ExtendedData?.GeneratedFileNamePrefix ?? this.UserSettings.GeneratedFileNamePrefix; this.UserSettings.OpenGeneratedFilesInIDE = microsoftConnectedServiceData.ExtendedData?.OpenGeneratedFilesInIDE ?? this.UserSettings.OpenGeneratedFilesInIDE; this.UserSettings.MakeTypesInternal = microsoftConnectedServiceData.ExtendedData?.MakeTypesInternal ?? this.UserSettings.MakeTypesInternal; this.UserSettings.NamespacePrefix = microsoftConnectedServiceData.ExtendedData?.NamespacePrefix ?? this.UserSettings.NamespacePrefix; this.UserSettings.UseDataServiceCollection = microsoftConnectedServiceData.ExtendedData?.UseDataServiceCollection ?? this.UserSettings.UseDataServiceCollection; this.UserSettings.UseNamespacePrefix = microsoftConnectedServiceData.ExtendedData?.UseNamespacePrefix ?? this.UserSettings.UseNamespacePrefix; this.UserSettings.IncludeT4File = microsoftConnectedServiceData.ExtendedData?.IncludeT4File ?? this.UserSettings.IncludeT4File; this.UserSettings.IgnoreUnexpectedElementsAndAttributes = microsoftConnectedServiceData.ExtendedData?.IgnoreUnexpectedElementsAndAttributes ?? this.UserSettings.IgnoreUnexpectedElementsAndAttributes; this.UserSettings.GenerateMultipleFiles = microsoftConnectedServiceData.ExtendedData?.GenerateMultipleFiles ?? this.UserSettings.GenerateMultipleFiles; this.UserSettings.EnableNamingAlias = microsoftConnectedServiceData.ExtendedData?.EnableNamingAlias ?? this.UserSettings.EnableNamingAlias; this.UserSettings.CustomHttpHeaders = microsoftConnectedServiceData.ExtendedData?.CustomHttpHeaders ?? this.UserSettings.CustomHttpHeaders; this.UserSettings.IncludeCustomHeaders = microsoftConnectedServiceData.ExtendedData?.IncludeCustomHeaders ?? this.UserSettings.IncludeCustomHeaders; this.UserSettings.WebProxyHost = microsoftConnectedServiceData.ExtendedData?.WebProxyHost ?? this.UserSettings.WebProxyHost; this.UserSettings.IncludeWebProxy = microsoftConnectedServiceData.ExtendedData?.IncludeWebProxy ?? this.UserSettings.IncludeWebProxy; this.UserSettings.IncludeWebProxyNetworkCredentials = microsoftConnectedServiceData.ExtendedData?.IncludeWebProxyNetworkCredentials ?? this.UserSettings.IncludeWebProxyNetworkCredentials; this.UserSettings.WebProxyNetworkCredentialsDomain = microsoftConnectedServiceData.ExtendedData?.WebProxyNetworkCredentialsDomain ?? this.UserSettings.WebProxyNetworkCredentialsDomain; this.UserSettings.WebProxyNetworkCredentialsPassword = microsoftConnectedServiceData.ExtendedData?.WebProxyNetworkCredentialsPassword ?? this.UserSettings.WebProxyNetworkCredentialsPassword; this.UserSettings.WebProxyNetworkCredentialsUsername = microsoftConnectedServiceData.ExtendedData?.WebProxyNetworkCredentialsUsername ?? this.UserSettings.WebProxyNetworkCredentialsUsername; ODataConnectedServiceWizard ServiceWizard = ((ConfigODataEndpointViewModel)this.DataContext).ServiceWizard; ServiceWizard.AdvancedSettingsViewModel.UserSettings = this.UserSettings; ServiceWizard.ConfigODataEndpointViewModel.UserSettings = this.UserSettings; this.Endpoint.Text = microsoftConnectedServiceData.ExtendedData?.Endpoint ?? this.Endpoint.Text; this.ServiceName.Text = microsoftConnectedServiceData.ExtendedData?.ServiceName ?? this.ServiceName.Text; this.CustomHttpHeaders.Text = microsoftConnectedServiceData.ExtendedData?.CustomHttpHeaders ?? this.CustomHttpHeaders.Text; this.WebProxyHost.Text = microsoftConnectedServiceData.ExtendedData?.WebProxyHost ?? this.WebProxyHost.Text; this.WebProxyNetworkCredentialsDomain.Text = microsoftConnectedServiceData.ExtendedData?.WebProxyNetworkCredentialsDomain ?? this.WebProxyNetworkCredentialsDomain.Text; this.WebProxyNetworkCredentialsPassword.Text = microsoftConnectedServiceData.ExtendedData?.WebProxyNetworkCredentialsPassword ?? this.WebProxyNetworkCredentialsPassword.Text; this.WebProxyNetworkCredentialsUsername.Text = microsoftConnectedServiceData.ExtendedData?.WebProxyNetworkCredentialsUsername ?? this.WebProxyNetworkCredentialsUsername.Text; this.IncludeHttpHeadersElement.IsChecked = microsoftConnectedServiceData.ExtendedData?.IncludeCustomHeaders ?? this.IncludeHttpHeadersElement.IsChecked; this.IncludeWebProxyElement.IsChecked = microsoftConnectedServiceData.ExtendedData?.IncludeWebProxy ?? this.IncludeWebProxyElement.IsChecked; this.IncludeWebProxyNetworkCredentialsElement.IsChecked = microsoftConnectedServiceData.ExtendedData?.IncludeWebProxyNetworkCredentials ?? this.IncludeWebProxyNetworkCredentialsElement.IsChecked; } }