public void ServiceThrowsOnAddTermWithoutName()
        {
            var service = new XmlTermsService(String.Empty);

            // Test null.
            try
            {
                service.AddTerm(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.AddTerm(new Term(" ", String.Empty), Scheduler.Immediate);
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ArgumentException));
                Assert.IsTrue(((ArgumentException)ex).ParamName == "term");
            }
        }
        public void ObservableThrowsOnAddExistingTerm()
        {
            var service = new XmlTermsService(XmlTermsServiceFixture.TermsToFile(
                                                  XmlTermsServiceFixture.SampleTerms,
                                                  "ObservableThrowsOnAddExistingTerm.xml"));

            Exception ex = null;

            service
            .AddTerm(XmlTermsServiceFixture.SampleTerms[0], Scheduler.Immediate)
            .Subscribe(_ => { }, ex2 => ex = ex2, () => { });

            Assert.IsInstanceOfType(ex, typeof(InvalidOperationException));
            Assert.IsTrue(ex.Message.Contains("already exists"));
        }
        public void ServiceThrowsOnAddNullTerm()
        {
            var service = new XmlTermsService(String.Empty);

            try
            {
                service.AddTerm(null, Scheduler.Immediate);
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ArgumentNullException));
                Assert.IsTrue(((ArgumentNullException)ex).ParamName == "term");
            }
        }
        public void ObservableAddsAndPushesNewTerm()
        {
            var fileName = XmlTermsServiceFixture.TermsToFile(
                XmlTermsServiceFixture.SampleTerms,
                "ObservableAddsAndPushesNewTerm.xml");

            var service = new XmlTermsService(fileName);
            var term    = new Term("newTerm", "newDef");

            Term pushed = null;

            service.AddTerm(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.Equals(term.Name));

            Assert.IsNotNull(xTerm);
            Assert.AreEqual(term.Definition, xTerm.Attribute(TermXmlNames.TermDefinitionAttribute).Value);
        }