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"); } }
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"); } }
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")); }
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); }