public void CanCreateTaskForApprpriateClients() { var clientRepository = new LocalRepository <Client>(); var taskQueueStorage = new Mock <ITaskQueueStorage>(); var taskRepository = new LocalRepository <InsideModel.Models.Task>(); var serverTime = new Mock <IServerTime>(); var taskManager = new Mock <ITaskManager>(); var task = new CreateUpdatePhonecallsTasksForClients( clientRepository, taskQueueStorage.Object, taskRepository, serverTime.Object, taskManager.Object); clientRepository.Add(ModelHelper.TestClient1AllDataNoReferences); clientRepository.Add(ModelHelper.TestClient2AllDataNoReferences); var taskExecutionDate = new DateTime(2014, 01, 01); serverTime.Setup(st => st.RequestStarted).Returns(taskExecutionDate); var taskMessage = "{\"StartDate\":\"2014-01-01\",\"EndDate\":\"2014-02-01\"}"; var message = new InsideModel.Models.Task() { Message = taskMessage }; task.PerformTask(message); taskQueueStorage.Verify(ts => ts.Add(It.Is <InsideModel.Models.Task>(t => t.Message == "{\"ClientId\":1,\"StartDate\":\"2014-01-01T00:00:00\",\"EndDate\":\"2014-02-01T00:00:00\"}")), Times.Exactly(1)); taskQueueStorage.Verify(ts => ts.Add(It.Is <InsideModel.Models.Task>(t => t.Message == "{\"ClientId\":3,\"StartDate\":\"2014-01-01T00:00:00\",\"EndDate\":\"2014-02-01T00:00:00\"}")), Times.Exactly(1)); }
public void RemoveExpiredTokens() { var tokenRepository = new LocalRepository <Token>(); var userRepository = new Mock <IRepository <InsideUser> >(); var provider = new AccessTokenProvider(tokenRepository, userRepository.Object); var expiredToken = new Token() { Id = 1, UserId = "NewGuidString", AccessToken = "Some Random Generated String 1", ExpirationDate = DateTime.Today.AddDays(-1) }; var validToken = new Token() { Id = 2, UserId = "NewGuidString2", AccessToken = "Some Random Generated String 2", ExpirationDate = DateTime.Today.AddDays(1) }; tokenRepository.Add(expiredToken); tokenRepository.Add(validToken); provider.RemoveExpired(); Assert.AreEqual(1, tokenRepository.All().Count()); Assert.AreEqual(validToken.ExpirationDate, tokenRepository.All().Single().ExpirationDate); }
public void CanHandleNewBudgets() { IRepository <Client> clientRepository = new LocalRepository <Client>(); IRepository <Budget> budgetRepository = new LocalRepository <Budget>(); var userManager = new Mock <IIdentityMembershipProvider>(); Budget budget1 = new Budget { Id = 1, ClientId = 1, IsHandled = false }; Budget budget2 = new Budget { Id = 2, ClientId = 1, IsHandled = false }; budgetRepository.Add(budget1); budgetRepository.Add(budget2); Assert.AreEqual(2, budgetRepository.All().Count()); var controller = new BudgetController(clientRepository, budgetRepository, userManager.Object); var result = controller.Handle(1); Assert.AreEqual(true, budgetRepository.Where(b => b.Id == budget1.Id).Single().IsHandled); Assert.AreEqual(false, budgetRepository.Where(b => b.Id == budget2.Id).Single().IsHandled); }
public void CanDeleteABudget() { IRepository <Client> clientRepository = new LocalRepository <Client>(); IRepository <Budget> budgetRepository = new LocalRepository <Budget>(); var userManager = new Mock <IIdentityMembershipProvider>(); Budget budget1 = new Budget(); budget1.Id = 1; budget1.Value = 1000; budget1.Month = new DateTime(2014, 1, 1); budget1.ClientId = 1; Budget budget2 = new Budget(); budget2.Id = 2; budget2.Value = 2000; budget2.Month = new DateTime(2014, 2, 1); budget2.ClientId = 2; budgetRepository.Add(budget1); budgetRepository.Add(budget2); Assert.AreEqual(2, budgetRepository.All().Count()); var controller = new BudgetController(clientRepository, budgetRepository, userManager.Object); controller.Delete(1); Assert.AreEqual(1, budgetRepository.All().Count()); }
public void CanGetListOfLabels() { var labelRepository = new LocalRepository <Label>(); labelRepository.Add(new Label() { Id = 1, Name = "Label 1" }); labelRepository.Add(new Label() { Id = 2, Name = "Label 2" }); labelRepository.Add(new Label() { Id = 3, Name = "Label 3" }); var clientRepository = new LocalRepository <Client>(); var controller = new LabelController(labelRepository, clientRepository); var result = controller.Index() as ViewResult; var resultModel = result.Model as LabelsViewModel; Assert.AreEqual(3, resultModel.Labels.Count); Assert.IsTrue(resultModel.Labels.Any(l => l.Id == 1 && l.Name == "Label 1")); Assert.IsTrue(resultModel.Labels.Any(l => l.Id == 2 && l.Name == "Label 2")); Assert.IsTrue(resultModel.Labels.Any(l => l.Id == 3 && l.Name == "Label 3")); }
public void CanDeleteLabel() { var labelRepository = new LocalRepository <Label>(); var clientRepository = new LocalRepository <Client>(); var controller = new LabelController(labelRepository, clientRepository); labelRepository.Add(new Label() { Id = 1, Name = "Label 1" }); labelRepository.Add(new Label() { Id = 2, Name = "Label 2" }); labelRepository.Add(new Label() { Id = 3, Name = "Label 3" }); Assert.AreEqual(3, labelRepository.All().Count()); controller.Delete(2); Assert.AreEqual(2, labelRepository.All().Count()); Assert.IsTrue(labelRepository.All().Any(l => l.Id == 1 && l.Name == "Label 1")); Assert.IsTrue(labelRepository.All().Any(l => l.Id == 3 && l.Name == "Label 3")); }
public void CreateCorrectTextForManyEmailContactInRepository() { var contactRepository = new LocalRepository <Contact>(); var contactProperty = new ContactProperty() { Id = 1, ContactId = 1, Type = "FromEmail", Value = "*****@*****.**" }; var contact1 = new Contact() { Id = 1, LeadType = "Email" }; contact1.Property.Add(contactProperty); var contact2 = new Contact() { Id = 2, LeadType = "Email" }; contactRepository.Add(contact2); contactRepository.Add(contact1); var notificationTextBuilder = new PhoneNotificationTextBuilder(contactRepository); var result = notificationTextBuilder.GetDefinition(contact1.Id); Assert.AreEqual("Du har fått ett nytt email från [email protected]", result); }
public void CanGetPageContactListFilteredOnTypeEmail() { var leadRepository = new LocalRepository <Contact>(); var userManager = new Mock <IIdentityMembershipProvider>(); var date = new DateTime(2014, 10, 15, 15, 45, 33); leadRepository.Add(new Contact() { ClientId = 1, LeadType = "Phone", Date = date.AddDays(1) }); leadRepository.Add(new Contact() { ClientId = 1, LeadType = "Email", Date = date.AddDays(2) }); leadRepository.Add(new Contact() { ClientId = 1, LeadType = "Email", Date = date.AddDays(3) }); leadRepository.Add(new Contact() { ClientId = 2, LeadType = "Phone", Date = date.AddDays(4) }); var serverTime = new Mock <IServerTime>(); serverTime.Setup(st => st.RequestStarted).Returns(new DateTime()); var controller = new LeadController(leadRepository, userManager.Object, serverTime.Object); controller.Request = new HttpRequestMessage { RequestUri = new Uri("http://insidetest.helloy.se/api/client/1/contact/") }; controller.Configuration = new HttpConfiguration(); controller.Configuration.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional }); controller.RequestContext.RouteData = new HttpRouteData( route: new HttpRoute(), values: new HttpRouteValueDictionary { { "ListContacts", "products" } }); var response = controller.GetContacts(1, type: "Email") as PageResult <Contact>; var resultList = response.results; Assert.AreEqual(2, resultList.Count()); Assert.AreEqual("Email", resultList.ToArray()[0].LeadType); Assert.AreEqual("Email", resultList.ToArray()[1].LeadType); }
public void CanGetLinkToNextPage() { var leadRepository = new LocalRepository <Contact>(); var userManager = new Mock <IIdentityMembershipProvider>(); var date = new DateTime(2014, 10, 15, 15, 45, 33); leadRepository.Add(new Contact() { ClientId = 1, LeadType = "Phone", Date = date.AddDays(1) }); for (int i = 0; i < 35; i++) { leadRepository.Add(new Contact() { ClientId = 1, LeadType = "Phone", Date = date.AddDays(i) }); } leadRepository.Add(new Contact() { ClientId = 2, LeadType = "Phone", Date = date.AddDays(4) }); var serverTime = new Mock <IServerTime>(); serverTime.Setup(st => st.RequestStarted).Returns(new DateTime()); var controller = new LeadController(leadRepository, userManager.Object, serverTime.Object); controller.Request = new HttpRequestMessage { RequestUri = new Uri("http://insidetest.helloy.se/api/client/1/contact/?clientId=1") }; controller.Configuration = new HttpConfiguration(); controller.Configuration.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional }); controller.Configuration.Routes.Add("ListContacts", new HttpRoute("api/client/{clientId}/contact/")); HttpRouteValueDictionary httpRouteValueDictionary = new HttpRouteValueDictionary { { "ListContacts", "products" } }; controller.RequestContext.RouteData = new HttpRouteData( route: new HttpRoute(), values: httpRouteValueDictionary); var response = controller.GetContacts(1) as PageResult <Contact>; var resultList = response.results; Assert.AreEqual(20, resultList.Count()); Assert.IsTrue(String.IsNullOrEmpty(response.prevPageLink)); Assert.IsFalse(String.IsNullOrEmpty(response.nextPageLink)); }
public void CanCreateCreateImportWebEventsTaskForActiveClientsWithCorrectLabelAndAlayticsId() { var clientRepository = new LocalRepository <Client>(); var taskQueueStorage = new Mock <ITaskQueueStorage>(); var taskRepository = new LocalRepository <InsideModel.Models.Task>(); var serverTime = new Mock <IServerTime>(); var taskManager = new Mock <ITaskManager>(); var task = new ImportCustomEventsTaskCreator( serverTime.Object, taskManager.Object, taskRepository, clientRepository, taskQueueStorage.Object); var clientLable = new Label() { Id = 1, Name = "Custom Event" }; var client1 = new Client() { Id = 1, Labels = new Collection <Label>() { clientLable }, IsActive = true, AnalyticsTableId = "someId" }; var client2 = new Client() { Id = 2, Labels = new Collection <Label>() { clientLable }, IsActive = true, AnalyticsTableId = "someId" }; var clientWithoutLabel = new Client() { Id = 3 }; clientRepository.Add(client1); clientRepository.Add(client2); clientRepository.Add(clientWithoutLabel); var taskExecutionDate = new DateTime(2014, 01, 01); serverTime.Setup(st => st.RequestStarted).Returns(taskExecutionDate); task.PerformTask(new InsideModel.Models.Task() { Message = "" }); taskQueueStorage.Verify(ts => ts.Add(It.Is <InsideModel.Models.Task>(t => t.Message == "{\"ClientId\":1,\"StartDate\":\"2013-12-29T00:00:00\",\"EndDate\":\"2014-01-01T00:00:00\"}" && t.Type == "ImportCustomEvents")), Times.Exactly(1)); taskQueueStorage.Verify(ts => ts.Add(It.Is <InsideModel.Models.Task>(t => t.Message == "{\"ClientId\":2,\"StartDate\":\"2013-12-29T00:00:00\",\"EndDate\":\"2014-01-01T00:00:00\"}" && t.Type == "ImportCustomEvents")), Times.Exactly(1)); }
public void InActiveClientOrClientWithNoAnalyticIdDontCreateTask() { var clientRepository = new LocalRepository <Client>(); var taskQueueStorage = new Mock <ITaskQueueStorage>(); var taskRepository = new LocalRepository <InsideModel.Models.Task>(); var serverTime = new Mock <IServerTime>(); var taskManager = new Mock <ITaskManager>(); var task = new ImportCustomEventsTaskCreator( serverTime.Object, taskManager.Object, taskRepository, clientRepository, taskQueueStorage.Object); var clientLable = new Label() { Id = 1, Name = "Custom Event" }; var inActiveClient = new Client() { Id = 1, Labels = new Collection <Label>() { clientLable }, AnalyticsTableId = "someId" }; var noAnalyticIdclient = new Client() { Id = 2, Labels = new Collection <Label>() { clientLable }, IsActive = true }; var clientWithoutLabel = new Client() { Id = 3 }; clientRepository.Add(inActiveClient); clientRepository.Add(noAnalyticIdclient); clientRepository.Add(clientWithoutLabel); var taskExecutionDate = new DateTime(2014, 01, 01); serverTime.Setup(st => st.RequestStarted).Returns(taskExecutionDate); task.PerformTask(new InsideModel.Models.Task() { Message = "" }); Assert.AreEqual(0, taskRepository.All().Count()); taskQueueStorage.Verify(ts => ts.Add(It.IsAny <InsideModel.Models.Task>()), Times.Never); }
public void ShowOnlyActiveClientsOfCertainConsultant() { var clientRepository = new LocalRepository <Client>(); var clientInRepository1 = ModelHelper.TestClient1AllDataNoReferences; var clientInRepository2 = ModelHelper.TestClient2AllDataNoReferences; var consultantMembershipProviderId1 = Guid.NewGuid().ToString(); var consultantMembershipProviderId2 = Guid.NewGuid().ToString(); var userManager = new Mock <IIdentityMembershipProvider>(); var consultantRepository = new LocalRepository <InsideUser>(); var labelRepository = new LocalRepository <Label>(); var consultant1 = new InsideUser() { Id = consultantMembershipProviderId1, Role = new Collection <InsideRole> { ModelHelper.TestConsultantRole } }; clientInRepository1.IsActive = true; clientInRepository1.ConsultantId = consultant1.Id; clientInRepository1.Consultant = consultant1; consultantRepository.Add(consultant1); clientRepository.Add(clientInRepository1); var consultant2 = new InsideUser() { Id = consultantMembershipProviderId2 }; consultantRepository.Add(consultant2); clientInRepository2.IsActive = true; clientInRepository2.ConsultantId = consultant2.Id; clientInRepository2.Consultant = consultant2; clientRepository.Add(clientInRepository2); userManager.Setup(um => um.GetRoles(consultant1.Id)).Returns(new List <string> { "consultant" }); var clientController = new ClientController(clientRepository, labelRepository, consultantRepository, userManager.Object); var claim = new Claim("test", consultant1.Id); ModelHelper.SetClaimAsCurrentUserForController(claim, clientController); var result = clientController.Index(false, null) as ViewResult; var clients = result.Model as ClientsViewModel; Assert.AreEqual(1, clients.Clients.Count()); }
public void IsAddingLabelsToModel() { var labelRepository = new LocalRepository <Label>(); labelRepository.Add(new Label() { Id = 1, Name = "Label 1" }); labelRepository.Add(new Label() { Id = 2, Name = "Label 2" }); var clientRepository = new LocalRepository <Client>(); var clientInRepository = ModelHelper.TestClient1AllDataNoReferences; var consultantMembershipProviderId = Guid.NewGuid().ToString(); var userManager = new Mock <IIdentityMembershipProvider>(); var consultantRepository = new LocalRepository <InsideUser>(); var consultant = new InsideUser() { Id = consultantMembershipProviderId, Role = new Collection <InsideRole> { ModelHelper.TestConsultantRole } }; consultantRepository.Add(consultant); clientInRepository.IsActive = false; clientInRepository.Consultant = consultant; clientRepository.Add(clientInRepository); userManager.Setup(um => um.GetRoles(consultant.Id)).Returns(new List <string> { "mockRole" }); var clientController = new ClientController(clientRepository, labelRepository, consultantRepository, userManager.Object); var claim = new Claim("test", consultant.Id); ModelHelper.SetClaimAsCurrentUserForController(claim, clientController); var result = clientController.Index(true, null) as ViewResult; var resultModel = result.Model as ClientsViewModel; Assert.AreEqual(2, resultModel.Labels.Count()); Assert.IsTrue(resultModel.Labels.Any(l => l.Name == "Label 1" && l.Id == 1)); Assert.IsTrue(resultModel.Labels.Any(l => l.Name == "Label 2" && l.Id == 2)); }
public void CanSetTagsForContactForClientDuplicateIgnored() { var tagRepository = new LocalRepository <Tag>(); var userManager = new Mock <IIdentityMembershipProvider>(); var contactRepository = new LocalRepository <Contact>(); var tag1 = new Tag { Id = 1, Name = "Tag1", ClientId = 1 }; tagRepository.Add(tag1); var tagToSet = new Tag { Id = 2, Name = "Tag2", ClientId = 1 }; tagRepository.Add(tagToSet); var contact = new Contact { Id = 1, ClientId = 1 }; contact.Tags.Add(tag1); contactRepository.Add(contact); var controller = new TagController(userManager.Object, tagRepository, contactRepository); var result = controller.SetTag(contact.ClientId, contact.Id, tagToSet.Id); Assert.AreEqual(2, tagRepository.All().Count()); Assert.AreEqual(2, contactRepository.Single(c => c.Id == 1).Tags.Count()); Assert.AreEqual("Tag1", contactRepository.Single(c => c.Id == 1).Tags.Single(t => t.Id == 1).Name); Assert.AreEqual("Tag2", contactRepository.Single(c => c.Id == 1).Tags.Single(t => t.Id == 2).Name); var result2 = controller.SetTag(contact.ClientId, contact.Id, tagToSet.Id); Assert.AreEqual(2, contactRepository.Single(c => c.Id == 1).Tags.Count()); Assert.AreEqual("Tag1", contactRepository.Single(c => c.Id == 1).Tags.Single(t => t.Id == 1).Name); Assert.AreEqual("Tag2", contactRepository.Single(c => c.Id == 1).Tags.Single(t => t.Id == 2).Name); }
public void MultiMandrilleventsWithSameIdIsNotDuplicatedInRepository() { var leadRepository = new LocalRepository <Contact>(); var xDataProvider = new Mock <IExternalDataProvider>(); var contactAutoRating = new Mock <IContactAutoRating>(); var mandrill_event = "[{\"event\":\"send\",\"msg\":{\"ts\":1365109999,\"subject\":\"This an example webhook message\",\"email\":\"[email protected]\"," + "\"sender\":\"[email protected]\",\"tags\":[\"webhook-example\"],\"opens\":[],\"clicks\":[],\"state\":\"sent\",\"metadata\":{\"user_id\":111}," + "\"_id\":\"1\",\"_version\":\"exampleaaaaaaaaaaaaaaa1\"},\"_id\":\"1\",\"ts\":1385020180}," + "{\"event\":\"send\",\"msg\":{\"ts\":1365109999,\"subject\":\"This an example webhook message\",\"email\":\"[email protected]\"," + "\"sender\":\"[email protected]\",\"tags\":[\"webhook-example\"],\"opens\":[],\"clicks\":[],\"state\":\"sent\",\"metadata\":{\"user_id\":111}," + "\"_id\":\"1\",\"_version\":\"exampleaaaaaaaaaaaaaaa1\"},\"_id\":\"1\",\"ts\":1385020180}," + "{\"event\":\"send\",\"msg\":{\"ts\":1365109999,\"subject\":\"This an example webhook message2\",\"email\":\"[email protected]\"," + "\"sender\":\"[email protected]\",\"tags\":[\"webhook-example\"],\"opens\":[],\"clicks\":[],\"state\":\"sent\",\"metadata\":{\"user_id\":222}," + "\"_id\":\"2\",\"_version\":\"exampleaaaaaaaaaaaaaaa2\"},\"_id\":\"2\",\"ts\":1385020180}]"; var clientRepository = new LocalRepository <Client>(); var client = ModelHelper.TestClient1AllDataNoReferences; client.EmailAddress = "*****@*****.**"; clientRepository.Add(client); var client2 = ModelHelper.TestClient1AllDataNoReferences; client2.EmailAddress = "*****@*****.**"; client2.Id = 2; clientRepository.Add(client2); var serverTime = new Mock <IServerTime>(); serverTime.Setup(st => st.RequestStarted).Returns(new DateTime(2013, 11, 21, 8, 50, 0)); //2013-11-21 08:49:40 on email date var contactService = new Mock <IContactService>(); var emailController = new WebhookController(leadRepository, clientRepository, contactService.Object, serverTime.Object, xDataProvider.Object, contactAutoRating.Object); var result = emailController.ManrillWebhook(mandrill_event); Assert.AreEqual(2, leadRepository.All().Count()); Assert.AreEqual("This an example webhook message", leadRepository.Where(l => l.Property.Any(lp => lp.Type == "MandrillId" && lp.Value == "1")).First().Property.First(lp => lp.Type == "Subject").Value); Assert.AreEqual("This an example webhook message2", leadRepository.Where(l => l.Property.Any(lp => lp.Type == "MandrillId" && lp.Value == "2")).First().Property.First(lp => lp.Type == "Subject").Value); contactAutoRating.Verify(ar => ar.SetAutoRating(It.IsAny <Contact>()), Times.Exactly(3)); contactService.Verify(cs => cs.NotifyClientsForNewContactWithEmail(It.IsAny <int>()), Times.Exactly(2)); contactService.Verify(cs => cs.NotifyClientsForNewContactWithPhoneNotification(It.IsAny <int>()), Times.Exactly(2)); contactService.Verify(cs => cs.NotifyClientsForNewContactWithSmsNotification(It.IsAny <int>()), Times.Exactly(2)); }
public void EditPostEmptyMembershipProviderIdReturnsViewOnException() { var adminRepository = new LocalRepository <InsideUser>(); var userManager = new Mock <IIdentityMembershipProvider>(); var accountManagerInRepository = ModelHelper.TestAccountManager; accountManagerInRepository.Id = null; adminRepository.Add(accountManagerInRepository); var controller = new AccountManagerController(adminRepository, userManager.Object); var accountManager1 = new AccountManagerViewModel() { Name = accountManagerInRepository.Name, Id = accountManagerInRepository.Id, Password = "******", Email = "*****@*****.**" }; userManager.Setup(u => u.GetUsers()).Returns(adminRepository.All); userManager.Setup(u => u.FindById(accountManagerInRepository.Id)).Returns(accountManagerInRepository); userManager.Setup(u => u.Create(It.IsAny <InsideUser>(), "Test Edited")).Returns(false).Verifiable(); var result = controller.Edit(accountManager1) as ViewResult; Assert.IsTrue(controller.ModelState.Count > 0); }
public void CanGetPositionsWithHistoryForClientInRepositoryWithOkDomain() { var clientRepository = new LocalRepository <Client>();; var serpRankingRepository = new Mock <ISerpRankingRepository>(); var seoService = new Mock <ISeoService>(); var downloadManager = new Mock <IDownloadManager>(); var seoDataMapper = new Mock <ISeoDataImportMapper>(); var client = ModelHelper.TestClient1AllDataNoReferences; clientRepository.Add(client); var startDate = new DateTime(2013, 06, 01); var endDate = new DateTime(2013, 09, 01); serpRankingRepository.Setup(sr => sr.GetRankingsWithHistory(client.Domain, startDate, endDate)) .Returns(new List <SerpRankingWithHistory>() { new SerpRankingWithHistory() { RankingUrl = client.Domain } }); var seoController = new SeoController(clientRepository, serpRankingRepository.Object, seoService.Object, downloadManager.Object, seoDataMapper.Object); var result = seoController.GetPositionsWithHistory(client.Id, startDate, endDate) as ContentResult; var resultObject = JsonConvert.DeserializeObject <List <SerpRankingWithHistory> >(result.Content); Assert.IsTrue(resultObject.Any(ro => ro.RankingUrl == client.Domain)); }
public void CanEditValueAndCommentOfABudget() { IRepository <Client> clientRepository = new LocalRepository <Client>(); IRepository <Budget> budgetRepository = new LocalRepository <Budget>(); var userManager = new Mock <IIdentityMembershipProvider>(); Budget budget1 = new Budget(); budget1.Id = 1; budget1.Value = 1000; budget1.Month = new DateTime(2014, 1, 1); budget1.ClientId = 1; budgetRepository.Add(budget1); Assert.AreEqual(1, budgetRepository.All().Count()); var controller = new BudgetController(clientRepository, budgetRepository, userManager.Object); var createBudgetPostMessage = new EditBudgetViewModel { id = 1, clientId = 1, month = "2014-01-01", value = 3000, comment = "New Comment" }; controller.Edit(createBudgetPostMessage); Assert.AreEqual(1, budgetRepository.All().Count()); Assert.AreEqual(3000, budgetRepository.All().First().Value); Assert.AreEqual("New Comment", budgetRepository.All().First().Comment); }
public void EditClientGetReturnsView() { var clientRepository = new LocalRepository <Client>(); var clientInRepository = ModelHelper.TestClient1AllDataNoReferences; var userManager = new Mock <IIdentityMembershipProvider>(); var labelRepository = new LocalRepository <Label>(); var clientID = 1; clientInRepository.Id = clientID; clientRepository.Add(clientInRepository); var consultantRepositoryMoq = new Mock <IRepository <InsideUser> >(); userManager.Setup(um => um.GetRoles(It.IsAny <string>())).Returns(new List <string> { "mockRole" }); var clientController = new ClientController(clientRepository, labelRepository, consultantRepositoryMoq.Object, userManager.Object); var claim = new Claim("test", "AnyId"); ModelHelper.SetClaimAsCurrentUserForController(claim, clientController); var result = clientController.Edit(clientID) as ViewResult; var resultModel = result.Model as ClientPageViewModel; Assert.AreEqual(clientID, resultModel.ClientViewModel.Id, "Expected edit view of model."); }
public void ThrowExceptionWithInActiveClient() { var phoneNotificationSender = new Mock <INotificationSender>(); var notificationPhoneTextBuilder = new Mock <IPhoneNotificationTextBuilder>(); var contactRepository = new LocalRepository <Contact>(); var client = ModelHelper.TestClient1AllDataNoReferences; client.IsActive = false; var generationDate = new DateTime(2013, 1, 17); var contactForUser = new Contact() { Id = 1, Client = client }; contactRepository.Add(contactForUser); var notificationTaskPerformer = new PhoneNotificationTaskPerformer(phoneNotificationSender.Object, notificationPhoneTextBuilder.Object, contactRepository); var taskMessage = "{\"ContactId\":1}"; notificationTaskPerformer.PerformTask(new InsideModel.Models.Task() { Message = taskMessage, EarliestExecution = generationDate }); }
public void CanCheckIfTaskInRepository() { var taskRepository = new LocalRepository <InsideModel.Models.Task>(); var taskManager = new Task.TaskCreator.TaskManager(taskRepository); var now = new DateTime(2013, 01, 01, 08, 0, 0); var lowerBoundDate = now.Date; var upperBoundDate = lowerBoundDate.AddDays(1); var taskMessage = "{\"ClientId\":1,\"StartDate\":\"2013-12-30T00:00:00\",\"EndDate\":\"2014-01-02T00:00:00\"}"; var result = taskManager.HasTaskInRepository(taskMessage, TaskType.AddProductAnalyticData, lowerBoundDate, upperBoundDate); Assert.IsFalse(result); taskRepository.Add(new InsideModel.Models.Task() { EarliestExecution = now.AddHours(2), Message = taskMessage, Type = TaskType.AddProductAnalyticData }); Assert.AreEqual(1, taskRepository.All().Count()); var result2 = taskManager.HasTaskInRepository(taskMessage, TaskType.AddProductAnalyticData, lowerBoundDate, upperBoundDate); Assert.IsTrue(result2); }
public void EditPostSavesData() { var clientRepository = RepositoryHelper.RepositoryLocalWithOneClient; var client = clientRepository.All().First(); var userRepository = new LocalRepository <InsideUser>(); userRepository.Add(ModelHelper.TestUser1AllDataNoReferences); var user = userRepository.All().First(); user.PasswordHash = "HashedOldPassword"; var userManager = new Mock <IIdentityMembershipProvider>(); userManager.Setup(u => u.FindById(user.Id)).Returns(user); userManager.Setup(u => u.UpdatePassword(user.Id, "Password1!")).Returns(true).Verifiable(); var controller = new UserController(clientRepository, userRepository, userManager.Object); ModelHelper.SetCurrentUserToRole("consultant", controller); var userPostData = new UserViewModel(); userPostData.Name = "new"; userPostData.Password = "******"; userPostData.ClientId = client.Id; userPostData.Id = user.Id; userPostData.ClientName = client.Name; var result = controller.Edit(userPostData) as ViewResult; /*userManager.Verify(u => u.RemovePassword(user.Id), Times.Once);*/ userManager.Verify(u => u.UpdatePassword(user.Id, "Password1!"), Times.Once); }
public void EditForIdReturnViewWithModel() { var clientRepository = RepositoryHelper.RepositoryLocalWithOneClient; var client = clientRepository.All().First(); var userRepository = new LocalRepository <InsideUser>(); userRepository.Add(ModelHelper.TestUser1AllDataNoReferences); var user = userRepository.All().First(); user.UserName = "******"; user.Client = client; var userManager = new Mock <IIdentityMembershipProvider>(); userManager.Setup(u => u.FindById(user.Id)).Returns(user); var claim = new Claim("test", "AnyId"); userManager.Setup(um => um.GetRoles(It.IsAny <string>())).Returns(new List <string> { "mockRole" }); var controller = new UserController(clientRepository, userRepository, userManager.Object); ModelHelper.SetCurrentUserToRole("consultant", controller); ModelHelper.SetClaimAsCurrentUserForController(claim, controller); var result = controller.Edit(user.Id) as ViewResult; var resultmodel = result.Model as UserEditViewModel; Assert.AreEqual(user.ClientId, resultmodel.User.ClientId); }
public void EditPostSavesDataForOkDataWithEmptyMembershipProviderId() { var adminRepository = new LocalRepository <InsideUser>(); var userManager = new Mock <IIdentityMembershipProvider>(); var accountManagerInRepository = ModelHelper.TestAccountManager; accountManagerInRepository.Id = null; accountManagerInRepository.PasswordHash = "HashedOldPassword"; adminRepository.Add(accountManagerInRepository); var controller = new AccountManagerController(adminRepository, userManager.Object); var accountManager1 = new AccountManagerViewModel() { Name = accountManagerInRepository.Name, Id = accountManagerInRepository.Id, Password = "******", Email = "*****@*****.**" }; userManager.Setup(u => u.GetUsers()).Returns(adminRepository.All); userManager.Setup(u => u.FindById(accountManagerInRepository.Id)).Returns(accountManagerInRepository); userManager.Setup(u => u.UpdatePassword(accountManagerInRepository.Id, "Test Edited")).Returns(true).Verifiable(); userManager.Setup(u => u.Create(accountManagerInRepository, "Test Edited")).Returns(true).Verifiable(); var result = controller.Edit(accountManager1) as ViewResult; /* userManager.Verify(u => u.RemovePassword(accountManagerInRepository.Id), Times.Once);*/ userManager.Verify(u => u.UpdatePassword(accountManagerInRepository.Id, "Test Edited"), Times.Never); userManager.Verify(u => u.Create(It.IsAny <InsideUser>(), "Test Edited"), Times.Once); Assert.AreEqual("*****@*****.**", adminRepository.All().First().Email); }
public void CreateDifferentTokenEachTime() { var tokenRepository = new Mock <IRepository <Token> >(); var userRepository = new LocalRepository <InsideUser>(); var provider = new AccessTokenProvider(tokenRepository.Object, userRepository); var userId = "NewGuidString"; userRepository.Add(new InsideUser() { Id = userId }); var result = provider.GetToken(userId); tokenRepository.Verify(tr => tr.Add(It.IsAny <Token>()), Times.Once); Assert.AreEqual(DateTime.Today.AddDays(30).Date, result.ExpirationDate.Date); Assert.AreEqual("NewGuidString", result.UserId); var result2 = provider.GetToken(userId); tokenRepository.Verify(tr => tr.Add(It.IsAny <Token>()), Times.Exactly(2)); Assert.AreEqual(DateTime.Today.AddDays(30).Date, result2.ExpirationDate.Date); Assert.AreEqual("NewGuidString", result2.UserId); Assert.AreNotEqual(result.AccessToken, result2.AccessToken); }
public void MandrillContentWebhookDoesntHaveEmailInRepository() { var leadRepository = new LocalRepository <Contact>(); var emailLead = ModelHelper.EmailLead; leadRepository.Add(emailLead); var serverTime = new Mock <IServerTime>(); var clientRepository = new LocalRepository <Client>(); clientRepository.Add(ModelHelper.TestClient1AllDataNoReferences); var xDataProvider = new Mock <IExternalDataProvider>(); var contactAutoRating = new Mock <IContactAutoRating>(); var contactService = new Mock <IContactService>(); serverTime.Setup(st => st.RequestStarted).Returns(new DateTime(2013, 01, 01, 9, 0, 0)); var emailController = new WebhookController(leadRepository, clientRepository, contactService.Object, serverTime.Object, xDataProvider.Object, contactAutoRating.Object); emailController.MandrillContentWebhook(new MadrillContentPost { id = "2", html = "<p>New Sample Text</p>", text = "New Sample Text", to = "*****@*****.**" }); Assert.AreEqual(2, leadRepository.All().Count()); Assert.AreEqual("New Sample Text", leadRepository.Where(e => e.Property.Any(lp => lp.Type == "MandrillId" && lp.Value == "2")).First().Property.First(lp => lp.Type == "Text").Value); Assert.AreEqual("<p>New Sample Text</p>", leadRepository.Where(e => e.Property.Any(lp => lp.Type == "MandrillId" && lp.Value == "2")).First().Property.First(lp => lp.Type == "Html").Value); contactAutoRating.Verify(ar => ar.SetAutoRating(It.IsAny <Contact>()), Times.Once()); contactService.Verify(cs => cs.NotifyClientsForNewContactWithEmail(It.IsAny <int>()), Times.Once()); contactService.Verify(cs => cs.NotifyClientsForNewContactWithPhoneNotification(It.IsAny <int>()), Times.Once()); contactService.Verify(cs => cs.NotifyClientsForNewContactWithSmsNotification(It.IsAny <int>()), Times.Once()); }
public void ThrowsExceptionWhenAddingTheSameEmailUpdatesExistingDataWithNewDataAndOnRetryFails() { var leadRepository = new Mock <LocalRepository <Contact> > { CallBase = true }; var serverTime = new Mock <IServerTime>(); var emailLead = ModelHelper.EmailLead; var xDataProvider = new Mock <IExternalDataProvider>(); var contactAutoRating = new Mock <IContactAutoRating>(); leadRepository.Setup(er => er.SaveChanges()).Throws(new Exception()); leadRepository.Object.Add(emailLead); var clientRepository = new LocalRepository <Client>(); var client = ModelHelper.TestClient1AllDataNoReferences; clientRepository.Add(client); var contactService = new Mock <IContactService>(); var emailController = new WebhookController(leadRepository.Object, clientRepository, contactService.Object, serverTime.Object, xDataProvider.Object, contactAutoRating.Object); emailController.MandrillContentWebhook(new MadrillContentPost { id = "1", html = "<p>Very New Sample Text</p>", text = "Very New Sample Text", to = "*****@*****.**" }); Assert.AreEqual(0, leadRepository.Object.Where(er => er.Property.Any(lp => lp.Type == "Html" && lp.Value == "<p>Very New Sample Text</p>")).Count()); Assert.AreEqual(0, leadRepository.Object.Where(er => er.Property.Any(lp => lp.Type == "Text" && lp.Value == "Very New Sample Text")).Count()); Assert.AreEqual(1, leadRepository.Object.Where(er => er.Property.Any(lp => lp.Type == "Text" && lp.Value == "New Sample Text")).Count()); contactAutoRating.Verify(ar => ar.SetAutoRating(It.IsAny <Contact>()), Times.Exactly(2)); contactService.Verify(cs => cs.NotifyClientsForNewContactWithEmail(It.IsAny <int>()), Times.Never); contactService.Verify(cs => cs.NotifyClientsForNewContactWithPhoneNotification(It.IsAny <int>()), Times.Never); contactService.Verify(cs => cs.NotifyClientsForNewContactWithSmsNotification(It.IsAny <int>()), Times.Never); }
public void DeleteForValidIdReturnsViewWithModel() { var adminRepository = new LocalRepository <InsideUser>(); var userManager = new Mock <IIdentityMembershipProvider>(); var accountManagerInRepository = ModelHelper.TestAccountManager; adminRepository.Add(accountManagerInRepository); userManager.Setup(u => u.FindById(accountManagerInRepository.Id)).Returns(accountManagerInRepository); var claim = new Claim("test", "AnyId"); userManager.Setup(um => um.GetRoles(It.IsAny <string>())).Returns(new List <string> { "mockRole" }); var controller = new AccountManagerController(adminRepository, userManager.Object); ModelHelper.SetClaimAsCurrentUserForController(claim, controller); var result = controller.Delete(accountManagerInRepository.Id) as ViewResult; var resultModel = result.Model as AccountManagerViewModel; Assert.AreEqual("Test AM", resultModel.Name); }
public void GetOneMandrillEventsAndThrowsExceptionFailsOnBothTries() { var leadRepository = new Mock <LocalRepository <Contact> >() { CallBase = true }; var xDataProvider = new Mock <IExternalDataProvider>(); var contactAutoRating = new Mock <IContactAutoRating>(); var mandrill_event = "[{\"event\":\"send\",\"msg\":{\"ts\":1365109999,\"subject\":\"This an example webhook message\",\"email\":\"[email protected]\"," + "\"sender\":\"[email protected]\",\"tags\":[\"webhook-example\"],\"opens\":[],\"clicks\":[],\"state\":\"sent\",\"metadata\":{\"user_id\":111}," + "\"_id\":\"1\",\"_version\":\"exampleaaaaaaaaaaaaaaa1\"},\"_id\":\"1\",\"ts\":1385020180}]"; leadRepository.Setup(er => er.SaveChanges()).Throws(new Exception()); var clientRepository = new LocalRepository <Client>(); var client = ModelHelper.TestClient1AllDataNoReferences; client.EmailAddress = "*****@*****.**"; clientRepository.Add(client); var serverTime = new Mock <IServerTime>(); var contactService = new Mock <IContactService>(); var emailController = new WebhookController(leadRepository.Object, clientRepository, contactService.Object, serverTime.Object, xDataProvider.Object, contactAutoRating.Object); var result = emailController.ManrillWebhook(mandrill_event); Assert.AreEqual(0, leadRepository.Object.All().Count()); contactAutoRating.Verify(ar => ar.SetAutoRating(It.IsAny <Contact>()), Times.Exactly(2)); contactService.Verify(cs => cs.NotifyClientsForNewContactWithEmail(It.IsAny <int>()), Times.Never); contactService.Verify(cs => cs.NotifyClientsForNewContactWithPhoneNotification(It.IsAny <int>()), Times.Never); contactService.Verify(cs => cs.NotifyClientsForNewContactWithSmsNotification(It.IsAny <int>()), Times.Never); }
public void ValidateExistingAndNotExistingToken() { var tokenRepository = new LocalRepository <Token>(); var userRepository = new Mock <IRepository <InsideUser> >(); var provider = new AccessTokenProvider(tokenRepository, userRepository.Object); var client = new Client() { Id = 1 }; var user = new InsideUser() { Id = "Id2", ClientId = client.Id, Client = client }; var validToken = new Token() { Id = 2, UserId = user.Id, AccessToken = "Some Random Generated String 2", ExpirationDate = DateTime.Today.AddDays(1), InsideUser = user }; tokenRepository.Add(validToken); var validResult = provider.Validate((int)validToken.InsideUser.ClientId, validToken.AccessToken); var inValidResult = provider.Validate((int)validToken.InsideUser.ClientId, "Some Invalid Random String"); Assert.IsTrue(validResult); Assert.IsFalse(inValidResult); }