예제 #1
0
        public void Should_throw_if_group_SecondsInterval_is_not_numeric()
        {
            //Arrange
            var fileLoaderMock = new Mock <IFileLoaderAgent>(MockBehavior.Strict);

            fileLoaderMock.Setup(x => x.ReadAllText(It.IsAny <string>())).Returns(() => string.Format("<CounterGroup Name=\"A\" SecondsInterval=\"A\"></CounterGroup>"));
            var       configBusiness = new ConfigBusiness(fileLoaderMock.Object);
            IConfig   config         = null;
            Exception exception      = null;

            //Act
            try
            {
                config = configBusiness.LoadFile("myFile.xml");
            }
            catch (Exception exp)
            {
                exception = exp;
            }

            //Assert
            Assert.That(config, Is.Null);
            Assert.That(exception, Is.Not.Null);
            Assert.That(exception.Message, Is.EqualTo("Cannot parse attribute SecondsInterval value to integer."));
        }
예제 #2
0
        public void Should_set_all_provided_values_to_the_counter()
        {
            //Arrange
            var counterGroupName = "AA";
            var secondsInterval  = 11;
            var counterName      = "A";
            var categoryName     = "B";
            var instanceName     = "C";
            var fieldName        = "D";
            var max            = 25.5f;
            var fileLoaderMock = new Mock <IFileLoaderAgent>(MockBehavior.Strict);

            fileLoaderMock.Setup(x => x.ReadAllText(It.IsAny <string>())).Returns(() => string.Format(CultureInfo.InvariantCulture, "<{0}><Database><Url>X</Url><Username>X</Username><Password>X</Password><Name>X</Name></Database><CounterGroup Name=\"{1}\" SecondsInterval=\"{2}\"><Counter><CounterName>{3}</CounterName><CategoryName>{4}</CategoryName><InstanceName>{5}</InstanceName><FieldName>{6}</FieldName><Limits Max=\"{7}\" /></Counter></CounterGroup></{0}>", Constants.ServiceName, counterGroupName, secondsInterval, counterName, categoryName, instanceName, fieldName, max));
            var       configBusiness = new ConfigBusiness(fileLoaderMock.Object);
            Exception exception      = null;

            //Act
            var config = configBusiness.LoadFile("myFile.xml");

            //Assert
            Assert.That(config, Is.Not.Null);
            Assert.That(exception, Is.Null);
            Assert.That(config.Groups.Count, Is.EqualTo(1));
            Assert.That(config.Groups.Single().Name, Is.EqualTo(counterGroupName));
            Assert.That(config.Groups.Single().SecondsInterval, Is.EqualTo(secondsInterval));
            Assert.That(config.Groups.Single().Counters.Count(), Is.EqualTo(1));
            Assert.That(config.Groups.Single().Counters.Single().CategoryName, Is.EqualTo(categoryName));
            Assert.That(config.Groups.Single().Counters.Single().CounterName.Name, Is.EqualTo(counterName));
            Assert.That(config.Groups.Single().Counters.Single().InstanceName.Name, Is.EqualTo(instanceName));
            Assert.That(config.Groups.Single().Counters.Single().FieldName, Is.EqualTo(fieldName));
            Assert.That(config.Groups.Single().Counters.Single().Max, Is.EqualTo(max));
        }
예제 #3
0
        public void Should_throw_if_group_has_no_Name()
        {
            //Arrange
            var fileLoaderMock = new Mock <IFileLoaderAgent>(MockBehavior.Strict);

            fileLoaderMock.Setup(x => x.ReadAllText(It.IsAny <string>())).Returns(() => string.Format("<CounterGroup></CounterGroup>"));
            var       configBusiness = new ConfigBusiness(fileLoaderMock.Object);
            IConfig   config         = null;
            Exception exception      = null;

            //Act
            try
            {
                config = configBusiness.LoadFile("myFile.xml");
            }
            catch (Exception exp)
            {
                exception = exp;
            }

            //Assert
            Assert.That(config, Is.Null);
            Assert.That(exception, Is.Not.Null);
            Assert.That(exception.Message, Is.EqualTo("No Name attribute specified for the CounterGroup."));
        }
예제 #4
0
        public void Should_not_throw_if_there_is_no_database_configuration_information()
        {
            //Arrange
            var folderPath     = "ABC";
            var fileLoaderMock = new Mock <IFileLoaderAgent>(MockBehavior.Strict);

            fileLoaderMock.Setup(x => x.GetApplicationFolderPath()).Returns(folderPath);
            fileLoaderMock.Setup(x => x.DoesDirectoryExist(folderPath)).Returns(true);
            fileLoaderMock.Setup(x => x.DoesFileExist(It.IsAny <string>())).Returns(false);
            fileLoaderMock.Setup(x => x.ReadAllText(It.IsAny <string>())).Returns(() => "<A></A>");
            var configBusiness = new ConfigBusiness(fileLoaderMock.Object);

            //Act
            var config = configBusiness.LoadFile("myFile.xml");

            //Assert
            Assert.That(config, Is.Not.Null);
        }
예제 #5
0
        public void Should_fill_database_configuration()
        {
            //Arrange
            var url            = "A";
            var username       = "******";
            var password       = "******";
            var databaseName   = "D";
            var fileLoaderMock = new Mock <IFileLoaderAgent>(MockBehavior.Strict);

            fileLoaderMock.Setup(x => x.ReadAllText(It.IsAny <string>())).Returns(() => string.Format("<Database><Url>{0}</Url><Username>{1}</Username><Password>{2}</Password><Name>{3}</Name></Database>", url, username, password, databaseName));
            var configBusiness = new ConfigBusiness(fileLoaderMock.Object);

            //Act
            var config = configBusiness.LoadFile("myFile.xml");

            //Assert
            var database = config.Databases.First();

            Assert.That(database, Is.Not.Null);
            Assert.That(database.Url, Is.EqualTo(url));
            Assert.That(database.Username, Is.EqualTo(username));
            Assert.That(database.Password, Is.EqualTo(password));
            Assert.That(database.Name, Is.EqualTo(databaseName));
        }