This repository has been archived by the owner on Nov 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from TheEadie/reduce-duplication
Remove IStorable
- Loading branch information
Showing
17 changed files
with
123 additions
and
603 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,55 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using LazyStorage.Interfaces; | ||
|
||
namespace LazyStorage.Tests | ||
{ | ||
public sealed class TestObject : IStorable<TestObject> | ||
public class TestObject | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
private DateTime _startDate; | ||
private DateTime _endDate; | ||
public DateTime StartDate { get; set; } | ||
public DateTime EndDate { get; set; } | ||
|
||
public TestObject() | ||
{ | ||
Name = ""; | ||
} | ||
|
||
public Dictionary<string, string> GetStorageInfo() | ||
public bool ContentEquals(TestObject other) | ||
{ | ||
var info = new Dictionary<string, string> | ||
{ | ||
{"Id", Id.ToString()}, | ||
{"Name", Name}, | ||
{"StartDate", _startDate.Ticks.ToString()}, | ||
{"EndDate", _endDate.Ticks.ToString()} | ||
}; | ||
|
||
return info; | ||
return (other.Name == Name) | ||
&& (other.StartDate == StartDate) | ||
&& (other.EndDate == EndDate); | ||
} | ||
} | ||
|
||
public void InitialiseWithStorageInfo(Dictionary<string, string> info) | ||
public class TestObjectStorageConverter : IConverter<TestObject> | ||
{ | ||
public StorableObject GetStorableObject(TestObject item) | ||
{ | ||
Id = int.Parse(info["Id"]); | ||
Name = info["Name"]; | ||
_startDate = new DateTime(long.Parse(info["StartDate"])); | ||
_endDate = new DateTime(long.Parse(info["EndDate"])); | ||
var storableObject = new StorableObject(); | ||
|
||
storableObject.Info.Add("Id", item.Name); | ||
storableObject.Info.Add("StartDate", item.StartDate.Ticks.ToString()); | ||
storableObject.Info.Add("EndDate", item.EndDate.Ticks.ToString()); | ||
|
||
return storableObject; | ||
} | ||
|
||
public bool Equals(TestObject other) | ||
public TestObject GetOriginalObject(StorableObject info) | ||
{ | ||
return other.Id == Id; | ||
var orginalObject = new TestObject | ||
{ | ||
Name = info.Info["Id"], | ||
StartDate = new DateTime(long.Parse(info.Info["StartDate"])), | ||
EndDate = new DateTime(long.Parse(info.Info["EndDate"])) | ||
}; | ||
|
||
return orginalObject; | ||
} | ||
|
||
public bool ContentEquals(TestObject other) | ||
public bool IsEqual(StorableObject storageObject, TestObject realObject) | ||
{ | ||
return other.Id == Id | ||
&& other.Name == Name | ||
&& other._startDate == _startDate | ||
&& other._endDate == _endDate; | ||
return realObject.Name == storageObject.Info["Id"]; | ||
} | ||
} | ||
} |
Oops, something went wrong.