public ActionResult Create(CoordinatedSharedMessageModel coordinatedMessages) { var isValid = TryValidateModel(coordinatedMessages); SecondaryValidation(coordinatedMessages); if (isValid && ModelState.IsValid) { CountryCodeReplacement countryCodeReplacement; using (var session = RavenDocStore.GetStore().OpenSession("Configuration")) { countryCodeReplacement = session.Load<CountryCodeReplacement>("CountryCodeConfig"); } var coordinatorId = Guid.NewGuid(); if (coordinatedMessages.Message.Length > 160) coordinatedMessages.Message = coordinatedMessages.Message.Substring(0, 160); if (coordinatedMessages.TimeSeparatorSeconds.HasValue && !coordinatedMessages.SendAllBy.HasValue) { var trickleSmsSpacedByTimePeriod = Mapper.MapToTrickleSpacedByPeriod(coordinatedMessages, countryCodeReplacement); trickleSmsSpacedByTimePeriod.CoordinatorId = coordinatorId; Bus.Send(trickleSmsSpacedByTimePeriod); } if (!coordinatedMessages.TimeSeparatorSeconds.HasValue && coordinatedMessages.SendAllBy.HasValue) { var trickleSmsOverTimePeriod = Mapper.MapToTrickleOverPeriod(coordinatedMessages, countryCodeReplacement); trickleSmsOverTimePeriod.CoordinatorId = coordinatorId; Bus.Send(trickleSmsOverTimePeriod); } return RedirectToAction("Details", "Coordinator", new {coordinatorId = coordinatorId.ToString()}); } return View("Create", coordinatedMessages); }
public void CoordinatorOverTimespanLongMessageIsShortenedReturnsDetails() { var model = new CoordinatedSharedMessageModel { Numbers = "04040404040", Message = "asfdkjadfskl asflkj;faskjf;aslkjf;lasdkjfaslkfjas;lkfjslkfjas;lkfjsalkfjas;fklasj;flksdjf;lkasjflskdjflkasjflksjlk lskaf jlsk fdaskl dflksjfalk sflkj sfkl jlkjs flkj skjkj sadflkjsaflj", StartTime = DateTime.Now.AddHours(2), SendAllBy = DateTime.Now.AddHours(3) }; var bus = MockRepository.GenerateMock<IBus>(); var mapper = MockRepository.GenerateMock<ICoordinatorModelToMessageMapping>(); var coordinatorMessage = new CoordinatedSharedMessageModel(); mapper.Expect(m => m.MapToTrickleOverPeriod(Arg<CoordinatedSharedMessageModel>.Is.Anything)) .Return(new TrickleSmsOverCalculatedIntervalsBetweenSetDates()) .WhenCalled(t => coordinatorMessage = (CoordinatedSharedMessageModel)(t.Arguments[0])); var trickleMessage = new TrickleSmsOverCalculatedIntervalsBetweenSetDates(); bus.Expect(b => b.Send(Arg<TrickleSmsOverCalculatedIntervalsBetweenSetDates>.Is.NotNull)) .WhenCalled(i => trickleMessage = (TrickleSmsOverCalculatedIntervalsBetweenSetDates)((object[])(i.Arguments[0]))[0]); var controller = new CoordinatorController { ControllerContext = new ControllerContext(), Bus = bus, Mapper = mapper }; var actionResult = (RedirectToRouteResult)controller.Create(model); Assert.That(actionResult.RouteValues["action"], Is.EqualTo("Details")); Assert.That(coordinatorMessage.Message, Is.EqualTo(model.Message.Substring(0, 160))); bus.VerifyAllExpectations(); mapper.VerifyAllExpectations(); }
public void MapToTrickleOverTimePeriodWithCountryCodeReplacement() { var model = new CoordinatedSharedMessageModel { Numbers = "04040404040, 11111111111", Message = "Message", StartTime = DateTime.Now.AddHours(2), SendAllBy = DateTime.Now.AddHours(3), Tags = "tag1, tag2", Topic = "Dance Dance Revolution!", ConfirmationEmail = "*****@*****.**" }; var mapper = new CoordinatorModelToMessageMapping(); var message = mapper.MapToTrickleOverPeriod(model, new CountryCodeReplacement { CountryCode = "+61", LeadingNumberToReplace = "0"}); var coordinationDuration = model.SendAllBy.Value.Subtract(model.StartTime); Assert.That(coordinationDuration, Is.GreaterThan(new TimeSpan(0))); Assert.That(message.Messages.Count, Is.EqualTo(2)); Assert.That(message.Messages[0].Mobile, Is.EqualTo("+614040404040")); Assert.That(message.Messages[0].Message, Is.EqualTo(model.Message)); Assert.That(message.Messages[1].Mobile, Is.EqualTo(model.Numbers.Split(',')[1].Trim())); Assert.That(message.Messages[1].Message, Is.EqualTo(model.Message)); Assert.That(message.MetaData.Tags, Is.EqualTo(model.Tags.Split(',').ToList().Select(t => t.Trim().ToList()))); Assert.That(message.MetaData.Topic, Is.EqualTo(model.Topic)); Assert.That(message.StartTimeUtc, Is.EqualTo(model.StartTime.ToUniversalTime())); Assert.That(message.Duration, Is.EqualTo(coordinationDuration)); Assert.That(message.ConfirmationEmail, Is.EqualTo(model.ConfirmationEmail)); }
public ActionResult Create(CoordinatedSharedMessageModel coordinatedMessages) { var isValid = TryValidateModel(coordinatedMessages); SecondaryValidation(coordinatedMessages); if (isValid && ModelState.IsValid) { var coordinatorId = Guid.NewGuid(); if (coordinatedMessages.Message.Length > 160) coordinatedMessages.Message = coordinatedMessages.Message.Substring(0, 160); if (coordinatedMessages.TimeSeparatorSeconds.HasValue && !coordinatedMessages.SendAllBy.HasValue) { var trickleSmsSpacedByTimePeriod = Mapper.MapToTrickleSpacedByPeriod(coordinatedMessages); trickleSmsSpacedByTimePeriod.CoordinatorId = coordinatorId; Bus.Send(trickleSmsSpacedByTimePeriod); } if (!coordinatedMessages.TimeSeparatorSeconds.HasValue && coordinatedMessages.SendAllBy.HasValue) { var trickleSmsOverTimePeriod = Mapper.MapToTrickleOverPeriod(coordinatedMessages); trickleSmsOverTimePeriod.CoordinatorId = coordinatorId; Bus.Send(trickleSmsOverTimePeriod); } return RedirectToAction("Details", "Coordinator", new {coordinatorId = coordinatorId.ToString()}); } return View("Create", coordinatedMessages); }
public void MapToSendAllAtOnce() { var model = new CoordinatedSharedMessageModel { Numbers = "04040404040, 11111111111", Message = "Message", StartTime = DateTime.Now.AddHours(2), SendAllAtOnce = true, Tags = "tag1, tag2", Topic = "Dance Dance Revolution!", ConfirmationEmail = "confirmation, two", UserTimeZone = "Australia/Sydney" }; var mappedDateTime = DateTime.Now; var olsenMapping = MockRepository.GenerateMock<IDateTimeUtcFromOlsenMapping>(); olsenMapping.Expect(o => o.DateTimeWithOlsenZoneToUtc(model.StartTime, model.UserTimeZone)).Return(mappedDateTime); var mapper = new CoordinatorModelToMessageMapping(olsenMapping); var message = mapper.MapToSendAllAtOnce(model, new CountryCodeReplacement(), new List<string>()); Assert.That(message.Messages.Count, Is.EqualTo(2)); Assert.That(message.Messages[0].Mobile, Is.EqualTo(model.Numbers.Split(',')[0].Trim())); Assert.That(message.Messages[0].Message, Is.EqualTo(model.Message)); Assert.That(message.Messages[1].Mobile, Is.EqualTo(model.Numbers.Split(',')[1].Trim())); Assert.That(message.Messages[1].Message, Is.EqualTo(model.Message)); Assert.That(message.MetaData.Tags, Is.EqualTo(model.Tags.Split(',').ToList().Select(t => t.Trim()).ToList())); Assert.That(message.MetaData.Topic, Is.EqualTo(model.Topic)); Assert.That(message.SendTimeUtc, Is.EqualTo(mappedDateTime)); Assert.That(message.ConfirmationEmail, Is.EqualTo(model.ConfirmationEmail)); Assert.That(message.ConfirmationEmails.Count, Is.EqualTo(2)); Assert.That(message.ConfirmationEmails[0], Is.EqualTo("confirmation")); Assert.That(message.ConfirmationEmails[1], Is.EqualTo("two")); Assert.That(message.UserOlsenTimeZone, Is.EqualTo(model.UserTimeZone)); }
public void CreaetExcludeMultiplePreviousCoordinatorMessagesRemovesMatchingNumbers_TrickleBetweenDates() { var CoordinatorToExclude1 = Guid.NewGuid(); var CoordinatorToExclude2 = Guid.NewGuid(); var model = new CoordinatedSharedMessageModel { Numbers = "04040404040, 1, 2, 3, 7, 12", Message = "asfdkjadfskl asflkj;faskjf;aslkjf;lasdkjfaslkfjas;lkfjslkfjas;lkfjsalkfjas;fklasj;flksdjf;lkasjflskdjflkasjflksjlk lskaf jlsk fdaskl dflksjfalk sflkj sfkl jlkjs flkj skjkj sadflkjsaflj", StartTime = DateTime.Now.AddHours(2), SendAllBy = DateTime.Now.AddHours(3), CoordinatorsToExclude = new List<Guid> { CoordinatorToExclude1, CoordinatorToExclude2 }, Topic = "frank", UserTimeZone = "Australia/Sydney" }; var bus = MockRepository.GenerateMock<IBus>(); var mapper = MockRepository.GenerateMock<ICoordinatorModelToMessageMapping>(); var ravenDocStore = MockRepository.GenerateMock<IRavenDocStore>(); var docStore = MockRepository.GenerateMock<IDocumentStore>(); var configSession = MockRepository.GenerateMock<IDocumentSession>(); var trackingSession = MockRepository.GenerateMock<IDocumentSession>(); var currentUser = MockRepository.GenerateStub<ICurrentUser>(); ravenDocStore.Expect(r => r.GetStore()).Return(docStore); docStore.Expect(d => d.OpenSession("Configuration")).Return(configSession); docStore.Expect(d => d.OpenSession("SmsTracking")).Return(trackingSession); configSession.Expect(d => d.Load<CountryCodeReplacement>("CountryCodeConfig")).Return(new CountryCodeReplacement()); var previousCoordinatorToExclude1 = new CoordinatorTrackingData(new List<MessageSendingStatus> { new MessageSendingStatus { Number = "04040404040" }, new MessageSendingStatus { Number = "1" } }); trackingSession.Expect(d => d.Load<CoordinatorTrackingData>(CoordinatorToExclude1.ToString())).Return( previousCoordinatorToExclude1); var previousCoordinatorToExclude2 = new CoordinatorTrackingData(new List<MessageSendingStatus> { new MessageSendingStatus { Number = "7" } }); trackingSession.Expect(d => d.Load<CoordinatorTrackingData>(CoordinatorToExclude2.ToString())).Return( previousCoordinatorToExclude2); var coordinatorMessage = new CoordinatedSharedMessageModel(); var excludeList1 = previousCoordinatorToExclude1.GetListOfCoordinatedSchedules(ravenDocStore.GetStore()).Select(s => s.Number).ToList(); var excludeList2 = previousCoordinatorToExclude2.GetListOfCoordinatedSchedules(ravenDocStore.GetStore()).Select(s => s.Number).ToList(); List<string> excludeList = null; mapper .Expect(m => m.MapToTrickleOverPeriod(Arg<CoordinatedSharedMessageModel>.Is.Anything, Arg<CountryCodeReplacement>.Is.Anything, Arg<List<string>>.Is.Anything, Arg<string>.Is.Anything)) .Return(new TrickleSmsOverCalculatedIntervalsBetweenSetDates()) .WhenCalled(t => coordinatorMessage = (CoordinatedSharedMessageModel)(t.Arguments[0])) .WhenCalled(t => excludeList = (List<string>)(t.Arguments[2])); bus.Expect(b => b.Send(Arg<TrickleSmsOverCalculatedIntervalsBetweenSetDates>.Is.NotNull)); var controller = new CoordinatorController { ControllerContext = new ControllerContext(), Bus = bus, Mapper = mapper, RavenDocStore = ravenDocStore, CurrentUser = currentUser }; var actionResult = (RedirectToRouteResult)controller.Create(model); Assert.That(actionResult.RouteValues["action"], Is.EqualTo("Details")); Assert.That(coordinatorMessage.Message, Is.EqualTo(model.Message.Substring(0, 160))); Assert.That(excludeList.ToList(), Is.EqualTo(excludeList1.Union(excludeList2).Distinct().ToList())); bus.VerifyAllExpectations(); mapper.VerifyAllExpectations(); configSession.VerifyAllExpectations(); trackingSession.VerifyAllExpectations(); }
public void CoordinatorContainsNoNumbersError() { var bus = MockRepository.GenerateMock<IBus>(); var controller = new CoordinatorController { ControllerContext = new ControllerContext(), Bus = bus }; var model = new CoordinatedSharedMessageModel { Numbers = "", Message = "message", StartTime = DateTime.Now.AddHours(2), SendAllBy = DateTime.Now.AddHours(3) }; var actionResult = (ViewResult)controller.Create(model); Assert.That(actionResult.ViewName, Is.EqualTo("Create")); }
public SendAllMessagesAtOnce MapToSendAllAtOnce(CoordinatedSharedMessageModel model, CountryCodeReplacement countryCodeReplacement, List<string> excludedNumbers) { return new SendAllMessagesAtOnce { Messages = model .GetCleanInternationalisedNumbers(countryCodeReplacement) .Where(n => !excludedNumbers.Contains(n)) .Select(n => new SmsData(n, model.Message)) .ToList(), SendTimeUtc = DateTimeOlsenMapping.DateTimeWithOlsenZoneToUtc(model.StartTime, model.UserTimeZone), MetaData = new SmsMetaData { Tags = model.GetTagList(), Topic = model.Topic }, ConfirmationEmail = model.ConfirmationEmail, ConfirmationEmails = model.GetEmailList(), UserOlsenTimeZone = model.UserTimeZone }; }
public TrickleSmsOverCalculatedIntervalsBetweenSetDates MapToTrickleOverPeriod(CoordinatedSharedMessageModel model, CountryCodeReplacement countryCodeReplacement, List<string> excludedNumbers) { return new TrickleSmsOverCalculatedIntervalsBetweenSetDates { Duration = model.SendAllBy.Value.Subtract(model.StartTime), Messages = model .GetCleanInternationalisedNumbers(countryCodeReplacement) .Where(n => !excludedNumbers.Contains(n)) .Select(n => new SmsData(n, model.Message)) .ToList(), StartTimeUtc = DateTimeOlsenMapping.DateTimeWithOlsenZoneToUtc(model.StartTime, model.UserTimeZone), // startTimeUtc,// model.StartTime.ToUniversalTime(), MetaData = new SmsMetaData { Tags = model.GetTagList(), Topic = model.Topic }, ConfirmationEmail = model.ConfirmationEmail, ConfirmationEmails = model.GetEmailList(), UserOlsenTimeZone = model.UserTimeZone }; }
public TrickleSmsOverCalculatedIntervalsBetweenSetDates MapToTrickleOverPeriod(CoordinatedSharedMessageModel model) { return new TrickleSmsOverCalculatedIntervalsBetweenSetDates { Duration = model.SendAllBy.Value.Subtract(model.StartTime), Messages = model.Numbers.Split(',').ToList().Select(n => new SmsData(n.Trim(), model.Message)). ToList(), StartTimeUtc = model.StartTime.ToUniversalTime(), MetaData = new SmsMetaData { Tags = string.IsNullOrWhiteSpace(model.Tags) ? null : model.Tags.Split(',').ToList().Select(t => t.Trim()).ToList(), Topic = model.Topic }, ConfirmationEmail = model.ConfirmationEmail }; }
private void SecondaryValidation(CoordinatedSharedMessageModel coordinatedMessages) { if (coordinatedMessages.Numbers == null || coordinatedMessages.Numbers.Split(',').Length == 0) ModelState.AddModelError("numberList", "Please include the numbers you want to send to."); if (coordinatedMessages.StartTime < DateTime.Now) ModelState.AddModelError("StartTime", "Start Time must be in the future"); if (coordinatedMessages.SendAllBy.HasValue && coordinatedMessages.SendAllBy.Value <= coordinatedMessages.StartTime) ModelState.AddModelError("SendAllBy", "SendAllBy time must be after StartTime"); if (coordinatedMessages.SendAllBy.HasValue && coordinatedMessages.TimeSeparatorSeconds.HasValue) ModelState.AddModelError("SendAllBy", "You must select either SendAllBy OR TimeSeparated - cannot pick both"); if (!coordinatedMessages.SendAllBy.HasValue && !coordinatedMessages.TimeSeparatorSeconds.HasValue) ModelState.AddModelError("SendAllBy", "You must select either SendAllBy OR TimeSeparated - cannot have none"); }
public ActionResult Create(CoordinatedSharedMessageModel coordinatedMessages) { var isValid = TryValidateModel(coordinatedMessages); SecondaryValidation(coordinatedMessages); if (isValid && ModelState.IsValid) { CountryCodeReplacement countryCodeReplacement; using (var session = RavenDocStore.GetStore().OpenSession("Configuration")) { countryCodeReplacement = session.Load<CountryCodeReplacement>("CountryCodeConfig"); } var excludeList = new List<string>(); using (var session = RavenDocStore.GetStore().OpenSession("SmsTracking")) { foreach (var previousCoordinatorId in coordinatedMessages.CoordinatorsToExclude) { var previousCoordinator = session.Load<CoordinatorTrackingData>(previousCoordinatorId.ToString()); excludeList.AddRange(previousCoordinator.GetListOfCoordinatedSchedules(RavenDocStore.GetStore()).Select(p => p.Number).ToList()); } } var cleanExcludeList = excludeList.Distinct().ToList(); var coordinatorId = Guid.NewGuid(); if (coordinatedMessages.Message.Length > 160) coordinatedMessages.Message = coordinatedMessages.Message.Substring(0, 160); var messageTypeRequired = coordinatedMessages.GetMessageTypeFromModel(); if (messageTypeRequired == typeof(TrickleSmsOverCalculatedIntervalsBetweenSetDates)) { var trickleSmsOverTimePeriod = Mapper.MapToTrickleOverPeriod (coordinatedMessages, countryCodeReplacement, cleanExcludeList, CurrentUser.Name ()); trickleSmsOverTimePeriod.CoordinatorId = coordinatorId; Bus.Send (trickleSmsOverTimePeriod); } else if (messageTypeRequired == typeof(SendAllMessagesAtOnce)) { var sendAllAtOnce = Mapper.MapToSendAllAtOnce (coordinatedMessages, countryCodeReplacement, cleanExcludeList, CurrentUser.Name ()); sendAllAtOnce.CoordinatorId = coordinatorId; Bus.Send (sendAllAtOnce); } else { throw new NotImplementedException ("This option has been removed"); } return RedirectToAction("Details", "Coordinator", new {coordinatorId = coordinatorId.ToString()}); } var selectListItems = new List<SelectListItem>(); using (var session = RavenDocStore.GetStore().OpenSession("SmsTracking")) { var last10Coordinators = session.Query<CoordinatorTrackingData>().OrderByDescending(c => c.CreationDateUtc).Take(10).ToList(); selectListItems = last10Coordinators.Select(c => new SelectListItem { Selected = false, Text = CoordinatorToExcludeText(c), Value = c.CoordinatorId.ToString() }).ToList(); foreach (var previousCoordinatorId in coordinatedMessages.CoordinatorsToExclude) { if (last10Coordinators.Any(c => c.CoordinatorId == previousCoordinatorId)) { selectListItems.First(s => Guid.Parse(s.Value) == previousCoordinatorId).Selected = true; } else { var coordinatorTrackingData = session.Load<CoordinatorTrackingData>(previousCoordinatorId.ToString()); selectListItems.Add(new SelectListItem { Selected = true, Text = coordinatorTrackingData.MetaData.Topic, Value = coordinatorTrackingData.CoordinatorId.ToString() }); } } } ViewData.Add("CoordinatorExcludeList", selectListItems); return View("Create", coordinatedMessages); }
private void SecondaryValidation(CoordinatedSharedMessageModel coordinatedMessages) { if (string.IsNullOrWhiteSpace(coordinatedMessages.Topic)) ModelState.AddModelError("Topic", "Topic must be set"); if (coordinatedMessages.Numbers == null || coordinatedMessages.Numbers.Split(',').Length == 0) ModelState.AddModelError("numberList", "Please include the numbers you want to send to."); if (coordinatedMessages.StartTime < DateTime.Now.AddMinutes(-5)) ModelState.AddModelError("StartTime", "Start Time must be in the future"); if (coordinatedMessages.SendAllBy.HasValue && coordinatedMessages.SendAllBy.Value <= coordinatedMessages.StartTime) ModelState.AddModelError("SendAllBy", "SendAllBy time must be after StartTime"); if (!coordinatedMessages.IsMessageTypeValid()) ModelState.AddModelError("SendAllBy","Message must contain either Time Separator OR DateTime to send all messages by."); }
public TrickleSmsOverCalculatedIntervalsBetweenSetDates MapToTrickleOverPeriod(CoordinatedSharedMessageModel model, CountryCodeReplacement countryCodeReplacement) { var rawNumberList = model.Numbers.Split(','); var cleanedInternationalisedNumbers = rawNumberList.Select(number => countryCodeReplacement != null ? countryCodeReplacement.CleanAndInternationaliseNumber(number) : number.Trim()).ToList(); var tags = string.IsNullOrWhiteSpace(model.Tags) ? null : model.Tags.Split(',').ToList().Select(t => t.Trim()).ToList(); return new TrickleSmsOverCalculatedIntervalsBetweenSetDates { Duration = model.SendAllBy.Value.Subtract(model.StartTime), Messages = cleanedInternationalisedNumbers .Select(n => new SmsData(n, model.Message)). ToList(), StartTimeUtc = model.StartTime.ToUniversalTime(), MetaData = new SmsMetaData { Tags = tags, Topic = model.Topic }, ConfirmationEmail = model.ConfirmationEmail }; }
public void CoordinatorSeparatedByTimeSpanReturnsDetails() { var model = new CoordinatedSharedMessageModel { Numbers= "04040404040", Message = "Message", StartTime = DateTime.Now.AddHours(2), TimeSeparatorSeconds = 5000, Tags = "tag1, tag2", Topic = "New Feature!" }; var bus = MockRepository.GenerateMock<IBus>(); var mapper = MockRepository.GenerateMock<ICoordinatorModelToMessageMapping>(); mapper.Expect(m => m.MapToTrickleSpacedByPeriod(Arg<CoordinatedSharedMessageModel>.Is.Anything)).Return(new TrickleSmsWithDefinedTimeBetweenEachMessage()); var trickleMessage = new TrickleSmsWithDefinedTimeBetweenEachMessage(); bus.Expect(b => b.Send(Arg<TrickleSmsWithDefinedTimeBetweenEachMessage>.Is.NotNull)) .WhenCalled(i => trickleMessage = (TrickleSmsWithDefinedTimeBetweenEachMessage) ((object[]) (i.Arguments[0]))[0]); var controller = new CoordinatorController { ControllerContext = new ControllerContext(), Bus = bus, Mapper = mapper }; var actionResult = (RedirectToRouteResult)controller.Create(model); Assert.That(actionResult.RouteValues["action"], Is.EqualTo("Details")); Assert.That(trickleMessage.CoordinatorId, Is.Not.EqualTo(Guid.Empty)); bus.VerifyAllExpectations(); mapper.VerifyAllExpectations(); }
public void MapToTrickleSpacedByTimePeriodWithCountryCodeReplacement() { var model = new CoordinatedSharedMessageModel { Numbers = "04040404040, 11111111111", Message = "Message", StartTime = DateTime.Now.AddHours(2), TimeSeparatorSeconds = 90, Tags = "tag1, tag2", Topic = "Dance Dance Revolution!", ConfirmationEmail = "confirmation, anotherone; yetanother: more", UserTimeZone = "Australia/Sydney" }; var mappedDateTime = DateTime.Now; var olsenMapping = MockRepository.GenerateMock<IDateTimeUtcFromOlsenMapping>(); olsenMapping.Expect(o => o.DateTimeWithOlsenZoneToUtc(model.StartTime, model.UserTimeZone)).Return(mappedDateTime); var mapper = new CoordinatorModelToMessageMapping(olsenMapping); var message = mapper.MapToTrickleSpacedByPeriod(model, new CountryCodeReplacement { CountryCode = "+61", LeadingNumberToReplace = "0"}, new List<string>()); Assert.That(message.Messages.Count, Is.EqualTo(2)); Assert.That(message.Messages[0].Mobile, Is.EqualTo("+614040404040")); Assert.That(message.Messages[0].Message, Is.EqualTo(model.Message)); Assert.That(message.Messages[1].Mobile, Is.EqualTo(model.Numbers.Split(',')[1].Trim())); Assert.That(message.Messages[1].Message, Is.EqualTo(model.Message)); Assert.That(message.MetaData.Tags, Is.EqualTo(model.Tags.Split(',').ToList().Select(t => t.Trim()).ToList())); Assert.That(message.MetaData.Topic, Is.EqualTo(model.Topic)); Assert.That(message.StartTimeUtc, Is.EqualTo(mappedDateTime)); Assert.That(message.TimeSpacing, Is.EqualTo(TimeSpan.FromSeconds(model.TimeSeparatorSeconds.Value))); Assert.That(message.ConfirmationEmail, Is.EqualTo(model.ConfirmationEmail)); Assert.That(message.ConfirmationEmails.Count, Is.EqualTo(4)); Assert.That(message.ConfirmationEmails[0], Is.EqualTo("confirmation")); Assert.That(message.ConfirmationEmails[1], Is.EqualTo("anotherone")); Assert.That(message.ConfirmationEmails[2], Is.EqualTo("yetanother")); Assert.That(message.ConfirmationEmails[3], Is.EqualTo("more")); }
public TrickleSmsWithDefinedTimeBetweenEachMessage MapToTrickleSpacedByPeriod(CoordinatedSharedMessageModel model, CountryCodeReplacement countryCodeReplacement) { var tags = string.IsNullOrWhiteSpace(model.Tags) ? null : model.Tags.Split(',').ToList().Select(t => t.Trim()).ToList(); var rawNumberList = model.Numbers.Split(','); var cleanedInternationalisedNumbers = rawNumberList.Select(number => countryCodeReplacement != null ? countryCodeReplacement.CleanAndInternationaliseNumber(number) : number.Trim()).ToList(); return new TrickleSmsWithDefinedTimeBetweenEachMessage { Messages = cleanedInternationalisedNumbers.Select(n => new SmsData(n, model.Message)).ToList(), StartTimeUtc = model.StartTime.ToUniversalTime(), TimeSpacing = TimeSpan.FromSeconds(model.TimeSeparatorSeconds.Value), MetaData = new SmsMetaData { Tags = tags, Topic = model.Topic }, ConfirmationEmail = model.ConfirmationEmail }; }
public void CreateErrorWithSelectedCoordinatorsToExclude() { var bus = MockRepository.GenerateMock<IBus>(); var ravenDocStore = MockRepository.GenerateMock<IRavenDocStore>(); var docStore = MockRepository.GenerateMock<IDocumentStore>(); ravenDocStore.Expect(r => r.GetStore()).Return(docStore); docStore.Expect(d => d.OpenSession("SmsTracking")).Return(SmsTrackingSession); var controller = new CoordinatorController { ControllerContext = new ControllerContext(), Bus = bus, RavenDocStore = ravenDocStore }; var model = new CoordinatedSharedMessageModel { Numbers = "04040404040", Message = string.Empty, StartTime = DateTime.Now.AddHours(2), SendAllBy = DateTime.Now.AddHours(3), CoordinatorsToExclude = new List<Guid> { Top1CoordinatorId } }; var actionResult = (ViewResult)controller.Create(model); var selectListItems = actionResult.ViewData["CoordinatorExcludeList"] as List<SelectListItem>; Assert.That(actionResult.ViewName, Is.EqualTo("Create")); Assert.True(selectListItems.First(s => s.Value == Top1CoordinatorId.ToString()).Selected); }
public void CreateEditExcludeCoordinatorTopTenNoCoordinatorsSelected() { var ravenDocStore = MockRepository.GenerateMock<IRavenDocStore>(); var docSession = MockRepository.GenerateMock<IDocumentSession>(); var docStore = MockRepository.GenerateMock<IDocumentStore>(); var mapper = MockRepository.GenerateMock<ICoordinatorModelToMessageMapping>(); var bus = MockRepository.GenerateMock<IBus>(); ravenDocStore.Expect(d => d.GetStore()).Return(docStore); docStore.Expect(d => d.OpenSession("Configuration")).Return(docSession); docStore.Expect(d => d.OpenSession("SmsTracking")).Return(SmsTrackingSession); mapper .Expect(m => m.MapToTrickleSpacedByPeriod(Arg<CoordinatedSharedMessageModel>.Is.Anything, Arg<CountryCodeReplacement>.Is.Anything, Arg<List<string>>.Is.Anything)) .Return(new TrickleSmsWithDefinedTimeBetweenEachMessage()); bus.Expect(b => b.Send(Arg<TrickleSmsWithDefinedTimeBetweenEachMessage>.Is.Anything)); docSession.Expect(d => d.Load<CountryCodeReplacement>("CountryCodeConfig")).Return(new CountryCodeReplacement()); var model = new CoordinatedSharedMessageModel { Numbers = "04040404040, 3984938", Message = "Message", StartTime = DateTime.Now.AddHours(2), CoordinatorsToExclude = new List<Guid>(), TimeSeparatorSeconds = 4, Topic = "frank", UserTimeZone = "Australia/Sydney" }; var controller = new CoordinatorController { ControllerContext = new ControllerContext(), RavenDocStore = ravenDocStore, Mapper = mapper, Bus = bus }; var actionResult = (RedirectToRouteResult)controller.Create(model); Assert.That(actionResult.RouteValues["action"], Is.EqualTo("Details")); ravenDocStore.VerifyAllExpectations(); }
public TrickleSmsWithDefinedTimeBetweenEachMessage MapToTrickleSpacedByPeriod(CoordinatedSharedMessageModel model, CountryCodeReplacement countryCodeReplacement, List<string> excludedNumbers) { return new TrickleSmsWithDefinedTimeBetweenEachMessage { Messages = model .GetCleanInternationalisedNumbers(countryCodeReplacement) .Where(n => !excludedNumbers.Contains(n)) .Select(n => new SmsData(n, model.Message)) .ToList(), StartTimeUtc = DateTimeOlsenMapping.DateTimeWithOlsenZoneToUtc(model.StartTime, model.UserTimeZone), TimeSpacing = TimeSpan.FromSeconds(model.TimeSeparatorSeconds.Value), MetaData = new SmsMetaData { Tags = model.GetTagList(), Topic = model.Topic }, ConfirmationEmail = model.ConfirmationEmail, ConfirmationEmails = model.GetEmailList(), UserOlsenTimeZone = model.UserTimeZone }; }
public TrickleSmsWithDefinedTimeBetweenEachMessage MapToTrickleSpacedByPeriod(CoordinatedSharedMessageModel model) { var tags = string.IsNullOrWhiteSpace(model.Tags) ? null : model.Tags.Split(',').ToList().Select(t => t.Trim()).ToList(); return new TrickleSmsWithDefinedTimeBetweenEachMessage { Messages = model.Numbers.Split(',').ToList().Select(n => new SmsData(n.Trim(), model.Message)). ToList(), StartTimeUtc = model.StartTime.ToUniversalTime(), TimeSpacing = TimeSpan.FromSeconds(model.TimeSeparatorSeconds.Value), MetaData = new SmsMetaData { Tags = tags, Topic = model.Topic }, ConfirmationEmail = model.ConfirmationEmail }; }
public void CreateTimeSeparatorNotDefinedError() { var bus = MockRepository.GenerateMock<IBus>(); var ravenDocStore = MockRepository.GenerateMock<IRavenDocStore>(); var docStore = MockRepository.GenerateMock<IDocumentStore>(); ravenDocStore.Expect(r => r.GetStore()).Return(docStore); docStore.Expect(d => d.OpenSession("SmsTracking")).Return(SmsTrackingSession); var controller = new CoordinatorController { ControllerContext = new ControllerContext(), Bus = bus, RavenDocStore = ravenDocStore }; var model = new CoordinatedSharedMessageModel { Numbers = "04040404040", Message = "Message", StartTime = DateTime.Now.AddHours(2) }; var actionResult = (ViewResult)controller.Create(model); Assert.That(actionResult.ViewName, Is.EqualTo("Create")); }
public void MapToTrickleOverTimePeriodRemovingExcludedNumbers() { var model = new CoordinatedSharedMessageModel { Numbers = "04040404040, 11111111111", Message = "Message", StartTime = DateTime.Now.AddHours(2), SendAllBy = DateTime.Now.AddHours(3), Topic = "Dance Dance Revolution!", ConfirmationEmail = "*****@*****.**", UserTimeZone = "Australia/Sydney" }; var mappedDateTime = DateTime.Now; var olsenMapping = MockRepository.GenerateMock<IDateTimeUtcFromOlsenMapping>(); olsenMapping.Expect(o => o.DateTimeWithOlsenZoneToUtc(model.StartTime, model.UserTimeZone)).Return(mappedDateTime); var mapper = new CoordinatorModelToMessageMapping(olsenMapping); var excludedNumbers = new List<string> { "04040404040" }; var message = mapper.MapToTrickleOverPeriod(model, new CountryCodeReplacement(), excludedNumbers); var coordinationDuration = model.SendAllBy.Value.Subtract(model.StartTime); Assert.That(coordinationDuration, Is.GreaterThan(new TimeSpan(0))); Assert.That(message.Messages.Count, Is.EqualTo(1)); Assert.That(message.Messages[0].Mobile, Is.EqualTo(model.Numbers.Split(',')[1].Trim())); Assert.That(message.Messages[0].Message, Is.EqualTo(model.Message)); Assert.That(message.MetaData.Tags, Is.EqualTo(null)); Assert.That(message.MetaData.Topic, Is.EqualTo(model.Topic)); Assert.That(message.StartTimeUtc, Is.EqualTo(mappedDateTime)); Assert.That(message.Duration, Is.EqualTo(coordinationDuration)); Assert.That(message.ConfirmationEmail, Is.EqualTo(model.ConfirmationEmail)); }
public void MapToTrickleSpacedByTimePeriodWithCountryCodeReplacement() { var model = new CoordinatedSharedMessageModel { Numbers = "04040404040, 11111111111", Message = "Message", StartTime = DateTime.Now.AddHours(2), TimeSeparatorSeconds = 90, Tags = "tag1, tag2", Topic = "Dance Dance Revolution!", ConfirmationEmail = "confirmation" }; var mapper = new CoordinatorModelToMessageMapping(); var message = mapper.MapToTrickleSpacedByPeriod(model, new CountryCodeReplacement { CountryCode = "+61", LeadingNumberToReplace = "0"}); Assert.That(message.Messages.Count, Is.EqualTo(2)); Assert.That(message.Messages[0].Mobile, Is.EqualTo("+614040404040")); Assert.That(message.Messages[0].Message, Is.EqualTo(model.Message)); Assert.That(message.Messages[1].Mobile, Is.EqualTo(model.Numbers.Split(',')[1].Trim())); Assert.That(message.Messages[1].Message, Is.EqualTo(model.Message)); Assert.That(message.MetaData.Tags, Is.EqualTo(model.Tags.Split(',').ToList().Select(t => t.Trim()).ToList())); Assert.That(message.MetaData.Topic, Is.EqualTo(model.Topic)); Assert.That(message.StartTimeUtc, Is.EqualTo(model.StartTime.ToUniversalTime())); Assert.That(message.TimeSpacing, Is.EqualTo(TimeSpan.FromSeconds(model.TimeSeparatorSeconds.Value))); Assert.That(message.ConfirmationEmail, Is.EqualTo(model.ConfirmationEmail)); }
public void CreateSeparatedByTimeSpanReturnsDetails() { var model = new CoordinatedSharedMessageModel { Numbers= "04040404040, 04040402", Message = "Message", StartTime = DateTime.Now.AddHours(2), TimeSeparatorSeconds = 5000, Tags = "tag1, tag2", Topic = "New Feature!", UserTimeZone = "Australia/Sydney" }; var bus = MockRepository.GenerateMock<IBus>(); var mapper = MockRepository.GenerateMock<ICoordinatorModelToMessageMapping>(); var ravenDocStore = MockRepository.GenerateMock<IRavenDocStore>(); var docStore = MockRepository.GenerateMock<IDocumentStore>(); var docSession = MockRepository.GenerateMock<IDocumentSession>(); ravenDocStore.Expect(r => r.GetStore()).Return(docStore); docStore.Expect(d => d.OpenSession("Configuration")).Return(docSession); docSession.Expect(d => d.Load<CountryCodeReplacement>("CountryCodeConfig")).Return(new CountryCodeReplacement()); mapper .Expect(m => m.MapToTrickleSpacedByPeriod(Arg<CoordinatedSharedMessageModel>.Is.Anything, Arg<CountryCodeReplacement>.Is.Anything, Arg<List<string>>.Is.Anything)) .Return(new TrickleSmsWithDefinedTimeBetweenEachMessage()); var trickleMessage = new TrickleSmsWithDefinedTimeBetweenEachMessage(); bus.Expect(b => b.Send(Arg<TrickleSmsWithDefinedTimeBetweenEachMessage>.Is.NotNull)) .WhenCalled(i => trickleMessage = (TrickleSmsWithDefinedTimeBetweenEachMessage) ((object[]) (i.Arguments[0]))[0]); var controller = new CoordinatorController { ControllerContext = new ControllerContext(), Bus = bus, Mapper = mapper, RavenDocStore = ravenDocStore }; var actionResult = (RedirectToRouteResult)controller.Create(model); Assert.That(actionResult.RouteValues["action"], Is.EqualTo("Details")); Assert.That(trickleMessage.CoordinatorId, Is.Not.EqualTo(Guid.Empty)); bus.VerifyAllExpectations(); mapper.VerifyAllExpectations(); }
public void CreateOverTimespanReturnsDetails() { var model = new CoordinatedSharedMessageModel { Numbers = "04040404040, lskadfjlasdk", Message = "Message", StartTime = DateTime.Now.AddHours(2), SendAllBy = DateTime.Now.AddHours(3), Topic = "frank", UserTimeZone = "Australia/Sydney" }; var bus = MockRepository.GenerateMock<IBus>(); var mapper = MockRepository.GenerateMock<ICoordinatorModelToMessageMapping>(); var ravenDocStore = MockRepository.GenerateMock<IRavenDocStore>(); var docStore = MockRepository.GenerateMock<IDocumentStore>(); var docSession = MockRepository.GenerateMock<IDocumentSession>(); var currentUser = MockRepository.GenerateStub<ICurrentUser>(); ravenDocStore.Expect(r => r.GetStore()).Return(docStore); docStore.Expect(d => d.OpenSession("Configuration")).Return(docSession); docSession.Expect(d => d.Load<CountryCodeReplacement>("CountryCodeConfig")).Return(new CountryCodeReplacement()); mapper .Expect(m => m.MapToTrickleOverPeriod(Arg<CoordinatedSharedMessageModel>.Is.Anything, Arg<CountryCodeReplacement>.Is.Anything, Arg<List<string>>.Is.Equal(new List<string>()), Arg<string>.Is.Anything)) .Return(new TrickleSmsOverCalculatedIntervalsBetweenSetDates()); var trickleMessage = new TrickleSmsOverCalculatedIntervalsBetweenSetDates(); bus.Expect(b => b.Send(Arg<TrickleSmsOverCalculatedIntervalsBetweenSetDates>.Is.NotNull)) .WhenCalled(i => trickleMessage = (TrickleSmsOverCalculatedIntervalsBetweenSetDates)(i.Arguments[0])); var controller = new CoordinatorController { ControllerContext = new ControllerContext(), Bus = bus, Mapper = mapper, RavenDocStore = ravenDocStore, CurrentUser = currentUser }; var actionResult = (RedirectToRouteResult)controller.Create(model); Assert.That(actionResult.RouteValues["action"], Is.EqualTo("Details")); Assert.That(trickleMessage.CoordinatorId, Is.Not.EqualTo(Guid.Empty)); bus.VerifyAllExpectations(); mapper.VerifyAllExpectations(); }
public void CoordinatorOverTimespanReturnsDetails() { var model = new CoordinatedSharedMessageModel { Numbers = "04040404040", Message = "Message", StartTime = DateTime.Now.AddHours(2), SendAllBy = DateTime.Now.AddHours(3) }; var bus = MockRepository.GenerateMock<IBus>(); var mapper = MockRepository.GenerateMock<ICoordinatorModelToMessageMapping>(); mapper.Expect(m => m.MapToTrickleOverPeriod(Arg<CoordinatedSharedMessageModel>.Is.Anything)).Return(new TrickleSmsOverCalculatedIntervalsBetweenSetDates()); var trickleMessage = new TrickleSmsOverCalculatedIntervalsBetweenSetDates(); bus.Expect(b => b.Send(Arg<TrickleSmsOverCalculatedIntervalsBetweenSetDates>.Is.NotNull)) .WhenCalled(i => trickleMessage = (TrickleSmsOverCalculatedIntervalsBetweenSetDates)((object[])(i.Arguments[0]))[0]); var controller = new CoordinatorController { ControllerContext = new ControllerContext(), Bus = bus, Mapper = mapper }; var actionResult = (RedirectToRouteResult)controller.Create(model); Assert.That(actionResult.RouteValues["action"], Is.EqualTo("Details")); Assert.That(trickleMessage.CoordinatorId, Is.Not.EqualTo(Guid.Empty)); bus.VerifyAllExpectations(); mapper.VerifyAllExpectations(); }
public void CreateSingleNumber_UseSendAllNow() { var model = new CoordinatedSharedMessageModel { Numbers = "04040404040", Message = "asfdkjadfskl asflkj;faskjf;aslkjf;lasdkjfaslkfjas;lkfjslkfjas;lkfjsalkfjas;fklasj;flksdjf;lkasjflskdjflkasjflksjlk lskaf jlsk fdaskl dflksjfalk sflkj sfkl jlkjs flkj skjkj sadflkjsaflj", StartTime = DateTime.Now.AddHours(2), Topic = "frank", UserTimeZone = "Australia/Sydney" }; var bus = MockRepository.GenerateMock<IBus>(); var mapper = MockRepository.GenerateMock<ICoordinatorModelToMessageMapping>(); var ravenDocStore = MockRepository.GenerateMock<IRavenDocStore>(); var docStore = MockRepository.GenerateMock<IDocumentStore>(); var configSession = MockRepository.GenerateMock<IDocumentSession>(); var trackingSession = MockRepository.GenerateMock<IDocumentSession>(); ravenDocStore.Expect(r => r.GetStore()).Return(docStore); docStore.Expect(d => d.OpenSession("Configuration")).Return(configSession); docStore.Expect(d => d.OpenSession("SmsTracking")).Return(trackingSession); configSession.Expect(d => d.Load<CountryCodeReplacement>("CountryCodeConfig")).Return(new CountryCodeReplacement()); var coordinatorMessage = new CoordinatedSharedMessageModel(); List<string> excludeList = null; mapper .Expect(m => m.MapToSendAllAtOnce(Arg<CoordinatedSharedMessageModel>.Is.Anything, Arg<CountryCodeReplacement>.Is.Anything, Arg<List<string>>.Is.Anything)) .Return(new SendAllMessagesAtOnce()) .WhenCalled(t => coordinatorMessage = (CoordinatedSharedMessageModel)(t.Arguments[0])) .WhenCalled(t => excludeList = (List<string>)(t.Arguments[2])); bus.Expect(b => b.Send(Arg<TrickleSmsOverCalculatedIntervalsBetweenSetDates>.Is.NotNull)); var controller = new CoordinatorController { ControllerContext = new ControllerContext(), Bus = bus, Mapper = mapper, RavenDocStore = ravenDocStore }; var actionResult = (RedirectToRouteResult)controller.Create(model); Assert.That(actionResult.RouteValues["action"], Is.EqualTo("Details")); Assert.That(coordinatorMessage.Message, Is.EqualTo(model.Message.Substring(0, 160))); bus.VerifyAllExpectations(); mapper.VerifyAllExpectations(); configSession.VerifyAllExpectations(); trackingSession.VerifyAllExpectations(); }