예제 #1
0
        public void Should_create_new_wrapper_from_xml_response_if_not_already_present()
        {
            // Given
            var environment = new DefaultNancyEnvironment();

            environment.AddValue(XmlConfiguration.Default);
            environment.Tracing(
                enabled: true,
                displayErrorTraces: true);

            var response = new XmlResponse <Model>(new Model()
            {
                Dummy = "Data"
            }, new DefaultXmlSerializer(environment), environment);
            var context = new NancyContext()
            {
                Response = response
            };

            // When
            var result = context.XmlBody <Model>();

            // Then
            result.Dummy.ShouldEqual("Data");
        }
예제 #2
0
        public RazorViewEngineFixture()
        {
            var environment = new DefaultNancyEnvironment();
            environment.Tracing(
                enabled: true,
                displayErrorTraces: true);

            this.configuration = A.Fake<IRazorConfiguration>();
            this.engine = new RazorViewEngine(this.configuration, environment);

            var cache = A.Fake<IViewCache>();
            A.CallTo(() => cache.GetOrAdd(A<ViewLocationResult>.Ignored, A<Func<ViewLocationResult, Func<INancyRazorView>>>.Ignored))
                .ReturnsLazily(x =>
                {
                    var result = x.GetArgument<ViewLocationResult>(0);
                    return x.GetArgument<Func<ViewLocationResult, Func<INancyRazorView>>>(1).Invoke(result);
                });

            this.renderContext = A.Fake<IRenderContext>();
            A.CallTo(() => this.renderContext.ViewCache).Returns(cache);
            A.CallTo(() => this.renderContext.LocateView(A<string>.Ignored, A<object>.Ignored))
                .ReturnsLazily(x =>
                {
                    var viewName = x.GetArgument<string>(0);
                    return FindView(viewName);
                });

            this.rootPathProvider = A.Fake<IRootPathProvider>();
            A.CallTo(() => this.rootPathProvider.GetRootPath()).Returns(Path.Combine(Environment.CurrentDirectory, "TestViews"));

            this.fileSystemViewLocationProvider = new FileSystemViewLocationProvider(this.rootPathProvider, new DefaultFileSystemReader());

            AppDomainAssemblyTypeScanner.AddAssembliesToScan("Nancy.ViewEngines.Razor.Tests.Models.dll");
        }
예제 #3
0
        public RazorViewEngineFixture()
        {
            var environment = new DefaultNancyEnvironment();

            environment.Tracing(
                enabled: true,
                displayErrorTraces: true);

            this.configuration = A.Fake <IRazorConfiguration>();
            this.engine        = new RazorViewEngine(this.configuration, environment, new AppDomainAssemblyCatalog());

            var cache = A.Fake <IViewCache>();

            A.CallTo(() => cache.GetOrAdd(A <ViewLocationResult> .Ignored, A <Func <ViewLocationResult, Func <INancyRazorView> > > .Ignored))
            .ReturnsLazily(x =>
            {
                var result = x.GetArgument <ViewLocationResult>(0);
                return(x.GetArgument <Func <ViewLocationResult, Func <INancyRazorView> > >(1).Invoke(result));
            });

            this.renderContext = A.Fake <IRenderContext>();
            A.CallTo(() => this.renderContext.ViewCache).Returns(cache);
            A.CallTo(() => this.renderContext.LocateView(A <string> .Ignored, A <object> .Ignored))
            .ReturnsLazily(x =>
            {
                var viewName = x.GetArgument <string>(0);
                return(FindView(viewName));
            });

            this.rootPathProvider = A.Fake <IRootPathProvider>();
            A.CallTo(() => this.rootPathProvider.GetRootPath()).Returns(Path.Combine(Environment.CurrentDirectory, "TestViews"));

            this.fileSystemViewLocationProvider = new FileSystemViewLocationProvider(this.rootPathProvider, new DefaultFileSystemReader());
        }
        public void Should_be_xml_serializable()
        {
            // Given
            var environment = new DefaultNancyEnvironment();

            environment.AddValue(Xml.XmlConfiguration.Default);
            environment.Tracing(
                enabled: true,
                displayErrorTraces: true);
            var serializer = new Nancy.Responses.DefaultXmlSerializer(environment);
            var model      = new DefaultStatusCodeHandler.DefaultStatusCodeHandlerResult()
            {
                StatusCode = HttpStatusCode.NotFound,
                Message    = "not found",
                Details    = "not found details"
            };

            // When
            var xml = new System.Xml.XmlDocument();

            using (var stream = new MemoryStream())
            {
                serializer.Serialize("application/xml", model, stream);

                stream.Position = 0;
                xml.Load(stream);
            }

            // Then
            Assert.Equal("DefaultStatusCodeHandlerResult", xml.DocumentElement.Name);
        }
        private INancyEnvironment GetTestingEnvironment(JsonConfiguration configuration)
        {
            var environment =
                new DefaultNancyEnvironment();

            environment.AddValue(configuration);

            return(environment);
        }
        public GenericFileResponseFixture(ITestOutputHelper output)
        {
            var environment = new DefaultNancyEnvironment();
            environment.StaticContent(safepaths: this.GetLocation());

            this.context = new NancyContext { Environment = environment };

            this.filePath = this.GetFilePath();
        }
예제 #7
0
        public void Should_throw_configuration_exception_if_list_of_blank_strings_used_for_supported_culutres_passed_to_globalization_configuration()
        {
            //Given, When
            var environment = new DefaultNancyEnvironment();
            var exception   = Record.Exception(() => environment.Cultures(new [] { "" }));

            //Then
            exception.ShouldBeOfType <ConfigurationException>();
        }
예제 #8
0
        public void Should_throw_configuration_exception_if_empty_list_of_supported_culutres_passed_to_globalization_configuration()
        {
            //Given, When
            var environment = new DefaultNancyEnvironment();
            var exception   = Record.Exception(() => environment.Globalization(Enumerable.Empty <string>()));

            //Then
            exception.ShouldBeOfType <ConfigurationException>();
        }
예제 #9
0
        /// <summary>
        /// Gets a special <see cref="INancyEnvironment"/> instance that is separate from the
        /// one used by the application.
        /// </summary>
        /// <returns></returns>
        private static INancyEnvironment GetDiagnosticsEnvironment()
        {
            var diagnosticsEnvironment =
                new DefaultNancyEnvironment();

            diagnosticsEnvironment.Json(retainCasing: false);

            return(diagnosticsEnvironment);
        }
예제 #10
0
        public void Should_throw_configuration_exception_if_null_value_used_for_supported_culutres_passed_to_globalization_configuration()
        {
            //Given, When
            var environment = new DefaultNancyEnvironment();
            var exception   = Record.Exception(() => environment.Globalization(null));

            //Then
            exception.ShouldBeOfType <ConfigurationException>();
        }
        private static INancyEnvironment GetTestableEnvironment(Action <INancyEnvironment> closure)
        {
            var environment =
                new DefaultNancyEnvironment();

            closure.Invoke(environment);

            return(environment);
        }
예제 #12
0
        private static INancyEnvironment GetTestingEnvironment()
        {
            var envionment =
                new DefaultNancyEnvironment();

            envionment.AddValue(JsonConfiguration.Default);

            return(envionment);
        }
예제 #13
0
        /// <summary>
        /// Gets a special <see cref="INancyEnvironment"/> instance that is separate from the
        /// one used by the application.
        /// </summary>
        /// <returns></returns>
        private static INancyEnvironment GetDiagnosticsEnvironment()
        {
            var diagnosticsEnvironment =
                new DefaultNancyEnvironment();

            diagnosticsEnvironment.Json(retainCasing: false);
            diagnosticsEnvironment.AddValue(ViewConfiguration.Default);

            return(diagnosticsEnvironment);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="T:System.Object"/> class.
        /// </summary>
        public DefaultModelBinderLocatorFixture()
        {
            var environment = new DefaultNancyEnvironment();
            environment.AddValue(JsonConfiguration.Default);

            var bindingDefaults =
                new BindingDefaults(environment);

            this.defaultBinder = new DefaultBinder(new ITypeConverter[] { }, new IBodyDeserializer[] { }, A.Fake<IFieldNameConverter>(), bindingDefaults);
        }
예제 #15
0
        private static DefaultRequestTraceFactory CreateFactory(bool displayErrorTraces = true)
        {
            var environment =
                new DefaultNancyEnvironment();

            environment.Tracing(
                enabled: true,
                displayErrorTraces: displayErrorTraces);

            return(new DefaultRequestTraceFactory(environment));
        }
예제 #16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:System.Object"/> class.
        /// </summary>
        public DefaultModelBinderLocatorFixture()
        {
            var environment = new DefaultNancyEnvironment();

            environment.AddValue(JsonConfiguration.Default);

            var bindingDefaults =
                new BindingDefaults(environment);

            this.defaultBinder = new DefaultBinder(ArrayCache.Empty <ITypeConverter>(), ArrayCache.Empty <IBodyDeserializer>(), A.Fake <IFieldNameConverter>(), bindingDefaults);
        }
        private static INancyEnvironment CreateEnvironment(int numberOfElementsToAdd)
        {
            var environment = new DefaultNancyEnvironment();

            for (var value = 0; value < numberOfElementsToAdd; value++)
            {
                environment.AddValue(value.ToString(), value);
            }

            return(environment);
        }
        public void Should_add_element_with_value_when_invoking_addvalue()
        {
            // Given
            var environment = new DefaultNancyEnvironment();
            var expected    = new object();

            // When
            environment.AddValue(expected);

            // Then
            ((IReadOnlyDictionary <string, object>)environment)[typeof(object).FullName].ShouldBeSameAs(expected);
        }
        public void Should_add_element_with_value_when_invoking_addvalue()
        {
            // Given
            var environment = new DefaultNancyEnvironment();
            var expected = new object();

            // When
            environment.AddValue(expected);

            // Then
            ((IReadOnlyDictionary<string, object>)environment)[typeof(object).FullName].ShouldBeSameAs(expected);
        }
        public void Should_add_element_with_full_name_of_type_as_key_when_invoking_addvalue()
        {
            // Given
            var environment = new DefaultNancyEnvironment();
            var expected = typeof(INancyEnvironmentExtensionsFixture).FullName;

            // When
            environment.AddValue<INancyEnvironmentExtensionsFixture>(null);

            // Then
            environment.ContainsKey(expected).ShouldBeTrue();
        }
예제 #21
0
        public void Should_throw_configuration_exception_if_default_culture_not_supported_globalization_configuration()
        {
            //Given
            var context = CreateContextRequest("/");

            //When
            var environment = new DefaultNancyEnvironment();
            var exception   = Record.Exception(() => environment.Globalization(new[] { "en-GB" }, defaultCulture: "quz-EC"));

            //Then
            exception.ShouldBeOfType <ConfigurationException>();
        }
        public DefaultStatusCodeHandlerFixture()
        {
            var environment =
                new DefaultNancyEnvironment();

            environment.Tracing(
                enabled: true,
                displayErrorTraces: true);

            this.responseNegotiator = A.Fake<IResponseNegotiator>();
            this.statusCodeHandler = new DefaultStatusCodeHandler(this.responseNegotiator, environment);
        }
        public void Should_add_element_with_full_name_of_type_as_key_when_invoking_addvalue()
        {
            // Given
            var environment = new DefaultNancyEnvironment();
            var expected    = typeof(INancyEnvironmentExtensionsFixture).FullName;

            // When
            environment.AddValue <INancyEnvironmentExtensionsFixture>(null);

            // Then
            environment.ContainsKey(expected).ShouldBeTrue();
        }
예제 #24
0
        public GenericFileResponseFixture(ITestOutputHelper output)
        {
            var environment = new DefaultNancyEnvironment();

            environment.StaticContent(safepaths: this.GetLocation());

            this.context = new NancyContext {
                Environment = environment
            };

            this.filePath = this.GetFilePath();
        }
예제 #25
0
        public DefaultStatusCodeHandlerFixture()
        {
            var environment =
                new DefaultNancyEnvironment();

            environment.Tracing(
                enabled: true,
                displayErrorTraces: true);

            this.responseNegotiator = A.Fake <IResponseNegotiator>();
            this.statusCodeHandler  = new DefaultStatusCodeHandler(this.responseNegotiator, environment);
        }
예제 #26
0
        public GenericFileResponseFixture()
        {
            var assemblyPath =
                Path.GetDirectoryName(this.GetType().Assembly.Location);
            
            var environment = new DefaultNancyEnvironment();
            environment.StaticContent(safepaths:assemblyPath);

            this.context = new NancyContext { Environment = environment };

            this.imagePath =
                Path.GetFileName(this.GetType().Assembly.Location);
        }
예제 #27
0
        /// <summary>
        /// Gets a special <see cref="INancyEnvironment"/> instance that is separate from the
        /// one used by the application.
        /// </summary>
        /// <returns></returns>
        private static INancyEnvironment GetDiagnosticsEnvironment()
        {
            var diagnosticsEnvironment =
                new DefaultNancyEnvironment();

            diagnosticsEnvironment.Json(retainCasing: false);
            diagnosticsEnvironment.AddValue(ViewConfiguration.Default);
            diagnosticsEnvironment.Tracing(
                enabled: true,
                displayErrorTraces: true);

            return(diagnosticsEnvironment);
        }
예제 #28
0
        public DefaultXmlSerializerTests()
        {
            var environment =
                new DefaultNancyEnvironment();

            environment.Tracing(
                enabled: true,
                displayErrorTraces: true);
            environment.Xml(true);
            environment.Globalization(new[] { "en-US" });

            this.xmlSerializer = new DefaultXmlSerializer(environment);
        }
예제 #29
0
        private static INancyEnvironment GetTestingEnvironment()
        {
            var environment =
                new DefaultNancyEnvironment();

            environment.Tracing(
                enabled: true,
                displayErrorTraces: true);

            environment.Json();

            return(environment);
        }
예제 #30
0
        private static INancyEnvironment GetTestableEnvironment(Action <INancyEnvironment> closure)
        {
            var environment =
                new DefaultNancyEnvironment();

            environment.Tracing(
                enabled: true,
                displayErrorTraces: true);

            closure.Invoke(environment);

            return(environment);
        }
        private static INancyEnvironment GetTestingEnvironment()
        {
            var envionment =
                new DefaultNancyEnvironment();

            envionment.AddValue(JsonConfiguration.Default);

            envionment.Tracing(
                enabled: true,
                displayErrorTraces: true);

            return(envionment);
        }
예제 #32
0
        public DefaultJsonSerializerTests()
        {
            var environment =
                new DefaultNancyEnvironment();

            environment.Tracing(
                enabled: true,
                displayErrorTraces: true);
            environment.Json();
            environment.Globalization(new[] { "en-US" });

            this.jsonSerializer = new DefaultJsonSerializer(environment);
        }
        public void Should_return_correct_key_presence_when_invoking_containskey(string keyToAdd, string keyToLookFor, bool expectedResult)
        {
            // Given
            var environment = new DefaultNancyEnvironment();

            environment.AddValue(keyToAdd, new object());

            // When
            var result = environment.ContainsKey(keyToLookFor);

            // Then
            result.ShouldEqual(expectedResult);
        }
예제 #34
0
        public void Should_create_new_wrapper_from_xml_response_if_not_already_present()
        {
            // Given
            var environment = new DefaultNancyEnvironment();
            environment.AddValue(XmlConfiguration.Default);
            var response = new XmlResponse<Model>(new Model() { Dummy = "Data" }, new DefaultXmlSerializer(environment), environment);
            var context = new NancyContext() { Response = response };

            // When
            var result = context.XmlBody<Model>();

            // Then
            result.Dummy.ShouldEqual("Data");
        }
        public void Should_return_correct_status_value_when_invoking_trygetvalue(string keyToLookFor, bool expectedResult)
        {
            // Given
            var environment = new DefaultNancyEnvironment();

            environment.AddValue("nancy", new object());
            object output;

            // When
            var result = environment.TryGetValue(keyToLookFor, out output);

            // Then
            result.ShouldEqual(expectedResult);
        }
        public void Should_retrieve_value_using_full_name_of_type_when_invoking_getvaluewithdefault_with_type_and_element_exists()
        {
            // Given
            var environment = new DefaultNancyEnvironment();
            var expected = new object();

            environment.AddValue(typeof(object).FullName, expected);

            // When
            var result = environment.GetValueWithDefault(new object());

            // Then
            result.ShouldBeSameAs(expected);
        }
예제 #37
0
        private static INancyEnvironment GetTestingEnvironment()
        {
            var environment =
                new DefaultNancyEnvironment();

            environment.Tracing(
                enabled: true,
                displayErrorTraces: true);

            environment.Json();
            environment.Globalization(new []{"en-US"});

            return environment;
        }
        public void Should_retrieve_default_value_using_full_name_of_type_when_invoking_getvaluewithdefault_with_type_and_element_does_not_exists()
        {
            // Given
            var environment  = new DefaultNancyEnvironment();
            var defaultValue = new object();

            environment.AddValue(typeof(string).FullName, new object());

            // When
            var result = environment.GetValueWithDefault(defaultValue);

            // Then
            result.ShouldBeSameAs(defaultValue);
        }
예제 #39
0
        private NancyContext CreateContextRequest(string path, IDictionary <string, IEnumerable <string> > cultureHeaders = null)
        {
            var context = new NancyContext();
            var request = new Request("GET", new Url {
                Path = path, Scheme = "http"
            }, null, cultureHeaders);

            context.Request = request;
            var environment = new DefaultNancyEnvironment();

            environment.Globalization(new[] { "en-US" }, "en-US");
            context.Environment = environment;
            return(context);
        }
        public void Should_retrieve_value_using_full_name_of_type_when_invoking_getvalue_with_type()
        {
            // Given
            var environment = new DefaultNancyEnvironment();
            var expected    = new object();

            environment.AddValue(typeof(object).FullName, expected);

            // When
            var result = environment.GetValue <object>();

            // Then
            result.ShouldBeSameAs(expected);
        }
        public XmlFormatterExtensionsFixtures()
        {
            this.rootPathProvider = A.Fake<IRootPathProvider>();
            var environment = new DefaultNancyEnvironment();
            environment.AddValue(XmlConfiguration.Default);

            var serializerFactory =
                new DefaultSerializerFactory(new ISerializer[] { new DefaultXmlSerializer(environment) });

            this.responseFormatter =
                new DefaultResponseFormatter(this.rootPathProvider, new NancyContext(), serializerFactory, environment);

            this.model = new Person { FirstName = "Andy", LastName = "Pike" };
            this.response = this.responseFormatter.AsXml(model);
        }
        public void Should_retrieve_value_when_invoking_getvalue_with_string_key()
        {
            // Given
            const string key = "thekey";

            var environment = new DefaultNancyEnvironment();
            var expected = new object();

            environment.AddValue(key, expected);

            // When
            var result = environment.GetValue<object>(key);

            // Then
            result.ShouldBeSameAs(expected);
        }
예제 #43
0
        public void Should_use_filename_and_content_type_for_attachments_from_file_response_if_not_overridden()
        {
            // Given
            var environment = new DefaultNancyEnvironment();
            environment.StaticContent(safepaths:this.GetLocation());

            var filename = this.GetFilePath();
            var response = new GenericFileResponse(filename, "foo/bar", new NancyContext() {Environment = environment});

            // When
            var result = response.AsAttachment();

            // Then
            result.Headers["Content-Disposition"].ShouldContain(Path.GetFileName(filename));
            result.ContentType.ShouldEqual("foo/bar");
        }
예제 #44
0
        public void Should_use_filename_and_content_type_for_attachments_from_file_response_if_not_overridden()
        {
            // Given
            var assemblyPath =
                Path.GetDirectoryName(this.GetType().Assembly.Location);

            var environment = new DefaultNancyEnvironment();
            environment.StaticContent(safepaths:assemblyPath);

            var filename = Path.GetFileName(this.GetType().Assembly.Location);
            var response = new GenericFileResponse(filename, "image/png", new NancyContext() {Environment = environment});

            // When
            var result = response.AsAttachment();
            
            // Then
            result.Headers["Content-Disposition"].ShouldContain(filename);
            result.ContentType.ShouldEqual("image/png");
        }
예제 #45
0
        private INancyEnvironment GetTestingEnvironment(JsonConfiguration configuration)
        {
            var environment =
                new DefaultNancyEnvironment();

            environment.AddValue(configuration);

            return environment;
        }
예제 #46
0
        private static INancyEnvironment GetTestingEnvironment()
        {
            var environment =
                new DefaultNancyEnvironment();

            environment.Tracing(
                enabled: true,
                displayErrorTraces: true);

            environment.Json();

            return environment;
        }
        public void Should_get_key_from_configuration_provider_for_default_configuration_object(Type type)
        {
            // Given
            var expectedKey = string.Concat("the-expected-key-", type.Name);
            var env = new DefaultNancyEnvironment();

            var fact = A.Fake<INancyEnvironmentFactory>();
            A.CallTo(() => fact.CreateEnvironment()).Returns(env);

            var provider = A.Fake<INancyDefaultConfigurationProvider>();
            A.CallTo(() => provider.GetDefaultConfiguration()).ReturnsLazily(() => Activator.CreateInstance(type));
            A.CallTo(() => provider.Key).Returns(expectedKey);

            var config = new DefaultNancyEnvironmentConfigurator(fact, new[] { provider });

            // When
            config.ConfigureEnvironment(x => { });

            // Then
            env.ContainsKey(expectedKey).ShouldBeTrue();
        }
        public void Should_return_correct_key_presence_when_invoking_containskey(string keyToAdd, string keyToLookFor, bool expectedResult)
        {
            // Given
            var environment = new DefaultNancyEnvironment();
            environment.AddValue(keyToAdd, new object());

            // When
            var result = environment.ContainsKey(keyToLookFor);

            // Then
            result.ShouldEqual(expectedResult);
        }
        public void Should_return_value_if_key_exists_when_invoking_trygetvalue()
        {
            // Given
            var environment = new DefaultNancyEnvironment();
            var expectedValue = new object();
            environment.AddValue("nancy", expectedValue);
            object output;

            // When
            environment.TryGetValue("nancy", out output);

            // Then
            output.ShouldBeSameAs(expectedValue);
        }
예제 #50
0
        private static DefaultRequestTraceFactory CreateFactory(bool displayErrorTraces = true)
        {
            var environment =
                new DefaultNancyEnvironment();

            environment.Tracing(
                enabled: true,
                displayErrorTraces: displayErrorTraces);

            return new DefaultRequestTraceFactory(environment);
        }
        public void Should_return_correct_status_value_when_invoking_trygetvalue(string keyToLookFor, bool expectedResult)
        {
            // Given
            var environment = new DefaultNancyEnvironment();
            environment.AddValue("nancy", new object());
            object output;

            // When
            var result = environment.TryGetValue(keyToLookFor, out output);

            // Then
            result.ShouldEqual(expectedResult);
        }
예제 #52
0
        /// <summary>
        /// Gets a special <see cref="INancyEnvironment"/> instance that is separate from the
        /// one used by the application.
        /// </summary>
        /// <returns></returns>
        private static INancyEnvironment GetDiagnosticsEnvironment()
        {
            var diagnosticsEnvironment =
                new DefaultNancyEnvironment();

            diagnosticsEnvironment.Json(retainCasing: false);

            return diagnosticsEnvironment;
        }
예제 #53
0
        private static INancyEnvironment GetTestableEnvironment(Action<INancyEnvironment> closure)
        {
            var environment =
                new DefaultNancyEnvironment();

            environment.Tracing(
                enabled: true,
                displayErrorTraces: true);

            closure.Invoke(environment);

            return environment;
        }
        public void Should_throw_configuration_exception_if_null_value_used_for_supported_culutres_passed_to_globalization_configuration()
        {
            //Given, When
            var environment = new DefaultNancyEnvironment();
            var exception = Record.Exception(() => environment.Globalization(null));

            //Then
            exception.ShouldBeOfType<ConfigurationException>();
        }
 private NancyContext CreateContextRequest(string path, IDictionary<string, IEnumerable<string>> cultureHeaders = null)
 {
     var context = new NancyContext();
     var request = new Request("GET", new Url { Path = path, Scheme = "http" }, null, cultureHeaders);
     context.Request = request;
     var environment = new DefaultNancyEnvironment();
     environment.Globalization(new[] { "en-US" }, "en-US");
     context.Environment = environment;
     return context;
 }
        public void Should_return_default_value_if_key_does_not_exist_when_invoking_trygetvalue()
        {
            // Given
            var environment = new DefaultNancyEnvironment();
            var expectedValue = new object();
            environment.AddValue("nancy", expectedValue);
            object output;

            // When
            environment.TryGetValue("foo", out output);

            // Then
            output.ShouldEqual(default(object));
        }
        private static INancyEnvironment CreateEnvironment(int numberOfElementsToAdd)
        {
            var environment = new DefaultNancyEnvironment();

            for (var value = 0; value < numberOfElementsToAdd; value++)
            {
                environment.AddValue(value.ToString(), value);
            }

            return environment;
        }
        private static INancyEnvironment GetTestableEnvironment(Action<INancyEnvironment> closure)
        {
            var environment =
                new DefaultNancyEnvironment();

            closure.Invoke(environment);

            return environment;
        }
예제 #59
0
 private NancyContext CreateContextRequest(string path, IDictionary<string, IEnumerable<string>> cultureHeaders = null)
 {
     var context = new NancyContext();
     var request = new Request("GET", new Url { Path = path, Scheme = "http" }, null, cultureHeaders);
     context.Request = request;
     var environment = new DefaultNancyEnvironment();
     environment.Cultures(GlobalizationConfiguration.Default.SupportedCultureNames);
     context.Environment = environment;
     return context;
 }
예제 #60
0
        /// <summary>
        /// Gets a special <see cref="INancyEnvironment"/> instance that is separate from the
        /// one used by the application.
        /// </summary>
        /// <returns></returns>
        private static INancyEnvironment GetDiagnosticsEnvironment()
        {
            var diagnosticsEnvironment =
                new DefaultNancyEnvironment();

            diagnosticsEnvironment.Json(retainCasing: false);
            diagnosticsEnvironment.AddValue(ViewConfiguration.Default);
            diagnosticsEnvironment.Tracing(
                enabled: true,
                displayErrorTraces: true);

            return diagnosticsEnvironment;
        }