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)); } }
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)); } }
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); } }
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); } }
public void CollectionSortHandler_CollectionSortHandler_PassNullWriterInConstructor_ThrowArgumentNullException() { using (ShimsContext.Create()) { // // Arrange. // var parser = new StubIDataParser <double>(); var reader = new StubDataReader(new StubIValidator()); ShimDataWriter <double> writer = null; // // Assert. // Assert.ThrowsException <ArgumentNullException>(() => new CollectionSortHandler <double>(reader, writer, parser)); } }
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()); } }
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)); } }