public void ControllerHasProducesAtttributeWithTheCorrectContentType() { var sut = new CampaignApiController(null); var attribute = sut.GetAttributes().OfType<ProducesAttribute>().SingleOrDefault(); Assert.NotNull(attribute); Assert.Equal(attribute.ContentTypes.Select(x => x).First(), "application/json"); }
public void ControllerHasRouteAtttributeWithTheCorrectRoute() { var sut = new CampaignApiController(null); var attribute = sut.GetAttributes().OfType<RouteAttribute>().SingleOrDefault(); Assert.NotNull(attribute); Assert.Equal(attribute.Template, "api/campaign"); }
public void GetCampaignsByPostalCodeReturnsCorrectResults() { var event1 = new Event { Id = 1, CampaignId = 1 }; event1.Campaign = new Campaign { Id = 1, Events = new List<Event> { event1 }, ManagingOrganization = new Organization() }; var event2 = new Event { Id = 2 }; var event3 = new Event { Id = 3 }; var campaign2 = new Campaign { Id = 2, Events = new List<Event> { event2, event3 }, ManagingOrganization = new Organization() }; event2.CampaignId = campaign2.Id; event2.Campaign = campaign2; event3.CampaignId = campaign2.Id; event3.Campaign = campaign2; var allEvents = new List<Event> { event1, event2, event3 }; var mediator = new Mock<IMediator>(); mediator.Setup(x => x.Send(It.IsAny<EventsByPostalCodeQuery>())).Returns(allEvents); var sut = new CampaignApiController(mediator.Object); var results = sut.GetCampaignsByPostalCode(It.IsAny<string>(), It.IsAny<int>()); Assert.Equal(results.Count(), allEvents.Count); }
public void GetCampaignsByPostalCodeReturnsCorrectResults() { var activity1 = new Activity { Id = 1, CampaignId = 1 }; activity1.Campaign = new Campaign { Id = 1, Activities = new List<Activity> { activity1 }, ManagingOrganization = new Organization() }; var activity2 = new Activity { Id = 2 }; var activity3 = new Activity { Id = 3 }; var campaign2 = new Campaign { Id = 2, Activities = new List<Activity> { activity2, activity3 }, ManagingOrganization = new Organization() }; activity2.CampaignId = campaign2.Id; activity2.Campaign = campaign2; activity3.CampaignId = campaign2.Id; activity3.Campaign = campaign2; var allActivities = new List<Activity> { activity1, activity2, activity3 }; var mediator = new Mock<IMediator>(); mediator.Setup(x => x.Send(It.IsAny<AcitivitiesByPostalCodeQuery>())).Returns(allActivities); var sut = new CampaignApiController(mediator.Object); var results = sut.GetCampaignsByPostalCode(It.IsAny<string>(), It.IsAny<int>()); Assert.Equal(results.Count(), allActivities.Count); }
public void GetCampaignsByPostalCodeReturnsCorrectModel() { var mediator = new Mock<IMediator>(); mediator.Setup(x => x.Send(It.IsAny<EventsByPostalCodeQuery>())).Returns(new List<Event>()); var sut = new CampaignApiController(mediator.Object); var result = sut.GetCampaignsByPostalCode(It.IsAny<string>(), It.IsAny<int>()); Assert.IsType<List<EventViewModel>>(result); }
public void GetCampaignsByPostalCodeSendsEventsByPostalCodeQueryWithCorrectPostalCodeAndDistance() { const string zip = "zip"; const int miles = 1; var mediator = new Mock<IMediator>(); mediator.Setup(x => x.Send(It.IsAny<EventsByPostalCodeQuery>())).Returns(new List<Event>()); var sut = new CampaignApiController(mediator.Object); sut.GetCampaignsByPostalCode(zip, miles); mediator.Verify(x => x.Send(It.Is<EventsByPostalCodeQuery>(y => y.PostalCode == zip && y.Distance == miles))); }