コード例 #1
0
        public void ServiceThrowsOnRemoveTermWithoutName()
        {
            var service = new XmlTermsService(String.Empty);

            // Test null.
            try
            {
                service.RemoveTerm(new Term(null, String.Empty), Scheduler.Immediate);
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ArgumentException));
                Assert.IsTrue(((ArgumentException)ex).ParamName == "term");
            }

            // Test whitespace.
            try
            {
                service.RemoveTerm(new Term(" ", String.Empty), Scheduler.Immediate);
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ArgumentException));
                Assert.IsTrue(((ArgumentException)ex).ParamName == "term");
            }
        }
コード例 #2
0
        public void ServiceThrowsOnRemoveNullTerm()
        {
            var service = new XmlTermsService(String.Empty);

            try
            {
                service.RemoveTerm(null, Scheduler.Immediate);
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ArgumentNullException));
                Assert.IsTrue(((ArgumentNullException)ex).ParamName == "term");
            }
        }
コード例 #3
0
        public void ObservableThrowsOnRemoveNonExistentTerm()
        {
            var service = new XmlTermsService(XmlTermsServiceFixture.TermsToFile(
                                                  XmlTermsServiceFixture.SampleTerms,
                                                  "ObservableThrowsOnRemoveNonExistentTerm.xml"));
            var newTerm = new Term("nonExistentTerm", String.Empty);

            Exception ex = null;

            service
            .RemoveTerm(newTerm, Scheduler.Immediate)
            .Subscribe(_ => { }, ex2 => ex = ex2, () => { });

            Assert.IsInstanceOfType(ex, typeof(InvalidOperationException));
            Assert.IsTrue(ex.Message.Contains("doesn't exist"));
        }
コード例 #4
0
        public void ObservableRemovesAndPushesTerm()
        {
            var fileName = XmlTermsServiceFixture.TermsToFile(
                XmlTermsServiceFixture.SampleTerms,
                "ObservableRemovesTerm.xml");

            var service = new XmlTermsService(fileName);
            var term    = XmlTermsServiceFixture.SampleTerms[0];

            Term pushed = null;

            service
            .RemoveTerm(term, Scheduler.Immediate)
            .Subscribe(p => pushed = p);

            Assert.AreEqual(term, pushed);

            var xTerm = XDocument.Load(fileName)
                        .Descendants(TermXmlNames.TermElement)
                        .FirstOrDefault(x => x.Attribute(TermXmlNames.TermNameAttribute).Value == term.Name);

            Assert.IsNull(xTerm);
        }