public void CreatesDictionary()
        {
            _createDictionary = new CreateDictionaryCommand();
            _engine           = new AutomationEngineInstance(null);
            OBData.DataTable inputDt = new OBData.DataTable();
            inputDt.Columns.Add("Keys");
            inputDt.Columns.Add("Values");
            DataRow row1 = inputDt.NewRow();

            row1["Keys"]   = "key1";
            row1["Values"] = "val1";
            inputDt.Rows.Add(row1);
            VariableMethods.CreateTestVariable(inputDt, _engine, "inputDt", typeof(OBData.DataTable));
            VariableMethods.CreateTestVariable(null, _engine, "output", typeof(Dictionary <,>));

            _createDictionary.v_ColumnNameDataTable    = (OBData.DataTable) "{inputDt}".ConvertUserVariableToObject(_engine, typeof(OBData.DataTable));
            _createDictionary.v_OutputUserVariableName = "{output}";

            _createDictionary.RunCommand(_engine);

            Dictionary <string, string> outDict = (Dictionary <string, string>) "{output}".ConvertUserVariableToObject(_engine, typeof(Dictionary <,>));

            Assert.True(outDict.ContainsKey("key1"));
            Assert.Equal("val1", outDict["key1"]);
        }
Exemplo n.º 2
0
        public void CreateDictionaryCommand_CreateQuery_1()
        {
            Mock <IIrbisConnection> mock       = GetConnectionMock();
            IIrbisConnection        connection = mock.Object;
            CreateDictionaryCommand command    = new CreateDictionaryCommand(connection);

            command.CreateQuery();
        }
Exemplo n.º 3
0
        public void CreateDictionaryCommand_Verify_1()
        {
            Mock <IIrbisConnection> mock       = GetConnectionMock();
            IIrbisConnection        connection = mock.Object;
            CreateDictionaryCommand command    = new CreateDictionaryCommand(connection);

            Assert.IsFalse(command.Verify(false));
        }
Exemplo n.º 4
0
        public void CreateDictionaryCommand_Construciton_1()
        {
            Mock <IIrbisConnection> mock       = GetConnectionMock();
            IIrbisConnection        connection = mock.Object;
            CreateDictionaryCommand command    = new CreateDictionaryCommand(connection);

            Assert.AreSame(connection, command.Connection);
        }
Exemplo n.º 5
0
        public void CreateDictionaryCommand_Verify_2()
        {
            Mock <IIrbisConnection> mock       = GetConnectionMock();
            IIrbisConnection        connection = mock.Object;
            CreateDictionaryCommand command    = new CreateDictionaryCommand(connection)
            {
                Database = "IBIS"
            };

            Assert.IsTrue(command.Verify(false));
        }
Exemplo n.º 6
0
        public void CreateDictionaryCommand_CreateQuery_2()
        {
            Mock <IIrbisConnection> mock       = GetConnectionMock();
            IIrbisConnection        connection = mock.Object;
            CreateDictionaryCommand command    = new CreateDictionaryCommand(connection)
            {
                Database = "IBIS"
            };
            ClientQuery query = command.CreateQuery();

            Assert.IsNotNull(query);
        }
Exemplo n.º 7
0
        public IActionResult Create([FromBody] CreateDictionaryCommand command)
        {
            var result = _commandBus.Send(command);

            if (!result.IsValid())
            {
                var Error = (InvalidResult)result;
                return(BadRequest(Error.Errors));
            }

            long dictionaryId = command.DictionaryId;

            return(RedirectToAction("Get", new { id = dictionaryId }));
        }
        public void ReturnCorrectMessage_WhenCorrectParrametersArePassed()
        {
            var repository        = new Mock <IRepository <Dictionary> >();
            var unitOfWork        = new Mock <IUnitOfWork>();
            var userProvider      = new Mock <IUserProvider>();
            var dictionaryFactory = new Mock <IDictionariesFactory>();

            string authorName      = "Whoever";
            string dictionaryTitle = "Vse Taq";
            string languageName    = "English";

            User user = new User()
            {
                Username = authorName
            };

            userProvider.Setup(u => u.LoggedUser).Returns(user);

            var language = new Language()
            {
                Name = languageName
            };

            var dictionary = new Dictionary()
            {
                Author   = authorName,
                Language = language,
                Title    = dictionaryTitle
            };

            dictionaryFactory.Setup(d => d.GetLanguage(languageName)).Returns(language);
            dictionaryFactory.Setup(d => d.GetDictionary(dictionaryTitle, authorName,
                                                         language, It.IsAny <DateTime>()))
            .Returns(dictionary);

            var command = new CreateDictionaryCommand(repository.Object, unitOfWork.Object,
                                                      userProvider.Object, dictionaryFactory.Object);

            var parameters = new List <string>()
            {
                dictionaryTitle,
                languageName
            };

            string expectedResult = $"A new dictionary with title {dictionaryTitle}, author {authorName} and language {languageName} was created.";
            string result         = command.Execute(parameters);

            Assert.AreEqual(expectedResult, result);
        }
        public void SavesMadeChanges_WhenCorrectParrametersArePassed()
        {
            var repository        = new Mock <IRepository <Dictionary> >();
            var unitOfWork        = new Mock <IUnitOfWork>();
            var userProvider      = new Mock <IUserProvider>();
            var dictionaryFactory = new Mock <IDictionariesFactory>();

            string authorName      = "Whoever";
            string dictionaryTitle = "Vse Taq";
            string languageName    = "English";

            User user = new User()
            {
                Username = authorName
            };

            userProvider.Setup(u => u.LoggedUser).Returns(user);

            var language = new Language()
            {
                Name = languageName
            };

            var dictionary = new Dictionary()
            {
                Author   = authorName,
                Language = language,
                Title    = dictionaryTitle
            };

            dictionaryFactory.Setup(d => d.GetLanguage(languageName)).Returns(language);
            dictionaryFactory.Setup(d => d.GetDictionary(dictionaryTitle, authorName,
                                                         language, It.IsAny <DateTime>()))
            .Returns(dictionary);

            var command = new CreateDictionaryCommand(repository.Object, unitOfWork.Object,
                                                      userProvider.Object, dictionaryFactory.Object);

            var parameters = new List <string>()
            {
                dictionaryTitle,
                languageName
            };

            command.Execute(parameters);

            unitOfWork.Verify(r => r.SaveChanges(), Times.Once);
        }
        public void Throw_WhenLessThanTwoParametersArePassed()
        {
            var repository        = new Mock <IRepository <Dictionary> >();
            var unitOfWork        = new Mock <IUnitOfWork>();
            var userProvider      = new Mock <IUserProvider>();
            var dictionaryFactory = new Mock <IDictionariesFactory>();
            var command           = new CreateDictionaryCommand(repository.Object, unitOfWork.Object,
                                                                userProvider.Object, dictionaryFactory.Object);

            var parameters = new List <string>()
            {
                "wordName"
            };

            Assert.Throws <ArgumentException>(() => command.Execute(parameters));
        }
Exemplo n.º 11
0
        public void CreateDictionaryCommand_ExecuteRequest_1()
        {
            int returnCode = 0;
            Mock <IIrbisConnection> mock       = GetConnectionMock();
            IIrbisConnection        connection = mock.Object;
            CreateDictionaryCommand command    = new CreateDictionaryCommand(connection)
            {
                Database = "IBIS"
            };
            ResponseBuilder builder = new ResponseBuilder()
                                      .StandardHeader(CommandCode.CreateDictionary, 123, 456)
                                      .NewLine()
                                      .Append(returnCode)
                                      .NewLine();
            TestingSocket socket = (TestingSocket)connection.Socket;

            socket.Response = builder.Encode();
            ClientQuery    query    = command.CreateQuery();
            ServerResponse response = command.Execute(query);

            Assert.AreEqual(returnCode, response.ReturnCode);
        }