diff --git a/src/NzbDrone.Core.Test/Housekeeping/Housekeepers/CleanupAdditionalUsersFixture.cs b/src/NzbDrone.Core.Test/Housekeeping/Housekeepers/CleanupAdditionalUsersFixture.cs new file mode 100644 index 000000000..065b9d375 --- /dev/null +++ b/src/NzbDrone.Core.Test/Housekeeping/Housekeepers/CleanupAdditionalUsersFixture.cs @@ -0,0 +1,37 @@ +using FizzWare.NBuilder; +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Core.Authentication; +using NzbDrone.Core.Housekeeping.Housekeepers; +using NzbDrone.Core.Test.Framework; + +namespace NzbDrone.Core.Test.Housekeeping.Housekeepers +{ + [TestFixture] + public class CleanupAdditionalUsersFixture : DbTest + { + [Test] + public void should_delete_additional_users() + { + var specs = Builder.CreateListOfSize(5) + .BuildListOfNew(); + + Db.InsertMany(specs); + + Subject.Clean(); + AllStoredModels.Should().HaveCount(1); + } + + [Test] + public void should_not_delete_if_only_one_user() + { + var spec = Builder.CreateNew() + .BuildNew(); + + Db.Insert(spec); + + Subject.Clean(); + AllStoredModels.Should().HaveCount(1); + } + } +} \ No newline at end of file diff --git a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index fa4a78235..2e61cbcdc 100644 --- a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -207,6 +207,7 @@ + diff --git a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupAdditionalUsers.cs b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupAdditionalUsers.cs new file mode 100644 index 000000000..62f58b962 --- /dev/null +++ b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupAdditionalUsers.cs @@ -0,0 +1,24 @@ +using NzbDrone.Core.Datastore; + +namespace NzbDrone.Core.Housekeeping.Housekeepers +{ + public class CleanupAdditionalUsers : IHousekeepingTask + { + private readonly IMainDatabase _database; + + public CleanupAdditionalUsers(IMainDatabase database) + { + _database = database; + } + + public void Clean() + { + var mapper = _database.GetDataMapper(); + + mapper.ExecuteNonQuery(@"DELETE FROM Users + WHERE ID NOT IN ( + SELECT ID FROM Users + LIMIT 1)"); + } + } +} diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index bc0ffc2a4..1f906f43c 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -497,6 +497,7 @@ +