/// <summary> /// Creates a new selection candidate. /// </summary> /// <param name="feedUri">The file name or URL of the feed listing the implementation.</param> /// <param name="feedPreferences">The <see cref="FeedPreferences"/> for <see cref="FeedUri"/>.</param> /// <param name="implementation">The implementation this selection candidate references.</param> /// <param name="requirements">A set of requirements/restrictions the <paramref name="implementation"/> needs to fullfill for <see cref="IsSuitable"/> to be <c>true</c>.</param> /// <param name="offlineUncached">Mark this candidate as unsuitable because it is uncached and <see cref="Config.NetworkUse"/> is set to <see cref="NetworkLevel.Offline"/>.</param> /// <exception cref="InvalidDataException"><paramref name="implementation"/>'s <see cref="ImplementationBase.ID"/> is empty.</exception> public SelectionCandidate([NotNull] FeedUri feedUri, [NotNull] FeedPreferences feedPreferences, [NotNull] Implementation implementation, [NotNull] Requirements requirements, bool offlineUncached = false) { #region Sanity checks if (feedUri == null) { throw new ArgumentNullException(nameof(feedUri)); } if (feedPreferences == null) { throw new ArgumentNullException(nameof(feedPreferences)); } if (implementation == null) { throw new ArgumentNullException(nameof(implementation)); } if (requirements == null) { throw new ArgumentNullException(nameof(requirements)); } #endregion if (string.IsNullOrEmpty(implementation.ID)) { throw new InvalidDataException(string.Format(Resources.ImplementationMissingID, implementation, feedUri)); } FeedUri = feedUri; FeedPreferences = feedPreferences; Implementation = implementation; _implementationPreferences = feedPreferences[implementation.ID]; CheckSuitabilty(requirements, offlineUncached); }
public void TestNormalize() { var keep = new ImplementationPreferences {ID = "id1", UserStability = Stability.Testing}; var superflous = new ImplementationPreferences {ID = "id2"}; var preferences = new FeedPreferences {Implementations = {keep, superflous}}; preferences.Normalize(); CollectionAssert.AreEquivalent(new[] {keep}, preferences.Implementations); }
public void TestNormalize() { var keep = new ImplementationPreferences {ID = "id1", UserStability = Stability.Testing}; var superflous = new ImplementationPreferences {ID = "id2"}; var preferences = new FeedPreferences {Implementations = {keep, superflous}}; preferences.Normalize(); preferences.Implementations.Should().BeEquivalentTo(keep); }
public void TestGetImplementationPreferences() { var preferences = new FeedPreferences(); var prefs1 = preferences["id1"]; Assert.AreSame(prefs1, preferences["id1"], "Second call with same ID should return same reference"); var prefs2 = new ImplementationPreferences {ID = "id2"}; preferences.Implementations.Add(prefs2); Assert.AreSame(prefs2, preferences["id2"], "Call with pre-existing ID should return existing reference"); CollectionAssert.AreEquivalent(new[] {prefs1, prefs2}, preferences.Implementations); }
public void TestGetImplementationPreferences() { var preferences = new FeedPreferences(); var prefs1 = preferences["id1"]; preferences["id1"].Should().BeSameAs(prefs1, because: "Second call with same ID should return same reference"); var prefs2 = new ImplementationPreferences {ID = "id2"}; preferences.Implementations.Add(prefs2); preferences["id2"].Should().BeSameAs(prefs2, because: "Call with pre-existing ID should return existing reference"); preferences.Implementations.Should().BeEquivalentTo(prefs1, prefs2); }