public void Returns_uncertified_deployments_by_application_and_environment() { var criteria = new CriterionSet(); criteria.AddCriterion(new Criterion(Deployment.APPLICATION, "SampleApp1")); criteria.AddCriterion(new Criterion(Deployment.ENVIRONMENT, "Environment")); criteria.AddCriterion(new Criterion(Deployment.CERTIFIED_ON, null)); criteria.AddCriterion(new Criterion(Deployment.RESULT, DeploymentResult.Success)); criteria.OrderBy = Deployment.DEPLOYED_ON; criteria.SortOrder = SortOrder.Descending; var foundDeployments = new Deployment[0]; var mocks = new MockRepository(); var repository = mocks.CreateMock<IPersistentObjectRepository>(); using (mocks.Record()) { repository.ConfigurationFile = "deployer.hibernate.cfg.xml"; Expect.Call(repository.FindAll<Deployment>(criteria)).Return(foundDeployments); } using (mocks.Playback()) { IDeploymentRepository deploymentRepository = new DeploymentRepository(repository); var deployments = deploymentRepository.FindSuccessfulUncertified("SampleApp1", "Environment"); Assert.That(deployments, Is.SameAs(foundDeployments)); } mocks.VerifyAll(); }
public IEnumerable<ApplicationInstance> GetByHostHeader(string uniqueHostHeader) { var criteria = new CriterionSet(); criteria.AddCriterion(new Criterion(ApplicationInstance.UniqueHostHeaderAttribute, uniqueHostHeader)); IEnumerable<ApplicationInstance> instances = _objectRepository.FindAll<ApplicationInstance>(criteria); return instances; }
public ApplicationInstance GetByMaintenanceHostHeaderAndMachineName(string maintenanceHostHeader, string machineName) { var criteria = new CriterionSet(); criteria.AddCriterion(new Criterion(ApplicationInstance.MachineNameAttribute, machineName)); criteria.AddCriterion(new Criterion(ApplicationInstance.MaintenanceHostHeaderAttribute, maintenanceHostHeader)); var instance = _objectRepository.FindFirst<ApplicationInstance>(criteria); return instance; }
private CriterionSet getCriteria(string application, string environment) { var criteria = new CriterionSet(); criteria.AddCriterion(new Criterion(Deployment.APPLICATION, application)); criteria.AddCriterion(new Criterion(Deployment.ENVIRONMENT, environment)); criteria.OrderBy = Deployment.DEPLOYED_ON; criteria.SortOrder = SortOrder.Descending; return criteria; }
public void Correctly_compares_equal_sets_both_having_null() { CriterionSet set1 = new CriterionSet(); CriterionSet set2 = new CriterionSet(); set1.AddCriterion(new Criterion("A1", null, ComparisonOperator.Equal)); set2.AddCriterion(new Criterion("A1", null, ComparisonOperator.Equal)); Assert.That(set1, Is.EqualTo(set2)); Assert.That(set2, Is.EqualTo(set1)); }
public void Property_accessors_work() { CriterionSet criteria = new CriterionSet(); Assert.AreEqual(null, criteria.OrderBy); criteria.OrderBy = "OrderBy"; Assert.AreEqual("OrderBy", criteria.OrderBy); Assert.AreEqual(null, criteria.SortOrder); criteria.SortOrder = SortOrder.Descending; Assert.AreEqual(SortOrder.Descending, criteria.SortOrder); }
public void Calculates_hash_code_based_on_criterion() { CriterionSet set1 = new CriterionSet(); Criterion criterion1 = new Criterion("A1", "V1", ComparisonOperator.Equal); Criterion criterion2 = new Criterion("A2", "V2", ComparisonOperator.Equal); set1.AddCriterion(criterion1); set1.AddCriterion(criterion2); Assert.That(set1.GetHashCode(), Is.EqualTo(criterion1.GetHashCode() + criterion2.GetHashCode())); }
public void Can_add_criterion() { CriterionSet set = new CriterionSet(); Criterion criterion1 = new Criterion("A1", "V1"); Criterion criterion2 = new Criterion("A2", "V2"); set.AddCriterion(criterion1); set.AddCriterion(criterion2); Assert.That(set.GetCriteria(), Is.EquivalentTo(new Criterion[] { criterion1, criterion2 })); }
public void Correctly_compares_equal_sets() { CriterionSet set1 = new CriterionSet(); CriterionSet set2 = new CriterionSet(); set1.AddCriterion(new Criterion("A1", "V1", ComparisonOperator.Equal)); set1.AddCriterion(new Criterion("A2", "V2", ComparisonOperator.Equal)); set2.AddCriterion(new Criterion("A1", "V1", ComparisonOperator.Equal)); set2.AddCriterion(new Criterion("A2", "V2", ComparisonOperator.Equal)); Assert.That(set1, Is.EqualTo(set2)); Assert.That(set2, Is.EqualTo(set1)); }
public override bool Equals(object obj) { CriterionSet other = (CriterionSet)obj; IEnumerable <Criterion> criteria = GetCriteria(); IEnumerable <Criterion> otherCriteria = other.GetCriteria(); if (EnumerableHelper.Count(criteria) != EnumerableHelper.Count(otherCriteria)) { return(false); } else if (SortOrder != other.SortOrder || OrderBy != other.OrderBy) { return(false); } else { bool criterionSetsEqual = true; foreach (Criterion criterion in criteria) { bool matchingCriterionFound = false; foreach (Criterion otherCriterion in otherCriteria) { object value1 = otherCriterion.Value; object value2 = criterion.Value; bool keyMatches = otherCriterion.Attribute == criterion.Attribute; bool valueMatches = (value1 == null && value2 == null) || (value1 != null && value1.Equals(value2)); bool operatorMatches = otherCriterion.Operator == criterion.Operator; if (keyMatches && valueMatches && operatorMatches) { matchingCriterionFound = true; break; } } if (!matchingCriterionFound) { criterionSetsEqual = false; break; } } return(criterionSetsEqual); } }
public void Correctly_compares_unequal_sets_based_on_sorting() { CriterionSet set1 = new CriterionSet(); CriterionSet set2 = new CriterionSet(); set1.OrderBy = "A1"; set2.OrderBy = "B1"; set1.SortOrder = SortOrder.Ascending; set2.SortOrder = SortOrder.Ascending; set1.AddCriterion(new Criterion("A1", null, ComparisonOperator.Equal)); set2.AddCriterion(new Criterion("A1", null, ComparisonOperator.Equal)); Assert.That(set1, Is.Not.EqualTo(set2)); Assert.That(set2, Is.Not.EqualTo(set1)); }
public void Can_correctly_gets_application_instances_by_machine_name_and_maintenance_host_header() { var instance = new ApplicationInstance(); var criteria = new CriterionSet(); criteria.AddCriterion(new Criterion("MachineName", "MyMachine")); criteria.AddCriterion(new Criterion("MaintenanceHostHeader", "MyDomain")); var mocks = new MockRepository(); var objectRepository = mocks.CreateMock<IPersistentObjectRepository>(); using (mocks.Record()) { objectRepository.ConfigurationFile = "webmanagement.hibernate.cfg.xml"; Expect.Call(objectRepository.FindFirst<ApplicationInstance>(criteria)).Return(instance); } using (mocks.Playback()) { IApplicationInstanceRepository repository = new ApplicationInstanceRepository(objectRepository); var actualInstance = repository.GetByMaintenanceHostHeaderAndMachineName("MyDomain", "MyMachine"); Assert.That(actualInstance, Is.SameAs(instance)); } }
public void Correctly_compares_unequal_sets_with_same_number_of_elements_but_different_number_of_values() { CriterionSet set1 = new CriterionSet(); CriterionSet set2 = new CriterionSet(); set1.AddCriterion(new Criterion("A1", "V1", ComparisonOperator.Equal)); set1.AddCriterion(new Criterion("A2", "V2", ComparisonOperator.Equal)); set2.AddCriterion(new Criterion("A1", "V1", ComparisonOperator.Equal)); Assert.That(set1, Is.Not.EqualTo(set2)); Assert.That(set2, Is.Not.EqualTo(set1)); }
public void Can_correctly_gets_application_instances_by_host_header() { var instance1 = new ApplicationInstance(); var instance2 = new ApplicationInstance(); var instances = new[] { instance1, instance2 }; var criteria = new CriterionSet(); criteria.AddCriterion(new Criterion("UniqueHostHeader", "MyHostHeader")); var mocks = new MockRepository(); var objectRepository = mocks.CreateMock<IPersistentObjectRepository>(); using (mocks.Record()) { objectRepository.ConfigurationFile = "webmanagement.hibernate.cfg.xml"; Expect.Call(objectRepository.FindAll<ApplicationInstance>(criteria)).Return(instances); } using (mocks.Playback()) { IApplicationInstanceRepository repository = new ApplicationInstanceRepository(objectRepository); IEnumerable<ApplicationInstance> actualInstances = repository.GetByHostHeader("MyHostHeader"); EnumerableAssert.That(actualInstances, Is.EqualTo(instances)); } }
public void Correctly_compares_complex_equal_sets() { CriterionSet set1 = new CriterionSet(); CriterionSet set2 = new CriterionSet(); string myString = "abc"; set1.AddCriterion(new Criterion("A1", myString)); set1.AddCriterion(new Criterion("A2", new DateTime(2007, 4, 15), ComparisonOperator.GreaterThan)); set2.AddCriterion(new Criterion("A1", myString)); set2.AddCriterion(new Criterion("A2", new DateTime(2007, 4, 15), ComparisonOperator.GreaterThan)); Assert.That(set1, Is.EqualTo(set2)); Assert.That(set2, Is.EqualTo(set1)); }
public void Correctly_compares_empty_set_with_non_empty_set() { CriterionSet set1 = new CriterionSet(); CriterionSet set2 = new CriterionSet(); set2.AddCriterion(new Criterion("A1", "V1", ComparisonOperator.Equal)); Assert.That(set1, Is.Not.EqualTo(set2)); Assert.That(set2, Is.Not.EqualTo(set1)); }
public void Does_not_add_null_valued_criteria() { Criterion nullCriterion = new Criterion("A1", null, ComparisonOperator.Equal); CriterionSet set1 = new CriterionSet(); set1.AddCriterion(nullCriterion); Assert.That(set1.GetCriteria(), Is.EqualTo(new Criterion[] { nullCriterion })); }
public void Correctly_compares_equal_empty_sets() { CriterionSet set1 = new CriterionSet(); CriterionSet set2 = new CriterionSet(); Assert.That(set1, Is.EqualTo(set2)); Assert.That(set2, Is.EqualTo(set1)); }