public void LogEvent_WithNullEventName_ThrowsArgumentNullException() { // arrange var broadcaster = new EAEPBroadcaster("host", "application", new MulticastSettings("192.168.0.1", 21, 1)); try { // act broadcaster.LogEvent(null); // assert Assert.Fail(); } catch(ArgumentNullException) { } }
public void LogEvent() { // arrange const string application = "signUp"; const string host = "local"; const string eventName = "buttonClick"; var timeStamp = new DateTime(2000, 1, 1); var expectedMessage = new EAEPMessage(timeStamp, host, application, eventName); expectedMessage.Parameters["name1"] = "value1"; expectedMessage.Parameters["name2"] = "value2"; var expectedBytes = Encoding.UTF8.GetBytes(expectedMessage.ToString()); var mockMulticaster = new Mock<IMulticastSender>(); var broadcaster = new EAEPBroadcaster(host, application, mockMulticaster.Object); // act broadcaster.LogEvent(timeStamp, eventName, new EventParameter("name1", "value1"), new EventParameter("name2", "value2")); // assert mockMulticaster.Verify(m => m.Send(expectedBytes), Times.Once()); }
public void LogEvent_IMulticastThrowsSocketException() { // arrange var mockMulticaster = new Mock<IMulticastSender>(); mockMulticaster.Setup(m => m.Send(It.IsAny<byte[]>())).Throws(new SocketException()); var broadcaster = new EAEPBroadcaster("host", "application", mockMulticaster.Object); try { // act broadcaster.LogEvent("someEvent"); } catch(SocketException) { // assert Assert.Fail(); } }