OData Connected Service 0.5.0 has been released and is available in the Visual Studio Marketplace.
The new version has the following new features:
- A new version of the Microsoft.OData.Client library(v7.6.3)
- Supports mocking of the generated functions and properties.
- An option to open the generated files in the IDE after code generation.
In addition to the above features, the new version has the following improvements and fixes:
- Generation of type definitions using their underlying types.
- The Microsoft WCF Toolkit dependency has been removed.
- All features and fixes from OData Client Code Generator are now in OData Connected Service.
Microsoft.OData.Client v7.6.3
OData Connected Service version 0.5.0 comes with Microsoft.OData.Client v7.6.3 which has great improvements: Some of the improvements are:
- Save ODataPath ToList for improved performance.
- Performance improvements in FunctionOverloadResolver.
- Fixes for OData.net Client throwing InvalidOperationException when calling ‘Move’ on a DataServiceCollection.
- Fixes for supporting escape function and key values terminating in colon.
- Fixes for IN operator fails on strings with commas in them.
- Allow Microsoft.OData.Client.Serializer.GetKeyString to receive an IDictionary Object.
- Fixes for $filter in (null) not working.
- Fixes for Combine Dispose methods on JsonWriter.
Supports Mocking of the generated functions and properties
The generated methods and properties can be mocked for purposes of testing your client code. You can use any Mock Framework to mock these methods.The following is a simple example to show that the generated methods can be mocked using the Moq Framework.
public string AddPerson(DefaultContainer defaultContainer) { Person person = new Person { FirstName = "PersonA" //…there are many more fields here. }; try { defaultContainer.AddToPeople(person). return "Saved Successfully". } catch (Exception exception) { return "Not Saved Successfully”. } }
Using the Moq Framework, we can setup the AddToPeople() method to return whatever we want it to return whenever we call it. Like below.
public void Return_SavedSuccessfully_WhenAddToPeopleMethodIsCalled() { string response = "Add". Mock<DefaultContainer> mock = new Mock<DefaultContainer>(null). mock.CallBase = true; mock.Setup(x => x.AddToPeople(It.IsAny<Person>())).Callback(() => { response = "Saved Successfully"; }); Users users = new Users (); string result = users.AddPerson(mock.Object); Assert.Equal(result, response). }
An Option to open the generated files in the IDE after code generation
This option has been added on the OData Connected Service setup wizard. It is on the Advanced Settings page. You can use this setting when you want the generated file to open in the IDE after code generation.To set this option, follow the following steps:
If you have the OData Connected Service extension installed,
- Right click on the project you are working on from the solution explorer.
- Select Add->Connected Service from the context menu.
- From the Connected Service Window that opens, select the Microsoft OData Connected Service.
- On the wizard window, configure your service endpoint by providing the service name and the OData URL endpoint then click Next.
- On the Next page, click on the “AdvancedSettings” link.
Check the checkbox beside the “Open generated files in the IDE when generation completes” configuration on this page then click finish.
The generated file will open in the IDE once the code generation process completes.
Generation of type definitions using their underlying types.
The previous versions of OData Connected Service could not generate code for an endpoint whose schema had:
- Elements with type definitions like the Outlook Beta API
<TypeDefinition Name="DateTime" UnderlyingType="Edm.String"/>
- Functions with parameters whose types are based on type definitions like below:
<Function Name="MyFunc" IsBound="true"> <Parameter Name="StartDate" Type="MyNamespace.DateTime" /> <ReturnType Type="Edm.Int32" Nullable="false" /> </Function>
This issue has been solved in the OData Connected Service version 0.5.0. The OData Connected Service can now generate type definitions using their underlying types without any errors or exceptions.
All features and fixes from OData Client Code Generator are now in OData Connected Service.
The OData Connected Service version 0.5.0 is now in sync with the latest version of the Microsoft OData Client Code Generator. All features and fixes in the Microsoft OData Client Code Generator are now available in OData Connected Service.
Removed the Microsoft WCF Toolkit dependency .
The Microsoft WCF Toolkit dependency has been removed from this version. That is, you do not need to install the WCF Toolkit for you to generate client code.
There are more features and fixes coming to OData Connected Service soon, so stay tuned for upcoming releases.
0 comments