Example #1
0
        public async Task Should_fail_when_the_factory_fails()
        {
            var helloKey = "Hello";

            var pendingValue = new PendingValue <string, SimpleValue>(helloKey, SimpleValueFactory.Faulty);

            var nodeValueFactory = new NodeValueFactory <SimpleValue>(pendingValue, 100);

            Assert.That(async() => await nodeValueFactory.CreateValue(), Throws.TypeOf <TestException>());
        }
Example #2
0
        public async Task Should_return_the_value_through_the_pending_value()
        {
            var helloKey = "Hello";

            var pendingValue = new PendingValue <string, SimpleValue>(helloKey, SimpleValueFactory.Healthy);

            var nodeValueFactory = new NodeValueFactory <SimpleValue>(pendingValue, 100);

            var value = await nodeValueFactory.CreateValue().ConfigureAwait(false);

            Assert.That(value, Is.Not.Null);
            Assert.That(value.Id, Is.EqualTo(helloKey));
            Assert.That(value.Value, Is.EqualTo("The key is Hello"));
        }
Example #3
0
        public async Task Should_accept_a_completed_node()
        {
            var tracker = new NodeTracker <SimpleValue>(1000, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(60), () => DateTime.UtcNow);

            var observer = new NodeObserver();

            tracker.Connect(observer);

            var pendingValue     = new PendingValue <string, SimpleValue>("Hello", SimpleValueFactory.Healthy);
            var nodeValueFactory = new NodeValueFactory <SimpleValue>(pendingValue, 100);
            var node             = new FactoryNode <SimpleValue>(nodeValueFactory);

            tracker.Add(nodeValueFactory);

            var value = await node.Value;

            var observedNode = await observer.Value;

            Assert.That(observedNode, Is.InstanceOf <BucketNode <SimpleValue> >());
        }
Example #4
0
        public async Task Should_complete_with_the_second_factory_once_it_works()
        {
            var helloKey = "Hello";

            var faultyValue = new PendingValue <string, SimpleValue>(helloKey, SimpleValueFactory.Faulty);

            var nodeValueFactory = new NodeValueFactory <SimpleValue>(faultyValue, 100);

            var healthyValue = new PendingValue <string, SimpleValue>(helloKey, SimpleValueFactory.Healthy);

            nodeValueFactory.Add(healthyValue);

            var value = await nodeValueFactory.CreateValue().ConfigureAwait(false);

            Assert.That(value, Is.Not.Null);
            Assert.That(value.Id, Is.EqualTo(helloKey));
            Assert.That(value.Value, Is.EqualTo("The key is Hello"));

            Assert.That(async() => await faultyValue.Value, Throws.TypeOf <TestException>());

            var healthy = await healthyValue.Value;
        }