From b580681f0c0a56cc0667087dc262d3e0fe852172 Mon Sep 17 00:00:00 2001 From: Ann Date: Sat, 14 Apr 2018 10:02:41 +0300 Subject: [PATCH 1/6] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B5=D0=BA=D1=82=20Gura?= =?UTF-8?q?d=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=BA=D0=B8=20=D1=83=D1=81=D0=BB=D0=BE=D0=B2=D0=B8=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AssemblyInfo.General.cs | 2 +- GraphLabs.Guard/GraphLabs.Guard.csproj | 64 +++++++++ GraphLabs.Guard/Guard.cs | 146 +++++++++++++++++++++ GraphLabs.Guard/Properties/AssemblyInfo.cs | 18 +++ GraphLabs.Site.sln | 19 +++ 5 files changed, 248 insertions(+), 1 deletion(-) create mode 100644 GraphLabs.Guard/GraphLabs.Guard.csproj create mode 100644 GraphLabs.Guard/Guard.cs create mode 100644 GraphLabs.Guard/Properties/AssemblyInfo.cs diff --git a/AssemblyInfo.General.cs b/AssemblyInfo.General.cs index 22c996d..3dc431f 100644 --- a/AssemblyInfo.General.cs +++ b/AssemblyInfo.General.cs @@ -3,5 +3,5 @@ [assembly: AssemblyCompany("Национальный Исследовательский Ядерный Университет МИФИ")] [assembly: AssemblyProduct("GraphLabs")] -[assembly: AssemblyCopyright("Copyright © 2012-2016")] +[assembly: AssemblyCopyright("Copyright © 2012-2018")] [assembly: AssemblyTrademark("")] \ No newline at end of file diff --git a/GraphLabs.Guard/GraphLabs.Guard.csproj b/GraphLabs.Guard/GraphLabs.Guard.csproj new file mode 100644 index 0000000..624f772 --- /dev/null +++ b/GraphLabs.Guard/GraphLabs.Guard.csproj @@ -0,0 +1,64 @@ + + + + + Debug + AnyCPU + {D0A05AEF-DC7E-4B2B-A82A-9A23EAA0AF95} + Library + Properties + GraphLabs.Guard + GraphLabs.Guard + v4.5.2 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + Properties\AssemblyInfo.General.cs + + + Properties\AssemblyVersion.cs + + + + + + + cd "$(SolutionDir)" +powershell "& ""$(SolutionDir)\generateVersionInfo.ps1""" + + + \ No newline at end of file diff --git a/GraphLabs.Guard/Guard.cs b/GraphLabs.Guard/Guard.cs new file mode 100644 index 0000000..59e8fd8 --- /dev/null +++ b/GraphLabs.Guard/Guard.cs @@ -0,0 +1,146 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GraphLabs.Guard +{ + public static class Guard + { + + private sealed class ContractException : Exception + { + public ContractException(string description, string nameOfMethod) : base(FormatErrorMessage(description, nameofMethod)) { } + + private static string FormatErrorMessage(string description, string nameOfMethod) + { + return ($"{description} in method {nameOfMethod}."); + } + } + + [Conditional("DEBUG")] + public static void IsNotNull( + string nameOfMethod, + T argument) + where T : class + { + if (argument == null) + { + throw new ContractException("Argument shoud be not null ", nameOfMethod); + } + } + + //Resharper.Annotations + [Conditional("DEBUG")] + public static void AreAssignedTypes( + string nameOfMethod, + Type defaultType, + Type type + ) + { + if (!typeof(defaultType).IsAssignableFrom(type)) + { + throw new ContractException("Specified type can not be assigned to the current type ", nameOfMethod); + } + } + + [Conditional("DEBUG")] + public static void AreEqualTypes( + string nameOfMethod, + Type defaultType, + Type type + ) + { + if (!typeof(defaultType).IsAssignableFrom(type)) + { + throw new ContractException("Specified type is not equal to the current type ", nameOfMethod); + } + } + + [Conditional("DEBUG")] + public static void IsNotWhiteSpace( + string nameOfMethod, + string argument) + { + if (string.IsNullOrWhiteSpace(argument)) + { + throw new ContractException("String should not be null or white space ", nameOfMethod); + } + } + + [Conditional("DEBUG")] + public static void IsPositiveLong( + string nameOfMethod, + long num) + { + if (num <= 0) + { + throw new ContractException("Long must be positive ", nameOfMethod); + } + } + + [Conditional("DEBUG")] + public static void IsPositiveInt( + string nameOfMethod, + int num) + { + if (num <= 0) + { + throw new ContractException("Int must be positive ", nameOfMethod); + } + } + + [Conditional("DEBUG")] + public static void ComparingDates( + string nameOfMethod, + DateTime newDate, + DateTime currentDate + ) + { + if (newDate < currentDate) + { + throw new ContractException("New date should be greater than current date ", nameOfMethod); + } + } + + + [Conditional("DEBUG")] + public static void IsCorrectIP( + string nameOfMethod, + string ip) + { + if (!IpHelper.CheckIsValidIP(ip)) + { + throw new ContractException("The current ip is not correct ", nameOfMethod; + } + } + + [Conditional("DEBUG")] + public static void IsNotEmpty( // и для строки + string nameOfMethod, + T argument) + { + if (argument == T.Empty) + { + throw new ContractException("Argumen shoud not be empty ", nameOfMethod); + } + } + + //roles.Any() используется только один раз + + + + + + + + + + + + + } + +} diff --git a/GraphLabs.Guard/Properties/AssemblyInfo.cs b/GraphLabs.Guard/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..efbb2f2 --- /dev/null +++ b/GraphLabs.Guard/Properties/AssemblyInfo.cs @@ -0,0 +1,18 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("GraphLabs.Guard")] +[assembly: AssemblyDescription("Утилиты для проверки утверждений.")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("d0a05aef-dc7e-4b2b-a82a-9a23eaa0af95")] diff --git a/GraphLabs.Site.sln b/GraphLabs.Site.sln index 998866c..97e347b 100644 --- a/GraphLabs.Site.sln +++ b/GraphLabs.Site.sln @@ -41,6 +41,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphLabs.Tests.Site", "Gra EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphLabs.Tests.Site.Models", "GraphLabs.Tests.Site.Models\GraphLabs.Tests.Site.Models.csproj", "{47FC998C-4129-4D8B-A5DC-12D1288C788C}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphLabs.Guard", "GraphLabs.Guard\GraphLabs.Guard.csproj", "{D0A05AEF-DC7E-4B2B-A82A-9A23EAA0AF95}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -277,6 +279,22 @@ Global {47FC998C-4129-4D8B-A5DC-12D1288C788C}.Release|x64.Build.0 = Release|Any CPU {47FC998C-4129-4D8B-A5DC-12D1288C788C}.Release|x86.ActiveCfg = Release|Any CPU {47FC998C-4129-4D8B-A5DC-12D1288C788C}.Release|x86.Build.0 = Release|Any CPU + {D0A05AEF-DC7E-4B2B-A82A-9A23EAA0AF95}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D0A05AEF-DC7E-4B2B-A82A-9A23EAA0AF95}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D0A05AEF-DC7E-4B2B-A82A-9A23EAA0AF95}.Debug|ARM.ActiveCfg = Debug|Any CPU + {D0A05AEF-DC7E-4B2B-A82A-9A23EAA0AF95}.Debug|ARM.Build.0 = Debug|Any CPU + {D0A05AEF-DC7E-4B2B-A82A-9A23EAA0AF95}.Debug|x64.ActiveCfg = Debug|Any CPU + {D0A05AEF-DC7E-4B2B-A82A-9A23EAA0AF95}.Debug|x64.Build.0 = Debug|Any CPU + {D0A05AEF-DC7E-4B2B-A82A-9A23EAA0AF95}.Debug|x86.ActiveCfg = Debug|Any CPU + {D0A05AEF-DC7E-4B2B-A82A-9A23EAA0AF95}.Debug|x86.Build.0 = Debug|Any CPU + {D0A05AEF-DC7E-4B2B-A82A-9A23EAA0AF95}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D0A05AEF-DC7E-4B2B-A82A-9A23EAA0AF95}.Release|Any CPU.Build.0 = Release|Any CPU + {D0A05AEF-DC7E-4B2B-A82A-9A23EAA0AF95}.Release|ARM.ActiveCfg = Release|Any CPU + {D0A05AEF-DC7E-4B2B-A82A-9A23EAA0AF95}.Release|ARM.Build.0 = Release|Any CPU + {D0A05AEF-DC7E-4B2B-A82A-9A23EAA0AF95}.Release|x64.ActiveCfg = Release|Any CPU + {D0A05AEF-DC7E-4B2B-A82A-9A23EAA0AF95}.Release|x64.Build.0 = Release|Any CPU + {D0A05AEF-DC7E-4B2B-A82A-9A23EAA0AF95}.Release|x86.ActiveCfg = Release|Any CPU + {D0A05AEF-DC7E-4B2B-A82A-9A23EAA0AF95}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -290,5 +308,6 @@ Global {406B1579-80A6-4C94-AC1D-3DAD87A12404} = {B67F78D5-C980-4F1E-8AD0-DD98594D2530} {7B12EB52-6778-405C-A644-48ACDC750296} = {4E833B0F-C7CB-425C-913D-13ED833B9F5A} {47FC998C-4129-4D8B-A5DC-12D1288C788C} = {4E833B0F-C7CB-425C-913D-13ED833B9F5A} + {D0A05AEF-DC7E-4B2B-A82A-9A23EAA0AF95} = {B67F78D5-C980-4F1E-8AD0-DD98594D2530} EndGlobalSection EndGlobal From 46200e6de6cfcb1137c2b94943b272aa5cf9b5f2 Mon Sep 17 00:00:00 2001 From: Ann Date: Sat, 28 Apr 2018 17:23:09 +0300 Subject: [PATCH 2/6] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=81=D0=B2=D0=B5=D0=B4=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B9=20=D0=BE=20=D0=B2=D1=8B=D0=B7=D1=8B=D0=B2=D0=B0=D1=8E?= =?UTF-8?q?=D1=89=D0=B5=D0=BC=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GraphLabs.Guard/ClassDiagram1.cd | 2 + GraphLabs.Guard/GraphLabs.Guard.csproj | 348 +++++++++++++++++++++++++ GraphLabs.Guard/Guard.cs | 136 +++++----- GraphLabs.Guard/packages.config | 77 ++++++ 4 files changed, 498 insertions(+), 65 deletions(-) create mode 100644 GraphLabs.Guard/ClassDiagram1.cd create mode 100644 GraphLabs.Guard/packages.config diff --git a/GraphLabs.Guard/ClassDiagram1.cd b/GraphLabs.Guard/ClassDiagram1.cd new file mode 100644 index 0000000..7b89419 --- /dev/null +++ b/GraphLabs.Guard/ClassDiagram1.cd @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/GraphLabs.Guard/GraphLabs.Guard.csproj b/GraphLabs.Guard/GraphLabs.Guard.csproj index 624f772..f4ba69f 100644 --- a/GraphLabs.Guard/GraphLabs.Guard.csproj +++ b/GraphLabs.Guard/GraphLabs.Guard.csproj @@ -1,5 +1,33 @@  + + + + + + + + + + + + + + + + + + + + + + + + + + + + Debug @@ -11,6 +39,8 @@ GraphLabs.Guard v4.5.2 512 + + true @@ -30,14 +60,237 @@ 4 + + ..\packages\Antlr2.Runtime.2.7.7.02\lib\antlr.runtime.dll + True + + + ..\packages\Appccelerate.StateMachine.3.3.0\lib\netstandard1.0\Appccelerate.StateMachine.dll + True + + + ..\packages\xmlrpcnet.2.5.0\lib\net20\CookComputing.XmlRpcV2.dll + True + + + ..\packages\JetBrains.Platform.Lib.DevExpress.2.0.20170610\lib\net20\DevExpress.Data.v7.1.dll + True + + + ..\packages\JetBrains.Platform.Lib.DevExpress.2.0.20170610\lib\net20\DevExpress.Utils.v7.1.dll + True + + + ..\packages\JetBrains.Platform.Lib.DevExpress.2.0.20170610\lib\net20\DevExpress.XtraEditors.v7.1.dll + True + + + ..\packages\JetBrains.Platform.Lib.DevExpress.2.0.20170610\lib\net20\DevExpress.XtraTreeList.v7.1.dll + True + + + ..\packages\DotNetZip.1.10.1\lib\net20\DotNetZip.dll + True + + + ..\packages\JetBrains.SharpZipLib.Stripped.0.87.20170720.14\lib\net40\ICSharpCode.SharpZipLib.dll + True + + + ..\packages\JetBrains.Annotations.11.1.0\lib\net20\JetBrains.Annotations.dll + True + + + ..\packages\JetBrains.Platform.MSBuild.Logger.Api.1.0.20170809\lib\net\JetBrains.MSBuild.Logger.Api.dll + True + + + ..\packages\JetBrains.System.Reflection.Metadata.20170417.0.0.0\lib\net45\JetBrains.System.Reflection.Metadata.dll + True + + + ..\packages\JetBrains.Toolset.ScriptSourcesCompiler.Interface.1.0.20170420.0\lib\net\JetBrains.Toolset.ScriptSourcesCompiler.Interface.dll + True + + + ..\packages\JetBrains.MahApps.Metro.1.5.0.1\lib\net45\MahApps.Metro.dll + True + + + + ..\packages\JetBrains.Microsoft.Deployment.Compression.Cab.3.11.0\lib\net20\Microsoft.Deployment.Compression.dll + True + + + ..\packages\JetBrains.Microsoft.Deployment.Compression.Cab.3.11.0\lib\net20\Microsoft.Deployment.Compression.Cab.dll + True + + + ..\packages\Microsoft.Owin.3.0.1\lib\net45\Microsoft.Owin.dll + True + + + ..\packages\Microsoft.Owin.FileSystems.3.0.1\lib\net45\Microsoft.Owin.FileSystems.dll + True + + + ..\packages\Microsoft.Owin.Host.HttpListener.3.0.1\lib\net45\Microsoft.Owin.Host.HttpListener.dll + True + + + ..\packages\Microsoft.Owin.Hosting.3.0.1\lib\net45\Microsoft.Owin.Hosting.dll + True + + + ..\packages\Microsoft.Owin.StaticFiles.3.0.1\lib\net45\Microsoft.Owin.StaticFiles.dll + True + + + ..\packages\JetBrains.Platform.Lib.VisualStudio.AnyVs.ShellInterop.PrivateBuild.2.0.20141005.1\lib\net20\Microsoft.VisualStudio.Shell.Interop.dll + True + + + ..\packages\Microsoft.Web.Xdt.2.1.1\lib\net40\Microsoft.Web.XmlTransform.dll + True + + + ..\packages\Windows7APICodePack.JetBrains.Stripped.1.1.20150225.0\lib\Net\Microsoft.WindowsAPICodePack.dll + True + + + ..\packages\Windows7APICodePack.JetBrains.Stripped.1.1.20150225.0\lib\Net\Microsoft.WindowsAPICodePack.Shell.dll + True + + + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll + True + + + ..\packages\JetBrains.NuGet.Ultimate.4.5.0.20180215\lib\net45\NuGet.Commands.dll + True + + + ..\packages\JetBrains.NuGet.Ultimate.4.5.0.20180215\lib\net45\NuGet.Common.dll + True + + + ..\packages\JetBrains.NuGet.Ultimate.4.5.0.20180215\lib\net45\NuGet.Configuration.dll + True + + + ..\packages\JetBrains.NuGet.Core.2.14.1.20180215\lib\net40-Client\NuGet.Core.dll + True + + + ..\packages\JetBrains.NuGet.Ultimate.4.5.0.20180215\lib\net45\NuGet.DependencyResolver.Core.dll + True + + + ..\packages\JetBrains.NuGet.Frameworks.4.5.0.20180215\lib\net45\NuGet.Frameworks.dll + True + + + ..\packages\JetBrains.NuGet.Ultimate.4.5.0.20180215\lib\net45\NuGet.LibraryModel.dll + True + + + ..\packages\JetBrains.NuGet.Ultimate.4.5.0.20180215\lib\net45\NuGet.PackageManagement.dll + True + + + ..\packages\JetBrains.NuGet.Ultimate.4.5.0.20180215\lib\net45\NuGet.Packaging.dll + True + + + ..\packages\JetBrains.NuGet.Ultimate.4.5.0.20180215\lib\net45\NuGet.Packaging.Core.dll + True + + + ..\packages\JetBrains.NuGet.Ultimate.4.5.0.20180215\lib\net45\NuGet.ProjectModel.dll + True + + + ..\packages\JetBrains.NuGet.Ultimate.4.5.0.20180215\lib\net45\NuGet.Protocol.dll + True + + + ..\packages\JetBrains.NuGet.Ultimate.4.5.0.20180215\lib\net45\NuGet.Resolver.dll + True + + + ..\packages\JetBrains.NuGet.Versioning.4.5.0.20180215\lib\net45\NuGet.Versioning.dll + True + + + ..\packages\NUnit.2.6.4\lib\nunit.framework.dll + True + + + ..\packages\NVelocity.1.0.3\lib\NVelocity.dll + True + + + ..\packages\Owin.1.0\lib\net40\Owin.dll + True + + + ..\packages\sharpcompress.0.11.6\lib\net40\SharpCompress.dll + True + + + ..\packages\JetBrains.Should.1.1.20\lib\Should.dll + True + + + ..\packages\Sprache.JetBrains.2.1.0\lib\net40\Sprache.dll + True + + + + + + + + + ..\packages\System.ValueTuple.4.4.0\lib\netstandard1.0\System.ValueTuple.dll + True + + + ..\packages\JetBrains.System.Windows.Interactivity.3.0.40218.0\lib\net45\System.Windows.Interactivity.dll + True + + + ..\packages\Vestris.ResourceLib.JetBrains.1.4.20150303.0\lib\Net\Vestris.ResourceLib.dll + True + + + ..\packages\JetBrains.Platform.Lib.WpfContrib.2.0.20170610\lib\net20\WpfContrib.dll + True + + + ..\packages\xunit.JetBrains.1.9.2\lib\net20\xunit.dll + True + + + ..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll + True + + + ..\packages\xunit.runner.utility.2.3.1\lib\net452\xunit.runner.utility.net452.dll + True + + + ..\packages\YamlDotNet.Signed.4.2.1\lib\net35\YamlDotNet.dll + True + @@ -49,11 +302,106 @@ + + + + cd "$(SolutionDir)" powershell "& ""$(SolutionDir)\generateVersionInfo.ps1""" + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/GraphLabs.Tests.Guard/GuardTest.cs b/GraphLabs.Tests.Guard/GuardTest.cs new file mode 100644 index 0000000..1c6674b --- /dev/null +++ b/GraphLabs.Tests.Guard/GuardTest.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GraphLabs.Tests.Guard +{ + public class GuardTest + { + } +} diff --git a/GraphLabs.Tests.Guard/Properties/AssemblyInfo.cs b/GraphLabs.Tests.Guard/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..b2c20a3 --- /dev/null +++ b/GraphLabs.Tests.Guard/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("GraphLabs.Tests.Guard")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("GraphLabs.Tests.Guard")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("effc3aa3-9708-4aad-85bb-40c096614662")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/UnitTestProject1/GraphLabs.Tests.Guard.csproj b/UnitTestProject1/GraphLabs.Tests.Guard.csproj new file mode 100644 index 0000000..136e8c8 --- /dev/null +++ b/UnitTestProject1/GraphLabs.Tests.Guard.csproj @@ -0,0 +1,89 @@ + + + + Debug + AnyCPU + {D0089CEE-F5BC-45C8-84B9-448DA06F4EDE} + Library + Properties + UnitTestProject1 + UnitTestProject1 + v4.5.2 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + {d0a05aef-dc7e-4b2b-a82a-9a23eaa0af95} + GraphLabs.Guard + + + + + + + False + + + False + + + False + + + False + + + + + + + + \ No newline at end of file diff --git a/UnitTestProject1/Properties/AssemblyInfo.cs b/UnitTestProject1/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..755c33e --- /dev/null +++ b/UnitTestProject1/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("UnitTestProject1")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("UnitTestProject1")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("d0089cee-f5bc-45c8-84b9-448da06f4ede")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/UnitTestProject1/UnitTestGuard.cs b/UnitTestProject1/UnitTestGuard.cs new file mode 100644 index 0000000..8e66611 --- /dev/null +++ b/UnitTestProject1/UnitTestGuard.cs @@ -0,0 +1,203 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using GraphLabs; +using System.Collections.Generic; + +namespace UnitTestProject1 +{ + [TestClass] + public class UnitTestGuard + { + private class A { } + private class B : A { }; + private class C { }; + [TestMethod] + public void TestMethodIsNotNull() + { + List a = new List() { 1, 2, 3 }; + Guard.IsNotNull(a); + + Exception exception = null; + List b = null; + try + { + Guard.IsNotNull(b); + } + catch (Exception ex) + { + exception = ex; + } + Assert.IsNotNull(exception); + } + + [TestMethod] + public void TestAreAssignedTypes() + { + Guard.AreAssignedTypes(typeof(A), typeof(B)); + Exception exception = null; + try + { + Guard.AreAssignedTypes(typeof(B), typeof(A)); + } + catch (Exception ex) + { + exception = ex; + } + Assert.IsNotNull(exception); + + exception = null; + try + { + Guard.AreAssignedTypes(typeof(C), typeof(A)); + } + catch (Exception ex) + { + exception = ex; + } + Assert.IsNotNull(exception); + + } + + [TestMethod] + public void TestAreEqual() + { + String str1 = "a"; + String str2 = "a"; + String str3 = "b"; + + Guard.AreEqual(str1, str2, nameof(str1), nameof(str2)); + Exception exception = null; + try + { + Guard.AreEqual(str1, str3, nameof(str1), nameof(str3)); + } + catch (Exception ex) + { + exception = ex; + } + Assert.IsNotNull(exception); + } + + [TestMethod] + public void TestIsNotNullOrWhiteSpace() + { + String str1 = "a"; + String str2 = ""; + String str3 = " "; + String str4 = null; + + Guard.IsNotNullOrWhiteSpace(str1); + Exception exception = null; + try + { + Guard.IsNotNullOrWhiteSpace(str2); + } + catch (Exception ex) + { + exception = ex; + } + Assert.IsNotNull(exception); + + exception = null; + try + { + Guard.IsNotNullOrWhiteSpace(str3); + } + catch (Exception ex) + { + exception = ex; + } + Assert.IsNotNull(exception); + + exception = null; + try + { + Guard.IsNotNullOrWhiteSpace(str4); + } + catch (Exception ex) + { + exception = ex; + } + Assert.IsNotNull(exception); + + } + + [TestMethod] + public void TestIsIsPositive() + { + int intp = 5; + int intn = -1; + long longp = 10; + long longn = -3; + + Guard.IsPositive(intp, nameof(intp)); + Guard.IsPositive(longp, nameof(longp)); + + Exception exception = null; + try + { + Guard.IsPositive(intn, nameof(intn)); + } + catch (Exception ex) + { + exception = ex; + } + Assert.IsNotNull(exception); + + exception = null; + try + { + Guard.IsPositive(longn, nameof(longn)); + } + catch (Exception ex) + { + exception = ex; + } + Assert.IsNotNull(exception); + + } + + + [TestMethod] + public void TestIsNotEmpty() + { + String str1 = "a"; + String str2 = null; + String str3 = ""; + + Guard.IsNotEmpty(str1, nameof(str1)); + Guard.IsNotEmpty(str1, nameof(str1)); + + Exception exception = null; + try + { + Guard.IsNotEmpty(str3, nameof(str3)); + } + catch (Exception ex) + { + exception = ex; + } + Assert.IsNotNull(exception); + + } + + [TestMethod] + public void TestIsTrueAssertion() + { + bool a = true; + bool b = false; + + Guard.IsTrueAssertion(a); + Exception exception = null; + try + { + Guard.IsTrueAssertion(b); + } + catch (Exception ex) + { + exception = ex; + } + Assert.IsNotNull(exception); + } + } +}