Exemple #1
0
        // TEST: Create displayable, verify created, create instance of displayable,
        //     verify created, delete instance, verify deleted
        private async Task <bool> CreateAndDeleteInstanceAsync()
        {
            string           testName     = "CreateAndDeleteInstance";
            string           testPhase    = "unknown";
            List <BT.ItemId> createdItems = new List <BT.ItemId>();

            try {
                using (new BTimeSpan(span => {
                    var msPerOp = (float)(span.TotalMilliseconds / createdItems.Count);
                    BasilTest.log.DebugFormat("{0} {1}: {2}s to complete test",
                                              _logHeader, testName, span.TotalSeconds);
                })) {
                    // Create an item that has a displayable
                    testPhase = "Creating displayable";
                    BT.ItemId createdDisplayableId = await CreateTestDisplayable();

                    createdItems.Add(createdDisplayableId);

                    // Verify the item has been created with a displayable by asking for it's parameters
                    testPhase = "verifying created item has been created";
                    BT.Props resp = await Client.RequestPropertiesAsync(createdDisplayableId, null);

                    if (!resp.ContainsKey("DisplayableType"))
                    {
                        throw new BasilException("Created item did not have Displayable properties");
                    }
                    ;

                    // Add AbilityInstance to the item to put it in the world
                    testPhase = "Adding AbilityInstance to displayable item";
                    resp      = await CreateInstanceAt(createdDisplayableId, 10, 11, 12);

                    BT.ItemId createdInstanceId = new BT.ItemId(resp["ItemId"]);
                    createdItems.Add(createdInstanceId);

                    // Verify the instance exists by fetching it's parameters.
                    testPhase = "Verifiying instance by fetching parameters";
                    resp      = await Client.RequestPropertiesAsync(createdInstanceId, null);

                    if (!resp.ContainsKey("Pos"))
                    {
                        throw new BasilException("After adding AbilityInstance, property 'Pos' not present");
                    }

                    // Delete the instance.
                    testPhase = "Deleting instance";
                    resp      = await Client.DeleteItemAsync(createdInstanceId);

                    createdItems.Remove(createdInstanceId);

                    // Make sure the item is deleted
                    testPhase = "Verifying cannot get fetch parameters of deleted instance";
                    bool success = false;
                    try {
                        resp = await Client.RequestPropertiesAsync(createdInstanceId, null);
                    }
                    catch (BasilException be) {
                        success = true;
                        var temp = be;  // suppress non-use warning
                    }
                    if (!success)
                    {
                        throw new BasilException("Fetched forgotton instance parameters");
                    }
                    BasilTest.log.InfoFormat("{0}: {1}: TEST SUCCESS", _logHeader, testName);
                }
            }
            catch (BasilException be) {
                BasilTest.log.InfoFormat("{0}: {1}: TEST FAILED: {2}: {3}", _logHeader, testName, testPhase, be);
            }
            catch (Exception e) {
                BasilTest.log.ErrorFormat("{0}: {1}: TEST EXCEPTION: {2}: {3}", _logHeader, testName, testPhase, e);
            }
            finally {
                CleanUpTest(createdItems);
            }

            return(false);
        }
Exemple #2
0
        // TEST: Create one Displayable, verify created, delete it, verify deleted
        private async Task CreateAndDeleteDisplayableAsync()
        {
            string           testName     = "CreateAndDeleteDisplayable";
            string           testPhase    = "unknown";
            List <BT.ItemId> createdItems = new List <BT.ItemId>();

            try {
                using (new BTimeSpan(span => {
                    var msPerOp = (float)(span.TotalMilliseconds / createdItems.Count);
                    BasilTest.log.DebugFormat("{0} {1}: {2}s to complete test",
                                              _logHeader, testName, span.TotalSeconds);
                })) {
                    // Create an item that has a displayable
                    testPhase = "Creating displayable";
                    BT.ItemId createdItemId;
                    using (new BTimeSpan(span => {
                        var msPerOp = (float)(span.TotalMilliseconds / createdItems.Count);
                        BasilTest.log.DebugFormat("{0} {1}: {2}s to create one displayable",
                                                  _logHeader, testName, span.TotalSeconds);
                    })) {
                        createdItemId = await CreateTestDisplayable();
                    };
                    createdItems.Add(createdItemId);

                    // Verify the item has been created with a displayable by asking for it's parameters
                    testPhase = "verifying created item has been created";
                    using (new BTimeSpan(span => {
                        var msPerOp = (float)(span.TotalMilliseconds / createdItems.Count);
                        BasilTest.log.DebugFormat("{0} {1}: {2}s to verify item created",
                                                  _logHeader, testName, span.TotalSeconds);
                    })) {
                        BT.Props resp = await Client.RequestPropertiesAsync(createdItemId, null);

                        if (!resp.ContainsKey("DisplayableType"))
                        {
                            throw new BasilException("Created item did not have Displayable properties");
                        }
                        ;
                    };

                    // Delete the item
                    testPhase = "Deleting the created item";
                    using (new BTimeSpan(span => {
                        var msPerOp = (float)(span.TotalMilliseconds / createdItems.Count);
                        BasilTest.log.DebugFormat("{0} {1}: {2}s to delete the one item",
                                                  _logHeader, testName, span.TotalSeconds);
                    })) {
                        BT.Props resp = await Client.DeleteItemAsync(createdItemId);
                    };

                    // Make sure we cannot get its parameters any more.
                    bool success = false;
                    try {
                        testPhase = "Verifying cannot get fetch parameters of forgotton displayable";
                        BT.Props resp = await Client.RequestPropertiesAsync(createdItemId, null);

                        // This should throw an exception as the item is not there
                        success = false;
                    }
                    catch (BasilException) {
                        success = true;
                    }
                    if (!success)
                    {
                        throw new BasilException("Fetched deleted instance parameters");
                    }
                    BasilTest.log.InfoFormat("{0}: {1}: TEST SUCCESS", _logHeader, testName);
                }
            }
            catch (BasilException be) {
                BasilTest.log.InfoFormat("{0}: {1}: TEST FAILED: {2}: {3}", _logHeader, testName, testPhase, be);
            }
            catch (Exception e) {
                BasilTest.log.ErrorFormat("{0}: {1}: TEST EXCEPTION: {2}: {3}", _logHeader, testName, testPhase, e);
            }
            finally {
                CleanUpTest(createdItems);
            }

            return;
        }