1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648
|
// SolutionTests.cs
//
// Author:
// Lluis Sanchez Gual <lluis@novell.com>
//
// Copyright (c) 2008 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
//
using System;
using System.IO;
using System.Collections.Generic;
using NUnit.Framework;
using UnitTests;
using MonoDevelop.Core;
namespace MonoDevelop.Projects
{
[TestFixture()]
public class SolutionTests: TestBase
{
[Test()]
public void SolutionItemsEvents()
{
int countFileAddedToProject = 0;
int countFileRemovedFromProject = 0;
int countFileRenamedInProject = 0;
int countReferenceAddedToProject = 0;
int countReferenceRemovedFromProject = 0;
int countSolutionItemAdded = 0;
int countSolutionItemRemoved = 0;
Solution sol = new Solution ();
sol.FileAddedToProject += delegate {
countFileAddedToProject++;
};
sol.FileRemovedFromProject += delegate {
countFileRemovedFromProject++;
};
sol.FileRenamedInProject += delegate {
countFileRenamedInProject++;
};
sol.ReferenceAddedToProject += delegate {
countReferenceAddedToProject++;
};
sol.ReferenceRemovedFromProject += delegate {
countReferenceRemovedFromProject++;
};
sol.SolutionItemAdded += delegate {
countSolutionItemAdded++;
};
sol.SolutionItemRemoved += delegate {
countSolutionItemRemoved++;
};
Assert.AreEqual (0, countFileAddedToProject);
Assert.AreEqual (0, countFileRemovedFromProject);
Assert.AreEqual (0, countFileRenamedInProject);
Assert.AreEqual (0, countReferenceAddedToProject);
Assert.AreEqual (0, countReferenceRemovedFromProject);
Assert.AreEqual (0, countSolutionItemAdded);
Assert.AreEqual (0, countSolutionItemRemoved);
SolutionFolder folder = new SolutionFolder ();
folder.Name = "Folder1";
sol.RootFolder.Items.Add (folder);
Assert.AreEqual (1, countSolutionItemAdded);
Assert.AreEqual (0, sol.Items.Count);
DotNetAssemblyProject project = new DotNetAssemblyProject ("C#");
project.Name = "project1";
sol.RootFolder.Items.Add (project);
Assert.AreEqual (2, countSolutionItemAdded);
Assert.AreEqual (1, sol.Items.Count);
DotNetAssemblyProject project2 = new DotNetAssemblyProject ("C#");
project2.Name = "project2";
folder.Items.Add (project2);
Assert.AreEqual (3, countSolutionItemAdded);
Assert.AreEqual (2, sol.Items.Count);
ProjectFile p1 = new ProjectFile ("test1.cs");
project2.Files.Add (p1);
Assert.AreEqual (1, countFileAddedToProject);
ProjectFile p2 = new ProjectFile ("test1.cs");
project.Files.Add (p2);
Assert.AreEqual (2, countFileAddedToProject);
p1.Name = "test2.cs";
Assert.AreEqual (1, countFileRenamedInProject);
p2.Name = "test2.cs";
Assert.AreEqual (2, countFileRenamedInProject);
project2.Files.Remove (p1);
Assert.AreEqual (1, countFileRemovedFromProject);
project.Files.Remove ("test2.cs");
Assert.AreEqual (2, countFileRemovedFromProject);
ProjectReference pr1 = new ProjectReference (ReferenceType.Package, "SomeTest");
project.References.Add (pr1);
Assert.AreEqual (1, countReferenceAddedToProject);
ProjectReference pr2 = new ProjectReference (project);
project2.References.Add (pr2);
Assert.AreEqual (2, countReferenceAddedToProject);
project.References.Remove (pr1);
Assert.AreEqual (1, countReferenceRemovedFromProject);
sol.RootFolder.Items.Remove (project);
Assert.AreEqual (2, countReferenceRemovedFromProject, "Removing a project must remove all references to it");
Assert.AreEqual (1, countSolutionItemRemoved);
Assert.AreEqual (1, sol.Items.Count);
folder.Items.Remove (project2);
Assert.AreEqual (2, countSolutionItemRemoved);
Assert.AreEqual (0, sol.Items.Count);
sol.RootFolder.Items.Remove (folder);
Assert.AreEqual (2, countFileAddedToProject);
Assert.AreEqual (2, countFileRemovedFromProject);
Assert.AreEqual (2, countFileRenamedInProject);
Assert.AreEqual (2, countReferenceAddedToProject);
Assert.AreEqual (2, countReferenceRemovedFromProject);
Assert.AreEqual (3, countSolutionItemAdded);
Assert.AreEqual (3, countSolutionItemRemoved);
}
[Test()]
public void SolutionName ()
{
int nameChanges = 0;
Solution sol = new Solution ();
sol.NameChanged += delegate {
nameChanges++;
};
string tmp = Path.GetTempPath ();
sol.Name = "test1";
Assert.AreEqual ("test1", sol.Name);
Assert.AreEqual ("test1.sln", (string) sol.FileName);
Assert.AreEqual (1, nameChanges);
sol.Name = "test2";
Assert.AreEqual ("test2", sol.Name);
Assert.AreEqual ("test2.sln", (string) sol.FileName);
Assert.AreEqual (2, nameChanges);
sol.FileName = Path.Combine (tmp, "test3.sln");
Assert.AreEqual ("test3", sol.Name);
Assert.AreEqual (Path.Combine (tmp, "test3.sln"), (string) sol.FileName);
Assert.AreEqual (3, nameChanges);
sol.Name = "test4";
Assert.AreEqual ("test4", sol.Name);
Assert.AreEqual (Path.Combine (tmp, "test4.sln"), (string) sol.FileName);
Assert.AreEqual (4, nameChanges);
sol.ConvertToFormat (Util.FileFormatMD1, true);
Assert.AreEqual ("test4", sol.Name);
Assert.AreEqual (Path.Combine (tmp, "test4.mds"), (string) sol.FileName);
Assert.AreEqual (4, nameChanges);
}
[Test()]
public void ProjectName ()
{
int nameChanges = 0;
DotNetAssemblyProject prj = new DotNetAssemblyProject ("C#");
prj.FileFormat = Util.FileFormatMSBuild05;
prj.NameChanged += delegate {
nameChanges++;
};
prj.Name = "test1";
Assert.AreEqual ("test1", prj.Name);
Assert.AreEqual ("test1.csproj", (string) prj.FileName);
Assert.AreEqual (1, nameChanges);
prj.Name = "test2";
Assert.AreEqual ("test2", prj.Name);
Assert.AreEqual ("test2.csproj", (string) prj.FileName);
Assert.AreEqual (2, nameChanges);
string fname = Path.Combine (Path.GetTempPath (), "test3.csproj");
prj.FileName = fname;
Assert.AreEqual ("test3", prj.Name);
Assert.AreEqual (fname, (string) prj.FileName);
Assert.AreEqual (3, nameChanges);
prj.Name = "test4";
Assert.AreEqual ("test4", prj.Name);
Assert.AreEqual (Path.Combine (Path.GetTempPath (), "test4.csproj"), (string) prj.FileName);
Assert.AreEqual (4, nameChanges);
prj.FileFormat = Util.FileFormatMD1;
Assert.AreEqual ("test4", prj.Name);
Assert.AreEqual (Path.Combine (Path.GetTempPath (), "test4.mdp"), (string) prj.FileName);
Assert.AreEqual (4, nameChanges);
Assert.AreEqual ("MD1", prj.FileFormat.Id);
// Projects inherit the file format from the parent solution
Solution sol = new Solution ();
sol.ConvertToFormat (Util.FileFormatMSBuild05, true);
sol.RootFolder.Items.Add (prj);
Assert.AreEqual ("test4", prj.Name);
Assert.AreEqual (Path.Combine (Path.GetTempPath (), "test4.csproj"), (string) prj.FileName);
Assert.AreEqual (4, nameChanges);
Assert.AreEqual ("MSBuild05", prj.FileFormat.Id);
// Removing the project from the solution should not restore the old format
sol.RootFolder.Items.Remove (prj);
Assert.AreEqual ("MSBuild05", prj.FileFormat.Id);
Assert.AreEqual ("test4", prj.Name);
Assert.AreEqual (Path.Combine (Path.GetTempPath (), "test4.csproj"), (string) prj.FileName);
Assert.AreEqual (4, nameChanges);
}
[Test()]
public void Reloading ()
{
Solution sol = TestProjectsChecks.CreateConsoleSolution ("reloading");
sol.Save (Util.GetMonitor ());
Assert.IsFalse (sol.NeedsReload);
Project p = sol.Items [0] as Project;
Assert.IsFalse (p.NeedsReload);
// Changing format must reset the reload flag (it's like we just created a new solution in memory)
sol.ConvertToFormat (Util.FileFormatMD1, true);
Assert.IsFalse (sol.NeedsReload);
Assert.IsFalse (p.NeedsReload);
sol.ConvertToFormat (Util.FileFormatMSBuild05, true);
Assert.IsFalse (sol.NeedsReload);
Assert.IsFalse (p.NeedsReload);
sol.RootFolder.Items.Remove (p);
Assert.IsFalse (p.NeedsReload);
p.FileFormat = Util.FileFormatMD1;
Assert.IsFalse (p.NeedsReload);
sol.RootFolder.Items.Add (p);
Assert.IsFalse (p.NeedsReload);
sol.RootFolder.Items.Remove (p);
Assert.IsFalse (p.NeedsReload);
p.FileFormat = Util.FileFormatMSBuild05;
Assert.IsFalse (p.NeedsReload);
sol.RootFolder.Items.Add (p);
Assert.IsFalse (p.NeedsReload);
string mdsSolFile = Util.GetSampleProject ("csharp-console-mdp", "csharp-console-mdp.mds");
Solution mdsSol = (Solution) Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), mdsSolFile);
Project pmds = mdsSol.Items [0] as Project;
Assert.IsFalse (mdsSol.NeedsReload);
Assert.IsFalse (pmds.NeedsReload);
// Check reloading flag in another solution
string solFile = sol.FileName;
Solution sol2 = (Solution) Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solFile);
Assert.IsFalse (sol2.NeedsReload);
Project p2 = sol2.Items [0] as Project;
Assert.IsFalse (p2.NeedsReload);
System.Threading.Thread.Sleep (1000);
sol.Save (Util.GetMonitor ());
Assert.IsTrue (sol2.NeedsReload);
}
[Test()]
public void ReloadingReferencedProject ()
{
string solFile = Util.GetSampleProject ("console-with-libs-mdp", "console-with-libs-mdp.mds");
Solution sol = (Solution) Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solFile);
DotNetProject p = (DotNetProject) sol.FindProjectByName ("console-with-libs-mdp");
DotNetProject lib2 = (DotNetProject) sol.FindProjectByName ("library2");
Assert.AreEqual (3, p.References.Count);
lib2.ParentFolder.ReloadItem (Util.GetMonitor (), lib2);
Assert.AreEqual (3, p.References.Count);
}
[Test()]
public void GetItemFiles ()
{
Solution sol = TestProjectsChecks.CreateConsoleSolution ("item-files");
List<FilePath> files = sol.GetItemFiles (false);
Assert.AreEqual (1, files.Count);
Assert.AreEqual (sol.FileName, files [0]);
DotNetProject p = (DotNetProject) sol.Items [0];
files = p.GetItemFiles (false);
Assert.AreEqual (1, files.Count);
Assert.AreEqual (p.FileName, files [0]);
files = p.GetItemFiles (true);
Assert.AreEqual (6, files.Count);
Assert.IsTrue (files.Contains (p.FileName));
foreach (ProjectFile pf in p.Files)
Assert.IsTrue (files.Contains (pf.FilePath), "Contains " + pf.FilePath);
files = sol.GetItemFiles (true);
Assert.AreEqual (7, files.Count);
Assert.IsTrue (files.Contains (sol.FileName));
Assert.IsTrue (files.Contains (p.FileName));
foreach (ProjectFile pf in p.Files)
Assert.IsTrue (files.Contains (pf.FilePath), "Contains " + pf.FilePath);
}
[Test()]
public void NeedsBuilding ()
{
string solFile = Util.GetSampleProject ("console-with-libs-mdp", "console-with-libs-mdp.mds");
Solution sol = (Solution) Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solFile);
DotNetProject p = (DotNetProject) sol.FindProjectByName ("console-with-libs-mdp");
Assert.IsNotNull (p);
DotNetProject lib1 = (DotNetProject) sol.FindProjectByName ("library1");
Assert.IsNotNull (lib1);
DotNetProject lib2 = (DotNetProject) sol.FindProjectByName ("library2");
Assert.IsNotNull (lib2);
SolutionConfigurationSelector config = (SolutionConfigurationSelector) "Debug";
Assert.IsTrue (p.NeedsBuilding (config));
Assert.IsTrue (lib1.NeedsBuilding (config));
Assert.IsTrue (lib2.NeedsBuilding (config));
// Build the project and the references
BuildResult res = p.Build (Util.GetMonitor (), config, true);
foreach (BuildError er in res.Errors)
Console.WriteLine (er.ToString ());
Assert.AreEqual (0, res.ErrorCount);
Assert.AreEqual (0, res.WarningCount);
Assert.AreEqual (3, res.BuildCount);
Assert.IsTrue (File.Exists (Util.Combine (p.BaseDirectory, "bin", "Debug", "console-with-libs-mdp.exe")));
Assert.IsTrue (File.Exists (Util.Combine (p.BaseDirectory, "bin", "Debug", GetMdb ("console-with-libs-mdp.exe"))));
Assert.IsTrue (File.Exists (Util.Combine (lib1.BaseDirectory, "bin", "Debug", "library1.dll")));
Assert.IsTrue (File.Exists (Util.Combine (lib1.BaseDirectory, "bin", "Debug", GetMdb ("library1.dll"))));
Assert.IsTrue (File.Exists (Util.Combine (lib2.BaseDirectory, "bin", "Debug", "library2.dll")));
Assert.IsTrue (File.Exists (Util.Combine (lib2.BaseDirectory, "bin", "Debug", GetMdb ("library2.dll"))));
// Build the project, but not the references
res = p.Build (Util.GetMonitor (), config, false);
Assert.AreEqual (0, res.ErrorCount);
Assert.AreEqual (0, res.WarningCount);
Assert.AreEqual (1, res.BuildCount);
}
[Test()]
public void BuildingAndCleaning ()
{
string solFile = Util.GetSampleProject ("console-with-libs-mdp", "console-with-libs-mdp.mds");
Solution sol = (Solution) Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solFile);
DotNetProject p = (DotNetProject) sol.FindProjectByName ("console-with-libs-mdp");
DotNetProject lib1 = (DotNetProject) sol.FindProjectByName ("library1");
DotNetProject lib2 = (DotNetProject) sol.FindProjectByName ("library2");
SolutionFolder folder = new SolutionFolder ();
folder.Name = "subfolder";
sol.RootFolder.Items.Add (folder);
sol.RootFolder.Items.Remove (lib2);
folder.Items.Add (lib2);
Workspace ws = new Workspace ();
ws.FileName = Path.Combine (sol.BaseDirectory, "workspace");
ws.Items.Add (sol);
ws.Save (Util.GetMonitor ());
// Build the project and the references
BuildResult res = ws.Build (Util.GetMonitor (), "Debug");
Assert.AreEqual (0, res.ErrorCount);
Assert.AreEqual (0, res.WarningCount);
Assert.AreEqual (3, res.BuildCount);
Assert.IsTrue (File.Exists (Util.Combine (p.BaseDirectory, "bin", "Debug", "console-with-libs-mdp.exe")));
Assert.IsTrue (File.Exists (Util.Combine (p.BaseDirectory, "bin", "Debug", GetMdb ("console-with-libs-mdp.exe"))));
Assert.IsTrue (File.Exists (Util.Combine (lib1.BaseDirectory, "bin", "Debug", "library1.dll")));
Assert.IsTrue (File.Exists (Util.Combine (lib1.BaseDirectory, "bin", "Debug", GetMdb ("library1.dll"))));
Assert.IsTrue (File.Exists (Util.Combine (lib2.BaseDirectory, "bin", "Debug", "library2.dll")));
Assert.IsTrue (File.Exists (Util.Combine (lib2.BaseDirectory, "bin", "Debug", GetMdb ("library2.dll"))));
// Clean the workspace
ws.Clean (Util.GetMonitor (), "Debug");
Assert.IsFalse (File.Exists (Util.Combine (p.BaseDirectory, "bin", "Debug", "console-with-libs-mdp.exe")));
Assert.IsFalse (File.Exists (Util.Combine (p.BaseDirectory, "bin", "Debug", GetMdb ("console-with-libs-mdp.exe"))));
Assert.IsFalse (File.Exists (Util.Combine (lib1.BaseDirectory, "bin", "Debug", "library1.dll")));
Assert.IsFalse (File.Exists (Util.Combine (lib1.BaseDirectory, "bin", "Debug", GetMdb ("library1.dll"))));
Assert.IsFalse (File.Exists (Util.Combine (lib2.BaseDirectory, "bin", "Debug", "library2.dll")));
Assert.IsFalse (File.Exists (Util.Combine (lib2.BaseDirectory, "bin", "Debug", GetMdb ("library2.dll"))));
// Build the solution
res = ws.Build (Util.GetMonitor (), "Debug");
Assert.AreEqual (0, res.ErrorCount);
Assert.AreEqual (0, res.WarningCount);
Assert.AreEqual (3, res.BuildCount);
Assert.IsTrue (File.Exists (Util.Combine (p.BaseDirectory, "bin", "Debug", "console-with-libs-mdp.exe")));
Assert.IsTrue (File.Exists (Util.Combine (p.BaseDirectory, "bin", "Debug", GetMdb ("console-with-libs-mdp.exe"))));
Assert.IsTrue (File.Exists (Util.Combine (lib1.BaseDirectory, "bin", "Debug", "library1.dll")));
Assert.IsTrue (File.Exists (Util.Combine (lib1.BaseDirectory, "bin", "Debug", GetMdb ("library1.dll"))));
Assert.IsTrue (File.Exists (Util.Combine (lib2.BaseDirectory, "bin", "Debug", "library2.dll")));
Assert.IsTrue (File.Exists (Util.Combine (lib2.BaseDirectory, "bin", "Debug", GetMdb ("library2.dll"))));
// Clean the solution
sol.Clean (Util.GetMonitor (), "Debug");
Assert.IsFalse (File.Exists (Util.Combine (p.BaseDirectory, "bin", "Debug", "console-with-libs-mdp.exe")));
Assert.IsFalse (File.Exists (Util.Combine (p.BaseDirectory, "bin", "Debug", GetMdb ("console-with-libs-mdp.exe"))));
Assert.IsFalse (File.Exists (Util.Combine (lib1.BaseDirectory, "bin", "Debug", "library1.dll")));
Assert.IsFalse (File.Exists (Util.Combine (lib1.BaseDirectory, "bin", "Debug", GetMdb ("library1.dll"))));
Assert.IsFalse (File.Exists (Util.Combine (lib2.BaseDirectory, "bin", "Debug", "library2.dll")));
Assert.IsFalse (File.Exists (Util.Combine (lib2.BaseDirectory, "bin", "Debug", GetMdb ("library2.dll"))));
// Build the solution folder
res = folder.Build (Util.GetMonitor (), (SolutionConfigurationSelector) "Debug");
Assert.AreEqual (0, res.ErrorCount);
Assert.AreEqual (0, res.WarningCount);
Assert.AreEqual (1, res.BuildCount);
Assert.IsFalse (File.Exists (Util.Combine (p.BaseDirectory, "bin", "Debug", "console-with-libs-mdp.exe")));
Assert.IsFalse (File.Exists (Util.Combine (p.BaseDirectory, "bin", "Debug", GetMdb ("console-with-libs-mdp.exe"))));
Assert.IsFalse (File.Exists (Util.Combine (lib1.BaseDirectory, "bin", "Debug", "library1.dll")));
Assert.IsFalse (File.Exists (Util.Combine (lib1.BaseDirectory, "bin", "Debug", GetMdb ("library1.dll"))));
Assert.IsTrue (File.Exists (Util.Combine (lib2.BaseDirectory, "bin", "Debug", "library2.dll")));
Assert.IsTrue (File.Exists (Util.Combine (lib2.BaseDirectory, "bin", "Debug", GetMdb ("library2.dll"))));
// Clean the solution folder
folder.Clean (Util.GetMonitor (), (SolutionConfigurationSelector) "Debug");
Assert.IsFalse (File.Exists (Util.Combine (lib2.BaseDirectory, "bin", "Debug", "library2.dll")));
Assert.IsFalse (File.Exists (Util.Combine (lib2.BaseDirectory, "bin", "Debug", GetMdb ("library2.dll"))));
}
[Test()]
public void FormatConversions ()
{
Solution sol = TestProjectsChecks.CreateConsoleSolution ("reloading");
Project p = (Project) sol.Items [0];
Assert.AreEqual (Services.ProjectService.DefaultFileFormatId, sol.FileFormat.Id);
Assert.AreEqual (Services.ProjectService.DefaultFileFormatId, p.FileFormat.Id);
// Change solution format of unsaved solution
sol.ConvertToFormat (Util.FileFormatMD1, true);
Assert.AreEqual ("MD1", sol.FileFormat.Id);
Assert.AreEqual ("MD1", p.FileFormat.Id);
sol.ConvertToFormat (Util.FileFormatMSBuild05, true);
Assert.AreEqual ("MSBuild05", sol.FileFormat.Id);
Assert.AreEqual ("MSBuild05", p.FileFormat.Id);
// Change solution format of saved solution
sol.Save (Util.GetMonitor ());
sol.ConvertToFormat (Util.FileFormatMD1, false);
Assert.AreEqual ("MD1", sol.FileFormat.Id);
Assert.AreEqual ("MSBuild05", p.FileFormat.Id);
p.FileFormat = Util.FileFormatMD1;
Assert.AreEqual ("MD1", p.FileFormat.Id);
// Add new project
Project newp = new DotNetAssemblyProject ("C#");
Assert.AreEqual ("MSBuild10", newp.FileFormat.Id);
sol.RootFolder.Items.Add (newp);
Assert.AreEqual ("MD1", newp.FileFormat.Id);
// Add saved project
string solFile = Util.GetSampleProject ("console-project", "ConsoleProject.sln");
Solution msol = (Solution) Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solFile);
Project mp = (Project) msol.Items [0];
Assert.AreEqual ("MSBuild05", mp.FileFormat.Id);
sol.RootFolder.Items.Add (newp);
Assert.AreEqual ("MSBuild05", mp.FileFormat.Id);
}
[Test()]
public void BuildConfigurationMappings ()
{
string solFile = Util.GetSampleProject ("test-build-configs", "test-build-configs.mds");
Solution sol = (Solution) Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solFile);
DotNetProject lib1 = (DotNetProject) sol.FindProjectByName ("Lib1");
DotNetProject lib2 = (DotNetProject) sol.FindProjectByName ("Lib2");
DotNetProject lib3 = (DotNetProject) sol.FindProjectByName ("Lib3");
DotNetProject lib4 = (DotNetProject) sol.FindProjectByName ("Lib4");
// Check that the output file names are correct
Assert.AreEqual (GetConfigFolderName (lib1, "Debug"), "Debug");
Assert.AreEqual (GetConfigFolderName (lib1, "Release"), "Release");
Assert.AreEqual (GetConfigFolderName (lib2, "Debug"), "Release");
Assert.AreEqual (GetConfigFolderName (lib2, "Release"), "Debug");
Assert.AreEqual (GetConfigFolderName (lib3, "Debug"), "DebugExtra");
Assert.AreEqual (GetConfigFolderName (lib3, "Release"), "ReleaseExtra");
// Check that building the solution builds the correct project configurations
CheckSolutionBuildClean (sol, "Debug");
CheckSolutionBuildClean (sol, "Release");
// Check that building a project builds the correct referenced project configurations
CheckProjectReferencesBuildClean (sol, "Debug");
CheckProjectReferencesBuildClean (sol, "Release");
// Single project build and clean
CheckProjectBuildClean (lib2, "Debug");
CheckProjectBuildClean (lib2, "Release");
CheckProjectBuildClean (lib3, "Debug");
CheckProjectBuildClean (lib3, "Release");
CheckProjectBuildClean (lib4, "Debug");
CheckProjectBuildClean (lib4, "Release");
}
void CheckSolutionBuildClean (Solution sol, string configuration)
{
SolutionConfigurationSelector config = (SolutionConfigurationSelector) configuration;
string tag = "CheckSolutionBuildClean config=" + configuration;
DotNetProject lib1 = (DotNetProject) sol.FindProjectByName ("Lib1");
DotNetProject lib2 = (DotNetProject) sol.FindProjectByName ("Lib2");
DotNetProject lib3 = (DotNetProject) sol.FindProjectByName ("Lib3");
DotNetProject lib4 = (DotNetProject) sol.FindProjectByName ("Lib4");
Assert.IsFalse (File.Exists (lib1.GetOutputFileName (config)), tag);
Assert.IsFalse (File.Exists (lib2.GetOutputFileName (config)), tag);
Assert.IsFalse (File.Exists (lib3.GetOutputFileName (config)), tag);
Assert.IsFalse (File.Exists (lib4.GetOutputFileName (config)), tag);
BuildResult res = sol.Build (Util.GetMonitor (), config);
Assert.AreEqual (0, res.WarningCount, tag);
Assert.AreEqual (0, res.ErrorCount, tag);
Assert.IsTrue (File.Exists (lib1.GetOutputFileName (config)), tag);
Assert.IsTrue (File.Exists (lib2.GetOutputFileName (config)), tag);
Assert.IsTrue (File.Exists (lib3.GetOutputFileName (config)), tag);
Assert.IsTrue (File.Exists (lib4.GetOutputFileName (config)), tag);
sol.Clean (Util.GetMonitor (), config);
Assert.IsFalse (File.Exists (lib1.GetOutputFileName (config)), tag);
Assert.IsFalse (File.Exists (lib2.GetOutputFileName (config)), tag);
Assert.IsFalse (File.Exists (lib3.GetOutputFileName (config)), tag);
Assert.IsFalse (File.Exists (lib4.GetOutputFileName (config)), tag);
}
void CheckProjectReferencesBuildClean (Solution sol, string configuration)
{
SolutionConfigurationSelector config = (SolutionConfigurationSelector) configuration;
string tag = "CheckProjectReferencesBuildClean config=" + configuration;
DotNetProject lib1 = (DotNetProject) sol.FindProjectByName ("Lib1");
DotNetProject lib2 = (DotNetProject) sol.FindProjectByName ("Lib2");
DotNetProject lib3 = (DotNetProject) sol.FindProjectByName ("Lib3");
DotNetProject lib4 = (DotNetProject) sol.FindProjectByName ("Lib4");
Assert.IsFalse (File.Exists (lib1.GetOutputFileName (config)), tag);
Assert.IsFalse (File.Exists (lib2.GetOutputFileName (config)), tag);
Assert.IsFalse (File.Exists (lib3.GetOutputFileName (config)), tag);
Assert.IsFalse (File.Exists (lib4.GetOutputFileName (config)), tag);
BuildResult res = lib1.Build (Util.GetMonitor (), config, true);
Assert.AreEqual (0, res.WarningCount, tag);
Assert.AreEqual (0, res.ErrorCount, tag + " " + res.CompilerOutput);
Assert.IsTrue (File.Exists (lib1.GetOutputFileName (config)), tag);
Assert.IsTrue (File.Exists (lib2.GetOutputFileName (config)), tag);
Assert.IsTrue (File.Exists (lib3.GetOutputFileName (config)), tag);
Assert.IsTrue (File.Exists (lib4.GetOutputFileName (config)), tag);
sol.Clean (Util.GetMonitor (), config);
}
void CheckProjectBuildClean (DotNetProject lib, string configuration)
{
SolutionConfigurationSelector config = (SolutionConfigurationSelector) configuration;
string tag = "CheckProjectBuildClean lib=" + lib.Name + " config=" + configuration;
Assert.IsFalse (File.Exists (lib.GetOutputFileName (config)), tag);
BuildResult res = lib.Build (Util.GetMonitor (), config, false);
Assert.AreEqual (0, res.WarningCount, tag);
Assert.AreEqual (0, res.ErrorCount, tag);
Assert.IsTrue (File.Exists (lib.GetOutputFileName (config)), tag);
lib.Clean (Util.GetMonitor (), config);
Assert.IsFalse (File.Exists (lib.GetOutputFileName (config)), tag);
}
string GetConfigFolderName (DotNetProject lib, string conf)
{
return Path.GetFileName (Path.GetDirectoryName (lib.GetOutputFileName ((SolutionConfigurationSelector)conf)));
}
}
}
|