/// <summary> /// Build up the tree structure of the gates from the gate cache /// </summary> /// <param name="root">root of the tree</param> /// <param name="cache">gate cache</param> private static void BuildTree(GateItem root, GateDataSet cache) { foreach (string name in cache.GateNames) { string[] sections = name.Split('.'); GateItem parentItem = root; GateItem item = null; for (int i = 0; i < sections.Length; i++) { if (!parentItem.Gates.TryGetValue(sections[i], out item)) { item = new GateItem { GateGroupName = sections[i] }; parentItem.Gates[sections[i]] = item; } parentItem = item; } if (item != null) { item.Name = name; } } }
public void IsApplicable_ContainterGateIsNotApplicable_NoReleaseGateReturned() { IGatedRequest gateRequest = SetupGateRequest("ClientThree", "16.3.0.0", "en-gb"); GateContext context = new GateContext(gateRequest, new BasicMachineInformation(), new DefaultExperimentContext()); GateDataSet dataSet = LoadGateDataSet(ReleaseGateXml); IGate gate = dataSet.GetGate("MyProduct.Test.ReleasePlan"); GatesAny gates = new GatesAny(gate.ReleasePlan); Assert.False(gates.IsApplicable(context, out IGate[] applicableReleaseGates), "Gate should not be applicable"); Assert.Null(applicableReleaseGates); }
/// <summary> /// Loads the gate data set. /// </summary> /// <param name="content">The content.</param> /// <returns>Gate data set.</returns> private static GateDataSet LoadGateDataSet(string content) { IDictionary<string, IResourceDetails> resources = new Dictionary<string, IResourceDetails>(2, StringComparer.OrdinalIgnoreCase) { { ResourceNames.Gates, EmbeddedResources.CreateResourceDetails(content) }, { ResourceNames.TestGroups, EmbeddedResources.CreateResourceDetails(ValidDataRaw) } }; GateDataSet dataSet = new GateDataSet(ResourceNames.Gates, ResourceNames.TestGroups); dataSet.Load(resources); return dataSet; }
public void IsApplicable_ContainterGateIsApplicable_ApplicableReleaseGateReturned() { IGatedRequest gateRequest = SetupGateRequest("ClientThree", "16.3.0.0", "en-us", "PreProduction", new[] { new GatedUser { UserIdentifier = "*****@*****.**" } }); GateContext context = new GateContext(gateRequest, new BasicMachineInformation(), new DefaultExperimentContext()); GateDataSet dataSet = LoadGateDataSet(ReleaseGateXml); IGate gate = dataSet.GetGate("MyProduct.Test.ReleasePlan"); GatesAny gates = new GatesAny(gate.ReleasePlan); Assert.True(gates.IsApplicable(context, out IGate[] applicableReleaseGates), "Gate should be applicable"); Assert.NotNull(applicableReleaseGates); Assert.Same(applicableReleaseGates[0], gate.ReleasePlan[0]); }
/// <summary> /// Loads GateDataSet from file /// </summary> /// <param name="settingsXml">The settings XML.</param> /// <param name="tipXml">The TIP XML.</param> /// <returns>Loaded Gates DataSet</returns> private static GateDataSet LoadGateDataSet(string settingsXml, string tipXml) { FileInfo settingsFile = new FileInfo(settingsXml); FileInfo tipFile = new FileInfo(tipXml); IDictionary <string, IResourceDetails> resources = new Dictionary <string, IResourceDetails>(2, StringComparer.OrdinalIgnoreCase) { { settingsFile.Name, new ResourceDetails(settingsFile.LastWriteTimeUtc, settingsFile.Length, File.ReadAllBytes(settingsFile.FullName)) }, { tipFile.Name, new ResourceDetails(tipFile.LastWriteTimeUtc, tipFile.Length, File.ReadAllBytes(tipFile.FullName)) } }; GateDataSet dataSet = new GateDataSet(settingsFile.Name, tipFile.Name); dataSet.Load(resources); return(dataSet); }
public void GatedCode_UsingGateWithReleasePlanHavingNoApplicableReleaseGates_NoApplicableReleaseGateReturnedUsingGatesProperty() { GateDataSet gateDataSet = LoadGateDataSet(GateXmlWithReleaseGates); // Gates property intialized with GatesNone object. GatedCode gatedCode = new GatedCode(gateDataSet.GetGate("MyProduct.Test.ReleasePlan")); UnitTestGateContext gateContext = new UnitTestGateContext { AlwaysReturnApplicable = false, ApplicableGates = new List <string>() { "MyProduct.Test.ReleasePlan", } }; Assert.False(gatedCode.IsBaselineCode, "Shouldn't be a baseline code as its gated."); Assert.False(gatedCode.Gates.IsApplicable(gateContext, out IGate[] gates), "Returns false as no release gate applicable"); Assert.Null(gates); }
public void GatedCode_UsingGateWithReleasePlanHavingApplicableReleaseGates_FirstApplicableReleaseGateReturnedUsingGatesProperty() { GateDataSet gateDataSet = LoadGateDataSet(GateXmlWithReleaseGates); // Gates property intialized with GatesAny object. GatedCode gatedCode = new GatedCode(gateDataSet.GetGate("MyProduct.Test.ReleasePlan")); UnitTestGateContext gateContext = new UnitTestGateContext { AlwaysReturnApplicable = false, ApplicableGates = new List <string>() { "MyProduct.Test.ReleasePlan", "MyProduct.WebSite.Feature.ReleasePlan.Integration" } }; Assert.False(gatedCode.IsBaselineCode, "Shouldn't be a baseline code as its gated."); Assert.True(gatedCode.Gates.IsApplicable(gateContext, out IGate[] gates), "Returns true with first applicable release gate."); Assert.Equal("MyProduct.WebSite.Feature.ReleasePlan.Integration", gates.First().FullyQualifiedName); }
/// <summary> /// Main entry point from command line. /// </summary> /// <param name="arguments">Command line arguments</param> /// <returns>0 if successfull; 1 otherwise</returns> public static int Main(string[] arguments) { ConsoleColor originalColor = Console.ForegroundColor; const string version = "2.0.0.0"; try { if (arguments.Length < 3) { Console.WriteLine("Omex gate generator, version {0}", version); Console.WriteLine("Usage: Microsoft.Omex.CodeGenerators.GateGen.exe omexgates.xml omextip.xml output.cs [namespace]"); return(1); } GateDataSet gateDataSet = null; try { gateDataSet = LoadGateDataSet(arguments[0], arguments[1]); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Unable to read file {0}.", arguments[0]); Console.WriteLine(ex); return(1); } finally { Console.ForegroundColor = originalColor; } GateItem root = new GateItem(); BuildTree(root, gateDataSet); AssemblyName assemblyName = Assembly.GetExecutingAssembly().GetName(); try { string omexGatesNamespace = "Microsoft.Omex.Gating"; if (arguments.Length >= 4 && !string.IsNullOrWhiteSpace(arguments[3])) { omexGatesNamespace = arguments[3]; } using (StreamWriter writer = new StreamWriter(arguments[2])) { writer.Write(string.Format(CultureInfo.InvariantCulture, Properties.Resources.GatesClassTemplate, assemblyName.Name, version, OutputTree(root, "\t"), omexGatesNamespace, "OmexGates", "Microsoft.Omex.Gating.Gates")); } } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Unable to write file {0}.", arguments[1]); Console.WriteLine(ex); return(1); } } finally { Console.ForegroundColor = originalColor; } return(0); }