public bool Remove(string uriPrefix) { Debug.Assert(!String.IsNullOrEmpty(uriPrefix)); string newServiceName = BuildSimpleServiceName(uriPrefix); newServiceName = ServiceNameCollection.NormalizeServiceName(newServiceName); bool needToRemove = Contains(newServiceName); if (needToRemove) { serviceNames.Remove(newServiceName); serviceNameCollection = null; //invalidate (readonly) ServiceNameCollection } if (Logging.On) { if (needToRemove) { Logging.PrintInfo(Logging.HttpListener, "ServiceNameStore#" + ValidationHelper.HashString(this) + "::Remove() " + SR.GetString(SR.net_log_listener_spn_remove, newServiceName, uriPrefix)); } else { Logging.PrintInfo(Logging.HttpListener, "ServiceNameStore#" + ValidationHelper.HashString(this) + "::Remove() " + SR.GetString(SR.net_log_listener_spn_not_remove, uriPrefix)); } } return(needToRemove); }
public void Constructor_ServiceNameCollection_ZeroElementsParam() { var paramValue = new ServiceNameCollection(new List <string>()); var ex = Assert.Throws <ArgumentException>("customServiceNames", () => new ExtendedProtectionPolicy(PolicyEnforcement.Always, ProtectionScenario.TransportSelected, paramValue)); Assert.Equal(typeof(ArgumentException), ex.GetType()); }
public bool Remove(string uriPrefix) { Debug.Assert(!string.IsNullOrEmpty(uriPrefix)); string newServiceName = BuildSimpleServiceName(uriPrefix); newServiceName = NormalizeServiceName(newServiceName); bool needToRemove = Contains(newServiceName); if (needToRemove) { _serviceNames.Remove(newServiceName); _serviceNameCollection = null; //invalidate (readonly) ServiceNameCollection } if (NetEventSource.IsEnabled) { if (needToRemove) { NetEventSource.Info(this, SR.Format(SR.net_log_listener_spn_remove, newServiceName, uriPrefix)); } else { NetEventSource.Info(this, SR.Format(SR.net_log_listener_spn_not_remove, uriPrefix)); } } return(needToRemove); }
public void CopyTo_DestinationTooSmall_Throws() { ICollection collection = new ServiceNameCollection(new[] { "first", "second" }); int[] destination = new int[collection.Count - 1]; Assert.Throws <ArgumentException>(() => collection.CopyTo(destination, 0)); }
public void Merge_EnumerableContainingNullOrEmpty_Throws(string item) { var collection = new ServiceNameCollection(new[] { "first", "second" }); Assert.Throws <ArgumentException>(() => collection.Merge(new[] { item })); Assert.Throws <ArgumentException>(() => collection.Merge(new[] { "third", item })); }
public bool Add(string uriPrefix) { string[] strArray = this.BuildServiceNames(uriPrefix); bool flag = false; foreach (string str in strArray) { if (this.AddSingleServiceName(str)) { flag = true; if (Logging.On) { Logging.PrintInfo(Logging.HttpListener, "ServiceNameStore#" + ValidationHelper.HashString(this) + "::Add() adding default SPNs '" + str + "' from prefix '" + uriPrefix + "'"); } } } if (flag) { this.serviceNameCollection = null; return(flag); } if (Logging.On) { Logging.PrintInfo(Logging.HttpListener, "ServiceNameStore#" + ValidationHelper.HashString(this) + "::Add() no default SPN added for prefix '" + uriPrefix + "'"); } return(flag); }
public void Merge_NonStringEnumerable_Throws() { var collection = new ServiceNameCollection(new[] { "first", "second" }); Assert.Throws <ArgumentException>(() => collection.Merge(new[] { 3 })); Assert.Throws <ArgumentException>(() => collection.Merge(new[] { new object() })); }
public void SyncRoot_NonNullSameObject() { ICollection collection = new ServiceNameCollection(new[] { "first", "second" }); Assert.NotNull(collection.SyncRoot); Assert.Same(collection.SyncRoot, collection.SyncRoot); }
public void Constructor_VariousCollections_Success(string[] expected, ICollection items) { var collection = new ServiceNameCollection(items); Assert.Equal(expected, collection.Cast <string>()); Assert.Equal(expected.Length, collection.Count); }
public bool Add(string uriPrefix) { Debug.Assert(!string.IsNullOrEmpty(uriPrefix)); string[] newServiceNames = BuildServiceNames(uriPrefix); bool addedAny = false; foreach (string spn in newServiceNames) { if (AddSingleServiceName(spn)) { addedAny = true; if (NetEventSource.IsEnabled) { NetEventSource.Info(this, SR.Format(SR.net_log_listener_spn_add, spn, uriPrefix)); } } } if (addedAny) { _serviceNameCollection = null; } else if (NetEventSource.IsEnabled) { NetEventSource.Info(this, SR.Format(SR.net_log_listener_spn_not_add, uriPrefix)); } return(addedAny); }
public void Merge_NullOrEmptyString_Throws() { var collection = new ServiceNameCollection(new[] { "first", "second" }); Assert.Throws <ArgumentException>(() => collection.Merge((string)null)); Assert.Throws <ArgumentException>(() => collection.Merge(string.Empty)); }
public void Contains_Found() { var collection = new ServiceNameCollection(new[] { "first", "second" }); Assert.True(collection.Contains("first")); Assert.True(collection.Contains("second")); }
public void SyncRemote(ServiceNameDiscoveryService.ServiceNameDiscoveryServiceClient serviceClient) { if (_unRegisterOpNames.Count > 0) { var serviceNameCollection = new ServiceNameCollection(); foreach (var opName in _unRegisterOpNames) { var serviceName = new ServiceNameElement(); serviceName.ApplicationId = opName.Key.ApplicationId; serviceName.ServiceName = opName.Key.OperationName; serviceName.SrcSpanType = opName.Key.SpanType; serviceNameCollection.Elements.Add(serviceName); } var mapping = serviceClient.discovery(serviceNameCollection); foreach (var item in mapping.Elements) { var element = item.Element; var key = new OperationNameKey(element.ApplicationId, element.ServiceName, SpanType.Entry == element.SrcSpanType, SpanType.Exit == element.SrcSpanType); _unRegisterOpNames.TryRemove(key, out _); _operationNameDic.TryAdd(key, item.ServiceId); } } }
public ServiceBindingNameTraceRecord(string serviceBindingNameSentByClient, string defaultServiceBindingNameOfServer, ServiceNameCollection serviceNameCollectionConfiguredOnServer) : base("ServiceBindingCheckAfterSpNego") { this.serviceBindingNameSentByClient = serviceBindingNameSentByClient; this.defaultServiceBindingNameOfServer = defaultServiceBindingNameOfServer; this.serviceNameCollectionConfiguredOnServer = serviceNameCollectionConfiguredOnServer; }
public void Enumerator_BehavesAsExpected() { string item1 = "first"; string item2 = "second"; string item3 = "third"; var collection = new ServiceNameCollection(new[] { item1, item2, item3 }); IEnumerator e = collection.GetEnumerator(); for (int i = 0; i < 2; i++) { // Not started Assert.Throws <InvalidOperationException>(() => e.Current); Assert.True(e.MoveNext()); Assert.Same(item1, e.Current); Assert.True(e.MoveNext()); Assert.Same(item2, e.Current); Assert.True(e.MoveNext()); Assert.Same(item3, e.Current); Assert.False(e.MoveNext()); Assert.False(e.MoveNext()); Assert.False(e.MoveNext()); // Ended Assert.Throws <InvalidOperationException>(() => e.Current); e.Reset(); } }
public void CopyTo_InvalidDestinationType_Throws() { ICollection collection = new ServiceNameCollection(new[] { "first", "second" }); int[] destination = new int[collection.Count]; Assert.Throws <InvalidCastException>(() => collection.CopyTo(destination, 0)); }
public void Contains_NotFound() { var collection = new ServiceNameCollection(new[] { "first", "second" }); Assert.False(collection.Contains(null)); Assert.False(collection.Contains(string.Empty)); Assert.False(collection.Contains("third")); }
public void Merge_NullEnumerable_Throws() { var collection = new ServiceNameCollection(new[] { "first", "second" }); // This really should be ArgumentNullException, but the full framework does not // guard against null, so NullReferenceException ends up being thrown instead. Assert.Throws <NullReferenceException>(() => collection.Merge((IEnumerable)null)); }
public void CopyTo_InvalidIndex_Throws() { ICollection collection = new ServiceNameCollection(new[] { "first", "second" }); int[] destination = new int[collection.Count]; Assert.Throws <ArgumentOutOfRangeException>(() => collection.CopyTo(destination, -1)); Assert.Throws <ArgumentException>(() => collection.CopyTo(destination, destination.Length)); }
public void Merge_VariousEnumerables_Success(string[] expected, IEnumerable serviceNames) { var collection = new ServiceNameCollection(new[] { "first", "second" }); ServiceNameCollection merged = collection.Merge(serviceNames); Assert.Equal(expected, merged.Cast <string>()); Assert.Equal(expected.Length, merged.Count); }
public void Merge_NonDuplicateString_Succeeds() { string[] expected = new[] { "first", "second", "third" }; var collection = new ServiceNameCollection(new[] { "first", "second" }); ServiceNameCollection merged = collection.Merge("third"); Assert.Equal(expected, merged.Cast <string>()); }
public void Contains_Found() { var collection = new ServiceNameCollection(new[] { "first", "second", "localhost:3000/test", "www.test.com" }); Assert.True(collection.Contains("first")); Assert.True(collection.Contains("second")); Assert.True(collection.Contains("localhost:3000/test")); Assert.True(collection.Contains("www.test.com")); }
public void Merge_DuplicateString_DuplicateFiltered(string duplicate) { string[] expected = new[] { "first", "second" }; var collection = new ServiceNameCollection(new[] { "first", "second" }); ServiceNameCollection merged = collection.Merge(duplicate); Assert.Equal(expected, merged.Cast <string>()); }
public void Merge_EnumerableContainingNullOrEmpty_Throws() { var collection = new ServiceNameCollection(new[] { "first", "second" }); AssertExtensions.Throws <ArgumentNullException>("serviceName", () => collection.Merge(new[] { (string)null })); AssertExtensions.Throws <ArgumentNullException>("serviceName", () => collection.Merge(new[] { "third", null })); AssertExtensions.Throws <ArgumentException>("serviceName", () => collection.Merge(new[] { "" })); AssertExtensions.Throws <ArgumentException>("serviceName", () => collection.Merge(new[] { "third", "" })); }
// Assumes already normalized private bool Contains(string newServiceName) { if (newServiceName == null) { return(false); } return(ServiceNameCollection.Contains(newServiceName, serviceNames)); }
public void Constructor_CollectionParam() { var paramValue = new List <string> { "Test1", "Test2" }; var expectedServiceNameCollection = new ServiceNameCollection(paramValue); var extendedProtectionPolicy = new ExtendedProtectionPolicy(PolicyEnforcement.Always, ProtectionScenario.TransportSelected, paramValue); Assert.Equal(2, extendedProtectionPolicy.CustomServiceNames.Count); Assert.Equal(expectedServiceNameCollection, extendedProtectionPolicy.CustomServiceNames); }
public void CopyTo_ValidDestination_Success() { string[] expected = new[] { "first", "second" }; ICollection collection = new ServiceNameCollection(expected); string[] destination = new string[collection.Count]; collection.CopyTo(destination, 0); Assert.Equal(expected, destination); }
public static bool IsSubset(ServiceNameCollection primaryList, ServiceNameCollection subset) { if ((subset == null) || (subset.Count == 0)) { return(true); } if ((primaryList == null) || (primaryList.Count < subset.Count)) { return(false); } return(primaryList.Merge(subset).Count == primaryList.Count); }
private bool AddSingleServiceName(string spn) { spn = ServiceNameCollection.NormalizeServiceName(spn); if (Contains(spn)) { return(false); } else { serviceNames.Add(spn); return(true); } }
public void ExtendedProtectionPolicy_ToString() { string serviceName1 = "Test1"; string serviceName2 = "Test2"; var serviceNameCollectionParam = new ServiceNameCollection(new List <string> { serviceName1, serviceName2 }); var extendedProtectionPolicy = new ExtendedProtectionPolicy(PolicyEnforcement.Always, ProtectionScenario.TransportSelected, serviceNameCollectionParam); string expectedResult = $"ProtectionScenario={ProtectionScenario.TransportSelected}; PolicyEnforcement={PolicyEnforcement.Always}; CustomChannelBinding=<null>; ServiceNames={serviceName1}, {serviceName2}"; string result = extendedProtectionPolicy.ToString(); Assert.Equal(expectedResult, result); }
public ExtendedProtectionPolicy BuildPolicy() { if (PolicyEnforcement == PolicyEnforcement.Never) { return new ExtendedProtectionPolicy(PolicyEnforcement.Never); } ServiceNameCollection spns = null; ServiceNameElementCollection spnCollection = CustomServiceNames; if (spnCollection != null && spnCollection.Count > 0) { List<string> spnList = new List<string>(spnCollection.Count); foreach (ServiceNameElement element in spnCollection) { spnList.Add(element.Name); } spns = new ServiceNameCollection(spnList); } return new ExtendedProtectionPolicy(PolicyEnforcement, ProtectionScenario, spns); }
public void CopyTo_NullDestination_Throws() { ICollection collection = new ServiceNameCollection(new[] { "first", "second" }); Assert.Throws<ArgumentNullException>(() => collection.CopyTo(null, 0)); }
public void CopyTo_DestinationTooSmall_Throws() { ICollection collection = new ServiceNameCollection(new[] { "first", "second" }); int[] destination = new int[collection.Count - 1]; Assert.Throws<ArgumentException>(() => collection.CopyTo(destination, 0)); }
public void CopyTo_InvalidIndex_Throws() { ICollection collection = new ServiceNameCollection(new[] { "first", "second" }); int[] destination = new int[collection.Count]; Assert.Throws<ArgumentOutOfRangeException>(() => collection.CopyTo(destination, -1)); Assert.Throws<ArgumentException>(() => collection.CopyTo(destination, destination.Length)); }
public void CopyTo_InvalidDestinationType_Throws() { ICollection collection = new ServiceNameCollection(new[] { "first", "second" }); int[] destination = new int[collection.Count]; Assert.Throws<InvalidCastException>(() => collection.CopyTo(destination, 0)); }
public void Merge_DuplicateString_DuplicateFiltered(string duplicate) { string[] expected = new[] { "first", "second" }; var collection = new ServiceNameCollection(new[] { "first", "second" }); ServiceNameCollection merged = collection.Merge(duplicate); Assert.Equal(expected, merged.Cast<string>()); }
public void Merge_NullEnumerable_Throws() { var collection = new ServiceNameCollection(new[] { "first", "second" }); // This really should be ArgumentNullException, but the full framework does not // guard against null, so NullReferenceException ends up being thrown instead. Assert.Throws<NullReferenceException>(() => collection.Merge((IEnumerable)null)); }
public void Merge_EnumerableContainingNullOrEmpty_Throws(string item) { var collection = new ServiceNameCollection(new[] { "first", "second" }); Assert.Throws<ArgumentException>(() => collection.Merge(new[] { item })); Assert.Throws<ArgumentException>(() => collection.Merge(new[] { "third", item })); }
public void Merge_VariousEnumerables_Success(string[] expected, IEnumerable serviceNames) { var collection = new ServiceNameCollection(new[] { "first", "second" }); ServiceNameCollection merged = collection.Merge(serviceNames); Assert.Equal(expected, merged.Cast<string>()); Assert.Equal(expected.Length, merged.Count); }
public void Constructor_VariousCollections_Success(string[] expected, ICollection items) { var collection = new ServiceNameCollection(items); Assert.Equal(expected, collection.Cast<string>()); Assert.Equal(expected.Length, collection.Count); }
public ExtendedProtectionPolicy(PolicyEnforcement policyEnforcement, ProtectionScenario protectionScenario, ServiceNameCollection customServiceNames);
public void Merge_NonDuplicateString_Succeeds() { string[] expected = new[] { "first", "second", "third" }; var collection = new ServiceNameCollection(new[] { "first", "second" }); ServiceNameCollection merged = collection.Merge("third"); Assert.Equal(expected, merged.Cast<string>()); }
public void Merge_NullOrEmptyString_Throws() { var collection = new ServiceNameCollection(new[] { "first", "second" }); Assert.Throws<ArgumentException>(() => collection.Merge((string)null)); Assert.Throws<ArgumentException>(() => collection.Merge(string.Empty)); }
public void Enumerator_BehavesAsExpected() { string item1 = "first"; string item2 = "second"; string item3 = "third"; var collection = new ServiceNameCollection(new[] { item1, item2, item3 }); IEnumerator e = collection.GetEnumerator(); for (int i = 0; i < 2; i++) { // Not started Assert.Throws<InvalidOperationException>(() => e.Current); Assert.True(e.MoveNext()); Assert.Same(item1, e.Current); Assert.True(e.MoveNext()); Assert.Same(item2, e.Current); Assert.True(e.MoveNext()); Assert.Same(item3, e.Current); Assert.False(e.MoveNext()); Assert.False(e.MoveNext()); Assert.False(e.MoveNext()); // Ended Assert.Throws<InvalidOperationException>(() => e.Current); e.Reset(); } }
public void Merge_NonStringEnumerable_Throws() { var collection = new ServiceNameCollection(new[] { "first", "second" }); Assert.Throws<ArgumentException>(() => collection.Merge(new[] { 3 })); Assert.Throws<ArgumentException>(() => collection.Merge(new[] { new object() })); }
public void IsSynchronized_ReturnsFalse() { ICollection collection = new ServiceNameCollection(new[] { "first", "second" }); Assert.False(collection.IsSynchronized); }