Exemplo n.º 1
0
        public async Task <Guid> HandleAsync(ProcessDataReturnXmlFile message)
        {
            Scheme scheme = await dataAccess.FetchSchemeByOrganisationIdAsync(message.OrganisationId);

            authorization.EnsureSchemeAccess(scheme.Id);

            // record XML processing start time
            Stopwatch stopwatch = Stopwatch.StartNew();

            var xmlGeneratorResult = xmlGenerator.GenerateDataReturns <SchemeReturn>(message);
            DataReturnUpload dataReturnUpload;

            if (xmlGeneratorResult.SchemaErrors.Any())
            {
                dataReturnUpload = new DataReturnUpload(scheme, xmlGeneratorResult.XmlString,
                                                        xmlGeneratorResult.SchemaErrors.Select(e => e.ToDataReturnsUploadError()).ToList(),
                                                        message.FileName, null, null);
            }
            else
            {
                int         complianceYear = int.Parse(xmlGeneratorResult.DeserialisedType.ComplianceYear);
                QuarterType quarter        = xmlGeneratorResult.DeserialisedType.ReturnPeriod.ToDomainQuarterType();

                var pcsReturnVersionBuilder         = dataReturnVersionBuilderDelegate(scheme, new Quarter(complianceYear, quarter));
                var dataReturnVersionFromXmlBuilder = dataReturnVersionFromXmlBuilderDelegate(pcsReturnVersionBuilder);

                var dataReturnVersionBuilderResult = await dataReturnVersionFromXmlBuilder.Build(xmlGeneratorResult.DeserialisedType);

                var allErrors = (dataReturnVersionBuilderResult.ErrorData
                                 .Select(e => new DataReturnUploadError(e.ErrorLevel.ToDomainErrorLevel(), Domain.Error.UploadErrorType.Business, e.Description)))
                                .ToList();

                dataReturnUpload = new DataReturnUpload(scheme, xmlGeneratorResult.XmlString, allErrors, message.FileName, complianceYear, Convert.ToInt32(quarter));

                if (!dataReturnVersionBuilderResult.ErrorData.Any(e => e.ErrorLevel == ErrorLevel.Error))
                {
                    dataReturnUpload.SetDataReturnVersion(dataReturnVersionBuilderResult.DataReturnVersion);
                }
            }

            // Record XML processing end time
            stopwatch.Stop();
            dataReturnUpload.SetProcessTime(stopwatch.Elapsed);

            await dataAccess.AddAndSaveAsync(dataReturnUpload);

            return(dataReturnUpload.Id);
        }
Exemplo n.º 2
0
        public void SetDataReturnVersion_ThrowsArugmentNullException()
        {
            // Arrange
            var dataReturnUpload = new DataReturnUpload(
                A.Dummy <Scheme>(),
                A.Dummy <string>(),
                A.Dummy <List <DataReturnUploadError> >(),
                A.Dummy <string>(),
                A.Dummy <int>(),
                A.Dummy <int>());

            // Act
            Action action = () => dataReturnUpload.SetDataReturnVersion(null);

            // Assert
            Assert.Throws <ArgumentNullException>(action);
        }
Exemplo n.º 3
0
        public void Submit_WhenContainsNoErrorsOrWarnings_SubmitsWithNoException()
        {
            var dataReturnUpload = new DataReturnUpload(
                A.Dummy <Scheme>(),
                A.Dummy <string>(),
                null,
                A.Dummy <string>(),
                A.Dummy <int>(),
                A.Dummy <int>());

            dataReturnUpload.SetDataReturnVersion(new DataReturnVersion(A.Dummy <DataReturn>()));

            var exception = Record.Exception(() => dataReturnUpload.Submit("*****@*****.**"));

            Assert.Null(exception);
            Assert.True(dataReturnUpload.DataReturnVersion.IsSubmitted);
        }
Exemplo n.º 4
0
        public void Submit_WhenContainsErrors_ThrowInvalidOperationException()
        {
            var error = new DataReturnUploadError(ErrorLevel.Error, A.Dummy <UploadErrorType>(), A.Dummy <string>());

            var dataReturnUpload = new DataReturnUpload(
                A.Dummy <Scheme>(),
                A.Dummy <string>(),
                new List <DataReturnUploadError> {
                error
            },
                A.Dummy <string>(),
                A.Dummy <int>(),
                A.Dummy <int>());

            dataReturnUpload.SetDataReturnVersion(new DataReturnVersion(A.Dummy <DataReturn>()));

            Assert.Throws <InvalidOperationException>(() => dataReturnUpload.Submit("*****@*****.**"));
        }
Exemplo n.º 5
0
        public void Submit_WhenAlreadySubmitted_ThrowInvalidOperationException()
        {
            // Arrange
            var dataReturnUpload = new DataReturnUpload(
                A.Dummy <Scheme>(),
                A.Dummy <string>(),
                A.Dummy <List <DataReturnUploadError> >(),
                A.Dummy <string>(),
                A.Dummy <int>(),
                A.Dummy <int>());

            dataReturnUpload.SetDataReturnVersion(new DataReturnVersion(A.Dummy <DataReturn>()));
            dataReturnUpload.Submit("*****@*****.**");

            // Act
            Action action = () => dataReturnUpload.Submit("*****@*****.**");

            // Assert
            Assert.Throws <InvalidOperationException>(action);
        }
Exemplo n.º 6
0
        public void Submit_WhenContainsWarnings_SubmitsWithNoException()
        {
            var warning = new DataReturnUploadError(ErrorLevel.Warning, A.Dummy <UploadErrorType>(), A.Dummy <string>());

            var dataReturnUpload = new DataReturnUpload(
                A.Dummy <Scheme>(),
                A.Dummy <string>(),
                new List <DataReturnUploadError> {
                warning
            },
                A.Dummy <string>(),
                A.Dummy <int>(),
                A.Dummy <int>());

            dataReturnUpload.SetDataReturnVersion(new DataReturnVersion(A.Dummy <DataReturn>()));

            var exception = Record.Exception(() => dataReturnUpload.Submit("*****@*****.**"));

            Assert.Null(exception);
            Assert.True(dataReturnUpload.DataReturnVersion.IsSubmitted);
        }