示例#1
0
        public void ExecuteShouldConsumeFromBinaryTopic()
        {
            // Arrange
            var outputDirectory = "/my-var";

            var optionsMock = new Mock <IOptions <ApplicationSettings> >();

            optionsMock.SetupGet(options => options.Value)
            .Returns(new ApplicationSettings
            {
                OutputDirectory = outputDirectory
            });

            var agnosticConsumerMock = new Mock <IAgnosticConsumer <byte[]> >();
            var fileClientMock       = new Mock <IFileClient>();
            var loggerMock           = new Mock <ILogger <ConsumeBinary> >();

            var consumeBinaryUseCase = new ConsumeBinary(agnosticConsumerMock.Object, fileClientMock.Object, optionsMock.Object, loggerMock.Object);

            // Act
            consumeBinaryUseCase.Execute();

            // Assert
            agnosticConsumerMock.Verify(agnosticConsumer => agnosticConsumer.Consume("binary", It.IsAny <Action <AgnosticMessage <byte[]> > >()));
        }
示例#2
0
        public void ExecuteShouldCreateAFileWhenAMessageIsConsumed()
        {
            // Arrange
            var outputDirectory = "/my-var";

            var optionsMock = new Mock <IOptions <ApplicationSettings> >();

            optionsMock.SetupGet(options => options.Value)
            .Returns(new ApplicationSettings
            {
                OutputDirectory = outputDirectory
            });

            var consumedMessageMock = new AgnosticMessage <byte[]>
            {
                Key     = "file1",
                Payload = new byte[] {}
            };

            var agnosticConsumerMock = new Mock <IAgnosticConsumer <byte[]> >();

            agnosticConsumerMock.Setup(a => a.Consume("binary", It.IsAny <Action <AgnosticMessage <byte[]> > >()))
            .Callback <string, Action <AgnosticMessage <byte[]> > >((_, action) =>
            {
                action(consumedMessageMock);
            });

            var fileClientMock = new Mock <IFileClient>();
            var loggerMock     = new Mock <ILogger <ConsumeBinary> >();

            var consumeBinaryUseCase = new ConsumeBinary(agnosticConsumerMock.Object, fileClientMock.Object, optionsMock.Object, loggerMock.Object);

            // Act
            consumeBinaryUseCase.Execute();

            // Assert
            fileClientMock.Verify(fileClient =>
                                  fileClient.Create(outputDirectory, consumedMessageMock.Key, consumedMessageMock.Payload),
                                  Times.Once);
        }