public void FindJournalsByLastModifiedDate()
        {
            JournalProxy proxy = new JournalProxy();
            JournalDto first = CreateJournalDto();
            first.Date = DateTime.Parse("01-Jan-2010");
            Thread.Sleep(5 * 1000);
            proxy.Insert(first);

            DateTime firstInsert = first.UtcLastModified;

            Thread.Sleep(10 * 1000);

            JournalDto second = CreateJournalDto();
            second.Date = DateTime.Parse("01-Jan-2010");
            Thread.Sleep(5 * 1000);
            proxy.Insert(second);

            DateTime secondInsert = second.UtcLastModified.AddSeconds(-1);

            List<JournalDto> secondOnly = proxy.FindList<JournalDto>(JournalProxy.ResponseXPath, "UtcLastModifiedFrom", secondInsert.ToString("s"), "UtcLastModifiedTo", DateTime.UtcNow.AddMinutes(5).ToString("s"));
            Assert.AreEqual(1, secondOnly.Count);
            // ReflectionTester.AssertAreEqual(second, secondOnly[0], "UtcLastModified");

            List<JournalDto> firstAndSecond = proxy.FindList<JournalDto>(JournalProxy.ResponseXPath, "UtcLastModifiedFrom", firstInsert.ToString("s"), "UtcLastModifiedTo", DateTime.UtcNow.AddMinutes(5).ToString("s"));
            Assert.AreEqual(2, firstAndSecond.Count);
            //ReflectionTester.AssertAreEqual(first, firstAndSecond[0], "UtcLastModified");
            //ReflectionTester.AssertAreEqual(second, firstAndSecond[1], "UtcLastModified");
        }
        public void FindJournalsByTags()
        {
            JournalProxy proxy = new JournalProxy();
            JournalDto dto = CreateJournalDto();

            string tag1 = "Journal" + System.Guid.NewGuid().ToString().Substring(0, 12);
            string tag2 = "Journal" + System.Guid.NewGuid().ToString().Substring(0, 12);

            dto.Tags = string.Format("{0},{1}", tag1, tag2);
            proxy.Insert(dto);
            Assert.IsTrue(dto.Uid > 0, "Uid must be > 0 after save.");

            dto = CreateJournalDto();
            dto.Tags = string.Format("{0},{1}", tag1, tag2);
            proxy.Insert(dto);
            Assert.IsTrue(dto.Uid > 0, "Uid must be > 0 after save.");
        }
        public void Delete()
        {
            JournalProxy proxy = new JournalProxy();
            JournalDto dto = CreateJournalDto();
            proxy.Insert(dto);

            proxy.DeleteByUid(dto.Uid);

            try
            {
                JournalDto fromDB = (JournalDto) proxy.GetByUid(dto.Uid);
                Assert.Fail("The Journal Entry was not deleted successfully.");
            }
            catch (RestException ex)
            {
                Assert.IsTrue(ex.Type == "RecordNotFoundException");
            }
        }
        public void TestRemovalOfAsciiControlCharacters()
        {
            var proxy = new JournalProxy();
            var dto = CreateJournalDto();
            proxy.Insert(dto);

            Assert.IsTrue(dto.Uid > 0, "Uid must be > 0 after save.");

            // Ascii control characters in the summary string below are not visible in visual studio. you need to copy this string to notepad++ to view the non printable characters
            const string summaryTextWithControlCharacters = "Control characters start between these hashes ##  ## control characters end";
            const string summaryTextWithoutControlCharacters = "Control characters start between these hashes ##  ## control characters end";
            dto.Summary = summaryTextWithControlCharacters;

            proxy.Update(dto);

            var read = (JournalDto)proxy.GetByUid(dto.Uid);

            Assert.IsTrue(read.Summary.Equals(summaryTextWithoutControlCharacters, StringComparison.OrdinalIgnoreCase));
        }
        public void FindJournalsForAPeriod()
        {
            JournalProxy proxy = new JournalProxy();
            JournalDto dto1 = CreateJournalDto();
            dto1.Date = DateTime.Parse("01-Jan-2010");
            proxy.Insert(dto1);

            JournalDto dto2 = CreateJournalDto();
            dto2.Date = DateTime.Parse("30-Jan-2010");
            proxy.Insert(dto2);

            NameValueCollection queries = new NameValueCollection();
            queries.Add("JournalDateFrom", "2010/01/01");
            queries.Add("JournalDateTo", "2010/01/30");

            XmlDocument list = proxy.Find(queries);
        }
        public void Update()
        {
            JournalProxy proxy = new JournalProxy();
            JournalDto dto = CreateJournalDto();
            proxy.Insert(dto);

            Assert.IsTrue(dto.Uid > 0, "Uid must be > 0 after save.");

            dto.Summary = "Add some summary.";
            dto.Notes = "Updated journal.";
            proxy.Update(dto);

            JournalDto read = (JournalDto)proxy.GetByUid(dto.Uid);

            ReflectionTester.AssertAreEqual("Journal", dto, read,new[] {"LastModified", "Tags"});
        }
        public void TestInsertMultiCcy1()
        {
            JournalProxy proxy = new JournalProxy();
            JournalDto insert = CreateJournalDto2();
            proxy.Insert(insert);
            Assert.IsTrue(insert.Uid > 0, "Uid must be > 0 after save.");

            JournalDto read = (JournalDto)proxy.GetByUid(insert.Uid);

            Assert.IsTrue(read.FCToBCFXRate > 0, "FX Rate should have been auto-populated.");

            // For comparison, set the original rate to the one set by Saasu.
            insert.FCToBCFXRate = read.FCToBCFXRate;

            ReflectionTester.AssertAreEqual("Journal", insert, read, new[] { "LastModified", "Tags" });
        }
        public void TestInsertAndUpdateByUid()
        {
            JournalProxy proxy = new JournalProxy();
            JournalDto insert = CreateJournalDto();

            proxy.Insert(insert);

            Assert.IsTrue(insert.Uid > 0, "Uid must be > 0 after save.");

            JournalDto read = (JournalDto)proxy.GetByUid(insert.Uid);

            read.Notes = "Updated";

            // change Total and Flip Them Around
            read.Items[0].Amount = 345.78M;
            read.Items[0].Type = DebitCreditType.Debit;

            read.Items[1].Amount = 345.78M;
            read.Items[1].Type = DebitCreditType.Credit;

            proxy.Update(read);

            JournalDto updated = (JournalDto)proxy.GetByUid(insert.Uid);

            ReflectionTester.AssertAreEqual("Journal", read, updated);
        }
 public void TestInsertAndGetByUidUnbalanced()
 {
     JournalProxy proxy = new JournalProxy();
     JournalDto insert = CreateJournalDto();
     insert.Items[0].Amount = 1999;
     try
     {
         proxy.Insert(insert);
         Assert.Fail("No error was thrown.");
     }
     catch(RestException ex)
     {
         Assert.AreEqual("The debit and credit total for the transaction items in this transaction do not match. Out of balance: -1,875.55.", ex.Message, "Incorrect error message.");
     }
 }
        public void TestInsertAndGetByUid()
        {
            JournalProxy proxy = new JournalProxy();
            JournalDto insert = CreateJournalDto();

            proxy.Insert(insert);

            Assert.IsTrue(insert.Uid > 0, "Uid must be > 0 after save.");

            JournalDto read = (JournalDto)proxy.GetByUid(insert.Uid);

            ReflectionTester.AssertAreEqual("Journal", insert, read, new[] { "Tags" });
        }
        public void InvalidAccountAndTaxCodeCombination()
        {
            JournalProxy proxy = new JournalProxy();
            JournalDto dto = CreateJournalDto();
            dto.Items[0].AccountUid = StGeorge.Uid;
            dto.Items[0].TaxCode = TaxCode.SaleInclGst;

            proxy.Insert(dto);
        }