public async void Fetch_TwoUploadsForTheSameComplianceYear_OnlyReturnsTheYearOnce() { using (var database = new DatabaseWrapper()) { const int complianceYear = 2005; // Arrange var modelHelper = new ModelHelper(database.Model); var organisation = modelHelper.CreateOrganisation(); await database.Model.SaveChangesAsync(); var scheme = modelHelper.CreateScheme(organisation); await database.Model.SaveChangesAsync(); var firstDataReturn = modelHelper.CreateDataReturn(scheme, complianceYear, (int)QuarterType.Q1); await database.Model.SaveChangesAsync(); var firstDataReturnVersion = modelHelper.CreateDataReturnVersion(scheme, complianceYear, (int)QuarterType.Q1, true, firstDataReturn); modelHelper.CreateDataReturnUpload(scheme, firstDataReturnVersion); await database.Model.SaveChangesAsync(); var secondDataReturn = modelHelper.CreateDataReturn(scheme, complianceYear, (int)QuarterType.Q2); await database.Model.SaveChangesAsync(); var secondDataReturnVersion = modelHelper.CreateDataReturnVersion(scheme, complianceYear, (int)QuarterType.Q2, true, secondDataReturn); modelHelper.CreateDataReturnUpload(scheme, secondDataReturnVersion); await database.Model.SaveChangesAsync(); // Act var dataAccess = new FetchDataReturnComplianceYearsForSchemeDataAccess(database.WeeeContext); var result = await dataAccess.GetDataReturnComplianceYearsForScheme(scheme.Id); // Assert Assert.Single(result.Where(y => y == complianceYear)); } }
public async Task GetDataReturnComplianceYearsForSchemeHandler_ReturnsYearsInDescendingOrder() { using (var database = new DatabaseWrapper()) { // Arrange ModelHelper helper = new ModelHelper(database.Model); var scheme = helper.CreateScheme(); var firstDataReturn = helper.CreateDataReturn(scheme, 2006, (int)QuarterType.Q1); var firstDataReturnVersion = helper.CreateDataReturnVersion(scheme, 2006, 1, true, firstDataReturn); helper.CreateDataReturnUpload(scheme, firstDataReturnVersion); var secondDataReturn = helper.CreateDataReturn(scheme, 2007, (int)QuarterType.Q1); var secondDataReturnVersion = helper.CreateDataReturnVersion(scheme, 2007, 1, true, secondDataReturn); helper.CreateDataReturnUpload(scheme, secondDataReturnVersion); database.Model.SaveChanges(); // Act var dataAccess = new FetchDataReturnComplianceYearsForSchemeDataAccess(database.WeeeContext); var yearsList = await dataAccess.GetDataReturnComplianceYearsForScheme(scheme.Id); //Assert Assert.NotNull(yearsList); Assert.Equal(2, yearsList.Count); Assert.Collection(yearsList, r1 => Assert.Equal("2007", r1.ToString()), r2 => Assert.Equal("2006", r2.ToString())); } }