Exemplo n.º 1
0
        private static void Main()
        {
            IServiceCollection serviceCollection = new ServiceCollection()
                                                   .AddLogging(configure => configure.AddConsole())
                                                   .AddPlugins(AppDomain.CurrentDomain.BaseDirectory);

            ServiceProvider serviceProvider = serviceCollection.BuildServiceProvider(new ServiceProviderOptions
            {
                ValidateScopes  = true,
                ValidateOnBuild = true
            });

            var pluginDictionary = serviceProvider
                                   .GetServices <IPlugin>()
                                   .ToDictionary(k => k.GetType().GetAssemblyName(), v => v);

            var sortServiceDictionary = serviceProvider
                                        .GetServices <ISortService>()
                                        .ToDictionary(k => k.GetType().GetAssemblyName(), v => v);

            foreach ((string assemblyName, IPlugin plugin) in pluginDictionary)
            {
                ISortService sortService = sortServiceDictionary[assemblyName];
                var          sortedArray = sortService.Sort((int[])Data.Clone());

                Console.WriteLine($"Name: {plugin.Name}");
                Console.WriteLine($"Results: {string.Join(", ", sortedArray)}");
            }
        }
Exemplo n.º 2
0
        public void TestSelectionSort(long[] input, long[] ordered)
        {
            ArrayList expected = new ArrayList(ordered);

            ArrayList result = _selectionSortService.Sort(new ArrayList(input));

            Assert.Equal(expected, result);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Exercise2([FromQuery] string sortOption)
        {
            var products = await _productsClient.GetProducts();

            var sortedProducts = await _sortService.Sort(sortOption, products);

            return(Content(JsonConvert.SerializeObject(sortedProducts)));
        }
        public void AddressSortServiceWillSortContactList()
        {
            //we pass in a collection with 1 element to avoid the argument null exception
            //the address parser mock will always return a predefined list of parsed contact entries
            //this enables is to test only the sort logic as the parse logic is tested elseware
            var res = _addressSort.Sort(new List <ContactEntry>()
            {
                new ContactEntry()
                {
                    Address = "1 test street"
                }
            }).ToList();

            Assert.IsNotNull(res);
            Assert.IsTrue(res.Count() == 7);
            Assert.IsTrue(res[0].StreetName == "A Road" && res[0].StreetNumber == "7");
            Assert.IsTrue(res[6].StreetName == "G Road" && res[6].StreetNumber == "1");
        }
        public void WhenPropertyNotProvided_SortsByIdAscending()
        {
            //Arrange
            var source = Builder <SortContext.DummyClassWithId> .CreateListOfSize(2)
                         .TheFirst(1)
                         .With(x => x.Id = 33)
                         .TheNext(1)
                         .With(x => x.Id = 5)
                         .Build();

            //Act
            var result = _sortService.Sort(source, new Sort());

            //Assert
            result.Should().BeInAscendingOrder(x => x.Id);
        }
Exemplo n.º 6
0
        public void WhenIdNotFound_DoesNotSort()
        {
            //Arrange
            var source = Builder <SortContext.DummyClassWithId> .CreateListOfSize(2)
                         .All()
                         .With(x => x.DummyClass = Builder <SortContext.DummyClass> .CreateNew().Build())
                         .TheFirst(1)
                         .With(x => x.Id = 7)
                         .TheNext(1)
                         .With(x => x.Id = 5)
                         .Build();

            //Act
            var result = _sortService.Sort(source, new Sort {
                SortColumn = "DummyClass"
            });

            //Assert
            result.Should().BeInDescendingOrder(x => x.Id);
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            _serviceProvider = RegisterServices();

            ISortService _sortService = _serviceProvider.GetService <ISortService>();

            var result = _sortService.Sort("Contrary to popular belief, the pink unicorn flies east.");

            Console.WriteLine($"Result is: { result }");
            Console.Read();

            DisposeServices();
        }
Exemplo n.º 8
0
        public IEnumerable <Tag> GetTags(string sort = null, string search = null)
        {
            IQueryable <Tag> tags = _context.Tags;

            if (search != null)
            {
                search = search.ToLower();
                tags   = tags
                         .Where(x => x.Name.ToLower().Contains(search));
            }
            tags = _sortService.Sort(tags, sort);
            return(tags.ToList());
        }
Exemplo n.º 9
0
        void ShouldSortFiles()
        {
            DataService.Data.PrepareFolder(Params.SourceFolder);
            DataService.Data.PrepareFiles(20, 5, Params.SourceFolder);
            Service.Sort(Params);
            var actualTotal = Service.Total;
            var actualReady = Service.Ready;
            var files       = Directory.GetFiles(Params.TargetFolder, "*", SearchOption.AllDirectories);

            Assert.Equal(files.Length, actualTotal);
            Assert.Equal(files.Length, actualReady);
            Assert.Equal(actualTotal, actualReady);
            DataService.Data.Dispose();
        }
Exemplo n.º 10
0
        public void NameSortServiceWillSortContactList()
        {
            var contactList = new List <ContactEntry>
            {
                new ContactEntry {
                    FirstName = "Jimmy", LastName = "Smith"
                },
                new ContactEntry {
                    FirstName = "Clive", LastName = "Owen"
                },
                new ContactEntry {
                    FirstName = "James", LastName = "Brown"
                },
                new ContactEntry {
                    FirstName = "Graham", LastName = "Howe"
                },
                new ContactEntry {
                    FirstName = "John", LastName = "Howe"
                },
                new ContactEntry {
                    FirstName = "Clive", LastName = "Smith"
                },
                new ContactEntry {
                    FirstName = "James", LastName = "Owen"
                },
                new ContactEntry {
                    FirstName = "Graham", LastName = "Brown"
                }
            };

            var res = _nameSort.Sort(contactList).ToList();

            Assert.IsNotNull(res);
            Assert.IsTrue(res.Count() == 9);
            Assert.IsTrue(res[0].Name == "Brown" && res[0].Count == 2);
            Assert.IsTrue(res[8].Name == "John" && res[8].Count == 1);
        }
Exemplo n.º 11
0
        public IEnumerable <ArtistListViewModel> GetArtists(string sort = null, string search = null)
        {
            IQueryable <Artist> artistsDal = _context.Artists;

            if (search != null)
            {
                search     = search.ToLower();
                artistsDal = artistsDal
                             .Where(x => x.Name.ToLower().Contains(search));
            }
            var artists = _sortService.Sort(artistsDal, sort)
                          .ToList();

            return(Mapper.Map <List <ArtistListViewModel> >(artists));
        }
Exemplo n.º 12
0
        public IEnumerable <AlbumListViewModel> GetAlbums(string sort = null, string search = null)
        {
            var albumsDal = _context.Albums
                            .Include(x => x.Author);

            if (search != null)
            {
                search    = search.ToLower();
                albumsDal = albumsDal
                            .Where(x => x.Title.ToLower().Contains(search));
            }
            var albums = _sortService.Sort(albumsDal, sort)
                         .ToList();

            return(Mapper.Map <IEnumerable <AlbumListViewModel> >(albums));
        }
        public void WhenSourceIsEmpty()
        {
            //Arrange
            var source = (ICollection <SortContext.DummyClass>)Enumerable.Empty <SortContext.DummyClass>();
            var sort   = new Sort {
                SortColumn = "email"
            };

            //Act
            var result = _sortService.Sort(source, sort);

            //Assert
            result.Should().BeEmpty();
        }
Exemplo n.º 14
0
        public IActionResult DoSort([FromBody] long[] sortRequest)
        {
            //TODO: In a more complex solution it would be logical to
            //make sorting an async task and immediately return status
            //(that posting was successful or not). Sorting status storing
            //and retrieving also would be needed for user information.
            _logger.LogInformation("A new set of numbers posted for sorting.");
            if (sortRequest.Length != 0)
            {
                var       watch         = Stopwatch.StartNew();
                ArrayList sortedNumbers = _sortService.Sort(new ArrayList(sortRequest));
                watch.Stop();
                var performance = watch.ElapsedMilliseconds;
                _storageService.StoreNewResult(sortedNumbers);
                _storageService.StorePerformance(performance);
                return(Ok("Array is sorted and saved, to retrieve it, call GET endpoint. Call GET /performance to see the latest sorting performance."));
            }

            return(BadRequest("Array cannot be empty."));
        }
Exemplo n.º 15
0
        public async Task Given_ValidInputs_When_Sort_Returns_SortedProducts()
        {
            // Arrange.
            _productSort1.SupportedSortOptions.Returns(new List <SortOptions> {
                SortOptions.ASCENDING, SortOptions.DESCENDING
            });
            _productSort2.SupportedSortOptions.Returns(new List <SortOptions> {
                SortOptions.HIGH, SortOptions.LOW
            });

            var products = _fixture.CreateMany <Product>(5).ToList();

            _productsRepository.Get(Arg.Any <string>()).Returns(products);

            _productSort1.Sort(Arg.Any <SortOptions>(), Arg.Is <List <Product> >(products)).Returns(products);

            // Act.
            var result = await _sut.Sort("ASCENDING");

            // Assert.
            result.SequenceEqual(products);
        }
Exemplo n.º 16
0
 public async Task <IActionResult> Get(
     [FromQuery]
     [Required]
     [SortOptionValidator]
     string sortOption)
 => Ok(await _sortService.Sort(sortOption.ToUpperInvariant()));
Exemplo n.º 17
0
 public List <Parcel> Sort(List <Parcel> parcelsToSort)
 {
     return(_sortService.Sort(parcelsToSort));
 }