using System.Collections.Generic; using Moq; using NUnit.Framework; using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Qualities; using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test.Qualities { [TestFixture] public class QualityDefinitionServiceFixture : CoreTest { [Test] public void init_should_add_all_definitions() { Subject.Handle(new ApplicationStartedEvent()); Mocker.GetMock() .Verify(v => v.InsertMany(It.Is>(d => d.Count == Quality.All.Count)), Times.Once()); } [Test] public void init_should_insert_any_missing_definitions() { Mocker.GetMock() .Setup(s => s.All()) .Returns(new List { new QualityDefinition(Quality.MP3_192) { Weight = 1, MinSize = 0, MaxSize = 100, Id = 20 } }); Subject.Handle(new ApplicationStartedEvent()); Mocker.GetMock() .Verify(v => v.InsertMany(It.Is>(d => d.Count == Quality.All.Count - 1)), Times.Once()); } [Test] public void init_should_update_existing_definitions() { Mocker.GetMock() .Setup(s => s.All()) .Returns(new List { new QualityDefinition(Quality.MP3_192) { Weight = 1, MinSize = 0, MaxSize = 100, Id = 20 } }); Subject.Handle(new ApplicationStartedEvent()); Mocker.GetMock() .Verify(v => v.UpdateMany(It.Is>(d => d.Count == 1)), Times.Once()); } [Test] public void init_should_remove_old_definitions() { Mocker.GetMock() .Setup(s => s.All()) .Returns(new List { new QualityDefinition(new Quality { Id = 100, Name = "Test" }) { Weight = 1, MinSize = 0, MaxSize = 100, Id = 20 } }); Subject.Handle(new ApplicationStartedEvent()); Mocker.GetMock() .Verify(v => v.DeleteMany(It.Is>(d => d.Count == 1)), Times.Once()); } } }