Exemplo n.º 1
0
        /// <summary>
        /// Get set of data elements async for the session's username, password and uniq.
        /// The set of data elements depends of "i" param.
        /// </summary>
        /// <param name="sessionId">The Session ID returned from the JavaScript data collector.</param>
        /// <param name="username">The username of the user.</param>
        /// <param name="password">Customer identifier.</param>
        /// <param name="uniq">The password of the user.</param>
        /// <param name="dse">The requested set of data elements expected in response.</param>
        /// <returns>Set of data elements</returns>
        public async Task <Info> GetInfoAsync(string sessionId, string username, string password, string uniq, DataSetElements dse)
        {
            int i = dse.Build();

            ValidateGetInfo(sessionId, username, password, uniq, i);

            using (WebClient client = new WebClient())
            {
                PrepareWebClient((WebClient)client, true);

                NameValueCollection reqparm = GetRequestedParams(sessionId, username, password, uniq, i);
                this.LogRequest(InfoEndpoint, username: username, password: password, session: sessionId, uniq: uniq, i: i);

                try
                {
                    byte[] responsebytes = await client.UploadValuesTaskAsync(InfoEndpoint, "POST", reqparm);

                    string responsebody = Encoding.UTF8.GetString(responsebytes);
                    Info   info         = JsonConvert.DeserializeObject <Info>(responsebody);

                    return(info);
                }
                catch (WebException ex)
                {
                    HandleWebException(ex);
                }
                return(null);
            }
        }
        public void TestCallWithBuildOnly_DefaultValueIsZero()
        {
            // Arrange
            var dataSetElements = new DataSetElements();

            // Act
            var dataSetNumber = dataSetElements.Build();

            // Assert
            Assert.AreEqual(0, dataSetNumber);
        }
Exemplo n.º 3
0
        private DataSetElements GetDataSetElementsFromExpectedValueAfterBuild(int expectedValue)
        {
            var dse = new DataSetElements();

            var info = new DataSetElements().WithInfo().Build();

            if ((expectedValue & info) == info)
            {
                dse.WithInfo();
            }

            var velocity = new DataSetElements().WithVelocity().Build();

            if ((expectedValue & velocity) == velocity)
            {
                dse.WithVelocity();
            }

            var decision = new DataSetElements().WithDecision().Build();

            if ((expectedValue & decision) == decision)
            {
                dse.WithDecision();
            }

            var trusted = new DataSetElements().WithTrusted().Build();

            if ((expectedValue & trusted) == trusted)
            {
                dse.WithTrusted();
            }

            var behavioSec = new DataSetElements().WithBehavioSec().Build();

            if ((expectedValue & behavioSec) == behavioSec)
            {
                dse.WithBehavioSec();
            }

            if (expectedValue != dse.Build())
            {
                throw new AccessException(AccessErrorType.INVALID_DATA, "Expected value and DataSetElements.Build() value are different.");
            }

            return(dse);
        }