Exemple #1
0
        public async void FileBackupSuccessWhenFileNotExists()
        {
            if (File.Exists(this.tempFileName))
            {
                File.Delete(this.tempFileName);
            }

            var underlying = new Mock <IConfigSource>();

            underlying.SetupSequence(t => t.GetDeploymentConfigInfoAsync())
            .ReturnsAsync(ValidConfigInfo1)
            .ThrowsAsync(new InvalidOperationException());
            ISerde <DeploymentConfigInfo> serde = this.GetSerde();

            using (IConfigSource configSource = new FileBackupConfigSource(this.tempFileName, underlying.Object, serde, NullEncryptionProvider.Instance))
            {
                DeploymentConfigInfo config1 = await configSource.GetDeploymentConfigInfoAsync();

                Assert.NotNull(config1);

                Assert.True(File.Exists(this.tempFileName));
                string backupJson = await DiskFile.ReadAllAsync(this.tempFileName);

                string returnedJson = serde.Serialize(config1);

                Assert.True(string.Equals(backupJson, returnedJson, StringComparison.OrdinalIgnoreCase));

                DeploymentConfigInfo config2 = await configSource.GetDeploymentConfigInfoAsync();

                Assert.NotNull(config2);

                Assert.Equal(serde.Serialize(config1), serde.Serialize(config2));
            }
        }
Exemple #2
0
        public async void FileBackupDoesNotThrowWhenEncryptFails()
        {
            if (File.Exists(this.tempFileName))
            {
                File.Delete(this.tempFileName);
            }

            var underlying = new Mock <IConfigSource>();

            underlying.SetupSequence(t => t.GetDeploymentConfigInfoAsync())
            .ReturnsAsync(ValidConfigInfo1);

            ISerde <DeploymentConfigInfo> serde = this.GetSerde();
            var encryptionProvider = new Mock <IEncryptionProvider>();

            encryptionProvider.Setup(ep => ep.EncryptAsync(It.IsAny <string>()))
            .ThrowsAsync(new IoTEdgedException("failed", 404, "", null, null));
            using (IConfigSource configSource = new FileBackupConfigSource(this.tempFileName, underlying.Object, serde, encryptionProvider.Object))
            {
                DeploymentConfigInfo config1 = await configSource.GetDeploymentConfigInfoAsync();

                Assert.NotNull(config1);

                Assert.Equal(ValidConfigInfo1, config1);

                encryptionProvider.Verify(ep => ep.EncryptAsync(It.IsAny <string>()));
            }
        }
Exemple #3
0
        public async void FileBackupDoesNotThrowWhenBackupFileDoesNotExist()
        {
            if (File.Exists(this.tempFileName))
            {
                File.Delete(this.tempFileName);
            }

            // Arrange
            var underlying = new Mock <IConfigSource>();

            underlying.Setup(cs => cs.GetDeploymentConfigInfoAsync())
            .ReturnsAsync(DeploymentConfigInfo.Empty);

            ISerde <DeploymentConfigInfo> serde = this.GetSerde();

            // Act
            using (IConfigSource configSource = new FileBackupConfigSource(this.tempFileName, underlying.Object, serde, NullEncryptionProvider.Instance))
            {
                // this call should fetch the config properly
                DeploymentConfigInfo config1 = await configSource.GetDeploymentConfigInfoAsync();

                Assert.NotNull(config1);
                Assert.Equal(DeploymentConfigInfo.Empty, config1);
            }
        }
Exemple #4
0
        public async void FileBackupSuccessCallsEncrypt()
        {
            if (File.Exists(this.tempFileName))
            {
                File.Delete(this.tempFileName);
            }

            var underlying = new Mock <IConfigSource>();

            underlying.SetupSequence(t => t.GetDeploymentConfigInfoAsync())
            .ReturnsAsync(ValidConfigInfo1);

            ISerde <DeploymentConfigInfo> serde = this.GetSerde();
            var encryptionProvider = new Mock <IEncryptionProvider>();

            encryptionProvider.Setup(ep => ep.EncryptAsync(It.IsAny <string>()))
            .ReturnsAsync(serde.Serialize(ValidConfigInfo1));
            using (IConfigSource configSource = new FileBackupConfigSource(this.tempFileName, underlying.Object, serde, encryptionProvider.Object))
            {
                DeploymentConfigInfo config1 = await configSource.GetDeploymentConfigInfoAsync();

                Assert.NotNull(config1);

                Assert.True(File.Exists(this.tempFileName));
                string backupJson = await DiskFile.ReadAllAsync(this.tempFileName);

                string returnedJson = serde.Serialize(config1);

                Assert.Equal(backupJson, returnedJson, true);
                encryptionProvider.Verify(ep => ep.EncryptAsync(It.IsAny <string>()));
            }
        }
Exemple #5
0
        public void CreateSuccess()
        {
            var underlying = new Mock <IConfigSource>();

            using (IConfigSource configSource = new FileBackupConfigSource(this.tempFileName, underlying.Object, this.GetSerde(), NullEncryptionProvider.Instance))
            {
                Assert.NotNull(configSource);
            }
        }
Exemple #6
0
        public async void FileBackupReadFromBackupCallsEncryptDecrypt()
        {
            if (File.Exists(this.tempFileName))
            {
                File.Delete(this.tempFileName);
            }

            var underlying = new Mock <IConfigSource>();

            underlying.SetupSequence(t => t.GetDeploymentConfigInfoAsync())
            .ReturnsAsync(ValidConfigInfo1)
            .ThrowsAsync(new InvalidOperationException());
            ISerde <DeploymentConfigInfo> serde = this.GetSerde();
            var encryptionProvider = new Mock <IEncryptionProvider>();

            encryptionProvider.Setup(ep => ep.EncryptAsync(It.IsAny <string>()))
            .ReturnsAsync(serde.Serialize(ValidConfigInfo1));
            encryptionProvider.Setup(ep => ep.DecryptAsync(It.IsAny <string>()))
            .ReturnsAsync(serde.Serialize(ValidConfigInfo1));

            DeploymentConfigInfo config1;
            DeploymentConfigInfo config2;

            using (IConfigSource configSource = new FileBackupConfigSource(this.tempFileName, underlying.Object, serde, encryptionProvider.Object))
            {
                config1 = await configSource.GetDeploymentConfigInfoAsync();

                Assert.NotNull(config1);

                Assert.True(File.Exists(this.tempFileName));
                string backupJson = await DiskFile.ReadAllAsync(this.tempFileName);

                string returnedJson = serde.Serialize(config1);

                Assert.True(string.Equals(backupJson, returnedJson, StringComparison.OrdinalIgnoreCase));
            }

            using (IConfigSource configSource = new FileBackupConfigSource(this.tempFileName, underlying.Object, serde, encryptionProvider.Object))
            {
                config2 = await configSource.GetDeploymentConfigInfoAsync();

                Assert.NotNull(config2);
            }

            Assert.Equal(serde.Serialize(config1), serde.Serialize(config2));
            encryptionProvider.Verify(ep => ep.EncryptAsync(It.IsAny <string>()));
            encryptionProvider.Verify(ep => ep.DecryptAsync(It.IsAny <string>()));
        }
        public async void FileBackupShouldNotThrowWhenDecryptFails()
        {
            if (File.Exists(this.tempFileName))
            {
                File.Delete(this.tempFileName);
            }

            var underlying = new Mock <IConfigSource>();

            underlying.SetupSequence(t => t.GetDeploymentConfigInfoAsync())
            .ReturnsAsync(ValidConfigInfo1)
            .ThrowsAsync(new InvalidOperationException());
            ISerde <DeploymentConfigInfo> serde = this.GetSerde();
            var encryptionProvider = new Mock <IEncryptionProvider>();

            encryptionProvider.Setup(ep => ep.EncryptAsync(It.IsAny <string>()))
            .ReturnsAsync(serde.Serialize(ValidConfigInfo1));
            encryptionProvider.Setup(ep => ep.DecryptAsync(It.IsAny <string>()))
            .ThrowsAsync(new WorkloadCommunicationException("failed", 404));

            using (IConfigSource configSource = new FileBackupConfigSource(this.tempFileName, underlying.Object, serde, encryptionProvider.Object))
            {
                DeploymentConfigInfo config1 = await configSource.GetDeploymentConfigInfoAsync();

                Assert.NotNull(config1);

                Assert.True(File.Exists(this.tempFileName));
                string backupJson = await DiskFile.ReadAllAsync(this.tempFileName);

                string returnedJson = serde.Serialize(config1);

                Assert.Equal(backupJson, returnedJson, ignoreCase: true);
            }

            using (IConfigSource configSource = new FileBackupConfigSource(this.tempFileName, underlying.Object, serde, encryptionProvider.Object))
            {
                DeploymentConfigInfo config2 = await configSource.GetDeploymentConfigInfoAsync();

                Assert.NotNull(config2);

                Assert.Equal(DeploymentConfigInfo.Empty, config2);
                encryptionProvider.Verify(ep => ep.EncryptAsync(It.IsAny <string>()));
                encryptionProvider.Verify(ep => ep.DecryptAsync(It.IsAny <string>()));
            }
        }
Exemple #8
0
        public async void FileBackupDoesNotHappenIfConfigSourceReportsException()
        {
            if (File.Exists(this.tempFileName))
            {
                File.Delete(this.tempFileName);
            }

            // Arrange
            var underlying = new Mock <IConfigSource>();

            underlying.SetupSequence(cs => cs.GetDeploymentConfigInfoAsync())
            .ReturnsAsync(ValidConfigInfo1)
            .ReturnsAsync(new DeploymentConfigInfo(10, new InvalidOperationException()));

            ISerde <DeploymentConfigInfo> serde = this.GetSerde();

            // Act
            using (IConfigSource configSource = new FileBackupConfigSource(this.tempFileName, underlying.Object, serde, NullEncryptionProvider.Instance))
            {
                // this call should fetch the config properly
                DeploymentConfigInfo config1 = await configSource.GetDeploymentConfigInfoAsync();

                Assert.NotNull(config1);
                Assert.Equal(0, config1.Version);
                Assert.False(config1.Exception.HasValue);

                // this should cause the version with the exception to be returned
                DeploymentConfigInfo config2 = await configSource.GetDeploymentConfigInfoAsync();

                // Assert
                Assert.NotNull(config2);
                Assert.True(config2.Exception.HasValue);
                Assert.IsType <InvalidOperationException>(config2.Exception.OrDefault());

                // this should still be the JSON from the first config - config1
                string backupJson = await DiskFile.ReadAllAsync(this.tempFileName);

                string returnedJson = serde.Serialize(config1);
                Assert.True(string.Equals(backupJson, returnedJson, StringComparison.OrdinalIgnoreCase));
            }
        }
        public async void FileBackupDoesNotHappenIfConfigSourceEmpty()
        {
            if (File.Exists(this.tempFileName))
            {
                File.Delete(this.tempFileName);
            }

            // Arrange
            var underlying = new Mock <IConfigSource>();

            underlying.SetupSequence(cs => cs.GetDeploymentConfigInfoAsync())
            .ReturnsAsync(ValidConfigInfo1)
            .ReturnsAsync(DeploymentConfigInfo.Empty);

            ISerde <DeploymentConfigInfo> serde = this.GetSerde();

            // Act
            using (IConfigSource configSource = new FileBackupConfigSource(this.tempFileName, underlying.Object, serde, NullEncryptionProvider.Instance))
            {
                // this call should fetch the config properly
                DeploymentConfigInfo config1 = await configSource.GetDeploymentConfigInfoAsync();

                Assert.NotNull(config1);
                Assert.Equal(0, config1.Version);

                // this should cause the version with the exception to be returned
                DeploymentConfigInfo config2 = await configSource.GetDeploymentConfigInfoAsync();

                // Assert
                Assert.NotNull(config2);
                Assert.Equal(0, config2.Version);
                Assert.Equal(config2.DeploymentConfig.Modules, config1.DeploymentConfig.Modules);

                // this should still be the JSON from the first config - config1
                string backupJson = await DiskFile.ReadAllAsync(this.tempFileName);

                string returnedJson = serde.Serialize(config1);
                Assert.Equal(backupJson, returnedJson, ignoreCase: true);
            }
        }
Exemple #10
0
        protected override void Load(ContainerBuilder builder)
        {
            // IEdgeAgentConnection
            builder.Register(
                c =>
            {
                var serde = c.Resolve <ISerde <DeploymentConfig> >();
                var deviceClientprovider = c.Resolve <IModuleClientProvider>();
                IEdgeAgentConnection edgeAgentConnection = new EdgeAgentConnection(deviceClientprovider, serde, this.configRefreshFrequency);
                return(edgeAgentConnection);
            })
            .As <IEdgeAgentConnection>()
            .SingleInstance();

            // Task<IConfigSource>
            builder.Register(
                async c =>
            {
                var serde = c.Resolve <ISerde <DeploymentConfigInfo> >();
                var edgeAgentConnection = c.Resolve <IEdgeAgentConnection>();
                IEncryptionProvider encryptionProvider = await c.Resolve <Task <IEncryptionProvider> >();
                var twinConfigSource             = new TwinConfigSource(edgeAgentConnection, this.configuration);
                IConfigSource backupConfigSource = new FileBackupConfigSource(this.backupConfigFilePath, twinConfigSource, serde, encryptionProvider);
                return(backupConfigSource);
            })
            .As <Task <IConfigSource> >()
            .SingleInstance();

            // IReporter
            builder.Register(
                c =>
            {
                var runtimeInfoDeserializerTypes = new Dictionary <string, Type>
                {
                    [DockerType]        = typeof(DockerReportedRuntimeInfo),
                    [Constants.Unknown] = typeof(UnknownRuntimeInfo)
                };

                var edgeAgentDeserializerTypes = new Dictionary <string, Type>
                {
                    [DockerType]        = typeof(EdgeAgentDockerRuntimeModule),
                    [Constants.Unknown] = typeof(UnknownEdgeAgentModule)
                };

                var edgeHubDeserializerTypes = new Dictionary <string, Type>
                {
                    [DockerType]        = typeof(EdgeHubDockerRuntimeModule),
                    [Constants.Unknown] = typeof(UnknownEdgeHubModule)
                };

                var moduleDeserializerTypes = new Dictionary <string, Type>
                {
                    [DockerType] = typeof(DockerRuntimeModule)
                };

                var deserializerTypesMap = new Dictionary <Type, IDictionary <string, Type> >
                {
                    { typeof(IRuntimeInfo), runtimeInfoDeserializerTypes },
                    { typeof(IEdgeAgentModule), edgeAgentDeserializerTypes },
                    { typeof(IEdgeHubModule), edgeHubDeserializerTypes },
                    { typeof(IModule), moduleDeserializerTypes }
                };

                return(new IoTHubReporter(
                           c.Resolve <IEdgeAgentConnection>(),
                           new TypeSpecificSerDe <AgentState>(deserializerTypesMap),
                           this.versionInfo
                           ) as IReporter);
            }
                )
            .As <IReporter>()
            .SingleInstance();

            base.Load(builder);
        }
Exemple #11
0
        public async void FileBackupWriteOnlyWhenConfigurationChanges()
        {
            if (File.Exists(this.tempFileName))
            {
                File.Delete(this.tempFileName);
            }

            var underlying = new Mock <IConfigSource>();

            underlying.SetupSequence(t => t.GetDeploymentConfigInfoAsync())
            .ReturnsAsync(ValidConfigInfo1)
            .ReturnsAsync(ValidConfigInfo1)
            .ReturnsAsync(ValidConfigInfo2)
            .ReturnsAsync(ValidConfigInfo2);

            ISerde <DeploymentConfigInfo> serde = this.GetSerde();

            using (IConfigSource configSource = new FileBackupConfigSource(this.tempFileName, underlying.Object, serde, NullEncryptionProvider.Instance))
            {
                DeploymentConfigInfo config1 = await configSource.GetDeploymentConfigInfoAsync();

                Assert.NotNull(config1);

                Assert.True(File.Exists(this.tempFileName));
                string backupJson = await DiskFile.ReadAllAsync(this.tempFileName);

                string returnedJson = serde.Serialize(config1);

                Assert.True(string.Equals(backupJson, returnedJson, StringComparison.OrdinalIgnoreCase));

                DateTime modifiedTime1 = File.GetLastWriteTimeUtc(this.tempFileName);
                Assert.True(DateTime.UtcNow - modifiedTime1 < TimeSpan.FromSeconds(5));

                DeploymentConfigInfo config2 = await configSource.GetDeploymentConfigInfoAsync();

                Assert.NotNull(config2);

                Assert.Equal(serde.Serialize(config1), serde.Serialize(config2));

                DateTime modifiedTime2 = File.GetLastWriteTimeUtc(this.tempFileName);
                Assert.Equal(modifiedTime2, modifiedTime1);

                DeploymentConfigInfo config3 = await configSource.GetDeploymentConfigInfoAsync();

                Assert.NotNull(config3);

                Assert.True(File.Exists(this.tempFileName));
                backupJson = await DiskFile.ReadAllAsync(this.tempFileName);

                returnedJson = serde.Serialize(config3);

                Assert.True(string.Equals(backupJson, returnedJson, StringComparison.OrdinalIgnoreCase));

                DateTime modifiedTime3 = File.GetLastWriteTimeUtc(this.tempFileName);
                Assert.True(DateTime.UtcNow - modifiedTime1 < TimeSpan.FromSeconds(5));
                Assert.NotEqual(modifiedTime1, modifiedTime3);

                DeploymentConfigInfo config4 = await configSource.GetDeploymentConfigInfoAsync();

                Assert.NotNull(config4);

                Assert.Equal(serde.Serialize(config4), serde.Serialize(config4));

                DateTime modifiedTime4 = File.GetLastWriteTimeUtc(this.tempFileName);
                Assert.Equal(modifiedTime4, modifiedTime3);
            }
        }
Exemple #12
0
        protected override void Load(ContainerBuilder builder)
        {
            // ILogsUploader
            builder.Register(c => new AzureBlobLogsUploader(this.iotHubHostName, this.deviceId))
            .As <ILogsUploader>()
            .SingleInstance();

            // Task<ILogsProvider>
            builder.Register(
                async c =>
            {
                var logsProcessor = new LogsProcessor(new LogMessageParser(this.iotHubHostName, this.deviceId));
                IRuntimeInfoProvider runtimeInfoProvider = await c.Resolve <Task <IRuntimeInfoProvider> >();
                return(new LogsProvider(runtimeInfoProvider, logsProcessor) as ILogsProvider);
            })
            .As <Task <ILogsProvider> >()
            .SingleInstance();

            // Task<IRequestManager>
            builder.Register(
                async c =>
            {
                var logsUploader            = c.Resolve <ILogsUploader>();
                var runtimeInfoProviderTask = c.Resolve <Task <IRuntimeInfoProvider> >();
                var logsProviderTask        = c.Resolve <Task <ILogsProvider> >();
                IRuntimeInfoProvider runtimeInfoProvider = await runtimeInfoProviderTask;
                ILogsProvider logsProvider = await logsProviderTask;
                var requestHandlers        = new List <IRequestHandler>
                {
                    new PingRequestHandler(),
                    new LogsUploadRequestHandler(logsUploader, logsProvider, runtimeInfoProvider),
                    new LogsRequestHandler(logsProvider, runtimeInfoProvider),
                    new TaskStatusRequestHandler()
                };
                return(new RequestManager(requestHandlers, this.requestTimeout) as IRequestManager);
            })
            .As <Task <IRequestManager> >()
            .SingleInstance();

            // ISdkModuleClientProvider
            builder.Register(c => new SdkModuleClientProvider())
            .As <ISdkModuleClientProvider>()
            .SingleInstance();

            // Task<IEdgeAgentConnection>
            builder.Register(
                async c =>
            {
                var serde = c.Resolve <ISerde <DeploymentConfig> >();
                var deviceClientprovider                 = c.Resolve <IModuleClientProvider>();
                var requestManagerTask                   = c.Resolve <Task <IRequestManager> >();
                IRequestManager requestManager           = await requestManagerTask;
                IEdgeAgentConnection edgeAgentConnection = new EdgeAgentConnection(deviceClientprovider, serde, requestManager, this.enableSubscriptions, this.configRefreshFrequency);
                return(edgeAgentConnection);
            })
            .As <Task <IEdgeAgentConnection> >()
            .SingleInstance();

            // Task<IStreamRequestListener>
            builder.Register(
                async c =>
            {
                if (this.enableStreams)
                {
                    var runtimeInfoProviderTask = c.Resolve <Task <IRuntimeInfoProvider> >();
                    var logsProviderTask        = c.Resolve <Task <ILogsProvider> >();
                    var edgeAgentConnectionTask = c.Resolve <Task <IEdgeAgentConnection> >();
                    IRuntimeInfoProvider runtimeInfoProvider = await runtimeInfoProviderTask;
                    ILogsProvider logsProvider = await logsProviderTask;
                    IEdgeAgentConnection edgeAgentConnection = await edgeAgentConnectionTask;
                    var streamRequestHandlerProvider         = new StreamRequestHandlerProvider(logsProvider, runtimeInfoProvider);
                    return(new StreamRequestListener(streamRequestHandlerProvider, edgeAgentConnection) as IStreamRequestListener);
                }
                else
                {
                    return(new NullStreamRequestListener() as IStreamRequestListener);
                }
            })
            .As <Task <IStreamRequestListener> >()
            .SingleInstance();

            // Task<IConfigSource>
            builder.Register(
                async c =>
            {
                var serde = c.Resolve <ISerde <DeploymentConfigInfo> >();
                var edgeAgentConnectionTask              = c.Resolve <Task <IEdgeAgentConnection> >();
                IEncryptionProvider encryptionProvider   = await c.Resolve <Task <IEncryptionProvider> >();
                IEdgeAgentConnection edgeAgentConnection = await edgeAgentConnectionTask;
                var twinConfigSource             = new TwinConfigSource(edgeAgentConnection, this.configuration);
                IConfigSource backupConfigSource = new FileBackupConfigSource(this.backupConfigFilePath, twinConfigSource, serde, encryptionProvider);
                return(backupConfigSource);
            })
            .As <Task <IConfigSource> >()
            .SingleInstance();

            // Task<IReporter>
            builder.Register(
                async c =>
            {
                var runtimeInfoDeserializerTypes = new Dictionary <string, Type>
                {
                    [DockerType]        = typeof(DockerReportedRuntimeInfo),
                    [Constants.Unknown] = typeof(UnknownRuntimeInfo)
                };

                var edgeAgentDeserializerTypes = new Dictionary <string, Type>
                {
                    [DockerType]        = typeof(EdgeAgentDockerRuntimeModule),
                    [Constants.Unknown] = typeof(UnknownEdgeAgentModule)
                };

                var edgeHubDeserializerTypes = new Dictionary <string, Type>
                {
                    [DockerType]        = typeof(EdgeHubDockerRuntimeModule),
                    [Constants.Unknown] = typeof(UnknownEdgeHubModule)
                };

                var moduleDeserializerTypes = new Dictionary <string, Type>
                {
                    [DockerType] = typeof(DockerRuntimeModule)
                };

                var deserializerTypesMap = new Dictionary <Type, IDictionary <string, Type> >
                {
                    { typeof(IRuntimeInfo), runtimeInfoDeserializerTypes },
                    { typeof(IEdgeAgentModule), edgeAgentDeserializerTypes },
                    { typeof(IEdgeHubModule), edgeHubDeserializerTypes },
                    { typeof(IModule), moduleDeserializerTypes }
                };

                var edgeAgentConnectionTask = c.Resolve <Task <IEdgeAgentConnection> >();
                IEdgeAgentConnection edgeAgentConnection = await edgeAgentConnectionTask;

                return(new IoTHubReporter(
                           edgeAgentConnection,
                           new TypeSpecificSerDe <AgentState>(deserializerTypesMap),
                           this.versionInfo) as IReporter);
            })
            .As <Task <IReporter> >()
            .SingleInstance();

            base.Load(builder);
        }
        public async Task FileBackupReadOnlyWhenUninitialized()
        {
            if (File.Exists(this.tempFileName))
            {
                File.Delete(this.tempFileName);
            }

            var underlying = new Mock <IConfigSource>();

            underlying.SetupSequence(t => t.GetDeploymentConfigInfoAsync())
            .ReturnsAsync(ValidConfigInfo1)
            .ReturnsAsync(DeploymentConfigInfo.Empty)
            .ThrowsAsync(new InvalidOperationException())
            .ReturnsAsync(ValidConfigInfo1)
            .ReturnsAsync(DeploymentConfigInfo.Empty)
            .ThrowsAsync(new InvalidOperationException());

            ISerde <DeploymentConfigInfo> serde = this.GetSerde();
            DeploymentConfigInfo          config1;

            using (IConfigSource configSource = new FileBackupConfigSource(this.tempFileName, underlying.Object, serde, NullEncryptionProvider.Instance))
            {
                config1 = await configSource.GetDeploymentConfigInfoAsync();

                Assert.NotNull(config1);

                Assert.True(File.Exists(this.tempFileName));
                string backupJson = await DiskFile.ReadAllAsync(this.tempFileName);

                string returnedJson = serde.Serialize(config1);

                Assert.Equal(backupJson, returnedJson, ignoreCase: true);
                File.Delete(this.tempFileName);

                DeploymentConfigInfo config2 = await configSource.GetDeploymentConfigInfoAsync();

                Assert.NotNull(config2);

                Assert.Equal(serde.Serialize(config1), serde.Serialize(config2));

                DeploymentConfigInfo config3 = await configSource.GetDeploymentConfigInfoAsync();

                Assert.NotNull(config3);

                Assert.Equal(serde.Serialize(config1), serde.Serialize(config3));
            }

            using (IConfigSource configSource = new FileBackupConfigSource(this.tempFileName, underlying.Object, serde, NullEncryptionProvider.Instance))
            {
                config1 = await configSource.GetDeploymentConfigInfoAsync();

                Assert.NotNull(config1);

                Assert.True(File.Exists(this.tempFileName));
                string backupJson = await DiskFile.ReadAllAsync(this.tempFileName);

                string returnedJson = serde.Serialize(config1);

                Assert.Equal(backupJson, returnedJson, ignoreCase: true);
            }

            using (IConfigSource configSource = new FileBackupConfigSource(this.tempFileName, underlying.Object, serde, NullEncryptionProvider.Instance))
            {
                DeploymentConfigInfo config5 = await configSource.GetDeploymentConfigInfoAsync();

                Assert.NotNull(config5);

                Assert.Equal(serde.Serialize(config1), serde.Serialize(config5));
            }

            using (IConfigSource configSource = new FileBackupConfigSource(this.tempFileName, underlying.Object, serde, NullEncryptionProvider.Instance))
            {
                DeploymentConfigInfo config5 = await configSource.GetDeploymentConfigInfoAsync();

                Assert.NotNull(config5);

                Assert.Equal(serde.Serialize(config1), serde.Serialize(config5));
            }

            File.Delete(this.tempFileName);
            using (IConfigSource configSource = new FileBackupConfigSource(this.tempFileName, underlying.Object, serde, NullEncryptionProvider.Instance))
            {
                DeploymentConfigInfo config6 = await configSource.GetDeploymentConfigInfoAsync();

                Assert.NotNull(config6);

                Assert.Equal(config6, DeploymentConfigInfo.Empty);
            }
        }