public void OutputBuilderTests_BuildProductLines_NullProductValue_ThrowsException() { //arrange var sut = new OutputBuilder(); IMinMax range = GetMinMaxMock(1, 5, 3); // Irrelevant to this test IAccumulatedProduct[] mockData = { GetAccumulatedProductMock("a", new double[0]), GetAccumulatedProductMock("b", null), GetAccumulatedProductMock("c", new double[0]), }; IAccumulatedProducts mockDatas = GetAccumulatedProductsMock(range, mockData); bool exceptionThrown = false; string exceptionMessage = ""; //act try { sut.BuildProductLines(mockDatas); } catch (InvalidOperationException e) { exceptionThrown = true; exceptionMessage = e.Message; } //assert Assert.IsTrue(exceptionThrown); Assert.AreEqual("Accumulated product 1 value: not allowed to be null", exceptionMessage); }
public void OutputBuilderTests_BuildProductLines_CorrectProductName_StringStartsWithProductNameAndAComma() { //arrange var sut = new OutputBuilder(); IMinMax range = GetMinMaxMock(1, 5, 3); // Irrelevant to this test string names = "Working"; IAccumulatedProduct[] mockData = { GetAccumulatedProductMock(names, new double[0]) }; IAccumulatedProducts mockDatas = GetAccumulatedProductsMock(range, mockData); //act List <string> outputString = sut.BuildProductLines(mockDatas); //assert Assert.AreEqual("Working, ", outputString.First()); }
public List <string> BuildProductLines(IAccumulatedProducts products) { if (products == null) { throw new ArgumentNullException(nameof(products)); } if (products.Products == null) { throw new InvalidOperationException("The list of accumulated products is not allowed to be null"); } if (!products.Products.Any()) { throw new InvalidOperationException("The list of accumulated products is not allowed to be empty"); } List <string> productLines = new List <string>(); int index = 0; foreach (IAccumulatedProduct product in products.Products) { if (product == null) { throw new InvalidOperationException($"Accumulated product {index}: Not allowed to be null"); } if (product.Name == null) { throw new InvalidOperationException($"Accumulated product {index} name: Not allowed to be null"); } if (product.Values == null) { throw new InvalidOperationException($"Accumulated product {index} value: not allowed to be null"); } string toOutput = string.Join(", ", product.Values); string finalOutput = product.Name + ", " + toOutput; productLines.Add(finalOutput); index++; } return(productLines); }
public void OutputBuilderTests_BuildProductLines_IfNoDataIn_ThrowsException() { //arrange var sut = new OutputBuilder(); IMinMax range = GetMinMaxMock(1, 5, 3); // Irrelevant to this test IAccumulatedProducts mockDatas = GetAccumulatedProductsMock(range, new IAccumulatedProduct[] { }); bool exceptionThrown = false; string exceptionMessage = ""; //act try { sut.BuildProductLines(mockDatas); } catch (InvalidOperationException e) { exceptionThrown = true; exceptionMessage = e.Message; } //assert Assert.IsTrue(exceptionThrown); Assert.AreEqual("The list of accumulated products is not allowed to be empty", exceptionMessage); }