public static void Script() { sap.ui.require(new string[] { "sap/ui/demo/walkthrough/model/formatter", "sap/ui/model/resource/ResourceModel", "sap/ui/thirdparty/sinon", "sap/ui/thirdparty/sinon-qunit" }, new Action <Formatter>( (formatter) => { sap.ui.model.resource.ResourceModel oResourceModel = null; QUnit.module("Test Module", new Hooks() { beforeEach = (Assert assert) => { oResourceModel = new sap.ui.model.resource.ResourceModel(new sap.ui.model.resource.ResourceModel.ResourceModelInfo() { bundleUrl = jQuery.sap.getModulePath("sap.ui.demo.walkthrough", "/i18n/i18n.properties") }); }, afterEach = (Assert assert) => { oResourceModel.destroy(); } }); QUnit.test("Should return the translated texts", (Assert assert) => { // Arrange var oModel = This.Instance.As <FormatterTests>().stub(); oModel.withArgs("i18n").As <SinonStub>().returns(oResourceModel); var oViewStub = new { getModel = oModel }; var oControllerStub = new { getView = This.Instance.As <FormatterTests>().stub().returns(oViewStub) }; // System under test var fnIsolatedFormatter = Globals.BindMethod <Func <string, string> >(formatter, nameof(formatter.statusText), oControllerStub); assert.strictEqual(fnIsolatedFormatter("A"), "New", "The long text for status A is correct"); assert.strictEqual(fnIsolatedFormatter("B"), "In Progress", "The long text for status B is correct"); assert.strictEqual(fnIsolatedFormatter("C"), "Done", "The long text for status C is correct"); assert.strictEqual(fnIsolatedFormatter("Foo"), "Foo", "The long text for status Foo is correct"); } ); } ) ); }
public static void StartupScript() { sap.ui.getCore().attachInit(() => { var oProductModel = new sap.ui.model.json.JSONModel(null); oProductModel.loadData("./bridge/model/Products.json"); sap.ui.getCore().setModel(oProductModel, "products"); // Create a JSON model from an object literal var oModel = new sap.ui.model.json.JSONModel(new { firstName = "Harry", lastName = "Hawk", enabled = true, address = new { street = "Dietmar-Hopp-Allee 16", city = "Walldorf", zip = "69190", country = "Germany" }, salesToDate = 12345.6789, priceThreshold = 20, currencyCode = "EUR" }); // Assign the model object to the SAPUI5 core sap.ui.getCore().setModel(oModel); // Create a resource bundle for language specific texts var oResourceModel = new sap.ui.model.resource.ResourceModel(new sap.ui.model.resource.ResourceModel.ResourceModelInfo() { bundleName = "sap.ui.demo.db.i18n.i18n" }); // Assign the model object to the SAPUI5 core using the name "i18n" sap.ui.getCore().setModel(oResourceModel, "i18n"); // Create view var oView = new sap.ui.core.mvc.XMLView(new sap.ui.core.mvc.XMLView.Settings() { viewName = "sap.ui.demo.db.view.App" } ); // Register the view with the message manager sap.ui.getCore().getMessageManager().registerObject(oView, true); // Insert the view into the DOM oView.placeAt("content"); }); }
public override void init() { // call the init function of the parent base.init(); // set data model var oData = new ViewModel() { recipient = new ViewModel.ViewModelRecipient { name = "World" } }; var oModel = new sap.ui.model.json.JSONModel(oData); this.setModel(oModel); // set i18n model var i18nModel = new sap.ui.model.resource.ResourceModel(new sap.ui.model.resource.ResourceModel.ResourceModelInfo() { bundleName = "sap.ui.demo.walkthrough.i18n.i18n" }); this.setModel(i18nModel, "i18n"); // set invoice model //var invoiceModel = new sap.ui.model.odata.v2.ODataModel("https://cors-anywhere.herokuapp.com/services.odata.org/V2/Northwind/Northwind.svc/"); var invoiceModel = new sap.ui.model.json.JSONModel("/invoices.json"); this.setModel(invoiceModel, "invoice"); // set device model var oDeviceModel = new sap.ui.model.json.JSONModel(jQuery.sap.getObject("sap.ui.Device")); oDeviceModel.setDefaultBindingMode(sap.ui.model.BindingMode.OneWay); this.setModel(oDeviceModel, "device"); // set dialog helloDialog = new HelloDialog(this.getRootControl <sap.ui.core.mvc.View>()); // initialize the routing stuff this.getRouter().initialize(); }