Inheritance: BaseController
Ejemplo n.º 1
0
        public void MockSetup()
        {
            F = new Fixture();

            var mockHardware = new Mock<IHardwareService>();
            var mockLog = new Mock<ILogger>();
            var mockApi = new Mock<IThirdPartyService>();
            var mocknzbGet = new Mock<ISettingsService<NzbGetSettingsDto>>();
            NzbDashSettings = new Mock<ISettingsService<NzbDashSettingsDto>>();

            var nzbDashSettingsDto = F.Create<NzbDashSettingsDto>();
            RamModel = F.Create<RamModel>();
            DriveModel = F.CreateMany<DriveModel>().ToList();
            var linksDto = F.CreateMany<LinksConfigurationDto>();

            mockHardware.Setup(x => x.GetUpTime()).Returns(new TimeSpan(2, 12, 33, 59, 200));
            mockHardware.Setup(x => x.GetRam()).Returns(RamModel);
            mockHardware.Setup(x => x.GetDrives()).Returns(DriveModel);

            NzbDashSettings.Setup(x => x.GetSettings()).Returns(nzbDashSettingsDto);

            HardwareServiceMock = mockHardware;
            ThirdPartyApi = mockApi;
            NzbGetMock = mocknzbGet;
            LinksDto = linksDto.ToList();

            _controller = new DashboardController(HardwareServiceMock.Object, ThirdPartyApi.Object,   mockLog.Object, null, null, NzbDashSettings.Object);
        }
Ejemplo n.º 2
0
        public void GetSabTabDownloads()
        {
            var mockNzbGet = new Mock<ISettingsService<NzbGetSettingsDto>>();
            var mockSab = new Mock<ISettingsService<SabNzbdSettingsDto>>();

            var sabSettings = F.Build<SabNzbdSettingsDto>().With(x => x.Enabled, true).Create();
            var sabQueue = F.Create<SabNzbdQueue>();

            mockSab.Setup(x => x.GetSettings()).Returns(sabSettings).Verifiable();
            ThirdPartyApi.Setup(x => x.GetSabNzbdQueue(It.IsAny<string>(), It.IsAny<string>())).Returns(sabQueue).Verifiable();

            _controller = new DashboardController(HardwareServiceMock.Object, ThirdPartyApi.Object,   new Mock<ILogger>().Object, mockNzbGet.Object, mockSab.Object, NzbDashSettings.Object);

            var result = (PartialViewResult)_controller.GetTabDownloads();
            var model = (TabDownloadViewModel)result.Model;

            Assert.That(model.Application, Is.EqualTo("Sabnzbd"));
            Assert.That(model.Downloads.Count, Is.EqualTo(sabQueue.jobs.Count));
            Assert.That(model.DownloadSpeed, Is.Not.Null);
            Assert.That(model.Downloads[0].DownloadPercentage, Is.Not.Null);
            Assert.That(model.Downloads[0].Status, Is.Not.Null);
            Assert.That(model.Downloads[0].ProgressBarClass, Is.Not.Null);
        }
Ejemplo n.º 3
0
        public void GetNzbGetTabDownloads()
        {
            var mockNzbGet = new Mock<ISettingsService<NzbGetSettingsDto>>();
            var mockSab = new Mock<ISettingsService<SabNzbdSettingsDto>>();
            var logger = new Mock<ILogger>();

            var nzbGetSettings = F.Build<NzbGetSettingsDto>().With(x => x.Enabled).Create();
            var nzbList = F.Create<NzbGetList>();
            var status = F.Create<NzbGetStatus>();

            mockNzbGet.Setup(x => x.GetSettings()).Returns(nzbGetSettings).Verifiable();
            ThirdPartyApi.Setup(x => x.GetNzbGetList(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Returns(nzbList).Verifiable();
               ThirdPartyApi.Setup(x => x.GetNzbGetStatus(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Returns(status).Verifiable();

            _controller = new DashboardController(HardwareServiceMock.Object, ThirdPartyApi.Object,   logger.Object, mockNzbGet.Object, mockSab.Object, NzbDashSettings.Object);

            var result = (PartialViewResult)_controller.GetTabDownloads();
            var model = (TabDownloadViewModel)result.Model;

            Assert.That(model.Application, Is.EqualTo("NzbGet"));
            Assert.That(model.DownloadSpeed, Is.EqualTo(MemorySizeConverter.SizeSuffix(status.Result.DownloadRate / 1024)));
            Assert.That(model.Downloads.Count, Is.EqualTo(nzbList.result.Count));
            Assert.That(model.Downloads[0].DownloadName, Is.EqualTo(nzbList.result[0].NZBName));
            Assert.That(model.Downloads[0].DownloadPercentage, Is.Not.Null);
            Assert.That(model.Downloads[0].Status, Is.Not.Null);
            Assert.That(model.Downloads[0].ProgressBarClass, Is.Not.Null);
        }
Ejemplo n.º 4
0
        public void GetSabDownloadCount()
        {
            var mockNzbGet = new Mock<ISettingsService<NzbGetSettingsDto>>();
            var mockSab = new Mock<ISettingsService<SabNzbdSettingsDto>>();

            var sabSettings = F.Create<SabNzbdSettingsDto>();
            var sabQueue = F.Create<SabNzbdQueue>();

            mockSab.Setup(x => x.GetSettings()).Returns(sabSettings).Verifiable();
            ThirdPartyApi.Setup(x => x.GetSabNzbdQueue(It.IsAny<string>(),It.IsAny<string>())).Returns(sabQueue).Verifiable();
            _controller = new DashboardController(HardwareServiceMock.Object, ThirdPartyApi.Object,   new Mock<ILogger>().Object, mockNzbGet.Object, mockSab.Object, NzbDashSettings.Object);

            var result = (PartialViewResult)_controller.GetDownloads();
            var model = (DashboardDownloadViewModel)result.Model;

            Assert.That(model.Application, Is.EqualTo("Sabnzbd"));
            Assert.That(model.DownloadItems, Is.EqualTo(sabQueue.jobs.Count));

            mockNzbGet.Verify(x => x.GetSettings(), Times.Once);
            mockSab.Verify(x => x.GetSettings(), Times.Once);
            ThirdPartyApi.Verify(x => x.GetNzbGetList(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never);
            ThirdPartyApi.Verify(x => x.GetSabNzbdQueue(It.IsAny<string>(),It.IsAny<string>()), Times.Once);
        }
Ejemplo n.º 5
0
        public void GetNoUsenetDownloaderDownloadCount()
        {
            var mockNzbGet = new Mock<ISettingsService<NzbGetSettingsDto>>();
            var mockSab = new Mock<ISettingsService<SabNzbdSettingsDto>>();
            var logger = new Mock<ILogger>();

            _controller = new DashboardController(HardwareServiceMock.Object, ThirdPartyApi.Object,   logger.Object, mockNzbGet.Object, mockSab.Object, NzbDashSettings.Object);

            var result = (PartialViewResult)_controller.GetDownloads();
            var model = (DashboardDownloadViewModel)result.Model;

            Assert.That(model.Application, Is.Null);
            logger.Verify(x => x.Trace(It.IsAny<string>()), Times.Once);
        }