public void Given_A_Match_object_with_predicate_handler_has_been_added_When_adding_handler_Then_it_succeeds() { var builder = new MatchBuilder(new DummyCompiler <object>()); builder.Match <object>(_ => { }, _ => true); //Although we have added a handler that matches objects, the predicate makes it uncertain if all objects matches //so adding a handler is ok. builder.Match <object>(_ => { }); }
public void Given_A_Match_object_handler_has_been_added_When_adding_handler_Then_it_fails() { var builder = new MatchBuilder(new DummyCompiler <object>()); builder.Match <object>(_ => { }); //As we have added a handler that matches everything, adding another handler is pointless, so //the builder should throw an exception. Assert.Throws <InvalidOperationException>(() => ((Action)(() => builder.Match <object>(_ => { })))()); }
public void Given_builder_has_built_When_adding_handler_Then_it_fails() { var builder = new MatchBuilder(new DummyCompiler <object>()); builder.Match <object>(_ => { }); builder.Build(); //As we have built, no more handlers should be accepted Assert.Throws <InvalidOperationException>(() => ((Action)(() => builder.Match <string>(_ => { })))()); Assert.Throws <InvalidOperationException>(() => ((Action)(() => builder.MatchAny(_ => { })))()); }
public void Given_an_IEnumerable_MatchBuilder_When_trying_to_match_a_type_that_is_an_IEnumerable_Then_it_succeeds() { var builder = new MatchBuilder <IEnumerable>(new DummyCompiler <IEnumerable>()); builder.Match(typeof(List <string>), _ => { }); }
public void Given_an_IEnumerable_MatchBuilder_When_trying_to_match_a_type_that_is_not_an_IEnumerable_Then_it_fails() { var builder = new MatchBuilder <IEnumerable>(new DummyCompiler <IEnumerable>()); Assert.Throws <ArgumentException>(() => ((Action)(() => builder.Match(typeof(int), _ => { })))()); }