Beispiel #1
0
        public void Test_PurchaseBooksTotalError()
        {
            Order order = new Order()
            {
                OrderItems = new List <OrderItem>()
                {
                    new OrderItem()
                    {
                        Quantity = 3,
                        Book     = new Book()
                        {
                            BookId = 1, Title = "Title 1", Image = "img1", Price = 10, Supplies = 10
                        }
                    },
                    new OrderItem()
                    {
                        Quantity = 5,
                        Book     = new Book()
                        {
                            BookId = 2, Title = "Title 2", Image = "img2", Price = 15, Supplies = 10
                        }
                    },
                },
            };

            order.Total = order.OrderItems.Sum(oi => oi.Quantity * oi.Book.Price) + 10;
            Assert.ThrowsException <OrderException>(() => service.PurchaseBooks(order, 1));
        }
Beispiel #2
0
 public void AssertArgument()
 {
     var ex = XAssert.ThrowsException <ArgumentException>(() =>
     {
         Assert.Argument(false, "child").IsTrue();
     });
 }
Beispiel #3
0
 public void AssertState()
 {
     var ex = XAssert.ThrowsException <InvalidOperationException>(() =>
     {
         Assert.State((string)null, "child").NotNull();
     });
 }
Beispiel #4
0
        public void ErrorListThrows()
        {
            Validator.CheckValue(false, "x").IsTrue();
            Validator.CheckValue(true, "y").IsFalse();
            var ex = XAssert.ThrowsException <MultipleErrorsException>(() => Validator.Throw());

            XAssert.AreEqual(2, ex.Errors.Count);
        }
        public void JwtConsentRequiredTest()
        {
            // Adding a Correct PEM key - no consent granted
            byte[]       pkey = Convert.FromBase64String(testConfig.PrivateKeyNoConsent);
            ApiException ex   = Assert.ThrowsException <ApiException>(() => testConfig.ApiClient.RequestJWTUserToken(testConfig.IntegratorKeyNoConsent, testConfig.UserId, testConfig.OAuthBasePath, pkey, testConfig.ExpiresInHours));

            Assert.IsNotNull(ex);
            // Assert.AreEqual(ex.ErrorContent, "{\"error\":\"consent_required\"}");
        }
Beispiel #6
0
        public void AssertNullArgument()
        {
            Qoden.Util.HttpUtility.ParseQueryString("aaaa=cc&ddd=3");

            var ex = XAssert.ThrowsException <ArgumentNullException>(() =>
            {
                Assert.Argument((string)null, "child").NotNull();
            });
        }
 public void ShouldFailForUncertaintyLessThanZero()
 {
     Assert.ThrowsException <ArgumentOutOfRangeException>(() =>
     {
         new LocationConstraintExtensionBuilder()
         .WithMaxUncertainty(-1)
         .Build();
     });
 }
 public void ShouldFailForLongitudesOutsideOfRange(double longitude)
 {
     Assert.ThrowsException <ArgumentOutOfRangeException>(() =>
     {
         new LocationConstraintExtensionBuilder()
         .WithLongitude(longitude)
         .Build();
     });
 }
Beispiel #9
0
        public void ErrorTest()
        {
            var excp = Assert.ThrowsException <ReindexerException>(() =>
            {
                Client.DropNamespace(Guid.NewGuid().ToString());
            });

            Assert.AreNotEqual(ReindexerErrorCode.OK, excp?.ErrorCode);
        }
        public void JwtConsentRequiredTest()
        {
            // Adding a Correct PEM key - no consent granted
            byte[]       pkey = System.Text.Encoding.UTF8.GetBytes(File.ReadAllText(testConfig.PrivateKeyNoConsentFilename));
            ApiException ex   = Assert.ThrowsException <ApiException>(() => testConfig.ApiClient.RequestJWTUserToken(testConfig.IntegratorKeyNoConsent, testConfig.UserId, testConfig.OAuthBasePath, pkey, testConfig.ExpiresInHours));

            Assert.IsNotNull(ex);
            Assert.AreEqual(ex.ErrorContent, "{\"error\":\"consent_required\"}");
        }
        public void JwtInvalidGrantTest()
        {
            // Adding a WRONG PEM key
            byte[]       privateKeyStream = Convert.FromBase64String(testConfig.PrivateKey);
            ApiException ex = Assert.ThrowsException <ApiException>(() => testConfig.ApiClient.RequestJWTUserToken(testConfig.IntegratorKeyNoConsent, testConfig.UserId, testConfig.OAuthBasePath, privateKeyStream, testConfig.ExpiresInHours));

            Assert.IsNotNull(ex);
            Assert.AreEqual("{\"error\":\"invalid_grant\",\"error_description\":\"no_valid_keys_or_signatures\"}", ex.ErrorContent);
        }
        public void JwtInvalidGrantTest()
        {
            // Adding a WRONG PEM key
            byte[] privateKeyStream = File.ReadAllBytes(testConfig.PrivateKeyFilename);

            ApiException ex = Assert.ThrowsException <ApiException>(() => testConfig.ApiClient.RequestJWTUserToken(testConfig.IntegratorKeyNoConsent, testConfig.UserId, testConfig.OAuthBasePath, privateKeyStream, testConfig.ExpiresInHours));

            Assert.IsNotNull(ex);
            Assert.AreEqual(ex.ErrorContent, "{\"error\":\"invalid_grant\"}");
        }
Beispiel #13
0
 public void Title_CheckIfTitle_ExpectedFailure()
 {
     this.RunInAllBrowsers(browser =>
     {
         browser.NavigateToUrl("/test/Title");
         MSAssert.ThrowsException <BrowserException>(() =>
         {
             browser.CheckIfTitle(c => c == "This is not title");
         });
     });
 }
Beispiel #14
0
        public void Title_CheckIfTitleEquals_NoTrim_ExpectedFailure()
        {
            this.RunInAllBrowsers(browser =>
            {
                browser.NavigateToUrl("/test/Title");

                MSAssert.ThrowsException <BrowserException>(() =>
                {
                    browser.CheckIfTitleEquals("This is title           ", trim: false);
                });
            });
        }
Beispiel #15
0
        public void Test_Circular_Reference1()
        {
            var ce        = new CalculationEngine();
            var context   = new ExpressionContext();
            var variables = context.Variables;

            variables.Add("x", 100);
            ce.Add("a", "x * 2", context);
            variables.Add("y", 1);
            ce.Add("b", "a + y + b", context);
            Assert.ThrowsException <CircularReferenceException>(() => { ce.Recalculate("a"); });
        }
        public void JwtUnexpectedPEMTypeTest()
        {
            var rsaKey = "---Invalid private key---";

            // Create a stream of bytes...
            byte[] privateKeyStream = System.Text.Encoding.UTF8.GetBytes(rsaKey);

            Exception ex = Assert.ThrowsException <Exception>(() => testConfig.ApiClient.RequestJWTUserToken(testConfig.IntegratorKeyNoConsent, testConfig.UserId, testConfig.OAuthBasePath, privateKeyStream, testConfig.ExpiresInHours));

            Assert.IsNotNull(ex);
            Assert.AreEqual(ex.Message, "Unexpected PEM type");
        }
        public void GetUserInfo_WrongAccessToken_ReturnsException()
        {
            var access_token = "---Invalid-Access-Token---";

            ApiException ex = Assert.ThrowsException <ApiException>(() => _testConfig.ApiClient.GetUserInfo(access_token));

            Assert.IsNotNull(ex?.ErrorContent);

            int unauthorizedStatusCode = 401;

            Assert.AreEqual(ex.ErrorCode, unauthorizedStatusCode);
        }
        public void CreateEnvelope_WrongTemplateId_ReturnApiException()
        {
            var envDef = new EnvelopeDefinition
            {
                EmailSubject = "[DocuSign C# SDK] - Please sign this doc",
                TemplateId   = "510fc78e-32f4-8778-44eb-6b53abb6c82E"
            };

            var          envelopesApi = new EnvelopesApi(_testConfig.ApiClient);
            ApiException ex           = Assert.ThrowsException <ApiException>(() => envelopesApi.CreateEnvelope(_testConfig.AccountId, envDef));

            Assert.IsNotNull(ex?.Headers);
        }
        public void JwtInvalidAccessToken_Unauthorized_Test()
        {
            string access_token = "---Invalid-Access-Token---";

            ApiException ex = Assert.ThrowsException <ApiException>(() => testConfig.ApiClient.GetUserInfo(access_token));

            Assert.IsNotNull(ex);
            Assert.IsNotNull(ex.ErrorContent);

            int unauthorizedStatusCode = 401;

            Assert.AreEqual(ex.ErrorCode, unauthorizedStatusCode);
        }
 public void ElementContained_CheckIfNotContainsElement_ExpectedFailure()
 {
     this.RunInAllBrowsers(browser =>
     {
         browser.NavigateToUrl("/test/ElementContained");
         MSAssert.ThrowsException <MoreElementsInSequenceException>(() =>
         {
             browser.First("#one").CheckIfNotContainsElement("span");
         });
         MSAssert.ThrowsException <MoreElementsInSequenceException>(() =>
         {
             browser.First("#two").CheckIfNotContainsElement("span");
         });
     });
 }
Beispiel #21
0
        public void ApiExceptionHeadersTest()
        {
            EnvelopeDefinition envDef = new EnvelopeDefinition();

            envDef.EmailSubject = "[DocuSign C# SDK] - Please sign this doc";
            // random incorrect guid
            envDef.TemplateId = "510fc78e-32f4-8778-44eb-6b53abb6c82E";

            // |EnvelopesApi| contains methods related to creating and sending Envelopes (aka signature requests)
            EnvelopesApi envelopesApi = new EnvelopesApi(_testConfig.ApiClient);
            ApiException ex           = Assert.ThrowsException <ApiException>(() => envelopesApi.CreateEnvelope(_testConfig.AccountId, envDef));

            Assert.IsNotNull(ex);
            Assert.IsNotNull(ex.Headers);
        }
 public void IsChecked_CheckIfIsNotChecked_TypeFailure()
 {
     RunInAllBrowsers(browser =>
     {
         browser.NavigateToUrl("/test/Checkboxes");
         MSAssert.ThrowsException <UnexpectedElementStateException>((() =>
         {
             browser.Single("#textbox1").CheckIfIsNotChecked();
         }));
         MSAssert.ThrowsException <UnexpectedElementStateException>((() =>
         {
             browser.Single("#span1").CheckIfIsNotChecked();
         }));
     });
 }
        public void Attribute_CheckIfHasNotAttribute_ExpectedFailure()
        {
            this.RunInAllBrowsers(browser =>
            {
                browser.NavigateToUrl("/test/Attribute");

                MSAssert.ThrowsException <UnexpectedElementStateException>(() =>
                {
                    browser.First("#content").CheckIfHasNotAttribute("class");
                });
                MSAssert.ThrowsException <UnexpectedElementStateException>(() =>
                {
                    browser.First("#dis-button").CheckIfHasNotAttribute("disabled");
                });
            });
        }
        public void IsDisplayed_ExpectedFailure()
        {
            this.RunInAllBrowsers(browser =>
            {
                browser.NavigateToUrl("/test/Displayed");

                MSAssert.ThrowsException <UnexpectedElementStateException>(() =>
                {
                    browser.First("#displayed").CheckIfIsNotDisplayed();
                });
                MSAssert.ThrowsException <UnexpectedElementStateException>(() =>
                {
                    browser.First("#non-displayed").CheckIfIsDisplayed();
                });
            });
        }
Beispiel #25
0
        public void InvalidPointIndexAccess_Throws_ContainerIndexOutOfRangeException()
        {
            // Arrange

            //Act
            void CheckFunction()
            {
                //Arrange
                var invalidIndex = 1;

                //Act
                var data = _pmc[0][0][0][invalidIndex];
            }

            //Assert
            Assert.ThrowsException <ContainerIndexOutOfRangeException>((Action)CheckFunction);
        }
        public void SelectMethod_ExpectedFailure()
        {
            this.RunInAllBrowsers(browser =>
            {
                browser.NavigateToUrl("/test/SelectMethod");


                Func <string, By> selectMethod = s => By.CssSelector($"[data-ui='{s}']");
                browser.SelectMethod           = selectMethod;

                var outerElem = browser.First("outer-data-ui");
                MSAssert.ThrowsException <NoSuchElementException>(() =>
                {
                    var innerElem = outerElem.First("#inner-id");
                });
            });
        }
Beispiel #27
0
        public void Url_CheckHyperLink_Relative_ExpectedFailure()
        {
            this.RunInAllBrowsers(browser =>
            {
                browser.NavigateToUrl("/test/HyperLink");

                MSAssert.ThrowsException <UnexpectedElementStateException>(() =>
                {
                    browser.CheckIfHyperLinkEquals("#RelativeLink", "/path0/test?query=test#fragment", UrlKind.Relative,
                                                   UriComponents.PathAndQuery);
                });
                MSAssert.ThrowsException <UnexpectedElementStateException>(() =>
                {
                    browser.CheckIfHyperLinkEquals("#RelativeLink", "/path/test?query=test#fragment_nonexistent",
                                                   UrlKind.Relative, UriComponents.AbsoluteUri);
                });
            });
        }
Beispiel #28
0
    public void ActionThrowsExceptionExactlyOfStaticType()
    {
        void a()
        {
            throw new ArgumentNullException("id");
        }

        Action            action = a;
        ArgumentException ae;

        // MSTest
        ae = MSTestAssert.ThrowsException <ArgumentException>(action);
        // Assert.ThrowsException failed. Threw exception ArgumentNullException, but exception ArgumentException was expected.
        // Exception Message: Value cannot be null.
        // Parameter name: id
        // Stack Trace: at ...

        // NUnit
        Assert.That(a, Throws.TypeOf <ArgumentException>(), () => "Some context");
        // Some context
        //  Expected: <System.ArgumentException>
        //  But was: <System.ArgumentNullException>

        // XUnit
        ae = XUnitAssert.Throws <ArgumentException>(action);
        // Assert.Throws() Failure
        // Expected: typeof(System.ArgumentException)
        // Actual:  typeof(System.ArgumentNullException): Value cannot be null.
        // Parameter name: id
        // ---- System.ArgumentNullException: Value cannot be null.
        // Parameter name: id

        // Fluent
        ae = action.Should().ThrowExactly <ArgumentException>("SOME REASONS").Which;
        // Expected type to be System.ArgumentException because SOME REASONS, but found System.ArgumentNullException.

        // Shouldly does not support this case.
    }
 public void Value_CheckIfValue_ExpectedException()
 {
     this.RunInAllBrowsers(browser =>
     {
         browser.NavigateToUrl("/test/value");
         MSAssert.ThrowsException <UnexpectedElementStateException>(() =>
         {
             browser.First("#input-radio2").CheckIfValue("radio1");
         });
         MSAssert.ThrowsException <UnexpectedElementStateException>(() =>
         {
             browser.First("#area").CheckIfValue("wrongvalue");
         });
         MSAssert.ThrowsException <UnexpectedElementStateException>(() =>
         {
             browser.First("#input-text").CheckIfValue("texT1");
         });
         MSAssert.ThrowsException <UnexpectedElementStateException>(() =>
         {
             browser.First("#input-text").CheckIfValue("   text1   ", trimValue: false);
         });
     });
 }
Beispiel #30
0
        public void Url_CheckHyperLink_Absolute_ExpectedFailure()
        {
            this.RunInAllBrowsers(browser =>
            {
                browser.NavigateToUrl("/test/HyperLink");

                MSAssert.ThrowsException <UnexpectedElementStateException>(() =>
                {
                    browser.CheckIfHyperLinkEquals("#AbsoluteLink", "https://www.google.com/path0/test?query=test#fragment",
                                                   UrlKind.Absolute, UriComponents.PathAndQuery);
                });
                MSAssert.ThrowsException <UnexpectedElementStateException>(() =>
                {
                    browser.CheckIfHyperLinkEquals("#AbsoluteSameSchema",
                                                   "https://localhost:1234/path/test?query=test#fragment", UrlKind.Absolute,
                                                   UriComponents.AbsoluteUri);
                });
                MSAssert.ThrowsException <UnexpectedElementStateException>(() =>
                {
                    browser.CheckIfHyperLinkEquals("#AbsoluteLink", "https://www.google.com/path/test?query=test#fragment_nonexistent",
                                                   UrlKind.Absolute, UriComponents.AbsoluteUri);
                });
            });
        }