コード例 #1
0
        public void AddVar_SameVar_Throws()
        {
            // Arrange
            var context = new TestCaseContext();
            var sut     = new VarsManager(
                context.OptionsService,
                context.Logger);

            var key  = "var";
            var aVar = new IntVar(key, "var-name", 15);

            // Act + Assert
            sut.AddVar(aVar);
            Assert.Throws <VarAlreadyExistsException>(() => sut.AddVar(aVar));
        }
コード例 #2
0
        public void GetAllVars()
        {
            // Arrange
            var context = new TestCaseContext();
            var sut     = new VarsManager(
                context.OptionsService,
                context.Logger);

            var random = new Random();

            int varsCount = 5;
            var vars      = new List <IVar>();

            for (int i = 0; i < varsCount; ++i)
            {
                vars.Add(new IntVar(
                             $"key{i}",
                             $"var-name{i}",
                             random.Next(-100, 100)));
            }

            // Act
            foreach (var v in vars)
            {
                sut.AddVar(v);
            }
            var actual = sut.GetAllVars();

            // Assert
            Assert.Equal(vars, actual);
        }
コード例 #3
0
        public void RemoveVar_Success()
        {
            // Arrange
            var context = new TestCaseContext();
            var sut     = new VarsManager(
                context.OptionsService,
                context.Logger);

            var key  = "var";
            var aVar = new IntVar(key, "var-name", 15);

            // Act + Assert
            sut.AddVar(aVar);
            sut.RemoveVar(key);
            Assert.Throws <VarNotFoundException>(() => sut.GetVar("key"));
        }
コード例 #4
0
        public void AddVar_Success()
        {
            // Arrange
            var context = new TestCaseContext();
            var sut     = new VarsManager(
                context.OptionsService,
                context.Logger);

            var key  = "var";
            var aVar = new IntVar(key, "var-name", 15);

            // Act
            sut.AddVar(aVar);
            var actual = sut.GetVar <IntVar>(key);

            // Assert
            Assert.Same(aVar, actual);
        }
コード例 #5
0
        public void GetVar_Overload()
        {
            // Arrange
            var context = new TestCaseContext();
            var sut     = new VarsManager(
                context.OptionsService,
                context.Logger);

            var key  = "key";
            var aVar = new IntVar("key", "var-name", 15);

            // Act
            sut.AddVar(aVar);
            var actual1 = sut.GetVar(key) as IntVar;
            var actual2 = sut.GetVar <IntVar>(key);

            // Assert
            Assert.Same(aVar, actual1);
            Assert.Same(aVar, actual2);
        }
コード例 #6
0
        public void ContainsVar()
        {
            // Arrange
            var context = new TestCaseContext();
            var sut     = new VarsManager(
                context.OptionsService,
                context.Logger);

            var key = "key";

            // Act
            var beforeAdd = sut.ContainsVar(key);

            sut.AddVar(new IntVar(key, "var-name"));
            var afterAdd = sut.ContainsVar(key);

            // Assert
            Assert.False(beforeAdd);
            Assert.True(afterAdd);
        }
コード例 #7
0
        public void ClearVars()
        {
            // Arrange
            var context = new TestCaseContext();
            var sut     = new VarsManager(
                context.OptionsService,
                context.Logger);

            int varsCount = 3;

            var vars = new List <IntVar>();

            for (int i = 0; i < varsCount; ++i)
            {
                sut.AddVar(new IntVar($"key{i}", $"var-name{i}"));
            }

            // Act
            sut.ClearVars();

            // Assert
            Assert.Empty(sut.GetAllVars());
        }