public void ReplaceData_Always_CallsClearData()
        {
            // Setup
            var collection = new TestUniqueItemCollection();
            var strategy   = new ConcreteStrategyClass(new TestFailureMechanism(), collection);

            // Call
            strategy.ConcreteReplaceData(Enumerable.Empty <TestItem>(), "some/source");

            // Assert
            Assert.IsTrue(strategy.IsClearDataCalled);
        }
        public void ReplaceData_ImportedDataCollectionNull_ThrowsArgumentNullException()
        {
            // Setup
            var collection = new TestUniqueItemCollection();
            var strategy   = new ConcreteStrategyClass(new TestFailureMechanism(), collection);

            // Call
            void Call() => strategy.ConcreteReplaceData(null, string.Empty);

            // Assert
            string paramName = Assert.Throws <ArgumentNullException>(Call).ParamName;

            Assert.AreEqual("importedDataCollection", paramName);
        }
        public void ReplaceData_SourceFilePathNull_ThrowsArgumentNullException()
        {
            // Setup
            var collection = new TestUniqueItemCollection();
            var strategy   = new ConcreteStrategyClass(new TestFailureMechanism(), collection);

            // Call
            void Call() => strategy.ConcreteReplaceData(Enumerable.Empty <TestItem>(), null);

            // Assert
            string paramName = Assert.Throws <ArgumentNullException>(Call).ParamName;

            Assert.AreEqual("sourceFilePath", paramName);
        }
        public void ReplaceData_Always_CalledWithExpectedFailureMechanism()
        {
            // Setup
            var failureMechanism = new TestFailureMechanism();
            var collection       = new TestUniqueItemCollection();
            var strategy         = new ConcreteStrategyClass(failureMechanism, collection);

            TestUniqueItemCollection[] expectedObservables =
            {
                collection
            };
            strategy.ClearDataReturnedList = expectedObservables;

            // Call
            IObservable[] affectedObjects = strategy.ConcreteReplaceData(Enumerable.Empty <TestItem>(),
                                                                         "some/source").ToArray();

            // Assert
            Assert.AreSame(failureMechanism, strategy.ClearDataFailureMechanism);
            CollectionAssert.AreEqual(expectedObservables, affectedObjects);
        }
        public void ReplaceData_ImportedDataCollectionAndValidSourcePath_UpdatesTargetCollectionAndSourcePath()
        {
            // Setup
            var collection = new TestUniqueItemCollection();
            var strategy   = new ConcreteStrategyClass(new TestFailureMechanism(), collection);

            var itemsToAdd = new[]
            {
                new TestItem("Item A"),
                new TestItem("Item B")
            };

            const string expectedSourcePath = "some/source";

            // Call
            strategy.ConcreteReplaceData(itemsToAdd, expectedSourcePath);

            // Assert
            CollectionAssert.AreEqual(itemsToAdd, collection);
            Assert.AreEqual(expectedSourcePath, collection.SourcePath);
        }
        public void ReplaceData_InvalidSourceFilePath_ThrowsUpdateDataException(string invalidPath)
        {
            // Setup
            var collection = new TestUniqueItemCollection();
            var strategy   = new ConcreteStrategyClass(new TestFailureMechanism(), collection);

            const string duplicateName = "Item A";
            var          itemsToAdd    = new[]
            {
                new TestItem(duplicateName),
                new TestItem(duplicateName)
            };

            // Call
            void Call() => strategy.ConcreteReplaceData(itemsToAdd, invalidPath);

            // Assert
            CollectionAssert.IsEmpty(collection);

            var exception = Assert.Throws <UpdateDataException>(Call);

            Assert.IsInstanceOf <ArgumentException>(exception.InnerException);
        }
        public void ReplaceData_ImportedDataCollectionContainsNull_ThrowsUpdateDataException()
        {
            // Setup
            var collection = new TestUniqueItemCollection();
            var strategy   = new ConcreteStrategyClass(new TestFailureMechanism(), collection);

            var itemsToAdd = new[]
            {
                new TestItem("Item A"),
                new TestItem("Item B"),
                null
            };

            // Call
            void Call() => strategy.ConcreteReplaceData(itemsToAdd, "some/source");

            // Assert
            CollectionAssert.IsEmpty(collection);

            var exception = Assert.Throws <UpdateDataException>(Call);

            Assert.IsInstanceOf <ArgumentException>(exception.InnerException);
        }
        public void ReplaceData_ImportedDataCollectionContainsDuplicateItems_ThrowsUpdateDataException()
        {
            // Setup
            var collection = new TestUniqueItemCollection();
            var strategy   = new ConcreteStrategyClass(new TestFailureMechanism(), collection);

            const string duplicateName = "Item A";
            var          itemsToAdd    = new[]
            {
                new TestItem(duplicateName),
                new TestItem(duplicateName)
            };

            // Call
            TestDelegate call = () => strategy.ConcreteReplaceData(itemsToAdd, "some/source");

            // Assert
            CollectionAssert.IsEmpty(collection);
            var    exception       = Assert.Throws <UpdateDataException>(call);
            string expectedMessage = $"TestItem moeten een unieke naam hebben. Gevonden dubbele elementen: {duplicateName}.";

            Assert.AreEqual(expectedMessage, exception.Message);
            Assert.IsInstanceOf <ArgumentException>(exception.InnerException);
        }