Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            try
            {
                IInstanceService instanceService = new InstanceService();

                var types       = instanceService.GetInstances <Vehicle>();
                var sortedTypes = types.OrderBy(x => x.Name);
                foreach (var type in sortedTypes)
                {
                    Console.WriteLine(type.Name);
                }
                Console.WriteLine("== end ==");

                //iTypesToDiskService diskService = new TypesToDiskService();
                //await diskService.SaveTypes(types, filePath);

                //var search = instanceService.SearchTypesByName<Vehicle>("c");
                //foreach (var item in search)
                //{
                //    Console.WriteLine(item);
                //}

                Console.ReadKey();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unhandled exception occured!");
                //loger.Log(ex);
            }
        }
        public void ShouldReturnValidInstancesCount()
        {
            //Arrange
            var assembly = typeof(Vehicle).Assembly;
            var types    = assembly.GetTypes().Where(t => t.BaseType == typeof(Vehicle));
            //Act
            var instances = InstanceService <Vehicle> .GetInstances();

            //Assert
            Assert.IsTrue(types.Count() == instances.Count());
        }
Ejemplo n.º 3
0
        public void VerifyInstanceCountViaClass_ReturnsOne()
        {
            // Arrange
            var service  = new InstanceService();
            var expected = 1;

            // Act
            var vehicle = service.GetInstances <Bicycle>();
            var actual  = vehicle.Count();

            // Assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 4
0
        public void VerifyInstanceCountViaAbstract_ReturnsFour()
        {
            // Arrange
            var service  = new InstanceService();
            var expected = 4;

            // Act
            var vehicles = service.GetInstances <Vehicle>();
            var actual   = vehicles.Count();

            // Assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            //Task 2 - Get instances of Vehicle
            IEnumerable <Vehicle> vehicles = InstanceService.GetInstances <Vehicle>();

            Console.WriteLine("Vehicle names:");
            //Task 3.1 - Writing vehicle types sorted alphabetically
            foreach (var vehicle in vehicles.OrderBy(key => key.Name).Select(v => v))
            {
                Type vehicleType = vehicle.GetType();
                Console.WriteLine(vehicleType.Name);
            }
            //Task 3.2 - Search for types by specifying part of the name
            string partName = "CaR";

            Console.WriteLine("Method for searching types by part of name: {0}", partName);
            IEnumerable <Vehicle> startsWithBiVehicles = vehicles.SearchType(partName);

            foreach (var vehicle in startsWithBiVehicles)
            {
                Type vehicleType = vehicle.GetType();
                Console.WriteLine(vehicleType.Name);
            }
            //Task 3.3 - Save vehicles to disk
            vehicles.WriteInstancesToDisk();
            //Task 4.1 - ReverseString
            string str1 = "1234";

            Console.WriteLine("Reversed string {0}: {1}", str1, MyString.ReverseString(str1));
            Console.WriteLine("Reversed string (extension) {0}: {1}", str1, str1.ReverseString());
            //Task 4.2 - Using IsPalindrome
            str1 = "lol";
            Console.WriteLine("IsPalindrome {0}: {1}", str1, MyString.IsPalindrome(str1));
            Console.WriteLine("IsPalindrome (extension) {0}: {1}", str1, str1.IsPalindrome());
            //Task 4.3 - MissingElements
            int[] inputarr = new int[] { 1, 3, 4 };
            Console.Write("Missing elements for input: ");
            foreach (var item in inputarr)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();
            foreach (var missing in MissingElems.MissingElements(inputarr))
            {
                Console.Write(missing + " ");
            }
            Console.ReadKey();
        }
Ejemplo n.º 6
0
        public void SaveToJsonFile_ReadJsonString()
        {
            // Arrange
            var persistance = new PersistanceService();
            var service     = new InstanceService();
            var path        = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"Data.json");

            // Act
            var vehicles = service.GetInstances <IVehicle>();

            persistance.SaveToJson(path, vehicles);
            var expected = JsonConvert.SerializeObject(vehicles);
            var actual   = persistance.GetJsonStringFromFile(path);

            // Assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 7
0
        public void SearchForCycle_ReturnsBicycleAndMotorcycle()
        {
            // Arrange
            var service    = new InstanceService();
            var searchTerm = "Cycle";

            // Act
            var vehicles   = service.GetInstances <IVehicle>();
            var enumerable = vehicles.ToList();
            var expected   = enumerable.Select(x => x).Where(x => x.GetType().Name == nameof(Bicycle) || x.GetType().Name == nameof(Motorcycle)).ToList();
            var actual     = enumerable.FindElements(inputs =>
            {
                var output = inputs.Where(x => x.GetType().Name.ToLowerInvariant().Contains(searchTerm.ToLowerInvariant()))
                             .ToList();
                return(output);
            }).ToList();

            // Assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 8
0
        public void GetInstancesTest()
        {
            InstanceService <Vehicle> instanceService = new InstanceService <Vehicle>();
            var         instances = instanceService.GetInstances();
            List <Type> expected  = new List <Type>()
            {
                typeof(VehicleHotAirBalloon), typeof(VehicleSkateboard), typeof(VehicleTank), typeof(VehicleTeleporter)
            };

            if (instances.Count() != expected.Count)
            {
                Assert.IsFalse(true, "Incorrect number of results found");
                return;
            }
            foreach (Type item in instances)
            {
                if (!expected.Contains(item))
                {
                    Assert.IsFalse(true, "Found result not supposed to be there");
                    return;
                }
            }
            Assert.IsFalse(false, "All expected elements found");
        }