public async Task CreateGetReturnsUnauthorized_WhenCampaignIsNull() { var mockMediator = new Mock <IMediator>(); var sut = new ResourceController(mockMediator.Object); var result = await sut.Create(It.IsAny <int>()) as UnauthorizedResult; result.ShouldNotBeNull(); result.ShouldBeOfType <UnauthorizedResult>(); result.StatusCode.ShouldBe((int)HttpStatusCode.Unauthorized); }
private void SelectFile(FileEntry file) { ResourceController = ResourceController.Create(file.FullName, (bool)ChkCleanXml.IsChecked); TeXml.Text = File.ReadAllText(file.FullName); BtnSave.IsEnabled = true; BtnTranslate.IsEnabled = true; if ((bool)ChkAutoTranslate.IsChecked) { ResourceController.Translate(CbTranslateDirection.Text); } IcResources.ItemsSource = null; IcResources.ItemsSource = ResourceController.Resources; BtnFileClose.IsEnabled = true; BtnReloadAutoCorrect.IsEnabled = true; }
public async Task CreateGetSendsCampaignSummaryViewModelQueryWithCorrectCampaignId() { var campaignSummaryViewModel = new CampaignSummaryViewModel { Id = 4, OrganizationId = 1, Name = "TestCampaign" }; var mockMediator = new Mock <IMediator>(); mockMediator.Setup(m => m.SendAsync(It.IsAny <CampaignSummaryQuery>())).ReturnsAsync(campaignSummaryViewModel); var sut = new ResourceController(mockMediator.Object); sut.MakeUserAnOrgAdmin(campaignSummaryViewModel.OrganizationId.ToString()); var result = await sut.Create(campaignSummaryViewModel.Id) as ViewResult; result.ShouldNotBeNull(); mockMediator.Verify(m => m.SendAsync(It.Is <CampaignSummaryQuery>(c => c.CampaignId == campaignSummaryViewModel.Id)), Times.Once); }
public async Task CreatePostSendsEditResourceCommandWithCorrectViewModel() { var campaignSummaryViewModel = new CampaignSummaryViewModel { Id = 4, OrganizationId = 1, Name = "TestCampaign" }; var mockMediator = new Mock <IMediator>(); mockMediator.Setup(m => m.SendAsync(It.IsAny <CampaignSummaryQuery>())).ReturnsAsync(campaignSummaryViewModel); var sut = new ResourceController(mockMediator.Object); sut.MakeUserAnOrgAdmin(campaignSummaryViewModel.OrganizationId.ToString()); var resourceEditViewModel = new ResourceEditViewModel(); var result = await sut.Create(resourceEditViewModel) as RedirectToActionResult; result.ShouldNotBeNull(); mockMediator.Verify(m => m.SendAsync(It.Is <CreateOrEditResourceCommand>(e => e.Resource == resourceEditViewModel)), Times.Once); }
public async Task CreateGetReturnsTheCorrectViewModel() { var campaignSummaryViewModel = new CampaignSummaryViewModel { Id = 4, OrganizationId = 1, Name = "TestCampaign" }; var mockMediator = new Mock <IMediator>(); mockMediator.Setup(m => m.SendAsync(It.IsAny <CampaignSummaryQuery>())).ReturnsAsync(campaignSummaryViewModel); var sut = new ResourceController(mockMediator.Object); sut.MakeUserAnOrgAdmin(campaignSummaryViewModel.OrganizationId.ToString()); var result = await sut.Create(campaignSummaryViewModel.Id) as ViewResult; result.Model.ShouldNotBeNull(); result.Model.ShouldBeOfType <ResourceEditViewModel>(); var model = result.Model as ResourceEditViewModel; model.CampaignId.ShouldBe(campaignSummaryViewModel.Id); }
public async Task CreateGetReturnsUnauthorized_WhenUserIsNotOrganizationAdmin() { var campaignSummaryViewModel = new CampaignSummaryViewModel { Id = 4, OrganizationId = 1, Name = "TestCampaign" }; var mockMediator = new Mock <IMediator>(); mockMediator.Setup(m => m.SendAsync(It.IsAny <CampaignSummaryQuery>())).ReturnsAsync(campaignSummaryViewModel); var sut = new ResourceController(mockMediator.Object); sut.MakeUserNotAnOrgAdmin(); var result = await sut.Create(It.IsAny <int>()) as UnauthorizedResult; result.ShouldNotBeNull(); result.ShouldBeOfType <UnauthorizedResult>(); result.StatusCode.ShouldBe((int)HttpStatusCode.Unauthorized); }
public async Task CreatePostReturnsView_IfModelStateIsNotValid() { var campaignSummaryViewModel = new CampaignSummaryViewModel { Id = 4, OrganizationId = 1, Name = "TestCampaign" }; var mockMediator = new Mock <IMediator>(); mockMediator.Setup(m => m.SendAsync(It.IsAny <CampaignSummaryQuery>())).ReturnsAsync(campaignSummaryViewModel); var sut = new ResourceController(mockMediator.Object); sut.MakeUserAnOrgAdmin(campaignSummaryViewModel.OrganizationId.ToString()); sut.ModelState.AddModelError("Name", "Filling name is mandatory!"); var result = await sut.Create(new ResourceEditViewModel()) as ViewResult; result.ShouldNotBeNull(); result.ViewName.ShouldBe("Edit"); result.Model.ShouldBeOfType <ResourceEditViewModel>(); }
public async Task CreatePostRedirectToActionWithTheCorrectCampaignId_AfterRsourceCreated() { var campaignSummaryViewModel = new CampaignSummaryViewModel { Id = 4, OrganizationId = 1, Name = "TestCampaign" }; var mockMediator = new Mock <IMediator>(); mockMediator.Setup(m => m.SendAsync(It.IsAny <CampaignSummaryQuery>())).ReturnsAsync(campaignSummaryViewModel); var sut = new ResourceController(mockMediator.Object); sut.MakeUserAnOrgAdmin(campaignSummaryViewModel.OrganizationId.ToString()); var resourceEditViewModel = new ResourceEditViewModel(); var result = await sut.Create(resourceEditViewModel) as RedirectToActionResult; result.ShouldNotBeNull(); result.ShouldBeOfType <RedirectToActionResult>(); result.ActionName.ShouldBe(nameof(CampaignController.Details)); result.ControllerName.ShouldBe(nameof(Campaign)); result.RouteValues["area"].ShouldBe(AreaNames.Admin); result.RouteValues["id"].ShouldBe(resourceEditViewModel.CampaignId); }
private EvaluationData CreateResource(string key, int?gameId = null, int?actorId = null, bool createNewGame = false, bool createNewUser = false) { if (createNewGame) { var game = new Game { Name = key }; _gameController.Create(game); gameId = game.Id; } if (createNewUser) { var user = new User { Name = key }; _userController.Create(user); actorId = user.Id; } var resource = new EvaluationData { GameId = gameId ?? Platform.GlobalGameId, ActorId = actorId ?? Platform.GlobalActorId, Key = key, Value = "100", EvaluationDataType = EvaluationDataType.Long, Category = EvaluationDataCategory.Resource, }; _resourceController.Create(resource); return(resource); }
public void Persist <T>(_Entity entity) { if (typeof(T) == typeof(User)) { UserController.Create((User)entity); } else if (typeof(T) == typeof(AppLocale)) { AppLocaleController.Create((AppLocale)entity); } else if (typeof(T) == typeof(AppText)) { AppTextController.Create((AppText)entity); } else if (typeof(T) == typeof(Bank)) { BankController.Create((Bank)entity); } else if (typeof(T) == typeof(Battle)) { BattleController.Create((Battle)entity); } else if (typeof(T) == typeof(City)) { CityController.Create((City)entity); } else if (typeof(T) == typeof(Harbor)) { HarborController.Create((Harbor)entity); } else if (typeof(T) == typeof(Inventory)) { InventoryController.Create((Inventory)entity); } else if (typeof(T) == typeof(Item)) { ItemController.Create((Item)entity); } else if (typeof(T) == typeof(Market)) { MarketController.Create((Market)entity); } else if (typeof(T) == typeof(Powerup)) { PowerupController.Create((Powerup)entity); } else if (typeof(T) == typeof(ProfileAI)) { ProfileAiController.Create((ProfileAI)entity); } else if (typeof(T) == typeof(Quest)) { QuestController.Create((Quest)entity); } else if (typeof(T) == typeof(Resource)) { ResourceController.Create((Resource)entity); } else if (typeof(T) == typeof(Reward)) { RewardController.Create((Reward)entity); } else if (typeof(T) == typeof(Scenario)) { ScenarioController.Create((Scenario)entity); } else if (typeof(T) == typeof(UserGame)) { UserGameController.Create((UserGame)entity); } else if (typeof(T) == typeof(Vessel)) { VesselController.Create((Vessel)entity); } else if (typeof(T) == typeof(Weapon)) { WeaponController.Create((Weapon)entity); } else { throw new Exception("Controller not implemented yet."); } }