コード例 #1
0
        public async System.Threading.Tasks.Task SendEventByIdQueryWithCorrectEventId()
        {
            var model = new EditViewModel { EventId = 1 };
            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.SendAsync(It.IsAny<EventByEventIdQuery>())).ReturnsAsync(new Event { Campaign = new Campaign() });

            var sut = new TaskEditViewModelValidator(mediator.Object);
            await sut.Validate(model);

            mediator.Verify(x => x.SendAsync(It.Is<EventByEventIdQuery>(y => y.EventId == model.EventId)), Times.Once);
        }
コード例 #2
0
        public async System.Threading.Tasks.Task ReturnCorrectErrorWhenModelsStartDateTimeIsLessThanParentEventStartDate()
        {
            var now = DateTimeOffset.Now;

            var @event = new Event { Campaign = new Campaign { TimeZoneId = "UTC", }, TimeZoneId = "UTC", StartDateTime = now.AddDays(1), EndDateTime = now.AddDays(-1) };

            var mockMediator = new Mock<IMediator>();
            mockMediator.Setup(x => x.SendAsync(It.IsAny<EventByEventIdQuery>())).ReturnsAsync(@event);
            
            var validator = new TaskEditViewModelValidator(mockMediator.Object);
            var errors = await validator.Validate(new EditViewModel());

            Assert.True(errors.Exists(x => x.Key.Equals("StartDateTime")));
            Assert.Equal(errors.Find(x => x.Key == "StartDateTime").Value, String.Format("Start date cannot be earlier than the event start date {0:g}.", @event.StartDateTime));
        }
コード例 #3
0
        public async System.Threading.Tasks.Task InvokeGetDateTimeOffsetWithCorrectParametersForEndDate()
        {
            var now = DateTimeOffset.Now;

            var model = new EditViewModel { EventId = 1, StartDateTime = now, EndDateTime = now };
            var @event = new Event { Campaign = new Campaign { TimeZoneId = "UTC" } };

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.SendAsync(It.IsAny<EventByEventIdQuery>())).ReturnsAsync(@event);

            var dateTimeOffsetProvider = new Mock<IConvertDateTimeOffset>();

            var sut = new TaskEditViewModelValidator(mediator.Object, dateTimeOffsetProvider.Object);
            await sut.Validate(model);

            dateTimeOffsetProvider.Verify(x => x.ConvertDateTimeOffsetTo(@event.Campaign.TimeZoneId, model.EndDateTime, model.EndDateTime.Hour,
                model.EndDateTime.Minute, 0));
        }
コード例 #4
0
        public async System.Threading.Tasks.Task ReturnCorrectErrorWhenModelsEndDateTimeIsGreaterThanParentEventStartDate()
        {
            var now = DateTimeOffset.Now;

            var @event = new Event { Campaign = new Campaign { TimeZoneId = "UTC", },
                StartDateTime = now,
                EndDateTime = now.AddDays(-1) };

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.SendAsync(It.IsAny<EventByEventIdQuery>())).ReturnsAsync(@event);

            var validator = new TaskEditViewModelValidator(mediator.Object);
            var errors = await validator.Validate(new EditViewModel
            {
                EndDateTime = now.AddDays(-1).AddMinutes(15)
            });

            Assert.True(errors.Exists(x => x.Key.Equals("EndDateTime")));
            Assert.Equal(errors.Find(x => x.Key == "EndDateTime").Value, String.Format("The end date of this task cannot be after the end date of the event {0:g}", @event.EndDateTime));
        }
コード例 #5
0
        public async System.Threading.Tasks.Task ReturnCorrectErrorWhenEndDateTimeIsLessThanStartDateTime()
        {
            var now = DateTimeOffset.Now;

            var @event = new Event { Campaign = new Campaign { TimeZoneId = "UTC" }};

            var dateTimeOffsetProvider = new Mock<IConvertDateTimeOffset>();
            dateTimeOffsetProvider.SetupSequence(x => x.ConvertDateTimeOffsetTo(It.IsAny<string>(), It.IsAny<DateTimeOffset>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
                .Returns(now.AddDays(1))
                .Returns(now.AddDays(-1));

            var mockMediator = new Mock<IMediator>();
            mockMediator.Setup(x => x.SendAsync(It.IsAny<EventByEventIdQuery>())).ReturnsAsync(@event);

            var validator = new TaskEditViewModelValidator(mockMediator.Object, dateTimeOffsetProvider.Object);
            var errors = await validator.Validate(new EditViewModel());

            Assert.True(errors.Exists(x => x.Key.Equals("EndDateTime")));
            Assert.Equal(errors.Find(x => x.Key == "EndDateTime").Value, "End date cannot be earlier than the start date");
        }
コード例 #6
0
        public async System.Threading.Tasks.Task ReturnCorrectErrorWhenEndDateTimeIsLessThanStartDateTime()
        {
            var now = DateTimeOffset.Now;

            var @event = new Event {
                Campaign = new Campaign { TimeZoneId = "UTC" },
                TimeZoneId = "UTC"};
            
            var mockMediator = new Mock<IMediator>();
            mockMediator.Setup(x => x.SendAsync(It.IsAny<EventByEventIdQuery>())).ReturnsAsync(@event);

            var validator = new TaskEditViewModelValidator(mockMediator.Object);
            var errors = await validator.Validate(new EditViewModel
            {
                StartDateTime = now,
                EndDateTime = now.AddMinutes(-30)
            });

            Assert.True(errors.Exists(x => x.Key.Equals("EndDateTime")));
            Assert.Equal(errors.Find(x => x.Key == "EndDateTime").Value, "End date cannot be earlier than the start date");
        }
コード例 #7
0
        public async System.Threading.Tasks.Task ReturnCorrectErrorWhenItineraryTaskWithStartAndEndDatesNotOnSameDay()
        {
            var now = DateTimeOffset.Now;

            var @event = new Event { Campaign = new Campaign { TimeZoneId = "UTC", }, StartDateTime = now, EndDateTime = now.AddDays(1), EventType = EventType.Itinerary };

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.SendAsync(It.IsAny<EventByEventIdQuery>())).ReturnsAsync(@event);

            var validator = new TaskEditViewModelValidator(mediator.Object);
            var errors = await validator.Validate(new EditViewModel
            {
                StartDateTime = now.AddDays(-1),
                EndDateTime = now
            });

            Assert.True(errors.Exists(x => x.Key.Equals("EndDateTime")));
            Assert.Equal(errors.Find(x => x.Key == "EndDateTime").Value, "For itinerary events the task end date must occur on the same day as the start date. Tasks cannot span multiple days");
        }
コード例 #8
0
        public async System.Threading.Tasks.Task ReturnNoErrorForItineraryTaskWhenModelsDatesAreValid()
        {
            var now = new DateTimeOffset(2016, 10, 4, 8, 0, 0, TimeSpan.FromSeconds(0));

            var @event = new Event { Campaign = new Campaign { TimeZoneId = "UTC", }, StartDateTime = now, EndDateTime = now.AddDays(1), TimeZoneId = "UTC", EventType = EventType.Itinerary };

            var mockMediator = new Mock<IMediator>();
            mockMediator.Setup(x => x.SendAsync(It.IsAny<EventByEventIdQuery>())).ReturnsAsync(@event);

            var validator = new TaskEditViewModelValidator(mockMediator.Object);
            var errors = await validator.Validate(new EditViewModel
            {
                StartDateTime = now.AddMinutes(15),
                EndDateTime = now.AddMinutes(120)
            });

            Assert.True(errors.Count == 0);
        }
コード例 #9
0
        public async System.Threading.Tasks.Task ReturnNoErrorForNonItineraryTaskWhenModelsDatesAreValid()
        {
            var now = DateTimeOffset.Now;

            var @event = new Event { Campaign = new Campaign { TimeZoneId = "UTC" }, TimeZoneId = "UTC", StartDateTime = now, EndDateTime = now.AddDays(1), EventType = EventType.Rally };

            var mockMediator = new Mock<IMediator>();
            mockMediator.Setup(x => x.SendAsync(It.IsAny<EventByEventIdQuery>())).ReturnsAsync(@event);

            
            var validator = new TaskEditViewModelValidator(mockMediator.Object);
            var errors = await validator.Validate(new EditViewModel
            {
                StartDateTime = now.AddMinutes(30),
                EndDateTime = now.AddDays(1).AddMinutes(-30)
            });

            Assert.True(errors.Count == 0);
        }
コード例 #10
0
        public async System.Threading.Tasks.Task ReturnNoErrorForItineraryTaskWhenModelsDatesAreValid()
        {
            var now = DateTimeOffset.Now;

            var @event = new Event { Campaign = new Campaign { TimeZoneId = "UTC", }, StartDateTime = now, EndDateTime = now.AddDays(1), EventType = EventType.Itinerary };

            var mockMediator = new Mock<IMediator>();
            mockMediator.Setup(x => x.SendAsync(It.IsAny<EventByEventIdQuery>())).ReturnsAsync(@event);

            var dateTimeOffsetProvider = new Mock<IConvertDateTimeOffset>();
            dateTimeOffsetProvider.SetupSequence(x => x.ConvertDateTimeOffsetTo(It.IsAny<string>(), It.IsAny<DateTimeOffset>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
                .Returns(now)
                .Returns(now);

            var validator = new TaskEditViewModelValidator(mockMediator.Object, dateTimeOffsetProvider.Object);
            var errors = await validator.Validate(new EditViewModel());

            Assert.True(errors.Count == 0);
        }
コード例 #11
0
        public async System.Threading.Tasks.Task ReturnCorrectErrorWhenModelsEndDateTimeIsGreaterThanParentEventStartDate()
        {
            var now = DateTimeOffset.Now;

            var @event = new Event { Campaign = new Campaign { TimeZoneId = "UTC", }, StartDateTime = now, EndDateTime = now.AddDays(-1) };

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.SendAsync(It.IsAny<EventByEventIdQuery>())).ReturnsAsync(@event);

            var dateTimeOffsetProvider = new Mock<IConvertDateTimeOffset>();
            dateTimeOffsetProvider.Setup(x => x.ConvertDateTimeOffsetTo(It.IsAny<string>(), It.IsAny<DateTimeOffset>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
                .Returns(now);

            var validator = new TaskEditViewModelValidator(mediator.Object, dateTimeOffsetProvider.Object);
            var errors = await validator.Validate(new EditViewModel());

            Assert.True(errors.Exists(x => x.Key.Equals("EndDateTime")));
            Assert.Equal(errors.Find(x => x.Key == "EndDateTime").Value, "End date cannot be later than the event end date " + @event.EndDateTime.ToString("d"));
        }