CurrentAppSimulator class

Applies to Windows and Windows Phone

Defines methods and properties used to instantiate an object that you can use to get simulated license info during testing.

Note  You must replace the CurrentAppSimulator class with the CurrentApp class before you submit the app to the Windows Store. Apps that use the CurrentAppSimulator will fail certification.

When the CurrentAppSimulator is used, a WindowsStoreProxy.xml file is created at the following location to support the simulation of a Windows Store transaction:

C:\Users\<username>\AppData\Local\Packages\<app package folder>\LocalState\Microsoft\Windows Store\ApiData\WindowsStoreProxy.xml

While you can modify the values in this file, the recommended alternative is to create your own WindowsStoreProxy.xml file (in a data folder of your VS project) for the simulator to use instead. When simulating the transaction, call CurrentAppSimulator.ReloadSimulatorAsync (<storage file based on path to your xml file>) to load your file.

If you do not call ReloadSimulatorAsync for your own WindowsStoreProxy.xml file, the simulator will create/load (but not overwrite) the default WindowsStoreProxy.xml file.

Syntax


public ref class CurrentAppSimulator abstract sealed 

Attributes

[MarshalingBehavior(Agile)]
[Threading(Both)]
[Version(0x06020000)]

Members

The CurrentAppSimulator class has these types of members:

Methods

The CurrentAppSimulator class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

MethodDescription
GetAppReceiptAsync Creates the async operation that the user can use to simulate requesting all receipts for this app and any in-app purchases.
GetProductReceiptAsync Creates the async operation that the user can use to simulate requesting the receipt for the productId specified.
GetUnfulfilledConsumablesAsync Returns a list of purchased consumables that have not been fulfilled.
LoadListingInformationAsync Loads the simulated app listing information asynchronously. Implements the IAsyncInfo interface.
LoadListingInformationByKeywordsAsync Windows Phone only. Loads the simulated app listing information asynchronously, returning features and products in the ProductListings collection that match all supplied keywords. Implements the IAsyncInfo interface.
LoadListingInformationByProductIdsAsync Windows Phone only. Loads the simulated app listing information asynchronously, returning features and products in the ProductListings collection that match any of the given products IDs. Implements the IAsyncInfo interface.
ReloadSimulatorAsync Reloads the simulator using a StorageFile containing the WindowsStoreProxy.xml file.
ReportConsumableFulfillmentAsync Simulates notifying the Windows Store that the purchase of a consumable is fulfilled and that the user has the right to access the content.
RequestAppPurchaseAsync Creates the async operation that simulates a user request to buy a full license for the current app.
RequestProductPurchaseAsync(String) Creates the async operation that displays the UI that is used to simulate an in-app purchase of content or a feature from the Windows Store.
RequestProductPurchaseAsync(String,Boolean) Creates the async operation that displays the UI that is used to simulate an in-app purchase of content or a feature from the Windows Store.
RequestProductPurchaseAsync(String,String,ProductPurchaseDisplayProperties) Creates the async operation that displays the UI that is used to simulate an in-app purchase of content or a feature from the Windows Store.

 

Properties

The CurrentAppSimulator class has these properties.

PropertyAccess typeDescription

AppId

Read-onlyGets a simulated app ID. Since CurrentAppSimulator is intended only for testing during app development, the returned CurrentAppSimulator.AppId will contain only 0's.

LicenseInformation

Read-onlyGets the simulated license metadata for the current app as provided by the simulation.

LinkUri

Read-onlyGets the simulated Uniform Resource Identifier (URI) that represents a Windows Store listing page for the current app.

 

Remarks

Until the app has been listed in the Windows Store, the CurrentApp object won't work in the app. Use the CurrentAppSimulator to test your app's licensing and in-app purchases while you develop your app. After you test your app and before you submit it to the Windows Store, replace the instances of CurrentAppSimulator with CurrentApp. Your app will fail certification if it uses CurrentAppSimulator.

Note  When using the simulation, the initial licensing state of the app is described in WindowsStoreProxy.xml. CurrentAppSimulator method that alter the license state, for example by buying a license or handling an in-app purchase, only update the license state of the object in memory. The contents of WindowsStoreProxy.xml are not changed. When the app starts again, the license state reverts to what is described in WindowsStoreProxy.xml.

The CurrentAppSimulator object gets its data from the WindowsStoreProxy.xml file in the %userprofile%\appdata\local\packages\<package-moniker>\localstate\microsoft\Windows Store\Apidata folder. You must configure this file for the scenario that you want to simulate in the CurrentAppSimulator properties.

The contents of this file are defined by the SimulatedCurrentApp.xsd file included as an example later in this topic, and they reflect the organization of the objects and properties of the Windows.ApplicationModel.Store namespace.

The elements of this file are included in the CurrentApp root node and include:

ListingInformation

Represents data that would normal be found in the app's listing and includes these elements:

App

Represents data about the app and contains these elements:

AppId

The GUID that identifies the app in the store. This can be any GUID for testing.

LinkUri

The URI of the listing page in the store. This can be any valid URI for testing.

AgeRating

An integer that represents the minimum age rating of the app. This is the same value you would specify in the Dashboard when you submit the app. The values used by the Windows Store are: 3, 7, 12, and 16.

CurrentMarket

This is the customer's country/region.

For each country/region in which the app is listed, there must be a MarketData element.

MarketData

Info about the app for this country/region.

Requires the xml:lang attribute, which specifies the country/region for which this info applies.

Name

The name of the app in this country/region.

Description

The description of the app for this country/region.

Price

The price of the app in this country/region.

CurrencySymbol

The currency symbol used in this country/region.

Product

Describes a product or a feature in this app that is enabled when the customer makes an in-app purchase.

Requires the ProductId attribute, which contains the string used by the app to identify the product or feature.

Requires the LicenseDuration attribute, which contains the number of days the license will be valid after the purchase. The expiration date of the new license created by a product purchase is the purchase date plus the license duration.

MarketData

Info about the product or feature for this country/region.

Requires the xml:lang attribute, which specifies the country/region for which this information applies.

Name

The name of the product or feature in this country/region.

Price

The price of the product or feature in this country/region.

CurrencySymbol

The currency symbol used in this country/region.

CurrencyCode

The currency code used in this country/region.

LicenseInformation

Represents data that describes the licenses available for this app and includes the following elements:

App

Describes the app's license:

IsActive

Describes the current license state of this app.

true indicates the license is valid. Normally this value is true, whether the app has a trial mode or not.

false indicates an invalid license. Set this value to false to test how your app behaves when it has an invalid license.

IsTrial

Describes the current trial state of this app.

true indicates the app is being used during the trial period.

false indicates the app is not in a trial, either because the app has been purchased or the trial period has expired.

ExpirationDate

The date the trial period for this app expires. The date must be express as: yyyy-mm-ddThh:mm:ss.ssZ. For example, 05:00 on January 19, 2012 would be specified as 2012-01-19T05:00:00.00Z.

If this element is required when IsTrial is true. Otherwise, it is not required.

DefaultResponse

Describes the default error code returned by a given method. The MethodName attribute allows you to specify one of these methods:

RequestAppPurchaseAsync_GetResult
RequestProductPurchaseAsync_GetResult
LoadListingInformationAsync_GetResult
The HResult attribute allows you to specify the error code. SimulatedCurrentApp.xsd contains the list of typical error codes you can use.

Product

Describes the license status of a product or feature in the app:

IsActive

Describes the current license state of this product or feature.

true indicates the product or feature can be used.

false indicates the product or feature cannot be used or has not been purchased.

ExpirationDate

The date the product or feature expires. The date must be express as: yyyy-mm-ddThh:mm:ss.ssZ. For example, 05:00 on January 19, 2012 would be specified as 2012-01-19T05:00:00.00Z.

If this element is present, the product or feature has an expiration date.

If this element is not present, the product or feature does not expire.

Simulation

Describes how various method calls work. When the SimulationMode attribute is set to Automatic, the methods will automatically return the specified HRESULT error codes. This can be used when running automated test cases.

Examples

This example is a WindowsStoreProxy.xml file (UTF-16 encoded) that describes an app with a trial mode that expires at 05:00 (Z) on Jan. 19, 2012.


<?xml version="1.0" encoding="UTF-16"?>
<CurrentApp>
  <ListingInformation>
    <App>
      <AppId>2B14D306-D8F8-4066-A45B-0FB3464C67F2</AppId>
      <LinkUri>http://apps.windows.microsoft.com/app/2B14D306-D8F8-4066-A45B-0FB3464C67F2</LinkUri>
      <CurrentMarket>en-US</CurrentMarket>
      <AgeRating>3</AgeRating>
      <MarketData xml:lang="en-us">
        <Name>Trial management full license</Name>
        <Description>Sample app for demonstrating trial license management</Description>
        <Price>4.99</Price>
        <CurrencySymbol>$</CurrencySymbol>
      </MarketData>
    </App>
  </ListingInformation>
  <LicenseInformation>
    <App>
      <IsActive>true</IsActive>
      <IsTrial>true</IsTrial>
      <ExpirationDate>2012-01-19T05:00:00.00Z</ExpirationDate>
    </App>
  </LicenseInformation>
  <Simulation SimulationMode="Automatic">
    <DefaultResponse MethodName="LoadListingInformationAsync_GetResult" HResult="E_FAIL"/>
  </Simulation>
</CurrentApp>

The next example is a WindowsStoreProxy.xml file (UTF-16 encoded) that describes an app that has been purchased and has a feature that expires at 05:00 (Z) on Jan. 19, 2012.


<?xml version="1.0" encoding="utf-16" ?>
<CurrentApp>
  <ListingInformation>
    <App>
      <AppId>988b90e4-5d4d-4dea-99d0-e423e414ffbc</AppId>
      <LinkUri>http://apps.windows.microsoft.com/app/988b90e4-5d4d-4dea-99d0-e423e414ffbc</LinkUri>
      <CurrentMarket>en-us</CurrentMarket>
      <AgeRating>3</AgeRating>
      <MarketData xml:lang="en-us">
        <Name>Expiring in-app feature</Name>
        <Description>App description text goes here.</Description>
        <Price>5.99</Price>
        <CurrencySymbol>$</CurrencySymbol>
      </MarketData>
    </App>
    <Product ProductId="feature1" LicenseDuration="10">
      <MarketData xml:lang="en-us">
        <Name>Feature 1</Name>
        <Price>1.99</Price>
        <CurrencySymbol>$</CurrencySymbol>
      </MarketData>
    </Product>
  </ListingInformation>
  <LicenseInformation>
    <App>
      <IsActive>true</IsActive>
      <IsTrial>false</IsTrial>
    </App>
    <Product ProductId="feature1">
      <IsActive>true</IsActive>
      <ExpirationDate>2012-01-19T00:00:00.00Z</ExpirationDate>
    </Product>
  </LicenseInformation>
</CurrentApp>


SimulatedCurrentApp.xsd

The next example is the XSD file that defines the structure of the temporary files used to test your app with the CurrentAppSimulator.


<?xml version="1.0" encoding="utf-8"?>  
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">  
  <xs:import namespace="http://www.w3.org/XML/1998/namespace" />  
  <xs:element name="CurrentApp" type="CurrentAppDefinition"></xs:element>  
  <xs:complexType name="CurrentAppDefinition">  
    <xs:sequence>  
      <xs:element name="ListingInformation" type="ListingDefinition" minOccurs="1" maxOccurs="1"/>  
      <xs:element name="LicenseInformation" type="LicenseDefinition" minOccurs="1" maxOccurs="1"/>  
      <xs:element name="Simulation" type="SimulationDefinition" minOccurs="0" maxOccurs="1"/>  
    </xs:sequence>  
  </xs:complexType>  
  <xs:simpleType name="ResponseCodes">  
    <xs:restriction base="xs:string">  
      <xs:enumeration value="S_OK">  
        <xs:annotation>  
          <xs:documentation>0x00000000</xs:documentation>  
        </xs:annotation>  
      </xs:enumeration>  
      <xs:enumeration value="E_INVALIDARG">  
        <xs:annotation>  
          <xs:documentation>0x80070057</xs:documentation>  
        </xs:annotation>  
      </xs:enumeration>  
      <xs:enumeration value="E_CANCELLED">  
        <xs:annotation>  
          <xs:documentation>0x800704C7</xs:documentation>  
        </xs:annotation>  
      </xs:enumeration>  
      <xs:enumeration value="E_FAIL">  
        <xs:annotation>  
          <xs:documentation>0x80004005</xs:documentation>  
        </xs:annotation>  
      </xs:enumeration>  
      <xs:enumeration value="E_OUTOFMEMORY">  
        <xs:annotation>  
          <xs:documentation>0x8007000E</xs:documentation>  
        </xs:annotation>  
      </xs:enumeration>  
      <xs:enumeration value="ERROR_ALREADY_EXISTS">  
        <xs:annotation>  
          <xs:documentation>0x800700B7</xs:documentation>  
        </xs:annotation>  
      </xs:enumeration>  
    </xs:restriction>  
  </xs:simpleType>  
  <xs:simpleType name="StoreMethodName">  
    <xs:restriction base="xs:string">  
      <xs:enumeration value="RequestAppPurchaseAsync_GetResult" id="RPPA" />  
      <xs:enumeration value="RequestProductPurchaseAsync_GetResult" id="RFPA" />  
      <xs:enumeration value="LoadListingInformationAsync_GetResult" id="LLIA" />  
    </xs:restriction>  
  </xs:simpleType>  
  <xs:simpleType name="SimulationMode">  
    <xs:restriction base="xs:string">  
      <xs:enumeration value="Interactive" />  
      <xs:enumeration value="Automatic" />  
    </xs:restriction>  
  </xs:simpleType>  
  <xs:complexType name="ListingDefinition">  
    <xs:sequence>  
      <xs:element name="App" type="AppListingDefinition" />  
      <xs:element name="Product" type="ProductListingDefinition" minOccurs="0" maxOccurs="unbounded" />  
    </xs:sequence>  
  </xs:complexType>  
  <xs:complexType name="AppListingDefinition">  
    <xs:sequence>  
      <xs:element name="AppId" type="xs:string" minOccurs="1" maxOccurs="1" />  
      <xs:element name="LinkUri" type="xs:anyURI" minOccurs="1" maxOccurs="1" />  
      <xs:element name="CurrentMarket" type="xs:language" minOccurs="1" maxOccurs="1" />  
      <xs:element name="AgeRating" type="xs:unsignedInt" minOccurs="1" maxOccurs="1" />  
      <xs:element name="MarketData" type="MarketSpecificAppData" minOccurs="1" maxOccurs="unbounded" />  
    </xs:sequence>  
  </xs:complexType>  
  <xs:complexType name="MarketSpecificAppData">  
    <xs:sequence>  
      <xs:element name="Name" type="xs:string" minOccurs="1" maxOccurs="1" />  
      <xs:element name="Description" type="xs:string" minOccurs="1" maxOccurs="1" />  
      <xs:element name="Price" type="xs:float" minOccurs="1" maxOccurs="1" />  
      <xs:element name="CurrencySymbol" type="xs:string" minOccurs="1" maxOccurs="1" />  
      <xs:element name="CurrencyCode" type="xs:string" minOccurs="0" maxOccurs="1" />  
    </xs:sequence>  
    <xs:attribute ref="xml:lang" use="required" />  
  </xs:complexType>  
  <xs:complexType name="MarketSpecificProductData">  
    <xs:sequence>  
      <xs:element name="Name" type="xs:string" minOccurs="1" maxOccurs="1" />  
      <xs:element name="Price" type="xs:float" minOccurs="1" maxOccurs="1" />  
      <xs:element name="CurrencySymbol" type="xs:string" minOccurs="1" maxOccurs="1" />  
      <xs:element name="CurrencyCode" type="xs:string" minOccurs="0" maxOccurs="1" />  
    </xs:sequence>  
    <xs:attribute ref="xml:lang" use="required" />  
  </xs:complexType>  
  <xs:complexType name="ProductListingDefinition">  
    <xs:sequence>  
      <xs:element name="MarketData" type="MarketSpecificProductData" minOccurs="1" maxOccurs="unbounded" />  
    </xs:sequence>  
    <xs:attribute name="ProductId" use="required">  
      <xs:simpleType>  
        <xs:restriction base="xs:string">  
          <xs:maxLength value="100"/>  
          <xs:pattern value="[^,]*"/>  
        </xs:restriction>  
      </xs:simpleType>  
    </xs:attribute>  
    <xs:attribute name="LicenseDuration" type="xs:integer" use="optional" />  
  </xs:complexType>  
  <xs:complexType name="LicenseDefinition">  
    <xs:sequence>  
      <xs:element name="App" type="AppLicenseDefinition" />  
      <xs:element name="Product" type="ProductLicenseDefinition" minOccurs="0" maxOccurs="unbounded" />  
    </xs:sequence>  
  </xs:complexType>  
  <xs:complexType name="AppLicenseDefinition">  
    <xs:sequence>  
      <xs:element name="IsActive" type="xs:boolean" minOccurs="1" maxOccurs="1" />  
      <xs:element name="IsTrial" type="xs:boolean" minOccurs="1" maxOccurs="1" />  
      <xs:element name="ExpirationDate" type="xs:dateTime" minOccurs="0" maxOccurs="1" />  
    </xs:sequence>  
  </xs:complexType>  
  <xs:complexType name="ProductLicenseDefinition">  
    <xs:sequence>  
      <xs:element name="IsActive" type="xs:boolean" minOccurs="1" maxOccurs="1" />  
      <xs:element name="ExpirationDate" type="xs:dateTime" minOccurs="0" maxOccurs="1" />  
    </xs:sequence>  
    <xs:attribute name="ProductId" type="xs:string" use="required" />  
  </xs:complexType>  
  <xs:complexType name="SimulationDefinition" >  
    <xs:sequence>  
      <xs:element name="DefaultResponse" type="DefaultResponseDefinition" minOccurs="0" maxOccurs="unbounded" />  
    </xs:sequence>  
    <xs:attribute name="SimulationMode" type="SimulationMode" use="optional" />  
  </xs:complexType>  
  <xs:complexType name="DefaultResponseDefinition">  
    <xs:attribute name="MethodName" type="StoreMethodName" use="required" />  
    <xs:attribute name="HResult" type="ResponseCodes" use="required" />  
  </xs:complexType>  
</xs:schema>

Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.ApplicationModel.Store
Windows::ApplicationModel::Store [C++]

Metadata

Windows.winmd

See also

Trial app and in-app purchase sample

 

 

Show:
© 2014 Microsoft