/// <summary> /// Process test storage and add dependant assemblies to dependencyDeploymentItems. /// </summary> /// <param name="testSource">The test source.</param> /// <param name="configFile">The config file.</param> /// <param name="deploymentItems">Deployment items.</param> /// <param name="warnings">Warnigns.</param> private void AddDependencies(string testSource, string configFile, IList <DeploymentItem> deploymentItems, IList <string> warnings) { Debug.Assert(!string.IsNullOrEmpty(testSource), "testSource should not be null or empty."); // config file can be null. Debug.Assert(deploymentItems != null, "deploymentItems should not be null."); Debug.Assert(Path.IsPathRooted(testSource), "path should be rooted."); // Note: if this is not an assembly we simply return empty array, also: // we do recursive search and report missing. IList <string> warningList; string[] references = this.assemblyUtility.GetFullPathToDependentAssemblies(testSource, configFile, out warningList); if (warningList != null && warningList.Count > 0) { warnings = warnings.Concat(warningList).ToList(); } if (EqtTrace.IsInfoEnabled) { EqtTrace.Info("DeploymentManager: Source:{0} has following references", testSource); } foreach (string reference in references) { DeploymentItem deploymentItem = new DeploymentItem(reference, string.Empty, DeploymentItemOriginType.Dependency); this.deploymentItemUtility.AddDeploymentItem(deploymentItems, deploymentItem); if (EqtTrace.IsInfoEnabled) { EqtTrace.Info("DeploymentManager: Reference:{0} ", reference); } } }
public void GetDeploymentItemsShouldReturnClassLevelDeploymentItemsOnly() { // Arrange. var classLevelDeploymentItems = new DeploymentItem[] { new DeploymentItem( this.defaultDeploymentItemPath, this.defaultDeploymentItemOutputDirectory), new DeploymentItem( this.defaultDeploymentItemPath + "\\temp2", this.defaultDeploymentItemOutputDirectory) }; // Act. var deploymentItems = this.deploymentItemUtility.GetDeploymentItems( typeof(DeploymentItemUtilityTests).GetMethod("GetDeploymentItemsShouldReturnNullOnNoDeploymentItems"), classLevelDeploymentItems, this.warnings); // Assert. var expectedDeploymentItems = new[] { new KeyValuePair <string, string>( this.defaultDeploymentItemPath, this.defaultDeploymentItemOutputDirectory), new KeyValuePair <string, string>( this.defaultDeploymentItemPath + "\\temp2", this.defaultDeploymentItemOutputDirectory) }; CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray()); }
public void EqualsShouldReturnFalseIfSourcePathIsDifferent() { DeploymentItem item1 = new DeploymentItem("e:\\temp\\temp1.dll"); DeploymentItem item2 = new DeploymentItem("e:\\temp\\temp2.dll"); Assert.IsFalse(item1.Equals(item2)); }
public void EqualsShouldReturnFalseIfRelativeOutputDirectoryIsDifferent() { DeploymentItem item1 = new DeploymentItem("e:\\temp\\temp1.dll", "foo1"); DeploymentItem item2 = new DeploymentItem("e:\\temp\\temp1.dll", "foo2"); Assert.IsFalse(item1.Equals(item2)); }
public void GetClassLevelDeploymentItemsShouldReportWarningsForInvalidDeploymentItems() { var deploymentItemAttributes = new[] { new KeyValuePair <string, string>( this.defaultDeploymentItemPath, this.defaultDeploymentItemOutputDirectory), new KeyValuePair <string, string>( null, this.defaultDeploymentItemOutputDirectory) }; this.SetupDeploymentItems(typeof(DeploymentItemUtilityTests).GetTypeInfo(), deploymentItemAttributes); var deploymentItems = this.deploymentItemUtility.GetClassLevelDeploymentItems(typeof(DeploymentItemUtilityTests), this.warnings); var expectedDeploymentItems = new DeploymentItem[] { new DeploymentItem( this.defaultDeploymentItemPath, this.defaultDeploymentItemOutputDirectory) }; CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray()); Assert.AreEqual(1, this.warnings.Count); StringAssert.Contains(this.warnings.ToArray()[0], Resource.DeploymentItemPathCannotBeNullOrEmpty); }
private async Task <bool> CheckCreateApplicationTypeStatusAsync(DeploymentItem item) { var startTime = DateTime.Now; var appTypeInfo = await GetApplicationTypeInfo(item); if (appTypeInfo == null) { return(false); } while (appTypeInfo.Status != ApplicationTypeStatus.Available) { var currentTime = DateTime.Now; if (currentTime > startTime.AddSeconds(item.MaxApplicationReadyWaitTime)) { return(false); } await Task.Delay(AvailableCheckDelay); appTypeInfo = await GetApplicationTypeInfo(item); if (appTypeInfo == null) { return(false); } } return(appTypeInfo.Status == ApplicationTypeStatus.Available); }
public void EqualsShouldReturnTrueIfSourcePathDiffersByCase() { DeploymentItem item1 = new DeploymentItem("e:\\temp\\temp1.dll"); DeploymentItem item2 = new DeploymentItem("e:\\temp\\Temp1.dll"); Assert.IsTrue(item1.Equals(item2)); }
public ApplicationDeploymentCommandTests() { _appClient = new Mock <IApplicationClient>(); _createCommand = new Mock <ICommand>(); _upgradeCommand = new Mock <ICommand>(); var fabricClient = new Mock <IServiceFabricClient>(); fabricClient.Setup(c => c.Applications).Returns(_appClient.Object); _item = new DeploymentItem { PackagePath = @"c:\temp\pkg", ApplicationTypeName = "AppType", ApplicationName = "fabric:/app", ApplicationId = "app", ApplicationTypeVersion = "1.0.0", ApplicationTypeBuildPath = "pkg" }; var context = new CommandContext { FabricClient = fabricClient.Object, Logger = Logger.Object, CurrentDeploymentItem = _item }; _command = new ApplicationDeploymentCommand(context, _createCommand.Object, _upgradeCommand.Object); }
private async Task <ApplicationTypeInfo> GetApplicationTypeInfo(DeploymentItem item) { var appTypeName = item.ApplicationTypeName; var appTypeInfoList = await _context.AppTypeClient.GetApplicationTypeInfoListByNameAsync(appTypeName); return(appTypeInfoList.Data.FirstOrDefault(p => p.Version == item.ApplicationTypeVersion)); }
public void EqualsShouldReturnTrueIfRelativeOutputDirectoryDiffersByCase() { DeploymentItem item1 = new DeploymentItem("e:\\temp\\temp1.dll", "foo1"); DeploymentItem item2 = new DeploymentItem("e:\\temp\\temp1.dll", "Foo1"); Assert.IsTrue(item1.Equals(item2)); }
public void EqualsShouldReturnTrueIfSourceAndRelativeOutputDirectoryAreSame() { DeploymentItem item1 = new DeploymentItem("e:\\temp\\temp1.dll", "foo1"); DeploymentItem item2 = new DeploymentItem("e:\\temp\\temp1.dll", "foo1"); Assert.IsTrue(item1.Equals(item2)); }
public void ToStringShouldReturnDeploymentItemIfRelativeOutputDirectoryIsNotSpecified() { var sourcePath = "e:\\temp\\temp1.dll"; DeploymentItem item = new DeploymentItem(sourcePath); Assert.AreEqual(string.Format(Resource.DeploymentItem, sourcePath), item.ToString()); }
public void GetClassLevelDeploymentItemsShouldReturnMoreThanOneDeploymentItems() { var deploymentItemAttributes = new[] { new KeyValuePair <string, string>( this.defaultDeploymentItemPath, this.defaultDeploymentItemOutputDirectory), new KeyValuePair <string, string>( this.defaultDeploymentItemPath + "\\temp2", this.defaultDeploymentItemOutputDirectory) }; this.SetupDeploymentItems(typeof(DeploymentItemUtilityTests).GetTypeInfo(), deploymentItemAttributes); var deploymentItems = this.deploymentItemUtility.GetClassLevelDeploymentItems( typeof(DeploymentItemUtilityTests), this.warnings); var expectedDeploymentItems = new DeploymentItem[] { new DeploymentItem( deploymentItemAttributes[0].Key, deploymentItemAttributes[0].Value), new DeploymentItem( deploymentItemAttributes[1].Key, deploymentItemAttributes[1].Value) }; CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray()); }
private async Task <bool> CheckUpgradeApplicationStatusAsync(DeploymentItem item) { var startTime = DateTime.Now; var appInfo = await _context.AppClient.GetApplicationUpgradeAsync(item.ApplicationId); var upgraded = appInfo.UpgradeState == UpgradeState.RollingForwardCompleted || appInfo.UpgradeState == UpgradeState.RollingBackCompleted; while (!upgraded) { var currentTime = DateTime.Now; if (currentTime > startTime.AddSeconds(item.MaxApplicationReadyWaitTime)) { return(false); } await Task.Delay(AvailableCheckDelay); appInfo = await _context.AppClient.GetApplicationUpgradeAsync(item.ApplicationId); upgraded = appInfo.UpgradeState == UpgradeState.RollingForwardCompleted || appInfo.UpgradeState == UpgradeState.RollingBackCompleted; } LogInfo( StageTypes.Deployment, $"Application {item.ApplicationName} upgrade state is {appInfo.UpgradeState}"); return(true); }
public void ToStringShouldReturnDeploymentItemAndRelativeOutputDirectory() { var sourcePath = "e:\\temp\\temp1.dll"; var relativeOutputDirectory = "foo1"; DeploymentItem item = new DeploymentItem(sourcePath, relativeOutputDirectory); Assert.AreEqual(string.Format(Resource.DeploymentItemWithOutputDirectory, sourcePath, relativeOutputDirectory), item.ToString()); }
public void GetHashCodeShouldConsiderSourcePathAndRelativeOutputDirectory() { var sourcePath = "e:\\temp\\temp1.dll"; var relativeOutputDirectory = "foo1"; DeploymentItem item = new DeploymentItem(sourcePath, relativeOutputDirectory); Assert.AreEqual(sourcePath.GetHashCode() + relativeOutputDirectory.GetHashCode(), item.GetHashCode()); }
private static string getDeploymentSource(DeploymentItem x, string outputDir) { var source = x.Path; if (!Path.IsPathRooted(source)) { source = Path.Combine(outputDir, source); } return(source); }
internal void AddDeploymentItem(IList <DeploymentItem> deploymentItemList, DeploymentItem deploymentItem) { Debug.Assert(deploymentItemList != null, "DeploymentItem list cannot be null"); Debug.Assert(deploymentItem != null, "DeploymentItem cannot be null"); if (!deploymentItemList.Contains(deploymentItem)) { deploymentItemList.Add(deploymentItem); } }
public void Verify() { var t = new LocalCommandLineTask("ping"); t.Args = "localhost"; var r = t.VerifyCanRun(); var vi = new DeploymentItem(DeploymentItemStatus.Good, ""); Assert.AreEqual(1, r.Results.Count); //Assert.Contains(vi, r.Results); }
private static void copyItem(DeploymentItem x, string outputDir) { var source = getDeploymentSource(x, outputDir); var destination = getDeploymentDestination(source, x, outputDir); if (source.Equals(destination)) { return; } if (hasChanged(source, destination)) { File.Copy(source, destination, true); } }
public void GetDeploymentItemsShouldReturnClassAndMethodLevelDeploymentItemsWithoutDuplicates() { // Arrange. var deploymentItemAttributes = new[] { new KeyValuePair <string, string>( this.defaultDeploymentItemPath, this.defaultDeploymentItemOutputDirectory), new KeyValuePair <string, string>( this.defaultDeploymentItemPath + "\\temp2", this.defaultDeploymentItemOutputDirectory) }; var memberInfo = typeof(DeploymentItemUtilityTests).GetMethod( "GetDeploymentItemsShouldReturnClassAndMethodLevelDeploymentItems"); this.SetupDeploymentItems(memberInfo, deploymentItemAttributes); var classLevelDeploymentItems = new DeploymentItem[] { new DeploymentItem( this.defaultDeploymentItemPath, this.defaultDeploymentItemOutputDirectory), new DeploymentItem( this.defaultDeploymentItemPath + "\\temp1", this.defaultDeploymentItemOutputDirectory) }; // Act. var deploymentItems = this.deploymentItemUtility.GetDeploymentItems( memberInfo, classLevelDeploymentItems, this.warnings); // Assert. var expectedDeploymentItems = new KeyValuePair <string, string>[] { new KeyValuePair <string, string>( this.defaultDeploymentItemPath, this.defaultDeploymentItemOutputDirectory), new KeyValuePair <string, string>( this.defaultDeploymentItemPath + "\\temp2", this.defaultDeploymentItemOutputDirectory), new KeyValuePair <string, string>( this.defaultDeploymentItemPath + "\\temp1", this.defaultDeploymentItemOutputDirectory) }; CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray()); }
private bool IsDeploymentItemSourceADirectory(DeploymentItem deploymentItem, string testSource, out string resultDirectory) { resultDirectory = null; string directory = this.GetFullPathToDeploymentItemSource(deploymentItem.SourcePath, testSource); directory = directory.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); if (this.FileUtility.DoesDirectoryExist(directory)) { resultDirectory = directory; return(true); } return(false); }
private string[] GetFullPathToFilesCorrespondingToDeploymentItem(DeploymentItem deploymentItem, string testSource, IList <string> warnings, out bool isDirectory) { Debug.Assert(deploymentItem != null, "deploymentItem should not be null."); Debug.Assert(!string.IsNullOrEmpty(testSource), "testsource should not be null or empty."); try { string directory; isDirectory = this.IsDeploymentItemSourceADirectory(deploymentItem, testSource, out directory); if (isDirectory) { return(this.fileUtility.AddFilesFromDirectory(directory, false).ToArray()); } string fileName; if (!this.IsDeploymentItemSourceAFile(deploymentItem.SourcePath, testSource, out fileName)) { // If file/directory is not found, then try removing the prefix and see if it is present. string fileOrDirNameOnly = Path.GetFileName( deploymentItem.SourcePath.TrimEnd( new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar })); if (!this.IsDeploymentItemSourceAFile(fileOrDirNameOnly, testSource, out fileName)) { string message = string.Format(CultureInfo.CurrentCulture, Resource.CannotFindFile, fileName); throw new FileNotFoundException(message, fileName); } } return(new[] { fileName }); } catch (Exception e) { warnings.Add(string.Format( CultureInfo.CurrentCulture, Resource.DeploymentErrorFailedToGetFileForDeploymentItem, deploymentItem, e.GetType(), e.Message)); isDirectory = false; return(null); } }
protected bool IsOutputDirectoryValid(DeploymentItem deploymentItem, string deploymentDirectory, IList <string> warnings) { Debug.Assert(deploymentItem != null, "deploymentItem should not be null."); Debug.Assert(!string.IsNullOrEmpty(deploymentDirectory), "deploymentDirectory should not be null or empty."); Debug.Assert(warnings != null, "warnings should not be null."); // Check that item.output dir does not go outside deployment Out dir, otherwise you can erase any file! string outputDir = deploymentDirectory; try { outputDir = Path.GetFullPath(Path.Combine(deploymentDirectory, deploymentItem.RelativeOutputDirectory)); // convert the short path to full length path (like joe~1.dom to joe.domain) and the comparison // startsWith in the next loop will work for the matching paths. deploymentDirectory = Path.GetFullPath(deploymentDirectory); } catch (Exception e) { string warning = string.Format( CultureInfo.CurrentCulture, Resource.DeploymentErrorFailedToAccesOutputDirectory, deploymentItem.SourcePath, outputDir, e.GetType(), e.GetExceptionMessage()); warnings.Add(warning); return(false); } if (!outputDir.StartsWith(deploymentDirectory, StringComparison.OrdinalIgnoreCase)) { string warning = string.Format( CultureInfo.CurrentCulture, Resource.DeploymentErrorBadDeploymentItem, deploymentItem.SourcePath, deploymentItem.RelativeOutputDirectory); warnings.Add(warning); return(false); } return(true); }
private static string getDeploymentDestination(string source, DeploymentItem x, string outputDir) { var destination = outputDir; if (x.OutputDirectory != null) { if (Path.IsPathRooted(x.OutputDirectory)) { destination = x.OutputDirectory; } else { destination = Path.Combine(outputDir, x.OutputDirectory); } if (!Directory.Exists(destination)) { Directory.CreateDirectory(destination); } } return(Path.Combine(destination, Path.GetFileName(source))); }
public RemoveApplicationTypeCommandTests() { _appClient = new Mock <IApplicationClient>(); _appTypeClient = new Mock <IApplicationTypeClient>(); _innerCommand = new Mock <ICommand>(); var fabricClient = new Mock <IServiceFabricClient>(); fabricClient.Setup(c => c.Applications).Returns(_appClient.Object); fabricClient.Setup(c => c.ApplicationTypes).Returns(_appTypeClient.Object); _item = new DeploymentItem { ApplicationTypeName = "AppType", ApplicationId = "app" }; var context = new CommandContext { FabricClient = fabricClient.Object, Logger = Logger.Object, CurrentDeploymentItem = _item }; _command = new RemoveApplicationTypeCommand(context, _innerCommand.Object); }
public void GetClassLevelDeploymentItemsShouldReturnADeploymentItem() { var kvpArray = new[] { new KeyValuePair <string, string>( this.defaultDeploymentItemPath, this.defaultDeploymentItemOutputDirectory) }; this.SetupDeploymentItems(typeof(DeploymentItemUtilityTests).GetTypeInfo(), kvpArray); var deploymentItems = this.deploymentItemUtility.GetClassLevelDeploymentItems(typeof(DeploymentItemUtilityTests), this.warnings); var expectedDeploymentItems = new DeploymentItem[] { new DeploymentItem( this.defaultDeploymentItemPath, this.defaultDeploymentItemOutputDirectory) }; CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray()); }
public CopyImageToStoreCommandTests() { _imageStoreClient = new Mock <IImageStoreClient>(); _innerCommand = new Mock <ICommand>(); var fabricClient = new Mock <IServiceFabricClient>(); fabricClient.Setup(c => c.ImageStore).Returns(_imageStoreClient.Object); _item = new DeploymentItem { PackagePath = @"c:\temp\pkg", ApplicationTypeName = "AppType", ApplicationId = "app" }; var context = new CommandContext { FabricClient = fabricClient.Object, Logger = Logger.Object, CurrentDeploymentItem = _item }; _command = new CopyImageToStoreCommand(context, _innerCommand.Object); }
private async Task <bool> CheckCreateApplicationStatusAsync(DeploymentItem item) { var startTime = DateTime.Now; var appInfo = await _context.AppClient.GetApplicationInfoAsync(item.ApplicationId); while (appInfo.Status != ApplicationStatus.Ready && appInfo.HealthState != HealthState.Ok) { var currentTime = DateTime.Now; if (currentTime > startTime.AddSeconds(item.MaxApplicationReadyWaitTime)) { return(false); } await Task.Delay(AvailableCheckDelay); appInfo = await _context.AppClient.GetApplicationInfoAsync(item.ApplicationId); } return(appInfo.Status == ApplicationStatus.Ready); }
public void EqualsShouldReturnFalseIfOtherItemIsNotDeploymentItem() { DeploymentItem item = new DeploymentItem("e:\\temp\\temp1.dll"); Assert.IsFalse(item.Equals(new DeploymentItemTests())); }
private DeploymentItem CreateDeploymentItem(DeploymentItemAttribute deploymentItemAttr) { PropertyCollection properties = ToastTool.TestContext.Properties; DeploymentItem deploymentItem = null; string path = deploymentItemAttr.Path; string outputDirectory = deploymentItemAttr.OutputDirectory; try { if (properties != null) { path = StringUtility.ReplaceTags(path, "$(", ")", properties); outputDirectory = StringUtility.ReplaceTags(outputDirectory, "$(", ")", properties); } deploymentItem = new DeploymentItem( new ParsedPath(path, PathType.File).MakeFullPath(ToastTool.TestContext.InternalOriginalCurrentDirectory), deploymentItemAttr.OutputDirectory == ParsedPath.Empty ? DeploymentDir : new ParsedPath(outputDirectory, PathType.Directory).MakeFullPath(DeploymentDir)); } catch (ArgumentException e) { WriteError(TestingResources.UnableToProcessDeploymentItem( path, outputDirectory, e.Message)); } return deploymentItem; }
private bool CopyDeploymentItem(DeploymentItem deploymentItem) { Debug.Assert(!deploymentItem.Path.IsRelativePath); Debug.Assert(!deploymentItem.OutputDirectory.IsRelativePath); if (!Directory.Exists(deploymentItem.OutputDirectory)) { if (!CreateDeploymentDirectory(deploymentItem.OutputDirectory)) return false; } ParsedPath deployedFilePath = deploymentItem.OutputDirectory.Append(deploymentItem.Path.FileAndExtension); // Don't try and copy a file over itself if (deployedFilePath == deploymentItem.Path) return true; try { SafeFileCopy(deploymentItem.Path, deployedFilePath); // Check if an .xxx.mdb file exists and deploy that too. ParsedPath deploymentFileMdb = deploymentItem.Path.WithExtension(deploymentItem.Path.Extension + ".mdb"); if (File.Exists(deploymentFileMdb)) { SafeFileCopy(deploymentFileMdb, deployedFilePath.WithExtension(deployedFilePath.Extension + ".mdb")); } return true; } catch (Exception e) { if (ExceptionUtility.IsCriticalException(e)) throw; WriteWarning(TestingResources.UnableToCopyFile(deploymentItem.Path, deployedFilePath, e.Message)); return false; } }