private static bool TryRewriteMethodBody(
            IImmutableDictionary <ISymbol, PrivateField> privateFields,
            IImmutableDictionary <SyntaxNode, ISymbol> references,
            ISymbol classMethod,
            out BlockSyntax body,
            out BlockSyntax newBody)
        {
            if (!references.Any())
            {
                body    = null;
                newBody = null;

                return(false);
            }

            if (!TryGetMemberBody(classMethod, out body))
            {
                // We don't know how the field is being used within this method
                foreach (var reference in references)
                {
                    privateFields[reference.Value].Excluded = true;
                }

                newBody = null;

                return(false);
            }

            ISet <SyntaxNode> rewrittenNodes;

            newBody = RewriteBody(privateFields, body, references, out rewrittenNodes);

            return(!ExcludePrivateFieldsBasedOnRewrittenNodes(privateFields, references, rewrittenNodes));
        }
示例#2
0
        public async Task TestGetModuleIdentities_WhenOffline_ReturnsEmptyList()
        {
            const string Name = "test-filters";

            var    serviceClient         = new Mock <IServiceClient>();
            string hostname              = "hostname";
            string deviceId              = "deviceId";
            string moduleSharedAccessKey = Convert.ToBase64String(Encoding.UTF8.GetBytes("primaryModuleAccessKey"));
            string gatewayHostName       = "localhost";

            serviceClient.Setup(sc => sc.GetModules()).Returns(Task.FromResult(ImmutableList <Module> .Empty.AsEnumerable()));

            // If we change to IList Mock doesn't recognize and making it a non Lambda would add a lot of complexity on this code.
            // ReSharper disable PossibleMultipleEnumeration
            serviceClient.Setup(sc => sc.CreateModules(It.Is <IEnumerable <string> >(m => m.Count() == 1 && m.First() == Name))).ThrowsAsync(new InvalidOperationException());
            // ReSharper restore PossibleMultipleEnumeration

            var module = new TestModule(Name, "v1", "test", ModuleStatus.Running, new TestConfig("image"), RestartPolicy.OnUnhealthy, DefaultConfigurationInfo, EnvVars);

            IImmutableDictionary <string, IModuleIdentity> modulesIdentities = await new ModuleIdentityLifecycleManager(serviceClient.Object, hostname, deviceId, gatewayHostName)
                                                                               .GetModuleIdentitiesAsync(ModuleSet.Create(module), ModuleSet.Empty);

            serviceClient.VerifyAll();
            Assert.False(modulesIdentities.Any());
        }
示例#3
0
        private void ReceiveRemovedNodePruningTick()
        {
            if (IsLeader && _removedNodes.Any())
            {
                InitRemovedNodePruning();
            }

            PerformRemovedNodePruning();
            TombstoneRemovedNodePruning();
        }
        public async Task TestGetModulesIdentity_WithEmptyDiff_ShouldReturnEmptyIdentities()
        {
            var    serviceClient   = new Mock <IServiceClient>();
            string hostname        = "hostname";
            string deviceId        = "deviceId";
            string gatewayHostName = "localhost";

            IImmutableDictionary <string, IModuleIdentity> modulesIdentities = await new ModuleIdentityLifecycleManager(serviceClient.Object, hostname, deviceId, gatewayHostName)
                                                                               .GetModuleIdentitiesAsync(ModuleSet.Empty, ModuleSet.Empty);

            Assert.False(modulesIdentities.Any());
        }
示例#5
0
        public async Task TestGetModulesIdentity_WithEmptyDiff_ShouldReturnEmptyIdentities()
        {
            // Arrange
            var identityManager = Mock.Of <IIdentityManager>(m => m.GetIdentities() == Task.FromResult(Enumerable.Empty <Identity>()));
            var moduleIdentityLifecycleManager = new ModuleIdentityLifecycleManager(identityManager, ModuleIdentityProviderServiceBuilder, EdgeletUri);

            // Act
            IImmutableDictionary <string, IModuleIdentity> modulesIdentities = await moduleIdentityLifecycleManager.GetModuleIdentitiesAsync(ModuleSet.Empty, ModuleSet.Empty);

            // Assert
            Assert.True(!modulesIdentities.Any());
            Mock.Get(identityManager).Verify();
        }
示例#6
0
 public ImmutableDiagram(
     [NotNull] IModel model,
     [NotNull] IImmutableDictionary <ModelNodeId, IDiagramNode> nodes,
     [NotNull] IImmutableDictionary <ModelRelationshipId, IDiagramConnector> connectors)
 {
     Model           = model;
     _nodes          = nodes;
     _connectors     = connectors;
     Nodes           = nodes.Values.ToImmutableHashSet();
     Connectors      = connectors.Values.ToImmutableHashSet();
     Rect            = CalculateRect();
     IsEmpty         = !_nodes.Any() && !_connectors.Any();
     _allShapesGraph = DiagramGraph.Create(Nodes, Connectors);
 }
示例#7
0
        public bool IsIncluded(string db, string collection)
        {
            if (!_filterMap.Any())
            {
                return(true);
            }
            else if (!_filterMap.ContainsKey(db))
            {
                return(false);
            }
            else
            {
                var collectionFilter = _filterMap[db];

                return(collectionFilter.Contains("*") ||
                       collectionFilter.Contains(collection));
            }
        }
        public ImmutableDiagram(
            [NotNull] IModel model,
            [NotNull] IImmutableDictionary <ModelNodeId, IDiagramNode> nodes,
            [NotNull] IImmutableDictionary <ModelRelationshipId, IDiagramConnector> connectors,
            [NotNull] IModelRelationshipFeatureProvider modelRelationshipFeatureProvider)
        {
            Model       = model;
            _nodes      = nodes;
            _connectors = connectors;
            _modelRelationshipFeatureProvider = modelRelationshipFeatureProvider;

            Nodes      = nodes.Values.ToImmutableHashSet();
            Connectors = connectors.Values.ToImmutableHashSet();
            Rect       = CalculateRect();
            IsEmpty    = !_nodes.Any() && !_connectors.Any();
            _diagramGraphsByRelationshipTransitivityGroup =
                CreateDiagramGraphsByRelationshipTransitivityGroup(modelRelationshipFeatureProvider, Nodes, Connectors);
        }
示例#9
0
        /// <summary>
        /// Deletes the states with specified keys (i.e., <paramref name="stateKeys"/>)
        /// updated by actions in the specified block (i.e., <paramref name="blockHash"/>).
        /// </summary>
        /// <param name="blockHash"><see cref="Block{T}.Hash"/> to delete states.
        /// </param>
        /// <param name="stateKeys">The state keys to delete which were updated by actions
        /// in the specified block (i.e., <paramref name="blockHash"/>).
        /// </param>
        /// <seealso cref="GetBlockStates"/>
        private void DeleteBlockStates(
            HashDigest <SHA256> blockHash,
            IEnumerable <string> stateKeys)
        {
            IImmutableDictionary <string, IValue> dict = GetBlockStates(blockHash);

            if (dict is null)
            {
                return;
            }

            dict = dict.RemoveRange(stateKeys);
            if (dict.Any())
            {
                SetBlockStates(blockHash, dict);
            }
            else
            {
                _stateDb.Remove(BlockStateKey(blockHash));
                _statesCache.Remove(blockHash);
            }
        }
示例#10
0
        public async Task TestGetModulesIdentity_IIdentityManagerException_ShouldReturnEmptyIdentities()
        {
            // Arrange
            var identityManager = Mock.Of <IIdentityManager>();

            Mock.Get(identityManager).Setup(m => m.GetIdentities()).ThrowsAsync(new InvalidOperationException());
            var moduleIdentityLifecycleManager = new ModuleIdentityLifecycleManager(identityManager, ModuleIdentityProviderServiceBuilder, EdgeletUri);
            var envVar = new Dictionary <string, EnvVal>();

            var       module1 = new TestModule("mod1", "v1", "test", ModuleStatus.Running, new TestConfig("image"), RestartPolicy.OnUnhealthy, DefaultConfigurationInfo, envVar);
            var       module2 = new TestModule("mod2", "v1", "test", ModuleStatus.Running, new TestConfig("image"), RestartPolicy.OnUnhealthy, DefaultConfigurationInfo, envVar);
            var       module3 = new TestModule("mod3", "v1", "test", ModuleStatus.Running, new TestConfig("image"), RestartPolicy.OnUnhealthy, DefaultConfigurationInfo, envVar);
            var       module4 = new TestModule("$edgeHub", "v1", "test", ModuleStatus.Running, new TestConfig("image"), RestartPolicy.OnUnhealthy, DefaultConfigurationInfo, envVar);
            ModuleSet desired = ModuleSet.Create(module1, module4);
            ModuleSet current = ModuleSet.Create(module2, module3, module4);

            // Act
            IImmutableDictionary <string, IModuleIdentity> modulesIdentities = await moduleIdentityLifecycleManager.GetModuleIdentitiesAsync(desired, current);

            // Assert
            Assert.False(modulesIdentities.Any());
            Mock.Get(identityManager).Verify();
        }
        private static bool TryRewriteMethodBody(
            IImmutableDictionary<ISymbol, PrivateField> privateFields,
            IImmutableDictionary<SyntaxNode, ISymbol> references,
            ISymbol classMethod,
            out BlockSyntax body,
            out BlockSyntax newBody)
        {
            if (!references.Any())
            {
                body = null;
                newBody = null;

                return false;
            }

            if (!TryGetMemberBody(classMethod, out body))
            {
                // We don't know how the field is being used within this method
                foreach (var reference in references)
                {
                    privateFields[reference.Value].Excluded = true;
                }

                newBody = null;

                return false;
            }

            ISet<SyntaxNode> rewrittenNodes;
            newBody = RewriteBody(privateFields, body, references, out rewrittenNodes);

            return !ExcludePrivateFieldsBasedOnRewrittenNodes(privateFields, references, rewrittenNodes);
        }