Skip to content

Commit

Permalink
WAF: MockSettingsService move to UnitTesting.Core
Browse files Browse the repository at this point in the history
  • Loading branch information
jbe2277 committed Oct 4, 2023
1 parent c992f13 commit fdf67d5
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
[assembly: SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "<Pending>", Scope = "member", Target = "~M:System.Waf.UnitTesting.UnitTestSynchronizationContext.Wait(System.Threading.Tasks.Task)")]
[assembly: SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "<Pending>", Scope = "member", Target = "~M:System.Waf.UnitTesting.UnitTestSynchronizationContext.Wait(System.TimeSpan)")]
[assembly: SuppressMessage("Maintainability", "CA1507:Use nameof to express symbol names", Justification = "<Pending>", Scope = "member", Target = "~M:System.Waf.UnitTesting.AssertHelper.GetProperty``1(System.Linq.Expressions.Expression{System.Func{``0,System.Object}})~System.Reflection.PropertyInfo")]
[assembly: SuppressMessage("Design", "CA1030:Use events where appropriate", Justification = "<Pending>", Scope = "member", Target = "~M:System.Waf.UnitTesting.Mocks.MockSettingsService.RaiseErrorOccurred(System.Waf.Applications.Services.SettingsErrorEventArgs)")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Collections.Concurrent;
using System.Waf.Applications.Services;

namespace System.Waf.UnitTesting.Mocks
{
/// <summary>Mock for the ISettingsService interface.</summary>
public class MockSettingsService : ISettingsService
{
private readonly ConcurrentDictionary<Type, Lazy<object>> services = new();

/// <summary>Gets or sets a delegate that is called when Get is called.</summary>
public Func<Type, object>? GetStub { get; set; }

/// <summary>Gets or sets a delegate that is called when Save is called.</summary>
public Action? SaveStub { get; set; }

/// <inheritdoc />
public string FileName { get; set; } = default!;

/// <inheritdoc />
public event EventHandler<SettingsErrorEventArgs>? ErrorOccurred;

/// <inheritdoc />
public T Get<T>() where T : class, new() => (T)(GetStub?.Invoke(typeof(T)) ?? services.GetOrAdd(typeof(T), new Lazy<object>(() => new T())).Value);

/// <inheritdoc />
public void Save() => SaveStub?.Invoke();

/// <summary>Raise the ErrorOccurred event.</summary>
/// <param name="e">The error event args.</param>
public void RaiseErrorOccurred(SettingsErrorEventArgs e) => ErrorOccurred?.Invoke(this, e);
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.
//
// To add a suppression to this file, right-click the message in the
// Error List, point to "Suppress Message(s)", and click
// "In Project Suppression File".
// You do not need to add suppressions to this file manually.
using System.Diagnostics.CodeAnalysis;

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "CanExecuteChanged", Scope = "member", Target = "~M:System.Waf.UnitTesting.AssertHelper.CanExecuteChangedEvent(System.Windows.Input.ICommand,System.Action)")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "PropertyChanged", Scope = "member", Target = "~M:System.Waf.UnitTesting.AssertHelper.PropertyChangedEvent``1(``0,System.Linq.Expressions.Expression{System.Func{``0,System.Object}},System.Action)")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Scope = "member", Target = "~M:System.Waf.UnitTesting.AssertHelper.ExpectedException``1(System.Action)~``0")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Scope = "member", Target = "~M:System.Waf.UnitTesting.AssertHelper.ExpectedException``1(System.Action)~``0")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Scope = "member", Target = "~M:System.Waf.UnitTesting.AssertHelper.PropertyChangedEvent``1(``0,System.Linq.Expressions.Expression{System.Func{``0,System.Object}},System.Action)")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2208:InstantiateArgumentExceptionsCorrectly", Scope = "member", Target = "~M:System.Waf.UnitTesting.AssertHelper.ThrowExpressionArgumentException")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Scope = "member", Target = "~P:System.Waf.UnitTesting.Mocks.MockMessageService.ShowQuestionAction")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes", Scope = "member", Target = "~P:System.Waf.UnitTesting.Mocks.MockDialogView`1.ShowDialogAction")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "~M:System.Waf.UnitTesting.UnitTestSynchronizationContext.Create~System.Waf.UnitTesting.UnitTestSynchronizationContext")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "~M:System.Waf.UnitTesting.UnitTestSynchronizationContext.CreateCopy~System.Threading.SynchronizationContext")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "~M:System.Waf.UnitTesting.UnitTestSynchronizationContext.Wait(System.TimeSpan)")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "CanExecuteChanged", Scope = "member", Target = "~M:System.Waf.UnitTesting.AssertHelper.CanExecuteChangedEvent(System.Windows.Input.ICommand,System.Action,System.Int32,System.Waf.UnitTesting.ExpectedChangedCountMode)")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Scope = "member", Target = "~M:System.Waf.UnitTesting.AssertHelper.PropertyChangedEvent``1(``0,System.Linq.Expressions.Expression{System.Func{``0,System.Object}},System.Action,System.Int32,System.Waf.UnitTesting.ExpectedChangedCountMode)")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "PropertyChanged", Scope = "member", Target = "~M:System.Waf.UnitTesting.AssertHelper.PropertyChangedEvent``1(``0,System.Linq.Expressions.Expression{System.Func{``0,System.Object}},System.Action,System.Int32,System.Waf.UnitTesting.ExpectedChangedCountMode)")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1030:UseEventsWhereAppropriate", Scope = "member", Target = "~M:System.Waf.UnitTesting.Mocks.MockSettingsService.RaiseErrorOccurred(System.Waf.Applications.Services.SettingsErrorEventArgs)")]
[assembly: SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "CanExecuteChanged", Scope = "member", Target = "~M:System.Waf.UnitTesting.AssertHelper.CanExecuteChangedEvent(System.Windows.Input.ICommand,System.Action)")]
[assembly: SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "PropertyChanged", Scope = "member", Target = "~M:System.Waf.UnitTesting.AssertHelper.PropertyChangedEvent``1(``0,System.Linq.Expressions.Expression{System.Func{``0,System.Object}},System.Action)")]
[assembly: SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Scope = "member", Target = "~M:System.Waf.UnitTesting.AssertHelper.ExpectedException``1(System.Action)~``0")]
[assembly: SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Scope = "member", Target = "~M:System.Waf.UnitTesting.AssertHelper.ExpectedException``1(System.Action)~``0")]
[assembly: SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Scope = "member", Target = "~M:System.Waf.UnitTesting.AssertHelper.PropertyChangedEvent``1(``0,System.Linq.Expressions.Expression{System.Func{``0,System.Object}},System.Action)")]
[assembly: SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Scope = "member", Target = "~P:System.Waf.UnitTesting.Mocks.MockMessageService.ShowQuestionAction")]
[assembly: SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes", Scope = "member", Target = "~P:System.Waf.UnitTesting.Mocks.MockDialogView`1.ShowDialogAction")]
[assembly: SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "~M:System.Waf.UnitTesting.UnitTestSynchronizationContext.Create~System.Waf.UnitTesting.UnitTestSynchronizationContext")]
[assembly: SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "~M:System.Waf.UnitTesting.UnitTestSynchronizationContext.CreateCopy~System.Threading.SynchronizationContext")]
[assembly: SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "~M:System.Waf.UnitTesting.UnitTestSynchronizationContext.Wait(System.TimeSpan)")]
[assembly: SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "CanExecuteChanged", Scope = "member", Target = "~M:System.Waf.UnitTesting.AssertHelper.CanExecuteChangedEvent(System.Windows.Input.ICommand,System.Action,System.Int32,System.Waf.UnitTesting.ExpectedChangedCountMode)")]
[assembly: SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Scope = "member", Target = "~M:System.Waf.UnitTesting.AssertHelper.PropertyChangedEvent``1(``0,System.Linq.Expressions.Expression{System.Func{``0,System.Object}},System.Action,System.Int32,System.Waf.UnitTesting.ExpectedChangedCountMode)")]
[assembly: SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "PropertyChanged", Scope = "member", Target = "~M:System.Waf.UnitTesting.AssertHelper.PropertyChangedEvent``1(``0,System.Linq.Expressions.Expression{System.Func{``0,System.Object}},System.Action,System.Int32,System.Waf.UnitTesting.ExpectedChangedCountMode)")]
[assembly: SuppressMessage("Microsoft.Design", "CA1030:UseEventsWhereAppropriate", Scope = "member", Target = "~M:System.Waf.UnitTesting.Mocks.MockSettingsService.RaiseErrorOccurred(System.Waf.Applications.Services.SettingsErrorEventArgs)")]

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.ComponentModel.Composition;
using System.Waf.Applications.Services;

namespace System.Waf.UnitTesting.Mocks
{
/// <summary>Mock for the ISettingsService interface.</summary>
[Export(typeof(ISettingsService)), Export(typeof(MockSettingsService)), Export]
public class MefMockSettingsService : MockSettingsService
{
}
}

This file was deleted.

0 comments on commit fdf67d5

Please sign in to comment.