Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Runtime/BinaryStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,14 @@ public IDisposable MultipleChangeScope()
/// <exception cref="UnregisteredTypeException">Thrown if the type is not registered.</exception>
public IList<T> GetListOf<T>(string key) => GetCollectionOf<T, ReactiveList<T>>(key);

/// <summary> Gets the read-only list associated with the specified key. </summary>
/// <typeparam name="T">The type of the list elements.</typeparam>
/// <param name="key">The key to get the list for.</param>
/// <returns>The read-only list associated with the key.</returns>
/// <exception cref="ObjectDisposedException">Thrown if the storage is disposed.</exception>
/// <exception cref="UnregisteredTypeException">Thrown if the type is not registered.</exception>
public IReadOnlyList<T> GetReadOnlyListOf<T>(string key) => GetCollectionOf<T, ReactiveList<T>>(key);

/// <summary> Gets the set associated with the specified key. </summary>
/// <typeparam name="T">The type of the set elements.</typeparam>
/// <param name="key">The key to get the set for.</param>
Expand All @@ -262,6 +270,14 @@ public IDisposable MultipleChangeScope()
/// <exception cref="UnregisteredTypeException">Thrown if the type is not registered.</exception>
public ISet<T> GetSetOf<T>(string key) => GetCollectionOf<T, ReactiveSet<T>>(key);

/// <summary> Gets the read-only set associated with the specified key. </summary>
/// <typeparam name="T">The type of the set elements.</typeparam>
/// <param name="key">The key to get the set for.</param>
/// <returns>The read-only set associated with the key.</returns>
/// <exception cref="ObjectDisposedException">Thrown if the storage is disposed.</exception>
/// <exception cref="UnregisteredTypeException">Thrown if the type is not registered.</exception>
public IReadOnlyCollection<T> GetReadOnlySetOf<T>(string key) => GetCollectionOf<T, ReactiveSet<T>>(key);

/// <summary> Gets the dictionary associated with the specified key. </summary>
/// <typeparam name="TKey">The type of the dictionary keys.</typeparam>
/// <typeparam name="TValue">The type of the dictionary values.</typeparam>
Expand All @@ -271,6 +287,15 @@ public IDisposable MultipleChangeScope()
/// <exception cref="UnregisteredTypeException">Thrown if the type is not registered.</exception>
public IDictionary<TKey, TValue> GetDictionaryOf<TKey, TValue>(string key) => GetCollectionOf<KeyValuePair<TKey, TValue>, ReactiveDictionary<TKey, TValue>>(key);

/// <summary> Gets the read-only dictionary associated with the specified key. </summary>
/// <typeparam name="TKey">The type of the dictionary keys.</typeparam>
/// <typeparam name="TValue">The type of the dictionary values.</typeparam>
/// <param name="key">The key to get the dictionary for.</param>
/// <returns>The read-only dictionary associated with the key.</returns>
/// <exception cref="ObjectDisposedException">Thrown if the storage is disposed.</exception>
/// <exception cref="UnregisteredTypeException">Thrown if the type is not registered.</exception>
public IReadOnlyDictionary<TKey, TValue> GetReadOnlyDictionaryOf<TKey, TValue>(string key) => GetCollectionOf<KeyValuePair<TKey, TValue>, ReactiveDictionary<TKey, TValue>>(key);

/// <summary> Determines whether the specified collection type is supported. </summary>
/// <typeparam name="T">The type of elements in the collection.</typeparam>
/// <typeparam name="TCollection">The type of the collection.</typeparam>
Expand Down
39 changes: 26 additions & 13 deletions Tests/BinaryStorageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ public void WhenReactiveListChanged_ThenValuesInStorageCorrect()
// Assert
storage.GetListOf<int>("numbers").Should().BeSameAs(list);
storage.GetListOf<int>("numbers").Should().Equal(list);
storage.GetReadOnlyListOf<int>("numbers").Should().BeSameAs(list);
storage.GetReadOnlyListOf<int>("numbers").Should().Equal(list);
}

[Test]
Expand Down Expand Up @@ -208,10 +210,12 @@ public void WhenReactiveListChanged_AndStorageReloaded_ThenValuesInStorageCorrec
{
// Assert
storage.Has("numbers");
var list = storage.GetListOf<int>("numbers");
list.Count.Should().Be(2);
list[0].Should().Be(1);
list[1].Should().Be(2);
storage.GetListOf<int>("numbers").Count.Should().Be(2);
storage.GetListOf<int>("numbers")[0].Should().Be(1);
storage.GetListOf<int>("numbers")[1].Should().Be(2);
storage.GetReadOnlyListOf<int>("numbers").Count.Should().Be(2);
storage.GetReadOnlyListOf<int>("numbers")[0].Should().Be(1);
storage.GetReadOnlyListOf<int>("numbers")[1].Should().Be(2);
}
}

Expand Down Expand Up @@ -249,6 +253,8 @@ public void WhenReactiveSetChanged_ThenValuesInStorageCorrect()
// Assert
storage.GetSetOf<int>("numbers").Should().BeSameAs(set);
storage.GetSetOf<int>("numbers").Should().Equal(set);
storage.GetReadOnlySetOf<int>("numbers").Should().BeSameAs(set);
storage.GetReadOnlySetOf<int>("numbers").Should().Equal(set);
}

[Test]
Expand Down Expand Up @@ -291,10 +297,12 @@ public void WhenReactiveSetChanged_AndStorageReloaded_ThenValuesInStorageCorrect
{
// Assert
storage.Has("numbers");
var set = storage.GetSetOf<int>("numbers");
set.Count.Should().Be(2);
set.Should().Contain(1);
set.Should().Contain(2);
storage.GetSetOf<int>("numbers").Count.Should().Be(2);
storage.GetSetOf<int>("numbers").Should().Contain(1);
storage.GetSetOf<int>("numbers").Should().Contain(2);
storage.GetReadOnlySetOf<int>("numbers").Count.Should().Be(2);
storage.GetReadOnlySetOf<int>("numbers").Should().Contain(1);
storage.GetReadOnlySetOf<int>("numbers").Should().Contain(2);
}
}

Expand Down Expand Up @@ -334,6 +342,8 @@ public void WhenReactiveDictionaryChanged_ThenValuesInStorageCorrect()
// Assert
storage.GetDictionaryOf<int, string>("numbers").Should().BeSameAs(map);
storage.GetDictionaryOf<int, string>("numbers").Should().Equal(map);
storage.GetReadOnlyDictionaryOf<int, string>("numbers").Should().BeSameAs(map);
storage.GetReadOnlyDictionaryOf<int, string>("numbers").Should().Equal(map);
}

[Test]
Expand Down Expand Up @@ -379,11 +389,14 @@ public void WhenReactiveDictionaryChanged_AndStorageReloaded_ThenValuesInStorage
{
// Assert
storage.Has("numbers");
var map = storage.GetDictionaryOf<int, string>("numbers");
map.Count.Should().Be(2);
map.Should().ContainKeys(1, 2);
map[1].Should().Be("one");
map[2].Should().Be("two");
storage.GetDictionaryOf<int, string>("numbers").Count.Should().Be(2);
storage.GetDictionaryOf<int, string>("numbers").Should().ContainKeys(1, 2);
storage.GetDictionaryOf<int, string>("numbers")[1].Should().Be("one");
storage.GetDictionaryOf<int, string>("numbers")[2].Should().Be("two");
storage.GetReadOnlyDictionaryOf<int, string>("numbers").Count.Should().Be(2);
storage.GetReadOnlyDictionaryOf<int, string>("numbers").Should().ContainKeys(1, 2);
storage.GetReadOnlyDictionaryOf<int, string>("numbers")[1].Should().Be("one");
storage.GetReadOnlyDictionaryOf<int, string>("numbers")[2].Should().Be("two");
}
}

Expand Down