public void should_check_if_sequence_contains_element() { var sequence = new[] {1, 2, 3, 4, 5}; bool containsTwo = sequence.Contains(2); bool containsTen = sequence.Contains(10); // please update variable values of the following 2 lines to fix the test. const bool expectedContainsTwo = false; const bool expectedContainsTen = true; Assert.Equal(expectedContainsTwo, containsTwo); Assert.Equal(expectedContainsTen, containsTen); }
private ElementFilter<ClientCompanyColumnName, ClientCompany, ClientCompaniesListFilter> BuildFilter(ClientCompaniesListFilter filter) { var companyActiveStatus = ClientCompanyStatus.Active.ToString(); var companyInactiveStatus = ClientCompanyStatus.Inactive.ToString(); IEnumerable<string> filterStatuses = new[] { companyActiveStatus, companyInactiveStatus }; if (filter.FilterByActiveStatus || filter.FilterByInactiveStatus) { if (!filter.FilterByActiveStatus) { filterStatuses = filterStatuses.Where(e => e != companyActiveStatus); } if (!filter.FilterByInactiveStatus) { filterStatuses = filterStatuses.Where(e => e != companyInactiveStatus); } } return ShorFilter.AddFilter<ClientCompanyColumnName, ClientCompany, ClientCompaniesListFilter>(f => !string.IsNullOrWhiteSpace(f.CompanyName), c => c.CompanyName.ToUpper().Contains(filter.CompanyName.ToUpper())). AddFilter(f => !string.IsNullOrWhiteSpace(f.CompanyId), c => c.CompanyId.ToUpper().Contains(filter.CompanyId.ToUpper())). AddFilter(f => true, c => filterStatuses.Contains(c.StatusId)). AddFilter(f => filter.IsWholesaleChannel, c => c.Profile.IsWholesale). AddFilter(f => filter.IsLender, c => c.Profile.IsLender). AddOrders(ClientCompanyColumnName.CompanyNameOrder, c => c.CompanyName). AddOrders(ClientCompanyColumnName.CompanyIdOrder, c => c.CompanyId). AddOrders(ClientCompanyColumnName.Status, c => c.StatusId); }
public void Copy_Razor_files_to_AWS_Bucket() { var fs = new FileSystemVirtualPathProvider(appHost, "~/../RazorRockstars.WebHost".MapHostAbsolutePath()); var skipDirs = new[] { "bin", "obj" }; var matchingFileTypes = new[] { "cshtml", "md", "css", "js", "png", "jpg" }; var replaceHtmlTokens = new Dictionary<string, string> { { "title-bg.png", "title-bg-aws.png" }, //Title Background { "https://gist.github.com/3617557.js", "https://gist.github.com/mythz/396dbf54ce6079cc8b2d.js" }, //AppHost.cs { "https://gist.github.com/3616766.js", "https://gist.github.com/mythz/ca524426715191b8059d.js" }, //S3 RockstarsService.cs { "RazorRockstars.WebHost/RockstarsService.cs", "RazorRockstars.S3/RockstarsService.cs" }, //S3 RockstarsService.cs { "http://github.com/ServiceStackApps/RazorRockstars/", "https://github.com/ServiceStackApps/RazorRockstars/tree/master/src/RazorRockstars.S3" } //Link to GitHub project }; foreach (var file in fs.GetAllFiles()) { if (skipDirs.Any(x => file.VirtualPath.StartsWith(x))) continue; if (!matchingFileTypes.Contains(file.Extension)) continue; if (file.Extension == "cshtml") { var html = file.ReadAllText(); replaceHtmlTokens.Each(x => html = html.Replace(x.Key, x.Value)); s3.WriteFile(file.VirtualPath, html); } else { s3.WriteFile(file); } } }
private void InitControlKeyMap() { var validTypes = new[] { typeof (Label), typeof (Button), typeof (CheckBox), typeof (RadioButton), typeof (GroupBox), //typeof (ObjectListView), }; foreach (var control in GetControls(this).Where(c => validTypes.Contains(c.GetType()))) { // if (control is ObjectListView) // { // var listView = control as ObjectListView; // for (var i = 0; i < listView.Columns.Count; i++) // { // var column = listView.Columns[i]; // _map.Add(column, column.Text); // } // } // else { _map.Add(control, control.Text); } } _map.Add(this, Text); }
public void ContainsQueriedData() { int n = 20; IEnumerable<TestObj> cq = from i in Enumerable.Range(1, n) select new TestObj { Name = i.ToString() }; var db = new TestDb(new SQLitePlatformWin32(), TestPath.GetTempFileName()); db.InsertAll(cq); db.Trace = true; var tensq = new[] {"0", "10", "20"}; List<TestObj> tens = (from o in db.Table<TestObj>() where tensq.Contains(o.Name) select o).ToList(); Assert.AreEqual(2, tens.Count); var moreq = new[] {"0", "x", "99", "10", "20", "234324"}; List<TestObj> more = (from o in db.Table<TestObj>() where moreq.Contains(o.Name) select o).ToList(); Assert.AreEqual(2, more.Count); // https://github.com/praeclarum/SQLite.Net/issues/28 List<string> moreq2 = moreq.ToList(); List<TestObj> more2 = (from o in db.Table<TestObj>() where moreq2.Contains(o.Name) select o).ToList(); Assert.AreEqual(2, more2.Count); }
private static IEnumerable<Token> Process(IEnumerator<Token> eTokens, char? expectedTerminator) { var openNesting = new[] {"[", "("}; while (eTokens.MoveNext()) { var token = eTokens.Current; if (expectedTerminator != null && token.Characters.Length == 1) { if (token.Characters[0] == expectedTerminator) yield break; } if (token.CharacterType != CodeCharacterType.ControlCharacters) { yield return token; continue; } if (openNesting.Contains(token.Characters)) { var terminator = token.Characters == "[" ? ']' : ')'; token.Characters += terminator; token.Children = Process(eTokens, terminator).ToList(); yield return token; } else yield return token; } }
public void ContainsForProperty_ReturnsCorrectReql() { var strings = new[] { "Hello" }; var data = new List<TestObject> { new TestObject { Name = "Hello" } }; ; SpawnData( data ); var expected = RethinkDB.R.Table( TableName ) .Filter( x => RethinkDB.R.Expr( RethinkDB.R.Array( strings ) ).Contains( x["Name"] ) ); var queryable = GetQueryable<TestObject>( TableName, expected ); var result = queryable .Where( x => strings.Contains( x.Name ) ) .ToList(); Assert.AreEqual( 1, result.Count ); }
public object GetConfiguration(string type, int id) { var objectType = Mappings.TreeNodeObjectTypes[new TreeNodeType("settings", type)]; var contentTypes = ContentTypeService.GetAllContentTypes().ToList(); var mediaTypes = ApplicationContext.Services.ContentTypeService.GetAllMediaTypes().ToList(); var types = new[] { (objectType == UmbracoObjectTypes.DocumentType ? UmbracoObjectTypes.Document : UmbracoObjectTypes.Media).GetGuid(), }; var relationTypes = ApplicationContext.Services.RelationService.GetAllRelationTypes() .Where(rt => types.Contains(rt.ParentObjectType)) ; var contentType = objectType == UmbracoObjectTypes.DocumentType ? (IContentTypeBase)contentTypes.Single(ct => ct.Id == id) : mediaTypes.Single(ct => ct.Id == id); var contentObjectType = objectType == UmbracoObjectTypes.DocumentType ? UmbracoObjectTypes.Document : UmbracoObjectTypes.Media; return new { contentTypes, mediaTypes, relationTypes, configuration = RelationEditor.Configuration.Get(contentObjectType, contentType.Alias) }; }
private Declaration ParentDeclaration(IdentifierReference reference) { var declarationTypes = new[] {DeclarationType.Function, DeclarationType.Procedure, DeclarationType.Property}; return UserDeclarations.SingleOrDefault(d => reference.ParentScoping.Equals(d) && declarationTypes.Contains(d.DeclarationType) && d.QualifiedName.QualifiedModuleName.Equals(reference.QualifiedModuleName)); }
public static float GetTotalDamageEBDB(this Obj_AI_Base target) { var slots = new[] {SpellSlot.Q, SpellSlot.W, SpellSlot.E, SpellSlot.R}; var dmg = Player.Instance.Spellbook.Spells.Where(s => s.IsReady && slots.Contains(s.Slot)) .Sum(s => Player.Instance.GetSpellDamage(target, s.Slot)); var aaDmg = Orbwalker.CanAutoAttack ? Player.Instance.GetAutoAttackDamage(target) : 0f; return dmg + aaDmg; }
public ActionResult Index(HttpPostedFileBase files) { if (files == null) { return new EmptyResult(); } if (string.IsNullOrEmpty(files.FileName)) { return new EmptyResult(); } var allowedTypes = new[] { ".xlsx" }; var extension = Path.GetExtension(files.FileName).ToLower(); if (files.ContentLength > 0 && allowedTypes.Contains(extension)) { using (var excelReader = ExcelReaderFactory.CreateOpenXmlReader(files.InputStream)) { var testPages = new List<TestPage>(); excelReader.IsFirstRowAsColumnNames = true; DataSet result = excelReader.AsDataSet(); for (int i = 0; i < result.Tables.Count; i++) { var headers = result.Tables[i].Columns; if (headers.Count == 0) { break; } if (!headers[0].ColumnName.ToLowerInvariant().Equals("url")) { break; } foreach (DataRow row in result.Tables[i].Rows) { var testPage = new TestPage() { URL = row[0].ToString() }; for (int a = 1; a < row.ItemArray.Length; a++) { testPage.ElementList.Add(new Element { Name = headers[a].ToString(), ExpectedValue = row[a].ToString().Trim() }); } testPages.Add(testPage); } } TestPagesService.Process(testPages); } } return View(); }
public static void Contains() { Qunit.RunTest("Contains", () => { var testClass = new TestClass(); IList<TestClass> array = new [] {testClass}; Qunit.IsTrue(array.Contains(testClass)); }); }
public static float GetAlliesDamagesNear(this Obj_AI_Base target, float percent = 0.7f, int range = 700, int delay = 250) { var dmg = 0f; var slots = new[] {SpellSlot.Q, SpellSlot.W, SpellSlot.E, SpellSlot.R}; foreach (var a in EntityManager.Heroes.Allies.Where(a => a.IsInRange(target, range))) { dmg += a.GetAutoAttackDamage(target); dmg += a.Spellbook.Spells.Where(s => slots.Contains(s.Slot) && s.IsReady).Sum(s => a.GetSpellDamage(target, s.Slot)); } return dmg*percent; }
public void PropertyFilter_finds_all_properties_on_base_type() { var propertyNames = new[] { "PublicBase", "PublicBaseForNew", "PublicVirtualBase", "PublicVirtualBase2", "InterfaceImplicit", }; var properties = new PropertyFilter().GetProperties( typeof(PropertyFilterTests_Base), true, null); Assert.True(properties.All(x => propertyNames.Contains(x.Name))); properties = new PropertyFilter().GetProperties( typeof(PropertyFilterTests_Base), false, Enumerable.Empty<PropertyInfo>()); Assert.Equal(propertyNames.Length, properties.Count()); Assert.True(properties.All(x => propertyNames.Contains(x.Name))); }
public void PropertyFilter_finds_declared_properties_on_derived_type() { var propertyNames = new[] { "PublicDerived" }; var properties = new PropertyFilter().GetProperties( typeof(PropertyFilterTests_Derived), true, Enumerable.Empty<PropertyInfo>()); Assert.Equal(propertyNames.Length, properties.Count()); Assert.True(properties.All(x => propertyNames.Contains(x.Name))); }
public void ReadXml(XmlReader reader) { var standardNames = new[] {"name", "quantity"}; var node = (XElement) XNode.ReadFrom(reader); var nameElement = node.Element(XName.Get("name", "http://restbuckson.net")); if (nameElement != null) Name = nameElement.Value; Quantity = (int) node.Element(XName.Get("quantity", "http://restbuckson.net")); Preferences = node.Elements() .Where(x => !standardNames.Contains(x.Name.LocalName)) .ToDictionary(x => x.Name.LocalName, x => x.Value); }
[U] public void ClassNameContainsBaseShouldBeAbstract() { var exceptions = new[] { typeof(DateMath) }; var baseClassesNotAbstract = typeof(IRequest).Assembly().GetTypes() .Where(t => t.IsClass() && !exceptions.Contains(t)) .Where(t => t.Name.Split('`')[0].EndsWith("Base")) .Where(t => !t.IsAbstractClass()) .Select(t => t.Name.Split('`')[0]) .ToList(); baseClassesNotAbstract.Should().BeEmpty(); }
/** * Abstract class names should end with a `Base` suffix */ [U] public void AbstractClassNamesEndWithBase() { var exceptions = new[] { typeof(DateMath) }; var abstractClasses = typeof(IRequest).Assembly().GetTypes() .Where(t => t.IsClass() && t.IsAbstract() && !t.IsSealed() && !exceptions.Contains(t)) .Where(t => !t.Name.Split('`')[0].EndsWith("Base")) .Select(t => t.Name.Split('`')[0]) .ToList(); abstractClasses.Should().BeEmpty(); }
public bool AllowDisplayElement(IEnumerable<IPluginArgument> arguments, MenuTabItem menuTabItem) { var orderFulfillmentMenuTab = menuTabItem.MenuTubPluginAttribute as OrderFulfillmentMenuTabAttribute; if (orderFulfillmentMenuTab == null) return true; var userAccessHelper = new UserAccessHelper(_securityContext); var controllerAttribute = menuTabItem.ControllerType.GetCustomAttributes(true).FirstOrDefault(e => e.GetType() == typeof(DVSAuthorizeFilterAttribute)) as DVSAuthorizeFilterAttribute; if (controllerAttribute != null) { if (!userAccessHelper.IsActionAvaibleByStatus(menuTabItem.ControllerName, menuTabItem.DefaultActionName, controllerAttribute.AllowedRoles.Select(r => r.ToString()).ToArray())) { return false; } } if (_securityContext.CurrentUser.Roles.Select(r => r.RoleType).Any(rt => OrderAccessSecurity.OrderFulfillmentAccessUsers.AppraiserRoles.Contains(rt))) { var controllerThanNotAllowDraftAndPendingAssignment = new[] { typeof(ContactInfoController), typeof(UpdateOrderController), typeof(CommunicationController), typeof(DocumentsController), typeof(ImportantDatesController), typeof(OrderHistoryController), typeof(ConditionsController) }; var isTabThatNotVisibleInDraftPendingAssignment = controllerThanNotAllowDraftAndPendingAssignment.Contains(menuTabItem.ControllerType); if (isTabThatNotVisibleInDraftPendingAssignment) { var orderId = arguments.Find<RoutingDetailsPluginArgument>().GetOrderIdFromRoutes(); if (!orderId.HasValue) { return false; } var currentOrder = _orderManager.GetOrderById(orderId.Value); return currentOrder.OrderStatus != OrderStatus.Draft && currentOrder.OrderStatus != OrderStatus.PendingAssignment; } } return true; }
public override IEnumerable<XElement> Install() { var usersNames = new[] { "developer", "advuser", "enduser" }; using (var conn = new DataConnection()) { var userSettings = conn.Get<IUserSettings>().Where(us => usersNames.Contains(us.Username)); var culture = DataConnection.AllLocales.First(); foreach (var setting in userSettings) { setting.CultureName = culture.Name; setting.C1ConsoleUiLanguage = culture.Name; setting.CurrentActiveLocaleCultureName = culture.Name; setting.ForeignLocaleCultureName = culture.Name; } conn.Update<IUserSettings>(userSettings); } yield return new XElement("FixUserSettings", usersNames); }
public void AddToTree(TreeView treeView) { var excludedTemplates = new[] { "Ark", "Harbour", "OrnamentBuilding" }; var excludedFactions = new[] { "third party" }; var list = Buildings.Where(_ => !excludedTemplates.Contains(_.Template)).Where(_ => !excludedFactions.Contains(_.Faction)); foreach (var firstLevel in list.GroupBy(_ => _.Faction).OrderBy(_ => _.Key)) { var firstLevelItem = new TreeViewItem { Header = firstLevel.Key }; foreach (var secondLevel in firstLevel.GroupBy(_ => _.Group).OrderBy(_ => _.Key)) { var secondLevelItem = new TreeViewItem { Header = secondLevel.Key }; foreach (var buildingInfo in secondLevel.OrderBy(_ => _.GetOrderParameter())) { secondLevelItem.Items.Add(buildingInfo.ToAnnoObject()); } firstLevelItem.Items.Add(secondLevelItem); } treeView.Items.Add(firstLevelItem); } }
/// <summary> /// Cancels all reports. /// </summary> public void CancelAllReports() { int staffId = EntityHelper.GetUserStaffId(); if (staffId != -1) { var cancellableStatuses = new[] { Enums.ReportStatus.Queued, Enums.ReportStatus.Processing }; List<ReportGenerationQueue> queuedReports = this.FindAll<ReportGenerationQueue>(report => report.ScheduledByStaffId == staffId && cancellableStatuses.Contains(report.ReportGenerationStatus)).ToList(); foreach (ReportGenerationQueue queue in queuedReports) { queue.ReportGenerationStatus = Enums.ReportStatus.Cancelled; } if (this.CanSubmitChanges()) { this.SubmitChanges(); } } }
public void Contains() { var db = new OrmTestSession(); db.CreateTable<TestObj>(); const int n = 20; IEnumerable<TestObj> cq = from i in Enumerable.Range(1, n) select new TestObj { Name = i.ToString(CultureInfo.InvariantCulture) }; db.InsertAll(cq); var tensq = new[] {"0", "10", "20"}; List<TestObj> tens = (from o in db.Table<TestObj>() where tensq.Contains(o.Name) select o).ToList(); Assert.AreEqual(2, tens.Count); var moreq = new[] {"0", "x", "99", "10", "20", "234324"}; List<TestObj> more = (from o in db.Table<TestObj>() where moreq.Contains(o.Name) select o).ToList(); Assert.AreEqual(2, more.Count); }
public void EnumerableContains_with_unicode_string_and_store_null_is_translated_to_expected_sql() { const string expectedSql = @"SELECT [Extent1].[Id] AS [Id] FROM [dbo].[Books] AS [Extent1] WHERE ([Extent1].[Title] IN (N'Title1', N'Title2')) OR ([Extent1].[Title] IS NULL)"; var array = new[] { "Title1", "Title2", null }; using (var context = new UnicodeContext()) { ((IObjectContextAdapter)context).ObjectContext.ContextOptions.UseCSharpNullComparisonBehavior = false; var query = from book in context.Books where array.Contains(book.Title) select book.Id; QueryTestHelpers.VerifyDbQuery(query, expectedSql); } }
public void QueriedStringArrayContainsTableColumnTest() { int n = 20; IEnumerable<TestObj> cq = from i in Enumerable.Range(1, n) select new TestObj { Name = i.ToString() }; var db = new OrmTestSession(); // temp stop trace for inputs SqliteSession.Trace = false; db.CreateTable<TestObj>(); db.InsertAll(cq); SqliteSession.Trace = true; var tensArray = new[] { "0", "10", "20" }; var tensResult = from tens in db.Table<TestObj>() where tensArray.Contains(tens.Name) select tens.Name; List<TestObj> more2 = (from all in db.Table<TestObj>() where tensResult.Contains(all.Name) select all).ToList(); Assert.AreEqual(2, more2.Count); }
public void ContainsConstantData() { int n = 20; IEnumerable<TestObj> cq = from i in Enumerable.Range(1, n) select new TestObj { Name = i.ToString() }; var db = new TestDb(new SQLitePlatformWin32(), TestPath.GetTempFileName()); db.InsertAll(cq); db.Trace = true; var tensq = new[] {"0", "10", "20"}; List<TestObj> tens = (from o in db.Table<TestObj>() where tensq.Contains(o.Name) select o).ToList(); Assert.AreEqual(2, tens.Count); var moreq = new[] {"0", "x", "99", "10", "20", "234324"}; List<TestObj> more = (from o in db.Table<TestObj>() where moreq.Contains(o.Name) select o).ToList(); Assert.AreEqual(2, more.Count); }
internal static IEnumerable<Token> ReduceTokens(IEnumerable<Token> tokens) { var typesToCombine = new[] { TokenType.Literal, TokenType.Quantifier, TokenType.GroupOption, TokenType.Number, TokenType.CharacterEscapeData }; var tokenQueue = new Queue<Token>(tokens); while (tokenQueue.Any()) { var currentToken = tokenQueue.Dequeue(); if (typesToCombine.Contains(currentToken.Type)) { var combinedData = tokenQueue .DequeueWhile(t => t.Type == currentToken.Type) .Aggregate(currentToken.Data, (current, token) => current + token.Data); yield return new Token(currentToken.Type, combinedData, currentToken.StartIndex); } else { yield return currentToken; } } }
private static IDictionary<string, Schema> GenerateTypeProperties(ArticleType templateType) { var typeProperties = new Dictionary<string, Schema>(); var restrictedFieldNames = new[] {"id", "parentid", "parenttype"}; foreach (var field in templateType.Fields.Where(field => !restrictedFieldNames.Contains(field.Name))) { typeProperties[field.Name] = new Schema { type = ConvertType(field), format = ConvertFormat(field), description = "" }; if (field.Type == DataType.SingleValue) typeProperties[field.Name].@ref = "SingleReference"; if (field.Type == DataType.MultiValue) typeProperties[field.Name].@ref = "MultiReference"; } return typeProperties; }
public void TestInOperatorEnumerale() { var value = new[] {"foo", "baz"}; var source = new[] { new TestSource {String = "foo", Int = 1}, new TestSource {String = "bar", Int = 2}, new TestSource {String = "baz", Int = 3}, new TestSource {String = "fii", Int = 4}, new TestSource {String = "baz", Int = 5}, new TestSource {String = "fuu", Int = 6}, new TestSource {String = "zap", Int = 7} }; var expectedResultList = source.Where(t => value.Contains(t.String)).ToList(); var filter = new FilterSetting { OperatorName = FilterOperators.InOperator, PropertyPath = "String", Value = value }; var result = _builder.Filter(source.AsQueryable(), new[] { filter }); TestUtil.AssertModels(expectedResultList, result.ToList()); }
public void LocalEnumerable_Contains() { var names = new[] {"Jack", "Bob"}; var people = Collection.AsQueryable().Where(x => names.Contains(x.FirstName)); var queryObject = ((IMongoQueryable)people).GetQueryObject(); Assert.AreEqual(0, queryObject.Fields.ElementCount); Assert.AreEqual(0, queryObject.NumberToLimit); Assert.AreEqual(0, queryObject.NumberToSkip); Assert.AreEqual( new BsonDocument( "fn", new BsonDocument( "$in", new BsonArray {"Jack", "Bob"})), queryObject.Query); }