LootExplosionStudio WIP commit
This commit is contained in:
parent
2278cbdc3a
commit
543446b23e
|
@ -186,4 +186,5 @@ FakesAssemblies/
|
|||
# LightSwitch generated files
|
||||
GeneratedArtifacts/
|
||||
_Pvt_Extensions/
|
||||
ModelManifest.xml
|
||||
ModelManifest.xml
|
||||
/Releases
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{56D0887E-B10D-4F9C-A88E-09CF8E8E06E3}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Filtration.LootExplosionStudio.Tests</RootNamespace>
|
||||
<AssemblyName>Filtration.LootExplosionStudio.Tests</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Moq">
|
||||
<HintPath>..\packages\Moq.4.2.1507.0118\lib\net40\Moq.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework">
|
||||
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Services\TestItemFilterBlockFinderService.cs" />
|
||||
<Compile Include="Services\TestLootItemAppearanceService.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Filtration.LootExplosionStudio\Filtration.LootExplosionStudio.csproj">
|
||||
<Project>{c8009b11-14d0-4421-94f0-9ef4603cb363}</Project>
|
||||
<Name>Filtration.LootExplosionStudio</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Filtration.ObjectModel\Filtration.ObjectModel.csproj">
|
||||
<Project>{4aac3beb-1dc1-483e-9d11-0e9334e80227}</Project>
|
||||
<Name>Filtration.ObjectModel</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
|
@ -0,0 +1,178 @@
|
|||
using Filtration.LootExplosionStudio.Services;
|
||||
using Filtration.ObjectModel;
|
||||
using Filtration.ObjectModel.BlockItemTypes;
|
||||
using Filtration.ObjectModel.Enums;
|
||||
using Filtration.ObjectModel.LootExplosionStudio;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Filtration.LootExplosionStudio.Tests.Services
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestItemFilterBlockFinderService
|
||||
{
|
||||
private ItemFilterBlockFinderServiceTestUtility _testUtility;
|
||||
|
||||
[SetUp]
|
||||
public void ItemFilterProcessingServiceTestSetup()
|
||||
{
|
||||
_testUtility = new ItemFilterBlockFinderServiceTestUtility();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FindBlockForLootItem_SingleBlock_BaseType_Matches()
|
||||
{
|
||||
// Arrange
|
||||
var testInputBaseType = "TestBaseType";
|
||||
var testInputBlockItem = new BaseTypeBlockItem();
|
||||
testInputBlockItem.Items.Add(testInputBaseType);
|
||||
|
||||
_testUtility.TestLootItem.BaseType = testInputBaseType;
|
||||
_testUtility.TestBlock.BlockItems.Add(testInputBlockItem);
|
||||
|
||||
|
||||
// Act
|
||||
var result = _testUtility.Service.FindBlockForLootItem(_testUtility.TestLootItem, _testUtility.TestScript);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(_testUtility.TestBlock, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FindBlockForLootItem_SingleHideBlock_Matches()
|
||||
{
|
||||
// Arrange
|
||||
|
||||
_testUtility.TestBlock.Action = BlockAction.Hide;
|
||||
|
||||
// Act
|
||||
var result = _testUtility.Service.FindBlockForLootItem(_testUtility.TestLootItem, _testUtility.TestScript);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(_testUtility.TestBlock, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FindBlockForLootItem_SingleBlock_MultipleBlockItems_Matches()
|
||||
{
|
||||
// Arrange
|
||||
var testInputBaseType = "TestBaseType";
|
||||
var testInputBaseTypeBlockItem = new BaseTypeBlockItem();
|
||||
testInputBaseTypeBlockItem.Items.Add(testInputBaseType);
|
||||
|
||||
var testInputClass = "Test Class";
|
||||
var testInputClassBlockItem = new ClassBlockItem();
|
||||
testInputClassBlockItem.Items.Add(testInputClass);
|
||||
|
||||
var testInputItemLevel = 57;
|
||||
var testInputItemLevelBlockItem = new ItemLevelBlockItem(FilterPredicateOperator.GreaterThan, 50);
|
||||
|
||||
_testUtility.TestLootItem.BaseType = testInputBaseType;
|
||||
_testUtility.TestLootItem.Class = testInputClass;
|
||||
_testUtility.TestLootItem.ItemLevel = testInputItemLevel;
|
||||
|
||||
_testUtility.TestBlock.BlockItems.Add(testInputBaseTypeBlockItem);
|
||||
_testUtility.TestBlock.BlockItems.Add(testInputClassBlockItem);
|
||||
_testUtility.TestBlock.BlockItems.Add(testInputItemLevelBlockItem);
|
||||
|
||||
|
||||
// Act
|
||||
var result = _testUtility.Service.FindBlockForLootItem(_testUtility.TestLootItem, _testUtility.TestScript);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(_testUtility.TestBlock, result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public void FindBlockForLootItem_SingleBlock_MultipleBlockItemsOneWithoutMatch_Matches()
|
||||
{
|
||||
// Arrange
|
||||
var testInputBaseType = "TestBaseType";
|
||||
var testInputBaseTypeBlockItem = new BaseTypeBlockItem();
|
||||
testInputBaseTypeBlockItem.Items.Add(testInputBaseType);
|
||||
|
||||
var testInputClass = "Test Class";
|
||||
var testInputClassBlockItem = new ClassBlockItem();
|
||||
testInputClassBlockItem.Items.Add(testInputClass);
|
||||
|
||||
var testInputItemLevel = 57;
|
||||
var testInputItemLevelBlockItem = new ItemLevelBlockItem(FilterPredicateOperator.GreaterThan, 50);
|
||||
|
||||
var testInputDropLevel = 35;
|
||||
var testInputDropLevelBlockItem = new DropLevelBlockItem(FilterPredicateOperator.GreaterThanOrEqual, 89);
|
||||
|
||||
_testUtility.TestLootItem.BaseType = testInputBaseType;
|
||||
_testUtility.TestLootItem.Class = testInputClass;
|
||||
_testUtility.TestLootItem.ItemLevel = testInputItemLevel;
|
||||
_testUtility.TestLootItem.DropLevel = testInputDropLevel;
|
||||
|
||||
_testUtility.TestBlock.BlockItems.Add(testInputBaseTypeBlockItem);
|
||||
_testUtility.TestBlock.BlockItems.Add(testInputClassBlockItem);
|
||||
_testUtility.TestBlock.BlockItems.Add(testInputItemLevelBlockItem);
|
||||
_testUtility.TestBlock.BlockItems.Add(testInputDropLevelBlockItem);
|
||||
|
||||
// Act
|
||||
var result = _testUtility.Service.FindBlockForLootItem(_testUtility.TestLootItem, _testUtility.TestScript);
|
||||
|
||||
// Assert
|
||||
Assert.IsNull(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FindBlockForLootItem_MultipleBlocksBlock_Matches()
|
||||
{
|
||||
// Arrange
|
||||
var testInputBlock1 = new ItemFilterBlock();
|
||||
var testInputClass1 = "Test Class";
|
||||
var testInputClassBlockItem1 = new ClassBlockItem();
|
||||
testInputClassBlockItem1.Items.Add(testInputClass1);
|
||||
testInputBlock1.BlockItems.Add(testInputClassBlockItem1);
|
||||
|
||||
_testUtility.TestScript.ItemFilterBlocks.Add(testInputBlock1);
|
||||
|
||||
var testInputBaseType = "TestBaseType";
|
||||
var testInputBaseTypeBlockItem = new BaseTypeBlockItem();
|
||||
testInputBaseTypeBlockItem.Items.Add(testInputBaseType);
|
||||
|
||||
var testInputClass = "Test Class";
|
||||
var testInputClassBlockItem = new ClassBlockItem();
|
||||
testInputClassBlockItem.Items.Add(testInputClass);
|
||||
|
||||
var testInputItemLevel = 57;
|
||||
var testInputItemLevelBlockItem = new ItemLevelBlockItem(FilterPredicateOperator.GreaterThan, 50);
|
||||
|
||||
_testUtility.TestLootItem.BaseType = testInputBaseType;
|
||||
_testUtility.TestLootItem.Class = testInputClass;
|
||||
_testUtility.TestLootItem.ItemLevel = testInputItemLevel;
|
||||
|
||||
_testUtility.TestBlock.BlockItems.Add(testInputBaseTypeBlockItem);
|
||||
_testUtility.TestBlock.BlockItems.Add(testInputClassBlockItem);
|
||||
_testUtility.TestBlock.BlockItems.Add(testInputItemLevelBlockItem);
|
||||
|
||||
// Act
|
||||
var result = _testUtility.Service.FindBlockForLootItem(_testUtility.TestLootItem, _testUtility.TestScript);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(_testUtility.TestBlock, result);
|
||||
}
|
||||
|
||||
private class ItemFilterBlockFinderServiceTestUtility
|
||||
{
|
||||
public ItemFilterBlockFinderServiceTestUtility()
|
||||
{
|
||||
TestBlock = new ItemFilterBlock();
|
||||
TestScript = new ItemFilterScript();
|
||||
TestScript.ItemFilterBlocks.Add(TestBlock);
|
||||
TestLootItem = new LootItem();
|
||||
|
||||
Service = new ItemFilterBlockFinderService();
|
||||
}
|
||||
|
||||
public ItemFilterScript TestScript { get; private set; }
|
||||
public ItemFilterBlock TestBlock { get; private set; }
|
||||
public LootItem TestLootItem { get; private set; }
|
||||
public ItemFilterBlockFinderService Service { get; private set; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,275 @@
|
|||
using System.Windows.Media;
|
||||
using Filtration.LootExplosionStudio.Services;
|
||||
using Filtration.ObjectModel;
|
||||
using Filtration.ObjectModel.BlockItemTypes;
|
||||
using Filtration.ObjectModel.Enums;
|
||||
using Filtration.ObjectModel.LootExplosionStudio;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Filtration.LootExplosionStudio.Tests.Services
|
||||
{
|
||||
[TestFixture]
|
||||
class TestLootItemAppearanceService
|
||||
{
|
||||
private LootItemAppearanceServiceTestUtility _testUtility;
|
||||
|
||||
[SetUp]
|
||||
public void ItemFilterProcessingServiceTestSetup()
|
||||
{
|
||||
_testUtility = new LootItemAppearanceServiceTestUtility();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProcessLootItemAgainstScript_NoMatchingBlocks_NormalItem_SetsCorrectTextColor()
|
||||
{
|
||||
// Arrange
|
||||
_testUtility.TestLootItem.Rarity = ItemRarity.Normal;
|
||||
|
||||
// Act
|
||||
_testUtility.Service.ProcessLootItemAgainstFilterScript(_testUtility.TestLootItem, _testUtility.TestScript);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(DefaultLootItemAppearanceConstants.NormalTextColor, _testUtility.TestLootItem.TextColor);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProcessLootItemAgainstScript_NoMatchingBlocks_MagicItem_SetsCorrectTextColor()
|
||||
{
|
||||
// Arrange
|
||||
_testUtility.TestLootItem.Rarity = ItemRarity.Magic;
|
||||
_testUtility.TestBlock.BlockItems.Add(new ItemLevelBlockItem(FilterPredicateOperator.GreaterThan, 99));
|
||||
|
||||
// Act
|
||||
_testUtility.Service.ProcessLootItemAgainstFilterScript(_testUtility.TestLootItem, _testUtility.TestScript);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(DefaultLootItemAppearanceConstants.MagicTextColor, _testUtility.TestLootItem.TextColor);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProcessLootItemAgainstScript_NoMatchingBlocks_RareItem_SetsCorrectTextColor()
|
||||
{
|
||||
// Arrange
|
||||
_testUtility.TestLootItem.Rarity = ItemRarity.Rare;
|
||||
_testUtility.TestBlock.BlockItems.Add(new ItemLevelBlockItem(FilterPredicateOperator.GreaterThan, 99));
|
||||
|
||||
// Act
|
||||
_testUtility.Service.ProcessLootItemAgainstFilterScript(_testUtility.TestLootItem, _testUtility.TestScript);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(DefaultLootItemAppearanceConstants.RareTextColor, _testUtility.TestLootItem.TextColor);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProcessLootItemAgainstScript_NoMatchingBlocks_UniqueItem_SetsCorrectTextColor()
|
||||
{
|
||||
// Arrange
|
||||
_testUtility.TestLootItem.Rarity = ItemRarity.Unique;
|
||||
_testUtility.TestBlock.BlockItems.Add(new ItemLevelBlockItem(FilterPredicateOperator.GreaterThan, 99));
|
||||
|
||||
// Act
|
||||
_testUtility.Service.ProcessLootItemAgainstFilterScript(_testUtility.TestLootItem, _testUtility.TestScript);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(DefaultLootItemAppearanceConstants.UniqueTextColor, _testUtility.TestLootItem.TextColor);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProcessLootItemAgainstScript_NoMatchingBlocks_SetsCorrectBackgroundColor()
|
||||
{
|
||||
// Arrange
|
||||
_testUtility.TestBlock.BlockItems.Add(new ItemLevelBlockItem(FilterPredicateOperator.GreaterThan, 99));
|
||||
|
||||
// Act
|
||||
_testUtility.Service.ProcessLootItemAgainstFilterScript(_testUtility.TestLootItem, _testUtility.TestScript);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(DefaultLootItemAppearanceConstants.BackgroundColor, _testUtility.TestLootItem.BackgroundColor);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProcessLootItemAgainstScript_NoMatchingBlocks_SetsCorrectBorderColor()
|
||||
{
|
||||
// Arrange
|
||||
_testUtility.TestBlock.BlockItems.Add(new ItemLevelBlockItem(FilterPredicateOperator.GreaterThan, 99));
|
||||
|
||||
// Act
|
||||
_testUtility.Service.ProcessLootItemAgainstFilterScript(_testUtility.TestLootItem, _testUtility.TestScript);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(DefaultLootItemAppearanceConstants.BorderColor, _testUtility.TestLootItem.BorderColor);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProcessLootItemAgainstScript_MatchingTextColorOnly_SetsColorsCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
var testInputTextColor = new Color {R = 123, G = 5, B = 22, A = 200};
|
||||
_testUtility.TestBlock.BlockItems.Add(new TextColorBlockItem {Color = testInputTextColor});
|
||||
|
||||
// Act
|
||||
_testUtility.Service.ProcessLootItemAgainstFilterScript(_testUtility.TestLootItem, _testUtility.TestScript);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(testInputTextColor, _testUtility.TestLootItem.TextColor);
|
||||
Assert.AreEqual(DefaultLootItemAppearanceConstants.BackgroundColor, _testUtility.TestLootItem.BackgroundColor);
|
||||
Assert.AreEqual(DefaultLootItemAppearanceConstants.BorderColor, _testUtility.TestLootItem.BorderColor);
|
||||
Assert.AreEqual(DefaultLootItemAppearanceConstants.FontSize, _testUtility.TestLootItem.FontSize );
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProcessLootItemAgainstScript_MatchingBackgroundColorOnly_RarityNormal_SetsColorsCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
var testInputBackgroundColor = new Color {R = 123, G = 5, B = 22, A = 200};
|
||||
_testUtility.TestBlock.BlockItems.Add(new BackgroundColorBlockItem {Color = testInputBackgroundColor});
|
||||
|
||||
// Act
|
||||
_testUtility.Service.ProcessLootItemAgainstFilterScript(_testUtility.TestLootItem, _testUtility.TestScript);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(testInputBackgroundColor, _testUtility.TestLootItem.BackgroundColor);
|
||||
Assert.AreEqual(DefaultLootItemAppearanceConstants.NormalTextColor, _testUtility.TestLootItem.TextColor);
|
||||
Assert.AreEqual(DefaultLootItemAppearanceConstants.BorderColor, _testUtility.TestLootItem.BorderColor);
|
||||
Assert.AreEqual(DefaultLootItemAppearanceConstants.FontSize, _testUtility.TestLootItem.FontSize);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProcessLootItemAgainstScript_MatchingBackgroundColorOnly_RarityMagic_SetsColorsCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
var testInputBackgroundColor = new Color { R = 123, G = 5, B = 22, A = 200 };
|
||||
_testUtility.TestBlock.BlockItems.Add(new BackgroundColorBlockItem {Color = testInputBackgroundColor});
|
||||
_testUtility.TestLootItem.Rarity = ItemRarity.Magic;
|
||||
|
||||
// Act
|
||||
_testUtility.Service.ProcessLootItemAgainstFilterScript(_testUtility.TestLootItem, _testUtility.TestScript);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(testInputBackgroundColor, _testUtility.TestLootItem.BackgroundColor);
|
||||
Assert.AreEqual(DefaultLootItemAppearanceConstants.MagicTextColor, _testUtility.TestLootItem.TextColor);
|
||||
Assert.AreEqual(DefaultLootItemAppearanceConstants.BorderColor, _testUtility.TestLootItem.BorderColor);
|
||||
Assert.AreEqual(DefaultLootItemAppearanceConstants.FontSize, _testUtility.TestLootItem.FontSize);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProcessLootItemAgainstScript_MatchingBackgroundColorOnly_RarityRare_SetsColorsCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
var testInputBackgroundColor = new Color { R = 123, G = 5, B = 22, A = 200 };
|
||||
_testUtility.TestBlock.BlockItems.Add(new BackgroundColorBlockItem { Color = testInputBackgroundColor });
|
||||
_testUtility.TestLootItem.Rarity = ItemRarity.Rare;
|
||||
|
||||
// Act
|
||||
_testUtility.Service.ProcessLootItemAgainstFilterScript(_testUtility.TestLootItem, _testUtility.TestScript);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(testInputBackgroundColor, _testUtility.TestLootItem.BackgroundColor);
|
||||
Assert.AreEqual(DefaultLootItemAppearanceConstants.RareTextColor, _testUtility.TestLootItem.TextColor);
|
||||
Assert.AreEqual(DefaultLootItemAppearanceConstants.BorderColor, _testUtility.TestLootItem.BorderColor);
|
||||
Assert.AreEqual(DefaultLootItemAppearanceConstants.FontSize, _testUtility.TestLootItem.FontSize);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProcessLootItemAgainstScript_MatchingBackgroundColorOnly_RarityUnique_SetsColorsCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
var testInputBackgroundColor = new Color { R = 123, G = 5, B = 22, A = 200 };
|
||||
_testUtility.TestBlock.BlockItems.Add(new BackgroundColorBlockItem { Color = testInputBackgroundColor });
|
||||
_testUtility.TestLootItem.Rarity = ItemRarity.Unique;
|
||||
|
||||
// Act
|
||||
_testUtility.Service.ProcessLootItemAgainstFilterScript(_testUtility.TestLootItem, _testUtility.TestScript);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(testInputBackgroundColor, _testUtility.TestLootItem.BackgroundColor);
|
||||
Assert.AreEqual(DefaultLootItemAppearanceConstants.UniqueTextColor, _testUtility.TestLootItem.TextColor);
|
||||
Assert.AreEqual(DefaultLootItemAppearanceConstants.BorderColor, _testUtility.TestLootItem.BorderColor);
|
||||
Assert.AreEqual(DefaultLootItemAppearanceConstants.FontSize, _testUtility.TestLootItem.FontSize);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProcessLootItemAgainstScript_MatchingBorderColorOnly_RarityUnique_SetsColorsCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
var testInputBorderColor = new Color { R = 123, G = 5, B = 22, A = 200 };
|
||||
_testUtility.TestBlock.BlockItems.Add(new BorderColorBlockItem { Color = testInputBorderColor });
|
||||
|
||||
// Act
|
||||
_testUtility.Service.ProcessLootItemAgainstFilterScript(_testUtility.TestLootItem, _testUtility.TestScript);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(testInputBorderColor, _testUtility.TestLootItem.BorderColor);
|
||||
Assert.AreEqual(DefaultLootItemAppearanceConstants.NormalTextColor, _testUtility.TestLootItem.TextColor);
|
||||
Assert.AreEqual(DefaultLootItemAppearanceConstants.BackgroundColor, _testUtility.TestLootItem.BackgroundColor);
|
||||
Assert.AreEqual(DefaultLootItemAppearanceConstants.FontSize, _testUtility.TestLootItem.FontSize);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProcessLootItemAgainstScript_MatchingFontSizeOnly_RarityUnique_SetsColorsCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
var testInputFontSize = 22;
|
||||
_testUtility.TestBlock.BlockItems.Add(new FontSizeBlockItem(22));
|
||||
|
||||
// Act
|
||||
_testUtility.Service.ProcessLootItemAgainstFilterScript(_testUtility.TestLootItem, _testUtility.TestScript);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(testInputFontSize, _testUtility.TestLootItem.FontSize);
|
||||
Assert.AreEqual(DefaultLootItemAppearanceConstants.NormalTextColor, _testUtility.TestLootItem.TextColor);
|
||||
Assert.AreEqual(DefaultLootItemAppearanceConstants.BackgroundColor, _testUtility.TestLootItem.BackgroundColor);
|
||||
Assert.AreEqual(DefaultLootItemAppearanceConstants.BorderColor, _testUtility.TestLootItem.BorderColor);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProcessLootItemAgainstScript_AllAppearanceMatching_SetsColorsCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
var testInputFontSize = 22;
|
||||
var testInputTextColor = new Color { R = 123, G = 5, B = 22, A = 200 };
|
||||
var testInputBackgroundColor = new Color { R = 123, G = 59, B = 27, A = 50 };
|
||||
var testInputBorderColor = new Color { R = 166, G = 0, B = 100, A = 255 };
|
||||
|
||||
_testUtility.TestBlock.BlockItems.Add(new FontSizeBlockItem(22));
|
||||
_testUtility.TestBlock.BlockItems.Add(new BorderColorBlockItem { Color = testInputBorderColor });
|
||||
_testUtility.TestBlock.BlockItems.Add(new BackgroundColorBlockItem { Color = testInputBackgroundColor });
|
||||
_testUtility.TestBlock.BlockItems.Add(new TextColorBlockItem { Color = testInputTextColor });
|
||||
|
||||
// Act
|
||||
_testUtility.Service.ProcessLootItemAgainstFilterScript(_testUtility.TestLootItem, _testUtility.TestScript);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(testInputFontSize, _testUtility.TestLootItem.FontSize);
|
||||
Assert.AreEqual(testInputTextColor, _testUtility.TestLootItem.TextColor);
|
||||
Assert.AreEqual(testInputBackgroundColor, _testUtility.TestLootItem.BackgroundColor);
|
||||
Assert.AreEqual(testInputBorderColor, _testUtility.TestLootItem.BorderColor);
|
||||
}
|
||||
|
||||
private class LootItemAppearanceServiceTestUtility
|
||||
{
|
||||
public LootItemAppearanceServiceTestUtility()
|
||||
{
|
||||
TestBlock = new ItemFilterBlock();
|
||||
TestScript = new ItemFilterScript();
|
||||
TestScript.ItemFilterBlocks.Add(TestBlock);
|
||||
TestLootItem = new LootItem();
|
||||
|
||||
MockItemFilterBlockFinderService = new Mock<IItemFilterBlockFinderService>();
|
||||
MockItemFilterBlockFinderService.Setup(
|
||||
b => b.FindBlockForLootItem(TestLootItem, TestScript))
|
||||
.Returns(TestBlock);
|
||||
|
||||
Service = new LootItemAppearanceService(MockItemFilterBlockFinderService.Object);
|
||||
}
|
||||
|
||||
public Mock<IItemFilterBlockFinderService> MockItemFilterBlockFinderService { get; private set; }
|
||||
|
||||
public ItemFilterScript TestScript { get; private set; }
|
||||
public ItemFilterBlock TestBlock { get; private set; }
|
||||
public LootItem TestLootItem { get; private set; }
|
||||
public LootItemAppearanceService Service { get; private set; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Moq" version="4.2.1507.0118" targetFramework="net451" />
|
||||
<package id="NUnit" version="2.6.4" targetFramework="net451" />
|
||||
</packages>
|
|
@ -0,0 +1,72 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{C8009B11-14D0-4421-94F0-9EF4603CB363}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Filtration.LootExplosionStudio</RootNamespace>
|
||||
<AssemblyName>Filtration.LootExplosionStudio</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Castle.Core">
|
||||
<HintPath>..\packages\Castle.Core.3.3.0\lib\net45\Castle.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Castle.Windsor">
|
||||
<HintPath>..\packages\Castle.Windsor.3.3.0\lib\net45\Castle.Windsor.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Services\ItemFilterBlockFinderService.cs" />
|
||||
<Compile Include="Services\LootItemAppearanceService.cs" />
|
||||
<Compile Include="Services\LootItemCollectionItemFilterCombinerService.cs" />
|
||||
<Compile Include="WindsorInstallers\ServicesInstaller.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Filtration.ObjectModel\Filtration.ObjectModel.csproj">
|
||||
<Project>{4aac3beb-1dc1-483e-9d11-0e9334e80227}</Project>
|
||||
<Name>Filtration.ObjectModel</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
|
@ -0,0 +1,37 @@
|
|||
using System.Linq;
|
||||
using Filtration.ObjectModel;
|
||||
using Filtration.ObjectModel.BlockItemBaseTypes;
|
||||
using Filtration.ObjectModel.LootExplosionStudio;
|
||||
|
||||
namespace Filtration.LootExplosionStudio.Services
|
||||
{
|
||||
internal interface IItemFilterBlockFinderService
|
||||
{
|
||||
ItemFilterBlock FindBlockForLootItem(LootItem lootItem, ItemFilterScript script);
|
||||
}
|
||||
|
||||
internal class ItemFilterBlockFinderService : IItemFilterBlockFinderService
|
||||
{
|
||||
public ItemFilterBlock FindBlockForLootItem(LootItem lootItem, ItemFilterScript script)
|
||||
{
|
||||
return script.ItemFilterBlocks.FirstOrDefault(block => BlockMatchesLootItem(lootItem, block));
|
||||
}
|
||||
|
||||
private static bool BlockMatchesLootItem(LootItem lootItem, ItemFilterBlock block)
|
||||
{
|
||||
if (!block.BlockItems.OfType<StringListBlockItem>().All(blockItem => blockItem.MatchesLootItem(lootItem)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
!block.BlockItems.OfType<NumericFilterPredicateBlockItem>()
|
||||
.All(blockItem => blockItem.MatchesLootItem(lootItem)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
using System.Linq;
|
||||
using System.Windows.Media;
|
||||
using Filtration.ObjectModel;
|
||||
using Filtration.ObjectModel.BlockItemTypes;
|
||||
using Filtration.ObjectModel.Enums;
|
||||
using Filtration.ObjectModel.LootExplosionStudio;
|
||||
|
||||
namespace Filtration.LootExplosionStudio.Services
|
||||
{
|
||||
internal interface ILootItemAppearanceService
|
||||
{
|
||||
void ProcessLootItemAgainstFilterScript(LootItem lootItem, ItemFilterScript script);
|
||||
}
|
||||
|
||||
internal class LootItemAppearanceService : ILootItemAppearanceService
|
||||
{
|
||||
private readonly IItemFilterBlockFinderService _blockFinderService;
|
||||
|
||||
public LootItemAppearanceService(IItemFilterBlockFinderService blockFinderService)
|
||||
{
|
||||
_blockFinderService = blockFinderService;
|
||||
}
|
||||
|
||||
public void ProcessLootItemAgainstFilterScript(LootItem lootItem, ItemFilterScript script)
|
||||
{
|
||||
var matchedBlock = _blockFinderService.FindBlockForLootItem(lootItem, script);
|
||||
if (matchedBlock == null)
|
||||
{
|
||||
lootItem.TextColor = GetDefaultTextColorForRarity(lootItem.Rarity);
|
||||
lootItem.BackgroundColor = DefaultLootItemAppearanceConstants.BackgroundColor;
|
||||
lootItem.BorderColor = DefaultLootItemAppearanceConstants.BorderColor;
|
||||
lootItem.FontSize = 35;
|
||||
return;
|
||||
}
|
||||
|
||||
lootItem.TextColor = matchedBlock.HasBlockItemOfType<TextColorBlockItem>()
|
||||
? matchedBlock.BlockItems.OfType<TextColorBlockItem>().First().Color
|
||||
: GetDefaultTextColorForRarity(lootItem.Rarity);
|
||||
|
||||
lootItem.BackgroundColor = matchedBlock.HasBlockItemOfType<BackgroundColorBlockItem>()
|
||||
? matchedBlock.BlockItems.OfType<BackgroundColorBlockItem>().First().Color
|
||||
: DefaultLootItemAppearanceConstants.BackgroundColor;
|
||||
|
||||
lootItem.BorderColor = matchedBlock.HasBlockItemOfType<BorderColorBlockItem>()
|
||||
? matchedBlock.BlockItems.OfType<BorderColorBlockItem>().First().Color
|
||||
: DefaultLootItemAppearanceConstants.BorderColor;
|
||||
|
||||
lootItem.FontSize = matchedBlock.HasBlockItemOfType<FontSizeBlockItem>()
|
||||
? matchedBlock.BlockItems.OfType<FontSizeBlockItem>().First().Value
|
||||
: 35;
|
||||
}
|
||||
|
||||
private Color GetDefaultTextColorForRarity(ItemRarity rarity)
|
||||
{
|
||||
switch (rarity)
|
||||
{
|
||||
case ItemRarity.Normal:
|
||||
{
|
||||
return DefaultLootItemAppearanceConstants.NormalTextColor;
|
||||
}
|
||||
case ItemRarity.Magic:
|
||||
{
|
||||
return DefaultLootItemAppearanceConstants.MagicTextColor;
|
||||
}
|
||||
case ItemRarity.Rare:
|
||||
{
|
||||
return DefaultLootItemAppearanceConstants.RareTextColor;
|
||||
}
|
||||
case ItemRarity.Unique:
|
||||
{
|
||||
return DefaultLootItemAppearanceConstants.UniqueTextColor;
|
||||
}
|
||||
default:
|
||||
{
|
||||
return DefaultLootItemAppearanceConstants.NormalTextColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
using Filtration.ObjectModel;
|
||||
using Filtration.ObjectModel.LootExplosionStudio;
|
||||
|
||||
namespace Filtration.LootExplosionStudio.Services
|
||||
{
|
||||
internal interface ILootItemCollectionItemFilterCombinerService
|
||||
{
|
||||
void CombineLootItemCollectionWithItemFilterScript(LootItemCollection lootItemCollection,
|
||||
ItemFilterScript script);
|
||||
}
|
||||
|
||||
internal class LootItemCollectionItemFilterCombinerService : ILootItemCollectionItemFilterCombinerService
|
||||
{
|
||||
private readonly ILootItemAppearanceService _lootItemAppearanceService;
|
||||
|
||||
public LootItemCollectionItemFilterCombinerService(ILootItemAppearanceService lootItemAppearanceService)
|
||||
{
|
||||
_lootItemAppearanceService = lootItemAppearanceService;
|
||||
}
|
||||
|
||||
public void CombineLootItemCollectionWithItemFilterScript(LootItemCollection lootItemCollection,
|
||||
ItemFilterScript script)
|
||||
{
|
||||
foreach (var lootItem in lootItemCollection)
|
||||
{
|
||||
_lootItemAppearanceService.ProcessLootItemAgainstFilterScript(lootItem, script);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
using Castle.MicroKernel.Registration;
|
||||
using Castle.MicroKernel.SubSystems.Configuration;
|
||||
using Castle.Windsor;
|
||||
using Filtration.LootExplosionStudio.Services;
|
||||
|
||||
namespace Filtration.LootExplosionStudio.WindsorInstallers
|
||||
{
|
||||
class ServicesInstaller : IWindsorInstaller
|
||||
{
|
||||
public void Install(IWindsorContainer container, IConfigurationStore store)
|
||||
{
|
||||
container.Register(
|
||||
Component.For<IItemFilterBlockFinderService>()
|
||||
.ImplementedBy<ItemFilterBlockFinderService>()
|
||||
.LifeStyle.Singleton);
|
||||
|
||||
container.Register(
|
||||
Component.For<ILootItemAppearanceService>()
|
||||
.ImplementedBy<LootItemAppearanceService>()
|
||||
.LifeStyle.Singleton);
|
||||
container.Register(
|
||||
Component.For<ILootItemCollectionItemFilterCombinerService>()
|
||||
.ImplementedBy<LootItemCollectionItemFilterCombinerService>()
|
||||
.LifeStyle.Singleton);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Castle.Core" version="3.3.0" targetFramework="net451" />
|
||||
<package id="Castle.Windsor" version="3.3.0" targetFramework="net451" />
|
||||
</packages>
|
Loading…
Reference in New Issue