public LocalizedModelsDiscoveryTests()
        {
            var types = new[] { typeof(SampleViewModel), typeof(SubViewModel) };
            var sut = new TypeDiscoveryHelper();

            Assert.NotEmpty(types);

            _properties = types.SelectMany(t => sut.ScanResources(t));
        }
Ejemplo n.º 2
0
 public IEnumerable<MorphAction> Combine()
 {
     var collections = new[]
                       {
                           PrepareCollectionFieldDefinitions,
                           PrepareWorkItemTypeDefinitions,
                           ProcessWorkItemData,
                           FinaliseWorkItemTypeDefinitions
                       };
     return collections.SelectMany(collection => collection);
 }
Ejemplo n.º 3
0
        public void Should_match_parameterized_action_path_with_request_path()
        {
            // Given
            var request = new Request("GET", "/fake/child/route", new Dictionary<string, IEnumerable<string>>(), new MemoryStream());
            var modules = new[] { new FakeNancyModuleWithBasePath() };
            var descriptions = modules.SelectMany(x => x.GetRouteDescription(request));

            // When
            var route = this.resolver.GetRoute(request, descriptions);

            // Then
            route.ShouldNotBeOfType<NoMatchingRouteFoundRoute>();
        }
Ejemplo n.º 4
0
        public void Should_be_case_insensitive_when_matching(string path)
        {
            // Given
            var request = new Request("GET", path, new Dictionary<string, IEnumerable<string>>(), new MemoryStream());

            var modules = new[] { new FakeNancyModuleWithBasePath() };
            var descriptions = modules.SelectMany(x => x.GetRouteDescription(request));

            // When
            var route = this.resolver.GetRoute(request, descriptions);

            // Then
            route.ShouldNotBeOfType<NoMatchingRouteFoundRoute>();
        }
Ejemplo n.º 5
0
        public void Should_match_on_combination_of_module_base_path_and_action_path_when_module_defines_base_path()
        {
            // Given
            var request = new Request("GET", "/fake/route/with/some/parts", new Dictionary<string, IEnumerable<string>>(), new MemoryStream());

            var modules = new[] { new FakeNancyModuleWithBasePath() };
            var descriptions = modules.SelectMany(x => x.GetRouteDescription(request));

            // When
            var route = this.resolver.GetRoute(request, descriptions);

            // Then
            route.ShouldNotBeOfType<NoMatchingRouteFoundRoute>();
        }
Ejemplo n.º 6
0
		TreeNode CreateTreeNodeCore()
		{
			var node = new TreeNode();

			using (var stream = item.OpenStream())
			{
				var rawEMsg = PeekUInt(stream);

				node.Nodes.Add(BuildInfoNode(rawEMsg));

				var header = ReadHeader(rawEMsg, stream);
				node.Nodes.Add(new TreeNodeObjectExplorer("Header", header).TreeNode);

				var body = ReadBody(rawEMsg, stream, header);
				var bodyNode = new TreeNodeObjectExplorer("Body", body).TreeNode;
				node.Nodes.Add(bodyNode);

				var payload = ReadPayload(stream);
				if (payload != null && payload.Length > 0)
				{
					node.Nodes.Add(new TreeNodeObjectExplorer("Payload", payload).TreeNode);
				}

				if (Specializations != null)
				{
					var objectsToSpecialize = new[] { body };
					while (objectsToSpecialize.Any())
					{
						var specializations = objectsToSpecialize.SelectMany(o => Specializations.SelectMany(x => x.ReadExtraObjects(o)));

						if (!specializations.Any())
						{
							break;
						}

						bodyNode.Collapse(ignoreChildren: true);

						var extraNodes = specializations.Select(x => new TreeNodeObjectExplorer(x.Key, x.Value).TreeNode).ToArray();
						node.Nodes.AddRange(extraNodes);

						// Let the specializers examine any new message objects.
						objectsToSpecialize = specializations.Select(x => x.Value).ToArray();
					}
				}
			}

			return node;
		}
        /// <summary>
        /// Initializes a new instance of the <see cref="WellKnownRetryStrategyElementCollectionCommand"/> class. 
        /// </summary>
        /// <param name="collection">The collection that will be affected by the add command.</param>
        /// <param name="uiService"><see cref="IUIServiceWpf"/> for displaying messages.</param>
        public WellKnownRetryStrategyElementCollectionCommand(ElementCollectionViewModel collection, IUIServiceWpf uiService)
            : base(collection, uiService)
        {
            this.section = collection.ContainingSection;

            var knownTypes = new[]
                {
                    typeof(IncrementalData), typeof(FixedIntervalData), typeof(ExponentialBackoffData),
                    typeof(CustomRetryStrategyData)
                };

            this.childCommands = knownTypes
                .SelectMany(x => this.section.CreateCollectionElementAddCommand(x, collection))
                .OrderBy(x => x.Title)
                .ToArray();
        }
Ejemplo n.º 8
0
        private void GetEnumerator_returns_SimpleEnumerator_for_simple_CoordinatorFactory(Action<Mock<DbDataReader>, IEnumerator<object>> setupRead,
            Func<IDbEnumerator<object>, List<object>> toList)
        {
            var sourceEnumerable = new[] { new object[] { 1 }, new object[] { 2 } };
            var underlyingEnumerator = ((IEnumerable<object[]>)sourceEnumerable).GetEnumerator();

            var dbDataReaderMock = new Mock<DbDataReader>();
            setupRead(dbDataReaderMock, underlyingEnumerator);
            dbDataReaderMock.Setup(m => m.GetValue(It.IsAny<int>())).Returns((int ordinal) => underlyingEnumerator.Current[ordinal]);

            var coordinatorFactory = Objects.MockHelper.CreateCoordinatorFactory<object>(shaper => shaper.Reader.GetValue(0));

            var shaperMock = new Mock<Shaper<object>>(dbDataReaderMock.Object, /*context*/ null, /*workspace*/ null,
                MergeOption.AppendOnly, /*stateCount*/ 1, coordinatorFactory, /*checkPermissions*/ null,
                /*readerOwned*/ false) { CallBase = true };

            var actualEnumerator = shaperMock.Object.GetEnumerator();

            Assert.Equal(sourceEnumerable.SelectMany(e => e).ToList(), toList(actualEnumerator));
        }
Ejemplo n.º 9
0
            private void Returns_SimpleEnumerator_for_simple_CoordinatorFactory(
                Func<IDbEnumerator<object>, List<object>> toList)
            {
                var sourceEnumerable = new[] { new object[] { 1 }, new object[] { 2 } };

                var coordinatorFactory = Objects.MockHelper.CreateCoordinatorFactory(s => s.Reader.GetValue(0));

                var shaper = new Shaper<object>(
                    MockHelper.CreateDbDataReader(sourceEnumerable),
                    /*context*/ null,
                    /*workspace*/ null,
                    MergeOption.AppendOnly,
                    /*stateCount*/ 1,
                    coordinatorFactory,
                    /*readerOwned*/ false,
                    /*useSpatialReader*/ false);

                var actualEnumerator = shaper.GetEnumerator();

                Assert.Equal(sourceEnumerable.SelectMany(e => e).ToList(), toList(actualEnumerator));
            }
Ejemplo n.º 10
0
        private void GetEnumerator_returns_SimpleEnumerator_for_simple_CoordinatorFactory(
            Func<IDbEnumerator<object>, List<object>> toList)
        {
            var sourceEnumerable = new[] { new object[] { 1 }, new object[] { 2 } };

            var coordinatorFactory = Objects.MockHelper.CreateCoordinatorFactory(shaper => shaper.Reader.GetValue(0));

            var shaperMock = new Mock<Shaper<object>>(
                MockHelper.CreateDbDataReader(sourceEnumerable),
                /*context*/ null,
                /*workspace*/ null,
                MergeOption.AppendOnly,
                /*stateCount*/ 1,
                coordinatorFactory,
                /*checkPermissions*/ null,
                /*readerOwned*/ false)
                                 {
                                     CallBase = true
                                 };

            var actualEnumerator = shaperMock.Object.GetEnumerator();

            Assert.Equal(sourceEnumerable.SelectMany(e => e).ToList(), toList(actualEnumerator));
        }
Ejemplo n.º 11
0
 public void FlattenWithProjection()
 {
     var source = new[] {"A,B,C", "Hello,World"};
     var result = source.SelectMany(x => x.Split(','), (original, split) => split.ToUpper());
     result.AssertSequenceEqual("A", "B", "C", "HELLO", "WORLD");
 }
Ejemplo n.º 12
0
        public void Should_set_parameters_on_route_when_match_was_made_for_parameterized_action_route()
        {
            // Given
            var request = new Request("GET", "/fake/foo/some/stuff/not/in/route/bar/more/stuff/not/in/route", new Dictionary<string, IEnumerable<string>>(), new MemoryStream());
            var modules = new[] { new FakeNancyModuleWithBasePath() };
            var descriptions = modules.SelectMany(x => x.GetRouteDescription(request));
            dynamic result;

            // When
            var route = this.resolver.GetRoute(request, descriptions);

            // Then
            Record.Exception(() => result = route.Parameters.value).ShouldBeNull();
            Record.Exception(() => result = route.Parameters.capture).ShouldBeNull();
        }
Ejemplo n.º 13
0
        public void Should_return_no_matching_route_found_route_when_no_match_could_be_found()
        {
            // Given
            var request = new Request("GET", "/invalid", new Dictionary<string, IEnumerable<string>>(), new MemoryStream());

            var modules = new[] { new FakeNancyModuleWithBasePath() };
            var descriptions = modules.SelectMany(x => x.GetRouteDescription(request));

            // When
            var route = this.resolver.GetRoute(request, descriptions);

            // Then
            route.ShouldBeOfType<NoMatchingRouteFoundRoute>();
        }
        public void ComplexValueTest()
        {
            var injectedProperties = new[]
                {
                    new
                    {
                        InjectedJSON = string.Empty,
                        ExpectedException = (ExpectedException)null
                    },
                    new
                    {
                        InjectedJSON = "\"@custom.annotation\": null",
                        ExpectedException = (ExpectedException)null
                    },
                    new
                    {
                        InjectedJSON = "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataAnnotationNamespacePrefix + "unknown\": { }",
                        ExpectedException = (ExpectedException)null
                    },
                    new
                    {
                        InjectedJSON = "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\": { }",
                        ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightPropertyAndValueDeserializer_UnexpectedAnnotationProperties", JsonLightConstants.ODataContextAnnotationName)
                    },
                    new
                    {
                        InjectedJSON = "\"@custom.annotation\": null, \"@custom.annotation\": 42",
                        ExpectedException = ODataExpectedExceptions.ODataException("DuplicatePropertyNamesChecker_DuplicateAnnotationNotAllowed", "custom.annotation")
                    },
                };

            var payloads = new[]
                {
                    new
                    {
                        Json = "{{{0}}}",
                        ExpectedValue = (ComplexInstance)PayloadBuilder.ComplexValue("TestModel.ComplexType")
                    },
                    new
                    {
                        Json = "{{{0}{1} \"Name\": \"Value\"}}",
                        ExpectedValue = (ComplexInstance)PayloadBuilder.ComplexValue("TestModel.ComplexType")
                            .PrimitiveProperty("Name", "Value")
                    },
                    new
                    {
                        Json = "{{\"Name\": \"Value\"{1}{0}}}",
                        ExpectedValue = (ComplexInstance)PayloadBuilder.ComplexValue("TestModel.ComplexType")
                            .PrimitiveProperty("Name", "Value")
                    },
                    new
                    {
                        Json = "{{\"Name\":\"Value\",{0}{1}\"City\":\"Redmond\"}}",
                        ExpectedValue = (ComplexInstance)PayloadBuilder.ComplexValue("TestModel.ComplexType")
                            .PrimitiveProperty("Name", "Value")
                            .PrimitiveProperty("City", "Redmond")
                    },
                };

            EdmModel model = new EdmModel();

            var addressType = new EdmComplexType("TestModel", "Address");
            addressType.AddStructuralProperty("Street", EdmCoreModel.Instance.GetString(isNullable: false));

            var complexType = new EdmComplexType("TestModel", "ComplexType");
            complexType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(isNullable: false));
            complexType.AddStructuralProperty("City", EdmCoreModel.Instance.GetString(isNullable: false));
            complexType.AddStructuralProperty("Address", new EdmComplexTypeReference(addressType, isNullable: false));
            complexType.AddStructuralProperty("Location", EdmPrimitiveTypeKind.GeographyPoint);

            var owningType = new EdmEntityType("TestModel", "OwningType");
            owningType.AddKeys(owningType.AddStructuralProperty("ID", EdmCoreModel.Instance.GetInt32(isNullable: false)));
            owningType.AddStructuralProperty("TopLevelProperty", new EdmComplexTypeReference(complexType, isNullable: true));
            model.AddElement(owningType);
            model.AddElement(addressType);
            model.AddElement(complexType);

            var container = new EdmEntityContainer("TestModel", "DefaultContainer");
            container.AddEntitySet("OwningType", owningType);
            model.AddElement(container);

            IEnumerable<PayloadReaderTestDescriptor> testDescriptors = payloads.SelectMany(payload => injectedProperties.Select(injectedProperty =>
            {
                return new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.Property("TopLevelProperty", payload.ExpectedValue.DeepCopy()
                            .JsonRepresentation(string.Format(payload.Json, injectedProperty.InjectedJSON, string.IsNullOrEmpty(injectedProperty.InjectedJSON) ? string.Empty : ","))
                        // JSON Light payloads don't store complex type names since the type can be inferred from the context URI and or API.
                            .SetAnnotation(new SerializationTypeNameTestAnnotation() { TypeName = null }))
                        .ExpectedProperty(owningType, "TopLevelProperty"),
                    PayloadEdmModel = model,
                    ExpectedException = injectedProperty.ExpectedException,
                    ExpectedResultPayloadElement = tc => tc.IsRequest
                        ? PayloadBuilder.Property(string.Empty, payload.ExpectedValue.DeepCopy()
                            .SetAnnotation(new SerializationTypeNameTestAnnotation() { TypeName = null }))
                        : PayloadBuilder.Property("TopLevelProperty", payload.ExpectedValue.DeepCopy()
                            .SetAnnotation(new SerializationTypeNameTestAnnotation() { TypeName = null }))
                };
            }));

            var explicitPayloads = new[]
                {
                    new
                    {
                        Description = "Primitive value as complex - should fail.",
                        Json = "42",
                        ExpectedPayload = PayloadBuilder.ComplexValue("TestModel.ComplexType"),
                        ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "StartObject", "PrimitiveValue")
                    },
                    new
                    {
                        Description = "Array value as complex - should fail.",
                        Json = "[]",
                        ExpectedPayload = PayloadBuilder.ComplexValue("TestModel.ComplexType"),
                        ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "StartObject", "StartArray")
                    },
                    new
                    {
                        Description = "Type annotation preceded by custom annotation - should fail",
                        Json = "{" +
                                "\"@custom.annotation\": null," +
                                "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataTypeAnnotationName + "\": \"TestModel.ComplexType\"," +
                                "\"Name\": \"Value\"" +
                            "}",
                        ExpectedPayload = PayloadBuilder.ComplexValue("TestModel.ComplexType"),
                        ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightPropertyAndValueDeserializer_ComplexTypeAnnotationNotFirst")
                    },
                    new
                    {
                        Description = "Custom property annotation - should be ignored.",
                        Json = "{" +
                                "\"" + JsonLightUtils.GetPropertyAnnotationName("Name", "custom.annotation") + "\": null," +
                                "\"Name\": \"Value\"" +
                            "}",
                        ExpectedPayload = PayloadBuilder.ComplexValue("TestModel.ComplexType")
                            .PrimitiveProperty("Name", "Value"),
                        ExpectedException = (ExpectedException)null
                    },
                    new
                    {
                        Description = "Duplicate custom property annotation - should fail.",
                        Json = "{" +
                                "\"" + JsonLightUtils.GetPropertyAnnotationName("Name", "custom.annotation") + "\": null," +
                                "\"" + JsonLightUtils.GetPropertyAnnotationName("Name", "custom.annotation") + "\": 42," +
                                "\"Name\": \"Value\"" +
                            "}",
                        ExpectedPayload = PayloadBuilder.ComplexValue("TestModel.ComplexType"),
                        ExpectedException = ODataExpectedExceptions.ODataException("DuplicatePropertyNamesChecker_DuplicateAnnotationForPropertyNotAllowed", "custom.annotation", "Name")
                    },
                    new
                    {
                        Description = "Unrecognized odata property annotation - should fail.",
                        Json = "{" +
                                "\"" + JsonLightUtils.GetPropertyAnnotationName("Name", JsonLightConstants.ODataAnnotationNamespacePrefix + "unknown") + "\": null," +
                                "\"Name\": \"Value\"" +
                            "}",
                        ExpectedPayload = PayloadBuilder.ComplexValue("TestModel.ComplexType").PrimitiveProperty("Name", "Value"),
                        ExpectedException = (ExpectedException)null
                    },
                    new
                    {
                        Description = "Custom property annotation after the property - should fail.",
                        Json = "{" +
                                "\"Name\": \"Value\"," +
                                "\"" + JsonLightUtils.GetPropertyAnnotationName("Name", "custom.annotation") + "\": null" +
                            "}",
                        ExpectedPayload = PayloadBuilder.ComplexValue("TestModel.ComplexType"),
                        ExpectedException = ODataExpectedExceptions.ODataException("DuplicatePropertyNamesChecker_PropertyAnnotationAfterTheProperty", "custom.annotation", "Name")
                    },
                    new
                    {
                        Description = "OData property annotation.",
                        Json = "{" +
                                "\"" + JsonLightUtils.GetPropertyAnnotationName("Name", JsonLightConstants.ODataTypeAnnotationName) + "\": \"Edm.String\"," +
                                "\"Name\": \"Value\"" +
                            "}",
                        ExpectedPayload = PayloadBuilder.ComplexValue("TestModel.ComplexType")
                            .PrimitiveProperty("Name", "Value"),
                        ExpectedException = (ExpectedException)null
                    },
                    new
                    {
                        Description = "Duplicate odata property annotation.",
                        Json = "{" +
                                "\"" + JsonLightUtils.GetPropertyAnnotationName("Name", JsonLightConstants.ODataTypeAnnotationName) + "\": \"Edm.Int32\"," +
                                "\"" + JsonLightUtils.GetPropertyAnnotationName("Name", JsonLightConstants.ODataTypeAnnotationName) + "\": \"Edm.String\"," +
                                "\"Name\": \"Value\"" +
                            "}",
                        ExpectedPayload = PayloadBuilder.ComplexValue("TestModel.ComplexType"),
                        ExpectedException = ODataExpectedExceptions.ODataException("DuplicatePropertyNamesChecker_DuplicateAnnotationForPropertyNotAllowed", JsonLightConstants.ODataTypeAnnotationName, "Name")
                    },
                    new
                    {
                        Description = "Property with object value and type name annotation - should fail.",
                        Json = "{" +
                                "\"" + JsonLightUtils.GetPropertyAnnotationName("Address", JsonLightConstants.ODataTypeAnnotationName) + "\":\"TestModel.Address\"," +
                                "\"Address\":{}" +
                            "}",
                        ExpectedPayload = PayloadBuilder.ComplexValue("TestModel.ComplexType"),
                        ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightPropertyAndValueDeserializer_ComplexValueWithPropertyTypeAnnotation", JsonLightConstants.ODataTypeAnnotationName)
                    },
                    new
                    {
                        Description = "String property with type annotation after the property - should fail.",
                        Json = "{" +
                                "\"Name\":\"value\"," +
                                "\"" + JsonLightUtils.GetPropertyAnnotationName("Name", JsonLightConstants.ODataTypeAnnotationName) + "\":\"Edm.String\"" +
                            "}",
                        ExpectedPayload = PayloadBuilder.ComplexValue("TestModel.ComplexType"),
                        ExpectedException = ODataExpectedExceptions.ODataException("DuplicatePropertyNamesChecker_PropertyAnnotationAfterTheProperty", JsonLightConstants.ODataTypeAnnotationName, "Name")
                    },
                    new
                    {
                        Description = "String property with null type annotation - should fail.",
                        Json = "{" +
                                "\"" + JsonLightUtils.GetPropertyAnnotationName("Name", JsonLightConstants.ODataTypeAnnotationName) + "\":null," +
                                "\"Name\":\"value\"" +
                            "}",
                        ExpectedPayload = PayloadBuilder.ComplexValue("TestModel.ComplexType"),
                        ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightPropertyAndValueDeserializer_InvalidTypeName", string.Empty)
                    },
                    new
                    {
                        Description = "null property with unknown type annotation - should fail.",
                        Json = "{" +
                                "\"" + JsonLightUtils.GetPropertyAnnotationName("Name", JsonLightConstants.ODataTypeAnnotationName) + "\":\"Unknown\"," +
                                "\"Name\":null" +
                            "}",
                        ExpectedPayload = PayloadBuilder.ComplexValue("TestModel.ComplexType"),
                        ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_IncorrectTypeKind", "Unknown", "Primitive", "Complex"),
                    },
                    new
                    {
                        Description = "Spatial property with odata.type annotation inside the GeoJson object - should fail.",
                        Json = "{" +
                                "\"Location\":" + SpatialUtils.GetSpatialStringValue(ODataFormat.Json, GeographyFactory.Point(33.1, -110.0).Build(), "Edm.GeographyPoint") +
                            "}",
                        ExpectedPayload = PayloadBuilder.ComplexValue("TestModel.ComplexType"),
                        ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightPropertyAndValueDeserializer_ODataTypeAnnotationInPrimitiveValue", JsonLightConstants.ODataTypeAnnotationName),
                    },
                    new
                    {
                        Description = "Spatial property with odata.type annotation inside and outside the GeoJson object - should fail.",
                        Json = "{" +
                                "\"" + JsonLightUtils.GetPropertyAnnotationName("Location", JsonLightConstants.ODataTypeAnnotationName) + "\":\"Edm.GeographyPoint\"," +
                                "\"Location\":" + SpatialUtils.GetSpatialStringValue(ODataFormat.Json, GeographyFactory.Point(33.1, -110.0).Build(), "Edm.GeographyPoint") +
                            "}",
                        ExpectedPayload = PayloadBuilder.ComplexValue("TestModel.ComplexType"),
                        ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightPropertyAndValueDeserializer_ODataTypeAnnotationInPrimitiveValue", JsonLightConstants.ODataTypeAnnotationName),
                    },
                };

            testDescriptors = testDescriptors.Concat(explicitPayloads.Select(payload =>
            {
                return new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.Property("TopLevelProperty", payload.ExpectedPayload.DeepCopy()
                            .JsonRepresentation(payload.Json)
                        // JSON Light payloads don't store complex type names since the type can be inferred from the context URI and or API.
                            .SetAnnotation(new SerializationTypeNameTestAnnotation() { TypeName = null }))
                        // Don't reorder the properties on serialization
                        .SetAnnotation(new JsonLightMaintainPropertyOrderAnnotation())
                        .ExpectedProperty(owningType, "TopLevelProperty"),
                    PayloadEdmModel = model,
                    ExpectedException = payload.ExpectedException,
                    DebugDescription = payload.Description,
                    ExpectedResultPayloadElement = tc => tc.IsRequest
                        ? PayloadBuilder.Property(string.Empty, payload.ExpectedPayload.DeepCopy()
                            .SetAnnotation(new SerializationTypeNameTestAnnotation() { TypeName = null }))
                        : PayloadBuilder.Property("TopLevelProperty", payload.ExpectedPayload.DeepCopy()
                            .SetAnnotation(new SerializationTypeNameTestAnnotation() { TypeName = null }))
                };
            }));

            // Manual test descriptors
            testDescriptors = testDescriptors.Concat(new PayloadReaderTestDescriptor[]
            {
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "null complex value in request.",
                    PayloadElement = PayloadBuilder.Property("TopLevelProperty", PayloadBuilder.ComplexValue("TestModel.ComplexType", true)
                            // JSON Light payloads don't store complex type names since the type can be inferred from the context URI and or API.
                            .SetAnnotation(new SerializationTypeNameTestAnnotation() { TypeName = null }))
                        .JsonRepresentation("{\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataNullAnnotationName + "\":true}")
                        .ExpectedProperty(owningType, "TopLevelProperty"),
                                        //PayloadModel = model,
                    PayloadEdmModel = model,
                    ExpectedResultPayloadElement = tc => PayloadBuilder.Property(string.Empty, PayloadBuilder.ComplexValue("TestModel.ComplexType", true)
                            .SetAnnotation(new SerializationTypeNameTestAnnotation() { TypeName = null })),
                    SkipTestConfiguration = tc => !tc.IsRequest
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "null complex value in response.",
                    PayloadElement = PayloadBuilder.Property("TopLevelProperty", PayloadBuilder.ComplexValue("TestModel.ComplexType", true)
                            // JSON Light payloads don't store complex type names since the type can be inferred from the context URI and or API.
                            .SetAnnotation(new SerializationTypeNameTestAnnotation() { TypeName = null }))
                        .JsonRepresentation(
                            "{" + 
                            "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.ComplexType\"," +
                            "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataNullAnnotationName + "\":true" +
                            "}")
                        .ExpectedProperty(owningType, "TopLevelProperty"),
                                        //PayloadModel = model,
                    PayloadEdmModel = model,
                    ExpectedResultPayloadElement = tc => PayloadBuilder.Property("TopLevelProperty", PayloadBuilder.ComplexValue("TestModel.ComplexType", true)
                            .SetAnnotation(new SerializationTypeNameTestAnnotation() { TypeName = null })),
                    SkipTestConfiguration = tc => tc.IsRequest
                }
            });

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations,
                (testDescriptor, testConfiguration) =>
                {
                    // These descriptors are already tailored specifically for Json Light and 
                    // do not require normalization.
                    testDescriptor.TestDescriptorNormalizers.Clear();
                    testDescriptor.RunTest(testConfiguration);
                });
        }
Ejemplo n.º 15
0
        public void Should_return_the_route_with_most_static_matches_when_multiple_matches_are_found()
        {
            // Given
            var request = new Request("GET", "/fake/child/route/foo", new Dictionary<string, IEnumerable<string>>(), new MemoryStream());
            var modules = new[] { new FakeNancyModuleWithBasePath() };
            var descriptions = modules.SelectMany(x => x.GetRouteDescription(request));
            var route = this.resolver.GetRoute(request, descriptions);
            var response = route.Invoke();

            // When
            var output = GetStringContentsFromResponse(response);

            // Then
            output.ShouldEqual("test");
        }
Ejemplo n.º 16
0
        public void Should_set_action_on_route_when_match_was_found()
        {
            // Given
            var request = new Request("GET", "/fake/route/with/some/parts", new Dictionary<string, IEnumerable<string>>(), new MemoryStream());
            var modules = new[] { new FakeNancyModuleWithBasePath() };
            var descriptions = modules.SelectMany(x => x.GetRouteDescription(request));

            // When
            var route = this.resolver.GetRoute(request, descriptions);
            var response = route.Invoke();
            var output = GetStringContentsFromResponse(response);

            // Then
            output.ShouldEqual("FakeNancyModuleWithBasePath");
        }
Ejemplo n.º 17
0
        public void Should_set_combination_of_module_base_path_and_action_path_on_no_matching_route_found_route_when_no_match_could_be_found()
        {
            // Given
            var request = new Request("GET", "/fake/route/with/some/parts", new Dictionary<string, IEnumerable<string>>(), new MemoryStream());
            var modules = new[] { new FakeNancyModuleWithBasePath() };
            var descriptions = modules.SelectMany(x => x.GetRouteDescription(request));

            // When
            var route = this.resolver.GetRoute(request, descriptions);

            // Then
            route.Path.ShouldEqual(request.Uri);
        }
Ejemplo n.º 18
0
        private static byte[] LocateIconOnFileSystem()
        {
            if (rootPathProvider == null)
            {
                return null;
            }

            byte[] icon = null;
            var extensions = new[] { "ico", "png" };

            var locatedFavIcons = extensions.SelectMany(extension => Directory
                .EnumerateFiles(rootPathProvider.GetRootPath(), string.Concat("favicon.", extension), SearchOption.AllDirectories))
                .ToArray();

            if (locatedFavIcons.Any())
            {
                var image =
                    Image.FromFile(locatedFavIcons.First());

                var converter = new ImageConverter();

                icon = (byte[])converter.ConvertTo(image, typeof(byte[]));
            }

            return icon;
        }
Ejemplo n.º 19
0
        public void Should_treat_action_route_parameters_as_greedy()
        {
            // Given
            var request = new Request("GET", "/fake/foo/some/stuff/not/in/route/bar/more/stuff/not/in/route", new Dictionary<string, IEnumerable<string>>(), new MemoryStream());
            var modules = new[] { new FakeNancyModuleWithBasePath() };
            var descriptions = modules.SelectMany(x => x.GetRouteDescription(request));

            // When
            var route = this.resolver.GetRoute(request, descriptions);

            // Then
            route.ShouldNotBeOfType<NoMatchingRouteFoundRoute>();
        }