public void Update_Success() { //Arrange var db = TestDbHelper.GetEmptyDatabase(); Mocker.SetConstant(db); var testProfile = new QualityProfile { Name = Guid.NewGuid().ToString(), Cutoff = QualityTypes.SDTV }; //Act var id = Convert.ToInt32(db.Insert(testProfile)); var currentProfile = db.SingleOrDefault<QualityProfile>(id); //Update currentProfile.Cutoff = QualityTypes.Bluray720p; Mocker.Resolve<QualityProvider>().Update(currentProfile); var updated = Mocker.Resolve<QualityProvider>().Get(currentProfile.QualityProfileId); //Assert updated.Name.Should().Be(currentProfile.Name); updated.Cutoff.Should().Be(QualityTypes.Bluray720p); updated.AllowedString.Should().Be(currentProfile.AllowedString); }
public virtual void Update(QualityProfile profile) { if (!_database.Exists<QualityProfile>("WHERE QualityProfileid = @0", profile.QualityProfileId)) { Logger.Error("Unable to update non-existing profile"); throw new InvalidOperationException("Unable to update non-existing profile"); } _database.Update(profile); }
public void Test_Storage_no_allowed() { //Arrange var database = TestDbHelper.GetEmptyDatabase(); var testProfile = new QualityProfile { Name = Guid.NewGuid().ToString(), Cutoff = QualityTypes.SDTV }; //Act var id = Convert.ToInt32(database.Insert(testProfile)); var fetch = database.SingleOrDefault<QualityProfile>(id); //Assert Assert.AreEqual(id, fetch.QualityProfileId); Assert.AreEqual(testProfile.Name, fetch.Name); Assert.AreEqual(testProfile.Cutoff, fetch.Cutoff); fetch.Allowed.Should().HaveCount(0); }
public virtual void SetupDefaultProfiles() { if (All().Count != 0) return; Logger.Info("Setting up default quality profiles"); var sd = new QualityProfile { Name = "SD", Allowed = new List<QualityTypes> { QualityTypes.SDTV, QualityTypes.DVD }, Cutoff = QualityTypes.SDTV }; var hd = new QualityProfile { Name = "HD", Allowed = new List<QualityTypes> { QualityTypes.HDTV, QualityTypes.WEBDL, QualityTypes.Bluray720p }, Cutoff = QualityTypes.HDTV }; Add(sd); Add(hd); }
public void Test_Storage() { //Arrange var database = TestDbHelper.GetEmptyDatabase(); var testProfile = new QualityProfile { Name = Guid.NewGuid().ToString(), Cutoff = QualityTypes.SDTV, Allowed = new List<QualityTypes> { QualityTypes.HDTV720p, QualityTypes.DVD }, }; //Act var id = Convert.ToInt32(database.Insert(testProfile)); var fetch = database.SingleOrDefault<QualityProfile>(id); //Assert Assert.AreEqual(id, fetch.QualityProfileId); Assert.AreEqual(testProfile.Name, fetch.Name); Assert.AreEqual(testProfile.Cutoff, fetch.Cutoff); Assert.AreEqual(testProfile.Allowed, fetch.Allowed); }
public void Test_Series_Quality() { //Arrange var database = TestDbHelper.GetEmptyDatabase(); var testProfile = new QualityProfile { Name = Guid.NewGuid().ToString(), Cutoff = QualityTypes.SDTV, Allowed = new List<QualityTypes> { QualityTypes.HDTV720p, QualityTypes.DVD }, }; var profileId = Convert.ToInt32(database.Insert(testProfile)); var series = Builder<Series>.CreateNew().Build(); series.QualityProfileId = profileId; database.Insert(testProfile); database.Insert(series); var result = database.Fetch<Series>(); result.Should().HaveCount(1); var profile = database.SingleOrDefault<QualityProfile>(result[0].QualityProfileId); Assert.AreEqual(profileId, result[0].QualityProfileId); Assert.AreEqual(testProfile.Name, profile.Name); }
private void WithWebdlCutoff() { var profile = new QualityProfile { Cutoff = QualityTypes.WEBDL }; Mocker.GetMock<QualityProvider>().Setup(s => s.Get(It.IsAny<int>())).Returns(profile); }
public JsonResult SaveQuality(QualityModel data) { if (ModelState.IsValid) { _configProvider.DefaultQualityProfile = data.DefaultQualityProfileId; //Saves only the Default Quality, skips User Profiles since none exist if (data.Profiles == null) return GetSuccessResult(); foreach (var profileModel in data.Profiles) { Logger.Debug(String.Format("Updating Profile: {0}", profileModel)); var profile = new QualityProfile(); profile.QualityProfileId = profileModel.QualityProfileId; profile.Name = profileModel.Name; profile.Cutoff = (QualityTypes)profileModel.Cutoff; profile.Allowed = new List<QualityTypes>(); if (profileModel.Sdtv) profile.Allowed.Add(QualityTypes.SDTV); if (profileModel.Dvd) profile.Allowed.Add(QualityTypes.DVD); if (profileModel.Hdtv) profile.Allowed.Add(QualityTypes.HDTV); if (profileModel.Webdl720p) profile.Allowed.Add(QualityTypes.WEBDL720p); if (profileModel.Webdl1080p) profile.Allowed.Add(QualityTypes.WEBDL1080p); if (profileModel.Bluray720p) profile.Allowed.Add(QualityTypes.Bluray720p); if (profileModel.Bluray1080p) profile.Allowed.Add(QualityTypes.Bluray1080p); //If the Cutoff value selected is not in the allowed list then return an error if (!profile.Allowed.Contains(profile.Cutoff)) return GetInvalidModelResult(); _qualityProvider.Update(profile); } var qualityTypesFromDb = _qualityTypeProvider.All(); qualityTypesFromDb.Single(q => q.QualityTypeId == 1).MaxSize = data.SdtvMaxSize; qualityTypesFromDb.Single(q => q.QualityTypeId == 2).MaxSize = data.DvdMaxSize; qualityTypesFromDb.Single(q => q.QualityTypeId == 4).MaxSize = data.HdtvMaxSize; qualityTypesFromDb.Single(q => q.QualityTypeId == 5).MaxSize = data.Webdl720pMaxSize; qualityTypesFromDb.Single(q => q.QualityTypeId == 3).MaxSize = data.Webdl1080pMaxSize; qualityTypesFromDb.Single(q => q.QualityTypeId == 6).MaxSize = data.Bluray720pMaxSize; qualityTypesFromDb.Single(q => q.QualityTypeId == 7).MaxSize = data.Bluray1080pMaxSize; _qualityTypeProvider.UpdateAll(qualityTypesFromDb); return GetSuccessResult(); } return GetInvalidModelResult(); }
public PartialViewResult GetQualityProfileView(QualityProfile profile) { var model = new QualityProfileModel(); model.QualityProfileId = profile.QualityProfileId; model.Name = profile.Name; model.Allowed = profile.Allowed; model.Sdtv = profile.Allowed.Contains(QualityTypes.SDTV); model.Dvd = profile.Allowed.Contains(QualityTypes.DVD); model.Hdtv = profile.Allowed.Contains(QualityTypes.HDTV); model.Webdl720p = profile.Allowed.Contains(QualityTypes.WEBDL720p); model.Webdl1080p = profile.Allowed.Contains(QualityTypes.WEBDL1080p); model.Bluray720p = profile.Allowed.Contains(QualityTypes.Bluray720p); model.Bluray1080p = profile.Allowed.Contains(QualityTypes.Bluray1080p); model.Cutoff = (int)profile.Cutoff; model.SdtvId = QualityTypes.SDTV.Id; model.DvdId = QualityTypes.DVD.Id; model.HdtvId = QualityTypes.HDTV.Id; model.Webdl720pId = QualityTypes.WEBDL720p.Id; model.Webdl1080pId = QualityTypes.WEBDL1080p.Id; model.Bluray720pId = QualityTypes.Bluray720p.Id; model.Bluray1080pId = QualityTypes.Bluray1080p.Id; return PartialView("QualityProfileItem", model); }
public PartialViewResult AddProfile() { var qualityProfile = new QualityProfile { Name = "New Profile", Allowed = new List<QualityTypes> { QualityTypes.Unknown }, Cutoff = QualityTypes.Unknown }; qualityProfile.QualityProfileId = _qualityProvider.Add(qualityProfile); return GetQualityProfileView(qualityProfile); }
public virtual int Add(QualityProfile profile) { return Convert.ToInt32(_database.Insert(profile)); }
public void Setup() { db = TestDbHelper.GetEmptyDatabase(); int currentFileId = 0; var qulityProfile = new QualityProfile { Name = "TestProfile", Allowed = new List<QualityTypes> { QualityTypes.DVD, QualityTypes.Bluray1080p }, Cutoff = QualityTypes.DVD }; db.Insert(qulityProfile); foreach (var _seriesId in seriesIds) { int seriesId = _seriesId; var series = Builder<Series>.CreateNew() .With(s => s.SeriesId = seriesId) .With(s => s.Monitored = true) .Build(); db.Insert(series); foreach (var _seasonNumber in seasonsNumbers) { for (int i = 1; i <= Episodes_Per_Season; i++) { var epFileId = 0; if (i < 10) { var epFile = Builder<EpisodeFile>.CreateNew() .With(e => e.SeriesId = seriesId) .And(e => e.SeasonNumber = _seasonNumber) .And(e => e.Path = Guid.NewGuid().ToString()) .Build(); files.Add(epFile); currentFileId++; epFileId = currentFileId; } var episode = Builder<Episode>.CreateNew() .With(e => e.SeriesId = seriesId) .And(e => e.SeasonNumber = _seasonNumber) .And(e => e.EpisodeNumber = i) .And(e => e.Ignored = false) .And(e => e.TvDbEpisodeId = episodes.Count + 1) .And(e => e.EpisodeFileId = epFileId) .And(e => e.AirDate = DateTime.Today.AddDays(-20)) .Build(); episodes.Add(episode); } } } db.InsertMany(episodes); db.InsertMany(files); }