public void Creates_New_Root_If_None_Exists()
            {
                DomainRoot.Arrange(dr => dr.GetRoot()).Returns <IProject>(null);

                Target.SetModules(Mock.Create <IModule>());

                DomainRoot.Assert(dr => dr.SetRoot(Arg.IsAny <Project>()), Occurs.Once());
            }
            public void Invokes_WorkspaceBuilder_On_Project()
            {
                var project = new Project();

                DomainRoot.Arrange(dr => dr.GetRoot()).Returns(project);

                Target.BuildWorkspace(new Project());

                WorkspaceBuilder.Assert(wsb => wsb.BuildWorkspaceForProject(project), Occurs.Once());
            }
            public void Adds_New_Module_To_In_Memory_Project()
            {
                var project = new Project();

                DomainRoot.Arrange(dr => dr.GetRoot()).Returns(project);

                var module = Target.GetAllForProject("asdf").First();

                Assert.AreEqual <int>(1, project.GetModuleNames().Count());
            }
        public void BeforeEachTest()
        {
            Document = Mock.Create <IXmlDocument>();
            Document.Arrange(doc => doc.Load(Arg.AnyString)).Returns(XDocument.Parse(NormalProjectText));

            DomainRoot = Mock.Create <DomainRoot>();
            DomainRoot.Arrange(dr => dr.GetRoot()).Returns(new Project());

            Target = new ModuleRepository(Document, DomainRoot);
        }
            public void Adds_Modules_Passed_In_To_DomainRoot()
            {
                var project = new Project();

                DomainRoot.Arrange(dr => dr.GetRoot()).Returns(project);

                Target.SetModules(Mock.Create <IModule>(), Mock.Create <IModule>());

                Assert.AreEqual <int>(2, project.GetModuleNames().Count());
            }
        public void BeforeEachTest()
        {
            XmlDocument      = Mock.Create <IXmlDocument>();
            WorkspaceBuilder = Mock.Create <IWorkspaceBuilder>();
            DomainRoot       = Mock.Create <DomainRoot>();

            DomainRoot.Arrange(dr => dr.GetRoot()).Returns((Project)null);
            DomainRoot.Arrange(dr => dr.SetRoot(Arg.IsAny <Project>())).DoInstead((Project p) => DomainRoot.Arrange(dr => dr.GetRoot()).Returns(p));

            Target = new ProjectRepository(XmlDocument, WorkspaceBuilder, DomainRoot);
        }
            public void Returns_Root_From_DomainRoot_When_It_Exists()
            {
                const string projectTitle = "blah";

                DomainRoot.Arrange(dr => dr.GetRoot()).Returns(new Project()
                {
                    Title = projectTitle
                });

                var project = Target.GetById("whatevs");

                Assert.AreEqual <string>(projectTitle, project.Title);
            }
            public void Overwites_Existing_Project_Title()
            {
                const string title   = "asdfasfda";
                var          project = new Project()
                {
                    Title = title
                };

                DomainRoot.Arrange(dr => dr.GetRoot()).Returns(new Project());

                Target.Save(project);

                XmlDocument.Assert(d => d.Save(Arg.Matches <XElement>(xe => xe.Descendants().Any(x => x.Name == "Title" && x.Value == title)), Arg.AnyString), Occurs.Once());
            }
            public void Does_Not_Overwrite_Existing_Project_When_Root_Is_Not_Null()
            {
                const string projectPath = "asdf";
                var          project     = new Project()
                {
                    ProjectPath = projectPath
                };

                DomainRoot.Arrange(dr => dr.GetRoot()).Returns(new Project());

                Target.Save(project);

                DomainRoot.Assert(dr => dr.SetRoot(Arg.Matches <Project>(p => p.ProjectPath == projectPath)), Occurs.Never());
            }
            public void Sets_Domain_Root_To_Passed_In_Project_When_Root_Is_Null()
            {
                const string projectPath = "asdf";
                var          project     = new Project()
                {
                    ProjectPath = projectPath
                };

                DomainRoot.Arrange(dr => dr.GetRoot()).Returns((Project)null);

                Target.Save(project);

                DomainRoot.Assert(dr => dr.SetRoot(Arg.Matches <Project>(p => p.ProjectPath == projectPath)));
            }