Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Commit

Permalink
Remove IStorable
Browse files Browse the repository at this point in the history
Too many bugs and its just a poorer way of doing this.
  • Loading branch information
TheEadie committed Feb 16, 2018
1 parent 6869f86 commit 1018da6
Show file tree
Hide file tree
Showing 14 changed files with 15 additions and 261 deletions.
67 changes: 2 additions & 65 deletions src/LazyStorage.Tests/PersistenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,69 +19,6 @@ public sealed class PersistenceTests : IDisposable

[Theory, MemberData(nameof(StorageTypes))]
public void CanSaveToStorage(ITestStorage storage)
{
_currentStorage = storage;
var dal = storage.GetStorage();
var repo = dal.GetRepository<TestObjectIStorable>();
var obj = new TestObjectIStorable();

repo.Set(obj);
dal.Save();

Assert.True(repo.Get().Any(), "The object could not be added to the repository");
}

[Theory, MemberData(nameof(StorageTypes))]
public void StoragePersistsBetweenSessions(ITestStorage storage)
{
_currentStorage = storage;
var dal = storage.GetStorage();
var repo = dal.GetRepository<TestObjectIStorable>();
var obj = new TestObjectIStorable();

repo.Set(obj);
dal.Save();

var dal2 = storage.GetStorage();
var repo2 = dal2.GetRepository<TestObjectIStorable>();

Assert.True(repo2.Get().Single().ContentEquals(obj), "The object could not be found in the persistent repo");
}

[Theory, MemberData(nameof(StorageTypes))]
public void StorageDoesNotPersistIfDiscarded(ITestStorage storage)
{
_currentStorage = storage;

// Create an object in memory
var obj1 = new TestObjectIStorable();

// Insert into the repo
var dal = storage.GetStorage();
var repo = dal.GetRepository<TestObjectIStorable>();
repo.Set(obj1);
dal.Save();

// Make some changes
var obj2 = new TestObjectIStorable
{
Id = 1,
Name = "Test"
};

// Update the object in the repo but discard changes
repo.Set(obj2);
dal.Discard();

var dal2 = storage.GetStorage();
var repo2 = dal2.GetRepository<TestObjectIStorable>();

var testObject = repo2.Get().Single();
Assert.True(testObject.ContentEquals(obj1), "The object changes were not reverted in the repo");
}

[Theory, MemberData(nameof(StorageTypes))]
public void CanSaveToStorageWithConverter(ITestStorage storage)
{
_currentStorage = storage;
var dal = storage.GetStorage();
Expand All @@ -103,7 +40,7 @@ public void CanSaveToStorageWithConverter(ITestStorage storage)
}

[Theory, MemberData(nameof(StorageTypes))]
public void StoragePersistsBetweenSessionsWithConverter(ITestStorage storage)
public void StoragePersistsBetweenSessions(ITestStorage storage)
{
_currentStorage = storage;
var dal = storage.GetStorage();
Expand All @@ -128,7 +65,7 @@ public void StoragePersistsBetweenSessionsWithConverter(ITestStorage storage)
}

[Theory, MemberData(nameof(StorageTypes))]
public void StorageDoesNotPersistIfDiscardedWithConverter(ITestStorage storage)
public void StorageDoesNotPersistIfDiscarded(ITestStorage storage)
{
_currentStorage = storage;

Expand Down
8 changes: 4 additions & 4 deletions src/LazyStorage.Tests/RepositoryWithConverterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

namespace LazyStorage.Tests
{
public class RepositoryWithConverterTests
public class RepositoryTests
{
public static IEnumerable<object[]> Repos => new[]
{
new object[] {new InMemoryRepositoryWithConverter<TestObject>(new TestObjectStorageConverter())},
new object[] {new XmlRepositoryWithConverter<TestObject>("RepositoryWithConverterTests", new TestObjectStorageConverter())},
new object[] {new JsonRepositoryWithConverter<TestObject>("RepositoryWithConverterTests", new TestObjectStorageConverter())},
new object[] {new InMemoryRepository<TestObject>(new TestObjectStorageConverter())},
new object[] {new XmlRepository<TestObject>("RepositoryWithConverter", new TestObjectStorageConverter())},
new object[] {new JsonRepository<TestObject>("RepositoryWithConverter", new TestObjectStorageConverter())},
};

[Theory, MemberData(nameof(Repos))]
Expand Down
73 changes: 0 additions & 73 deletions src/LazyStorage.Tests/RepositoryWithIStorableObjectTests.cs

This file was deleted.

53 changes: 0 additions & 53 deletions src/LazyStorage.Tests/TestObjectIStorable.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

namespace LazyStorage.InMemory
{
internal class InMemoryRepositoryWithConverter<T> : IRepository<T>
internal class InMemoryRepository<T> : IRepository<T>
{
private readonly IConverter<T> _converter;

public InMemoryRepositoryWithConverter(IConverter<T> converter)
public InMemoryRepository(IConverter<T> converter)
{
_converter = converter;
}
Expand Down
8 changes: 1 addition & 7 deletions src/LazyStorage/InMemory/InMemoryStorage.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using LazyStorage.Interfaces;
using LazyStorage.Xml;

namespace LazyStorage.InMemory
{
Expand All @@ -13,18 +12,13 @@ public InMemoryStorage()
_repos = new Dictionary<string, IRepository>();
}

public IRepository<T> GetRepository<T>() where T : IStorable<T>, new()
{
return GetRepository(new StorableConverter<T>());
}

public IRepository<T> GetRepository<T>(IConverter<T> converter)
{
var typeAsString = typeof(T).ToString();

if (!_repos.ContainsKey(typeAsString))
{
var inMemoryRepositoryWithConverter = new InMemoryRepositoryWithConverter<T>(converter);
var inMemoryRepositoryWithConverter = new InMemoryRepository<T>(converter);
inMemoryRepositoryWithConverter.Load();
_repos.Add(typeAsString, inMemoryRepositoryWithConverter);
}
Expand Down
12 changes: 0 additions & 12 deletions src/LazyStorage/Interfaces/IStorable.cs

This file was deleted.

1 change: 0 additions & 1 deletion src/LazyStorage/Interfaces/IStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{
public interface IStorage
{
IRepository<T> GetRepository<T>() where T : IStorable<T>, new();
IRepository<T> GetRepository<T>(IConverter<T> converter);
void Save();
void Discard();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

namespace LazyStorage.Json
{
internal class JsonRepositoryWithConverter<T> : IRepository<T>
internal class JsonRepository<T> : IRepository<T>
{
private readonly string _uri;
private List<T> _repository = new List<T>();
private readonly IConverter<T> _converter;

public JsonRepositoryWithConverter(string storageFolder, IConverter<T> converter)
public JsonRepository(string storageFolder, IConverter<T> converter)
{
_uri = $"{storageFolder}{typeof(T)}.json";
_converter = converter;
Expand Down
8 changes: 1 addition & 7 deletions src/LazyStorage/Json/JsonStorage.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using LazyStorage.Interfaces;
using LazyStorage.Xml;

namespace LazyStorage.Json
{
Expand All @@ -15,18 +14,13 @@ public JsonStorage(string storageFolder)
_storageFolder = storageFolder;
}

public IRepository<T> GetRepository<T>() where T : IStorable<T>, new()
{
return GetRepository(new StorableConverter<T>());
}

public IRepository<T> GetRepository<T>(IConverter<T> converter)
{
var typeAsString = typeof(T).ToString();

if (!_repos.ContainsKey(typeAsString))
{
var jsonRepositoryWithConverter = new JsonRepositoryWithConverter<T>(_storageFolder, converter);
var jsonRepositoryWithConverter = new JsonRepository<T>(_storageFolder, converter);
jsonRepositoryWithConverter.Load();
_repos.Add(typeAsString, jsonRepositoryWithConverter);
}
Expand Down
25 changes: 0 additions & 25 deletions src/LazyStorage/StorableConverter.cs

This file was deleted.

1 change: 0 additions & 1 deletion src/LazyStorage/StorableObject.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Reflection;

namespace LazyStorage
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

namespace LazyStorage.Xml
{
internal class XmlRepositoryWithConverter<T> : IRepository<T>
internal class XmlRepository<T> : IRepository<T>
{
private readonly string _uri;
private List<T> _repository = new List<T>();
private readonly IConverter<T> _converter;

public XmlRepositoryWithConverter(string storageFolder, IConverter<T> converter)
public XmlRepository(string storageFolder, IConverter<T> converter)
{
_uri = $"{storageFolder}{typeof(T)}.xml";
_converter = converter;
Expand Down
Loading

0 comments on commit 1018da6

Please sign in to comment.