public void LoadItems_BuildingsHaveSpecialFaction_ShouldNotLoadBuildings(string factionToSet) { // Arrange var viewModel = new PresetsTreeViewModel(_mockedTreeLocalization); var buildings = new List <BuildingInfo> { new BuildingInfo { Header = "(A4) Anno 1404", Faction = factionToSet } }; var buildingPresets = new BuildingPresets(); buildingPresets.Buildings = buildings; // Act viewModel.LoadItems(buildingPresets); // Assert //there are always 2 road items Assert.Equal(2, viewModel.Items.Count); }
public void FilterGameVersion_SubsetIsLoadedAndFilterTextIsEmpty_ShouldFilterByGameVersion(CoreConstants.GameVersion gameVersionsToFilter, int expectedMainNodeCount) { // Arrange var viewModel = new PresetsTreeViewModel(_mockedTreeLocalization); viewModel.LoadItems(_subsetFromPresetsFile); viewModel.FilterText = string.Empty; //make sure to really trigger the filter method if (viewModel.FilterGameVersion != CoreConstants.GameVersion.Unknown) { viewModel.FilterGameVersion = CoreConstants.GameVersion.Unknown; } else { viewModel.FilterGameVersion = CoreConstants.GameVersion.All; } // Act viewModel.FilterGameVersion = gameVersionsToFilter; // Assert //+ 2 road buildings Assert.Equal(2 + expectedMainNodeCount, viewModel.Items.Where(x => x.IsVisible).Count()); }
public void SetCondensedTreeState_SavedTreeStateIsCompatible_ShouldSetTreeState() { // Arrange var buildingPresetsVersion = "1.0"; var buildingPresets = new BuildingPresets(); buildingPresets.Buildings = new List <BuildingInfo>(); buildingPresets.Version = buildingPresetsVersion; var viewModel = new PresetsTreeViewModel(_mockedTreeLocalization); viewModel.LoadItems(buildingPresets); var(items, expectedState) = GetTreeAndState(expandLastMainNode: false); viewModel.Items.Clear(); foreach (var curItem in items) { viewModel.Items.Add(curItem); } var savedTreeState = new Dictionary <int, bool> { { 4, true }, { 5, false } }; // Act viewModel.SetCondensedTreeState(savedTreeState, buildingPresetsVersion); // Assert var currentState = viewModel.GetCondensedTreeState(); Assert.Equal(savedTreeState, currentState); }
public void LoadItems_BuildingsHaveFaction_ShouldLoadBuildings() { // Arrange var viewModel = new PresetsTreeViewModel(_mockedTreeLocalization); var buildings = new List <BuildingInfo> { new BuildingInfo { Header = "(A4) Anno 1404", Faction = "Workers", Identifier = "A4_house"//required for GetOrderParameter } }; var buildingPresets = new BuildingPresets(); buildingPresets.Buildings = buildings; // Act viewModel.LoadItems(buildingPresets); // Assert //first 2 items always the road items Assert.Single((viewModel.Items[2] as GameHeaderTreeItem).Children); Assert.Equal(buildings[0].Faction, (viewModel.Items[2] as GameHeaderTreeItem).Children[0].Header); }
public void LoadItems_BuildingPresetsIsNull_ShouldThrow() { // Arrange var viewModel = new PresetsTreeViewModel(_mockedTreeLocalization); // Act/Assert Assert.Throws <ArgumentNullException>(() => viewModel.LoadItems(null)); }
public void GetCondensedTreeState_ItemsAreEmpty_ShouldReturnEmptyList() { // Arrange var viewModel = new PresetsTreeViewModel(_mockedTreeLocalization); // Act var result = viewModel.GetCondensedTreeState(); // Assert Assert.Empty(result); }
public void ReturnKeyPressed_CommandParameterIsNull_ShouldNotSetSelectedItem() { // Arrange var viewModel = new PresetsTreeViewModel(_mockedTreeLocalization); // Act viewModel.ReturnKeyPressedCommand.Execute(null); // Assert Assert.Null(viewModel.SelectedItem); }
public void DoubleClick_CommandParameterIsNull_ShouldNotSetSelectedItem() { // Arrange var viewModel = new PresetsTreeViewModel(_mockedTreeLocalization, _mockedCommons); // Act viewModel.DoubleClickCommand.Execute(null); // Assert Assert.Null(viewModel.SelectedItem); }
public void LoadItems_VersionOfBuildingPresetsIsSet_ShouldRaisePropertyChangedEvent() { // Arrange var viewModel = new PresetsTreeViewModel(_mockedTreeLocalization); var buildingPresets = new BuildingPresets(); buildingPresets.Buildings = new List <BuildingInfo>(); // Act/Assert Assert.PropertyChanged(viewModel, nameof(viewModel.BuildingPresetsVersion), () => viewModel.LoadItems(buildingPresets)); }
public void LoadItems_Subset_ShouldLoadBuildings() { // Arrange var viewModel = new PresetsTreeViewModel(_mockedTreeLocalization); // Act viewModel.LoadItems(_subsetFromPresetsFile); // Assert //2 road buildings + 4 game versions Assert.Equal(6, viewModel.Items.Count); }
public void DoubleClick_CommandParameterIsUnknownObject_ShouldNotSetSelectedItem() { // Arrange var viewModel = new PresetsTreeViewModel(_mockedTreeLocalization); var commandParameter = new Object(); // Act viewModel.DoubleClickCommand.Execute(commandParameter); // Assert Assert.Null(viewModel.SelectedItem); }
public void ReturnKeyPressed_CommandParameterHasNoAnnoObject_ShouldNotSetSelectedItem() { // Arrange var viewModel = new PresetsTreeViewModel(_mockedTreeLocalization); var commandParameter = new GenericTreeItem(null); // Act viewModel.ReturnKeyPressedCommand.Execute(commandParameter); // Assert Assert.Null(viewModel.SelectedItem); }
public void Ctor_ShouldSetDefaultValues() { // Arrange/Act var viewModel = new PresetsTreeViewModel(_mockedTreeLocalization); // Assert Assert.NotNull(viewModel.Items); Assert.NotNull(viewModel.FilteredItems); Assert.NotNull(viewModel.DoubleClickCommand); Assert.NotNull(viewModel.ReturnKeyPressedCommand); Assert.Equal(string.Empty, viewModel.BuildingPresetsVersion); Assert.Equal(CoreConstants.GameVersion.All, viewModel.FilterGameVersion); Assert.Equal(string.Empty, viewModel.FilterText); }
public void FilterText_SearchForPoliceAndFilterGameVersionIs2070_ShouldOnlyShowPoliceStationAndExpandParentsForAnno2070() { // Arrange var filterText = "Police"; var viewModel = new PresetsTreeViewModel(_mockedTreeLocalization); viewModel.LoadItems(_subsetForFiltering); viewModel.FilterText = string.Empty; viewModel.FilterGameVersion = CoreConstants.GameVersion.Anno2070; // Act viewModel.FilterText = filterText; // Assert Assert.False(viewModel.Items[0].IsVisible); //first road tile Assert.False(viewModel.Items[1].IsVisible); //second road tile var anno1404Node = viewModel.Items[2]; Assert.Equal("(A4) Anno 1404", anno1404Node.Header); Assert.False(anno1404Node.IsVisible); var anno2070Node = viewModel.Items[3]; Assert.Equal("(A5) Anno 2070", anno2070Node.Header); Assert.True(anno2070Node.IsVisible); Assert.True(anno2070Node.IsExpanded); var othersNode = anno2070Node.Children.Single(x => x.Header.StartsWith("Others")); Assert.True(othersNode.IsVisible); Assert.True(othersNode.IsExpanded); var specialNode = othersNode.Children.Single(x => x.Header.StartsWith("Special")); Assert.True(specialNode.IsVisible); Assert.True(specialNode.IsExpanded); var policeStationNode = specialNode.Children.First(x => x.Header.StartsWith("Police")); Assert.True(policeStationNode.IsVisible); //all other nodes should not be visible var anno2205Node = viewModel.Items[4]; Assert.Equal("(A6) Anno 2205", anno2205Node.Header); Assert.False(anno2205Node.IsVisible); var anno1800Node = viewModel.Items[5]; Assert.Equal("(A7) Anno 1800", anno1800Node.Header); Assert.False(anno1800Node.IsVisible); }
public void SetCondensedTreeState_LastPresetsVersionIsNullOrWhiteSpace_ShouldNotSetAnyStateAndNotThrow(string lastBuildingPresetsVersionToSet) { // Arrange var viewModel = new PresetsTreeViewModel(_mockedTreeLocalization); var(items, expectedState) = GetTreeAndState(); viewModel.Items = new ObservableCollection <GenericTreeItem>(items); // Act viewModel.SetCondensedTreeState(new Dictionary <int, bool>(), lastBuildingPresetsVersionToSet); // Assert Assert.Equal(expectedState, viewModel.GetCondensedTreeState()); }
public void GetCondensedTreeState_ItemsExpanded_ShouldReturnCorrectList() { // Arrange var viewModel = new PresetsTreeViewModel(_mockedTreeLocalization); var(items, expectedState) = GetTreeAndState(); viewModel.Items = new ObservableCollection <GenericTreeItem>(items); // Act var result = viewModel.GetCondensedTreeState(); // Assert Assert.Equal(expectedState, result); }
public void ReturnKeyPressed_CommandParameterHasAnnoObject_ShouldSetSelectedItem() { // Arrange var viewModel = new PresetsTreeViewModel(_mockedTreeLocalization); var annoObjectToSet = new AnnoObject(); var commandParameter = new GenericTreeItem(null); commandParameter.AnnoObject = annoObjectToSet; // Act viewModel.ReturnKeyPressedCommand.Execute(commandParameter); // Assert Assert.Equal(commandParameter, viewModel.SelectedItem); }
public void LoadItems_BuildingPresetsPassed_ShouldSetVersionOfBuildingPresets(string versionToSet) { // Arrange var viewModel = new PresetsTreeViewModel(_mockedTreeLocalization); var buildingPresets = new BuildingPresets(); buildingPresets.Buildings = new List <BuildingInfo>(); buildingPresets.Version = versionToSet; // Act viewModel.LoadItems(buildingPresets); // Assert Assert.Equal(versionToSet, viewModel.BuildingPresetsVersion); }
public void ReturnKeyPressed_CommandParameterHasAnnoObject_ShouldRaiseApplySelectedItemEvent() { // Arrange var viewModel = new PresetsTreeViewModel(_mockedTreeLocalization); var annoObjectToSet = new AnnoObject(); var commandParameter = new GenericTreeItem(null); commandParameter.AnnoObject = annoObjectToSet; // Act/Assert Assert.Raises <EventArgs>( x => viewModel.ApplySelectedItem += x, x => viewModel.ApplySelectedItem -= x, () => viewModel.ReturnKeyPressedCommand.Execute(commandParameter)); }
public void ReturnKeyPressed_CommandParameterIsNull_ShouldNotRaiseApplySelectedItemEvent() { // Arrange var viewModel = new PresetsTreeViewModel(_mockedTreeLocalization); // Act var ex = Record.Exception(() => Assert.Raises <EventArgs>( x => viewModel.ApplySelectedItem += x, x => viewModel.ApplySelectedItem -= x, () => viewModel.ReturnKeyPressedCommand.Execute(null))); // Assert var exception = Assert.IsType <RaisesException>(ex); Assert.Equal("(No event was raised)", exception.Actual); Assert.Equal("EventArgs", exception.Expected); }
public void LoadItems_BuildingPresetsContainsNoBuildings_ShouldLoadTwoRoadItems() { // Arrange var viewModel = new PresetsTreeViewModel(_mockedTreeLocalization); var buildingPresets = new BuildingPresets(); buildingPresets.Buildings = new List <BuildingInfo>(); // Act viewModel.LoadItems(buildingPresets); // Assert Assert.Equal(2, viewModel.Items.Count); Assert.True(viewModel.Items[0].AnnoObject.Road); Assert.True(viewModel.Items[1].AnnoObject.Road); }
public void DoubleClick_CommandParameterIsUnknownObject_ShouldNotRaiseApplySelectedItemEvent() { // Arrange var viewModel = new PresetsTreeViewModel(_mockedTreeLocalization); var commandParameter = new Object(); // Act var ex = Record.Exception(() => Assert.Raises <EventArgs>( x => viewModel.ApplySelectedItem += x, x => viewModel.ApplySelectedItem -= x, () => viewModel.DoubleClickCommand.Execute(commandParameter))); // Assert var exception = Assert.IsType <RaisesException>(ex); Assert.Equal("(No event was raised)", exception.Actual); Assert.Equal("EventArgs", exception.Expected); }
public void LoadItems_ViewModelHasItems_ShouldClearItemsBeforeLoad() { // Arrange var viewModel = new PresetsTreeViewModel(_mockedTreeLocalization); var itemsToAdd = Enumerable.Repeat(new GenericTreeItem(null), 10); foreach (var curItem in itemsToAdd) { viewModel.Items.Add(curItem); } var buildingPresets = new BuildingPresets(); buildingPresets.Buildings = new List <BuildingInfo>(); // Act viewModel.LoadItems(buildingPresets); // Assert Assert.Equal(2, viewModel.Items.Count); }
public void SetCondensedTreeState_LastPresetsVersionIsDifferent_ShouldNotSetAnyStateAndNotThrow() { // Arrange var buildingPresetsVersion = "1.0"; var buildingPresets = new BuildingPresets(); buildingPresets.Buildings = new List <BuildingInfo>(); buildingPresets.Version = buildingPresetsVersion; var viewModel = new PresetsTreeViewModel(_mockedTreeLocalization, _mockedCommons); viewModel.LoadItems(buildingPresets); var(items, expectedState) = GetTreeAndState(); viewModel.Items = new ObservableCollection <GenericTreeItem>(items); // Act viewModel.SetCondensedTreeState(new Dictionary <int, bool>(), "2.0"); // Assert Assert.Equal(expectedState, viewModel.GetCondensedTreeState()); }
public void SetCondensedTreeState_SavedTreeStateIsNull_ShouldNotSetAnyStateAndNotThrow() { // Arrange var buildingPresetsVersion = "1.0"; var buildingPresets = new BuildingPresets(); buildingPresets.Buildings = new List <BuildingInfo>(); buildingPresets.Version = buildingPresetsVersion; var viewModel = new PresetsTreeViewModel(_mockedTreeLocalization); viewModel.LoadItems(buildingPresets); var(items, expectedState) = GetTreeAndState(); viewModel.Items = new ObservableCollection <GenericTreeItem>(items); // Act viewModel.SetCondensedTreeState(null, buildingPresetsVersion); // Assert Assert.Equal(expectedState, viewModel.GetCondensedTreeState()); }
public void LoadItems_BuildingsHaveHeader_ShouldSetCorrectGameVersion(string headerToSet, CoreConstants.GameVersion expectedGameVersion) { // Arrange var viewModel = new PresetsTreeViewModel(_mockedTreeLocalization); var buildings = new List <BuildingInfo> { new BuildingInfo { Header = headerToSet } }; var buildingPresets = new BuildingPresets(); buildingPresets.Buildings = buildings; // Act viewModel.LoadItems(buildingPresets); // Assert //first 2 items always the road items Assert.Equal(expectedGameVersion, (viewModel.Items[2] as GameHeaderTreeItem).GameVersion); }
public void FilterText_SearchForPoliceAndFilterGameVersionIsAll_ShouldOnlyShowPoliceStationAndExpandParents() { // Arrange var filterText = "Police"; var viewModel = new PresetsTreeViewModel(_mockedTreeLocalization, _mockedCommons); viewModel.LoadItems(_subsetForFiltering); viewModel.FilterText = string.Empty; viewModel.FilterGameVersion = CoreConstants.GameVersion.All; // Act viewModel.FilterText = filterText; // Assert Assert.False(viewModel.Items[0].IsVisible); //first road tile Assert.False(viewModel.Items[1].IsVisible); //second road tile var anno1404Node = viewModel.Items[2]; Assert.Equal("(A4) Anno 1404", anno1404Node.Header); Assert.False(anno1404Node.IsVisible); var anno2070Node = viewModel.Items[3]; Assert.Equal("(A5) Anno 2070", anno2070Node.Header); Assert.True(anno2070Node.IsVisible); Assert.True(anno2070Node.IsExpanded); var othersNode = anno2070Node.Children.Single(x => x.Header.StartsWith("Others")); Assert.True(othersNode.IsVisible); Assert.True(othersNode.IsExpanded); var specialNode = othersNode.Children.Single(x => x.Header.StartsWith("Special")); Assert.True(specialNode.IsVisible); Assert.True(specialNode.IsExpanded); var policeStationNode = specialNode.Children.First(x => x.Header.StartsWith("Police")); Assert.True(policeStationNode.IsVisible); var anno2205Node = viewModel.Items[4]; Assert.Equal("(A6) Anno 2205", anno2205Node.Header); Assert.True(anno2205Node.IsVisible); Assert.True(anno2205Node.IsExpanded); Assert.False(anno2205Node.Children.Single(x => x.Header.StartsWith("Facilities")).IsVisible); var earthNode = anno2205Node.Children.Single(x => x.Header.StartsWith("(1) Earth")); Assert.True(earthNode.IsVisible); Assert.True(earthNode.IsExpanded); var publicNode = earthNode.Children.Single(x => x.Header.StartsWith("Public")); Assert.True(publicNode.IsVisible); Assert.True(publicNode.IsExpanded); policeStationNode = publicNode.Children.First(x => x.Header.StartsWith("Police")); Assert.True(policeStationNode.IsVisible); var anno1800Node = viewModel.Items[5]; Assert.Equal("(A7) Anno 1800", anno1800Node.Header); Assert.True(anno1800Node.IsVisible); Assert.True(anno1800Node.IsExpanded); var workersNode = anno1800Node.Children.Single(x => x.Header.StartsWith("(2) Workers")); Assert.True(workersNode.IsVisible); Assert.True(workersNode.IsExpanded); Assert.False(workersNode.Children.Single(x => x.Header.StartsWith("Production")).IsVisible); publicNode = workersNode.Children.Single(x => x.Header.StartsWith("Public")); Assert.True(publicNode.IsVisible); Assert.True(publicNode.IsExpanded); policeStationNode = publicNode.Children.First(x => x.Header.StartsWith("Police")); Assert.True(policeStationNode.IsVisible); }
public void LoadItems_SubsetForFiltering_ShouldLoadAllItemsAndAddExtraNodeForModulesIn2205() { // Arrange var viewModel = new PresetsTreeViewModel(_mockedTreeLocalization); // Act viewModel.LoadItems(_subsetForFiltering); // Assert Assert.True(viewModel.Items[0].IsVisible); //first road tile Assert.True(viewModel.Items[1].IsVisible); //second road tile var anno1404Node = viewModel.Items[2]; Assert.Equal("(A4) Anno 1404", anno1404Node.Header); Assert.True(anno1404Node.IsVisible); var productionNode = anno1404Node.Children.Single(x => x.Header.StartsWith("Production")); Assert.True(productionNode.IsVisible); var factoryNode = productionNode.Children.Single(x => x.Header.StartsWith("Factory")); Assert.True(factoryNode.IsVisible); var bakeryNode = factoryNode.Children.Single(x => x.Header.StartsWith("Bakery")); Assert.True(bakeryNode.IsVisible); var publicNode = anno1404Node.Children.Single(x => x.Header.StartsWith("Public")); Assert.True(publicNode.IsVisible); var specialNode = publicNode.Children.Single(x => x.Header.StartsWith("Special")); Assert.True(specialNode.IsVisible); var fireStationNode = specialNode.Children.First(x => x.Header.StartsWith("Fire")); Assert.True(fireStationNode.IsVisible); var anno2070Node = viewModel.Items[3]; Assert.Equal("(A5) Anno 2070", anno2070Node.Header); Assert.True(anno2070Node.IsVisible); var othersNode = anno2070Node.Children.Single(x => x.Header.StartsWith("Others")); Assert.True(othersNode.IsVisible); specialNode = othersNode.Children.Single(x => x.Header.StartsWith("Special")); Assert.True(specialNode.IsVisible); var policeStationNode = specialNode.Children.First(x => x.Header.StartsWith("Police")); Assert.True(policeStationNode.IsVisible); var anno2205Node = viewModel.Items[4]; Assert.Equal("(A6) Anno 2205", anno2205Node.Header); Assert.True(anno2205Node.IsVisible); var facilityNode = anno2205Node.Children.Single(x => x.Header.StartsWith("Facilities")); Assert.True(facilityNode.IsVisible); var agricutureNode = facilityNode.Children.Single(x => x.Header.StartsWith("Agriculture")); Assert.True(agricutureNode.IsVisible); var riceFarmNode = agricutureNode.Children.Single(x => x.Header.StartsWith("Rice Farm")); Assert.True(riceFarmNode.IsVisible); var moduleNode = agricutureNode.Children.Single(x => x.Header.StartsWith("Agriculture Modules")); Assert.True(moduleNode.IsVisible); var riceFieldNode = moduleNode.Children.Single(x => x.Header.StartsWith("Rice Field")); Assert.True(riceFieldNode.IsVisible); var earthNode = anno2205Node.Children.Single(x => x.Header.StartsWith("(1) Earth")); Assert.True(earthNode.IsVisible); publicNode = earthNode.Children.Single(x => x.Header.StartsWith("Public")); Assert.True(publicNode.IsVisible); policeStationNode = publicNode.Children.First(x => x.Header.StartsWith("Police")); Assert.True(policeStationNode.IsVisible); var anno1800Node = viewModel.Items[5]; Assert.Equal("(A7) Anno 1800", anno1800Node.Header); Assert.True(anno1800Node.IsVisible); var workersNode = anno1800Node.Children.Single(x => x.Header.StartsWith("(2) Workers")); Assert.True(workersNode.IsVisible); productionNode = workersNode.Children.Single(x => x.Header.StartsWith("Production")); Assert.True(productionNode.IsVisible); bakeryNode = productionNode.Children.Single(x => x.Header.StartsWith("Bakery")); Assert.True(bakeryNode.IsVisible); publicNode = workersNode.Children.Single(x => x.Header.StartsWith("Public")); Assert.True(publicNode.IsVisible); policeStationNode = publicNode.Children.First(x => x.Header.StartsWith("Police")); Assert.True(policeStationNode.IsVisible); }