using System; using System.Collections.Generic; using System.Linq; using FluentAssertions; using Moq; using NUnit.Framework; using NzbDrone.Core.Download; using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test.Messaging.Commands { [TestFixture] public class CommandQueueManagerFixture : CoreTest { [SetUp] public void Setup() { var id = 0; var commands = new List(); Mocker.GetMock() .Setup(s => s.Insert(It.IsAny())) .Returns(c => { c.Id = id + 1; commands.Add(c); id++; return c; }); Mocker.GetMock() .Setup(s => s.Get(It.IsAny())) .Returns(c => { return commands.SingleOrDefault(e => e.Id == c); }); } [Test] public void should_not_remove_commands_for_five_minutes_after_they_end() { var command = Subject.Push(new CheckForFinishedDownloadCommand()); // Start the command to mimic CommandQueue's behaviour command.StartedAt = DateTime.Now; command.Status = CommandStatus.Started; Subject.Start(command); Subject.Complete(command, "All done"); Subject.CleanCommands(); Subject.Get(command.Id).Should().NotBeNull(); Mocker.GetMock() .Verify(v => v.Get(It.IsAny()), Times.Never()); } } }