From ff2b573d68881237f956643a32a8bb48d323cb43 Mon Sep 17 00:00:00 2001 From: Maria Chervenkova <72970885+MariaDch@users.noreply.github.com> Date: Tue, 3 Dec 2024 15:21:43 +0200 Subject: [PATCH] merge develop into master (#224) * Use common signing (#208) o closes telerik/MATTeam#710 * Support for .NET Standard 2.1 (#209) o converted JustMock project .NET Core App 2.0 target to .NET Standard 2.1 o removed JustMock project .NET Framework 4.5.0 target o re-target all JustMock dependent projects to .NET Framework 4.7.2 * Raise Async Event causes Method Signature Error (#211) * Raise Async Event causes Method Signature Error o closes #745 * Raise Async Event causes Method Signature Error o applied review comments * Support for .NET 9 preview 6 (#212) o fixed ref returns interception * Fix the vulnerable transitive dependency to System.Security.Permissions 5.0.0 (#213) o closes telerik/MATTeam#753 * fix: Implement methods for automocking #759 - Implement Arrange and ReturnsAsync methods for Task; - Implement Arrange method for ValueTask; * fix: Add tests for automocking - Add test for Arrange an ReturnsAsync; * chore: Change copyright information * chore: Replace tabs with spaces (#216) * chore: Replace tabs with spaces - Closes #782 * fix: Broken symbols --------- Co-authored-by: Maria Chervenkova * fix: Set NEWOBJ_INTERCEPTION_ON_OVERWRITE var to be disabled by default (#217) Co-authored-by: Maria Chervenkova * Fix .NET versions in the readme files (#218) * fix: Create tests for Mock.Reset (#220) * fix: Create tests for Mock.Reset * fix: SonarQube scanner findings - Refactor test code to remove copy-paste --------- Co-authored-by: Maria Chervenkova * Update license files (#221) * Update license files (#222) * Update license files (#223) o replace the link --------- Co-authored-by: Ivo Stoilov Co-authored-by: Maria Chervenkova --- LICENSE | 12 +- README.md | 6 + Telerik.JustMock.Tests/MockResetFixture.cs | 120 ++++++++++++++++++ .../Telerik.JustMock.Tests.projitems | 1 + 4 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 Telerik.JustMock.Tests/MockResetFixture.cs diff --git a/LICENSE b/LICENSE index 39352dbf..3203649c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,3 +1,12 @@ + Packaged distributions of JustMock Lite obtained from NuGet are made + available pursuant to the ProgressĀ® TelerikĀ® JustMock EULA at + https://www.telerik.com/purchase/license-agreements, unless you have + entered into a separate software license agreement with the licensor + that covers JustMock Lite. + + Source code obtained from the Progress Telerik JustMock Lite GitHub + repository is made available under Apache-2.0, a copy of which is + included below. Apache License Version 2.0, January 2004 @@ -187,7 +196,8 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2010-2018 Telerik EAD + Copyright 2010-2024 Progress Software Corporation and/or its subsidiaries + or affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index 0ead3b22..3b9c326c 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,12 @@ JustMock - **Mock Microsoft EntityFramework** - Allows you to easily create in-memory mocks of the DbSet and DbContext types. - And many more +### Licensing + +Packaged distributions of Progress Telerik JustMock Lite obtained from NuGet are made available pursuant to the Progress Telerik JustMock EULA at https://www.telerik.com/purchase/license-agreements, unless you have entered into a separate MSA with the licensor. + +Source code obtained from the Progress Telerik JustMock Lite GitHub repository is made available under Apache-2.0. + ### Examples ```csharp diff --git a/Telerik.JustMock.Tests/MockResetFixture.cs b/Telerik.JustMock.Tests/MockResetFixture.cs new file mode 100644 index 00000000..09460544 --- /dev/null +++ b/Telerik.JustMock.Tests/MockResetFixture.cs @@ -0,0 +1,120 @@ +using System; +using System.Threading; +using System.Threading.Tasks; + +#region JustMock Test Attributes +#if NUNIT +using NUnit.Framework; +using TestCategory = NUnit.Framework.CategoryAttribute; +using TestClass = NUnit.Framework.TestFixtureAttribute; +using TestMethod = NUnit.Framework.TestAttribute; +using TestInitialize = NUnit.Framework.SetUpAttribute; +using TestCleanup = NUnit.Framework.TearDownAttribute; +using AssertionException = NUnit.Framework.AssertionException; +#if NUNIT3 +using ClassInitialize = NUnit.Framework.OneTimeSetUpAttribute; +using ClassCleanup = NUnit.Framework.OneTimeTearDownAttribute; +#endif +#elif XUNIT +using Xunit; +using Telerik.JustMock.XUnit.Test.Attributes; +using TestCategory = Telerik.JustMock.XUnit.Test.Attributes.XUnitCategoryAttribute; +using TestClass = Telerik.JustMock.XUnit.Test.Attributes.EmptyTestClassAttribute; +using TestMethod = Xunit.FactAttribute; +using TestInitialize = Telerik.JustMock.XUnit.Test.Attributes.EmptyTestInitializeAttribute; +using TestCleanup = Telerik.JustMock.XUnit.Test.Attributes.EmptyTestCleanupAttribute; +using AssertionException = Telerik.JustMock.XUnit.AssertFailedException; +#elif VSTEST_PORTABLE +using Microsoft.VisualStudio.TestPlatform.UnitTestFramework; +using AssertionException = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.AssertFailedException; +#else +using Microsoft.VisualStudio.TestTools.UnitTesting; +using AssertionException = Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException; +#endif +#endregion + +namespace Telerik.JustMock.Tests +{ + [TestClass] + public class MockResetFixture + { +#if NUNIT3 + private static Foo staticFoo; + [ClassInitialize] + public static void ClassInitialize() + { + staticFoo = Mock.Create(); + Mock.Arrange(() => staticFoo.FooNotImplemented()); + } + + [ClassCleanup] + public static void ClassCleanup() + { + Mock.Reset(); + Assert.Throws(() => staticFoo.FooNotImplemented()); + } +#elif !NUNIT && !XUNIT + private static Foo staticFoo; + [ClassInitialize] + public static void ClassInitialize(TestContext ctx){ + staticFoo = Mock.Create(); + Mock.Arrange(() => staticFoo.FooNotImplemented()); + } + + [ClassCleanup] + public static void ClassCleanup() + { + Mock.Reset(); + Assert.Throws(() => staticFoo.FooNotImplemented()); + } + +#endif + private Foo myFoo; + [TestInitialize] + public void TestInit() + { + myFoo = Mock.Create(); + Mock.Arrange(() => myFoo.FooNotImplemented()); + } + + [TestCleanup] + public void TestCleanup() + { + Mock.Reset(); + Assert.Throws(() => myFoo.FooNotImplemented()); + } + + [TestMethod] + public void ThrowNotImplementedAfterMockReset() + { + // Arrange + var myFoo = Mock.Create(); + + // Act + Mock.Reset(); + + // Assert + Assert.Throws(() => myFoo.FooNotImplemented()); + } + + [TestMethod] + public void DoNotThrowErrorWithMockReset() + { + // Act + Mock.Reset(); + + // Assert + myFoo.FooNotImplemented(); + + } + + class Foo + { + public void FooNotImplemented() + { + throw new NotImplementedException(); + } + } + + } +} diff --git a/Telerik.JustMock.Tests/Telerik.JustMock.Tests.projitems b/Telerik.JustMock.Tests/Telerik.JustMock.Tests.projitems index 69b424c9..5c9bf993 100644 --- a/Telerik.JustMock.Tests/Telerik.JustMock.Tests.projitems +++ b/Telerik.JustMock.Tests/Telerik.JustMock.Tests.projitems @@ -47,6 +47,7 @@ +