protected async Task ResponseParseTestAsync(Func <TClient, Task <byte[]> > actAsync, HttpResponseMessage mockedHttpResponseMessage, byte[] validAPIResponseByteArray, User piiUser = null, OmniSession omniSession = null)
        {
            var mockedClient   = InitalizeMockedClient(mockedHttpResponseMessage, piiUser: piiUser, omniSession: omniSession);
            var actualResponse = await actAsync(mockedClient);

            AssertExtensions.AreDeeplyEqual(validAPIResponseByteArray, actualResponse);
        }
        protected async Task ResponseParseTestAsync <TResponse>(Func <TClient, Task <TResponse> > actAsync, HttpResponseMessage mockedHttpResponseMessage, string validAPIResponseJson, User piiUser = null, OmniSession omniSession = null)
        {
            var mockedClient = InitalizeMockedClient(mockedHttpResponseMessage, piiUser: piiUser, omniSession: omniSession);

            var actualResponse = await actAsync(mockedClient);

            AssertExtensions.AreDeeplyEqual(JsonConvert.DeserializeObject <TResponse>(validAPIResponseJson), actualResponse);
        }
        protected async Task RequestParseTestAsync <TRequest>(Func <TClient, Task> actAsync, string validAPIRequestJson, User piiUser = null, OmniSession omniSession = null)
        {
            Action <HttpRequestMessage, CancellationToken> testCallback = (req, can) =>
            {
                var actualRequest = req.Content.ReadAsAsync <TRequest>().Result;
                AssertExtensions.AreDeeplyEqual(JsonConvert.DeserializeObject <TRequest>(validAPIRequestJson), actualRequest);
            };

            var mockedClient = InitalizeMockedClient(testCallback: testCallback, piiUser: piiUser, omniSession: omniSession);

            await actAsync(mockedClient);
        }
Esempio n. 4
0
        public void IsNullOrEmptyParameterEmptyTest()
        {
            string sampleParameter = "";

            try
            {
                Validator.For(sampleParameter, "sampleParameter").IsNotNullOrEmpty();
                Assert.Fail("Expected exception is not raised.");
            }
            catch (ArgumentException ex)
            {
                AssertExtensions.AreDeeplyEqual(new ArgumentException("sampleParameter can not be empty or null."), ex);
            }
        }
Esempio n. 5
0
        public void IsGreaterThanOrEqualThrowExceptionTest()
        {
            int sampleParameter = 5;

            try
            {
                Validator.For(sampleParameter, "sampleParameter").IsGreaterThanOrEqual(6);
                Assert.Fail("Expected exception is not raised.");
            }
            catch (ArgumentException ex)
            {
                AssertExtensions.AreDeeplyEqual(new ArgumentException("sampleParameter must be greater than or equal to 6."), ex);
            }
        }
Esempio n. 6
0
        public void InRangeThrowExceptionTest()
        {
            int sampleParameter = 5;

            try
            {
                Validator.For(sampleParameter, "sampleParameter").InRange(6, 10);
                Assert.Fail("Expected exception is not raised.");
            }
            catch (ArgumentOutOfRangeException ex)
            {
                AssertExtensions.AreDeeplyEqual(new ArgumentOutOfRangeException("sampleParameter", 5, string.Format("{0} must be in range ({1} - {2}).", "sampleParameter", 6, 10)), ex);
            }
        }
Esempio n. 7
0
        public void ContainsParameterNullTest()
        {
            string sampleParameter = null;

            try
            {
                Validator.For(sampleParameter, "sampleParameter").Contains(';');
                Assert.Fail("Expected exception is not raised.");
            }
            catch (ArgumentException ex)
            {
                AssertExtensions.AreDeeplyEqual(new ArgumentException("sampleParameter can not be empty or null."), ex);
            }
        }
Esempio n. 8
0
        public void NotNullThrowExceptionTest()
        {
            object sampleNullObject = null;

            try
            {
                Validator.For(sampleNullObject, "sampleNullObject").IsNotNull();
                Assert.Fail("Expected exception is not raised.");
            }
            catch (ArgumentNullException ex)
            {
                AssertExtensions.AreDeeplyEqual(new ArgumentNullException("sampleNullObject can not be null."), ex);
            }
        }
Esempio n. 9
0
        public void ContainsThrowExceptionTest()
        {
            string sampleParameter = "Test";

            try
            {
                Validator.For(sampleParameter, "sampleParameter").Contains(';');
                Assert.Fail("Expected exception is not raised.");
            }
            catch (ArgumentException ex)
            {
                AssertExtensions.AreDeeplyEqual(new ArgumentException("sampleParameter must be include ';' character."), ex);
            }
        }
        protected async Task APIExceptionResponseTestAsync(Func <TClient, Task> actAsync, HttpResponseMessage mockedHttpResponseMessage, ExceptionResult expectedExceptionResult, User piiUser = null, OmniSession omniSession = null)
        {
            var  mockedClient    = InitalizeMockedClient(mockedHttpResponseMessage, piiUser: piiUser, omniSession: omniSession);
            bool exceptionRaised = true;

            try
            {
                await actAsync(mockedClient);

                exceptionRaised = false;
            }
            catch (XOMNIPublicAPIException ex)
            {
                AssertExtensions.AreDeeplyEqual(expectedExceptionResult, ex.ApiExceptionResult);
            }
            if (!exceptionRaised)
            {
                Assert.Fail("Expected exception is not raised.");
            }
        }
        protected async Task SDKExceptionResponseTestAsync(Func <TClient, Task> actAsync, Exception expectedException, User piiUser = null, OmniSession omniSession = null)
        {
            var  mockedClient    = InitalizeMockedClient(piiUser: piiUser, omniSession: omniSession);
            bool exceptionRaised = true;

            try
            {
                await actAsync(mockedClient);

                exceptionRaised = false;
            }
            catch (Exception ex)
            {
                AssertExtensions.AreDeeplyEqual(expectedException, ex);
            }

            if (!exceptionRaised)
            {
                Assert.Fail("Expected exception is not raised.");
            }
        }