/// <summary> /// Creates new instance of ApiConnector /// </summary> /// <param name="accessTokenDelegate">Valid oAuth Access Token</param> /// <param name="client"></param> /// <param name="refreshTokenDelegate"></param> public ApiConnector(Func <string> accessTokenDelegate, ExactOnlineClient client, Func <int, bool> refreshTokenDelegate = null) { _client = client; _refreshTokenDelegate = refreshTokenDelegate; _accessTokenDelegate = accessTokenDelegate ?? throw new ArgumentException("accessTokenDelegate"); }
static void Main(string[] args) { // To make this work set the authorisation properties of your test app in the testapp.config. var testApp = new TestApp(); var connector = new Connector(testApp.ClientId.ToString(), testApp.ClientSecret, testApp.CallbackUrl); var client = new ExactOnlineClient(connector.EndPoint, connector.GetAccessToken); // Get the Code and Name of a random account in the administration. var fields = new[] { "Code", "Name" }; var account = client.For <Account>().Top(1).Select(fields).Get().FirstOrDefault(); Debug.WriteLine("Account {0} - {1}", account.Code.TrimStart(), account.Name); //This is an example of how to use skipToken for paging. string skipToken = string.Empty; var accounts = client.For <Account>().Select(fields).Get(ref skipToken); Debug.WriteLine("skipToken {0}", skipToken); //Now I can use the skip token to get the first record from the next page. var nextAccount = client.For <Account>().Top(1).Select(fields).Get(ref skipToken).FirstOrDefault(); Debug.WriteLine("Account {0} - {1}", nextAccount.Code.TrimStart(), nextAccount.Name); }
public void UpdateLinkedEntities() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); var salesInvoiceId = CreateSalesInvoice(client, 1); // Fetch sales invoice including sales invoice lines var salesInvoice = client.For <SalesInvoice>() .Select("InvoiceID,SalesInvoiceLines/ID,SalesInvoiceLines/InvoiceID,SalesInvoiceLines/Description") .Expand("SalesInvoiceLines") .GetEntity(salesInvoiceId); var salesInvoiceLines = (List <SalesInvoiceLine>)salesInvoice.SalesInvoiceLines; var orginialInvoiceline = salesInvoiceLines[0]; // The original invoice line is not managed because it's taken as related entity from the sales invoice. // Call the api to get a managed invoice line that can be updated. var managedInvoiceLine = client.For <SalesInvoiceLine>().GetEntity(orginialInvoiceline.ID); managedInvoiceLine.Description = string.Format("Changed On {0}", DateTime.UtcNow); // Update and compare client.For <SalesInvoiceLine>().Update(managedInvoiceLine); Assert.AreNotEqual(orginialInvoiceline.Description, managedInvoiceLine.Description); }
public void ExactOnlineQuery_WithWrongProperty_Fails() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); client.For <Account>().Select(new[] { "Xxx" }).Get(); }
public ExactOnlineConnection(string clientId, string clientSecret, string redirectUri, string endPoint, IDropboxUserToken dropboxUserToken) { this.dropboxUserToken = dropboxUserToken; miscellaneousDocumentType = 55; generalCategory = Guid.Parse("3b6d3833-b31b-423d-bc3c-39c62b8f2b12"); //Guid.Parse(clientId); this.endPoint = endPoint; authorization = new AuthorizationState { Callback = new Uri(redirectUri) }; var token = dropboxUserToken.TryRetrieveTokenFromDatabase(HardcodedUser.Id); authorization.AccessToken = token.ExactAccessToken; authorization.AccessTokenExpirationUtc = token.ExactAccessTokenExpiration; exactClient = IsAccessTokenValid() ? new ExactOnlineClient(endPoint, GetAccessToken) : exactClient; var serverDescription = new AuthorizationServerDescription { AuthorizationEndpoint = new Uri(string.Format("{0}/api/oauth2/auth", endPoint)), TokenEndpoint = new Uri(string.Format("{0}/api/oauth2/token", endPoint)) }; oAuthClient = new UserAgentClient(serverDescription, clientId, clientSecret); oAuthClient.ClientCredentialApplicator = ClientCredentialApplicator.PostParameter(clientSecret); }
/// <summary> ///*** Create Docuemnt Folder inside parent folder /// *** Incase of error it set static variable MsgError with error details /// </summary> /// <param name="FolderName">FolderName</param> /// <param name="strParentFolderGUID">Parent Folder GUID.</param> /// <returns>Folder GUID</returns> public string CreateDocumentFolder(string FolderName, string strParentFolderGUID) { try { //*** Create new entity Instance var objDocumentFolder = new DocumentFolder { Code = FolderName, Description = FolderName }; if (strParentFolderGUID != "") { objDocumentFolder.ParentFolder = Guid.Parse(strParentFolderGUID); } var client = new ExactOnlineClient(_endpoint, GetAccessToken); if (client.For <DocumentFolder>().Insert(ref objDocumentFolder)) { return(objDocumentFolder.ID.ToString()); } else { return(""); } } catch (Exception e) //*** Error { MsgError = e.ToString(); return(""); } }
public void ExactClient_GetCurrentMe_Succeeds() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); Assert.IsNotNull(client.CurrentMe()); }
private static Guid GetCategoryId(ExactOnlineClient client) { var categories = client.For <DocumentCategory>().Select("ID").Where("Description+eq+'General'").Get(); var category = categories.First().ID; return(category); }
/// <summary> ///*** Delete Docuemnt Folder inside parent folder /// *** Incase of error it set static variable MsgError with error details /// </summary> /// <param name="strFolderGUID">Folder GUID.</param> /// <returns>Deleteion Result</returns> public bool DeleteDocument(string strDocumentGUID) { try { //*** Get Exact Online Client Object var client = new ExactOnlineClient(_endpoint, GetAccessToken); //*** Get Folder Entity var document = client.For <Document>().Top(1).Where("ID eq guid'" + strDocumentGUID + "'").Select(new string[] { "ID" }).Get(); if (document.Count > 0) { return(client.For <Document>().Delete(document[0])); } else { MsgError = "Document not found"; return(false); } } catch (Exception e) //*** Error { MsgError = e.ToString(); return(false); } }
public void ExactOnlineQuery_WithWrongProperty_Fails() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); client.For<Account>().Select(new[] { "Xxx" }).Get(); }
public void PagingResults() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); //// Get enumerator //var count = client.For<Account>().Count(); //var result = client.For<Account>() // .Expand("BankAccounts") // .Skip(10) // .Get(); //Assert.IsTrue(result.Count == (count - 10)); var accounts = client.For<Account>() .Select("ID,Code,Name") .Where("Name+eq+'Test Eurobike'") .Get(); string hoi = ""; foreach (var account in accounts) { hoi += account.Name + "\t" + account.Code + "\n"; } }
public void UpdateLinkedEntities() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); var salesInvoiceId = CreateSalesInvoice(client, 1); // Fetch sales invoice including sales invoice lines var salesInvoice = client.For<SalesInvoice>() .Select("InvoiceID,SalesInvoiceLines/ID,SalesInvoiceLines/InvoiceID,SalesInvoiceLines/Description") .Expand("SalesInvoiceLines") .GetEntity(salesInvoiceId); var salesInvoiceLines = (List<SalesInvoiceLine>)salesInvoice.SalesInvoiceLines; var orginialInvoiceline = salesInvoiceLines[0]; // The original invoice line is not managed because it's taken as related entity from the sales invoice. // Call the api to get a managed invoice line that can be updated. var managedInvoiceLine = client.For<SalesInvoiceLine>().GetEntity(orginialInvoiceline.ID); managedInvoiceLine.Description = string.Format("Changed On {0}", DateTime.UtcNow); // Update and compare client.For<SalesInvoiceLine>().Update(managedInvoiceLine); Assert.AreNotEqual(orginialInvoiceline.Description, managedInvoiceLine.Description); }
/// <summary> ///*** Get the documents Type "Attachment". /// *** Incase of error it set static variable MsgError with error details /// </summary> /// <returns>DocumentType Attachment ID</returns> private int getAttachmentDocumentTypeId() { try { //*** Get Exact Online Client Object var client = new ExactOnlineClient(_endpoint, GetAccessToken); //*** Get result into Array List var documentsType = client.For <DocumentType>().Top(1).Where("Description eq 'Attachment'").Select(new string[] { "ID" }).Get(); if (documentsType.Count > 0) { return(documentsType[0].ID); } else { return(0); } } catch (Exception e) //*** Error { MsgError = e.ToString(); return(0); } }
private static Guid CreateSalesInvoice(ExactOnlineClient client, int numberOfLines) { var item = client.For <Item>().Top(1).Select("ID").Where("IsSalesItem+eq+true").Get().First(); var customer = client.For <Account>().Top(1).Select("ID").Where("IsSales+eq+true").Get().First(); var salesInvoice = new SalesInvoice { OrderedBy = customer.ID, Description = "SDK User level test" }; var salesInvoiceLines = new List <SalesInvoiceLine>(); for (int iterator = 0; iterator < numberOfLines; iterator++) { var salesInvoiceLine = new SalesInvoiceLine { Item = item.ID, Quantity = 1, Description = "Line " + iterator }; salesInvoiceLines.Add(salesInvoiceLine); } salesInvoice.SalesInvoiceLines = salesInvoiceLines; client.For <SalesInvoice>().Insert(ref salesInvoice); return(salesInvoice.InvoiceID); }
public void PagingResults() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); //// Get enumerator //var count = client.For<Account>().Count(); //var result = client.For<Account>() // .Expand("BankAccounts") // .Skip(10) // .Get(); //Assert.IsTrue(result.Count == (count - 10)); var accounts = client.For <Account>() .Select("ID,Code,Name") .Where("Name+eq+'Test Eurobike'") .Get(); string hoi = ""; foreach (var account in accounts) { hoi += account.Name + "\t" + account.Code + "\n"; } }
public void UpdateReadonlyFields_IgnoresReadonlyFields() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); var account = client.For <Account>().Top(1).Select("ID,Name").Get().First(); var originalName = account.Name; var originalId = account.ID; account.Name = "Test account name2"; account.Created = DateTime.Now; account.Creator = new Guid("c20a5590-c605-4f59-8fbb-112ee142bc59"); account.CreatorFullName = "Edward Jackson"; account.ID = originalId; account.LogoThumbnailUrl = "www.google.nl"; account.Modified = DateTime.Now; account.Modifier = new Guid("c20a5590-c605-4f59-8fbb-112ee142bc59"); account.ModifierFullName = "Test"; account.ClassificationDescription = "Test"; account.CostcenterDescription = "Test"; account.InvoiceAccountCode = "Test"; account.InvoiceAccountName = "Test"; account.LanguageDescription = "Bla"; account.PurchaseCurrencyDescription = "Test"; account.ResellerCode = "Test"; account.ResellerName = "Test"; account.SalesCurrencyDescription = "Test"; account.SalesVATCodeDescription = "Test"; account.StateName = "Test"; Assert.IsTrue(client.For <Account>().Update(account)); // Change it back to testname account.Name = originalName; Assert.IsTrue(client.For <Account>().Update(account)); }
public void GetCollectionOfAllAcountEntitiesInCSharpObjects_Succeeds() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); var accounts = client.For<Account>().Select("ID").Get(); Assert.IsTrue(accounts.Count > 0, "Get Collection Of All Account Entities in CSharp Objects is not implemented corectly"); }
public void CreateUserDocument() { var testObject = new TestObjectsCreator(); var client = new ExactOnlineClient(testObject.EndPoint, testObject.GetOAuthAuthenticationToken); var created = CreateDocument(client); Assert.IsTrue(created); }
public void Authenticate(Uri responseUri) { authorization = oAuthClient.ProcessUserAuthorization(responseUri, authorization); exactClient = new ExactOnlineClient(endPoint, GetAccessToken); dropboxUserToken.UpdateOrCreateToken(HardcodedUser.Id, exactToken: authorization.AccessToken, exactTokenExpiration: authorization.AccessTokenExpirationUtc); }
public void GetSpecificCollectionUsingOData_WithNonExistingEntity() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); var accounts = client.For <Object>() .Where("Description+eq+'Gebouwen'") .Get(); }
/// <summary> /// Creates new instance of ApiConnector /// </summary> /// <param name="accessTokenDelegate">Valid oAuth Access Token</param> public ApiConnector(AccessTokenManagerDelegate accessTokenDelegate, ExactOnlineClient client) { _client = client; if (accessTokenDelegate == null) { throw new ArgumentException("accessTokenDelegate"); } _accessTokenDelegate = accessTokenDelegate; }
public void GetSpecificCollectionUsingOData_WithNonExistingEntity() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); var accounts = client.For<Object>() .Where("Description+eq+'Gebouwen'") .Get(); }
public void GetCollectionOfAllAcountEntitiesInCSharpObjects_Succeeds() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); var accounts = client.For <Account>().Select("ID").Get(); Assert.IsTrue(accounts.Count > 0, "Get Collection Of All Account Entities in CSharp Objects is not implemented corectly"); }
public void TestPerformanceApiCallDelete() { var client = new ExactOnlineClient(_toc.EndPoint, _toc.GetOAuthAuthenticationToken); var account = client.For <Account>().Select("ID").Where("Name+eq+'43905139517985179437'").Get().FirstOrDefault(); var originalprocesstime = TimeSpan.FromSeconds(13.0); var currentprocesstime = TestTimer.Time(() => DoDeleteRequest(account)); Assert.IsTrue(currentprocesstime < originalprocesstime); }
public void ExpiredAccessToken_Succeeds() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); System.Threading.Thread.Sleep(600000); //Sleep for 10 minutes, then the token is expired var accounts = client.For<Account>().Select("ID").Get(); Assert.IsTrue(accounts.Count > 0); }
public void GetUserDocument() { var testObject = new TestObjectsCreator(); var client = new ExactOnlineClient(testObject.EndPoint, testObject.GetOAuthAuthenticationToken); var document = GetDocument(client); Assert.IsNotNull(document); Assert.AreEqual(document.ID, _documentId); }
public void ExactOnlineQuery_WithCorrectProperty_Succeeds() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); var accounts = client.For<Account>() .Select(new[] { "Code" }) .Get(); Assert.IsTrue(accounts.Count> 1); }
public void ExactOnlineQuery_WithCorrectProperty_Succeeds() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); var accounts = client.For <Account>() .Select(new[] { "Code" }) .Get(); Assert.IsTrue(accounts.Count > 1); }
private Document GetDocument(ExactOnlineClient client) { if (_documentId == Guid.Empty) { CreateDocument(client); } var document = client.For <Document>().GetEntity(_documentId); return(document); }
public void ExpiredAccessToken_Succeeds() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); System.Threading.Thread.Sleep(600000); //Sleep for 10 minutes, then the token is expired var accounts = client.For <Account>().Select("ID").Get(); Assert.IsTrue(accounts.Count > 0); }
static void Main(string[] args) { // To make this work set the authorisation properties of your test app in the testapp.config. var testApp = new TestApp(); // When you initialize your Connector class, always reuse it and do not create it again and again. // Otwerwise your calls will be rejected as you should reuse your existing token var connector = new Connector(testApp.ClientId.ToString(), testApp.ClientSecret, testApp.CallbackUrl); // Pass function with all required properties as delegate to ExactOnlineClient class var client1 = new ExactOnlineClient(connector.EndPoint, connector.GetAccessToken); // Call with client 1 // Get the Code and Name of a random account in the administration. var fields = new[] { "Code", "Name" }; var account = client1.For <Account>().Top(1).Select(fields).Get().FirstOrDefault(); Debug.WriteLine(String.Format("Account {0} - {1}", account.Code.TrimStart(), account.Name)); Debug.WriteLine(String.Format("X-RateLimit-Limit: {0} - X-RateLimit-Remaining: {1} - X-RateLimit-Reset: {2}", client1.EolResponseHeader.RateLimit.Limit, client1.EolResponseHeader.RateLimit.Remaining, client1.EolResponseHeader.RateLimit.Reset)); // Now if you would like to create another ExactOnlineClient, you should reuse existing Connector class that you created // Othwerise if you create new Connector class, it is going to request for a new token // and your call will be rejected as your old token has not been expired var client2 = new ExactOnlineClient(connector.EndPoint, connector.GetAccessToken); // Call with client 2 and reusing existing token // This is an example of how to use skipToken for paging. string skipToken = string.Empty; var accounts = client2.For <Account>().Select(fields).Get(ref skipToken); Debug.WriteLine(String.Format("skipToken {0}", skipToken)); Debug.WriteLine(String.Format("X-RateLimit-Limit: {0} - X-RateLimit-Remaining: {1} - X-RateLimit-Reset: {2}", client2.EolResponseHeader.RateLimit.Limit, client2.EolResponseHeader.RateLimit.Remaining, client2.EolResponseHeader.RateLimit.Reset)); // Now application is going to wait until token is expired // Token expires after 9 mins and 30 seconds (570 seconds in total) and after that time the token has to be refreshed var tokenExpiresInSeconds = 570; Debug.WriteLine($"Application is going to sleep for {tokenExpiresInSeconds} seconds"); Thread.Sleep(tokenExpiresInSeconds * 1000); //Call with client1 and token will be refreshed before making a request //Now I can use the skip token to get the first record from the next page. var nextAccount = client1.For <Account>().Top(1).Select(fields).Get(ref skipToken).FirstOrDefault(); Debug.WriteLine(String.Format("Account {0} - {1}", nextAccount.Code.TrimStart(), nextAccount.Name)); Debug.WriteLine(String.Format("X-RateLimit-Limit: {0} - X-RateLimit-Remaining: {1} - X-RateLimit-Reset: {2}", client1.EolResponseHeader.RateLimit.Limit, client1.EolResponseHeader.RateLimit.Remaining, client1.EolResponseHeader.RateLimit.Reset)); }
public void DeleteUserDocument() { var testObject = new TestObjectsCreator(); var client = new ExactOnlineClient(testObject.EndPoint, testObject.GetOAuthAuthenticationToken); var document = GetDocument(client); var result = client.For<Document>().Delete(document); Assert.IsTrue(result); // Document does not exist anymore so it throws an exception client.For<Document>().GetEntity(document.ID); }
public void DeleteUserDocument() { var testObject = new TestObjectsCreator(); var client = new ExactOnlineClient(testObject.EndPoint, testObject.GetOAuthAuthenticationToken); var document = GetDocument(client); var result = client.For <Document>().Delete(document); Assert.IsTrue(result); // Document does not exist anymore so it throws an exception client.For <Document>().GetEntity(document.ID); }
private ActionResult AuthenticationCallback() { Session[EXACT_AUTH_STATE] = client.ProcessUserAuthorization(this.Request); // Call ExactOnline SDK ExactOnlineClient exact = new ExactOnlineClient(ConfigurationManager.AppSettings["exactOnlineUrl"], AccessTokenManager); UserLogin token = Session[DropboxController.DROPBOX_ACCESS_TOKEN] as UserLogin; List <DocumentCategory> categories = exact.For <DocumentCategory>().Select(new string[] { "ID", "Description" }).Get(); Dropbox dropbox = new Dropbox(token, true); IEnumerable <string> fileNames = dropbox.GetNewDocumentNames(); Dictionary <Guid, string> newReferences = new Dictionary <Guid, string>(); foreach (string fileName in fileNames) { byte[] file = dropbox.GetFileBytes(fileName); string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName); Document document = new Document() { Subject = fileNameWithoutExtension, Body = fileNameWithoutExtension, Type = 55, DocumentDate = DateTime.Now.Date, Category = categories[3].ID }; bool createdDocument = exact.For <Document>().Insert(ref document); DocumentAttachment attachment = new DocumentAttachment() { Document = document.ID, FileName = fileName, FileSize = (double)file.Length, Attachment = file }; bool createdAttachment = exact.For <DocumentAttachment>().Insert(ref attachment); newReferences.Add(document.ID, fileName); } Dictionary <Guid, string> existingReferences = dropbox.GetExactOnlineReferences(); dropbox.UpdateExactOnlineReferences(existingReferences, newReferences); return(View()); // Later, if necessary: // bool success = client.RefreshAuthorization(auth); }
public void GetSpecificCollectionUsingOData() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); var accounts = client.For <GLAccount>() .Select("Code") .Where("Description+eq+'Gebouwen'") .And("Code+eq+'0300'") .Get(); Assert.IsTrue(accounts.Any()); }
public void GetSpecificCollectionUsingOData() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); var accounts = client.For<GLAccount>() .Select("Code") .Where("Description+eq+'Gebouwen'") .And("Code+eq+'0300'") .Get(); Assert.IsTrue(accounts.Any()); }
public void GetSpecificCollectionUsingOData_WithOutOData() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); var accounts = client.For<GLAccount>() .Select("Code") .Get(); if (!accounts.Any()) { throw new Exception("The collection of Account entities is empty"); } }
public void GetSpecificCollectionUsingOData_WithOutOData() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); var accounts = client.For <GLAccount>() .Select("Code") .Get(); if (!accounts.Any()) { throw new Exception("The collection of Account entities is empty"); } }
static void Main(string[] args) { // To make this work set the authorisation properties of your test app in the testapp.config. var testApp = new TestApp(); var connector = new Connector(testApp.ClientId.ToString(), testApp.ClientSecret, testApp.CallbackUrl); var client = new ExactOnlineClient(connector.EndPoint, connector.GetAccessToken); // Get the Code and Name of a random account in the administration var fields = new[] { "Code", "Name" }; var account = client.For <Account>().Top(1).Select(fields).Get().FirstOrDefault(); Debug.WriteLine("Account {0} - {1}", account.Code.TrimStart(), account.Name); }
public void GetSpecificCollectionUsingOData_WithNonExistingField() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); var accounts = client.For<Account>() .Select("Code") .Where("Description+eq+'Gebouwen'") .Get(); if (accounts.Count > 1) { throw new Exception("The collection has entities, but filter field does not exist. Exception expected."); } }
public void GetSpecificCollectionUsingOData_WithNonExistingField() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); var accounts = client.For <Account>() .Select("Code") .Where("Description+eq+'Gebouwen'") .Get(); if (accounts.Count > 1) { throw new Exception("The collection has entities, but filter field does not exist. Exception expected."); } }
public void DeleteLinkedEntities() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); // Create a sales invoice with 2 lines var salesInvoiceId = CreateSalesInvoice(client, 2); // Get one of the invoice lines var filter = string.Format("InvoiceID+eq+guid'{0}'", salesInvoiceId); var invoiceLine = client.For<SalesInvoiceLine>().Select("ID").Where(filter).Get().First(); // Delete the line var deleted = client.For<SalesInvoiceLine>().Delete(invoiceLine); Assert.IsTrue(deleted); }
public void UpdateUserDocument() { var testObject = new TestObjectsCreator(); var client = new ExactOnlineClient(testObject.EndPoint, testObject.GetOAuthAuthenticationToken); var document = GetDocument(client); const string subject = "User Acceptance Test Document Updated"; // Update document document.Subject = subject; document.DocumentDate = DateTime.Now.Date; var updated = client.For<Document>().Update(document); var updatedDocument = client.For<Document>().GetEntity(document.ID); Assert.IsTrue(updated); Assert.IsNotNull(updatedDocument); Assert.AreEqual(subject, updatedDocument.Subject); }
public void ModificationRestrictions_Succeed() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); // Create var newJournal = new Journal {Description = "New Journal"}; try { client.For<Journal>().Insert(ref newJournal); throw new Exception(); } catch { } // Update Journal journal = client.For<Journal>().Top(1).Select("ID").Get().First(); journal.Description = "Test Description"; try { client.For<Journal>().Update(journal); throw new Exception(); } catch { } // Delete try { client.For<Journal>().Delete(journal); throw new Exception(); } catch { } }
static void Main(string[] args) { // These are the authorisation properties of your app. // You can find the values in the App Center when you are maintaining the app. const string clientId = "wcq4xgyjo823b0v"; const string clientSecret = "vukz3fusvkt58rm"; // This can be any url as long as it is identical to the callback url you specified for your app in the App Center. var callbackUrl = new Uri("https://github.com/artzain/gorkasapp"); var connector = new Connector(clientId, clientSecret, callbackUrl); var client = new ExactOnlineClient(connector.EndPoint, connector.GetAccessToken); // Get the Code and Name of a random account in the administration var fields = new[] { "Code", "Name" }; var account = client.For<Account>().Top(1).Select(fields).Get().FirstOrDefault(); Debug.WriteLine("Account {0} - {1}", account.Code.TrimStart(), account.Name); }
static async Task<int> MainAsync() { // These are the authorisation properties of your app. // You can find the values in the App Center when you are maintaining the app. const string clientId = "b4e43a22-ab19-4531-9d5a-e08702dad431"; const string clientSecret = "rur2OsABYUgG"; // This can be any url as long as it is identical to the callback url you specified for your app in the App Center. var callbackUrl = new Uri("http://cup-it.net"); var connector = new Connector(clientId, clientSecret, callbackUrl); var client = new ExactOnlineClient(); await client.Initialize(connector.EndPoint, connector.GetAccessToken); // Get the Code and Name of a random account in the administration var fields = new[] { "Code", "Name" }; var account = client.For<Account>().Top(1).Select(fields).GetAsync().Result.FirstOrDefault(); Debug.WriteLine("Account {0} - {1}", account.Code.TrimStart(), account.Name); //fields = new[] { "InvoiceNumber", "AmountDC", "CustomerName", "Document", "DueDate", "EntryDate", "Status" }; //var filter = $"ReportingYear eq 2015"; //var data = await client.For<SalesEntry>().Select(fields).Where(filter).GetAllAsync(); //Debug.WriteLine($"{data.Count} Salesentries"); var defaultMailbox = await client.GetDefaultMailbox(); // Create the mail // Type 1000 = Inkoop factuur var msg = new MailMessage { RecipientMailboxID = defaultMailbox.ID, SenderMailboxID = defaultMailbox.ID, Type = 1000, Subject = "hello" }; var result = await client.For<MailMessage>().InsertAsync(msg); return 0; }
public void CreateLinkedEntities() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); // Fetch sales invoice var salesInvoiceId = CreateSalesInvoice(client, 1); var salesinvoice = client.For<SalesInvoice>().GetEntity(salesInvoiceId); // Fetch item var item = client.For<Item>().Top(1).Select("ID").Where("IsSalesItem+eq+true").Get().First(); // add line var invoiceline = new SalesInvoiceLine { Description = "New Sales Invoice Line", InvoiceID = salesinvoice.InvoiceID, Item = item.ID }; Assert.IsTrue(client.For<SalesInvoiceLine>().Insert(ref invoiceline)); }
public void DeleteAccountWithDeleteMethod() { var toc = new TestObjectsCreator(); // Create new account var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); var newAccount = new Account {Name = "Test account"}; if (client.For<Account>().Insert(ref newAccount)) { // Try to delete account if (!client.For<Account>().Delete(newAccount)) { throw new Exception("Failed to delete test account entity. Possibly this test will not work as the database is now corrupt. Please delete account with name 'Account for 184249' manualy"); } } else { throw new Exception("Cannot create test account entity"); } }
public void CreateSalesInvoiceWithLine() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); var customerId = GetCustomerId(client); var itemId = GetItemId(client); var newInvoice = new SalesInvoice { Currency = "EUR", OrderDate = new DateTime(2012, 10, 26), InvoiceTo = customerId, Journal = "70", OrderedBy = customerId, Description = "New invoice for Entity With Collection" }; var newInvoiceLine = new SalesInvoiceLine { Description = "New invoice line for Entity With Collection", Item = itemId }; var invoicelines = new List<SalesInvoiceLine> {newInvoiceLine}; newInvoice.SalesInvoiceLines = invoicelines; // Add SalesInvoice to Database Assert.IsTrue(client.For<SalesInvoice>().Insert(ref newInvoice)); // Get SalesInvoice and check if contains collections of InvoiceLines SalesInvoice salesInvoice = client.For<SalesInvoice>() .Expand("SalesInvoiceLines") .GetEntity(newInvoice.InvoiceID.ToString()); Assert.IsNotNull(salesInvoice); Assert.AreEqual(1, salesInvoice.SalesInvoiceLines.Count()); }
public void AlterStateAccountObjectDirectly_Succeeds() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); // Get account to update var accounts = client.For<Account>().Top(1).Select("ID").Get(); var account = accounts.First(); // Change name of account & update account.Name = "Test Name UAT2"; if (!client.For<Account>().Update(account)) { throw new Exception("Account is not updated"); } else { // Change account back for test purposes account.Name = "Test Name UAT"; if (!client.For<Account>().Update(account)) { throw new Exception("Changing account entity back for tests failed. Possibly these tests won't work anymore"); } } }
private static Guid GetCategoryId(ExactOnlineClient client) { var categories = client.For<DocumentCategory>().Select("ID").Where("Description+eq+'General'").Get(); var category = categories.First().ID; return category; }
private static int GetCurrentDivision(TestObjectsCreator toc) { var clientWithoutDivision = new ExactOnlineClient(toc.GetWebsite(), toc.GetOAuthAuthenticationToken); return clientWithoutDivision.GetDivision(); }
public void Authenticate(Uri responseUri) { _authorization = _oAuthClient.ProcessUserAuthorization(responseUri, _authorization); _client = new ExactOnlineClient(_endPoint, GetAccessToken); }
private bool CreateDocument(ExactOnlineClient client) { var document = new Document { Subject = "User Acceptance Test Document", Body = "User Acceptance Test Document", Category = GetCategoryId(client), Type = 55, //Miscellaneous DocumentDate = DateTime.Now.Date }; var created = client.For<Document>().Insert(ref document); if (created) { _documentId = document.ID; } return created; }
public void ExactClient_TestEndPointWithSlash_Succeeds() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.GetWebsite(), toc.GetOAuthAuthenticationToken); }
public Document GetDocument(Guid id, ExactOnlineClient exactOnlinClient = null) { try { ExactOnlineClient client = exactOnlinClient ?? this.GetExactOnlineClient(); return client.For<Document>().GetEntity(id); } catch (Exception ex) { AuditLogService.Log(Level.Error, EventType.Exception, EventAction.DocumentGet, ex.Message); } return null; }
public Guid GetDocumentId(string path, ExactOnlineClient exactOnlinClient = null) { try { ExactOnlineClient client = exactOnlinClient ?? this.GetExactOnlineClient(); return client.For<Document>().Select("ID").Where("Subject+eq+'" + this.GetFileName(path) + "'").Get().First().ID; } catch (Exception ex) { if (!ex.Message.Contains("Sequence contains no elements")) { AuditLogService.Log(Level.Error, EventType.Exception, EventAction.DocumentGet, ex.Message); throw ex; } } return Guid.Empty; }
private Document GetDocument(ExactOnlineClient client) { if (_documentId == Guid.Empty) { CreateDocument(client); } var document = client.For<Document>().GetEntity(_documentId); return document; }