public async Task <ActionResult> FetchDetails(string registrationNumber, int complianceYear) { if (Request != null && !Request.IsAjaxRequest()) { throw new InvalidOperationException(); } if (!ModelState.IsValid) { return(Json(null, JsonRequestBehavior.AllowGet)); } using (IWeeeClient client = apiClient()) { await SetBreadcrumb(); GetProducerDetails request = new GetProducerDetails() { RegistrationNumber = registrationNumber, ComplianceYear = complianceYear }; ProducerDetails producerDetails = await client.SendAsync(User.GetAccessToken(), request); return(PartialView("_detailsResults", producerDetails)); } }
public async Task FetchDetails_FetchesDetailsFromApiAndReturnsDetailsView() { // Arrange BreadcrumbService breadcrumb = A.Dummy <BreadcrumbService>(); ISearcher <ProducerSearchResult> producerSearcher = A.Dummy <ISearcher <ProducerSearchResult> >(); IWeeeClient weeeClient = A.Fake <IWeeeClient>(); A.CallTo(() => weeeClient.SendAsync(A <string> ._, A <GetProducerComplianceYear> ._)) .WhenArgumentsMatch(a => ((GetProducerComplianceYear)a[1]).RegistrationNumber == "WEE/AA1111AA") .Returns(new List <int> { 2018, 2017, 2016 }); ProducerDetails producerDetails = A.Dummy <ProducerDetails>(); A.CallTo(() => weeeClient.SendAsync(A <string> ._, A <GetProducerDetails> ._)) .WhenArgumentsMatch(a => ((GetProducerDetails)a[1]).RegistrationNumber == "WEE/AA1111AA") .Returns(producerDetails); Func <IWeeeClient> weeeClientFunc = A.Fake <Func <IWeeeClient> >(); A.CallTo(() => weeeClientFunc()) .Returns(weeeClient); ProducersController controller = new ProducersController(breadcrumb, producerSearcher, weeeClientFunc, cache, configurationService); // Act ActionResult result = await controller.FetchDetails("WEE/AA1111AA", 2015); // Assert A.CallTo(() => weeeClient.SendAsync(A <string> ._, A <GetProducerDetails> ._)) .WhenArgumentsMatch(a => ((GetProducerDetails)a[1]).RegistrationNumber == "WEE/AA1111AA") .MustHaveHappened(); PartialViewResult viewResult = result as PartialViewResult; Assert.NotNull(viewResult); Assert.True(string.IsNullOrEmpty(viewResult.ViewName) || viewResult.ViewName.ToLowerInvariant() == "_detailsresults"); Assert.Equal(producerDetails, viewResult.Model); }
public DetailsViewModel() { Details = new ProducerDetails(); }
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); }