public void ParseFile_WithOneValidMinimalRowInCsvInputFile_ReadsAndSavesStageDischargeRecordsAndReturnsSuccess()
        {
            using (var stream = CreateMinimalValidFileStream())
            {
                _mockAppender.GetLocationByIdentifier(Arg.Any <string>())
                .Returns(LocationInfoHelper.GetTestLocationInfo(_fixture));

                var results = _csvDataPlugin.ParseFile(stream, _mockAppender, _mockLogger);

                results.Status.Should().NotBe(ParseFileStatus.CannotParse);

                _mockAppender.Received().AddFieldVisit(Arg.Any <LocationInfo>(), Arg.Any <FieldVisitDetails>());
                _mockAppender.Received(1).AddDischargeActivity(Arg.Any <FieldVisitInfo>(), Arg.Any <DischargeActivity>());
            }
        }
        public void ParseFile_WithLocationContextParseFile_CallsGlobalContextParseFile()
        {
            using (var stream = CreateValidCsvFileStream())
            {
                var location = LocationInfoHelper.GetTestLocationInfo(_fixture);
                _mockAppender.GetLocationByIdentifier(Arg.Any <string>())
                .Returns(LocationInfoHelper.GetTestLocationInfo(_fixture));

                var results = _csvDataPlugin.ParseFile(stream, location, _mockAppender, _mockLogger);

                results.Status.Should().NotBe(ParseFileStatus.CannotParse);
                results.Status.Should().Be(ParseFileStatus.SuccessfullyParsedAndDataValid);

                _mockAppender.Received().AddFieldVisit(Arg.Any <LocationInfo>(), Arg.Any <FieldVisitDetails>());
                _mockAppender.Received(1).AddDischargeActivity(Arg.Any <FieldVisitInfo>(), Arg.Any <DischargeActivity>());
            }
        }
        public void SetUp()
        {
            Fixture = new Fixture();

            Logger = new NullLog();
            FieldDataResultsAppender = Substitute.For <IFieldDataResultsAppender>();

            _locationInfo = LocationInfoHelper.GetTestLocationInfo(Fixture);

            FieldDataResultsAppender
            .GetLocationByUniqueId(Arg.Any <string>())
            .Returns(_locationInfo);

            FieldDataResultsAppender
            .GetLocationByIdentifier(Arg.Any <string>())
            .Returns(_locationInfo);
        }
        public void ParseFile_WithFiveValidRowsInCsvInputFile_ReadsAndSavesAndReturnsSuccess()
        {
            var csvFile = new InMemoryCsvFile <StageDischargeReadingRecord>();

            PutNRecordsInCsvFile(5, ref csvFile);

            using (var stream = csvFile.GetInMemoryCsvFileStream())
            {
                _mockAppender.GetLocationByIdentifier(Arg.Any <string>())
                .Returns(LocationInfoHelper.GetTestLocationInfo(_fixture),
                         LocationInfoHelper.GetTestLocationInfo(_fixture),
                         LocationInfoHelper.GetTestLocationInfo(_fixture),
                         LocationInfoHelper.GetTestLocationInfo(_fixture),
                         LocationInfoHelper.GetTestLocationInfo(_fixture));

                var results = _csvDataPlugin.ParseFile(stream, _mockAppender, _mockLogger);

                results.Status.Should().NotBe(ParseFileStatus.CannotParse, results.ErrorMessage);
                results.Status.Should().Be(ParseFileStatus.SuccessfullyParsedAndDataValid);

                _mockAppender.Received().AddFieldVisit(Arg.Any <LocationInfo>(), Arg.Any <FieldVisitDetails>());
                _mockAppender.Received(5).AddDischargeActivity(Arg.Any <FieldVisitInfo>(), Arg.Any <DischargeActivity>());
            }
        }