< Summary

Class:Microsoft.Azure.Batch.BehaviorManager
Assembly:Microsoft.Azure.Batch
File(s):C:\Git\azure-sdk-for-net\sdk\batch\Microsoft.Azure.Batch\src\BehaviorManager.cs
Covered lines:35
Uncovered lines:0
Coverable lines:35
Total lines:119
Line coverage:100% (35 of 35)
Covered branches:14
Total branches:14
Branch coverage:100% (14 of 14)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-100%100%
.ctor(...)-100%100%
get_BaseBehaviors()-100%100%
get_PerCallBehaviors()-100%100%
get_MasterListOfBehaviors()-100%100%
CreateBehaviorManagerWithDetailLevel(...)-100%100%
GetBehaviors()-100%100%
AppendDetailLevel(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\batch\Microsoft.Azure.Batch\src\BehaviorManager.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License. See License.txt in the project root for license information.
 3
 4namespace Microsoft.Azure.Batch
 5{
 6    using System;
 7    using System.Collections.Generic;
 8    using System.Linq;
 9
 10    /// <summary>
 11    /// Tools for managing multiple collections of behaviors.
 12    /// </summary>
 13    internal class BehaviorManager
 14    {
 29415        internal BehaviorManager(
 29416            IEnumerable<BatchClientBehavior> baseBehaviors,
 29417            IEnumerable<BatchClientBehavior> perCallBehaviors,
 29418            DetailLevel detailLevel = null)
 19        {
 29420            this.BaseBehaviors = new List<BatchClientBehavior>();
 21
 29422            if (null != baseBehaviors)
 23            {
 29424                this.BaseBehaviors.AddRange(baseBehaviors);
 25            }
 26
 29427            this.PerCallBehaviors = new List<BatchClientBehavior>();
 28
 29429            if (null != perCallBehaviors)
 30            {
 17231                this.PerCallBehaviors.AddRange(perCallBehaviors);
 32            }
 33
 29434            if (detailLevel != null)
 35            {
 236                this.AppendDetailLevel(detailLevel);
 37            }
 29438        }
 39
 3340        private BehaviorManager(BehaviorManager other)
 41        {
 3342            this.BaseBehaviors = new List<BatchClientBehavior>(other.BaseBehaviors);
 3343            this.PerCallBehaviors = new List<BatchClientBehavior>(other.PerCallBehaviors);
 3344        }
 45
 100046        internal List<BatchClientBehavior> BaseBehaviors { get; set; }
 85747        internal List<BatchClientBehavior> PerCallBehaviors { get; set; }
 48
 49        /// <summary>
 50        /// Returns a new list of behaviors that is the concatination of the base + per-call.
 51        /// </summary>
 52        internal List<BatchClientBehavior> MasterListOfBehaviors
 53        {
 54            get
 55            {
 31256                List<BatchClientBehavior> ml = new List<BatchClientBehavior>(this.BaseBehaviors);
 57
 31258                ml.AddRange(this.PerCallBehaviors);
 59
 31260                return ml;
 61            }
 62        }
 63
 64        /* On "impl" inheritance
 65         *
 66         * Impls like GetNodeFileAsyncImpl cannot/must-not honor inheritance by propagating behaviors
 67         * from the manager or outter class... the new child objects get their base from
 68         * BehaviorMangaer.BaseBehaviors.
 69         *
 70         * When we add features like DetailLevel.. they must not taint the base
 71         * collection... or children will get them.
 72         *
 73         * By corallary, such features should probably not taint the PerCallBeahviors either.
 74         * We need an "Inbetween" collection.
 75         *
 76         * There is a bug on Detaillevel order-of-execution and this work should be part of that bug.
 77         *
 78        */
 79        internal BehaviorManager CreateBehaviorManagerWithDetailLevel(DetailLevel detailLevel)
 80        {
 81            //Copy "this"
 3382            BehaviorManager result = new BehaviorManager(this);
 83
 3384            result.AppendDetailLevel(detailLevel);
 3385            return result;
 86        }
 87
 88        /// <summary>
 89        /// Gets an ordered list of behaviors of the specific type.
 90        /// </summary>
 91        /// <typeparam name="T"></typeparam>
 92        /// <returns></returns>
 93        internal List<T> GetBehaviors<T>() where T : BatchClientBehavior
 94        {
 8295            List<T> result = new List<T>();
 96            //Find all behaviors of type T and get the (in order)
 48497            foreach (BatchClientBehavior behavior in this.MasterListOfBehaviors)
 98            {
 16099                T typedBehavior = behavior as T;
 160100                if (typedBehavior != null)
 101                {
 8102                    result.Add(typedBehavior);
 103                }
 104            }
 105
 82106            return result;
 107        }
 108
 109        private void AppendDetailLevel(DetailLevel detailLevel)
 110        {
 35111            if ((null != detailLevel) && (detailLevel is ODATADetailLevel))
 112            {
 13113                ODATADetailLevelIntercept intercept = new ODATADetailLevelIntercept(detailLevel as ODATADetailLevel);
 114
 13115                this.PerCallBehaviors.Add(intercept);
 116            }
 35117        }
 118    }
 119}