Sentinel() публичный Метод

When an exception is thrown, we can pass a sentinel string into the context. This is a secret internal string that somehow marks the point that the code has reached. This can be picked up in unit tests to determine that not only was the right type of exception was thrown, but that it was thrown for the right reason. Secret sentinel strings have the advantages of being easy to make up on the spot and immunity to internationalisation, which makes them better than methods that compare error messages, which can change on a whim. To mark a moment in the code, access the context object via this method like this: myContext.Sentinel("My meaningful string"); // returns myContext
public Sentinel ( string sentinelLabel ) : SwiffotronContext
sentinelLabel string An arbitrary string.
Результат SwiffotronContext
Пример #1
0
        /// <summary>
        /// Opens a stream from a store by its key string.
        /// </summary>
        /// <param name="key">The key, including store prefix</param>
        /// <returns>A stream, or null if not found.</returns>
        public Stream Open(SwiffotronContext ctx, string key)
        {
            Uri storeURI = new Uri(key);

            if (storeURI.Scheme != "store") /* ISSUE 67: Constants, please. */
            {
                throw new SwiffotronException(
                          SwiffotronError.BadInputXML,
                          ctx,
                          @"Store paths should begin with store://");
            }

            string storeId = storeURI.Host;

            if (!stores.ContainsKey(storeId))
            {
                throw new SwiffotronException(
                          SwiffotronError.BadInputXML,
                          ctx,
                          @"Store '" + storeId + @"' not registered.");
            }

            try
            {
                return(stores[storeId].OpenInput(storeURI.LocalPath.Substring(1)));
            }
            catch (FileNotFoundException fnfe)
            {
                throw new SwiffotronException(
                          SwiffotronError.BadPathOrID,
                          ctx.Sentinel("FileNotFoundInStore"),
                          "File not found: " + key,
                          fnfe);
            }
        }
Пример #2
0
        /// <summary>
        /// Opens a stream from a store by its key string.
        /// </summary>
        /// <param name="key">The key, including store prefix</param>
        /// <returns>A stream, or null if not found.</returns>
        public Stream Open(SwiffotronContext ctx, string key)
        {
            Uri storeURI = new Uri(key);

            if (storeURI.Scheme != "store") /* ISSUE 67: Constants, please. */
            {
                throw new SwiffotronException(
                        SwiffotronError.BadInputXML,
                        ctx,
                        @"Store paths should begin with store://");
            }

            string storeId = storeURI.Host;

            if (!stores.ContainsKey(storeId))
            {
                throw new SwiffotronException(
                        SwiffotronError.BadInputXML,
                        ctx,
                        @"Store '" + storeId + @"' not registered.");
            }

            try
            {
                return stores[storeId].OpenInput(storeURI.LocalPath.Substring(1));
            }
            catch (FileNotFoundException fnfe)
            {
                throw new SwiffotronException(
                        SwiffotronError.BadPathOrID,
                        ctx.Sentinel("FileNotFoundInStore"),
                        "File not found: " + key,
                        fnfe);
            }
        }