public void ReplaceColors_ReplacesBackgroundColorsCorrectly() { // Arrange var oldColor = new Color {A = 255, R = 255, G = 0, B = 0}; var newColor = new Color {A = 255, R = 0, G = 255, B = 100}; var testInputReplaceColors = new ReplaceColorsParameterSet { OldBackgroundColor = oldColor, NewBackgroundColor = newColor, ReplaceBackgroundColor = true }; var testInputBlock1 = new ItemFilterBlock(); testInputBlock1.BlockItems.Add(new BackgroundColorBlockItem(new Color {A = 255, R = 255, G = 0, B = 0})); var testInputBlock2 = new ItemFilterBlock(); testInputBlock2.BlockItems.Add(new BackgroundColorBlockItem(new Color { A = 255, R = 255, G = 1, B = 0 })); var testInputBlock3 = new ItemFilterBlock(); testInputBlock3.BlockItems.Add(new BackgroundColorBlockItem(new Color { A = 255, R = 255, G = 0, B = 0 })); var script = new ItemFilterScript(); script.ItemFilterBlocks.Add(testInputBlock1); script.ItemFilterBlocks.Add(testInputBlock2); script.ItemFilterBlocks.Add(testInputBlock3); // Act script.ReplaceColors(testInputReplaceColors); // Assert Assert.AreEqual(newColor, testInputBlock1.BlockItems.OfType<BackgroundColorBlockItem>().First().Color); Assert.AreNotEqual(newColor, testInputBlock2.BlockItems.OfType<BackgroundColorBlockItem>().First().Color); Assert.AreEqual(newColor, testInputBlock3.BlockItems.OfType<BackgroundColorBlockItem>().First().Color); }
public void Initialise(ItemFilterScript itemFilterScript, ItemFilterBlock initialiseFromBlock) { _replaceColorsParameterSet = new ReplaceColorsParameterSet(); if (initialiseFromBlock.BlockItems.Count(b => b.GetType() == typeof(TextColorBlockItem)) > 0) { _replaceColorsParameterSet.ReplaceTextColor = true; var existingBlockColor = ((TextColorBlockItem) initialiseFromBlock.BlockItems.First(b => b.GetType() == typeof(TextColorBlockItem))).Color; _replaceColorsParameterSet.OldTextColor = existingBlockColor; _replaceColorsParameterSet.NewTextColor = existingBlockColor; } if (initialiseFromBlock.BlockItems.Count(b => b.GetType() == typeof(BackgroundColorBlockItem)) > 0) { _replaceColorsParameterSet.ReplaceBackgroundColor = true; var existingBlockColor = ((BackgroundColorBlockItem) initialiseFromBlock.BlockItems.First(b => b.GetType() == typeof(BackgroundColorBlockItem))).Color; _replaceColorsParameterSet.OldBackgroundColor = existingBlockColor; _replaceColorsParameterSet.NewBackgroundColor = existingBlockColor; } if (initialiseFromBlock.BlockItems.Count(b => b.GetType() == typeof(BorderColorBlockItem)) > 0) { _replaceColorsParameterSet.ReplaceBorderColor = true; var existingBlockColor = ((BorderColorBlockItem) initialiseFromBlock.BlockItems.First(b => b.GetType() == typeof(BorderColorBlockItem))).Color; _replaceColorsParameterSet.OldBorderColor = existingBlockColor; _replaceColorsParameterSet.NewBorderColor = existingBlockColor; } _itemFilterScript = itemFilterScript; }
public void ReplaceColors_OnlyReplacesColorsWhenAllSetParametersMatched() { // Arrange var oldBackgroundColor = new Color { A = 255, R = 255, G = 0, B = 0 }; var newBackgroundColor = new Color { A = 255, R = 0, G = 255, B = 100 }; var oldTextColor = new Color { A = 255, R = 100, G = 0, B = 50 }; var newTextColor = new Color { A = 255, R = 101, G = 255, B = 51 }; var testInputReplaceColors = new ReplaceColorsParameterSet { OldBackgroundColor = oldBackgroundColor, NewBackgroundColor = newBackgroundColor, OldTextColor = oldTextColor, NewTextColor = newTextColor, ReplaceBackgroundColor = true, ReplaceTextColor = true }; var testInputBlock1 = new ItemFilterBlock(); testInputBlock1.BlockItems.Add(new BackgroundColorBlockItem(oldBackgroundColor)); testInputBlock1.BlockItems.Add(new TextColorBlockItem(oldTextColor)); var testInputBlock2 = new ItemFilterBlock(); testInputBlock2.BlockItems.Add(new BackgroundColorBlockItem(oldBackgroundColor)); testInputBlock2.BlockItems.Add(new TextColorBlockItem(new Color { A = 1, R = 2, G = 3, B = 4 })); var script = new ItemFilterScript(); script.ItemFilterBlocks.Add(testInputBlock1); script.ItemFilterBlocks.Add(testInputBlock2); // Act script.ReplaceColors(testInputReplaceColors); // Assert // First test block has had its colors changed Assert.AreEqual(newBackgroundColor, testInputBlock1.BlockItems.OfType <BackgroundColorBlockItem>().First().Color); Assert.AreEqual(newTextColor, testInputBlock1.BlockItems.OfType <TextColorBlockItem>().First().Color); // Second test block has not had its colors changed Assert.AreEqual(oldBackgroundColor, testInputBlock2.BlockItems.OfType <BackgroundColorBlockItem>().First().Color); Assert.AreNotEqual(newTextColor, testInputBlock2.BlockItems.OfType <TextColorBlockItem>().First().Color); }
public void ReplaceColors_ReplacesBackgroundColorsCorrectly() { // Arrange var oldColor = new Color { A = 255, R = 255, G = 0, B = 0 }; var newColor = new Color { A = 255, R = 0, G = 255, B = 100 }; var testInputReplaceColors = new ReplaceColorsParameterSet { OldBackgroundColor = oldColor, NewBackgroundColor = newColor, ReplaceBackgroundColor = true }; var testInputBlock1 = new ItemFilterBlock(); testInputBlock1.BlockItems.Add(new BackgroundColorBlockItem(new Color { A = 255, R = 255, G = 0, B = 0 })); var testInputBlock2 = new ItemFilterBlock(); testInputBlock2.BlockItems.Add(new BackgroundColorBlockItem(new Color { A = 255, R = 255, G = 1, B = 0 })); var testInputBlock3 = new ItemFilterBlock(); testInputBlock3.BlockItems.Add(new BackgroundColorBlockItem(new Color { A = 255, R = 255, G = 0, B = 0 })); var script = new ItemFilterScript(); script.ItemFilterBlocks.Add(testInputBlock1); script.ItemFilterBlocks.Add(testInputBlock2); script.ItemFilterBlocks.Add(testInputBlock3); // Act script.ReplaceColors(testInputReplaceColors); // Assert Assert.AreEqual(newColor, testInputBlock1.BlockItems.OfType <BackgroundColorBlockItem>().First().Color); Assert.AreNotEqual(newColor, testInputBlock2.BlockItems.OfType <BackgroundColorBlockItem>().First().Color); Assert.AreEqual(newColor, testInputBlock3.BlockItems.OfType <BackgroundColorBlockItem>().First().Color); }
public void ReplaceColors_OnlyReplacesColorsWhenAllSetParametersMatched() { // Arrange var oldBackgroundColor = new Color { A = 255, R = 255, G = 0, B = 0 }; var newBackgroundColor = new Color { A = 255, R = 0, G = 255, B = 100 }; var oldTextColor = new Color { A = 255, R = 100, G = 0, B = 50 }; var newTextColor = new Color { A = 255, R = 101, G = 255, B = 51 }; var testInputReplaceColors = new ReplaceColorsParameterSet { OldBackgroundColor = oldBackgroundColor, NewBackgroundColor = newBackgroundColor, OldTextColor = oldTextColor, NewTextColor = newTextColor, ReplaceBackgroundColor = true, ReplaceTextColor = true }; var testInputBlock1 = new ItemFilterBlock(); testInputBlock1.BlockItems.Add(new BackgroundColorBlockItem(oldBackgroundColor)); testInputBlock1.BlockItems.Add(new TextColorBlockItem(oldTextColor)); var testInputBlock2 = new ItemFilterBlock(); testInputBlock2.BlockItems.Add(new BackgroundColorBlockItem(oldBackgroundColor)); testInputBlock2.BlockItems.Add(new TextColorBlockItem(new Color {A = 1, R = 2, G = 3, B = 4})); var script = new ItemFilterScript(); script.ItemFilterBlocks.Add(testInputBlock1); script.ItemFilterBlocks.Add(testInputBlock2); // Act script.ReplaceColors(testInputReplaceColors); // Assert // First test block has had its colors changed Assert.AreEqual(newBackgroundColor, testInputBlock1.BlockItems.OfType<BackgroundColorBlockItem>().First().Color); Assert.AreEqual(newTextColor, testInputBlock1.BlockItems.OfType<TextColorBlockItem>().First().Color); // Second test block has not had its colors changed Assert.AreEqual(oldBackgroundColor, testInputBlock2.BlockItems.OfType<BackgroundColorBlockItem>().First().Color); Assert.AreNotEqual(newTextColor, testInputBlock2.BlockItems.OfType<TextColorBlockItem>().First().Color); }
public void ReplaceColors(ReplaceColorsParameterSet replaceColorsParameterSet) { foreach ( var block in ItemFilterBlocks.Where(b => BlockIsColorReplacementCandidate(replaceColorsParameterSet, b))) { if (replaceColorsParameterSet.ReplaceTextColor) { var textColorBlockItem = block.BlockItems.OfType<TextColorBlockItem>().First(); textColorBlockItem.Color = replaceColorsParameterSet.NewTextColor; } if (replaceColorsParameterSet.ReplaceBackgroundColor) { var backgroundColorBlockItem = block.BlockItems.OfType<BackgroundColorBlockItem>().First(); backgroundColorBlockItem.Color = replaceColorsParameterSet.NewBackgroundColor; } if (replaceColorsParameterSet.ReplaceBorderColor) { var borderColorBlockItem = block.BlockItems.OfType<BorderColorBlockItem>().First(); borderColorBlockItem.Color = replaceColorsParameterSet.NewBorderColor; } } }
public void Initialise(ItemFilterScript itemFilterScript) { _replaceColorsParameterSet = new ReplaceColorsParameterSet(); _itemFilterScript = itemFilterScript; }
public void Initialise(ItemFilterScript itemFilterScript) { _replaceColorsParameterSet = new ReplaceColorsParameterSet(); _itemFilterScript = itemFilterScript; }
public void Initialise(ItemFilterScript itemFilterScript, IItemFilterBlock initialiseFromBlock) { _replaceColorsParameterSet = new ReplaceColorsParameterSet(); if (initialiseFromBlock.BlockItems.Count(b => b.GetType() == typeof (TextColorBlockItem)) > 0) { _replaceColorsParameterSet.ReplaceTextColor = true; var existingBlockColor = ((TextColorBlockItem) initialiseFromBlock.BlockItems.First(b => b.GetType() == typeof (TextColorBlockItem))).Color; _replaceColorsParameterSet.OldTextColor = existingBlockColor; _replaceColorsParameterSet.NewTextColor = existingBlockColor; } if (initialiseFromBlock.BlockItems.Count(b => b.GetType() == typeof(BackgroundColorBlockItem)) > 0) { _replaceColorsParameterSet.ReplaceBackgroundColor = true; var existingBlockColor = ((BackgroundColorBlockItem) initialiseFromBlock.BlockItems.First(b => b.GetType() == typeof(BackgroundColorBlockItem))).Color; _replaceColorsParameterSet.OldBackgroundColor = existingBlockColor; _replaceColorsParameterSet.NewBackgroundColor = existingBlockColor; } if (initialiseFromBlock.BlockItems.Count(b => b.GetType() == typeof(BorderColorBlockItem)) > 0) { _replaceColorsParameterSet.ReplaceBorderColor = true; var existingBlockColor = ((BorderColorBlockItem) initialiseFromBlock.BlockItems.First(b => b.GetType() == typeof(BorderColorBlockItem))).Color; _replaceColorsParameterSet.OldBorderColor = existingBlockColor; _replaceColorsParameterSet.NewBorderColor = existingBlockColor; } _itemFilterScript = itemFilterScript; }
private bool BlockIsColorReplacementCandidate(ReplaceColorsParameterSet replaceColorsParameterSet, IItemFilterBlock block) { var textColorItem = block.HasBlockItemOfType<TextColorBlockItem>() ? block.BlockItems.OfType<TextColorBlockItem>().First() : null; var backgroundColorItem = block.HasBlockItemOfType<BackgroundColorBlockItem>() ? block.BlockItems.OfType<BackgroundColorBlockItem>().First() : null; var borderColorItem = block.HasBlockItemOfType<BorderColorBlockItem>() ? block.BlockItems.OfType<BorderColorBlockItem>().First() : null; // If we don't have all of the things we want to replace, then we aren't a candidate for replacing those things. if ((textColorItem == null && replaceColorsParameterSet.ReplaceTextColor) || (backgroundColorItem == null && replaceColorsParameterSet.ReplaceBackgroundColor) || (borderColorItem == null && replaceColorsParameterSet.ReplaceBorderColor)) { return false; } if ((replaceColorsParameterSet.ReplaceTextColor && textColorItem.Color != replaceColorsParameterSet.OldTextColor) || (replaceColorsParameterSet.ReplaceBackgroundColor && backgroundColorItem.Color != replaceColorsParameterSet.OldBackgroundColor) || (replaceColorsParameterSet.ReplaceBorderColor && borderColorItem.Color != replaceColorsParameterSet.OldBorderColor)) { return false; } return true; }