public void CreateRule_GivenInvalidRuleName_ThrowsInvalidRuleException() { // Arrange dynamic content = new ExpandoObject(); content.Prop1 = 123; content.Prop2 = "Sample string"; content.Prop3 = 500.34m; RuleDataModel <ContentType, ConditionType> ruleDataModel = new RuleDataModel <ContentType, ConditionType> { Content = content, ContentType = ContentType.ContentTypeSample, DateBegin = new DateTime(2020, 1, 1), DateEnd = null, Name = null, Priority = 1, RootCondition = null }; RuleFactory <ContentType, ConditionType> ruleFactory = new RuleFactory <ContentType, ConditionType>(); // Act InvalidRuleException invalidRuleException = Assert.Throws <InvalidRuleException>(() => ruleFactory.CreateRule(ruleDataModel)); // Assert invalidRuleException.Should().NotBeNull(); invalidRuleException.Errors.Should().NotBeEmpty(); invalidRuleException.Errors.Should().Contain("'Name' must not be empty."); }
public void SerializeDeserialize_InvalidRuleException_Correctly() { // Arrange const string MSG = "error"; var ex = new InvalidRuleException(MSG) { RuleType = typeof(int), TargetType = typeof(string) }; // Act using (var ms = new MemoryStream()) { var formatter = new BinaryFormatter(); formatter.Serialize(ms, ex); ms.Flush(); ms.Position = 0; ex = (InvalidRuleException)formatter.Deserialize(ms); } // Assert Assert.Equal(MSG, ex.Message); Assert.Equal(typeof(int), ex.RuleType); Assert.Equal(typeof(string), ex.TargetType); }