public async Task GetOrAddAatfDeliveryLocation_NoMatchingApprovalNumber_ReturnsNewAatfDeliveryLocation() { // Arrange var dbContextHelper = new DbContextHelper(); var context = A.Fake<WeeeContext>(); var aatfDeliveryLocationDb = new AatfDeliveryLocation("xxx", "BBB"); var aatfDeliveryLocations = dbContextHelper.GetAsyncEnabledDbSet(new List<AatfDeliveryLocation> { aatfDeliveryLocationDb }); A.CallTo(() => context.AatfDeliveryLocations) .Returns(aatfDeliveryLocations); var dataAccess = new DataReturnVersionBuilderDataAccess(A.Dummy<Scheme>(), A.Dummy<Quarter>(), context); // Act var result = await dataAccess.GetOrAddAatfDeliveryLocation("AAA", "BBB"); // Assert Assert.NotNull(result); Assert.NotSame(aatfDeliveryLocationDb, result); Assert.Equal("AAA", result.ApprovalNumber); Assert.Equal("BBB", result.FacilityName); Assert.Contains(result, dataAccess.CachedAatfDeliveryLocations.Values); A.CallTo(() => aatfDeliveryLocations.Add(result)) .MustHaveHappened(); }
public async Task Build_ExistingLatestSubmittedDataReturnVersion_WithAllExistingWeeeDeliveredAmounts_ReturnsDataReturnVersionWithExistingWeeeDeliveredReturnVersion() { var aatfDeliveryLocation = new AatfDeliveryLocation("ApprovalNumber", "FacilityName"); var weeeDeliveredReturnVersion = new WeeeDeliveredReturnVersion(); weeeDeliveredReturnVersion.AddWeeeDeliveredAmount( new WeeeDeliveredAmount(ObligationType.B2C, WeeeCategory.ConsumerEquipment, 100, aatfDeliveryLocation)); var dataReturn = new DataReturn(A.Dummy <Scheme>(), A.Dummy <Quarter>()); var dataReturnVersion = new DataReturnVersion(dataReturn, A.Dummy <WeeeCollectedReturnVersion>(), weeeDeliveredReturnVersion, A.Dummy <EeeOutputReturnVersion>()); dataReturn.SetCurrentVersion(dataReturnVersion); var helper = new DataReturnVersionBuilderHelper(); A.CallTo(() => helper.DataAccess.FetchDataReturnOrDefault()) .Returns(dataReturn); A.CallTo(() => helper.DataAccess.GetOrAddAatfDeliveryLocation(A <string> ._, A <string> ._)) .Returns(aatfDeliveryLocation); var builder = helper.Create(); await builder.AddAatfDeliveredAmount("ApprovalNumber", "FacilityName", WeeeCategory.ConsumerEquipment, ObligationType.B2C, 100); var result = await builder.Build(); Assert.Same(weeeDeliveredReturnVersion, result.DataReturnVersion.WeeeDeliveredReturnVersion); }
public async Task GetOrAddAatfDeliveryLocation_NoMatchingApprovalNumber_ReturnsNewAatfDeliveryLocation() { // Arrange var dbContextHelper = new DbContextHelper(); var context = A.Fake <WeeeContext>(); var aatfDeliveryLocationDb = new AatfDeliveryLocation("xxx", "BBB"); var aatfDeliveryLocations = dbContextHelper.GetAsyncEnabledDbSet(new List <AatfDeliveryLocation> { aatfDeliveryLocationDb }); A.CallTo(() => context.AatfDeliveryLocations) .Returns(aatfDeliveryLocations); var dataAccess = new DataReturnVersionBuilderDataAccess(A.Dummy <Scheme>(), A.Dummy <Quarter>(), context); // Act var result = await dataAccess.GetOrAddAatfDeliveryLocation("AAA", "BBB"); // Assert Assert.NotNull(result); Assert.NotSame(aatfDeliveryLocationDb, result); Assert.Equal("AAA", result.ApprovalNumber); Assert.Equal("BBB", result.FacilityName); Assert.Contains(result, dataAccess.CachedAatfDeliveryLocations.Values); A.CallTo(() => aatfDeliveryLocations.Add(result)) .MustHaveHappened(); }
public WeeeDeliveredAmountBuilder() { obligationType = ObligationType.B2C; tonnage = 100; weeeCategory = WeeeCategory.AutomaticDispensers; aatfDeliveryLocation = new AatfDeliveryLocation("ApprovalNumber", "FacilityName"); }
public async Task <AatfDeliveryLocation> GetOrAddAatfDeliveryLocation(string approvalNumber, string facilityName) { // Replace empty strings with null facilityName = string.IsNullOrEmpty(facilityName) ? null : facilityName; if (cachedAatfDeliveryLocations == null) { cachedAatfDeliveryLocations = await context.AatfDeliveryLocations .ToDictionaryAsync(aatf => string.Format("{0}{1}", aatf.ApprovalNumber, aatf.FacilityName), StringComparer.OrdinalIgnoreCase); } var key = string.Format("{0}{1}", approvalNumber, facilityName); AatfDeliveryLocation aatfDeliveryLocation; if (!cachedAatfDeliveryLocations.TryGetValue(key, out aatfDeliveryLocation)) { aatfDeliveryLocation = new AatfDeliveryLocation(approvalNumber, facilityName); cachedAatfDeliveryLocations.Add(key, aatfDeliveryLocation); context.AatfDeliveryLocations.Add(aatfDeliveryLocation); } return(aatfDeliveryLocation); }
public static WeeeDeliveredAmount WithAatfDeliveryLocation(AatfDeliveryLocation aatfDeliveryLocation) { var builder = new WeeeDeliveredAmountBuilder(); builder.aatfDeliveryLocation = aatfDeliveryLocation; return(builder.Build()); }
public async Task GetOrAddAatfDeliveryLocation_PopulatesCacheWithDatabaseValues(string approvalNumber, string facilityName) { // Arrange var dbContextHelper = new DbContextHelper(); var context = A.Fake<WeeeContext>(); var aatfDeliveryLocationDb = new AatfDeliveryLocation(approvalNumber, facilityName); var aatfDeliveryLocations = dbContextHelper.GetAsyncEnabledDbSet(new List<AatfDeliveryLocation> { aatfDeliveryLocationDb }); A.CallTo(() => context.AatfDeliveryLocations) .Returns(aatfDeliveryLocations); var dataAccess = new DataReturnVersionBuilderDataAccess(A.Dummy<Scheme>(), A.Dummy<Quarter>(), context); // Act await dataAccess.GetOrAddAatfDeliveryLocation(approvalNumber, facilityName); // Assert Assert.Equal(1, dataAccess.CachedAatfDeliveryLocations.Count); Assert.Contains(aatfDeliveryLocationDb, dataAccess.CachedAatfDeliveryLocations.Values); }
public async Task GetOrAddAatfDeliveryLocation_WithMatchingApprovalNumberAndFacilityName_DoesNotAddToCacheAndDatabase(string approvalNumber, string facilityName) { // Arrange var dbContextHelper = new DbContextHelper(); var context = A.Fake<WeeeContext>(); var aatfDeliveryLocationDb = new AatfDeliveryLocation(approvalNumber, facilityName); var aatfDeliveryLocations = dbContextHelper.GetAsyncEnabledDbSet(new List<AatfDeliveryLocation> { aatfDeliveryLocationDb }); A.CallTo(() => context.AatfDeliveryLocations) .Returns(aatfDeliveryLocations); var dataAccess = new DataReturnVersionBuilderDataAccess(A.Dummy<Scheme>(), A.Dummy<Quarter>(), context); // Act var result = await dataAccess.GetOrAddAatfDeliveryLocation(approvalNumber, facilityName); // Assert Assert.Equal(1, dataAccess.CachedAatfDeliveryLocations.Count); A.CallTo(() => aatfDeliveryLocations.Add(result)) .MustNotHaveHappened(); }
public async Task AddAatfDeliveredAmount_CreatesAatfDeliveredAmountDomainObject() { var helper = new DataReturnVersionBuilderHelper(); A.CallTo(() => helper.DataAccess.FetchDataReturnOrDefault()) .Returns((DataReturn)null); var aatfDeliveryLocation = new AatfDeliveryLocation("Approval Number", "Facility name"); A.CallTo(() => helper.DataAccess.GetOrAddAatfDeliveryLocation(A <string> ._, A <string> ._)) .Returns(aatfDeliveryLocation); var builder = helper.Create(); await builder.AddAatfDeliveredAmount("Approval Number", "Facility name", A.Dummy <WeeeCategory>(), ObligationType.B2C, A.Dummy <decimal>()); var result = await builder.Build(); Assert.Equal(1, result.DataReturnVersion.WeeeDeliveredReturnVersion.WeeeDeliveredAmounts.Count); Assert.Collection(result.DataReturnVersion.WeeeDeliveredReturnVersion.WeeeDeliveredAmounts, r => Assert.Equal("Approval Number", r.AatfDeliveryLocation.ApprovalNumber)); Assert.Same(aatfDeliveryLocation, result.DataReturnVersion.WeeeDeliveredReturnVersion.WeeeDeliveredAmounts.Single().AatfDeliveryLocation); }
private static IEnumerable <WeeeDeliveredAmount> CreateDeliveredToAatfs(string approvalNumber) { var deliveredToAatfs = new List <WeeeDeliveredAmount>(); string facilityName = string.Empty; if (RandomHelper.OneIn(2)) { facilityName = RandomHelper.CreateRandomString("Facility", 0, 250); } var deliveryLocation = new AatfDeliveryLocation(approvalNumber, facilityName); IEnumerable <IReturnItem> returnItems = CreateReturnItems(null); foreach (IReturnItem returnItem in returnItems) { deliveredToAatfs.Add(new WeeeDeliveredAmount(returnItem.ObligationType, returnItem.WeeeCategory, returnItem.Tonnage, deliveryLocation)); } return(deliveredToAatfs); }
public async Task GetOrAddAatfDeliveryLocation_PopulatesCacheWithDatabaseValues(string approvalNumber, string facilityName) { // Arrange var dbContextHelper = new DbContextHelper(); var context = A.Fake <WeeeContext>(); var aatfDeliveryLocationDb = new AatfDeliveryLocation(approvalNumber, facilityName); var aatfDeliveryLocations = dbContextHelper.GetAsyncEnabledDbSet(new List <AatfDeliveryLocation> { aatfDeliveryLocationDb }); A.CallTo(() => context.AatfDeliveryLocations) .Returns(aatfDeliveryLocations); var dataAccess = new DataReturnVersionBuilderDataAccess(A.Dummy <Scheme>(), A.Dummy <Quarter>(), context); // Act await dataAccess.GetOrAddAatfDeliveryLocation(approvalNumber, facilityName); // Assert Assert.Equal(1, dataAccess.CachedAatfDeliveryLocations.Count); Assert.Contains(aatfDeliveryLocationDb, dataAccess.CachedAatfDeliveryLocations.Values); }
public async Task GetOrAddAatfDeliveryLocation_WithMatchingApprovalNumberAndFacilityName_DoesNotAddToCacheAndDatabase(string approvalNumber, string facilityName) { // Arrange var dbContextHelper = new DbContextHelper(); var context = A.Fake <WeeeContext>(); var aatfDeliveryLocationDb = new AatfDeliveryLocation(approvalNumber, facilityName); var aatfDeliveryLocations = dbContextHelper.GetAsyncEnabledDbSet(new List <AatfDeliveryLocation> { aatfDeliveryLocationDb }); A.CallTo(() => context.AatfDeliveryLocations) .Returns(aatfDeliveryLocations); var dataAccess = new DataReturnVersionBuilderDataAccess(A.Dummy <Scheme>(), A.Dummy <Quarter>(), context); // Act var result = await dataAccess.GetOrAddAatfDeliveryLocation(approvalNumber, facilityName); // Assert Assert.Equal(1, dataAccess.CachedAatfDeliveryLocations.Count); A.CallTo(() => aatfDeliveryLocations.Add(result)) .MustNotHaveHappened(); }
public async Task AddAatfDeliveredAmount_CreatesAatfDeliveredAmountDomainObject() { var helper = new DataReturnVersionBuilderHelper(); A.CallTo(() => helper.DataAccess.FetchDataReturnOrDefault()) .Returns((DataReturn)null); var aatfDeliveryLocation = new AatfDeliveryLocation("Approval Number", "Facility name"); A.CallTo(() => helper.DataAccess.GetOrAddAatfDeliveryLocation(A<string>._, A<string>._)) .Returns(aatfDeliveryLocation); var builder = helper.Create(); await builder.AddAatfDeliveredAmount("Approval Number", "Facility name", A.Dummy<WeeeCategory>(), ObligationType.B2C, A.Dummy<decimal>()); var result = await builder.Build(); Assert.Equal(1, result.DataReturnVersion.WeeeDeliveredReturnVersion.WeeeDeliveredAmounts.Count); Assert.Collection(result.DataReturnVersion.WeeeDeliveredReturnVersion.WeeeDeliveredAmounts, r => Assert.Equal("Approval Number", r.AatfDeliveryLocation.ApprovalNumber)); Assert.Same(aatfDeliveryLocation, result.DataReturnVersion.WeeeDeliveredReturnVersion.WeeeDeliveredAmounts.Single().AatfDeliveryLocation); }
public async Task Build_ExistingLatestSubmittedDataReturnVersion_WithAllExistingWeeeDeliveredAmounts_ReturnsDataReturnVersionWithExistingWeeeDeliveredReturnVersion() { var aatfDeliveryLocation = new AatfDeliveryLocation("ApprovalNumber", "FacilityName"); var weeeDeliveredReturnVersion = new WeeeDeliveredReturnVersion(); weeeDeliveredReturnVersion.AddWeeeDeliveredAmount( new WeeeDeliveredAmount(ObligationType.B2C, WeeeCategory.ConsumerEquipment, 100, aatfDeliveryLocation)); var dataReturn = new DataReturn(A.Dummy<Scheme>(), A.Dummy<Quarter>()); var dataReturnVersion = new DataReturnVersion(dataReturn, A.Dummy<WeeeCollectedReturnVersion>(), weeeDeliveredReturnVersion, A.Dummy<EeeOutputReturnVersion>()); dataReturn.SetCurrentVersion(dataReturnVersion); var helper = new DataReturnVersionBuilderHelper(); A.CallTo(() => helper.DataAccess.FetchDataReturnOrDefault()) .Returns(dataReturn); A.CallTo(() => helper.DataAccess.GetOrAddAatfDeliveryLocation(A<string>._, A<string>._)) .Returns(aatfDeliveryLocation); var builder = helper.Create(); await builder.AddAatfDeliveredAmount("ApprovalNumber", "FacilityName", WeeeCategory.ConsumerEquipment, ObligationType.B2C, 100); var result = await builder.Build(); Assert.Same(weeeDeliveredReturnVersion, result.DataReturnVersion.WeeeDeliveredReturnVersion); }
private static IEnumerable<WeeeDeliveredAmount> CreateDeliveredToAatfs(string approvalNumber) { var deliveredToAatfs = new List<WeeeDeliveredAmount>(); string facilityName = string.Empty; if (RandomHelper.OneIn(2)) { facilityName = RandomHelper.CreateRandomString("Facility", 0, 250); } var deliveryLocation = new AatfDeliveryLocation(approvalNumber, facilityName); IEnumerable<IReturnItem> returnItems = CreateReturnItems(null); foreach (IReturnItem returnItem in returnItems) { deliveredToAatfs.Add(new WeeeDeliveredAmount(returnItem.ObligationType, returnItem.WeeeCategory, returnItem.Tonnage, deliveryLocation)); } return deliveredToAatfs; }
public void GenerateXml_CreatesValidDataReturnsXmlFile() { // Arrange var scheme = A.Fake <Scheme>(); A.CallTo(() => scheme.ApprovalNumber) .Returns("WEE/SC0001ST/SCH"); var dataReturn = new DataReturn(scheme, new Quarter(2016, QuarterType.Q2)); var dataReturnVersion = new DataReturnVersion(dataReturn); // WEEE collected dataReturnVersion.WeeeCollectedReturnVersion.AddWeeeCollectedAmount( new WeeeCollectedAmount(WeeeCollectedAmountSourceType.Dcf, ObligationType.B2C, WeeeCategory.ElectricalAndElectronicTools, 100)); dataReturnVersion.WeeeCollectedReturnVersion.AddWeeeCollectedAmount( new WeeeCollectedAmount(WeeeCollectedAmountSourceType.Dcf, ObligationType.B2B, WeeeCategory.DisplayEquipment, 200)); dataReturnVersion.WeeeCollectedReturnVersion.AddWeeeCollectedAmount( new WeeeCollectedAmount(WeeeCollectedAmountSourceType.Distributor, ObligationType.B2C, WeeeCategory.ElectricalAndElectronicTools, 100)); dataReturnVersion.WeeeCollectedReturnVersion.AddWeeeCollectedAmount( new WeeeCollectedAmount(WeeeCollectedAmountSourceType.Distributor, ObligationType.B2C, WeeeCategory.ITAndTelecommsEquipment, 50)); dataReturnVersion.WeeeCollectedReturnVersion.AddWeeeCollectedAmount( new WeeeCollectedAmount(WeeeCollectedAmountSourceType.FinalHolder, ObligationType.B2C, WeeeCategory.ElectricalAndElectronicTools, 100)); dataReturnVersion.WeeeCollectedReturnVersion.AddWeeeCollectedAmount( new WeeeCollectedAmount(WeeeCollectedAmountSourceType.FinalHolder, ObligationType.B2C, WeeeCategory.MedicalDevices, 2)); // WEEE delivered var aatfDeliveryLocation1 = new AatfDeliveryLocation("WEE/AA0001AA/ATF", "TestAATF1"); dataReturnVersion.WeeeDeliveredReturnVersion.AddWeeeDeliveredAmount( new WeeeDeliveredAmount(ObligationType.B2C, WeeeCategory.LargeHouseholdAppliances, 200, aatfDeliveryLocation1)); dataReturnVersion.WeeeDeliveredReturnVersion.AddWeeeDeliveredAmount( new WeeeDeliveredAmount(ObligationType.B2C, WeeeCategory.PhotovoltaicPanels, 200, aatfDeliveryLocation1)); var aatfDeliveryLocation2 = new AatfDeliveryLocation("WEE/AA0002AA/ATF", "TestAATF2"); dataReturnVersion.WeeeDeliveredReturnVersion.AddWeeeDeliveredAmount( new WeeeDeliveredAmount(ObligationType.B2B, WeeeCategory.PhotovoltaicPanels, 200, aatfDeliveryLocation2)); var aeDeliveryLocation1 = new AeDeliveryLocation("WEE/AA0001AA/AE", "TestAE1"); dataReturnVersion.WeeeDeliveredReturnVersion.AddWeeeDeliveredAmount( new WeeeDeliveredAmount(ObligationType.B2C, WeeeCategory.LargeHouseholdAppliances, 200, aeDeliveryLocation1)); dataReturnVersion.WeeeDeliveredReturnVersion.AddWeeeDeliveredAmount( new WeeeDeliveredAmount(ObligationType.B2B, WeeeCategory.LightingEquipment, 20, aeDeliveryLocation1)); var aeDeliveryLocation2 = new AeDeliveryLocation("WEE/AA0002AA/AE", "TestAE2"); dataReturnVersion.WeeeDeliveredReturnVersion.AddWeeeDeliveredAmount( new WeeeDeliveredAmount(ObligationType.B2B, WeeeCategory.LightingEquipment, 10, aeDeliveryLocation2)); // EEE output var registeredProducer1 = CreateRegisteredProducer(scheme, 2016, "WEE/AA0001RP", "Test Organisation1"); dataReturnVersion.EeeOutputReturnVersion.AddEeeOutputAmount( new EeeOutputAmount(ObligationType.B2C, WeeeCategory.LightingEquipment, 3000, registeredProducer1)); dataReturnVersion.EeeOutputReturnVersion.AddEeeOutputAmount( new EeeOutputAmount(ObligationType.B2C, WeeeCategory.PhotovoltaicPanels, 100, registeredProducer1)); var registeredProducer2 = CreateRegisteredProducer(scheme, 2016, "WEE/AA0002RP", "Test Organisation2"); dataReturnVersion.EeeOutputReturnVersion.AddEeeOutputAmount( new EeeOutputAmount(ObligationType.B2C, WeeeCategory.PhotovoltaicPanels, 100, registeredProducer2)); var xmlGenerator = new XmlGenerator(); // Act var generatedXml = xmlGenerator.GenerateXml(dataReturnVersion); // Assert var xmlSchemaHelper = new XmlSchemaHelper(@"DataReturns\v3schema.xsd"); var validationResult = xmlSchemaHelper.ValidateXml(generatedXml); Assert.Empty(validationResult); }
public static WeeeDeliveredAmount WithAatfDeliveryLocation(AatfDeliveryLocation aatfDeliveryLocation) { var builder = new WeeeDeliveredAmountBuilder(); builder.aatfDeliveryLocation = aatfDeliveryLocation; return builder.Build(); }
public WeeeDeliveredAmount CreateWeeeDeliveredAmount(DataReturnVersion dataReturnVersion, AatfDeliveryLocation location, string obligationType, int weeeCategory, decimal tonnage) { var weeeDeliveredAmount = new WeeeDeliveredAmount { Id = IntegerToGuid(GetNextId()), AatfDeliveryLocationId = location.Id, AatfDeliveryLocation = location, ObligationType = obligationType, Tonnage = tonnage, WeeeCategory = weeeCategory }; AddWeeeDeliveredAmount(dataReturnVersion, weeeDeliveredAmount); return weeeDeliveredAmount; }
public AatfDeliveryLocation CreateAatfDeliveryLocation(string approvalNumber, string facilityName) { var aatfDeliveryLocation = new AatfDeliveryLocation { Id = IntegerToGuid(GetNextId()), ApprovalNumber = approvalNumber, FacilityName = facilityName }; model.AatfDeliveryLocations.Add(aatfDeliveryLocation); return aatfDeliveryLocation; }
public async Task<AatfDeliveryLocation> GetOrAddAatfDeliveryLocation(string approvalNumber, string facilityName) { // Replace empty strings with null facilityName = string.IsNullOrEmpty(facilityName) ? null : facilityName; if (cachedAatfDeliveryLocations == null) { cachedAatfDeliveryLocations = await context.AatfDeliveryLocations .ToDictionaryAsync(aatf => string.Format("{0}{1}", aatf.ApprovalNumber, aatf.FacilityName), StringComparer.OrdinalIgnoreCase); } var key = string.Format("{0}{1}", approvalNumber, facilityName); AatfDeliveryLocation aatfDeliveryLocation; if (!cachedAatfDeliveryLocations.TryGetValue(key, out aatfDeliveryLocation)) { aatfDeliveryLocation = new AatfDeliveryLocation(approvalNumber, facilityName); cachedAatfDeliveryLocations.Add(key, aatfDeliveryLocation); context.AatfDeliveryLocations.Add(aatfDeliveryLocation); } return aatfDeliveryLocation; }