Demo entry 5968393

BasicTest

   

Submitted by cla on Sep 11, 2016 at 10:25
Language: C#. Code size: 49.3 kB.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using BugTrackerInterfaces;
using Moq;
using NUnit.Framework;
using Ninject;

namespace BugTrackerTests {
    public static class Configuration
    {
        public const string ImplementationAssembly =
            @"C:\Users\Mau\Documents\Visual Studio 2015\Projects\TAP2015.BugTracker\TAP2015.BugTracker.ReferenceImplementation\bin\Debug\TAP2015.BugTracker.ReferenceImplementation.dll";

        public const string ConnectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=Tap2012For2015Tests;Integrated Security=SSPI; MultipleActiveResultSets=True";
    }

    [TestFixture]
    public abstract class TestRoot {
        protected static readonly IBugTrackerFactory Factory;

        protected static readonly IPrincipal Admin = new GenericPrincipal(new GenericIdentity("foo"), new[] {StandardRoles.Admin});
        protected static readonly IPrincipal Developer = new GenericPrincipal(new GenericIdentity("bar"), new[] {StandardRoles.Developer});
        protected static readonly IPrincipal NormalUser = new GenericPrincipal(new GenericIdentity("baz"), new string[0]);
        protected static readonly IPrincipal NormalUser2 = new GenericPrincipal(new GenericIdentity("bunny"), new string[0]);
        protected static readonly IPrincipal UnauthenticatedUser = new GenericPrincipal(new Mock<IIdentity>().Object, new string[0]);

        static TestRoot() {
            var kernel = new StandardKernel();
            try {
                kernel.Load(Configuration.ImplementationAssembly);
                Factory = kernel.Get<IBugTrackerFactory>();
            } catch (Exception e) {
                Debug.WriteLine(e);
            }
        }

        [SetUp]
        public void InitializeDb() {
            Factory.BugTrackerInitialize(Admin, Configuration.ConnectionString);
        }
    }

    [Category("Basic")]
    [Category("Setup")]
    public class BugTrackerSetupTests : TestRoot {
        [Test]
        public void InitializedDb_CreatesAnEmptyDb() {
            var tracker = Factory.LoadBugTracker(Admin, Configuration.ConnectionString);
            Assert.That(tracker.BugReportManager.GetAllInfo(NormalUser),Is.Empty);
            Assert.That(tracker.SoftwareManager.GetAllInfo(NormalUser), Is.Empty);
        }

        [Test]
        public void InitializeDb_WantsAuthenticatedUser() {
            Assert.That(()=>Factory.BugTrackerInitialize(UnauthenticatedUser, Configuration.ConnectionString),Throws.TypeOf<AuthorizationException>());
        }

        [Test]
        public void InitializeDb_WantsAdminUser() {
            Assert.That(() => Factory.BugTrackerInitialize(NormalUser, Configuration.ConnectionString), Throws.TypeOf<AuthorizationException>());
        }

        [Test]
        public void InitializeDb_WantsNonNullUser() {
            Assert.That(() => Factory.BugTrackerInitialize(null, Configuration.ConnectionString), Throws.TypeOf<TapArgumentNullException>());
        }

        [Test]
        public void InitializeDb_WantsNonNullConnectionString() {
            Assert.That(() => Factory.BugTrackerInitialize(Admin, null), Throws.TypeOf<TapArgumentNullException>());
        }


        [Test]
        public void InitializeDb_WantsNonEmptyConnectionString() {
            Assert.That(() => Factory.BugTrackerInitialize(Admin, string.Empty), Throws.TypeOf<TapArgumentOutOfRangeException>());
        }

        [Test]
        public void LoadBT_ThrowsOnNullConnectionString() {
            Assert.That(() => Factory.LoadBugTracker(Admin, null), Throws.TypeOf<TapArgumentNullException>());
        }
        [Test]
        public void LoadBT_WantsAuthenticatedUser()
        {
            Assert.That(() => Factory.LoadBugTracker(UnauthenticatedUser, Configuration.ConnectionString), Throws.TypeOf<AuthorizationException>());
        }
    }

    [Category("Basic")]
    [Category("BugReportManager")]
    public class BugReportManagerTests : TestRoot {
        [Test]
        public void GetAllInfo_ReturnsEmptyArrayOnEmptyDB() {
            var brm = Factory.LoadBugTracker(NormalUser, Configuration.ConnectionString).BugReportManager;
            var reports = brm.GetAllInfo(NormalUser);
            Assert.That(reports,Is.Empty);
        }

        [Test]
        public void Delete_DeletesBugReportWithCommentsAndDuplicates() {
            var sm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).SoftwareManager;
            var brm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).BugReportManager;
            var swId = sm.AddSoftware(Admin, "a", "b");
            var releaseId = sm.AddRelease(Admin, swId, new SoftwareVersion(1, 0), "author", "change log");
            var otherReleaseId = sm.AddRelease(Admin, swId, new SoftwareVersion(2, 4), "other author", "other change log");
            var bugReportId = brm.AddReport(Admin, releaseId, "aaaa");
            brm.MarkAsDuplicateOf(Admin, bugReportId, brm.AddReport(Admin, otherReleaseId, "xxx"));
            brm.MarkAsDuplicateOf(Admin, bugReportId, brm.AddReport(Admin, otherReleaseId, "yyy"));
            brm.AddComment(Admin, bugReportId, "bubu");
            brm.Delete(Admin, bugReportId);
            var result = brm.GetAllInfo(Admin);
            Assert.That(result.Length,Is.EqualTo(2));
        }

        [Test]
        public void Delete_ThrowsOnNonexistentId() {
            var brm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).BugReportManager;
            Assert.That(() => brm.Delete(Admin, 77), Throws.TypeOf<NonexistentObjectException>());
        }

        [Test]
        public void DeleteComment_ThrowsOnNonexistentId() {
            var brm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).BugReportManager;
            Assert.That(() => brm.DeleteComment(Admin, 2222),Throws.TypeOf<NonexistentObjectException>());
        }

        [Test]
        public void UpdateDescription_Updates() {
            var sm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).SoftwareManager;
            var brm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).BugReportManager;
            var swId = sm.AddSoftware(Admin, "a", "b");
            var releaseId = sm.AddRelease(Admin, swId, new SoftwareVersion(1, 0), "author", "change log");
            var bugReportId = brm.AddReport(Admin, releaseId, "aaaa");
            string newDescription = new string('*', DomainConstraints.SoftwareDescriptionMaxLength);
            brm.UpdateDescription(Admin, bugReportId, newDescription);
            Assert.That(newDescription, Is.EqualTo(brm.GetInfoById(Admin, bugReportId).Description));
        }

        [Test]
        public void UpdateDescription_ThrowsIfNotCreator() {
            var sm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).SoftwareManager;
            var brm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).BugReportManager;
            var swId = sm.AddSoftware(Admin, "a", "b");
            var releaseId = sm.AddRelease(Admin, swId, new SoftwareVersion(1, 0), "author", "change log");
            var bugReportId = brm.AddReport(Admin, releaseId, "aaaa");
            string newDescription = new string('*', DomainConstraints.SoftwareDescriptionMaxLength);
            Assert.That(() => brm.UpdateDescription(NormalUser2, bugReportId, newDescription), Throws.TypeOf<AuthorizationException>());
        }

        private static int AssignAux(IBugReportManager brm, string assignee) {
            var sm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).SoftwareManager;
            var swId = sm.AddSoftware(Admin, "a", "b");
            var releaseId = sm.AddRelease(Admin, swId, new SoftwareVersion(1, 0), "author", "change log");
            var bugReportId = brm.AddReport(Admin, releaseId, "aaaa");
            brm.Assign(Developer, bugReportId, assignee);
            return bugReportId;
        }

        [Test]
        public void Assign_SetsAssignee() {
            var brm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).BugReportManager;
            const string assignee = "linus";
            var bugReportId = AssignAux(brm, assignee);
            Assert.That(assignee, Is.EqualTo(brm.GetAssignee(Admin, bugReportId)));
            Assert.That(assignee,Is.EqualTo(brm.GetInfoById(Admin, bugReportId).AssignedTo));
        }

        [Test]
        public void Assign_ThrowsIfNotAdminOrDeveloper() {
            var sm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).SoftwareManager;
            var brm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).BugReportManager;
            var swId = sm.AddSoftware(Admin, "a", "b");
            var releaseId = sm.AddRelease(Admin, swId, new SoftwareVersion(1, 0), "author", "change log");
            var bugReportId = brm.AddReport(Admin, releaseId, "aaaa");
            Assert.That(() => brm.Assign(NormalUser2, bugReportId, "romero"), Throws.TypeOf<AuthorizationException>());
        }

        [Test]
        public void Assign_ThrowsIfClosed() {
            var sm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).SoftwareManager;
            var brm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).BugReportManager;
            var swId = sm.AddSoftware(Admin, "a", "b");
            var releaseId = sm.AddRelease(Admin, swId, new SoftwareVersion(1, 0), "author", "change log");
            var bugReportId = brm.AddReport(Admin, releaseId, "aaaa");
            brm.CloseAsResolved(Admin, bugReportId);
            Assert.That(() => brm.Assign(Admin, bugReportId, "romero"),Throws.TypeOf<TapInvalidOperationException>());
        }

        [Test]
        public void Assign_ThrowsIfAlreadyAssigned() {
            var sm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).SoftwareManager;
            var brm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).BugReportManager;
            var swId = sm.AddSoftware(Admin, "a", "b");
            var releaseId = sm.AddRelease(Admin, swId, new SoftwareVersion(1, 0), "author", "change log");
            var bugReportId = brm.AddReport(Admin, releaseId, "aaaa");
            brm.Assign(Admin, bugReportId, "romero");
            Assert.That(() => brm.Assign(Admin, bugReportId, "romero"), Throws.TypeOf<TapInvalidOperationException>());
        }

        [Test]
        public void Assign_SetsAssigner() {
            var brm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).BugReportManager;
            var bugReportId = AssignAux(brm, "aaaa");
            Assert.That(Developer.Identity.Name, Is.EqualTo(brm.GetInfoById(Admin, bugReportId).AssignedBy));
        }

        [Test]
        public void Assign_SetsStatus() {
            var brm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).BugReportManager;
            var bugReportId = AssignAux(brm, "aaaa");
            Assert.That(BugReportStatus.OpenAssigned, Is.EqualTo(brm.GetExtendedInfoById(Admin, bugReportId).Status));
        }

        private static int CloseAux(IBugReportManager brm) {
            var sm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).SoftwareManager;
            var swId = sm.AddSoftware(Admin, "a", "b");
            var releaseId = sm.AddRelease(Admin, swId, new SoftwareVersion(1, 0), "author", "change log");
            var bugReportId = brm.AddReport(Admin, releaseId, "aaaa");
            return bugReportId;
        }

        [Test]
        public void CloseAsResolved_SetsStatus() {
            var brm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).BugReportManager;
            var id = CloseAux(brm);
            brm.CloseAsResolved(Admin, id);
            Assert.That(BugReportStatus.ClosedAsResolved, Is.EqualTo(brm.GetInfoById(Admin, id).Status));
        }

        [Test]
        public void CloseAsRejected_SetsStatus() {
            var brm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).BugReportManager;
            var id = CloseAux(brm);
            brm.CloseAsRejected(Admin, id);
            Assert.That(BugReportStatus.ClosedAsRejected, Is.EqualTo(brm.GetInfoById(Admin, id).Status));
        }

        [Test]
        public void CloseAsResolved_Throws() {
            var brm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).BugReportManager;
            var id = CloseAux(brm);
            brm.CloseAsRejected(Admin, id);
            Assert.That(() => brm.CloseAsResolved(Admin, id),Throws.TypeOf<TapInvalidOperationException>());
        }

        [Test]
        public void CloseAsRejected_Throws() {
            var brm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).BugReportManager;
            var id = CloseAux(brm);
            brm.CloseAsRejected(Admin, id);
            Assert.That(() => brm.CloseAsRejected(Admin, id), Throws.TypeOf<TapInvalidOperationException>());
        }

        private static int CreateBugReport(IBugReportManager brm, string swName) {
            var sm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).SoftwareManager;
            var swId = sm.AddSoftware(Admin, swName, "b");
            var releaseId = sm.AddRelease(Admin, swId, new SoftwareVersion(1, 0), "author", "change log");
            var bugReportId = brm.AddReport(Admin, releaseId, "aaaa");
            return bugReportId;
        }

        [Test]
        public void MarkAsDuplicateOf_ThrowsOnEqualId() {
            var brm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).BugReportManager;
            var id = CreateBugReport(brm, "a");
            Assert.That(() => brm.MarkAsDuplicateOf(Admin, id, id),Throws.TypeOf<TapInvalidOperationException>());
        }

        [Test]
        public void MarkAsDuplicateOf_ThrowsOnAlreadyMarked() {
            var brm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).BugReportManager;
            var id1 = CreateBugReport(brm, "!1");
            var id2 = CreateBugReport(brm, "*2");
            brm.MarkAsDuplicateOf(Admin, id1, id2);
            Assert.That(() => brm.MarkAsDuplicateOf(Admin, id1, id2), Throws.TypeOf<TapInvalidOperationException>());
        }

        [Test]
        public void UnmarkAsDuplicateOf_ThrowsOnEqualId() {
            var brm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).BugReportManager;
            var id = CreateBugReport(brm, "a");
            Assert.That(() => brm.UnmarkAsDuplicateOf(Admin, id, id), Throws.TypeOf<TapInvalidOperationException>());
        }

        [Test]
        public void UnmarkAsDuplicateOf_ThrowsOnNonmarkedId() {
            var brm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).BugReportManager;
            var id1 = CreateBugReport(brm, "!1");
            var id2 = CreateBugReport(brm, "*2");
            Assert.That(() => brm.UnmarkAsDuplicateOf(Admin, id1, id2), Throws.TypeOf<TapInvalidOperationException>());
        }

        [Test]
        public void UnmarkAsDuplicateOf_Unmarks() {
            var brm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).BugReportManager;
            var id1 = CreateBugReport(brm, "!1");
            var id2 = CreateBugReport(brm, "*2");
            brm.MarkAsDuplicateOf(Admin, id1, id2);
            brm.UnmarkAsDuplicateOf(Admin, id1, id2);
            Assert.That(id1, Is.EqualTo(brm.FindAllDuplicateOf(Admin, id1).Single()));
        }

        [Test]
        public void FindAllDuplicateOf_DoesNotLoop() {
            var brm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).BugReportManager;
            var id1 = CreateBugReport(brm, "!1");
            var id2 = CreateBugReport(brm, "*2");
            var id3 = CreateBugReport(brm, "-3");
            brm.MarkAsDuplicateOf(Admin, id1, id2);
            brm.MarkAsDuplicateOf(Admin, id2, id3);
            brm.MarkAsDuplicateOf(Admin, id3, id2);
            Assert.That(new[] {id1, id2, id3},Is.EquivalentTo(brm.FindAllDuplicateOf(Admin, id1)));
        }

        [Test]
        public void UpdateComment_Updates() {
            var brm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).BugReportManager;
            var brId = CreateBugReport(brm, "!1");
            var cId = brm.AddComment(Developer, brId, "a");
            var newText = new string('a', DomainConstraints.CommentTextMaxLength);
            brm.UpdateComment(Developer, cId, newText);
            Assert.That(newText, Is.EqualTo(brm.GetExtendedInfoById(Admin, brId).Comments.Single().Text));
        }

        [Test]
        public void DeleteComment_Deletes() {
            var brm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).BugReportManager;
            var brId = CreateBugReport(brm, "!1");
            var cId = brm.AddComment(Developer, brId, "a");
            brm.DeleteComment(Developer, cId);
            var survivingComments = brm.GetExtendedInfoById(Admin, brId).Comments;
            Assert.That(survivingComments,Is.Empty);
        }

        private const string JohnCarmack = "john carmack";

        private static void CreateScenario1(out IBugReportManager brm,
                                            out int idSw1, out int idSw2, out int idSw3,
                                            out int idSw1Rel1, out int idSw1Rel2, out int idSw1Rel3,
                                            out int idSw2Rel1, out int idSw2Rel2,
                                            out int idSw3Rel1, out int idSw3Rel2, out int idSw3Rel3, out int idSw3Rel4,
                                            out int idBrSw2Rel1_1, out int idBrSw2Rel1_2, out int idBrSw2Rel2_1, out int idBrSw2Rel2_2) {
            var sm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).SoftwareManager;
            brm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).BugReportManager;
            idSw1 = sm.AddSoftware(Admin, "s1", "ds1");
            idSw2 = sm.AddSoftware(Admin, "s2", "ds2");
            idSw3 = sm.AddSoftware(Admin, "s3", "ds3");

            idSw1Rel1 = sm.AddRelease(Admin, idSw1, new SoftwareVersion(1, 0), "idSw1Rel1", "idSw1Rel1 change log");
            idSw1Rel2 = sm.AddRelease(Admin, idSw1, new SoftwareVersion(1, 1), "idSw1Rel2", "idSw1Rel2 change log");
            idSw1Rel3 = sm.AddRelease(Admin, idSw1, new SoftwareVersion(1, 2), "idSw1Rel3", "idSw1Rel3 change log");

            idSw2Rel1 = sm.AddRelease(Admin, idSw2, new SoftwareVersion(2, 5), "idSw2Rel1", "idSw2Rel1 change log");
            idSw2Rel2 = sm.AddRelease(Admin, idSw2, new SoftwareVersion(3, 1), "idSw2Rel2", "idSw2Rel2 change log");

            idSw3Rel1 = sm.AddRelease(Admin, idSw3, new SoftwareVersion(1, 0), "idSw3Rel1", "idSw3Rel1 change log");
            idSw3Rel2 = sm.AddRelease(Admin, idSw3, new SoftwareVersion(1, 1), "idSw3Rel2", "idSw3Rel2 change log");
            idSw3Rel3 = sm.AddRelease(Admin, idSw3, new SoftwareVersion(1, 2), "idSw3Rel3", "idSw3Rel3 change log");
            idSw3Rel4 = sm.AddRelease(Admin, idSw3, new SoftwareVersion(4, 7), "idSw3Rel4", "idSw3Rel4 change log");

            idBrSw2Rel1_1 = brm.AddReport(Developer, idSw2Rel1, "a");
            idBrSw2Rel1_2 = brm.AddReport(NormalUser, idSw2Rel1, "bb");
            idBrSw2Rel2_1 = brm.AddReport(NormalUser2, idSw2Rel2, "ccc");
            idBrSw2Rel2_2 = brm.AddReport(Admin, idSw2Rel2, "dddd");

            brm.Assign(Admin, idBrSw2Rel1_1, JohnCarmack);
            brm.CloseAsRejected(Admin, idBrSw2Rel1_1);
            brm.CloseAsResolved(Admin, idBrSw2Rel1_2);
            brm.MarkAsDuplicateOf(Admin, idBrSw2Rel1_1, idBrSw2Rel1_2);
        }

        [Test]
        public void GetExtendedInfoBySoftware_ReturnsAll() {
            IBugReportManager brm;
            int idSw1, idSw2, idSw3, idSw1Rel1, idSw1Rel2, idSw1Rel3, idSw2Rel1, idSw2Rel2, idSw3Rel1, idSw3Rel2, idSw3Rel3, idSw3Rel4, idBrSw2Rel1_1, idBrSw2Rel1_2, idBrSw2Rel2_1, idBrSw2Rel2_2;
            CreateScenario1(out brm,
                            out idSw1, out idSw2, out idSw3,
                            out idSw1Rel1, out idSw1Rel2, out idSw1Rel3,
                            out idSw2Rel1, out idSw2Rel2,
                            out idSw3Rel1, out idSw3Rel2, out idSw3Rel3, out idSw3Rel4,
                            out idBrSw2Rel1_1, out idBrSw2Rel1_2, out idBrSw2Rel2_1, out idBrSw2Rel2_2);
            var allInfos = brm.GetExtendedInfoBySoftware(Admin, idSw2, null, BugReportFilter.All);

            Assert.That(new[] {idBrSw2Rel1_1, idBrSw2Rel1_2, idBrSw2Rel2_1, idBrSw2Rel2_2}, Is.EquivalentTo(allInfos.Select(br => br.Id)));

            var br1 = allInfos.Single(sw => sw.Id == idBrSw2Rel1_1);
            TestUtilities.ExtendedBugReportDTOEqualityAssert(br1, idBrSw2Rel1_1, Admin.Identity.Name,JohnCarmack,Developer.Identity.Name,"a",idSw2,"s2",new SoftwareVersion(2,5),BugReportStatus.ClosedAsRejected,new [] { idBrSw2Rel1_2 },new CommentInfoDTO[0] );

            var br2 = allInfos.Single(sw => sw.Id == idBrSw2Rel1_2);
            TestUtilities.ExtendedBugReportDTOEqualityAssert(br2, idBrSw2Rel1_2, null, null,NormalUser.Identity.Name, "bb", idSw2, "s2", new SoftwareVersion(2, 5), BugReportStatus.ClosedAsResolved, new int[0], new CommentInfoDTO[0]);

            var br3 = allInfos.Single(sw => sw.Id == idBrSw2Rel2_1);
            TestUtilities.ExtendedBugReportDTOEqualityAssert(br3, idBrSw2Rel2_1, null, null, NormalUser2.Identity.Name, "ccc", idSw2, "s2", new SoftwareVersion(3,1), BugReportStatus.OpenUnassigned, new int[0], new CommentInfoDTO[0]);

            var br4 = allInfos.Single(sw => sw.Id == idBrSw2Rel2_2);
            TestUtilities.ExtendedBugReportDTOEqualityAssert(br4, idBrSw2Rel2_2, null, null, Admin.Identity.Name, "dddd", idSw2, "s2", new SoftwareVersion(3, 1), BugReportStatus.OpenUnassigned, new int[0], new CommentInfoDTO[0]);
        }

        [Test]
        public void GetAllExtendedInfo_ReturnsAllInfo() {
            IBugReportManager brm;
            int idSw1, idSw2, idSw3, idSw1Rel1, idSw1Rel2, idSw1Rel3, idSw2Rel1, idSw2Rel2, idSw3Rel1, idSw3Rel2, idSw3Rel3, idSw3Rel4, idBrSw2Rel1_1, idBrSw2Rel1_2, idBrSw2Rel2_1, idBrSw2Rel2_2;
            CreateScenario1(out brm,
                            out idSw1, out idSw2, out idSw3,
                            out idSw1Rel1, out idSw1Rel2, out idSw1Rel3,
                            out idSw2Rel1, out idSw2Rel2,
                            out idSw3Rel1, out idSw3Rel2, out idSw3Rel3, out idSw3Rel4,
                            out idBrSw2Rel1_1, out idBrSw2Rel1_2, out idBrSw2Rel2_1, out idBrSw2Rel2_2);
            Assert.That(new[] {idBrSw2Rel1_1, idBrSw2Rel1_2, idBrSw2Rel2_1, idBrSw2Rel2_2},Is.EquivalentTo(brm.GetAllExtendedInfo(Admin).Select(br => br.Id)));
        }

        [Test]
        public void GetInfoByAssignee_ReturnsAllForCarmack() {
            IBugReportManager brm;
            int idSw1, idSw2, idSw3, idSw1Rel1, idSw1Rel2, idSw1Rel3, idSw2Rel1, idSw2Rel2, idSw3Rel1, idSw3Rel2, idSw3Rel3, idSw3Rel4, idBrSw2Rel1_1, idBrSw2Rel1_2, idBrSw2Rel2_1, idBrSw2Rel2_2;
            CreateScenario1(out brm,
                            out idSw1, out idSw2, out idSw3,
                            out idSw1Rel1, out idSw1Rel2, out idSw1Rel3,
                            out idSw2Rel1, out idSw2Rel2,
                            out idSw3Rel1, out idSw3Rel2, out idSw3Rel3, out idSw3Rel4,
                            out idBrSw2Rel1_1, out idBrSw2Rel1_2, out idBrSw2Rel2_1, out idBrSw2Rel2_2);
            Assert.That(idBrSw2Rel1_1, Is.EqualTo(brm.GetInfoByAssignee(Admin, JohnCarmack, BugReportFilter.All).Select(br => br.Id).Single()));
        }

        [Test]
        public void GetInfoByAssignee_ReturnsClosedForCarmack() {
            IBugReportManager brm;
            int idSw1, idSw2, idSw3, idSw1Rel1, idSw1Rel2, idSw1Rel3, idSw2Rel1, idSw2Rel2, idSw3Rel1, idSw3Rel2, idSw3Rel3, idSw3Rel4, idBrSw2Rel1_1, idBrSw2Rel1_2, idBrSw2Rel2_1, idBrSw2Rel2_2;
            CreateScenario1(out brm,
                            out idSw1, out idSw2, out idSw3,
                            out idSw1Rel1, out idSw1Rel2, out idSw1Rel3,
                            out idSw2Rel1, out idSw2Rel2,
                            out idSw3Rel1, out idSw3Rel2, out idSw3Rel3, out idSw3Rel4,
                            out idBrSw2Rel1_1, out idBrSw2Rel1_2, out idBrSw2Rel2_1, out idBrSw2Rel2_2);
            Assert.That(idBrSw2Rel1_1, Is.EqualTo(brm.GetInfoByAssignee(Admin, JohnCarmack, BugReportFilter.Closed).Select(br => br.Id).Single()));
        }

        [Test]
        public void GetInfoByAssignee_ReturnsOpenForCarmack() {
            IBugReportManager brm;
            int idSw1, idSw2, idSw3, idSw1Rel1, idSw1Rel2, idSw1Rel3, idSw2Rel1, idSw2Rel2, idSw3Rel1, idSw3Rel2, idSw3Rel3, idSw3Rel4, idBrSw2Rel1_1, idBrSw2Rel1_2, idBrSw2Rel2_1, idBrSw2Rel2_2;
            CreateScenario1(out brm,
                            out idSw1, out idSw2, out idSw3,
                            out idSw1Rel1, out idSw1Rel2, out idSw1Rel3,
                            out idSw2Rel1, out idSw2Rel2,
                            out idSw3Rel1, out idSw3Rel2, out idSw3Rel3, out idSw3Rel4,
                            out idBrSw2Rel1_1, out idBrSw2Rel1_2, out idBrSw2Rel2_1, out idBrSw2Rel2_2);
            Assert.That(brm.GetExtendedInfoByAssignee(Admin, JohnCarmack, BugReportFilter.Open),Is.Empty);
        }

        [Test]
        public void GetInfoByAssignee_Romero() {
            IBugReportManager brm;
            int idSw1, idSw2, idSw3, idSw1Rel1, idSw1Rel2, idSw1Rel3, idSw2Rel1, idSw2Rel2, idSw3Rel1, idSw3Rel2, idSw3Rel3, idSw3Rel4, idBrSw2Rel1_1, idBrSw2Rel1_2, idBrSw2Rel2_1, idBrSw2Rel2_2;
            CreateScenario1(out brm,
                            out idSw1, out idSw2, out idSw3,
                            out idSw1Rel1, out idSw1Rel2, out idSw1Rel3,
                            out idSw2Rel1, out idSw2Rel2,
                            out idSw3Rel1, out idSw3Rel2, out idSw3Rel3, out idSw3Rel4,
                            out idBrSw2Rel1_1, out idBrSw2Rel1_2, out idBrSw2Rel2_1, out idBrSw2Rel2_2);
            Assert.That(brm.GetExtendedInfoByAssignee(Admin, "john romero", BugReportFilter.All),Is.Empty);
        }

        [Test]
        public void GetInfoBySoftware_ReturnsAll() {
            IBugReportManager brm;
            int idSw1, idSw2, idSw3, idSw1Rel1, idSw1Rel2, idSw1Rel3, idSw2Rel1, idSw2Rel2, idSw3Rel1, idSw3Rel2, idSw3Rel3, idSw3Rel4, idBrSw2Rel1_1, idBrSw2Rel1_2, idBrSw2Rel2_1, idBrSw2Rel2_2;
            CreateScenario1(out brm,
                            out idSw1, out idSw2, out idSw3,
                            out idSw1Rel1, out idSw1Rel2, out idSw1Rel3,
                            out idSw2Rel1, out idSw2Rel2,
                            out idSw3Rel1, out idSw3Rel2, out idSw3Rel3, out idSw3Rel4,
                            out idBrSw2Rel1_1, out idBrSw2Rel1_2, out idBrSw2Rel2_1, out idBrSw2Rel2_2);
            Assert.That(new[] {idBrSw2Rel1_1, idBrSw2Rel1_2, idBrSw2Rel2_1, idBrSw2Rel2_2},Is.EquivalentTo(brm.GetInfoBySoftware(Admin, idSw2, null, BugReportFilter.All).Select(br => br.Id)));
        }

        [Test]
        public void GetInfoBySoftware_ReturnsUnassigned() {
            IBugReportManager brm;
            int idSw1, idSw2, idSw3, idSw1Rel1, idSw1Rel2, idSw1Rel3, idSw2Rel1, idSw2Rel2, idSw3Rel1, idSw3Rel2, idSw3Rel3, idSw3Rel4, idBrSw2Rel1_1, idBrSw2Rel1_2, idBrSw2Rel2_1, idBrSw2Rel2_2;
            CreateScenario1(out brm,
                            out idSw1, out idSw2, out idSw3,
                            out idSw1Rel1, out idSw1Rel2, out idSw1Rel3,
                            out idSw2Rel1, out idSw2Rel2,
                            out idSw3Rel1, out idSw3Rel2, out idSw3Rel3, out idSw3Rel4,
                            out idBrSw2Rel1_1, out idBrSw2Rel1_2, out idBrSw2Rel2_1, out idBrSw2Rel2_2);
            Assert.That(new[] {idBrSw2Rel1_2, idBrSw2Rel2_1, idBrSw2Rel2_2},Is.EquivalentTo(brm.GetInfoBySoftware(Admin, idSw2, null, BugReportFilter.Unassigned).Select(br => br.Id)));
        }

        [Test]
        public void GetExtendedInfoBySoftware_ReturnsAllSpecifyingVersion() {
            IBugReportManager brm;
            int idSw1, idSw2, idSw3, idSw1Rel1, idSw1Rel2, idSw1Rel3, idSw2Rel1, idSw2Rel2, idSw3Rel1, idSw3Rel2, idSw3Rel3, idSw3Rel4, idBrSw2Rel1_1, idBrSw2Rel1_2, idBrSw2Rel2_1, idBrSw2Rel2_2;
            CreateScenario1(out brm,
                            out idSw1, out idSw2, out idSw3,
                            out idSw1Rel1, out idSw1Rel2, out idSw1Rel3,
                            out idSw2Rel1, out idSw2Rel2,
                            out idSw3Rel1, out idSw3Rel2, out idSw3Rel3, out idSw3Rel4,
                            out idBrSw2Rel1_1, out idBrSw2Rel1_2, out idBrSw2Rel2_1, out idBrSw2Rel2_2);
            Assert.That(new[] {idBrSw2Rel1_1, idBrSw2Rel1_2},Is.EquivalentTo(brm.GetExtendedInfoBySoftware(Admin, idSw2, new SoftwareVersion(2, 5), BugReportFilter.All).Select(br => br.Id)));
        }

        [Test]
        public void GetInfoBySoftware_ReturnsRejected() {
            IBugReportManager brm;
            int idSw1, idSw2, idSw3, idSw1Rel1, idSw1Rel2, idSw1Rel3, idSw2Rel1, idSw2Rel2, idSw3Rel1, idSw3Rel2, idSw3Rel3, idSw3Rel4, idBrSw2Rel1_1, idBrSw2Rel1_2, idBrSw2Rel2_1, idBrSw2Rel2_2;
            CreateScenario1(out brm,
                            out idSw1, out idSw2, out idSw3,
                            out idSw1Rel1, out idSw1Rel2, out idSw1Rel3,
                            out idSw2Rel1, out idSw2Rel2,
                            out idSw3Rel1, out idSw3Rel2, out idSw3Rel3, out idSw3Rel4,
                            out idBrSw2Rel1_1, out idBrSw2Rel1_2, out idBrSw2Rel2_1, out idBrSw2Rel2_2);
            Assert.That(idBrSw2Rel1_1, Is.EqualTo(brm.GetInfoBySoftware(Admin, idSw2, null, BugReportFilter.Rejected).Select(br => br.Id).Single()));
        }

        [Test]
        public void GetInfoBySoftware_ReturnsResolved() {
            IBugReportManager brm;
            int idSw1, idSw2, idSw3, idSw1Rel1, idSw1Rel2, idSw1Rel3, idSw2Rel1, idSw2Rel2, idSw3Rel1, idSw3Rel2, idSw3Rel3, idSw3Rel4, idBrSw2Rel1_1, idBrSw2Rel1_2, idBrSw2Rel2_1, idBrSw2Rel2_2;
            CreateScenario1(out brm,
                            out idSw1, out idSw2, out idSw3,
                            out idSw1Rel1, out idSw1Rel2, out idSw1Rel3,
                            out idSw2Rel1, out idSw2Rel2,
                            out idSw3Rel1, out idSw3Rel2, out idSw3Rel3, out idSw3Rel4,
                            out idBrSw2Rel1_1, out idBrSw2Rel1_2, out idBrSw2Rel2_1, out idBrSw2Rel2_2);
            Assert.That(idBrSw2Rel1_2, Is.EqualTo(brm.GetInfoBySoftware(Admin, idSw2, null, BugReportFilter.Resolved).Select(br => br.Id).Single()));
        }

        [Test]
        public void GetInfoBySoftware_ReturnsAssigned() {
            IBugReportManager brm;
            int idSw1, idSw2, idSw3, idSw1Rel1, idSw1Rel2, idSw1Rel3, idSw2Rel1, idSw2Rel2, idSw3Rel1, idSw3Rel2, idSw3Rel3, idSw3Rel4, idBrSw2Rel1_1, idBrSw2Rel1_2, idBrSw2Rel2_1, idBrSw2Rel2_2;
            CreateScenario1(out brm,
                            out idSw1, out idSw2, out idSw3,
                            out idSw1Rel1, out idSw1Rel2, out idSw1Rel3,
                            out idSw2Rel1, out idSw2Rel2,
                            out idSw3Rel1, out idSw3Rel2, out idSw3Rel3, out idSw3Rel4,
                            out idBrSw2Rel1_1, out idBrSw2Rel1_2, out idBrSw2Rel2_1, out idBrSw2Rel2_2);
            Assert.That(idBrSw2Rel1_1, Is.EqualTo(brm.GetInfoBySoftware(Admin, idSw2, null, BugReportFilter.Assigned).Select(br => br.Id).Single()));
        }

        [Test]
        public void GetInfoBySoftware_ReturnsClosed() {
            IBugReportManager brm;
            int idSw1, idSw2, idSw3, idSw1Rel1, idSw1Rel2, idSw1Rel3, idSw2Rel1, idSw2Rel2, idSw3Rel1, idSw3Rel2, idSw3Rel3, idSw3Rel4, idBrSw2Rel1_1, idBrSw2Rel1_2, idBrSw2Rel2_1, idBrSw2Rel2_2;
            CreateScenario1(out brm,
                            out idSw1, out idSw2, out idSw3,
                            out idSw1Rel1, out idSw1Rel2, out idSw1Rel3,
                            out idSw2Rel1, out idSw2Rel2,
                            out idSw3Rel1, out idSw3Rel2, out idSw3Rel3, out idSw3Rel4,
                            out idBrSw2Rel1_1, out idBrSw2Rel1_2, out idBrSw2Rel2_1, out idBrSw2Rel2_2);
            Assert.That(new[] {idBrSw2Rel1_1, idBrSw2Rel1_2},Is.EquivalentTo(brm.GetInfoBySoftware(Admin, idSw2, null, BugReportFilter.Closed).Select(br => br.Id)));
        }

        [Test]
        public void GetInfoBySoftware_ReturnsOpen() {
            IBugReportManager brm;
            int idSw1, idSw2, idSw3, idSw1Rel1, idSw1Rel2, idSw1Rel3, idSw2Rel1, idSw2Rel2, idSw3Rel1, idSw3Rel2, idSw3Rel3, idSw3Rel4, idBrSw2Rel1_1, idBrSw2Rel1_2, idBrSw2Rel2_1, idBrSw2Rel2_2;
            CreateScenario1(out brm,
                            out idSw1, out idSw2, out idSw3,
                            out idSw1Rel1, out idSw1Rel2, out idSw1Rel3,
                            out idSw2Rel1, out idSw2Rel2,
                            out idSw3Rel1, out idSw3Rel2, out idSw3Rel3, out idSw3Rel4,
                            out idBrSw2Rel1_1, out idBrSw2Rel1_2, out idBrSw2Rel2_1, out idBrSw2Rel2_2);
            Assert.That(new[] {idBrSw2Rel2_1, idBrSw2Rel2_2},Is.EquivalentTo(brm.GetInfoBySoftware(Admin, idSw2, null, BugReportFilter.Open).Select(br => br.Id)));
        }

        [Test]
        public void GetInfoById_ThrowsOnNonexistentId() {
            var bm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).BugReportManager;
            Assert.That(() => bm.GetInfoById(Admin, 0xcafe),Throws.TypeOf<NonexistentObjectException>());
        }
    }

    public static class TestUtilities
    {
        public static void ReleaseInfoDTOEqualityAssert(ReleaseInfoDTO releaseInfoDTO, int id, string author, string changeLog, SoftwareVersion version)
        {
            Assert.That(author, Is.EqualTo(releaseInfoDTO.Author));
            Assert.That(changeLog, Is.EqualTo(releaseInfoDTO.ChangeLog));
            Assert.That(version, Is.EqualTo(releaseInfoDTO.Version));
        }

        public static void SoftwareInfoDTOEqualityAssert(SoftwareInfoDTO swInfo, int id, string name)
        {
            Assert.AreEqual(swInfo.Id, id);
            Assert.AreEqual(swInfo.Name, name);

        }

        public static void ExtendedSoftwareInfoDTOEqualityAssert(ExtendedSoftwareInfoDTO extendedSwInfo, int id, string name, string description, ReleaseInfoDTO[] releases)
        {
            SoftwareInfoDTOEqualityAssert(extendedSwInfo, id, name);
            Assert.That(extendedSwInfo.Description, Is.EqualTo(description));
            //Assert that extendedSwInfo.Releases is equivalent to releases
            Assert.AreEqual(releases.Length, extendedSwInfo.Releases.Length);
            foreach (var r in releases)
                ReleaseInfoDTOEqualityAssert(extendedSwInfo.Releases.Single(rr => rr.Id == r.Id), r.Id, r.Author,
                    r.ChangeLog, r.Version);
        }


        public static void BugReportDTOEqualityAssert(BugReportInfoDTO x, int Id, string assignedBy, string assignedTo,
            string createdBy, string description, int softwareId, string softwareName, SoftwareVersion softwareVersion,
            BugReportStatus status)
        {
            Assert.That(x.Id, Is.EqualTo(Id));
            Assert.That(x.AssignedBy, Is.EqualTo(assignedBy));
            Assert.That(x.AssignedTo, Is.EqualTo(assignedTo));
            Assert.That(x.CreatedBy, Is.EqualTo(createdBy));
            Assert.That(x.Description, Is.EqualTo(description));
            Assert.That(x.SoftwareId, Is.EqualTo(softwareId));
            Assert.That(x.SoftwareName, Is.EqualTo(softwareName));
            Assert.That(x.SoftwareVersion, Is.EqualTo(softwareVersion));
            Assert.That(x.Status, Is.EqualTo(status));
        }

        public static void CommentInfoDTOEqualityAssert(CommentInfoDTO x, CommentInfoDTO y)
        {
            Assert.That(x.Id,Is.EqualTo(y.Id));
            Assert.That(x.Author,Is.EqualTo(y.Author));
            Assert.That(x.Text,Is.EqualTo(y.Text));
        }

        public static void ExtendedBugReportDTOEqualityAssert(ExtendedBugReportInfoDTO x, int Id, string assignedBy,
            string assignedTo,
            string createdBy, string description, int softwareId, string softwareName, SoftwareVersion softwareVersion,
            BugReportStatus status, int[] duplicateOf, CommentInfoDTO[] comments)
        {
            BugReportDTOEqualityAssert(x, Id, assignedBy, assignedTo, createdBy, description, softwareId, softwareName,
                softwareVersion, status);
            Assert.That(x.DuplicateOf, Is.EquivalentTo(duplicateOf));
            var xComments = x.Comments;

            if (comments.Length > 0)
            {
                Assert.That(xComments.Length, Is.EqualTo(comments.Length));
                foreach (var c in comments)
                    CommentInfoDTOEqualityAssert(c, xComments.Single(cc => cc.Id == c.Id));
            }
            else
                Assert.That(xComments, Is.Empty);
        }
    }

    [Category("Basic")]
    [Category("SoftwareManager")]
    public class SoftwareManagerTests : TestRoot {
        [Test]
        public void GetInfoById_ThrowsOnNonexistentId() {
            var sm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).SoftwareManager;
            Assert.That(() => sm.GetInfoById(Admin, 123),Throws.TypeOf<NonexistentObjectException>());
        }

        [Test]
        public void GetAllInfo_ReturnsEmptyArrayOnEmptyDB() {
            var sm = Factory.LoadBugTracker(NormalUser, Configuration.ConnectionString).SoftwareManager;
            var software = sm.GetAllInfo(NormalUser);
            Assert.That(software,Is.Empty);
        }

        [Test]
        public void AddSoftware_ThrowsOnNameTooLong() {
            var sm = Factory.LoadBugTracker(NormalUser, Configuration.ConnectionString).SoftwareManager;
            Assert.That(() => sm.AddSoftware(Admin, new string('a', DomainConstraints.SoftwareNameMaxLength + 1), "a"), Throws.TypeOf<TapArgumentOutOfRangeException>());
        }

        [Test]
        public void AddSoftware_ThrowsOnDescriptionTooLong() {
            var sm = Factory.LoadBugTracker(NormalUser, Configuration.ConnectionString).SoftwareManager;
            Assert.That(() => sm.AddSoftware(Admin, "a", new string('a', DomainConstraints.SoftwareDescriptionMaxLength + 1)), Throws.TypeOf<TapArgumentOutOfRangeException>());
        }

        [Test]
        public void AddSoftware_ThrowsOnNameTooShort() {
            var sm = Factory.LoadBugTracker(NormalUser, Configuration.ConnectionString).SoftwareManager;
            Assert.That(() => sm.AddSoftware(Admin, string.Empty, "a"), Throws.TypeOf<TapArgumentOutOfRangeException>());
        }

        [Test]
        public void AddSoftware_ThrowsOnDescriptionTooShort() {
            var sm = Factory.LoadBugTracker(NormalUser, Configuration.ConnectionString).SoftwareManager;
            Assert.That(() => sm.AddSoftware(Admin, "a", string.Empty), Throws.TypeOf<TapArgumentOutOfRangeException>());
        }

        [TestCase(false, "a", "b")]
        [TestCase(true, "qui", "quo", "qua")]
        public void AddSoftware_InsertsCorrectNames(bool useAdmin, params string[] names) {
            var user = useAdmin ? Admin : NormalUser;
            var sm = Factory.LoadBugTracker(user, Configuration.ConnectionString).SoftwareManager;
            foreach (var name in names)
                sm.AddSoftware(Admin, name, "d");
            var allSw = sm.GetAllInfo(user);
            Assert.That(allSw.Select(sw => sw.Name),Is.EquivalentTo(names));
        }

        [TestCase(false, "a", "b")]
        [TestCase(true, "qui", "quo", "qua")]
        public void AddSoftware_InsertsCorrectDescriptions(bool useAdmin, params string[] names) {
            var namesAndDescriptions = names.Select(n => new {Name = n, Description = n + n}).ToArray();
            var user = useAdmin ? Admin : NormalUser;
            var sm = Factory.LoadBugTracker(user, Configuration.ConnectionString).SoftwareManager;
            foreach (var nd in namesAndDescriptions)
                sm.AddSoftware(Admin, nd.Name, nd.Description);
            var allSw = sm.GetAllExtendedInfo(user);
            Assert.That(allSw.Select(sw => sw.Description),Is.EquivalentTo(namesAndDescriptions.Select(nd => nd.Description)));
        }

        [TestCase(new[] {"a"}, new[] {"b"})]
        public void UpdateSoftware_UpdatesName(string[] oldNames, string[] newNames) {
            var sm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).SoftwareManager;
            var descriptions = oldNames.Select((_, i) => string.Format("desc{0}", i)).ToArray();
            var ids = oldNames.Zip(descriptions, (n, d) => sm.AddSoftware(Admin, n, d)).ToArray();
            for (int i = 0; i < ids.Length; i++)
                sm.UpdateSoftware(Admin, ids[i], newNames[i], descriptions[i]);
            var allSw = sm.GetAllInfo(Developer);
            Assert.That(allSw.Select(sw => sw.Name),Is.EquivalentTo(newNames));
        }

        [Test]
        public void UpdateSoftware_CreatingDuplicateNameThrows() {
            var sm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).SoftwareManager;
            int id1 = sm.AddSoftware(Admin, "a", "c");
            sm.AddSoftware(Admin, "b", "d");
            Assert.That(() => sm.UpdateSoftware(Admin, id1, "b", "e"), Throws.TypeOf<DuplicateNameException>());
        }

        [TestCase(new[] {"a"}, new[] {"b"})]
        public void UpdateSoftware_UpdatesDescription(string[] oldDescriptions, string[] newDescriptions) {
            var sm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).SoftwareManager;
            var names = oldDescriptions.Select((_, i) => string.Format("name{0}", i)).ToArray();
            var ids = oldDescriptions.Zip(names, (d, n) => sm.AddSoftware(Admin, n, d)).ToArray();
            for (int i = 0; i < ids.Length; i++)
                sm.UpdateSoftware(Admin, ids[i], names[i], newDescriptions[i]);
            var allSw = sm.GetAllExtendedInfo(Developer);
            Assert.That(allSw.Select(sw => sw.Description),Is.EquivalentTo(newDescriptions));
        }

        [Test]
        public void DeleteSoftware_DeletesIt() {
            var sm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).SoftwareManager;
            var id = sm.AddSoftware(Admin, "a", "b");
            sm.DeleteSoftware(Admin, id);
            Assert.That(sm.GetAllInfo(Admin),Is.Empty);
        }

        [Test]
        public void DeleteSoftware_DeletesItAndItsReleasesAndBugReportsWithCommentsAndDuplicates() {
            var sm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).SoftwareManager;
            var brm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).BugReportManager;
            var id = sm.AddSoftware(Admin, "a", "b");
            var otherSwId = sm.AddSoftware(Admin, "c", "d");
            var rid = sm.AddRelease(Admin, id, new SoftwareVersion(), "author", "change log");
            var otherReleaseId = sm.AddRelease(Admin, otherSwId, new SoftwareVersion(), "other author", "other change log");
            var brid = brm.AddReport(Admin, rid, "aaaa");
            brm.MarkAsDuplicateOf(Admin, brid, brm.AddReport(Admin, otherReleaseId, "xxx"));
            brm.MarkAsDuplicateOf(Admin, brid, brm.AddReport(Admin, otherReleaseId, "yyy"));
            brm.AddComment(Admin, brid, "bubu");
            sm.DeleteSoftware(Admin, id);
            sm.DeleteSoftware(Admin, otherSwId);
            Assert.That(sm.GetAllInfo(Admin),Is.Empty);
        }

        [Test]
        public void GetInfoById_ReturnsInfo() {
            var sm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).SoftwareManager;
            sm.AddSoftware(Admin, "a1", "b1");
            const string NAME = "a2";
            var id2 = sm.AddSoftware(Admin, NAME, "b2");
            sm.AddSoftware(Admin, "a3", "b3");
            var info = sm.GetInfoById(Developer, id2);
            Assert.That(info.Id, Is.EqualTo(id2));
            Assert.That(info.Name, Is.EqualTo(NAME));
        }

        [Test]
        public void GetExtendedInfoById_ReturnsInfo() {
            var sm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).SoftwareManager;
            sm.AddSoftware(Admin, "a1", "b1");
            const string name = "a2";
            var id2 = sm.AddSoftware(Admin, name, "b2");
            var ver1 = new SoftwareVersion(11, 22);
            const string authorRel1 = "au";
            var changeLog1 = "cl";
            var rId1 = sm.AddRelease(Admin, id2, ver1, authorRel1, changeLog1);
            var release1 = new ReleaseInfoDTO() {Author=authorRel1,ChangeLog= changeLog1, Id=rId1,Version=ver1};
            var ver2 = new SoftwareVersion(33, 44);
            var authorRel2 = new string('a', DomainConstraints.ReleaseAuthorMaxLength);
            var changeLogRel2 = new string('d', DomainConstraints.ReleaseChangeLogMaxLength);
            var rId2 = sm.AddRelease(Admin, id2, ver2, authorRel2, changeLogRel2);
            var release2 = new ReleaseInfoDTO() { Author = authorRel2, ChangeLog = changeLogRel2, Id = rId2, Version = ver2};
            sm.AddSoftware(Admin, "a3", "b3");
            var info = sm.GetExtendedInfoById(Developer, id2);
            TestUtilities.ExtendedSoftwareInfoDTOEqualityAssert(info, id2, name, "b2", new ReleaseInfoDTO[] {release1,release2});
        }


        [Test]
        public void UpdateRelease_Updates() {
            var sm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).SoftwareManager;
            sm.AddSoftware(Admin, "a1", "b1");
            const string name = "a2";
            var id2 = sm.AddSoftware(Admin, name, "b2");
            var rId = sm.AddRelease(Admin, id2, new SoftwareVersion(11, 22), "au", "cl");
            var newVersion = new SoftwareVersion(17, 18);
            const string newAuthor = "donald duck";
            const string newChangelog = "whatever...";
            sm.UpdateRelease(Admin, rId, newVersion, newAuthor, newChangelog);
            var info = sm.GetExtendedInfoById(Developer, id2).Releases.Single();
            TestUtilities.ReleaseInfoDTOEqualityAssert(info, id2,newAuthor,newChangelog,newVersion);
        }

        [Test]
        public void UpdateRelease_ThrowsIfDuplicateVersion() {
            var sm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).SoftwareManager;
            sm.AddSoftware(Admin, "a1", "b1");
            const string NAME = "a2";
            var id2 = sm.AddSoftware(Admin, NAME, "b2");
            var rId = sm.AddRelease(Admin, id2, new SoftwareVersion(11, 22), "au", "cl");
            var conflictingVersion = new SoftwareVersion(33, 44);
            sm.AddRelease(Admin, id2, conflictingVersion, "au", "cl");
            Assert.That(() => sm.UpdateRelease(Admin, rId, conflictingVersion, "donald duck", "whatever..."), Throws.TypeOf<DuplicateVersionException>());
        }

        [Test]
        public void DeleteRelease_Deletes() {
            var sm = Factory.LoadBugTracker(Admin, Configuration.ConnectionString).SoftwareManager;
            sm.AddSoftware(Admin, "a1", "b1");
            const string name = "a2";
            var id2 = sm.AddSoftware(Admin, name, "b2");
            const int major1 = 11;
            sm.AddRelease(Admin, id2, new SoftwareVersion(major1, 22), "au", "cl");
            var rId = sm.AddRelease(Admin, id2, new SoftwareVersion(33, 44), "au", "cl");
            const int major3 = 55;
            sm.AddRelease(Admin, id2, new SoftwareVersion(major3, 66), "au", "cl");
            const int major4 = 77;
            sm.AddRelease(Admin, id2, new SoftwareVersion(major4, 88), "au", "cl");
            sm.DeleteRelease(Admin, rId);
            var majors = sm.GetExtendedInfoById(Developer, id2).Releases.Select(r => r.Version.Major);
            Assert.That(new[] {major1, major3, major4},Is.EquivalentTo(majors));
        }
    }

}

This snippet took 0.12 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).