public void PrintSimDetailFactory_PopulateWithMixedFields_CheckFieldsAllocatedCorrectly()
        {
            // Arrange
            var simDetailFactory = new PrintSimDetailFactory();

            ProductField[] productFields = new ProductField[]
            {
                new ProductField {
                    Deleted       = false, Editable = false, Printable = true, Font = "consolas", PrintSide = 0, ProductPrintFieldTypeId = 0,
                    FontColourRGB = Color.Black.ToArgb(), FontSize = 10, X = 15, Y = 30, Value = Encoding.UTF8.GetBytes("Hello From Print Sim field 1")
                },
                new ProductField {
                    Deleted       = false, Editable = false, Printable = true, Font = "arial", PrintSide = 1, ProductPrintFieldTypeId = 0,
                    FontColourRGB = Color.Red.ToArgb(), FontSize = 12, X = 20, Y = 52, Value = Encoding.UTF8.GetBytes("Hello From Print Sim field 2")
                },
                new ProductField {
                    Deleted = false, Editable = false, Printable = true, PrintSide = 0, Width = 100, Height = 200, ProductPrintFieldTypeId = 1,
                    X       = 43, Y = 66, Value = Encoding.UTF8.GetBytes("Hello From Print Sim field 3")
                },
                new ProductField {
                    Deleted = false, Editable = false, Printable = true, PrintSide = 1, Width = 430, Height = 789, ProductPrintFieldTypeId = 1,
                    X       = 5, Y = 9, Value = Encoding.UTF8.GetBytes("Hello From Print Sim field 4")
                }
            };

            // Act
            var simPrintDetails = simDetailFactory.Populate(productFields);

            // Assert
            simPrintDetails.BackPanelText.Length.Should().Be(1);
            simPrintDetails.BackPanelImages.Length.Should().Be(1);
            simPrintDetails.FrontPanelText.Length.Should().Be(1);
            simPrintDetails.FrontPanelImages.Length.Should().Be(1);
        }
        public void PrintSimDetailFactory_PopulateWithDeletedProductField_ThrowsArgumentException()
        {
            // Arrange
            var simDetailFactory = new PrintSimDetailFactory();

            ProductField[] productFields = new ProductField[]
            {
                new ProductField {
                    Deleted       = true, Editable = false, Printable = true, Font = "consolas", PrintSide = 0, ProductPrintFieldTypeId = 0,
                    FontColourRGB = Color.Black.ToArgb(), FontSize = 10, X = 15, Y = 30, Value = Encoding.UTF8.GetBytes("Hello From Print Sim")
                }
            };

            // Act
            Exception exception = null;

            try
            {
                var simPrintDetails = simDetailFactory.Populate(productFields);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            // Assert
            exception.Should().NotBeNull(because: "An ArgumentNullException must be thrown if the array passed to Populate() does not have any valid product fields to print.");
            exception.Should().BeOfType(typeof(ArgumentNullException), because: "The populate fields array does not have any valid product fields. In this case the field is set to deleted");
            ((ArgumentNullException)exception).ParamName.Should().Be("productFields", because: "This is the argument that should have thrown the ArgumentNullException");
        }
        public void PrintSimDetailFactory_PopulateWithBackMixedFields_OnlyHaveBackFieldsPopulated()
        {
            // Arrange
            var simDetailFactory = new PrintSimDetailFactory();

            ProductField[] productFields = new ProductField[]
            {
                new ProductField {
                    Deleted       = false, Editable = false, Printable = true, Font = "consolas", PrintSide = 1, ProductPrintFieldTypeId = 0,
                    FontColourRGB = Color.Black.ToArgb(), FontSize = 10, X = 15, Y = 30, Value = Encoding.UTF8.GetBytes("Hello From Print Sim field 1")
                },
                new ProductField {
                    Deleted       = false, Editable = false, Printable = true, Font = "arial", PrintSide = 1, ProductPrintFieldTypeId = 0,
                    FontColourRGB = Color.Red.ToArgb(), FontSize = 12, X = 20, Y = 52, Value = Encoding.UTF8.GetBytes("Hello From Print Sim field 2")
                },
                new ProductField {
                    Deleted = false, Editable = false, Printable = true, PrintSide = 1, Width = 100, Height = 200, ProductPrintFieldTypeId = 1,
                    X       = 43, Y = 66, Value = Encoding.UTF8.GetBytes("Hello From Print Sim field 3")
                },
                new ProductField {
                    Deleted = false, Editable = false, Printable = true, PrintSide = 1, Width = 430, Height = 789, ProductPrintFieldTypeId = 1,
                    X       = 5, Y = 9, Value = Encoding.UTF8.GetBytes("Hello From Print Sim field 4")
                }
            };

            // Act
            var simPrintDetails = simDetailFactory.Populate(productFields);

            // Assert
            simPrintDetails.BackPanelText.Length.Should().Be(2, because: "Two back side text field passed to Populate(). Must set two BackPanelText objects.");
            simPrintDetails.BackPanelImages.Length.Should().Be(2, because: "Two back side image field passed to Populate(). Must set two BackPanelImages objects.");
            simPrintDetails.FrontPanelText.Length.Should().Be(0, because: "No front fields passed to Populate()");
            simPrintDetails.FrontPanelImages.Length.Should().Be(0, because: "No front fields passed to Populate()");
        }
        public void PrintSimDetailFactory_PopulateWithTwoBackImageFields_SecondBackPanelFieldSetCorrectly()
        {
            // Arrange
            var simDetailFactory = new PrintSimDetailFactory();

            ProductField[] productFields = new ProductField[]
            {
                new ProductField {
                    Deleted = false, Editable = false, Printable = true, PrintSide = 1, Width = 100, Height = 200, ProductPrintFieldTypeId = 1,
                    X       = 15, Y = 30, Value = Encoding.UTF8.GetBytes("Hello From Print Sim field 1")
                },
                new ProductField {
                    Deleted = false, Editable = false, Printable = true, PrintSide = 1, Width = 430, Height = 789, ProductPrintFieldTypeId = 1,
                    X       = 20, Y = 52, Value = Encoding.UTF8.GetBytes("Hello From Print Sim field 2")
                }
            };

            var secondField      = productFields[1];
            var secondImageField = new PrintSimCardImageDetail(secondField.Value, secondField.X, secondField.Y, secondField.Width, secondField.Height);

            // Act
            var simPrintDetails = simDetailFactory.Populate(productFields);

            // Assert
            simPrintDetails.BackPanelImages[1].Should().BeEquivalentTo(secondImageField);
        }
        public void PrintSimDetailFactory_PopulateWithBackImageFields_OnlyHaveBackImageFieldsPopulated()
        {
            // Arrange
            var simDetailFactory = new PrintSimDetailFactory();

            ProductField[] productFields = new ProductField[]
            {
                new ProductField {
                    Deleted = false, Editable = false, Printable = true, PrintSide = 1, Width = 100, Height = 200, ProductPrintFieldTypeId = 1,
                    X       = 15, Y = 30, Value = Encoding.UTF8.GetBytes("Hello From Print Sim field 1")
                },
                new ProductField {
                    Deleted = false, Editable = false, Printable = true, PrintSide = 1, Width = 430, Height = 789, ProductPrintFieldTypeId = 1,
                    X       = 20, Y = 52, Value = Encoding.UTF8.GetBytes("Hello From Print Sim field 2")
                }
            };

            // Act
            var simPrintDetails = simDetailFactory.Populate(productFields);

            // Assert
            simPrintDetails.FrontPanelText.Length.Should().Be(0, because: "No text fields passed to Populate()");
            simPrintDetails.BackPanelText.Length.Should().Be(0, because: "No text fields passed to Populate()");
            simPrintDetails.FrontPanelImages.Length.Should().Be(0, because: "No front side image fields passed to Populate()");
            simPrintDetails.BackPanelImages.Length.Should().Be(2, because: "Two back side image field passed to Populate(). Must set two BackPanelImages objects.");
        }
        public void PrintSimDetailFactory_PopulateWithTwoBackTextFields_SecondBackPanelFieldSetCorrectly()
        {
            // Arrange
            var simDetailFactory = new PrintSimDetailFactory();

            ProductField[] productFields = new ProductField[]
            {
                new ProductField {
                    Deleted       = false, Editable = false, Printable = true, Font = "consolas", PrintSide = 1,
                    FontColourRGB = Color.Black.ToArgb(), FontSize = 10, X = 15, Y = 30, Value = Encoding.UTF8.GetBytes("Hello From Print Sim field 1")
                },
                new ProductField {
                    Deleted       = false, Editable = false, Printable = true, Font = "arial", PrintSide = 1,
                    FontColourRGB = Color.Red.ToArgb(), FontSize = 12, X = 20, Y = 52, Value = Encoding.UTF8.GetBytes("Hello From Print Sim field 2")
                }
            };

            var secondField     = productFields[1];
            var secondTextField = new PrintSimCardTextDetail(secondField.ValueToString(), secondField.X, secondField.Y, secondField.Font,
                                                             secondField.FontSize, secondField.FontColourRGB, FontStyle.Regular);

            // Act
            var simPrintDetails = simDetailFactory.Populate(productFields);

            // Assert
            simPrintDetails.BackPanelText[1].Should().BeEquivalentTo(secondTextField);
        }
        public void PrintSimDetailFactory_PopulateWithSingleProductField_Success()
        {
            // Arrange
            var simDetailFactory = new PrintSimDetailFactory();

            ProductField[] productFields = new ProductField[]
            {
                new ProductField {
                    Deleted       = false, Editable = false, Printable = true, Font = "consolas", PrintSide = 0, ProductPrintFieldTypeId = 0,
                    FontColourRGB = Color.Black.ToArgb(), FontSize = 10, X = 15, Y = 30, Value = Encoding.UTF8.GetBytes("Hello From Print Sim")
                }
            };

            // Act
            var simPrintDetails = simDetailFactory.Populate(productFields);

            // Assert
            simPrintDetails.FrontPanelText.Length.Should().Be(1, because: "Single front side text field passed in");
        }
        public void PrintSimDetailFactory_PopulateWithBackMixedFields_BackPanelTextFieldSetCorrectly()
        {
            // Arrange
            var simDetailFactory = new PrintSimDetailFactory();

            ProductField[] productFields = new ProductField[]
            {
                new ProductField {
                    Deleted       = false, Editable = false, Printable = true, Font = "consolas", PrintSide = 1, ProductPrintFieldTypeId = 0,
                    FontColourRGB = Color.Black.ToArgb(), FontSize = 10, X = 15, Y = 30, Value = Encoding.UTF8.GetBytes("Hello From Print Sim field 1")
                },
                new ProductField {
                    Deleted       = false, Editable = false, Printable = true, Font = "arial", PrintSide = 1, ProductPrintFieldTypeId = 0,
                    FontColourRGB = Color.Red.ToArgb(), FontSize = 12, X = 20, Y = 52, Value = Encoding.UTF8.GetBytes("Hello From Print Sim field 2")
                },
                new ProductField {
                    Deleted = false, Editable = false, Printable = true, PrintSide = 1, Width = 100, Height = 200, ProductPrintFieldTypeId = 1,
                    X       = 43, Y = 66, Value = Encoding.UTF8.GetBytes("Hello From Print Sim field 3")
                },
                new ProductField {
                    Deleted = false, Editable = false, Printable = true, PrintSide = 1, Width = 430, Height = 789, ProductPrintFieldTypeId = 1,
                    X       = 5, Y = 9, Value = Encoding.UTF8.GetBytes("Hello From Print Sim field 4")
                }
            };

            var firstField     = productFields[0];
            var firstTextField = new PrintSimCardTextDetail(firstField.ValueToString(), firstField.X, firstField.Y, firstField.Font,
                                                            firstField.FontSize, firstField.FontColourRGB, FontStyle.Regular);
            var secondField     = productFields[1];
            var secondTextField = new PrintSimCardTextDetail(secondField.ValueToString(), secondField.X, secondField.Y, secondField.Font,
                                                             secondField.FontSize, secondField.FontColourRGB, FontStyle.Regular);

            // Act
            var simPrintDetails = simDetailFactory.Populate(productFields);

            // Assert
            simPrintDetails.BackPanelText[0].Should().BeEquivalentTo(firstTextField);
            simPrintDetails.BackPanelText[1].Should().BeEquivalentTo(secondTextField);
        }
        public void PrintSimDetailFactory_PopulateWithNullProductFieldArray_ThrowsArgumentException()
        {
            // Arrange
            var simDetailFactory = new PrintSimDetailFactory();

            ProductField[] productFields = null;

            // Act
            Exception exception = null;

            try
            {
                var simPrintDetails = simDetailFactory.Populate(productFields);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            // Assert
            exception.Should().NotBeNull(because: "An ArgumentNullException must be thrown if a null array is passed to Populate(). Calling code should make sure there is something to populate.");
            exception.Should().BeOfType(typeof(ArgumentNullException), because: "The populate fields argument is null or empty. Must return correct expection type to indicate this");
            ((ArgumentNullException)exception).ParamName.Should().Be("productFields", because: "This is the argument that should have thrown the ArgumentNullException");
        }