reactiveui / ReactiveUI.Validation

Validation helpers for ReactiveUI-based apps.
https://reactiveui.net/docs/handbook/user-input-validation
MIT License
236 stars 24 forks source link

[ISSUE] Redesign ISupportsValidation #35

Closed MovGP0 closed 4 years ago

MovGP0 commented 5 years ago

Describe the issue It is currently not easily possible to overwrite the ValidationContext class for unit testing. It would be better to make it sealed and implement a base interface to allow for inversion of control (IOC) in unit tests.

Instead of

public interface ISupportsValidation
  {
    /// <summary>Gets get the validation context.</summary>
    ValidationContext ValidationContext { get; }
  }

public class ValidationContext : ReactiveObject, IDisposable, IValidationComponent
{
    // ...
}

use

public interface IValidationContext : IDisposable, IValidationComponent
{
     // ....
}

public sealed class ValidationContext : ReactiveObject, IValidationContext
{
    // ...
}

public interface ISupportsValidation
  {
    /// <summary>Gets get the validation context.</summary>
    IValidationContext ValidationContext { get; }
  }
open-collective-bot[bot] commented 5 years ago

Hey @MovGP0 :wave:,

Thank you for opening an issue. We will get back to you as soon as we can. Also, check out our Open Collective and consider backing us.

https://opencollective.com/reactiveui

PS.: We offer priority support for all backers. Don't forget to add priority label when you start backing us :smile:

ReactiveUI - Open Collective
An advanced, composable, functional reactive model-view-viewmodel framework for all .NET platforms!
glennawatson commented 5 years ago

Happy to take a PR for this one if you like.

worldbeater commented 4 years ago

Btw why would you ever need to mock a ValidationContext? In unit tests, you could pass an instance of an ImmediateScheduler to the constructor of the ValidationContext, and this would result in immediate scheduling required by unit tests. We are following this pattern in ReactiveUI.Validation.Tests now. https://github.com/reactiveui/ReactiveUI.Validation/blob/37505fc7bd74f48f252485f67aedb24ac5e2d00b/src/ReactiveUI.Validation.Tests/ValidationContextTests.cs#L41 Or, you could pass a TestScheduler from the ReactiveUI.Testing package. Setting up the desired validation context behavior should be quite easy via the fixture.ValidationRule(x => x.PropertyName) syntax.

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.