public void SerialisationSucceeds()
        {
            // Arrange
            var sut = new SessionRequest
            {
                Username     = TestConstants.USERNAME,
                Password     = TestConstants.PASSWORD,
                SerialNumber = TestConstants.SERIAL_NUMBER
            };

            // Act
            var result = sut.SerializeObject();

            // Assert
            Assert.IsTrue(result.Contains("\"username\""));
            Assert.IsTrue(result.Contains("\"password\""));
            Assert.IsTrue(result.Contains("\"serialNumber\""));
        }
Beispiel #2
0
        public string GetToken(Uri baseUri, string username, string password, string serialNumber)
        {
            Contract.Requires(null != baseUri);
            Contract.Requires(baseUri.IsAbsoluteUri);
            Contract.Requires(!string.IsNullOrWhiteSpace(username));
            Contract.Requires(!string.IsNullOrWhiteSpace(password));
            Contract.Requires(!string.IsNullOrWhiteSpace(serialNumber));
            Contract.Ensures(!string.IsNullOrWhiteSpace(Contract.Result <string>()));

            this.BaseUri = baseUri;

            var sut = new SessionRequest
            {
                Username     = username,
                Password     = password,
                SerialNumber = serialNumber
            };

            var body       = sut.SerializeObject();
            var client     = new RestCallExecutor();
            var requestUri = new Uri(baseUri, Constants.ApiOperation.SESSION);
            var result     = client.Invoke(HttpMethod.Post, requestUri.AbsoluteUri, null, body);

            Contract.Assert(!string.IsNullOrWhiteSpace(result));

            var response = BaseDto.DeserializeObject <SessionResponse>(result);

            UserInformation = new UserInformation()
            {
                UserId        = response.UserId,
                Username      = username,
                Password      = password,
                SerialNumber  = serialNumber,
                SecurityToken = response.SecurityToken
            };

            return(response.SecurityToken);
        }