public void ClientFactory_CreateCollection_CreatesClientsOnlyForValidClientTypes() { // Arrange var factory = new ClientFactory(); var client1 = new ClientSettings { Name = "Client 1", Server = "foo" }; var client2 = new ClientSettings { Name = "Client 2", Server = "bar" }; var client3 = new ClientSettings { ClientType = ClientType.Legacy, Name = "Client 3" }; // Act var clients = factory.CreateCollection(new[] { client1, client2, client3 }); // Assert Assert.AreEqual(2, clients.Count); }
public void ClientFactory_CreateCollection_ThrowsWhenClientSettingsIsNotValid() { // Arrange var factory = new ClientFactory(); var client = new ClientSettings { Name = "Client 1", Server = "foo", Port = 0 }; // Act & Assert Assert.Throws <ArgumentException>(() => factory.CreateCollection(new[] { client })); }
public void Load(IEnumerable <ClientSettings> settings) { if (settings == null) { throw new ArgumentNullException(nameof(settings)); } Clear(); int added = 0; // don't enter write lock before Clear(), would result in deadlock _syncLock.EnterWriteLock(); try { // add each instance to the collection foreach (var client in _factory.CreateCollection(settings)) { if (client != null) { client.SlotsChanged += OnInvalidate; client.RetrievalFinished += OnInvalidate; _clientDictionary.Add(client.Settings.Name, client); added++; } } } finally { _syncLock.ExitWriteLock(); } if (added != 0) { OnDictionaryChanged(new ConfigurationChangedEventArgs(ConfigurationChangedType.Add, null)); } }
public void ClientFactory_CreateCollection_ThrowsWhenSettingsIsNull() { var factory = new ClientFactory(); Assert.Throws <ArgumentNullException>(() => factory.CreateCollection(null)); }