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"]; 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); }
/// <summary> /// Retrieves an existing entry from <see cref="Implementations"/> by ID or creates a new one if no appropriate one exists. /// </summary> /// <param name="id">The <see cref="ImplementationPreferences.ID"/> to search for.</param> /// <returns>The found or newly created <see cref="ImplementationPreferences"/>.</returns> public ImplementationPreferences this[string id] { get { var result = Implementations.FirstOrDefault(implementation => implementation.ID == id); if (result == null) { result = new ImplementationPreferences { ID = id }; Implementations.Add(result); } return(result); } }
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 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); }