/// <summary>
 /// Retrieve an entity
 /// </summary>
 /// <param name="cf">A company file that has been retrieved</param>
 /// <param name="financialYear">The requested financial year</param>
 /// <param name="credentials">The credentials to access the company file</param>
 /// <param name="onComplete">The action to call when the operation is complete</param>
 /// <param name="onError">The action to call when the operation has an error</param>
 /// <param name="eTag">The <see cref="BaseEntity.ETag" /> from a previously fetched entity</param>
 public void Get(CompanyFile cf, int financialYear,
                 ICompanyFileCredentials credentials, Action<HttpStatusCode, AccountBudget> onComplete,
                 Action<Uri, Exception> onError, string eTag = null)
 {
     MakeApiGetRequestDelegate(BuildUri(cf, financialYear), credentials, onComplete,
                               onError, eTag);
 }
 public void Setup()
 {
     _companyFile = new CompanyFile { 
         Id = Guid.NewGuid(),
     };
     _companyFile.Uri = new Uri("https://api.myob.com/accountright/" + _companyFile.Id);
     _route = "route";
 }
예제 #3
0
        public void Initialise(IApiConfiguration configuration, CompanyFile companyFile,
                               ICompanyFileCredentials credentials, IOAuthKeyService oAuthKeyService)
        {
            // Add any initialization after the InitializeComponent() call.
            MyConfiguration = configuration;
            MyCompanyFile = companyFile;
            MyCredentials = credentials;
            MyOAuthKeyService = oAuthKeyService;

            Text = string.Format("{0} - {1}", companyFile.Name, companyFile.Uri);
        }
        public void WeGetAccountingPropertiesUsingCompanyFileBaseUrl([ValueSource("_getAccountingPropertiesActions")] Tuple<string, Func<AccountingPropertiesService, CompanyFile, AccountingProperties>> action)
        {
            // arrange
            var cf = new CompanyFile() { Uri = new Uri("https://dc1.api.myob.com/accountright/7D5F5516-AF68-4C5B-844A-3F054E00DF10") };
            _webFactory.RegisterResultForUri(cf.Uri.AbsoluteUri + "/GeneralLedger/AccountingProperties", new PagedCollection<AccountingProperties>() { Items = new[] { new AccountingProperties { ConversionDate = DateTime.Parse("01/01/2013") } }, Count = 1 }.ToJson());

            // act
            var received = action.Item2(_service, cf);

            // assert
            Assert.AreEqual(DateTime.Parse("01/01/2013"), received.ConversionDate);
        }
 public ExampleCustomerViewModel()
     : base(null)
 {
     Customer = new Customer()
         {
             CompanyName = "MI6",
             FirstName = "James",
             LastName = "Bond",
             IsIndividual = false,
             CurrentBalance = 125.27m
         };
     CompanyFile = new CompanyFile() {Name = "Sample Company"};
 }
 public void SetUp()
 {
     _configuration = Substitute.For<IApiConfiguration>();
     _webFactory = new TestWebRequestFactory();
     _service = new AccountBudgetService(_configuration, _webFactory);
     _configuration.ApiBaseUrl.Returns(ApiRequestHandler.ApiRequestUri.AbsoluteUri);
     _financialYear = 2014;
     _cf = new CompanyFile
         {
             Uri = new Uri("https://dc1.api.myob.com/accountright/7D5F5516-AF68-4C5B-844A-3F054E00DF10")
         };
     _getRangeUri = string.Format("{0}/{1}/?", _cf.Uri.AbsoluteUri, _service.Route);
 }
        public void WeGetContactPhotoUsingCompanyFileBaseUrl([ValueSource("_getPhotoActions")] Tuple<string, Func<ContactService, CompanyFile, byte[]>> action)
        {
            // arrange
            var cf = new CompanyFile() { Uri = new Uri("https://dc1.api.myob.com/accountright/7D5F5516-AF68-4C5B-844A-3F054E00DF10") };
            var photo = new Photo() {Data = new byte[] {0, 1, 2, 3}};
            _webFactory.RegisterResultForUri(cf.Uri.AbsoluteUri + "/Contact/" + _uid + "/Photo", photo.ToJson());

            // act
            var received = action.Item2(_service, cf);

            // assert
            Assert.AreEqual(photo.Data, received, "Incorrect data received during {0} operation", action.Item1);
        }
        public void WePostCalculateDiscountsUsingCompanyFileBaseUrl([ValueSource("_executeActions")] Tuple<string, Func<CalculateDiscountsFeesService, CompanyFile, CalculateDiscountsFeesResponse>> action)
        {
            // arrange
            var cf = new CompanyFile { Uri = new Uri("https://dc1.api.myob.com/accountright/7D5F5516-AF68-4C5B-844A-3F054E00DF10") };

            var location = cf.Uri.AbsoluteUri + "/" + _service.Route;
            _webFactory.RegisterResultForUri(cf.Uri.AbsoluteUri + "/" + _service.Route, new CalculateDiscountsFees().ToJson(), HttpStatusCode.OK, location);

            // act
            var received = action.Item2(_service, cf);

            // assert
            Assert.IsNotNull(received);
        }
 public void SetUp()
 {
     _configuration = Substitute.For<IApiConfiguration>();
     _webFactory = new TestWebRequestFactory();
     _service = new TimesheetService(_configuration, _webFactory);
     _configuration.ApiBaseUrl.Returns(ApiRequestHandler.ApiRequestUri.AbsoluteUri);
     _newGuid = Guid.NewGuid();
     _cf = new CompanyFile
         {
             Uri = new Uri("https://dc1.api.myob.com/accountright/7D5F5516-AF68-4C5B-844A-3F054E00DF10")
         };
     _getRangeUri = string.Format("{0}/{1}/?StartDate={2}&EndDate={3}", _cf.Uri.AbsoluteUri,
                                  _service.Route, ((DateTime?)new DateTime(2014, 10, 22)).Value.Date.ToString("s"), ((DateTime?)new DateTime(2014, 10, 29)).Value.Date.ToString("s"));
 }
 /// <summary>
 /// Retrieve an entity
 /// </summary>
 /// <param name="cf">A company file that has been retrieved</param>
 /// <param name="uri">The uri of the entity to retrieve</param>
 /// <param name="credentials">The credentials to access the company file</param>
 /// <returns></returns>
 public Timesheet Get(CompanyFile cf, Uri uri, ICompanyFileCredentials credentials)
 {
     return MakeApiGetRequestSync<Timesheet>(ValidateUri(cf, uri), credentials, null, null);
 }
 /// <summary>
 /// Retrieve an entity
 /// </summary>
 /// <param name="cf">A company file that has been retrieved</param>
 /// <param name="uri">The uri of the entity to retrieve</param>
 /// <param name="credentials">The credentials to access the company file</param>
 /// <returns></returns>
 public Task<Timesheet> GetAsync(CompanyFile cf, Uri uri, ICompanyFileCredentials credentials)
 {
     return this.GetAsync(cf, uri, credentials, CancellationToken.None);
 }
 /// <exclude/>
 static Uri ValidateUri(CompanyFile cf, Uri uri)
 {
     if (!uri.AbsoluteUri.ToLowerInvariant().StartsWith(cf.Uri.AbsoluteUri.ToLowerInvariant()))
         throw new ArgumentException("The supplied Uri is not valid for the company file.", "uri");
     return uri;
 }
예제 #13
0
 public CompanyFileWithResources Get(CompanyFile cf, ICompanyFileCredentials credentials)
 {
     return MakeApiGetRequestSync<CompanyFileWithResources>(cf.Uri, credentials);
 }
 /// <summary>
 /// Update an existing entity
 /// </summary>
 /// <param name="cf">A company file that has been retrieved</param>
 /// <param name="entity">The entity to update</param>
 /// <param name="credentials">The credentials to access the company file</param>
 /// <param name="onComplete">The action to call when the operation is complete</param>
 /// <param name="onError">The action to call when the operation has an error</param>
 /// <param name="errorLevel"></param>
 public void Update(CompanyFile cf, Timesheet entity, ICompanyFileCredentials credentials, Action<HttpStatusCode, string> onComplete, Action<Uri, Exception> onError, ErrorLevel errorLevel = ErrorLevel.IgnoreWarnings)
 {
     var queryString = QueryStringFromErrorLevel(errorLevel);
     MakeApiPutRequestDelegate(BuildUri(cf, entity.Employee == null ? (Guid?)null : entity.Employee.UID, extraQueryString: queryString), entity, credentials, onComplete, onError);
 }
 /// <summary>
 /// Update an existing entity
 /// </summary>
 /// <param name="cf">A company file that has been retrieved</param>
 /// <param name="entity">The entity to update</param>
 /// <param name="credentials">The credentials to access the company file</param>
 /// <param name="errorLevel"></param>
 /// <returns></returns>
 public Task<string> UpdateAsync(CompanyFile cf, Timesheet entity, ICompanyFileCredentials credentials, ErrorLevel errorLevel = ErrorLevel.IgnoreWarnings)
 {
     return this.UpdateAsync(cf, entity, credentials, CancellationToken.None, errorLevel);
 }
 /// <summary>
 /// Retrieve a paged list of entities
 /// </summary>
 /// <param name="cf">A company file that has been retrieved</param>
 /// <param name="queryString">An odata filter</param>
 /// <param name="credentials">The credentials to access the company file</param>
 /// <param name="cancellationToken"></param>
 /// <returns></returns>
 public Task<PagedCollection<Timesheet>> GetRangeAsync(CompanyFile cf, string queryString, ICompanyFileCredentials credentials, CancellationToken cancellationToken)
 {
     return this.MakeApiGetRequestAsync<PagedCollection<Timesheet>>(this.BuildUri(cf, null, queryString.Maybe(_ => "?" + _.TrimStart(new[] { '?' }))), credentials, cancellationToken, null);
 }
 /// <summary>
 /// Retrieve a paged list of entities
 /// </summary>
 /// <param name="cf">A company file that has been retrieved</param>
 /// <param name="queryString">An odata filter</param>
 /// <param name="credentials">The credentials to access the company file</param>
 /// <returns></returns>
 public PagedCollection<Timesheet> GetRange(CompanyFile cf, string queryString, ICompanyFileCredentials credentials)
 {
     return MakeApiGetRequestSync<PagedCollection<Timesheet>>(BuildUri(cf, null, queryString == null ? null : "?" + queryString.TrimStart(new[] { '?' })), credentials, null, null);
 }
 /// <summary>
 /// Retrieve an entity
 /// </summary>
 /// <param name="cf">A company file that has been retrieved</param>
 /// <param name="uri">The uri of the entity to retrieve</param>
 /// <param name="credentials">The credentials to access the company file</param>
 /// <param name="cancellationToken"></param>
 /// <returns></returns>
 public Task<Timesheet> GetAsync(CompanyFile cf, Uri uri, ICompanyFileCredentials credentials, CancellationToken cancellationToken)
 {
     return this.MakeApiGetRequestAsync<Timesheet>(ValidateUri(cf, uri), credentials, cancellationToken, null);
 }
 /// <summary>
 /// Retrieve a paged list of entities
 /// </summary>
 /// <param name="cf">A company file that has been retrieved</param>
 /// <param name="queryString">An odata filter</param>
 /// <param name="credentials">The credentials to access the company file</param>
 /// <param name="onComplete">The action to call when the operation is complete</param>
 /// <param name="onError">The action to call when the operation has an error</param>
 public void GetRange(CompanyFile cf, string queryString, ICompanyFileCredentials credentials, Action<HttpStatusCode, PagedCollection<Timesheet>> onComplete, Action<Uri, Exception> onError)
 {
     MakeApiGetRequestDelegate(BuildUri(cf, null, queryString == null ? null : "?" + queryString.TrimStart(new[] { '?' })), credentials, onComplete, onError, null);
 }
        public void WePutContactUsingCompanyFileBaseUrl_WarningsAsErrors([ValueSource("_putActionsWarnings")] Tuple<string, Func<TimesheetService, CompanyFile, string>> action)
        {
            // arrange
            var cf = new CompanyFile() { Uri = new Uri("https://dc1.api.myob.com/accountright/7D5F5516-AF68-4C5B-844A-3F054E00DF10") };
            var location = cf.Uri.AbsoluteUri + "/Payroll/Timesheet/" + Uid;
            _webFactory.RegisterResultForUri(cf.Uri.AbsoluteUri + "/Payroll/Timesheet/" + Uid + "?warningsAsErrors=true", (string)null, HttpStatusCode.OK, location);

            // act
            var received = action.Item2(_service, cf);

            // assert
            Assert.AreEqual(location, received, "Incorrect data received during {0} operation", received);
        }
 /// <summary>
 /// Retrieve a paged list of entities
 /// </summary>
 /// <param name="cf">A company file that has been retrieved</param>
 /// <param name="queryString">An odata filter</param>
 /// <param name="credentials">The credentials to access the company file</param>
 /// <returns></returns>
 public Task<PagedCollection<Timesheet>> GetRangeAsync(CompanyFile cf, string queryString, ICompanyFileCredentials credentials)
 {
     return this.GetRangeAsync(cf, queryString, credentials, CancellationToken.None);
 }
 /// <summary>
 /// Retrieve an entity
 /// </summary>
 /// <param name="cf">A company file that has been retrieved</param>
 /// <param name="uid">The identifier of the entity to retrieve</param>
 /// <param name="startDate">Timesheet start date</param>
 /// <param name="endDate">Timesheet end date</param>
 /// <param name="credentials">The credentials to access the company file</param>
 /// <param name="onComplete">The action to call when the operation is complete</param>
 /// <param name="onError">The action to call when the operation has an error</param>
 public void Get(CompanyFile cf, Guid uid, DateTime? startDate, DateTime? endDate, ICompanyFileCredentials credentials, Action<HttpStatusCode, Timesheet> onComplete, Action<Uri, Exception> onError)
 {
     MakeApiGetRequestDelegate(BuildUri(cf, uid, startDate: startDate, endDate: endDate), credentials, onComplete, onError, null);
 }
        /// <summary>
        /// Update an existing entity
        /// </summary>
        /// <param name="cf">A company file that has been retrieved</param>
        /// <param name="entity">The entity to update</param>
        /// <param name="credentials">The credentials to access the company file</param>
        /// <param name="errorLevel"></param>
        /// <returns></returns>
        public string Update(CompanyFile cf, Timesheet entity, ICompanyFileCredentials credentials, ErrorLevel errorLevel = ErrorLevel.IgnoreWarnings)
        {
            var queryString = QueryStringFromErrorLevel(errorLevel);

            return MakeApiPutRequestSync(BuildUri(cf, entity.Employee == null ? (Guid?)null : entity.Employee.UID, extraQueryString:queryString), entity, credentials);
        }
 /// <summary>
 /// Retrieve an entity
 /// </summary>
 /// <param name="cf">A company file that has been retrieved</param>
 /// <param name="uid">The identifier of the entity to retrieve</param>
 /// <param name="startDate">Timesheet start date</param>
 /// <param name="endDate">Timesheet end date</param>
 /// <param name="credentials">The credentials to access the company file</param>
 /// <returns></returns>
 public Timesheet Get(CompanyFile cf, Guid uid, DateTime? startDate, DateTime? endDate, ICompanyFileCredentials credentials)
 {
     return MakeApiGetRequestSync<Timesheet>(BuildUri(cf, uid, startDate: startDate, endDate: endDate), credentials, null, null);
 }
        /// <summary>
        /// Update an existing entity
        /// </summary>
        /// <param name="cf">A company file that has been retrieved</param>
        /// <param name="entity">The entity to update</param>
        /// <param name="credentials">The credentials to access the company file</param>
        /// <param name="errorLevel"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task<string> UpdateAsync(CompanyFile cf, Timesheet entity, ICompanyFileCredentials credentials, CancellationToken cancellationToken, ErrorLevel errorLevel = ErrorLevel.IgnoreWarnings)
        {
            var queryString = QueryStringFromErrorLevel(errorLevel);

            return this.MakeApiPutRequestAsync(this.BuildUri(cf, entity.Employee == null ? (Guid?)null : entity.Employee.UID, extraQueryString: queryString), entity, credentials, cancellationToken);
        }
 /// <summary>
 /// Retrieve an entity
 /// </summary>
 /// <param name="cf">A company file that has been retrieved</param>
 /// <param name="uid">The identifier of the entity to retrieve</param>
 /// <param name="startDate">Timesheet start date</param>
 /// <param name="endDate">Timesheet end date</param>
 /// <param name="credentials">The credentials to access the company file</param>
 /// <returns></returns>
 public Task<Timesheet> GetAsync(CompanyFile cf, Guid uid, DateTime? startDate, DateTime? endDate, ICompanyFileCredentials credentials)
 {
     return this.GetAsync(cf, uid, startDate, endDate, credentials, CancellationToken.None);
 }
        private Uri BuildUri(CompanyFile companyFile, Guid? uid = null, string postResource = null, DateTime? startDate = null, DateTime? endDate = null, string extraQueryString = null)
        {
            string qs = null;
            if (startDate.HasValue) qs+= string.Format("StartDate={0}&", startDate.Value.Date.ToString("s"));
            if (endDate.HasValue) qs += string.Format("EndDate={0}&", endDate.Value.Date.ToString("s"));
            if ((extraQueryString != null && extraQueryString != string.Empty)) qs += extraQueryString.TrimStart('?');

            return UriHelper.BuildUri(companyFile, Route, uid, postResource, qs == null ? null : qs.TrimEnd('&'));
        }
 /// <summary>
 /// Retrieve an entity
 /// </summary>
 /// <param name="cf">A company file that has been retrieved</param>
 /// <param name="uid">The identifier of the entity to retrieve</param>
 /// <param name="startDate">Timesheet start date</param>
 /// <param name="endDate">Timesheet end date</param>
 /// <param name="credentials">The credentials to access the company file</param>
 /// <param name="cancellationToken"></param>
 /// <returns></returns>
 public Task<Timesheet> GetAsync(CompanyFile cf, Guid uid, DateTime? startDate, DateTime? endDate, ICompanyFileCredentials credentials, CancellationToken cancellationToken)
 {
     return this.MakeApiGetRequestAsync<Timesheet>(this.BuildUri(cf, uid, startDate: startDate, endDate: endDate), credentials, cancellationToken, null);
 }
 /// <summary>
 /// Build a uri
 /// </summary>
 /// <param name="companyFile"></param>
 /// <param name="route"></param>
 /// <param name="uid"></param>
 /// <param name="postResource"></param>
 /// <param name="queryString"></param>
 /// <returns></returns>
 public static Uri BuildUri(CompanyFile companyFile, string route, Guid? uid = null, string postResource = null, string queryString = null)
 {
     var qs = string.IsNullOrEmpty(queryString) ? string.Empty : queryString.StartsWith("?") ? queryString : "?" + queryString;
     return new Uri(string.Format("{0}/{1}/{2}{3}{4}", companyFile.Uri, route, uid.HasValue ? uid.Value.ToString() : string.Empty, postResource ?? string.Empty, qs));
 }
 /// <summary>
 /// Retrieve an entity
 /// </summary>
 /// <param name="cf">A company file that has been retrieved</param>
 /// <param name="uri">The uri of the entity to retrieve</param>
 /// <param name="credentials">The credentials to access the company file</param>
 /// <param name="onComplete">The action to call when the operation is complete</param>
 /// <param name="onError">The action to call when the operation has an error</param>
 public void Get(CompanyFile cf, Uri uri, ICompanyFileCredentials credentials, Action<HttpStatusCode, Timesheet> onComplete, Action<Uri, Exception> onError)
 {
     MakeApiGetRequestDelegate(ValidateUri(cf, uri), credentials, onComplete, onError, null);
 }