public void NeagtedAdHocSpecificationIsSerializable() { var testSpecification1 = new AdHocSpecification <string>(n => n == "it fails"); var testSpecification = new NegateSpecification <string>(testSpecification1); // serialize and deserialize the spec var serializedSpecification = Serialize(testSpecification); var deserializedSpecification = Deserialize <Specification <string> >(serializedSpecification); Assert.That(deserializedSpecification.IsSatisfiedBy("it works"), Is.True); Assert.That(deserializedSpecification.IsSatisfiedBy("it fails"), Is.False); }
public void NegateSpecificationTestNegateSpecification() { // arrange var specFirstName = new AdHocSpecification <Sample>(x => x.FirstName.StartsWith("J")); var spec = new NegateSpecification <Sample>(specFirstName); // act var resultFirstName = TestData.List.Where(specFirstName.IsSatisfied()).OrderBy(c => c.FirstName); var result = TestData.List.Where(spec.IsSatisfied()).OrderBy(c => c.FirstName); // assert Assert.That(resultFirstName.Count(), Is.EqualTo(2)); Assert.That(resultFirstName.First().FirstName, Is.EqualTo("Jose")); Assert.That(resultFirstName.Last().FirstName, Is.EqualTo("Julian")); Assert.That(result.Count(), Is.EqualTo(1)); Assert.That(result.First().FirstName, Is.EqualTo("Manuel")); Assert.That(result.First().LastName, Is.EqualTo("Rivera")); }