public void FeatureSerialization()
        {
            var coordinates = new[]
            {
                new List<IPosition>
                {
                    new GeographicPosition(52.370725881211314, 4.889259338378906),
                    new GeographicPosition(52.3711451105601, 4.895267486572266),
                    new GeographicPosition(52.36931095278263, 4.892091751098633),
                    new GeographicPosition(52.370725881211314, 4.889259338378906)
                },
                new List<IPosition>
                {
                    new GeographicPosition(52.370725881211314, 4.989259338378906),
                    new GeographicPosition(52.3711451105601, 4.995267486572266),
                    new GeographicPosition(52.36931095278263, 4.992091751098633),
                    new GeographicPosition(52.370725881211314, 4.989259338378906)
                },
            };

            var settings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() };
            IGeometryObject geometry;

            geometry = new LineString(coordinates[0]);
            JsonAssert.AssertCoordinates(JsonConvert.SerializeObject(new Feature.Feature(geometry), DefaultJsonSerializerSettings), 1, coordinates[0]);

            geometry = new Point(coordinates[0][0]);
            JsonAssert.AssertCoordinates(JsonConvert.SerializeObject(new Feature.Feature(geometry), DefaultJsonSerializerSettings), 0, coordinates[0].Take(1).ToArray());

            geometry = new MultiLineString(coordinates.Select(ca => new LineString(ca)).ToList());
            JsonAssert.AssertCoordinates(JsonConvert.SerializeObject(new Feature.Feature(geometry), DefaultJsonSerializerSettings), 2, coordinates);

            geometry = new Polygon(coordinates.Select(ca => new LineString(ca)).ToList());
            JsonAssert.AssertCoordinates(JsonConvert.SerializeObject(new Feature.Feature(geometry), DefaultJsonSerializerSettings), 2, coordinates);
        }
        public static IEnumerable<object[]> GetReadStreamTheories()
        {
            var theories = new[]
            {
                new ReadStreamTheory("stream-1", StreamPosition.Start, ReadDirection.Forward, 2, 
                    new StreamEventsPage("stream-1", PageReadStatus.Success, 0, 2, 2, ReadDirection.Forward, false,
                          ExpectedStreamEvent("stream-1", 1, 0, SystemClock.GetUtcNow().UtcDateTime),
                          ExpectedStreamEvent("stream-1", 2, 1, SystemClock.GetUtcNow().UtcDateTime))),

                new ReadStreamTheory("not-exist", 1, ReadDirection.Forward, 2, 
                    new StreamEventsPage("not-exist", PageReadStatus.StreamNotFound, 1, -1, -1, ReadDirection.Forward, true)),

                new ReadStreamTheory("stream-2", 1, ReadDirection.Forward, 2, 
                    new StreamEventsPage("stream-2", PageReadStatus.Success, 1, 3, 2, ReadDirection.Forward, true,
                          ExpectedStreamEvent("stream-2", 5, 1, SystemClock.GetUtcNow().UtcDateTime),
                          ExpectedStreamEvent("stream-2", 6, 2, SystemClock.GetUtcNow().UtcDateTime))),

                new ReadStreamTheory("stream-1", StreamPosition.End, ReadDirection.Backward, 2, 
                    new StreamEventsPage("stream-1", PageReadStatus.Success, -1, 0, 2, ReadDirection.Backward, false,
                          ExpectedStreamEvent("stream-1", 3, 2, SystemClock.GetUtcNow().UtcDateTime),
                          ExpectedStreamEvent("stream-1", 2, 1, SystemClock.GetUtcNow().UtcDateTime))),

                 new ReadStreamTheory("stream-1", StreamPosition.End, ReadDirection.Backward, 4, 
                    new StreamEventsPage("stream-1", PageReadStatus.Success, -1, -1, 2, ReadDirection.Backward, true,
                          ExpectedStreamEvent("stream-1", 3, 2, SystemClock.GetUtcNow().UtcDateTime),
                          ExpectedStreamEvent("stream-1", 2, 1, SystemClock.GetUtcNow().UtcDateTime),
                          ExpectedStreamEvent("stream-1", 1, 0, SystemClock.GetUtcNow().UtcDateTime)))
            };

            return theories.Select(t => new object[] { t });
        }
        public static void NURBS1()
        {
            // Draw a simple NURBS
            // Example from this page:http://www.robthebloke.org/opengl_programming.html

            var page = SampleEnvironment.Application.ActiveDocument.Pages.Add();

            var points = new[]
                             {
                                 new VA.Drawing.Point(10, 10),
                                 new VA.Drawing.Point(5, 10),
                                 new VA.Drawing.Point(-5, 5),
                                 new VA.Drawing.Point(-10, 5),
                                 new VA.Drawing.Point(-4, 10),
                                 new VA.Drawing.Point(-4, 5),
                                 new VA.Drawing.Point(-8, 1)
                             };

            var origin = new VA.Drawing.Point(4, 4);
            var scale = new VA.Drawing.Size(1.0/4.0, 1.0/4.0);

            var controlpoints = points.Select(x => (x*scale) + origin).ToList();
            var knots = new double[] {0, 0, 0, 0, 1, 2, 3, 4, 4, 4, 4};
            var degree = 3;
            var weights = controlpoints.Select(i => 1.0).ToList();

            var s0 = page.DrawNURBS(controlpoints, knots, weights, degree);
            s0.Text = "Generic NURBS shape";
        }
        public void TestIsAHuman()
        {
            // Arrange
            var verifier = new UserAgentVerifier();
            var userAgents = new[]
            {
                // IE
                "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko",

                // Chrome
                "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36",

                // Firefox
                "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0",

                // Safari
                "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2",

                // Opera
                "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.132 Safari/537.36 OPR/21.0.1432.57 (Edition Campaign 51)", // opera

                // Yandex.Browser
                "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.5 (KHTML, like Gecko) YaBrowser/1.0.1084.5402 Chrome/19.0.1084.5402 Safari/536.5",
                "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.5 (KHTML, like Gecko) YaBrowser/1.0.1084.5402 Chrome/19.0.1084.5402 Safari/536.5",
                "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) YaBrowser/1.0.1084.5402 Chrome/19.0.1084.5402 Safari/536.5",
                "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.12785 YaBrowser/13.12.1599.12785 Safari/537.36"
            };

            // Act
            IEnumerable<bool> results = userAgents.Select(verifier.IsBot);

            // Assert
            Assert.True(results.All(r => !r));
        }
Example #5
0
	IEnumerable<ushort> Test ()
	{
		string[] s = new[] { "a", "b", "c" };

		var m = s.Select (l => ctx.Foo (l)).ToArray ();

		yield break;
	}
        public void ComplexValueTest()
        {
            EdmModel model = new EdmModel();

            var emptyComplexType = new EdmComplexType(DefaultNamespaceName, "EmptyComplexType");
            model.AddElement(emptyComplexType);

            var complexTypeWithStringProperty = new EdmComplexType(DefaultNamespaceName, "ComplexTypeWithStringProperty");
            complexTypeWithStringProperty.AddStructuralProperty("stringProperty", EdmCoreModel.Instance.GetString(isNullable: true));
            complexTypeWithStringProperty.AddStructuralProperty("numberProperty", EdmCoreModel.Instance.GetInt32(isNullable: false));
            model.AddElement(complexTypeWithStringProperty);

            model.Fixup();
            

            IEnumerable<PayloadReaderTestDescriptor> testDescriptors = new[]
            {
                // Empty element is a valid complex value
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.ComplexValue("TestModel.EmptyComplexType")
                        .XmlValueRepresentation(new XNode[0])
                        .WithTypeAnnotation(emptyComplexType),
                    PayloadEdmModel = model
                },
            };

            testDescriptors = testDescriptors.Concat(
                PropertiesElementAtomValues.CreatePropertiesElementPaddingPayloads<ComplexInstance>(
                    new PayloadReaderTestDescriptor(this.Settings)
                    {
                        PayloadElement = PayloadBuilder.ComplexValue("TestModel.ComplexTypeWithStringProperty")
                            .WithTypeAnnotation(complexTypeWithStringProperty),
                        PayloadEdmModel = model
                    },
                    (complexInstance, xmlValue) => complexInstance.XmlValueRepresentation(xmlValue)));

            testDescriptors = testDescriptors.Select(td => td.InProperty());

            testDescriptors = testDescriptors.Concat(new []
            {
                // Top-level property without expected type and no type name - this is read as primitive string!
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.Property(null, PayloadBuilder.PrimitiveValue(string.Empty))
                        .XmlRepresentation("<m:value/>"),
                    PayloadEdmModel = model,
                },
            });

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.AtomFormatConfigurations,
                (testDescriptor, testConfiguration) =>
                {
                    testDescriptor.RunTest(testConfiguration);
                });
        }
Example #7
0
        public void PickNone()
        {
            var solver = new UnboundedDPKnapsackSolver();
            IEnumerable<int> seq = new[] { 10, 20, 30, };
            IEnumerable<IItem> items = seq.Select(item => new IntItem(item));
            IEnumerable<IItem> knapsack = solver.Solve(items, 0);

            Assert.AreEqual(0, knapsack.Count());
        }
Example #8
0
        public void PickMany()
        {
            var solver = new UnboundedDPKnapsackSolver();
            IEnumerable<int> seq = new[] { 1, 2, 3, 4, 5 };
            IEnumerable<IItem> items = seq.Select(item => new IntItem(item));
            IEnumerable<IItem> knapsack = solver.Solve(items, 10);

            Assert.AreEqual(10, knapsack.Sum(item => item.Value));
            Assert.AreEqual(10, knapsack.Sum(item => item.Weight));
        }
Example #9
0
 public void DontCompleteOne()
 {
     var taskCompletionSources = new []
                                 {
                                     new TaskCompletionSource<int>(), 
                                     new TaskCompletionSource<int>()
                                 };
     var whenAllTask = TaskUtils.WhenAll(taskCompletionSources.Select(tcs => tcs.Task));
     taskCompletionSources[0].SetResult(1);
     Assert.IsFalse(whenAllTask.IsCompleted);
 }
Example #10
0
        public void returns_enumerable_of_different_type()
        {
            List<string> names = new[] {"Luke", "Yoda", "Anakin"}.ToList();

            IEnumerable<Jedi> jedi = names.Select(n => new Jedi(n));

            jedi.Count().ShouldBe(3);
            jedi.ElementAt(0).Name.ShouldBe("Luke");
            jedi.ElementAt(1).Name.ShouldBe("Yoda");
            jedi.ElementAt(2).Name.ShouldBe("Anakin");
        }
        public void SoundsLike_SearchMultipleWords_ReturnsAllMatchingRecords()
        {
            //Arrange
            var names = new[] {"Robert", "Mitt"};
            var soundexCodes = names.Select(w => w.ToSoundex());
            var expected = _testData.Where(td => soundexCodes.Contains(td.Name.ToSoundex()));

            //Act
            var result = _testData.Search(x => x.Name).Soundex("Robert", "Mitt");

            //Assert
            CollectionAssert.AreEqual(expected, result);
        }
Example #12
0
 public async Task NonGenericVersion()
 {
     var taskCompletionSources = new []
                                 {
                                     new TaskCompletionSource<int>(), 
                                     new TaskCompletionSource<int>()
                                 };
     var whenAllTask = TaskUtils.WhenAll(taskCompletionSources.Select(tcs => tcs.Task).Cast<Task>());
     taskCompletionSources[0].SetResult(1);
     Assert.IsFalse(whenAllTask.IsCompleted);
     taskCompletionSources[1].SetResult(1);
     await whenAllTask;
 }
Example #13
0
 public async Task ArrayVersion()
 {
     var taskCompletionSources = new[]
                                 {
                                     new TaskCompletionSource<int>(), 
                                     new TaskCompletionSource<int>()
                                 };
     Task whenAllTask = TaskUtils.WhenAll(taskCompletionSources.Select(tcs => tcs.Task).ToArray());
     taskCompletionSources[0].SetResult(1);
     Assert.IsFalse(whenAllTask.IsCompleted);
     taskCompletionSources[1].SetResult(1);
     await whenAllTask;
 }
        public void GivenPublicField_WhenInvokeDataSelector_ThenCategoriesPropertyMatches()
        {
            string[] expected = new[] { "category1", "category2", "category3" };
            PublicField customField = new PublicField
            {
                Categories = expected.Select(c => new CustomFieldCategory { Name = c }).ToList(),
                CustomFieldType = new CustomFieldType()
            };
            PublicFieldClientDataTable target = new PublicFieldClientDataTable(MockRequest);

            dynamic actual = target.DataSelector.Compile().Invoke(customField);

            CollectionAssert.AreEqual(expected, ((IEnumerable<string>)actual.Categories).ToList());
        }
 private IEnumerable<string> GetPreloadImageSourcePaths()
 {
     var wwwrootFolderPath = Path.Combine(_appEnvironment.ApplicationBasePath, "wwwroot");
     var imagesFolderPath = Path.Combine(wwwrootFolderPath, "images");
     var cupsFolderPath = Path.Combine(imagesFolderPath, "cups");
     var cupTitlesFolderPath = Path.Combine(imagesFolderPath, "cup-titles");
     var trackTitlesFolderPath = Path.Combine(imagesFolderPath, "track-titles");
     var absoluteImageFilePaths = new[] {cupsFolderPath, cupTitlesFolderPath, trackTitlesFolderPath}
         .SelectMany(path => Directory.EnumerateFiles(path, "*.png", SearchOption.AllDirectories));
     var wwwrootFolderPathLength = wwwrootFolderPath.Length;
     return
         absoluteImageFilePaths.Select(
             path => path.Substring(wwwrootFolderPathLength).Replace(@"\", "/"));
 }
Example #16
0
 public async Task GenericIEnumerableWithSomeContents()
 {
     var taskCompletionSources = new []
                                 {
                                     new TaskCompletionSource<int>(),
                                     new TaskCompletionSource<int>(),
                                     new TaskCompletionSource<int>()
                                 };
     var whenAllTask = TaskUtils.WhenAll(taskCompletionSources.Select(tcs => tcs.Task));
     taskCompletionSources[0].SetResult(1);
     taskCompletionSources[1].SetResult(2);
     taskCompletionSources[2].SetResult(3);
     var results = await whenAllTask;
     CollectionAssert.AreEquivalent(new[] {1, 2, 3}, results.ToList());
 }
        public IEnumerable<PhoneModel> PhoneModel_choices()
        {
            //this data could come from your database
            var data = new[]
            {
                new {Company = "Apple", Models = new[] { "iPhone 5s", "iPhone 6"}},
                new {Company = "Sony", Models = new[] { "Z3", "Z3 Compact"}}
            };

            return data.Select(i => new PhoneModel()
            {
                Company = i.Company,
                ModelChoices = i.Models
            }.DisplayName(i.Company));
        }
Example #18
0
        public void TestMethod1()
        {
            var list = new[] { 1, 2, 3, 4 };

            var obj = list.Select(x => new
            {
                x
            });

            dynamic d = new DynamicObjects(obj);

            var z = d[0].x;

            Assert.AreEqual(1, z);

        }
        static Highligher()
        {
            var patterns = new[]
                               {
                                   "*debt*equity*",
                                   "*Forward Price*Earnings*",
                                   "*Forward P/E*",
                                   "*Forward PE*",
                                   "*Current Ratio*",
                                   "P/E (TTM)",
                                   "Price/Sales",
                                   "Price/Earnings"
                               };

            Wildcards = patterns.Select(s => new Wildcard(s, RegexOptions.IgnoreCase)).ToList();
        }
Example #20
0
        public void TestMethod12()
        {
            var list = new[] { 100, 2, 3, 4 };

            var obj = list.Select(x => new
            {
                l = new { a = x, b = x }
            });

            dynamic d = new DynamicObjects(obj);

            var z = d[0].l.a;

            Assert.AreEqual(100, z);

        }
Example #21
0
        /// <summary> Tells the story in the chosen language. </summary>
        static IEnumerable<string> TellStory (Dictionary <string, string> dict, Morpher.IDynamicDeclension grammar)
        {
            // THE PLOT. See if you can read the story from it!
            var story = new [] 
            {
                new {Verb = "title",     Actors = ""},
                new {Verb = "likes2",    Actors = "bob,alice,photo"},
                new {Verb = "commented", Actors = "bob,alice,photo"},
                new {Verb = "emailed",   Actors = "bob,alice"},
                new {Verb = "likes",     Actors = "bob,alice"},
                new {Verb = "likes",     Actors = "alice,celebrity"},
            };

            return story.Select (sentence => Regex.Replace (
                string.Format (dict [sentence.Verb], sentence.Actors.Split (',')), 
                @"<(?<id>\w*)(:(?<format>\w*))?>",
                match => GetDeclension (dict [match.Groups ["id"].Value], match.Groups ["format"].Value, grammar)));
        }
Example #22
0
        public static List<ProcessInfo> KillAllCassiniInstances()
        {
            var processNames = new[] { "WebDev.WebServer", "WebDev.WebServer20", "WebDev.WebServer40", "iisexpress" };

            var processesKilled = new List<ProcessInfo>();
            foreach (var runningProcess in processNames.Select(Process.GetProcessesByName).SelectMany(p => p))
            {
                var processInfo = new ProcessInfo
                                      {
                                          Handle = runningProcess.Handle,
                                          Id = runningProcess.Id,
                                          Name = runningProcess.ProcessName
                                      };
                runningProcess.Kill();
                processesKilled.Add(processInfo);
            }
            return processesKilled;
        }
Example #23
0
        public void GroupbyTest()
        {
            var list = new[] { 100, 2, 3, 4 };

            var obj = list.Select(x => new
            {
                l = new { a = x, b = x, c = 9 }
            }).GroupBy(x => new { x.l.a, x.l.b });

            dynamic d = new DynamicObjects(obj);


            var key = d[0];
            var v = key[0];
            var w = v.l;
            var l = w.a;


        }
        /// <summary>
        ///     Returns an array of <see cref="SelectListItem" /> for culture chooser.
        /// </summary>
        public static ICollection<SelectListItem> GetCultureItems(this HtmlHelper htmlHelper)
        {
            var cultureNames = new[]
            {
                "en-US",
                "uk-UA",
                "cs-CZ",
            };

            return cultureNames
                .Select(CultureInfo.GetCultureInfo)
                .Select(culture => new SelectListItem
                {
                    Selected = culture.Equals(DynamicFileVirtualPathProvider.CurrentCulture),
                    Text = culture.NativeName,
                    Value = culture.Name
                })
                .ToArray();
        }
        public void CalculateCoverage_FileExists_WithLines_ReturnsCodeCoverageTable()
        {
            var annotations = new[]
            {
                new { fileName = "first", id = 1, index = 2, hitCount = 1, coverage = 100.0m, line = "first_1" },
                new { fileName = "second", id = 2, index = 8, hitCount = 3, coverage = 100.0m, line = "second_2" },
                new { fileName = "third", id = 3, index = 13, hitCount = 0, coverage = 0.0m, line = string.Empty }
            };

            var annotationTable = new AnnotationTable();
            foreach (var a in annotations)
            {
                annotationTable.Add(a.fileName);
                annotationTable[a.fileName].Add(new Annotation(a.id, a.index, a.hitCount));
            }

            var calculator = new CodeCoverageCalculator(null, annotationTable)
            {
                FileReader = new StubFileReader
                {
                    ExistsValue = true,
                    GetLinesValue = annotations.Select(a => a.line)
                }
            };

            var actualCoverage = calculator.CalculateCoverage();

            var expectedCoverage = new CodeCoverageTable
            {
                Total = (decimal)2 / 3 * 100
            };

            foreach (var a in annotations)
                expectedCoverage.Add(a.fileName, a.coverage);

            Assert.AreEqual(expectedCoverage.Plugin, actualCoverage.Plugin);
            Assert.AreEqual(expectedCoverage.Total, actualCoverage.Total);
            Assert.AreEqual(expectedCoverage.ToString(), actualCoverage.ToString());
            CollectionAssert.AreEqual(expectedCoverage, actualCoverage);
        }
Example #26
0
        private IEnumerable<PayloadReaderTestDescriptor> CreateFeedValidatorDescriptors(IEdmModel model)
        {
            var cityType = model.FindType("TestModel.CityType");
            var personType = model.FindType("TestModel.Person");
            var employeeType = model.FindType("TestModel.Employee");

            var testCases = new[]
                {
                    new
                    {
                        Description = "Homogenous collection (no inheritance)",
                        Feed = (ODataPayloadElement)PayloadBuilder.EntitySet().WithTypeAnnotation(personType).IgnoreEntitySet()
                            .Append(PayloadBuilder.Entity("TestModel.Person")
                                .PrimitiveProperty("Id", 1).WithTypeAnnotation(personType))
                            .Append(PayloadBuilder.Entity("TestModel.Person")
                                .PrimitiveProperty("Id", 2).WithTypeAnnotation(personType)),
                        ExpectedException = (ExpectedException)null,
                        Model = model
                    },
                    new
                    {
                        Description = "Homogenous collection (inheritance, base type first)",
                        Feed = (ODataPayloadElement)PayloadBuilder.EntitySet().WithTypeAnnotation(personType).IgnoreEntitySet()
                            .Append(PayloadBuilder.Entity("TestModel.Person")
                                .PrimitiveProperty("Id", 1).WithTypeAnnotation(personType))
                            .Append(PayloadBuilder.Entity("TestModel.Employee")
                                .PrimitiveProperty("Id", 2).WithTypeAnnotation(employeeType)),
                        ExpectedException = (ExpectedException)null,
                        Model = model
                    },
                    new
                    {
                        Description = "Homogenous collection (inheritance, derived type first)",
                        Feed = (ODataPayloadElement)PayloadBuilder.EntitySet().WithTypeAnnotation(personType).IgnoreEntitySet()
                            .Append(PayloadBuilder.Entity("TestModel.Employee")
                                .PrimitiveProperty("Id", 1).WithTypeAnnotation(employeeType))
                            .Append(PayloadBuilder.Entity("TestModel.Person")
                                .PrimitiveProperty("Id", 2).WithTypeAnnotation(personType)),
                        ExpectedException = (ExpectedException)null,
                        Model = model
                    },
                    new
                    {
                        Description = "Heterogeneous collection",
                        Feed = (ODataPayloadElement)PayloadBuilder.EntitySet().WithTypeAnnotation(personType).IgnoreEntitySet()
                            .Append(PayloadBuilder.Entity("TestModel.Person")
                                .PrimitiveProperty("Id", 1).WithTypeAnnotation(personType))
                            .Append(PayloadBuilder.Entity("TestModel.CityType")
                                .PrimitiveProperty("Id", 2).WithTypeAnnotation(cityType)),
                        ExpectedException = ODataExpectedExceptions.ODataException("FeedWithoutExpectedTypeValidator_IncompatibleTypes", "TestModel.CityType", "TestModel.Person"),
                        Model = model
                    },
                    new
                    {
                        Description = "Heterogeneous collection (no model)",
                        Feed = (ODataPayloadElement)PayloadBuilder.EntitySet().IgnoreEntitySet()
                            .Append(PayloadBuilder.Entity("TestModel.Person")
                                .PrimitiveProperty("Id", 1))
                            .Append(PayloadBuilder.Entity("TestModel.CityType")
                                .PrimitiveProperty("Id", 2)),
                        ExpectedException = (ExpectedException)null,
                        Model = (IEdmModel)null
                    },
                };

            // Create the tests for a top-level feed
            return testCases.Select(testCase =>
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = testCase.Description,
                    PayloadDescriptor = new PayloadTestDescriptor()
                    {
                        DebugDescription = testCase.Description,
                        PayloadElement = testCase.Feed,
                    },
                    PayloadEdmModel = testCase.Model,
                    ExpectedException = testCase.ExpectedException,
                });
        }
 public IEnumerable<FileInfo> SaveSubtitle(Subtitle subtitle)
 {
     var languages = new[] { subtitle.Language };
     var download = _api.DownloadSubtitle(subtitle.Id, languages.Select(l => l.TwoLetterIsoName));
     return new []{ download };
 }
Example #28
0
        public void MaxSingleWithSelectorAccessingProperty()
        {
            var source = new []
            {
                new { name = "Tim", num = 40.5f },
                new { name = "John", num = -10.25f },
                new { name = "Bob", num = 100.45f }
            };

            Assert.Equal(100.45f, source.Select(e => e.num).Max());
        }
        public IHttpActionResult GetProxies()
        {
            var discoveryUrls = new[] { "crm4", "crm", "crm9", "crm5", "crm6", "crm7", "crm2"};
            var regions = new[]
            {
                "Europe, Middle East and Africa", "North America", "North America 2", "Asia Pacific Area",
                "Oceania","Japan", "South America"
            };

            var proxies = discoveryUrls.Select((t, count) => new DynamicsProxy
            {
                DiscoveryUrl = $"https://disco.{t}.dynamics.com/XRMServices/2011/Discovery.svc", Region = regions[count]
            }).ToList();

            return Ok(proxies);
        }
        private void TestParametersAgainstCollection(
            ControlType controlType,
            string name,
            string automationId,
            string className,
            string txtValue,
            IEnumerable<IUiElement> collection,
            UsualWildcardRegex selector,
            int expectedNumberOfElements)
        {
            // Arrange
            ControlType[] controlTypes =
                new[] { controlType };
            
            GetControlCmdletBase cmdlet =
                FakeFactory.Get_GetControlCmdletBase(controlTypes, name, automationId, className, txtValue);
            
            var data =
                new ControlSearcherData {
                ControlType = controlTypes.ConvertControlTypeToStringArray(),
                Name = name,
                AutomationId = automationId,
                Class = className,
                Value = txtValue
            };
            
            Condition condition;
            bool useWildcardOrRegex = true;
            switch (selector) {
                case UsualWildcardRegex.Wildcard:
                    condition =
                        ControlSearcher.GetWildcardSearchCondition(
                            data);
                    useWildcardOrRegex = true;
                    break;
                case UsualWildcardRegex.Regex:
                    condition =
                        ControlSearcher.GetWildcardSearchCondition(
                            data);
                    useWildcardOrRegex = false;
                    break;
            }
            
            // Act
            var resultList = RealCodeCaller.GetResultList_ReturnOnlyRightElements(collection.ToArray(), data, useWildcardOrRegex);
            
            // Assert
            MbUnit.Framework.Assert.Count(expectedNumberOfElements, resultList);
            Assert.Equal(expectedNumberOfElements, resultList.Count);
            string[] controlTypeNames;
            switch (selector) {
                case UsualWildcardRegex.Wildcard:
                    const WildcardOptions options = WildcardOptions.IgnoreCase;
                    // 20140312
//                    WildcardPattern namePattern = new WildcardPattern(name, options);
//                    WildcardPattern automationIdPattern = new WildcardPattern(automationId, options);
//                    WildcardPattern classNamePattern = new WildcardPattern(className, options);
//                    WildcardPattern txtValuePattern = new WildcardPattern(txtValue, options);
                    var namePattern = new WildcardPattern(name, options);
                    var automationIdPattern = new WildcardPattern(automationId, options);
                    var classNamePattern = new WildcardPattern(className, options);
                    var txtValuePattern = new WildcardPattern(txtValue, options);
                    
                    // 20140312
//                    if (!string.IsNullOrEmpty(name)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => namePattern.IsMatch(x.Current.Name));
//                        resultList.All(x => namePattern.IsMatch(x.Current.Name));
//                    }
//                    if (!string.IsNullOrEmpty(automationId)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => automationIdPattern.IsMatch(x.Current.AutomationId));
//                        resultList.All(x => automationIdPattern.IsMatch(x.Current.AutomationId));
//                    }
//                    if (!string.IsNullOrEmpty(className)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => classNamePattern.IsMatch(x.Current.ClassName));
//                        resultList.All(x => classNamePattern.IsMatch(x.Current.ClassName));
//                    }
//                    controlTypeNames =
//                        controlTypes.Select(ct => null != ct ? ct.ProgrammaticName.Substring(12) : string.Empty).ToArray();
//                    if (null != controlType) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => controlTypeNames.Contains(x.Current.ControlType.ProgrammaticName.Substring(12)));
//                        resultList.All(x => controlTypeNames.Contains(x.Current.ControlType.ProgrammaticName.Substring(12)));
//                    }
                    if (!string.IsNullOrEmpty(name)) {
                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => namePattern.IsMatch(x.GetCurrent().Name));
                        resultList.All(x => namePattern.IsMatch(x.GetCurrent().Name));
                    }
                    if (!string.IsNullOrEmpty(automationId)) {
                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => automationIdPattern.IsMatch(x.GetCurrent().AutomationId));
                        resultList.All(x => automationIdPattern.IsMatch(x.GetCurrent().AutomationId));
                    }
                    if (!string.IsNullOrEmpty(className)) {
                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => classNamePattern.IsMatch(x.GetCurrent().ClassName));
                        resultList.All(x => classNamePattern.IsMatch(x.GetCurrent().ClassName));
                    }
                    controlTypeNames =
                        controlTypes.Select(ct => null != ct ? ct.ProgrammaticName.Substring(12) : string.Empty).ToArray();
                    if (null != controlType) {
                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => controlTypeNames.Contains(x.GetCurrent().ControlType.ProgrammaticName.Substring(12)));
                        resultList.All(x => controlTypeNames.Contains(x.GetCurrent().ControlType.ProgrammaticName.Substring(12)));
                    }
                    
                    if (!string.IsNullOrEmpty(txtValue)) {
                        MbUnit.Framework.Assert.ForAll(
                            resultList
                            .Cast<IUiElement>()
                            .ToList<IUiElement>(), x =>
                            {
                                IValuePattern valuePattern = x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern;
                                return valuePattern != null && txtValuePattern.IsMatch(valuePattern.Current.Value);
                            });
                        
                        resultList.All(
                            x => {
                                IValuePattern valuePattern = x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern;
                                return valuePattern != null && txtValuePattern.IsMatch(valuePattern.Current.Value);
                            });
                    }
                    break;
                case UsualWildcardRegex.Regex:
                    // 20140312
//                    if (!string.IsNullOrEmpty(name)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => Regex.IsMatch(x.Current.Name, name));
//                        resultList.All(x => Regex.IsMatch(x.Current.Name, name));
//                    }
//                    if (!string.IsNullOrEmpty(automationId)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => Regex.IsMatch(x.Current.AutomationId, automationId));
//                        resultList.All(x => Regex.IsMatch(x.Current.AutomationId, automationId));
//                    }
//                    if (!string.IsNullOrEmpty(className)) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => Regex.IsMatch(x.Current.ClassName, className));
//                        resultList.All(x => Regex.IsMatch(x.Current.ClassName, className));
//                    }
//                    controlTypeNames =
//                        controlTypes.Select(ct => null != ct ? ct.ProgrammaticName.Substring(12) : string.Empty).ToArray();
//                    if (null != controlType) {
//                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => controlTypeNames.Contains(x.Current.ControlType.ProgrammaticName.Substring(12)));
//                        resultList.All(x => controlTypeNames.Contains(x.Current.ControlType.ProgrammaticName.Substring(12)));
//                    }
                    if (!string.IsNullOrEmpty(name)) {
                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => Regex.IsMatch(x.GetCurrent().Name, name));
                        resultList.All(x => Regex.IsMatch(x.GetCurrent().Name, name));
                    }
                    if (!string.IsNullOrEmpty(automationId)) {
                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => Regex.IsMatch(x.GetCurrent().AutomationId, automationId));
                        resultList.All(x => Regex.IsMatch(x.GetCurrent().AutomationId, automationId));
                    }
                    if (!string.IsNullOrEmpty(className)) {
                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => Regex.IsMatch(x.GetCurrent().ClassName, className));
                        resultList.All(x => Regex.IsMatch(x.GetCurrent().ClassName, className));
                    }
                    controlTypeNames =
                        controlTypes.Select(ct => null != ct ? ct.ProgrammaticName.Substring(12) : string.Empty).ToArray();
                    if (null != controlType) {
                        MbUnit.Framework.Assert.ForAll(resultList.Cast<IUiElement>().ToList<IUiElement>(), x => controlTypeNames.Contains(x.GetCurrent().ControlType.ProgrammaticName.Substring(12)));
                        resultList.All(x => controlTypeNames.Contains(x.GetCurrent().ControlType.ProgrammaticName.Substring(12)));
                    }
                    
                    if (!string.IsNullOrEmpty(txtValue)) {
                        MbUnit.Framework.Assert.ForAll(
                            resultList
                            .Cast<IUiElement>()
                            .ToList<IUiElement>(), x =>
                            {
                                IValuePattern valuePattern = x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern;
                                return valuePattern != null && Regex.IsMatch(valuePattern.Current.Value, txtValue);
                            });
                        Assert.True(
                            resultList.All(
                                x => {
                                    IValuePattern valuePattern = x.GetCurrentPattern<IValuePattern>(ValuePattern.Pattern) as IValuePattern;
                                    return valuePattern != null && Regex.IsMatch(valuePattern.Current.Value, txtValue);
                                })
                           );
                    }
                    break;
            }
        }