public void AssignGroupToStoredFavorite_Update_SavesToDatabase() { IFavorite favorite = this.AddFavoriteToPrimaryPersistence(); IGroup groupToDelete = this.PrimaryFactory.CreateGroup("TestGroupToDelete"); this.PrimaryPersistence.Groups.Add(groupToDelete); this.PrimaryFavorites.UpdateFavorite(favorite, new List <IGroup> { groupToDelete }); IGroup groupToAdd = this.PrimaryFactory.CreateGroup("TestGroupToAdd"); this.PrimaryFavorites.UpdateFavorite(favorite, new List <IGroup> { groupToAdd }); DbFavorite checkFavorite = this.CheckFavorites.Include(f => f.Groups).FirstOrDefault(); Assert.AreEqual(1, checkFavorite.Groups.Count, "Child group is missing"); IGroup group = checkFavorite.Groups.FirstOrDefault(); Assert.IsTrue(group.Name == "TestGroupToAdd", "wrong merge of groups"); int targetGroupsCount = this.CheckDatabase.Groups.Count(); Assert.AreEqual(2, targetGroupsCount, "Groups count was changed"); Assert.AreEqual(2, this.updatedCount, "Event wasn't delivered"); }
public void StoredFavorite_Delete_RemovesFromDatabaseTablesAndFiresEvent() { DbFavorite favorite = this.AddFavoriteToPrimaryPersistence(); // force the password to be stored to ensure ((IFavorite)favorite).Security.EncryptedPassword = VALIDATION_VALUE; this.PrimaryFavorites.Update(favorite); this.PrimaryFavorites.Delete(favorite); int after = this.CheckFavorites.Count(); Assert.AreEqual(0, after, "Favorite wasn't deleted"); int displayOptions = this.CheckDatabase.DisplayOptions.Count(); Assert.AreEqual(0, displayOptions, "DisplayOptions wasn't deleted"); int security = this.CheckDatabase.Security.Count(); Assert.AreEqual(0, security, "Security wasn't deleted"); int execute = this.CheckDatabase.BeforeConnectExecute.Count(); Assert.AreEqual(0, execute, "BeforeConnectExecute wasn't deleted"); int credentialBase = this.CheckDatabase.CredentialBase.Count(); Assert.AreEqual(0, credentialBase, "CredentialBase wasn't deleted"); Assert.AreEqual(1, this.deletedCount, "Event wasn't delivered"); }
private void RecordHistory() { InjectionDateTime.SetTestDateTime(); DbFavorite favorite = this.AddFavoriteToPrimaryPersistence(); this.PrimaryHistory.RecordHistoryItem(favorite); }
/// <summary> /// Creates test favorite and adds it to the primary persistence. /// Returns newly created favorite /// </summary> internal DbFavorite AddFavoriteToPrimaryPersistence() { DbFavorite favorite = this.CreateTestFavorite(); this.PrimaryFavorites.Add(favorite); return(favorite); }
internal static DbFavorite CreateFavorite(PersistenceSecurity persistenceSecurity, Groups groups, StoredCredentials credentials, DataDispatcher dispatcher) { var favorite = new DbFavorite(); favorite.Display = new DbDisplayOptions(); favorite.Security = new DbSecurityOptions(); favorite.ExecuteBeforeConnect = new DbBeforeConnectExecute(); favorite.AssignStores(groups, credentials, persistenceSecurity, dispatcher); favorite.MarkAsNewlyCreated(); return favorite; }
public void AddFavorite_CachesAddedFavorite() { IGroup group = this.AddGroupAToPrimaryPersistence(); DbFavorite favorite = this.AddFavoriteToPrimaryPersistence(); group.AddFavorite(favorite); List <IFavorite> favorites = group.Favorites; Assert.AreEqual(1, favorites.Count, "Group favorites count doesn't match."); Assert.AreEqual(1, this.updatedCount, "Group update event didn't reach properly."); }
private void CreateTestFavorites() { List <IFavorite> testFavorites = new List <IFavorite>(); for (int index = 0; index < 3; index++) { DbFavorite favorite = this.CreateTestFavorite(); favorite.Name += index; testFavorites.Add(favorite); } this.PrimaryFavorites.Add(testFavorites); }
public void DeleteFavoriteWhenDisconnectedTest() { DbFavorite favoriteA = this.AddFavoriteToPrimaryPersistence(); // simulate disconnection using invalid connection string for next call Settings.Instance.ConnectionString = @"Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\fake.mdf;Integrated Security=True;User Instance=True"; this.PrimaryPersistence.Dispatcher.ErrorOccurred += new EventHandler <DataErrorEventArgs>(this.DispatcherErrorOccurred); // first call throws a connection exception, which is reported and results in reset connection string this.PrimaryFavorites.Delete(favoriteA); // second call throws a concurrency exception, which should be handled this.PrimaryFavorites.Delete(favoriteA); Assert.IsTrue(removedEventCatched, "Disconnected state wasn't reported"); }
public void SaveOnAlreadyUpdatedFavoriteTest() { DbFavorite favoriteA = this.AddFavoriteToPrimaryPersistence(); var favoriteB = this.SecondaryFavorites.FirstOrDefault() as DbFavorite; this.PrimaryPersistence.Dispatcher.FavoritesChanged += new FavoritesChangedEventHandler(this.OnUpdateAlreadyUpdatedFavoritesChanged); this.UpdateFavorite(favoriteA, this.PrimaryFavorites); this.UpdateFavorite(favoriteB, this.SecondaryFavorites); // last update wins this.UpdateFavorite(favoriteA, this.PrimaryFavorites); // now the stored name is "Test Changed Changed", because third update replaced previous change this.SecondaryFavorites.Delete(favoriteB); // next update shouldn't fail on deleted favorite this.UpdateFavorite(favoriteA, this.PrimaryFavorites); Assert.IsTrue(this.removedEventCatched, "Persistence didn't catched the already removed favorite update event."); }
public void HistoryCommitTest() { DbFavorite favorite = this.AddFavoriteToPrimaryPersistence(); // that's not a mistake, we want to check, if two fast tries are ignored this.PrimaryHistory.RecordHistoryItem(favorite); this.PrimaryHistory.RecordHistoryItem(favorite); int expectedCount = this.GetExpectedHistoryCount(); Assert.AreEqual(2, this.historyRecordedCount, "Recorded history wasn't reported"); // to preserve duplicate times, when creating new entry in database, only one should be recorded Assert.AreEqual(1, expectedCount, "History wasn't stored into database"); this.PrimaryFavorites.Delete(favorite); int expectedCountAfter = this.GetExpectedHistoryCount(); Assert.AreEqual(0, expectedCountAfter, "Favorite history wasn't deleted from database"); }
public void UpdateFavoriteIcon_StoresIconToDatabase() { IFavorite favorite = this.CreateTestFavorite(); // try to access on not saved favorite this.PrimaryFavorites.Add(favorite); this.PrimaryFavorites.UpdateFavoriteIcon(favorite, IMAGE_FILE); this.PrimaryFavorites.Update(favorite); Image favoriteIcon = this.PrimaryFavorites.LoadFavoriteIcon(favorite); DbFavorite checkFavorite = this.CheckFavorites.FirstOrDefault(); Assert.IsNotNull(favoriteIcon, "Icon wasn't assigned successfully"); var loadedIcon = this.SecondaryFavorites.LoadFavoriteIcon(checkFavorite); Assert.IsNotNull(loadedIcon, "Icon didn't reach the database"); ImageAssert.EqualsToExpectedIcon(this.TestContext.DeploymentDirectory, favoriteIcon); }
public void AddTwoFavorites_AddPropertiesToDatabaseAndFiresEvent() { DbFavorite favorite = this.CreateTestFavorite(); DbFavorite favorite2 = this.CreateTestFavorite(); int before = this.CheckFavorites.Count(); this.PrimaryFavorites.Add(favorite); this.PrimaryFavorites.Add(favorite2); int after = this.CheckFavorites.Count(); string protocolProperties = this.CheckDatabase.GetProtocolPropertiesByFavorite(favorite.Id); IFavorite checkFavorite = this.SecondaryPersistence.Favorites.FirstOrDefault(); Assert.AreNotEqual(before, after, -2, "Favorites didn't reach the database"); Assert.IsTrue(!string.IsNullOrEmpty(protocolProperties), "Protocol properties are null"); Assert.IsNotNull(checkFavorite.Security, "Security is null"); Assert.IsNotNull(checkFavorite.Display, "Display is null"); Assert.IsNotNull(checkFavorite.ExecuteBeforeConnect, "ExecuteBeforeConnect is null"); Assert.AreEqual(2, this.addedCount, "Event wasn't delivered"); }
private ValidationStates ValidateDbFavorite() { // created dbfavorite is not compleate, only necessary to make validable using IFavorite var favorite = new DbFavorite(); favorite.ExecuteBeforeConnect = new DbBeforeConnectExecute(); favorite.Security = new DbSecurityOptions(); favorite.Details.LoadFieldsFromReferences(); favorite.Protocol = LongText.Substring(0, 11); favorite.ServerName = LongText; favorite.Name = LongText; favorite.Notes = LongText; favorite.ExecuteBeforeConnect.Command = LongText; favorite.ExecuteBeforeConnect.CommandArguments = LongText; favorite.ExecuteBeforeConnect.InitialDirectory = LongText; return(validator.Validate(favorite)); }
private void UpdateFavorite(DbFavorite toUpdate, IFavorites targetPersistence) { toUpdate.Name += " Changed"; targetPersistence.Update(toUpdate); }