Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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");
 }
Exemplo n.º 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);
 }
Exemplo n.º 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);
        }
Exemplo n.º 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}");
 }
Exemplo n.º 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);
        }
Exemplo n.º 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");
 }
Exemplo n.º 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)));
        }
Exemplo n.º 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)));
        }
Exemplo n.º 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());
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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");
 }
Exemplo n.º 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)));
        }
Exemplo n.º 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");
 }
Exemplo n.º 21
0
 public void GetHasHttpGetAttribute()
 {
     var sut = new EventApiController(null, null);
     var attribute = sut.GetAttributesOn(x => x.Get()).OfType<HttpGetAttribute>().SingleOrDefault();
     Assert.NotNull(attribute);
 }
Exemplo n.º 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");
 }
Exemplo n.º 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);
 }
Exemplo n.º 24
0
 public async Task RegisterEventReturnsHttpBadRequetWhenSignupModelIsNull()
 {
     var sut = new EventApiController(null, null);
     var result = await sut.RegisterEvent(null);
     Assert.IsType<BadRequestResult>(result);
 }
Exemplo n.º 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");
 }
Exemplo n.º 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);
        }
Exemplo n.º 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))));
        }
Exemplo n.º 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"));
        }
Exemplo n.º 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");
 }
Exemplo n.º 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");
 }