The Microsoft Commercial Marketplace SaaS .NET client enables publishers to build solutions interacting with Fulfillment and Metering APIs with .NET.
Перейти к файлу
SANTHOSH B baf36c5ccc
Merge pull request #78 from microsoft/dependabot/nuget/tests/Microsoft.Marketplace.Tests/System.Text.Json-8.0.5
Bump System.Text.Json from 8.0.1 to 8.0.5 in /tests/Microsoft.Marketplace.Tests
2024-10-08 14:36:49 -07:00
.github Update dotnet-core.yml 2024-01-17 00:15:12 -08:00
.vscode Preview 2 update (#38) 2021-02-08 14:31:34 -08:00
src updated meter api perm link 2024-01-19 09:28:17 -08:00
tests Bump System.Text.Json in /tests/Microsoft.Marketplace.Tests 2024-10-08 20:42:37 +00:00
.gitattributes Merge dev into master (#30) 2020-10-01 15:05:08 -07:00
.gitignore Preview 2 update (#38) 2021-02-08 14:31:34 -08:00
CODE_OF_CONDUCT.md Merge dev into master (#30) 2020-10-01 15:05:08 -07:00
Directory.Build.props all nuget library upgrades, upgrade to net6 and fix unit tests 2024-01-16 21:26:40 -08:00
LICENSE Merge dev into master (#30) 2020-10-01 15:05:08 -07:00
Microsoft.Marketplace.sln all nuget library upgrades, upgrade to net6 and fix unit tests 2024-01-16 21:26:40 -08:00
NuGet.Config Bug fixes to preview 2 2021-02-22 11:15:20 -08:00
README.md Preview 2 update (#38) 2021-02-08 14:31:34 -08:00
SECURITY.md Merge dev into master (#30) 2020-10-01 15:05:08 -07:00

README.md

.NET Core

Change log

- Started using AutoRest C# generator V3 to take advantage of new features.
- Removed container based code generation. Using the code build target for code generation coming with C# generator V3. Please see the generate.cmd file in the src folder.
- Modified the repo structure for streamlining with the new code generation method.
- Added two C# projects supporting code generation (SaaS and Metering) and one project for building the binary assets (Microsoft.Marketplace.csproj).    

Breaking changes for preview2

- Constructors for the clients are now using classes deriving from Azure.Core.TokenCredential defined in Azure.Identity namespace (in Azure.Identity NuGet package)
- Removed *TokenProvider 
- Removed ListAllSubscriptionsAsync method on the FulfillmentOperations in favor of the generated ListSubscriptions* methods that implement pagination. Please see the tests for different usages.
- Renamed FulfillmentOperations property on the MarketplaceSaaSClient to Fulfillment
- Removed serialization checks on the SubscriberPlan and UsageEvent classes for consistency. The libraries rely on serialization checks on the service side.

Using the client libraries

The library has two clients, one for the SaaS fulfillment API version 2 (MarketplaceSaaSClient) and one for metered billing APIs (MarketplaceMeteringClient).

Both of them use the client credentials flow, service-to-service authentication for authenticating to call the APIs. The clients support both client secrets and X.509 certificates.After registering an single-tenant application on Azure AD, just create a client secret, or use a X.509 to call the constructor as follows:

    new MarketplaceSaaSClient(new ClientSecretCredential(config["TenantId"], config["ClientId"], config["clientSecret"]));

If you want to use an X.509 certificate instead, use ClientCertificateCredential where clientCertificate is of type System*.Security.Cryptography.X509Certificates.X509Certificate2.

        new MarketplaceSaaSClient(new ClientCertificateCredential (config["TenantId"], config["ClientId"], clientCertificate);

Then call the appropriate method corresponding to the API call.

    var subscriptions = await this.sut.Fulfillment.ListSubscriptionsAsync().ToListAsync();

Running the tests

We are using the Azure.Core.TestFramework from the Azure SDK for .NET. Since no NuGet package includes this assembly at the time of the development of this library project, we opted to make a copy of that source tree and directly include in our repository.

We will be turning on the RecordedTestMode.Record each time we generate the client code when the API surface changes or we need to change the implementation. We are including the session recordings, and the tests will be run against the recorded sessions by default.

The tests use the standard .NET core configuration system user secrets for configuration. Simply add user secrets for the following values, using your favorite method, i.e. either "dotnet user-secrets", Visual Studio Code extension, or Visual Studio 2019 user secrets menu option.

  • TenantId
  • ClientId
  • clientSecret

If you want to record your own sessions, turn on recording by modifying the test constructor and use RecordedTestMode.Record, then run the tests.

One test requires a marketplace purchase identification token and you can get it from a landing page link generated from an actual subscription. Simply url-decode it, and set the value in the test.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.