public void Submit_WhenAlreadySubmitted_ThrowInvalidOperationException()
        {
            // Arrange
            var dataReturn = new DataReturn(A.Dummy<Scheme>(), A.Dummy<Quarter>());
            var dataReturnVersion = new DataReturnVersion(dataReturn);

            // Act
            dataReturnVersion.Submit("*****@*****.**");

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

            // Assert
            Assert.Throws<InvalidOperationException>(action);
        }
Exemplo n.º 2
0
        public void Submit_WhenAlreadySubmitted_ThrowInvalidOperationException()
        {
            // Arrange
            var dataReturn        = new DataReturn(A.Dummy <Scheme>(), A.Dummy <Quarter>());
            var dataReturnVersion = new DataReturnVersion(dataReturn);

            // Act
            dataReturnVersion.Submit("*****@*****.**");

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

            // Assert
            Assert.Throws <InvalidOperationException>(action);
        }
Exemplo n.º 3
0
        public async Task HandleAsync_SendsEmailWithDataReturnYear()
        {
            // Arrange
            string emailAddress       = "*****@*****.**";
            var    competentAuthority = new UKCompetentAuthority(Guid.NewGuid(), "Name", "Abbreviation", A.Dummy <Country>(), emailAddress, 0);

            Scheme scheme = A.Fake <Scheme>();

            A.CallTo(() => scheme.CompetentAuthority)
            .Returns(competentAuthority);

            Quarter quarter = new Quarter(2015, QuarterType.Q1);

            DataReturn        dataReturn        = new DataReturn(scheme, quarter);
            DataReturnVersion dataReturnVersion = new DataReturnVersion(dataReturn);

            dataReturnVersion.Submit("testUserId");

            var schemeSubmissionEvent = new SchemeDataReturnSubmissionEvent(dataReturnVersion);

            var emailService = A.Fake <IWeeeEmailService>();
            var dataAccess   = A.Dummy <ISchemeDataReturnSubmissionEventHandlerDataAccess>();
            var handler      = new SchemeDataReturnSubmissionEventHandler(emailService, dataAccess);

            // Act
            await handler.HandleAsync(schemeSubmissionEvent);

            // Assert
            A.CallTo(() => emailService.SendSchemeDataReturnSubmitted(A <string> ._, A <string> ._, 2015, A <int> ._, A <bool> ._))
            .MustHaveHappened(Repeated.Exactly.Once);
        }
Exemplo n.º 4
0
        public async Task HandleAsync_InvokesDataAccess_GetNumberOfDataReturnSubmissionsAsync_WithCorrectParameters()
        {
            // Arrange
            string emailAddress       = "*****@*****.**";
            var    competentAuthority = new UKCompetentAuthority(Guid.NewGuid(), "Name", "Abbreviation", A.Dummy <Country>(), emailAddress, 0);

            Scheme scheme = A.Fake <Scheme>();

            A.CallTo(() => scheme.CompetentAuthority)
            .Returns(competentAuthority);

            Quarter quarter = new Quarter(2016, QuarterType.Q2);

            DataReturn        dataReturn        = new DataReturn(scheme, quarter);
            DataReturnVersion dataReturnVersion = new DataReturnVersion(dataReturn);

            dataReturnVersion.Submit("testUserId");

            var dataAccess   = A.Fake <ISchemeDataReturnSubmissionEventHandlerDataAccess>();
            var emailService = A.Fake <IWeeeEmailService>();
            var handler      = new SchemeDataReturnSubmissionEventHandler(emailService, dataAccess);

            var schemeSubmissionEvent = new SchemeDataReturnSubmissionEvent(dataReturnVersion);

            // Act
            await handler.HandleAsync(schemeSubmissionEvent);

            // Assert
            A.CallTo(() => dataAccess.GetNumberOfDataReturnSubmissionsAsync(scheme, 2016, QuarterType.Q2))
            .MustHaveHappened();
        }
        public async Task HandleAsync_SendsEmailWithSchemeName()
        {
            // Arrange
            string emailAddress = "*****@*****.**";
            var competentAuthority = new UKCompetentAuthority(Guid.NewGuid(), "Name", "Abbreviation", A.Dummy<Country>(), emailAddress);

            Scheme scheme = A.Fake<Scheme>();
            A.CallTo(() => scheme.CompetentAuthority)
                .Returns(competentAuthority);
            A.CallTo(() => scheme.SchemeName)
                .Returns("Test Scheme Name");

            Quarter quarter = new Quarter(2016, QuarterType.Q1);

            DataReturn dataReturn = new DataReturn(scheme, quarter);
            DataReturnVersion dataReturnVersion = new DataReturnVersion(dataReturn);
            dataReturnVersion.Submit("testUserId");

            var schemeSubmissionEvent = new SchemeDataReturnSubmissionEvent(dataReturnVersion);

            var emailService = A.Fake<IWeeeEmailService>();
            var dataAccess = A.Dummy<ISchemeDataReturnSubmissionEventHandlerDataAccess>();
            var handler = new SchemeDataReturnSubmissionEventHandler(emailService, dataAccess);

            // Act
            await handler.HandleAsync(schemeSubmissionEvent);

            // Assert
            A.CallTo(() => emailService.SendSchemeDataReturnSubmitted(A<string>._, "Test Scheme Name", A<int>._, A<int>._, A<bool>._))
                .MustHaveHappened(Repeated.Exactly.Once);
        }
        public void Submit_AddSubmissionEventToEventsList()
        {
            // Arrange
            var dataReturn = new DataReturn(A.Dummy<Scheme>(), A.Dummy<Quarter>());
            var dataReturnVersion = new DataReturnVersion(dataReturn);

            // Act
            dataReturnVersion.Submit("*****@*****.**");

            // Assert
            Assert.Equal(1, dataReturnVersion.Events.Count());
            Assert.IsType<SchemeDataReturnSubmissionEvent>(dataReturnVersion.Events.Single());
            Assert.Same(dataReturnVersion, ((SchemeDataReturnSubmissionEvent)dataReturnVersion.Events.Single()).DataReturnVersion);
        }
        public void Submit_WhenNotYetSubmitted_MarksDataReturnVersionAsSubmitted()
        {
            // Arrange
            var dataReturn = new DataReturn(A.Dummy<Scheme>(), A.Dummy<Quarter>());
            var dataReturnVersion = new DataReturnVersion(dataReturn);

            // Act
            dataReturnVersion.Submit("*****@*****.**");

            // Assert
            Assert.True(dataReturnVersion.IsSubmitted);
            Assert.Equal(dataReturnVersion.SubmittingUserId, "*****@*****.**");
            Assert.Equal(dataReturnVersion.DataReturn.Id, dataReturn.Id);
        }
Exemplo n.º 8
0
        public void Submit_AddSubmissionEventToEventsList()
        {
            // Arrange
            var dataReturn        = new DataReturn(A.Dummy <Scheme>(), A.Dummy <Quarter>());
            var dataReturnVersion = new DataReturnVersion(dataReturn);

            // Act
            dataReturnVersion.Submit("*****@*****.**");

            // Assert
            Assert.Equal(1, dataReturnVersion.Events.Count());
            Assert.IsType <SchemeDataReturnSubmissionEvent>(dataReturnVersion.Events.Single());
            Assert.Same(dataReturnVersion, ((SchemeDataReturnSubmissionEvent)dataReturnVersion.Events.Single()).DataReturnVersion);
        }
Exemplo n.º 9
0
        public void Submit_WhenNotYetSubmitted_MarksDataReturnVersionAsSubmitted()
        {
            // Arrange
            var dataReturn        = new DataReturn(A.Dummy <Scheme>(), A.Dummy <Quarter>());
            var dataReturnVersion = new DataReturnVersion(dataReturn);

            // Act
            dataReturnVersion.Submit("*****@*****.**");

            // Assert
            Assert.True(dataReturnVersion.IsSubmitted);
            Assert.Equal(dataReturnVersion.SubmittingUserId, "*****@*****.**");
            Assert.Equal(dataReturnVersion.DataReturn.Id, dataReturn.Id);
        }
        public async Task HandleAsync_WithDataReturnWithNoEee_SetsHasSubmittedEEEToFalse()
        {
            // Arrange
            IWeeeAuthorization authorization = AuthorizationBuilder.CreateUserWithAllRights();

            Organisation organisation = Organisation.CreateSoleTrader("Trading Name");

            Scheme scheme = new Scheme(organisation);

            RegisteredProducer registeredProducer = new RegisteredProducer("WEE/AA1111AA", 2016, scheme);

            Guid registeredProducerId = new Guid("75B6B4E7-BA92-477D-A6CA-C43C8C0E9823");
            typeof(Entity).GetProperty("Id").SetValue(registeredProducer, registeredProducerId);

            MemberUpload memberUpload = new MemberUpload(
                A.Dummy<Guid>(),
                "data",
                new List<MemberUploadError>(),
                0,
                2016,
                scheme,
                "file.xml",
                "UserID");

            ProducerSubmission producerSubmission = new ProducerSubmission(
                registeredProducer,
                memberUpload,
                A.Dummy<ProducerBusiness>(),
                A.Dummy<AuthorisedRepresentative>(),
                A.Dummy<DateTime>(),
                A.Dummy<decimal?>(),
                A.Dummy<bool>(),
                A.Dummy<DateTime?>(),
                A.Dummy<string>(),
                A.Dummy<EEEPlacedOnMarketBandType>(),
                A.Dummy<SellingTechniqueType>(),
                A.Dummy<ObligationType>(),
                A.Dummy<AnnualTurnOverBandType>(),
                A.Dummy<List<BrandName>>(),
                A.Dummy<List<SICCode>>(),
                A.Dummy<ChargeBandAmount>(),
                A.Dummy<decimal>());

            registeredProducer.SetCurrentSubmission(producerSubmission);
            DataReturn dataReturn = new DataReturn(scheme, new Quarter(2016, QuarterType.Q4));

            DataReturnVersion dataReturnVersion = new DataReturnVersion(dataReturn);

            dataReturnVersion.Submit("UserID");

            IGetProducerDetailsByRegisteredProducerIdDataAccess dataAccess = A.Fake<IGetProducerDetailsByRegisteredProducerIdDataAccess>();

            A.CallTo(() => dataAccess.Fetch(registeredProducerId)).Returns(registeredProducer);
            A.CallTo(() => dataAccess.FetchDataReturns(scheme, 2016)).Returns(new List<DataReturn>() { dataReturn });

            GetProducerDetailsByRegisteredProducerIdHandler handler = new GetProducerDetailsByRegisteredProducerIdHandler(dataAccess, authorization);

            // Act
            GetProducerDetailsByRegisteredProducerId request = new GetProducerDetailsByRegisteredProducerId(registeredProducerId);
            ProducerDetailsScheme result = await handler.HandleAsync(request);

            // Assert
            Assert.Equal(false, result.HasSubmittedEEE);
        }
Exemplo n.º 11
0
        public Task Submit(DataReturnVersion dataReturnVersion)
        {
            dataReturnVersion.Submit(context.GetCurrentUser());

            return(context.SaveChangesAsync());
        }
        public async Task HandleAsync_InvokesDataAccess_GetNumberOfDataReturnSubmissionsAsync_WithCorrectParameters()
        {
            // Arrange
            string emailAddress = "*****@*****.**";
            var competentAuthority = new UKCompetentAuthority(Guid.NewGuid(), "Name", "Abbreviation", A.Dummy<Country>(), emailAddress);

            Scheme scheme = A.Fake<Scheme>();
            A.CallTo(() => scheme.CompetentAuthority)
                .Returns(competentAuthority);

            Quarter quarter = new Quarter(2016, QuarterType.Q2);

            DataReturn dataReturn = new DataReturn(scheme, quarter);
            DataReturnVersion dataReturnVersion = new DataReturnVersion(dataReturn);
            dataReturnVersion.Submit("testUserId");

            var dataAccess = A.Fake<ISchemeDataReturnSubmissionEventHandlerDataAccess>();
            var emailService = A.Fake<IWeeeEmailService>();
            var handler = new SchemeDataReturnSubmissionEventHandler(emailService, dataAccess);

            var schemeSubmissionEvent = new SchemeDataReturnSubmissionEvent(dataReturnVersion);

            // Act
            await handler.HandleAsync(schemeSubmissionEvent);

            // Assert
            A.CallTo(() => dataAccess.GetNumberOfDataReturnSubmissionsAsync(scheme, 2016, QuarterType.Q2))
                .MustHaveHappened();
        }
        public async Task HandleAsync_WithDataReturnWithNullEee_SetsHasSubmittedEEEToFalse()
        {
            // Arrange
            IWeeeAuthorization authorization = AuthorizationBuilder.CreateUserWithAllRights();

            Organisation organisation = Organisation.CreateSoleTrader("Trading Name");

            Scheme scheme = new Scheme(organisation);

            RegisteredProducer registeredProducer = new RegisteredProducer("WEE/AA1111AA", 2016, scheme);

            Guid registeredProducerId = new Guid("75B6B4E7-BA92-477D-A6CA-C43C8C0E9823");

            typeof(Entity).GetProperty("Id").SetValue(registeredProducer, registeredProducerId);

            MemberUpload memberUpload = new MemberUpload(
                A.Dummy <Guid>(),
                "data",
                new List <MemberUploadError>(),
                0,
                2016,
                scheme,
                "file.xml",
                "UserID");

            ProducerSubmission producerSubmission = new ProducerSubmission(
                registeredProducer,
                memberUpload,
                A.Dummy <ProducerBusiness>(),
                A.Dummy <AuthorisedRepresentative>(),
                A.Dummy <DateTime>(),
                A.Dummy <decimal?>(),
                A.Dummy <bool>(),
                A.Dummy <DateTime?>(),
                A.Dummy <string>(),
                A.Dummy <EEEPlacedOnMarketBandType>(),
                A.Dummy <SellingTechniqueType>(),
                A.Dummy <ObligationType>(),
                A.Dummy <AnnualTurnOverBandType>(),
                A.Dummy <List <BrandName> >(),
                A.Dummy <List <SICCode> >(),
                A.Dummy <ChargeBandAmount>(),
                A.Dummy <decimal>(),
                A.Dummy <StatusType>());

            registeredProducer.SetCurrentSubmission(producerSubmission);
            DataReturn dataReturn = new DataReturn(scheme, new Quarter(2016, QuarterType.Q4));

            DataReturnVersion dataReturnVersion = new DataReturnVersion(dataReturn,
                                                                        new WeeeCollectedReturnVersion(), new WeeeDeliveredReturnVersion(), null);

            dataReturnVersion.Submit("UserID");

            IGetProducerDetailsByRegisteredProducerIdDataAccess dataAccess = A.Fake <IGetProducerDetailsByRegisteredProducerIdDataAccess>();

            A.CallTo(() => dataAccess.Fetch(registeredProducerId)).Returns(registeredProducer);
            A.CallTo(() => dataAccess.FetchDataReturns(scheme, 2016)).Returns(new List <DataReturn>()
            {
                dataReturn
            });

            GetProducerDetailsByRegisteredProducerIdHandler handler = new GetProducerDetailsByRegisteredProducerIdHandler(dataAccess, authorization);

            // Act
            GetProducerDetailsByRegisteredProducerId request = new GetProducerDetailsByRegisteredProducerId(registeredProducerId);
            ProducerDetailsScheme result = await handler.HandleAsync(request);

            // Assert
            Assert.Equal(false, result.HasSubmittedEEE);
        }