public object this[Type type] { get { var key = ProfileStorage.Key(type); var profileStorage = _persister.FindBy(_profileId, key).FirstOrDefault(); return profileStorage != null ? profileStorage.GetValue() : null; } set { if (value == null) return; var key = ProfileStorage.Key(value.GetType()); var valueStorage = _persister.FindBy(_profileId, key).FirstOrDefault(); if (valueStorage != null) { valueStorage.SetValue(value); _persister.Update(valueStorage); } else { valueStorage = new ProfileStorage(new TypeNameWithoutVersion(value.GetType())) {ProfileId = _profileId.Value}; valueStorage.SetValue(value); _persister.Insert(valueStorage); } } }
public void ShouldStoreAndRetrieveRecord() { var profileStorage = new ProfileStorage {ProfileId = _profile.Id, ValueKey = "value key"}; profileStorage.SetValue("my value"); _persister.Insert(profileStorage); var retrieved = _persister.FindBy(_profile.Id).Single(); retrieved.Should(Be.EqualTo(profileStorage).Using<ProfileStorage>(Compare)); }
public void ShouldDeleteByNameWhenNameContainsSpecialCharacters() { var profileStorage = new ProfileStorage { ProfileId = _profile.Id, ValueKey = "value key", Name = "'test" }; profileStorage.SetValue("my value"); _persister.Insert(profileStorage); _persister.Delete(_profile.Id, profileStorage.ValueKey, profileStorage.Name); _persister.Contains(profileStorage.Name, _profile.Id, profileStorage.ValueKey, profileStorage.GetValue()).Should( Be.False); }
public void Update(params ProfileStorage[] profileStorages) { using (var context = CreateContext()) { foreach (var profileStorage in profileStorages) { var updatedProfileStorage = new ProfileStorage(new TypeNameWithoutVersion(profileStorage.ValueKey)) { Id = profileStorage.Id, ProfileId = profileStorage.ProfileId, Name = profileStorage.Name}; context.ProfileStorages.Attach(updatedProfileStorage); updatedProfileStorage.SetValue(profileStorage.GetValue()); } Flush(context); } }
private static int Compare(ProfileStorage actual, ProfileStorage expected) { if (actual.Id != expected.Id) return -1; if (actual.ProfileId != expected.ProfileId) return -1; if (actual.Name != expected.Name) return -1; if (!actual.GetValue().Equals(expected.GetValue())) return -1; return 0; }
private ProfileStorage[] CreateProfileStorages() { var profileStorage = new ProfileStorage {ProfileId = _profile.Id, ValueKey = "value key", Name = "Name"}; profileStorage.SetValue("my value"); var profileStorage1 = new ProfileStorage {ProfileId = _profile.Id, ValueKey = "value key1", Name = "Name"}; profileStorage1.SetValue("my value1"); var profileStorage2 = new ProfileStorage {ProfileId = _profile.Id, ValueKey = "value key2", Name = "Name2"}; profileStorage2.SetValue("my value2"); var profileStorages = new[] {profileStorage, profileStorage1, profileStorage2}; _persister.Insert(profileStorages); return profileStorages; }
partial void DeleteProfileStorage(ProfileStorage instance);
partial void UpdateProfileStorage(ProfileStorage instance);
partial void InsertProfileStorage(ProfileStorage instance);