public void UpdateTermsInDatabase_WithoutUser_ReturnsCorrectError() { var cacheManager = Mocks.DynamicMock<ICacheManager>(); var historyReader = Mocks.DynamicMock<IDnaDataReader>(); historyReader.Stub(x => x.GetInt32NullAsZero("historyId")).Return(1); historyReader.Stub(x => x.Read()).Return(true).Repeat.Once(); var creator = Mocks.DynamicMock<IDnaDataReaderCreator>(); creator.Stub(x => x.CreateDnaDataReader("addtermsfilterterm")).Return(Mocks.DynamicMock<IDnaDataReader>()); creator.Stub(x => x.CreateDnaDataReader("addtermsfilterupdate")).Return(historyReader); var getTermsReader = Mocks.DynamicMock<IDnaDataReader>(); getTermsReader.Stub(x => x.Read()).Return(false); creator.Stub(x => x.CreateDnaDataReader("gettermsbymodclassid")).Return(getTermsReader); Mocks.ReplayAll(); string reason = "a reason"; int userId = 0; Error expected = new Error { Type = "UpdateTermsInDatabase", ErrorMessage = "Valid user must be supplied" }; TermsLists target = new TermsLists(); target.Termslist.Add(TermsListTest.GetTermsList()); Error actual = target.UpdateTermsInDatabase(creator, cacheManager, reason, userId, true); Assert.AreEqual(expected.ErrorMessage, actual.ErrorMessage); Assert.AreEqual(expected.Type, actual.Type); creator.AssertWasNotCalled(x => x.CreateDnaDataReader("addtermsfilterterm")); creator.AssertWasNotCalled(x => x.CreateDnaDataReader("addtermsfilterupdate")); }
public void UpdateTermsInDatabase_InvalidTerms_ReturnsCorrectError() { var cacheManager = Mocks.DynamicMock<ICacheManager>(); var historyReader = Mocks.DynamicMock<IDnaDataReader>(); historyReader.Stub(x => x.GetInt32NullAsZero("historyId")).Return(1); historyReader.Stub(x => x.Read()).Return(true).Repeat.Once(); var creator = Mocks.DynamicMock<IDnaDataReaderCreator>(); creator.Stub(x => x.CreateDnaDataReader("addtermsfilterterm")).Return(Mocks.DynamicMock<IDnaDataReader>()); creator.Stub(x => x.CreateDnaDataReader("addtermsfilterupdate")).Return(historyReader); var getTermsReader = Mocks.DynamicMock<IDnaDataReader>(); getTermsReader.Stub(x => x.Read()).Return(false); creator.Stub(x => x.CreateDnaDataReader("gettermsbymodclassid")).Return(getTermsReader); Mocks.ReplayAll(); string reason = "a reason"; int userId = 1; Error expected = new Error { Type = "UpdateTermForModClassId", ErrorMessage = "Term value cannot be empty./r/nTerm value cannot be empty." }; var termsList = new TermsList(1); termsList.Terms.Add(new TermDetails()); TermsLists target = new TermsLists(); target.Termslist.Add(termsList); target.Termslist.Add(termsList); Error actual = target.UpdateTermsInDatabase(creator, cacheManager, reason, userId, true); Assert.AreEqual(expected.ErrorMessage, actual.ErrorMessage); Assert.AreEqual(expected.Type, actual.Type); creator.AssertWasNotCalled(x => x.CreateDnaDataReader("addtermsfilterterm")); creator.AssertWasCalled(x => x.CreateDnaDataReader("addtermsfilterupdate")); }
public void UpdateTermsInDatabase_CorrectValue_ReturnsNullError() { var cacheManager = Mocks.DynamicMock<ICacheManager>(); var historyReader = Mocks.DynamicMock<IDnaDataReader>(); historyReader.Stub(x => x.GetInt32NullAsZero("historyId")).Return(1); historyReader.Stub(x => x.Read()).Return(true).Repeat.Once(); var creator = Mocks.DynamicMock<IDnaDataReaderCreator>(); creator.Stub(x => x.CreateDnaDataReader("addtermsfilterterm")).Return(Mocks.DynamicMock<IDnaDataReader>()); creator.Stub(x => x.CreateDnaDataReader("addtermsfilterupdate")).Return(historyReader); var getTermsReader = Mocks.DynamicMock<IDnaDataReader>(); getTermsReader.Stub(x => x.Read()).Return(false); creator.Stub(x => x.CreateDnaDataReader("gettermsbymodclassid")).Return(getTermsReader); Mocks.ReplayAll(); string reason = "a reason"; int userId = 1; Error expected = new Error { Type = "UpdateTermsInDatabase", ErrorMessage = "Unable to get history id" }; TermsLists target = new TermsLists(); target.Termslist.Add(TermsListTest.GetTermsList()); Error actual = target.UpdateTermsInDatabase(creator, cacheManager, reason, userId, true); Assert.IsNull(actual); creator.AssertWasCalled(x => x.CreateDnaDataReader("addtermsfilterterm")); creator.AssertWasCalled(x => x.CreateDnaDataReader("addtermsfilterupdate")); }