public void When_all_packages_are_the_same_version_then_nothing_is_found()
        {
            // Arrange
            var solution = new Solution
                {
                    Projects = new[]
                        {
                            new Project{
                                PackageDependencies = new[]
                                {
                                    new NuGetPackageDependency{Id="MyPackage",Version = "1.0",PackageFilePath = "where I am 1"},
                                    new NuGetPackageDependency{Id="Something Else",Version = "2.0",PackageFilePath = "where I am 1"},
                                }
                            },
                            new Project{
                                PackageDependencies = new[]
                                {
                                    new NuGetPackageDependency{Id="MyPackage",Version = "1.0",PackageFilePath = "where I am 2"},
                                    new NuGetPackageDependency{Id="Yet Another Thing",Version = "3.0",PackageFilePath = "where I am 2"},
                                }
                            },
                        }
                };

            var validator = new AllDependenciesAreSameVersionValidator();

            // Act
            var results = validator.Validate(solution.Projects);

            // Assert
            Assert.That(results,Is.Empty);
        }
        public void When_packages_have_different_versions_then_each_one_is_returned()
        {
            // Arrange
            var solution = new Solution
                {
                    NuSpecFiles = new[]
                        {
                            new NuSpecFile{
                                PackageDependencies = new[]
                                    {
                                        new NuGetPackageDependency{Id="MyPackage",Version = "1.0",PackageFilePath = "where I am 1"},
                                        new NuGetPackageDependency{Id="MyPackage",Version = "1.1",PackageFilePath = "where I am 2"},
                                        new NuGetPackageDependency{Id="Something Else",Version = "2.0",PackageFilePath = "where I am 1"},
                                    }
                            }
                        }
                };

            var validator = new NuSpecContainsOnlyOneEntryPerPackageValidator();

            // Act
            var results = validator.Validate(solution.NuSpecFiles).ToList();

            // Assert
            Assert.That(results.Count(),Is.EqualTo(1));
            Assert.That(results[0].Message,Is.StringContaining("MyPackage"));
            Assert.That(results[0].Message,Is.StringContaining("1.0"));
            Assert.That(results[0].Message,Is.StringContaining("1.1"));
            Assert.That(results[0].Message,Is.StringContaining("where I am 1"));
            Assert.That(results[0].Message,Is.StringContaining("where I am 2"));
        }
        public void When_all_packages_are_the_same_version_then_nothing_is_found()
        {
            // Arrange
            var solution = new Solution
                {
                    NuSpecFiles = new[]
                        {
                            new NuSpecFile{
                                PackageDependencies = new[]
                                    {
                                        new NuGetPackageDependency{Id="MyPackage",Version = "1.0",PackageFilePath = "where I am 1"},
                                        new NuGetPackageDependency{Id="Something Else",Version = "2.0",PackageFilePath = "where I am 1"},
                                    }
                            },
                            new NuSpecFile{
                                PackageDependencies = new[]
                                    {
                                        new NuGetPackageDependency{Id="MyPackage",Version = "1.0",PackageFilePath = "where I am 2"},
                                        new NuGetPackageDependency{Id="Yet Another Thing",Version = "3.0",PackageFilePath = "where I am 2"},
                                    }
                            },
                        }
                };

            var validator = new NuSpecContainsOnlyOneEntryPerPackageValidator();

            // Act
            var results = validator.Validate(solution.NuSpecFiles);

            // Assert
            Assert.That(results,Is.Empty);
        }
        public void BeforeAll()
        {
            _solutionName = "MySolution.sln";
            _fullFilePath = @"C:\where I am\A Solution\MySolution.sln";
            _projectOne = Builder<Project>.CreateNew().Build();
            _projectTwo = Builder<Project>.CreateNew().Build();
            _nuspec1 = Builder<NuSpecFile>.CreateNew().Build();
            _nuspec2 = Builder<NuSpecFile>.CreateNew().Build();

            var solutionFileContents = GetSolutionFileContents();

            var fileSystem = new Mock<IFileSystem>();
            fileSystem.Setup(fs => fs.FindFullFilePath(_solutionName)).Returns(_fullFilePath);
            fileSystem.Setup(fs => fs.ReadFile(_fullFilePath)).Returns(solutionFileContents);
            fileSystem.Setup(fs => fs.GetDirectory(_fullFilePath)).Returns("");

            var projectBuilder = new Mock<IBuilder<Project, BuildProjectRequest>>();
            projectBuilder.Setup(b => b.Build(It.Is<BuildProjectRequest>(projectRequest => projectRequest.ProjectFilePath == "Project1\\Project1.csproj"))).Returns(_projectOne);
            projectBuilder.Setup(b => b.Build(It.Is<BuildProjectRequest>(projectRequest => projectRequest.ProjectFilePath == "Project2\\Project2.csproj"))).Returns(_projectTwo);

            var nuspecBuilder = new Mock<IBuilder<NuSpecFile, string>>();
            nuspecBuilder.Setup(b => b.Build("spec1")).Returns(_nuspec1);
            nuspecBuilder.Setup(b => b.Build("spec2")).Returns(_nuspec2);

            var builder = new SolutionBuilder(fileSystem.Object, projectBuilder.Object, nuspecBuilder.Object);

            var request = new BuildSolutionRequest()
                .WithSolutionName(_solutionName)
                .WithNuSpec("spec1")
                .WithNuSpec("spec2");

            _solution = builder.Build(request);
        }
        public static void BeforeAll(TestContext context)
        {
            var solutionBuilder = new SolutionBuilder();
            var request = new BuildSolutionRequest()
                .WithSolutionName("NuGetSolutionValidator")
                .WithProjects(p => p.Name != "NugetSolutionValidator.Tests")
                .WithNuSpec("NuGetSolutionValidator")
                .WithNuSpecProjectSet("NuGetSolutionValidator", new[] { "NuGetSolutionValidator.NUnit" });

            _solution = solutionBuilder.Build(request);
        }
        public void BeforeAll()
        {
            var solutionBuilder = new SolutionBuilder();
            var request = new BuildSolutionRequest()
                .WithSolutionName("NuGetSolutionValidator")
                .WithProjects(p => p.Name.Contains("SampleProject"))
                //.WithNuSpec("NuGetSolutionValidator")
                //.WithNuSpecProjectSet("NuGetSolutionValidator", new[] { "NuGetSolutionValidator.NUnit" })
                ;

            _solution = solutionBuilder.Build(request);
        }
        public void When_packages_have_different_versions_then_each_one_is_returned()
        {
            // Arrange
            var solution = new Solution
            {
                Projects = new[]
                        {
                            new Project{
                                PackageDependencies = new[]
                                {
                                    new NuGetPackageDependency{Id="MyPackage",Version = "1.0",PackageFilePath = "where I am 1"},
                                    new NuGetPackageDependency{Id="Something Else",Version = "2.0",PackageFilePath = "where I am 1"},
                                }
                            },
                            new Project{
                                PackageDependencies = new[]
                                {
                                    new NuGetPackageDependency{Id="MyPackage",Version = "1.1",PackageFilePath = "where I am 2"},
                                    new NuGetPackageDependency{Id="Yet Another Thing",Version = "3.0",PackageFilePath = "where I am 2"},
                                }
                            },
                        }
            };

            var validator = new AllDependenciesAreSameVersionValidator();

            // Act
            var results = validator.Validate(solution.Projects).ToList();

            // Assert
            Assert.That(results.Count(),Is.EqualTo(1));
            Assert.That(results[0].Message,Is.StringContaining("MyPackage"));
            Assert.That(results[0].Message,Is.StringContaining("1.0"));
            Assert.That(results[0].Message,Is.StringContaining("1.1"));
            Assert.That(results[0].Message,Is.StringContaining("where I am 1"));
            Assert.That(results[0].Message,Is.StringContaining("where I am 2"));
        }