Exemplo n.º 1
0
        public void GivenUnenrichedCacheItem_WhenAskingForResultItem_ThenItShouldThrow()
        {
            // arrange
            InMemoryCache.Instance().Set(Id, new ExpandoObject());
            Result result = new Result();

            // act
            Action action = () => result.Item(Id);

            // assert
            action.Should().Throw <WebException>();
        }
Exemplo n.º 2
0
        public void GivenEnrichedCacheItem_WhenAskingForResultItem_ThenItReturnHydratedObject()
        {
            // arrange
            dynamic expandoObject = new ExpandoObject();

            expandoObject.Results = new { Property = "value" };
            InMemoryCache.Instance().Set(Id, (ExpandoObject)expandoObject);
            Result result = new Result();

            // act
            dynamic actual = result.Item(Id);

            // assert
            ((string)actual.Results.Property).Should().Be("value");
        }
Exemplo n.º 3
0
        public ExpandoObject Item(string id)
        {
            dynamic resultItem = _memoryCache.Get <ExpandoObject>(id);
            Task    task       = new Task(() =>
            {
                while (resultItem is null || !((IDictionary <string, object>)resultItem).ContainsKey(new ResultsFieldName()))
                {
                    Thread.Sleep(_configuration.PollingFrequency());
                    resultItem = _memoryCache.Get <ExpandoObject>(id);
                }
            });

            task.Start();

            if (!task.Wait(_configuration.UniqueResultTimeout()))
            {
                throw new WebException(new TimeoutMessage());
            }

            InMemoryCache.Instance().Remove(id);
            return(resultItem);
        }
Exemplo n.º 4
0
 public void Setup()
 {
     Environment.SetEnvironmentVariable(new UniqueResultTimeoutMillisecondsKey(), "500");
     Environment.SetEnvironmentVariable(new UniqueResultPollingFrequencyKey(), "10");
     InMemoryCache.Instance().Remove(Id);
 }
Exemplo n.º 5
0
 public Result() : this(new ResultConfiguration(), InMemoryCache.Instance())
 {
 }