public bool SaveSettings(NzbGetSettingsDto model) { _logger.Trace("Started NzbGetRepository"); _logger.Trace(string.Format("Looking for id {0} in the NzbGetRepository", model.Id)); var entity = Repo.Get(model.Id); if (entity == null) { _logger.Trace("Our entity is null so we are going to insert one"); var newEntity = new NzbGetSettings(); newEntity.InjectFrom(model); _logger.Trace("Inserting now"); var insertResult = Repo.Insert(newEntity); _logger.Trace(string.Format("Our insert was {0}", insertResult != long.MinValue)); return(insertResult != long.MinValue); } _logger.Trace("We found an entity so we are going to modify the existing one"); entity.Enabled = model.Enabled; entity.IpAddress = model.IpAddress; entity.Password = model.Password; entity.Port = model.Port; entity.Username = model.Username; entity.ShowOnDashboard = model.ShowOnDashboard; _logger.Trace("Updating modified record"); var result = Repo.Update(entity); _logger.Trace(string.Format("Our modify was {0}", result)); return(result); }
public void SetUp() { var mockRepo = new Mock <ISqlRepository <NzbGetSettings> >(); ExpectedGetLinks = new List <NzbGetSettings> { new NzbGetSettings { Id = 1, Enabled = true, IpAddress = "192", Password = "******", Port = 25, Username = "******", ShowOnDashboard = true } }; ExpectedLink = new NzbGetSettings { Id = 1, Enabled = true, IpAddress = "192", Password = "******", Port = 25, Username = "******", ShowOnDashboard = true }; mockRepo.Setup(x => x.GetAll()).Returns(ExpectedGetLinks).Verifiable(); mockRepo.Setup(x => x.Get(1)).Returns(ExpectedLink).Verifiable(); mockRepo.Setup(x => x.Update(It.IsAny <NzbGetSettings>())).Returns(true).Verifiable(); mockRepo.Setup(x => x.Insert(It.IsAny <NzbGetSettings>())).Returns(1).Verifiable(); MockRepo = mockRepo; Service = new NzbGetSettingsService(mockRepo.Object); }