示例#1
0
        public async void GetDeploymentConfigTest2()
        {
            // Arrange
            var    runtimeInfo       = Mock.Of <IRuntimeInfo>();
            var    edgeHubModule     = Mock.Of <IEdgeHubModule>(m => m.Name == "$edgeHub");
            var    edgeAgentModule   = Mock.Of <IEdgeAgentModule>(m => m.Name == "$edgeAgent");
            var    systemModules     = new SystemModules(edgeAgentModule, edgeHubModule);
            string customModule1Name = null;
            string customModule2Name = null;
            var    customModule1     = Mock.Of <IModule>();
            var    customModule2     = Mock.Of <IModule>();

            Mock.Get(customModule1).SetupSet(n => n.Name = It.IsAny <string>()).Callback <string>(n => customModule1Name = n);
            Mock.Get(customModule2).SetupSet(n => n.Name = It.IsAny <string>()).Callback <string>(n => customModule2Name = n);
            IDictionary <string, IModule> modules = new Dictionary <string, IModule>
            {
                ["module1"] = customModule1,
                ["module2"] = customModule2
            };
            var deploymentConfig     = new DeploymentConfig("1.0", runtimeInfo, systemModules, modules);
            var deploymentConfigInfo = new DeploymentConfigInfo(5, deploymentConfig);

            var edgeAgentConnection = new Mock <IEdgeAgentConnection>();

            edgeAgentConnection.Setup(e => e.GetDeploymentConfigInfoAsync()).ReturnsAsync(Option.Some(deploymentConfigInfo));
            var configuration    = Mock.Of <IConfiguration>();
            var twinConfigSource = new TwinConfigSource(edgeAgentConnection.Object, configuration);

            // Act
            DeploymentConfigInfo receivedDeploymentConfigInfo = await twinConfigSource.GetDeploymentConfigInfoAsync();

            // Assert
            Assert.NotNull(receivedDeploymentConfigInfo);
            Assert.NotNull(receivedDeploymentConfigInfo.DeploymentConfig);
            Assert.Equal(5, receivedDeploymentConfigInfo.Version);

            DeploymentConfig returnedDeploymentConfig = receivedDeploymentConfigInfo.DeploymentConfig;

            Assert.Equal(Option.Some(edgeAgentModule), returnedDeploymentConfig.SystemModules.EdgeAgent);
            Assert.Equal(Option.Some(edgeHubModule), returnedDeploymentConfig.SystemModules.EdgeHub);
            ModuleSet moduleSet = returnedDeploymentConfig.GetModuleSet();

            Assert.Equal(4, returnedDeploymentConfig.GetModuleSet().Modules.Count);
            Assert.Equal(customModule1.Name, moduleSet.Modules["module1"].Name);
            Assert.Equal(customModule2.Name, moduleSet.Modules["module2"].Name);
            Assert.Equal(edgeHubModule.Name, moduleSet.Modules["$edgeHub"].Name);
            Assert.Equal(edgeAgentModule.Name, moduleSet.Modules["$edgeAgent"].Name);
            Assert.Equal("module1", customModule1Name);
            Assert.Equal("module2", customModule2Name);
        }
示例#2
0
        public void BasicTest()
        {
            var edgeAgentModule = Mock.Of <IEdgeAgentModule>(m => m.Name == "edgeAgent");
            var edgeHubModule   = Mock.Of <IEdgeHubModule>(m => m.Name == "edgeHub");
            var systemModules   = new SystemModules(edgeAgentModule, edgeHubModule);

            var mod1 = new TestModule(null, string.Empty, "test", ModuleStatus.Running, new TestConfig("mod1"), RestartPolicy.Always, ImagePullPolicy.OnCreate, Constants.DefaultPriority, new ConfigurationInfo(), null);
            var mod2 = new TestModule(null, string.Empty, "test", ModuleStatus.Running, new TestConfig("mod2"), RestartPolicy.Always, ImagePullPolicy.OnCreate, Constants.DefaultPriority, new ConfigurationInfo(), null);

            var modules = new Dictionary <string, IModule>
            {
                ["mod1"] = mod1,
                ["mod2"] = mod2
            };

            var deploymentConfig = new DeploymentConfig("1.0", Mock.Of <IRuntimeInfo>(), systemModules, modules);

            Assert.Equal("mod1", deploymentConfig.Modules["mod1"].Name);
            Assert.Equal("mod2", deploymentConfig.Modules["mod2"].Name);

            ModuleSet moduleSet = deploymentConfig.GetModuleSet();

            Assert.NotNull(moduleSet);
            Assert.Equal(4, moduleSet.Modules.Count);
            Assert.Equal(edgeHubModule.Name, moduleSet.Modules["edgeHub"].Name);
            Assert.Equal(edgeAgentModule.Name, moduleSet.Modules["edgeAgent"].Name);
            Assert.Equal(modules["mod1"].Name, moduleSet.Modules["mod1"].Name);
            Assert.Equal(modules["mod2"].Name, moduleSet.Modules["mod2"].Name);
        }
示例#3
0
        public async void ReconcileAsyncOnSetPlan()
        {
            var desiredModule       = new TestModule("desired", "v1", "test", ModuleStatus.Running, new TestConfig("image"), RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, new ConfigurationInfo("1"), null);
            var currentModule       = new TestModule("current", "v1", "test", ModuleStatus.Running, new TestConfig("image"), RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, new ConfigurationInfo("1"), null);
            var recordKeeper        = Option.Some(new TestPlanRecorder());
            var moduleExecutionList = new List <TestRecordType>
            {
                new TestRecordType(TestCommandType.TestCreate, desiredModule),
                new TestRecordType(TestCommandType.TestRemove, currentModule)
            };
            var commandList = new List <ICommand>
            {
                new TestCommand(TestCommandType.TestCreate, desiredModule, recordKeeper),
                new TestCommand(TestCommandType.TestRemove, currentModule, recordKeeper)
            };
            var testPlan = new Plan(commandList);

            var token = new CancellationToken();

            var runtimeInfo      = Mock.Of <IRuntimeInfo>();
            var deploymentConfig = new DeploymentConfig("1.0", runtimeInfo, new SystemModules(null, null), new Dictionary <string, IModule> {
                ["desired"] = desiredModule
            });
            var       deploymentConfigInfo = new DeploymentConfigInfo(0, deploymentConfig);
            ModuleSet desiredSet           = deploymentConfig.GetModuleSet();
            ModuleSet currentSet           = ModuleSet.Create(currentModule);

            var mockConfigSource = new Mock <IConfigSource>();
            var mockEnvironment  = new Mock <IEnvironment>();
            var mockPlanner      = new Mock <IPlanner>();
            var planRunner       = new OrderedPlanRunner();
            var mockReporter     = new Mock <IReporter>();
            var mockModuleIdentityLifecycleManager = new Mock <IModuleIdentityLifecycleManager>();
            var configStore             = Mock.Of <IEntityStore <string, string> >();
            var mockEnvironmentProvider = Mock.Of <IEnvironmentProvider>(m => m.Create(It.IsAny <DeploymentConfig>()) == mockEnvironment.Object);
            var serde = Mock.Of <ISerde <DeploymentConfigInfo> >();
            var encryptionDecryptionProvider = Mock.Of <IEncryptionProvider>();

            mockConfigSource.Setup(cs => cs.GetDeploymentConfigInfoAsync())
            .ReturnsAsync(deploymentConfigInfo);
            mockEnvironment.Setup(env => env.GetModulesAsync(token))
            .ReturnsAsync(currentSet);
            mockModuleIdentityLifecycleManager.Setup(m => m.GetModuleIdentitiesAsync(desiredSet, currentSet))
            .ReturnsAsync(ImmutableDictionary <string, IModuleIdentity> .Empty);
            mockPlanner.Setup(pl => pl.PlanAsync(It.IsAny <ModuleSet>(), currentSet, runtimeInfo, ImmutableDictionary <string, IModuleIdentity> .Empty))
            .Returns(Task.FromResult(testPlan));
            mockModuleIdentityLifecycleManager.Setup(m => m.GetModuleIdentitiesAsync(It.IsAny <ModuleSet>(), currentSet))
            .Returns(Task.FromResult((IImmutableDictionary <string, IModuleIdentity>)ImmutableDictionary <string, IModuleIdentity> .Empty));
            mockReporter.Setup(r => r.ReportAsync(token, It.IsAny <ModuleSet>(), It.IsAny <IRuntimeInfo>(), It.IsAny <long>(), Option.Some(DeploymentStatus.Success)))
            .Returns(Task.CompletedTask);

            var agent = new Agent(mockConfigSource.Object, mockEnvironmentProvider, mockPlanner.Object, planRunner, mockReporter.Object, mockModuleIdentityLifecycleManager.Object, configStore, DeploymentConfigInfo.Empty, serde, encryptionDecryptionProvider);

            await agent.ReconcileAsync(token);

            mockEnvironment.Verify(env => env.GetModulesAsync(token), Times.Exactly(1));
            mockPlanner.Verify(pl => pl.PlanAsync(It.IsAny <ModuleSet>(), currentSet, runtimeInfo, ImmutableDictionary <string, IModuleIdentity> .Empty), Times.Once);
            mockReporter.VerifyAll();
            recordKeeper.ForEach(r => Assert.Equal(moduleExecutionList, r.ExecutionList));
        }
示例#4
0
        public void BasicTest(string[] signercert, string[] intermediatecacert, string signature, string algo)
        {
            var edgeAgentModule = Mock.Of <IEdgeAgentModule>(m => m.Name == "edgeAgent");
            var edgeHubModule   = Mock.Of <IEdgeHubModule>(m => m.Name == "edgeHub");
            var systemModules   = new SystemModules(edgeAgentModule, edgeHubModule);

            var mod1 = new TestModule(null, string.Empty, "test", ModuleStatus.Running, new TestConfig("mod1"), RestartPolicy.Always, ImagePullPolicy.OnCreate, Constants.DefaultStartupOrder, new ConfigurationInfo(), null);
            var mod2 = new TestModule(null, string.Empty, "test", ModuleStatus.Running, new TestConfig("mod2"), RestartPolicy.Always, ImagePullPolicy.OnCreate, Constants.DefaultStartupOrder, new ConfigurationInfo(), null);

            var modules = new Dictionary <string, IModule>
            {
                ["mod1"] = mod1,
                ["mod2"] = mod2
            };
            var deploymentConfig                  = new DeploymentConfig("1.0", Mock.Of <IRuntimeInfo>(), systemModules, modules, null);
            ManifestIntegrity integrity           = new ManifestIntegrity(new TwinHeader(signercert, intermediatecacert), new TwinSignature(signature, algo));
            var deploymentConfigWithTwinIntegrity = new DeploymentConfig("1.0", Mock.Of <IRuntimeInfo>(), systemModules, modules, integrity);

            Assert.Equal("mod1", deploymentConfig.Modules["mod1"].Name);
            Assert.Equal("mod2", deploymentConfig.Modules["mod2"].Name);

            ModuleSet moduleSet = deploymentConfig.GetModuleSet();

            Assert.NotNull(moduleSet);
            Assert.Equal(4, moduleSet.Modules.Count);
            Assert.Equal(edgeHubModule.Name, moduleSet.Modules["edgeHub"].Name);
            Assert.Equal(edgeAgentModule.Name, moduleSet.Modules["edgeAgent"].Name);
            Assert.Equal(modules["mod1"].Name, moduleSet.Modules["mod1"].Name);
            Assert.Equal(modules["mod2"].Name, moduleSet.Modules["mod2"].Name);
            Assert.Equal(deploymentConfigWithTwinIntegrity.Integrity, Option.Some(integrity));
        }
示例#5
0
        public async void ReconcileAsyncReportsFailedWhenEncryptProviderThrows()
        {
            var token                              = default(CancellationToken);
            var serde                              = Mock.Of <ISerde <DeploymentConfigInfo> >();
            var mockConfigSource                   = new Mock <IConfigSource>();
            var mockEnvironment                    = new Mock <IEnvironment>();
            var mockEnvironmentProvider            = new Mock <IEnvironmentProvider>();
            var mockPlanner                        = new Mock <IPlanner>();
            var mockPlanRunner                     = new Mock <IPlanRunner>();
            var mockReporter                       = new Mock <IReporter>();
            var mockModuleIdentityLifecycleManager = new Mock <IModuleIdentityLifecycleManager>();
            var runtimeInfo                        = Mock.Of <IRuntimeInfo>();
            var configStore                        = Mock.Of <IEntityStore <string, string> >();
            var encryptionDecryptionProvider       = new Mock <IEncryptionProvider>();
            var availabilityMetric                 = Mock.Of <IAvailabilityMetric>();
            var deploymentConfig                   = new DeploymentConfig(
                "1.0",
                runtimeInfo,
                new SystemModules(null, null),
                new Dictionary <string, IModule>
            {
                { "mod1", new TestModule("mod1", "1.0", "docker", ModuleStatus.Running, new TestConfig("boo"), RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, new ConfigurationInfo("1"), null) }
            });
            var       desiredModule        = new TestModule("desired", "v1", "test", ModuleStatus.Running, new TestConfig("image"), RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, new ConfigurationInfo("1"), null);
            var       recordKeeper         = Option.Some(new TestPlanRecorder());
            var       deploymentConfigInfo = new DeploymentConfigInfo(0, deploymentConfig);
            ModuleSet desiredModuleSet     = deploymentConfig.GetModuleSet();
            ModuleSet currentModuleSet     = desiredModuleSet;

            var commandList = new List <ICommand>
            {
                new TestCommand(TestCommandType.TestCreate, desiredModule, recordKeeper)
            };
            var testPlan = new Plan(commandList);

            mockEnvironmentProvider.Setup(m => m.Create(It.IsAny <DeploymentConfig>())).Returns(mockEnvironment.Object);
            mockConfigSource.Setup(cs => cs.GetDeploymentConfigInfoAsync())
            .ReturnsAsync(deploymentConfigInfo);
            mockEnvironment.Setup(env => env.GetModulesAsync(token))
            .ReturnsAsync(currentModuleSet);
            mockEnvironment.Setup(env => env.GetRuntimeInfoAsync()).ReturnsAsync(runtimeInfo);
            mockModuleIdentityLifecycleManager.Setup(m => m.GetModuleIdentitiesAsync(It.Is <ModuleSet>(ms => ms.Equals(desiredModuleSet)), currentModuleSet))
            .ReturnsAsync(ImmutableDictionary <string, IModuleIdentity> .Empty);
            mockPlanner.Setup(pl => pl.PlanAsync(It.Is <ModuleSet>(ms => ms.Equals(desiredModuleSet)), currentModuleSet, runtimeInfo, ImmutableDictionary <string, IModuleIdentity> .Empty))
            .ReturnsAsync(testPlan);
            encryptionDecryptionProvider.Setup(ep => ep.EncryptAsync(It.IsAny <string>()))
            .ThrowsAsync(new WorkloadCommunicationException("failed", 404));

            var agent = new Agent(mockConfigSource.Object, mockEnvironmentProvider.Object, mockPlanner.Object, mockPlanRunner.Object, mockReporter.Object, mockModuleIdentityLifecycleManager.Object, configStore, DeploymentConfigInfo.Empty, serde, encryptionDecryptionProvider.Object, availabilityMetric);

            await agent.ReconcileAsync(token);

            // Assert
            mockPlanner.Verify(p => p.PlanAsync(It.IsAny <ModuleSet>(), It.IsAny <ModuleSet>(), It.IsAny <IRuntimeInfo>(), It.IsAny <ImmutableDictionary <string, IModuleIdentity> >()), Times.Once);
            mockReporter.Verify(r => r.ReportAsync(It.IsAny <CancellationToken>(), It.IsAny <ModuleSet>(), It.IsAny <IRuntimeInfo>(), 0, new DeploymentStatus(DeploymentStatusCode.Failed, "failed")));
            mockPlanRunner.Verify(r => r.ExecuteAsync(0, It.IsAny <Plan>(), token), Times.Once);
            encryptionDecryptionProvider.Verify(ep => ep.EncryptAsync(It.IsAny <string>()), Times.Exactly(2));
        }
示例#6
0
        public async void ReconcileAsyncOnEmptyPlan()
        {
            var token                              = default(CancellationToken);
            var serde                              = Mock.Of <ISerde <DeploymentConfigInfo> >();
            var mockConfigSource                   = new Mock <IConfigSource>();
            var mockEnvironment                    = new Mock <IEnvironment>();
            var mockEnvironmentProvider            = new Mock <IEnvironmentProvider>();
            var mockPlanner                        = new Mock <IPlanner>();
            var mockPlanRunner                     = new Mock <IPlanRunner>();
            var mockReporter                       = new Mock <IReporter>();
            var mockModuleIdentityLifecycleManager = new Mock <IModuleIdentityLifecycleManager>();
            var runtimeInfo                        = Mock.Of <IRuntimeInfo>();
            var configStore                        = Mock.Of <IEntityStore <string, string> >();
            var encryptionDecryptionProvider       = Mock.Of <IEncryptionProvider>();
            var availabilityMetric                 = Mock.Of <IAvailabilityMetric>();

            var deploymentConfig = new DeploymentConfig(
                "1.0",
                runtimeInfo,
                new SystemModules(null, null),
                new Dictionary <string, IModule>
            {
                { "mod1", new TestModule("mod1", "1.0", "docker", ModuleStatus.Running, new TestConfig("boo"), RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, new ConfigurationInfo("1"), null) }
            });
            var       deploymentConfigInfo = new DeploymentConfigInfo(0, deploymentConfig);
            ModuleSet desiredModuleSet     = deploymentConfig.GetModuleSet();
            ModuleSet currentModuleSet     = desiredModuleSet;

            mockEnvironmentProvider.Setup(m => m.Create(It.IsAny <DeploymentConfig>())).Returns(mockEnvironment.Object);
            mockConfigSource.Setup(cs => cs.GetDeploymentConfigInfoAsync())
            .ReturnsAsync(deploymentConfigInfo);
            mockEnvironment.Setup(env => env.GetModulesAsync(token))
            .ReturnsAsync(currentModuleSet);
            mockEnvironment.Setup(env => env.GetRuntimeInfoAsync()).ReturnsAsync(runtimeInfo);
            mockModuleIdentityLifecycleManager.Setup(m => m.GetModuleIdentitiesAsync(It.Is <ModuleSet>(ms => ms.Equals(desiredModuleSet)), currentModuleSet))
            .ReturnsAsync(ImmutableDictionary <string, IModuleIdentity> .Empty);
            mockPlanner.Setup(pl => pl.PlanAsync(It.Is <ModuleSet>(ms => ms.Equals(desiredModuleSet)), currentModuleSet, runtimeInfo, ImmutableDictionary <string, IModuleIdentity> .Empty))
            .Returns(Task.FromResult(Plan.Empty));

            var agent = new Agent(mockConfigSource.Object, mockEnvironmentProvider.Object, mockPlanner.Object, mockPlanRunner.Object, mockReporter.Object, mockModuleIdentityLifecycleManager.Object, configStore, DeploymentConfigInfo.Empty, serde, encryptionDecryptionProvider, availabilityMetric);

            await agent.ReconcileAsync(token);

            mockEnvironment.Verify(env => env.GetModulesAsync(token), Times.Once);
            mockPlanner.Verify(pl => pl.PlanAsync(It.Is <ModuleSet>(ms => ms.Equals(desiredModuleSet)), currentModuleSet, runtimeInfo, ImmutableDictionary <string, IModuleIdentity> .Empty), Times.Once);
            mockReporter.Verify(r => r.ReportAsync(token, currentModuleSet, runtimeInfo, DeploymentConfigInfo.Empty.Version, DeploymentStatus.Success), Times.Once);
            mockPlanRunner.Verify(r => r.ExecuteAsync(1, Plan.Empty, token), Times.Never);
        }
示例#7
0
        public async void ReconcileAsyncWithNoDeploymentChange()
        {
            var desiredModule = new TestModule("CustomModule", "v1", "test", ModuleStatus.Running, new TestConfig("image"), RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, new ConfigurationInfo("1"), null);
            var currentModule = new TestModule("CustomModule", "v1", "test", ModuleStatus.Running, new TestConfig("image"), RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, new ConfigurationInfo("1"), null);

            var testPlan         = new Plan(new List <ICommand>());
            var token            = default(CancellationToken);
            var runtimeInfo      = Mock.Of <IRuntimeInfo>();
            var deploymentConfig = new DeploymentConfig("1.0", runtimeInfo, new SystemModules(null, null), new Dictionary <string, IModule> {
                ["CustomModule"] = desiredModule
            });
            var       deploymentConfigInfo = new DeploymentConfigInfo(0, deploymentConfig);
            ModuleSet desiredSet           = deploymentConfig.GetModuleSet();
            ModuleSet currentSet           = ModuleSet.Create(currentModule);

            var mockConfigSource = new Mock <IConfigSource>();
            var mockEnvironment  = new Mock <IEnvironment>();
            var mockPlanner      = new Mock <IPlanner>();
            var planRunner       = new OrderedPlanRunner();
            var mockReporter     = new Mock <IReporter>();
            var mockModuleIdentityLifecycleManager = new Mock <IModuleIdentityLifecycleManager>();
            var configStore             = Mock.Of <IEntityStore <string, string> >();
            var mockEnvironmentProvider = Mock.Of <IEnvironmentProvider>(m => m.Create(It.IsAny <DeploymentConfig>()) == mockEnvironment.Object);
            var serde = Mock.Of <ISerde <DeploymentConfigInfo> >();
            var encryptionDecryptionProvider = Mock.Of <IEncryptionProvider>();
            var availabilityMetric           = Mock.Of <IAvailabilityMetric>();

            mockConfigSource.Setup(cs => cs.GetDeploymentConfigInfoAsync())
            .ReturnsAsync(deploymentConfigInfo);
            mockEnvironment.Setup(env => env.GetModulesAsync(token))
            .ReturnsAsync(currentSet);
            mockModuleIdentityLifecycleManager.Setup(m => m.GetModuleIdentitiesAsync(desiredSet, currentSet))
            .ReturnsAsync(ImmutableDictionary <string, IModuleIdentity> .Empty);
            mockPlanner.Setup(pl => pl.PlanAsync(It.IsAny <ModuleSet>(), currentSet, runtimeInfo, ImmutableDictionary <string, IModuleIdentity> .Empty))
            .Returns(Task.FromResult(testPlan));
            mockReporter.Setup(r => r.ReportAsync(token, It.IsAny <ModuleSet>(), It.IsAny <IRuntimeInfo>(), It.IsAny <long>(), DeploymentStatus.Success))
            .Returns(Task.CompletedTask);

            var agent = new Agent(mockConfigSource.Object, mockEnvironmentProvider, mockPlanner.Object, planRunner, mockReporter.Object, mockModuleIdentityLifecycleManager.Object, configStore, DeploymentConfigInfo.Empty, serde, encryptionDecryptionProvider, availabilityMetric);

            await agent.ReconcileAsync(token);

            mockEnvironment.Verify(env => env.GetModulesAsync(token), Times.Exactly(1));
            mockPlanner.Verify(pl => pl.PlanAsync(It.IsAny <ModuleSet>(), currentSet, runtimeInfo, ImmutableDictionary <string, IModuleIdentity> .Empty), Times.Once);
            mockReporter.Verify(r => r.ReportAsync(token, It.IsAny <ModuleSet>(), It.IsAny <IRuntimeInfo>(), It.IsAny <long>(), DeploymentStatus.Success), Times.Once);
        }
示例#8
0
        public async void ReconcileAsyncAbortsWhenModuleIdentityLifecycleManagerThrows()
        {
            // Arrange
            var mockConfigSource = new Mock <IConfigSource>();
            var mockEnvironment  = new Mock <IEnvironment>();
            var mockPlanner      = new Mock <IPlanner>();
            var mockPlanRunner   = new Mock <IPlanRunner>();
            var mockReporter     = new Mock <IReporter>();
            var token            = default(CancellationToken);
            var mockModuleIdentityLifecycleManager = new Mock <IModuleIdentityLifecycleManager>();
            var configStore             = Mock.Of <IEntityStore <string, string> >();
            var mockEnvironmentProvider = Mock.Of <IEnvironmentProvider>(m => m.Create(It.IsAny <DeploymentConfig>()) == mockEnvironment.Object);
            var serde = Mock.Of <ISerde <DeploymentConfigInfo> >();
            var encryptionDecryptionProvider = Mock.Of <IEncryptionProvider>();
            var availabilityMetric           = Mock.Of <IAvailabilityMetric>();

            var deploymentConfig = new DeploymentConfig(
                "1.0",
                Mock.Of <IRuntimeInfo>(),
                new SystemModules(null, null),
                new Dictionary <string, IModule>
            {
                { "mod1", new TestModule("mod1", "1.0", "docker", ModuleStatus.Running, new TestConfig("boo"), RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, new ConfigurationInfo("1"), null) }
            });
            var       deploymentConfigInfo = new DeploymentConfigInfo(0, deploymentConfig);
            ModuleSet desiredModuleSet     = deploymentConfig.GetModuleSet();

            mockConfigSource.Setup(cs => cs.GetDeploymentConfigInfoAsync())
            .ReturnsAsync(deploymentConfigInfo);
            mockEnvironment.Setup(env => env.GetModulesAsync(token))
            .ReturnsAsync(ModuleSet.Empty);
            mockModuleIdentityLifecycleManager.Setup(m => m.GetModuleIdentitiesAsync(It.Is <ModuleSet>(ms => ms.Equals(desiredModuleSet)), ModuleSet.Empty))
            .Throws <InvalidOperationException>();
            mockReporter.Setup(r => r.ReportAsync(token, It.IsAny <ModuleSet>(), It.IsAny <IRuntimeInfo>(), It.IsAny <long>(), It.Is <DeploymentStatus>(s => s.Code == DeploymentStatusCode.Failed)))
            .Returns(Task.CompletedTask);

            var agent = new Agent(mockConfigSource.Object, mockEnvironmentProvider, mockPlanner.Object, mockPlanRunner.Object, mockReporter.Object, mockModuleIdentityLifecycleManager.Object, configStore, DeploymentConfigInfo.Empty, serde, encryptionDecryptionProvider, availabilityMetric);

            // Act
            // Assert
            await agent.ReconcileAsync(token);

            mockPlanner.Verify(p => p.PlanAsync(It.IsAny <ModuleSet>(), It.IsAny <ModuleSet>(), It.IsAny <IRuntimeInfo>(), It.IsAny <ImmutableDictionary <string, IModuleIdentity> >()), Times.Never);
            mockReporter.VerifyAll();
            mockPlanRunner.Verify(r => r.ExecuteAsync(1, It.IsAny <Plan>(), token), Times.Never);
        }