示例#1
0
        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());
        }
示例#2
0
        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());
        }