Ejemplo n.º 1
0
        public void Handle_ReturnsTrueWhenElementAdded(bool added)
        {
            // arrange
            var request   = new InsertRequest();
            var processor = new InsertProcessor();
            var storage   = Substitute.For <IStorage>();

            storage.Add(Arg.Any <string>(), Arg.Any <DateTime?>(), Arg.Any <ByteString>()).Returns(added);

            // Act
            InsertResponse response = processor.Reply(request, storage);

            // assert
            Assert.Equal(response.Added, added);
        }
Ejemplo n.º 2
0
        public void Handle_ReturnsTrueWhenElementAdded(bool added)
        {
            // arrange
            var request   = new InsertRequest();
            var processor = new InsertProcessor();
            var storage   = Substitute.For <IStorage>();

            storage.TryRemove(request.Key).Returns(added);
            byte[] expectedBytes = SerializationUtils.SerializeToStreamWithLength(added);
            var    socket        = Substitute.For <Socket>();

            socket.Send(Arg.Any <byte[]>(), Arg.Any <int>(), Arg.Any <int>(), Arg.Any <SocketFlags>())
            .Returns(expectedBytes.Length);

            // act
            processor.Handle(ref request, storage, socket);

            // assert
            socket.Received(1).Send(Arg.Is <byte[]>(x => x.SequenceEqual(expectedBytes)), Arg.Any <int>(), Arg.Any <int>(), Arg.Any <SocketFlags>());
        }