public void ShouldThrowCodeContractViolationException() { //Arrange var notifier = new ExceptionNotifier(); //Act and assert Assert.Throws <CodeContractViolationException>(() => notifier.Notify(TestDataFactory.CreateViolationData())); }
public void ShouldExecuteLoggingOnCustomLoggerOnlyOnce() { //Arrange var fakeLogger = A.Fake <ILogger>(); var notifier = new LogNotifier(fakeLogger); var violationData = TestDataFactory.CreateViolationData(); //Act notifier.Notify(violationData); //Assert A.CallTo(() => fakeLogger.LogViolation(null)).WithAnyArguments().MustHaveHappened(Repeated.Exactly.Once); }
public void ShouldExecuteLogginOnCustomLoggerWithData() { //Arrange var fakeLogger = A.Fake <ILogger>(); var notifier = new LogNotifier(fakeLogger); var violationData = TestDataFactory.CreateViolationData(); //Act notifier.Notify(violationData); //Assert A.CallTo(() => fakeLogger.LogViolation(violationData)).MustHaveHappened(); }
public void ShouldExecuteDebugAssertWithErrorMessage() { //Arrange var copyOfListners = Debug.Listeners.Cast <TraceListener>().ToArray(); Debug.Listeners.Clear(); var testListener = new TestTraceListner(); Debug.Listeners.Add(testListener); const string expectedErrorMessage = "DebugAssertErrorMessage"; var notifier = new DebugAssertNotifier(); //Act notifier.Notify(TestDataFactory.CreateViolationData(errorMessage: expectedErrorMessage)); //Assert Debug.Listeners.Clear(); Debug.Listeners.AddRange(copyOfListners); Assert.Equal(expectedErrorMessage, testListener.LastMessage); }
public void ThrownExceptionShouldHaveNameFromData() { //Arrange const string expectedName = "VariableName"; var notifier = new ExceptionNotifier(); //Act var exception = Assert.Throws <CodeContractViolationException>(() => notifier.Notify(TestDataFactory.CreateViolationData(name: expectedName))); //Assert Assert.Equal(expectedName, exception.Name); }
public void ThrownExceptionShouldHaveValueFromData() { //Arrange const int expectedValue = 123456; var notifier = new ExceptionNotifier(); //Act var exception = Assert.Throws <CodeContractViolationException>(() => notifier.Notify(TestDataFactory.CreateViolationData(expectedValue))); //Assert Assert.Equal(expectedValue, exception.Value); }
public void ThrownExceptionShouldHaveMessageFromData() { //Arrange const string expectedErrorMessage = "ExpectedErrorMessage"; var notifier = new ExceptionNotifier(); //Act var exception = Assert.Throws <CodeContractViolationException>(() => notifier.Notify(TestDataFactory.CreateViolationData(errorMessage: expectedErrorMessage))); //Assert Assert.Equal(expectedErrorMessage, exception.Message); }