public void AllConditionDelegatesAreExecutedToFindCorrectFactory(int numberOfRegisteredReactionFactories) { var callCounter = 0; bool fakeConditionDelegate(Stream inputStream) { callCounter++; return(false); } var testedProvider = new ThreadsafeBagServerReactionProvider(); for (var i = 0; i < numberOfRegisteredReactionFactories; i++) { testedProvider.RegisterServerReactionFactoryForCondition((Stream inputStream) => new MemoryStream(), fakeConditionDelegate); } using var fakeInputStream = new MemoryStream(); // This will throw an exception, as no matching condition has been registered, so without a try block, the test would fail. try { testedProvider.CreateServerReaction(fakeInputStream); } catch (ServerReactionException exc) when(exc.Message.Equals("The server could not create a reaction to a client's input: None of the registered factories' conditions matched the input stream.")) { } callCounter.Should().Be(numberOfRegisteredReactionFactories); }
public void CreatingReactionReturnsStreamFromCorrectFactory() { using var expectedStream = new MemoryStream(); var testedProvider = new ThreadsafeBagServerReactionProvider(); testedProvider.RegisterServerReactionFactoryForCondition((Stream inputStream) => new MemoryStream(), (Stream inputStream) => false); testedProvider.RegisterServerReactionFactoryForCondition((Stream inputStream) => new MemoryStream(), (Stream inputStream) => false); testedProvider.RegisterServerReactionFactoryForCondition((Stream inputStream) => expectedStream, (Stream inputStream) => true); testedProvider.RegisterServerReactionFactoryForCondition((Stream inputStream) => new MemoryStream(), (Stream inputStream) => false); testedProvider.RegisterServerReactionFactoryForCondition((Stream inputStream) => new MemoryStream(), (Stream inputStream) => false); using var fakeInputSream = new MemoryStream(); var receivedReaction = testedProvider.CreateServerReaction(fakeInputSream); receivedReaction.Should().Be(expectedStream); }
public void RegisteringReactionFactoryThrowsExceptionIfReactionFactoryIsNull() { var provider = new ThreadsafeBagServerReactionProvider(); Action registration = () => provider.RegisterServerReactionFactoryForCondition(null, (Stream inputStream) => true); registration.Should() .ThrowExactly <ArgumentNullException>() .Which.ParamName.Should().Be("reactionFactory"); }
public void RegisteringReactionFactoryThrowsExceptionIfConditionDelegateIsNull() { var provider = new ThreadsafeBagServerReactionProvider(); Action registration = () => provider.RegisterServerReactionFactoryForCondition((Stream inputStream) => new MemoryStream(), null); registration.Should() .ThrowExactly <ArgumentNullException>() .Which.ParamName.Should().Be("conditionDelegate"); }
public void CreatingReactionThrowsExceptionIfNoMatchingConditionHasBeenRegistered() { var testedProvider = new ThreadsafeBagServerReactionProvider(); testedProvider.RegisterServerReactionFactoryForCondition((Stream input) => new MemoryStream(), (Stream input) => false); using var fakeInputStream = new MemoryStream(); Action reactionCreation = () => testedProvider.CreateServerReaction(fakeInputStream); reactionCreation.Should().ThrowExactly <ServerReactionException>() .WithMessage("The server could not create a reaction to a client's input: None of the registered factories' conditions matched the input stream."); }