Skip to content

Commit

Permalink
BookLib: rename test base class to ApplicationsTest
Browse files Browse the repository at this point in the history
  • Loading branch information
jbe2277 committed Jul 12, 2024
1 parent c232f20 commit d7b6679
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Waf.UnitTesting.Mocks;
using Waf.BookLibrary.Library.Applications.Controllers;

namespace Test.BookLibrary.Library.Applications;

[TestClass]
public abstract class TestClassBase
{
public CompositionContainer? Container { get; private set; }

[TestInitialize]
public void Initialize()
{
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(typeof(MockMessageService).Assembly));
catalog.Catalogs.Add(new AssemblyCatalog(typeof(TestClassBase).Assembly));
catalog.Catalogs.Add(new AssemblyCatalog(typeof(ModuleController).Assembly));

OnCatalogInitialize(catalog);

Container = new(catalog, CompositionOptions.DisableSilentRejection);
var batch = new CompositionBatch();
batch.AddExportedValue(Container);
Container.Compose(batch);

OnInitialize();
}

[TestCleanup]
public void Cleanup()
{
OnCleanup();
Container?.Dispose();
}

public T Get<T>() => Container!.GetExportedValue<T>();

public Lazy<T> GetLazy<T>() => new(() => Container!.GetExportedValue<T>());

protected virtual void OnCatalogInitialize(AggregateCatalog catalog) { }

protected virtual void OnInitialize() { }

protected virtual void OnCleanup() { }
}
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Waf.UnitTesting.Mocks;
using Waf.BookLibrary.Library.Applications.Controllers;

namespace Test.BookLibrary.Library.Applications;

[TestClass]
public abstract class ApplicationsTest
{
public CompositionContainer? Container { get; private set; }

[TestInitialize]
public void Initialize()
{
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(typeof(MockMessageService).Assembly));
catalog.Catalogs.Add(new AssemblyCatalog(typeof(ApplicationsTest).Assembly));
catalog.Catalogs.Add(new AssemblyCatalog(typeof(ModuleController).Assembly));

OnCatalogInitialize(catalog);

Container = new(catalog, CompositionOptions.DisableSilentRejection);
var batch = new CompositionBatch();
batch.AddExportedValue(Container);
Container.Compose(batch);

OnInitialize();
}

[TestCleanup]
public void Cleanup()
{
OnCleanup();
Container?.Dispose();
}

public T Get<T>() => Container!.GetExportedValue<T>();

public Lazy<T> GetLazy<T>() => new(() => Container!.GetExportedValue<T>());

protected virtual void OnCatalogInitialize(AggregateCatalog catalog) { }

protected virtual void OnInitialize() { }

protected virtual void OnCleanup() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Test.BookLibrary.Library.Applications.Controllers;

[TestClass]
public class BookControllerTest : TestClassBase
public class BookControllerTest : ApplicationsTest
{
protected override void OnInitialize()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace Test.BookLibrary.Library.Applications.Controllers;

[TestClass]
public class EntityControllerTest : TestClassBase
public class EntityControllerTest : ApplicationsTest
{
[TestMethod]
public void ValidateBeforeSave()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Test.BookLibrary.Library.Applications.Controllers;

[TestClass]
public class ModuleControllerTest : TestClassBase
public class ModuleControllerTest : ApplicationsTest
{
protected override void OnInitialize()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace Test.BookLibrary.Library.Applications.Controllers;

[TestClass]
public class PersonControllerTest : TestClassBase
public class PersonControllerTest : ApplicationsTest
{
protected override void OnInitialize()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[assembly: SuppressMessage("Microsoft.Design", "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable", Scope = "type", Target = "~T:Test.BookLibrary.Library.Applications.TestClassBase")]
[assembly: SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "<Pending>", Scope = "member", Target = "~M:Test.BookLibrary.Library.Applications.TestClassBase.Initialize")]
[assembly: SuppressMessage("Microsoft.Design", "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable", Scope = "type", Target = "~T:Test.BookLibrary.Library.Applications.ApplicationsTest")]
[assembly: SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "<Pending>", Scope = "member", Target = "~M:Test.BookLibrary.Library.Applications.ApplicationsTest.Initialize")]

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Test.BookLibrary.Library.Applications.ViewModels;

[TestClass]
public class LendToViewModelTest : TestClassBase
public class LendToViewModelTest : ApplicationsTest
{
protected override void OnCleanup()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Test.BookLibrary.Library.Applications.ViewModels;

[TestClass]
public class PersonListViewModelTest : TestClassBase
public class PersonListViewModelTest : ApplicationsTest
{
[TestMethod]
public void PersonListViewModelPersonsTest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Test.BookLibrary.Library.Applications.ViewModels;

[TestClass]
public class ShellViewModelTest : TestClassBase
public class ShellViewModelTest : ApplicationsTest
{
[TestMethod]
public void ShellViewModelBasicTest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Test.BookLibrary.Reporting.Applications;

[TestClass]
public class ReportingTest : TestClassBase
public class ReportingTest : ApplicationsTest
{
protected override void OnCatalogInitialize(AggregateCatalog catalog)
{
Expand Down

0 comments on commit d7b6679

Please sign in to comment.