Exemplo n.º 1
0
        public void UnFoundField_IsNotReturned()
        {
            var path = new GraphFieldPath(GraphCollection.Subscription, "path1/path2");
            var mock = new Mock <IGraphField>();

            mock.Setup(x => x.Route).Returns(path);
            mock.Setup(x => x.FieldSource).Returns(GraphFieldTemplateSource.Action);

            var path1 = new GraphFieldPath(GraphCollection.Subscription, "path1/path3");
            var mock1 = new Mock <IGraphField>();

            mock1.Setup(x => x.Route).Returns(path1);
            mock1.Setup(x => x.FieldSource).Returns(GraphFieldTemplateSource.Action);

            var o          = new object();
            var collection = new DefaultFieldSourceCollection();

            collection.AddSource(mock.Object, o);
            Assert.AreEqual(1, collection.Count);

            // retreive for an object def. not in the collection
            var found = collection.TryRetrieveSource(mock1.Object, out var result);

            Assert.IsFalse(found);
            Assert.IsNull(result);
        }
Exemplo n.º 2
0
        public void UpdatedFieldIsAdded_CanBeRetrieved()
        {
            var path = new GraphFieldPath(GraphCollection.Subscription, "path1/path2");
            var mock = new Mock <IGraphField>();

            mock.Setup(x => x.Route).Returns(path);
            mock.Setup(x => x.FieldSource).Returns(GraphFieldTemplateSource.Action);

            var o  = new object();
            var o1 = new object();

            var collection = new DefaultFieldSourceCollection(GraphFieldTemplateSource.Action);

            // add then update the source
            collection.AddSource(mock.Object, o);
            collection.AddSource(mock.Object, o1);

            var found = collection.TryRetrieveSource(mock.Object, out var result);

            Assert.IsTrue(collection.ContainsKey(mock.Object));
            Assert.AreEqual(1, collection.Count);

            Assert.IsTrue(found);
            Assert.IsNotNull(result);

            // ensure retrieved result is the second object added
            Assert.AreEqual(o1, result);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GraphFieldExecutionContext" /> class.
 /// </summary>
 /// <param name="parentContext">The parent context.</param>
 /// <param name="fieldRequest">The field request being executed against on this pipeline context.</param>
 /// <param name="variableData">The variable data.</param>
 /// <param name="defaultFieldSources">A collection of objects to use
 /// when attempting to resolve source objects for any down stream fields.</param>
 public GraphFieldExecutionContext(
     IGraphMiddlewareContext parentContext,
     IGraphFieldRequest fieldRequest,
     IResolvedVariableCollection variableData,
     DefaultFieldSourceCollection defaultFieldSources = null)
     : base(parentContext)
 {
     this.Request             = Validation.ThrowIfNullOrReturn(fieldRequest, nameof(fieldRequest));
     this.VariableData        = variableData;
     this.ResolvedSourceItems = new List <GraphDataItem>();
     this.DefaultFieldSources = defaultFieldSources ?? new DefaultFieldSourceCollection();
 }
Exemplo n.º 4
0
        public void DisallowedFieldIsNotAdded_CanNotBeRetrieved()
        {
            var path = new GraphFieldPath(GraphCollection.Subscription, "path1/path2");
            var mock = new Mock <IGraphField>();

            mock.Setup(x => x.Route).Returns(path);
            mock.Setup(x => x.FieldSource).Returns(GraphFieldTemplateSource.Method);

            var o          = new object();
            var collection = new DefaultFieldSourceCollection();

            collection.AddSource(mock.Object, o);

            var found = collection.TryRetrieveSource(mock.Object, out var result);

            Assert.IsFalse(collection.ContainsKey(mock.Object));
            Assert.AreEqual(0, collection.Count);

            Assert.IsFalse(found);
            Assert.IsNull(result);
        }
Exemplo n.º 5
0
        public void WhenMultipleAllowedSources_AllCanBeRetrieved()
        {
            var path = new GraphFieldPath(GraphCollection.Subscription, "path1/path2");
            var mock = new Mock <IGraphField>();

            mock.Setup(x => x.Route).Returns(path);
            mock.Setup(x => x.FieldSource).Returns(GraphFieldTemplateSource.Method);

            var path1 = new GraphFieldPath(GraphCollection.Subscription, "path1/path3");
            var mock1 = new Mock <IGraphField>();

            mock1.Setup(x => x.Route).Returns(path1);
            mock1.Setup(x => x.FieldSource).Returns(GraphFieldTemplateSource.Action);

            var o          = new object();
            var o1         = new object();
            var collection = new DefaultFieldSourceCollection(GraphFieldTemplateSource.Action | GraphFieldTemplateSource.Method);

            collection.AddSource(mock.Object, o);
            collection.AddSource(mock1.Object, o1);

            var found  = collection.TryRetrieveSource(mock.Object, out var result);
            var found1 = collection.TryRetrieveSource(mock1.Object, out var result1);

            Assert.IsTrue(collection.ContainsKey(mock.Object));
            Assert.IsTrue(collection.ContainsKey(mock1.Object));
            Assert.AreEqual(2, collection.Count);

            Assert.IsTrue(found);
            Assert.IsNotNull(result);
            Assert.AreEqual(o, result);

            Assert.IsTrue(found1);
            Assert.IsNotNull(result1);
            Assert.AreEqual(o1, result1);
        }