public static ResolvedServiceStop CreateResolvedArrivalStop( string timetableId = "X12345", StpIndicator indicator = StpIndicator.Permanent, ICalendar calendar = null, ScheduleLocation[] stops = null, int id = 1, CifService service = null, string retailServiceId = null, DateTime on = default(DateTime), bool isCancelled = false, Station atLocation = null, Time when = default(Time)) { on = on == default(DateTime) ? MondayAugust12 : on; var schedule = CreateSchedule(timetableId, indicator, calendar, stops, service, retailServiceId); var resolved = new ResolvedService(schedule, on, isCancelled); var destination = schedule.Locations.Last() as ScheduleStop; atLocation = atLocation ?? destination.Station; when = when.Equals(default(Time)) ? destination.Arrival : when; var find = new StopSpecification(atLocation, when, on, TimesToUse.Arrivals); resolved.TryFindStop(find, out var stop); return(stop); }
private static Model.FoundSummaryItem MapResolvedStop(Timetable.CifSchedule schedule = null, Timetable.Station at = null, Time?time = null, Timetable.Station from = null, Timetable.Station to = null) { schedule = schedule ?? TestSchedules.CreateScheduleWithService(); at = at ?? TestStations.Surbiton; time = time ?? TestSchedules.Ten; var find = new StopSpecification(at, time.Value, TestDate, TimesToUse.Departures); var resolved = new ResolvedService(schedule, TestDate, false); resolved.TryFindStop(find, out var stop); if (to != null) { stop.GoesTo(to); } if (from != null) { stop.ComesFrom(from); } var mapper = ToViewProfileConfiguration.CreateMapper(); return(mapper.Map <Timetable.ResolvedServiceStop, Model.FoundSummaryItem>(stop, opts => opts.Items["On"] = stop.On)); }
public async Task DeleteAsyncShould_ReturnsTrueAnd_DeletesCorrectResolvedIssue() { //Arrange var activityService = new Mock <IManagerActivityService>(); var pictureService = IPictureServiceMock.New(DefaultPicId); var issueService = new Mock <IManagerIssueService>(); var service = new ResolvedService(Db, issueService.Object, pictureService.Object, activityService.Object); var(managerId, secondIssue, secondResolved, resolved) = await ResolvedCreator.CreateResolvedManagerAndIssue(Db); //Act var result = await service.DeleteAsync(managerId, secondResolved.Id); var resolvedIssuesAfter = await this.Db.ResolvedIssues.ToListAsync(); var urbanIssueAfter = await this.Db.UrbanIssues.Where(i => i.Id == secondIssue.Id).FirstOrDefaultAsync(); //Assert result.Should().BeTrue(); Db.ResolvedIssues.Should().HaveCount(resolvedIssuesAfter.Count); Db.ResolvedIssues.Should().BeEquivalentTo(resolvedIssuesAfter); urbanIssueAfter.ResolvedIssue.Should().BeNull(); issueService.Verify(i => i.RemoveResolvedReferenceAsync(It.IsAny <int>()), Times.Once); pictureService.Verify(p => p.DeleteImageAsync(It.IsAny <int>()), Times.Once); activityService.Verify(a => a.WriteLogAsync(It.IsAny <string>(), It.IsAny <ManagerActivityType>()), Times.Once); }
public async Task UpdateAsyncShould_ReturnsTrueAnd_ChangesResolvedPictureFileHasPassed() { //Arrange var issueService = new Mock <IManagerIssueService>(); var pictureService = IPictureServiceMock.New(DefaultPicId); var activityService = new Mock <IManagerActivityService>(); var service = new ResolvedService(Db, issueService.Object, pictureService.Object, activityService.Object); var(manager, resolved) = await ResolvedCreator.CreateResolvedAndManager(Db); var file = new Mock <IFormFile>(); var oldImage = resolved.CloudinaryImage; //Act var result = await service.UpdateAsync(manager.Id, resolved.Id, ChangedDescription, file.Object); //Assert result.Should().BeTrue(); resolved.CloudinaryImage.Should().NotBe(oldImage); resolved.CloudinaryImageId.Should().Be(DefaultPicId); resolved.Description.Should().NotMatch(DefaultDescription); resolved.Description.Should().Match(ChangedDescription); pictureService.Verify(p => p.DeleteImageAsync(It.IsAny <int>()), Times.Once); activityService.Verify(a => a.WriteLogAsync(It.IsAny <string>(), It.IsAny <ManagerActivityType>()), Times.Once); }
public S Convert(ResolvedService source, S destination, ResolutionContext context) { if (source is Timetable.ResolvedServiceWithAssociations withAssociations) { return(MapServiceWithAssociations(withAssociations, context)); } return(CreateService(source, context)); }
public static ResolvedAssociation CreateAssociation(ResolvedService main, string associatedUid, bool associationIsCancelled = false, bool isNextDay = false) { var associated = CreateScheduleWithService(associatedUid, stops: CreateWokingClaphamSchedule(NineForty)); var associatedDate = isNextDay ? main.On.AddDays(1) : main.On; var resolvedAssociated = new ResolvedService(associated, associatedDate, false); return(CreateAssociation(main, resolvedAssociated, associationIsCancelled)); }
public void DoNotFindStop() { var service = new ResolvedService(TestSchedules.CreateSchedule(), DateTime.Today, false); var find = CreateFindSpec(TestSchedules.TenThirty); Assert.False(service.TryFindStop(find, out var stop)); Assert.Null(stop); }
public void FindStopIsIndependentOfWhetherCancelled(bool isCancelled) { var service = new ResolvedService(TestSchedules.CreateSchedule(), DateTime.Today, isCancelled); var find = CreateFindSpec(TestSchedules.Ten); Assert.True(service.TryFindStop(find, out var stop)); Assert.NotNull(stop); }
private S CreateService(ResolvedService source, ResolutionContext context) { context.Items["On"] = source.On; var service = context.Mapper.Map <S>(source.Details); service.Date = source.On; service.IsCancelled = source.IsCancelled; return(service); }
public static ResolvedAssociation CreateAssociation(ResolvedService main, ResolvedService associated, bool associationIsCancelled = false) { var association = TestAssociations.CreateAssociationWithServices((CifService)main.Details.Service, (CifService)associated.Details.Service); return(new ResolvedAssociation( association, main.On, associationIsCancelled, associated)); }
private static Model.ServiceSummary MapSchedule(Timetable.CifSchedule schedule = null, bool isCancelled = false) { var mapper = ToViewProfileConfiguration.CreateMapper(); schedule = schedule ?? TestSchedules.CreateScheduleWithService(); var resolved = new ResolvedService(schedule, TestDate, isCancelled); return(mapper.Map <Timetable.ResolvedService, Model.ServiceSummary>(resolved, opts => opts.Items["On"] = resolved.On)); }
public void RemovedCancelledAssocation() { ResolvedService service = TestSchedules.CreateServiceWithAssociation(associationIsCancelled: true); Assert.True(service.HasAssociations()); var notCancelled = FilterCancelled(new [] { service }); Assert.NotEmpty(notCancelled); Assert.False(notCancelled[0].HasAssociations()); }
public static ResolvedServiceWithAssociations CreateServiceWithAssociation( ResolvedService resolved, bool associationIsCancelled = false, string associatedUid = "A98765", bool isNextDay = false) { var association = CreateAssociation(resolved, associatedUid, associationIsCancelled, isNextDay); var resolvedWithAssociations = new ResolvedServiceWithAssociations(resolved, new [] { association }); return(resolvedWithAssociations); }
public static ResolvedServiceStop CreateResolvedDepartureStop( ResolvedService service, Station atLocation = null, Time when = default(Time)) { var origin = service.Details.Locations.First() as ScheduleStop; atLocation = atLocation ?? origin.Station; when = when.Equals(default(Time)) ? origin.Departure : when; var find = new StopSpecification(atLocation, when, service.On, TimesToUse.Departures); service.TryFindStop(find, out var stop); return(stop); }
public async Task GetAsyncShould_ReturnsCorrectModel() { //Arrange var service = new ResolvedService(Db, null, null, null); var resolved = await ResolvedCreator.Create(Db); //Act var result = await service.GetAsync <ResolvedIssueEditModel>(resolved.Id); //Assert result.Should().BeOfType <ResolvedIssueEditModel>(); result.Id.Should().Be(resolved.Id); result.CloudinaryImageId.Should().Be(resolved.CloudinaryImageId); result.Description.Should().Be(resolved.Description); }
public static ResolvedServiceStop CreateResolvedDepartureStop( string timetableId = "X12345", StpIndicator indicator = StpIndicator.Permanent, ICalendar calendar = null, ScheduleLocation[] stops = null, CifService service = null, string retailServiceId = null, DateTime on = default(DateTime), bool isCancelled = false, Station atLocation = null, Time when = default(Time)) { on = on == default(DateTime) ? MondayAugust12 : on; var schedule = CreateSchedule(timetableId, indicator, calendar, stops, service, retailServiceId); var resolved = new ResolvedService(schedule, on, isCancelled); return(CreateResolvedDepartureStop(resolved, atLocation, when)); }
public async Task UpdateAsyncShould_ReturnsFalseIf_UpdaterIsNotTheSameAsUploader() { //Arrange var publisher = UserCreator.Create(); var updater = UserCreator.Create(); await this.Db.AddRangeAsync(publisher, updater); var issue = UrbanIssueCreator.CreateIssue(RegionType.All); await this.Db.AddAsync(issue); var resolved = ResolvedCreator.Create(publisher.Id, issue.Id, DefaultPicId); await this.Db.AddAsync(resolved); await this.Db.SaveChangesAsync(); var issueService = new Mock <IManagerIssueService>(); var pictureService = IPictureServiceMock.New(DefaultPicId); var activityService = new Mock <IManagerActivityService>(); var service = new ResolvedService(Db, issueService.Object, pictureService.Object, activityService.Object); //Act var result = await service.UpdateAsync(updater.Id, resolved.Id, ChangedDescription, null); var resolvedAfterAct = await this.Db.FindAsync <ResolvedIssue>(resolved.Id); //Assert result.Should().Be(false); resolved.Should().BeEquivalentTo(resolvedAfterAct); pictureService.Verify(p => p.DeleteImageAsync(It.IsAny <int>()), Times.Never); activityService.Verify(a => a.WriteLogAsync(It.IsAny <string>(), It.IsAny <ManagerActivityType>()), Times.Never); }
public async Task DeleteAsyncShould_ReturnsFalse_IfManagerId_IsNotEqualTo_ResolvedPublisherId() { //Arrange var issueService = new Mock <IManagerIssueService>(); var pictureService = IPictureServiceMock.New(DefaultPicId); var activityService = new Mock <IManagerActivityService>(); var service = new ResolvedService(Db, issueService.Object, pictureService.Object, activityService.Object); var manager = UserCreator.Create(); var publisher = UserCreator.Create(); await Db.AddRangeAsync(manager, publisher); var issue = UrbanIssueCreator.CreateIssue(RegionType.All); await Db.AddAsync(issue); var resolved = ResolvedCreator.Create(publisher.Id, issue.Id, 0); await Db.AddAsync(resolved); await Db.SaveChangesAsync(); //Act var result = await service.DeleteAsync(manager.Id, resolved.Id); //Assert result.Should().BeFalse(); issueService.Verify(i => i.RemoveResolvedReferenceAsync(It.IsAny <int>()), Times.Never); pictureService.Verify(p => p.DeleteImageAsync(It.IsAny <int>()), Times.Never); activityService.Verify(a => a.WriteLogAsync(It.IsAny <string>(), It.IsAny <ManagerActivityType>()), Times.Never); }
private A MapAssociation(ResolvedAssociation source, ResolvedService service, ResolutionContext context) { var(associatedService, associatedServiceStop) = MapOtherService(); var association = new A() { Stop = MapStop(source.Stop.Stop, context), IsBroken = source.Stop.IsBroken, IsCancelled = source.IsCancelled, IsMain = source.IsMain(service.TimetableUid), Date = source.On, AssociationCategory = source.Details.Category.ToString(), AssociatedServiceStop = associatedServiceStop }; SetAssociatedService(association, associatedService); return(association); (S, Model.ScheduledStop) MapOtherService() { // Association maybe on different day. var originalDate = context.Items["On"]; try { var otherService = CreateService(source.AssociatedService, context); var otherStop = MapStop(source.Stop.AssociatedServiceStop, context); return(otherService, otherStop); } finally { // Reset service date context.Items["On"] = originalDate; } } }
public void ToStringReturnsTimetableUidAndDate(bool isCancelled, string expected) { var service = new ResolvedService(TestSchedules.CreateSchedule(), TestDate, isCancelled); Assert.Equal(expected, service.ToString()); }