public void GeoCoordinate_Valiate() { ExtendedAssert.Throws <ArgumentException>(() => new GeoCoordinate(91.0, 0)); ExtendedAssert.Throws <ArgumentException>(() => new GeoCoordinate(-91.0, 0)); ExtendedAssert.Throws <ArgumentException>(() => new GeoCoordinate(0, 181.0)); ExtendedAssert.Throws <ArgumentException>(() => new GeoCoordinate(0, -181.0)); }
public void GeoRectangle_Wraparound() { // Verify that we detect coordinate wraparound. ExtendedAssert.Throws <ArgumentException>(() => new GeoRectangle(new GeoCoordinate(45, 5), new GeoCoordinate(60, 0))); ExtendedAssert.Throws <ArgumentException>(() => new GeoRectangle(new GeoCoordinate(45, -10), new GeoCoordinate(0, 0))); }
public void SerializedActionQueue_Limit() { // Verify that the queue throws an [InvalidOperationException] if the number of items in // the queue are exceeded. I'm going to do this by queuing a relatively long-running action // and then quickly submitting four more actions where the last one should exceed the limit // of three actions I'm going to set for the queue. var queue = new SerializedActionQueue(3); var done = false; var task1 = false; try { queue.EnqueueAction(() => { task1 = true; Thread.Sleep(TimeSpan.FromSeconds(1)); done = true; }); Helper.WaitFor(() => task1, TimeSpan.FromSeconds(1)); queue.EnqueueAction(() => Thread.Sleep(0)); queue.EnqueueAction(() => Thread.Sleep(0)); queue.EnqueueAction(() => Thread.Sleep(0)); ExtendedAssert.Throws <InvalidOperationException>(() => queue.EnqueueAction(() => Thread.Sleep(0))); Helper.WaitFor(() => done, TimeSpan.FromSeconds(5)); } finally { queue.Clear(); } }
public void CompositeEnumerator_SourceChanged() { // Verify that InvalidOperationExceptions are thrown when the when // performing operations on the enumerator after the source has // signalled that it has been modified. List <int> source = new List <int>(); CompositeEnumerator <int> enumerator; source.Add(0); source.Add(1); source.Add(2); enumerator = new CompositeEnumerator <int>(source.GetEnumerator()); enumerator.OnSourceChanged(); ExtendedAssert.Throws <InvalidOperationException>(() => enumerator.MoveNext()); enumerator = new CompositeEnumerator <int>(source.GetEnumerator()); enumerator.OnSourceChanged(); ExtendedAssert.Throws <InvalidOperationException>(() => { int i = enumerator.Current; }); enumerator = new CompositeEnumerator <int>(source.GetEnumerator()); enumerator.OnSourceChanged(); ExtendedAssert.Throws <InvalidOperationException>(() => { enumerator.Reset(); }); }
public void Throws_Exception_On_Empty_Or_Null_String() { var myValidator = new Validator(); ExtendedAssert.Throws <InvalidOperationException>(() => myValidator.VerifyNotNullOrEmpty(string.Empty)); ExtendedAssert.Throws <InvalidOperationException>(() => myValidator.VerifyNotNullOrEmpty(null)); }
public void AsymmetricCrypto_EncryptedCredentials() { string privateKey = AsymmetricCrypto.CreatePrivateKey(CryptoAlgorithm.RSA, 1024); string publicKey = AsymmetricCrypto.GetPublicKey(CryptoAlgorithm.RSA, privateKey); Credentials credentials; byte[] encrypted; credentials = new Credentials("realm", "user", "password"); encrypted = AsymmetricCrypto.EncryptCredentials(credentials, "RSA", publicKey); credentials = AsymmetricCrypto.DecryptCredentials(encrypted, "RSA", privateKey); Assert.AreEqual("realm", credentials.Realm); Assert.AreEqual("user", credentials.Account); Assert.AreEqual("password", credentials.Password); // Force a security failure by decrypting with the wrong key ExtendedAssert.Throws <SecurityException>( () => { privateKey = AsymmetricCrypto.CreatePrivateKey(CryptoAlgorithm.RSA, 1024); AsymmetricCrypto.DecryptCredentials(encrypted, "RSA", privateKey); }); // Force a security failure by tampering with the encrypted credentials ExtendedAssert.Throws <SecurityException>( () => { encrypted[4] = (byte)~encrypted[4]; AsymmetricCrypto.DecryptCredentials(encrypted, "RSA", privateKey); }); }
public void Throws_An_Exception_When_Any_Argument_Is_Null() { string one = "asdf"; string two = "sadf"; string three = null; ExtendedAssert.Throws <ArgumentNullException>(() => new Validator().VerifyParamsNonNull(one, two, three)); }
public void Dispose_Of_The_Http_Client() { var target = new GithubInquisitor(); target.Dispose(); ExtendedAssert.Throws(() => target.Client.CancelPendingRequests()); }
public void AsyncManualResetEvent_Error() { AsyncManualResetEvent manualEvent; // Verify that we get and [ObjectDisposedException] for [Set()] and [Reset()] // a disposed event. manualEvent = new AsyncManualResetEvent(); manualEvent.Dispose(); ExtendedAssert.Throws <ObjectDisposedException>(() => manualEvent.Set()); ExtendedAssert.Throws <ObjectDisposedException>(() => manualEvent.Reset()); Task.Run(() => ExtendedAssert.ThrowsAsync <ObjectDisposedException>(async() => await manualEvent.WaitAsync())).Wait(); // Verify that disposing an event causes any waiting tasks // to unblock with an [ObjectDisposedException]. manualEvent = new AsyncManualResetEvent(); var taskInfo = new TaskStateCollection(); var badException = false; for (int i = 0; i < taskInfo.Count; i++) { new Task( async state => { int taskIndex = (int)state; taskInfo[taskIndex].IsRunning = true; try { await manualEvent.WaitAsync(); } catch (ObjectDisposedException) { taskInfo[taskIndex].IsFaulted = true; } catch { badException = true; taskInfo[taskIndex].IsFaulted = true; } taskInfo[taskIndex].IsComplete = true; }, i).Start(); } Helper.WaitFor(() => taskInfo.AllRunning, defaultTimeout); Assert.IsFalse(taskInfo.AnyComplete); manualEvent.Dispose(); Helper.WaitFor(() => taskInfo.AllFaulted, defaultTimeout); Assert.IsFalse(badException); }
public void ChannelVariableCollection_Exceptions() { var variables = new ChannelVariableCollection(); ExtendedAssert.Throws <ArgumentNullException>(() => variables.Add(null, "value")); ExtendedAssert.Throws <ArgumentNullException>(() => variables.Add("name", null)); ExtendedAssert.Throws <ArgumentException>(() => variables.Add("", "value")); ExtendedAssert.Throws <ArgumentException>(() => variables.Add("=", "value")); ExtendedAssert.Throws <ArgumentException>(() => variables.Add(",", "value")); ExtendedAssert.Throws <ArgumentException>(() => variables.Add("name", "^")); }
public void ReadOnlyDictionary_TryModify() { var dictionary = new Dictionary <string, string>(); var readOnly = new ReadOnlyDictionary <string, string>(dictionary); ExtendedAssert.Throws <NotSupportedException>(() => readOnly.Clear()); ExtendedAssert.Throws <NotSupportedException>(() => readOnly.Add("hello", "world")); ExtendedAssert.Throws <NotSupportedException>(() => readOnly["test"] = "fail"); ExtendedAssert.Throws <NotSupportedException>(() => readOnly.Remove("hello")); ExtendedAssert.Throws <NotSupportedException>(() => readOnly.Remove(new KeyValuePair <string, string>("hello", "world"))); }
public void SwitchEventCodeSet_ReadOnly() { var readOnly = new SwitchEventCodeSet(SwitchEventCode.Heartbeat); readOnly.IsReadOnly = true; Assert.IsTrue(readOnly.IsReadOnly); Assert.IsTrue(readOnly.Contains(SwitchEventCode.Heartbeat)); ExtendedAssert.Throws <InvalidOperationException>(() => readOnly.IsReadOnly = false); ExtendedAssert.Throws <InvalidOperationException>(() => readOnly.Add(SwitchEventCode.Dtmf)); ExtendedAssert.Throws <InvalidOperationException>(() => readOnly.Remove(SwitchEventCode.Dtmf)); ExtendedAssert.Throws <InvalidOperationException>(() => readOnly.Clear()); }
public void ArgCollection_ReadOnly() { ArgCollection ps = new ArgCollection(); ps["hello"] = "world!"; Assert.IsFalse(ps.IsReadOnly); Assert.AreEqual("world!", ps["hello"]); ps.IsReadOnly = true; Assert.IsTrue(ps.IsReadOnly); Assert.AreEqual("world!", ps["hello"]); ExtendedAssert.Throws <InvalidOperationException>(() => ps.IsReadOnly = false); ExtendedAssert.Throws <NotSupportedException>(() => ps["foo"] = "bar"); }
public void GeoCompositeRegion_VerifyNotComposible() { // Verify that we get an exception when trying to compose a composite region // as a subtractive region. ExtendedAssert.Throws <ArgumentException>( () => { new GeoCompositeRegion( new GeoRegion[] { new GeoRectangle(30, 0, 0, 30) }, new GeoRegion[] { new GeoCompositeRegion(new GeoRegion[0]) }); }); }
public void KeyChain_Basic() { string privateKey1 = AsymmetricCrypto.CreatePrivateKey(CryptoAlgorithm.RSA, 1024); string publicKey1 = AsymmetricCrypto.GetPublicKey(CryptoAlgorithm.RSA, privateKey1); string privateKey2 = AsymmetricCrypto.CreatePrivateKey(CryptoAlgorithm.RSA, 1024); string publicKey2 = AsymmetricCrypto.GetPublicKey(CryptoAlgorithm.RSA, privateKey2); KeyChain keyChain = new KeyChain(); ExtendedAssert.Throws <CryptographicException>( () => { keyChain.GetPrivateKey(publicKey1); }); keyChain.Add(privateKey1); keyChain.Add(privateKey2); Assert.AreEqual(privateKey1, keyChain.GetPrivateKey(publicKey1)); Assert.AreEqual(privateKey2, keyChain.GetPrivateKey(publicKey2)); }
public void Bits_ShiftRight() { var b = new Bits("001100111001111001111100111111001111111"); Assert.AreEqual("001100111001111001111100111111001111111", (string)(b >> 0)); Assert.AreEqual("000110011100111100111110011111100111111", (string)(b >> 1)); Assert.AreEqual("000011001110011110011111001111110011111", (string)(b >> 2)); Assert.AreEqual("000001100111001111001111100111111001111", (string)(b >> 3)); Assert.AreEqual("000000110011100111100111110011111100111", (string)(b >> 4)); Assert.AreEqual("000000011001110011110011111001111110011", (string)(b >> 5)); var s = b.ToString(); for (int i = 0; i < 100; i++) { Assert.AreEqual(s, (string)(b >> i)); s = "0" + s.Substring(0, s.Length - 1); } ExtendedAssert.Throws <ArgumentException>(() => { var output = b >> -1; }); }
public void Bits_ShiftLeft() { var b = new Bits("001100111001111001111100111111001111111"); Assert.AreEqual("001100111001111001111100111111001111111", (string)(b << 0)); Assert.AreEqual("011001110011110011111001111110011111110", (string)(b << 1)); Assert.AreEqual("110011100111100111110011111100111111100", (string)(b << 2)); Assert.AreEqual("100111001111001111100111111001111111000", (string)(b << 3)); Assert.AreEqual("001110011110011111001111110011111110000", (string)(b << 4)); Assert.AreEqual("011100111100111110011111100111111100000", (string)(b << 5)); var s = b.ToString(); for (int i = 0; i < 100; i++) { Assert.AreEqual(s, (string)(b << i)); s = s.Substring(1) + "0"; } ExtendedAssert.Throws <ArgumentException>(() => { var output = b << -1; }); }
public void SecureTicket_Tamper() { DateTime now = DateTime.UtcNow; SymmetricKey key = new SymmetricKey("aes:Cz1uS3EYB5aLDgXdKKmzGPnMU3/QwK1i+8nY3KuUaCw=:Toel2ZQR6TBtOvq+zatyoA=="); SecureTicket ticket; byte[] encrypted; ticket = new SecureTicket("my-resource", TimeSpan.FromSeconds(10)); ticket.Set("arg0", "myarg-0"); ticket.Set("arg1", "myarg-1"); ticket["arg2"] = "myarg-2"; encrypted = ticket.ToArray(key); encrypted[0] = (byte)~encrypted[0]; ExtendedAssert.Throws <CryptographicException>( () => { ticket = SecureTicket.Parse(key, encrypted); Assert.Fail("Expected a CryptographicException"); }); }
public void Throws_ArgumentNullException_On_Null_Argument() { ExtendedAssert.Throws <ArgumentNullException>(() => new Validator().VerifyNonNull((object)null)); }
public void Throws_ArgumentException_On_Null_Path() { ExtendedAssert.Throws <ArgumentException>(() => Target.CreateNewProject(null)); }
public void Throws_On_Null_Argument() { ExtendedAssert.Throws <ArgumentNullException>(() => new MainWindowViewModel(null, null)); }
public void Throws_Exception_When_Project_Has_Not_Been_Loaded() { ExtendedAssert.Throws <InvalidOperationException>(() => Target.SaveProject()); }
public void Throw_Exception_When_Attempt_Is_Made_To_Move_Nonexistent_Piece() { ExtendedAssert.Throws <ArgumentNullException>(() => Target.MovePiece(DestinationCoordinate, OriginCoordinate)); }
public void RequestSignature_Args() { ArgCollection args = new ArgCollection(); SymmetricKey key = Crypto.GenerateSymmetricKey(); string signature; // Verify a request with no arguments. args.Clear(); signature = RequestSignature.Generate(key, args); RequestSignature.Verify(key, signature, args, null, graceInterval); // Verify a request with a few arguments args.Clear(); args["arg1"] = "hello"; args["arg2"] = "world"; args["arg3"] = "test"; signature = RequestSignature.Generate(key, args); Assert.IsTrue(RequestSignature.TryVerify(key, signature, args, null, graceInterval)); // Verify that argument normaization works by reversing the // orher of the arguments added. args.Clear(); args["arg3"] = "test"; args["arg2"] = "world"; args["arg1"] = "hello"; Assert.IsTrue(RequestSignature.TryVerify(key, signature, args, null, graceInterval)); // Test with the signature as part of the arguments. args["signature"] = signature; Assert.IsTrue(RequestSignature.TryVerify(key, signature, args, "signature", graceInterval)); // Tamper with one of the argument values and verify failure args["arg2"] = "xxx"; Assert.IsFalse(RequestSignature.TryVerify(key, signature, args, null, graceInterval)); // Do it again args["arg2"] = "WORLD"; ExtendedAssert.Throws <SecurityException>( () => { RequestSignature.Verify(key, signature, args, null, graceInterval); Assert.Fail("SecurityException expected"); }); // Change the shared key and verify failure args.Clear(); args["arg1"] = "hello"; args["arg2"] = "world"; args["arg3"] = "test"; signature = RequestSignature.Generate(key, args); Assert.IsFalse(RequestSignature.TryVerify(Crypto.GenerateSymmetricKey(), signature, args, null, graceInterval)); }
public void Throw_Exception_For_OutOfBounds_Destination_Argument() { ExtendedAssert.Throws <ArgumentException>(() => Target.MovePiece(OriginCoordinate, BoardCoordinate.For(10, 10))); }
public void Throw_Exception_On_Null_ConstructorArgument() { ExtendedAssert.Throws <ArgumentNullException>(() => new CastlingStatusChecker(null)); }
public void Throw_Exception_When_Called_With_1_2() { ExtendedAssert.Throws <ArgumentException>(() => Target.RemovePiece(BoardCoordinate.For(1, 2))); }
public void Throws_Exception_On_Null_Argument() { ExtendedAssert.Throws <ArgumentNullException>(() => new ArbitraryCommand(null)); }
public void Throws_ArgumentException_On_Empty_Path() { ExtendedAssert.Throws <ArgumentException>(() => Target.LoadProject(string.Empty)); }
public void Throws_ArgumentNullException_On_Null_Argument() { ExtendedAssert.Throws <ArgumentNullException>(() => new ConstructorDependencyBuilder(null)); }