< Summary

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

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_BindingState()-100%100%
.ctor(...)-100%100%
ReadProperty(...)-100%100%
WriteProperty(...)-100%100%
IsAccessAllowed(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\batch\Microsoft.Azure.Batch\src\PropertyAccessController.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.Globalization;
 8
 9    /// <summary>
 10    /// Controls access to a set of properties.  All reads/writes pass through here.
 11    /// </summary>
 12    internal class PropertyAccessController
 13    {
 14        private readonly BindingState bindingState;
 15
 16        internal BindingState BindingState
 17        {
 95718            get { return this.bindingState; }
 19        }
 20
 21        /// <summary>
 22        /// Creates a new instance of a <see cref="PropertyAccessController"/>.
 23        /// </summary>
 24        /// <param name="bindingState">The binding state to set this on this acesss controller.</param>
 4991525        public PropertyAccessController(BindingState bindingState)
 26        {
 4991527            this.bindingState = bindingState;
 4991528        }
 29
 30        /// <summary>
 31        /// Executes the specified <paramref name="propertyReadAction"/>.
 32        /// </summary>
 33        /// <typeparam name="T">The type of the property to read.</typeparam>
 34        /// <param name="propertyReadAction">The property read action to execute.</param>
 35        /// <param name="allowedAccess">The allowed access of the particular property.</param>
 36        /// <param name="propertyName">The name of the property.</param>
 37        /// <returns>The result of the <paramref name="propertyReadAction"/>.</returns>
 38        public T ReadProperty<T>(Func<T> propertyReadAction, BindingAccess allowedAccess, string propertyName)
 39        {
 55243640            if (!this.IsAccessAllowed(BindingAccess.Read, allowedAccess))
 41            {
 5442                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, BatchErrorMessages.Prope
 43            }
 44
 55238245            return propertyReadAction();
 46        }
 47
 48        /// <summary>
 49        /// Executes the specified <paramref name="propertyWriteAction"/>
 50        /// </summary>
 51        /// <param name="propertyWriteAction">The write action.</param>
 52        /// <param name="allowedAccess">The allowed access of the particular property.</param>
 53        /// <param name="propertyName">The name of the property.</param>
 54        public void WriteProperty(Action propertyWriteAction, BindingAccess allowedAccess, string propertyName)
 55        {
 4123156            if (!this.IsAccessAllowed(BindingAccess.Write, allowedAccess))
 57            {
 2058                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, BatchErrorMessages.Prope
 59            }
 60
 4121161            propertyWriteAction();
 4096862        }
 63
 64        private bool IsAccessAllowed(BindingAccess requestedAccess, BindingAccess allowedAccess)
 65        {
 59366766            bool accessAllowed = allowedAccess.HasFlag(requestedAccess);
 67
 59366768            return accessAllowed;
 69        }
 70    }
 71}