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); }
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); }
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); }
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()); }
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); }
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>()); }
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()); }
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()); }