예제 #1
0
        public void GetSendsEventsWithUnlockedCampaignsQuery()
        {
            var mediator = new Mock<IMediator>();
            var sut = new EventApiController(mediator.Object, null);
            sut.Get();

            mediator.Verify(x => x.Send(It.IsAny<EventsWithUnlockedCampaignsQuery>()), Times.Once);
        }
예제 #2
0
        public void GetByIdReturnsCorrectViewModel()
        {
            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.Send(It.IsAny<EventByIdQuery>())).Returns(new Event { Campaign = new Campaign { ManagingOrganization = new Organization() }});
            var sut = new EventApiController(mediator.Object, null);
            var result = sut.Get(It.IsAny<int>());

            Assert.IsType<EventViewModel>(result);
        }
예제 #3
0
        public void GetReturnsCorrectModel()
        {
            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.Send(It.IsAny<EventsWithUnlockedCampaignsQuery>())).Returns(new List<EventViewModel>());

            var sut = new EventApiController(mediator.Object, null);
            var results = sut.Get();

            Assert.IsType<List<EventViewModel>>(results);
        }
예제 #4
0
        public void GetByIdSendsEventByEventIdQueryWithCorrectData()
        {
            const int eventId = 1;

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.Send(It.IsAny<EventByIdQuery>())).Returns(new Event { Campaign = new Campaign { ManagingOrganization = new Organization() }});
            var sut = new EventApiController(mediator.Object, null);

            sut.Get(eventId);

            mediator.Verify(x => x.Send(It.Is<EventByIdQuery>(y => y.EventId == eventId)), Times.Once);
        }
예제 #5
0
 public void RegisterEventHasHttpPostAttributeWithCorrectTemplate()
 {
     var sut = new EventApiController(null, null);
     var attribute = (HttpPostAttribute)sut.GetAttributesOn(x => x.RegisterEvent(It.IsAny<EventSignupViewModel>())).SingleOrDefault(x => x.GetType() == typeof(HttpPostAttribute));
     Assert.NotNull(attribute);
     Assert.Equal(attribute.Template, "signup");
 }
예제 #6
0
 public void RegisterEventHasValidateAntiForgeryTokenAttribute()
 {
     var sut = new EventApiController(null, null);
     var attribute = (ValidateAntiForgeryTokenAttribute)sut.GetAttributesOn(x => x.RegisterEvent(It.IsAny<EventSignupViewModel>())).SingleOrDefault(x => x.GetType() == typeof(ValidateAntiForgeryTokenAttribute));
     Assert.NotNull(attribute);
 }
예제 #7
0
        public void GetEventsByGeographySendsEventsByGeographyQueryWithCorrectLatitudeLongitudeAndMiles()
        {
            const double latitude = 1;
            const double longitude = 2;
            const int miles = 100;

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.Send(It.IsAny<EventsByGeographyQuery>())).Returns(new List<Event>());

            var sut = new EventApiController(mediator.Object, null);
            sut.GetEventsByGeography(latitude, longitude, miles);

            mediator.Verify(x => x.Send(It.Is<EventsByGeographyQuery>(y => y.Latitude == latitude && y.Longitude == longitude && y.Miles == miles)), Times.Once);
        }
예제 #8
0
 public void GetByIdHasHttpGetAttributeWithCorrectTemplate()
 {
     var sut = new EventApiController(null, null);
     var attribute = sut.GetAttributesOn(x => x.Get(It.IsAny<int>())).OfType<HttpGetAttribute>().SingleOrDefault();
     Assert.NotNull(attribute);
     Assert.Equal(attribute.Template, "{id}");
 }
예제 #9
0
        public void GetCheckinReturnsTheCorrectView()
        {
            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.Send(It.IsAny<EventByIdQuery>())).Returns(new Event { Campaign = new Campaign { ManagingOrganization = new Organization() }});

            var sut = new EventApiController(mediator.Object, null);
            var result = (ViewResult)sut.GetCheckin(It.IsAny<int>());

            Assert.Equal("NoUserCheckin", result.ViewName);
        }
예제 #10
0
 public void PutCheckinHasHttpPutAttributeWithCorrectTemplate()
 {
     var sut = new EventApiController(null, null);
     var attribute = (HttpPutAttribute)sut.GetAttributesOn(x => x.PutCheckin(It.IsAny<int>())).SingleOrDefault(x => x.GetType() == typeof(HttpPutAttribute));
     Assert.NotNull(attribute);
     Assert.Equal(attribute.Template, "{id}/checkin");
 }
예제 #11
0
        public async Task UnregisterEventSendsUnregisterEventWithCorrectEventSignupId()
        {
            const int eventId = 1;
            const int eventSignupId = 1;

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.Send(It.IsAny<EventSignupByEventIdAndUserIdQuery>()))
                .Returns(new EventSignup { Id = eventSignupId, Event = new Event(), User = new ApplicationUser() });

            var controller = new EventApiController(mediator.Object, null);
            controller.SetDefaultHttpContext();

            await controller.UnregisterEvent(eventId);

            mediator.Verify(x => x.SendAsync(It.Is<UnregisterEvent>(y => y.EventSignupId == eventSignupId)));
        }
예제 #12
0
        public async Task PutCheckinSendsAddEventSignupCommandAsyncWithCorrectDataWhenUsersSignedUpIsNotNullAndCheckinDateTimeIsNull()
        {
            const string userId = "userId";
            var utcNow = DateTime.UtcNow;

            var campaignEvent = new Event();
            var eventSignup = new EventSignup { User = new ApplicationUser { Id = userId } };
            campaignEvent.UsersSignedUp.Add(eventSignup);

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.Send(It.IsAny<EventByIdQuery>())).Returns(campaignEvent);

            var sut = new EventApiController(mediator.Object, null) { DateTimeUtcNow = () => utcNow };
            sut.SetFakeUser(userId);
            await sut.PutCheckin(It.IsAny<int>());

            mediator.Verify(x => x.SendAsync(It.Is<AddEventSignupCommandAsync>(y => y.EventSignup == eventSignup)));
            mediator.Verify(x => x.SendAsync(It.Is<AddEventSignupCommandAsync>(y => y.EventSignup.CheckinDateTime == utcNow)));
        }
예제 #13
0
        public async Task PutCheckinReturnsCorrectJsonWhenUsersSignedUpIsNullAndCheckinDateTimeIsNotNull()
        {
            const string userId = "userId";
            var campaignEvent = new Event { Name = "EventName", Description = "EventDescription" };

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.Send(It.IsAny<EventByIdQuery>())).Returns(campaignEvent);

            var sut = new EventApiController(mediator.Object, null);
            sut.SetFakeUser(userId);

            var expected = $"{{ NeedsSignup = True, Event = {{ Name = {campaignEvent.Name}, Description = {campaignEvent.Description} }} }}";

            var result = (JsonResult)await sut.PutCheckin(It.IsAny<int>());

            Assert.IsType<JsonResult>(result);
            Assert.Equal(expected, result.Value.ToString());
        }
예제 #14
0
        public async Task PutCheckinSendsEventByEventIdQueryWithCorrectEventId()
        {
            const int eventId = 1;

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.Send(It.IsAny<EventByIdQuery>())).Returns(new Event());

            var sut = new EventApiController(mediator.Object, null);
            await sut.PutCheckin(eventId);

            mediator.Verify(x => x.Send(It.Is<EventByIdQuery>(y => y.EventId == eventId)), Times.Once);
        }
예제 #15
0
        public async Task PutCheckinReturnsHttpNotFoundWhenUnableToFindEventByEventId()
        {
            var sut = new EventApiController(Mock.Of<IMediator>(), null);
            var result = await sut.PutCheckin(It.IsAny<int>());

            Assert.IsType<NotFoundResult>(result);
        }
예제 #16
0
        public void GetEventsByGeographyReturnsCorrectViewModel()
        {
            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.Send(It.IsAny<EventsByGeographyQuery>())).Returns(new List<Event>());

            var sut = new EventApiController(mediator.Object, null);
            var result = sut.GetEventsByGeography(It.IsAny<double>(), It.IsAny<double>(), It.IsAny<int>());

            Assert.IsType<List<EventViewModel>>(result);
        }
예제 #17
0
        public async Task UnregisterEventReturnsHttpNotFoundWhenUnableToGetEventSignupByEventSignupIdAndUserId()
        {
            var controller = new EventApiController(Mock.Of<IMediator>(), null);
            controller.SetDefaultHttpContext();

            var result = await controller.UnregisterEvent(It.IsAny<int>());
            Assert.IsType<NotFoundResult>(result);
        }
예제 #18
0
 public void UnregisterEventHasHttpDeleteAttributeWithCorrectTemplate()
 {
     var sut = new EventApiController(null, null);
     var attribute = (HttpDeleteAttribute)sut.GetAttributesOn(x => x.UnregisterEvent(It.IsAny<int>())).SingleOrDefault(x => x.GetType() == typeof(HttpDeleteAttribute));
     Assert.NotNull(attribute);
     Assert.Equal(attribute.Template, "{id}/signup");
 }
예제 #19
0
        public async Task UnregisterEventSendsEventSignupByEventIdAndUserIdQueryWithCorrectEventIdAndUserId()
        {
            const int eventId = 1;
            const string userId = "1";

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.Send(It.IsAny<EventSignupByEventIdAndUserIdQuery>()))
                .Returns(new EventSignup { Event = new Event(), User = new ApplicationUser() });

            var controller = new EventApiController(mediator.Object, null);
            controller.SetFakeUser(userId);

            await controller.UnregisterEvent(eventId);

            mediator.Verify(x => x.Send(It.Is<EventSignupByEventIdAndUserIdQuery>(y => y.EventId == eventId && y.UserId == userId)));
        }
예제 #20
0
 public void ControllerHasRouteAtttributeWithTheCorrectRoute()
 {
     var sut = new EventApiController(null, null);
     var attribute = sut.GetAttributes().OfType<RouteAttribute>().SingleOrDefault();
     Assert.NotNull(attribute);
     Assert.Equal(attribute.Template, "api/event");
 }
예제 #21
0
 public void GetHasHttpGetAttribute()
 {
     var sut = new EventApiController(null, null);
     var attribute = sut.GetAttributesOn(x => x.Get()).OfType<HttpGetAttribute>().SingleOrDefault();
     Assert.NotNull(attribute);
 }
예제 #22
0
 public void GetEventsByLocationHasRouteAttributeWithCorrectRoute()
 {
     var sut = new EventApiController(null, null);
     var attribute = sut.GetAttributesOn(x => x.GetEventsByGeography(It.IsAny<double>(), It.IsAny<double>(), It.IsAny<int>())).OfType<RouteAttribute>().SingleOrDefault();
     Assert.NotNull(attribute);
     Assert.Equal(attribute.Template, "searchbylocation");
 }
예제 #23
0
 public void UnregisterEventHasAuthorizeAttribute()
 {
     var sut = new EventApiController(null, null);
     var attribute = (AuthorizeAttribute)sut.GetAttributesOn(x => x.UnregisterEvent(It.IsAny<int>())).SingleOrDefault(x => x.GetType() == typeof(AuthorizeAttribute));
     Assert.NotNull(attribute);
 }
예제 #24
0
 public async Task RegisterEventReturnsHttpBadRequetWhenSignupModelIsNull()
 {
     var sut = new EventApiController(null, null);
     var result = await sut.RegisterEvent(null);
     Assert.IsType<BadRequestResult>(result);
 }
예제 #25
0
 public void ControllerHasProducesAtttributeWithTheCorrectContentType()
 {
     var sut = new EventApiController(null, null);
     var attribute = sut.GetAttributes().OfType<ProducesAttribute>().SingleOrDefault();
     Assert.NotNull(attribute);
     Assert.Equal(attribute.ContentTypes.Select(x => x).First(), "application/json");
 }
예제 #26
0
        public async Task RegisterEventReturnsCorrectJsonWhenModelStateIsNotValid()
        {
            const string modelStateErrorMessage = "modelStateErrorMessage";

            var sut = new EventApiController(null, null);
            sut.AddModelStateErrorWithErrorMessage(modelStateErrorMessage);

            var jsonResult = (JsonResult)await sut.RegisterEvent(new EventSignupViewModel());
            var result = jsonResult.GetValueForProperty<List<string>>("errors");

            Assert.IsType<JsonResult>(jsonResult);
            Assert.IsType<List<string>>(result);
            Assert.Equal(result.First(), modelStateErrorMessage);
        }
예제 #27
0
        public async Task RegisterEventSendsEventSignupCommandAsyncWithCorrectData()
        {
            var model = new EventSignupViewModel();
            var mediator = new Mock<IMediator>();

            var sut = new EventApiController(mediator.Object, null);
            await sut.RegisterEvent(model);

            mediator.Verify(x => x.SendAsync(It.Is<EventSignupCommand>(command => command.EventSignup.Equals(model))));
        }
예제 #28
0
        public async Task RegisterEventReturnsSuccess()
        {
            var sut = new EventApiController(Mock.Of<IMediator>(), null);
            var result = await sut.RegisterEvent(new EventSignupViewModel());

            Assert.True(result.ToString().Contains("success"));
        }
예제 #29
0
 public void GetByIdHasProducesAttributeWithCorrectContentTypes()
 {
     var sut = new EventApiController(null, null);
     var attribute = sut.GetAttributesOn(x => x.Get(It.IsAny<int>())).OfType<ProducesAttribute>().SingleOrDefault();
     Assert.NotNull(attribute);
     Assert.Equal(attribute.Type, typeof(EventViewModel));
     Assert.Equal(attribute.ContentTypes.Select(x => x).First(), "application/json");
 }
예제 #30
0
 public void GetEventsByPostalCodeHasRouteAttributeWithRoute()
 {
     var sut = new EventApiController(null, null);
     var attribute = sut.GetAttributesOn(x => x.GetEventsByPostalCode(It.IsAny<string>(), It.IsAny<int>())).OfType<RouteAttribute>().SingleOrDefault();
     Assert.NotNull(attribute);
     Assert.Equal(attribute.Template, "search");
 }