Skip to content

Commit

Permalink
#340 partial - removed admin area magic strings. (#2074)
Browse files Browse the repository at this point in the history
  • Loading branch information
anobleperson authored and BillWagner committed Aug 16, 2017
1 parent 7d9f576 commit 8423411
Show file tree
Hide file tree
Showing 96 changed files with 792 additions and 686 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using AllReady.Constants;
using Xunit;
using DeleteViewModel = AllReady.Areas.Admin.Features.Events.DeleteViewModel;

Expand Down Expand Up @@ -556,7 +557,7 @@ public async Task DeleteConfirmed_RedirectsToCorrectAction_AndControllerWithCorr
redirectResult.ControllerName.ShouldBe("Campaign");
redirectResult.ActionName.ShouldBe("Details");

redirectResult.RouteValues["area"].ShouldBe("Admin");
redirectResult.RouteValues["area"].ShouldBe(AreaNames.Admin);
redirectResult.RouteValues["id"].ShouldBe(cmapaignId);
}

Expand Down Expand Up @@ -850,7 +851,7 @@ public void ControllerHasAreaAtttributeWithTheCorrectAreaName()
var sut = EventControllerWithNoInjectedDependencies();
var attribute = sut.GetAttributes().OfType<AreaAttribute>().SingleOrDefault();
Assert.NotNull(attribute);
Assert.Equal(attribute.RouteValue, "Admin");
Assert.Equal(attribute.RouteValue, AreaNames.Admin);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using AllReady.Areas.Admin.Features.Goals;
using AllReady.Areas.Admin.ViewModels.Campaign;
using AllReady.Areas.Admin.ViewModels.Goal;
using AllReady.Constants;
using AllReady.Models;
using MediatR;
using Microsoft.AspNetCore.Http;
Expand Down Expand Up @@ -147,7 +148,7 @@ public async void TestGoalCreatePostForSiteAdminWithValidModelStateReturnsRedire
Assert.NotNull(result);
Assert.Equal("Details", result.ActionName);
Assert.Equal("Campaign", result.ControllerName);
Assert.Equal("admin", result.RouteValues["area"]);
Assert.Equal(AreaNames.Admin, result.RouteValues["area"]);
Assert.Equal(campaignId, result.RouteValues["id"]);

mockMediator.Verify(mock => mock.SendAsync(It.IsAny<GoalEditCommand>()), Times.Once);
Expand Down Expand Up @@ -178,7 +179,7 @@ public async void GoalCreatePostForOrgAdminWithValidModelStateReturnsRedirectToA
Assert.NotNull(result);
Assert.Equal("Details", result.ActionName);
Assert.Equal("Campaign", result.ControllerName);
Assert.Equal("admin", result.RouteValues["area"]);
Assert.Equal(AreaNames.Admin, result.RouteValues["area"]);
Assert.Equal(campaignId, result.RouteValues["id"]);

mockMediator.Verify(mock => mock.SendAsync(It.IsAny<GoalEditCommand>()), Times.Once);
Expand Down Expand Up @@ -369,7 +370,7 @@ public async void TestGoalDeleteConfirmedOrgAdminRedirectToAction()
Assert.NotNull(result);
Assert.Equal("Details", result.ActionName);
Assert.Equal("Campaign", result.ControllerName);
Assert.Equal("admin", result.RouteValues["area"]);
Assert.Equal(AreaNames.Admin, result.RouteValues["area"]);
Assert.Equal(campaignId, result.RouteValues["id"]);
mockMediator.Verify(mock => mock.SendAsync(It.IsAny<GoalDeleteCommand>()), Times.Once);
}
Expand Down Expand Up @@ -402,7 +403,7 @@ public async void TestGoalDeleteConfirmedSiteAdminRedirectToAction()
Assert.NotNull(result);
Assert.Equal("Details", result.ActionName);
Assert.Equal("Campaign", result.ControllerName);
Assert.Equal("admin", result.RouteValues["area"]);
Assert.Equal(AreaNames.Admin, result.RouteValues["area"]);
Assert.Equal(campaignId, result.RouteValues["id"]);
mockMediator.Verify(mock => mock.SendAsync(It.IsAny<GoalDeleteCommand>()), Times.Once);
}
Expand Down Expand Up @@ -589,7 +590,7 @@ public async void GoalEditPostForOrgAdminWithValidModelStateReturnsRedirectToAct
Assert.NotNull(result);
Assert.Equal("Details", result.ActionName);
Assert.Equal("Campaign", result.ControllerName);
Assert.Equal("admin", result.RouteValues["area"]);
Assert.Equal(AreaNames.Admin, result.RouteValues["area"]);
Assert.Equal(campaignId, result.RouteValues["id"]);

mockMediator.Verify(mock => mock.SendAsync(It.IsAny<GoalEditCommand>()), Times.Once);
Expand Down Expand Up @@ -626,7 +627,7 @@ public async void TestGoalEditPostForSiteAdminWithValidModelStateReturnsRedirect
Assert.NotNull(result);
Assert.Equal("Details", result.ActionName);
Assert.Equal("Campaign", result.ControllerName);
Assert.Equal("admin", result.RouteValues["area"]);
Assert.Equal(AreaNames.Admin, result.RouteValues["area"]);
Assert.Equal(campaignId, result.RouteValues["id"]);

mockMediator.Verify(mock => mock.SendAsync(It.IsAny<GoalEditCommand>()), Times.Once);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using AllReady.Constants;
using Xunit;

namespace AllReady.UnitTest.Areas.Admin.Controllers
Expand All @@ -35,7 +36,7 @@ public void Controller_HasAreaAtttribute_WithTheCorrectAreaName()
var sut = new ItineraryController(null, null, null);
var attribute = sut.GetAttributes().OfType<AreaAttribute>().SingleOrDefault();
Assert.NotNull(attribute);
Assert.Equal(attribute.RouteValue, "Admin");
Assert.Equal(attribute.RouteValue, AreaNames.Admin);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using AllReady.Areas.Admin.Controllers;
using AllReady.Areas.Admin.Features.Organizations;
using AllReady.Areas.Admin.ViewModels.OrganizationApi;
using AllReady.Constants;
using AllReady.Models;
using AllReady.UnitTest.Extensions;
using MediatR;
Expand Down Expand Up @@ -81,7 +82,7 @@ public void ControllerHasAreaAtttributeWithTheCorrectAreaName()
var sut = new OrganizationApiController(null);
var attribute = sut.GetAttributes().OfType<AreaAttribute>().SingleOrDefault();
Assert.NotNull(attribute);
Assert.Equal(attribute.RouteValue, "Admin");
Assert.Equal(attribute.RouteValue, AreaNames.Admin);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using AllReady.Areas.Admin.ViewModels.Organization;
using AllReady.Areas.Admin.ViewModels.Shared;
using AllReady.Areas.Admin.ViewModels.Validators;
using AllReady.Constants;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
Expand Down Expand Up @@ -50,7 +51,7 @@ public OrganizationControllerTests()
[Fact]
public void TheControllerShouldHaveAnAreaAttributeOfAdmin()
{
ClassHasCorrectAttribute(typeof(AreaAttribute), "Admin");
ClassHasCorrectAttribute(typeof(AreaAttribute), AreaNames.Admin);
}

[Fact]
Expand Down Expand Up @@ -273,7 +274,7 @@ public async Task EditPostRedirectsToCorrectActionWithCorrectData_WhenModelState
var result = (RedirectToActionResult)await controller.Edit(model);

Assert.Equal("Details", result.ActionName);
Assert.Equal("Admin", result.RouteValues["area"]);
Assert.Equal(AreaNames.Admin, result.RouteValues["area"]);
Assert.Equal(Id, result.RouteValues["id"]);
}

Expand Down Expand Up @@ -371,7 +372,7 @@ public async Task DeleteConfirmedShouldSendAMessageWithTheCorrectIdUsingTheMedia
[Fact]
public async Task DeleteConfirmedShouldRedirectToTheCorrectActionAndArea()
{
var routeValueDictionary = new RouteValueDictionary { ["area"] = "Admin" };
var routeValueDictionary = new RouteValueDictionary { ["area"] = AreaNames.Admin };

var sut = new OrganizationController(Mock.Of<IMediator>(), null);
var result = await sut.DeleteConfirmed(It.IsAny<int>()) as RedirectToActionResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using AllReady.Constants;
using Xunit;

namespace AllReady.UnitTest.Areas.Admin.Controllers
Expand All @@ -26,7 +27,7 @@ public void ControllerHasAreaAtttribute_WithTheCorrectAreaName()
var sut = new RequestController(null);
var attribute = sut.GetAttributes().OfType<AreaAttribute>().SingleOrDefault();
Assert.NotNull(attribute);
Assert.Equal(attribute.RouteValue, "Admin");
Assert.Equal(attribute.RouteValue, AreaNames.Admin);
}

[Fact]
Expand Down Expand Up @@ -112,7 +113,7 @@ public async Task Create_ReturnsCorrectViewAndViewModel_WhenEventIsNotNullAndUse
var viewModel = new EventSummaryViewModel { Id = eventId, OrganizationId = orgId };

var mediator = new Mock<IMediator>();
mediator.Setup(mock => mock.SendAsync(It.IsAny<EventSummaryQuery>())).ReturnsAsync(viewModel);
mediator.Setup(mock => mock.SendAsync(It.IsAny<EventSummaryQuery>())).ReturnsAsync(viewModel);
mediator.Setup(x => x.SendAsync(It.IsAny<AuthorizableEventQuery>())).ReturnsAsync(new FakeAuthorizableEvent(false, false, false, true));

var sut = new RequestController(mediator.Object);
Expand Down Expand Up @@ -144,8 +145,8 @@ public void EditPost_HasRouteAttribute_WithCorrectTemplate()
Assert.NotNull(routeAttribute);
Assert.Equal(routeAttribute.Template, "Edit");
Assert.Equal(routeAttribute.Name, RequestController.EditRequestPostRouteName);
}

}

[Fact]
public async Task EditPost_ReturnsViewResult_WhenModelStateIsNotValid()
{
Expand Down Expand Up @@ -246,7 +247,7 @@ public async Task EditPost_AddsCorrectErrorToModelState_WhenPhoneNumberValidatio

[Fact]
public async Task EditPost_ReturnsCorrectViewAndViewModel_WhenPhoneNumberValidationFails()
{
{
const int eventId = 1;
const int orgId = 1;
var model = new EditRequestViewModel { EventId = eventId, Phone = "111-111-1111" };
Expand All @@ -273,7 +274,7 @@ public async Task EditPost_SendsEditRequestCommandWithCorrrectModel_WhenModelSta

var mediator = new Mock<IMediator>();
mediator.Setup(mock => mock.SendAsync(It.IsAny<EventSummaryQuery>())).ReturnsAsync(viewModel);
mediator.Setup(mock => mock.SendAsync(It.IsAny<ValidatePhoneNumberRequestCommand>())).ReturnsAsync(new ValidatePhoneNumberResult { IsValid = true });
mediator.Setup(mock => mock.SendAsync(It.IsAny<ValidatePhoneNumberRequestCommand>())).ReturnsAsync(new ValidatePhoneNumberResult { IsValid = true });
mediator.Setup(x => x.SendAsync(It.IsAny<AuthorizableEventQuery>())).ReturnsAsync(new FakeAuthorizableEvent(false, false, false, true));
mediator.Setup(x => x.SendAsync(It.IsAny<AuthorizableRequestQuery>())).ReturnsAsync(new FakeAuthorizableRequest(false, true, false, false));

Expand Down Expand Up @@ -328,8 +329,8 @@ public void EditGet_HasRouteAttribute_WithCorrectTemplate()
public async Task EditGet_SendsEditRequestQuery_WithCorrectArguments()
{
var eventId = Guid.NewGuid();
var mediator = new Mock<IMediator>();

var mediator = new Mock<IMediator>();

var sut = new RequestController(mediator.Object);
await sut.Edit(eventId);

Expand Down Expand Up @@ -365,9 +366,9 @@ public async Task EditGet_ReturnsForbidResult_WhenUserIsNotAuthorized()

[Fact]
public async Task EditGet_ReturnsViewResult_WhenRequestIsFoundAndUserIsAuthorized()
{
{
var mediator = new Mock<IMediator>();
mediator.Setup(x => x.SendAsync(It.IsAny<EditRequestQuery>())).ReturnsAsync(new EditRequestViewModel { Name = "test" });
mediator.Setup(x => x.SendAsync(It.IsAny<EditRequestQuery>())).ReturnsAsync(new EditRequestViewModel { Name = "test" });
mediator.Setup(x => x.SendAsync(It.IsAny<AuthorizableRequestQuery>())).ReturnsAsync(new FakeAuthorizableRequest(true, false, false, false));

var sut = new RequestController(mediator.Object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using AllReady.Areas.Admin.Features.Resource;
using AllReady.Areas.Admin.ViewModels.Campaign;
using AllReady.Areas.Admin.ViewModels.Resource;
using AllReady.Constants;
using AllReady.Models;
using AllReady.UnitTest.Extensions;
using MediatR;
Expand Down Expand Up @@ -175,7 +176,7 @@ public async Task CreatePostRedirectToActionWithTheCorrectCampaignId_AfterRsourc
result.ShouldBeOfType<RedirectToActionResult>();
result.ActionName.ShouldBe(nameof(CampaignController.Details));
result.ControllerName.ShouldBe(nameof(Campaign));
result.RouteValues["area"].ShouldBe("Admin");
result.RouteValues["area"].ShouldBe(AreaNames.Admin);
result.RouteValues["id"].ShouldBe(resourceEditViewModel.CampaignId);
}

Expand Down Expand Up @@ -412,7 +413,7 @@ public async Task DeleteConfirmdedRedirectToCorrectAction_AfterDeleteHasBeenDone
result.ShouldNotBeNull();
result.ActionName.ShouldBe(nameof(CampaignController.Details));
result.ControllerName.ShouldBe("Campaign");
result.RouteValues["area"].ShouldBe("Admin");
result.RouteValues["area"].ShouldBe(AreaNames.Admin);
result.RouteValues["id"].ShouldBe(deleteResourceQuery.CampaignId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Security.Claims;
using System.Threading.Tasks;
using AllReady.Areas.Admin.ViewModels.Site;
using AllReady.Constants;
using Xunit;

namespace AllReady.UnitTest.Areas.Admin.Controllers
Expand Down Expand Up @@ -1354,7 +1355,7 @@ public void ControllerHasAreaAtttributeWithTheCorrectAreaName()
var controller = new SiteController(null, null, null);
var attribute = controller.GetAttributes().OfType<AreaAttribute>().SingleOrDefault();
Assert.NotNull(attribute);
Assert.Equal(attribute.RouteValue, "Admin");
Assert.Equal(attribute.RouteValue, AreaNames.Admin);
}

[Fact]
Expand Down
Loading

0 comments on commit 8423411

Please sign in to comment.