public void Given_ValidAESKeyPOCO_When_SerializeAndDeserialize_Then_POCOContentIsTheSame()
        {
            // Arrange
            var aesKeyXmlPoco = new EnvCryptKey()
            {
                Name = "My AES Key",
                Aes  = new[]
                {
                    new EnvCryptKeyAes()
                    {
                        Iv  = "aesIV",
                        Key = "aesKey"
                    }
                },
                Encryption = "Aes",
                Type       = null
            };

            // Act
            var xmlUtil      = new XmlSerializationUtils <EnvCryptKey>();
            var serialized   = xmlUtil.Serialize(aesKeyXmlPoco);
            var deserialized = xmlUtil.Deserialize(serialized);

            // Assert
            deserialized.Should().NotBeNull();
            deserialized.Name.Should().Be(aesKeyXmlPoco.Name);
            deserialized.Encryption.Should().Be(aesKeyXmlPoco.Encryption);
            deserialized.Type.Should().BeNull();
            deserialized.Aes.Should().HaveCount(1);
            deserialized.Aes[0].Iv.Should().Be("aesIV");
            deserialized.Aes[0].Key.Should().Be("aesKey");
        }
Exemplo n.º 2
0
        public TasksResponse Execute()
        {
            var xml = XmlSerializationUtils.Serialize(this._Wrapper);
            var url = this.MakeUrl();

            if (_boolSwitch.Enabled)
            {
                Trace.WriteLine("Post URL:");
                Trace.WriteLine(url);
                Trace.WriteLine("Request XML:");
                Trace.WriteLine(xml);
            }

            var result = HttpUtils.Post(this.MakeUrl(), xml);

            if (_boolSwitch.Enabled)
            {
                Trace.WriteLine("Response XML:");
                Trace.WriteLine(result);
            }

            var tasksResponse = (TasksResponse)XmlSerializationUtils.Deserialize(typeof(TasksResponse), result);

            CheckErrors(tasksResponse.Errors);

            return(tasksResponse);
        }
Exemplo n.º 3
0
        public virtual void DeleteByUid(int uid)
        {
            string          url      = this.MakeUrl() + "&uid=" + uid;
            string          result   = HttpUtils.Delete(url);
            CrudResponseDto response = (CrudResponseDto)XmlSerializationUtils.Deserialize(
                this.ResponseDtoType, result);

            this.CheckErrors(response.Errors);
        }
Exemplo n.º 4
0
        public virtual EntityDto GetByUid(int uid)
        {
            string      url      = this.MakeUrl() + "&uid=" + uid;
            string      result   = HttpUtils.Get(url);
            ResponseDto response = (ResponseDto)XmlSerializationUtils.Deserialize(this.ResponseDtoType, result);

            this.CheckErrors(response.Errors);
            return(this.ExtractContentFromGetByUidResponse(response));
        }
        /// <summary>
        /// Search contact by contact id (not contact uid).
        /// </summary>
        /// <param name="contactID"></param>
        /// <returns></returns>
        private contactListResponse SearchByContactID(string contactID)
        {
            NameValueCollection queries = new NameValueCollection();

            queries.Add("contactid", contactID);
            string url = RestProxy.MakeUrl("ContactList");

            url += "&" + Util.ToQueryString(queries);
            string xmlFragment           = HttpUtils.Get(url);
            contactListResponse response = (contactListResponse)XmlSerializationUtils.Deserialize(typeof(contactListResponse), xmlFragment);

            return(response);
        }
        /// <summary>
        /// Search contact, Carl O'Neil from O'Neil Capital.
        /// </summary>
        /// <returns></returns>
        private contactListResponse SearchCarl()
        {
            NameValueCollection queries = new NameValueCollection();

            queries.Add("givenname", "carl");                   // AKA first name.
            queries.Add("familyName", "o'neil");                // AKA last name.
            queries.Add("organisationName", "o'neil capital");  // AKA organisation, company.
            string url = RestProxy.MakeUrl("ContactList");

            url += "&" + Util.ToQueryString(queries);

            string xmlFragment           = HttpUtils.Get(url);
            contactListResponse response = (contactListResponse)XmlSerializationUtils.Deserialize(typeof(contactListResponse), xmlFragment);

            return(response);
        }
Exemplo n.º 7
0
        public void GetInventoryItemList()
        {
            string url = "http://localhost/restapi/inventoryitemlist?wsaccesskey=4962-A8E9-D414-4DCA-80F2-4A77-CEE6-7DBD&fileuid=1697";
            // string url = "https://secure.saasu.com/alpha/webservices/rest/r1/inventoryitemlist?wsaccesskey=4962-A8E9-D414-4DCA-80F2-4A77-CEE6-7DBD&fileuid=1697";
            string xmlFragment = HttpUtils.Get(url);

            inventoryItemListResponse response = (inventoryItemListResponse)XmlSerializationUtils.Deserialize(typeof(inventoryItemListResponse), xmlFragment);
            inventoryItemListResponseInventoryItemList list = response.Items[0];

            Console.WriteLine("Number of items: {0}", list.inventoryItemListItem.Length);

            foreach (inventoryItemListResponseInventoryItemListInventoryItemListItem item in list.inventoryItemListItem)
            {
                // Console.WriteLine("Inventory item uid: {0}", item.inventoryItemUid);
                this.Count(item.code);
            }
        }
Exemplo n.º 8
0
        public void Given_ValidDatXML_When_Parsed_Then_CountsCorrect()
        {
            // Arrange
            var serializationUtil = new XmlSerializationUtils <EnvCryptEncryptedData>();

            // Act
            var res = serializationUtil.Deserialize(@"<EnvCryptEncryptedData>
	<Category Name=""Prod ReadOnly"">
		<!-- EnvCrypt always stores Strings -->
		
		<Entry Name=""ComLib"">
			<!-- Hash of only part of the key because KeyName is not unique -->
			<Decryption KeyName=""first key"" Hash=""123456"" Algo=""RSA"" />

<!-- 2nd decryption should be ignored. This should not be allowed. -->
			<Decryption KeyName=""asdasdsad RO Key"" Hash=""0"" Algo=""RSA"" />
			
			<EncryptedValue>...</EncryptedValue>
			<!-- Value to be encrypted may spill over max that can be encrypted in one go (RSA) -->
			<EncryptedValue>...</EncryptedValue>
		</Entry>
		<Entry Name=""ComLibConnectionString"">
			<!-- No encryption -->
			<EncryptedValue>...</EncryptedValue>
		</Entry>
	</Category>
	<Category Name=""Prod ReadWrite"">
		<Entry Name=""ComLib"">
			<!-- Hash of only part of the key because KeyName is not unique -->
			<Decryption KeyName=""Prod RW Key"" Hash=""1"" Algo=""AES""/>
			<EncryptedValue>...</EncryptedValue>
		</Entry>
		<Entry Name=""ComLibConnectionString"">
			<!-- No encryption -->
			<EncryptedValue>...</EncryptedValue>
		</Entry>
	</Category>
</EnvCryptEncryptedData>");

            // Assert
            res.Items.Should().HaveCount(2);          // 2 categories
            res.Items[0].Entry.Should().HaveCount(2); // 2 entries in 1st category
            res.Items[0].Entry[0].Decryption.KeyName.Should().Be("first key");
            res.Items[0].Entry[0].Decryption.Hash.Should().Be(123456);
        }
Exemplo n.º 9
0
        public List <T> FindList <T>(string nodeXPath, params string[] parametersAndValues)
            where T : EntityDto, new()
        {
            NameValueCollection parameters = null;

            if (parametersAndValues != null)
            {
                for (int i = 0; i < parametersAndValues.Length; i += 2)
                {
                    if (parameters == null)
                    {
                        parameters = new NameValueCollection();
                    }
                    parameters.Add(parametersAndValues[i], parametersAndValues[i + 1]);
                }
            }

            XmlDocument document = Find(parameters);

            XmlElement  root      = document.DocumentElement;
            XmlNodeList itemsNode = root.SelectNodes(nodeXPath);

            List <T> list = new List <T>();

            foreach (XmlNode itemNode in itemsNode)
            {
                try
                {
                    T dto = (T)XmlSerializationUtils.Deserialize(typeof(T), itemNode.OuterXml);
                    list.Add(dto);
                }
                catch (Exception ex)
                {
                    throw new ApplicationException("Could not deserialize:" + itemNode.OuterXml, ex);
                }
            }

            return(list);
        }
        // [Test]
        public void InsertJournal_MoreThan2Decimals()
        {
            string xml    = @"<?xml version=""1.0"" encoding=""utf-16""?>
<tasks xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""
http://www.w3.org/2001/XMLSchema"">
<insertJournal>
<journal uid=""0"">
<utcLastModified>0001-01-01T00:00:00</utcLastModified>
<date>2012-07-03</date>
<summary>Pay run for pay period ending: 06/07/2012</summary>
<requiresFollowUp>false</requiresFollowUp>
<autoPopulateFxRate>true</autoPopulateFxRate>
<fcToBcFxRate>0</fcToBcFxRate>
<reference>233</reference>
<journalItems>
<journalItem>
<accountUid>299019</accountUid>
<amount>9761.66000</amount>
<type>Credit</type>
</journalItem>
<journalItem>
<accountUid>744</accountUid>
<taxCode>W1</taxCode>
<amount>13300.98648</amount>
<type>Debit</type>
</journalItem>
<journalItem>
<accountUid>744</accountUid>
<taxCode>W1</taxCode>
<amount>0</amount>
<type>Credit</type>
</journalItem>
<journalItem>
<accountUid>744</accountUid>
<taxCode>W1</taxCode>
<amount>0</amount>
<type>Credit</type>
</journalItem>
<journalItem>
<accountUid>744</accountUid>
<taxCode>W1</taxCode>
<amount>0</amount>
<type>Credit</type>
</journalItem>
<journalItem>
<accountUid>744</accountUid>
<taxCode>W1</taxCode>
<amount>0</amount>
<type>Credit</type>
</journalItem>
<journalItem>
<accountUid>744</accountUid>
<taxCode>W1</taxCode>
<amount>0</amount>
<type>Credit</type>
</journalItem>
<journalItem>
<accountUid>744</accountUid>
<taxCode>W1</taxCode>
<amount>0</amount>
<type>Credit</type>
</journalItem>
<journalItem>
<accountUid>2361</accountUid>
<taxCode>W1</taxCode>
<amount>0</amount>
<type>Credit</type>
</journalItem>
<journalItem>
<accountUid>299028</accountUid>
<taxCode>W1</taxCode>
<amount>301.92000</amount>
<type>Debit</type>
</journalItem>
<journalItem>
<accountUid>299028</accountUid>
<taxCode>W1</taxCode>
<amount>0</amount>
<type>Credit</type>
</journalItem>
<journalItem>
<accountUid>744</accountUid>
<taxCode>W1</taxCode>
<amount>0</amount>
<type>Credit</type>
</journalItem>
<journalItem>
<accountUid>744</accountUid>
<taxCode>W1</taxCode>
<amount>969.24648</amount>
<type>Credit</type>
</journalItem>
<journalItem>
<accountUid>741</accountUid>
<amount>2872.00000</amount>
<type>Credit</type>
</journalItem>
<journalItem>
<accountUid>745</accountUid>
<amount>1197.08000</amount>
<type>Debit</type>
</journalItem>
<journalItem>
<accountUid>743</accountUid>
<amount>1197.08000</amount>
<type>Credit</type>
</journalItem>
<journalItem>
<accountUid>744</accountUid>
<amount>969.23000</amount>
<type>Debit</type>
</journalItem>
<journalItem>
<accountUid>2374</accountUid>
<amount>969.23000</amount>
<type>Credit</type>
</journalItem>
<journalItem>
<accountUid>2371</accountUid>
<taxCode>W1</taxCode>
<amount>2872.00000</amount>
<type>Credit</type>
</journalItem>
<journalItem>
<accountUid>2371</accountUid>
<taxCode>W1,W2</taxCode>
<amount>2872.00000</amount>
<type>Debit</type>
</journalItem>
</journalItems>
</journal>
</insertJournal>
</tasks>
";
            string url    = RestProxy.MakeUrl("Tasks");
            string result = HttpUtils.Post(url, xml);

            Console.WriteLine("Result:");
            Console.WriteLine(result);

            var tasksResponse = (TasksResponse)XmlSerializationUtils.Deserialize(typeof(TasksResponse), result);

            Assert.AreEqual(0, tasksResponse.Errors.Count, "Should save successfully.");
        }