public void AddWordTest()
        {
            // Arrange.
            var dictionaryManager = Mock.Create<IDictionaryManager>(Behavior.Loose);
            Mock.Arrange(() => dictionaryManager.AddUserWordAsync(Arg.AnyString)).Returns(TaskEx.FromResult(true));

            var logger = Mock.Create<ILogger>(Behavior.Loose);
            var dictionary = new UserDictionary(Enumerable.Empty<string>(), dictionaryManager, logger);

            var dataChanged = false;

            dictionary.DataChanged += (sender, args) => dataChanged = true;

            // Act.
            dictionary.AddWord("test");

            // Assert.
            Assert.IsTrue(dataChanged);

            Assert.AreEqual(1, dictionary.Words.Count());
            Assert.IsTrue(dictionary.ContainsWord("test"));

            Mock.Assert(() => dictionaryManager.AddUserWordAsync("test"), Occurs.Once());

            // Argument validation.
            TestsHelper.VerifyThrow<ArgumentException>(() => dictionary.AddWord(string.Empty));
        }
        public void ConstructorTests()
        {
            // Arrange.
            var words = new[] { "aaa", "bbb", "ccc" };
            var dictionaryManager = Mock.Create<IDictionaryManager>(Behavior.Loose);
            var logger = Mock.Create<ILogger>(Behavior.Loose);

            // Act.
            var dictionary = new UserDictionary(words, dictionaryManager, logger);

            // Assert.
            Assert.AreEqual(3, dictionary.Words.Count());
            Assert.IsTrue(dictionary.ContainsWord("aaa"));
            Assert.IsTrue(dictionary.ContainsWord("bbb"));
            Assert.IsTrue(dictionary.ContainsWord("ccc"));

            // Argument validation.
            TestsHelper.VerifyThrow<ArgumentNullException>(() => new UserDictionary(null, dictionaryManager, logger));
            TestsHelper.VerifyThrow<ArgumentNullException>(() => new UserDictionary(words, null, logger));
            TestsHelper.VerifyThrow<ArgumentNullException>(() => new UserDictionary(words, dictionaryManager, null));
        }
        public void WhenAddUserWordFails_ErrorIsLogged()
        {
            // Arrange.
            var dictionaryManager = Mock.Create<IDictionaryManager>(Behavior.Loose);
            var exception = new Exception();
            Mock.Arrange(() => dictionaryManager.AddUserWordAsync(Arg.AnyString)).Returns(TaskHelper.FromException(exception));

            var logger = Mock.Create<ILogger>(Behavior.Loose);
            var dictionary = new UserDictionary(Enumerable.Empty<string>(), dictionaryManager, logger);
            
            var dataChanged = false;

            dictionary.DataChanged += (sender, args) => dataChanged = true;
            // Act.
            dictionary.AddWord("test");

            // Assert.
            Assert.IsTrue(dataChanged);

            Assert.AreEqual(1, dictionary.Words.Count());
            Assert.IsTrue(dictionary.ContainsWord("test"));
            Mock.Assert(() => logger.Log(LogSeverity.Error, "Global Dictionary", exception), Occurs.Once());
        }
        public void WhenClearUserWordsFails_ErrorIsLogged()
        {
            // Arrange.
            var dictionaryManager = Mock.Create<IDictionaryManager>(Behavior.Loose);
            var exception = new Exception();
            Mock.Arrange(() => dictionaryManager.ClearUserWordsAsync()).Returns(TaskHelper.FromException(exception));

            var logger = Mock.Create<ILogger>(Behavior.Loose);
            var dictionary = new UserDictionary(new[] { "aaa", "bbb" }, dictionaryManager, logger);

            var dataChanged = false;

            dictionary.DataChanged += (sender, args) => dataChanged = true;

            // Act.
            dictionary.ClearWords();

            // Assert.
            Assert.IsTrue(dataChanged);

            Assert.AreEqual(0, dictionary.Words.Count());
            Mock.Assert(() => logger.Log(LogSeverity.Error, "Global Dictionary", exception), Occurs.Once());
        }
        public void ClearWordsTest()
        {
            // Arrange.
            var dictionaryManager = Mock.Create<IDictionaryManager>(Behavior.Loose);
            Mock.Arrange(() => dictionaryManager.ClearUserWordsAsync()).Returns(TaskEx.FromResult(true));

            var logger = Mock.Create<ILogger>(Behavior.Loose);
            var dictionary = new UserDictionary(new[] { "aaa", "bbb" }, dictionaryManager, logger);

            var dataChanged = false;

            dictionary.DataChanged += (sender, args) => dataChanged = true;

            // Act.
            dictionary.ClearWords();

            // Assert.
            Assert.IsTrue(dataChanged);

            Assert.AreEqual(0, dictionary.Words.Count());

            Mock.Assert(() => dictionaryManager.ClearUserWordsAsync(), Occurs.Once());
        }