Beispiel #1
0
        public void CollectionSortHandler_Write_LeftEmptySortedCollection_ThrowArgumentNullException()
        {
            using (ShimsContext.Create())
            {
                //
                // Arrange.
                //
                var path   = Path.GetTempPath();
                var parser = new StubIDataParser <double>();
                var reader = new ShimDataReader();
                var writer = new ShimDataWriter <double>()
                {
                    WriteContentT0Array = (array) => throw new ArgumentNullException()
                };
                CollectionSortHandler <double> collectionSortHandler;

                //
                // Act.
                //
                collectionSortHandler = new CollectionSortHandler <double>(reader, writer, parser);

                //
                // Assert.
                //
                Assert.ThrowsException <ArgumentNullException>(() => collectionSortHandler.Write(path));
            }
        }
Beispiel #2
0
        public void CollectionSortHandler_Read_PassIncorrectPathToTheFile_ThrowException()
        {
            using (ShimsContext.Create())
            {
                //
                // Arrange.
                //
                CollectionSortHandler <int> collectionSortHandler;
                var path   = Path.GetTempPath();
                var parser = new StubIDataParser <int>();
                var writer = new ShimDataWriter <int>();
                var reader = new ShimDataReader()
                {
                    ReadContentString = (str) => throw new ArgumentNullException()
                };

                //
                // Act.
                //
                collectionSortHandler = new CollectionSortHandler <int>(reader, writer, parser);

                //
                // Assert.
                //
                Assert.ThrowsException <Exception>(() => collectionSortHandler.Read(path));
            }
        }
Beispiel #3
0
        public void CollectionSortHandler_Read_PassCorrectPathToTheFile_GetCorrectContent()
        {
            using (ShimsContext.Create())
            {
                //
                // Arrange.
                //
                int[] actualCollection;
                var   expectedCollection = new int[] { 125, 12, 33 };
                var   parser             = new StubIDataParser <int>()
                {
                    ConvertDataString = (str) => expectedCollection
                };
                var path   = Path.GetTempPath();
                var reader = new ShimDataReader();
                var writer = new ShimDataWriter <int>();
                CollectionSortHandler <int> collectionSortHandler;

                //
                // Act.
                //
                collectionSortHandler = new CollectionSortHandler <int>(reader, writer, parser);
                collectionSortHandler.Read(path);
                actualCollection = collectionSortHandler.UnSortedCollection;

                //
                // Assert.
                //
                Assert.AreEqual(expectedCollection, actualCollection);
            }
        }
Beispiel #4
0
        public void CollectionSortHandler_Execute_PassSelectionSortType_GetSortedCollection()
        {
            using (ShimsContext.Create())
            {
                //
                // Arrange.
                //
                var expectedCollection = new double[] { 1.5, 4, 11, 56, 166 };
                var sorterType         = SortType.SelectionSort;
                var path   = Path.GetTempPath();
                var parser = new StubIDataParser <double>()
                {
                    ConvertDataString = (str) => new double[] { 166, 11, 56, 4, 1.5 }
                };
                var reader = new ShimDataReader();
                var writer = new ShimDataWriter <double>();
                CollectionSortHandler <double> collectionSortHandler;
                bool isCollectionSorted;

                //
                // Act.
                //
                collectionSortHandler = new CollectionSortHandler <double>(reader, writer, parser);
                collectionSortHandler.GenerateSorter(sorterType);
                collectionSortHandler.Read(path);
                collectionSortHandler.Execute();
                isCollectionSorted = collectionSortHandler.SortedCollection.SequenceEqual(expectedCollection);

                //
                // Assert.
                //
                Assert.IsTrue(isCollectionSorted);
            }
        }
Beispiel #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CollectionSortingViewModel{T}"/> class.
 /// </summary>
 /// <owner>Anton Petrenko</owner>
 public CollectionSortingViewModel()
 {
     this.handler = new CollectionSortHandler <T>
                        (new DataReader(new LocalFileValidator()), new DataWriter <T>(), new ArrayParser <T>());
     this.UnSortedCollectionOfNumbers = new ObservableCollection <T>();
     this.SortedCollectionOfNumbers   = new ObservableCollection <T>();
 }
Beispiel #6
0
        public void CollectionSortHandler_Execute_LeftEmptyUnsortedCollection_ThrowException()
        {
            using (ShimsContext.Create())
            {
                //
                // Arrange.
                //
                var parser = new StubIDataParser <double>();
                var reader = new ShimDataReader();
                var writer = new ShimDataWriter <double>();
                CollectionSortHandler <double> collectionSortHandler;

                //
                // Act.
                //
                collectionSortHandler = new CollectionSortHandler <double>(reader, writer, parser);

                //
                // Assert.
                //
                Assert.ThrowsException <Exception>(() => collectionSortHandler.Execute());
            }
        }
Beispiel #7
0
        public void CollectionSortHandler_Write_PassEmptyPath_ThrowArgumentNullException()
        {
            using (ShimsContext.Create())
            {
                //
                // Arrange.
                //
                var parser = new StubIDataParser <double>();
                var reader = new ShimDataReader();
                var writer = new ShimDataWriter <double>();
                CollectionSortHandler <double> collectionSortHandler;

                //
                // Act.
                //
                collectionSortHandler = new CollectionSortHandler <double>(reader, writer, parser);

                //
                // Assert.
                //
                Assert.ThrowsException <ArgumentNullException>(() => collectionSortHandler.Write(null));
            }
        }