Browse Source

Simplify test controls in styling unit tests.

Making a change to interfaces was becoming a pain because of this.
pull/3263/head
Steven Kirk 7 years ago
parent
commit
24f11bba18
  1. 85
      tests/Avalonia.Styling.UnitTests/SelectorTests_Child.cs
  2. 2
      tests/Avalonia.Styling.UnitTests/SelectorTests_Class.cs
  3. 85
      tests/Avalonia.Styling.UnitTests/SelectorTests_Descendent.cs
  4. 3
      tests/Avalonia.Styling.UnitTests/SelectorTests_Name.cs
  5. 4
      tests/Avalonia.Styling.UnitTests/SelectorTests_Not.cs
  6. 5
      tests/Avalonia.Styling.UnitTests/SelectorTests_OfType.cs
  7. 9
      tests/Avalonia.Styling.UnitTests/SelectorTests_Or.cs
  8. 83
      tests/Avalonia.Styling.UnitTests/TestControlBase.cs
  9. 81
      tests/Avalonia.Styling.UnitTests/TestTemplatedControl.cs

85
tests/Avalonia.Styling.UnitTests/SelectorTests_Child.cs

@ -81,89 +81,12 @@ namespace Avalonia.Styling.UnitTests
Assert.Equal("TestLogical1 > TestLogical3", selector.ToString()); Assert.Equal("TestLogical1 > TestLogical3", selector.ToString());
} }
public abstract class TestLogical : ILogical, IStyleable public abstract class TestLogical : Control
{ {
public TestLogical() public ILogical LogicalParent
{ {
Classes = new Classes(); get => Parent;
} set => ((ISetLogicalParent)this).SetParent(value);
public event EventHandler<AvaloniaPropertyChangedEventArgs> PropertyChanged;
public event EventHandler<AvaloniaPropertyChangedEventArgs> InheritablePropertyChanged;
public event EventHandler<LogicalTreeAttachmentEventArgs> AttachedToLogicalTree;
public event EventHandler<LogicalTreeAttachmentEventArgs> DetachedFromLogicalTree;
public Classes Classes { get; }
public string Name { get; set; }
public bool IsAttachedToLogicalTree { get; }
public IAvaloniaReadOnlyList<ILogical> LogicalChildren { get; set; }
public ILogical LogicalParent { get; set; }
public Type StyleKey { get; }
public ITemplatedControl TemplatedParent { get; }
IObservable<IStyleable> IStyleable.StyleDetach { get; }
IAvaloniaReadOnlyList<string> IStyleable.Classes => Classes;
public object GetValue(AvaloniaProperty property)
{
throw new NotImplementedException();
}
public T GetValue<T>(AvaloniaProperty<T> property)
{
throw new NotImplementedException();
}
public void SetValue(AvaloniaProperty property, object value, BindingPriority priority)
{
throw new NotImplementedException();
}
public void SetValue<T>(AvaloniaProperty<T> property, T value, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public IDisposable Bind(AvaloniaProperty property, IObservable<object> source, BindingPriority priority)
{
throw new NotImplementedException();
}
public bool IsAnimating(AvaloniaProperty property)
{
throw new NotImplementedException();
}
public bool IsSet(AvaloniaProperty property)
{
throw new NotImplementedException();
}
public IDisposable Bind<T>(AvaloniaProperty<T> property, IObservable<T> source, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public void NotifyAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
{
throw new NotImplementedException();
}
public void NotifyDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
{
throw new NotImplementedException();
}
public void NotifyResourcesChanged(ResourcesChangedEventArgs e)
{
throw new NotImplementedException();
} }
} }

2
tests/Avalonia.Styling.UnitTests/SelectorTests_Class.cs

@ -144,7 +144,7 @@ namespace Avalonia.Styling.UnitTests
Assert.Equal(new[] { true, false }, result); Assert.Equal(new[] { true, false }, result);
} }
public class Control1 : TestControlBase public class Control1 : Control
{ {
} }
} }

85
tests/Avalonia.Styling.UnitTests/SelectorTests_Descendent.cs

@ -111,89 +111,12 @@ namespace Avalonia.Styling.UnitTests
Assert.Equal("TestLogical1.foo TestLogical3", selector.ToString()); Assert.Equal("TestLogical1.foo TestLogical3", selector.ToString());
} }
public abstract class TestLogical : ILogical, IStyleable public abstract class TestLogical : Control
{ {
public TestLogical() public ILogical LogicalParent
{ {
Classes = new Classes(); get => Parent;
} set => ((ISetLogicalParent)this).SetParent(value);
public event EventHandler<AvaloniaPropertyChangedEventArgs> PropertyChanged;
public event EventHandler<AvaloniaPropertyChangedEventArgs> InheritablePropertyChanged;
public event EventHandler<LogicalTreeAttachmentEventArgs> AttachedToLogicalTree;
public event EventHandler<LogicalTreeAttachmentEventArgs> DetachedFromLogicalTree;
public Classes Classes { get; }
public string Name { get; set; }
public bool IsAttachedToLogicalTree { get; }
public IAvaloniaReadOnlyList<ILogical> LogicalChildren { get; set; }
public ILogical LogicalParent { get; set; }
public Type StyleKey { get; }
public ITemplatedControl TemplatedParent { get; }
IAvaloniaReadOnlyList<string> IStyleable.Classes => Classes;
IObservable<IStyleable> IStyleable.StyleDetach { get; }
public object GetValue(AvaloniaProperty property)
{
throw new NotImplementedException();
}
public T GetValue<T>(AvaloniaProperty<T> property)
{
throw new NotImplementedException();
}
public void SetValue(AvaloniaProperty property, object value, BindingPriority priority)
{
throw new NotImplementedException();
}
public void SetValue<T>(AvaloniaProperty<T> property, T value, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public IDisposable Bind(AvaloniaProperty property, IObservable<object> source, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public bool IsAnimating(AvaloniaProperty property)
{
throw new NotImplementedException();
}
public bool IsSet(AvaloniaProperty property)
{
throw new NotImplementedException();
}
public IDisposable Bind<T>(AvaloniaProperty<T> property, IObservable<T> source, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public void NotifyAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
{
throw new NotImplementedException();
}
public void NotifyDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
{
throw new NotImplementedException();
}
public void NotifyResourcesChanged(ResourcesChangedEventArgs e)
{
throw new NotImplementedException();
} }
} }

3
tests/Avalonia.Styling.UnitTests/SelectorTests_Name.cs

@ -1,6 +1,7 @@
// Copyright (c) The Avalonia Project. All rights reserved. // Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information. // Licensed under the MIT license. See licence.md file in the project root for full license information.
using Avalonia.Controls;
using Moq; using Moq;
using Xunit; using Xunit;
@ -52,7 +53,7 @@ namespace Avalonia.Styling.UnitTests
Assert.Equal("Control1#foo", target.ToString()); Assert.Equal("Control1#foo", target.ToString());
} }
public class Control1 : TestControlBase public class Control1 : Control
{ {
} }
} }

4
tests/Avalonia.Styling.UnitTests/SelectorTests_Not.cs

@ -103,11 +103,11 @@ namespace Avalonia.Styling.UnitTests
Assert.Equal(typeof(Control1), target.TargetType); Assert.Equal(typeof(Control1), target.TargetType);
} }
public class Control1 : TestControlBase public class Control1 : Control
{ {
} }
public class Control2 : TestControlBase public class Control2 : Control
{ {
} }
} }

5
tests/Avalonia.Styling.UnitTests/SelectorTests_OfType.cs

@ -1,6 +1,7 @@
// Copyright (c) The Avalonia Project. All rights reserved. // Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information. // Licensed under the MIT license. See licence.md file in the project root for full license information.
using Avalonia.Controls;
using Moq; using Moq;
using Xunit; using Xunit;
@ -44,11 +45,11 @@ namespace Avalonia.Styling.UnitTests
Assert.Equal(SelectorMatchResult.AlwaysThisType, target.Match(control).Result); Assert.Equal(SelectorMatchResult.AlwaysThisType, target.Match(control).Result);
} }
public class Control1 : TestControlBase public class Control1 : Control
{ {
} }
public class Control2 : TestControlBase public class Control2 : Control
{ {
} }
} }

9
tests/Avalonia.Styling.UnitTests/SelectorTests_Or.cs

@ -1,6 +1,7 @@
// Copyright (c) The Avalonia Project. All rights reserved. // Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information. // Licensed under the MIT license. See licence.md file in the project root for full license information.
using Avalonia.Controls;
using Xunit; using Xunit;
namespace Avalonia.Styling.UnitTests namespace Avalonia.Styling.UnitTests
@ -78,7 +79,7 @@ namespace Avalonia.Styling.UnitTests
default(Selector).OfType<Control1>().Class("foo"), default(Selector).OfType<Control1>().Class("foo"),
default(Selector).OfType<Control2>().Class("bar")); default(Selector).OfType<Control2>().Class("bar"));
Assert.Equal(typeof(TestControlBase), target.TargetType); Assert.Equal(typeof(Control), target.TargetType);
} }
[Fact] [Fact]
@ -91,15 +92,15 @@ namespace Avalonia.Styling.UnitTests
Assert.Equal(null, target.TargetType); Assert.Equal(null, target.TargetType);
} }
public class Control1 : TestControlBase public class Control1 : Control
{ {
} }
public class Control2 : TestControlBase public class Control2 : Control
{ {
} }
public class Control3 : TestControlBase public class Control3 : Control
{ {
} }
} }

83
tests/Avalonia.Styling.UnitTests/TestControlBase.cs

@ -1,83 +0,0 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Reactive;
using Avalonia.Collections;
using Avalonia.Controls;
using Avalonia.Data;
namespace Avalonia.Styling.UnitTests
{
public class TestControlBase : IStyleable
{
public TestControlBase()
{
Classes = new Classes();
SubscribeCheckObservable = new TestObservable();
}
#pragma warning disable CS0067 // Event not used
public event EventHandler<AvaloniaPropertyChangedEventArgs> PropertyChanged;
public event EventHandler<AvaloniaPropertyChangedEventArgs> InheritablePropertyChanged;
#pragma warning restore CS0067
public string Name { get; set; }
public virtual Classes Classes { get; set; }
public Type StyleKey => GetType();
public TestObservable SubscribeCheckObservable { get; private set; }
public ITemplatedControl TemplatedParent
{
get;
set;
}
IAvaloniaReadOnlyList<string> IStyleable.Classes => Classes;
IObservable<IStyleable> IStyleable.StyleDetach { get; }
public object GetValue(AvaloniaProperty property)
{
throw new NotImplementedException();
}
public T GetValue<T>(AvaloniaProperty<T> property)
{
throw new NotImplementedException();
}
public void SetValue(AvaloniaProperty property, object value, BindingPriority priority)
{
throw new NotImplementedException();
}
public void SetValue<T>(AvaloniaProperty<T> property, T value, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public bool IsAnimating(AvaloniaProperty property)
{
throw new NotImplementedException();
}
public bool IsSet(AvaloniaProperty property)
{
throw new NotImplementedException();
}
public IDisposable Bind(AvaloniaProperty property, IObservable<object> source, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public IDisposable Bind<T>(AvaloniaProperty<T> property, IObservable<T> source, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
}
}

81
tests/Avalonia.Styling.UnitTests/TestTemplatedControl.cs

@ -1,81 +0,0 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Reactive;
using Avalonia.Collections;
using Avalonia.Controls;
using Avalonia.Data;
namespace Avalonia.Styling.UnitTests
{
public abstract class TestTemplatedControl : ITemplatedControl, IStyleable
{
public event EventHandler<AvaloniaPropertyChangedEventArgs> PropertyChanged;
public event EventHandler<AvaloniaPropertyChangedEventArgs> InheritablePropertyChanged;
public abstract Classes Classes
{
get;
}
public abstract string Name
{
get;
}
public abstract Type StyleKey
{
get;
}
public abstract ITemplatedControl TemplatedParent
{
get;
}
IAvaloniaReadOnlyList<string> IStyleable.Classes => Classes;
IObservable<IStyleable> IStyleable.StyleDetach { get; }
public object GetValue(AvaloniaProperty property)
{
throw new NotImplementedException();
}
public T GetValue<T>(AvaloniaProperty<T> property)
{
throw new NotImplementedException();
}
public void SetValue(AvaloniaProperty property, object value, BindingPriority priority)
{
throw new NotImplementedException();
}
public void SetValue<T>(AvaloniaProperty<T> property, T value, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public IDisposable Bind(AvaloniaProperty property, IObservable<object> source, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public IDisposable Bind<T>(AvaloniaProperty<T> property, IObservable<T> source, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public bool IsAnimating(AvaloniaProperty property)
{
throw new NotImplementedException();
}
public bool IsSet(AvaloniaProperty property)
{
throw new NotImplementedException();
}
}
}
Loading…
Cancel
Save