Пример #1
0
        public void CompleteEnumValueValue_ShouldSerializeValue()
        {
            // arrange
            string expectedResult      = "ABC";
            object result              = null;
            bool   nextHandlerIsRaised = false;

            EnumType enumType = new EnumType(d =>
            {
                d.Name("Foo");
                d.Item("ABC");
            });

            Mock <IFieldValueCompletionContext> context =
                new Mock <IFieldValueCompletionContext>(MockBehavior.Strict);

            context.Setup(t => t.Type).Returns(enumType);
            context.Setup(t => t.Value).Returns(expectedResult);
            context.Setup(t => t.SetResult(It.IsAny <string>()))
            .Callback(new Action <object>(v =>
            {
                result = v;
            }));

            // act
            ScalarFieldValueHandler handler = new ScalarFieldValueHandler();

            handler.CompleteValue(context.Object, c => nextHandlerIsRaised = true);

            // assert
            Assert.Equal(expectedResult, result);
            Assert.False(nextHandlerIsRaised);
        }
Пример #2
0
        public void CompleteListOfStringValue_ShouldDelegateToNextHandler()
        {
            // arrange
            string resolverValue       = Guid.NewGuid().ToString();
            object result              = null;
            bool   nextHandlerIsRaised = false;

            ListType listType = new ListType(new StringType());

            Mock <IFieldValueCompletionContext> context =
                new Mock <IFieldValueCompletionContext>(MockBehavior.Strict);

            context.Setup(t => t.Type).Returns(listType);
            context.Setup(t => t.Value).Returns(resolverValue);
            context.Setup(t => t.SetResult(Moq.It.IsAny <string>()))
            .Callback(new Action <object>(v =>
            {
                result = v;
            }));

            // act
            ScalarFieldValueHandler handler = new ScalarFieldValueHandler();

            handler.CompleteValue(context.Object, c => nextHandlerIsRaised = true);

            // assert
            Assert.Null(result);
            Assert.True(nextHandlerIsRaised);
        }
Пример #3
0
        public void CompleteStringScalarValue_ShouldSerializeValue()
        {
            // arrange
            string expectedResult      = Guid.NewGuid().ToString();
            object result              = null;
            bool   nextHandlerIsRaised = false;

            StringType stringType = new StringType();

            Mock <IFieldValueCompletionContext> context =
                new Mock <IFieldValueCompletionContext>(MockBehavior.Strict);

            context.Setup(t => t.Type).Returns(stringType);
            context.Setup(t => t.Value).Returns(expectedResult);
            context.Setup(t => t.SetResult(Moq.It.IsAny <string>()))
            .Callback(new Action <object>(v =>
            {
                result = v;
            }));

            // act
            ScalarFieldValueHandler handler = new ScalarFieldValueHandler();

            handler.CompleteValue(context.Object, c => nextHandlerIsRaised = true);

            // assert
            Assert.Equal(expectedResult, result);
            Assert.False(nextHandlerIsRaised);
        }