Exemplo n.º 1
0
        public void CreatePackageSpec_OneProjectReferenceWhichCannotBeResolved_WarningLoggedAndNoProjectReferencedAddedToPackageSpec()
        {
            CreateProject("MyProject", @"d:\projects\MyProject\MyProject.csproj");
            AddTargetFramework("netcoreapp1.0");
            string referencedProjectFileName = @"d:\projects\MyProject\Lib\Lib.csproj".ToNativePath();
            string include = @"Lib\Lib.csproj".ToNativePath();

            AddProjectReference("Lib", referencedProjectFileName, include);
            solution.OnResolveProject = pr => {
                return(null);
            };
            PackageOperationMessage messageLogged = null;

            packageManagementEvents.PackageOperationMessageLogged += (sender, e) => {
                messageLogged = e.Message;
            };
            CreatePackageSpec();

            var    targetFramework = spec.RestoreMetadata.TargetFrameworks.Single();
            string expectedMessage = string.Format("WARNING: Unable to resolve project '{0}' referenced by 'MyProject'.", include);

            Assert.AreEqual("MyProject", spec.Name);
            Assert.AreEqual("MyProject", spec.RestoreMetadata.ProjectName);
            Assert.AreEqual("netcoreapp1.0", spec.RestoreMetadata.OriginalTargetFrameworks.Single());
            Assert.AreEqual(".NETCoreApp,Version=v1.0", targetFramework.FrameworkName.ToString());
            Assert.AreEqual(expectedMessage, messageLogged.ToString());
            Assert.AreEqual(MessageLevel.Warning, messageLogged.Level);
            Assert.AreEqual(0, targetFramework.ProjectReferences.Count);
        }
Exemplo n.º 2
0
        public void GetProjectReferencesAsync_OneInvalidProjectReference_NoProjectReferencesAndWarningLogged()
        {
            var projectToBeReferenced = CreateDotNetProject("Test");
            var mainProject           = CreateDotNetProject("MyProject");

            CreateSolution(mainProject, projectToBeReferenced);
            var projectReference = ProjectReference.CreateProjectReference(projectToBeReferenced);

            // Mark project reference as invalid.
            projectReference.SetInvalid("Not valid");
            mainProject.References.Add(projectReference);
            CreateProjectReferencesReader(mainProject);
            PackageOperationMessage messageLogged = null;

            packageManagementEvents.PackageOperationMessageLogged += (sender, e) => {
                messageLogged = e.Message;
            };

            var references = GetProjectReferences();

            string expectedMessage = "Failed to resolve all project references. The package restore result for 'MyProject' or a dependant project may be incomplete.";

            Assert.AreEqual(0, references.Count);
            Assert.IsNotNull(messageLogged);
            Assert.AreEqual(MessageLevel.Warning, messageLogged.Level);
            Assert.AreEqual(expectedMessage, messageLogged.ToString());
        }
        public void ToString_CreateWarningMessage_ReturnsMessage()
        {
            var message = new PackageOperationMessage(MessageLevel.Warning, "test");
            var text    = message.ToString();

            Assert.AreEqual("test", text);
        }
        public void ToString_CreateFormattedWarningMessage_ReturnsFormattedMessage()
        {
            string format  = "Test '{0}'.";
            var    message = new PackageOperationMessage(MessageLevel.Warning, format, "A");
            var    text    = message.ToString();

            var expectedText = "Test 'A'.";

            Assert.AreEqual(expectedText, text);
        }