Esempio n. 1
0
        public void AddSerializer_WithSameSerializerAlreadyInCache_DoesNotAddDuplicate()
        {
            // Arrange
            var cache = new SerializerCache();

            cache.AddSerializer(serializer);

            // Act
            cache.AddSerializer(serializer);

            // Assert
            Assert.That(cache.AllSerializers.Count(), Is.EqualTo(1));
        }
Esempio n. 2
0
        public void AddSerializer_WithDifferentInstancePOfSerializerAlreadyInCache_DoesNotAddDuplicate()
        {
            // Arrange
            var cache = new SerializerCache();
            var otherMockSerializer = new Mock <ISerializer>();

            otherMockSerializer.Setup(m => m.Descriptor).Returns(descriptor);
            cache.AddSerializer(serializer);

            // Act
            cache.AddSerializer(otherMockSerializer.Object);

            // Assert
            Assert.That(cache.AllSerializers.Count(), Is.EqualTo(1));
        }
Esempio n. 3
0
        public void AddSerializer_WithSerializer_DoesNotThrow()
        {
            // Arrange
            var cache = new SerializerCache();

            // Act
            TestDelegate addSerializer = () => cache.AddSerializer(serializer);

            // Assert
            Assert.That(addSerializer, Throws.Nothing);
        }
Esempio n. 4
0
        public void AddSerializer_WithNullSerializer_ThrowsArgumentNullException()
        {
            // Arrange
            var cache = new SerializerCache();

            // Act
            TestDelegate addSerializer = () => cache.AddSerializer(null);

            // Assert
            Assert.That(addSerializer, Throws.ArgumentNullException);
        }
Esempio n. 5
0
        public void AddSerializer_WithNoOtherSerializers_SetsToDefault()
        {
            // Arrange
            var cache = new SerializerCache();

            // Act
            cache.AddSerializer(serializer);
            var defaultSerializer = cache.DefaultSerializer;

            // Assert
            Assert.That(serializer, Is.EqualTo(defaultSerializer));
        }
Esempio n. 6
0
        public async Task SenderReceiver_WhenBoundAndConnected_PassesMessage()
        {
            // Arrange
            var    responseStr     = "Hello, World!";
            var    requestStr      = "Hello";
            var    receivedRequest = string.Empty;
            ushort port            = 6555;
            var    called          = false;

            mockRequestDispatcher
            .Setup(m => m.Handle(ref It.Ref <RequestTask> .IsAny))
            .Callback(new Handler((ref RequestTask task) => {
                called          = true;
                receivedRequest = (string)task.Request;
                task.ResponseSender(responseStr);
            }));

            var packageFactory  = new PackageFactory();
            var serializer      = new DotNetSerializer();
            var serializerCache = new SerializerCache();
            var messageFactory  = new NetMQMessageFactory(serializerCache, packageFactory);
            var sender          = new NetMQSender(new DealerSocket(), messageFactory);
            var receiver        = new NetMQReceiver(new RouterSocket(), messageFactory, requestDispatcher);
            var poller          = new NetMQPoller();

            serializerCache.AddSerializer(serializer);

            sender.AddAddress(TcpAddress.Localhost(port));
            sender.InitializeConnection();

            receiver.AddAddress(TcpAddress.Wildcard(port));
            receiver.InitializeConnection();

            poller.Add(sender.PollableSocket);
            poller.Add(receiver.PollableSocket);
            poller.RunAsync();

            var package = new DataPackage <string>(new GuidPackageId(), requestStr);

            // Act
            var response = await sender.SendAndReceive(package, TimeSpan.FromSeconds(5));

            // Cleanup
            poller.StopAsync();
            sender.TerminateConnection();
            receiver.TerminateConnection();

            // Assert
            Assert.That(called, Is.True);
            Assert.That(receivedRequest, Is.EqualTo(requestStr));
            Assert.That((string)response, Is.EqualTo(responseStr));
        }
Esempio n. 7
0
        public void SerializerFor_WithSerializerAdded_ReturnsSameInstance()
        {
            // Arrange
            var cache = new SerializerCache();

            cache.AddSerializer(serializer);

            // Act
            var hasSerializer = cache.SerializerFor("test", out var returnedSerializer);

            // Assert
            Assert.That(returnedSerializer, Is.SameAs(serializer));
        }
Esempio n. 8
0
        public void SerializerFor_WithSerializerAdded_ReturnsTrue()
        {
            // Arrange
            var cache = new SerializerCache();

            cache.AddSerializer(serializer);

            // Act
            var hasSerializer = cache.SerializerFor("test", out var returnedSerializer);

            // Assert
            Assert.That(hasSerializer, Is.True);
        }