Esempio n. 1
0
        public void ShouldLoadLazyObjects2()
        {
            var content =
                @"Discriminator,Engine
                Car,{new Gears.Interpreter.Tests.Pages.Iteration5Tests.Engine(){Power=5}}
                Apple,None
                ";

            var path = _inputFolder + "\\Scenario4.csv";

            File.WriteAllText(path, content);

            Bootstrapper.Register();
            ServiceLocator.Instance.Resolve <ITypeRegistry>().Register(typeof(Car));
            ServiceLocator.Instance.Resolve <ITypeRegistry>().Register(typeof(Apple));

            var obj = new FileObjectAccess(path, ServiceLocator.Instance.Resolve <ITypeRegistry>()).GetAll().First();

            Assert.IsNotInstanceOf <CorruptObject>(obj, obj.ToString());
            Assert.IsInstanceOf <Car>(obj);
            var car = obj as Car;

            Assert.IsNotNull(car.Engine);
            Assert.AreEqual(5, car.Engine.Power);

            var dataContext = new DataContext(new FileObjectAccess(path, ServiceLocator.Instance.Resolve <ITypeRegistry>()));
            var cars        = dataContext.GetAll <Car>();
            var apples      = dataContext.GetAll <Apple>();

            Assert.AreEqual(1, cars.Count());
            Assert.AreEqual(1, apples.Count());
        }
Esempio n. 2
0
        public void ShouldLoadLazyObjects3()
        {
            var content =
                @"Discriminator,Engine
                NonVirtualCar,{new Gears.Interpreter.Tests.Pages.Iteration5Tests.Engine(){Power=5}}
                NonVirtualApple,ApplesDontHaveEngines
                ";

            var path = _inputFolder + "\\Scenario4.csv";

            File.WriteAllText(path, content);

            Bootstrapper.Register();
            ServiceLocator.Instance.Resolve <ITypeRegistry>().Register(typeof(NonVirtualCar));
            ServiceLocator.Instance.Resolve <ITypeRegistry>().Register(typeof(NonVirtualApple));

            var apple = new FileObjectAccess(path, ServiceLocator.Instance.Resolve <ITypeRegistry>()).GetAll().Last();

            Assert.IsInstanceOf <NonVirtualApple>(apple, apple.ToString());
            Assert.IsFalse(apple.GetType().Name.ToLower().Contains("proxy"));
            Assert.AreEqual("ApplesDontHaveEngines", (apple as NonVirtualApple).Engine);

            var obj = new FileObjectAccess(path, ServiceLocator.Instance.Resolve <ITypeRegistry>()).GetAll().First();

            Assert.IsInstanceOf <CorruptObject>(obj, obj.ToString());
            var car = obj as CorruptObject;

            Assert.IsTrue(car.Exception.Message.Contains("virtual"));
        }
Esempio n. 3
0
        public void ShouldLoadScenarioFileCorrectly()
        {
            Bootstrapper.Register();
            var keywords = new FileObjectAccess(FileFinder.Find("Iteration1.xlsx"), ServiceLocator.Instance.Resolve <ITypeRegistry>()).GetAll <Keyword>().ToList();

            Assert.IsInstanceOf <GoToUrl>(keywords.ElementAt(0));
            Assert.AreEqual("http://www.SELENIUMhq.org/", (keywords.ElementAt(0) as GoToUrl).Url);
        }
Esempio n. 4
0
        public override object DoRun()
        {
            if (string.IsNullOrEmpty(File))
            {
                throw new ArgumentException("Filename must be specified.");
            }

            if (File.ToLower().EndsWith(".dll"))
            {
                var file = FileFinder.Find(File);

                if (Technique == Technique.Show)
                {
                    return(new InformativeAnswer($"Dll file exists {file}"));
                }

                var pluggedInTypes = TypeRegistry.Register(file);

                if (pluggedInTypes.Any())
                {
                    return(new SuccessAnswer($"Loaded {pluggedInTypes.Count()} plugins from \n\t {file}"));
                }
                else
                {
                    return(new WarningAnswer("No plugins were loaded."));
                }
            }
            else
            {
                var file = FileFinder.Find(File);

                if (Technique == Technique.Show)
                {
                    Process.Start("explorer.exe", file);
                    return(new InformativeAnswer($"Opening file {file}"));
                }

                var fileObjectAccess = new FileObjectAccess(file, ServiceLocator.Instance.Resolve <ITypeRegistry>());
                var data             = fileObjectAccess.GetAll();

                Interpreter.Data.Include(fileObjectAccess);

                Interpreter.Plan = data.OfType <IKeyword>();

                var corruptObjects = data.OfType <CorruptObject>();
                if (corruptObjects.Any())
                {
                    return
                        (new ExceptionAnswer("Invalid Keywords found in file.").With(
                             new ExceptionAnswer(string.Join("\n\t", corruptObjects))));
                }

                return(new SuccessAnswer("File loaded successfully."));
            }
        }
Esempio n. 5
0
        public void ShouldLoadLazyObjects()
        {
            var codeStub = "{Generate.Word()}";
            var content  = $"Discriminator,FruitName\nTree,{codeStub}\n";
            var path     = _inputFolder + "\\Scenario3.csv";

            File.WriteAllText(path, content);

            Bootstrapper.Register();
            ServiceLocator.Instance.Resolve <ITypeRegistry>().Register(typeof(Tree));
            var tree = new FileObjectAccess(path, ServiceLocator.Instance.Resolve <ITypeRegistry>()).Get <Tree>();

            Assert.IsNotNull(tree);
            Assert.IsTrue(tree.GetType().Name.ToLower().Contains("proxy"));
            Assert.IsNotNull(codeStub, tree.FruitName);
            Assert.AreNotEqual(codeStub, tree.FruitName);
        }
Esempio n. 6
0
        public IEnumerable <object> RecursiveRead(string parentPath)
        {
            if (string.IsNullOrEmpty(FileName))
            {
                throw new InvalidOperationException("An Include object was passed to the system without FileName specified");
            }

            var fullPath = FileFinder.Find(FileName);

            if (File.Exists(fullPath))
            {
                return(new FileObjectAccess(fullPath, ServiceLocator.Instance.Resolve <ITypeRegistry>()).GetAll());
            }

            var directoryName = System.IO.Path.GetDirectoryName(parentPath);

            if (directoryName != null)
            {
                fullPath = System.IO.Path.Combine(directoryName, FileName);
                if (File.Exists(fullPath))
                {
                    return(new FileObjectAccess(fullPath, ServiceLocator.Instance.Resolve <ITypeRegistry>()).GetAll());
                }
            }

            try
            {
                var includedData = new FileObjectAccess(FileFinder.Find(FileName), ServiceLocator.Instance.Resolve <ITypeRegistry>());

                return(includedData.GetAll());
            }
            catch (Exception)
            {
                throw new IOException($"Included file '{FileName}' in '{this.ToString()}' was not found.");
            }
        }