public async Task FormatOutputText_ReturnsFormattedText(string path) { // arrange var service = new OutputFormatter(); var storageCollection = new List <Storage>() { new Storage() { Id = "testId1", Materials = new List <Material>() { new Material() { Id = "materialId1", Name = "materialName1", Quantity = 12 } } }, new Storage() { Id = "testId2", Materials = new List <Material>() { new Material() { Id = "materialId2", Name = "materialName1", Quantity = 5 } } }, new Storage() { Id = "testId3", Materials = new List <Material>() { new Material() { Id = "materialId3", Name = "materialName3", Quantity = 7 } } } }; var expected = await FileReadeHelper.ReadFromFileAsync(path); // act var actual = service.FormatOutputText(storageCollection); // assert Assert.IsNotNull(actual); Assert.AreEqual(expected, actual); }
public async Task ReadFileAsLinesAsync_CorrectFilePath_ReturnsTextLineCollection(string path) { // arrange var inputLines = (await FileReadeHelper.ReadFromFileAsync(path)).Split(Environment.NewLine).ToList(); var service = new Services.FileReader(); // act var actual = await service.ReadFileAsLinesAsync(path); // assert Assert.IsNotNull(actual); Assert.IsInstanceOfType(actual, typeof(List <string>)); Assert.AreEqual(inputLines.Count, actual.Count); }
public async Task ConvertInputToStorageModelCollection_CorrectPayload_ReturnStorageCollection(string path) { // arrange var inputLines = (await FileReadeHelper.ReadFromFileAsync(path)).Split(Environment.NewLine).ToList(); var logger = Substitute.For <ILogger <LineItemConverter> >(); var service = new LineItemConverter(logger); // act var actual = service.ConvertToStorageModelCollection(inputLines); // assert Assert.IsNotNull(actual); Assert.IsInstanceOfType(actual, typeof(List <Storage>)); Assert.AreEqual(14, actual.Count); }
public async Task ConvertInputToStorageModelCollection_IncorrectPayload_ReturnEmptyCollection(string path) { // arrange var inputLines = (await FileReadeHelper.ReadFromFileAsync(path)).Split(Environment.NewLine).ToList(); var logger = Substitute.For <ILogger <LineItemConverter> >(); var service = new LineItemConverter(logger); // act var actual = service.ConvertToStorageModelCollection(inputLines); // assert Assert.IsNotNull(actual); Assert.IsInstanceOfType(actual, typeof(List <Storage>)); Assert.AreEqual(0, actual.Count); logger.Received().Log( LogLevel.Error, Arg.Any <EventId>(), Arg.Is <object>(o => o.ToString() == "Index was outside the bounds of the array."), null, Arg.Any <Func <object, Exception, string> >()); }