diff --git a/MvsSln/Core/ConfigItem.cs b/MvsSln/Core/ConfigItem.cs index ad2d6f4..9844e48 100644 --- a/MvsSln/Core/ConfigItem.cs +++ b/MvsSln/Core/ConfigItem.cs @@ -24,6 +24,7 @@ using System; using System.Diagnostics; +using net.r_eg.MvsSln.Extensions; namespace net.r_eg.MvsSln.Core { @@ -85,10 +86,8 @@ public string PlatformByRuleICase public static bool operator ==(ConfigItem a, ConfigItem b) { - if(Object.ReferenceEquals(a, null)) { - return Object.ReferenceEquals(b, null); - } - return a.Equals(b); + return Object.ReferenceEquals(a, null) ? + Object.ReferenceEquals(b, null) : a.Equals(b); } public static bool operator !=(ConfigItem a, ConfigItem b) @@ -103,15 +102,18 @@ public override bool Equals(object obj) } var b = (ConfigItem)obj; - return (ConfigurationByRuleICase == b.ConfigurationByRuleICase) - && (PlatformByRuleICase == b.PlatformByRuleICase); + + return ConfigurationByRuleICase == b.ConfigurationByRuleICase + && PlatformByRuleICase == b.PlatformByRuleICase; } public override int GetHashCode() { - unchecked { - return (Configuration.GetHashCode() << 5) + Configuration.GetHashCode() ^ Platform.GetHashCode(); - } + return 0.CalculateHashCode + ( + Configuration.GetHashCode(), + Platform.GetHashCode() + ); } public override string ToString() diff --git a/MvsSln/Core/Guids.cs b/MvsSln/Core/Guids.cs index d2a5401..58eba7e 100644 --- a/MvsSln/Core/Guids.cs +++ b/MvsSln/Core/Guids.cs @@ -22,8 +22,9 @@ * THE SOFTWARE. */ -using System.Linq; +using System; using System.Collections.Generic; +using System.Linq; namespace net.r_eg.MvsSln.Core { diff --git a/MvsSln/Core/ObjHandlers/HandlerValue.cs b/MvsSln/Core/ObjHandlers/HandlerValue.cs index 9a0316a..7c65273 100644 --- a/MvsSln/Core/ObjHandlers/HandlerValue.cs +++ b/MvsSln/Core/ObjHandlers/HandlerValue.cs @@ -23,6 +23,7 @@ */ using System; +using net.r_eg.MvsSln.Extensions; namespace net.r_eg.MvsSln.Core.ObjHandlers { @@ -39,10 +40,8 @@ public struct HandlerValue public static bool operator ==(HandlerValue a, HandlerValue b) { - if(Object.ReferenceEquals(a, null)) { - return Object.ReferenceEquals(b, null); - } - return a.Equals(b); + return Object.ReferenceEquals(a, null) ? + Object.ReferenceEquals(b, null) : a.Equals(b); } public static bool operator !=(HandlerValue a, HandlerValue b) @@ -65,19 +64,12 @@ public override bool Equals(object obj) public override int GetHashCode() { - int polynom(int r, int x) - { - unchecked { - return (r << 5) + r ^ x; - } - }; - - int h = 0; - h = polynom(h, handler.GetHashCode()); - h = polynom(h, value.GetHashCode()); - h = polynom(h, id.GetHashCode()); - - return h; + return 0.CalculateHashCode + ( + handler.GetHashCode(), + value.GetHashCode(), + id.GetHashCode() + ); } public HandlerValue(IObjHandler handler) diff --git a/MvsSln/Core/ProjectItem.cs b/MvsSln/Core/ProjectItem.cs index 23d88c2..ebbf9ac 100644 --- a/MvsSln/Core/ProjectItem.cs +++ b/MvsSln/Core/ProjectItem.cs @@ -26,6 +26,7 @@ using System.Diagnostics; using System.IO; using System.Text.RegularExpressions; +using net.r_eg.MvsSln.Extensions; using net.r_eg.MvsSln.Log; namespace net.r_eg.MvsSln.Core @@ -37,27 +38,27 @@ namespace net.r_eg.MvsSln.Core public struct ProjectItem { /// - /// Project GUID + /// Project GUID. /// public string pGuid; /// - /// Project type GUID + /// Project type GUID. /// public string pType; /// - /// Project name + /// Project name. /// public string name; /// - /// Relative path to project + /// Relative path to project. /// public string path; /// - /// Full path to project + /// Evaluated full path to project. /// public string fullPath; @@ -72,9 +73,9 @@ public struct ProjectItem public ProjectType EpType; /// - /// Evaluate project type via Guid. + /// Evaluate project type via GUID. /// - /// Project type Guid. + /// Project type GUID. /// [Obsolete("Use `Guids.ProjectTypeBy(string guid)` instead.", false)] public static ProjectType ProjectTypeBy(string guid) @@ -82,38 +83,115 @@ public static ProjectType ProjectTypeBy(string guid) return Guids.ProjectTypeBy(guid); } - public ProjectItem(string name, ProjectType pType) - : this(name, name, pType) + public static bool operator ==(ProjectItem a, ProjectItem b) + { + return Object.ReferenceEquals(a, null) ? + Object.ReferenceEquals(b, null) : a.Equals(b); + } + + public static bool operator !=(ProjectItem a, ProjectItem b) + { + return !(a == b); + } + + public override bool Equals(object obj) + { + if(Object.ReferenceEquals(obj, null) || !(obj is ProjectItem)) { + return false; + } + + var b = (ProjectItem)obj; + + return pGuid == b.pGuid + && pType == b.pType + && name == b.name + && path == b.path + && fullPath == b.fullPath + && EpType == b.EpType + && parent == b.parent; + } + + public override int GetHashCode() + { + return 0.CalculateHashCode + ( + pGuid.GetHashCode(), + pType.GetHashCode(), + name.GetHashCode(), + path.GetHashCode(), + fullPath.GetHashCode(), + EpType.GetHashCode(), + parent.GetHashCode() + ); + } + + /// Project name. + /// Project type GUID. + /// Parent folder. + public ProjectItem(string name, ProjectType pType, SolutionFolder? parent = null) + : this(name, pType, name, parent) { } - public ProjectItem(string pGuid, string name, ProjectType pType) - : this(pGuid, name, name, pType) + /// Project name. + /// Project type GUID. + /// + /// Parent folder. + /// To evaluate `fullPath` define path to solution directory. + public ProjectItem(string name, ProjectType pType, string path, SolutionFolder? parent = null, string slnDir = null) + : this(Guid.NewGuid().SlnFormat(), name, pType, path, parent, slnDir) { } - public ProjectItem(string name, string path, ProjectType pType, string slnDir = null) - : this(Guid.NewGuid().ToString(), name, path, pType, slnDir) + /// Project GUID. + /// Project name. + /// Project type GUID. + /// Parent folder. + public ProjectItem(string pGuid, string name, ProjectType pType, SolutionFolder? parent = null) + : this(pGuid, name, pType, name, parent) { } - public ProjectItem(string pGuid, string name, string path, ProjectType pType, string slnDir = null) + /// Project GUID. + /// Project name. + /// Project type GUID. + /// Relative path to project. + /// Parent folder. + /// To evaluate `fullPath` define path to solution directory. + public ProjectItem(string pGuid, string name, ProjectType pType, string path, SolutionFolder? parent = null, string slnDir = null) : this() { - Init(pGuid, name, path, pType, slnDir); + Init(pGuid, name, path, pType, parent, slnDir); } + /// Project GUID. + /// Project name. + /// Relative path to project. + /// Project type GUID. + /// To evaluate `fullPath` define path to solution directory. public ProjectItem(string pGuid, string name, string path, string pType, string slnDir = null) : this() { Init(pGuid, name, path, pType, slnDir); } + /// Initialize data from other project. + public ProjectItem(ProjectItem prj) + { + pGuid = prj.pGuid.ReformatSlnGuid(); + pType = prj.pType.ReformatSlnGuid(); + name = prj.name; + path = prj.path; + fullPath = prj.fullPath; + EpType = prj.EpType; + parent = prj.parent; + } + /// Initialize data from raw line. - /// Path to solution directory. + /// To evaluate `fullPath` define path to solution directory. public ProjectItem(string raw, string solutionDir) : this() { @@ -133,28 +211,28 @@ public ProjectItem(string raw, string solutionDir) ); } - private void Init(string pGuid, string name, string path, ProjectType pType, string slnDir) + private void Init(string pGuid, string name, string path, ProjectType pType, SolutionFolder? parent, string slnDir) { SetProjectType(pType); - Init(pGuid, name, path, slnDir); + SetFields(pGuid, name, path, slnDir, parent); } private void Init(string pGuid, string name, string path, string pType, string slnDir) { SetProjectType(pType); - Init(pGuid, name, path, slnDir); + SetFields(pGuid, name, path, slnDir); } - private void Init(string pGuid, string name, string path, string slnDir) + private void SetFields(string pGuid, string name, string path, string slnDir, SolutionFolder? parent = null) { this.name = name.Trim(); this.path = path.Trim(); - this.pGuid = pGuid.Trim(); + this.pGuid = pGuid.ReformatSlnGuid(); SetFullPath(slnDir); - LSender.Send(this, $"ProjectItem ->['{pGuid}'; '{name}'; '{path}'; '{fullPath}'; '{pType}' ]", Message.Level.Trace); - parent = new RefType(); + + this.parent = new RefType(parent); } private void SetProjectType(ProjectType pType) @@ -169,16 +247,12 @@ private void SetProjectType(ProjectType pType) /// private void SetProjectType(string pType) { - this.pType = pType; + this.pType = pType.ReformatSlnGuid(); EpType = Guids.ProjectTypeBy(pType); } private void SetFullPath(string slnDir) { - if(slnDir == null) { - return; - } - if(Path.IsPathRooted(path)) { fullPath = path; } diff --git a/MvsSln/Core/RawText.cs b/MvsSln/Core/RawText.cs index d850d78..956d93f 100644 --- a/MvsSln/Core/RawText.cs +++ b/MvsSln/Core/RawText.cs @@ -22,8 +22,10 @@ * THE SOFTWARE. */ +using System; using System.Diagnostics; using System.Text; +using net.r_eg.MvsSln.Extensions; namespace net.r_eg.MvsSln.Core { @@ -49,6 +51,40 @@ public static implicit operator RawText(string str) return new RawText(str); } + public static bool operator ==(RawText a, RawText b) + { + return Object.ReferenceEquals(a, null) ? + Object.ReferenceEquals(b, null) : a.Equals(b); + } + + public static bool operator !=(RawText a, RawText b) + { + return !(a == b); + } + + public override bool Equals(object obj) + { + if(Object.ReferenceEquals(obj, null) || !(obj is RawText)) { + return false; + } + + var b = (RawText)obj; + + return data == b.data + && trimmed == b.trimmed + && encoding == b.encoding; + } + + public override int GetHashCode() + { + return 0.CalculateHashCode + ( + data.GetHashCode(), + trimmed.GetHashCode(), + encoding.GetHashCode() + ); + } + public override string ToString() { return data; diff --git a/MvsSln/Core/RefType.cs b/MvsSln/Core/RefType.cs index 8e27335..849e18b 100644 --- a/MvsSln/Core/RefType.cs +++ b/MvsSln/Core/RefType.cs @@ -22,6 +22,7 @@ * THE SOFTWARE. */ +using System; using System.Diagnostics; namespace net.r_eg.MvsSln.Core @@ -48,6 +49,34 @@ public static implicit operator RefType(T v) return new RefType(v); } + public static bool operator ==(RefType a, RefType b) + { + bool _EqNull(RefType x) + { + return Object.ReferenceEquals(x, null) + || Object.ReferenceEquals(x.Value, null); + } + return _EqNull(a) ? _EqNull(b) : a.Equals(b); + } + + public static bool operator !=(RefType a, RefType b) + { + return !(a == b); + } + + public override bool Equals(object obj) + { + if(Object.ReferenceEquals(obj, null) || !(obj is RefType)) { + return false; + } + return Value.Equals(((RefType)obj).Value); + } + + public override int GetHashCode() + { + return Value.GetHashCode(); + } + public RefType(T value) { Value = value; diff --git a/MvsSln/Core/SlnHandlers/LProjectConfigurationPlatforms.cs b/MvsSln/Core/SlnHandlers/LProjectConfigurationPlatforms.cs index 42eeb68..1e5d28e 100644 --- a/MvsSln/Core/SlnHandlers/LProjectConfigurationPlatforms.cs +++ b/MvsSln/Core/SlnHandlers/LProjectConfigurationPlatforms.cs @@ -24,6 +24,7 @@ using System; using System.Collections.Generic; +using net.r_eg.MvsSln.Extensions; using net.r_eg.MvsSln.Log; namespace net.r_eg.MvsSln.Core.SlnHandlers @@ -46,18 +47,12 @@ public bool Equals(Cortege a, Cortege b) public int GetHashCode(Cortege obj) { - Func polynom = delegate(int r, int x) { - unchecked { - return (r << 5) + r ^ x; - } - }; - - int h = 0; - h = polynom(h, obj.pGuid.GetHashCode()); - h = polynom(h, obj.csln.GetHashCode()); - h = polynom(h, obj.cprj.GetHashCode()); - - return h; + return 0.CalculateHashCode + ( + obj.pGuid.GetHashCode(), + obj.csln.GetHashCode(), + obj.cprj.GetHashCode() + ); } } diff --git a/MvsSln/Core/SolutionFolder.cs b/MvsSln/Core/SolutionFolder.cs index f07dd4c..b291408 100644 --- a/MvsSln/Core/SolutionFolder.cs +++ b/MvsSln/Core/SolutionFolder.cs @@ -22,9 +22,11 @@ * THE SOFTWARE. */ +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using net.r_eg.MvsSln.Extensions; namespace net.r_eg.MvsSln.Core { @@ -41,13 +43,161 @@ public struct SolutionFolder /// public IEnumerable items; + public static bool operator ==(SolutionFolder a, SolutionFolder b) + { + return Object.ReferenceEquals(a, null) ? + Object.ReferenceEquals(b, null) : a.Equals(b); + } + + public static bool operator !=(SolutionFolder a, SolutionFolder b) + { + return !(a == b); + } + + /// + /// Elements will not compared. + /// + /// + /// + public override bool Equals(object obj) + { + if(Object.ReferenceEquals(obj, null) || !(obj is SolutionFolder)) { + return false; + } + + return header == ((SolutionFolder)obj).header; + } + + public override int GetHashCode() + { + return header.GetHashCode(); + } + + /// Not null Folder GUID. + /// Not null Solution folder name. + /// Optional items inside. + /// + public SolutionFolder(string fGuid, string name, IEnumerable items) + : this(fGuid, name, null, items) + { + + } + + /// Not null Folder GUID. + /// Not null Solution folder name. + /// + public SolutionFolder(Guid fGuid, string name) + : this(fGuid.SlnFormat(), name, null, null) + { + + } + + /// Not null Folder GUID. + /// Not null Solution folder name. + /// Parent folder. + /// Optional items inside. + /// + public SolutionFolder(string fGuid, string name, SolutionFolder parent, params RawText[] items) + : this(fGuid, name, parent, items?.AsEnumerable()) + { + + } + + /// Not null Folder GUID. + /// Not null Solution folder name. + /// Parent folder. + /// Optional items inside. + /// + public SolutionFolder(string fGuid, string name, SolutionFolder? parent, IEnumerable items) + : this + ( new ProjectItem + ( + fGuid ?? throw new ArgumentNullException(), + name ?? throw new ArgumentNullException(), + ProjectType.SlnFolder, + parent + ), + items + ) + { + + } + + /// Not null Solution folder name. + /// Optional items inside. + /// + public SolutionFolder(string name, params RawText[] items) + : this(name, items?.AsEnumerable()) + { + + } + + /// Not null Solution folder name. + /// Optional items inside. + /// + public SolutionFolder(string name, IEnumerable items) + : this + ( new ProjectItem + ( + name ?? throw new ArgumentNullException(), + ProjectType.SlnFolder + ), + items + ) + { + + } + + /// Not null Solution folder name. + /// Parent folder. + /// Optional items inside. + /// + public SolutionFolder(string name, SolutionFolder parent, params RawText[] items) + : this(name, parent, items?.AsEnumerable()) + { + + } + + /// Not null Solution folder name. + /// Parent folder. + /// Optional items inside. + /// + public SolutionFolder(string name, SolutionFolder parent, IEnumerable items) + : this + ( new ProjectItem + ( + name ?? throw new ArgumentNullException(), + ProjectType.SlnFolder, + parent + ), + items + ) + { + + } + + /// Information about folder. + /// List of items for this folder. + public SolutionFolder(ProjectItem pItem, params RawText[] def) + : this(pItem, def?.AsEnumerable()) + { + + } + /// Information about folder. /// List of items for this folder. public SolutionFolder(ProjectItem pItem, IEnumerable def) : this() { header = pItem; - items = def; + items = def ?? new List(); + } + + /// Initialize data from other folder. + public SolutionFolder(SolutionFolder folder) + { + header = folder.header; + items = folder.items; } #region DebuggerDisplay diff --git a/MvsSln/Extensions/MathExtension.cs b/MvsSln/Extensions/MathExtension.cs new file mode 100644 index 0000000..c24d53c --- /dev/null +++ b/MvsSln/Extensions/MathExtension.cs @@ -0,0 +1,57 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2013-2019 Denis Kuzmin < entry.reg@gmail.com > GitHub/3F + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. +*/ + +namespace net.r_eg.MvsSln.Extensions +{ + public static class MathExtension + { + /// + /// Our optimal polynom for hash functions. + /// + /// initial vector + /// new value + /// + public static int HashPolynom(this int r, int x) + { + unchecked { + return (r << 5) + r ^ x; + } + } + + /// + /// Calculate final Hash Code from specified vector and pushed values. + /// + /// initial vector + /// List of individual Hash Code values. + /// + public static int CalculateHashCode(this int r, params int[] values) + { + int h = r; + foreach(var v in values) { + h.HashPolynom(v); + } + return h; + } + } +} \ No newline at end of file diff --git a/MvsSln/Extensions/StringExtension.cs b/MvsSln/Extensions/StringExtension.cs index c345948..1e242ec 100644 --- a/MvsSln/Extensions/StringExtension.cs +++ b/MvsSln/Extensions/StringExtension.cs @@ -38,14 +38,41 @@ public static class StringExtension /// public static Guid Guid(this string str) { + if(System.Guid.TryParse(str, out Guid res)) { + return res; + } + if(str == null) { str = String.Empty; } + using(MD5 md5 = MD5.Create()) { return new Guid(md5.ComputeHash(Encoding.UTF8.GetBytes(str))); } } + /// + /// Sln format of GUID: + /// 32 uppercase digits separated by hyphens, enclosed in braces: + /// ie. {100FD7F2-3278-49C7-B9D4-A91F1C65BED3} + /// + /// + /// + public static string SlnFormat(this Guid guid) + { + return guid.ToString("B").ToUpper(); + } + + /// + /// Returns string GUID formated via `GuidSlnFormat` + /// + /// + /// + public static string ReformatSlnGuid(this string guid) + { + return guid?.Trim().Guid().SlnFormat(); + } + /// /// Gets part of string before specific symbols. /// diff --git a/MvsSln/MvsSln.csproj b/MvsSln/MvsSln.csproj index 814df5b..4527417 100644 --- a/MvsSln/MvsSln.csproj +++ b/MvsSln/MvsSln.csproj @@ -91,6 +91,7 @@ + diff --git a/MvsSlnTest/Core/ObjHandlers/WNestedProjectsTest.cs b/MvsSlnTest/Core/ObjHandlers/WNestedProjectsTest.cs index 714f806..a4f2629 100644 --- a/MvsSlnTest/Core/ObjHandlers/WNestedProjectsTest.cs +++ b/MvsSlnTest/Core/ObjHandlers/WNestedProjectsTest.cs @@ -11,34 +11,18 @@ public class WNestedProjectsTest { protected List folders = new List() { - new SolutionFolder - ( - new ProjectItem("{8B05CE1C-999E-460D-80FF-E44DFEC019E7}", "dir1", ProjectType.SlnFolder), - new List() { } - ), - new SolutionFolder - ( - new ProjectItem("{BEB7D6F5-5065-4427-9797-2AD7511862D8}", "dir2", ProjectType.SlnFolder), - new List() { } - ), - new SolutionFolder - ( - new ProjectItem("{1257C186-1EC7-41C6-9344-14B2341BE6F6}", "dir3", ProjectType.SlnFolder), - new List() { } - ), - new SolutionFolder - ( - new ProjectItem("{80AEF083-D86A-416E-88B8-300DF20399AF}", "dir4", ProjectType.SlnFolder), - new List() { } - ), + new SolutionFolder("{8B05CE1C-999E-460D-80FF-E44DFEC019E7}", "dir1", null), + new SolutionFolder("{BEB7D6F5-5065-4427-9797-2AD7511862D8}", "dir2", null), + new SolutionFolder("{1257C186-1EC7-41C6-9344-14B2341BE6F6}", "dir3", null), + new SolutionFolder("{80AEF083-D86A-416E-88B8-300DF20399AF}", "dir4", null), }; protected List projects = new List() { - new ProjectItem("{A2D23001-08A8-49AF-A975-64ADA41EB08A}", "Project1", "path1", ProjectType.Cs), - new ProjectItem("{470DA54D-A309-4A6B-8670-33F017213113}", "Project2", "path2", ProjectType.Cs), - new ProjectItem("{C4C66B30-66CD-4D68-9A95-372CA4A13611}", "Project3", "path3", ProjectType.Vc), - new ProjectItem("{C1A3BCC3-F120-471D-A31E-4B835A06F42D}", "Project4", "path4", ProjectType.Vc), + new ProjectItem("{A2D23001-08A8-49AF-A975-64ADA41EB08A}", "Project1", ProjectType.Cs), + new ProjectItem("{470DA54D-A309-4A6B-8670-33F017213113}", "Project2", ProjectType.Cs), + new ProjectItem("{C4C66B30-66CD-4D68-9A95-372CA4A13611}", "Project3", ProjectType.Vc), + new ProjectItem("{C1A3BCC3-F120-471D-A31E-4B835A06F42D}", "Project4", ProjectType.Vc), }; [TestMethod] diff --git a/MvsSlnTest/Core/ObjHandlers/WProjectSolutionItemsTest.cs b/MvsSlnTest/Core/ObjHandlers/WProjectSolutionItemsTest.cs index 0c250d8..d8db1fc 100644 --- a/MvsSlnTest/Core/ObjHandlers/WProjectSolutionItemsTest.cs +++ b/MvsSlnTest/Core/ObjHandlers/WProjectSolutionItemsTest.cs @@ -13,26 +13,35 @@ public void ExtractTest1() { var data = new List() { - new SolutionFolder(new ProjectItem() { - pType = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", - name = ".gnt", - path = ".gnt", - pGuid = "{65FF5D56-E814-4956-89BD-7C53EC557BFE}" - }, - new List(){ - ".gnt\\gnt.core", - ".gnt\\packages.config" - }), + new SolutionFolder + ( + new ProjectItem() + { + pType = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", + name = ".gnt", + path = ".gnt", + pGuid = "{65FF5D56-E814-4956-89BD-7C53EC557BFE}" + }, + new List() + { + ".gnt\\gnt.core", + ".gnt\\packages.config" + } + ), - new SolutionFolder(new ProjectItem() { - pType = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", - name = "tools", - path = "tools", - pGuid = "{849DD790-F856-493C-A19E-2560A21F6AF1}" - }, - new List(){ - "tools\\gnt.bat" - }), + new SolutionFolder + ( + new ProjectItem() + { + pType = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", + name = "tools", + path = "tools", + pGuid = "{849DD790-F856-493C-A19E-2560A21F6AF1}" + }, + new List(){ + "tools\\gnt.bat" + } + ), }; var target = (new WProjectSolutionItems(data)).Extract(null); diff --git a/MvsSlnTest/Core/ProjectItemTest.cs b/MvsSlnTest/Core/ProjectItemTest.cs index 047fdd4..a357721 100644 --- a/MvsSlnTest/Core/ProjectItemTest.cs +++ b/MvsSlnTest/Core/ProjectItemTest.cs @@ -6,6 +6,311 @@ namespace net.r_eg.MvsSlnTest.Core [TestClass] public class ProjectItemTest { + [TestMethod] + public void CtorTest1() + { + ProjectItem p = new ProjectItem("Project1", ProjectType.Cs); + + Assert.AreEqual + ( + new ProjectItem() + { + pGuid = p.pGuid, + fullPath = p.fullPath, + name = "Project1", + path = "Project1", + EpType = ProjectType.Cs, + pType = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" + }, + p + ); + + SolutionFolder f = new SolutionFolder("dir1"); + + p = new ProjectItem("Project1", ProjectType.Cs, f); + Assert.AreEqual + ( + new ProjectItem() + { + pGuid = p.pGuid, + fullPath = p.fullPath, + name = "Project1", + path = "Project1", + EpType = ProjectType.Cs, + pType = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", + parent = f + }, + p + ); + + p = new ProjectItem("Project2", ProjectType.Vc, "path 1"); + Assert.AreEqual + ( + new ProjectItem() + { + pGuid = p.pGuid, + fullPath = p.fullPath, + name = "Project2", + path = "path 1", + EpType = ProjectType.Vc, + pType = "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}", + }, + p + ); + + p = new ProjectItem("Project2", ProjectType.Vc, "path 1", f); + Assert.AreEqual + ( + new ProjectItem() + { + pGuid = p.pGuid, + fullPath = p.fullPath, + name = "Project2", + path = "path 1", + EpType = ProjectType.Vc, + pType = "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}", + parent = f + }, + p + ); + + p = new ProjectItem("Project 3", ProjectType.Vc, "prj path", f, @"C:\path\"); + Assert.AreEqual + ( + new ProjectItem() + { + pGuid = p.pGuid, + fullPath = @"C:\path\prj path", + name = "Project 3", + path = "prj path", + EpType = ProjectType.Vc, + pType = "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}", + parent = f + }, + p + ); + } + + [TestMethod] + public void CtorTest2() + { + ProjectItem p = new ProjectItem("{EE7DD6B7-56F4-478D-8745-3D204D915473}", "Project1", ProjectType.Cs); + + Assert.AreEqual + ( + new ProjectItem() + { + pGuid = "{EE7DD6B7-56F4-478D-8745-3D204D915473}", + fullPath = p.fullPath, + name = "Project1", + path = "Project1", + EpType = ProjectType.Cs, + pType = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" + }, + p + ); + + SolutionFolder f = new SolutionFolder("dir1"); + + p = new ProjectItem("{EE7DD6B7-56F4-478D-8745-3D204D915473}", "Project1", ProjectType.Cs, f); + Assert.AreEqual + ( + new ProjectItem() + { + pGuid = "{EE7DD6B7-56F4-478D-8745-3D204D915473}", + fullPath = p.fullPath, + name = "Project1", + path = "Project1", + EpType = ProjectType.Cs, + pType = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", + parent = f + }, + p + ); + + p = new ProjectItem("{EE7DD6B7-56F4-478D-8745-3D204D915473}", "Project1", ProjectType.Cs, "path 1"); + Assert.AreEqual + ( + new ProjectItem() + { + pGuid = "{EE7DD6B7-56F4-478D-8745-3D204D915473}", + fullPath = p.fullPath, + name = "Project1", + path = "path 1", + EpType = ProjectType.Cs, + pType = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", + }, + p + ); + + Assert.AreNotEqual + ( + new ProjectItem() + { + pGuid = "{EE7DD6B7-56F4-478D-8745-3D204D915473}", + fullPath = p.fullPath, + name = "Project1", + path = "path 1", + EpType = ProjectType.Cs, + pType = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", + parent = f + }, + p + ); + + p = new ProjectItem("{47EF5301-84E5-4210-A145-6460A1C8627A}", "Project2", ProjectType.Cs, "path 1", f); + Assert.AreEqual + ( + new ProjectItem() + { + pGuid = "{47EF5301-84E5-4210-A145-6460A1C8627A}", + fullPath = p.fullPath, + name = "Project2", + path = "path 1", + EpType = ProjectType.Cs, + pType = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", + parent = f + }, + p + ); + + p = new ProjectItem("{47EF5301-84E5-4210-A145-6460A1C8627A}", "Project2", ProjectType.Cs, "path 2", f, @"D:\slndir"); + Assert.AreEqual + ( + new ProjectItem() + { + pGuid = "{47EF5301-84E5-4210-A145-6460A1C8627A}", + fullPath = @"D:\slndir\path 2", + name = "Project2", + path = "path 2", + EpType = ProjectType.Cs, + pType = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", + parent = f + }, + p + ); + } + + [TestMethod] + public void CtorTest3() + { + var p = new ProjectItem + ( + "{47EF5301-84E5-4210-A145-6460A1C8627A}", + "Project2", + ProjectType.Cs, + "path 1", + new SolutionFolder("dir1") + ); + + Assert.AreEqual + ( + new ProjectItem(p), + p + ); + } + + [TestMethod] + public void EqTest1() + { + var project1 = new ProjectItem() + { + pGuid = "{8473B51C-3A9B-4A1B-8A41-D40FAC465DDD}", + pType = "{76FB8376-8A6F-48F8-BB0F-656FD6E36F09}", + name = "name 1", + path = "path 1", + fullPath = "full path 1", + EpType = ProjectType.Unknown + }; + + var project2SameAs1 = new ProjectItem() + { + pGuid = "{8473B51C-3A9B-4A1B-8A41-D40FAC465DDD}", + pType = "{76FB8376-8A6F-48F8-BB0F-656FD6E36F09}", + name = "name 1", + path = "path 1", + fullPath = "full path 1", + EpType = ProjectType.Unknown + }; + + var project3AreNotSameAs1 = new ProjectItem() + { + pGuid = "{8473B51C-3A9B-4A1B-8A41-D40FAC465DDD}", + pType = "{76FB8376-8A6F-48F8-BB0F-656FD6E36F09}", + name = "name 2", + path = "path 1", + fullPath = "full path 1", + EpType = ProjectType.Unknown + }; + + Assert.AreEqual(project1, project2SameAs1); + Assert.AreNotEqual(project1, project3AreNotSameAs1); + } + + [TestMethod] + public void EqTest2() + { + SolutionFolder folder1 = new SolutionFolder + ( + new ProjectItem() + { + pGuid = "{C5EB299D-B7C4-41C7-992C-233D3721180D}", + pType = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", + name = "dir 1", + path = "dir 1", + EpType = ProjectType.SlnFolder + } + ); + + SolutionFolder folder2 = new SolutionFolder + ( + new ProjectItem() + { + pGuid = "{55096B63-0420-4D9B-9DAD-77A94276D07D}", + pType = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", + name = "dir 2", + path = "dir 2", + EpType = ProjectType.SlnFolder + } + ); + + var project1 = new ProjectItem() + { + pGuid = "{8473B51C-3A9B-4A1B-8A41-D40FAC465DDD}", + pType = "{76FB8376-8A6F-48F8-BB0F-656FD6E36F09}", + name = "name 1", + path = "path 1", + fullPath = "full path 1", + EpType = ProjectType.Unknown, + parent = new RefType(folder1) + }; + + var project2SameAs1 = new ProjectItem() + { + pGuid = "{8473B51C-3A9B-4A1B-8A41-D40FAC465DDD}", + pType = "{76FB8376-8A6F-48F8-BB0F-656FD6E36F09}", + name = "name 1", + path = "path 1", + fullPath = "full path 1", + EpType = ProjectType.Unknown, + parent = new RefType(folder1) + }; + + var project3AreNotSameAs1 = new ProjectItem() + { + pGuid = "{8473B51C-3A9B-4A1B-8A41-D40FAC465DDD}", + pType = "{76FB8376-8A6F-48F8-BB0F-656FD6E36F09}", + name = "name 1", + path = "path 1", + fullPath = "full path 1", + EpType = ProjectType.Unknown, + parent = new RefType(folder2) + }; + + Assert.AreEqual(project1, project2SameAs1); + Assert.AreNotEqual(project1, project3AreNotSameAs1); + } + [TestMethod] public void ParseTest1() { diff --git a/MvsSlnTest/Core/SolutionFolderTest.cs b/MvsSlnTest/Core/SolutionFolderTest.cs new file mode 100644 index 0000000..218c485 --- /dev/null +++ b/MvsSlnTest/Core/SolutionFolderTest.cs @@ -0,0 +1,620 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using net.r_eg.MvsSln.Core; +using net.r_eg.MvsSln.Extensions; + +namespace net.r_eg.MvsSlnTest.Core +{ + [TestClass] + public class SolutionFolderTest + { + [TestMethod] + public void SubFolderTest1() + { + var f0 = new SolutionFolder("dir3", "hMSBuild.bat"); + var f1 = new SolutionFolder("dir2", f0); + var f2 = new SolutionFolder("dir1", f1); + + Assert.AreEqual + ( + new SolutionFolder() + { + header = new ProjectItem() + { + name = "dir1", + EpType = ProjectType.SlnFolder, + pType = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", + pGuid = f2.header.pGuid, + path = f2.header.path, + fullPath = f2.header.fullPath, + + parent = new SolutionFolder() + { + header = new ProjectItem() + { + name = "dir2", + EpType = ProjectType.SlnFolder, + pType = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", + pGuid = f1.header.pGuid, + path = f1.header.path, + fullPath = f1.header.fullPath, + + parent = new SolutionFolder() + { + header = new ProjectItem() + { + name = "dir3", + EpType = ProjectType.SlnFolder, + pType = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", + pGuid = f0.header.pGuid, + path = f0.header.path, + fullPath = f0.header.fullPath, + + parent = null, + }, + }, + }, + }, + }, + }, + + f2 + ); + } + + [TestMethod] + public void CtorTest1() + { + var f = new SolutionFolder("MyFolder1", ".gnt\\gnt.core", ".gnt\\packages.config"); + Assert.AreEqual + ( + new SolutionFolder() + { + header = new ProjectItem() + { + name = "MyFolder1", + EpType = ProjectType.SlnFolder, + pType = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", + pGuid = f.header.pGuid, + path = f.header.path, + fullPath = f.header.fullPath, + }, + + items = new List() + { + ".gnt\\gnt.core", ".gnt\\packages.config" + } + }, + f + ); + Assert.AreEqual(2, f.items.Count()); + Assert.AreEqual((RawText)".gnt\\gnt.core", f.items.ElementAt(0)); + Assert.AreEqual((RawText)".gnt\\packages.config", f.items.ElementAt(1)); + + + f = new SolutionFolder("MyFolder1", ".gnt\\gnt.core"); + Assert.AreEqual + ( + new SolutionFolder() + { + header = new ProjectItem() + { + name = "MyFolder1", + EpType = ProjectType.SlnFolder, + pType = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", + pGuid = f.header.pGuid, + path = f.header.path, + fullPath = f.header.fullPath, + }, + + items = new List() + { + ".gnt\\gnt.core" + } + }, + f + ); + Assert.AreEqual(1, f.items.Count()); + Assert.AreEqual((RawText)".gnt\\gnt.core", f.items.ElementAt(0)); + + + f = new SolutionFolder("MyFolder1"); + Assert.AreEqual + ( + new SolutionFolder() + { + header = new ProjectItem() + { + name = "MyFolder1", + EpType = ProjectType.SlnFolder, + pType = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", + pGuid = f.header.pGuid, + path = f.header.path, + fullPath = f.header.fullPath, + }, + items = new List() { } + }, + f + ); + Assert.AreEqual(0, f.items.Count()); + } + + [TestMethod] + public void CtorTest2() + { + var f = new SolutionFolder("MyFolder4", (new RawText[] { ".gnt\\gnt.core" }).AsEnumerable()); + + Assert.AreEqual + ( + new SolutionFolder() + { + header = new ProjectItem() + { + name = "MyFolder4", + EpType = ProjectType.SlnFolder, + pType = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", + pGuid = f.header.pGuid, + path = f.header.path, + fullPath = f.header.fullPath, + }, + + items = new List() + { + ".gnt\\gnt.core" + } + }, + f + ); + + Assert.AreEqual(1, f.items.Count()); + Assert.AreEqual((RawText)".gnt\\gnt.core", f.items.ElementAt(0)); + } + + [TestMethod] + public void CtorTest3() + { + var f = new SolutionFolder + ( + "MyFolder1", + "{EE7DD6B7-56F4-478D-8745-3D204D915473}", + new SolutionFolder("dir1"), + ".gnt\\gnt.core", + ".gnt\\packages.config" + ); + + Assert.AreEqual + ( + new SolutionFolder(f), + f + ); + } + + [TestMethod] + public void CtorTest4() + { + var f0 = new SolutionFolder("dir1"); + var f = new SolutionFolder("MyFolder1", f0, ".gnt\\gnt.core", ".gnt\\packages.config"); + + Assert.AreEqual + ( + new SolutionFolder() + { + header = new ProjectItem() + { + name = "MyFolder1", + EpType = ProjectType.SlnFolder, + pType = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", + parent = f0, + pGuid = f.header.pGuid, + path = f.header.path, + fullPath = f.header.fullPath, + }, + + items = new List() + { + ".gnt\\gnt.core", ".gnt\\packages.config" + } + }, + f + ); + Assert.AreEqual(2, f.items.Count()); + Assert.AreEqual((RawText)".gnt\\gnt.core", f.items.ElementAt(0)); + Assert.AreEqual((RawText)".gnt\\packages.config", f.items.ElementAt(1)); + + + f = new SolutionFolder("MyFolder2", f0, ".gnt\\gnt.core"); + Assert.AreEqual + ( + new SolutionFolder() + { + header = new ProjectItem() + { + name = "MyFolder2", + EpType = ProjectType.SlnFolder, + pType = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", + parent = f0, + pGuid = f.header.pGuid, + path = f.header.path, + fullPath = f.header.fullPath, + }, + + items = new List() + { + ".gnt\\gnt.core" + } + }, + f + ); + Assert.AreEqual(1, f.items.Count()); + Assert.AreEqual((RawText)".gnt\\gnt.core", f.items.ElementAt(0)); + + + f = new SolutionFolder("MyFolder3", f0); + Assert.AreEqual + ( + new SolutionFolder() + { + header = new ProjectItem() + { + name = "MyFolder3", + EpType = ProjectType.SlnFolder, + pType = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", + parent = f0, + pGuid = f.header.pGuid, + path = f.header.path, + fullPath = f.header.fullPath, + }, + items = new List() { } + }, + f + ); + Assert.AreEqual(0, f.items.Count()); + + + f = new SolutionFolder("MyFolder4", f0, (new RawText[] { ".gnt\\gnt.core" }).AsEnumerable()); + Assert.AreEqual + ( + new SolutionFolder() + { + header = new ProjectItem() + { + name = "MyFolder4", + EpType = ProjectType.SlnFolder, + pType = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", + parent = f0, + pGuid = f.header.pGuid, + path = f.header.path, + fullPath = f.header.fullPath, + }, + + items = new List() + { + ".gnt\\gnt.core" + } + }, + f + ); + Assert.AreEqual(1, f.items.Count()); + Assert.AreEqual((RawText)".gnt\\gnt.core", f.items.ElementAt(0)); + } + + [TestMethod] + public void CtorTest5() + { + var f = new SolutionFolder( + "{EE7DD6B7-56F4-478D-8745-3D204D915473}", "MyFolder1", + new RawText[] { ".gnt\\gnt.core", ".gnt\\packages.config" } + ); + Assert.AreEqual + ( + new SolutionFolder() + { + header = new ProjectItem() + { + name = "MyFolder1", + EpType = ProjectType.SlnFolder, + pType = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", + pGuid = "{EE7DD6B7-56F4-478D-8745-3D204D915473}", + path = f.header.path, + fullPath = f.header.fullPath, + }, + + items = new List() + { + ".gnt\\gnt.core", ".gnt\\packages.config" + } + }, + f + ); + Assert.AreEqual(2, f.items.Count()); + Assert.AreEqual((RawText)".gnt\\gnt.core", f.items.ElementAt(0)); + Assert.AreEqual((RawText)".gnt\\packages.config", f.items.ElementAt(1)); + + + var f0 = new SolutionFolder(); + + f = new SolutionFolder + ( + "{EE7DD6B7-56F4-478D-8745-3D204D915473}", + "MyFolder1", + f0, + ".gnt\\gnt.core", ".gnt\\packages.config" + ); + Assert.AreEqual + ( + new SolutionFolder() + { + header = new ProjectItem() + { + name = "MyFolder1", + EpType = ProjectType.SlnFolder, + pType = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", + pGuid = "{EE7DD6B7-56F4-478D-8745-3D204D915473}", + path = f.header.path, + parent = f0, + fullPath = f.header.fullPath, + }, + + items = new List() + { + ".gnt\\gnt.core", ".gnt\\packages.config" + } + }, + f + ); + Assert.AreEqual(2, f.items.Count()); + Assert.AreEqual((RawText)".gnt\\gnt.core", f.items.ElementAt(0)); + Assert.AreEqual((RawText)".gnt\\packages.config", f.items.ElementAt(1)); + } + + [TestMethod] + public void CtorTest6() + { + var f = new SolutionFolder + ( + "{EE7DD6B7-56F4-478D-8745-3D204D915473}", "MyFolder1", + new RawText[] { ".gnt\\gnt.core" } + ); + Assert.AreEqual + ( + new SolutionFolder() + { + header = new ProjectItem() + { + name = "MyFolder1", + EpType = ProjectType.SlnFolder, + pType = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", + pGuid = "{EE7DD6B7-56F4-478D-8745-3D204D915473}", + path = f.header.path, + fullPath = f.header.fullPath, + }, + + items = new List() + { + ".gnt\\gnt.core" + } + }, + f + ); + Assert.AreEqual(1, f.items.Count()); + Assert.AreEqual((RawText)".gnt\\gnt.core", f.items.ElementAt(0)); + + + f = new SolutionFolder("{EE7DD6B7-56F4-478D-8745-3D204D915473}", "MyFolder1", new RawText[] { }); + Assert.AreEqual + ( + new SolutionFolder() + { + header = new ProjectItem() + { + name = "MyFolder1", + EpType = ProjectType.SlnFolder, + pType = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", + pGuid = "{EE7DD6B7-56F4-478D-8745-3D204D915473}", + path = f.header.path, + fullPath = f.header.fullPath, + }, + items = new List() { } + }, + f + ); + Assert.AreEqual(0, f.items.Count()); + + + f = new SolutionFolder + ( + "{EE7DD6B7-56F4-478D-8745-3D204D915473}", "MyFolder1", + (new RawText[] { ".gnt\\gnt.core" }).AsEnumerable() + ); + Assert.AreEqual + ( + new SolutionFolder() + { + header = new ProjectItem() + { + name = "MyFolder1", + EpType = ProjectType.SlnFolder, + pType = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", + pGuid = "{EE7DD6B7-56F4-478D-8745-3D204D915473}", + path = f.header.path, + fullPath = f.header.fullPath, + }, + + items = new List() + { + ".gnt\\gnt.core" + } + }, + f + ); + Assert.AreEqual(1, f.items.Count()); + Assert.AreEqual((RawText)".gnt\\gnt.core", f.items.ElementAt(0)); + } + + [TestMethod] + public void CtorTest7() + { + var f0 = new SolutionFolder("dir1"); + + var f = new SolutionFolder + ( + "{EE7DD6B7-56F4-478D-8745-3D204D915473}", "MyFolder4", f0, + (new RawText[] { ".gnt\\gnt.core" }).AsEnumerable() + ); + Assert.AreEqual + ( + new SolutionFolder() + { + header = new ProjectItem() + { + name = "MyFolder4", + EpType = ProjectType.SlnFolder, + pType = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", + pGuid = "{EE7DD6B7-56F4-478D-8745-3D204D915473}", + parent = f0, + path = f.header.path, + fullPath = f.header.fullPath, + }, + + items = new List() + { + ".gnt\\gnt.core" + } + }, + f + ); + Assert.AreEqual(1, f.items.Count()); + Assert.AreEqual((RawText)".gnt\\gnt.core", f.items.ElementAt(0)); + + + f = new SolutionFolder + ( + "{EE7DD6B7-56F4-478D-8745-3D204D915473}", "MyFolder1", f0, + ".gnt\\gnt.core", ".gnt\\packages.config" + ); + Assert.AreEqual + ( + new SolutionFolder() + { + header = new ProjectItem() + { + name = "MyFolder1", + EpType = ProjectType.SlnFolder, + pType = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", + pGuid = "{EE7DD6B7-56F4-478D-8745-3D204D915473}", + parent = f0, + path = f.header.path, + fullPath = f.header.fullPath, + }, + + items = new List() + { + ".gnt\\gnt.core", ".gnt\\packages.config" + } + }, + f + ); + Assert.AreEqual(2, f.items.Count()); + Assert.AreEqual((RawText)".gnt\\gnt.core", f.items.ElementAt(0)); + Assert.AreEqual((RawText)".gnt\\packages.config", f.items.ElementAt(1)); + + + f = new SolutionFolder("{EE7DD6B7-56F4-478D-8745-3D204D915473}", "MyFolder2", f0, ".gnt\\gnt.core"); + Assert.AreEqual + ( + new SolutionFolder() + { + header = new ProjectItem() + { + name = "MyFolder2", + EpType = ProjectType.SlnFolder, + pType = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", + pGuid = "{EE7DD6B7-56F4-478D-8745-3D204D915473}", + parent = f0, + path = f.header.path, + fullPath = f.header.fullPath, + }, + + items = new List() + { + ".gnt\\gnt.core" + } + }, + f + ); + Assert.AreEqual(1, f.items.Count()); + Assert.AreEqual((RawText)".gnt\\gnt.core", f.items.ElementAt(0)); + + + f = new SolutionFolder("{5D5C7878-22BE-4E5B-BD96-6CBBAC614AD3}", "MyFolder3", f0); + Assert.AreEqual + ( + new SolutionFolder() + { + header = new ProjectItem() + { + name = "MyFolder3", + EpType = ProjectType.SlnFolder, + pType = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", + pGuid = "{5D5C7878-22BE-4E5B-BD96-6CBBAC614AD3}", + parent = f0, + path = f.header.path, + fullPath = f.header.fullPath, + }, + items = new List() { } + }, + f + ); + Assert.AreEqual(0, f.items.Count()); + } + + [TestMethod] + public void CtorTest8() + { + Guid guid = new Guid("{8B05CE1C-999E-460D-80FF-E44DFEC019E7}"); + + var f = new SolutionFolder(guid, "dir1"); + Assert.AreEqual + ( + new SolutionFolder() + { + header = new ProjectItem() + { + name = "dir1", + EpType = ProjectType.SlnFolder, + pType = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", + pGuid = f.header.pGuid, + path = f.header.path, + fullPath = f.header.fullPath, + }, + items = new List() { } + }, + f + ); + Assert.AreEqual(0, f.items.Count()); + + + f = new SolutionFolder("{8B05CE1C-999E-460D-80FF-E44DFEC019E7}", "dir2", null); + Assert.AreEqual + ( + new SolutionFolder() + { + header = new ProjectItem() + { + name = "dir2", + EpType = ProjectType.SlnFolder, + pType = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", + pGuid = "{8B05CE1C-999E-460D-80FF-E44DFEC019E7}", + path = f.header.path, + fullPath = f.header.fullPath, + }, + items = new List() { } + }, + f + ); + Assert.AreEqual(0, f.items.Count()); + } + } +} diff --git a/MvsSlnTest/Extensions/StringExtensionTest.cs b/MvsSlnTest/Extensions/StringExtensionTest.cs index 9510d5e..15863cc 100644 --- a/MvsSlnTest/Extensions/StringExtensionTest.cs +++ b/MvsSlnTest/Extensions/StringExtensionTest.cs @@ -19,6 +19,27 @@ public void GuidTest1() Assert.AreEqual(new Guid("{d98c1dd4-008f-04b2-e980-0998ecf8427e}"), ((string)null).Guid()); } + [TestMethod] + public void GuidSlnFormatTest1() + { + Assert.AreEqual + ( + "{D98C1DD4-008F-04B2-E980-0998ECF8427E}", + new Guid("{d98c1dd4-008f-04b2-e980-0998ecf8427e}").SlnFormat() + ); + } + + [TestMethod] + public void ReformatSlnGuidTest1() + { + Assert.AreEqual("{D98C1DD4-008F-04B2-E980-0998ECF8427E}", "".ReformatSlnGuid()); + Assert.AreEqual("{D98C1DD4-008F-04B2-E980-0998ECF8427E}", " ".ReformatSlnGuid()); + Assert.AreEqual(null, ((string)null).ReformatSlnGuid()); + Assert.AreEqual("{842DDBFE-FECA-8620-2CB4-399751A8A7E3}", "invalid".ReformatSlnGuid()); + Assert.AreEqual("{DCE5BB88-7640-4CFB-861D-6CBAA1F6EF0E}", "dce5bb88-7640-4cfb-861d-6cbaa1f6ef0e".ReformatSlnGuid()); + Assert.AreEqual("{D98C1DD4-008F-04B2-E980-0998ECF8427E}", "{d98c1dd4-008f-04b2-e980-0998ecf8427e}".ReformatSlnGuid()); + } + [TestMethod] public void DirectoryPathFormatTest1() { diff --git a/MvsSlnTest/MvsSlnTest.csproj b/MvsSlnTest/MvsSlnTest.csproj index de88bb8..0eb62f7 100644 --- a/MvsSlnTest/MvsSlnTest.csproj +++ b/MvsSlnTest/MvsSlnTest.csproj @@ -64,6 +64,7 @@ + diff --git a/Readme.md b/Readme.md index 6ab469a..de2cae5 100644 --- a/Readme.md +++ b/Readme.md @@ -10,6 +10,10 @@ It was part of the [vsSolutionBuildEvent](https://github.com/3F/vsSolutionBuildE [![release-src](https://img.shields.io/github/release/3F/MvsSln.svg)](https://github.com/3F/MvsSln/releases/latest) [![License](https://img.shields.io/badge/License-MIT-74A5C2.svg)](https://github.com/3F/MvsSln/blob/master/License.txt) [![NuGet package](https://img.shields.io/nuget/v/MvsSln.svg)](https://www.nuget.org/packages/MvsSln/) +[![Tests](https://img.shields.io/appveyor/tests/3Fs/mvssln/master.svg)](https://ci.appveyor.com/project/3Fs/mvssln/build/tests) + +[![Build history](https://buildstats.info/appveyor/chart/3Fs/mvssln?buildCount=20&includeBuildsFromPullRequest=true&showStats=true)](https://ci.appveyor.com/project/3Fs/mvssln/history) + **Download:** [/releases](https://github.com/3F/MvsSln/releases) [ **[latest](https://github.com/3F/MvsSln/releases/latest)** ] @@ -78,6 +82,44 @@ using(var sln = new Sln(@"D:\projects\Conari\Conari.sln", SlnItems.All &~ SlnIte } // release all loaded projects ``` +Easy to create/modify/or just use parsed folders, projects, and other. + +Safely compare anything: + +```csharp +if(new ProjectItem(...) == new ProjectItem(...)) { ... } +if(new SolutionFolder(...) == new SolutionFolder(...)) { ... } +if(new RawText(...) == new RawText(...)) { ... } +if(new ConfigItem(...) == new ConfigItem(...)) { ... } +if((RawText)"data" == (RawText)"data") { ... } +```` + + +Use Subdirectories: + +```csharp +new SolutionFolder("dir1", + new SolutionFolder("dir2", + new SolutionFolder("dir3", "hMSBuild.bat", "DllExport.bat") + ) +); +... +new SolutionFolder("{EE7DD6B7-56F4-478D-8745-3D204D915473}", "MyFolder2", dir1, ".gnt\\gnt.core"); +... +``` + +Projects and Folders: + +```csharp +new ProjectItem("Project1", ProjectType.Cs); +new ProjectItem("Project1", ProjectType.Cs, new SolutionFolder("dir1")); +new ProjectItem("Project2", ProjectType.Vc, "path 1"); +new ProjectItem("{EE7DD6B7-56F4-478D-8745-3D204D915473}", "Project1", ProjectType.Cs, dir2); +... +``` + +See related unit tests. + By the way, the any new solution handler (reader or writer) can be easily added by our flexible architecture. *See below.* Control anything and have fun ! @@ -167,7 +209,7 @@ Release_net45|Any CPU Release|Any CPU ``` -The all available configurations for each projects should be 8 * 8 = 64, i.e. 64 instances that can be loaded as each different projects. `EnvWithProjects` will load all available projects and you finally should see 64 different instances, as for vsSolutionBuildEvent above. +Maximum possible configurations for each projects above should be calculated as 8 * 8 = 64, ie. 64 instances that *can be* loaded as each different project. `EnvWithProjects` will try load all available, but in fact, mostly 2 or more project-configuration can be related to the same 1 solution-configuration, therefore it can be just 30 or even 20 in reality, and so on. However, if you only need to work with common data of selected project: you just need to use any available configuration. To load projects only with specific configuration, use for example `IEnvironment.LoadProjects`: @@ -185,7 +227,7 @@ using(var sln = new Sln(@"vsSolutionBuildEvent.sln", SlnItems.Env)) } ``` -With latest version should be also available `IEnvironment.LoadMinimalProjects` or `EnvWithMinimalProjects` flag. +**With latest version** should be also available `IEnvironment.LoadMinimalProjects` or `EnvWithMinimalProjects` flag. ### Adding Reference & Assembly name