Index: src/Common/DelftTools.Shell.Core/ApplicationPlugin.cs =================================================================== diff -u -r8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9 -r6b59ea277522a35859f061196c54d808249c4fb0 --- src/Common/DelftTools.Shell.Core/ApplicationPlugin.cs (.../ApplicationPlugin.cs) (revision 8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9) +++ src/Common/DelftTools.Shell.Core/ApplicationPlugin.cs (.../ApplicationPlugin.cs) (revision 6b59ea277522a35859f061196c54d808249c4fb0) @@ -6,29 +6,29 @@ namespace DelftTools.Shell.Core { /// - /// Provides default functionality making it easier to implement IPlugin. + /// Provides default functionality making it easier to implement . /// Handles Active status in activate/deactivate. /// public abstract class ApplicationPlugin : IPlugin { /// /// Gets the name of the plugin. - /// The name. + /// public abstract string Name { get; } /// - /// Gets the name of the plugin as displayed in the Gui. - /// The name. + /// Gets the name of the plugin as displayed in the user interface. + /// public abstract string DisplayName { get; } /// - /// Gets the description. - /// The description. + /// Gets the description of the plugin. + /// public abstract string Description { get; } /// /// Gets the version of the plugin. - /// The version. + /// public abstract string Version { get; } /// Index: src/Common/DelftTools.Shell.Core/DelftTools.Shell.Core.csproj =================================================================== diff -u -r8702d012630646100a38f3e7f3e8ea3dd9749718 -r6b59ea277522a35859f061196c54d808249c4fb0 --- src/Common/DelftTools.Shell.Core/DelftTools.Shell.Core.csproj (.../DelftTools.Shell.Core.csproj) (revision 8702d012630646100a38f3e7f3e8ea3dd9749718) +++ src/Common/DelftTools.Shell.Core/DelftTools.Shell.Core.csproj (.../DelftTools.Shell.Core.csproj) (revision 6b59ea277522a35859f061196c54d808249c4fb0) @@ -146,7 +146,6 @@ - @@ -163,7 +162,6 @@ - Index: src/Common/DelftTools.Shell.Core/Extensions/CompositeActivityExtensions.cs =================================================================== diff -u -r8702d012630646100a38f3e7f3e8ea3dd9749718 -r6b59ea277522a35859f061196c54d808249c4fb0 --- src/Common/DelftTools.Shell.Core/Extensions/CompositeActivityExtensions.cs (.../CompositeActivityExtensions.cs) (revision 8702d012630646100a38f3e7f3e8ea3dd9749718) +++ src/Common/DelftTools.Shell.Core/Extensions/CompositeActivityExtensions.cs (.../CompositeActivityExtensions.cs) (revision 6b59ea277522a35859f061196c54d808249c4fb0) @@ -3,16 +3,25 @@ namespace DelftTools.Shell.Core.Extensions { + /// + /// Extension methods for . + /// public static class CompositeActivityExtensions { - public static IEnumerable GetAllActivitiesRecursive(this ICompositeActivity compositeModel) where T : IActivity + /// + /// Gets all activities recursively matching a given type. + /// + /// The type of activity to be matched for. + /// The composite activity. + /// An iterator over all activities implementing/inheriting . + public static IEnumerable GetAllActivitiesRecursive(this ICompositeActivity compositeActivity) where T : IActivity { - if (compositeModel is T) + if (compositeActivity is T) { - yield return (T) compositeModel; + yield return (T) compositeActivity; } - foreach (var subActivity in compositeModel.Activities) + foreach (var subActivity in compositeActivity.Activities) { var compActivity = subActivity as ICompositeActivity; if (compActivity != null) @@ -31,31 +40,5 @@ } } } - - private static ICompositeActivity GetParentActivity(IActivity workflow, IActivity targetActivity) - { - var compositeWorkflow = workflow as ICompositeActivity; - if (compositeWorkflow == null) - { - return null; - } - - foreach (var a in compositeWorkflow.Activities) - { - if (a == targetActivity) - { - return compositeWorkflow; - } - - var parent = GetParentActivity(a, targetActivity); - - if (parent != null) - { - return parent; - } - } - - return null; - } } } \ No newline at end of file Fisheye: Tag 6b59ea277522a35859f061196c54d808249c4fb0 refers to a dead (removed) revision in file `src/Common/DelftTools.Shell.Core/Extensions/FilePathHandler.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 6b59ea277522a35859f061196c54d808249c4fb0 refers to a dead (removed) revision in file `src/Common/DelftTools.Shell.Core/Extensions/ProjectItemExtensions.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: src/Common/DelftTools.Shell.Core/Project.cs =================================================================== diff -u -r5f9327caaaca2d654839bcdcdcf70529e8263d17 -r6b59ea277522a35859f061196c54d808249c4fb0 --- src/Common/DelftTools.Shell.Core/Project.cs (.../Project.cs) (revision 5f9327caaaca2d654839bcdcdcf70529e8263d17) +++ src/Common/DelftTools.Shell.Core/Project.cs (.../Project.cs) (revision 6b59ea277522a35859f061196c54d808249c4fb0) @@ -10,13 +10,6 @@ [Entity(FireOnCollectionChange = false)] public class Project : IObservable { - private string name; - private string description; - - private bool isChanged; - private bool isTemporary; - private bool isMigrated; - /// /// Creates instance of the Project. /// @@ -25,33 +18,25 @@ } /// - /// Creates instance of the Project using the supplied . + /// Creates instance of the project using the supplied . /// /// Readable name of the project. public Project(string name) { - this.name = name; + Name = name; Items = new EventedList(); } /// /// Gets or sets a readable name of the project. /// - public string Name - { - get { return name; } - set { name = value; } - } + public string Name { get; set; } /// /// Gets or sets description of the project. /// - public string Description - { - get { return description; } - set { description = value; } - } + public string Description { get; set; } /// /// The items in the project. @@ -61,20 +46,12 @@ /// /// True if project has changes. /// - public bool IsChanged - { - get { return isChanged; } - set { isChanged = value; } - } + public bool IsChanged { get; set; } /// /// True if project is temporary. /// - public bool IsTemporary - { - get { return isTemporary; } - set { isTemporary = value; } - } + public bool IsTemporary { get; set; } # region IObservable Index: test/Common/DelftTools.Tests/DelftTools.Tests.csproj =================================================================== diff -u -rf3b4a403f57012040e904bb19f7d7bde6e35198c -r6b59ea277522a35859f061196c54d808249c4fb0 --- test/Common/DelftTools.Tests/DelftTools.Tests.csproj (.../DelftTools.Tests.csproj) (revision f3b4a403f57012040e904bb19f7d7bde6e35198c) +++ test/Common/DelftTools.Tests/DelftTools.Tests.csproj (.../DelftTools.Tests.csproj) (revision 6b59ea277522a35859f061196c54d808249c4fb0) @@ -179,7 +179,9 @@ True Resources.resx + + Index: test/Common/DelftTools.Tests/Shell/Core/ApplicationPluginTest.cs =================================================================== diff -u --- test/Common/DelftTools.Tests/Shell/Core/ApplicationPluginTest.cs (revision 0) +++ test/Common/DelftTools.Tests/Shell/Core/ApplicationPluginTest.cs (revision 6b59ea277522a35859f061196c54d808249c4fb0) @@ -0,0 +1,140 @@ +using System.Linq; + +using DelftTools.Shell.Core; + +using NUnit.Framework; + +namespace DelftTools.Tests.Shell.Core +{ + [TestFixture] + public class ApplicationPluginTest + { + [Test] + public void DefaultConstructor_ExpectedValues() + { + // call + var applicationPlugin = new SimpleApplicationPlugin(); + + // assert + Assert.IsFalse(applicationPlugin.IsActive); + Assert.IsNull(applicationPlugin.Image); + Assert.IsNull(applicationPlugin.Resources); + Assert.IsNull(applicationPlugin.Application); + CollectionAssert.IsEmpty(applicationPlugin.DependentPluginNames); + } + + [Test] + public void GetFileImporters_ReturnEmptyEnummerable() + { + // setup + var applicationPlugin = new SimpleApplicationPlugin(); + + // call + var importers = applicationPlugin.GetFileImporters().ToArray(); + + // assert + CollectionAssert.IsEmpty(importers); + } + + [Test] + public void GetFileExporters_ReturnEmptyEnummerable() + { + // setup + var applicationPlugin = new SimpleApplicationPlugin(); + + // call + var importers = applicationPlugin.GetFileExporters().ToArray(); + + // assert + CollectionAssert.IsEmpty(importers); + } + + [Test] + public void GetDataItemInfos_ReturnEmptyEnummerable() + { + // setup + var applicationPlugin = new SimpleApplicationPlugin(); + + // call + var importers = applicationPlugin.GetDataItemInfos().ToArray(); + + // assert + CollectionAssert.IsEmpty(importers); + } + + [Test] + public void GetPersistentAssemblies_ReturnEmptyEnummerable() + { + // setup + var applicationPlugin = new SimpleApplicationPlugin(); + + // call + var importers = applicationPlugin.GetPersistentAssemblies().ToArray(); + + // assert + CollectionAssert.IsEmpty(importers); + } + + [Test] + public void Activate_PluginWasNotActivated_SetIsActiveTrue() + { + // setup + var applicationPlugin = new SimpleApplicationPlugin(); + + // call + applicationPlugin.Activate(); + + // assert + Assert.IsTrue(applicationPlugin.IsActive); + } + + [Test] + public void Deactivate_PluginWasActivated_SetIsActiveFalse() + { + // setup + var applicationPlugin = new SimpleApplicationPlugin(); + applicationPlugin.Activate(); + + // call + applicationPlugin.Deactivate(); + + // assert + Assert.IsFalse(applicationPlugin.IsActive); + } + } + + class SimpleApplicationPlugin : ApplicationPlugin + { + public override string Name + { + get + { + throw new System.NotImplementedException(); + } + } + + public override string DisplayName + { + get + { + throw new System.NotImplementedException(); + } + } + + public override string Description + { + get + { + throw new System.NotImplementedException(); + } + } + + public override string Version + { + get + { + throw new System.NotImplementedException(); + } + } + } +} \ No newline at end of file Index: test/Common/DelftTools.Tests/Shell/Core/Extensions/CompositeActivityExtensionsTest.cs =================================================================== diff -u --- test/Common/DelftTools.Tests/Shell/Core/Extensions/CompositeActivityExtensionsTest.cs (revision 0) +++ test/Common/DelftTools.Tests/Shell/Core/Extensions/CompositeActivityExtensionsTest.cs (revision 6b59ea277522a35859f061196c54d808249c4fb0) @@ -0,0 +1,147 @@ +using System.Linq; + +using DelftTools.Shell.Core.Extensions; +using DelftTools.Shell.Core.Workflow; +using DelftTools.Utils.Collections.Generic; + +using NUnit.Framework; + +using Rhino.Mocks; + +namespace DelftTools.Tests.Shell.Core.Extensions +{ + [TestFixture] + public class CompositeActivityExtensionsTest + { + [Test] + public void GetAllActivitiesRecursive_CompositeActivityWithoutChildren_ReturnOnlyCompositeActivity() + { + // setup + var activitiesList = new EventedList(); + + var mocks = new MockRepository(); + var compositeActivityMock = mocks.StrictMock(); + compositeActivityMock.Expect(ca => ca.Activities).Return(activitiesList); + mocks.ReplayAll(); + + // call + var allActivities = compositeActivityMock.GetAllActivitiesRecursive().ToArray(); + + // assert + CollectionAssert.AreEqual(new[] { compositeActivityMock }, allActivities); + mocks.VerifyAll(); + } + + [Test] + public void GetAllActivitiesRecursive_CompositeActivityWithoutChildrenNotMatchingRequestedActivityType_ReturnEmptyEnummerable() + { + // setup + var activitiesList = new EventedList(); + + var mocks = new MockRepository(); + var compositeActivityMock = mocks.StrictMock(); + compositeActivityMock.Expect(ca => ca.Activities).Return(activitiesList); + mocks.ReplayAll(); + + // call + var allActivities = compositeActivityMock.GetAllActivitiesRecursive().ToArray(); + + // assert + CollectionAssert.IsEmpty(allActivities); + mocks.VerifyAll(); + } + + [Test] + public void GetAllActivitiesRecursive_CompositeActivityWithChildren_ReturnCompositeActivityAndChildren() + { + // setup + var activitiesList = new EventedList(); + + var mocks = new MockRepository(); + var compositeActivityMock = mocks.StrictMock(); + compositeActivityMock.Expect(ca => ca.Activities).Return(activitiesList); + var childActivity1 = mocks.StrictMock(); + var childActivity2 = mocks.StrictMock(); + mocks.ReplayAll(); + + activitiesList.AddRange(new[] { childActivity1, childActivity2 }); + + // call + var allActivities = compositeActivityMock.GetAllActivitiesRecursive().ToArray(); + + // assert + var expected = new[] { compositeActivityMock, childActivity1, childActivity2 }; + CollectionAssert.AreEqual(expected, allActivities); + mocks.VerifyAll(); + } + + [Test] + public void GetAllActivitiesRecursive_CompositeActivityWithSomeChildrenMatching_ReturnOnlyMatchingChildren() + { + // setup + var activitiesList = new EventedList(); + + var mocks = new MockRepository(); + var compositeActivityMock = mocks.StrictMock(); + compositeActivityMock.Expect(ca => ca.Activities).Return(activitiesList); + var childActivity1 = mocks.StrictMock(); + var childActivity2 = mocks.StrictMock(); + mocks.ReplayAll(); + + activitiesList.AddRange(new[] { childActivity1, childActivity2 }); + + // call + var allActivities = compositeActivityMock.GetAllActivitiesRecursive().ToArray(); + + // assert + CollectionAssert.AreEqual(new[] { childActivity2 }, allActivities); + mocks.VerifyAll(); + } + + [Test] + public void GetAllActivitiesRecursive_NestedCompositeActivities_ReturnAllActivities() + { + // setup + var activitiesList1 = new EventedList(); + var activitiesList2 = new EventedList(); + var activitiesList3 = new EventedList(); + + var mocks = new MockRepository(); + var compositeActivityMock1 = mocks.StrictMock(); + compositeActivityMock1.Expect(ca => ca.Activities).Return(activitiesList1); + + var childActivity1 = mocks.StrictMock(); + childActivity1.Expect(ca => ca.Activities).Return(activitiesList2); + + var childActivity2 = mocks.StrictMock(); + childActivity2.Expect(ca => ca.Activities).Return(activitiesList3); + + var sub1ChildActivity1 = mocks.StrictMock(); + var sub1ChildActivity2 = mocks.StrictMock(); + + var sub2ChildActivity1 = mocks.StrictMock(); + var sub2ChildActivity2 = mocks.StrictMock(); + + mocks.ReplayAll(); + + activitiesList1.AddRange(new[] { childActivity1, childActivity2 }); + activitiesList2.AddRange(new[] { sub1ChildActivity1, sub1ChildActivity2 }); + activitiesList3.AddRange(new[] { sub2ChildActivity1, sub2ChildActivity2 }); + + // call + var allActivities = compositeActivityMock1.GetAllActivitiesRecursive().ToArray(); + + // assert + var expected = new[] { compositeActivityMock1, + childActivity1, sub1ChildActivity1, sub1ChildActivity2, + childActivity2, sub2ChildActivity1, sub2ChildActivity2 }; + CollectionAssert.AreEqual(expected, allActivities); + mocks.VerifyAll(); + } + + public interface ISomeActivity : IActivity + { + + } + } +} \ No newline at end of file Index: test/Common/DelftTools.Tests/Shell/Core/ProjectTest.cs =================================================================== diff -u -r8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9 -r6b59ea277522a35859f061196c54d808249c4fb0 --- test/Common/DelftTools.Tests/Shell/Core/ProjectTest.cs (.../ProjectTest.cs) (revision 8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9) +++ test/Common/DelftTools.Tests/Shell/Core/ProjectTest.cs (.../ProjectTest.cs) (revision 6b59ea277522a35859f061196c54d808249c4fb0) @@ -1,23 +1,111 @@ +using System.ComponentModel; + using DelftTools.Shell.Core; + using NUnit.Framework; +using Rhino.Mocks; + namespace DelftTools.Tests.Shell.Core { [TestFixture] public class ProjectTest { [Test] - public void CreateWithDefaultName() + public void DefaultConstructor_ExpectedValue() { + // call var project = new Project(); + + // assert + Assert.IsInstanceOf(project); + Assert.IsInstanceOf(project); + Assert.IsInstanceOf(project); + Assert.AreEqual("Project", project.Name); + Assert.IsNull(project.Description); + CollectionAssert.IsEmpty(project.Items); + Assert.IsFalse(project.IsChanged); + Assert.IsFalse(project.IsTemporary); } [Test] - public void CreateWithCustomName() + public void NameConstructor_SetNameAndInitializeOtherProperties() { - var project = new Project("Test Project"); - Assert.AreEqual(project.Name, "Test Project"); + // setup + const string someName = ""; + + // call + var project = new Project(someName); + + // assert + Assert.AreEqual(someName, project.Name); + Assert.IsNull(project.Description); + CollectionAssert.IsEmpty(project.Items); + Assert.IsFalse(project.IsChanged); + Assert.IsFalse(project.IsTemporary); } + + [Test] + public void AutomaticProperties_SetAndGettingValue_ShouldReturnSetValue() + { + // setup & Call + const string niceProjectName = "Nice project name"; + const string nicerDescription = "Nicer description"; + + var project = new Project + { + Name = niceProjectName, + Description = nicerDescription, + IsChanged = true, + IsTemporary = true + }; + + // assert + Assert.AreEqual(niceProjectName, project.Name); + Assert.AreEqual(nicerDescription, project.Description); + Assert.IsTrue(project.IsChanged); + Assert.IsTrue(project.IsTemporary); + } + + [Test] + public void NotifyObservers_WithObserverAttached_ObserverIsNotified() + { + // setup + var mocks = new MockRepository(); + var observerMock = mocks.StrictMock(); + observerMock.Expect(o => o.UpdateObserver()); + mocks.ReplayAll(); + + var project = new Project(); + project.Attach(observerMock); + + // call + project.NotifyObservers(); + + // assert + mocks.VerifyAll(); + } + + [Test] + public void NotifyObservers_AttachedObserverHasBeenDetached_ObserverShouldNoLongerBeNotified() + { + // setup + var mocks = new MockRepository(); + var observerMock = mocks.StrictMock(); + observerMock.Expect(o => o.UpdateObserver()).Repeat.Once(); + mocks.ReplayAll(); + + var project = new Project(); + project.Attach(observerMock); + project.NotifyObservers(); + + // call + project.Detach(observerMock); + project.NotifyObservers(); + + // assert + mocks.VerifyAll(); + } } } \ No newline at end of file