public void Given_a_timed_out_instance_When_sending_messages_to_it_Then_messages_are_forwarded_to_deadLetter() { var deadLetterActor = A.Fake <ActorRef>(); var testBootstrapper = new TestBootstrapper() { DeadLetterActorCreator = (path, system) => deadLetterActor }; var actorSystem = testBootstrapper.CreateSystem(); var promiseActorRef = PromiseActorRef.Create(actorSystem, 10, "target"); try{ promiseActorRef.Future.Wait(); } catch (Exception) {} var fakeSender = A.Fake <ActorRef>(); var message1 = new object(); var message2 = new object(); promiseActorRef.Send(message1, fakeSender); promiseActorRef.Send(message2, fakeSender); A.CallTo(() => deadLetterActor.Send(message1, fakeSender)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => deadLetterActor.Send(message2, fakeSender)).MustHaveHappened(Repeated.Exactly.Once); }
public void ShouldBeAbleTo_ShowClick() { var interpreter = TestBootstrapper.Setup( @" Discriminator, What Show, Click Button1"); Should.Be <SuccessAnswer>(interpreter.Please($"gotourl file:///{_file}")); var answer = interpreter.Please(App.Interpreter.RUN_NEXT_ITEM_IN_PLAN); Should.Be <SuccessAnswer>(answer); Thread.Sleep(2000); Assert.IsTrue(answer.Children.First() is OverlayAnswer); Assert.AreEqual(46, (answer.Children.First() as OverlayAnswer).Artifacts.First().Rectangle.Width); Assert.AreEqual(16, (answer.Children.First() as OverlayAnswer).Artifacts.First().Rectangle.X); //Assert.IsTrue(ServiceLocator.Instance.Resolve<IAnnotationOverlay>().IsShowing); //Assert.IsFalse(ServiceLocator.Instance.Resolve<IAnnotationOverlay>().Form.IsDisposed); Should.Be <SuccessAnswer>(interpreter.Please($"gotourl http://www.google.com")); Thread.Sleep(2000); Should.Be <SuccessAnswer>(interpreter.Please($"gotourl file:///{_file}")); Thread.Sleep(2000); //Assert.IsFalse(ServiceLocator.Instance.Resolve<IAnnotationOverlay>().IsShowing); //Assert.IsNull(ServiceLocator.Instance.Resolve<IAnnotationOverlay>().Form); answer = interpreter.Please("show click Button1"); Assert.IsTrue(answer.Children.First() is OverlayAnswer); Assert.AreEqual(46, (answer.Children.First() as OverlayAnswer).Artifacts.First().Rectangle.Width); Assert.AreEqual(16, (answer.Children.First() as OverlayAnswer).Artifacts.First().Rectangle.X); Thread.Sleep(4000); Assert.IsTrue(ServiceLocator.Instance.Resolve <IAnnotationOverlay>().IsShowing); }
public async Task ListFilesInSingleRequest() { var httpClient = Substitute.For <IHttpClientHelper>(); var container = TestBootstrapper.Init(httpClient); var dropboxResponse = new DropboxApiResponseListFiles { entries = new[] { new Entry { name = "Item 1" } } }; httpClient.PostAsync(new Uri("https://api.dropboxapi.com/2/files/list_folder"), @"{""path"":"""", ""recursive"": true}", Arg.Any <string>(), Arg.Any <CancellationToken>()) .Returns(Task.FromResult(JsonConvert.SerializeObject(dropboxResponse))); var sut = container.Resolve <IDropboxHelper>(); var files = await sut.GetFilesAsync("", CancellationToken.None); Assert.NotEmpty(files); Assert.Equal(1, files.Count); Assert.Equal("Item 1", files[0].Name); }
public void Get_search_should_return_empty_view() { //arrange var twitterApi = A.Fake <ITwitterPublicClient>(); var bootstrapper = new TestBootstrapper( with => { with.Module <SearchModule>(); with.Dependency(twitterApi); }); var browser = new Browser(bootstrapper); //act var response = browser.Get("/search"); //assert response.StatusCode.Should().Be(HttpStatusCode.OK); var viewModel = response.GetModel <SearchViewModel>(); viewModel.Query.Should().NotBeNull(); viewModel.Query.ShouldBeEquivalentTo(new SearchQuery()); viewModel.Result.Should().BeNull(); response.GetViewName().Should().Be("Search"); }
public async void Should_Bind_To_A_Class() { var module = new ConfigurableNancyModule(c => c.Post("/stuff", (_, m) => { var stuff = m.Bind <TestUser>(); return(stuff.Id.ToString()); })); var bootstrapper = new TestBootstrapper(config => config.Module(module)); var user = new TestUser { Age = 31, Id = Guid.NewGuid(), Name = "Deniz" }; #if NETCORE var browser = new Browser(bootstrapper); var browserResponse = await browser.Post("/stuff", context => { context.HttpRequest(); context.HyperionBody(user); }); #else var browser = new Browser(bootstrapper); var browserResponse = browser.Post("/stuff", context => { context.HttpRequest(); context.HyperionBody(user); }); #endif Assert.Equal(user.Id.ToString(), browserResponse.Body.AsString()); }
public void Authenticated_Get_should_return_Status_View() { //arrange var twitterApi = A.Fake <ITwitterAuthenticatedClient>(); var twitterUserTracker = A.Fake <ITwitterUserTracker>(); const long TwitterUserId = 123L; var twitterUser = new TwitterUser(TwitterUserId); var bootstrapper = new TestBootstrapper( with => { with.Module <TweetModule>(); with.Dependency <ITwitterUserTracker>(twitterUserTracker); with.RequestStartup( (_, __, context) => { context.CurrentUser = twitterUser; }); }); var browser = new Browser(bootstrapper); //act var response = browser.Get("/tweet"); //assert response.StatusCode.Should().Be(HttpStatusCode.OK); response.GetViewName().Should().Be("Status"); }
public void Get_Auth_Sign_In_Populates_Twitter_Auth_Link() { //arrange var twitterApi = A.Fake <ITwitterAuthenticatedClient>(); var callBackUrl = new Uri("http://api.faketwitter.com/?foo=bar"); A.CallTo(() => twitterApi.GetAuthorizationUri(A <string> ._)).Returns(callBackUrl); var twitterUserTracker = new TwitterUserTracker(); var bootstrapper = new TestBootstrapper( with => { with.Module <AuthModule>(); with.Dependency <ITwitterAuthenticatedClient>(twitterApi); with.Dependency <ITwitterUserTracker>(twitterUserTracker); }); var browser = new Browser(bootstrapper); //act var response = browser.Get("/auth/signin"); //assert response.StatusCode.Should().Be(HttpStatusCode.OK); response.GetViewName().Should().Be("SignIn"); var authUrl = (Uri)(response.Context.ViewBag.AuthUrl); authUrl.ShouldBeEquivalentTo(callBackUrl); }
public void When_timing_out_Then_AskTimeoutException_is_thrown() { var actorSystem = new TestBootstrapper().CreateSystem(); var promiseActorRef = PromiseActorRef.Create(actorSystem, 10, "target"); Assert.Throws <AggregateException>(() => promiseActorRef.Future.Wait()).ContainsException <AskTimeoutException>().Should().BeTrue(); }
public void ClientControllerTestStart() { IUnityContainer container = TestBootstrapper.Initialise(); this.ProjectService = container.Resolve <IProjectService>(); this.controller = new ProjectController(this.ProjectService); }
public async void PetAbility_Is_Parsed_Correctly(int id, string name, string petAbilityType, int petAbilityId, int rounds, int cooldown) { // arrange var testBootstrapper = new TestBootstrapper(); var mockBlizzardApiHelper = new MockBlizzardApiHelper(); mockBlizzardApiHelper.SetupPetAbilityMock(testBootstrapper); mockBlizzardApiHelper.SetupBlizzardIMSMock(testBootstrapper); var mediator = testBootstrapper.ServiceProvider.GetRequiredService <IMediator>(); // act var result = await mediator.Send(new GetPetAbilityRequest { Id = id }); // assert using (new AssertionScope()) { result.Should().NotBeNull(); result.Name.Should().Be(name); result.PetAbilityType.Should().Be(petAbilityType); result.PetAbilityTypeId.Should().Be(petAbilityId); result.Rounds.Should().Be(rounds); result.Cooldown.Should().Be(cooldown); } }
public void GetEngine_ReturnsEngine() { var bootstrapper = new TestBootstrapper(); bootstrapper.Initialise(); var engine = bootstrapper.GetEngine(); Assert.NotNull(engine); }
public async Task ProductCategoriesWorkflow() { using var client = await TestBootstrapper.CreateTestClientWithInMemoryDb(); await TestRecordsCreator.CreateCategoryAsync(client, "stocks/Germany/Dax 30"); var getCategoriesResponse = await client.GetAsync("/api/product-categories"); var categories = (await getCategoriesResponse.Content.ReadAsStringAsync()) .DeserializeJson <GetProductCategoriesResponse>().ProductCategories; Assert.Equal(3, categories.Count); Assert.True(categories.First(c => c.Id == "stocks.germany.dax_30").IsLeaf); Assert.False(categories.First(c => c.Id == "stocks.germany").IsLeaf); Assert.False(categories.First(c => c.Id == "stocks").IsLeaf); var deleteRequest = new DeleteProductCategoryRequest() { UserName = "******", }; var leafCategoryId = "stocks.germany.dax_30"; await client.DeleteAsJsonAsync($"/api/product-categories/{leafCategoryId}", deleteRequest); getCategoriesResponse = await client.GetAsync("/api/product-categories"); categories = (await getCategoriesResponse.Content.ReadAsStringAsync()) .DeserializeJson <GetProductCategoriesResponse>().ProductCategories; Assert.Equal(2, categories.Count); Assert.True(categories.First(c => c.Id == "stocks.germany").IsLeaf); Assert.False(categories.First(c => c.Id == "stocks").IsLeaf); }
public CachingProxyV3NancyModuleTest() { metaCacheProvider = new Mock <IPackageMetadataCache>(MockBehavior.Strict); client = new Mock <IHttpClient>(MockBehavior.Strict); originalResponse = new HttpResponseMessage(System.Net.HttpStatusCode.OK) { Content = new ByteArrayContent(Encoding.UTF8.GetBytes(originalResponseContent)) }; originalResponse.Content.Headers.Add("Content-Type", "application/json"); client.Setup(c => c.SendAsync(It.IsAny <HttpRequestMessage>())) .ReturnsAsync(originalResponse); interceptor = new GenericV3JsonInterceptor(); replacementsProvider = new Mock <IUrlReplacementsProvider>(MockBehavior.Strict); replacementsProvider.Setup(p => p.GetReplacements(It.IsAny <string>())).Returns(new Dictionary <string, string>()); cacheProvider = new Mock <INupkgCacheProvider>(MockBehavior.Strict); tx = new Mock <INupkgCacheTransaction>(MockBehavior.Strict); cacheProvider.Setup(c => c.OpenTransaction()).Returns(tx.Object); tx.Setup(t => t.TryGet(It.IsAny <string>(), It.IsAny <string>())).Returns(null as byte[]); tx.Setup(t => t.Dispose()); tx.Setup(t => t.Insert(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <byte[]>())); var bootstrapper = new TestBootstrapper(typeof(CachingProxyV3NancyModule), b => { b.RegisterInstance(client.Object).As <IHttpClient>(); b.RegisterInstance(interceptor).As <IV3JsonInterceptor>(); b.RegisterInstance(replacementsProvider.Object).As <IUrlReplacementsProvider>(); b.RegisterInstance(cacheProvider.Object).As <INupkgCacheProvider>(); b.RegisterInstance(metaCacheProvider.Object).As <IPackageMetadataCache>(); }); this.browser = new Browser(bootstrapper, ctx => { ctx.HostName("testhost"); }); }
static void Main(string[] args) { string s = "http://cn.bing.com/search?q=MD5CryptoServiceProvider+slow&qs=n&pq=md5cryptoserviceprovider+slow&sc=0-25&sp=-1&sk=&cvid=67d40cbd8c424d55a3db83e6e9868267&first=51&FORM=PERE4"; using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider()) { byte[] inBytes = Encoding.UTF8.GetBytes(s); var bytes = md5.ComputeHash(inBytes); Console.WriteLine(bytes.Length); } var splitter = new TransformBlock <string, KeyValuePair <string, int> >( input => { var splitted = input.Split('='); return(new KeyValuePair <string, int>(splitted[0], int.Parse(splitted[1]))); }); var dict = new Dictionary <string, int>(); var aggregater = new ActionBlock <KeyValuePair <string, int> >( pair => { int oldValue; dict[pair.Key] = dict.TryGetValue(pair.Key, out oldValue) ? oldValue + pair.Value : pair.Value; }); splitter.LinkTo(aggregater, new DataflowLinkOptions() { PropagateCompletion = true }); splitter.Post("a=1"); splitter.Post("b=2"); splitter.Post("a=5"); splitter.Complete(); aggregater.Completion.Wait(); Console.WriteLine("sum(a) = {0}", dict["a"]); //prints sum(a) = 6 string containerName = "dataflowex-demo-" + Guid.NewGuid(); TestBootstrapper.BootSqlServerWithDockerCli(null, containerName); //CalcAsync().Wait(); //SlowFlowAsync().Wait(); //FailDemoAsync().Wait(); //TransformAndLinkDemo().Wait(); //LinkLeftToDemo().Wait(); //CircularFlowAutoComplete().Wait(); //RecorderDemo().Wait(); BulkInserterDemo().Wait(); //BulkInserterDemo2().Wait(); //BroadcasterDemo().Wait(); //MyLoggerDemo().Wait(); //ETLLookupDemo().Wait(); TestBootstrapper.ShutdownSqlServerWithDockerCli(false, containerName); // leave the container so that we can check result manually through ssms. }
public async Task MigrateAsync() { var container = TestBootstrapper.Init(); var destRepo = container.ResolveNamed <IBlogPostRepository>("SqlServer") as BlogPostSqlServerRepository; await destRepo.UpdateDatabaseAsync(CancellationToken.None); }
public NavigationFlyoutViewModelTest() { TestBootstrapper bootstrapper = new TestBootstrapper(); bootstrapper.Run(); vm = new NavigationFlyoutViewModel(); }
public SettingsSolidViewModelTest() { TestBootstrapper bootstrapper = new TestBootstrapper(); bootstrapper.Run(); vm = new SettingsSolidViewModel(); }
public void GetModule_ReturnsModule() { var bootstrapper = new TestBootstrapper(); bootstrapper.Initialise(); bootstrapper.GetEngine(); INancyModule module = bootstrapper.GetModule(typeof(SampleModule), new NancyContext()); Assert.IsType(typeof(SampleModule), module); }
public void Initialize() { TestBootstrapper.TestServiceStructureMap(); AutoMapperInit.BuildMap(); userService = ObjectFactory.GetInstance <IUserService>(); userController = new UserController(userService); MockControllerHelpers.RegisterTestRoutes(); }
public void Initialize() { TestBootstrapper.TestServiceStructureMap(); AutoMapperInit.BuildMap(); domainService = ObjectFactory.GetInstance <IUserService>(); domainService.UserRepository = ObjectFactory.GetInstance <IUserRepository>(); domainService.UnitOfWork = ObjectFactory.GetInstance <IUnitOfWork>(); }
public SettingsThumbnailViewModelTest() { TestBootstrapper bootstrapper = new TestBootstrapper(); bootstrapper.Run(); vm = new SettingsThumbnailViewModel(); }
public SettingsAttributesViewModelTest() { TestBootstrapper bootstrapper = new TestBootstrapper(); bootstrapper.Run(); vm = new SettingsAttributesViewModel(); }
public HomeTilesViewModelTest() { TestBootstrapper bootstrapper = new TestBootstrapper(); bootstrapper.Run(); vm = new HomeTilesViewModel(); }
public void Bootstrapper_End() { var sut = new TestBootstrapper(); sut.SetContainer(mockContainerProvider.Object); sut.End(); }
public void GetAllModules_ReturnsModules() { var bootstrapper = new TestBootstrapper(); bootstrapper.Initialise(); bootstrapper.GetEngine(); var modules = bootstrapper.GetAllModules(new NancyContext()); Assert.True(modules.Any()); }
public LeftTitlebarCommandsViewModelTest() { TestBootstrapper bootstrapper = new TestBootstrapper(); bootstrapper.Run(); vm = new LeftTitlebarCommandsViewModel(); }
public ChangelogListViewModelTest() { TestBootstrapper bootstrapper = new TestBootstrapper(); bootstrapper.Run(); vm = new ChangelogListViewModel(); }
public void SetUp() { _server = new Server(64978); Runner.SqlCompact(ConnectionString).Down(); Runner.SqlCompact(ConnectionString).Up(); _bootstrapper = new TestBootstrapper(); _browser = new Browser(_bootstrapper, context => context.UserHostAddress("TEST")); }
public void Should_Register_Output_View_Model_In_Container() { // Given, When var scanner = new Mock <ITailProviderScannerService>().Object; var bootstrapper = new TestBootstrapper(scanner); // Then Assert.True(bootstrapper.HasBinding <StreamViewModel>()); }
public void Runs() { var config = new MDKFactory.ProgramConfig { GridTerminalSystem = Mock.Of <IMyGridTerminalSystem>(), }; TestBootstrapper.Run(config); }
public void UpdateImagePathsTests(string source, string imageFolder, string expectedResult) { var container = TestBootstrapper.Init(); var renderer = container.Resolve <IBlogPostRenderer>() as BlogPostMarkdownRenderer; var result = renderer?.UpdateImagePaths(source, imageFolder); Assert.Equal(expectedResult, result); }
public void Should_Register_Tail_Service_In_Container() { // Given, When var scanner = new Mock <ITailProviderScannerService>().Object; var bootstrapper = new TestBootstrapper(scanner); // Then Assert.True(bootstrapper.HasBinding <ITailListenerService>()); }
public async Task ListFilesOverMultipleRequests() { var httpClient = Substitute.For <IHttpClientHelper>(); var container = TestBootstrapper.Init(httpClient); var dropboxResponse = new DropboxApiResponseListFiles { has_more = true, cursor = "mycursor", entries = new[] { new Entry { name = "Item 1" }, new Entry { name = "Item 2" }, new Entry { name = "Item 3" }, } }; var dropboxResponse2 = new DropboxApiResponseListFiles { has_more = false, cursor = "", entries = new[] { new Entry { name = "Item 4" }, new Entry { name = "Item 5" }, } }; httpClient.PostAsync(new Uri("https://api.dropboxapi.com/2/files/list_folder"), @"{""path"":"""", ""recursive"": true}", Arg.Any <string>(), Arg.Any <CancellationToken>()) .Returns(Task.FromResult(JsonConvert.SerializeObject(dropboxResponse))); httpClient.PostAsync(new Uri("https://api.dropboxapi.com/2/files/list_folder/continue"), @"{""cursor"": ""mycursor""}", Arg.Any <string>(), Arg.Any <CancellationToken>()) .Returns(Task.FromResult(JsonConvert.SerializeObject(dropboxResponse2))); var sut = container.Resolve <IDropboxHelper>(); var files = await sut.GetFilesAsync("", CancellationToken.None); Assert.NotEmpty(files); Assert.Equal(5, files.Count); Assert.Equal("Item 1", files[0].Name); Assert.Equal("Item 2", files[1].Name); Assert.Equal("Item 3", files[2].Name); Assert.Equal("Item 4", files[3].Name); Assert.Equal("Item 5", files[4].Name); }
public void Should_UseVariableInFill() { var interpreter = TestBootstrapper.Setup(); Should.Be <SuccessAnswer>(interpreter.Please($"gotourl file:///{_file}")); Should.Be <SuccessAnswer>(interpreter.Please("remember textFieldName 'TextArea1'")); Should.Be <SuccessAnswer>(interpreter.Please("fill [textFieldName] with SampleText")); Should.Have("SampleText").InFieldWithId("IdTextArea1"); }
public void GetModule_DisposableTransientDependency_ReturnsModule() { var bootstrapper = new TestBootstrapper(); bootstrapper.Initialise(); bootstrapper.GetEngine(); var module = (SampleModuleWithDisposableTransientDependency)bootstrapper.GetModule( typeof(SampleModuleWithDisposableTransientDependency), new NancyContext()); Assert.IsType(typeof(DisposableTransient), module.Transient); }
public void GetModule_PerRequestDependency_ReturnsModule() { var bootstrapper = new TestBootstrapper(); bootstrapper.Initialise(); bootstrapper.GetEngine(); var module = (SampleModuleWithPerRequestDependency)bootstrapper.GetModule( typeof(SampleModuleWithPerRequestDependency), new NancyContext()); Assert.IsType(typeof(PerRequest), module.PerRequest); }
public void SetUp() { _createApplication = new CreateApplicationFake(); _getApplication = new GetApplicationByName(); _getFeature = new GetFeatureByNameAndApplication(); _server = new Server(64978); _testBootstrapper = new TestBootstrapper(); _browser = new Browser(_testBootstrapper, context => context.UserHostAddress("localhost")); Runner.SqlCompact(ConnectionString).Down(); Runner.SqlCompact(ConnectionString).Up(); }
public LoginFixture() { var bootstrapper = new TestBootstrapper(); this.browser = new Browser(bootstrapper); }
public void Ping_ShouldInvokeRequestStartup() { var bootstrapper = new TestBootstrapper(); var browser = new Browser(bootstrapper); var response = browser.Get("/ping"); Assert.True(response.StatusCode == HttpStatusCode.OK); }
public void GetModule_WithNancyContextDependency_ReturnsModuleWithDependency() { var bootstrapper = new TestBootstrapper(); var browser = new Browser(bootstrapper); browser.Get("/"); }
private static TestBootstrapper CreateBootstrapper() { var bootstrapper = new TestBootstrapper(); bootstrapper.Initialise(); bootstrapper.GetEngine(); return bootstrapper; }
public void GetEngine_RegistersRequestStartup() { var bootstrapper = new TestBootstrapper(); bootstrapper.Initialise(); var engine = bootstrapper.GetEngine(); engine.HandleRequest(new Request("Post", "Sample", "http")); }
public DefaultNancyBootstrapperModuleCatalogFixture() { this.bootstrapper = new TestBootstrapper(this.ModuleTypesToRegister); this.bootstrapper.Initialise(); }