public async Task HandleAsync_WithNoRecordForRegistrationNumberAndComplianceYear_ThrowsArgumentException()
        {
            // Arrange
            IGetProducerDetailsDataAccess dataAccess = A.Fake <IGetProducerDetailsDataAccess>();

            A.CallTo(() => dataAccess.Fetch("WEE/AA1111AA", 2016))
            .Returns(new List <ProducerSubmission>());

            IWeeeAuthorization authorization = AuthorizationBuilder.CreateUserWithAllRights();
            IMapper            mapper        = A.Fake <IMapper>();

            GetProducerDetailsHandler handler = new GetProducerDetailsHandler(dataAccess, authorization, mapper);

            Requests.Admin.GetProducerDetails request = new Requests.Admin.GetProducerDetails()
            {
                RegistrationNumber = "WEE/AA1111AA",
                ComplianceYear     = 2016
            };

            // Act
            Func <Task <ProducerDetails> > action = async() => await handler.HandleAsync(request);

            // Assert
            await Assert.ThrowsAsync <ArgumentException>(action);
        }
        public async Task HandleAsync_WithNonInternalUser_ThrowsSecurityException(AuthorizationBuilder.UserType userType)
        {
            // Arrange
            IGetProducerDetailsDataAccess dataAccess    = A.Dummy <IGetProducerDetailsDataAccess>();
            IWeeeAuthorization            authorization = AuthorizationBuilder.CreateFromUserType(userType);
            IMapper mapper = A.Fake <IMapper>();

            GetProducerDetailsHandler handler = new GetProducerDetailsHandler(dataAccess, authorization, mapper);

            Requests.Admin.GetProducerDetails request = new Requests.Admin.GetProducerDetails()
            {
                RegistrationNumber = "WEE/AA1111AA"
            };

            // Act
            Func <Task <ProducerDetails> > action = async() => await handler.HandleAsync(request);

            // Assert
            await Assert.ThrowsAsync <SecurityException>(action);
        }
        public async Task HandleAsync_ProducerRegisteredTwiceIn2017ForSameScheme_ReturnsLatestProducerDetailsWithFirstRegistrationDate()
        {
            // Arrange
            var scheme = A.Fake <EA.Weee.Domain.Scheme.Scheme>();

            A.CallTo(() => scheme.SchemeName).Returns("Scheme Name");

            var memberUpload1 = A.Fake <EA.Weee.Domain.Scheme.MemberUpload>();

            A.CallTo(() => memberUpload1.ComplianceYear).Returns(2017);
            A.CallTo(() => memberUpload1.Scheme).Returns(scheme);

            var producer1 = new EA.Weee.Domain.Producer.ProducerSubmission(
                new Domain.Producer.RegisteredProducer("WEE/AA1111AA", 2017, scheme),
                memberUpload1,
                new EA.Weee.Domain.Producer.ProducerBusiness(),
                null,
                new DateTime(2015, 1, 1),
                0,
                false,
                null,
                "Trading Name 1",
                EEEPlacedOnMarketBandType.Lessthan5TEEEplacedonmarket,
                SellingTechniqueType.Both,
                Domain.Obligation.ObligationType.Both,
                AnnualTurnOverBandType.Greaterthanonemillionpounds,
                new List <Domain.Producer.BrandName>(),
                new List <Domain.Producer.SICCode>(),
                A.Dummy <ChargeBandAmount>(),
                0,
                A.Dummy <StatusType>());

            var memberUpload2 = A.Fake <EA.Weee.Domain.Scheme.MemberUpload>();

            A.CallTo(() => memberUpload2.ComplianceYear).Returns(2017);
            A.CallTo(() => memberUpload2.Scheme).Returns(scheme);

            var producer2 = new EA.Weee.Domain.Producer.ProducerSubmission(
                new Domain.Producer.RegisteredProducer("WEE/AA1111AA", 2017, scheme),
                memberUpload2,
                CreatePartnershipBusiness(),
                null,
                new DateTime(2015, 1, 2),
                0,
                false,
                null,
                "Trading Name 2",
                EEEPlacedOnMarketBandType.Lessthan5TEEEplacedonmarket,
                SellingTechniqueType.Both,
                Domain.Obligation.ObligationType.Both,
                AnnualTurnOverBandType.Greaterthanonemillionpounds,
                new List <Domain.Producer.BrandName>(),
                new List <Domain.Producer.SICCode>(),
                A.Dummy <ChargeBandAmount>(),
                0,
                A.Dummy <StatusType>());

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

            A.CallTo(() => dataAccess.Fetch("WEE/AA1111AA", 2017)).Returns(new List <Domain.Producer.ProducerSubmission>()
            {
                producer1,
                producer2
            });

            IWeeeAuthorization authorization = AuthorizationBuilder.CreateUserWithAllRights();

            IMapper mapper = A.Fake <IMapper>();

            GetProducerDetailsHandler handler = new GetProducerDetailsHandler(dataAccess, authorization, mapper);

            Requests.Admin.GetProducerDetails request = new Requests.Admin.GetProducerDetails()
            {
                RegistrationNumber = "WEE/AA1111AA",
                ComplianceYear     = 2017
            };

            // Act
            ProducerDetails result = await handler.HandleAsync(request);

            // Assert
            Assert.NotNull(result);
            Assert.Equal("Trading Name 2", result.Schemes[0].TradingName);
            Assert.Equal(new DateTime(2015, 1, 1), result.Schemes[0].RegistrationDate);
        }