private IEnumerable<object> InsertSeparators( System.Collections.IEnumerable a, string sSeparator ) { if ( a.Cast<object> ( ).Any ( ) ) { yield return a.Cast<object> ( ).First ( ); foreach ( var o in a.Cast<object> ( ).Skip ( 1 ) ) { yield return sSeparator; yield return o; } } }
public void ShowUsingMapView() { var points = new[,] { {new Point(0, 0), new Point(1, 0), new Point(2, 0)}, {new Point(0, 1), new Point(1, 1), new Point(2, 1)}, }; var coverage = new DiscreteGridPointCoverage(2, 3, points.Cast<IPoint>()); var values = new[,] { {1.0, 2.0}, {3.0, 4.0}, {5.0, 6.0} }; coverage.SetValues(values); var coverageLayer = new DiscreteGridPointCoverageLayer {Coverage = coverage}; var map = new Map {Layers = {coverageLayer}}; MapTestHelper.ShowModal(map); }
public CommandComputer(System.Collections.IList iList) { // TODO: Complete member initialization this.clients = (List<ClientThread>)iList.Cast<ClientThread>().ToList() ; InitializeComponent(); }
public static void FillControls(Dictionary<string, string> collection, System.Windows.Forms.Control.ControlCollection controls) { foreach (Control control in controls.Cast<Control>().Where(y => y.Tag != null).OrderBy(y => y.TabIndex)) { FillControl(collection, control); } }
public void Inbox_support_queueing_multiple_queries() { var tasks = new[] { Task.Factory.StartNew(() => _inbox.Receive()), Task.Factory.StartNew(() => { Thread.Sleep(100); return _inbox.ReceiveWhere(x => x.ToString() == "world"); }), Task.Factory.StartNew(() => { Thread.Sleep(200); return _inbox.ReceiveWhere(x => x.ToString() == "hello"); }) }; _inbox.Receiver.Tell(42); _inbox.Receiver.Tell("hello"); _inbox.Receiver.Tell("world"); Task.WaitAll(tasks.Cast<Task>().ToArray()); tasks[0].Result.ShouldBe(42); tasks[1].Result.ShouldBe("world"); tasks[2].Result.ShouldBe("hello"); }
public void ShowUsingMapViewWhereValuesContainNoDataValue() { var points = new[,] { {new Point(0, 0), new Point(1, 0)}, {new Point(2, 1), new Point(3, 1.5)}, {new Point(1, 2), new Point(3, 3)} }; var coverage = new DiscreteGridPointCoverage(2, 3, points.Cast<IPoint>()); var values = new[,] { {1.0, 2.0}, {3.0, 4.0}, {5.0, -999.0} }; coverage.Components[0].NoDataValues = new [] {-999.0}; coverage.SetValues(values); var coverageLayer = new DiscreteGridPointCoverageLayer { Coverage = coverage }; var map = new Map { Layers = { coverageLayer } }; MapTestHelper.ShowModal(map); }
public void CallsMemberGenerators() { var spies = new[]{new SpyGenerator(), new SpyGenerator()}; var memberGenerators = spies.Cast<CodeGeneratorBase>().ToArray(); Generator = new NamespaceGenerator(Configuration, memberGenerators); Generator.Generate(compileUnit, ContentType); Assert.That(spies.All(s => s.Called)); }
public void WhenAnyWeightsArrayElementDoesNotPointToArray_Throw() { var array1 = new[] { 1.1, 1.2 }; ExcelFunctions.MakeArray("array1", array1.Cast<object>().ToArray()); Action action = () => ExcelFunctions.MakeWeights("weights", new object[] {"array1", "array2"}); action.ShouldThrow<NNXException>() .WithMessage("*Element at index 2 ('array2') does not point to a valid array of numbers.*"); }
public bool Write(System.Collections.Generic.IEnumerable<char> buffer) { return this.backend.Write(buffer.Cast(c => { this.OnWrite.Call(c); return c; })); }
public void SelectAllItems(System.ComponentModel.ICollectionView availableItemsCollectionView) { IList<Property> itemsList = new List<Property>(availableItemsCollectionView.Cast<Property>()); foreach (Property obj in itemsList) { SelectItem(obj); } }
public void WhenAnyWeightsArrayElementIsNotDoubleArray_Throw(object bad) { var array1 = new[] { 1.1, 1.2 }; ExcelFunctions.MakeArray("array1", array1.Cast<object>().ToArray()); ObjectStore.Add("bad", bad); Action action = () => ExcelFunctions.MakeWeights("weights", new object[] { "array1", "bad" }); action.ShouldThrow<NNXException>() .WithMessage("*Element at index 2 ('bad') does not point to a valid array of numbers.*"); }
public void ShouldReturnObjectName() { var array1 = new[] { 1.1, 1.2 }; var array2 = new[] { 2.1, 2.2, 2.3 }; ExcelFunctions.MakeArray("array1", array1.Cast<object>().ToArray()); ExcelFunctions.MakeArray("array2", array2.Cast<object>().ToArray()); var name = ExcelFunctions.MakeWeights("weights", new object[] { "array1", "array2" }); name.Should().Be("weights"); }
public override System.Web.Caching.CacheDependency GetCacheDependency(string virtualPath, System.Collections.IEnumerable virtualPathDependencies, DateTime utcStart) { if (virtualPathDependencies == null) { return Previous.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart); } return Previous.GetCacheDependency(virtualPath, virtualPathDependencies.Cast<string>().Where(vp => GetCompiledType(vp) == null), utcStart); }
public void CastCreatesNewFisherIfNoneExistsWithMatchingUserId() { var newId = "NewId"; System.Cast(newId); var newFisher = FisherData.FirstOrDefault(x => x.UserId.Equals(newId)); Assert.IsNotNull(newFisher); }
public void CastsLine() { var fisher = FisherData.First(); fisher.IsFishing = false; System.Cast(fisher.UserId); Assert.IsTrue(fisher.IsFishing); Assert.IsTrue(fisher.HookedTime >= DateTime.Now.AddSeconds(AppSettings.FishingCastMinimum)); Assert.IsTrue(fisher.HookedTime <= DateTime.Now.AddSeconds(AppSettings.FishingCastMaximum)); }
public void CastSetsHookTimeWithTournamentSettingsWhileTournamentActive() { var fisher = FisherData.First(); fisher.IsFishing = false; System.Tournament.StartTournament(); System.Cast(fisher.UserId); Assert.IsTrue(fisher.IsFishing); Assert.IsTrue(fisher.HookedTime >= DateTime.Now.AddSeconds(AppSettings.FishingTournamentCastMinimum)); Assert.IsTrue(fisher.HookedTime <= DateTime.Now.AddSeconds(AppSettings.FishingTournamentCastMaximum)); }
public void SpecificationsMatchesConstructorSpecifications() { // Fixture setup var expectedSpecifications = new[] { new DelegatingRequestSpecification(), new DelegatingRequestSpecification(), new DelegatingRequestSpecification() }; var sut = new AndRequestSpecification(expectedSpecifications.Cast<IRequestSpecification>()); // Exercise system IEnumerable<IRequestSpecification> result = sut.Specifications; // Verify outcome Assert.True(expectedSpecifications.SequenceEqual(result)); // Teardown }
public void WhenGivenArrayList_ShouldMakeWeights() { var array1 = new[] {1.1, 1.2}; var array2 = new[] {2.1, 2.2, 2.3}; ExcelFunctions.MakeArray("array1", array1.Cast<object>().ToArray()); ExcelFunctions.MakeArray("array2", array2.Cast<object>().ToArray()); ExcelFunctions.MakeWeights("weights", new object[] {"array1", "array2"}); var result = ObjectStore.Get<double[][]>("weights"); result.Should().HaveCount(2); result[0].Should().Equal(array1); result[1].Should().Equal(array2); }
public void Generate_CallsPropertyGeneratorsForAllProperties() { var spies = new[] {new SpyGenerator(), new SpyGenerator()}; var memberGenerators = spies.Cast<CodeGeneratorBase>().ToArray(); var generator = new PropertiesGenerator(null, memberGenerators); generator.Generate(type, contentType); Assert.That(spies.All(spy => spy.Called)); Assert.That( spies.All(spy => spy.CodeObjects.SequenceEqual( type.Members.OfType<CodeMemberProperty>() ) ) ); }
public void SutYieldsInjectedArray() { var expected = new[] { new Mock<IReflectionElementRefraction<object>>().Object, new Mock<IReflectionElementRefraction<object>>().Object, new Mock<IReflectionElementRefraction<object>>().Object }; var sut = new CompositeReflectionElementRefraction<object>(expected); Assert.True(expected.SequenceEqual(sut)); Assert.True( expected.Cast<object>().SequenceEqual(sut.OfType<object>())); }
public void TestMethod1() { var parameters = new[] { 2.0m, 5.0m }; var list = new List<ParameterExpression> { Expression.Parameter(typeof (decimal)), Expression.Parameter(typeof (decimal)) }; var expr = Expression.Lambda<Func<decimal, decimal, decimal>>( Expression.Multiply( list[0], list[1]), list); var result = expr.Compile().DynamicInvoke(parameters.Cast<object>().ToArray()); Assert.AreEqual(10.0m, result); }
public static Func<string, RoleEnvironmentException> BuildRoleEnvironmentExceptionCreator() { var exceptionType = typeof(RoleEnvironmentException); var constructor = exceptionType.GetConstructor( BindingFlags.NonPublic | BindingFlags.Instance, null, new[] {typeof(string)}, null); var exceptionParameters = new[] { Expression.Parameter(typeof(string), "message") }; var newExpression = Expression.New(constructor, exceptionParameters.Cast<Expression>()); return Expression .Lambda<Func<string, RoleEnvironmentException>>(newExpression, exceptionParameters) .Compile(); }
void LoadCustomConfiguration(System.Xml.XmlNodeList nodeList) { if (nodeList == null || nodeList.Count == 0) { throw new ConfigurationErrorsException("No configuration provided."); } var node = nodeList.Cast<XmlNode>().FirstOrDefault(x => x.LocalName == "file"); if (node == null) { throw new ConfigurationErrorsException("Expected 'file' element."); } var elem = node as XmlElement; var path = elem.Attributes["path"]; if (path == null || String.IsNullOrWhiteSpace(path.Value)) { throw new ConfigurationErrorsException("Expected 'path' attribute."); } this.filename = path.Value; }
public void CreateTimeDependent() { var points = new[,] { {new Point(0, 0), new Point(1, 0)}, {new Point(2, 1), new Point(3, 1.5)}, {new Point(1, 2), new Point(3, 3)} }; var coverage = new DiscreteGridPointCoverage(3, 2, points.Cast<IPoint>()) { IsTimeDependent = true }; var values = new[,] { {1.0, 2.0}, {3.0, 4.0}, {5.0, 6.0} }; var t = DateTime.Now; coverage.SetValues(values, new VariableValueFilter<DateTime>(coverage.Time, t)); values = new[,] { {10.0, 20.0}, {30.0, 40.0}, {50.0, 60.0} }; coverage.SetValues(values, new VariableValueFilter<DateTime>(coverage.Time, t.AddYears(1))); var values1 = coverage.GetValues<double>(new VariableValueFilter<DateTime>(coverage.Time, t)); values1.Should().Have.SameSequenceAs(new[] {1.0, 2.0, 3.0, 4.0, 5.0, 6.0}); var values2 = coverage.GetValues<double>(new VariableValueFilter<DateTime>(coverage.Time, t.AddYears(1))); values2.Should().Have.SameSequenceAs(new[] { 10.0, 20.0, 30.0, 40.0, 50.0, 60.0 }); }
public static Dictionary<string, string> GetAttributesCollection(System.Windows.Forms.Control.ControlCollection controls, bool validate = false) { Dictionary<string, string> collection = new Dictionary<string, string>(); foreach (Control control in controls.Cast<Control>().Where(y => y.Tag != null).OrderBy(y => y.TabIndex)) { string attribute; bool required; string defaultvalue; if (ControlUtils.GetControlDefinition(control, out attribute, out required, out defaultvalue)) { var value = ControlUtils.GetValueFromControl(control); if (required && string.IsNullOrEmpty(value)) { throw new ArgumentNullException(attribute, "Field cannot be empty"); } if (required || value != defaultvalue) { collection.Add(attribute, value); } } } return collection; }
protected override void SetMenu(System.Collections.Generic.IEnumerable<Duplicati.GUI.TrayIcon.IMenuItem> items) { m_menus = items.Cast<MenuItemWrapper>().ToList(); ResetMenus(); }
public override object CreateMultiResolutionImage(System.Collections.Generic.IEnumerable<object> images) { var refImg = (WpfImage)images.First (); var f = refImg.Frames[0]; var frames = images.Cast<WpfImage> ().Select (img => new WpfImage.ImageFrame (img.Frames[0].ImageSource, f.Width, f.Height)); return new WpfImage (frames); }
private void ApplyMove(System.Collections.IList items) { var collection = items.Cast<MoveToChalkViewModel>(); foreach (var v in collection) v.Move(); Refresh(); }
public void WhenDoubleArrayOfArraysValueIsAssigned_SetPropertyValue() { var array1 = new[] {1.1, 1.2}; var array2 = new[] {2.1, 2.2, 2.3}; ExcelFunctions.MakeArray("array1", array1.Cast<object>().ToArray()); ExcelFunctions.MakeArray("array2", array2.Cast<object>().ToArray()); ExcelFunctions.MakeWeights("array", new [] { "array1", "array2" }); _properties[0, 0] = "DoubleArrayOfArrays"; _properties[0, 1] = "array"; ExcelFunctions.MakeObject(Name, ObjectType, _properties); var result = ObjectStore.Get<MakeObjectTestType>(Name); result.DoubleArrayOfArrays.Should().NotBeNullOrEmpty(); result.DoubleArrayOfArrays.Should().HaveCount(2); result.DoubleArrayOfArrays[0].Should().Equal(array1); result.DoubleArrayOfArrays[1].Should().Equal(array2); }
public void WhenDoubleEnumerableIsAssigned_IfValueRefersToDoubleArray_ShouldSetValue() { var expected = new[] { 1.1, 1.2 }; ExcelFunctions.MakeArray("array", expected.Cast<object>().ToArray()); _properties[0, 0] = "DoubleEnumerableProperty"; _properties[0, 1] = "array"; ExcelFunctions.MakeObject(Name, ObjectType, _properties); var result = ObjectStore.Get<MakeObjectTestType>(Name); result.DoubleEnumerableProperty.Should().Equal(expected); }
private void RemoveWells(System.Collections.IList items) { var collection = items.Cast<WellViewModel>(); foreach (var v in collection) { if (allWells.ContainsKey(v.DisplayName)) { allWells.Remove(v.DisplayName); wells.Remove(v.DisplayName); } } BuildWellList(); }
private void GetHeights(System.Collections.IList items) { var collection = items.Cast<M11Branch>().SelectMany(b=>b.CrossSections).ToList(); GetHeightsOnxsec(collection); }
private void ApplyMove(System.Collections.IList tomove) { var collection = tomove.Cast<CrossSection>(); foreach (var v in collection) { if (v.DEMHeight.HasValue) { v.MaxHeightMrk1and3 = v.DEMHeight.Value; HasChanges = true; } } }