public async Task Given_ThePacketIsAUniverseDiscoveryPacket_When_MulticastSendIPV4IsCalled_Then_ThePacketIsSent()
		{
			var expectedUniverse = UniverseDiscoveryPacket.DiscoveryUniverse;
			var packet = new UniverseDiscoveryPacket();
			packet.UniverseDiscoveryLayer.Universes = new UInt16[] { 1 };
			packet.FramingLayer.SourceName = "Source";
			byte[] expectedBytes = new byte[packet.Length];
			packet.Write(expectedBytes);

			var expectedIP = IPAddress.Parse("127.0.0.1");

			var udpWrapper = Mock.Of<IUdpWrapper>();
			var addressProvider = Mock.Of<ISacnMulticastAddressProvider>(x =>
				x.GetMulticastAddress(
					It.Is<UInt16>(universe => universe == expectedUniverse)
				) == expectedIP

			);
			var sender = new TestMulticastSacnSender(udpWrapper, addressProvider);
			await sender.Send(packet);

			Mock.Get(udpWrapper)
				.Verify(x => x.Send(
					It.Is<IPEndPoint>(x => x.Address == expectedIP && x.Port == 5568),
					It.Is<ReadOnlyMemory<byte>>(x => x.ToArray().SequenceEqual(expectedBytes))
				));
		}
示例#2
0
        public void When_WriteIsCalled_Then_TheDataIsCorrect()
        {
            byte[] CID        = Enumerable.Range(1, 12).Select(x => (byte)x).ToArray();
            var    sourceName = "This is a good enough source name";
            byte   page       = 1;
            byte   lastPage   = 45;

            UInt16[] universes = Enumerable.Range(25, 25)
                                 .Select(x => (UInt16)x)
                                 .ToArray();

            var packet = new UniverseDiscoveryPacket();

            packet.RootLayer.CID                    = CID;
            packet.FramingLayer.SourceName          = sourceName;
            packet.UniverseDiscoveryLayer.Page      = page;
            packet.UniverseDiscoveryLayer.LastPage  = page;
            packet.UniverseDiscoveryLayer.Universes = universes;

            var expectedBytes = GetUniverseDiscoveryPacket(CID, sourceName, page, lastPage, universes);

            using var owner = MemoryPool <byte> .Shared.Rent(packet.Length);

            var bytes = owner.Memory.Span.Slice(0, packet.Length);

            packet.Write(bytes);

            Assert.Equal(expectedBytes.ToArray(), bytes.ToArray());
        }
        public async Task Given_ThePacketIsUniverseDiscoveryPacket_When_UnicastSendIsCalled_Then_ThePacketIsSent()
        {
            var expectedAddress = new IPAddress(new byte[] { 1, 2, 3, 4 });
            var packet          = new UniverseDiscoveryPacket();

            packet.UniverseDiscoveryLayer.Universes = new UInt16[] { 1, 2, 3, 4 };
            packet.FramingLayer.SourceName          = "Source";
            byte[] expectedBytes = new byte[packet.Length];
            packet.Write(expectedBytes);

            var udpWrapper = Mock.Of <IUdpWrapper>();
            var sender     = new UnicastSacnSender(udpWrapper, expectedAddress);
            await sender.Send(packet);

            Mock.Get(udpWrapper)
            .Verify(x => x.Send(
                        It.Is <IPEndPoint>(x => x.Address == expectedAddress && x.Port == 5568),
                        It.Is <ReadOnlyMemory <byte> >(x => x.ToArray().SequenceEqual(expectedBytes))
                        ));
        }