public void Initialize() { InitializeAutoMapper.Initialize(); mockRepository = new MockRepository(MockBehavior.Default); mockCampaignRepository = mockRepository.Create <ICampaignRepository>(); mockContactRepository = mockRepository.Create <IContactRepository>(); mockTagRepository = mockRepository.Create <ITagRepository>(); mockUrlService = mockRepository.Create <IUrlService>(); mockIndexingService = mockRepository.Create <IIndexingService>(); mockSearchService = mockRepository.Create <ISearchService <Campaign> >(); mockContactSearchService = mockRepository.Create <ISearchService <Contact> >(); mockCachingService = mockRepository.Create <ICachingService>(); mockAdvancedSearchService = mockRepository.Create <IAdvancedSearchService>(); mockUserService = mockRepository.Create <IUserService>(); mockUserRepository = mockRepository.Create <IUserRepository>(); mockAccountService = mockRepository.Create <IAccountService>(); mockMessageService = mockRepository.Create <IMessageService>(); mockCommunicaitonService = mockRepository.Create <ICommunicationService>(); mockServiceProviderRepository = mockRepository.Create <IServiceProviderRepository>(); IUnitOfWork mockUnitOfWork = mockRepository.Create <IUnitOfWork>().Object; CampaignMockData campaignMockData = new CampaignMockData(); campaignService = new CampaignService(mockCampaignRepository.Object, mockContactRepository.Object, mockUnitOfWork, mockUrlService.Object, mockTagRepository.Object, mockCachingService.Object, mockIndexingService.Object, mockSearchService.Object, mockAdvancedSearchService.Object, mockUserService.Object, mockUserRepository.Object, mockMessageService.Object, mockCommunicaitonService.Object, mockAccountService.Object, mockServiceProviderRepository.Object, mockContactSearchService.Object); }
public void GetCampaign_SearchWithCampaignId_ReturnCampaignSuccessfully() { Campaign campaign = CampaignMockData.CreateCampaignWithCustomValues(mockRepository, 5, "Test", new DateTime(2012, 1, 1) , "*****@*****.**", 5, Entities.CampaignStatus.Draft, sampleLayout, "Test campaign", "", 1); mockCampaignRepository.Setup(tr => tr.GetCampaignById(It.IsAny <int>())).Returns(campaign); GetCampaignResponse response = new GetCampaignResponse(); GetCampaignRequest request = new GetCampaignRequest(LEGAL_CAMPAIGN_ID); response = campaignService.GetCampaign(request); mockRepository.VerifyAll(); Assert.AreEqual(campaign.Id, response.CampaignViewModel.CampaignID); }
public void DeleteCampaign_PassedValidCampaignId_SoftDeletedSuccessfully_NotImplementedYet() { mockCampaignRepository.Setup(cr => cr.DeactivateCampaign(It.IsAny <int[]>(), It.IsAny <int>())).Verifiable(); CampaignViewModel campaignViewModel = CampaignMockData.CreateCampaignViewModelWithCustomValues(mockRepository, 1, DateTime.Now.ToString() , "test", DateTime.Now, "*****@*****.**", 2, Entities.CampaignStatus.Scheduled, 1, 2, 2); DeleteCampaignRequest request = new DeleteCampaignRequest() { CampaignID = new int[] { campaignViewModel.CampaignID } }; DeleteCampaignResponse response = campaignService.Deactivate(request); mockCampaignRepository.VerifyAll(); Assert.AreEqual(null, response.Exception); }
public void UpdateCampaign_PassedInvalidCampaign_NotInserted_NotImplementedYet() { mockCampaignRepository.Setup(cr => cr.IsCampaignNameUnique(It.IsAny <Campaign>())).Returns(true); CampaignViewModel campaignViewModel = CampaignMockData.CreateCampaignViewModelWithCustomValues(mockRepository, 1, DateTime.Now.ToString() , "test", DateTime.Now.AddDays(-1), "*****@*****.**", 2, Entities.CampaignStatus.Scheduled, 1, 2, 2); UpdateCampaignRequest request = new UpdateCampaignRequest() { CampaignViewModel = campaignViewModel }; UpdateCampaignResponse response = campaignService.UpdateCampaign(request); mockCampaignRepository.VerifyAll(); Assert.AreEqual("Schedule time is invalid\r\n", response.Exception.Message); }
public void UpdateCampaign_PassedValidCampaign_UpdatedSuccessfully() { mockCampaignRepository.Setup(cr => cr.Update(It.IsAny <Campaign>())).Verifiable(); mockCampaignRepository.Setup(cr => cr.IsCampaignNameUnique(It.IsAny <Campaign>())).Returns(true); CampaignViewModel campaignViewModel = CampaignMockData.CreateCampaignViewModelWithCustomValues(mockRepository, 1, DateTime.Now.ToString() , "test", DateTime.Now, "*****@*****.**", 2, Entities.CampaignStatus.Scheduled, 1, 2, 2); UpdateCampaignRequest request = new UpdateCampaignRequest() { CampaignViewModel = campaignViewModel }; UpdateCampaignResponse response = campaignService.UpdateCampaign(request); mockCampaignRepository.VerifyAll(); Assert.AreEqual(null, response.Exception); }
public void InsertCampaign_PassedCampaignWithNameThatAlreadyExists_ThrowException() { mockCampaignRepository.Setup(tr => tr.IsCampaignNameUnique(It.IsAny <Campaign>())).Returns(false); CampaignViewModel campaignViewModel = CampaignMockData.CreateCampaignViewModelWithCustomValues(mockRepository, 0, DateTime.Now.ToString() , "test", DateTime.Now, "*****@*****.**", 2, Entities.CampaignStatus.Scheduled, 1, 2, 2); InsertCampaignRequest request = new InsertCampaignRequest() { CampaignViewModel = campaignViewModel }; InsertCampaignResponse response = new InsertCampaignResponse(); response = campaignService.InsertCampaign(request); mockRepository.VerifyAll(); Assert.AreNotEqual(null, response.Exception); }
public void InsertCampaign_WithNoContactTags_NotInserted() { mockCampaignRepository.Setup(tr => tr.IsCampaignNameUnique(It.IsAny <Campaign>())).Returns(true); mockCampaignRepository.Setup(tr => tr.Insert(It.IsAny <Campaign>())).Verifiable("Insert method called"); CampaignViewModel campaignViewModel = CampaignMockData.CreateCampaignViewModelWithCustomValues(mockRepository, 0, DateTime.Now.ToString() , "test", DateTime.Now, "*****@*****.**", 2, Entities.CampaignStatus.Scheduled, 1, 2, 2); InsertCampaignRequest request = new InsertCampaignRequest() { CampaignViewModel = campaignViewModel }; InsertCampaignResponse response = new InsertCampaignResponse(); response = campaignService.InsertCampaign(request); mockRepository.VerifyAll(); Assert.AreEqual(null, response.Exception); }
public static CampaignViewModel CreateCampaignViewModelWithCustomValues(MockRepository mockRepository, int campaignId , string name, string subject, DateTime?scheduleTime, string from, int contactsCount, CampaignStatus campaignStatus, byte templateId, int campaignTagCount, int contactTagCount) { CampaignViewModel campaignViewModel = new CampaignViewModel(); campaignViewModel.CampaignID = campaignId; campaignViewModel.Name = name; campaignViewModel.Subject = subject; campaignViewModel.ScheduleTime = scheduleTime; campaignViewModel.From = from; campaignViewModel.HTMLContent = "test"; campaignViewModel.CampaignStatus = campaignStatus; campaignViewModel.CampaignTemplate = new CampaignTemplateViewModel() { TemplateId = templateId }; campaignViewModel.Contacts = CampaignMockData.GetMockCampaignContactViewModels(mockRepository, 5); var list = new List <TagViewModel>() { new TagViewModel() { TagID = 1 }, new TagViewModel() { TagID = 2 } }; for (int i = 0; i < campaignTagCount; i++) { list.Add(new TagViewModel() { TagID = i }); } campaignViewModel.TagsList = list; list.Clear(); for (int i = 0; i < campaignTagCount; i++) { list.Add(new TagViewModel() { TagID = i }); } campaignViewModel.ContactTags = list; return(campaignViewModel); }
public static Campaign CreateCampaignWithCustomValues(MockRepository mockRepository, int campaignId, string name, DateTime?scheduleTime , string from, int contactsCount, CampaignStatus campaignStatus, CampaignTemplate template, string subject, string content, byte emailProviderID) { Campaign campaign = new Campaign(); campaign.Id = campaignId; campaign.Name = name; campaign.ScheduleTime = scheduleTime; campaign.From = from; campaign.Contacts = CampaignMockData.GetMockContacts(mockRepository, 5).ToList(); campaign.CampaignStatus = campaignStatus; campaign.Template = template; campaign.Subject = subject; campaign.HTMLContent = content; campaign.ServiceProviderID = emailProviderID; return(campaign); }