Ejemplo n.º 1
0
        public void AddQboTest()
        {
            Customer customer = new Customer();
            string   guid     = Guid.NewGuid().ToString("N");

            customer.GivenName   = guid.Substring(0, 25);
            customer.Title       = guid.Substring(0, 15);
            customer.MiddleName  = guid.Substring(0, 5);
            customer.FamilyName  = guid.Substring(0, 25);
            customer.DisplayName = guid.Substring(0, 20);

            try
            {
                ManualResetEvent manualEvent = new ManualResetEvent(false);
                qboService.OnAddAsyncCompleted = (sender, e) =>
                {
                    Assert.IsNotNull(e);
                    Customer addedCustomer = e.Entity as Customer;
                    Assert.IsTrue(!string.IsNullOrEmpty(addedCustomer.Id));
                    manualEvent.Set();
                };
                qboService.AddAsync(customer);
                manualEvent.WaitOne(30000);
            }
            catch (System.Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
Ejemplo n.º 2
0
        internal static T AddAsync <T>(ServiceContext context, T entity) where T : IEntity
        {
            //Initializing the Dataservice object with ServiceContext
            DataService service = new DataService(context);

            bool isAdded = false;

            IdsException exp = null;

            T actual = (T)Activator.CreateInstance(entity.GetType());
            // Used to signal the waiting test thread that a async operation have completed.
            ManualResetEvent manualEvent = new ManualResetEvent(false);

            // Async callback events are anonomous and are in the same scope as the test code,
            // and therefore have access to the manualEvent variable.
            service.OnAddAsyncCompleted += (sender, e) =>
            {
                isAdded = true;
                manualEvent.Set();
                if (e.Error != null)
                {
                    exp = e.Error;
                }
                if (exp == null)
                {
                    if (e.Entity != null)
                    {
                        actual = (T)e.Entity;
                    }
                }
            };

            // Call the service method
            service.AddAsync(entity);

            manualEvent.WaitOne(30000, false); Thread.Sleep(10000);

            if (exp != null)
            {
                throw exp;
            }

            // Check if we completed the async call, or fail the test if we timed out.
            if (!isAdded)
            {
                //return null;
            }

            // Set the event to non-signaled before making next async call.
            manualEvent.Reset();

            return(actual);
        }
Ejemplo n.º 3
0
        public ActionResult <IEnumerable <string> > Get()
        {
            //var tst = _alberoService.LoadAllAsync();
            //tst.Wait();
            //var r = tst.Result;

            var tst = _dataService.AddAsync(new NewTestDataDto()
            {
                data = "Test"
            });

            _uow.Commit("testing");



            return(new string[] { "value1", "value2" });
        }
Ejemplo n.º 4
0
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            var start = DateTime.Now;
            var trace = new Trace
            {
                EndpointWithoutParams = request.RequestUri.AbsolutePath,
                EndpointParams        = request.RequestUri.Query,
                Method         = request.Method.ToString(),
                RequestContent = JsonConvert.SerializeObject(request.Content)
            };

            var response = await base.SendAsync(request, cancellationToken);

            trace.ResponseStatusCode = response.StatusCode.ToString();
            trace.ResponseContent    = (response.Content?.Headers?.ContentLength ?? 0) > 1000
                ? $"ContentLength:{response.Content.Headers.ContentLength }"
                : JsonConvert.SerializeObject(response.Content);
            trace.ProcessTimeMls = Math.Round((DateTime.Now - start).TotalMilliseconds, 0);


            await _traceService.AddAsync(trace);

            return(response);
        }