예제 #1
0
        public async Task EditSavedRepository_ReplaceOldValue()
        {
            var exampleRepo = "firstExampleRepoUrl";
            var exampleJob  = "newExampleJob";

            var parameter = "repository";
            var value     = $"{exampleRepo}={exampleJob}";
            var args      = new string[] { Command, $"{parameter}:{value}" };

            var configuration = GetDefaultConfiguration();
            var userConsole   = new Mock <IUserConsole>();

            userConsole.Setup(c => c.ReadInput(repoName, false)).Returns(exampleRepo);
            userConsole.Setup(c => c.ReadInput(jenkinsJob, false)).Returns(exampleJob);

            var command = new SetConfiguration(GetConfigurationSerializerMock(configuration).Object, GetEncryptorMock().Object, userConsole.Object);
            var app     = new CommandLineApplication();

            app.Command(command.Name, command.Command);

            var code = await app.ExecuteAsync(args);

            Assert.That(code, Is.EqualTo(JenoCodes.Ok));
            Assert.That(configuration.Repository, Contains.Key(exampleRepo));
            Assert.That(configuration.Repository, Contains.Value(exampleJob));
            Assert.That(configuration.Repository[exampleRepo], Is.EqualTo(exampleJob));
            userConsole.Verify(c => c.ReadInput(repoName, false), Times.Never);
            userConsole.Verify(c => c.ReadInput(jenkinsJob, false), Times.Never);
        }
        public void TestNumberReader()
        {
            var reader = ColumnReaders.NumberReader("foo");
            var m      = new ParsedMetrics(new LabelDict("env"));

            reader(m, "1");
            Assert.That(m.Metrics, Has.Exactly(1).Items);
            Assert.That(m.Metrics, Contains.Key("foo"));
            Assert.That(m.Metrics, Contains.Value(1.0));
            Assert.That(m.Labels.Count, Is.EqualTo(0));

            reader(m, "2.0");
            Assert.That(m.Metrics, Has.Exactly(1).Items);
            Assert.That(m.Metrics, Contains.Key("foo"));
            Assert.That(m.Metrics, Contains.Value(2.0));
            Assert.That(m.Labels.Count, Is.EqualTo(0));

            reader(m, "2.0e1");
            Assert.That(m.Metrics, Has.Exactly(1).Items);
            Assert.That(m.Metrics, Contains.Key("foo"));
            Assert.That(m.Metrics, Contains.Value(20.0));
            Assert.That(m.Labels.Count, Is.EqualTo(0));

            Assert.That(() => reader(m, ""), Throws.TypeOf <ParserError>());
            Assert.That(() => reader(m, "nope"), Throws.TypeOf <ParserError>());
        }
예제 #3
0
        public async Task AddNewRepositoryWithoutValue_GetValueFromUserAndSaveRepositoryInConfiguration()
        {
            var exampleRepo = "thirdExampleRepoUrl";
            var exampleJob  = "thirdExampleJob";

            var parameter = "repository";
            var args      = new string[] { Command, parameter };

            var configuration = GetDefaultConfiguration();
            var userConsole   = new Mock <IUserConsole>();

            userConsole.Setup(c => c.ReadInput(repoName, false)).Returns(exampleRepo);
            userConsole.Setup(c => c.ReadInput(jenkinsJob, false)).Returns(exampleJob);

            var command = new SetConfiguration(GetConfigurationSerializerMock(configuration).Object, GetEncryptorMock().Object, userConsole.Object);
            var app     = new CommandLineApplication();

            app.Command(command.Name, command.Command);

            var code = await app.ExecuteAsync(args);

            Assert.That(code, Is.EqualTo(JenoCodes.Ok));
            Assert.That(configuration.Repository, Contains.Key(exampleRepo));
            Assert.That(configuration.Repository, Contains.Value(exampleJob));
            Assert.That(configuration.Repository[exampleRepo], Is.EqualTo(exampleJob));
            userConsole.Verify(c => c.ReadInput(repoName, false), Times.Once);
            userConsole.Verify(c => c.ReadInput(jenkinsJob, false), Times.Once);
        }
예제 #4
0
        public void Assert_contains_key_and_value()
        {
            var dictionary = new Dictionary <string, string>()
            {
                ["name"] = "carlos"
            };

            Assert.That(dictionary, Contains.Key("name"));
            Assert.That(dictionary, Contains.Value("carlos"));
        }
예제 #5
0
    public void When_SubmapAdded_Expect_MapContainsSubmap()
    {
        Map map    = new Map();
        Map submap = new Map();

        map.Add(submap);
        Assert.That(map, Contains.Key(submap.Coordinates), "Map does not recognize submap key.");
        Assert.That(map, Contains.Value(submap), "Map does not recognize submap value.");
        Assert.That(submap, Is.SameAs(map[submap.Coordinates]), "Submap is not the same object as the submap inside of map.");
    }
예제 #6
0
    public void When_SubtileAdded_Expect_TileContainsSubtile()
    {
        World world   = new World(new MapSettings());
        Tile  tile    = new Tile(Directions.O, null, world, 1);
        Tile  subtile = new Tile(Directions.O, null, world, 0);

        tile.Add(subtile);
        Assert.That(tile, Contains.Key(subtile.Coordinates), "Map does not recognize submap key.");
        Assert.That(tile, Contains.Value(subtile), "Map does not recognize submap value.");
        Assert.That(subtile, Is.SameAs(tile[subtile.Coordinates]), "Submap is not the same object as the submap inside of map.");
    }
예제 #7
0
        public void AssertThat_ContainsCommonlyUsed()
        {
            var keys = new[] { ConsoleKey.Spacebar, ConsoleKey.Tab, ConsoleKey.Clear };

            Assert.That(keys, Contains.Item(ConsoleKey.Tab));

            var stringKey = new Dictionary <ConsoleColor, string>
            {
                { ConsoleColor.Green, "Ok" },
                { ConsoleColor.Red, "Error" },
                { ConsoleColor.Yellow, "Warning" }
            };

            Assert.That(stringKey, Contains.Key(ConsoleColor.Green));
            Assert.That(stringKey, Contains.Value("Ok"));
        }
        public void AddCustomData_WhenCustomDataIsEmpty_AddsTheCustomData()
        {
            // Arrange
            var key   = "Identifier";
            var value = "value";

            // Act
            _uut.AddCustomData(key, value);

            // Assert
            Assert.Multiple(() =>
            {
                Assert.That(_uut.CustomData, Contains.Key(key));
                Assert.That(_uut.CustomData, Contains.Value(value));
            });
        }
        public void Dictionary_RemoveEntries_Where()
        {
            var dic = new Dictionary <string, int>()
            {
                { "A", 1 },
                { "B", 2 },
                { "C", 3 },
                { "D", 4 },
                { "E", 5 },
            };

            dic.RemoveWhere((key, value) => key == "D" || value % 2 == 1);

            Assert.That(dic, Has.Exactly(1).Items);
            Assert.That(dic, Contains.Key("B"));
            Assert.That(dic, Contains.Value(2));
        }
        public void AddCustomData_TwoTimes_AddsBothSets()
        {
            // Arrange
            var key1   = "Identifier";
            var value1 = "value";

            var key2   = "custom";
            var value2 = "data";

            // Act
            _uut.AddCustomData(key1, value1);
            _uut.AddCustomData(key2, value2);

            // Assert
            Assert.Multiple(() =>
            {
                Assert.That(_uut.CustomData, Contains.Key(key1));
                Assert.That(_uut.CustomData, Contains.Value(value1));

                Assert.That(_uut.CustomData, Contains.Key(key2));
                Assert.That(_uut.CustomData, Contains.Value(value2));
            });
        }
예제 #11
0
        public void GetSunkenShips_ShouldReturnTheSunkenShipsInTheDictionary()
        {
            AssertContains5Ships();

            //Arrange
            Mock <IShip>[] shipMocks           = ReplaceShipsWithMocks();
            int            numberOfSunkenShips = RandomGenerator.Next(1, 5);

            foreach (Mock <IShip> shipMock in shipMocks.Take(numberOfSunkenShips))
            {
                shipMock.SetupGet(s => s.HasSunk).Returns(true);
            }

            //Act
            IList <IShip> sunkenShips = _fleet.GetSunkenShips();

            //Act + Assert
            Assert.That(sunkenShips, Has.Count.EqualTo(numberOfSunkenShips));
            foreach (IShip ship in sunkenShips)
            {
                Assert.That(_internalDictionary, Contains.Value(ship),
                            $"The ship '{ship.Kind.Name}' in the returned list cannot be found in the internal dictionary of ships.");
            }
        }
예제 #12
0
 public void CreateInstanceFromNodeID(Type expectedType)
 {
     Assert.That(s_NodeIdValueTypes, Is.Not.Null);
     Assert.That(s_NodeIdValueTypes, Contains.Value(expectedType), $"Type \"{nameof(expectedType)}\" is not found in NodeID - Type mapping.");
 }