本文整理汇总了C#中Nancy.Testing.Browser类的典型用法代码示例。如果您正苦于以下问题:C# Browser类的具体用法?C# Browser怎么用?C# Browser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Browser类属于Nancy.Testing命名空间,在下文中一共展示了Browser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: when_binding_to_a_collection_with_blacklisted_property
public void when_binding_to_a_collection_with_blacklisted_property()
{
// Given
var guid = Guid.NewGuid();
string source = string.Format("{{\"SomeString\":\"some string value\",\"SomeGuid\":\"{0}\"}}", guid);
var context = new BindingContext
{
DestinationType = typeof(Stuff),
ValidModelBindingMembers = typeof(Stuff).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(propertyInfo => propertyInfo.Name != "SomeString").Select(p => new BindingMemberInfo(p)),
};
// Given
var module = new ConfigurableNancyModule(c => c.Post("/stuff", (_, m) =>
{
var stuff = m.Bind<List<Stuff>>("SomeString");
return stuff.ToJSON();
}));
var bootstrapper = new TestBootstrapper(config => config.Module(module));
// When
var browser = new Browser(bootstrapper);
var result = browser.Post("/stuff", with =>
{
with.HttpRequest();
with.JsonBody(new List<Stuff> { new Stuff(1, "one"), new Stuff(2, "two") }, new JilSerializer());
});
// Then
Assert.AreEqual("[{\"Id\":1,\"SomeString\":null},{\"Id\":2,\"SomeString\":null}]", result.Body.AsString());
}
示例2: Should_apply_default_accept_when_no_accept_header_sent
public void Should_apply_default_accept_when_no_accept_header_sent()
{
// Given
var browser = new Browser(with =>
{
with.ResponseProcessor<TestProcessor>();
with.Module(new ConfigurableNancyModule(x =>
{
x.Get("/", parameters =>
{
var context =
new NancyContext { NegotiationContext = new NegotiationContext() };
var negotiator =
new Negotiator(context);
return negotiator;
});
}));
});
// When
var response = browser.Get("/");
// Then
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
示例3: TracingSmokeTests
public TracingSmokeTests()
{
this.bootstrapper = new ConfigurableBootstrapper(
configuration => configuration.Modules(new Type[] { typeof(RazorWithTracingTestModule) }));
this.browser = new Browser(bootstrapper);
}
示例4: TestGetReturnsJsonArray
public void TestGetReturnsJsonArray()
{
// Setup
var mockBrightstar = new Mock<IBrightstarService>();
mockBrightstar.Setup(s => s.ListStores()).Returns(new[] {"store1", "store2", "store3"});
var app =
new Browser(new FakeNancyBootstrapper(mockBrightstar.Object,
new FallbackStorePermissionsProvider(StorePermissions.All, StorePermissions.All),
new FallbackSystemPermissionsProvider(SystemPermissions.All, SystemPermissions.ListStores)));
// Execute
var response = app.Get("/", c => c.Accept(MediaRange.FromString("application/json")));
// Assert
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
Assert.That(response.ContentType, Contains.Substring("application/json"));
Assert.That(response.Body, Is.Not.Null);
var responseContent = response.Body.DeserializeJson <StoresResponseModel>();
Assert.That(responseContent, Is.Not.Null);
Assert.That(responseContent.Stores, Is.Not.Null);
Assert.That(responseContent.Stores.Count, Is.EqualTo(3));
Assert.That(responseContent.Stores.Any(s => s.Equals("store1") ));
Assert.That(responseContent.Stores.Any(s => s.Equals("store2") ));
Assert.That(responseContent.Stores.Any(s => s.Equals("store3") ));
}
示例5: HomeModuleTests
public HomeModuleTests()
{
StaticConfiguration.DisableErrorTraces = false;
var bootstrapper = GetConfigurableBootstrapper();
_browser = new Browser(bootstrapper);
}
示例6: shows_how_to_add_stuff_to_the_application_startup
public void shows_how_to_add_stuff_to_the_application_startup()
{
// Arrange
// Ripped from the Nancy-testing tests
// Let's play with the date of the application
// and kick ourself off 100 years in the future
var date = new DateTime(2113, 01, 31);
var bootstrapper = new Nancy.Testing.ConfigurableBootstrapper(with =>
{
with.Module<DateModule>();
with.ApplicationStartup((container, pipelines) =>
{
// Other options are:
// pipelines.AfterRequest
// pipelines.OnError
// But for now - let's hook in before each request
pipelines.BeforeRequest += ctx =>
{
ctx.Items.Add("date", date);
return null;
};
});
});
var browser = new Browser(bootstrapper);
// Act
var response = browser.Get("/dateInTheFuture");
// Assert
Assert.Equal("The date is: 2113-01-31", response.Body.AsString());
}
示例7: Creates_user_when_valid_data_is_posted
public void Creates_user_when_valid_data_is_posted()
{
const string login = "[email protected]";
const string password = "password";
var adapter = new InMemoryAdapter();
Database.UseMockAdapter(adapter);
var browser = new Browser(BootstrapperFactory.Create());
var response = browser.Post("/admin/setup", with =>
{
with.HttpRequest();
with.FormValue("Login", login);
with.FormValue("Password", password);
});
var db = Database.Open();
var allUsers = db.Users.All().ToList();
Assert.AreEqual(1, allUsers.Count);
Assert.AreEqual(login, allUsers[0].Login);
Assert.AreEqual(password + "salt", allUsers[0].HashedPassword);
Assert.AreEqual("salt", allUsers[0].Salt);
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
}
示例8: Init
public void Init()
{
_storageEngine = new Mock<IStorageEngine>();
var bootstrapper = new OverlookBootStrapper(_storageEngine.Object);
_browser = new Browser(bootstrapper);
}
示例9: ViewBagTests
public ViewBagTests()
{
this.bootstrapper = new ConfigurableBootstrapper(
configuration => configuration.Modules(typeof(RazorTestModule)));
this.browser = new Browser(bootstrapper);
}
示例10: PostInvalidMemeTypeRequestTest
public void PostInvalidMemeTypeRequestTest(string text)
{
const string unknownResponseText = "Sorry! I don't know what that means! \n\nTo generate a meme for the current channel, type '/meme <memetype>:<meme text>' and I'll generate and insert the meme for you.\nI know about the following memes:\n - Success Kid (sk)\n - All The Things (att)\n - Dwight Schrute (dwight)\n - I Don't Always (ida)\n - Doge (doge)\n - Yoda (yoda1)\n - Thinkin' Yoda (yoda2)\n";
const string responseType = "ephemeral";
var browser = new Browser(cfg =>
{
cfg.Module<ImageModule>();
cfg.Dependency<IRootPathProvider>(new DefaultRootPathProvider());
cfg.Dependency<ICommandParser>(new CommandParser());
cfg.Dependency<IBlobStore>(new MockedImageStore("not_invalid"));
cfg.Dependency<IImageGenerator>(new ImageGenerator(new MockedImageProvider()));
});
var result = browser.Post("/image/", context =>
{
if (text != null)
context.FormValue("text", text);
});
var model = result.Body.DeserializeJson<Models.UnknownResponse>();
Assert.NotNull(model);
Assert.Equal(responseType, model.response_type);
Assert.Equal(unknownResponseText, model.text);
Assert.Null(model.attachments);
}
示例11: Should_return_info_page_if_password_empty
public async Task Should_return_info_page_if_password_empty()
{
// Given
var bootstrapper = new ConfigurableBootstrapper(with =>
{
with.Configure(env =>
{
env.Diagnostics(
enabled: true,
password: string.Empty,
cryptographyConfiguration: this.cryptoConfig);
});
with.EnableAutoRegistration();
with.Diagnostics<DefaultDiagnostics>();
});
var browser = new Browser(bootstrapper);
// When
var result = await browser.Get(DiagnosticsConfiguration.Default.Path);
// Then
Assert.True(result.Body.AsString().Contains("Diagnostics Disabled"));
}
示例12: SetUp
public void SetUp()
{
Runner.SqlCompact(ConnectionString).Down();
Runner.SqlCompact(ConnectionString).Up();
_server = new Server(64978);
_browser = new Browser(new LemonadeBootstrapper(), context => context.UserHostAddress("localhost"));
}
示例13: TestFixtureSetup
public void TestFixtureSetup()
{
_browser = new Browser(cfg =>
{
cfg.Module<SiteModule>();
});
}
示例14: SetUp
public void SetUp()
{
_fakeShortener = new FakeShortener();
_bootstrapper = new ConfigurableBootstrapper(with => with.Dependency(_fakeShortener));
_browser = new Browser(_bootstrapper);
}
示例15: PartialViewTests
public PartialViewTests()
{
this.bootstrapper = new ConfigurableBootstrapper(
configuration => configuration.Modules(new [] { typeof(RazorTestModule) }));
this.browser = new Browser(bootstrapper);
}