diff --git a/scripts/Microsoft.Xaml.Behaviors.Uwp.Managed.nuspec b/scripts/Microsoft.Xaml.Behaviors.Uwp.Managed.nuspec
index 5321a36..4ba6253 100644
--- a/scripts/Microsoft.Xaml.Behaviors.Uwp.Managed.nuspec
+++ b/scripts/Microsoft.Xaml.Behaviors.Uwp.Managed.nuspec
@@ -47,10 +47,6 @@
-
-
-
-
\ No newline at end of file
diff --git a/scripts/Microsoft.Xaml.Behaviors.WinUI.Managed.nuspec b/scripts/Microsoft.Xaml.Behaviors.WinUI.Managed.nuspec
index 5a6a6ae..e077d14 100644
--- a/scripts/Microsoft.Xaml.Behaviors.WinUI.Managed.nuspec
+++ b/scripts/Microsoft.Xaml.Behaviors.WinUI.Managed.nuspec
@@ -34,14 +34,6 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/BehaviorsSDKManaged/Directory.Build.props b/src/BehaviorsSDKManaged/Directory.Build.props
new file mode 100644
index 0000000..aca29dc
--- /dev/null
+++ b/src/BehaviorsSDKManaged/Directory.Build.props
@@ -0,0 +1,37 @@
+
+
+
+
+ $([MSBuild]::EnsureTrailingSlash($([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), BehaviorsSDKManaged.sln))))
+ $(BehaviorsSDKManagedSolutionPath)
+
+
+
+
+ 12.0
+ true
+
+
+ strict
+
+
+ true
+
+
diff --git a/src/BehaviorsSDKManaged/ManagedUnitTests/ActionCollectionTest.cs b/src/BehaviorsSDKManaged/ManagedUnitTests/ActionCollectionTest.cs
index 978c9eb..f6b3136 100644
--- a/src/BehaviorsSDKManaged/ManagedUnitTests/ActionCollectionTest.cs
+++ b/src/BehaviorsSDKManaged/ManagedUnitTests/ActionCollectionTest.cs
@@ -5,45 +5,44 @@
using Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer;
using Microsoft.Xaml.Interactivity;
-namespace ManagedUnitTests
+namespace ManagedUnitTests;
+
+[TestClass]
+public class ActionCollectionTest
{
- [TestClass]
- public class ActionCollectionTest
+ [UITestMethod]
+ public void Constructor_DefaultConstructor_SetsVolumeCorrectly()
+ {
+ PlaySoundAction playSoundAction = new PlaySoundAction();
+ Assert.AreEqual(0.5, playSoundAction.Volume, "Volume should be initialized to 0.5");
+ }
+
+ [UITestMethod]
+ public void Invoke_RelativeSource_Invokes()
{
- [UITestMethod]
- public void Constructor_DefaultConstructor_SetsVolumeCorrectly()
- {
- PlaySoundAction playSoundAction = new PlaySoundAction();
- Assert.AreEqual(0.5, playSoundAction.Volume, "Volume should be initialized to 0.5");
- }
-
- [UITestMethod]
- public void Invoke_RelativeSource_Invokes()
- {
- PlaySoundAction playSoundAction = new PlaySoundAction();
-
- playSoundAction.Source = "foo.wav";
- bool result = (bool)playSoundAction.Execute(null, null);
- Assert.IsTrue(result);
- }
-
- [UITestMethod]
- public void Invoke_AbsoluteSource_Invokes()
- {
- PlaySoundAction playSoundAction = new PlaySoundAction();
-
- playSoundAction.Source = "ms-appx:///foo.wav";
- bool result = (bool)playSoundAction.Execute(null, null);
- Assert.IsTrue(result);
- }
-
- [UITestMethod]
- public void Invoke_InvalidSource_ReturnsFalse()
- {
- PlaySoundAction playSoundAction = new PlaySoundAction();
-
- Assert.IsFalse((bool)playSoundAction.Execute(null, null),
- "PlaySoundAction.Execute should return false with a null source path.");
- }
+ PlaySoundAction playSoundAction = new PlaySoundAction();
+
+ playSoundAction.Source = "foo.wav";
+ bool result = (bool)playSoundAction.Execute(null, null);
+ Assert.IsTrue(result);
+ }
+
+ [UITestMethod]
+ public void Invoke_AbsoluteSource_Invokes()
+ {
+ PlaySoundAction playSoundAction = new PlaySoundAction();
+
+ playSoundAction.Source = "ms-appx:///foo.wav";
+ bool result = (bool)playSoundAction.Execute(null, null);
+ Assert.IsTrue(result);
+ }
+
+ [UITestMethod]
+ public void Invoke_InvalidSource_ReturnsFalse()
+ {
+ PlaySoundAction playSoundAction = new PlaySoundAction();
+
+ Assert.IsFalse((bool)playSoundAction.Execute(null, null),
+ "PlaySoundAction.Execute should return false with a null source path.");
}
}
diff --git a/src/BehaviorsSDKManaged/ManagedUnitTests/BehaviorCollectionTest.cs b/src/BehaviorsSDKManaged/ManagedUnitTests/BehaviorCollectionTest.cs
index ee0d254..6c4466c 100644
--- a/src/BehaviorsSDKManaged/ManagedUnitTests/BehaviorCollectionTest.cs
+++ b/src/BehaviorsSDKManaged/ManagedUnitTests/BehaviorCollectionTest.cs
@@ -6,246 +6,245 @@
using Microsoft.Xaml.Interactivity;
using Windows.UI.Xaml.Controls;
-namespace ManagedUnitTests
+namespace ManagedUnitTests;
+
+[TestClass]
+public class BehaviorCollectionTest
{
- [TestClass]
- public class BehaviorCollectionTest
+ [UITestMethod]
+ public void VectorChanged_NonBehaviorAdded_ExceptionThrown()
{
- [UITestMethod]
- public void VectorChanged_NonBehaviorAdded_ExceptionThrown()
- {
- BehaviorCollection behaviorCollection = new BehaviorCollection();
- behaviorCollection.Add(new StubBehavior());
+ BehaviorCollection behaviorCollection = new BehaviorCollection();
+ behaviorCollection.Add(new StubBehavior());
- TestUtilities.AssertThrowsInvalidOperationException(() => behaviorCollection.Add(new TextBlock()));
- }
+ TestUtilities.AssertThrowsInvalidOperationException(() => behaviorCollection.Add(new TextBlock()));
+ }
- [UITestMethod]
- public void VectorChanged_BehaviorChangedToNonBehavior_ExceptionThrown()
- {
- BehaviorCollection behaviorCollection = new BehaviorCollection();
- behaviorCollection.Add(new StubBehavior());
+ [UITestMethod]
+ public void VectorChanged_BehaviorChangedToNonBehavior_ExceptionThrown()
+ {
+ BehaviorCollection behaviorCollection = new BehaviorCollection();
+ behaviorCollection.Add(new StubBehavior());
- TestUtilities.AssertThrowsInvalidOperationException(() => behaviorCollection[0] = new ToggleSwitch());
- }
+ TestUtilities.AssertThrowsInvalidOperationException(() => behaviorCollection[0] = new ToggleSwitch());
+ }
- [UITestMethod]
- public void VectorChanged_DuplicateAdd_ExceptionThrown()
- {
- BehaviorCollection behaviorCollection = new BehaviorCollection();
- StubBehavior stub = new StubBehavior();
- behaviorCollection.Add(stub);
+ [UITestMethod]
+ public void VectorChanged_DuplicateAdd_ExceptionThrown()
+ {
+ BehaviorCollection behaviorCollection = new BehaviorCollection();
+ StubBehavior stub = new StubBehavior();
+ behaviorCollection.Add(stub);
- TestUtilities.AssertThrowsInvalidOperationException(() => behaviorCollection.Add(stub));
+ TestUtilities.AssertThrowsInvalidOperationException(() => behaviorCollection.Add(stub));
- }
+ }
- [UITestMethod]
- public void VectorChanged_AddWhileNotAttached_AttachNotCalled()
- {
- BehaviorCollection behaviorCollection = new BehaviorCollection();
- StubBehavior stub = new StubBehavior();
- behaviorCollection.Add(stub);
+ [UITestMethod]
+ public void VectorChanged_AddWhileNotAttached_AttachNotCalled()
+ {
+ BehaviorCollection behaviorCollection = new BehaviorCollection();
+ StubBehavior stub = new StubBehavior();
+ behaviorCollection.Add(stub);
- TestUtilities.AssertNotAttached(stub);
- }
+ TestUtilities.AssertNotAttached(stub);
+ }
- [UITestMethod]
- public void VectorChanged_AddWhileAttached_AllAttached()
- {
- BehaviorCollection behaviorCollection = new BehaviorCollection();
- behaviorCollection.Attach(new Button());
+ [UITestMethod]
+ public void VectorChanged_AddWhileAttached_AllAttached()
+ {
+ BehaviorCollection behaviorCollection = new BehaviorCollection();
+ behaviorCollection.Attach(new Button());
- behaviorCollection.Add(new StubBehavior());
- behaviorCollection.Add(new StubBehavior());
- behaviorCollection.Add(new StubBehavior());
+ behaviorCollection.Add(new StubBehavior());
+ behaviorCollection.Add(new StubBehavior());
+ behaviorCollection.Add(new StubBehavior());
- foreach (StubBehavior stub in behaviorCollection)
- {
- TestUtilities.AssertAttached(stub, behaviorCollection.AssociatedObject);
- }
+ foreach (StubBehavior stub in behaviorCollection)
+ {
+ TestUtilities.AssertAttached(stub, behaviorCollection.AssociatedObject);
}
+ }
- [UITestMethod]
- public void VectorChanged_ReplaceWhileAttached_OldDetachedNewAttached()
- {
- BehaviorCollection behaviorCollection = new BehaviorCollection();
- behaviorCollection.Attach(new Button());
+ [UITestMethod]
+ public void VectorChanged_ReplaceWhileAttached_OldDetachedNewAttached()
+ {
+ BehaviorCollection behaviorCollection = new BehaviorCollection();
+ behaviorCollection.Attach(new Button());
- StubBehavior first = new StubBehavior();
- behaviorCollection.Add(first);
+ StubBehavior first = new StubBehavior();
+ behaviorCollection.Add(first);
- StubBehavior second = new StubBehavior();
+ StubBehavior second = new StubBehavior();
- behaviorCollection[0] = second;
+ behaviorCollection[0] = second;
- TestUtilities.AssertDetached(first);
+ TestUtilities.AssertDetached(first);
- TestUtilities.AssertAttached(second, behaviorCollection.AssociatedObject);
- }
+ TestUtilities.AssertAttached(second, behaviorCollection.AssociatedObject);
+ }
- [UITestMethod]
- public void VectorChanged_RemoveWhileNotAttached_DetachNotCalled()
- {
- BehaviorCollection behaviorCollection = new BehaviorCollection();
+ [UITestMethod]
+ public void VectorChanged_RemoveWhileNotAttached_DetachNotCalled()
+ {
+ BehaviorCollection behaviorCollection = new BehaviorCollection();
- StubBehavior behavior = new StubBehavior();
- behaviorCollection.Add(behavior);
- behaviorCollection.Remove(behavior);
+ StubBehavior behavior = new StubBehavior();
+ behaviorCollection.Add(behavior);
+ behaviorCollection.Remove(behavior);
- TestUtilities.AssertNotDetached(behavior);
- }
+ TestUtilities.AssertNotDetached(behavior);
+ }
- [UITestMethod]
- public void VectorChanged_RemoveWhileAttached_Detached()
- {
- BehaviorCollection behaviorCollection = new BehaviorCollection();
- behaviorCollection.Attach(new ToggleSwitch());
+ [UITestMethod]
+ public void VectorChanged_RemoveWhileAttached_Detached()
+ {
+ BehaviorCollection behaviorCollection = new BehaviorCollection();
+ behaviorCollection.Attach(new ToggleSwitch());
- StubBehavior behavior = new StubBehavior();
- behaviorCollection.Add(behavior);
- behaviorCollection.Remove(behavior);
+ StubBehavior behavior = new StubBehavior();
+ behaviorCollection.Add(behavior);
+ behaviorCollection.Remove(behavior);
- TestUtilities.AssertDetached(behavior);
- }
+ TestUtilities.AssertDetached(behavior);
+ }
- [UITestMethod]
- public void VectorChanged_ResetWhileNotAttached_DetachNotCalled()
- {
- StubBehavior[] behaviorArray = { new StubBehavior(), new StubBehavior(), new StubBehavior() };
+ [UITestMethod]
+ public void VectorChanged_ResetWhileNotAttached_DetachNotCalled()
+ {
+ StubBehavior[] behaviorArray = { new StubBehavior(), new StubBehavior(), new StubBehavior() };
- BehaviorCollection behaviorCollection = new BehaviorCollection();
- foreach (StubBehavior behavior in behaviorArray)
- {
- behaviorCollection.Add(behavior);
- }
+ BehaviorCollection behaviorCollection = new BehaviorCollection();
+ foreach (StubBehavior behavior in behaviorArray)
+ {
+ behaviorCollection.Add(behavior);
+ }
- behaviorCollection.Clear();
+ behaviorCollection.Clear();
- foreach (StubBehavior behavior in behaviorArray)
- {
- TestUtilities.AssertNotDetached(behavior);
- }
+ foreach (StubBehavior behavior in behaviorArray)
+ {
+ TestUtilities.AssertNotDetached(behavior);
}
+ }
- [UITestMethod]
- public void VectorChanged_ResetWhileAttached_AllDetached()
- {
- StubBehavior[] behaviorArray = { new StubBehavior(), new StubBehavior(), new StubBehavior() };
+ [UITestMethod]
+ public void VectorChanged_ResetWhileAttached_AllDetached()
+ {
+ StubBehavior[] behaviorArray = { new StubBehavior(), new StubBehavior(), new StubBehavior() };
- BehaviorCollection behaviorCollection = new BehaviorCollection();
- behaviorCollection.Attach(new Button());
+ BehaviorCollection behaviorCollection = new BehaviorCollection();
+ behaviorCollection.Attach(new Button());
- foreach (StubBehavior behavior in behaviorArray)
- {
- behaviorCollection.Add(behavior);
- }
+ foreach (StubBehavior behavior in behaviorArray)
+ {
+ behaviorCollection.Add(behavior);
+ }
- behaviorCollection.Clear();
+ behaviorCollection.Clear();
- foreach (StubBehavior behavior in behaviorArray)
- {
- TestUtilities.AssertDetached(behavior);
- }
+ foreach (StubBehavior behavior in behaviorArray)
+ {
+ TestUtilities.AssertDetached(behavior);
}
+ }
- [UITestMethod]
- public void Attach_MultipleBehaviors_AllAttached()
- {
- BehaviorCollection behaviorCollection = new BehaviorCollection();
- behaviorCollection.Add(new StubBehavior());
- behaviorCollection.Add(new StubBehavior());
- behaviorCollection.Add(new StubBehavior());
+ [UITestMethod]
+ public void Attach_MultipleBehaviors_AllAttached()
+ {
+ BehaviorCollection behaviorCollection = new BehaviorCollection();
+ behaviorCollection.Add(new StubBehavior());
+ behaviorCollection.Add(new StubBehavior());
+ behaviorCollection.Add(new StubBehavior());
- Button button = new Button();
- behaviorCollection.Attach(button);
+ Button button = new Button();
+ behaviorCollection.Attach(button);
- Assert.AreEqual(button, behaviorCollection.AssociatedObject, "Attach should set the AssociatedObject to the given parameter.");
+ Assert.AreEqual(button, behaviorCollection.AssociatedObject, "Attach should set the AssociatedObject to the given parameter.");
- foreach (StubBehavior stub in behaviorCollection)
- {
- TestUtilities.AssertAttached(stub, button);
- }
+ foreach (StubBehavior stub in behaviorCollection)
+ {
+ TestUtilities.AssertAttached(stub, button);
}
+ }
- [UITestMethod]
- public void Attach_Null_AttachNotCalledOnItems()
- {
- BehaviorCollection behaviorCollection = new BehaviorCollection();
- behaviorCollection.Add(new StubBehavior());
- behaviorCollection.Add(new StubBehavior());
- behaviorCollection.Add(new StubBehavior());
+ [UITestMethod]
+ public void Attach_Null_AttachNotCalledOnItems()
+ {
+ BehaviorCollection behaviorCollection = new BehaviorCollection();
+ behaviorCollection.Add(new StubBehavior());
+ behaviorCollection.Add(new StubBehavior());
+ behaviorCollection.Add(new StubBehavior());
- behaviorCollection.Attach(null);
+ behaviorCollection.Attach(null);
- foreach (StubBehavior stub in behaviorCollection)
- {
- TestUtilities.AssertNotAttached(stub);
- }
+ foreach (StubBehavior stub in behaviorCollection)
+ {
+ TestUtilities.AssertNotAttached(stub);
}
+ }
- [UITestMethod]
- public void Attach_MultipleObjects_ExceptionThrown()
- {
- BehaviorCollection behaviorCollection = new BehaviorCollection();
- StubBehavior stub = new StubBehavior();
- behaviorCollection.Attach(new Button());
+ [UITestMethod]
+ public void Attach_MultipleObjects_ExceptionThrown()
+ {
+ BehaviorCollection behaviorCollection = new BehaviorCollection();
+ StubBehavior stub = new StubBehavior();
+ behaviorCollection.Attach(new Button());
- TestUtilities.AssertThrowsInvalidOperationException(() => behaviorCollection.Attach(new StackPanel()));
- }
+ TestUtilities.AssertThrowsInvalidOperationException(() => behaviorCollection.Attach(new StackPanel()));
+ }
- [UITestMethod]
- public void Attach_NonNullThenNull_ExceptionThrown()
- {
- BehaviorCollection behaviorCollection = new BehaviorCollection();
- behaviorCollection.Add(new StubBehavior());
+ [UITestMethod]
+ public void Attach_NonNullThenNull_ExceptionThrown()
+ {
+ BehaviorCollection behaviorCollection = new BehaviorCollection();
+ behaviorCollection.Add(new StubBehavior());
- behaviorCollection.Attach(new Button());
+ behaviorCollection.Attach(new Button());
- TestUtilities.AssertThrowsInvalidOperationException(() => behaviorCollection.Attach(null));
- }
+ TestUtilities.AssertThrowsInvalidOperationException(() => behaviorCollection.Attach(null));
+ }
- [UITestMethod]
- public void Attach_MultipleTimeSameObject_AttachCalledOnce()
- {
- BehaviorCollection behaviorCollection = new BehaviorCollection() { new StubBehavior() };
+ [UITestMethod]
+ public void Attach_MultipleTimeSameObject_AttachCalledOnce()
+ {
+ BehaviorCollection behaviorCollection = new BehaviorCollection() { new StubBehavior() };
- Button button = new Button();
- behaviorCollection.Attach(button);
- behaviorCollection.Attach(button);
+ Button button = new Button();
+ behaviorCollection.Attach(button);
+ behaviorCollection.Attach(button);
- // This method hard codes AttachCount == 1.
- TestUtilities.AssertAttached((StubBehavior)behaviorCollection[0], button);
- }
+ // This method hard codes AttachCount == 1.
+ TestUtilities.AssertAttached((StubBehavior)behaviorCollection[0], button);
+ }
- [UITestMethod]
- public void Detach_NotAttached_DetachNotCalledOnItems()
- {
- BehaviorCollection behaviorCollection = new BehaviorCollection() { new StubBehavior() };
+ [UITestMethod]
+ public void Detach_NotAttached_DetachNotCalledOnItems()
+ {
+ BehaviorCollection behaviorCollection = new BehaviorCollection() { new StubBehavior() };
- behaviorCollection.Detach();
+ behaviorCollection.Detach();
- TestUtilities.AssertNotDetached((StubBehavior)behaviorCollection[0]);
- }
+ TestUtilities.AssertNotDetached((StubBehavior)behaviorCollection[0]);
+ }
- [UITestMethod]
- public void Detach_Attached_AllItemsDetached()
- {
- BehaviorCollection behaviorCollection = new BehaviorCollection();
- behaviorCollection.Add(new StubBehavior());
- behaviorCollection.Add(new StubBehavior());
- behaviorCollection.Add(new StubBehavior());
+ [UITestMethod]
+ public void Detach_Attached_AllItemsDetached()
+ {
+ BehaviorCollection behaviorCollection = new BehaviorCollection();
+ behaviorCollection.Add(new StubBehavior());
+ behaviorCollection.Add(new StubBehavior());
+ behaviorCollection.Add(new StubBehavior());
- behaviorCollection.Attach(new Button());
- behaviorCollection.Detach();
+ behaviorCollection.Attach(new Button());
+ behaviorCollection.Detach();
- Assert.IsNull(behaviorCollection.AssociatedObject, "The AssociatedObject should be null after Detach.");
+ Assert.IsNull(behaviorCollection.AssociatedObject, "The AssociatedObject should be null after Detach.");
- foreach (StubBehavior behavior in behaviorCollection)
- {
- TestUtilities.AssertDetached(behavior);
- }
+ foreach (StubBehavior behavior in behaviorCollection)
+ {
+ TestUtilities.AssertDetached(behavior);
}
}
}
diff --git a/src/BehaviorsSDKManaged/ManagedUnitTests/BlankPage.xaml.cs b/src/BehaviorsSDKManaged/ManagedUnitTests/BlankPage.xaml.cs
index 27f017d..ba99bec 100644
--- a/src/BehaviorsSDKManaged/ManagedUnitTests/BlankPage.xaml.cs
+++ b/src/BehaviorsSDKManaged/ManagedUnitTests/BlankPage.xaml.cs
@@ -1,21 +1,20 @@
using Windows.UI.Xaml.Controls;
-namespace ManagedUnitTests
+namespace ManagedUnitTests;
+
+///
+/// This page serves two purposes:
+///
+/// 1. Its existence causes the XAML compiler to implement IXamlMetadataProvider
+/// on the App class. IXamlMetadataProvider is used by NavigateToPageAction and will
+/// only be implemented on App if there are XAML types defined in the project.
+///
+/// 2. It provides a target for the NavigateToPageAction to navigate to in tests.
+///
+public sealed partial class BlankPage : Page
{
- ///
- /// This page serves two purposes:
- ///
- /// 1. Its existence causes the XAML compiler to implement IXamlMetadataProvider
- /// on the App class. IXamlMetadataProvider is used by NavigateToPageAction and will
- /// only be implemented on App if there are XAML types defined in the project.
- ///
- /// 2. It provides a target for the NavigateToPageAction to navigate to in tests.
- ///
- public sealed partial class BlankPage : Page
+ public BlankPage()
{
- public BlankPage()
- {
- this.InitializeComponent();
- }
+ this.InitializeComponent();
}
}
diff --git a/src/BehaviorsSDKManaged/ManagedUnitTests/InteractionTest.cs b/src/BehaviorsSDKManaged/ManagedUnitTests/InteractionTest.cs
index b43b569..70cfa75 100644
--- a/src/BehaviorsSDKManaged/ManagedUnitTests/InteractionTest.cs
+++ b/src/BehaviorsSDKManaged/ManagedUnitTests/InteractionTest.cs
@@ -9,149 +9,148 @@
using Microsoft.Xaml.Interactivity;
using Windows.UI.Xaml.Controls;
-namespace ManagedUnitTests
+namespace ManagedUnitTests;
+
+[TestClass]
+public class InteractionTest
{
- [TestClass]
- public class InteractionTest
+ [UITestMethod]
+ public void SetBehaviors_MultipleBehaviors_AllAttached()
{
- [UITestMethod]
- public void SetBehaviors_MultipleBehaviors_AllAttached()
+ BehaviorCollection behaviorCollection = new BehaviorCollection();
+ behaviorCollection.Add(new StubBehavior());
+ behaviorCollection.Add(new StubBehavior());
+ behaviorCollection.Add(new StubBehavior());
+
+ Button button = new Button();
+ Interaction.SetBehaviors(button, behaviorCollection);
+
+ foreach (StubBehavior behavior in behaviorCollection)
{
- BehaviorCollection behaviorCollection = new BehaviorCollection();
- behaviorCollection.Add(new StubBehavior());
- behaviorCollection.Add(new StubBehavior());
- behaviorCollection.Add(new StubBehavior());
-
- Button button = new Button();
- Interaction.SetBehaviors(button, behaviorCollection);
-
- foreach (StubBehavior behavior in behaviorCollection)
- {
- Assert.AreEqual(1, behavior.AttachCount, "Should only have called Attach once.");
- Assert.AreEqual(0, behavior.DetachCount, "Should not have called Detach.");
- Assert.AreEqual(button, behavior.AssociatedObject, "Should be attached to the host of the BehaviorCollection.");
- }
+ Assert.AreEqual(1, behavior.AttachCount, "Should only have called Attach once.");
+ Assert.AreEqual(0, behavior.DetachCount, "Should not have called Detach.");
+ Assert.AreEqual(button, behavior.AssociatedObject, "Should be attached to the host of the BehaviorCollection.");
}
+ }
- [UITestMethod]
- public void SetBehaviors_MultipleSets_DoesNotReattach()
- {
- BehaviorCollection behaviorCollection = new BehaviorCollection() { new StubBehavior() };
+ [UITestMethod]
+ public void SetBehaviors_MultipleSets_DoesNotReattach()
+ {
+ BehaviorCollection behaviorCollection = new BehaviorCollection() { new StubBehavior() };
- Button button = new Button();
- Interaction.SetBehaviors(button, behaviorCollection);
- Interaction.SetBehaviors(button, behaviorCollection);
+ Button button = new Button();
+ Interaction.SetBehaviors(button, behaviorCollection);
+ Interaction.SetBehaviors(button, behaviorCollection);
- foreach (StubBehavior behavior in behaviorCollection)
- {
- Assert.AreEqual(1, behavior.AttachCount, "Should only have called Attach once.");
- }
+ foreach (StubBehavior behavior in behaviorCollection)
+ {
+ Assert.AreEqual(1, behavior.AttachCount, "Should only have called Attach once.");
}
+ }
- [UITestMethod]
- public void SetBehaviors_CollectionThenNull_DeatchCollection()
- {
- BehaviorCollection behaviorCollection = new BehaviorCollection() { new StubBehavior() };
+ [UITestMethod]
+ public void SetBehaviors_CollectionThenNull_DeatchCollection()
+ {
+ BehaviorCollection behaviorCollection = new BehaviorCollection() { new StubBehavior() };
- Button button = new Button();
- Interaction.SetBehaviors(button, behaviorCollection);
- Interaction.SetBehaviors(button, null);
+ Button button = new Button();
+ Interaction.SetBehaviors(button, behaviorCollection);
+ Interaction.SetBehaviors(button, null);
- foreach (StubBehavior behavior in behaviorCollection)
- {
- Assert.AreEqual(1, behavior.DetachCount, "Should only have called Detach once.");
- Assert.IsNull(behavior.AssociatedObject, "AssociatedObject should be null after Detach.");
- }
+ foreach (StubBehavior behavior in behaviorCollection)
+ {
+ Assert.AreEqual(1, behavior.DetachCount, "Should only have called Detach once.");
+ Assert.IsNull(behavior.AssociatedObject, "AssociatedObject should be null after Detach.");
}
+ }
- [UITestMethod]
- public void SetBehaviors_NullThenNull_NoOp()
- {
- // As long as this doesn't crash/assert, we're good.
+ [UITestMethod]
+ public void SetBehaviors_NullThenNull_NoOp()
+ {
+ // As long as this doesn't crash/assert, we're good.
- Button button = new Button();
- Interaction.SetBehaviors(button, null);
- Interaction.SetBehaviors(button, null);
- Interaction.SetBehaviors(button, null);
- }
+ Button button = new Button();
+ Interaction.SetBehaviors(button, null);
+ Interaction.SetBehaviors(button, null);
+ Interaction.SetBehaviors(button, null);
+ }
+
+ [UITestMethod]
+
+ public void SetBehaviors_ManualDetachThenNull_DoesNotDoubleDetach()
+ {
+ BehaviorCollection behaviorCollection = new BehaviorCollection();
+ behaviorCollection.Add(new StubBehavior());
+ behaviorCollection.Add(new StubBehavior());
+ behaviorCollection.Add(new StubBehavior());
- [UITestMethod]
+ Button button = new Button();
+ Interaction.SetBehaviors(button, behaviorCollection);
- public void SetBehaviors_ManualDetachThenNull_DoesNotDoubleDetach()
+ foreach (StubBehavior behavior in behaviorCollection)
{
- BehaviorCollection behaviorCollection = new BehaviorCollection();
- behaviorCollection.Add(new StubBehavior());
- behaviorCollection.Add(new StubBehavior());
- behaviorCollection.Add(new StubBehavior());
-
- Button button = new Button();
- Interaction.SetBehaviors(button, behaviorCollection);
-
- foreach (StubBehavior behavior in behaviorCollection)
- {
- behavior.Detach();
- }
-
- Interaction.SetBehaviors(button, null);
-
- foreach (StubBehavior behavior in behaviorCollection)
- {
- Assert.AreEqual(1, behavior.DetachCount, "Setting BehaviorCollection to null should not call Detach on already Detached Behaviors.");
- Assert.IsNull(behavior.AssociatedObject, "AssociatedObject should be null after Detach.");
- }
+ behavior.Detach();
}
- [UITestMethod]
- public void ExecuteActions_NullParameters_ReturnsEmptyEnumerable()
- {
- // Mostly just want to test that this doesn't throw any exceptions.
- IEnumerable