public async Task ShouldPacketBeFilterd_False() { DHCPv6Packet packet = DHCPv6Packet.AsInner(1, DHCPv6PacketTypes.Solicit, new List <DHCPv6PacketOption>()); List <Mock <IDHCPv6PacketFilter> > filterMocks = new List <Mock <IDHCPv6PacketFilter> >(); for (int i = 0; i < 10; i++) { Mock <IDHCPv6PacketFilter> filterMock = new Mock <IDHCPv6PacketFilter>(MockBehavior.Strict); filterMock.Setup(x => x.ShouldPacketBeFiltered(packet)).ReturnsAsync(false).Verifiable(); filterMocks.Add(filterMock); } IDHCPv6PacketFilterEngine engine = new SimpleDHCPv6PacketFilterEngine(filterMocks.Select(x => x.Object), Mock.Of <ILogger <SimpleDHCPv6PacketFilterEngine> >()); (bool, string)result = await engine.ShouldPacketBeFilterd(packet); Assert.False(result.Item1); Assert.True(String.IsNullOrEmpty(result.Item2)); foreach (var item in filterMocks) { item.Verify(); } }
public void AddFilter_Failed_Null() { IDHCPv6PacketFilterEngine engine = new SimpleDHCPv6PacketFilterEngine( Mock.Of <ILogger <SimpleDHCPv6PacketFilterEngine> >()); Assert.ThrowsAny <ArgumentNullException>(() => engine.AddFilter(null)); }
public async Task ShouldPacketBeFilterd_True(Int32 filterAmount, Int32 index) { DHCPv6Packet packet = DHCPv6Packet.AsInner(1, DHCPv6PacketTypes.Solicit, new List <DHCPv6PacketOption>()); List <Mock <IDHCPv6PacketFilter> > filterMocks = new List <Mock <IDHCPv6PacketFilter> >(); for (int i = 0; i < filterAmount; i++) { Mock <IDHCPv6PacketFilter> filterMock = new Mock <IDHCPv6PacketFilter>(MockBehavior.Strict); filterMock.Setup(x => x.ShouldPacketBeFiltered(packet)).ReturnsAsync(i == index).Verifiable(); filterMocks.Add(filterMock); } IDHCPv6PacketFilterEngine engine = new SimpleDHCPv6PacketFilterEngine(filterMocks.Select(x => x.Object), Mock.Of <ILogger <SimpleDHCPv6PacketFilterEngine> >()); (bool, string)result = await engine.ShouldPacketBeFilterd(packet); Assert.True(result.Item1); Assert.False(String.IsNullOrEmpty(result.Item2)); for (int i = 0; i < filterMocks.Count; i++) { var filterMock = filterMocks[i]; if (i <= index) { filterMock.Verify(); } else { filterMock.Verify(x => x.ShouldPacketBeFiltered(packet), Times.Never); } } }
public void AddFilter() { IDHCPv6PacketFilterEngine engine = new SimpleDHCPv6PacketFilterEngine( Mock.Of <ILogger <SimpleDHCPv6PacketFilterEngine> >()); IDHCPv6PacketFilter filter = Mock.Of <IDHCPv6PacketFilter>(MockBehavior.Strict); Assert.Empty(engine.Filters); engine.AddFilter(filter); Assert.Single(engine.Filters); Assert.Equal(filter, engine.Filters.First()); }
public void Constructor() { List <IDHCPv6PacketFilter> filters = new List <IDHCPv6PacketFilter>(); for (int i = 0; i < 10; i++) { filters.Add(Mock.Of <IDHCPv6PacketFilter>(MockBehavior.Strict)); } IDHCPv6PacketFilterEngine engine = new SimpleDHCPv6PacketFilterEngine(filters, Mock.Of <ILogger <SimpleDHCPv6PacketFilterEngine> >()); Assert.Equal(filters.Count, engine.Filters.Count()); for (int i = 0; i < filters.Count; i++) { Assert.Equal(filters[i], engine.Filters.ElementAt(i)); } }