Пример #1
0
        public void ShouldCreateNewContactFormWhenGivenValidContactFormDetails()
        {
            string expectedTitle = "testcontactform";
            string expectedParentUri = "http://local.bbc.co.uk/dna/h2g2";
            string expectedId = "newcontactform" + DateTime.Now.Ticks.ToString();
            string expectedContactEmail = "*****@*****.**";
            string expectedSiteName = "h2g2";
            ModerationStatus.ForumStatus expectedModerationStatus = ModerationStatus.ForumStatus.Reactive;

            ISite mockedSite = mocks.StrictMock<ISite>();
            mockedSite.Stub(x => x.EditorsEmail).Return("*****@*****.**");
            mockedSite.Stub(x => x.SiteName).Return(expectedSiteName);

            ISiteList mockedSiteList = mocks.DynamicMock<ISiteList>();
            mockedSiteList.Stub(x => x.GetSite(expectedSiteName)).Return(mockedSite);

            ContactForm newContactFormDetails = new ContactForm();
            newContactFormDetails.ContactEmail = expectedContactEmail;
            newContactFormDetails.Title = expectedTitle;
            newContactFormDetails.ParentUri = expectedParentUri;
            newContactFormDetails.Id = expectedId;
            newContactFormDetails.ModerationServiceGroup = expectedModerationStatus;
            newContactFormDetails.SiteName = expectedSiteName;
            newContactFormDetails.NotSignedInUserId = 0;

            IDnaDataReader mockedDataReader1 = MockedGetContactFormDetailFromFormID(newContactFormDetails, false);

            int expectedForumId = 789654123; 
            IDnaDataReader mockedDataReader2 = MockedCreateCommentForum(newContactFormDetails, expectedForumId);

            newContactFormDetails.ForumID = expectedForumId; 
            IDnaDataReader mockedDataReader3 =  MockedSetCommentForumAsContactForm(newContactFormDetails);

            IDnaDataReader mockedDataReader4 = MockedGetContactFormDetailFromFormID(newContactFormDetails, true);

            Queue<IDnaDataReader> mockedReaders = new Queue<IDnaDataReader>();
            mockedReaders.Enqueue(mockedDataReader1);
            mockedReaders.Enqueue(mockedDataReader4);

            IDnaDataReaderCreator mockerDataReaderCreator = mocks.StrictMock<IDnaDataReaderCreator>();
            mockerDataReaderCreator.Expect(x => x.CreateDnaDataReader("getcontactformdetailfromformid")).Return(mockedDataReader1);
            mockerDataReaderCreator.Expect(x => x.CreateDnaDataReader("getcontactformdetailfromformid")).Return(mockedDataReader4);
            mockerDataReaderCreator.Stub(x => x.CreateDnaDataReader("commentforumcreate")).Return(mockedDataReader2);
            mockerDataReaderCreator.Stub(x => x.CreateDnaDataReader("setcommentforumascontactform")).Return(mockedDataReader3);

            ICallingUser mockedUser = mocks.StrictMock<ICallingUser>();
            mockedUser.Stub(x => x.IsUserA(UserTypes.Editor)).Return(true);

            Contacts contacts = new Contacts(null, mockerDataReaderCreator, null, mockedSiteList);
            contacts.CallingUser = mockedUser;

            mocks.ReplayAll();

            ContactForm createdContactForm = contacts.CreateContactForm(newContactFormDetails, mockedSiteList.GetSite("h2g2"));

            Assert.AreEqual(expectedContactEmail, createdContactForm.ContactEmail);
            Assert.AreEqual(expectedForumId, createdContactForm.ForumID);
            Assert.AreEqual(expectedId, createdContactForm.Id);
            Assert.AreEqual(expectedParentUri, createdContactForm.ParentUri);
            Assert.AreEqual(expectedTitle, createdContactForm.Title);
            Assert.AreEqual(expectedSiteName, createdContactForm.SiteName);

            mocks.VerifyAll();
        }
Пример #2
0
        public void ShouldThrowInvalidContactEmailExceptionWhenCreatingANewFormGivenAnInvalidContactEmailAddress()
        {
            string sitename = "h2g2";
            ISite mockedSite = mocks.StrictMock<ISite>();
            mockedSite.Stub(x => x.SiteName).Return(sitename);

            ContactForm form = new ContactForm() { Id = "doesnotexist", SiteName = sitename, ContactEmail = "invalid.email@crapemailaddress" };
            IDnaDataReader mockedDataReader = MockedGetContactFormDetailFromFormID(form, false);
            IDnaDataReaderCreator mockerDataReaderCreator = mocks.StrictMock<IDnaDataReaderCreator>();
            mockerDataReaderCreator.Expect(x => x.CreateDnaDataReader("getcontactformdetailfromformid")).Return(mockedDataReader);

            Contacts contacts = new Contacts(null, mockerDataReaderCreator, null, null);

            ICallingUser mockedUser = mocks.StrictMock<ICallingUser>();
            mockedUser.Stub(x => x.IsUserA(UserTypes.Editor)).Return(true);
            contacts.CallingUser = mockedUser;

            mocks.ReplayAll();

            try
            {
                ContactForm createdContactForm = contacts.CreateContactForm(form, mockedSite);
            }
            catch (ApiException ex)
            {
                Assert.AreEqual(ApiException.GetError(ErrorType.InvalidContactEmail).Message, ex.Message);
                throw ex;
            }
        }
Пример #3
0
        public void ShouldThrowNotAuthorizedExceptionWhenCreatingANullCallingUser()
        {
            string sitename = "h2g2";
            ISite mockedSite = mocks.StrictMock<ISite>();
            mockedSite.Stub(x => x.SiteName).Return(sitename);

            ContactForm form = new ContactForm() { Id = "doesnotexist", SiteName = sitename };
            IDnaDataReader mockedDataReader = MockedGetContactFormDetailFromFormID(form, false);
            IDnaDataReaderCreator mockerDataReaderCreator = mocks.StrictMock<IDnaDataReaderCreator>();
            mockerDataReaderCreator.Expect(x => x.CreateDnaDataReader("getcontactformdetailfromformid")).Return(mockedDataReader);

            Contacts contacts = new Contacts(null, mockerDataReaderCreator, null, null);

            mocks.ReplayAll();

            try
            {
                ContactForm createdContactForm = contacts.CreateContactForm(form, mockedSite);
            }
            catch (ApiException ex)
            {
                Assert.AreEqual(ApiException.GetError(ErrorType.NotAuthorized).Message, ex.Message);
                throw ex;
            }
        }
Пример #4
0
        public void ShouldThrowInvalidContactEmailExceptionWhenCreatingANewFormGivenNoContactFormDetails()
        {
            string sitename = "h2g2";
            ISite mockedSite = mocks.StrictMock<ISite>();
            mockedSite.Stub(x => x.SiteName).Return(sitename);

            Contacts contacts = new Contacts(null, null, null, null);

            mocks.ReplayAll();

            try
            {
                ContactForm createdContactForm = contacts.CreateContactForm(null, mockedSite);
            }
            catch (ApiException ex)
            {
                Assert.AreEqual(ApiException.GetError(ErrorType.InvalidContactEmail).Message, ex.Message);
                throw ex;
            }
        }
Пример #5
0
 public void ShouldThrowUnknownSiteExceptionWhenCreatingANewFormGivenANullSite()
 {
     Contacts contacts = new Contacts(null, null, null, null);
     try
     {
         ContactForm createdContactForm = contacts.CreateContactForm(null, null);
     }
     catch (ApiException ex)
     {
         Assert.AreEqual(ApiException.GetError(ErrorType.UnknownSite).Message, ex.Message);
         throw ex;
     }
 }