Exemplo n.º 1
0
        public async Task WhenMemoryMetricsWithAppConfigProvidedWithWarning_ShouldReturnMessage()
        {
            //Arrange
            var memoryConfig = new MemoryConfigBuilder()
                               .WithMaxPercentageUsage(10)
                               .Build();

            var config = new AppConfigBuilder()
                         .WithMemory(memoryConfig)
                         .Build();

            var converter = this.Context
                            .WithAppConfig(config)
                            .Build();

            var memoryMetrics = new MemoryMetricsBuilder()
                                .WithTotal(100)
                                .WithFree(30)
                                .Build();

            //Act
            var message = await converter.GetAsync(memoryMetrics);

            //Assert
            Assert.AreEqual("Warning - RAM Memory", message.Title);
            Assert.AreEqual("RAM memory 70% consumed!\r\n\r\n\r\nTotal: 100B\r\nUsed: 70B\r\nFree: 30B", message.Content);
        }
Exemplo n.º 2
0
        public async Task WhenMemoryMetricsWithAppConfigProvidedWithoutReportModeWithoutWarningWithoutTest_ShouldReturnNull()
        {
            //Arrange
            var memoryConfig = new MemoryConfigBuilder()
                               .WithMaxPercentageUsage(90)
                               .WithReportMode(false)
                               .Build();

            var config = new AppConfigBuilder()
                         .WithMemory(memoryConfig)
                         .Build();

            var converter = this.Context
                            .WithAppConfig(config)
                            .Build();

            var memoryMetrics = new MemoryMetricsBuilder()
                                .WithTotal(10)
                                .WithFree(10)
                                .Build();

            //Act
            var message = await converter.GetAsync(memoryMetrics);

            //Assert
            Assert.IsNull(message);
        }
Exemplo n.º 3
0
        public async Task WhenMemoryMetricsWithAppConfigProvidedWithReportMode_ShouldReturnMessage()
        {
            //Arrange
            var memoryConfig = new MemoryConfigBuilder()
                               .WithMaxPercentageUsage(90)
                               .WithReportMode(true)
                               .Build();

            var config = new AppConfigBuilder()
                         .WithMemory(memoryConfig)
                         .Build();

            var converter = this.Context
                            .WithAppConfig(config)
                            .Build();

            var memoryMetrics = new MemoryMetricsBuilder()
                                .WithTotal(10)
                                .WithFree(10)
                                .Build();

            //Act
            var message = await converter.GetAsync(memoryMetrics);

            //Assert
            Assert.AreEqual("RAM Memory", message.Title);
            Assert.AreEqual("Total: 10B\r\nUsed: 0B\r\nFree: 10B", message.Content);
        }
Exemplo n.º 4
0
        public void WhenNoMessageReturned_ShouldNotEnqueue()
        {
            //Arrange
            var maxPercentageUsage = 30;
            var total        = 100;
            var free         = 30;
            var memoryConfig = new MemoryConfigBuilder()
                               .WithEnabled(true)
                               .WithMaxPercentageUsage(maxPercentageUsage)
                               .Build();
            var appConfig = new AppConfigBuilder()
                            .WithMemory(memoryConfig)
                            .Build();

            this.Context.ConfigMock.Mock_Config(appConfig);

            var memoryMetrics = new MemoryMetricsBuilder()
                                .WithTotal(total)
                                .WithFree(free)
                                .Build();

            this.Context.MemoryInfoMock.Mock_GetMemoryMetrics(memoryMetrics);

            this.Context.MessageConverterMock.Mock_Get((Expression <Func <MemoryMetrics, bool> >)(x => x.Total == total && x.Free == free), null);

            var service = this.Context.Build();

            //Act
            service.DoWorkAsync();

            //Assert
            this.Context.MemoryInfoMock.Verify_GetMemoryMetricsCalled(Times.Once());
            this.Context.MessageConverterMock.Verify_GetCalled((Expression <Func <MemoryMetrics, bool> >)(x => x.Total == total && x.Free == free), Times.Once());
            this.Context.MessageQueueServiceMock.Verify_EnqueueCalled(Times.Never());
        }
Exemplo n.º 5
0
        public void WhenNoMaxPercentageUsageProvided_ShouldThrowNothing()
        {
            //Arrange
            var config = new MemoryConfigBuilder()
                         .WithEnabled(true)
                         .WithDelayStart(AppConsts.DELAY_MIN)
                         .WithReportMode(true)
                         .WithRunInterval(AppConsts.INTERVAL_MIN)
                         .Build();
            var validator = this.Context.Build();

            //Act / Assert
            Assert.That(() => validator.ValidateAsync(config), Throws.Nothing);
        }
Exemplo n.º 6
0
        public void WhenNoDelayStartProvided_ShouldThrowArgumentNullException()
        {
            //Arrange
            var config = new MemoryConfigBuilder()
                         .WithEnabled(true)
                         .WithMaxPercentageUsage(AppConsts.PERCENT_MIN)
                         .WithReportMode(true)
                         .WithRunInterval(AppConsts.INTERVAL_MIN)
                         .Build();
            var validator = this.Context.Build();

            //Act / Assert
            Assert.That(() => validator.ValidateAsync(config), Throws.InstanceOf <ArgumentOutOfRangeException>());
        }
Exemplo n.º 7
0
        public async Task WhenMessageReturned_ShouldEnqueue()
        {
            //Arrange
            var maxPercentageUsage = 30;
            var total        = 100;
            var free         = 30;
            var memoryConfig = new MemoryConfigBuilder()
                               .WithEnabled(true)
                               .WithMaxPercentageUsage(maxPercentageUsage)
                               .Build();
            var appConfig = new AppConfigBuilder()
                            .WithMemory(memoryConfig)
                            .Build();

            this.Context.ConfigMock.Mock_Config(appConfig);

            var memoryMetrics = new MemoryMetricsBuilder()
                                .WithTotal(total)
                                .WithFree(free)
                                .Build();

            this.Context.MemoryInfoMock.Mock_GetMemoryMetrics(memoryMetrics);

            var title   = "title";
            var content = "content";
            var message = new MessageBuilder()
                          .WithTitle(title)
                          .WithContent(content)
                          .Build();

            this.Context.MessageConverterMock.Mock_Get((Expression <Func <MemoryMetrics, bool> >)(x => x.Total == total && x.Free == free), message);

            var service = this.Context.Build();

            //Act
            await service.DoWorkAsync();

            //Assert
            this.Context.MemoryInfoMock.Verify_GetMemoryMetricsCalled(Times.Once());
            this.Context.MessageConverterMock.Verify_GetCalled((Expression <Func <MemoryMetrics, bool> >)(x => x.Total == total && x.Free == free), Times.Once());
            this.Context.MessageQueueServiceMock.Verify_EnqueueCalled(x => x.Title == title && x.Content == content, Times.Once());
        }
Exemplo n.º 8
0
        public void ValidationShouldBeExecutedOnce()
        {
            //Arrange
            var maxPercentageUsage = 30;
            var memoryConfig       = new MemoryConfigBuilder()
                                     .WithEnabled(true)
                                     .WithMaxPercentageUsage(maxPercentageUsage)
                                     .Build();
            var appConfig = new AppConfigBuilder()
                            .WithMemory(memoryConfig)
                            .Build();

            this.Context.ConfigMock.Mock_Config(appConfig);

            var service = this.Context.Build();

            //Act
            service.ValidateAsync();

            //Assert
            this.Context.MemoryConfigValidatorMock.Verify_ValidateCalled(x => x.Enabled == true && x.MaxPercentageUsage == maxPercentageUsage, Times.Once());
        }