public void UpgradeWithSetting()
        {
            string currentExecutingDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            string jsonFilePath    = Path.Combine(currentExecutingDirectory, "Application_No_Setting.json");
            string descriptionJson = File.ReadAllText(jsonFilePath);

            SingleInstance.Application application = JsonConvert.DeserializeObject <SingleInstance.Application>(descriptionJson);

            string applicationTypeName    = "MeshApplicationType";
            string applicationTypeVersion = "v1";
            Uri    applicationName        = new Uri("fabric:/myapp");
            string tempBuildPath          = Path.Combine(TestUtility.TestDirectory, Guid.NewGuid().ToString());
            string outputPath             = Path.Combine(TestUtility.TestDirectory, Guid.NewGuid().ToString());

            string applicationId = Guid.NewGuid().ToString();

            this.imageBuilder.BuildSingleInstanceApplication(
                application,
                applicationTypeName,
                applicationTypeVersion,
                applicationId,
                applicationName,
                true, //generateDNS
                TimeSpan.MaxValue,
                tempBuildPath,
                outputPath, // output pkg build path
                false,      //use open network
                false,      //use local nat network
                "C:\\",
                new SingleInstance.GenerationConfig());

            BuildLayoutInfo         buildLayoutInfo     = new BuildLayoutInfo(this.imageStore, tempBuildPath);
            ApplicationInstanceType applicationInstance = TestUtility.GetApplicationInstance(buildLayoutInfo, applicationId, 1);

            TestUtility.VerifyStoreLayout(buildLayoutInfo);

            StoreLayoutSpecification storeLayoutSpec = StoreLayoutSpecification.Create();

            storeLayoutSpec.SetRoot(outputPath);
            string servicePackageFile = storeLayoutSpec.GetServicePackageFile(applicationTypeName, applicationId, "myBackendServicePkg", applicationInstance.ServicePackageRef[0].RolloutVersion);
            var    servicepackage     = buildLayoutInfo.ImageStoreWrapper.GetFromStore <ServicePackageType>(servicePackageFile, TestUtility.ImageStoreDefaultTimeout);

            string rolloutVersion1 = servicepackage.RolloutVersion;

            // Test Case 1: Instance Count change
            string jsonFilePath2    = Path.Combine(currentExecutingDirectory, "Application_No_Setting2.json");
            string descriptionJson2 = File.ReadAllText(jsonFilePath2);

            SingleInstance.Application application2 = JsonConvert.DeserializeObject <SingleInstance.Application>(descriptionJson2);

            string applicationTypeVersion2 = "v2";

            this.imageBuilder.BuildSingleInstanceApplicationForUpgrade(
                application2,
                applicationTypeName,
                applicationTypeVersion,
                applicationTypeVersion2,
                applicationId,
                applicationInstance.Version,
                applicationName,
                true, //generateDNS
                TimeSpan.MaxValue,
                tempBuildPath,
                outputPath,
                false, //use open network
                false, //use local nat network
                "C:\\",
                new SingleInstance.GenerationConfig());

            ApplicationInstanceType applicationInstance2 = TestUtility.GetApplicationInstance(buildLayoutInfo, applicationId, 2);
            string servicePackageFile2 = storeLayoutSpec.GetServicePackageFile(applicationTypeName, applicationId, "myBackendServicePkg", applicationInstance2.ServicePackageRef[0].RolloutVersion);
            var    servicepackage2     = buildLayoutInfo.ImageStoreWrapper.GetFromStore <ServicePackageType>(servicePackageFile2, TestUtility.ImageStoreDefaultTimeout);

            Verify.AreEqual(servicepackage2.ManifestVersion, "v1");

            string rolloutVersion2 = servicepackage2.RolloutVersion;

            Verify.AreEqual(rolloutVersion1, rolloutVersion2);
            TestUtility.VerifyStoreLayout(buildLayoutInfo);

            // Test Case 2: Adding settings
            string jsonSettingFilePath1    = Path.Combine(currentExecutingDirectory, "Application_Setting1.json");
            string settingDescriptionJson1 = File.ReadAllText(jsonSettingFilePath1);

            SingleInstance.Application applicationWithSetting1 = JsonConvert.DeserializeObject <SingleInstance.Application>(settingDescriptionJson1);

            string applicationTypeVersion3 = "v3";

            this.imageBuilder.BuildSingleInstanceApplicationForUpgrade(
                applicationWithSetting1,
                applicationTypeName,
                applicationTypeVersion2,
                applicationTypeVersion3,
                applicationId,
                applicationInstance2.Version,
                applicationName,
                true, //generateDNS
                TimeSpan.MaxValue,
                tempBuildPath,
                outputPath,
                false, //use open network
                false, //use localnat network
                "C:\\",
                new SingleInstance.GenerationConfig());
            ApplicationInstanceType applicationInstance3 = TestUtility.GetApplicationInstance(buildLayoutInfo, applicationId, 3);
            string servicePackageFile3 = storeLayoutSpec.GetServicePackageFile(applicationTypeName, applicationId, "myBackendServicePkg", applicationInstance3.ServicePackageRef[0].RolloutVersion);
            var    servicepackage3     = buildLayoutInfo.ImageStoreWrapper.GetFromStore <ServicePackageType>(servicePackageFile3, TestUtility.ImageStoreDefaultTimeout);

            Verify.AreEqual(servicepackage3.ManifestVersion, applicationTypeVersion3);

            string rolloutVersion3 = servicepackage3.RolloutVersion;

            Verify.AreNotEqual(rolloutVersion2, rolloutVersion3);
            TestUtility.VerifyStoreLayout(buildLayoutInfo);

            // Test Case 3: Changing settings only
            string jsonSettingFilePath2    = Path.Combine(currentExecutingDirectory, "Application_Setting2.json");
            string settingDescriptionJson2 = File.ReadAllText(jsonSettingFilePath2);

            SingleInstance.Application applicationWithSetting2 = JsonConvert.DeserializeObject <SingleInstance.Application>(settingDescriptionJson2);

            string applicationTypeVersion4 = "v4";

            this.imageBuilder.BuildSingleInstanceApplicationForUpgrade(
                applicationWithSetting2,
                applicationTypeName,
                applicationTypeVersion3,
                applicationTypeVersion4,
                applicationId,
                applicationInstance3.Version,
                applicationName,
                true, //generateDNS
                TimeSpan.MaxValue,
                tempBuildPath,
                outputPath,
                false, //use open network
                false, //use localnat network
                "C:\\",
                new SingleInstance.GenerationConfig());
            ApplicationInstanceType applicationInstance4 = TestUtility.GetApplicationInstance(buildLayoutInfo, applicationId, 4);
            string servicePackageFile4 = storeLayoutSpec.GetServicePackageFile(applicationTypeName, applicationId, "myBackendServicePkg", applicationInstance4.ServicePackageRef[0].RolloutVersion);
            var    servicepackage4     = buildLayoutInfo.ImageStoreWrapper.GetFromStore <ServicePackageType>(servicePackageFile4, TestUtility.ImageStoreDefaultTimeout);

            Verify.AreEqual(servicepackage4.ManifestVersion, applicationTypeVersion4);

            // Code package version remains the same for settings upgrade
            foreach (var codePackage in servicepackage4.DigestedCodePackage)
            {
                Verify.AreEqual(applicationTypeVersion3, codePackage.CodePackage.Version);
            }
            // Config package version is set to target version for settings upgrade
            foreach (var configPackage in servicepackage4.DigestedConfigPackage)
            {
                Verify.AreEqual(applicationTypeVersion4, configPackage.ConfigPackage.Version);
            }

            string rolloutVersion4 = servicepackage4.RolloutVersion;

            Verify.AreNotEqual(rolloutVersion3, rolloutVersion4);
            TestUtility.VerifyStoreLayout(buildLayoutInfo);

            // Test Case 4: Keep settings
            string jsonSettingFilePath3    = Path.Combine(currentExecutingDirectory, "Application_Setting2InstanceCount.json");
            string settingDescriptionJson3 = File.ReadAllText(jsonSettingFilePath3);

            SingleInstance.Application applicationWithSetting3 = JsonConvert.DeserializeObject <SingleInstance.Application>(settingDescriptionJson3);

            string applicationTypeVersion5 = "v5";

            this.imageBuilder.BuildSingleInstanceApplicationForUpgrade(
                applicationWithSetting3,
                applicationTypeName,
                applicationTypeVersion4,
                applicationTypeVersion5,
                applicationId,
                applicationInstance4.Version,
                applicationName,
                true, //generateDNS
                TimeSpan.MaxValue,
                tempBuildPath,
                outputPath,
                false, //use open network
                false, //use localnat network
                "C:\\",
                new SingleInstance.GenerationConfig());
            ApplicationInstanceType applicationInstance5 = TestUtility.GetApplicationInstance(buildLayoutInfo, applicationId, 5);
            string servicePackageFile5 = storeLayoutSpec.GetServicePackageFile(applicationTypeName, applicationId, "myBackendServicePkg", applicationInstance5.ServicePackageRef[0].RolloutVersion);
            var    servicepackage5     = buildLayoutInfo.ImageStoreWrapper.GetFromStore <ServicePackageType>(servicePackageFile5, TestUtility.ImageStoreDefaultTimeout);

            // SP manifest version remains the same
            Verify.AreEqual(servicepackage5.ManifestVersion, applicationTypeVersion4);

            // SP rollout version remains the same
            string rolloutVersion5 = servicepackage5.RolloutVersion;

            Verify.AreEqual(rolloutVersion4, rolloutVersion5);
            TestUtility.VerifyStoreLayout(buildLayoutInfo);

            // Test Case 5: Autoscaling - Instance Count change
            string jsonSettingFilePath4    = Path.Combine(currentExecutingDirectory, "Application_Setting3Autoscaling.json");
            string settingDescriptionJson4 = File.ReadAllText(jsonSettingFilePath4);

            SingleInstance.Application applicationWithSetting4 = JsonConvert.DeserializeObject <SingleInstance.Application>(settingDescriptionJson4);

            string applicationTypeVersion6 = "v6";

            this.imageBuilder.BuildSingleInstanceApplicationForUpgrade(
                applicationWithSetting4,
                applicationTypeName,
                applicationTypeVersion5,
                applicationTypeVersion6,
                applicationId,
                applicationInstance5.Version,
                applicationName,
                true, //generateDNS
                TimeSpan.MaxValue,
                tempBuildPath,
                outputPath,
                false, //use open network
                false, //use localnat network
                "C:\\",
                new SingleInstance.GenerationConfig());

            ApplicationInstanceType applicationInstance6 = TestUtility.GetApplicationInstance(buildLayoutInfo, applicationId, 6);
            string servicePackageFile6 = storeLayoutSpec.GetServicePackageFile(applicationTypeName, applicationId, "myBackendServicePkg", applicationInstance6.ServicePackageRef[0].RolloutVersion);
            var    servicepackage6     = buildLayoutInfo.ImageStoreWrapper.GetFromStore <ServicePackageType>(servicePackageFile6, TestUtility.ImageStoreDefaultTimeout);

            Verify.AreEqual(servicepackage6.ManifestVersion, "v4");

            string rolloutVersion6 = servicepackage6.RolloutVersion;

            Verify.AreEqual(rolloutVersion5, rolloutVersion6);
            TestUtility.VerifyStoreLayout(buildLayoutInfo);

            // Test Case 6: Changing settings and image at the same time
            string jsonSettingFilePath5    = Path.Combine(currentExecutingDirectory, "Application_Setting3.json");
            string settingDescriptionJson5 = File.ReadAllText(jsonSettingFilePath5);

            SingleInstance.Application applicationWithSetting5 = JsonConvert.DeserializeObject <SingleInstance.Application>(settingDescriptionJson5);

            string applicationTypeVersion7 = "v7";

            this.imageBuilder.BuildSingleInstanceApplicationForUpgrade(
                applicationWithSetting5,
                applicationTypeName,
                applicationTypeVersion6,
                applicationTypeVersion7,
                applicationId,
                applicationInstance6.Version,
                applicationName,
                true, //generateDNS
                TimeSpan.MaxValue,
                tempBuildPath,
                outputPath,
                false, //use open network
                false, //use localnat network
                "C:\\",
                new SingleInstance.GenerationConfig());

            ApplicationInstanceType applicationInstance7 = TestUtility.GetApplicationInstance(buildLayoutInfo, applicationId, 7);
            string servicePackageFile7 = storeLayoutSpec.GetServicePackageFile(applicationTypeName, applicationId, "myBackendServicePkg", applicationInstance7.ServicePackageRef[0].RolloutVersion);
            var    servicepackage7     = buildLayoutInfo.ImageStoreWrapper.GetFromStore <ServicePackageType>(servicePackageFile7, TestUtility.ImageStoreDefaultTimeout);

            Verify.AreEqual(servicepackage7.ManifestVersion, applicationTypeVersion7);

            // Code package version and config package version are set to target version applicationTypeVersion7
            foreach (var codePackage in servicepackage7.DigestedCodePackage)
            {
                Verify.AreEqual(applicationTypeVersion7, codePackage.CodePackage.Version);
            }
            foreach (var configPackage in servicepackage7.DigestedConfigPackage)
            {
                Verify.AreEqual(applicationTypeVersion7, configPackage.ConfigPackage.Version);
            }

            string rolloutVersion7 = servicepackage7.RolloutVersion;

            Verify.AreNotEqual(rolloutVersion6, rolloutVersion7);
            TestUtility.VerifyStoreLayout(buildLayoutInfo);
        }