public void ShouldLazyLoadFromString()
        {
            var sampleType = new SampleViewTestClass1().GetType(); // NB: Instance used to get actual SL type of (instead of 'typeof' which returns native Type).
            var typeName = sampleType.FullName;
            var assemblyName = sampleType.Assembly.FullName;
            var model = new ViewTestClass(typeName, null, assemblyName, "File.xap");

            model.TypeName.ShouldBe(typeName);
            model.IsActivated.ShouldBe(false);

            // Activate from Type.
            model.Type.ShouldNotBe(null);
            model.Type.FullName.ShouldBe(typeName);
            model.IsActivated.ShouldBe(true);

            // Activate from Attribute.
            model = new ViewTestClass(typeName, null, assemblyName, "File.xap");
            model.IsActivated.ShouldBe(false);
            model.Attribute.ShouldNotBe(null);
            model.IsActivated.ShouldBe(true);

            // Activate from ViewTests.
            model = new ViewTestClass(typeName, null, assemblyName, "File.xap");
            model.IsActivated.ShouldBe(false);
            model.ViewTests.Count.ShouldNotBe(0);
            model.IsActivated.ShouldBe(true);
        }
        public void ShouldRetrieveMethodsFromClass()
        {
            var sampleType = new SampleViewTestClass1().GetType(); // NB: Instance used to get actual SL type of (instead of 'typeof' which returns native Type).

            var list = ViewTest.GetMethods(sampleType);
            list.Count.ShouldBe(4);

            var method1 = list[0];
            method1.MethodInfo.ShouldNotBe(null);
        }
        public void ShouldConstructFromType()
        {
            var sampleType = new SampleViewTestClass1().GetType(); // NB: Instance used to get actual SL type of (instead of 'typeof' which returns native Type).
            var model = new ViewTestClass(sampleType, "File.xap");

            model.TypeName.ShouldBe(sampleType.FullName);
            model.AssemblyName.ShouldBe(ReflectionUtil.GetAssemblyName(sampleType.Assembly.FullName));
            model.IsActivated.ShouldBe(true);

            Assert.AreEqual(sampleType, model.Type);
            Assert.IsNotNull(model.Attribute);
        }
        public void ShouldLoadClassesFromAssembly()
        {
            var module = new ViewTestClassesModule();

            PropertyChangedEventArgs args = null;
            module.PropertyChanged += (sender, e) => args = e;

            var sampleAssembly = new SampleViewTestClass1().GetType().Assembly;

            var count = module.AddFromAssembly(sampleAssembly, "File.xap");
            count.ShouldNotBe(0);
            args.PropertyName.ShouldBe(ViewTestClassesModule.PropClasses);
        }
 public void ShouldHaveCollectionOfViewTests()
 {
     var sampleType = new SampleViewTestClass1().GetType(); // NB: Instance used to get actual SL type of (instead of 'typeof' which returns native Type).
     var model = new ViewTestClass(sampleType, "File.xap");
     model.ViewTests.Count.ShouldBe(4);
 }
        public void ShouldAlertWhenChildMethodExecuteRequestIsMade()
        {
            var sampleType = new SampleViewTestClass1().GetType(); // NB: Instance used to get actual SL type of (instead of 'typeof' which returns native Type).
            var classModel = new ViewTestClass(sampleType, "File.xap");
            var testModel = classModel.ViewTests[2];
            testModel.ShouldNotBe(classModel.DefaultViewTest);

            classModel.CurrentViewTest.ShouldBe(classModel.DefaultViewTest);

            var argsProp = new List<string>();
            classModel.PropertyChanged += (sender, e) => argsProp.Add(e.PropertyName);

            TestExecuteEventArgs argsExecuteRequest = null;
            classModel.ExecuteRequest += (sender, e) => argsExecuteRequest = e;

            testModel.Execute();
            argsExecuteRequest.ShouldNotBe(null);
            argsProp.ShouldContain(LinqExtensions.GetPropertyName<ViewTestClass>(m => m.CurrentViewTest));

            classModel.CurrentViewTest.ShouldBe(testModel);
        }
        public void ShouldReload()
        {
            TestHarnessModel.ResetSingleton();
            var testHarness = TestHarnessModel.Instance;
            var sampleType = new SampleViewTestClass1().GetType(); // NB: Instance used to get actual SL type of (instead of 'typeof' which returns native Type).

            var model1 = new ViewTestClass(sampleType.FullName, null, sampleType.Assembly.FullName, "File.xap");

            var module = new ViewTestClassesAssemblyModule(new ModuleSetting(sampleType.Assembly.FullName, "File.xap"));
            module.Classes.AddRange(new[] { model1 });
            testHarness.Modules.Add(module);
            module.CurrentClass.ShouldBe(null);

            model1.IsCurrent = true;
            testHarness.CurrentClass.ShouldBe(model1);

            var instance = (SampleViewTestClass1)model1.Instance;
            instance.MyProperty.ShouldBe(null);
            instance.MyProperty = "My Custom Value";

            model1.Reload();
            instance = (SampleViewTestClass1)model1.Instance;
            instance.MyProperty.ShouldBe(null);
        }
        public void ShouldSetIsCurrent()
        {
            TestHarnessModel.ResetSingleton();
            var testHarness = TestHarnessModel.Instance;
            var sampleType = new SampleViewTestClass1().GetType(); // NB: Instance used to get actual SL type of (instead of 'typeof' which returns native Type).

            var model1 = new ViewTestClass(sampleType.FullName, null, sampleType.Assembly.FullName, "File.xap");
            var model2 = new ViewTestClass(typeof(SampleViewTestClass2), "File.xap");

            var module = new ViewTestClassesAssemblyModule(new ModuleSetting(sampleType.Assembly.FullName, "File.xap"));
            module.Classes.AddRange(new []{model1, model2});
            testHarness.Modules.Add(module);
            module.CurrentClass.ShouldBe(null);

            PropertyChangedEventArgs argsModel1 = null;
            model1.PropertyChanged += (sender, e) => argsModel1 = e;

            // ----------

            model1.IsActivated.ShouldBe(false);
            model1.IsCurrent.ShouldBe(false);
            model1.IsCurrent = true;
            model1.IsCurrent.ShouldBe(true);
            testHarness.CurrentClass.ShouldBe(model1);

            argsModel1.PropertyName.ShouldBe(LinqExtensions.GetPropertyName<ViewTestClass>(m => m.IsCurrent));

            module.CurrentClass.ShouldBe(model1);

            model2.IsCurrent = true;
            model2.IsCurrent.ShouldBe(true);
            testHarness.CurrentClass.ShouldBe(model2);
            model1.IsCurrent.ShouldBe(false); // Deselected.
            module.CurrentClass.ShouldBe(model2);

            model2.IsCurrent = false;
            module.CurrentClass.ShouldBe(null);
            testHarness.CurrentClass.ShouldBe(null);
        }
        public void ShouldDetermineIfAssemblyIsLoaded()
        {
            TestHarnessModel.ResetSingleton();
            var testHarness = TestHarnessModel.Instance;
            testHarness.Modules.Clear();

            var sampleType = new SampleViewTestClass1().GetType(); // NB: Instance used to get actual SL type of (instead of 'typeof' which returns native Type).
            var typeName = sampleType.FullName;
            var assemblyName = sampleType.Assembly.FullName;
            var model = new ViewTestClass(typeName, null, assemblyName, "File.xap");

            var module = new ViewTestClassesAssemblyModule(new ModuleSetting(assemblyName, "File.xap"));
            testHarness.Modules.Add(module);

            model.IsAssemblyLoaded.ShouldBe(false);
            module.LoadAssembly(sampleType.Assembly);
            model.IsAssemblyLoaded.ShouldBe(true);

            TestHarnessModel.ResetSingleton();
        }