diff --git a/CommonAssemblyInfo.cs b/CommonAssemblyInfo.cs index 0713f119..e711a2a7 100644 --- a/CommonAssemblyInfo.cs +++ b/CommonAssemblyInfo.cs @@ -29,3 +29,5 @@ limitations under the License. [assembly: AssemblyVersion("2013.3.1021.0")] [assembly: AssemblyFileVersion("2013.3.1021.0")] + +[assembly: AssemblyMetadata("BuildDate", "2013/10/21")] diff --git a/Telerik.JustMock/Core/Licensing/LicenseException.cs b/Telerik.JustMock/Core/Licensing/LicenseException.cs new file mode 100644 index 00000000..421cf1d7 --- /dev/null +++ b/Telerik.JustMock/Core/Licensing/LicenseException.cs @@ -0,0 +1,34 @@ +/* + JustMock Lite + Copyright © 2025 Progress Software Corporation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +using System; + +namespace Telerik.JustMock.Core.Licensing +{ + /// + /// The exception that is thrown in case of licensing error + /// + [Serializable] + public class LicenseException : MockException + { + public LicenseException() : base() { } + + public LicenseException(string message) : base(message) { } + + public LicenseException(string message, Exception innerException) : base(message, innerException) { } + } +} diff --git a/Telerik.JustMock/Core/Licensing/LicenseManager.cs b/Telerik.JustMock/Core/Licensing/LicenseManager.cs new file mode 100644 index 00000000..0978ece3 --- /dev/null +++ b/Telerik.JustMock/Core/Licensing/LicenseManager.cs @@ -0,0 +1,91 @@ +/* + JustMock Lite + Copyright © 2025 Progress Software Corporation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +using System; +using System.Linq; +using System.Reflection; + +namespace Telerik.JustMock.Core.Licensing +{ +#nullable enable + public static class LicenseManager + { + private const string DefaultProductName = "Telerik JustMock Lite"; + private const string DefaultProductCode = "JM"; + private const string DefaultLicenseType = "free"; + private static readonly DateTime DefaultLicenseDate = DateTime.Now; + + private static string? licenseProductName; + private static DateTime licenseDate; + + public static bool IsLicenseValid => true; + + public static bool IsLicenseKeyFileFound => false; + + public static bool IsLicenseKeyFileValid => false; + + public static string? LicenseProductName + { + get + { + if (licenseProductName == null) + { + var assemblyProductAttribute = typeof(LicenseManager).Assembly.GetCustomAttribute(typeof(AssemblyProductAttribute)) as AssemblyProductAttribute; + licenseProductName = + assemblyProductAttribute == null + ? + DefaultProductName + : + assemblyProductAttribute.Product; + } + return licenseProductName; + } + } + + public static string LicenseProductCode => DefaultProductCode; + + public static string? LicenseProductVersion => typeof(LicenseManager).Assembly.GetName().Version.ToString(); + + public static DateTime? LicenseExpiration => null; + + public static DateTime LicenseDate + { + get + { + if (licenseDate == null) + { + licenseDate = DefaultLicenseDate; + var assemblyMetadataAttributes = typeof(LicenseManager).Assembly.GetCustomAttributes().OfType(); + foreach (var assemblyMetadataAttribute in assemblyMetadataAttributes) + { + if (assemblyMetadataAttribute.Key == "BuildDate") + { + licenseDate = DateTime.Parse(assemblyMetadataAttribute.Value); + break; + } + } + } + return licenseDate; + } + } + + public static string? LicenseType => DefaultLicenseType; + + public static string Message = String.Empty; + } +#nullable disable +} diff --git a/Telerik.JustMock/Core/MocksRepository.cs b/Telerik.JustMock/Core/MocksRepository.cs index 6f03bc96..3da0cb4f 100644 --- a/Telerik.JustMock/Core/MocksRepository.cs +++ b/Telerik.JustMock/Core/MocksRepository.cs @@ -1,6 +1,6 @@ /* JustMock Lite - Copyright © 2010-2015,2018-2019,2021-2022 Progress Software Corporation + Copyright © 2010-2015,2018-2019,2021-2022,2025 Progress Software Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -31,6 +31,7 @@ limitations under the License. using Telerik.JustMock.Core.TransparentProxy; using Telerik.JustMock.Diagnostics; using Telerik.JustMock.Expectations; +using Telerik.JustMock.Core.Licensing; #if DEBUG using Telerik.JustMock.Helpers; #endif @@ -133,6 +134,11 @@ internal bool IsRetired static MocksRepository() { + if (!Licensing.LicenseManager.IsLicenseValid) + { + throw new Licensing.LicenseException(Licensing.LicenseManager.Message); + } + #if !COREFX var badApples = new[] { diff --git a/Telerik.JustMock/Core/ProfilerInterceptor.cs b/Telerik.JustMock/Core/ProfilerInterceptor.cs index a50de40b..5851329e 100644 --- a/Telerik.JustMock/Core/ProfilerInterceptor.cs +++ b/Telerik.JustMock/Core/ProfilerInterceptor.cs @@ -1,6 +1,6 @@ /* JustMock Lite - Copyright © 2010-2015,2021-2023 Progress Software Corporation + Copyright © 2010-2015,2021-2023,2025 Progress Software Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -671,16 +671,13 @@ public static void Identify() public static void ThrowElevatedMockingException(MemberInfo member = null) { - var marker = typeof(object).Assembly.GetType("Telerik.JustMock.TrialExpiredMarker"); - if (marker == null) - { - var ex = member != null ? new ElevatedMockingException(member) : new ElevatedMockingException(); - throw ex; - } - else - { - throw new Trial.JustMockExpiredException(); - } + var ex = + member != null + ? + new ElevatedMockingException(member) + : + new ElevatedMockingException(); + throw ex; } public static bool IsProfilerAttached { [DebuggerHidden] get { return bridge != null; } } diff --git a/Telerik.JustMock/Telerik.JustMock.csproj b/Telerik.JustMock/Telerik.JustMock.csproj index 7cd0d994..b3be19ab 100644 --- a/Telerik.JustMock/Telerik.JustMock.csproj +++ b/Telerik.JustMock/Telerik.JustMock.csproj @@ -14,6 +14,7 @@ {0749EBC2-4E83-4960-BF28-1FF5C2DEB2B9} Library Properties + latest $(TargetFrameworks);$(PreviewTargetFramework)