Пример #1
0
        public void AggregationTest_AddToAllocationRepo()
        {
            // Assemble
            Guid fileID = Guid.NewGuid();
            int  count  = 1;
            // Action
            AggregationManager objectUnderTest = new AggregationManager(_logger.Object, _publisher.Object, _allocationRepo, _metaRepo);

            objectUnderTest.AddToAllocationRepo(fileID.ToString(), count.ToString());
            // Assert
            Assert.True(objectUnderTest._allocationRepo.Count == 1);
        }
Пример #2
0
        public void AggregationTest_AddToAllocationRepo_When_Exception()
        {
            // Assemble
            int count = 1;

            _logger.Setup(x => x.Log(LogLevel.Critical, It.IsAny <EventId>(), It.IsAny <FormattedLogValues>(), It.IsAny <Exception>(), It.IsAny <Func <object, Exception, string> >()));

            // Action
            AggregationManager objectUnderTest = new AggregationManager(_logger.Object, _publisher.Object, _allocationRepo, _metaRepo);
            Action             act             = () => objectUnderTest.AddToAllocationRepo(null, count.ToString());

            // Assert
            Assert.Throws <Exception>(act);
            _logger.Verify(x => x.Log(LogLevel.Critical, It.IsAny <EventId>(), It.IsAny <FormattedLogValues>(), It.IsAny <Exception>(), It.IsAny <Func <object, Exception, string> >()), Times.Once());
        }
Пример #3
0
        public void AggregationManager_EnrichAndSendMessage()
        {
            //Arrange
            string key = Guid.Parse("247d7eb3-2fbe-4b3c-84ef-f3580f5c6331").ToString();
            string actualMessageToPublish   = getActualMessage();
            string expectedMessageToPublish = string.Empty;

            _publisher.Setup(p => p.SendMessage(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Guid>()))
            .Callback <string, string, Guid>((c1, c2, c3) => { expectedMessageToPublish = c1; });

            AggregationManager objectUnderTest = new AggregationManager(_logger.Object, _publisher.Object, _allocationRepo, _metaRepo);

            objectUnderTest.AddToMetaRepo(key, 1, getMetaMessage(key));
            objectUnderTest.AddToAllocationRepo(key, @"{""someJasonName"":""somevalue1""}");
            objectUnderTest.AddToAllocationRepo(key, @"{""someJasonName"":""somevalue2""}");
            objectUnderTest.AddToAllocationRepo(key, @"{""someJasonName"":""somevalue3""}");
            //Action
            var result = objectUnderTest.EnrichAndSendMessage(key, Guid.Parse(key), 3, "topic");

            //Assert
            Assert.True(result);
            Assert.True(actualMessageToPublish == expectedMessageToPublish);
            _publisher.Verify(p => p.SendMessage(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Guid>()), Times.Once());
        }
Пример #4
0
        public void AggregationManager_EnrichAndSendMessage_When_FileAllocationCountIsZero()
        {
            //Arrange
            int    fileAllocationCount = 0;
            string key = Guid.Parse("247d7eb3-2fbe-4b3c-84ef-f3580f5c6331").ToString();

            _publisher.Setup(p => p.SendMessage(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Guid>()));
            AggregationManager objectUnderTest = new AggregationManager(_logger.Object, _publisher.Object, _allocationRepo, _metaRepo);

            objectUnderTest.AddToAllocationRepo(key, @"{""someJasonName"":""somevalue1""}");
            //Action
            var result = objectUnderTest.EnrichAndSendMessage(key, Guid.Parse(key), fileAllocationCount, "topic");

            //Assert
            Assert.True(result);
            _publisher.Verify(p => p.SendMessage(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Guid>()), Times.Never());
        }
Пример #5
0
        public void AggregationManager_EnrichAndSendMessage_When_Exception_While_Enriching()
        {
            //Arrange
            int    fileAllocationCount = 1;
            string key = Guid.Parse("247d7eb3-2fbe-4b3c-84ef-f3580f5c6331").ToString();

            _logger.Setup(x => x.Log(LogLevel.Critical, It.IsAny <EventId>(), It.IsAny <FormattedLogValues>(), It.IsAny <Exception>(), It.IsAny <Func <object, Exception, string> >()));
            _publisher.Setup(p => p.SendMessage(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Guid>()));
            AggregationManager objectUnderTest = new AggregationManager(_logger.Object, _publisher.Object, _allocationRepo, _metaRepo);

            objectUnderTest.AddToAllocationRepo(key, "{'someJasonName':'somevalue1'}");
            //Action
            var result = objectUnderTest.EnrichAndSendMessage(key, Guid.Parse(key), fileAllocationCount, "topic");

            //Assert
            Assert.False(result);
            _publisher.Verify(p => p.SendMessage(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Guid>()), Times.Never());
            _logger.Verify(x => x.Log(LogLevel.Critical, It.IsAny <EventId>(), It.IsAny <FormattedLogValues>(), It.IsAny <Exception>(), It.IsAny <Func <object, Exception, string> >()), Times.Once());
        }