public void ShouldBuildThreeValidatorsWithThreeValidationAttributes() { ParameterInfo paramToValidate = GetParameterInfo("MethodWithMultipleValidators", "id"); Validator v = ParameterValidatorFactory.CreateValidator(paramToValidate); Assert.IsNotNull(v); Assert.IsTrue(v is AndCompositeValidator); List<Validator> validators = new List<Validator>(((AndCompositeValidator)v).Validators); Assert.AreEqual(3, validators.Count); Assert.IsTrue( validators.Exists( delegate(Validator v1) { return v1 is NotNullValidator; })); Assert.IsTrue( validators.Exists( delegate(Validator v1) { return v1 is StringLengthValidator; })); Assert.IsTrue( validators.Exists( delegate(Validator v1) { return v1 is RegexValidator; })); }
public void ShouldReturnDescriptorsWhenUpdatedWithParameterInfo() { MetadataValidatedParameterElement validatedElement = new MetadataValidatedParameterElement(); validatedElement.UpdateFlyweight(GetMethod1NameParameterInfo()); Assert.IsNull(validatedElement.MemberInfo); Assert.IsNull(validatedElement.TargetType); Assert.AreEqual(CompositionType.And, validatedElement.CompositionType); Assert.IsFalse(validatedElement.IgnoreNulls); List<IValidatorDescriptor> descriptors = new List<IValidatorDescriptor>(validatedElement.GetValidatorDescriptors()); Assert.AreEqual(3, descriptors.Count); // reflection doesn't preserve ordering of attributes. Therefore, // it doesn't preserve ordering of validators. Is this an issue? Assert.IsTrue(descriptors.Exists(delegate(IValidatorDescriptor d) { return d is NotNullValidatorAttribute; })); Assert.IsTrue(descriptors.Exists(delegate(IValidatorDescriptor d) { return d is StringLengthValidatorAttribute; })); Assert.IsTrue(descriptors.Exists(delegate(IValidatorDescriptor d) { return d is RegexValidatorAttribute; })); }
public void Gera_Relation_Criar_Cartao() { var assembledUsuario = UsuarioResourceAssembler.AddRelationLinks(_usuario, _url); var list = new List<LinkRelation>(assembledUsuario.Links); Assert.IsTrue(list.Exists(x => x.Rel == "/rels/usuarios/adicionar-cartao"), "'/rels/usuarios/adicionar-cartao' relation is missing"); }
public void Gera_Self_Relation() { var assembledUsuario = UsuarioResourceAssembler.AddRelationLinks(_usuario, _url); var list = new List<LinkRelation>(assembledUsuario.Links); Assert.IsTrue(list.Exists(x => x.Rel == "self"),"self relation is missing"); }
public void Gera_Validacao_Usuario_Quando_Usuario_Nao_Foi_Validado() { _usuario.StatusValidacao = 0; var assembledUsuario = UsuarioResourceAssembler.AddRelationLinks(_usuario, _url); var list = new List<LinkRelation>(assembledUsuario.Links); Assert.IsTrue(list.Exists(x => x.Rel == "/rels/usuarios/validacao"), "'/rels/usuarios/validar' relation is missing"); }
public void Gera_Validacao_Telefone_Relation() { var assembledUsuario = UsuarioResourceAssembler.AddRelationLinks(_usuario, _url); var list = new List<LinkRelation>(assembledUsuario.Links); Assert.IsTrue(list.Exists(x => x.Rel == "/rels/usuarios/registrar-numero-telefone"), "'/rels/usuarios/registrar-numero-telefone' relation is missing"); }
public void AttackCleanUp_RemoveLowHealth() { // arrange List<Combatant> combatants = new List<Combatant>(); Combatant combatant1Copy = CopyCombatant(combatant1); combatant1Copy.Health = 0; Combatant combatant2Copy = CopyCombatant(combatant2); combatant2Copy.Health = 0; combatants.Add(combatant1Copy); combatants.Add(combatant2Copy); Battle battleClass = new Battle(); // act battleClass.AttackCleanUp(ref combatant1Copy, ref combatant2Copy, ref combatants); // assert if (combatants.Exists(x => x.CombatantID == combatant1Copy.CombatantID)) { Assert.Fail("AttackCleanUp failed to remove the attacker with low stanima"); return; } if (combatants.Exists(x => x.CombatantID == combatant2Copy.CombatantID)) { Assert.Fail("AttackCleanUp failed to remvoe the defender with low stanima"); return; } Assert.IsTrue(true); }
public void AttackCleanUp_NoRemoval() { // arrange List<Combatant> combatants = new List<Combatant>(); Combatant combatant1Copy = CopyCombatant(combatant1); Combatant combatant2Copy = CopyCombatant(combatant2); combatants.Add(combatant1Copy); combatants.Add(combatant2Copy); Battle battleClass = new Battle(); // act battleClass.AttackCleanUp(ref combatant1Copy, ref combatant2Copy, ref combatants); // assert if(combatant1Copy.Stanima == combatant1Copy.MaxStanima - 1 && combatant2Copy.Stanima == combatant2Copy.MaxStanima - 1 && combatants.Exists(x => x.CombatantID == combatant1Copy.CombatantID) && combatants.Exists(x => x.CombatantID == combatant2Copy.CombatantID)) { Assert.IsTrue(true); } else { Assert.Fail("AttackCleanUp removes combatants it's not supposed to remove"); } }
public void TestRemoveNameSpaceForSite() { // Create a new NameSpace object and create a new name space for a test site IInputContext context = DnaMockery.CreateDatabaseInputContext(); // Create the namespace object and call the add namespace method NameSpaces testNameSpace = new NameSpaces(context); NameSpaceItem newName = AddNameSpaceToSite(1, "category"); Assert.IsTrue(newName.ID > 0, "NameSpaceId is zero! Failed to create new name space. namespace being added = category"); // Now add some phrases to the namespace by adding some phrases to an article List<string> phrases = new List<string>(); phrases.Add("funny"); phrases.Add("sad"); phrases.Add("random"); phrases.Add("practical"); using (IDnaDataReader reader = context.CreateDnaDataReader("addkeyphrasestoarticle")) { // Add the phrases string keyPhrases = ""; foreach (string phrase in phrases) { keyPhrases += phrase + "|"; } keyPhrases = keyPhrases.TrimEnd('|'); reader.AddParameter("h2g2id", 5176); reader.AddParameter("keywords", keyPhrases); reader.AddParameter("namespaces", "category|category|category|category"); reader.Execute(); } // Now get all the phrases for a given namespace List<string> namespacePhrases = GetPhrasesForNameSpace(1, newName.ID, testNameSpace); Assert.IsTrue(namespacePhrases.Count == 4, "Get phrases for namespace failed to find all phrases"); // now compare the phrases with the known values. for (int i = 0; i < namespacePhrases.Count; i++) { // Check to make sure that we have all the same items in both lists Assert.IsTrue(phrases.Exists(delegate(string match) { return match == namespacePhrases[i]; }), "Failed to find known phrase in the found phrases. Phrase = " + namespacePhrases[i]); } // now remove the namespace and check to make sure that the phrases are removed form the article using (IDnaDataReader reader3 = context.CreateDnaDataReader("deletenamespaceandassociatedlinks")) { testNameSpace.RemoveNameSpaceForSite(1, newName.ID); // Now get all the phrases for the namespace we removed. NameSpaces testNameSpace2 = new NameSpaces(context); namespacePhrases = GetPhrasesForNameSpace(1, newName.ID, testNameSpace2); Assert.IsTrue(namespacePhrases.Count == 0, "The number of phrases returned from a remove namespace should be zero!"); } }
public void TestGetPhrasesforNameSpace() { // Create a new NameSpace object and create a new name space for a test site IInputContext context = DnaMockery.CreateDatabaseInputContext(); // Create the namespace object and call the add namespace method NameSpaces testNameSpace = new NameSpaces(context); NameSpaceItem newName = AddNameSpaceToSite(1, "category"); Assert.IsTrue(newName.ID > 0, "NameSpaceId is zero! Failed to create new name space. namespace being added = category"); // Now add some phrases to the namespace by adding some phrases to an article List<string> phrases = new List<string>(); phrases.Add("funny"); phrases.Add("sad"); phrases.Add("random"); phrases.Add("practical"); using (IDnaDataReader reader = context.CreateDnaDataReader("addkeyphrasestoarticle")) { // Add the phrases string keyPhrases = ""; foreach (string phrase in phrases) { keyPhrases += phrase + "|"; } keyPhrases = keyPhrases.TrimEnd('|'); reader.AddParameter("h2g2id", 5176); reader.AddParameter("keywords",keyPhrases); reader.AddParameter("namespaces", "category|category|category|category"); reader.Execute(); } List<string> namespacePhrases = GetPhrasesForNameSpace(1, newName.ID, testNameSpace); Assert.IsTrue(namespacePhrases.Count == 4, "Get phrases for namespace failed to find all phrases"); // now compare the phrases with the known values. for (int i = 0; i < namespacePhrases.Count; i++) { Assert.IsTrue(phrases.Exists(delegate(string match) { return match == namespacePhrases[i]; }), "Failed to find known phrase in the found phrases. Phrase = " + namespacePhrases[i]); } }
public void AttachNaClGDBTest() { PluginDebuggerGDB_Accessor target = new PluginDebuggerGDB_Accessor(dte_, properties_); string existingGDB = "AttachNaClGDBTest_existingGDB"; try { target.gdbProcess_ = TestUtilities.StartProcessForKilling(existingGDB, 20); string existingInitFileName = Path.GetTempFileName(); target.gdbInitFileName_ = existingInitFileName; // Visual studio won't allow adding a breakpoint unless it is associated with // an existing file and valid line number, so use BlankValidSolution. dte_.Solution.Open(naclSolution); string fileName = "main.cpp"; string functionName = "NaClProjectInstance::HandleMessage"; int lineNumber = 39; dte_.Debugger.Breakpoints.Add(Function: functionName); dte_.Debugger.Breakpoints.Add(Line: lineNumber, File: fileName); target.Attach(null, new PluginDebuggerBase.PluginFoundEventArgs(0)); Assert.IsTrue(File.Exists(target.gdbInitFileName_), "Init file not written"); var gdbCommands = new List<string>(File.ReadAllLines(target.gdbInitFileName_)); // Validate that the commands contain what we specified. // The syntax itself is not validated since this add-in is not responsible for // the syntax and it could change. Assert.IsTrue( gdbCommands.Exists(s => s.Contains(fileName) && s.Contains(lineNumber.ToString())), "Line breakpoint not properly set"); Assert.IsTrue( gdbCommands.Exists(s => s.Contains(functionName)), "Function breakpoint not properly set"); // Note fake assembly string should be double escaped when passed to gdb. Assert.IsTrue( gdbCommands.Exists(s => s.Contains(functionName)), @"fake\\Assembly\\String"); // Check that the pre-existing gdb process was killed and its init file cleaned up. Assert.IsFalse( TestUtilities.DoesProcessExist("python.exe", existingGDB), "Failed to kill existing GDB process"); Assert.IsFalse( File.Exists(existingInitFileName), "Failed to delete existing temp gdb init file"); } finally { if (dte_.Debugger.Breakpoints != null) { // Remove all breakpoints. foreach (EnvDTE.Breakpoint bp in dte_.Debugger.Breakpoints) { bp.Delete(); } } // Clean up file if not erased. if (!string.IsNullOrEmpty(target.gdbInitFileName_) && File.Exists(target.gdbInitFileName_)) { File.Delete(target.gdbInitFileName_); } // Kill the gdb process if not killed. if (target.gdbProcess_ != null && !target.gdbProcess_.HasExited) { target.gdbProcess_.Kill(); target.gdbProcess_.Dispose(); } } }
public void SearchOrderRetrievesOrderFromStartOrderIndex() { OrdersManagementDataSet ds = InitOrdersManagementDataSet(); OrdersService ordersService = new OrdersService(ds, new FakeProductService()); int ordersTotalCount; ICollection<Order> foundOrders = ordersService.SearchOrders("Order", 2, int.MaxValue, out ordersTotalCount); Assert.AreEqual(3, ordersTotalCount); Assert.AreEqual(1, foundOrders.Count); List<Order> searchableList = new List<Order>(foundOrders); Assert.IsFalse(searchableList.Exists(delegate(Order order) { return order.OrderId == 1; })); Assert.IsFalse(searchableList.Exists(delegate(Order order) { return order.OrderId == 2; })); Assert.IsTrue(searchableList.Exists(delegate(Order order) { return order.OrderId == 3; })); }
public void MasterVoteTest() { TaskNode node1 = new TaskNode(); TaskNode node2 = new TaskNode(); TaskNode node3 = new TaskNode(); TaskNode node4 = new TaskNode(); try { List<TaskNode> nodeList = new List<TaskNode>() { node2, node3, node4, }; Thread.Sleep(3000); Assert.AreEqual(Role.Master.ToString(), node1.NodeRole); node1.Shutdown(); Thread.Sleep(50000); Assert.IsTrue(nodeList.Exists(u => u.NodeRole == Role.Master.ToString())); } finally { node1.Shutdown(); node2.Shutdown(); node4.Shutdown(); node3.Shutdown(); } }
public void WhenInitialize_ThenExpectedPropertiesAreProtected() { var expected = new List<Property> { new Property { EntityName = "SSD.Domain.Student", Name = "StudentKey" }, new Property { EntityName = "SSD.Domain.Student", Name = "ServiceRequests" }, new Property { EntityName = "SSD.Domain.Student", Name = "StudentAssignedOfferings" }, new Property { EntityName = "SSD.Domain.ServiceOffering", Name = "StudentAssignedOfferings" } }; ResetDatabase(); Target.Dispose(); Target = new EducationDataContext(); var actual = Target.Properties.Where(p => p.IsProtected).ToList(); Assert.IsTrue(expected.All(p => actual.Exists(a => a.Name == p.Name && a.EntityName == p.EntityName))); Assert.IsFalse(actual.Any(a => !expected.Exists(p => p.Name == a.Name && p.EntityName == a.EntityName))); }
public void TestTupleVertexIndexes() { VoronoiWrapper vw = new VoronoiWrapper(); vw.AddSegment(0, 0, 0, 10); vw.AddSegment(0, 10, 10, 10); vw.AddSegment(10, 10, 10, 0); vw.AddSegment(10, 0, 0, 0); vw.AddSegment(0, 0, 5, 5); vw.AddSegment(5, 5, 10, 10); vw.ConstructVoronoi(); List<Tuple<double, double>> vertices = vw.GetVertices(); List<Tuple<int, int, int, int, Tuple<bool, bool, bool, int, int>>> edges = vw.GetEdges(); List<int> vertexIndexes = new List<int>(); foreach (var e in edges) { if(!vertexIndexes.Exists(v=> v==e.Item2)) vertexIndexes.Add(e.Item2); if (!vertexIndexes.Exists(v => v == e.Item3)) vertexIndexes.Add(e.Item3); } vertexIndexes.Remove(-1); vertexIndexes.Sort(); int minIndex = vertexIndexes.Min(); int maxIndex = vertexIndexes.Max(); Assert.AreEqual(0, minIndex); Assert.AreEqual(vertices.Count - 1, maxIndex); }
public void GetCustomersByNamePrefixWithQuotesSearchesCorrectlyAndPreventsInjection() { OrdersManagementDataSet ds = new OrdersManagementDataSet(); AddCustomer(ds, "21", "The Store"); AddCustomer(ds, "22", "The'se Cheeses"); AddCustomer(ds, "23", "The'se Cheeses International"); CustomerService customerService = new CustomerService(ds); ICollection<Customer> customers = customerService.GetCustomersByNamePrefix("THE'S"); Assert.IsNotNull(customers); Assert.AreEqual(2, customers.Count); List<Customer> searchableList = new List<Customer>(customers); Assert.IsNotNull(searchableList.Exists(delegate(Customer customer) { return customer.CustomerId == "22"; })); Assert.IsNotNull(searchableList.Exists(delegate(Customer customer) { return customer.CustomerId == "23"; })); }
public void EnumeratesThreeModulesWithDependencies() { var store = new MockConfigurationStore(); var module1 = new ModuleConfigurationElement("Module1.dll", "Test.Module1", "Module1", false); module1.Dependencies = new ModuleDependencyCollection( new[] { new ModuleDependencyConfigurationElement("Module2") }); var module2 = new ModuleConfigurationElement("Module2.dll", "Test.Module2", "Module2", false); module2.Dependencies = new ModuleDependencyCollection( new[] { new ModuleDependencyConfigurationElement("Module3") }); var module3 = new ModuleConfigurationElement("Module3.dll", "Test.Module3", "Module3", false); store.Modules = new[] { module3, module2, module1 }; IModuleEnumerator enumerator = new ConfigurationModuleEnumerator(store); var modules = new List<ModuleInfo>(enumerator.GetModules()); Assert.AreEqual(3, modules.Count); Assert.IsTrue(modules.Exists(module => module.ModuleName == "Module1")); Assert.IsTrue(modules.Exists(module => module.ModuleName == "Module2")); Assert.IsTrue(modules.Exists(module => module.ModuleName == "Module3")); }
private static bool CheckNodesNotInList(List<Node> nodes, params string[] nameArray) { if (nameArray != null && nameArray.Length > 0) { for (int i = 0; i < nameArray.Length; i++) { _existName = nameArray[i]; if (nodes.Exists(ExistNode)) { return false; } } } return true; }
public void SearchOrdersDoesALikeMatch() { OrdersManagementDataSet ds = InitOrdersManagementDataSet(); OrdersService ordersService = new OrdersService(ds, new FakeProductService()); ICollection<Order> foundOrders = ordersService.SearchOrders("Description"); List<Order> searchableList = new List<Order>(foundOrders); Assert.AreEqual(2, foundOrders.Count); Assert.IsTrue(searchableList.Exists(delegate(Order order) { return order.OrderId == 1; })); Assert.IsTrue(searchableList.Exists(delegate(Order order) { return order.OrderId == 2; })); Assert.IsFalse(searchableList.Exists(delegate(Order order) { return order.OrderId == 3; })); }
public void EnumeratesThreeModulesWithDependencies() { MockModuleInfoStore store = new MockModuleInfoStore(); ModuleConfigurationElement module1 = new ModuleConfigurationElement("Module1.Name", "Module1.Assembly", "Module1.VirtualPath"); module1.Dependencies = new ModuleDependencyCollection( new ModuleDependencyConfigurationElement[] {new ModuleDependencyConfigurationElement("Module2.Name")}); ModuleConfigurationElement module2 = new ModuleConfigurationElement("Module2.Name", "Module2.Assembly", "Module2.VirtualPath"); module2.Dependencies = new ModuleDependencyCollection( new ModuleDependencyConfigurationElement[] {new ModuleDependencyConfigurationElement("Module3.Name")}); ModuleConfigurationElement module3 = new ModuleConfigurationElement("Module3.Name", "Module3.Assembly", "Module3.VirtualPath"); store.Modules = new ModuleConfigurationElement[] {module3, module2, module1}; WebModuleEnumerator enumerator = new WebModuleEnumerator(store); List<IModuleInfo> modules = new List<IModuleInfo>(enumerator.EnumerateModules()); Assert.AreEqual(3, modules.Count); Assert.IsTrue(modules.Exists(delegate(IModuleInfo module) { return module.Name == "Module1.Name"; })); Assert.IsTrue(modules.Exists(delegate(IModuleInfo module) { return module.Name == "Module2.Name"; })); Assert.IsTrue(modules.Exists(delegate(IModuleInfo module) { return module.Name == "Module3.Name"; })); }
public void RegisterRequiredPermissionsRegistersOnePermissionSetWithTwoActions() { TestableModule module = new TestableModule(); MockPermissionCatalog permissionCatalog = new MockPermissionCatalog(); module.TestRegisterRequiredPermissions(permissionCatalog); Assert.AreEqual(1, permissionCatalog.RegisteredPermissions.Count); Assert.AreEqual("Reports", permissionCatalog.RegisteredSet.ModuleName); Assert.AreEqual(2, permissionCatalog.RegisteredSet.Actions.Count); List<Action> actions = new List<Action>(permissionCatalog.RegisteredSet.Actions); Assert.IsTrue(actions.Exists(delegate(Action action) { return action.RuleName == Constants.Permissions.AllowViewPaymentHistory; })); Assert.IsTrue(actions.Exists(delegate(Action action) { return action.RuleName == Constants.Permissions.AllowViewAccountsSummary; })); }
/// <summary> /// Compares the Media of card one with those of card two. /// </summary> /// <param name="one">The card one.</param> /// <param name="two">The card two.</param> /// <remarks>Documented by Dev03, 2008-09-29</remarks> private void CompareMedia(ICard one, ICard two) { List<IMedia> answerMedia = new List<IMedia>(); answerMedia.AddRange(two.AnswerMedia); foreach (IMedia media in one.AnswerMedia) { Assert.IsTrue( answerMedia.Exists( delegate(IMedia m) { bool isMatch = true; isMatch = isMatch && (m.Active == media.Active); isMatch = isMatch && (m.Default == media.Default); isMatch = isMatch && (m.Example == media.Example); isMatch = isMatch && (m.MimeType == media.MimeType); isMatch = isMatch && (m.MediaType == media.MediaType); isMatch = isMatch && (m.Stream.Length == media.Stream.Length); return isMatch; } ), String.Format("No match for answer Media item found in card {0}.", one.ToString())); } List<IMedia> questionMedia = new List<IMedia>(); questionMedia.AddRange(two.QuestionMedia); foreach (IMedia media in one.QuestionMedia) { Assert.IsTrue( questionMedia.Exists( delegate(IMedia m) { bool isMatch = true; isMatch = isMatch && (m.Active == media.Active); isMatch = isMatch && (m.Default == media.Default); isMatch = isMatch && (m.Example == media.Example); isMatch = isMatch && (m.MimeType == media.MimeType); isMatch = isMatch && (m.MediaType == media.MediaType); isMatch = isMatch && (m.Stream.Length == media.Stream.Length); return isMatch; } ), String.Format("No match for question Media item found in card {0}.", one.ToString())); } }
public void SearchOrderNotExceedMaximumOrdersCount() { OrdersManagementDataSet ds = InitOrdersManagementDataSet(); OrdersService ordersService = new OrdersService(ds, new FakeProductService()); int ordersTotalCount; ICollection<Order> foundOrders = ordersService.SearchOrders("Order", 0, 2, out ordersTotalCount); Assert.AreEqual(3, ordersTotalCount); Assert.AreEqual(2, foundOrders.Count); List<Order> searchableList = new List<Order>(foundOrders); Assert.IsTrue(searchableList.Exists(delegate(Order order) { return order.OrderId == 1; })); Assert.IsTrue(searchableList.Exists(delegate(Order order) { return order.OrderId == 2; })); Assert.IsFalse(searchableList.Exists(delegate(Order order) { return order.OrderId == 3; })); }