示例#1
0
        public void StoresRelativePaths()
        {
// ReSharper disable AssignNullToNotNullAttribute
// ReSharper disable PossibleNullReferenceException
            XmlDocumentFactory.Type = typeof(XmlDocumentMock);
            LoaderFactory.Type      = typeof(LoaderMock);
            var codeBase = GetType().Assembly.CodeBase;

            var url = new Uri(codeBase);
            var assemblyPathName = url.AbsolutePath;

            var fi   = new FileInfo(assemblyPathName);
            var path = fi.DirectoryName;

            var src = RecipeFactory.NewRecipe(Path.Combine(path, "StoresRelativePaths.recipe"));

            src.Clear();
            src.AddAssembly(assemblyPathName);
            src.Save();

            var doc = XmlDocumentFactory.CreateInstance();

            doc.Load(Path.Combine(path, "StoresRelativePaths.recipe"));
            var elem = doc["recipe"]["assembly"];

            Assert.Equals("csUnit.Core.Tests.DLL", elem.Attributes["path"].Value);
// ReSharper restore AssignNullToNotNullAttribute
// ReSharper restore PossibleNullReferenceException
        }
示例#2
0
        public void RecipeFileName()
        {
            RecipeFactory.Type = typeof(MySpecialRecipe);
            var recipe = RecipeFactory.NewRecipe("foo.recipe");

            Assert.Equals("foo.recipe", recipe.PathName);
        }
示例#3
0
        public void SelectingNoneIncludesAll()
        {
            RecipeFactory.Type = typeof(ASpecialRecipe);
            var recipe = RecipeFactory.NewRecipe(string.Empty);

            _fc.ResetAllCategories();

            var testRun = new TestRun(new AllTestsCriterion());

            recipe.RunTests(testRun);

            ISelector registeredFilter = null;

            foreach (var filter in recipe.Selectors)
            {
                if (filter.Equals(_fc.Filter))
                {
                    registeredFilter = filter;
                    break;
                }
            }
// ReSharper disable PossibleNullReferenceException
            Assert.True(registeredFilter.Includes(new ASpecialTestMethod("Blue")));
// ReSharper restore PossibleNullReferenceException
            Assert.True(registeredFilter.Includes(new ASpecialTestMethod("Red")));
            Assert.True(registeredFilter.Includes(new ASpecialTestMethod("Green")));
        }
示例#4
0
 public void TearDown()
 {
     XmlDocumentFactory.Type = XmlDocumentFactory.Default;
     XmlDocumentMock.Reset();
     RecipeFactory.Type = RecipeFactory.Default;
     RecipeFactory.NewRecipe(string.Empty);
 }
示例#5
0
        public void CriterionAppliedWithMultipleAssemblies()
        {
            var recipe = RecipeFactory.NewRecipe("twoassemblies.deleteme.recipe");

            recipe.AddAssembly(_testDll);
            var testDll = Path.Combine(Util.SolutionCodeBase,
                                       "csUnit.CompatibilityTests\\NUnit-2.4.7\\bin\\Debug\\NUnit-2.4.7.dll");

            recipe.AddAssembly(testDll);
            var listener = new SimpleRecipeListener(recipe);

            recipe.RunTests(new TestRun(new AllTestsCriterion()));
            recipe.Join();
            Assert.Equals(7, listener.TestCount);
            Assert.Equals(5, listener.PassedCount);

            listener = new SimpleRecipeListener(recipe);
            var setCriterion = new MultipleTestsCriterion();

            setCriterion.Add("TestDll", "TestDll.ClassWithTests", "AFailingTest");
            setCriterion.Add("TestDll", "TestDll.ClassWithTests", "ATestWithError");
            recipe.RunTests(new TestRun(setCriterion));

            recipe.Join();
            Assert.Equals(2, listener.TestCount);
        }
示例#6
0
        public void DefaultCreatesRecipeInstance()
        {
            RecipeFactory.Type = RecipeFactory.Default;
            var recipe = RecipeFactory.NewRecipe(string.Empty);

            Assert.Equals(typeof(Recipe), recipe.GetType());
        }
示例#7
0
        public void FindAssemblyByNameInEmptyRecipe()
        {
            var r  = RecipeFactory.NewRecipe(string.Empty);
            var ta = r[_csUnitTestExePath];

            Assert.Null(ta);
        }
示例#8
0
        public void RecipeFactoryProducingNonDefault()
        {
            RecipeFactory.Type = typeof(MySpecialRecipe);
            var recipe = RecipeFactory.NewRecipe(string.Empty);

            Assert.Equals(typeof(MySpecialRecipe), recipe.GetType());
        }
示例#9
0
        public void EmptyRecipeTestRunDoesntFail()
        {
            var recipe = RecipeFactory.NewRecipe(string.Empty);

            recipe.RunTests(new TestRun(new AllTestsCriterion()));
            Assert.False(recipe.TestsRunning);
        }
示例#10
0
        public void AddAssembly()
        {
            LoaderFactory.Type = typeof(LoaderMock);
            var r = RecipeFactory.NewRecipe(string.Empty);

            r.AddAssembly(_csUnitTestExePath);
            Assert.Equals(1, r.AssemblyCount);
        }
示例#11
0
 protected override void Execute(object sender, EventArgs args)
 {
     if (CommandTarget.AskSaveModifiedRecipe() == false)
     {
         return;
     }
     RecipeFactory.NewRecipe(string.Empty);
 }
示例#12
0
        public void FilterControlRegistersFilter()
        {
            RecipeFactory.Type = typeof(ASpecialRecipe);
            var recipe = RecipeFactory.NewRecipe(string.Empty);

            Assert.NotNull(_fc);
            Assert.Equals(recipe.Selectors.Count, 1);
        }
示例#13
0
        public void FilterControlRegistersFilter()
        {
            RecipeFactory.Type = typeof(ASpecialRecipe);
            _fc = new CategoryControl();
            IRecipe recipe = RecipeFactory.NewRecipe("");

            Assert.Greater(recipe.Selectors.Count, 0);
        }
示例#14
0
        public void FiresClosingLoadedEventsWithNewInstance()
        {
            var eventHandler = new MyEventHandler2();

            RecipeFactory.Loaded  += eventHandler.OnRecipeLoaded;
            RecipeFactory.Closing += eventHandler.OnRecipeClosing;
            RecipeFactory.NewRecipe(string.Empty);
            Assert.Equals("OnRecipeClosingOnRecipeLoaded", eventHandler.Events);
        }
示例#15
0
        public void FindAssemblyByNameWithUnknownName()
        {
            LoaderFactory.Type = typeof(LoaderMock);
            IRecipe r = RecipeFactory.NewRecipe(string.Empty);

            r.AddAssembly(_csUnitTestExePath);
            var ta = r["fluffy duck"];

            Assert.Null(ta);
        }
示例#16
0
        public void FindAssemblyByName()
        {
            LoaderFactory.Type = typeof(LoaderMock);
            var r = RecipeFactory.NewRecipe(string.Empty);

            r.AddAssembly(_csUnitTestExePath);
            var ta = r[_csUnitTestExePath];

            Assert.Equals(ta.Name.CodeBase, _csUnitTestExePath);
        }
示例#17
0
        public void CanAddAssemblyByUri()
        {
            LoaderFactory.Type = typeof(LoaderMock);
            var recipe   = RecipeFactory.NewRecipe(string.Empty);
            var assembly = GetType().Assembly;
            var url      = new Uri(assembly.CodeBase);

            recipe.AddAssembly(assembly.CodeBase);
            Assert.Equals(1, recipe.Assemblies.Length);
            Assert.Contains(url.LocalPath, recipe.Assemblies[0].Name.CodeBase);
        }
        public void ChangingFilterMarksRecipeModified()
        {
            XmlDocumentFactory.Type = typeof(XmlDocumentMock);
            CategorySelector selector = new CategorySelector();
            IRecipe          recipe   = RecipeFactory.NewRecipe(string.Empty);

            recipe.RegisterSelector(selector);
            recipe.Save(@"c:\nirvana.recipe");
            Assert.False(recipe.Modified, "Expected recipe not being modified.");
            selector.IncludedCategories.Add("bla");
            Assert.True(recipe.Modified, "Expected recipe being modified.");
        }
示例#19
0
        public void ExcludedSurvivesRefresh()
        {
            RecipeFactory.Type = typeof(ASpecialRecipe);
            RecipeFactory.NewRecipe(string.Empty);
            _fc.ResetAllCategories();
            _fc.ExcludeCategory("Blue");
            _fc.RefreshCategoriesList();
            var expected = new Categories();

            expected.Add("Blue");
            Assert.Equals(expected, _fc.ExcludedCategories);
        }
示例#20
0
        public void TestCountConsidersFiltersOnMethods()
        {
            var filter       = new CategoryFilterMock();
            var recipe       = RecipeFactory.NewRecipe(string.Empty) as Recipe;
            var mockAssembly = new MockAssembly();

// ReSharper disable PossibleNullReferenceException
            recipe.AddAssembly(mockAssembly);
// ReSharper restore PossibleNullReferenceException
            Assert.Equals(2, recipe.CountTests());
            recipe.RegisterSelector(filter);
            Assert.Equals(1, recipe.CountTests());
        }
示例#21
0
        public void SelectionSurvivesRefresh()
        {
            RecipeFactory.Type = typeof(ASpecialRecipe);
            IRecipe recipe = RecipeFactory.NewRecipe("");

            _fc.ResetAllCategories();
            _fc.IncludeCategory("Blue");
            _fc.RefreshCategoriesList();
            Categories expected = new Categories();

            expected.Add("Blue");
            Assert.Equals(expected, _fc.IncludedCategories);
        }
示例#22
0
        public void ForEach()
        {
            LoaderFactory.Type = typeof(LoaderMock);
            var required = new[] { _csUnitTestExePath, GetType().Assembly.Location };
            var r        = RecipeFactory.NewRecipe(string.Empty);

            r.AddAssembly(required[0]);
            r.AddAssembly(required[1]);

            foreach (var ta in r)
            {
                Assert.Contains(ta.Name.CodeBase, required);
            }
        }
示例#23
0
        public void SaveRetrieve()
        {
            XmlDocumentFactory.Type = typeof(XmlDocumentMock);
            LoaderFactory.Type      = typeof(LoaderMock);

            var path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            var r    = RecipeFactory.NewRecipe(string.Empty);

            r.AddAssembly(_csUnitTestExePath);
            r.Save(path + "\\SaveRetrieve.recipe");

            var retrieved = RecipeFactory.Load(path + "\\SaveRetrieve.recipe");

            Assert.Equals(1, retrieved.AssemblyCount);
        }
示例#24
0
        public void StoresInRecipe()
        {
            XmlDocumentFactory.Type = typeof(XmlDocumentMock);
            LoaderFactory.Type      = typeof(LoaderMock);
            var recipe = RecipeFactory.NewRecipe(string.Empty);
            var filter = new FilterMock();

            recipe.RegisterSelector(filter);
            recipe.Save(@"c:\nirvana.recipe");
            var retrievedRecipe = RecipeFactory.NewRecipe(string.Empty);
            var xmlDocument     = new XmlDocumentMock(XmlDocumentMock.RawContent);

            retrievedRecipe.LoadFromXml(xmlDocument);
            Assert.Contains(filter, retrievedRecipe.Selectors);
            Assert.Equals("<filterMock />", filter._serializedContent);
            Assert.Equals(filter._serializedContent, filter._deserializedContent);
        }
示例#25
0
        public void CategoriesFound()
        {
            var current = RecipeFactory.NewRecipe(string.Empty) as Recipe;

            if (current != null)
            {
                current.AddAssembly(new AssemblyMock());
                Assert.True(current.Categories.Contains("Cat1"), "Doesn't contain category 'Cat1'.");
                Assert.True(current.Categories.Contains("Cat2"), "Doesn't contain category 'Cat2'.");
                Assert.True(current.Categories.Contains("Panda"), "Doesn't contain category 'Panda'.");
                current.Close();
            }
            else
            {
                Assert.Fail("Couldn't create new recipe.");
            }
        }
示例#26
0
            public void ConsoleIsRedirected()
            {
                var assemblyPathName = Path.Combine(Environment.CurrentDirectory, "..\\..\\..\\..\\build\\Debug\\ConsoleRedirection.dll");

                using (var recipe = RecipeFactory.NewRecipe(string.Empty)) {
                    var temporarilyStoredConsoleOut = Console.Out;
                    Console.SetOut(MyConsole);
                    recipe.SetConsoleOutputTo(MyConsole);
                    recipe.AddAssembly(assemblyPathName);
                    recipe.RunTests(new TestRun(new AllTestsCriterion()));
                    recipe.Join();
                    Console.SetOut(temporarilyStoredConsoleOut);
                }

                Assert.Contains("Show me the list:" + MyConsole.NewLine + "A" + MyConsole.NewLine
                                + "B" + MyConsole.NewLine + "C" + MyConsole.NewLine + "# end of list #" + MyConsole.NewLine,
                                MyConsole.GetStringBuilder().ToString());
            }
示例#27
0
        public void CriterionIsRemovedForSecondTestRun()
        {
            var recipe = RecipeFactory.NewRecipe(string.Empty);

            recipe.AddAssembly(_testDll);

            var criterion = new NameCriterion("TestDll.ClassWithTests.ASucceedingTest");
            var listener  = new SimpleRecipeListener(recipe);

            recipe.RunTests(new TestRun(criterion));
            recipe.Join();
            Assert.Equals(1, listener.TestCount);

            listener = new SimpleRecipeListener(recipe);
            recipe.RunTests(new TestRun(new AllTestsCriterion()));
            recipe.Join();
            Assert.Equals(3, listener.TestCount);
        }
示例#28
0
        public void RegisteredFilterWorksForSelectedCategory()
        {
            RecipeFactory.Type = typeof(ASpecialRecipe);
            IRecipe recipe = RecipeFactory.NewRecipe("");

            _fc.ResetAllCategories();
            _fc.IncludeCategory("Blue");
            ISelector registeredFilter = null;

            foreach (ISelector filter in recipe.Selectors)
            {
                registeredFilter = filter;
                break;
            }
            Assert.True(registeredFilter.Includes(new ASpecialTestMethod("Blue")));
            Assert.False(registeredFilter.Includes(new ASpecialTestMethod("Red")));
            Assert.False(registeredFilter.Includes(new ASpecialTestMethod("Green")));
        }
示例#29
0
        public void RegisteredFilterWorksForSelectedCategory()
        {
            RecipeFactory.Type = typeof(ASpecialRecipe);
            var recipe = RecipeFactory.NewRecipe(string.Empty);

            _fc.ResetAllCategories();
            _fc.IncludeCategory("Blue");
            ISelector registeredFilter = null;

            foreach (var filter in recipe.Selectors)
            {
                registeredFilter = filter;
                break;
            }
// ReSharper disable PossibleNullReferenceException
            Assert.True(registeredFilter.Includes(new ASpecialTestMethod("Blue")));
// ReSharper restore PossibleNullReferenceException
            Assert.False(registeredFilter.Includes(new ASpecialTestMethod("Red")));
            Assert.False(registeredFilter.Includes(new ASpecialTestMethod("Green")));
        }
示例#30
0
        public void UsesCriteria()
        {
            var uri        = new Uri(GetType().Assembly.CodeBase);
            var targetPath = Path.Combine(Util.SolutionCodeBase, "build\\Debug\\csUnit.Core.Tests.dll");

            if (File.Exists(targetPath))
            {
                File.Delete(targetPath);
            }
            File.Copy(uri.AbsolutePath, targetPath);
            var recipe    = RecipeFactory.NewRecipe(string.Empty) as Recipe;
            var criterion = new MyCriterion();

            if (recipe != null)
            {
                recipe.AddAssembly(_testDll);
                recipe.RunTests(new TestRun(criterion));
                recipe.Join();
            }
            Assert.True(criterion.HasBeenCalled);
        }