public void CanWatchOptions() { var services = new ServiceCollection().AddOptionsMonitor(); services.AddSingleton <IConfigureOptions <FakeOptions> >(new CountIncrement(this)); var changeToken = new FakeChangeToken(); var tracker = new FakeSource(changeToken); services.AddSingleton <IOptionsChangeTokenSource <FakeOptions> >(tracker); var sp = services.BuildServiceProvider(); var monitor = sp.GetRequiredService <IOptionsMonitor <FakeOptions> >(); Assert.NotNull(monitor); Assert.Equal("1", monitor.CurrentValue.Message); string updatedMessage = null; monitor.OnChange(o => updatedMessage = o.Message); changeToken.InvokeChangeCallback(); Assert.Equal("2", updatedMessage); // Verify old watch is changed too Assert.Equal("2", monitor.CurrentValue.Message); }
public void SetUp() { _source = new FakeSource(); _column = new ColumnBuilder().Build(); _row = new RowBuilder().Build(); _filter = new FakeFilter(); _view = new FakeView(); _project = new Project() { Sources = new List <Source> { _source }, Columns = new List <Column> { _column }, Rows = new List <Row> { _row }, Filters = new List <Filter> { _filter }, Views = new List <View> { _view } }; _dataContext = new DataContext(); _dataContext.Sources.Add(_source.GetType(), _source); _dataContext.Columns.Add(_column); _dataContext.Rows.Add(_row); _dataContext.Filters.Add(_filter); _dataContext.Views.Add(_view.GetType(), _view); }
public void BuildInnerExpressionPath() { //Property to set System.Reflection.PropertyInfo prop = typeof(FakeRecipient).GetProperty("StringProperty"); //expression and binding item string expr = "Root.Value"; BindingItemExpression itembind = BindingItemExpression.Create(expr, prop); //Set the items value to be extracted as an inner property on the source PDFDataBindEventArgs args = CreateDataBindArgs(); string expected = "This is the test"; FakeSource root = new FakeSource(); root.Value = expected; args.Context.Items["Root"] = root; //bind the recipient - should have its property set to the item value FakeRecipient recip = new FakeRecipient(); itembind.BindComponent(recip, args); string actual = recip.StringProperty; Assert.AreEqual(expected, actual); }
public bool CheckLambdaExecution(ICondition condition, FakeSource source) { var lambda = condition.AsLambda(); var func = (Func <FakeSource, bool>)lambda.Compile(); return(func(source)); }
public override void Refresh() { var result = GetSource(PageSize, CurrentPage); FakeSource.Clear(); FakeSource.AddRange(result); }
public void CanWatchOptionsWithMultipleSourcesAndCallbacks() { var services = new ServiceCollection().AddOptions(); services.AddSingleton <IConfigureOptions <FakeOptions> >(new CountIncrement(this)); var changeToken = new FakeChangeToken(); var tracker = new FakeSource(changeToken); services.AddSingleton <IOptionsChangeTokenSource <FakeOptions> >(tracker); var changeToken2 = new FakeChangeToken(); var tracker2 = new FakeSource(changeToken2); services.AddSingleton <IOptionsChangeTokenSource <FakeOptions> >(tracker2); var sp = services.BuildServiceProvider(); var monitor = sp.GetRequiredService <IOptionsMonitor <FakeOptions> >(); Assert.NotNull(monitor); Assert.Equal("1", monitor.CurrentValue.Message); string updatedMessage = null; string updatedMessage2 = null; var cleanup = monitor.OnChange(o => updatedMessage = o.Message); var cleanup2 = monitor.OnChange(o => updatedMessage2 = o.Message); changeToken.InvokeChangeCallback(); Assert.Equal("2", updatedMessage); Assert.Equal("2", updatedMessage2); // Verify old watch is changed too Assert.Equal("2", monitor.CurrentValue.Message); changeToken2.InvokeChangeCallback(); Assert.Equal("3", updatedMessage); Assert.Equal("3", updatedMessage2); // Verify old watch is changed too Assert.Equal("3", monitor.CurrentValue.Message); cleanup.Dispose(); changeToken.InvokeChangeCallback(); changeToken2.InvokeChangeCallback(); // Verify only the second message changed Assert.Equal("3", updatedMessage); Assert.Equal("5", updatedMessage2); cleanup2.Dispose(); changeToken.InvokeChangeCallback(); changeToken2.InvokeChangeCallback(); // Verify no message changed Assert.Equal("3", updatedMessage); Assert.Equal("5", updatedMessage2); }
private Chunk GetChunk(int objectsQuantity) { var data = new FakeSource(objectsQuantity).GetData(); var chunk = new Chunk(_indexNameFunc(null), _typeName); chunk.AddRange(data); return(chunk); }
public void IndexData_WhenChunkProcessorWorksCorrectly_ShouldReturnZeroObjectsNotProcessed(int objectsQuantity, int chunkSize) { var data = new FakeSource(objectsQuantity).GetData().ToList(); var fakeChunkProcessor = GetChunkProcessor(chunkSize); var dataProcessor = GetDataProcessor(fakeChunkProcessor); var result = dataProcessor.IndexData(data, _indexNameFunc, _typeName); result.ObjectsProcessed.ShouldBe(objectsQuantity); result.ObjectsNotProcessed.ShouldBe(0); }
public void Get() { var source = new FakeSource(); source.Get(new PackageDependency("Foo")).Should(Be.Null); source.Add("Foo 1.2.3", "Dep > 1.0"); source.Get(new PackageDependency("Foo")).ShouldNot(Be.Null); source.Get(new PackageDependency("Foo")).Id.ShouldEqual("Foo"); source.Get(new PackageDependency("Foo")).Version.ToString().ShouldEqual("1.2.3"); source.Get(new PackageDependency("Foo")).Details.Dependencies.ToStrings().ShouldEqual(new List <string> { "Dep > 1.0" }); }
public void BuildInnerInnerKeyedExpressionPath() { //Build the object graph string expected = "This is the test"; FakeSource innerinner = new FakeSource(); innerinner.Value = expected; FakeSource inner = new FakeSource(); inner.Keys = new Dictionary <string, FakeSource>(); inner.Keys["First"] = innerinner; FakeSource root = new FakeSource(); root.Items = new List <FakeSource>(); root.Items.Add(null); root.Items.Add(inner); //expression and binding item string expr = "Root.Items[1].Keys['First'].Value"; //Property to set System.Reflection.PropertyInfo prop = typeof(FakeRecipient).GetProperty("StringProperty"); //Create the expression binding BindingItemExpression itembind = BindingItemExpression.Create(expr, prop); //Set the items value to be extracted as an inner property on the source PDFDataBindEventArgs args = CreateDataBindArgs(); //Set the root entry to the top of the object braph args.Context.Items["Root"] = root; //bind the recipient - should have its property set to the item value FakeRecipient recip = new FakeRecipient(); itembind.BindComponent(recip, args); //String Property should be set to the expected value string actual = recip.StringProperty; Assert.AreEqual(expected, actual); }
public void Index_IsProductSourceValid_ReturnsTrue() { // Arrange var fake = new FakeSource(); var items = fake.GetProducts(); var controller = new HomeController(); // Act var model = (controller.Index() as ViewResult)?.ViewData.Model as IEnumerable <Product>; // Assert Assert.Equal(items, model, GiveComparer.GetComparerObj <Product>( (a, b) => a.Name == b.Name && a.Price == b.Price )); }
public void IndexData_WhenChunkProcessorDoesNotWorksCorrectly_ShouldReturnCorrectNumberOfObjectsProcessedAndNotProcessed (int objectsQuantity, int chunkSize, int numberOfObjectsNotProcessed) { var data = new FakeSource(objectsQuantity).GetData().ToList(); var dataNotProcessed = data.Where((x, i) => i < 3).ToList(); var fakeChunkProcessor = new ChunkProcessor(new ChunkConfiguration { ChunkSize = chunkSize } , new FakeObjectsIndexer() { IndexingError = IndexingError.Unknow, ObjectsNotIndexed = dataNotProcessed } , new FakeObjectsStore() , Logger); var dataProcessor = GetDataProcessor(fakeChunkProcessor); var result = dataProcessor.IndexData(data, _indexNameFunc, _typeName); result.ObjectsProcessed.ShouldBe(objectsQuantity - numberOfObjectsNotProcessed); result.ObjectsNotProcessed.ShouldBe(numberOfObjectsNotProcessed); }
public bool CheckIsMatchExecution(ICondition condition, FakeSource source) { var castedCondition = (Condition <FakeSource>)condition; return(castedCondition.IsMatch(source)); }
public static async Task JoinInvitation([NotNull] string ip, int port, [CanBeNull] string password) { OnlineManager.EnsureInitialized(); var list = OnlineManager.Instance.List; var source = new FakeSource(ip, port); var wrapper = new OnlineSourceWrapper(list, source); ServerEntry server; using (var waiting = new WaitingDialog()) { waiting.Report(ControlsStrings.Common_Loading); await wrapper.EnsureLoadedAsync(); server = list.GetByIdOrDefault(source.Id); if (server == null) { throw new Exception(@"Unexpected"); } } if (password != null) { server.Password = password; } var content = new OnlineServer(server) { Margin = new Thickness(0, 0, 0, -38), ToolBar = { FitWidth = true }, // Values taken from ModernDialog.xaml // TODO: Extract them to some style? Title = { FontSize = 24, FontWeight = FontWeights.Light, Margin = new Thickness(6, 0, 0, 8) } }; content.Title.SetValue(TextOptions.TextFormattingModeProperty, TextFormattingMode.Ideal); var dlg = new ModernDialog { ShowTitle = false, Content = content, MinHeight = 400, MinWidth = 450, MaxHeight = 99999, MaxWidth = 700, Padding = new Thickness(0), ButtonsMargin = new Thickness(8), SizeToContent = SizeToContent.Manual, ResizeMode = ResizeMode.CanResizeWithGrip, LocationAndSizeKey = @".OnlineServerDialog" }; dlg.SetBinding(Window.TitleProperty, new Binding { Path = new PropertyPath(nameof(server.DisplayName)), Source = server }); dlg.ShowDialog(); await wrapper.ReloadAsync(true); }
public static async Task JoinInvitationNoUI([NotNull] string ip, int port, [CanBeNull] string password) { OnlineManager.EnsureInitialized(); var list = OnlineManager.Instance.List; var source = new FakeSource(ip, port); var wrapper = new OnlineSourceWrapper(list, source); var drive_opts = SettingsHolder.Drive; ServerEntry server; Logging.Write("Going through server list ..."); using (var waiting = new WaitingDialog()) { waiting.Report(ControlsStrings.Common_Loading); await wrapper.EnsureLoadedAsync(); server = list.GetByIdOrDefault(source.Id); if (server == null) { throw new Exception(@"Unexpected"); } } Logging.Write("Updating server infos ..."); await server.Update(ServerEntry.UpdateMode.Full, false, true); if (password != null) { server.Password = password; } //Change name here //We are going to use the server entry team name to match client local name. //Then we change the client online name to match the name required by the server. IReadOnlyList <ServerEntry.CurrentDriver> drivers = server.CurrentDrivers; Logging.Write("Going through all drivers ..."); if (drivers == null) { throw new Exception(@"Unexpected"); } foreach (var driver in drivers) { if (driver.Team == drive_opts.PlayerName) { drive_opts.PlayerNameOnline = driver.Name; break; } } Logging.Write("Joining server ...."); await server.JoinCommand.ExecuteAsync(null); Logging.Write("Checking booking time ..."); while (server.BookingTimeLeft > TimeSpan.Zero) { await Task.Delay(2000); } Logging.Write("Joining ..."); await server.JoinCommand.ExecuteAsync(ServerEntry.ActualJoin); await wrapper.ReloadAsync(true); }
public async Task <ArgumentHandleResult> ProgressRaceOnlineJoin(NameValueCollection p) { /* required arguments */ var ip = p.Get(@"ip"); var httpPort = FlexibleParser.TryParseInt(p.Get(@"httpPort")); var password = p.Get(@"plainPassword"); var encryptedPassword = p.Get(@"password"); if (string.IsNullOrWhiteSpace(ip)) { throw new InformativeException("IP is missing"); } if (!httpPort.HasValue) { throw new InformativeException("HTTP port is missing or is in invalid format"); } OnlineManager.EnsureInitialized(); if (string.IsNullOrWhiteSpace(password) && !string.IsNullOrWhiteSpace(encryptedPassword)) { password = OnlineServer.DecryptSharedPassword(ip, httpPort.Value, encryptedPassword); } var list = OnlineManager.Instance.List; var source = new FakeSource(ip, httpPort.Value); var wrapper = new OnlineSourceWrapper(list, source); ServerEntry server; using (var waiting = new WaitingDialog()) { waiting.Report(ControlsStrings.Common_Loading); await wrapper.EnsureLoadedAsync(); server = list.GetByIdOrDefault(source.Id); if (server == null) { throw new Exception(@"Unexpected"); } } if (password != null) { server.Password = password; } var content = new OnlineServer(server) { Margin = new Thickness(0, 0, 0, -43), ToolBar = { FitWidth = true }, // Values taken from ModernDialog.xaml // TODO: Extract them to some style? Title = { FontSize = 24, FontWeight = FontWeights.Light, Margin = new Thickness(6, 0, 0, 8) } }; content.Title.SetValue(TextOptions.TextFormattingModeProperty, TextFormattingMode.Ideal); var dlg = new ModernDialog { ShowTitle = false, Content = content, MinHeight = 400, MinWidth = 450, MaxHeight = 99999, MaxWidth = 700, Padding = new Thickness(0), ButtonsMargin = new Thickness(8), SizeToContent = SizeToContent.Manual, ResizeMode = ResizeMode.CanResizeWithGrip, LocationAndSizeKey = @".OnlineServerDialog" }; dlg.SetBinding(Window.TitleProperty, new Binding { Path = new PropertyPath(nameof(server.DisplayName)), Source = server }); dlg.ShowDialog(); await wrapper.ReloadAsync(true); return(ArgumentHandleResult.Successful); }
public void can_return_dependencies_for_package_that_has_dependencies_which_have_subdependencies_which_have_subdependencies() { /* * Package overview. * * Package1 * P1Sub * P1SubSub1 * P1SubSub2 * P1SubSubSub * * Package2 * P2Sub1 * P2Sub2 * P2Sub3 = 1.0 * P2Sub3Sub * P2Sub3SubSub ~> 1.5 * P2Sub3SubSubSub * * P2Sub3SubSub 1.5.0, 1.5.9, 1.6.0, 2.0.0 * * P2Sub3 0.9 (no deps) * P2Sub3 1.0 (has the dependencies above) */ var source = new FakeSource(); source.Add("Package1", "P1Sub"); source.Add("P1Sub", "P1SubSub1", "P1SubSub2"); source.Add("P1SubSub1"); source.Add("P1SubSub2", "P1SubSubSub"); source.Add("P1SubSubSub"); source.Add("Package2", "P2Sub1", "P2Sub2", "P2Sub3 1.0"); source.Add("P2Sub1"); source.Add("P2Sub2"); source.Add("P2Sub3 0.9"); source.Add("P2Sub3 1.0", "P2Sub3Sub"); source.Add("P2Sub3Sub", "P2Sub3SubSub ~> 1.5"); source.Add("P2Sub3SubSub 1.5.0", "P2Sub3SubSubSub"); source.Add("P2Sub3SubSub 1.5.9", "P2Sub3SubSubSub"); source.Add("P2Sub3SubSub 1.6.0"); source.Add("P2Sub3SubSub 2.0.0"); source.Add("P2Sub3SubSubSub"); var package1 = source.GetPackagesWithId("Package1").First(); var package2 = source.GetPackagesWithId("Package2").First(); // check that a few things are setup correctly ... source.Packages.First(p => p.Id == "P2Sub3Sub").Details.Dependencies.First().ToString().ShouldEqual("P2Sub3SubSub ~> 1.5"); /* get Package1's dependencies * * Package1 * P1Sub * P1SubSub1 * P1SubSub2 * P1SubSubSub */ var found = package1.FindDependencies(source); found.Count.ShouldEqual(4); found.Select(p => p.Id).ShouldContain("P1Sub"); found.Select(p => p.Id).ShouldContain("P1SubSub1"); found.Select(p => p.Id).ShouldContain("P1SubSub2"); found.Select(p => p.Id).ShouldContain("P1SubSubSub"); // get Package2's dependencies /* * Package2 * P2Sub1 * P2Sub2 * P2Sub3 = 1.0 * P2Sub3Sub * P2Sub3SubSub ~> 1.5 * P2Sub3SubSubSub */ found = package2.FindDependencies(source); found.Count.ShouldEqual(6); found.Select(p => p.IdAndVersion()).ToArray().ShouldContain("P2Sub1-1.0"); found.Select(p => p.IdAndVersion()).ToArray().ShouldContain("P2Sub2-1.0"); found.Select(p => p.IdAndVersion()).ToArray().ShouldContain("P2Sub3-1.0"); found.Select(p => p.IdAndVersion()).ToArray().ShouldContain("P2Sub3Sub-1.0"); found.Select(p => p.IdAndVersion()).ToArray().ShouldContain("P2Sub3SubSub-1.5.9"); found.Select(p => p.IdAndVersion()).ToArray().ShouldContain("P2Sub3SubSubSub-1.0"); // get Package1 and Package2's dependencies found = Source.FindDependencies(new IPackage[] { package1, package2 }, source); found.Count.ShouldEqual(10); found.Select(p => p.Id).ToArray().ShouldContain("P1Sub"); found.Select(p => p.Id).ToArray().ShouldContain("P1SubSub1"); found.Select(p => p.Id).ToArray().ShouldContain("P1SubSub2"); found.Select(p => p.Id).ToArray().ShouldContain("P1SubSubSub"); found.Select(p => p.IdAndVersion()).ToArray().ShouldContain("P2Sub1-1.0"); found.Select(p => p.IdAndVersion()).ToArray().ShouldContain("P2Sub2-1.0"); found.Select(p => p.IdAndVersion()).ToArray().ShouldContain("P2Sub3-1.0"); found.Select(p => p.IdAndVersion()).ToArray().ShouldContain("P2Sub3Sub-1.0"); found.Select(p => p.IdAndVersion()).ToArray().ShouldContain("P2Sub3SubSub-1.5.9"); found.Select(p => p.IdAndVersion()).ToArray().ShouldContain("P2Sub3SubSubSub-1.0"); // while we have all of this loaded up, let's test missing dependencies ... // let's remove P2Sub3SubSub 1.5.* so P2Sub3SubSub ~> 1.5 fails source.Packages.Where(p => p.IdAndVersion().StartsWith("P2Sub3SubSub-1.5.")).ToList().ForEach(p => source.Packages.Remove(p)); try { Source.FindDependencies(new IPackage[] { package1, package2 }, source); Assert.Fail("Expected MissingDependencyException to be thrown"); } catch (MooGet.MissingDependencyException ex) { ex.Dependencies.Count.ShouldEqual(1); ex.Dependencies.First().ToString().ShouldEqual("P2Sub3SubSub ~> 1.5"); } }